Search Unity

Question How to use CommandBuffer.DrawMeshInstanced()?

Discussion in 'General Graphics' started by inSight01, May 17, 2022.

  1. inSight01

    inSight01

    Joined:
    Apr 18, 2017
    Posts:
    90
    I've been playing around with Graphics.DrawMeshInstanced() and it works nicely. I read a post somewhere that said it's better to use CommandBuffer.DrawMeshInstanced(). It seems to work (no errors, and stat's says it's rendering tris/verts etc) but it's not visibly showing on the screen.

    I'm using a standard material with default shader and GPU Instance enabled. I'm assuming I'm doing something wrong?

    Simplified version of how I'm executing the code.

    Code (CSharp):
    1. commandBuffer.Clear();
    2. commandBuffer.DrawMeshInstanced(mesh, 0, material, -1, matrices, matrices.Length);
    3. Graphics.ExecuteCommandBuffer(commandBuffer);
     
  2. Stormer2020

    Stormer2020

    Joined:
    Sep 14, 2020
    Posts:
    92
    Same issue~
     
  3. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    675
  4. inSight01

    inSight01

    Joined:
    Apr 18, 2017
    Posts:
    90
    This was a while ago now.

    No. All references I've found in regards to using CommandBuffer stated that it can be used just like the Graphics API. There was never a mention of setting the view and projection matrices. That link, however, does mention something rather important.

    This function is compatible with the Built-in Render Pipeline. It is not compatible with the Universal Render Pipeline (URP), the High Definition Render Pipeline (HDRP), or custom Scriptable Render Pipelines.

    I believe I was using URP at the time. I wonder if that was the issue.