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

Question DrawMeshInstanced API

Discussion in 'Graphics for ECS' started by Krajca, May 26, 2021.

  1. Krajca

    Krajca

    Joined:
    May 6, 2014
    Posts:
    347
    Do DrawMesh and DrawMeshInstanced need custom culling and/or custom drawing order? And how to achieve it?

    EDIT. Let me rephrase that. I know I need custom frustum culling, wanted only confirmation it's the case. Sorting order is a confusing one. All samples I found had only sorting of drawn objects. What about sorting against the rest of objects? What about depth culling?
     
    Last edited: May 27, 2021
  2. SebastianAaltonen

    SebastianAaltonen

    Unity Technologies

    Joined:
    Feb 21, 2020
    Posts:
    112
    If you use DrawMeshInstanced, you need to manually cull all instances. There's no automatic culling for instances. You also need to sort manually.

    You can't sort instanced draw calls against other objects, since instanced draw call is a single GPU operation. If you need to sort globally, then you need to sort everything first and then construct instanced draw calls after sorting, if you have compatible meshes/materials next to each other after sorting. This is a common limitation in GPU instanced draw calls, and not unique to Unity's implementation.
     
  3. Krajca

    Krajca

    Joined:
    May 6, 2014
    Posts:
    347
    So basically I should sort everything out and then find clumps of objects I want to instantiate?
    Does rendering keep material render queue so it will be depth sorted in that case?
     
  4. SebastianAaltonen

    SebastianAaltonen

    Unity Technologies

    Joined:
    Feb 21, 2020
    Posts:
    112
    If you want full global sorting across all instanced draw calls, you need to depth sort the instances yourself.
     
  5. Krajca

    Krajca

    Joined:
    May 6, 2014
    Posts:
    347
    But I need to sort only that batch I want to draw? Disregarding everything else?
    That's the part I don't understand. i.e.
    I have like 100 enemies across my scene. When instancing, will all my meshes will be drawn on top/below of everything else, or the only sorting I need to care of is that inside of the batch?