Stylized Grass Shader
The grass shader is what must be set on a material. In turn, the material can be applied to a grass mesh.
It features two primary shading modes. These are akin to the Simple Lit and Lit UniveralRP materials. You should choose either one, depending on the shading features you intend to use in your project.
- Plain grass color
- Lambert shading (same as Legacy/Unity 4 shaders)
- Per pixel color map
- Point and spot lights (per object)
- Physically-based shading
- Point and spot lights (per pixel/vertex)
- Global Illumination
- Environment reflections
- Light Probes
This functionality bends the grass away from the camera as it starts to look straight down. It will help to create the illusion of dense grass coverage.
No set up for this is required, but the strength of the effect has to be set on the grass material, under the “Vertices” tab. By default it is set to 0.
The “Billboard” toggle will rotate the mesh towards the camera on the XZ axis. When using this, the mesh requires to use the “GrassBillboardQuad” mesh. This is essentially a quad with the pivot point at the bottom, and the top vertices have vertex colors (required for the animations to work). The “GrassBillboard” prefab is already set up with the correct mesh and a material with billboarding enabled.
Important to note: The prefabs should have a Y-rotation of 0. This is because the shader will rotate the mesh. If the prefabs have a random rotation, billboarding will not behave correctly.
The shader does not use any multi-compile keywords. It does use them for URP features (like the Lit shader does), this means potentially 20K shader variants will be compiled for the first build. In Unity 2020.2 improved shader stripping was introduced, meaning no variants will be created for URP features not in use. For example, if shadows are enabled in every pipeline asset in the project, a variant without shadows will never be compiled.
You may see up to 4000-6000 shader variants being compiled when building, this is quite normal. Any subsequent builds will be much faster, since the compiled shaders will be cached.
As of version 1.1.7 a build pre-processor script is included, this will remove any shader variants for features that belong to a higher URP version (eg. decals in Unity 2021.2). This will ensure build times are as fast as they should be. The stripping process may take up to 2 minutes, depending on which Unity version you’re using.