Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity reorders calls to DrawMeshNow. How can I prevent it?

Discussion in 'General Graphics' started by raja-bala, Jan 14, 2015.

  1. raja-bala

    raja-bala

    Joined:
    Jul 11, 2012
    Posts:
    29
    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 tried setting the tag to various layers (opaque, geometry, transparent, overlay) and still they get reordered.

    I'm clueless on how to go about fixing it. Someone, anyone.. please help me!
     
  2. maxwelldoggums

    maxwelldoggums

    Joined:
    Sep 8, 2008
    Posts:
    157
    To my knowledge, DrawMeshNow does exactly that, it draws the mesh immediately. This means you do have direct control over when the mesh is drawn in the pipeline, but it may not be when you expect it relative to other meshes.

    The steps in the render pipeline follow a standard procedure, ( the details of which can be found here ) however the sorting of individual objects within each step may vary dramatically for performance reasons, and you will not have control over this ordering.

    What do you mean by "Blit doesn't work right with the latter"? I personally haven't used Blit too extensively, but logically it should work at any stage in the render pipeline.

    Worst-case you may be able to use the regular DrawMesh function. That will push your mesh through the standard pipeline, just like any other MeshRenderer.