WindEffect
A deck.gl effect that sets one wind for the whole scene. Every
TreeLayer in the deck bends with it, wood, foliage and crops alike, in
the same direction and on the same clock, as LightingEffect lights every lit layer.
WindExtension brings deck.gl's own instanced 3D layers into the same wind.
See it in the Wind Garden example.
import {Deck} from '@deck.gl/core';
import {TreeLayer} from '@deck.gl-community/layers/tree-layers';
import {WindEffect} from '@deck.gl-community/layers/wind-layers/wind-effect';
new Deck({
effects: [new WindEffect({speed: 6, direction: 90, gust: 0.4})],
layers: [new TreeLayer({id: 'orchard', data: trees}), new TreeLayer({id: 'hedge', data: hedge})]
});
To change the wind, pass a new instance. deck.gl keeps the registered effect and gives it the new
props, as it does for LightingEffect.
Properties
| Property | Default | Description |
|---|---|---|
speed | null | Wind speed in m/s at the 10 m reference height. Without strength, it sets the bend through getWindStrength. |
strength | null | Bend as a fraction of object height. Wins over speed. With neither, the bend is 0.025, a gentle breeze; 0 is still air. |
direction | ≈65.8 | Compass bearing the wind blows toward, in degrees clockwise from north. Set null for isotropic sway on trees. |
gust | 0 | 0–1. Slow swell: strength (and speed) varies between × (1 − gust) and × (1 + gust). |
turbulence | 1 | Scale of the crown, branch and leaf motion. 0 leaves a pure bend. |
shear | 1/7 | Exponent of the height profile v(z) = v₁₀ (z / 10)^shear, used by getWindVelocity. About 0.25 over a city or an orchard. |
time | null | Wind clock in seconds. null follows deck.gl's animation timeline; a number freezes the pose; a function () => number is an app-owned clock. |
effect.strength is the resolved bend: strength, else the response to speed, else 0.025.
One wind per deck
Wind is deck-wide: layers have no strength or clock of their own. Every part of every tree bends
with the effect, and layers are still without one. To keep one layer still in a windy scene, such
as a sheltered courtyard, set windEnabled: false on it, as shadowEnabled: false opts a layer
out of shadows.
| Layer | Opt out | Per object |
|---|---|---|
TreeLayer | windEnabled: false | None: every tree bends alike. |
WindExtension layers | Remove the extension. | getWind [height, phase, flex]: bend height, phase and flex; flex 0 is rigid. |
Standalone SplatLayer renders wind-independent Gaussian assets.
For repeatable screenshots and tests, give the effect a fixed time.
Rendering
TreeLayer uses its native photoreal tree shaders on WebGL2 and WebGPU. Moving gust fronts
bend the wood, carry the crops and foliage, and drive leaf flutter and storm motion. Trees
read the scene's resolved strength, direction and clock. The native tree shader computes
its own spatial gusts. The effect's gust and turbulence settings control the
WindExtension shader.
Shadows and picking use the same tree pose as visible geometry. A timeline-driven wind requests redraws while it is active. A fixed time freezes its pose.
A time callback hands frame scheduling to the app, as in a weather scene that animates with
_animate and pauses when hidden: wind layers read the callback on every draw but request no
redraws of their own.
let time = 0;
const wind = new WindEffect({speed: 6, direction: 120, time: () => time});
// The app advances `time` and redraws; trees, rain and clouds share the clock.
Other layers can read the wind through the exported wind shader module, whose props the effect
supplies through getShaderModuleProps.
Physical wind
The helpers below are pure functions with no deck.gl dependency. They take a plain
{speed, direction, gust, shear} object, so wind.props works as is.
getWindStrength
getWindStrength(speed: number): number
The vegetation response curve: 0.025 × (speed / 5)^1.4, capped at 0.2. 5 m/s gives 0.025,
6 m/s 0.032, a 15 m/s gale 0.12; the cap is reached near 22 m/s. The exponent below 2 reflects
flexible crowns streamlining as the wind grows.
getWindVelocity
getWindVelocity(wind, height: number, time?: number): [east, north]
Air velocity in m/s at height metres, on the power-law profile v(z) = v₁₀ (z / 10)^shear, with
the same gust swell used by the extension. Use it for particles and clouds that move with the wind.
Without speed, the air is still.
getWindDisplacement
getWindDisplacement(wind, height: number, time?: number): [east, north]
The distance in metres the air has travelled since time 0: the exact integral of
getWindVelocity, gusts included. An offset built on it, for example for rain, stays continuous
through gusts, where velocity × time would jump.
import {getWindDisplacement, getWindVelocity} from '@deck.gl-community/layers/wind-layers/wind-effect';
const clouds = getWindVelocity(wind.props, 1500, time); // m/s
const rainOffset = getWindDisplacement(wind.props, 225, time); // metres
Wind from station data
The effect can take its speed and direction from measurements. Sample a geo-layers WindField at
the scene's centre and pass the result to the effect:
import {sampleWindField} from '@deck.gl-community/layers/wind-layers';
import {TreeLayer} from '@deck.gl-community/layers/tree-layers';
import {WindEffect} from '@deck.gl-community/layers/wind-layers/wind-effect';
// WindSample.direction is the direction of travel, counterclockwise radians from east.
const toBearing = (radians: number) => (((90 - (radians * 180) / Math.PI) % 360) + 360) % 360;
const sample = sampleWindField(field, orchardCenter, forecastFrame)!;
new Deck({
effects: [new WindEffect({speed: sample.speed, direction: toBearing(sample.direction)})],
layers: [new TreeLayer({data: trees})]
});
@deck.gl-community/layers/wind-layers draws WindSample.direction as the way the air moves: its arrows
point and its particles travel along (cos, sin) of it. That is WindEffect's convention too,
apart from the angle units. Station data that reports where the wind comes from needs another
180°.
WindExtension
The extension bends deck.gl's instanced 3D layers using the scene's WindEffect strength,
bearing and clock. TreeLayer handles wind in its native shaders.
import {SimpleMeshLayer} from '@deck.gl/mesh-layers';
import {WindExtension} from '@deck.gl-community/layers/wind-layers/wind-effect';
new SimpleMeshLayer({
data: reeds,
mesh,
getPosition: d => d.position,
extensions: [new WindExtension()],
getWind: d => [d.height, d.phase, 3]
});
| Layer | windBase |
|---|---|
SimpleMeshLayer, ScenegraphLayer | 'instance': height above each object's anchor |
ColumnLayer, GridCellLayer | 'instance' |
PointCloudLayer | 'ground': each point's height above z = 0 |
| Property | Default | Description |
|---|---|---|
getWind | [10, index × golden angle, 1] | Per-object [height, phase, flex]: the bend reaches full strength at height metres above the base, phase (radians) offsets its sway, flex multiplies its strength. |
windBase | 'instance' | 'instance' bends from each object's anchor; 'ground' from z = 0, for point clouds. |
The extension is WebGL2 only: deck.gl's WGSL layers have no vertex filter hook, so on WebGPU it
leaves the layer unchanged. Column heights often encode data; bending them suits decorative
extrusions, not charts. Lighting on ColumnLayer uses the unbent normal.