Guides
Explosions and fireballs
A burst is a one-shot injection of fuel, heat, smoke and pressure. An explosion is a short, violent blast that tears into lobes and leaves a soot mushroom. A fireball is a slower, rolling ball of flame.
fire.explode([0, 0.8, 0]), then fire.explode([0, 0.8, 0], 1.4) six seconds later, on high.#Trigger one
fire.explode([0, 1, 0]); // detonation at a world position
fire.fireball(new THREE.Vector3(0, 1, 0), 0.7);
fire.burst([0, 1, 0], 'explosion', 2); // the general form: type + strengthstrength defaults to 1. It scales the fuel, smoke, radial push and expansion, and the radius grows with ∛strength, so strength: 8 is twice as wide. Up to 4 bursts are active at once. A fifth replaces the oldest.
#Burst types
BURST_TYPES holds the two archetypes:
fireball | explosion | |
|---|---|---|
radius (m) | 0.6 | 0.55 |
fuel | 90 | 160 |
temperature | 1.35 | 1.6 |
smoke | 4 | 12 |
boost (burn-rate boost) | 0.4 | 1.6 |
up (upward push) | 3.2 | 2.0 |
radial (outward push) | 3.0 | 20 |
expansion | 0.6 | 2.2 |
duration (s) | 0.22 | 0.12 |
embers | 3 | 14 |
lumpiness | 0.45 | 0.8 |
A burst injects for its duration, so an explosion delivers its fuel in about seven frames at 60 fps. params.expansion multiplies the burst expansion too, and params.smoke its smoke.
You can edit BURST_TYPES before triggering bursts, since burst() reads it every time:
import { BURST_TYPES } from 'naturegl-fire';
BURST_TYPES.explosion.smoke = 20; // dirtier explosions from now on#Why explosions don't look like balls
A radial push alone would be projected away by the pressure solve, because the gas is incompressible. So a burst also injects a divergence source in the pressure pass: volume appears at the burst and has to go somewhere. On top of that:
- Lumpy injection. The seed ball is carved into noise pockets (
lumpiness), so it blooms into separate lobes instead of an expanding sphere. - Jittered push. The outward push direction is jittered with noise, so the shell tears apart.
- Burn boost. The burst multiplies the local burn rate (
boost), so the fuel flashes over in a few frames. The heat that's released then rises as a column and rolls into a mushroom.
explosion: the soot cloud after a detonationfireball: a slower, rounder burst every 2.8 s#Auto-bursts
A preset can fire bursts on a timer. fireball and explosion do:
fire.autoBurst = { type: 'explosion', every: 4.4, offset: [0, 0.8, 0], strength: 1 };
fire.autoBurst = null; // stopoffset is relative to fire.origin, so setOrigin() moves the auto-burst with the preset. After loadPreset() the first auto-burst fires 0.4 s in.
#React to bursts
onBurst is called for every burst, including auto-bursts. The demo uses it for camera shake:
fire.onBurst = (type, position, strength) => {
if (type === 'explosion') shake = 1;
playSound(type, position, strength);
};The fire light follows the measured flame on its own. It also leans 30% toward the emitters, or toward the active burst when there are no emitters.