I have a couple questions about the DrawMeshInstanced API.
My questions are:
Does DrawMeshInstanced improve performance over MeshRenderer (with an InstancedShader) when hundreds of GameObjects are used for Colliders and Rigid Bodies, but their rendering is done using DrawMeshInstanced?
Secondly When using Color as an Instanced property in the DrawMeshInstanced array, which Type should we be using in MaterialPropertyBlock’s SetTypeArray API? Why no SetColorArray?
Lastly, when using DrawMeshInstanced and MaterialPropertyBlock’s SetTypeArray APIs, how do we know which index into the array will be used for each Instance of the Mesh? - I’m under the assumption that if we want to draw 1000 colored cubes using DrawMeshInstanced then we need to populate the MaterialPropertyBlock with 1000 colors, even if 900 of those colors are the same. Is this accurate?
The biggest advantage I saw switching from a MeshRenderer on GameObjects to using DrawMeshInstanced was that Unity finally instanced everything consistently. With a MeshRenderer and an InstancedShader in Unity 5.4, I was seeing instancing groups of 2-7 with an occasional group of 100 or so. With DrawMeshInstanced, I can force Unity to instance 500 at a time. The difference in draw calls is massive. In my game, I have thousands of lasers flying around. When I switched to DrawMeshInstanced, I removed over 1000 draw calls and massively increased the frame rate.
I cannot answer your MaterialPropertyBlock question, because I am not doing anything with that. In my game, I just set up the MaterialPropertyBlock and leave it empty. I did not need to apply any per instance parameters.
Yes. I run separate instancing pools for each type, grouping, and color of laser. The red and blue lasers use different materials but the same shader. Every projectile within one instancing group is the same with no color differences. The red and blue lasers use different instancing pools.
I even have custom instancing pools for prebaked groupings of projectiles, such as large triple blue lasers fired from heavy turrets on certain battleships. For that example, one draw call covers 500 prebaked instances with 3 large blue lasers per instance, so I can get 1500 lasers in a single draw call that way. It is more work initially to set it up that way, but it offers the best scalability for my use case.