Search Unity

Question GPU Instancing low vertex count

Discussion in 'General Graphics' started by opaqe, Feb 14, 2023.

  1. opaqe

    opaqe

    Joined:
    Nov 22, 2014
    Posts:
    8
    I came across this note in the unity docs.

    What Unity API do I use to "create a single buffer that contains mesh information." What would be the recommended method for rendering particles/billboards?
     
  2. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    The recommended method for particles is VFX Graph or Shuriken. VFX Graph can handle millions of particles without breaking a sweat.

    For LOD or tree billboards, unless you have 1,000+ on screen at once just let the rendering system do its thing and don't worry.

    If you want to go down the rabbit hole, the suggested way is probably to get a CommandBuffer, pass some data from your app in a ComputeBuffer, use a ComputeShader to generate vertices, and then call DrawProcedural (or DrawProceduralIndirect) so it's just a single draw call instead of many instanced draws.

    The main use case would be grass, because Unity's terrain grass rendering does not scale, but there are several grass assets that already do this on the asset store with various levels of quality. So it's only worth doing yourself if you want to achieve a particular style/look with your grass (or for learning purposes).
     
    Zyblade likes this.
  3. Furgl

    Furgl

    Joined:
    Jan 6, 2022
    Posts:
    24
    For DrawProcedural and DrawProceduralIndirect, the Unity docs now say:
    RenderPrimitives and RenderPrimitivesIndexed docs both say that they use GPU instancing. Is there a different method that doesn't use GPU instancing that is recommended to render a mesh with a low number of vertices many times?
     
  4. adamgryu

    adamgryu

    Joined:
    Mar 1, 2014
    Posts:
    188
    I'm also curious about this - I just want to draw a lot of quads efficiently, so I'm just looking for some sample code of how to "create a single buffer that contains all the mesh information and use that to draw the meshes", as the GPU Instancing page says to when meshes are less than 256 vertices.
     
  5. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    Use the Mesh class, passing a single vertex/index buffer containing all your individual quad’s data.

    Alternatively, if you’re rendering a lot of instances of the exact same mesh you can use GPU instancing.