First, please bear with whatever silly beginner’s misunderstandings from my part, plus that I strongly believe I miss something basic here.
I try to use DrawMesh
in order to create multiple spheres with different material properties by supplying a MaterialPropertyBlock
, but the spheres are rendered with identical material (although they are not dynamically batched). The code is like this:
void Awake()
{
//Where random values are defined for the Transformation matrix, Base color, etc.
}
void Update()
{
if (block == null)
{
block = new MaterialPropertyBlock();
block.SetVectorArray(baseColorId, baseColors);
block.SetFloatArray(metallicId, metallic);
block.SetFloatArray(smoothnessId, smoothness);
}
//Below is my non-working code
for (int j = 0; j < matrices.Length; j++)
{
Graphics.DrawMesh(
mesh, matrices[j], material,
0, null, 0,
block,
ShadowCastingMode.On, true, null,
lightProbeVolume ? LightProbeUsage.UseProxyVolume : LightProbeUsage.CustomProvided,
lightProbeVolume
);
}
}
My understanding is that the for
loop is performing as intended, but the renderer renders all spheres with the properties of the last (I assume) iteration. I skip the rest of the code, which I know it works fine as it is borrowed from a tutorial (catlike coding) with the only difference being that the DrawMeshInstanced
function is used instead. In my case I cannot use the latter due to my system’s gpu.
Do I have to use Coroutines in this case? Any suggestion?