Stylized Grass Shader Documentation

Stylized Grass Shader

Stylized Grass Shader
Author: jonathan
Version: 1.0.8
Dated: 31 Aug 2019

4.Placing grass #

There are several methods to populate a terrain with grass in Unity, this section outlines them and their (dis)advantages. The package does not contain any tools to achieve this, as it focused on providing a grass shader. Such tools and systems should be considered entirely separate.

While the shader has been written to be as efficient as possible, the method used for rendering grass meshes will greatly determine how and where performance will be affected.

Unity terrain vegetation system

This is arguably the most accessible method, and does not require any third-party tools. However, it is important to understand that the grass/detail object system does not support meshes with custom shaders. To get around this, add a grass prefab as a “tree” instead.

If you’re using navmeshes then this method is not advised, since trees placed through the terrain system are automatically marked as navmesh obstacles. Meaning that navmesh agents won’t able to navigate through grass (placed as trees).

The Unity vegetation system hasn’t been updated in a long time, and is no longer up to modern standards. It won’t deliver high performance when grass is placed in large amounts.

There is currently a bug in the URP that causes shadows flicker when using either the Distance Fading or Perspective Correction feature, in conjunction with the terrain vegetation system. A bug report has already been filed. If this affects you, please place a vote, which will bump up its priority: https://issuetracker.unity3d.com/product/unity/issues/guid/1215610

Pros:

  • No need for 3rd party tools

Cons:

  • Not optimized for dense grass
  • Grass can’t align to terrain surface
  • Requires manual painting (tools like MapMagic and Gaia could handle placement)
  • Cannot be used with navmeshes
  • No options for random scale, rotation or density
  • Questionable compatibility with Global Illumination or Light Probes
  • Changes to materials won’t apply unless the “tree” prefab is refreshed

Placing grass as GameObjects

By dragging a grass prefab into the scene you’ll have full control over it, just like any other object. It goes without saying that placing a piece grass one by one is not going to be fun. For this reason you can use any prefab painting tool, such as PolyBrush.

Note that populating a scene with a large amount of individual GameObjects will increased CPU load, scene file size and loading times. So the amount of grass you can place is limited by how much performance legroom your project already has in this area. The shader uses GPU Instancing, so drawcalls in any case will fortunately be limited.

Pros:

  • Easy to manage to like any other GameObject
  • Material changes are directly visible
  • Meshes can be used with Occlusion Culling
  • Control over shadow casting

Cons:

  • Requires a third-party painting tool (free or paid)
  • Has to be manually placed or painted
  • Requires CPU resources for maintaining the individual GameObjects

Nature Renderer

Nature Renderer uses the terrain’s tree and details data, but renders everything using its own system. It allows you to use the terrain vegetation system as you would normally, but get all the modern rendering methods required for high amounts of vegetation (GPU instancing, cell-based and frustrum culling). As a result, this would work with other systems that spawn grass on terrain such as Gaia or Map Magic.

Pros:

  • No change in workflow
  • Renders large amounts of grass at relatively fast speed
  • Material changes are directly visible
  • Aligns grass to terrain surface
  • Stylized Grass supports its wind controller

Cons:

  • Requires an additional purchase

Vegetation Studio + Pro

This would be the silver bullet. Vegetation Studio is a system that utilizes GPU Instancing to draw identical meshes in only a few draw calls. It also performs frustum culling, to only render what’s visible in the camera field. It does not use any GameObjects, the grass is purely stored in memory. Additionally, it provides a powerful rule-based system for spawning grass.

The grass shader is compatible with its Instanced Indirect rendering, which enables more than 1023 items to render 1 draw call, next to GPU-powered culling.

Pros:

  • Renders large amounts of grass at relatively fast speed
  • Procedural rule-based placement of grass (in addition granular manual control)
  • Fast control over density and scale/rotation/alignment
  • Support for placement on meshes
  • Integrated material controlled when selecting a grass item

Cons:

  • Requires an additional purchase

Tips and tricks

  • Individual grass objects should be rotated randomly on the Y axis between 0-180º. This greatly reduces visual repetition.
  • Scaling the objects randomly between 80-120% is also advised for the same reason.
  • Align the grass to the surface it is placed on. This will help with translating lighting, especially on hills.
  • Disabling shadow casting for the grass will greatly improved performance, consider going in that direction as a style choice. Using contact shadows is highly recommended as an alternative (not for URP, unfortunately)

Note: uNature is not compatible, as this only works with their own shaders.

If you’re the developer of a grass rendering/placement system and would like to validate compatibility, please get in touch!

Yes No Suggest edit
Last updated on May 9, 2020
3 of 3 users found this section helpful
Suggest Edit