DrawMeshInstanced in command buffer not working

Hi,

I’m rendering into multiple render targets using a command buffer, which works perfectly fine with the code below. However, when I replace DrawMesh with DrawMeshInstanced, nothing is drawn even in this very simple example.

commandBuffer.SetRenderTarget(multipleRenderTargets, BuiltinRenderTextureType.CameraTarget);

if (DrawInstanced)
{
    Matrix4x4[] matrix = new Matrix4x4[] { testObject.transform.localToWorldMatrix };
    commandBuffer.DrawMeshInstanced(mesh, 0, mat, 0, matrix);
}
else
{
    commandBuffer.DrawMesh(mesh, testObject.transform.localToWorldMatrix, mat, 0, 0);
}

Does instanced drawing simply not work with multiple render targets, or am I doing something wrong?

Thanks
Daerst

// EDIT: Tried with 5.5.0b7 and 5.5.0b11.

I can’t get it to work for a single RenderTarget either. If you set only a single target in the above code, it still works with DrawMesh and still doesn’t with DrawMeshInstanced. What am I doing wrong?

Hey Daerst,

Do you use a shader modified for instancing for the material being passed to DrawMeshInstanced? It requires such a shader to work (check out Unity - Manual: GPU instancing).

Hey zeroyao,

huh! You’re right, I tried a custom one and the Standard shader, neither of which were ready for Instancing. I’ll try fixing my shader :slight_smile: Thanks!

For anyone wondering why DrawMeshInstanced only accepts a single MaterialPropertyBlock:

Cheers
Daerst