我想在我的着色器中定义一个浮点数组,如下所示:
Properties
{
_TilesX ("Tiles X", Int) = 10
_TilesY ("Tiles Y", Int) = 10
_TileData1 ("Tile data", Float[]) = {} // THIS!!!
_Texture1 ("Texture odd", 2D) = "white" {}
_Texture2 ("Texture even", 2D) = "white" {}
}
我正在尝试创建一个用作网格的平面,并且我想在运行时修改 _TileData1 以更改图块的 Y 偏移量。我使用 _TilesX 和 _TilesY 从 1d 数组中获取图块的 2d 位置。
需要明确的是,我只是想了解如何定义属性类型float[]
因为我在 Unity 的手册页或论坛上找不到如何执行此操作。
您不能将属性用于float[]
。但是您可以将它们用作着色器中的变量并从脚本中设置它们:
在你的着色器中:
CGPROGRAM
int _SegmentsCount = 0;
float _Segments[1000];
void surf (Input IN, inout SurfaceOutput o) {
for (int i = 0; i < _SegmentsCount; i++) {
// This is obsviously just an example,
// avoid loops in shaders if you can help it.
}
}
ENDCG
然后在你的脚本中:
float [] array = new float[] { 0.25f, 0.75f };
material.SetFloatArray("_Segments", array);
material.SetInt("_SegmentsCount", 2);
renderer.material = material;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)