I am writing a custom shader under URP with SRP Batcher enabled.
I want to declare a vector array property, say “_Colors”:
half4 _Colors[8];
and in order to make this shader SRP Batcher compatible:
CBUFFER_START(UnityPerMaterial)
half4 _Colors[8];
CBUFFER_END
But now I have no idea to declare it in Properties
block, because there is no Array
type similar to Vector
or Color
. As a result, this shader will not be SRP Batcher compatible
Besides, I have tried some ways and found something interesting:
- If a uniform variable in
UnityPerMaterial
CBuffer has aArray
type, and a property declared inProperties
block with same name, whatever its type is, SRP Batcher will feel satisfied. (tested by attachmented TestSRPBatcherCompatibilityWithArrayVariable.shader) - If a uniform variable in
UnityPerMaterial
CBuffer has aMatrix
type, and no property declared inProperties
block with same name, SRP Batcher will feel satisfied. (tested by attachmented TestSRPBatcherCompatibilityWithArrayVariable.shader)
All above are so confused to me.
(All my attachmented shaders are tested under Unity 2019.4.29f1 with URP 7.4.1, on a Windows PC.)
7452779–914441–TestSRPBatcherCompatibilityWithArrayVariable.shader (1.63 KB)
7452779–914444–TestSRPBatcherCompatibilityWithMatrixVariable.shader (1.51 KB)