Stylized Grass Shader Documentation

Stylized Grass Shader

Stylized Grass Shader
Version: 1.3.0
Review

6.Using grass bending #

The shader is paired with a system to flatten and/or bend the grass through meshes, trails or particle effects. This can be previewed in the “BendingDemo” scene.

Setup

1. Render feature

 

Add the “Grass Bending Feature” render pipeline to the renderer in use

Alternatively: Create an empty GameObject and go to Add Component -> Stylized Grass -> Stylized Grass Renderer. 

Click “Add” if the error appears.

All done!

With the component selected, you’ll notice a white box around the scene-view camera. This represents the area in which bending is processed.

2. Grass Benders

Bending can be performed through 3D shapes as represented by meshes, trails or particle effects. Their shape and position is translated to the shader on the GPU, so no actual physics calculations are being used. This is done through the “Grass Bender” component. It can be added to these types of renderers

  • Mesh Renderer
  • Trail Renderer
  • Line Renderer
  • Particle System

You can easily convert a renderer to a Grass Bender by opening the context menu on any Mesh Filter, Trail Renderer or Particle System component.

After which, a Grass Bender component will be added to the object

Move it around in scene-view, and you’ll see it taking effect on the grass placed in the scene.

 

You can create meshes, or trail renders as a child of your player object so it’ll follow it. It is recommended to create a sphere at the feet of the player, so grass always bends where it stands. Next to using a trail so the grass bends behind it when it moves. In any case, you can disable the renderer so the actual mesh isn’t visible to the camera, it’ll still be visible to the bending renderer.

In the Prefabs/Benders folder you can find several pre-configured prefabs for this purpose.

Inspiration:

  • For a explosion particle effect, create a sub-particle system using a sphere and roughly the same lifetime. When it fires, the grass will appear to bend away by the force of the explosion
  • For ragdolls, create capsules for all the limbs and torso. When they are thrown to the ground, the grass will appear to be flattened by the body.

Limitations

Particle effects must use 3D meshes instead of flat billboards. To do so, go to the Particle System’s “Renderer” section and set the ‘Render Mode’ to ‘Mesh’, next assign a mesh, such as a sphere. You can disable the Renderer component, so it’s invisible to the game camera.

With Unity’s TrailRenderer component. Trails retract at the same speed as they extend. Fast movement will cause the grass to also spring back rapidly. If a trail is not moving, its lifetime also doesn’t decrease.

The “BendTrailParticles” prefab is an alternative example of using a particle system to leave a trail of bent grass.

Yes No Suggest edit
Last updated on August 6, 2022
3 of 3 users found this section helpful
Suggest Edit