Is there a way to control the rendering order of DrawMeshInstanced? Ideally, I want to render in the order the calls are made from C#. Something like this:
- render instanced meshes with alpha blending OFF and depth writes ON.
- render instanced meshes with alpha blending ON and depth writes OFF.
- render instanced meshes with alpha blending OFF and depth writes ON.
At the moment, it seems random whether the alpha blended meshes are rendered first or not, or at least sometimes the effect works, others not. I guess Unity is deciding the rendering order depending on the states specified in the shader?
Also, where is the best place to call DrawMeshInstanced? In Update or something like OnPreRender?
Still trying to resolve this. Anyone recommend a good way of getting in contact with the Unity devs? Apart from the standard Unity documentation, anyone come across any titbits regarding how DrawMeshInstanced works under the hood?
Hello,
For rendering order, AFAIK only the “Queue” tag written in the shader can control it. You probably need to prepare 3 materials with 3 different shaders to explicitly specify the rendering order.
As for the callback where DrawMeshInstanced could be placed, I’ll go with OnPreCull. That’s the place before all rendering starts, so that the internal renderers created by DrawMeshInstanced will be available to collect for rendering.
Disclaimer: Purely based on my own experience, may not be the best solution.
Works a treat! Using “Geometry+1” etc in the shaders does the trick. Many thanks!
1 Like