Search Unity

DrawMeshInstanced sorting question

Discussion in 'General Graphics' started by adslitw, Jan 17, 2019.

  1. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    I've got what I think is a perfect candiate for using DrawMeshInstanced - loads of identical transparent background tree billboards. However when I 'convert' the billboard gameobjects to a 4x4 array and use DrawMeshInstanced instead, the depth sorting of the meshes is all screwed up.

    My best guess is that every frame I need to do some sort of sorting on the array in order to draw them in the correct order (based on distance from camera I guess), but that seems like a lot of work? Am I overlooking something, or not using it right, or missing a shader setting, or... something else?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    No, you got it right. You need to sort them yourself. By using DrawMeshInstanced you're effectively telling Unity "hey, I got this" and taking over responsibility for sorting. If you want Unity to handle the sorting just leave the billboarded objects as game objects in the scene with instanced shaders/materials and it'll handle it for you.
     
  3. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    275
    Alright, that's great, thanks!