There is a new API: Unity - Scripting API: Graphics.RenderMeshIndirect, it’s useful to draw a range of submesh in one drawcall rather than the normal DrawMesh(which only accept one submesh index in one drawcall).
The example shows me that we can pass the localToWorld as a global variable to replace the built-in one.
But I found if I still use unity_ObjectToWorld, then the translation parts is same to the worldBounds’ center passed by RenderParams.
So I think it is reasonable to have an additional Matrix4x4 parameter in RenderParams to allow user set the built-in “unity_ObjectToWorld” and “unity_WorldToObject”, it could also save shader keywords if the shader will be used in non-indirect draw way.
Could it be implemented in future version of Unity?
3 Likes
I was just about to ask a very similar question. I am using DrawProceduralIndirect to draw geometry from graphics buffers. And the built in matrices unity_ObjectToWorld and unity_WorldToObject are not set in the shader. Sure I can set my own matrices as the example but there are problems. Other functions will still use the build in matrices, so if these matrices are not set you will probably have a lot of artifact if you are using a shader that does more than set a color. A workaround is to set these matrices early in the vertex shader but that just feels ugly to assign the same value to the same uniform matrices for each vertex!
e.g.
Varyings LitPassVertex(Attributes input)
{
...
unity_ObjectToWorld = _ObjectToWorld;
unity_WorldToObject = _WorldToObject;
...
}
Trying SetMatrix directly to these matrices doesn’t work as you point out…