I’m trying to allow the “_BaseColor” property of the standard URP Lit shader to accept an array of colors in a MaterialPropertyBlock. I’ve made sure the Material has “Enable GPU Instancing” on. Here is what I have:
MaterialPropertyBlock baseMPB = new MaterialPropertyBlock();
Vector4[] _colorsBase = new Vector4[myArray.Length];
for (int index = 0; index < myArray.Length; index++)
{
// Some function that sets _colorsBase vectors
}
baseMPB.SetVectorArray("_BaseColor", _colorsBase);
Graphics.DrawMeshInstanced(myMesh, 0, myMaterial, myTransformsArray, myArray.Length, baseMPB);
However, this only uses the very first color in _colorsBase and does not change colors on subsequent meshes.
I’ve done quite a lot of looking and it seems according to this thread, Color is not setup to be instanced by default.
I don’t have too much experience with ShaderLab nor HLSL so it’s been difficult even trying to figure out where to get started with adding it in. It looks like I have to Copy+Paste both “Lit.Shader” and “LitInput.hlsl” and make changes on those. However, reading through these threads still have me very confused on how to start:
On top of that, taking a look inside LitInput.hlsl seems to include this snippet:
// NOTE: Do not ifdef the properties for dots instancing, but ifdef the actual usage.
// Otherwise you might break CPU-side as property constant-buffer offsets change per variant.
// NOTE: Dots instancing is orthogonal to the constant buffer above.
#ifdef UNITY_DOTS_INSTANCING_ENABLED
UNITY_DOTS_INSTANCING_START(MaterialPropertyMetadata)
UNITY_DOTS_INSTANCED_PROP(float4, _BaseColor)
...
UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata)
#define _BaseColor UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4 , _BaseColor)
...
#endif
Which seems to indicate that there’s already been work done on instancing _BaseColor? Where should I even start for this? I don’t even know when the conversion between Color in Lit.shader and float4 in LitInput.hlsl occurs.