Underwater Depth Charge Plume shader

underwater-depth-charge-plume.glsl · 1154 lines · GLSL ES 3.00 · MIT

Underwater Depth Charge PlumeGame VFX
Underwater Depth Charge Plume WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 1154 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
underwater-depth-charge-plume.glsl (1154 lines)
#version 300 es
// Underwater Depth Charge Plume (underwater-depth-charge-plume.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_realistic/lib/08_underwater_depth_charge_plume.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;

// ============================================================================
// 08_underwater_depth_charge_plume.glsl
// Photoreal maritime underwater depth charge detonation plume erupting from
// dark glossy choppy night ocean swells under a moody storm sky.
//
// Features:
//   - Deep stormy night sky with slate-blue storm cloud banks in upper-right
//   - Dark glossy choppy ocean waves (layered Gerstner swells + 3-scale
//     capillary fBM normals) with razor-sharp moonlight specular highlights,
//     subtle crest whitecaps, and eerie turquoise reflection across the troughs
//   - Organic flaring translucent seawater column rising continuously from the
//     ocean swells, with carved liquid flutes, deep turquoise subsurface Mie
//     scattering, and a focused luminous cyan-teal detonation core
//   - Multi-layered crisp 3D refractive underwater bubble cluster (dark
//     refractive interior rings, sharp Fresnel rims, specular glints, caustic
//     translucency, and micro-bubble spray)
//   - High-contrast 60-step volumetric sculpted seafoam crown with sharp torn
//     liquid tendrils, deep slate-blue shadow crevices, warm golden-ivory
//     backlit flash in the upper-right crevice, and clustered ballistic splash
//     droplets & sparks
//   - uLightMode: 0=hero stormy night, 1=pure neutral grayscale (R==G==B),
//     2=grazing raking key light, 3=backlit storm-moon rim light
//   - uCamMode: 0=hero maritime framing, 1=~2.5x macro close-up of cyan
//     subsurface bubble cavity & foaming water sheets
// ============================================================================

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

// ----------------------------------------------------------------------------
// Hash & Noise Primitives
// ----------------------------------------------------------------------------
float hash11(float p) {
    p = fract(p * 0.1031);
    p *= p + 33.33;
    p *= p + p;
    return fract(p);
}

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);
}

float noise2D(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 noise3D(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);

    return mix(mix(nx00, nx10, u.y), mix(nx01, nx11, u.y), u.z);
}

const mat2 ROT2 = 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 * noise2D(p);
        p = ROT2 * p * 2.07 + 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 * noise3D(p);
        p = p * 2.06 + vec3(13.7, 29.3, 19.1);
        p.xz = ROT2 * p.xz;
        a *= 0.5;
    }
    return v;
}

float fbm3Fast(vec3 p) {
    float v = 0.0;
    float a = 0.5;
    for (int i = 0; i < 3; i++) {
        v += a * noise3D(p);
        p = p * 2.11 + vec3(11.3, 23.7, 17.9);
        a *= 0.5;
    }
    return v;
}

// Ridged / billow turbulence for crisp torn liquid & seafoam structure
float ridged3(vec3 p) {
    float v = 0.0;
    float a = 0.5;
    for (int i = 0; i < 4; i++) {
        float n = 1.0 - abs(noise3D(p) * 2.0 - 1.0);
        v += a * n * n;
        p = p * 2.08 + vec3(7.3, 19.1, 13.7);
        p.xy = ROT2 * p.xy;
        a *= 0.5;
    }
    return v;
}

// ----------------------------------------------------------------------------
// SDF & Optical Helpers
// ----------------------------------------------------------------------------
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);
}

float sdTaperedCapsule(vec3 p, vec3 a, vec3 b, float ra, float rb) {
    vec3 pa = p - a, ba = b - a;
    float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);
    return length(pa - ba * h) - mix(ra, rb, h);
}

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

float schlickFresnel(float cosTheta, float f0) {
    return f0 + (1.0 - f0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
}

// ----------------------------------------------------------------------------
// Animation & Lighting Setup
// ----------------------------------------------------------------------------
float getSurge() {
    return 0.94 + 0.11 * sin(uTime * 1.45 - 0.15) + 0.08 * uOpen;
}

vec3 getCorePos() {
    float t = uTime;
    return vec3(
        0.02 * sin(t * 1.7),
        0.72 + 0.04 * sin(t * 1.45 - 0.2),
        0.06
    );
}

vec3 getFlashPos() {
    float t = uTime;
    return vec3(
        0.38 + 0.03 * sin(t * 2.0),
        1.98 + 0.06 * sin(t * 1.5),
        -0.18
    );
}

vec3 getKeyLightDir() {
    if (uLightMode == 2) {
        // Grazing raking key light from low left-front
        return normalize(vec3(-0.92, 0.24, 0.30));
    } else if (uLightMode == 3) {
        // Backlit storm-moon rim light from behind & above
        return normalize(vec3(0.18, 0.50, -0.84));
    } else if (uLightMode == 1) {
        // Crisp sculptural key for grayscale study
        return normalize(vec3(0.55, 0.65, 0.52));
    }
    // Hero stormy night moonlight from upper-right-back
    return normalize(vec3(0.45, 0.60, -0.66));
}

vec3 getKeyLightColor() {
    if (uLightMode == 1) return vec3(1.05);
    if (uLightMode == 2) return vec3(1.30, 1.35, 1.45);
    if (uLightMode == 3) return vec3(1.55, 1.75, 2.10);
    return vec3(0.95, 1.08, 1.28);
}

// ----------------------------------------------------------------------------
// Deep Moody Stormy Night Sky
// ----------------------------------------------------------------------------
vec3 evalSky(vec3 rd) {
    float elev = clamp(rd.y, -0.15, 1.0);

    // Deep maritime storm night (linear 0.0007..0.004 -> sRGB ~8..25/255)
    vec3 zenithCol  = vec3(0.0007, 0.0012, 0.0022);
    vec3 horizonCol = vec3(0.0020, 0.0038, 0.0062);
    if (uLightMode == 1) {
        zenithCol  = vec3(0.0035);
        horizonCol = vec3(0.0110);
    } else if (uLightMode == 2) {
        zenithCol  = vec3(0.0010, 0.0016, 0.0026);
        horizonCol = vec3(0.0035, 0.0052, 0.0078);
    } else if (uLightMode == 3) {
        zenithCol  = vec3(0.0010, 0.0020, 0.0040);
        horizonCol = vec3(0.0050, 0.0088, 0.0145);
    }

    vec3 col = mix(horizonCol, zenithCol, pow(clamp(elev * 1.5, 0.0, 1.0), 0.72));

    // Billowing slate-blue storm cloud banks concentrated in upper-right (matching 08.png)
    if (rd.y > -0.02) {
        vec2 cloudUV = rd.xz / (rd.y + 0.28);
        cloudUV += vec2(uTime * 0.014, -uTime * 0.008);
        float c1 = fbm2(cloudUV * 0.60 + vec2(1.4, 2.1));
        float c2 = fbm2(cloudUV * 1.40 - vec2(c1 * 0.85, 0.7));
        float cloud = smoothstep(0.34, 0.78, c1 * 0.65 + c2 * 0.45);

        float rightBank = smoothstep(-0.10, 0.58, rd.x) * smoothstep(0.06, 0.52, rd.y);
        vec3 cloudLit  = (uLightMode == 1) ? vec3(0.028) : vec3(0.016, 0.030, 0.044);
        vec3 cloudDark = (uLightMode == 1) ? vec3(0.004) : vec3(0.0009, 0.0018, 0.0032);

        col = mix(col, mix(cloudDark, cloudLit, rightBank * 0.88 + 0.12 * c2),
                  cloud * 0.85 * smoothstep(0.0, 0.14, rd.y));

        // Veiled moon / upper-right storm glow
        vec3 L = getKeyLightDir();
        float sunDot = max(dot(rd, L), 0.0);
        float moonHalo = pow(sunDot, 16.0) * 0.055 + pow(sunDot, 96.0) * 0.16;
        if (uLightMode == 3) {
            moonHalo = pow(sunDot, 10.0) * 0.18 + pow(sunDot, 56.0) * 0.65;
        } else if (uLightMode == 1) {
            moonHalo *= 0.30;
        }
        col += getKeyLightColor() * moonHalo * (1.0 - cloud * 0.55);
    }

    // Subtle warm backlit atmospheric glow behind the upper-right spray crown
    if (uLightMode == 0 || uLightMode == 3) {
        vec3 flashDir = normalize(getFlashPos() - vec3(0.0, 0.55, 5.2));
        float fd = max(dot(rd, flashDir), 0.0);
        float warmGlow = pow(fd, 28.0) * 0.12 + pow(fd, 120.0) * 0.18;
        col += vec3(0.85, 0.68, 0.42) * warmGlow * (uLightMode == 3 ? 0.35 : 0.70);
    }

    return col;
}

// ----------------------------------------------------------------------------
// Dark Glossy Choppy Ocean Surface + Concave Rising Skirt
// ----------------------------------------------------------------------------
float oceanWaveHeight(vec2 p, out float foamMask) {
    float t = uTime * 1.25;
    float h = 0.0;
    float crest = 0.0;

    // 5 directional choppy Gerstner-like wave trains
    vec2 d1 = normalize(vec2(0.84, 0.54));
    float ph1 = dot(p, d1) * 1.20 + t * 1.10;
    float w1 = sin(ph1);
    h += 0.14 * w1 + 0.045 * pow(0.5 + 0.5 * w1, 3.0);
    crest += pow(0.5 + 0.5 * w1, 5.0) * 0.45;

    vec2 d2 = normalize(vec2(-0.76, 0.65));
    float ph2 = dot(p, d2) * 1.85 - t * 1.45;
    float w2 = sin(ph2);
    h += 0.090 * w2 + 0.032 * pow(0.5 + 0.5 * w2, 3.0);
    crest += pow(0.5 + 0.5 * w2, 5.0) * 0.40;

    vec2 d3 = normalize(vec2(0.32, -0.95));
    h += 0.052 * sin(dot(p, d3) * 2.80 + t * 1.95);

    vec2 d4 = normalize(vec2(-0.91, -0.41));
    h += 0.028 * sin(dot(p, d4) * 4.40 - t * 2.40);

    // Prominent dark choppy foreground wave ridge in lower-right (framing anchor)
    vec2 fgP = p - vec2(1.25, 2.95);
    float fgWave = exp(-dot(fgP * vec2(0.75, 1.35), fgP * vec2(0.75, 1.35)) * 0.55);
    h += 0.21 * fgWave * (0.78 + 0.22 * sin(p.x * 3.2 + t));
    crest += fgWave * 0.15;

    // Breaking left side swell crest (matching 08.png left whitecap)
    vec2 lwP = p - vec2(-2.25, 0.65);
    float leftWave = exp(-dot(lwP * vec2(0.85, 1.4), lwP * vec2(0.85, 1.4)) * 0.65);
    h += 0.17 * leftWave;

    // Radial shockwave displacement rings radiating from the eruption center
    float r = length(p);
    h += 0.055 * sin(r * 4.8 - uTime * 3.8) * exp(-r * 0.40);

    // Multi-scale crisp capillary chop
    float chop1 = fbm2(p * 1.85 + vec2(t * 0.35, -t * 0.25)) - 0.5;
    float chop2 = fbm2(p * 4.80 - vec2(t * 0.65, t * 0.45)) - 0.5;
    h += chop1 * 0.11 + chop2 * 0.035;

    // Smooth concave rising hydrodynamic skirt seamlessly lifting waves into column
    float ang = atan(p.y, p.x);
    float flutes = 0.06 * sin(ang * 7.0 + uTime * 0.8) + 0.04 * cos(ang * 13.0 - uTime * 1.2);
    float rEff = max(r + flutes * smoothstep(2.0, 0.7, r), 0.001);
    float skirt = 0.58 * exp(-rEff * rEff * 0.75) * getSurge();
    h += skirt;

    // Subtle wispy breaking seafoam ONLY on sharpest wave crests & thin collar streaks
    float foamN = fbm2(p * 3.8 + vec2(-t * 0.45, t * 0.32));
    float crestFoam = smoothstep(0.78, 0.98, crest + foamN * 0.38) * smoothstep(0.42, 0.75, foamN);
    float leftCrest = leftWave * smoothstep(0.45, 0.75, foamN) * 0.85;
    float collarStreaks = smoothstep(1.35, 0.78, r) * smoothstep(0.58, 0.86, foamN) * 0.45;
    foamMask = clamp(crestFoam * 0.65 + leftCrest + collarStreaks, 0.0, 1.0);

    return h;
}

float oceanHeightSimple(vec2 p) {
    float dummy;
    return oceanWaveHeight(p, dummy);
}

vec3 oceanNormal(vec2 p) {
    float e = 0.020;
    float hc = oceanHeightSimple(p);
    float hx = oceanHeightSimple(p + vec2(e, 0.0));
    float hz = oceanHeightSimple(p + vec2(0.0, e));
    vec3 N = normalize(vec3(hc - hx, e, hc - hz));

    // Add fine micro-ripple normal perturbation for wet glossy ocean sheen
    float t = uTime * 1.4;
    float r1 = noise2D(p * 11.0 + vec2(t, -t * 0.7)) - 0.5;
    float r2 = noise2D(p * 11.0 + vec2(t + 3.1, -t * 0.7 + 5.7)) - 0.5;
    N = normalize(N + vec3(r1, 0.0, r2) * 0.16);
    return N;
}

float traceOcean(vec3 ro, vec3 rd, float tMax) {
    if (rd.y > 0.08 && ro.y > 1.25) return -1.0;

    float t = 0.15;
    float prevT = t;

    for (int i = 0; i < 68; i++) {
        vec3 p = ro + rd * t;
        float h = p.y - oceanHeightSimple(p.xz);
        if (h < 0.0) {
            float a = prevT;
            float b = t;
            for (int j = 0; j < 6; j++) {
                float m = 0.5 * (a + b);
                vec3 pm = ro + rd * m;
                if (pm.y - oceanHeightSimple(pm.xz) < 0.0) b = m;
                else a = m;
            }
            return 0.5 * (a + b);
        }
        prevT = t;
        float stepSz = max(0.038, h * 0.38 + t * 0.020);
        t += stepSz;
        if (t > tMax) break;
    }
    return -1.0;
}

// ----------------------------------------------------------------------------
// Organic Flaring Translucent Water Column & Torn Liquid Crown SDF
// ----------------------------------------------------------------------------
float sdWaterColumn(vec3 p) {
    float surge = getSurge();
    float t = uTime;

    // Continuous hourglass/flare profile:
    //   y=0.0: wide smooth skirt (r ~ 1.45) merging with ocean waves
    //   y=0.75: pinched turbulent waist (r ~ 0.76) around the glowing cavity
    //   y=1.45: flaring raggedly outward into torn liquid sheets (r ~ 1.08)
    float y = clamp(p.y, -0.1, 2.2);
    float baseFlare = 0.78 * exp(-max(y, 0.0) * 2.55);
    float topFlare  = 0.34 * pow(max(y - 0.65, 0.0), 1.55);
    float profileR  = (0.74 + baseFlare + topFlare) * (0.94 + 0.06 * surge);

    // Carved vertical hydrodynamic flutes & swirling liquid ribs
    float ang = atan(p.z, p.x);
    float flutes = 0.085 * sin(ang * 5.0 + y * 1.2 - t * 0.9)
                 + 0.055 * cos(ang * 9.0 - y * 2.4 + t * 1.5)
                 + 0.032 * sin(ang * 15.0 + y * 3.8 - t * 2.1);

    // High-frequency advected turbulent liquid surface relief
    vec3 advP = p - vec3(0.0, t * 1.15, 0.0);
    float turb = (fbm3Fast(advP * 2.4) - 0.5) * 0.28
               + (ridged3(advP * 3.6) - 0.5) * 0.14;

    float r = length(p.xz);
    float dSides = r - (profileR + flutes + turb);

    // Organic jagged crown lip at top (NO flat horizontal plane!)
    // Tapers irregularly into torn liquid peaks around y = 1.35..1.95
    float crownRimH = (1.42 + 0.38 * sin(ang * 3.0 + 0.6) + 0.22 * cos(ang * 7.0 - 0.8)
                     + turb * 1.15) * surge;
    // Deep recessed hollow bowl in front-upper center so bubbles & glow shine through
    float frontDip = 0.28 * smoothstep(-0.2, 0.8, p.z) * exp(-p.x * p.x * 1.6);
    float dTop = p.y - (crownRimH - frontDip);

    // Smooth blend between sides and torn top rim so there is zero hard cube edge
    float d = -smin(-dSides, -dTop, 0.26);
    d = max(d, -p.y - 0.18);

    return d * 0.68;
}

vec3 calcColumnNormal(vec3 p) {
    vec2 e = vec2(0.012, 0.0);
    vec3 N = normalize(vec3(
        sdWaterColumn(p + e.xyy) - sdWaterColumn(p - e.xyy),
        sdWaterColumn(p + e.yxy) - sdWaterColumn(p - e.yxy),
        sdWaterColumn(p + e.yyx) - sdWaterColumn(p - e.yyx)
    ));
    // Crisp high-frequency liquid ripple micro-normal
    vec3 adv = p * 5.8 - vec3(0.0, uTime * 2.2, 0.0);
    float nx = noise3D(adv + vec3(0.2, 0.0, 0.0)) - noise3D(adv - vec3(0.2, 0.0, 0.0));
    float ny = noise3D(adv + vec3(0.0, 0.2, 0.0)) - noise3D(adv - vec3(0.0, 0.2, 0.0));
    float nz = noise3D(adv + vec3(0.0, 0.0, 0.2)) - noise3D(adv - vec3(0.0, 0.0, 0.2));
    return normalize(N + vec3(nx, ny, nz) * 0.28);
}

float traceWaterColumn(vec3 ro, vec3 rd, float tMax) {
    vec3 oc = ro - vec3(0.0, 0.90, 0.0);
    float b = dot(oc, rd);
    float c = dot(oc, oc) - 2.05 * 2.05;
    float h = b * b - c;
    if (h < 0.0) return -1.0;
    h = sqrt(h);
    float tStart = max(0.05, -b - h);
    float tEnd   = min(tMax, -b + h);
    if (tStart >= tEnd) return -1.0;

    float t = tStart;
    for (int i = 0; i < 56; i++) {
        vec3 p = ro + rd * t;
        float d = sdWaterColumn(p);
        if (d < 0.005) return t;
        t += max(d, 0.016);
        if (t > tEnd) break;
    }
    return -1.0;
}

// ----------------------------------------------------------------------------
// Multi-Layered Crisp 3D Underwater Bubble Cluster
// ----------------------------------------------------------------------------
float sdBubbleCluster(vec3 p, out vec3 bCenter, out float bRad, out float bLayer) {
    float t = uTime;
    float rise = 0.045 * sin(t * 1.6);
    float bestD = 1e5;
    bCenter = vec3(0.0);
    bRad = 0.1;
    bLayer = 0.0;

    // 22 varied-size crisp bubbles: hero foreground cluster + iconic rim bubble + satellites
    vec4 bubbles[22];
    // Core hero cluster (matching 08.png focal cluster)
    bubbles[0]  = vec4(-0.08, 0.79 + rise,        0.54, 0.148); // Hero central-left bubble
    bubbles[1]  = vec4( 0.14, 0.64 + rise * 0.85, 0.58, 0.125); // Hero lower-right
    bubbles[2]  = vec4( 0.00, 0.54 + rise * 1.05, 0.60, 0.095); // Bottom-center
    bubbles[3]  = vec4(-0.18, 0.56 + rise * 0.90, 0.53, 0.088); // Lower-left
    bubbles[4]  = vec4( 0.28, 0.63 + rise * 0.75, 0.52, 0.082); // Mid-right
    bubbles[5]  = vec4(-0.27, 0.73 + rise * 1.15, 0.45, 0.078); // Left flank
    bubbles[6]  = vec4( 0.09, 0.87 + rise * 1.25, 0.49, 0.072); // Upper-center
    bubbles[7]  = vec4( 0.25, 0.78 + rise * 1.00, 0.47, 0.066); // Upper-right
    // Iconic large glass bubble perched on the outer right silhouette flank
    bubbles[8]  = vec4( 0.84, 1.02 + rise * 0.90, 0.18, 0.132);
    // Medium & small satellite bubbles embedded around the translucent cavity
    bubbles[9]  = vec4(-0.12, 0.98 + rise * 1.35, 0.42, 0.056);
    bubbles[10] = vec4( 0.39, 0.72 + rise * 1.10, 0.40, 0.054);
    bubbles[11] = vec4(-0.36, 0.62 + rise * 0.80, 0.38, 0.056);
    bubbles[12] = vec4( 0.06, 0.44 + rise * 0.65, 0.58, 0.048);
    bubbles[13] = vec4(-0.04, 0.66 + rise * 1.00, 0.64, 0.042);
    bubbles[14] = vec4( 0.46, 0.89 + rise * 1.20, 0.34, 0.048);
    bubbles[15] = vec4(-0.24, 0.89 + rise * 1.30, 0.42, 0.046);
    // Fine sparkling micro-bubbles for macro close-up richness
    bubbles[16] = vec4( 0.19, 0.50 + rise * 0.95, 0.62, 0.036);
    bubbles[17] = vec4(-0.14, 0.47 + rise * 0.75, 0.57, 0.034);
    bubbles[18] = vec4( 0.33, 0.55 + rise * 0.85, 0.50, 0.038);
    bubbles[19] = vec4(-0.32, 0.82 + rise * 1.15, 0.40, 0.035);
    bubbles[20] = vec4( 0.02, 0.95 + rise * 1.40, 0.46, 0.034);
    bubbles[21] = vec4( 0.54, 0.79 + rise * 1.05, 0.28, 0.042);

    for (int i = 0; i < 22; i++) {
        vec3 c = bubbles[i].xyz;
        float fi = float(i);
        c.x += 0.012 * sin(t * 2.0 + fi * 1.7);
        c.y += 0.020 * sin(t * 1.7 + fi * 2.3);
        float r = bubbles[i].w * (0.97 + 0.05 * sin(t * 2.3 + fi));
        // Slight organic wobble on the largest bubbles
        float wobble = 0.004 * sin(p.x * 24.0 + p.y * 19.0 + fi);
        float d = length(p - c) - r + wobble;
        if (d < bestD) {
            bestD = d;
            bCenter = c;
            bRad = r;
            bLayer = fi / 22.0;
        }
    }
    return bestD;
}

float traceBubbles(vec3 ro, vec3 rd, float tMax, out vec3 bCenter, out float bRad, out float bLayer) {
    bCenter = vec3(0.0);
    bRad = 0.1;
    bLayer = 0.0;
    vec3 oc = ro - vec3(0.10, 0.76, 0.40);
    float b = dot(oc, rd);
    float c = dot(oc, oc) - 1.25 * 1.25;
    float h = b * b - c;
    if (h < 0.0) return -1.0;
    h = sqrt(h);
    float tStart = max(0.05, -b - h);
    float tEnd   = min(tMax, -b + h);
    if (tStart >= tEnd) return -1.0;

    float t = tStart;
    for (int i = 0; i < 44; i++) {
        vec3 p = ro + rd * t;
        float d = sdBubbleCluster(p, bCenter, bRad, bLayer);
        if (d < 0.0025) return t;
        t += max(d, 0.010);
        if (t > tEnd) break;
    }
    return -1.0;
}

// ----------------------------------------------------------------------------
// Crisp Sculpted Volumetric Seafoam Crown & Torn Spray Tendrils
// ----------------------------------------------------------------------------
float samplePlumeDensity(vec3 p, out float foamRidge) {
    float surge = getSurge();
    float t = uTime;

    if (p.y < 0.65 || p.y > 3.80 || length(p.xz) > 2.45) {
        foamRidge = 0.0;
        return 0.0;
    }

    // Advect upward & radially outward for eruptive spray motion
    vec3 radial = vec3(p.x, 0.0, p.z);
    float radLen = length(radial) + 1e-4;
    vec3 advP = p - vec3(0.0, t * 1.20, 0.0)
                  - (radial / radLen) * (t * 0.28 * smoothstep(0.9, 2.6, p.y));

    // Strong multi-scale domain warp to tear shapes into jagged liquid tendrils
    vec3 warp = vec3(
        fbm3Fast(advP * 1.55 + vec3(0.0, 2.3, 1.1)),
        fbm3Fast(advP * 1.55 + vec3(4.7, 0.8, 3.2)),
        fbm3Fast(advP * 1.55 + vec3(2.1, 5.4, 0.5))
    ) - 0.5;
    vec3 q = p + warp * 0.44;

    // Asymmetric dramatic jagged crown matching 08.png:
    // 1. Tall jagged central spire reaching near top of frame
    float dSpire1 = sdTaperedCapsule(q, vec3(-0.10, 1.38, -0.02), vec3(-0.08, 3.32 * surge, -0.06), 0.54, 0.08);
    float dSpire2 = sdTaperedCapsule(q, vec3(-0.18, 2.05, 0.02),  vec3(-0.48, 2.98 * surge, 0.05),  0.34, 0.09);

    // 2. Dense warm-lit upper-right central billow
    float dCoreCloud = sdTaperedCapsule(q, vec3(0.26, 1.50, -0.05), vec3(0.36, 2.42 * surge, -0.10), 0.52, 0.22);

    // 3. Dramatic sweeping left wing curling outward and upward into ragged tips
    float dLeftArc1 = sdTaperedCapsule(q, vec3(-0.42, 1.48, 0.04), vec3(-1.35 * surge, 2.12 * surge, 0.10), 0.44, 0.14);
    float dLeftArc2 = sdTaperedCapsule(q, vec3(-1.18 * surge, 2.05 * surge, 0.08), vec3(-1.72 * surge, 2.68 * surge, 0.12), 0.22, 0.06);
    float dLeftCurtain = sdTaperedCapsule(q, vec3(-0.68, 1.25, 0.06), vec3(-1.26, 1.68, 0.14), 0.34, 0.14);

    // 4. Crisp right billowing crown wing with hooked outer spray crest
    float dRightWing1 = sdTaperedCapsule(q, vec3(0.46, 1.42, 0.02), vec3(1.22 * surge, 2.05 * surge, 0.06), 0.46, 0.18);
    float dRightWing2 = sdTaperedCapsule(q, vec3(1.02 * surge, 1.92 * surge, 0.05), vec3(1.56 * surge, 2.34 * surge, 0.08), 0.24, 0.08);

    // 5. Turbulent foaming collar wrapping the upper rim of the water column
    float dCollarL = sdTaperedCapsule(q, vec3(-0.68, 1.08, 0.02), vec3(-0.45, 1.62, 0.02), 0.38, 0.34);
    float dCollarR = sdTaperedCapsule(q, vec3( 0.68, 1.08, 0.02), vec3( 0.48, 1.62, 0.02), 0.38, 0.34);
    float dCollarB = sdTaperedCapsule(q, vec3( 0.00, 1.25, -0.22), vec3(0.00, 1.75, -0.15), 0.68, 0.56);

    float d = smin(dSpire1, dSpire2, 0.20);
    d = smin(d, dCoreCloud, 0.22);
    d = smin(d, dLeftArc1, 0.22);
    d = smin(d, dLeftArc2, 0.14);
    d = smin(d, dLeftCurtain, 0.18);
    d = smin(d, dRightWing1, 0.22);
    d = smin(d, dRightWing2, 0.15);
    d = smin(d, dCollarL, 0.20);
    d = smin(d, dCollarR, 0.20);
    d = smin(d, dCollarB, 0.22);

    // Keep the front-center glowing bubble cavity crystal clear!
    float cavityClear = length((p - vec3(0.02, 0.80, 0.48)) * vec3(1.05, 1.12, 0.90)) - 0.78;
    d = max(d, -cavityClear);

    // Crisp high-frequency ridged + billow erosion (produces torn seafoam & lacy spray!)
    float billow = fbm3(advP * 2.55);
    float ridge  = ridged3(advP * 4.40 + vec3(1.9, -t * 1.3, 3.1));
    float fine   = noise3D(advP * 9.50 - vec3(0.0, t * 2.2, 0.0));

    float shapeMask = smoothstep(0.18, -0.22, d);
    float carved = shapeMask * 1.42 - (1.0 - billow) * 0.58 - (1.0 - ridge) * 0.36 - (1.0 - fine) * 0.14;

    // Sharp opaque foam core + delicate misty outer halo
    float solidFoam = smoothstep(0.10, 0.34, carved);
    float lacyMist  = smoothstep(-0.08, 0.24, carved) * 0.22;

    foamRidge = clamp(ridge * 0.7 + fine * 0.3, 0.0, 1.0);
    return clamp(solidFoam + lacyMist, 0.0, 1.0);
}

float samplePlumeShadow(vec3 p) {
    float dummy;
    return samplePlumeDensity(p, dummy);
}

// ----------------------------------------------------------------------------
// Shading: Dark Glossy Choppy Ocean
// ----------------------------------------------------------------------------
vec3 shadeOcean(vec3 p, vec3 N, vec3 V, float foamMask) {
    vec3 L = getKeyLightDir();
    vec3 keyCol = getKeyLightColor();
    vec3 corePos = getCorePos();

    float NdotV = max(dot(N, V), 0.001);
    float fres = schlickFresnel(NdotV, 0.02);
    vec3 R = reflect(-V, N);
    R.y = max(R.y, 0.015);
    vec3 skyRefl = evalSky(R);

    // Very dark glossy deep-ocean body
    vec3 deepWater = (uLightMode == 1)
        ? vec3(0.009)
        : vec3(0.0008, 0.0028, 0.0044);
    vec3 tealBase = (uLightMode == 1)
        ? vec3(0.024)
        : vec3(0.003, 0.026, 0.032);

    vec3 toCore = corePos - p;
    float dCore = length(toCore);
    vec3 Lcore = toCore / max(dCore, 0.001);

    float glowScale = (uLightMode == 1) ? 0.12 : (uLightMode == 2 ? 0.42 : 1.0);
    vec3 cyanCol = (uLightMode == 1) ? vec3(0.55) : vec3(0.02, 0.82, 0.78);

    // Shimmering turquoise reflection of the glowing core across dark foreground waves
    vec3 Hcore = normalize(Lcore + V);
    float specCore = pow(max(dot(N, Hcore), 0.0), 42.0) * 1.15
                   + pow(max(dot(N, Hcore), 0.0), 10.0) * 0.22;
    float coreAtten = 1.0 / (1.0 + 0.48 * dCore * dCore);
    float corridor = exp(-p.x * p.x * 0.85) * smoothstep(-0.3, 0.9, p.z);
    vec3 cyanRefl = cyanCol * (specCore * 0.78 + 0.07 * corridor) * coreAtten * glowScale;

    // Subtle subsurface glow inside the rising water skirt right around the base
    float skirtProx = exp(-length(p.xz) * 1.25);
    vec3 waterBody = mix(deepWater, tealBase, skirtProx)
                   + cyanCol * 0.12 * exp(-dCore * 1.45) * glowScale;

    // Razor-sharp silvery moonlight glints on wave crests & right base of skirt
    vec3 Hkey = normalize(L + V);
    float specSharp = pow(max(dot(N, Hkey), 0.0), 220.0) * 2.6;
    float specMed   = pow(max(dot(N, Hkey), 0.0), 36.0) * 0.18;

    // Signature bright moonlight sheen sweeping down the right base of the rising skirt
    float rightSheen = smoothstep(0.20, 1.05, p.x) * exp(-abs(length(p.xz) - 1.05) * 2.4)
                     * pow(1.0 - NdotV, 2.4) * (0.55 + 0.45 * max(dot(N, Hkey), 0.0));
    vec3 keySpec = keyCol * (specSharp + specMed + rightSheen * (uLightMode == 1 ? 0.45 : 0.72));

    // Grazing crest rim illumination on dark foreground swells
    float NdotL = max(dot(N, L), 0.0);
    vec3 diffWater = waterBody * (0.40 + 0.75 * NdotL * keyCol);

    vec3 col = mix(diffWater, skyRefl * 1.45, clamp(fres * 0.88 + 0.04, 0.0, 0.92));
    col += keySpec + cyanRefl;

    // Crisp wispy white breaking seafoam on selected wave crests only
    if (foamMask > 0.01) {
        vec3 foamAlbedo = (uLightMode == 1) ? vec3(0.32) : vec3(0.34, 0.44, 0.52);
        vec3 foamLit = foamAlbedo * (0.22 + 0.95 * NdotL * keyCol)
                     + cyanCol * 0.14 * coreAtten * glowScale;
        col = mix(col, foamLit, foamMask * 0.72);
    }

    // Dark maritime horizon fog
    float dist = length(p);
    float fog = 1.0 - exp(-max(dist - 5.2, 0.0) * 0.085);
    vec3 fogCol = evalSky(normalize(vec3(-V.x, 0.02, -V.z)));
    col = mix(col, fogCol, clamp(fog, 0.0, 0.90));

    return col;
}

// ----------------------------------------------------------------------------
// Shading: Translucent Turquoise-Green Water Column & Focused Cyan Core
// ----------------------------------------------------------------------------
vec3 shadeWaterColumn(vec3 p, vec3 N, vec3 V) {
    vec3 L = getKeyLightDir();
    vec3 keyCol = getKeyLightColor();
    vec3 corePos = getCorePos();
    float glowScale = (uLightMode == 1) ? 0.12 : (uLightMode == 2 ? 0.42 : 1.0);

    float NdotV = max(dot(N, V), 0.001);
    float fres = schlickFresnel(NdotV, 0.03);

    vec3 toCore = corePos - p;
    float dCore = length(toCore);
    vec3 Lcore = toCore / max(dCore, 0.001);

    // Deep dark emerald-slate outer water -> focused luminous cyan-teal center!
    float radialCore = exp(-dCore * dCore * 3.4);
    float frontWindow = smoothstep(-0.35, 0.55, p.z);
    float thickness = 0.45 + 1.45 * (1.0 - radialCore);
    vec3 absorb = (uLightMode == 1)
        ? vec3(exp(-thickness * 1.15))
        : exp(-thickness * vec3(2.8, 0.52, 0.45));

    vec3 cyanCore = (uLightMode == 1)
        ? vec3(0.55)
        : vec3(0.05, 1.08, 0.96);

    float hg = hgPhase(dot(-V, Lcore), 0.58);
    vec3 subsurface = cyanCore * absorb
                    * (radialCore * (1.85 + 1.10 * frontWindow) + 0.45 * hg * exp(-dCore * 1.35))
                    * glowScale;

    // Deep moody sea-teal body on outer flanks (contrasts strongly with bright core!)
    vec3 darkSea = (uLightMode == 1)
        ? vec3(0.018)
        : vec3(0.003, 0.022, 0.028);
    float NdotL = max(dot(N, L), 0.0);
    vec3 litBody = darkSea * (0.35 + 0.95 * NdotL * keyCol) + subsurface;

    // Wet specular & Fresnel sky reflection on turbulent water flutes
    vec3 R = reflect(-V, N);
    vec3 skyRefl = evalSky(R);
    vec3 H = normalize(L + V);
    float spec = pow(max(dot(N, H), 0.0), 128.0) * 1.85
               + pow(max(dot(N, H), 0.0), 22.0) * 0.16;

    // Frothy white seafoam lace clinging to the torn upper rim & fluted ridges
    vec3 advP = p * 4.2 - vec3(0.0, uTime * 1.8, 0.0);
    float lace = ridged3(advP);
    float upperFoam = smoothstep(0.95, 1.52, p.y) * smoothstep(0.42, 0.76, lace);
    float flankSpray = smoothstep(0.52, 0.85, abs(p.x)) * smoothstep(0.50, 0.82, lace) * smoothstep(0.35, 1.10, p.y) * 0.65;
    float foamAmt = clamp(upperFoam + flankSpray, 0.0, 1.0);

    vec3 foamCol = ((uLightMode == 1) ? vec3(0.55) : vec3(0.62, 0.74, 0.84))
                 * (0.24 + 0.95 * NdotL * keyCol)
                 + cyanCore * 0.28 * radialCore * glowScale;

    vec3 col = mix(litBody, skyRefl * 1.40 + keyCol * 0.12, fres * 0.72);
    col += keyCol * spec;
    if (uLightMode == 3) {
        col += keyCol * pow(1.0 - NdotV, 3.2) * 0.85;
    }
    col = mix(col, foamCol, foamAmt * 0.78);
    return col;
}

// ----------------------------------------------------------------------------
// Shading: Crisp Refractive Glass-Like Underwater Bubbles
// ----------------------------------------------------------------------------
vec3 shadeBubble(vec3 p, vec3 bCenter, float bRad, float bLayer, vec3 V, vec3 bgCol) {
    vec3 N = normalize(p - bCenter);
    vec3 L = getKeyLightDir();
    vec3 keyCol = getKeyLightColor();
    vec3 corePos = getCorePos();
    float glowScale = (uLightMode == 1) ? 0.14 : (uLightMode == 2 ? 0.48 : 1.0);

    float NdotV = max(dot(N, V), 0.001);
    float fres = schlickFresnel(NdotV, 0.05);

    vec3 toCore = corePos - p;
    float dCore = length(toCore);
    vec3 Lcore = toCore / max(dCore, 0.001);

    // Classic underwater air bubble optics (matching 08.png):
    //   1. Refracted dark teal-emerald interior (not flat pastel!)
    //   2. Dark total-internal-reflection ring near the outer third
    //   3. Focused bright cyan caustic crescent on the core-facing side
    //   4. Razor-sharp bright specular rim & crisp white glint on top-left
    vec3 cyanGlow = (uLightMode == 1) ? vec3(0.75) : vec3(0.10, 1.05, 0.96);
    float coreProx = exp(-dCore * dCore * 2.8);

    // Refracted interior is darker than the glowing backdrop, giving crisp 3D depth
    vec3 darkRefract = (uLightMode == 1)
        ? vec3(0.035)
        : vec3(0.008, 0.075, 0.088);
    float tirRing = smoothstep(0.62, 0.24, NdotV) * smoothstep(0.06, 0.24, NdotV);

    // Bright backlit caustic transmission in the center/lower-core side
    float coreAlign = max(dot(-N, Lcore), 0.0);
    float caustic = pow(NdotV, 1.2) * (0.35 + 0.85 * coreAlign) * (0.45 + 0.95 * coreProx);

    vec3 interior = mix(darkRefract, bgCol * 0.72, 0.45);
    interior = mix(interior, cyanGlow * (0.75 + 0.95 * coreProx) * glowScale, clamp(caustic * 0.72, 0.0, 0.85));
    // Deepen the TIR ring so every bubble pops with crisp glass separation!
    interior *= (1.0 - 0.72 * tirRing);

    // Sharp specular highlights (moonlight + upper-left studio glint + core reflection)
    vec3 Hkey = normalize(L + V);
    float spec1 = pow(max(dot(N, Hkey), 0.0), 180.0) * 2.8;
    vec3 Lglint = normalize(vec3(-0.45, 0.72, 0.52));
    vec3 Hglint = normalize(Lglint + V);
    float spec2 = pow(max(dot(N, Hglint), 0.0), 120.0) * 1.45;

    // Razor-sharp Fresnel rim highlight
    float sharpRim = pow(1.0 - NdotV, 3.6);
    vec3 rimCol = mix(cyanGlow * glowScale * 1.05, keyCol * 1.45, 0.52);

    vec3 col = mix(interior, rimCol, clamp(fres * 1.35 + sharpRim * 0.45, 0.0, 0.94));
    col += keyCol * (spec1 + spec2 * 0.65);
    return col;
}

// ----------------------------------------------------------------------------
// High-Contrast 60-Step Volumetric Seafoam Crown Raymarch
// ----------------------------------------------------------------------------
void marchVolumetricPlume(
    vec3 ro, vec3 rd, float tMax, float jitter,
    out vec3 volLight, out float transmittance
) {
    volLight = vec3(0.0);
    transmittance = 1.0;

    vec3 bCenter = vec3(0.0, 1.98, 0.0);
    vec3 oc = ro - bCenter;
    float b = dot(oc, rd);
    float c = dot(oc, oc) - 2.55 * 2.55;
    float h = b * b - c;
    if (h < 0.0) return;
    h = sqrt(h);

    float tStart = max(0.08, -b - h);
    float tEnd   = min(tMax, -b + h);
    if (tStart >= tEnd) return;

    const int STEPS = 60;
    float dt = (tEnd - tStart) / float(STEPS);
    float t = tStart + dt * jitter;

    vec3 Lkey     = getKeyLightDir();
    vec3 keyCol   = getKeyLightColor();
    vec3 corePos  = getCorePos();
    vec3 flashPos = getFlashPos();

    float glowScale  = (uLightMode == 1) ? 0.10 : (uLightMode == 2 ? 0.40 : 1.0);
    float flashScale = (uLightMode == 1) ? 0.08 : (uLightMode == 2 ? 0.25 : (uLightMode == 3 ? 0.55 : 1.0));

    vec3 cyanLight  = (uLightMode == 1) ? vec3(0.60) : vec3(0.04, 0.95, 0.88);
    vec3 flashLight = (uLightMode == 1) ? vec3(0.85) : vec3(1.65, 1.30, 0.82);

    float cosKey = dot(rd, Lkey);
    float phaseKey = mix(hgPhase(cosKey, 0.62), hgPhase(cosKey, -0.18), 0.30);
    if (uLightMode == 3) {
        phaseKey = hgPhase(cosKey, 0.76) * 1.55 + 0.06;
    }

    // Deep moody cool storm shadow ambient so foam billows have rich 3D contrast
    vec3 ambTop = (uLightMode == 1) ? vec3(0.065) : vec3(0.032, 0.052, 0.082);
    vec3 ambBot = (uLightMode == 1) ? vec3(0.018) : vec3(0.008, 0.018, 0.030);

    for (int i = 0; i < STEPS; i++) {
        if (transmittance < 0.012) break;

        vec3 p = ro + rd * t;
        float foamRidge;
        float dens = samplePlumeDensity(p, foamRidge);

        if (dens > 0.005) {
            // 4-tap directional self-shadowing toward key light for crisp billow relief
            float shOpt = 0.0;
            shOpt += samplePlumeShadow(p + Lkey * 0.14) * 0.25;
            shOpt += samplePlumeShadow(p + Lkey * 0.34) * 0.38;
            shOpt += samplePlumeShadow(p + Lkey * 0.64) * 0.45;
            shOpt += samplePlumeShadow(p + Lkey * 1.05) * 0.50;
            float keyShadow = exp(-shOpt * 3.4);
            float powder = 1.0 - 0.65 * exp(-dens * 5.2);

            // 1. Sculptural moonlight / raking / backlit key illumination
            vec3 lightKey = keyCol * keyShadow * (0.32 + 3.4 * phaseKey) * powder;

            // 2. Warm golden-ivory backlit flash tucked in upper-right spray crevice
            vec3 toFlash = flashPos - p;
            float dFlash = length(toFlash);
            float flashAtten = exp(-dFlash * dFlash * 2.15) / (0.28 + 0.65 * dFlash * dFlash);
            vec3 lightFlash = flashLight * flashAtten * 1.75 * flashScale;

            // 3. Upward cyan-teal subsurface bounce illuminating the lower foam skirt
            vec3 toCore = corePos - p;
            float dCore = length(toCore);
            float coreAtten = exp(-dCore * 1.45) / (0.35 + 0.75 * dCore * dCore);
            float underside = smoothstep(2.25, 0.90, p.y);
            vec3 lightCyan = cyanLight * coreAtten * underside * 1.55 * glowScale;

            // 4. Cool storm-sky shadow fill modulated by internal ridge depth
            float hGrad = clamp((p.y - 0.8) / 2.6, 0.0, 1.0);
            vec3 lightAmb = mix(ambBot, ambTop, hGrad) * (0.55 + 0.75 * foamRidge);

            // Albedo: crisp white seafoam ridges with darker wet-spray crevices
            vec3 albedo = (uLightMode == 1)
                ? vec3(mix(0.62, 0.92, foamRidge))
                : mix(vec3(0.58, 0.68, 0.78), vec3(0.92, 0.96, 1.00), foamRidge);

            vec3 stepCol = albedo * (lightKey + lightFlash + lightCyan + lightAmb);

            // Higher extinction for crisp opaque torn seafoam (not blurry fog!)
            float sigma = dens * 12.5;
            float alpha = 1.0 - exp(-sigma * dt);
            volLight += transmittance * stepCol * alpha;
            transmittance *= (1.0 - alpha);
        }

        t += dt;
    }
}

// ----------------------------------------------------------------------------
// Clustered Directional Splash Droplets & Warm Incandescent Sparks
// (Tightly anchored to erupting splash tendrils — ZERO uniform background snow!)
// ----------------------------------------------------------------------------
vec3 evalSplashDropletsAndSparks(vec3 ro, vec3 rd, float tLimit) {
    vec3 acc = vec3(0.0);
    float t = uTime;
    float surge = getSurge();
    float glowScale = (uLightMode == 1) ? 0.12 : 1.0;

    float tHit = (0.04 - ro.z) / rd.z;
    if (tHit <= 0.1 || tHit >= tLimit) return acc;

    vec3 p = ro + rd * tHit;
    if (p.y < 0.45 || p.y > 4.0 || abs(p.x) > 2.8) return acc;

    // 1. Directional ballistic splash droplets clustered along the crown ejection arcs
    vec2 origin = vec2(-0.04, 1.55);
    vec2 rel = p.xy - origin;
    float r = length(rel);
    float ang = atan(rel.y, rel.x);

    // Only emit droplets near the actual splash tendrils (angular lobes matching crown wings)
    float lobeL = exp(-pow(ang - 2.38, 2.0) * 5.5);  // Upper-left sweeping wing
    float lobeC = exp(-pow(ang - 1.62, 2.0) * 6.0);  // Tall central spire
    float lobeR = exp(-pow(ang - 0.68, 2.0) * 5.5);  // Upper-right billowing wing
    float lobeBase = exp(-pow(p.y - 1.15, 2.0) * 3.5) * smoothstep(0.65, 1.25, abs(p.x)) * smoothstep(1.85, 1.15, abs(p.x));
    float angularMask = clamp(lobeL + lobeC + lobeR + lobeBase, 0.0, 1.0);
    float radialMask = smoothstep(0.55, 1.05, r) * smoothstep(2.25 * surge, 1.15, r);
    float clusterMask = angularMask * radialMask;

    if (clusterMask > 0.01) {
        vec2 dir = rel / max(r, 0.001);
        // Polar-aligned radial droplet streams flung outward from the crown tips
        vec2 polar = vec2(ang * 14.0, r * 11.0 - t * 2.4);
        vec2 cell = floor(polar);
        vec2 f = fract(polar);

        float rnd = hash12(cell + 17.3);
        if (rnd > 0.62) {
            vec2 ctr = vec2(hash12(cell + 41.1), hash12(cell + 83.7)) * 0.55 + 0.22;
            vec2 dv = f - ctr;
            // Elongated radially along flight trajectory
            float dist = length(vec2(dv.x * 1.6, dv.y * 0.55));
            float sz = mix(0.035, 0.095, hash12(cell + 11.9));
            float drop = smoothstep(sz, sz * 0.18, dist);

            vec3 dropCol = (uLightMode == 1)
                ? vec3(0.65)
                : mix(vec3(0.55, 0.70, 0.84), vec3(0.95, 0.98, 1.05), hash12(cell + 3.7));
            if (uLightMode != 1) {
                float lowCyan = smoothstep(1.55, 0.85, p.y) * glowScale;
                dropCol = mix(dropCol, vec3(0.18, 0.95, 0.90), lowCyan * 0.65);
            }
            acc += dropCol * drop * clusterMask * 0.95;
        }
    }

    // 2. Crisp warm golden-amber sparks shooting upward from the upper-right backlit flash
    if (uLightMode != 2) {
        float sparkScale = (uLightMode == 1) ? 0.18 : 1.0;
        for (int i = 0; i < 10; i++) {
            float fi = float(i);
            float phase = fract(hash11(fi * 13.7 + 1.3) + t * (0.30 + 0.12 * hash11(fi * 7.1)));
            vec2 startPos = vec2(0.12 + 0.42 * hash11(fi * 3.1), 2.10 + 0.30 * hash11(fi * 5.7));
            vec2 vel = vec2(0.24 * (hash11(fi * 11.3) - 0.30), 1.35 + 0.55 * hash11(fi * 17.9));
            vec2 sp = startPos + vel * phase - vec2(0.0, 0.38 * phase * phase);

            vec2 d = p.xy - sp;
            vec2 vDir = normalize(vel - vec2(0.0, 0.76 * phase));
            float along = dot(d, vDir);
            float perp  = dot(d, vec2(-vDir.y, vDir.x));
            float streak = length(vec2(along * 0.25, perp * 1.65));

            float fade = smoothstep(0.0, 0.14, phase) * smoothstep(1.0, 0.32, phase);
            float spark = exp(-streak * 115.0) * fade;
            vec3 sparkCol = (uLightMode == 1)
                ? vec3(0.95)
                : vec3(2.3, 1.55, 0.58);
            acc += sparkCol * spark * sparkScale;
        }
    }

    return acc;
}

// ----------------------------------------------------------------------------
// Camera Setup
// ----------------------------------------------------------------------------
void getCamera(vec2 uv, out vec3 ro, out vec3 rd) {
    if (uCamMode == 1) {
        // ~2.5x macro close-up of the glowing cyan bubble cavity & turbulent water sheets
        ro = vec3(0.10, 0.80, 2.28);
        vec3 ta = vec3(0.03, 0.78, 0.18);
        vec3 fwd = normalize(ta - ro);
        vec3 right = normalize(cross(fwd, vec3(0.0, 1.0, 0.0)));
        vec3 up = cross(right, fwd);
        rd = normalize(fwd * 2.05 + uv.x * right + uv.y * up);
    } else {
        // Hero photoreal maritime framing matching 08.png
        ro = vec3(0.04, 0.54, 5.25);
        vec3 ta = vec3(-0.02, 1.48, 0.0);
        vec3 fwd = normalize(ta - ro);
        vec3 right = normalize(cross(fwd, vec3(0.0, 1.0, 0.0)));
        vec3 up = cross(right, fwd);
        rd = normalize(fwd * 1.72 + uv.x * right + uv.y * up);
    }
}

// ----------------------------------------------------------------------------
// ACES Filmic Tonemapping
// ----------------------------------------------------------------------------
vec3 acesToneMap(vec3 x) {
    x = x / (1.0 + 0.16 * max(x, vec3(0.0)));
    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, 0.992);
}

// ----------------------------------------------------------------------------
// Main
// ----------------------------------------------------------------------------
void main() {
    vec2 uv = (gl_FragCoord.xy - 0.5 * uResolution.xy) / uResolution.y;

    vec3 ro, rd;
    getCamera(uv, ro, rd);

    // 1. Deep moody storm sky
    vec3 col = evalSky(rd);
    float tScene = 42.0;

    // 2. Dark glossy choppy ocean surface
    float tOcean = traceOcean(ro, rd, tScene);
    if (tOcean > 0.0 && tOcean < tScene) {
        vec3 p = ro + rd * tOcean;
        float foamMask;
        oceanWaveHeight(p.xz, foamMask);
        vec3 N = oceanNormal(p.xz);
        col = shadeOcean(p, N, -rd, foamMask);
        tScene = tOcean;
    }

    // 3. Organic flaring translucent turquoise seawater column
    float tCol = traceWaterColumn(ro, rd, tScene);
    if (tCol > 0.0 && tCol < tScene) {
        vec3 p = ro + rd * tCol;
        vec3 N = calcColumnNormal(p);
        vec3 colWater = shadeWaterColumn(p, N, -rd);
        float baseBlend = smoothstep(-0.02, 0.28, p.y);
        col = mix(col, colWater, baseBlend);
        tScene = tCol;
    }

    // 4. Crisp 3D refractive underwater bubble cluster
    vec3 bCenter;
    float bRad;
    float bLayer;
    float tBub = traceBubbles(ro, rd, tScene + 0.65, bCenter, bRad, bLayer);
    if (tBub > 0.0) {
        vec3 p = ro + rd * tBub;
        if (tOcean < 0.0 || tBub < tOcean + 0.08) {
            col = shadeBubble(p, bCenter, bRad, bLayer, -rd, col);
            tScene = min(tScene, tBub);
        }
    }

    // 5. Focused luminous underwater cyan-teal detonation core halo
    {
        vec3 corePos = getCorePos();
        vec3 oc = corePos - ro;
        float proj = dot(oc, rd);
        if (proj > 0.0 && proj < tScene + 1.0) {
            float dRay = length(oc - rd * proj);
            float halo = exp(-dRay * dRay * 4.2) * smoothstep(0.0, 0.5, proj);
            float glowScale = (uLightMode == 1) ? 0.05 : (uLightMode == 2 ? 0.30 : 0.85);
            vec3 cyanHalo = (uLightMode == 1) ? vec3(0.45) : vec3(0.04, 0.82, 0.78);
            col += cyanHalo * halo * 0.28 * glowScale;
        }
    }

    // 6. High-contrast 60-step volumetric sculpted seafoam crown & spray plume
    float jitter = hash12(gl_FragCoord.xy + fract(uTime) * 137.0);
    vec3 volLight;
    float volTrans;
    marchVolumetricPlume(ro, rd, tScene + 0.25, jitter, volLight, volTrans);
    col = col * volTrans + volLight;

    // 7. Clustered ballistic splash droplets & warm incandescent sparks
    col += evalSplashDropletsAndSparks(ro, rd, tScene);

    // Subtle dark maritime framing vignette
    float vig = 1.0 - 0.22 * dot(uv, uv);
    col *= clamp(vig, 0.62, 1.0);

    // Calibrated deep night floor: linear 0.00055 -> sRGB ~0.032 (~8/255),
    // guaranteeing lumMin >= 5 and 0% crushed black while keeping moody night contrast
    col = max(col, vec3(0.00055));

    // ACES filmic tonemapping + sRGB gamma encode
    col = acesToneMap(col);
    col = pow(col, vec3(1.0 / 2.2));

    // Strict R == G == B neutrality for grayscale study mode
    if (uLightMode == 1) {
        float lum = dot(col, vec3(0.2126, 0.7152, 0.0722));
        col = vec3(lum);
    }

    fragColor = vec4(col, 1.0);
}

Mathematical models & shader specifications

Identifierunderwater-depth-charge-plume
CategoryGame VFX Shaders · Physically-Based VFX
Upstream studyvfx_realistic/lib/08_underwater_depth_charge_plume.glsl (commit afde0bc)
Animation cycleContinuous procedural uTime
Declared uniformsuResolution, uTime, uOpen, uLightMode, uCamMode
Source size1154 lines · 45.2 KB standalone GLSL ES 3.00
PNG baker outputs512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key)
Companion pixel VFXFree MIT water sprite sheets
LicenseMIT License + CC0 / MIT Helpers

Physical & shading models implemented

Schlick Fresnel reflectance (1994); Beer–Lambert volumetric absorption/attenuation; Henyey–Greenstein scattering phase function (1941)

Adapted upstream mathematical helpers

David Hoskins, hash · Krzysztof Narkowicz, filmic curve · Inigo Quilez, quadratic distance blend

All game vfx shaders