Patrick Ryan's profile

Vegetation Shader

This shader is an expansion of the vegetation shader example from the Shader Forge plug-in for Unity. I started with the example formula for vertex displacement, sin((blue channel x Pi) + time) x amplitude x red channel x (normalized(vector3 + perterbed normal)), and modified both the vertex displacement formula and the control over the diffuse and specular contributions. Below you can see the comparison of the three versions of the shader.
From left to right: the original Shader Forge vegetation shader, the first revision to add control over diffuse color, add specular and gloss maps, and give control over the specular and gloss power, and the final revision adding a tip blend control for both color and intensity within the diffuse map.
Once the specular and gloss maps were added as well as controls to set power for each, I added the ability to change the tip color of the vegetation as controlled through vertex color. As the vertex displacement was using the red and blue channels of each vertex, I used the green channel and added .5 green to the vertices around the end of each leaf cluster. This allowed me to use the blend from the green channel as a mask to overlay another color for the tip with controls for hue and intensity.
The final vegetation shader compared with the original mesh showing vertex color used for masking both diffuse color and vertex displacement. 
Below is the final shader node tree from Shader Forge as well as the controls portion available through the inspector in Unity. The shader takes into account transmission of light through the leaves, ambient light in the scene, controls for wind direction, amplitude level, and the force of the wind.
And finally the shaders in motion. With the controls for amplitude, wind direction, and wind power available in the inspector, multiple materials can be made with slight differences in these variables to ensure that plants near each other don't mirror motion. Another reason for this control is the same plant mesh can be duplicated and rotated to break up the repetition of shape and still be able to change the wind direction to match the neighboring meshes and create a consistent feel.
Vegetation Shader
Published:

Vegetation Shader

Vertex displacement and texture map control

Published: