Three.js Volumetric Fire Shader

Ray-marched volumetric campfire in Three.js where domain-warped rising fBm defines the flame, temperature drives a blackbody color ramp, and sparks plus a flickering point light complete the scene.

Key topics: three.js fire, volumetric fire, fire shader, ray marching, blackbody, campfire

What this code does

- Emissive Volume: a back-faced box marches rays through the flame and adds emission with no absorption, using additive blending.
- Flame Shape: a cone narrowing with height is combined with scrolling 3D noise, so tongues detach and rise.
- Domain Warping: noise offsets the noise lookup itself, which curls the flames like turbulent plumes.
- Blackbody Ramp: higher temperature moves the color from deep red to orange, yellow and white.
- Scene Lighting: a point light flickers with incommensurate sines, and sparks are simple drifting points.
- Controls: intensity, temperature, turbulence scale, rise speed, flame width and sparks.

Continue Learning

JavaScript Implementation

ES6+
// Emissive volume: march through a box and add light where the noisy flame density is high
const fireGLSL = `
  for (int i = 0; i < 64; i++) {
    vec3 p = rayOrigin + rayDir * t;
    float h = p.y / 3.0;                                    // 0 at the base, 1 at the tip
    vec3 q = p * 1.5 - vec3(0.0, uTime * 1.6, 0.0);         // noise scrolls upward
    float shape = (1.0 - length(p.xz) / (0.75 * (1.0 - h * 0.85))) * (1.0 - h);
    float d = clamp(shape * 1.6 + fbm(q) - 0.95, 0.0, 1.0);
    color += blackbody(d * (1.1 - h)) * d * stepSize * 3.0; // hotter = whiter
    t += stepSize;
  }`
// Use side: THREE.BackSide and AdditiveBlending on a BoxGeometry around the fire.