How it Works
GPU Grass places and renders objects on the GPU based on masks.
6 masks are generated per terrain.
- Terrain Color
- Terrain Layer
- Collision Mask
3 masks are generated per object type.
These masks are generated in the editor and updated when something changes. They are packed into textures and sent to the GPU.
These 3 steps happen every frame on the GPU.
Step 1: Placement
Positions are generated in a compute shader.
- GPU Grass uses either random values or blue noise to generate positions.
- Positions are filtered based on the placement mask.
- Positions are sorted into LODs.
Step 2: Culling
- Positons are culled using the camera's frustum.
Step 3: Rendering
- Objects are rendered using Graphics.DrawMeshInstancedIndirect
- Scale, rotation and other data is calculated in the shader based on masks.