shader 如何声明数组_如何在Shader属性中定义浮点数组?

在Unity中,无法直接在Shader属性中定义浮点数组(_TileData1)。尽管可以使用SetFloatArray从脚本中设置数组,但这些数组不会被序列化或显示在材质编辑器中。然而,可以在CGPROGRAM块中定义它们用于计算,并通过MonoBehaviour脚本进行修改。
摘要由CSDN通过智能技术生成

I'd like to define an array of floats in my shader, something like this:

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" {}

}

I'm trying to create a single plane that I'll use as a grid and I want to modify the _TileData1 at run-time to change the Y offset of a tile. I'm using _TilesX and _TilesY to get a 2d position of the tile from a 1d array.

Just to be clear, I just want to find out how to define a property type of float[] since I couldn't find how to do so on Unity's manual pages or forums.

解决方案

Apparently not.

I didn't think so, as I'd never seen it, but I thought I'd take a search around and I ran across this thread where the person answering the question says this (emphasis mine):

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).

So you would be able to use it in the calculation, but you would only be able to modify the value via MonoBehaviour script (and would need to).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值