Charge & Release Energy Nova shader

charge-and-release-energy-nova.glsl · 1092 lines · GLSL ES 3.00 · MIT

Charge & Release Energy NovaGame VFX
Charge & Release Energy Nova WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 1092 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

Choreographed Loop VFX
charge-and-release-energy-nova.glsl (1092 lines)
#version 300 es
// Charge & Release Energy Nova (charge-and-release-energy-nova.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_animated/lib/01_charge_and_release_energy_nova.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)
// Charge-and-Release Energy Nova: true volumetric turbulent plasma singularity
// vortex levitating above a dark reflective obsidian arena with concentric
// energy rings, chaotic domain-warped golden-violet volumetric shockwave
// nebula, volumetric light rays, and crackling multi-branch electric-cyan
// lightning. Choreographed seamless 3.0s loop.
precision highp float;
precision highp int;

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

out vec4 fragColor;

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

const vec3  SPHERE_C = vec3(0.0, 0.02, 0.0);
const float FLOOR_Y  = -1.16;
const float RING_Y   = 0.62;

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

vec2 hash22(vec2 p) {
    vec3 p3 = fract(p.xyx * vec3(0.1031, 0.1030, 0.0973));
    p3 += dot(p3, p3.yzx + 33.33);
    return fract((p3.xx + p3.yz) * p3.zy);
}

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 vnoise2(vec2 p) {
    vec2 i = floor(p);
    vec2 f = fract(p);
    vec2 u = f * f * (3.0 - 2.0 * f);
    float a = hash12(i);
    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 vnoise3(vec3 p) {
    vec3 i = floor(p);
    vec3 f = fract(p);
    vec3 u = f * f * (3.0 - 2.0 * f);
    float n000 = hash13(i);
    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);
}

float fbm2(vec2 p) {
    float s = 0.0;
    float a = 0.5;
    mat2 m = mat2(1.6, 1.2, -1.2, 1.6);
    for (int i = 0; i < 4; i++) {
        s += a * vnoise2(p);
        p = m * p;
        a *= 0.5;
    }
    return s;
}

// Fast 3-octave 3D fBM for true volumetric turbulence
float fbm3(vec3 p) {
    float s = 0.0;
    float a = 0.52;
    for (int i = 0; i < 3; i++) {
        s += a * vnoise3(p);
        p = p * 2.04 + vec3(17.1, 31.7, 11.3);
        a *= 0.5;
    }
    return s;
}

// Ridged 3D fBM for sharp turbulent plasma filaments
float ridged3(vec3 p) {
    float s = 0.0;
    float a = 0.55;
    for (int i = 0; i < 3; i++) {
        float n = 1.0 - abs(2.0 * vnoise3(p) - 1.0);
        s += a * n * n;
        p = p * 2.12 + vec3(9.4, 23.1, 15.7);
        a *= 0.48;
    }
    return s;
}

mat2 rot2(float a) {
    float c = cos(a), s = sin(a);
    return mat2(c, -s, s, c);
}

// -----------------------------------------------------------------------------
// Choreographed Seamless 3.0s Animation State
// phase in [0, 1):
//   0.00 - 0.32 : Anticipation charge (compression, inward plasma filaments, floor charge)
//   0.32 - 0.50 : Peak snap release (hero peak at t=1.2s -> phase=0.40)
//   0.50 - 1.00 : Expanding shockwave nebula, crackling discharges, smooth recovery
// -----------------------------------------------------------------------------
struct AnimState {
    float phase;
    float tauP;
    float charge;
    float burst;
    float shockProg;
    float shockVis;
    float boltPower;
    float sphereR;
    float ringInner;
    float ringOuter;
};

AnimState evalAnim(float t) {
    AnimState st;
    float p = fract(t / 3.0);
    st.phase = p;
    st.tauP  = TAU * p;

    // Anticipation charge envelope: ramps 0.0->0.30, snaps off 0.30->0.36
    float cUp   = smoothstep(0.0, 0.30, p);
    float cDrop = 1.0 - smoothstep(0.30, 0.36, p);
    st.charge = cUp * cDrop;

    // Peak snap release: snaps up 0.31->0.40, peaks at 0.40, smooth decay to 0.94
    float bRise = smoothstep(0.30, 0.39, p);
    float bFall = 1.0 - smoothstep(0.42, 0.94, p);
    float heroPulse = exp(-pow((p - 0.40) / 0.11, 2.0));
    st.burst = clamp(bRise * bFall * 0.78 + heroPulse * 0.35, 0.0, 1.0);

    // Shockwave expansion progress (strictly seamless wrap)
    float sp = fract(p - 0.31);
    st.shockProg = sp;

    float expCurve = 1.0 - pow(1.0 - clamp(sp / 0.72, 0.0, 1.0), 2.3);
    st.ringInner = mix(0.76, 1.95, expCurve);
    st.ringOuter = mix(1.56, 3.22, expCurve);

    float sIn  = smoothstep(0.0, 0.055, sp);
    float sOut = 1.0 - smoothstep(0.28, 0.68, sp);
    float preHalo = 0.24 * smoothstep(0.74, 0.98, sp) * (1.0 - smoothstep(0.98, 1.0, sp));
    st.shockVis = clamp(sIn * sOut + preHalo, 0.0, 1.0);

    float boltStatic = 0.30 * st.charge;
    float boltMain   = smoothstep(0.31, 0.37, p) * (1.0 - smoothstep(0.48, 0.88, p));
    st.boltPower = clamp(max(boltStatic, boltMain) + 0.12 * heroPulse, 0.0, 1.0);

    float compress = -0.14 * smoothstep(0.02, 0.30, p) * (1.0 - smoothstep(0.30, 0.35, p));
    float expand   =  0.08 * smoothstep(0.31, 0.40, p) * (1.0 - smoothstep(0.45, 0.96, p));
    float breath   =  0.012 * sin(st.tauP);
    st.sphereR = 0.67 + compress + expand + breath;

    return st;
}

// -----------------------------------------------------------------------------
// SDF Geometry & Unit-Sign Tetrahedral Normals (for Clay Mode & Specular/Relief)
// -----------------------------------------------------------------------------
float sphereRelief(vec3 p, AnimState st) {
    vec3 n = normalize(p);
    float ang = atan(n.y, n.x);
    float rxy = length(n.xy);
    float swirl = ang + 3.0 * log(rxy + 0.18) - 2.0 * st.tauP;
    vec3 sp = vec3(n.xy * rot2(-st.tauP), n.z) * 3.2;
    float turb = fbm3(sp) - 0.5;
    float ridges = sin(swirl * 4.0 + turb * 5.0) * 0.5 + 0.5;
    return (ridges * 0.020 + turb * 0.018) * (0.65 + 0.35 * st.burst);
}

float sdSphereCore(vec3 p, AnimState st) {
    vec3 q = p - SPHERE_C;
    float d = length(q) - st.sphereR;
    if (d < 0.14) {
        d -= sphereRelief(q, st);
    }
    return d;
}

float sdShockRingClay(vec3 p, AnimState st) {
    vec3 q = p - vec3(0.0, RING_Y, 0.0);
    float r = length(q.xz);
    float rMid = 0.5 * (st.ringInner + st.ringOuter);
    float rHalf = 0.5 * (st.ringOuter - st.ringInner);
    vec2 rotXZ = q.xz * rot2(-st.tauP);
    float turb = fbm3(vec3(rotXZ * 1.4, q.y * 2.5)) - 0.5;
    float dr = abs(r - rMid + turb * 0.22) - rHalf * (0.85 + 0.3 * turb);
    float thickness = 0.065 * (1.0 - 0.55 * clamp(abs(r - rMid) / max(rHalf, 0.01), 0.0, 1.0)) + turb * 0.04;
    vec2 d2 = vec2(max(dr, 0.0), abs(q.y) - max(thickness, 0.012));
    return min(max(d2.x, d2.y), 0.0) + length(max(d2, 0.0)) - 0.015;
}

float sdArenaFloor(vec3 p) {
    float d = p.y - FLOOR_Y;
    float r = length(p.xz);
    float r0 = abs(r - 0.40);
    float r1 = abs(r - 0.62);
    float r2 = abs(r - 0.86);
    float r3 = abs(r - 1.14);
    float r4 = abs(r - 1.48);
    float ringD = min(min(min(r0, r1), min(r2, r3)), r4);
    float groove = 0.016 * (1.0 - smoothstep(0.015, 0.055, ringD));
    vec2 tile = abs(fract(p.xz * 0.68 + 0.5) - 0.5);
    float seam = min(tile.x, tile.y);
    groove += 0.010 * (1.0 - smoothstep(0.008, 0.028, seam)) * smoothstep(0.95, 1.65, r);
    float rim = 0.06 * smoothstep(5.9, 6.2, r);
    return d + groove - rim;
}

// -----------------------------------------------------------------------------
// Sharp Angular Multi-Branch 3D Lightning Bolts
// Piecewise-linear jagged kinks (not smooth sine ribbons!) + forked branches.
// -----------------------------------------------------------------------------
struct BoltDef {
    vec3 a;
    vec3 b;
    float amp;
    float thickness;
    float seed;
    float weight;
    float segs;
};

// Piecewise-linear jagged displacement along bolt u in [0, 1], seamless over 3.0s
vec3 boltJaggedOffset(float u, float seed, float amp, float segs, float phase) {
    float env = sin(u * PI);
    // Discrete periodic time frames (12 snaps per 3.0s loop) smoothly cross-faded
    float tf = phase * 12.0;
    float t0 = mod(floor(tf), 12.0);
    float t1 = mod(t0 + 1.0, 12.0);
    float ft = fract(tf);
    ft = ft * ft * (3.0 - 2.0 * ft);

    // Coarse angular zig-zag kinks (linear interpolation -> sharp corners!)
    float su = u * segs;
    float i0 = floor(su);
    float i1 = i0 + 1.0;
    float fu = fract(su);

    vec2 r0a = hash22(vec2(i0 + seed * 13.7, t0 * 3.1 + seed)) - 0.5;
    vec2 r1a = hash22(vec2(i1 + seed * 13.7, t0 * 3.1 + seed)) - 0.5;
    vec2 r0b = hash22(vec2(i0 + seed * 13.7, t1 * 3.1 + seed)) - 0.5;
    vec2 r1b = hash22(vec2(i1 + seed * 13.7, t1 * 3.1 + seed)) - 0.5;
    vec2 kink1 = mix(mix(r0a, r1a, fu), mix(r0b, r1b, fu), ft);

    // Fine high-frequency crackling micro-kinks
    float su2 = u * segs * 2.5;
    float j0 = floor(su2);
    float j1 = j0 + 1.0;
    float fu2 = fract(su2);
    vec2 f0a = hash22(vec2(j0 * 1.3 + seed * 29.1, t0 * 5.3 + seed)) - 0.5;
    vec2 f1a = hash22(vec2(j1 * 1.3 + seed * 29.1, t0 * 5.3 + seed)) - 0.5;
    vec2 f0b = hash22(vec2(j0 * 1.3 + seed * 29.1, t1 * 5.3 + seed)) - 0.5;
    vec2 f1b = hash22(vec2(j1 * 1.3 + seed * 29.1, t1 * 5.3 + seed)) - 0.5;
    vec2 kink2 = mix(mix(f0a, f1a, fu2), mix(f0b, f1b, fu2), ft);

    vec2 k = (kink1 * 1.45 + kink2 * 0.55) * amp * env;
    return vec3(k.x, k.y, (kink1.x - kink2.y) * 0.45 * amp * env);
}

BoltDef getBolt(int idx, AnimState st) {
    BoltDef bd;
    float sr = st.sphereR * 0.94;
    bd.amp = 0.24;
    bd.thickness = 0.015;
    bd.seed = float(idx) * 2.31 + 1.1;
    bd.weight = 1.0;
    bd.segs = 11.0;

    if (idx == 0) {
        // Bold vertical bolt shooting UP
        bd.a = SPHERE_C + vec3(0.0, sr, 0.0);
        bd.b = vec3(0.06, 3.15, -0.12);
        bd.amp = 0.26; bd.thickness = 0.022; bd.weight = 1.30; bd.segs = 12.0;
    } else if (idx == 1) {
        // Bold grounding bolt shooting DOWN to floor ring center
        bd.a = SPHERE_C + vec3(0.0, -sr, 0.0);
        bd.b = vec3(0.0, FLOOR_Y + 0.02, 0.0);
        bd.amp = 0.16; bd.thickness = 0.023; bd.weight = 1.38; bd.segs = 8.0;
    } else if (idx == 2) {
        // Dramatic wide LEFT horizontal bolt
        bd.a = SPHERE_C + vec3(-sr, -0.02, 0.05);
        bd.b = vec3(-3.65, 0.48, 0.22);
        bd.amp = 0.30; bd.thickness = 0.020; bd.weight = 1.25; bd.segs = 13.0;
    } else if (idx == 3) {
        // Dramatic wide RIGHT horizontal bolt
        bd.a = SPHERE_C + vec3(sr, 0.0, 0.04);
        bd.b = vec3(3.65, 0.56, 0.18);
        bd.amp = 0.30; bd.thickness = 0.020; bd.weight = 1.25; bd.segs = 13.0;
    } else if (idx == 4) {
        // Upper-left diagonal main bolt
        bd.a = SPHERE_C + normalize(vec3(-0.70, 0.70, 0.08)) * sr;
        bd.b = vec3(-2.40, 2.75, -0.30);
        bd.amp = 0.24; bd.thickness = 0.013; bd.weight = 0.90; bd.segs = 11.0;
    } else if (idx == 5) {
        // Upper-right diagonal main bolt
        bd.a = SPHERE_C + normalize(vec3(0.68, 0.72, 0.06)) * sr;
        bd.b = vec3(2.30, 2.80, -0.25);
        bd.amp = 0.24; bd.thickness = 0.013; bd.weight = 0.90; bd.segs = 11.0;
    } else if (idx == 6) {
        // Lower-left grounding bolt hitting floor rings
        bd.a = SPHERE_C + normalize(vec3(-0.76, -0.62, 0.18)) * sr;
        bd.b = vec3(-1.35, FLOOR_Y + 0.02, 0.26);
        bd.amp = 0.18; bd.thickness = 0.013; bd.weight = 0.92; bd.segs = 9.0;
    } else if (idx == 7) {
        // Lower-right grounding bolt hitting floor rings
        bd.a = SPHERE_C + normalize(vec3(0.76, -0.62, 0.15)) * sr;
        bd.b = vec3(1.42, FLOOR_Y + 0.02, 0.22);
        bd.amp = 0.18; bd.thickness = 0.013; bd.weight = 0.90; bd.segs = 9.0;
    } else if (idx == 8) {
        // Forked branch off LEFT horizontal bolt (shooting down-left)
        bd.a = vec3(-1.45, 0.12, 0.12);
        bd.b = vec3(-2.90, -0.62, 0.05);
        bd.amp = 0.20; bd.thickness = 0.010; bd.weight = 0.72; bd.segs = 8.0;
    } else if (idx == 9) {
        // Forked branch off RIGHT horizontal bolt (shooting down-right)
        bd.a = vec3(1.48, 0.16, 0.10);
        bd.b = vec3(2.85, -0.58, 0.04);
        bd.amp = 0.20; bd.thickness = 0.010; bd.weight = 0.72; bd.segs = 8.0;
    } else if (idx == 10) {
        // Forked branch off TOP vertical bolt (shooting upper-right)
        bd.a = vec3(0.02, 1.48, -0.05);
        bd.b = vec3(1.05, 2.55, -0.18);
        bd.amp = 0.18; bd.thickness = 0.009; bd.weight = 0.65; bd.segs = 7.0;
    } else if (idx == 11) {
        // Forked branch off TOP vertical bolt (shooting upper-left)
        bd.a = vec3(-0.02, 1.32, -0.04);
        bd.b = vec3(-1.15, 2.38, -0.20);
        bd.amp = 0.18; bd.thickness = 0.009; bd.weight = 0.65; bd.segs = 7.0;
    } else if (idx == 12) {
        // Secondary lower-left fork from sphere
        bd.a = SPHERE_C + normalize(vec3(-0.92, -0.35, -0.10)) * sr;
        bd.b = vec3(-2.35, -0.78, -0.15);
        bd.amp = 0.18; bd.thickness = 0.010; bd.weight = 0.68; bd.segs = 8.0;
    } else {
        // Secondary lower-right fork from sphere
        bd.a = SPHERE_C + normalize(vec3(0.92, -0.35, -0.10)) * sr;
        bd.b = vec3(2.42, -0.72, -0.12);
        bd.amp = 0.18; bd.thickness = 0.010; bd.weight = 0.68; bd.segs = 8.0;
    }
    return bd;
}

vec2 rayBoltDist(vec3 ro, vec3 rd, BoltDef bd, float phase) {
    vec3 ba = bd.b - bd.a;
    vec3 oa = ro - bd.a;
    float baba = dot(ba, ba);
    float bard = dot(ba, rd);
    float baoa = dot(ba, oa);
    float rdoa = dot(rd, oa);
    float denom = max(baba - bard * bard, 1e-4);

    float tRay = max((baba * (-rdoa) + bard * baoa) / denom, 0.05);
    float u = clamp((baoa + bard * tRay) / max(baba, 1e-4), 0.0, 1.0);

    vec3 dir = normalize(ba);
    vec3 upRef = abs(dir.y) > 0.9 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0);
    vec3 tx = normalize(cross(dir, upRef));
    vec3 ty = cross(dir, tx);

    vec3 disp = boltJaggedOffset(u, bd.seed, bd.amp, bd.segs, phase);
    vec3 pt = bd.a + ba * u + tx * disp.x + ty * disp.y + dir * (disp.z * 0.15);

    float tNew = max(dot(pt - ro, rd), 0.05);
    vec3 rayP = ro + rd * tNew;
    return vec2(length(rayP - pt), tNew);
}

float sdBoltClay(vec3 p, BoltDef bd, float phase) {
    vec3 ba = bd.b - bd.a;
    float u = clamp(dot(p - bd.a, ba) / max(dot(ba, ba), 1e-4), 0.0, 1.0);
    vec3 dir = normalize(ba);
    vec3 upRef = abs(dir.y) > 0.9 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0);
    vec3 tx = normalize(cross(dir, upRef));
    vec3 ty = cross(dir, tx);
    vec3 disp = boltJaggedOffset(u, bd.seed, bd.amp, bd.segs, phase);
    vec3 pt = bd.a + ba * u + tx * disp.x + ty * disp.y;
    float rad = bd.thickness * (0.85 + 0.55 * (1.0 - u));
    return length(p - pt) - rad;
}

vec2 mapClay(vec3 p, AnimState st) {
    float dSph = sdSphereCore(p, st);
    vec2 res = vec2(dSph, 1.0);

    float dFlr = sdArenaFloor(p);
    if (dFlr < res.x) res = vec2(dFlr, 2.0);

    if (st.shockVis > 0.05) {
        float dRing = sdShockRingClay(p, st);
        if (dRing < res.x) res = vec2(dRing, 3.0);
    }

    if (st.boltPower > 0.1) {
        float dBolt = 1e5;
        for (int i = 0; i < 8; i++) {
            BoltDef bd = getBolt(i, st);
            dBolt = min(dBolt, sdBoltClay(p, bd, st.phase));
        }
        if (dBolt < res.x) res = vec2(dBolt, 4.0);
    }
    return res;
}

vec3 calcClayNormal(vec3 p, AnimState st) {
    const float h = 0.002;
    const vec2 k = vec2(1.0, -1.0);
    return normalize(
        k.xyy * mapClay(p + k.xyy * h, st).x +
        k.yyx * mapClay(p + k.yyx * h, st).x +
        k.yxy * mapClay(p + k.yxy * h, st).x +
        k.xxx * mapClay(p + k.xxx * h, st).x
    );
}

// -----------------------------------------------------------------------------
// TRUE VOLUMETRIC TRANSLUCENT PLASMA SINGULARITY VORTEX SPHERE
// Raymarches THROUGH the translucent 3D plasma volume with optical absorption
// (Beer-Lambert transmittance), domain-warped 3D ridged-fBM gold & violet
// filaments, deep dark singularity core, and luminous cyan energy shell.
// Returns vec4(emittedRGB, transmittance) so background shows through!
// -----------------------------------------------------------------------------
vec4 evalVolumetricPlasmaSphere(vec3 ro, vec3 rd, float maxT, AnimState st, int steps, float jitter) {
    float outerR = st.sphereR * 1.16;
    vec3 oc = ro - SPHERE_C;
    float b = dot(oc, rd);
    float c = dot(oc, oc) - outerR * outerR;
    float disc = b * b - c;
    if (disc <= 0.0) return vec4(0.0, 0.0, 0.0, 1.0);

    float sq = sqrt(disc);
    float t0 = max(-b - sq, 0.02);
    float t1 = min(-b + sq, maxT);
    if (t1 <= t0) return vec4(0.0, 0.0, 0.0, 1.0);

    float dt = (t1 - t0) / float(steps);
    float t = t0 + dt * jitter;

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

    // Seamless periodic rotation matrices
    float rotA = -st.tauP;
    float rotB =  st.tauP;

    for (int i = 0; i < 24; i++) {
        if (i >= steps || trans < 0.02) break;
        vec3 p = ro + rd * t - SPHERE_C;
        float r = length(p);
        float rn = r / st.sphereR; // 0 at center, 1.0 at containment shell, 1.16 outer corona

        if (rn < 1.15) {
            // 3D logarithmic vortex swirl around Z axis (facing camera) + subtle 3D tilt
            float rxy = length(p.xy);
            float twist = 3.4 * log(rxy + 0.16) + rotA;
            vec3 q = p;
            q.xy = q.xy * rot2(twist);
            // Gentle secondary swirl in XZ for rich 3D depth
            vec3 q2 = p;
            q2.xz = q2.xz * rot2(rotB + r * 2.2);

            // Domain-warped 3D turbulent plasma density (ZERO uniform sine stripes!)
            vec3 warp = vec3(
                fbm3(q * 2.4 + vec3(0.0, 2.3, 1.7)),
                fbm3(q * 2.4 + vec3(5.1, -1.4, 3.2)),
                fbm3(q * 2.4 + vec3(-3.3, 4.1, -2.5))
            ) - 0.5;

            vec3 qp = q * 3.1 + warp * 1.45;
            float nCloud = fbm3(qp);
            float nFil   = ridged3(qp * 1.35 + vec3(0.0, 0.0, p.z * 2.0));
            float nCyan  = ridged3(q2 * 3.8 + warp * 1.1);

            // 1. Deep dark singularity event-horizon core (absorbs light!)
            float coreAbsorb = smoothstep(0.46, 0.14, rn);

            // 2. Swirling luminous violet-magenta volumetric plasma clouds
            float plasmaBand = smoothstep(0.24, 0.54, rn) * (1.0 - smoothstep(0.84, 1.06, rn));
            float violetDens = smoothstep(0.36, 0.80, nCloud) * plasmaBand;
            // Asymmetric richness matching reference (stronger violet right/lower-right)
            float asymV = 0.65 + 0.55 * smoothstep(-0.4, 0.55, p.x - 0.25 * p.y);

            // 3. Incandescent turbulent golden plasma filaments (wispy, chaotic, not vinyl!)
            float goldFil = pow(clamp(nFil, 0.0, 1.0), 4.6) * smoothstep(0.26, 0.52, rn) * (1.0 - smoothstep(0.82, 1.00, rn));
            float goldHot = pow(clamp(nFil, 0.0, 1.0), 9.0) * smoothstep(0.28, 0.50, rn) * (1.0 - smoothstep(0.86, 1.02, rn));

            // 4. Translucent electric-cyan outer containment shell & plasma corona
            float shellEnv = exp(-pow((rn - 0.94) / 0.11, 2.0));
            float cyanShell = shellEnv * (0.45 + 0.85 * pow(clamp(nCyan, 0.0, 1.0), 2.2));
            // Grazing view-angle Fresnel boost on the translucent containment shell
            vec3 nDir = p / max(r, 1e-4);
            float rimBoost = 0.35 + 1.35 * pow(1.0 - abs(dot(nDir, rd)), 2.2);

            // Local emission & absorption
            vec3 emit = vec3(0.0);
            emit += vec3(0.44, 0.06, 0.98) * violetDens * asymV * 1.55;
            emit += vec3(0.80, 0.18, 1.00) * pow(violetDens, 2.0) * asymV * 0.95;
            emit += vec3(1.00, 0.56, 0.08) * goldFil * 3.20;
            emit += vec3(1.00, 0.88, 0.44) * goldHot * 2.80;
            emit += vec3(0.08, 0.82, 1.00) * cyanShell * rimBoost * 1.65;
            emit += vec3(0.45, 0.95, 1.00) * pow(cyanShell, 2.0) * rimBoost * 0.85;

            // Subtle deep indigo rim right around the dark singularity void
            float voidEdge = exp(-pow((rn - 0.30) / 0.08, 2.0)) * (0.4 + 0.6 * nFil);
            emit += vec3(0.18, 0.14, 0.68) * voidEdge * 0.65;

            // Choreographed pulse
            emit *= (0.85 + 0.32 * st.burst + 0.18 * st.charge);

            // Lighting mode modulation
            if (uLightMode == 2) {
                vec3 lDir = normalize(vec3(0.88, 0.28, 0.38));
                float keyL = 0.35 + 0.85 * max(dot(nDir, lDir), 0.0);
                emit = emit * 0.65 * keyL + vec3(0.55, 0.62, 0.78) * shellEnv * max(dot(nDir, lDir), 0.0) * 0.9;
            } else if (uLightMode == 3) {
                vec3 lDir = normalize(vec3(0.0, 0.35, -1.0));
                float backL = pow(1.0 - abs(dot(nDir, rd)), 2.2) * (0.5 + 0.5 * max(dot(nDir, lDir), 0.0));
                emit = emit * 0.72 + vec3(0.24, 0.84, 1.0) * shellEnv * backL * 1.5;
            }

            // Optical density: dark void strongly absorbs, plasma clouds softly absorb
            float sigma = coreAbsorb * 7.5 + violetDens * 1.15 + cyanShell * 0.45;
            float stepTrans = exp(-sigma * dt);

            accum += trans * emit * dt;
            trans *= stepTrans;
        }
        t += dt;
    }

    return vec4(accum, trans);
}

// -----------------------------------------------------------------------------
// TRUE VOLUMETRIC TURBULENT GOLDEN-VIOLET SHOCKWAVE NEBULA RING
// Chaotic, swirling, domain-warped 3D fBM plasma clouds & wispy trailing
// filaments (ZERO uniform concentric vinyl-record grooves!).
// -----------------------------------------------------------------------------
vec3 evalVolumetricShockwave(vec3 ro, vec3 rd, float maxT, AnimState st, int steps, float jitter) {
    if (st.shockVis <= 0.005) return vec3(0.0);

    float halfH = 0.34;
    float yMin = RING_Y - halfH;
    float yMax = RING_Y + halfH;

    // Intersect ray with horizontal slab [yMin, yMax]
    float t0, t1;
    if (abs(rd.y) < 1e-4) {
        if (ro.y < yMin || ro.y > yMax) return vec3(0.0);
        t0 = 0.1;
        t1 = maxT;
    } else {
        float ta = (yMin - ro.y) / rd.y;
        float tb = (yMax - ro.y) / rd.y;
        t0 = min(ta, tb);
        t1 = max(ta, tb);
    }

    t0 = max(t0, 0.1);
    t1 = min(t1, maxT);
    if (t1 <= t0) return vec3(0.0);

    // Clamp radial bounding cylinder so rays don't waste steps outside the ring
    float rBound = st.ringOuter * 1.38;
    float aXZ = dot(rd.xz, rd.xz);
    if (aXZ > 1e-5) {
        float bXZ = dot(ro.xz, rd.xz);
        float cXZ = dot(ro.xz, ro.xz) - rBound * rBound;
        float dXZ = bXZ * bXZ - aXZ * cXZ;
        if (dXZ <= 0.0) return vec3(0.0);
        float sq = sqrt(dXZ);
        t0 = max(t0, (-bXZ - sq) / aXZ);
        t1 = min(t1, (-bXZ + sq) / aXZ);
        if (t1 <= t0) return vec3(0.0);
    }

    float dt = (t1 - t0) / float(steps);
    float t = t0 + dt * jitter;

    float rIn  = st.ringInner;
    float rOut = st.ringOuter;
    float rSpan = max(rOut - rIn, 0.1);

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

    for (int i = 0; i < 18; i++) {
        if (i >= steps || trans < 0.04) break;
        vec3 p = ro + rd * t;
        float r = length(p.xz);

        if (r > rIn * 0.65 && r < rOut * 1.35) {
            float dy = p.y - RING_Y;
            // Swirl coordinates tangentially with differential Keplerian shear (seamless via tauP!)
            float shear = -st.tauP + 1.15 * log(r + 0.35);
            vec2 swXZ = p.xz * rot2(shear);
            vec3 sp = vec3(swXZ * 1.35, dy * 3.8);

            // Two-level domain warp for chaotic billowing turbulent nebula edges
            vec3 warp1 = vec3(
                fbm3(sp + vec3(0.0, 3.1, 1.4)),
                fbm3(sp + vec3(4.7, -2.2, 2.8)),
                fbm3(sp + vec3(-2.9, 1.5, -3.6))
            ) - 0.5;

            // Warp radial & vertical boundaries so ring edges are ragged, wispy plasma (NOT rigid circles!)
            float rWarped = r + warp1.x * 0.42 + warp1.y * 0.22;
            float rn = (rWarped - rIn) / rSpan;

            float radialEnv = smoothstep(-0.12, 0.22, rn) * (1.0 - smoothstep(0.68, 1.18, rn));
            // Billowing vertical thickness (thicker in turbulent plumes, razor-thin in wispy tails)
            float thick = 0.11 + 0.10 * (warp1.z + 0.5) * (1.0 - 0.4 * clamp(rn, 0.0, 1.0));
            float vertEnv = exp(-pow((dy + warp1.z * 0.07) / thick, 2.0));
            float env = radialEnv * vertEnv;

            if (env > 0.004) {
                // Stretched tangential streamlines for sweeping chaotic plasma filaments
                vec2 streamXZ = p.xz * rot2(shear * 1.45);
                vec3 pTurb = vec3(streamXZ * 2.15, dy * 4.6) + warp1 * 1.55;

                float nebCloud = fbm3(pTurb);
                float filRidge = ridged3(pTurb * 1.45 + vec3(warp1.yx * 1.2, 0.0));
                float fineWisp = ridged3(vec3(streamXZ * 4.2, dy * 6.5) + warp1 * 2.1);

                // Deep billowing electric-violet plasma nebula in inner-to-mid shockwave
                float violetMask = smoothstep(-0.05, 0.32, rn) * (1.0 - smoothstep(0.54, 0.96, rn));
                float violetCloud = smoothstep(0.32, 0.78, nebCloud) * violetMask;

                // Fiery golden-amber turbulent plasma streaks & wispy trailing filaments
                float goldMask = smoothstep(0.14, 0.74, rn);
                float goldWisps = pow(clamp(filRidge, 0.0, 1.0), 3.4) * (0.38 + 0.62 * goldMask);
                float goldHot   = pow(clamp(fineWisp, 0.0, 1.0), 6.2) * (0.30 + 0.70 * goldMask);

                // Trailing outer glowing embers breaking off the turbulent edge
                float outerTail = smoothstep(0.55, 1.05, rn) * pow(clamp(fineWisp, 0.0, 1.0), 8.0);

                // Inner cyan-violet energy coupling wisps
                float innerCyan = exp(-pow((rn - 0.10) / 0.14, 2.0)) * pow(clamp(filRidge, 0.0, 1.0), 2.2);

                vec3 vCol = vec3(0.46, 0.06, 0.98) * violetCloud * 1.85
                          + vec3(0.76, 0.18, 1.00) * pow(violetCloud, 2.2) * 1.15;
                vec3 gCol = vec3(1.00, 0.52, 0.05) * goldWisps * 3.10
                          + vec3(1.00, 0.84, 0.32) * (goldHot * 3.40 + outerTail * 4.50);
                vec3 cCol = vec3(0.10, 0.78, 1.00) * innerCyan * 1.10;

                // Keep violet and gold deeply saturated (no muddy white wash)
                float goldCut = clamp(goldWisps * 1.2 + goldHot, 0.0, 1.0);
                vec3 emit = (vCol * (1.0 - 0.50 * goldCut) + gCol + cCol) * env;

                // Subtle internal smoke absorption for rich 3D volumetric depth
                float sigma = (violetCloud * 0.85 + goldWisps * 0.45) * env;
                accum += trans * emit * dt;
                trans *= exp(-sigma * dt);
            }
        }
        t += dt;
    }

    float gain = st.shockVis * (0.92 + 0.35 * st.burst);
    if (uLightMode == 2) gain *= 0.65;
    if (uLightMode == 3) gain *= 0.78;
    return accum * gain;
}

// -----------------------------------------------------------------------------
// Volumetric 3D Crackling Multi-Branch Lightning + Inward Charge Filaments
// -----------------------------------------------------------------------------
vec3 evalLightning(vec3 ro, vec3 rd, float maxT, AnimState st) {
    vec3 col = vec3(0.0);

    if (st.boltPower > 0.01) {
        for (int i = 0; i < 14; i++) {
            BoltDef bd = getBolt(i, st);
            vec2 dm = rayBoltDist(ro, rd, bd, st.phase);
            float d = dm.x;
            float tHit = dm.y;
            if (tHit >= maxT) continue;

            float flick = 0.76 + 0.24 * sin(st.tauP * 4.0 + bd.seed * 5.2);
            float boltMask = (i < 4) ? 1.0 : smoothstep(0.20, 0.60, st.boltPower);
            float w = bd.weight * flick * boltMask * st.boltPower;

            // Razor-sharp incandescent core + tight electric cyan-violet bloom
            float core = exp(-pow(d / (bd.thickness * 0.48), 1.85));
            float mid  = exp(-d / (bd.thickness * 2.0));
            float halo = exp(-d / (bd.thickness * 5.8));

            vec3 boltCol = vec3(0.96, 0.99, 1.00) * core * 1.75
                         + vec3(0.14, 0.74, 1.00) * mid * 0.85
                         + vec3(0.42, 0.20, 1.00) * halo * 0.22;
            col += boltCol * w;
        }
    }

    // Anticipation charge inward plasma wisps (0.00 - 0.34)
    if (st.charge > 0.02) {
        float tPlane = -ro.z / (rd.z + (abs(rd.z) < 1e-4 ? 1e-4 : 0.0));
        if (tPlane > 0.1 && tPlane < maxT) {
            vec3 p = ro + rd * tPlane - SPHERE_C;
            float r = length(p.xy);
            if (r > st.sphereR * 0.95 && r < 2.3) {
                vec2 sw = p.xy * rot2(2.4 * log(r + 0.2) - 2.0 * st.tauP);
                float nW = ridged3(vec3(sw * 2.8, st.charge * 1.5));
                float streaks = pow(clamp(nW, 0.0, 1.0), 4.5);
                float env = smoothstep(2.2, 1.1, r) * smoothstep(st.sphereR * 0.95, st.sphereR * 1.20, r);
                vec3 wispCol = mix(vec3(0.55, 0.16, 1.0), vec3(0.14, 0.84, 1.0), nW);
                col += wispCol * streaks * env * st.charge * 1.15;
            }
        }
    }

    if (uLightMode == 2) col *= 0.68;
    if (uLightMode == 3) col *= 0.80;
    return col;
}

// -----------------------------------------------------------------------------
// Volumetric God-Rays, Outer Plasma Aura & Cell-Safe Floating Sparks
// -----------------------------------------------------------------------------
vec3 evalGodRaysAndSparks(vec3 ro, vec3 rd, float maxT, float sphereTrans, AnimState st) {
    vec3 col = vec3(0.0);

    // Volumetric radial light rays + cyan-violet atmospheric scatter around the core
    vec3 oc = SPHERE_C - ro;
    float tProj = clamp(dot(oc, rd), 0.0, maxT);
    vec3 closest = ro + rd * tProj - SPHERE_C;
    float dMin = length(closest);

    // Only scatter outside the dense core (weighted by transmittance so dark void stays crisp!)
    float rayMask = smoothstep(st.sphereR * 0.82, st.sphereR * 1.08, dMin);
    float haloR = max(dMin - st.sphereR * 0.92, 0.0);
    float auraCyan = exp(-haloR * 4.2) * rayMask;
    float auraViol = exp(-haloR * 1.85) * rayMask;

    // Dramatic volumetric radial light shafts beaming from the vortex
    float ang = atan(closest.y, closest.x);
    float shafts = fbm2(vec2(ang * 2.5 + st.tauP * 0.0, 1.7 + sin(st.tauP) * 0.15));
    float shafts2 = fbm2(vec2(ang * 5.0 - 2.3, 4.1 + cos(st.tauP) * 0.15));
    float rayBeam = pow(clamp(shafts * 0.6 + shafts2 * 0.5, 0.0, 1.0), 2.8) * exp(-haloR * 1.35) * rayMask;

    col += vec3(0.08, 0.76, 1.00) * auraCyan * (0.45 + 0.30 * st.burst + 0.16 * st.charge);
    col += vec3(0.42, 0.12, 0.92) * auraViol * (0.14 + 0.12 * st.burst);
    col += mix(vec3(0.16, 0.78, 1.00), vec3(0.68, 0.32, 1.00), shafts2) * rayBeam * (0.42 + 0.45 * st.burst);

    // Cell-safe floating golden/violet sparks in two depth planes
    for (int layer = 0; layer < 2; layer++) {
        float fl = float(layer);
        float zPlane = (layer == 0) ? 0.55 : -0.65;
        float tP = (zPlane - ro.z) / (rd.z + (abs(rd.z) < 1e-4 ? 1e-4 : 0.0));
        if (tP > 0.25 && tP < maxT) {
            vec2 sp = (ro + rd * tP).xy;
            float r = length(sp);
            vec2 dir = sp / max(r, 0.02);
            vec2 tang = vec2(-dir.y, dir.x);

            vec2 cellUV = sp * (2.6 + fl * 1.2);
            vec2 id = floor(cellUV);
            vec2 f  = fract(cellUV) - 0.5;
            vec2 rnd = hash22(id + fl * 17.3);

            vec2 pos = (rnd - 0.5) * 0.30 + 0.07 * vec2(
                sin(st.tauP + rnd.x * TAU),
                cos(st.tauP + rnd.y * TAU)
            );
            vec2 df = f - pos;
            float cellSafe = smoothstep(0.49, 0.34, max(abs(f.x), abs(f.y)));

            vec2 streakDir = normalize(tang * 0.72 + dir * 0.69);
            vec2 streakPerp = vec2(-streakDir.y, streakDir.x);
            float along = dot(df, streakDir);
            float perp  = dot(df, streakPerp);

            float sparkD = length(vec2(along * 0.62, perp * 2.15));
            float spark = exp(-pow(sparkD / 0.036, 2.0)) * step(0.64, rnd.x) * cellSafe;
            spark *= smoothstep(0.82, 1.35, r) * smoothstep(3.5, 1.8, r);

            vec3 sCol = (rnd.y > 0.32) ? vec3(1.0, 0.62, 0.12) : vec3(0.68, 0.22, 1.0);
            col += sCol * spark * (0.75 + 0.55 * st.burst) * (0.25 + 0.75 * sphereTrans);
        }
    }

    return col;
}

// -----------------------------------------------------------------------------
// Dark Architectural Obsidian Arena Backdrop
// -----------------------------------------------------------------------------
vec3 evalArenaBackdrop(vec3 ro, vec3 rd, AnimState st) {
    float elev = clamp(rd.y * 0.5 + 0.5, 0.0, 1.0);
    vec3 col = mix(vec3(0.0024, 0.0034, 0.0080), vec3(0.0014, 0.0020, 0.0050), elev);

    float a = dot(rd.xz, rd.xz);
    if (a > 1e-4) {
        float b = dot(ro.xz, rd.xz);
        float c = dot(ro.xz, ro.xz) - 7.2 * 7.2;
        float disc = b * b - a * c;
        if (disc > 0.0) {
            float tWall = (-b + sqrt(disc)) / a;
            if (tWall > 0.0) {
                vec3 wp = ro + rd * tWall;
                float ang = atan(wp.z, wp.x);
                float ribs = smoothstep(0.84, 0.97, abs(sin(ang * 14.0)));
                float tiers = smoothstep(0.88, 0.98, abs(sin(wp.y * 3.8)));
                vec3 wallBase = vec3(0.0020, 0.0028, 0.0064) * (1.0 + 0.55 * ribs + 0.35 * tiers);

                // Warm golden arena perimeter rail
                float rail = exp(-pow((wp.y - (FLOOR_Y + 0.06)) / 0.036, 2.0));
                wallBase += vec3(1.00, 0.58, 0.14) * rail * 0.55;

                // Subtle warm amber sconces along lower wall
                float sconceAng = fract(ang * 4.0 / PI + 0.5) - 0.5;
                float sconce = exp(-pow(sconceAng * 18.0, 2.0)) * exp(-pow((wp.y - (FLOOR_Y + 0.45)) / 0.09, 2.0));
                wallBase += vec3(1.00, 0.62, 0.18) * sconce * 0.25;

                // Subtle overhead stadium rig trusses & crisp compact corner lights
                float trussY = smoothstep(2.6, 3.8, wp.y);
                float spotY  = exp(-pow((wp.y - 3.65) / 0.12, 2.0));
                float spotX  = pow(clamp(sin(ang * 20.0) * 0.5 + 0.5, 0.0, 1.0), 32.0);
                float cornerMask = smoothstep(0.42, 0.68, abs(rd.x));
                wallBase += vec3(0.55, 0.68, 1.00) * spotY * spotX * cornerMask * 0.36;
                wallBase += vec3(0.003, 0.004, 0.009) * trussY * ribs;

                // Subtle atmospheric bounce from central nova
                float bounce = exp(-abs(wp.y - 0.15) * 0.55);
                wallBase += vec3(0.007, 0.015, 0.036) * bounce * (0.65 + 0.45 * st.burst);

                col = wallBase;
            }
        }
    }

    if (uLightMode == 3) {
        float backGlow = pow(max(dot(rd, normalize(vec3(0.0, 0.05, -1.0))), 0.0), 8.0);
        col += vec3(0.14, 0.34, 0.56) * backGlow * 0.75;
    }

    return col;
}

// -----------------------------------------------------------------------------
// Reflective Obsidian Arena Floor with Concentric Glowing Energy Rings
// -----------------------------------------------------------------------------
vec3 shadeObsidianFloor(vec3 p, vec3 rd, AnimState st, float jitter) {
    float r = length(p.xz);

    vec2 tileUV = p.xz * 0.68;
    vec2 tileID = floor(tileUV);
    vec2 tileF  = abs(fract(tileUV + 0.5) - 0.5);
    float seamD = min(tileF.x, tileF.y);
    float grout = 1.0 - smoothstep(0.008, 0.024, seamD);
    float tileSeed = hash12(tileID);

    float nRip1 = fbm2(p.xz * 2.4 + vec2(tileSeed * 7.0));
    float nRip2 = fbm2(p.xz * 2.4 + vec2(4.2, -2.7));
    vec3 nor = normalize(vec3(
        (nRip1 - 0.5) * 0.042,
        1.0,
        (nRip2 - 0.5) * 0.042
    ));

    vec3 baseAlb = vec3(0.0036, 0.0050, 0.0108) * (0.82 + 0.36 * tileSeed);
    baseAlb = mix(baseAlb, vec3(0.0018, 0.0024, 0.0052), grout * 0.75);

    // Concentric glowing energy rings beneath the sphere
    float rings = 0.0;
    float rRadii[5] = float[5](0.36, 0.58, 0.82, 1.10, 1.46);
    float rWidths[5] = float[5](0.018, 0.022, 0.026, 0.020, 0.015);
    for (int i = 0; i < 5; i++) {
        float fi = float(i);
        float dRing = abs(r - rRadii[i]);
        float chargeWave = sin(fi * 1.15 + st.tauP * 2.0) * 0.5 + 0.5;
        float ringBoost = mix(0.50 + 0.50 * chargeWave, 1.10, st.burst);
        float core = exp(-pow(dRing / rWidths[i], 2.0));
        float soft = exp(-dRing / (rWidths[i] * 3.4));
        rings += (core * 1.05 + soft * 0.20) * ringBoost;
    }

    float impactCore = exp(-r * r * 16.0);
    float impactHalo = exp(-r * 2.5);
    float impactBoost = 0.42 + 0.92 * st.boltPower + 0.30 * st.charge;

    vec3 ringCol = vec3(0.52, 0.82, 1.00) * rings * 0.72
                 + vec3(0.16, 0.65, 1.00) * impactHalo * impactBoost * 0.58
                 + vec3(0.92, 0.97, 1.00) * impactCore * impactBoost * 1.25;

    float perim = exp(-pow((r - 6.15) / 0.08, 2.0));
    ringCol += vec3(1.00, 0.60, 0.16) * perim * 0.72;

    // True raytraced volumetric reflection on wet obsidian floor
    vec3 rRd = reflect(rd, nor);
    vec3 rRo = p + nor * 0.005;

    vec3 reflBg = evalArenaBackdrop(rRo, rRd, st);
    vec4 reflSph = evalVolumetricPlasmaSphere(rRo, rRd, 16.0, st, 10, jitter);
    vec3 reflRing = evalVolumetricShockwave(rRo, rRd, 16.0, st, 8, jitter);
    vec3 reflCol = reflBg * reflSph.a + reflSph.rgb + reflRing * (0.35 + 0.65 * reflSph.a);
    reflCol += evalLightning(rRo, rRd, 16.0, st) * 0.80;
    reflCol += evalGodRaysAndSparks(rRo, rRd, 16.0, reflSph.a, st) * 0.65;

    float fres = 0.08 + 0.78 * pow(1.0 - clamp(dot(nor, -rd), 0.0, 1.0), 3.0);
    float reflStrength = fres * (0.82 - 0.38 * grout) * (0.85 + 0.15 * tileSeed);

    vec3 toNova = SPHERE_C - p;
    float dNova = length(toNova);
    vec3 lNova = toNova / max(dNova, 0.01);
    float novaDiff = max(dot(nor, lNova), 0.0) / (1.0 + 0.30 * dNova * dNova);
    vec3 novaTint = mix(vec3(0.16, 0.68, 1.0), vec3(0.55, 0.22, 1.0), smoothstep(0.6, 2.8, r));
    vec3 directCol = baseAlb * (0.55 + novaTint * novaDiff * (2.2 + 1.2 * st.burst));

    vec3 hNova = normalize(lNova - rd);
    float spec = pow(max(dot(nor, hNova), 0.0), 42.0) * (1.0 - 0.65 * grout);
    directCol += novaTint * spec * 0.26;

    if (uLightMode == 2) {
        vec3 lKey = normalize(vec3(0.90, 0.22, 0.36));
        float kDiff = max(dot(nor, lKey), 0.0);
        float kSpec = pow(max(dot(nor, normalize(lKey - rd)), 0.0), 48.0);
        directCol += vec3(0.95, 0.90, 0.84) * (0.12 * kDiff + 0.42 * kSpec);
    } else if (uLightMode == 3) {
        vec3 lBack = normalize(vec3(0.0, 0.24, -1.0));
        float bSpec = pow(max(dot(nor, normalize(lBack - rd)), 0.0), 28.0);
        directCol += vec3(0.35, 0.78, 1.0) * bSpec * 0.55;
    }

    vec3 col = directCol + reflCol * reflStrength + ringCol * (1.0 - 0.35 * grout);
    float fog = 1.0 - exp(-0.015 * r * r);
    col = mix(col, vec3(0.0022, 0.0032, 0.0076), clamp(fog * 0.70, 0.0, 0.70));
    return col;
}

// -----------------------------------------------------------------------------
// Neutral Grayscale Clay / Form Study Mode (uLightMode == 1, R == G == B)
// -----------------------------------------------------------------------------
vec3 renderClayMode(vec3 ro, vec3 rd, AnimState st) {
    float t = 0.0;
    float matId = -1.0;
    const float MAX_T = 16.0;

    for (int i = 0; i < 84; i++) {
        vec3 p = ro + rd * t;
        vec2 h = mapClay(p, st);
        if (h.x < 0.002) {
            matId = h.y;
            break;
        }
        t += h.x * 0.85;
        if (t > MAX_T) break;
    }

    float bg = mix(0.16, 0.24, clamp(rd.y * 0.5 + 0.5, 0.0, 1.0));
    if (matId < 0.0) return vec3(bg);

    vec3 p = ro + rd * t;
    vec3 nor = calcClayNormal(p, st);

    vec3 lKey  = normalize(vec3(0.62, 0.72, 0.52));
    vec3 lFill = normalize(vec3(-0.75, 0.30, 0.45));
    vec3 lRim  = normalize(vec3(0.05, 0.55, -0.82));

    float diffKey  = max(dot(nor, lKey), 0.0);
    float diffFill = max(dot(nor, lFill), 0.0);
    float rim      = pow(1.0 - clamp(dot(nor, -rd), 0.0, 1.0), 3.0) * (0.35 + 0.65 * max(dot(nor, lRim), 0.0));
    float spec     = pow(max(dot(nor, normalize(lKey - rd)), 0.0), 28.0);

    float occ = 0.0;
    for (int i = 1; i <= 3; i++) {
        float dist = 0.05 * float(i);
        occ += (dist - mapClay(p + nor * dist, st).x) / dist;
    }
    float ao = clamp(1.0 - 0.32 * occ, 0.25, 1.0);

    float alb = 0.54;
    if (matId > 1.5 && matId < 2.5) alb = 0.42;
    if (matId > 2.5 && matId < 3.5) alb = 0.62;
    if (matId > 3.5)                alb = 0.76;

    float lum = alb * (0.20 + 0.74 * diffKey + 0.24 * diffFill) * ao + 0.14 * spec + 0.22 * rim;
    float fog = 1.0 - exp(-0.012 * t * t);
    lum = mix(lum, bg, clamp(fog, 0.0, 0.75));
    return vec3(lum);
}

// -----------------------------------------------------------------------------
// 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 Entry Point
// -----------------------------------------------------------------------------
void main() {
    vec2 uv = (2.0 * gl_FragCoord.xy - uResolution) / max(uResolution.y, 1.0);
    AnimState st = evalAnim(uTime);

    vec3 ro, ta;
    float fl;
    if (uCamMode == 1) {
        // ~2.5x macro close-up on the translucent volumetric plasma core & inner lightning
        ro = vec3(0.08, -0.02, 1.66);
        ta = vec3(0.00,  0.02, 0.00);
        fl = 1.72;
    } else {
        ro = vec3(0.00, -0.32, 3.38);
        ta = vec3(0.00,  0.08, 0.00);
        fl = 1.32;
    }

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

    if (uLightMode == 1) {
        vec3 clay = renderClayMode(ro, rd, st);
        clay = pow(clamp(clay, 0.0, 1.0), vec3(1.0 / 2.2));
        fragColor = vec4(clay, 1.0);
        return;
    }

    // Interleaved gradient noise for smooth, zero-banding volumetric raymarch jitter
    float jitter = fract(52.9829189 * fract(dot(gl_FragCoord.xy, vec2(0.06711056, 0.00583715))));

    // 1. Opaque stage: obsidian arena floor or dark architectural backdrop
    float tFloor = (rd.y < -0.001) ? (FLOOR_Y - ro.y) / rd.y : 1e5;
    if (tFloor < 0.0) tFloor = 1e5;

    float maxT = 18.0;
    vec3 bgCol;
    if (tFloor < maxT) {
        maxT = tFloor;
        bgCol = shadeObsidianFloor(ro + rd * tFloor, rd, st, jitter);
    } else {
        bgCol = evalArenaBackdrop(ro, rd, st);
    }

    // 2. True volumetric translucent plasma singularity vortex sphere
    vec4 sphVol = evalVolumetricPlasmaSphere(ro, rd, maxT, st, 22, jitter);

    // 3. True volumetric turbulent golden-violet shockwave nebula ring
    // Split depth cleanly: back half of ring is partially occluded by the dense singularity core
    float tSphereCenter = max(dot(SPHERE_C - ro, rd), 0.0);
    vec3 ringBack  = evalVolumetricShockwave(ro + rd * min(tSphereCenter, maxT), rd, max(maxT - tSphereCenter, 0.0), st, 10, jitter);
    vec3 ringFront = evalVolumetricShockwave(ro, rd, min(tSphereCenter, maxT), st, 12, jitter);

    vec3 col = (bgCol + ringBack) * sphVol.a + sphVol.rgb + ringFront;

    // 4. Crackling multi-branch 3D lightning, volumetric god-rays, and sparks
    col += evalLightning(ro, rd, maxT, st);
    col += evalGodRaysAndSparks(ro, rd, maxT, sphVol.a, st);

    // 5. Exposure + ACES filmic tonemapping + dark obsidian floor clamp + sRGB gamma + dither
    col *= 0.88;
    col = acesFilm(col);
    col = max(col, vec3(0.0014));
    col = pow(col, vec3(1.0 / 2.2));

    float dither = (hash12(gl_FragCoord.xy + fract(uTime)) + hash12(gl_FragCoord.xy + 19.3) - 1.0) / 255.0;
    col = clamp(col + dither, 0.0, 1.0);

    fragColor = vec4(col, 1.0);
}

Mathematical models & shader specifications

Identifiercharge-and-release-energy-nova
CategoryGame VFX Shaders · Choreographed Loop VFX
Upstream studyvfx_animated/lib/01_charge_and_release_energy_nova.glsl (commit f3d2025)
Animation cycleContinuous procedural uTime
Declared uniformsuResolution, uTime, uOpen, uLightMode, uCamMode
Source size1092 lines · 43.5 KB standalone GLSL ES 3.00
PNG baker outputs512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key)
Companion pixel VFXFree MIT explosions sprite sheets
LicenseMIT License + CC0 / MIT Helpers

Physical & shading models implemented

Schlick Fresnel reflectance (1994); Beer–Lambert volumetric absorption/attenuation

Adapted upstream mathematical helpers

David Hoskins, hash · Krzysztof Narkowicz, filmic curve · Inigo Quilez, tetrahedral SDF normal · Jorge Jimenez, Interleaved Gradient Noise

All game vfx shaders