Napalm Ground Fire Wall shader

napalm-ground-fire-wall.glsl · 980 lines · GLSL ES 3.00 · MIT

Napalm Ground Fire WallGame VFX
Napalm Ground Fire Wall WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 980 linesSPEC GLSL ES 3.00

Seamless PNG Texture Baker
1-Click Engine Shader Export
WebGL2 .glsl
.glsl
Godot 4 .gdshader
Three.js GLSL3

Engine shader code & wrappers

Physically-Based VFX
napalm-ground-fire-wall.glsl (980 lines)
#version 300 es
// Napalm Ground Fire Wall (napalm-ground-fire-wall.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_realistic/lib/04_napalm_ground_fire_wall.glsl
// License: MIT (Copyright 2026 Gokay Aydogan) + MIT/CC0 helpers — https://pixelfx.io/LICENSE-SHADERS.txt
// Uniforms: uResolution (vec2), uTime (float), uOpen (0..1), uLightMode (0..3), uCamMode (0..1)
precision highp float;
precision highp int;

uniform vec2 uResolution;
uniform float uTime;
uniform float uOpen;
uniform int uLightMode;
uniform int uCamMode;

out vec4 fragColor;

// ============================================================================
// 04_napalm_ground_fire_wall.glsl
// Photorealistic diagonal napalm ground fire wall burning along dark wet
// cracked asphalt tarmac, with a massive billowing black petroleum-soot smoke
// column, Planck blackbody licking flame tongues, and viscous glossy burning
// fuel puddles reflecting the blaze.
// ============================================================================

const float PI  = 3.14159265359;
const float TAU = 6.28318530718;

// Diagonal fire trench axis in XZ plane: foreground-left -> midground-right
const vec2 LINE_ORIGIN = vec2(-0.10, 0.38);
const vec2 LINE_DIR    = vec2(0.75257669, -0.65850461); // normalize(vec2(0.80, -0.70))
const vec2 LINE_NORM   = vec2(0.65850461,  0.75257669); // points toward foreground-right puddle

// ----------------------------------------------------------------------------
// Hash & Procedural Noise
// ----------------------------------------------------------------------------
float hash12(vec2 p) {
    vec3 p3 = fract(vec3(p.xyx) * 0.1031);
    p3 += dot(p3, p3.yzx + 33.33);
    return fract((p3.x + p3.y) * p3.z);
}

float hash13(vec3 p3) {
    p3 = fract(p3 * 0.1031);
    p3 += dot(p3, p3.zyx + 31.32);
    return fract((p3.x + p3.y) * p3.z);
}

vec3 hash33(vec3 p3) {
    p3 = fract(p3 * vec3(0.1031, 0.1030, 0.0973));
    p3 += dot(p3, p3.yxz + 33.33);
    return fract((p3.xxy + p3.yxx) * p3.zyx);
}

// Interleaved gradient noise (subtle jitter)
float ign(vec2 fragCoord) {
    vec3 magic = vec3(0.06711056, 0.00583715, 52.9829189);
    return fract(magic.z * fract(dot(fragCoord, magic.xy)));
}

float noise2(vec2 p) {
    vec2 i = floor(p);
    vec2 f = fract(p);
    vec2 u = f * f * (3.0 - 2.0 * f);
    float a = hash12(i + vec2(0.0, 0.0));
    float b = hash12(i + vec2(1.0, 0.0));
    float c = hash12(i + vec2(0.0, 1.0));
    float d = hash12(i + vec2(1.0, 1.0));
    return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}

float noise3(vec3 p) {
    vec3 i = floor(p);
    vec3 f = fract(p);
    vec3 u = f * f * (3.0 - 2.0 * f);

    float n000 = hash13(i + vec3(0.0, 0.0, 0.0));
    float n100 = hash13(i + vec3(1.0, 0.0, 0.0));
    float n010 = hash13(i + vec3(0.0, 1.0, 0.0));
    float n110 = hash13(i + vec3(1.0, 1.0, 0.0));
    float n001 = hash13(i + vec3(0.0, 0.0, 1.0));
    float n101 = hash13(i + vec3(1.0, 0.0, 1.0));
    float n011 = hash13(i + vec3(0.0, 1.0, 1.0));
    float n111 = hash13(i + vec3(1.0, 1.0, 1.0));

    float nx00 = mix(n000, n100, u.x);
    float nx10 = mix(n010, n110, u.x);
    float nx01 = mix(n001, n101, u.x);
    float nx11 = mix(n011, n111, u.x);

    float nxy0 = mix(nx00, nx10, u.y);
    float nxy1 = mix(nx01, nx11, u.y);
    return mix(nxy0, nxy1, u.z);
}

const mat2 M2 = mat2(0.80, -0.60, 0.60, 0.80);

float fbm2(vec2 p) {
    float v = 0.0;
    float a = 0.5;
    for (int i = 0; i < 4; i++) {
        v += a * noise2(p);
        p = M2 * p * 2.04 + vec2(17.1, 31.7);
        a *= 0.5;
    }
    return v;
}

float fbm3(vec3 p) {
    float v = 0.0;
    float a = 0.5;
    for (int i = 0; i < 4; i++) {
        v += a * noise3(p);
        p = p * 2.06 + vec3(13.7, 29.3, 41.1);
        a *= 0.5;
    }
    return v;
}

float fbm3Low(vec3 p) {
    float v = 0.50 * noise3(p);
    p = p * 2.05 + vec3(19.1, 7.3, 31.9);
    v += 0.25 * noise3(p);
    p = p * 2.02 + vec3(5.7, 23.1, 11.4);
    v += 0.125 * noise3(p);
    return v * 1.142857;
}

// Multi-octave billow/cauliflower FBM (chunky bulbous lobes + deep crevices)
float billowFbm3(vec3 p) {
    float v = 0.0;
    float a = 0.52;
    for (int i = 0; i < 4; i++) {
        float n = noise3(p);
        float b = 1.0 - abs(2.0 * n - 1.0);
        v += a * (b * b);
        p = p * 2.08 + vec3(17.3, 29.1, 11.7);
        a *= 0.50;
    }
    return v;
}

// High-frequency curl-like turbulence for sharp licking flames & rolling soot
vec3 curlTurbulence(vec3 p) {
    vec3 q = p * 1.75;
    float a = noise3(q) - 0.5;
    float b = noise3(q + vec3(11.3, 5.7, 19.1)) - 0.5;
    float c = noise3(q + vec3(27.1, 14.2, 3.9)) - 0.5;
    vec3 v1 = vec3(b - c, c - a, a - b);

    vec3 q2 = p * 3.85 + vec3(4.2, -7.1, 9.5);
    float d = noise3(q2) - 0.5;
    float e = noise3(q2 + vec3(17.4, 9.2, 21.8)) - 0.5;
    float f = noise3(q2 + vec3(6.1, 29.7, 13.3)) - 0.5;
    vec3 v2 = vec3(e - f, f - d, d - e);

    return v1 * 0.62 + v2 * 0.38;
}

// Voronoi edge distance for realistic asphalt cracks
float asphaltCracks(vec2 p) {
    vec2 n = floor(p);
    vec2 f = fract(p);
    float md1 = 8.0;
    float md2 = 8.0;
    for (int j = -1; j <= 1; j++) {
        for (int i = -1; i <= 1; i++) {
            vec2 g = vec2(float(i), float(j));
            vec2 o = vec2(hash12(n + g), hash12(n + g + vec2(43.7, 19.3)));
            vec2 r = g + o - f;
            float d = dot(r, r);
            if (d < md1) {
                md2 = md1;
                md1 = d;
            } else if (d < md2) {
                md2 = d;
            }
        }
    }
    return sqrt(md2) - sqrt(md1);
}

// Smooth minimum for organic overlapping smoke cumulus lobes
float smin(float a, float b, float k) {
    float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);
    return mix(b, a, h) - k * h * (1.0 - h);
}

// ----------------------------------------------------------------------------
// Rich Saturated Planck Blackbody Fire Palette
// (Low blue & rich amber-orange so ACES stays vibrant fiery orange-gold, never beige)
// ----------------------------------------------------------------------------
vec3 blackbodyFire(float temp01) {
    float t = clamp(temp01, 0.0, 1.0);
    vec3 c0 = vec3(0.45, 0.012, 0.0004); // deep crimson-red flame edge
    vec3 c1 = vec3(1.00, 0.095, 0.0018); // saturated fiery red-orange
    vec3 c2 = vec3(1.00, 0.285, 0.0090); // blazing napalm orange
    vec3 c3 = vec3(1.00, 0.560, 0.0420); // vibrant amber-gold
    vec3 c4 = vec3(1.00, 0.820, 0.1700); // hot incandescent golden-yellow core

    vec3 col = mix(c0, c1, smoothstep(0.00, 0.26, t));
    col = mix(col, c2, smoothstep(0.22, 0.54, t));
    col = mix(col, c3, smoothstep(0.50, 0.82, t));
    col = mix(col, c4, smoothstep(0.78, 1.00, t));
    return col;
}

// ----------------------------------------------------------------------------
// Coordinate helpers along the diagonal napalm trench
// ----------------------------------------------------------------------------
vec2 toLineCoords(vec2 xz) {
    vec2 q = xz - LINE_ORIGIN;
    return vec2(dot(q, LINE_DIR), dot(q, LINE_NORM)); // (along, perp)
}

// ----------------------------------------------------------------------------
// Viscous Fuel Puddle SDF & Mask on Ground (y = 0)
// ----------------------------------------------------------------------------
float evalPuddleHeight(vec2 xz) {
    vec2 lp = toLineCoords(xz);
    float s = lp.x;
    float d = lp.y;

    vec2 w = vec2(fbm2(xz * 1.55 + vec2(3.1, 7.4)), fbm2(xz * 1.55 + vec2(15.2, 2.8))) - 0.5;
    float sW = s + w.x * 0.36;
    float dW = d + w.y * 0.30;

    // 1. Hero foreground-right viscous fuel pool
    vec2 p1 = vec2((sW - 0.32) / 1.32, (dW - 0.64) / 0.62);
    float pool1 = 1.0 - length(p1);

    // 2. Secondary lobe extending toward bottom-right corner
    vec2 p2 = vec2((sW - 0.98) / 0.84, (dW - 0.88) / 0.40);
    float pool2 = 1.0 - length(p2);

    // 3. Narrow wet fuel slick hugging the burning trench edge
    float alongEnv = smoothstep(-2.45, -1.75, sW) * (1.0 - smoothstep(1.95, 2.65, sW));
    float slick = (0.18 - abs(dW - 0.08)) * 2.4 * alongEnv;

    // 4. Foreground-left smaller fuel puddle catching foreground flames
    vec2 p3 = vec2((sW + 1.35) / 0.68, (dW - 0.34) / 0.30);
    float pool3 = 1.0 - length(p3);

    float h = max(max(pool1, pool2), max(slick, pool3));
    float edgeNoise = (fbm2(xz * 5.2 + vec2(9.2, 4.1)) - 0.48) * 0.22;
    return h + edgeNoise;
}

// ----------------------------------------------------------------------------
// Sculptural Asymmetric Cumulus Smoke Column Base SDF (zero funnel/tornado look)
// ----------------------------------------------------------------------------
float smokeCrownBaseSDF(vec3 p, float t, float openBoost) {
    vec2 orig = LINE_ORIGIN + LINE_DIR * 0.22;
    vec3 q = p - vec3(orig.x, 0.0, orig.y);

    // Subtle rising buoyant sway
    float w1 = 0.07 * sin(t * 0.75);
    float w2 = 0.07 * cos(t * 0.62);

    // Overlapping asymmetric billowing cumulus puffs matching 04.png silhouette:
    // Lower belly wrapping behind/around the flame heart
    float d0 = length(q - vec3(-0.14 + w1, 1.25, -0.14)) - 0.56 * openBoost;
    float d1 = length(q - vec3( 0.28 - w2, 1.52, -0.05)) - 0.50 * openBoost;
    // Dramatic mid-upper left-bulging dark oily lobe
    float d2 = length(q - vec3(-0.36 + w2, 2.28, -0.08)) - 0.68 * openBoost;
    // Dramatic mid-upper right-bulging glossy-rimmed cauliflower lobe
    float d3 = length(q - vec3( 0.38 + w1, 2.42,  0.10)) - 0.66 * openBoost;
    // Upper dense billowing crown extending to top of frame
    float d4 = length(q - vec3(-0.08 - w1, 3.08, -0.10)) - 0.84 * openBoost;
    float d5 = length(q - vec3( 0.26 + w2, 3.68, -0.04)) - 0.78 * openBoost;
    // Lower-right shoulder puff
    float d6 = length(q - vec3( 0.46,      1.08,  0.04)) - 0.34 * openBoost;

    float d = smin(d0, d1, 0.26);
    d = smin(d, d2, 0.32);
    d = smin(d, d3, 0.30);
    d = smin(d, d4, 0.36);
    d = smin(d, d5, 0.36);
    d = smin(d, d6, 0.22);
    return d;
}

// ----------------------------------------------------------------------------
// Volumetric Napalm Fire + Dense Black Oil-Soot Smoke Field
// ----------------------------------------------------------------------------
struct VolSample {
    float fireDensity;
    float fireTemp;
    float smokeDensity;
    float sootDarkness;
    float sparkGlow;
};

VolSample evalVolume(vec3 p, float t, bool highDetail) {
    VolSample vs;
    vs.fireDensity = 0.0;
    vs.fireTemp = 0.0;
    vs.smokeDensity = 0.0;
    vs.sootDarkness = 0.88;
    vs.sparkGlow = 0.0;

    if (p.y < -0.02 || p.y > 4.35) return vs;

    float openBoost = 1.0 + 0.14 * clamp(uOpen, 0.0, 1.0);
    vec2 lp = toLineCoords(p.xz);
    float s = lp.x;
    float d = lp.y;

    if (s < -2.9 || s > 3.0 || abs(d) > 2.0) return vs;

    // ------------------------------------------------------------------------
    // 1. NARROW DIAGONAL LICKING NAPALM FIRE WALL + CENTRAL ROARING HEART
    // ------------------------------------------------------------------------
    if (p.y < 2.25 && abs(d) < 0.72) {
        vec3 pAdv = p - vec3(0.05 * p.y, t * 2.95, -0.04 * p.y);
        vec3 turb = curlTurbulence(pAdv * vec3(1.85, 1.15, 1.85));
        float hScale = smoothstep(0.0, 0.28, p.y);
        vec3 pFlame = p + turb * (0.10 + 0.17 * hScale);

        vec2 lpF = toLineCoords(pFlame.xz);
        float sF = lpF.x;
        float dF = lpF.y;

        float trenchEnv = smoothstep(-2.45, -1.95, sF) * (1.0 - smoothstep(2.05, 2.65, sF));

        // Central tall roaring blaze heart (s ~ 0.18)
        float heartBell = exp(-pow((sF - 0.18) / 0.48, 2.0));
        // Distinct licking foreground & midground tongues along the diagonal line
        float fgPeak1 = exp(-pow((sF + 1.82) / 0.22, 2.0)) * 0.44;
        float fgPeak2 = exp(-pow((sF + 0.92) / 0.20, 2.0)) * 0.36;
        float bgPeak  = exp(-pow((sF - 1.25) / 0.24, 2.0)) * 0.28;

        // Sharp jagged dancing flame tongues
        float tWave1 = noise3(vec3(sF * 4.2, p.y * 0.95 - t * 3.4, 1.7));
        float tWave2 = noise3(vec3(sF * 9.2 + 5.3, p.y * 1.65 - t * 5.0, 4.9));
        float tongueHeight = (0.24 + 0.36 * tWave1 + 0.24 * tWave2) * trenchEnv;
        tongueHeight += heartBell * (1.08 + 0.40 * tWave1) * openBoost;
        tongueHeight += (fgPeak1 + fgPeak2 + bgPeak) * (0.50 + 0.50 * tWave2);

        float hNorm = p.y / max(tongueHeight, 0.05);
        float halfWidth = (0.052 + 0.140 * heartBell) * mix(1.0, 0.28, clamp(hNorm, 0.0, 1.0)) * openBoost;

        float trenchCurve = 0.042 * sin(sF * 2.5 + 0.5) + 0.024 * cos(sF * 5.4 - t * 1.4);
        float radial = abs(dF - trenchCurve) / max(halfWidth, 0.025);

        float baseFade = smoothstep(-0.01, 0.035, p.y);
        float topFade  = 1.0 - smoothstep(0.24, 1.00, hNorm);

        // High-frequency filament & ridged flame-tongue carving
        vec3 nCoord = vec3(pFlame.x * 4.2, pFlame.y * 2.1 - t * 4.6, pFlame.z * 4.2);
        float fNoise = highDetail ? fbm3(nCoord) : fbm3Low(nCoord);
        float ridgedFil = 1.0 - abs(2.0 * noise3(nCoord * 2.15 + vec3(7.1, -t * 2.8, 3.2)) - 1.0);
        float fineLick  = highDetail ? (1.0 - abs(2.0 * noise3(nCoord * 4.2 + vec3(1.9, -t * 5.5, 9.4)) - 1.0)) : 0.6;

        float coreShape = (1.0 - radial * radial) * baseFade * topFade * trenchEnv;
        float flameMask = coreShape
                        - mix(0.22, 0.64, hNorm) * (1.0 - fNoise)
                        - 0.17 * (1.0 - ridgedFil)
                        - 0.08 * (1.0 - fineLick) * hNorm;

        // Curling fiery wisps licking up into the lower black smoke belly
        if (heartBell > 0.08 && p.y > 0.62 && p.y < 1.98) {
            vec3 sp = p - vec3(0.04, 1.18, 0.24);
            float ang = p.y * 2.2 - t * 1.55;
            vec2 rXZ = mat2(cos(ang), -sin(ang), sin(ang), cos(ang)) * sp.xz;
            float ln = fbm3Low(vec3(rXZ * 3.6, p.y * 2.0 - t * 3.6));
            float env = exp(-dot(sp.xz, sp.xz) * 5.4) * smoothstep(0.62, 1.08, p.y) * (1.0 - smoothstep(1.38, 1.98, p.y));
            flameMask = max(flameMask, (ln - 0.50) * 1.9 * env);
        }

        if (flameMask > 0.0) {
            float filMod = mix(0.35, 1.0, smoothstep(0.18, 0.80, fNoise * 0.55 + ridgedFil * 0.30 + fineLick * 0.15));
            vs.fireDensity = clamp(flameMask * 3.4 * filMod, 0.0, 2.2);
            // Rich temperature range: deep crimson/orange outer licks -> vibrant amber-gold inner veins
            float temp = clamp(flameMask * 1.15 + 0.22 * (1.0 - hNorm) + 0.20 * heartBell * ridgedFil - 0.30 * radial, 0.0, 0.96);
            vs.fireTemp = temp;
        }
    }

    // ------------------------------------------------------------------------
    // 2. SCULPTURAL CAULIFLOWER BLACK PETROLEUM-SOOT SMOKE CROWN
    // ------------------------------------------------------------------------
    float smokeBaseEnv = smoothstep(0.28, 0.85, p.y) * (1.0 - smoothstep(3.75, 4.30, p.y));
    if (smokeBaseEnv > 0.001) {
        float baseSDF = smokeCrownBaseSDF(p, t, openBoost);
        if (baseSDF < 0.72) {
            vec3 sp = p - vec3(0.0, t * 0.86, 0.0);
            vec3 sTurb = curlTurbulence(sp * 0.95 + vec3(0.0, -t * 0.22, 0.0));
            vec3 spW = sp + sTurb * 0.28;

            // Strong multi-octave cauliflower displacement breaks up any smooth contour
            float bLarge = highDetail ? billowFbm3(spW * 1.45) : fbm3Low(spW * 1.45);
            float bFine  = noise3(spW * 3.85 + vec3(11.2, -t * 0.72, 5.4));
            float displace = (bLarge * 0.58 + bFine * 0.20) - 0.24;

            // Signed field > 0 inside cauliflower smoke billows
            float rawSoot = (-baseSDF + displace) * smokeBaseEnv;

            // Carve front-bottom window so the central raging fire bursts out dramatically
            float heartWindow = exp(-pow((p.y - 0.78) / 0.44, 2.0)) *
                                smoothstep(-0.08, 0.28, d) *
                                exp(-pow((s - 0.18) / 0.44, 2.0));
            rawSoot -= heartWindow * 0.56;

            if (rawSoot > 0.0) {
                float crispSoot = smoothstep(0.0, 0.16, rawSoot) * (0.75 + 0.95 * rawSoot);
                vs.smokeDensity += crispSoot * 8.2;
                vs.sootDarkness = clamp(smoothstep(0.03, 0.28, rawSoot) * 0.95 + 0.05, 0.0, 1.0);
            }
        }
    }

    // ------------------------------------------------------------------------
    // 3. SUBTLE WISPY SMOKE DRIFTING OFF THE FIRE WALL & UPPER HANGAR AIR
    // ------------------------------------------------------------------------
    if (p.y > 0.15 && p.y < 3.4 && abs(d) < 1.50) {
        float wispAlong = smoothstep(-2.3, -1.4, s) * (1.0 - smoothstep(1.7, 2.5, s));
        vec3 wp = vec3(p.x * 1.05 - 0.14 * t, p.y * 0.90 - t * 0.70, p.z * 1.05);
        float wn = fbm3Low(wp * 1.28);
        float wispEnv = wispAlong * exp(-abs(d) * 1.80) * smoothstep(0.18, 0.62, p.y) * (1.0 - smoothstep(1.45, 3.1, p.y));
        float wisp = max(0.0, (wn - 0.52) * 1.75) * wispEnv;
        if (wisp > 0.0) {
            float prev = vs.smokeDensity;
            vs.smokeDensity += wisp * 0.60;
            vs.sootDarkness = mix(0.26, vs.sootDarkness, prev / max(vs.smokeDensity, 0.001));
        }
    }

    // ------------------------------------------------------------------------
    // 4. FINE FLYING EMBERS AROUND THE PLUME
    // ------------------------------------------------------------------------
    if (highDetail && p.y > 0.40 && p.y < 3.0) {
        vec2 orig = LINE_ORIGIN + LINE_DIR * 0.22;
        float distPlume = length(p.xz - orig);
        if (distPlume < 1.15) {
            vec3 spGrid = p * 5.8 + vec3(0.35 * sin(p.y * 2.2 + t * 2.1), -t * 5.0, 0.35 * cos(p.y * 1.9 - t * 1.7));
            vec3 cell = floor(spGrid);
            vec3 f = fract(spGrid) - 0.5;
            vec3 rnd = hash33(cell);
            if (rnd.x > 0.970) {
                vec3 offset = (rnd - 0.5) * 0.58;
                float dSpark = length(f - offset);
                float spark = smoothstep(0.068, 0.012, dSpark);
                float env = smoothstep(1.15, 0.25, distPlume) * (1.0 - smoothstep(2.1, 3.0, p.y));
                vs.sparkGlow = spark * env * 1.75;
            }
        }
    }

    return vs;
}

// Fast smoke-only density query for self-shadowing & crisp cauliflower surface normals
float evalSmokeOnly(vec3 p, float t) {
    if (p.y < 0.22 || p.y > 4.35) return 0.0;
    float smokeBaseEnv = smoothstep(0.28, 0.85, p.y) * (1.0 - smoothstep(3.75, 4.30, p.y));
    float openBoost = 1.0 + 0.14 * clamp(uOpen, 0.0, 1.0);
    float baseSDF = smokeCrownBaseSDF(p, t, openBoost);
    if (baseSDF > 0.68) return 0.0;

    vec3 sp = p - vec3(0.0, t * 0.86, 0.0);
    float bLarge = billowFbm3(sp * 1.45);
    float rawSoot = max(0.0, (-baseSDF + (bLarge * 0.58 - 0.14)) * smokeBaseEnv);
    return smoothstep(0.0, 0.16, rawSoot) * (0.75 + 0.95 * rawSoot) * 8.2;
}

float hgPhase(float cosTheta, float g) {
    float g2 = g * g;
    float denom = 1.0 + g2 - 2.0 * g * cosTheta;
    return (1.0 - g2) / (4.0 * PI * pow(max(denom, 0.001), 1.5));
}

// ----------------------------------------------------------------------------
// Linear-Space Lighting Rig per uLightMode
// ----------------------------------------------------------------------------
struct LightRig {
    vec3 keyDir;
    vec3 keyCol;
    vec3 rimDir;
    vec3 rimCol;
    vec3 ambTop;
    vec3 ambHorizon;
    float fireEmissionScale;
    float smokeAlbedoBoost;
};

LightRig getLightRig() {
    LightRig rig;
    if (uLightMode == 1) {
        rig.keyDir = normalize(vec3(0.62, 0.66, 0.42));
        rig.keyCol = vec3(0.95);
        rig.rimDir = normalize(vec3(-0.42, 0.52, -0.74));
        rig.rimCol = vec3(0.75);
        rig.ambTop = vec3(0.0032);
        rig.ambHorizon = vec3(0.0052);
        rig.fireEmissionScale = 0.24;
        rig.smokeAlbedoBoost = 2.6;
    } else if (uLightMode == 2) {
        rig.keyDir = normalize(vec3(0.92, 0.18, 0.34));
        rig.keyCol = vec3(1.25, 1.15, 1.02);
        rig.rimDir = normalize(vec3(-0.65, 0.35, -0.68));
        rig.rimCol = vec3(0.28, 0.38, 0.55);
        rig.ambTop = vec3(0.0010, 0.0014, 0.0022);
        rig.ambHorizon = vec3(0.0016, 0.0021, 0.0030);
        rig.fireEmissionScale = 0.90;
        rig.smokeAlbedoBoost = 1.45;
    } else if (uLightMode == 3) {
        rig.keyDir = normalize(vec3(0.25, 0.55, 0.79));
        rig.keyCol = vec3(0.16, 0.22, 0.32);
        rig.rimDir = normalize(vec3(-0.12, 0.38, -0.92));
        rig.rimCol = vec3(1.55, 1.80, 2.25);
        rig.ambTop = vec3(0.0012, 0.0018, 0.0030);
        rig.ambHorizon = vec3(0.0018, 0.0025, 0.0040);
        rig.fireEmissionScale = 0.90;
        rig.smokeAlbedoBoost = 1.65;
    } else {
        rig.keyDir = normalize(vec3(0.60, 0.72, -0.35));
        rig.keyCol = vec3(0.62, 0.72, 0.92);
        rig.rimDir = normalize(vec3(0.35, 0.58, -0.73));
        rig.rimCol = vec3(0.48, 0.60, 0.82);
        rig.ambTop = vec3(0.00085, 0.00125, 0.00210);
        rig.ambHorizon = vec3(0.00135, 0.00185, 0.00285);
        rig.fireEmissionScale = 1.0;
        rig.smokeAlbedoBoost = 1.0;
    }
    return rig;
}

// ----------------------------------------------------------------------------
// Adaptive-Step Volumetric Raymarch (eliminates concentric step rings & dither)
// ----------------------------------------------------------------------------
vec4 marchFireAndSmoke(vec3 ro, vec3 rd, float tMin, float tMax, float jitter, float time, LightRig rig, bool isReflection) {
    vec3 bMin = vec3(-2.35, -0.02, -1.95);
    vec3 bMax = vec3( 2.35,  4.25,  2.15);

    vec3 invRd = 1.0 / (rd + vec3(1e-6));
    vec3 t0s = (bMin - ro) * invRd;
    vec3 t1s = (bMax - ro) * invRd;
    vec3 tSm = min(t0s, t1s);
    vec3 tBg = max(t0s, t1s);

    float tEnter = max(tMin, max(tSm.x, max(tSm.y, tSm.z)));
    float tExit  = min(tMax, min(tBg.x, min(tBg.y, tBg.z)));

    if (tEnter >= tExit) return vec4(0.0, 0.0, 0.0, 1.0);

    // Fine step size inside active fire/smoke eliminates banding & dither completely
    float dsFine   = isReflection ? 0.055 : 0.036;
    float dsCoarse = isReflection ? 0.145 : 0.105;
    int maxSteps   = isReflection ? 48 : 112;

    // Gentle sub-step start jitter (avoids visible checkerboard stipple)
    float tCur = tEnter + dsFine * (0.25 + 0.50 * jitter);

    vec3 accum = vec3(0.0);
    float trans = 1.0;

    vec3 fireHeartPos = vec3(LINE_ORIGIN.x + LINE_DIR.x * 0.18, 0.62, LINE_ORIGIN.y + LINE_DIR.y * 0.18);
    float flicker = 0.93 + 0.07 * sin(time * 13.7) * cos(time * 7.3);

    float cosKey = dot(rd, rig.keyDir);
    float cosRim = dot(rd, rig.rimDir);
    float phaseKey = mix(hgPhase(cosKey, 0.35), hgPhase(cosKey, -0.15), 0.35);
    float phaseRim = hgPhase(cosRim, 0.62);

    vec2 plumeOrig = LINE_ORIGIN + LINE_DIR * 0.22;

    for (int i = 0; i < 112; i++) {
        if (i >= maxSteps || tCur >= tExit || trans < 0.008) break;

        vec3 p = ro + rd * tCur;

        // Cheap proximity check to choose fine vs coarse step
        vec2 lpQ = toLineCoords(p.xz);
        float nearTrench = abs(lpQ.y);
        float nearPlume  = length(p.xz - plumeOrig);
        bool inActiveZone = (nearTrench < 0.62 && p.y < 2.25) || (nearPlume < 1.38 && p.y > 0.20);

        float ds = inActiveZone ? dsFine : dsCoarse;
        ds = min(ds, tExit - tCur);

        if (inActiveZone || nearTrench < 1.35) {
            VolSample vs = evalVolume(p, time, !isReflection);

            if (vs.smokeDensity > 0.002 || vs.fireDensity > 0.002 || vs.sparkGlow > 0.001) {
                // --- 1. Rich Saturated Planck Blackbody Fire Emission ---
                vec3 fireEmit = vec3(0.0);
                if (vs.fireDensity > 0.002) {
                    vec3 fireCol = blackbodyFire(vs.fireTemp);
                    float fireLum = (0.55 + 2.65 * pow(vs.fireTemp, 1.55)) * vs.fireDensity * rig.fireEmissionScale;
                    if (uLightMode == 1) {
                        float g = dot(fireCol, vec3(0.299, 0.587, 0.114));
                        fireCol = vec3(g);
                    }
                    fireEmit = fireCol * fireLum;
                }

                // --- 2. Fine Flying Embers ---
                if (vs.sparkGlow > 0.001) {
                    vec3 spCol = (uLightMode == 1) ? vec3(0.80) : vec3(1.0, 0.45, 0.06);
                    fireEmit += spCol * vs.sparkGlow * 1.65 * rig.fireEmissionScale;
                }

                // --- 3. Dense Opaque Charcoal-Black Oil-Soot Smoke + Glossy Rim ---
                vec3 smokeScatter = vec3(0.0);
                if (vs.smokeDensity > 0.002) {
                    float baseAlbedo = mix(0.15, 0.017, vs.sootDarkness) * rig.smokeAlbedoBoost;
                    baseAlbedo = clamp(baseAlbedo, 0.012, 0.44);

                    float tauKey = 0.0;
                    float tauFire = 0.0;
                    if (!isReflection) {
                        tauKey += evalSmokeOnly(p + rig.keyDir * 0.14, time) * 0.14;
                        tauKey += evalSmokeOnly(p + rig.keyDir * 0.36, time) * 0.22;

                        vec3 toFire = fireHeartPos - p;
                        vec3 fDir = normalize(toFire + vec3(1e-5));
                        tauFire += evalSmokeOnly(p + fDir * 0.15, time) * 0.15;
                        tauFire += evalSmokeOnly(p + fDir * 0.38, time) * 0.23;
                    }

                    float lightKey = exp(-tauKey * 2.35);
                    float multiKey = 0.16 * exp(-tauKey * 0.45);

                    // Warm fiery under-lighting from central blaze & trench
                    vec3 toHeart = fireHeartPos - p;
                    float distHeart2 = dot(toHeart, toHeart) + 0.14;
                    float fireAtten = 1.0 / (distHeart2 * 1.05 + 0.24);

                    vec2 nearestXZ = LINE_ORIGIN + LINE_DIR * clamp(lpQ.x, -2.2, 2.2);
                    float distLine2 = dot(p.xz - nearestXZ, p.xz - nearestXZ) + p.y * p.y + 0.12;
                    float lineAtten = 0.35 / (distLine2 * 1.45 + 0.22);

                    float fireTransmit = exp(-tauFire * 1.50);
                    vec3 fireLightCol = (uLightMode == 1) ? vec3(0.55) : vec3(1.0, 0.28, 0.024);
                    vec3 fireBounce = fireLightCol * (fireAtten * 2.35 + lineAtten * 0.90) * fireTransmit * flicker * (0.35 + 0.65 * rig.fireEmissionScale);

                    // Crisp glossy oily-tar specular rim on lit cauliflower folds (signature ref 04)
                    vec3 oilySpec = vec3(0.0);
                    if (!isReflection && vs.sootDarkness > 0.45 && trans > 0.10 && lightKey > 0.15) {
                        float eps = 0.055;
                        float gx = evalSmokeOnly(p + vec3(eps, 0.0, 0.0), time) - vs.smokeDensity;
                        float gy = evalSmokeOnly(p + vec3(0.0, eps, 0.0), time) - vs.smokeDensity;
                        float gz = evalSmokeOnly(p + vec3(0.0, 0.0, eps), time) - vs.smokeDensity;
                        vec3 grad = vec3(gx, gy, gz);
                        float gLen = length(grad);
                        if (gLen > 0.12) {
                            vec3 nSmoke = -grad / gLen;
                            vec3 hKey = normalize(rig.keyDir - rd);
                            float spec = pow(max(dot(nSmoke, hKey), 0.0), 32.0);
                            float fres = pow(1.0 - max(dot(nSmoke, -rd), 0.0), 3.5);
                            oilySpec = rig.keyCol * (spec * 0.58 + fres * 0.075) * lightKey * vs.sootDarkness;

                            if (uLightMode == 3) {
                                vec3 hRim = normalize(rig.rimDir - rd);
                                float rSpec = pow(max(dot(nSmoke, hRim), 0.0), 18.0);
                                oilySpec += rig.rimCol * (rSpec * 0.36 + fres * 0.18) * exp(-tauKey * 0.8);
                            }
                        }
                    }

                    vec3 amb = mix(rig.ambHorizon, rig.ambTop, clamp(p.y * 0.30, 0.0, 1.0));
                    vec3 directKey = rig.keyCol * (lightKey * (0.42 + 1.8 * phaseKey) + multiKey * 0.24);
                    vec3 directRim = rig.rimCol * exp(-tauKey * 1.15) * (0.18 + 2.0 * phaseRim);

                    vec3 sootTint = (uLightMode == 1) ? vec3(1.0) : mix(vec3(0.84, 0.88, 0.94), vec3(0.66, 0.62, 0.60), vs.sootDarkness);
                    smokeScatter = (directKey + directRim + fireBounce + amb * 2.2) * baseAlbedo * sootTint + oilySpec;
                }

                float sigmaSmoke = vs.smokeDensity * 4.10;
                float sigmaFire  = vs.fireDensity * 0.55;
                float sigmaT     = sigmaSmoke + sigmaFire;
                float stepTrans  = exp(-sigmaT * ds);

                float smokeWeight = (sigmaSmoke / max(sigmaT, 1e-4)) * (1.0 - stepTrans);
                vec3 stepCol = smokeScatter * smokeWeight + fireEmit * ds * (0.5 + 0.5 * stepTrans);

                accum += trans * stepCol;
                trans *= stepTrans;
            }
        }

        tCur += ds;
    }

    return vec4(accum, trans);
}

// ----------------------------------------------------------------------------
// Dark Industrial Hangar Background
// ----------------------------------------------------------------------------
vec3 evalHangarBackground(vec3 rd, LightRig rig, float time) {
    float y = max(rd.y, 0.0);
    vec3 bg = mix(rig.ambHorizon, rig.ambTop, smoothstep(0.0, 0.65, y));

    float az = atan(rd.x, -rd.z);
    float elev = rd.y;

    float cols = smoothstep(0.80, 0.97, abs(sin(az * 7.5 + 0.4)));
    float wallRibs = smoothstep(0.76, 0.96, abs(sin(elev * 34.0)));
    float ceilingMask = smoothstep(0.26, 0.44, elev);
    float wallMask = (1.0 - ceilingMask) * smoothstep(0.0, 0.05, elev);
    float arch = (cols * 0.45 + wallRibs * 0.25) * wallMask;

    float bayGlow = exp(-pow((az - 0.55) / 0.55, 2.0)) * smoothstep(0.02, 0.28, elev) * (1.0 - smoothstep(0.28, 0.58, elev));
    float upperHaze = exp(-pow((az + 0.32) / 0.65, 2.0)) * smoothstep(0.10, 0.45, elev);

    vec3 archTint = (uLightMode == 1) ? vec3(0.005) : vec3(0.0018, 0.0024, 0.0038);
    bg += archTint * arch * 0.75;
    bg += rig.keyCol * (bayGlow * 0.0042 + upperHaze * 0.0028);

    float fireHorizon = exp(-pow(az / 0.78, 2.0)) * exp(-elev * 8.5);
    vec3 fireHazeCol = (uLightMode == 1) ? vec3(0.008) : vec3(0.032, 0.009, 0.0018);
    float flick = 0.94 + 0.06 * sin(time * 9.3);
    bg += fireHazeCol * fireHorizon * flick * rig.fireEmissionScale;

    if (uLightMode == 3) {
        float sunDot = max(dot(rd, rig.rimDir), 0.0);
        bg += rig.rimCol * (pow(sunDot, 14.0) * 0.025 + pow(sunDot, 64.0) * 0.08);
    }

    float bgSmoke = fbm2(vec2(az * 2.5 - time * 0.05, elev * 4.0 - time * 0.09));
    bg += mix(rig.ambHorizon, rig.keyCol * 0.006, 0.5) * smoothstep(0.45, 0.85, bgSmoke) * 0.85 * (1.0 - smoothstep(0.38, 0.85, elev));

    return bg;
}

// ----------------------------------------------------------------------------
// GGX Specular Microfacet Helper
// ----------------------------------------------------------------------------
float ggxSpec(vec3 N, vec3 V, vec3 L, float rough) {
    vec3 H = normalize(V + L);
    float NoH = max(dot(N, H), 0.0);
    float NoV = max(dot(N, V), 0.001);
    float NoL = max(dot(N, L), 0.001);
    float a = rough * rough;
    float a2 = a * a;
    float denom = NoH * NoH * (a2 - 1.0) + 1.0;
    float D = a2 / (PI * denom * denom + 1e-5);
    float k = (rough + 1.0);
    k = (k * k) * 0.125;
    float G = (NoV / (NoV * (1.0 - k) + k)) * (NoL / (NoL * (1.0 - k) + k));
    return (D * G) / (4.0 * NoV * NoL + 1e-4);
}

// ----------------------------------------------------------------------------
// Ground Asphalt + Viscous Burning Fuel Puddle Shading
// ----------------------------------------------------------------------------
vec3 shadeGround(vec3 p, vec3 rd, float dist, float jitter, float time, LightRig rig) {
    vec3 V = -rd;
    vec2 xz = p.xz;
    vec2 lp = toLineCoords(xz);
    float s = lp.x;
    float d = lp.y;

    float pH = evalPuddleHeight(xz);
    float puddleMask = smoothstep(0.0, 0.032, pH);
    float wetMask = smoothstep(-0.24, 0.03, pH);
    float detailFade = 1.0 / (1.0 + dist * dist * 0.065);

    // --- 1. Asphalt Micro-Pebble Aggregate & Cracks ---
    float agg1 = noise2(xz * 36.0);
    float agg2 = noise2(xz * 82.0 + vec2(11.4, 27.9));
    float macroRough = fbm2(xz * 2.2 + vec2(4.3, 9.1));
    float crackD = asphaltCracks(xz * 1.9 + vec2(macroRough * 0.35));
    float crackMask = 1.0 - smoothstep(0.012, 0.048, crackD);

    float eA = 0.0065;
    float h0 = (agg1 * 0.6 + agg2 * 0.4) * 0.024 + macroRough * 0.016 - crackMask * 0.018;
    float hx = (noise2((xz + vec2(eA, 0.0)) * 36.0) * 0.6 + noise2((xz + vec2(eA, 0.0)) * 82.0 + vec2(11.4, 27.9)) * 0.4) * 0.024
             + fbm2((xz + vec2(eA, 0.0)) * 2.2 + vec2(4.3, 9.1)) * 0.016;
    float hz = (noise2((xz + vec2(0.0, eA)) * 36.0) * 0.6 + noise2((xz + vec2(0.0, eA)) * 82.0 + vec2(11.4, 27.9)) * 0.4) * 0.024
             + fbm2((xz + vec2(0.0, eA)) * 2.2 + vec2(4.3, 9.1)) * 0.016;
    vec3 nAsphalt = normalize(vec3((h0 - hx) / eA * detailFade, 1.0, (h0 - hz) / eA * detailFade));

    // --- 2. Viscous Fuel Puddle Normal ---
    float eP = 0.012;
    float pHx = evalPuddleHeight(xz + vec2(eP, 0.0));
    float pHz = evalPuddleHeight(xz + vec2(0.0, eP));
    float meniscusBand = smoothstep(-0.012, 0.020, pH) * (1.0 - smoothstep(0.020, 0.075, pH));
    vec2 menGrad = vec2(pH - pHx, pH - pHz) / eP;

    float r1 = noise2(xz * 4.8 + vec2(time * 0.32, -time * 0.25));
    float r2 = noise2(xz * 9.8 + vec2(-time * 0.40, time * 0.48));
    float r1x = noise2((xz + vec2(0.028, 0.0)) * 4.8 + vec2(time * 0.32, -time * 0.25));
    float r1z = noise2((xz + vec2(0.0, 0.028)) * 4.8 + vec2(time * 0.32, -time * 0.25));
    vec2 rippleGrad = vec2(r1 - r1x, r1 - r1z) * 0.32 + (r2 - 0.5) * 0.012;

    vec3 nPuddle = normalize(vec3(
        rippleGrad.x + menGrad.x * meniscusBand * 0.20,
        1.0,
        rippleGrad.y + menGrad.y * meniscusBand * 0.20
    ));
    vec3 N = normalize(mix(nAsphalt, nPuddle, puddleMask));

    // --- 3. Dark Wet Asphalt Albedo + Subtle Painted Hangar Markings ---
    vec3 asphaltAlbedo = mix(vec3(0.008, 0.009, 0.011), vec3(0.020, 0.021, 0.024), agg1 * 0.55 + macroRough * 0.45);
    asphaltAlbedo *= mix(1.0, 0.45, wetMask);
    asphaltAlbedo *= (1.0 - crackMask * 0.60);

    float yellowLine = smoothstep(0.055, 0.015, abs(xz.y + 1.35 - xz.x * 0.04)) * smoothstep(0.2, -0.6, xz.x);
    float whiteLine  = smoothstep(0.075, 0.020, abs(xz.x - 1.75 - (xz.y + 0.5) * 0.36)) * smoothstep(1.2, -0.5, xz.y);
    float paintWear  = smoothstep(0.28, 0.72, macroRough);
    if (uLightMode == 1) {
        asphaltAlbedo = mix(asphaltAlbedo, vec3(0.08), yellowLine * paintWear * 0.45);
        asphaltAlbedo = mix(asphaltAlbedo, vec3(0.14), whiteLine * paintWear * 0.55);
    } else {
        asphaltAlbedo = mix(asphaltAlbedo, vec3(0.14, 0.10, 0.018), yellowLine * paintWear * 0.42);
        asphaltAlbedo = mix(asphaltAlbedo, vec3(0.16, 0.17, 0.18), whiteLine * paintWear * 0.52);
    }

    // --- 4. Viscous Amber-Orange Fuel Puddle Body ---
    float nearFire = exp(-abs(d) * 1.15) * smoothstep(-2.4, -1.5, s) * (1.0 - smoothstep(1.8, 2.6, s));
    float puddleDepth = smoothstep(0.0, 0.30, pH);
    vec3 fuelBody = mix(vec3(0.005, 0.0018, 0.0006), vec3(0.26, 0.044, 0.002), nearFire * 0.75 + 0.25 * puddleDepth);
    float heroPoolGlow = exp(-pow((s - 0.38) / 1.10, 2.0)) * exp(-pow((d - 0.68) / 0.58, 2.0));
    fuelBody += vec3(0.36, 0.068, 0.003) * heroPoolGlow * puddleDepth * rig.fireEmissionScale;
    if (uLightMode == 1) {
        fuelBody = vec3(dot(fuelBody, vec3(0.299, 0.587, 0.114)) * 0.42);
    }

    // --- 5. Direct Illumination on Tarmac & Puddle ---
    float flicker = 0.93 + 0.07 * sin(time * 13.7 + s * 1.7) * cos(time * 7.3 - s * 0.9);
    float rough = mix(mix(0.44, 0.16, wetMask), 0.04, puddleMask);

    vec2 nearestLineXZ = LINE_ORIGIN + LINE_DIR * clamp(s, -2.3, 2.3);
    vec3 toLine = vec3(nearestLineXZ.x, 0.28, nearestLineXZ.y) - p;
    float dLine2 = dot(toLine, toLine) + 0.08;
    vec3 L_line = normalize(toLine);
    float attenLine = 1.0 / (dLine2 * 1.65 + 0.22);

    vec3 heartPos = vec3(LINE_ORIGIN.x + LINE_DIR.x * 0.18, 0.72, LINE_ORIGIN.y + LINE_DIR.y * 0.18);
    vec3 toHeart = heartPos - p;
    float dHeart2 = dot(toHeart, toHeart) + 0.22;
    vec3 L_heart = normalize(toHeart);
    float attenHeart = 1.0 / (dHeart2 * 0.95 + 0.30);

    vec3 fireCol = (uLightMode == 1) ? vec3(0.42) : vec3(1.0, 0.30, 0.025);
    float fireStr = flicker * (0.35 + 0.65 * rig.fireEmissionScale);

    float diffLine  = max(dot(N, L_line), 0.0) * attenLine * 0.95;
    float diffHeart = max(dot(N, L_heart), 0.0) * attenHeart * 1.35;
    float specLine  = ggxSpec(N, V, L_line, max(rough, 0.15)) * attenLine * 0.24;
    float specHeart = ggxSpec(N, V, L_heart, max(rough, 0.17)) * attenHeart * 0.36;

    float diffKey = max(dot(N, rig.keyDir), 0.0);
    float specKey = ggxSpec(N, V, rig.keyDir, max(rough, 0.09));
    float specRim = ggxSpec(N, V, rig.rimDir, max(rough, 0.11));

    float NoV = max(dot(N, V), 0.001);
    float F0 = mix(0.032, 0.052, puddleMask);
    float fresnel = F0 + (1.0 - F0) * pow(1.0 - NoV, 5.0);

    vec3 surfAlbedo = mix(asphaltAlbedo, fuelBody, puddleMask);
    vec3 diffuseLight = (rig.ambHorizon * 1.6 + rig.ambTop * 0.9)
                      + rig.keyCol * diffKey * 0.14
                      + fireCol * (diffLine + diffHeart) * fireStr;

    vec3 col = surfAlbedo * diffuseLight * mix(1.0, 0.45, puddleMask);
    col += fuelBody * puddleMask * (0.30 + 0.42 * nearFire) * fireStr;

    vec3 specAsphalt = (rig.keyCol * specKey * 0.22 + rig.rimCol * specRim * 0.18) * mix(0.30, 1.25, wetMask);
    specAsphalt += fireCol * (specLine + specHeart) * fireStr * mix(0.22, 0.72, wetMask);

    float menSpec = ggxSpec(nPuddle, V, rig.keyDir, 0.065) * meniscusBand * 0.72;
    float menRim  = ggxSpec(nPuddle, V, rig.rimDir, 0.085) * meniscusBand * 0.55;
    vec3 meniscusGlint = (rig.keyCol * menSpec + rig.rimCol * menRim) * (1.0 - puddleMask * 0.30);

    col += specAsphalt * (1.0 - puddleMask * 0.70) + meniscusGlint;

    // --- 6. Smooth Banding-Free Volumetric Planar Reflection in Fuel Puddles ---
    float reflStrength = mix(wetMask * 0.20, 1.0, puddleMask);
    if (reflStrength > 0.02) {
        vec3 reflDir = reflect(rd, N);
        reflDir.y = max(reflDir.y, 0.004);
        reflDir = normalize(reflDir);

        vec3 reflBg = evalHangarBackground(reflDir, rig, time);
        vec4 reflVol = marchFireAndSmoke(p + vec3(0.0, 0.012, 0.0), reflDir, 0.02, 10.5, jitter, time, rig, true);
        vec3 reflCol = reflVol.rgb + reflBg * reflVol.a;

        vec3 oilTint = (uLightMode == 1) ? vec3(0.88) : vec3(1.05, 0.72, 0.44);
        reflCol *= mix(vec3(1.0), oilTint, puddleMask);

        float reflWeight = clamp(fresnel * 1.25 + 0.24 * puddleMask, 0.0, 0.90) * reflStrength;
        col = mix(col, reflCol, reflWeight * 0.72) + reflCol * reflWeight * 0.18;
    }

    // --- 7. Charred Glowing Embers Along the Narrow Napalm Trench ---
    float trenchEmber = exp(-pow(d / 0.09, 2.0)) * smoothstep(-2.4, -1.85, s) * (1.0 - smoothstep(1.95, 2.55, s));
    float emberNoise = smoothstep(0.36, 0.84, noise2(xz * 14.0 + vec2(0.0, time * 0.25)));
    vec3 emberCol = (uLightMode == 1) ? vec3(0.35) : vec3(1.0, 0.16, 0.006);
    col += emberCol * trenchEmber * emberNoise * 0.90 * flicker * rig.fireEmissionScale;

    float fog = 1.0 - exp(-dist * dist * 0.0055);
    col = mix(col, rig.ambHorizon, clamp(fog, 0.0, 0.85));

    return col;
}

// ----------------------------------------------------------------------------
// ACES Filmic Tonemapping
// ----------------------------------------------------------------------------
vec3 acesFilm(vec3 x) {
    const float a = 2.51;
    const float b = 0.03;
    const float c = 2.43;
    const float d = 0.59;
    const float e = 0.14;
    return clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0.0, 1.0);
}

// ----------------------------------------------------------------------------
// Main
// ----------------------------------------------------------------------------
void main() {
    vec2 uv = (gl_FragCoord.xy - 0.5 * uResolution) / min(uResolution.x, uResolution.y);
    float time = uTime;

    vec3 ro, ta;
    float fl;
    if (uCamMode == 1) {
        ro = vec3(0.88, 0.44, 2.32);
        ta = vec3(0.02, 0.46, 0.28);
        fl = 2.40;
    } else {
        ro = vec3(-0.30, 0.50, 3.85);
        ta = vec3(0.08, 0.94, -0.35);
        fl = 1.62;
    }

    ro.y += 0.003 * sin(time * 1.3);

    vec3 fw = normalize(ta - ro);
    vec3 rt = normalize(cross(fw, vec3(0.0, 1.0, 0.0)));
    vec3 up = cross(rt, fw);
    vec3 rd = normalize(fw * fl + rt * uv.x + up * uv.y);

    LightRig rig = getLightRig();
    float jitter = ign(gl_FragCoord.xy);

    float tGround = 1e5;
    bool hitGround = false;
    if (rd.y < -0.0004) {
        float tg = -ro.y / rd.y;
        if (tg > 0.01 && tg < 45.0) {
            tGround = tg;
            hitGround = true;
        }
    }

    vec3 sceneCol;
    if (hitGround) {
        vec3 pGround = ro + rd * tGround;
        sceneCol = shadeGround(pGround, rd, tGround, jitter, time, rig);
    } else {
        sceneCol = evalHangarBackground(rd, rig, time);
    }

    float tMaxVol = hitGround ? tGround : 14.0;
    vec4 vol = marchFireAndSmoke(ro, rd, 0.05, tMaxVol, jitter, time, rig, false);

    vec3 col = vol.rgb + sceneCol * vol.a;

    float exposure = (uLightMode == 1) ? 1.05 : 0.95;
    col = acesFilm(col * exposure);

    col = min(col, vec3(0.90) + (col - vec3(0.90)) * 0.45);
    col = clamp(col, 0.0, 0.98);
    col = max(col, vec3(0.00038));

    // Linear -> sRGB
    col = pow(col, vec3(1.0 / 2.2));

    float vig = 1.0 - 0.14 * dot(uv, uv);
    col *= clamp(vig, 0.84, 1.0);

    if (uLightMode == 1) {
        float g = dot(col, vec3(0.299, 0.587, 0.114));
        col = vec3(g);
    }

    fragColor = vec4(col, 1.0);
}

Mathematical models & shader specifications

Identifiernapalm-ground-fire-wall
CategoryGame VFX Shaders · Physically-Based VFX
Upstream studyvfx_realistic/lib/04_napalm_ground_fire_wall.glsl (commit afde0bc)
Animation cycleContinuous procedural uTime
Declared uniformsuResolution, uTime, uOpen, uLightMode, uCamMode
Source size980 lines · 40.7 KB standalone GLSL ES 3.00
PNG baker outputs512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key)
Companion pixel VFXFree MIT fire sprite sheets
LicenseMIT License + CC0 / MIT Helpers

Physical & shading models implemented

Voronoi/Worley cellular fields (Voronoi 1908; Worley 1996); GGX microfacet specular (Trowbridge–Reitz 1975; Walter et al. 2007); Schlick Fresnel reflectance (1994); Beer–Lambert volumetric absorption/attenuation; Henyey–Greenstein scattering phase function (1941); Planck blackbody radiation color approximation

Adapted upstream mathematical helpers

David Hoskins, hash · Krzysztof Narkowicz, filmic curve · Inigo Quilez, quadratic distance blend · Jorge Jimenez, Interleaved Gradient Noise

All game vfx shaders