gpt4 book ai didi

unity3d - 如何在Shader属性中定义 float 组?

转载 作者:行者123 更新时间:2023-12-04 22:56:13 25 4
gpt4 key购买 nike

我想在我的着色器中定义一个浮点数数组,如下所示:

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的手册页或论坛上找不到该类型。

最佳答案

显然不是。
我没有这样想,因为我从未见过,但我想我会四处搜寻,然后碰到this thread,回答问题的人这样说(强调我的意思):

You can set arrays from script using SetFloatArray, SetVectorArray, and SetColorArray as of 5.4, but you can't define an array in the properties. Basically this means you can still set the value and have it defined in the CGPROGRAM block to be used, but it won't be serialized / saved by the material asset or show up in the material editor. It's an odd omission, especially since texture arrays are supported as properties (though texture arrays are a specific type of texture sampler rather than an array of texture properties like color arrays).


因此,您可以在计算中使用它,但是您只能通过MonoBehaviour脚本修改该值(并且需要这样做)。

关于unity3d - 如何在Shader属性中定义 float 组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45098671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com