0

My game has 2 cameras.

I'm instancing a bunch of grass and I want the second camera to not render the grass. How can I do this?

The grass is instanced via DrawMeshInstancedIndirect.

Daniel
  • 7,357
  • 7
  • 32
  • 84
  • camera: If null (default), the mesh will be drawn in all cameras. Otherwise it will be drawn in the given Camera only. – shingo Oct 28 '22 at 04:29
  • Could you elaborate on this? I didn't understand. I have 2 cameras, only one should render the GPU instanced mesh, the other one shouldn't. – Daniel Oct 28 '22 at 05:12
  • 1
    **camera** is an argument of DrawMeshInstancedIndirect, and you should properly set it. – shingo Oct 28 '22 at 05:16
  • Please, write it as an answer so I can properly mark as correct! Didn't know DrawMeshInstancedIndirect had a camera property! Worked perfectly! – Daniel Oct 28 '22 at 07:02

1 Answers1

1

DrawMeshInstancedIndirect has an argument "camera", its description is:

If null (default), the mesh will be drawn in all cameras. Otherwise it will be drawn in the given Camera only.

To draw meshes in a specific camera, just pass this camera instance to the method.

Camera cameraToDraw;

Graphics.DrawMeshInstancedIndirect(
    mesh, 
    submeshIndex,
    material,
    bounds,
    buffer,
    camera: cameraToDraw); 
shingo
  • 18,436
  • 5
  • 23
  • 42