- Home /
Prevent Unity from reordering DrawMeshNow calls
I was under the impression that using DrawMeshNow
gives me complete control over the order of draw call submissions in Unity. After a gazillion hours of debug, I've realized that isn't the case.
I call DrawMeshNow
from OnPostRender
(and not OnRenderObject
because Blit
doesn't work right with the latter).
My shader originally had Tag = "Transparent"
, and I thought that was the problem. Didn't fix it. Removed the blend state in my shader. Didn't fix it. Recreated the material (to avoid stale stuff from the previous one) -- no luck.
Unity doesn't just reverse the order. That'd be easy to work around. I've seen (using Intel GPA) my submitted order of 1,2,3 being rendered as 3,1,2.
I'm clueless on how to go about fixing it. Someone, anyone.. please help me!
Answer by raja-bala · Jan 14, 2015 at 08:01 PM
Figured it out. It was a single line of misplaced code that created the havoc.
myMat.SetPass(0);
needs to be called AFTER all the material properties are set, just prior to DrawMeshNow
.
i.e,
for(int ii = 0; ii < 5; ii++) {
myMat.SetInt("_OrderIndex", ii);
myMat.SetPass(0); // this has to be AFTER all properties are set
Graphics.DrawMeshNow(myMesh, meshPos[ii], meshRot[ii]);
}
Your answer
Follow this Question
Related Questions
Writing to RWTexture3D using a pixel shader without using Graphics.Blit 0 Answers
Shadow Support in Custom Shader 0 Answers
materials visible if seen by (1) all or (2) any camera(s) 0 Answers
Shader compiler: internal error compiling shader snippet type=0 platform=0: 1 Answer
How to render OnPostRender with other custom post process render filters. 0 Answers