Culling mask for GPU instanced mesh

373 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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);