Home

Awesome

Unity Grass Instancer

Contains C# scripts and shaders for GPU instanced grass (or any other mesh)

Made with Unity 2020.3.4f1 and HDRP 10.4.0

Also tested with Unity 2022.3.40f1 and URP 14.0.11

Alt text

Video showcase: https://www.youtube.com/watch?v=3SGxhRqzCm8

Project contains 5 approaches

(Performance increases every step)

Requirements

Material GPU instancing setting

Setup

Important settings

Note: some settings don't apply to all approaches.

FAQ

Why can't I see any instances?

This can have numerous reasons.

First be sure to check the requirements and setup sections. Make sure the mesh is scaled correctly.

Adjust the scale factor in the import settings to your needs or use 100 if you are using the provided 3D model.

Your mesh could also be not placed or rotated correctly:

Why are all instances invisible or black?

This may happend, because you're placing the objects with the material by hand. This does not work because the shader needs and instance ID which is only provided by calling DrawMeshInstanced and DrawMeshinstancedIndirect for rendering. Also the _trsBuffer which contains all the data for the instances is only initialized at start and it's needed for rendering.

Another reason could be that the shader is not compatible with your render pipeline. I currently only provide a shader for URP and a shadergraph for HDRP. The HDRP shadergraph only works with Unity 2021.2 or higher since the instance ID node does not exist in earlier versions.

If you have more issues, please open an issue here on Github.

What's next/TODOs

Resources

Glossary (terms I often use)