S&box Wiki

Foliage Shader

Procedural Wind Animation

foliage2.gif

The foliage shader supports procedural wind animation using vertex colors, to turn it on look for this feature in the material editor:

image.png

Vertex Color

image.png

The intensity and variation of foliage movements are defined by each RGB channel in vertex colors as follows:

Red channel: used for animation of smaller or peripheral parts of vegetation (leaves). Bright parts are animated, and dark parts are stiff.

Green channel: which parts of branches can be bent, brighter parts indicate bendable portions and dark parts stiff portions.

Blue channel: used for per-leaf phase variation - this is to de-synchronize the movement of different leaves. This should match across entire leaves.

After you turn on foliage animation on the material, the model will need to be force recompiled - this will make sure the vertex color stream gets baked into the compiled model.

Material Parameters

image.png
  • Branch Amplitude: How much the branches bend (multiplied by the green channel)
  • Branch Frequency: How frequently the branches bend (multiplied by the wind speed)
  • Edge Amplitude: How much the leaves flutter (multiplied by the red channel)
  • Edge Frequency: How frequently the leaves flutter (multiplied by the wind speed)
  • Trunk Deflection: A scale factor of how much the tree bends with the wind
  • Trunk Deflection Start: The height at which the tree begins to bend from

Global Wind Parameters

Currently wind speed and direction is controlled by the following convars:

  • r_world_wind_strength - default: 40.0
  • r_world_wind_dir - default: 0.707 0.707 0.0

This will change in the near future to be game / map configurable.