Search Unity

What is the purpose of the submeshIndex parameter of Graphics.DrawMeshInstancedIndirect?

Discussion in 'General Graphics' started by DeltaPiSystems, Sep 12, 2019.

  1. DeltaPiSystems

    DeltaPiSystems

    Joined:
    Jul 26, 2019
    Posts:
    30
    I took the sample from the documentation page and applied a mesh with multiple submeshes to it.

    As I was reading the code I noticed that the vertices/indices of the submesh that gets drawn is defined in the bufferWithArgs.

    Naturally I decided to set the submeshIndex parameter to 0 and see what happened when I changed the submesh index of the example script to 1.

    Everything worked just fine!

    So what's up with that parameter?
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Indeed its usage is very subtle :)

    This got asked before, due to how it seems to be useless. From memory, I think it is only important in the very rare case where 2 submeshes have different topologies (lines, triangles, etc). In this case, Unity would submit the draw call with the wrong topology if the submesh index was not specified correctly.
     
  3. DeltaPiSystems

    DeltaPiSystems

    Joined:
    Jul 26, 2019
    Posts:
    30
    Ah that makes perfect sense, thank you :)

    Edit:
    Maybe it would make sense to clarify such a thing in the documentation?
     
  4. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Good point - Done :)