threejs-weathering
v0.1.0
Published
Weather and weathering for three.js: rain, snow, wind and lightning, wildfires that spread and regrow, and wet/snowy/burnt/damaged material states
Maintainers
Readme
threejs-weathering
Weather and weathering for three.js. Seeded, time-driven weather runs over a threejs-biomes world: fronts, rain,
sleet, snow, wind and gusts, fog, thunderstorms and lightning. Precipitation is drawn on the GPU. Wildfires spread
with fuel, moisture, wind and slope, and the land regrows over years. The package also handles storm and impact
damage, and provides the shared material-state layer (wetness, snow, burn, damage) every other package plugs into.
npm i threejs-weathering threejs-particles threejs-biomes threethree.js
import { Weather, StateField, Wildfire, Precipitation, applyMaterialStatesTo } from 'threejs-weathering'
const weather = new Weather({ seed: 7 }, world)
const field = new StateField({ size: 1024, resolution: 128 }) // wetness, snow, burn, damage
const fire = new Wildfire({ world, weather, field, renderer, camera, size: 1024, look: { bloom: { enabled: true } } })
scene.add(fire.object)
fire.ignite(30, -10)
applyMaterialStatesTo(terrain.material, { wetness: field.node().wetness, snow: field.node().snow, ...fire.node() })
pipeline.outputNode = fire.bloom(pass(scene, camera).getTextureNode('output')) // optional bloom on flames and embers
renderer.setAnimationLoop(() => {
fire.update(time) // fire sim + GPU particles
field.updateFromWeather(weather, time)
field.update()
pipeline.render()
})React Three Fiber
import { Weather, Precipitation, Lightning, Wildfire } from 'threejs-weathering/react'
<Weather world={world} timeScale={60} field={{ size: 1024 }}>
<Precipitation />
<Lightning />
<Wildfire size={1024} ignitions={[[0, 0, 10, 4]]} look={{ haze: { enabled: true } }} />
</Weather>Wildfires
FireSim is a deterministic cellular automaton after Rothermel. Spread depends on fuel from the biome scatter
tables, fuel moisture from the weather, wind and slope. Water, rock, snow, roads and firebreaks stop it. Cells go
unburnt → burning → burnt → regrowing.
Wind makes the spread elliptical. The length-to-breadth ratio follows Anderson (1983) from the midflame wind
(midflame × the weather's wind, capped by maxLengthToBreadth), with the ignition at the rear focus: the head runs,
the flanks are slow and the backing fire crawls. Seeded, spatially correlated fuel and moisture variation makes the
edge finger and break up instead of growing as a ring.
Wildfire draws it with threejs-particles GPU systems (WebGPU), about 30k particles by default:
- Flames (premultiplied blending: they emit light and their dense cores hide what is behind) come only from the active front: recently ignited cells, weighted by intensity, with a flaming phase that lasts longer in heavy fuel. They are tall, noise-shaped, velocity-stretched tongues with a blackbody colour ramp (deep red edges, a near-white core) in HDR. They lean with the wind, lick and flicker through curl-noise turbulence, and climb into the crowns where there are trees.
- Smoke comes from the front, plus faint wisps from smouldering and freshly burnt ground. The puffs are lit,
alpha-blended and depth-sorted on the GPU. The plume is dense and dark brown-grey at the base, bends downwind with
height (wind shear), and over an intense fire caps into a bright, sharply billowing pyrocumulus-like top
(
smoke.capHeight,smoke.capIntensity). Each puff is warped, billowing noise, self-shadowed towards the sun, back-lit with a silver lining, and lit warm from below while it is still hot. A coarse grid carries the fire's heat up into a column that bends downwind and spreads with height, and also shadows the plume. Smoke is white over light or wet fuel and dark brown over heavy, dry, woody fuel. - Embers are thin streaks lofted by the plume and carried downwind, cooling from yellow to red.
- Ground: inside the front the ground is black char (white-grey ash where heavy fuel burnt through) with sparse
smouldering spots. The glowing band sits only at the front.
fire.node()givesburn,heat(glow) andashfor any material, sampled with a smooth, noise-warped filter so the 8 m cells never show. - Light: a point light at the front flickers, and its colour follows the flames' blackbody temperature.
- Smoke occlusion:
fire.smokeOcclusionAt(x, z)returns 0…1 from a Gaussian plume bent downwind, andfire.sunTransmittance(x, z)gives a dimmed, reddened sun.fire.uniforms.smokeOcclusionholds the value at the camera, for sky and lighting.
Spotting (embers starting new fires ahead of the front) isn't simulated. Embers are visual only.
WildfireLook
| Group | Options |
|---|---|
| flames | max, rate, size, height, life, temperature (K), intensity, flaming (s), crownHeight, turbulence |
| smoke | max, rate, size, life, rise, opacity, clean, dirty, linger, shadowSteps, lightSteps, detail, capHeight, capIntensity (pyrocumulus top) |
| embers | max, rate, size, life, intensity |
| haze | enabled (off by default), max, strength: screen-space refraction above the front |
| glow | front, smoulder: ground glow written into heat |
| light | intensity, distance, flicker |
| grid | enabled, resolution, height: the plume grid |
| bloom | enabled (off by default), strength, radius, threshold: used by fire.bloom(color) |
The quality knobs are particle max counts, smoke.shadowSteps, smoke.lightSteps, smoke.detail, grid,
haze.enabled and bloom.enabled. Changing counts, steps, haze or grid rebuilds the particle systems.
Compared with 0.1, the look changed: flames.perCell, width, color and core are gone (colour is blackbody now).
smoke.perCell and embers.perCell became rate. The texture's B and A channels now hold ash share and front
intensity. update(time, budget, dt?) takes an optional real-time step for the particles.
Material states
applyMaterialStates / applyMaterialStatesTo take any of wetness, snow, burn, damage, plus heat and
ash. All patterns are anti-aliased: they fade to their mean colour as their wavelength nears the pixel footprint,
and every threshold is one pixel soft. Burn scar edges are crisp at the scale of the fire front and broken up only
at small scales near the edge.
