Skip to main content
Version: Next (dev)

Foliage Wind

Trees built as foliage composites, or meshes with a Wind Skeleton, carry a small skeleton of bones from the trunk out to the twigs. Every frame a GPU pass moves each bone of each tree as a damped spring, pulled toward the bend that the wind and touch ask for at that bone. The material then moves each vertex with its bone. Because the bend of every bone is limited, the renderer knows at build time how far any vertex can move, so culling stays exact while the tree sways.

The wind comes from the scene's wind system: a Simple Wind component sets the base wind and gusts, and wind volumes add local wind. See Wind.

Setting up a tree for wind​

  1. Put a Foliage Bones component (category Effects > Wind) on the object with the tree's mesh component. Dragging a Foliage Composite asset into a scene adds it for you. The component has no properties; it does nothing for meshes without a skeleton.
  2. Give the mesh materials that apply bone wind (see below).
  3. Make sure the scene has a wind system, for example a Simple Wind component.

Material setup​

Bone wind is applied by the Vegetation shader (Shaders/Materials/Vegetation.plShader) when its USE_FOLIAGE_BONES option is on. Base your bark and leaf materials on the Vegetation base material and turn USE_FOLIAGE_BONES on. Materials with any other shader draw the tree in its rest pose.

The Vegetation shader also has a Wind group of per-vertex settings (bend stiffness, branch and edge flutter). These drive the older per-vertex wind for meshes without a skeleton.

Touch and shockwaves​

Bones also bend away from things that push into the plant:

  • Touch. Characters, vehicles and physics bodies splat a push into a camera-centred touch map, which decays over time. Bones bend away from the push at their tips. With the plasma.vegetation package, add a Vegetation Touch component to anything that should push plants, and dynamic physics bodies push them too. Touch sources can be spheres or capsules (a body lying down, a log, the side of a vehicle).
  • Shockwaves. A shockwave is a wind volume. Because bones sample the wind field, a sphere wind volume bursting next to a tree bends it away from the centre.

Distance tiers​

Simulating every tree in a forest every frame is not needed:

  • Frozen tier. Trees further than Vegetation.Bones.AnimationDistance (200 m) from the wind focus, the main camera, ease back to rest and hold it. Their shadows can then stay cached in the virtual shadow map.
  • Shared wind variants (with plasma.vegetation). Trees of one type in a vegetation layer share a few wind-animated variants per wind tile, which differ in phase and stiffness. Each drawn tree borrows one, so a forest of thousands of trees runs only a few simulations per type and tile.
  • Own simulation near the camera. A tree near the camera, touched or pinned, gets its own bone instance at its real position. It starts bent as its variant showed it and simulates with the variant's wind sample point, stiffness and phase at first, then moves to its own over Vegetation.Composite.ControlBlendTime. It moves back before it rejoins the variant, so the hand-off does not pop.

A bamboo stem in wind as the camera approaches from 57 m to 17 m. Top row, without the hand-off: the stem straightens when it gets its own simulation. Bottom row, with Vegetation.Composite.ControlHandOff: it keeps the variant's bend and moves to its own smoothly

CVars​

Bone wind (engine):

CVarDefaultDescription
Vegetation.Bones.EnabledonAnimates foliage with its bone skeleton. Off holds every tree in its rest pose.
Vegetation.Bones.AnimationDistance200Foliage further than this many metres from the wind focus (main camera) stops animating and rests.
Vegetation.Bones.WindScale1Multiplier on the wind the bones feel.
Vegetation.Bones.TouchScale1Multiplier on the touch push the bones feel.
Vegetation.Bones.Damping0.35Damping ratio of the bone springs: 0 never settles, 1 is critically damped.
Vegetation.Bones.FixedTimeStep0When above 0, the bones advance by this many seconds per frame instead of the frame time. For tests and captures.
Vegetation.Touch.EnabledonAdvances the touch map each frame. Off leaves plants unbent by characters.
Vegetation.Touch.MapExtent64Size in metres of the touch map around the main camera.
Wind.Debug.PinTime-1When 0 or more, the wind field, the per-vertex wind and the bones use this time every frame. For comparing captures.

Shared variants (plasma.vegetation package):

CVarDefaultDescription
Vegetation.Composite.WindTileSize256Side in metres of the square tiles whose trees of one type share wind variants.
Vegetation.Composite.WindVariants8Shared wind variants per composite type and tile, 1 to 32.
Vegetation.Composite.PromoteRadius25Trees this close to the main camera get their own bone instance. 0 = only touched or pinned trees.
Vegetation.Composite.BlendTime0.5Seconds a tree takes to blend between its variant's pose and its own.
Vegetation.Composite.DemoteDelay2Seconds a tree must go without a touch, the camera nearby or a pin before it blends back to its variant.
Vegetation.Composite.ControlHandOffonA promoted tree starts bent with its variant's wind control and then moves to its own. Off, it starts unbent with its own at once.
Vegetation.Composite.ControlBlendTime1.5Seconds the wind control takes to move between the variant's and the tree's own. Keep it below DemoteDelay.
Vegetation.Touch.PhysicsonDynamic physics bodies and characters inside the touch map bend vegetation.
Vegetation.Touch.MaxPhysicsSources32Most physics bodies that bend vegetation per frame, nearest to the camera first.

Troubleshooting​

ProblemCause and fix
The tree stands stillCheck for a Foliage Bones component, a mesh with a skeleton (a Foliage Composite, or a mesh with Wind Skeleton set), materials with USE_FOLIAGE_BONES, and a wind system in the scene.
Distant trees stop movingThey are past Vegetation.Bones.AnimationDistance. Raise it if far trees must move, at the cost of shadow caching.
A tree jumps when the camera comes closeThe hand-off to its own simulation is off (Vegetation.Composite.ControlHandOff), or ControlBlendTime is longer than DemoteDelay.
Shading does not change as branches bendBone wind moves positions only; normals stay in the rest pose.

See Also​