Jade Wind Tornado Ribbons shader

jade-wind-tornado-ribbons.glsl · 701 lines · GLSL ES 3.00 · MIT

Jade Wind Tornado RibbonsGame VFX3s Loop
Jade Wind Tornado Ribbons WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 701 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

Stylized Cel VFX
jade-wind-tornado-ribbons.glsl (701 lines)
#version 300 es
// Jade Wind Tornado Ribbons (jade-wind-tornado-ribbons.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_stylized/lib/09_jade_wind_tornado_ribbons.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;

// ============================================================================
// STYLIZED JADE WIND TORNADO PALETTE (SPIDER-VERSE / HADES / VALORANT)
// ============================================================================
// Linear-space albedos tuned so post-ACES/gamma dark floor lands near sRGB (0.08,0.09,0.12)
const vec3 COL_FLOOR_LIN    = vec3(0.011, 0.013, 0.019);
const vec3 COL_INK          = vec3(0.0018, 0.0022, 0.0032);
const vec3 COL_JADE_DEEP    = vec3(0.018, 0.22, 0.17);
const vec3 COL_JADE_MID     = vec3(0.08, 0.62, 0.42);
const vec3 COL_JADE_BRIGHT  = vec3(0.42, 0.94, 0.70);
const vec3 COL_MINT_WHITE   = vec3(0.92, 1.00, 0.96);
const vec3 COL_LEAF_DARK    = vec3(0.05, 0.28, 0.03);
const vec3 COL_LEAF_MID     = vec3(0.20, 0.72, 0.08);
const vec3 COL_LEAF_BRIGHT  = vec3(0.54, 0.95, 0.18);
const vec3 COL_ARENA_RED    = vec3(0.48, 0.04, 0.06);

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

// Material IDs
const float MAT_FLOOR    = 1.0;
const float MAT_RIBBON   = 2.0;
const float MAT_CRESCENT = 3.0;
const float MAT_LEAF     = 4.0;
const float MAT_BLADE    = 5.0;

// ============================================================================
// MATH & NOISE UTILITIES
// ============================================================================
mat2 rot2D(float a) {
    float c = cos(a);
    float s = sin(a);
    return mat2(c, -s, s, c);
}

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 noise2D(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 smin(float a, float b, float k) {
    float h = clamp(0.5 + 0.5 * (b - a) / max(k, 1e-5), 0.0, 1.0);
    return mix(b, a, h) - k * h * (1.0 - h);
}

vec2 opU(vec2 a, vec2 b) {
    return (a.x < b.x) ? a : b;
}

// ============================================================================
// TORNADO SPINE & FUNNEL PROFILE
// ============================================================================
vec2 tornadoSpine(float y, float phase, float openAmt) {
    float h = clamp(y * 0.3846, 0.0, 1.0);
    float sway = (0.06 + 0.08 * openAmt) * h * h;
    return vec2(
        sin(h * 3.1 - phase) * sway,
        cos(h * 2.6 - phase) * sway * 0.85
    );
}

float funnelRadius(float y, float openAmt) {
    float h = clamp(y * 0.3774, 0.0, 1.0);
    float flare = mix(0.76, 1.18, openAmt);
    float baseR = 0.24 * mix(0.85, 1.12, openAmt);
    // Cheap h * sqrt(h) ≈ h^1.5 avoiding expensive pow()
    return baseR + (0.28 * h + 0.92 * h * sqrt(h)) * flare;
}

// ============================================================================
// HELICAL CEL-SHADED WIND RIBBONS SDF
// ============================================================================
float sdHelixRibbons(vec3 p, float phase, float openAmt) {
    float rXZ = length(p.xz);
    float dBound = max(rXZ - 2.25, max(-p.y - 0.05, p.y - 3.05));
    if (dBound > 0.25) return dBound;

    vec2 spine = tornadoSpine(p.y, phase, openAmt);
    vec3 q = p;
    q.xz -= spine;

    float r = length(q.xz);
    float ang = atan(q.z, q.x);
    float h = clamp(q.y * 0.3774, 0.0, 1.0);
    float rFunnel = funnelRadius(q.y, openAmt);

    // 1. PRIMARY OUTER STACKED CONICAL WIND RIBBONS (2-start seamless helix)
    float twist1 = 8.4;
    float phi1 = 2.0 * (ang - phase) - q.y * twist1;
    float dPhi1 = atan(sin(phi1), cos(phi1));
    float dy1 = dPhi1 / twist1;

    float ripple1 = 0.055 * sin(ang * 3.0 - phase * 2.0 + q.y * 2.2) * smoothstep(0.05, 0.4, h);
    float dr1 = r - (rFunnel + ripple1);

    float tilt1 = mix(0.32, 0.62, h);
    vec2 cs1 = rot2D(tilt1) * vec2(dr1, dy1);

    float endTaper1 = smoothstep(0.02, 0.14, h) * smoothstep(1.02, 0.78, h);
    float windNotch1 = 0.85 + 0.15 * sin(ang * 5.0 - phase * 2.0 + q.y * 5.0);
    float halfH1 = mix(0.068, 0.150, h) * mix(0.84, 1.16, openAmt) * endTaper1 * windNotch1;
    float halfT1 = mix(0.024, 0.038, h) * endTaper1;

    vec2 box1 = abs(cs1) - vec2(halfT1, halfH1);
    float dRib1 = length(max(box1, 0.0)) + min(max(box1.x, box1.y), 0.0) - 0.008;
    dRib1 = max(dRib1, max(0.05 - q.y, q.y - 2.68));

    // 2. SECONDARY INNER CORE SPIRAL RIBBONS
    float twist2 = 10.5;
    float phi2 = 2.0 * (ang - phase * 2.0) - q.y * twist2 + 1.57;
    float dPhi2 = atan(sin(phi2), cos(phi2));
    float dy2 = dPhi2 / twist2;
    float dr2 = r - (rFunnel * 0.68 + 0.03 * cos(ang * 2.0 + q.y * 3.0 - phase));

    vec2 cs2 = rot2D(0.45) * vec2(dr2, dy2);
    float endTaper2 = smoothstep(0.04, 0.18, h) * smoothstep(0.92, 0.68, h);
    float halfH2 = mix(0.044, 0.090, h) * mix(0.80, 1.15, openAmt) * endTaper2;
    float halfT2 = 0.019 * endTaper2;
    vec2 box2 = abs(cs2) - vec2(halfT2, halfH2);
    float dRib2 = length(max(box2, 0.0)) + min(max(box2.x, box2.y), 0.0) - 0.006;
    dRib2 = max(dRib2, max(0.08 - q.y, q.y - 2.38));

    // 3. GROUND BASE SWIRLING VORTEX RING
    float baseAng = ang - phase;
    float arcMask = 0.5 + 0.5 * cos(baseAng);
    float baseR = mix(0.62, 0.92, openAmt) + 0.10 * sin(baseAng * 2.0);
    vec2 csBase = rot2D(0.28) * vec2(r - baseR, q.y - (0.095 + 0.045 * sin(baseAng)));
    float wBase = mix(0.035, 0.135, smoothstep(0.05, 0.85, arcMask));
    float tBase = mix(0.015, 0.038, smoothstep(0.05, 0.75, arcMask));
    vec2 boxBase = abs(csBase) - vec2(wBase, tBase);
    float dBaseRing = length(max(boxBase, 0.0)) + min(max(boxBase.x, boxBase.y), 0.0) - 0.007;

    // 4. UPPER TRAILING OUTER WIND-PLUME ARC
    float plumeAng = ang - phase + 0.9;
    float plumeWrap = atan(sin(plumeAng), cos(plumeAng));
    float plumeT = clamp((plumeWrap + 1.8) / 3.4, 0.0, 1.0);
    float plumeArc = smoothstep(0.0, 0.22, plumeT) * smoothstep(1.0, 0.18, plumeT);
    float plumeR = funnelRadius(2.45, openAmt) * (1.14 + 0.24 * plumeT);
    float plumeY = 2.15 + 0.62 * sin(plumeT * PI * 0.85) - 0.28 * plumeT;
    vec2 csPlume = rot2D(0.65) * vec2(r - plumeR, q.y - plumeY);
    float wPlume = 0.145 * plumeArc * mix(0.75, 1.15, openAmt);
    float tPlume = 0.024 * plumeArc;
    vec2 boxPlume = abs(csPlume) - vec2(tPlume, wPlume);
    float dPlume = length(max(boxPlume, 0.0)) + min(max(boxPlume.x, boxPlume.y), 0.0) - 0.006;
    dPlume = max(dPlume, abs(plumeWrap) - 1.85);

    float d = min(dRib1, dRib2);
    d = smin(d, dBaseRing, 0.03);
    d = min(d, dPlume);

    return d * 0.65;
}

// ============================================================================
// SHARP WHITE CRESCENT AIR-SLASH HIGHLIGHTS SDF
// ============================================================================
float sdCrescentArc(vec3 p, float rad, float thick, float width) {
    float dOuter = length(p.xy) - rad;
    float dInner = length(p.xy - vec2(rad * 0.34, rad * 0.22)) - rad * 0.86;
    float d2D = max(dOuter, -dInner);
    float dZ = abs(p.z) - thick;
    vec2 w = vec2(d2D, dZ);
    return min(max(w.x, w.y), 0.0) + length(max(w, 0.0)) - width;
}

float sdAirSlashes(vec3 p, float phase, float openAmt) {
    // Cheap bounding cylinder early-out
    float dBound = max(length(p.xz) - 2.15, max(0.65 - p.y, p.y - 2.95));
    if (dBound > 0.25) return dBound;

    float scale = mix(0.84, 1.14, openAmt);
    float d = 1e5;

    // 1. Hero lower-front bright crescent air-slash hugging the tornado waist
    {
        vec3 q = p - vec3(0.0, 1.25, 0.0);
        q.xz = rot2D(-phase + 0.55) * q.xz;
        q -= vec3(0.0, 0.0, 0.96 * scale);
        if (length(q) < 0.55 * scale) {
            q.xy = rot2D(0.55) * q.xy;
            q.yz = rot2D(-0.32) * q.yz;
            d = min(d, sdCrescentArc(q, 0.42 * scale, 0.018, 0.008));
        }
    }

    // 2. Upper-right luminous air-slash crescent orbiting high rim
    {
        vec3 q = p - vec3(0.0, 2.38, 0.0);
        q.xz = rot2D(-phase - 1.25) * q.xz;
        q -= vec3(0.0, 0.0, 1.38 * scale);
        if (length(q) < 0.46 * scale) {
            q.xy = rot2D(-2.25) * q.xy;
            q.xz = rot2D(0.35) * q.xz;
            d = min(d, sdCrescentArc(q, 0.34 * scale, 0.016, 0.007));
        }
    }

    // 3. Mid-back sweeping crescent accent
    {
        vec3 q = p - vec3(0.0, 1.72, 0.0);
        q.xz = rot2D(-phase + 2.65) * q.xz;
        q -= vec3(0.0, 0.0, 1.18 * scale);
        if (length(q) < 0.42 * scale) {
            q.xy = rot2D(1.35) * q.xy;
            d = min(d, sdCrescentArc(q, 0.30 * scale, 0.015, 0.007));
        }
    }

    return d;
}

// ============================================================================
// STYLIZED WIND-DAGGER SHARDS SDF (METALLIC-MINT & JADE)
// ============================================================================
float sdWindBlade(vec3 p, float sz) {
    vec3 q = p / sz;
    q.y -= 0.16 * q.x * q.x;
    float t = clamp((q.x + 0.48) * 0.8197, 0.0, 1.0);
    float halfW = mix(0.22, 0.006, sqrt(t));
    float dHilt = (t - 0.18) * 10.0;
    halfW += 0.10 * exp(-dHilt * dHilt);
    float halfT = mix(0.032, 0.006, t);

    vec3 b = abs(q - vec3(0.12, 0.0, 0.0)) - vec3(0.60, halfW, halfT);
    float d = length(max(b, 0.0)) + min(max(b.x, max(b.y, b.z)), 0.0);
    return d * sz * 0.78;
}

float sdWindBlades(vec3 p, float phase, float openAmt) {
    // Cheap bounding cylinder early-out
    float dBound = max(length(p.xz) - 2.35, max(0.35 - p.y, p.y - 2.85));
    if (dBound > 0.25) return dBound;

    float scale = mix(0.84, 1.16, openAmt);
    float sz = 0.42 * mix(0.85, 1.12, openAmt);
    float d = 1e5;

    for (int i = 0; i < 4; i++) {
        float fi = float(i);
        float ang = phase + fi * (TAU * 0.25) + 0.42;
        float yPos = 0.85 + fi * 0.48 + 0.08 * sin(phase + fi * 1.7);
        float rad = funnelRadius(yPos, openAmt) + 0.24 * scale;

        vec3 q = p - vec3(cos(ang) * rad, yPos, sin(ang) * rad);
        float dSph = length(q) - sz * 0.95;
        if (dSph < d) {
            q.xz = rot2D(ang + PI * 0.5) * q.xz;
            q.xy = rot2D(0.28 + 0.12 * sin(fi * 2.1)) * q.xy;
            q.yz = rot2D(0.35 * cos(fi * 1.9)) * q.yz;
            d = min(d, sdWindBlade(q, sz));
        }
    }
    return d;
}

// ============================================================================
// ORBITING INK-OUTLINED EMERALD LEAF-BLADES SDF (7 CRISP LEAVES)
// ============================================================================
float sdSingleLeaf(vec3 p, float sz) {
    vec3 q = p / sz;
    q.y -= 0.18 * q.x * q.x - 0.12 * q.z * q.z;
    float nx = abs(q.x);
    float maxZ = 0.44 * max(1.0 - nx * nx, 0.0);
    float dXZ = max(nx - 1.0, abs(q.z) - maxZ);
    float dY = abs(q.y) - 0.035;
    vec2 w = vec2(dXZ, dY);
    float d = min(max(w.x, w.y), 0.0) + length(max(w, 0.0)) - 0.012;
    return d * sz * 0.78;
}

float sdOrbitingLeaves(vec3 p, float phase, float openAmt) {
    float dBound = max(length(p.xz) - 2.85, max(0.05 - p.y, p.y - 3.25));
    if (dBound > 0.25) return dBound;

    float d = 1e5;
    float spread = mix(0.82, 1.18, openAmt);

    for (int i = 0; i < 7; i++) {
        float fi = float(i);
        float h0 = hash11(fi * 17.31 + 3.1);
        float h1 = hash11(fi * 29.73 + 7.4);
        float h2 = hash11(fi * 43.19 + 1.9);

        float speed = (mod(fi, 2.0) < 0.5) ? 1.0 : 2.0;
        float ang = phase * speed + fi * 0.8976 + h0 * 0.8;
        float yBase = 0.35 + h1 * 2.35 + 0.15 * sin(phase + fi * 1.3);
        float rad = (funnelRadius(yBase, openAmt) + 0.34 + 0.52 * h2) * spread;

        vec3 q = p - vec3(cos(ang) * rad, yBase, sin(ang) * rad);
        float leafSz = mix(0.13, 0.21, h0);
        float dSph = length(q) - leafSz * 1.25;
        if (dSph < d) {
            q.xz = rot2D(ang + phase) * q.xz;
            q.xy = rot2D(h1 * TAU + sin(phase + fi) * 0.65) * q.xy;
            q.yz = rot2D(h2 * TAU + cos(phase + fi) * 0.55) * q.yz;
            d = min(d, sdSingleLeaf(q, leafSz));
        }
    }
    return d;
}

// ============================================================================
// COMBINED VORTEX SCENE SDF (FLOOR IS INTERSECTED ANALYTICALLY!)
// ============================================================================
vec2 mapVortex(vec3 p, float phase, float openAmt) {
    vec2 res = vec2(sdHelixRibbons(p, phase, openAmt), MAT_RIBBON);
    res = opU(res, vec2(sdAirSlashes(p, phase, openAmt), MAT_CRESCENT));
    res = opU(res, vec2(sdWindBlades(p, phase, openAmt), MAT_BLADE));
    res = opU(res, vec2(sdOrbitingLeaves(p, phase, openAmt), MAT_LEAF));
    return res;
}

// Unit-weight tetrahedral normal for vortex geometry
vec3 calcNormal(vec3 p, float phase, float openAmt) {
    const float h = 0.0022;
    const vec2 k = vec2(1.0, -1.0);
    vec3 n = k.xyy * mapVortex(p + k.xyy * h, phase, openAmt).x +
             k.yyx * mapVortex(p + k.yyx * h, phase, openAmt).x +
             k.yxy * mapVortex(p + k.yxy * h, phase, openAmt).x +
             k.xxx * mapVortex(p + k.xxx * h, phase, openAmt).x;
    return normalize(n + vec3(1e-7));
}

// ============================================================================
// LIGHTING & QUANTIZED 3-BAND CEL SHADING
// ============================================================================
vec3 getLightDir() {
    if (uLightMode == 2) {
        return normalize(vec3(-0.88, 0.36, 0.30)); // Grazing side rim light
    } else if (uLightMode == 3) {
        return normalize(vec3(-0.22, 0.52, -0.82)); // Dramatic backlit rim
    }
    return normalize(vec3(0.58, 0.82, 0.48)); // Hero 3/4 key light
}

float cel3Band(float ndl) {
    float b1 = smoothstep(0.06, 0.12, ndl);
    float b2 = smoothstep(0.50, 0.56, ndl);
    return 0.24 + 0.42 * b1 + 0.34 * b2;
}

// ============================================================================
// FLOATING GRAPHIC WIND-EDDY CONCENTRIC RINGS (2D/3D ACCENT)
// ============================================================================
vec3 evalWindEddyRings(vec3 ro, vec3 rd, float tMax, float phase, float openAmt) {
    vec3 acc = vec3(0.0);
    float spread = mix(0.85, 1.15, openAmt);

    for (int i = 0; i < 5; i++) {
        float fi = float(i);
        float ang = phase + fi * 1.2566 + 0.7;
        float y = 0.65 + fi * 0.44 + 0.08 * sin(phase + fi * 2.0);
        float rad = (1.32 + 0.48 * hash11(fi * 11.7)) * spread;
        vec3 center = vec3(cos(ang) * rad, y, sin(ang) * rad);

        vec3 toC = center - ro;
        float t = dot(toC, rd);
        if (t > 0.2 && t < tMax) {
            float d = length(ro + rd * t - center);
            float rOuter = smoothstep(0.012, 0.002, abs(d - 0.115));
            float rInner = smoothstep(0.011, 0.002, abs(d - 0.065));
            float pulse = 0.65 + 0.35 * sin(phase + fi * 1.9);
            float ringMask = max(rOuter, rInner) * pulse;
            acc += mix(COL_JADE_MID, COL_JADE_BRIGHT, rInner) * ringMask * 0.68;
        }
    }
    return acc;
}

// ============================================================================
// FLOOR SHADING (ANALYTIC SHADOW + INK-GROUTED CHARCOAL TILES)
// ============================================================================
vec3 shadeFloor(vec3 p, vec3 lightDir, float phase, float openAmt) {
    vec2 fp = rot2D(0.28) * p.xz;
    vec2 tileId = floor(fp * 0.85);
    vec2 tileUv = fract(fp * 0.85);

    // Crisp black-ink grout lines between matte charcoal tiles
    vec2 groutD = min(tileUv, 1.0 - tileUv);
    float groutLine = 1.0 - smoothstep(0.018, 0.036, min(groutD.x, groutD.y));

    // Subtle hand-inked tile grain & variation
    float tileVar = (hash12(tileId) - 0.5) * 0.0032;
    float grain = (noise2D(fp * 6.5) - 0.5) * 0.0028;
    vec3 baseFloor = COL_FLOOR_LIN + vec3(tileVar + grain);

    // Distant crimson arena boundary trim ring (matching 09.png top)
    float distR = length(p.xz);
    float arenaTrim = smoothstep(0.065, 0.015, abs(distR - 5.15));
    float trimInk   = smoothstep(0.115, 0.055, abs(distR - 5.15));
    if (uLightMode != 1) {
        baseFloor = mix(baseFloor, COL_INK, trimInk * 0.75);
        baseFloor = mix(baseFloor, COL_ARENA_RED * 0.42, arenaTrim);
    }

    // Fast analytic cast shadow of the funnel cone on y = 0
    vec2 shDir = lightDir.xz / max(lightDir.y, 0.25);
    vec2 shCenter = -shDir * 0.95;
    vec2 dSh = p.xz - shCenter;
    float shProj = length(dSh / vec2(mix(1.15, 1.55, openAmt), mix(1.05, 1.45, openAmt)));
    float shBand = mix(0.46, 1.0, smoothstep(0.75, 1.15, shProj));

    // Dark vortex eye right at center base
    float eyeDark = mix(0.28, 1.0, smoothstep(0.25, 0.82, distR));

    // Quantized seafoam-jade bounce illumination on charcoal tiles
    float glowRing = exp(-pow((distR - mix(0.68, 1.05, openAmt)) * 1.45, 2.0));
    float glowCore = exp(-distR * distR * 0.48);
    float swirlCaustic = 0.5 + 0.5 * sin(atan(p.z, p.x) * 3.0 - phase + distR * 4.5);
    float bounceMask = (glowRing * 0.65 + glowCore * 0.35) * (0.72 + 0.28 * swirlCaustic) * mix(0.65, 1.15, openAmt);

    vec3 col = baseFloor * shBand * eyeDark;
    if (uLightMode != 1) {
        float bounceBand = smoothstep(0.18, 0.26, bounceMask) * 0.45 + smoothstep(0.52, 0.60, bounceMask) * 0.55;
        col += mix(COL_JADE_DEEP, COL_JADE_MID, bounceBand) * bounceMask * 0.22;
    }

    // Apply crisp black-ink grout lines
    col = mix(col, COL_INK, groutLine * 0.94);

    // Subtle distance fade toward arena horizon
    float fog = smoothstep(5.5, 16.0, distR);
    col = mix(col, COL_FLOOR_LIN * 0.48, fog);

    if (uLightMode == 1) {
        float lum = dot(col, vec3(0.2126, 0.7152, 0.0722));
        col = vec3(lum);
    }
    return col;
}

// ============================================================================
// VORTEX MATERIAL SHADING (BOLD INK CONTOURS + 3-BAND CEL)
// ============================================================================
vec3 shadeVortex(vec3 p, vec3 n, vec3 v, vec3 lightDir, float matID, float minEdge, float phase, float openAmt) {
    float ndl = dot(n, lightDir);
    float ndv = max(dot(n, v), 0.0);
    float cel = cel3Band(ndl);

    vec3 col = COL_JADE_MID;

    if (matID < 2.5) {
        // MAT_RIBBON: SEAFOAM JADE-GREEN & MINT-WHITE CEL-SHADED WIND RIBBONS
        float h = clamp(p.y * 0.3774, 0.0, 1.0);
        float ang = atan(p.z, p.x);

        float streakVal = sin(p.y * 28.0 - ang * 4.0 + phase * 2.0);
        float speedStreak = smoothstep(0.62, 0.76, streakVal);
        float darkStreak  = smoothstep(0.84, 0.92, -streakVal);

        vec3 cBand = COL_JADE_DEEP;
        cBand = mix(cBand, COL_JADE_MID, smoothstep(0.32, 0.38, cel));
        cBand = mix(cBand, COL_JADE_BRIGHT, smoothstep(0.70, 0.76, cel));

        float topLift = smoothstep(0.35, 0.95, h) * 0.32;
        cBand = mix(cBand, COL_MINT_WHITE, clamp(speedStreak * 0.48 + topLift * smoothstep(0.45, 0.55, cel), 0.0, 0.85));
        cBand = mix(cBand, COL_JADE_DEEP * 0.38, darkStreak * 0.58);

        float fresnelInk = smoothstep(0.56, 0.72, 1.0 - ndv);
        float silInk = smoothstep(0.022, 0.008, minEdge);
        float inkMask = max(fresnelInk, silInk * 0.85);

        col = mix(cBand, COL_INK, inkMask * 0.95);
    }
    else if (matID < 3.5) {
        // MAT_CRESCENT: SHARP WHITE CRESCENT AIR-SLASH HIGHLIGHTS
        vec3 slashCol = mix(COL_JADE_BRIGHT, COL_MINT_WHITE, smoothstep(0.18, 0.42, ndv));
        slashCol *= mix(1.02, 1.24, openAmt);
        float inkMask = smoothstep(0.60, 0.76, 1.0 - ndv);
        col = mix(slashCol, COL_INK, inkMask * 0.94);
    }
    else if (matID < 4.5) {
        // MAT_LEAF: ORBITING INK-OUTLINED EMERALD LEAF-BLADES
        vec3 leafCol = COL_LEAF_DARK;
        leafCol = mix(leafCol, COL_LEAF_MID, smoothstep(0.32, 0.38, cel));
        leafCol = mix(leafCol, COL_LEAF_BRIGHT, smoothstep(0.72, 0.78, cel));

        float vein = smoothstep(0.92, 0.98, abs(sin((p.x + p.y + p.z) * 24.0)));
        leafCol = mix(leafCol, COL_LEAF_DARK * 0.42, vein * 0.45);

        float inkMask = smoothstep(0.50, 0.68, 1.0 - ndv);
        col = mix(leafCol, COL_INK, inkMask * 0.96);
    }
    else {
        // MAT_BLADE: STYLIZED WIND-DAGGER SHARDS
        float facet = smoothstep(0.42, 0.50, cel);
        vec3 metalCol = mix(vec3(0.38, 0.56, 0.52), vec3(0.84, 0.94, 0.91), facet);
        float inlay = smoothstep(0.2, 0.5, sin(p.y * 14.0 + p.x * 10.0));
        vec3 bladeCol = mix(COL_JADE_MID, metalCol, inlay);

        float inkMask = smoothstep(0.54, 0.70, 1.0 - ndv);
        col = mix(bladeCol, COL_INK, inkMask * 0.95);
    }

    if (uLightMode == 1) {
        float lum = dot(col, vec3(0.2126, 0.7152, 0.0722));
        col = vec3(lum);
    }
    return col;
}

// ============================================================================
// ACES FILMIC TONE MAPPING (PREVENTING >1% CLIPPING)
// ============================================================================
vec3 acesToneMap(vec3 x) {
    x = 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, 1.0);
}

// ============================================================================
// FAST ANALYTIC BOUNDING CYLINDER INTERSECTION (r <= R, y in [yMin, yMax])
// ============================================================================
vec2 intersectCylinder(vec3 ro, vec3 rd, float R, float yMin, float yMax) {
    float a = dot(rd.xz, rd.xz);
    float b = dot(ro.xz, rd.xz);
    float c = dot(ro.xz, ro.xz) - R * R;

    float tMin = 0.05;
    float tMax = 1e5;

    if (a > 1e-6) {
        float disc = b * b - a * c;
        if (disc < 0.0) return vec2(1.0, -1.0);
        float sq = sqrt(max(disc, 0.0));
        tMin = max(tMin, (-b - sq) / a);
        tMax = min(tMax, (-b + sq) / a);
    } else if (c > 0.0) {
        return vec2(1.0, -1.0);
    }

    if (abs(rd.y) > 1e-6) {
        float ty1 = (yMin - ro.y) / rd.y;
        float ty2 = (yMax - ro.y) / rd.y;
        tMin = max(tMin, min(ty1, ty2));
        tMax = min(tMax, max(ty1, ty2));
    } else if (ro.y < yMin || ro.y > yMax) {
        return vec2(1.0, -1.0);
    }

    return vec2(tMin, tMax);
}

// ============================================================================
// MAIN RENDER ENTRY
// ============================================================================
void main() {
    vec2 res = max(uResolution, vec2(1.0));
    vec2 uv = (gl_FragCoord.xy - 0.5 * res) / min(res.x, res.y);

    // Seamless 3.0s loop phase
    float phase = TAU * fract(uTime / 3.0);
    float openAmt = clamp(uOpen, 0.0, 1.0);
    vec3 lightDir = getLightDir();

    // Camera setup:
    // 0 = Hero 3/4 high-angle Hades/Valorant view looking into the jade vortex
    // 1 = Close-up macro on swirling upper ribbons, white crescent & emerald leaves
    vec3 ro, ta;
    float focal;
    if (uCamMode == 1) {
        ro = vec3(0.75, 2.35, 2.35);
        ta = vec3(-0.05, 1.55, 0.0);
        focal = 1.95;
    } else {
        ro = vec3(0.38, 3.45, 4.35);
        ta = vec3(-0.02, 1.18, 0.0);
        focal = 1.58;
    }

    vec3 cw = normalize(ta - ro);
    vec3 cu = normalize(cross(cw, vec3(0.0, 1.0, 0.0)));
    vec3 cv = cross(cu, cw);
    vec3 rd = normalize(uv.x * cu + uv.y * cv + focal * cw);

    const float MAX_DIST = 24.0;

    // ------------------------------------------------------------------------
    // 1. ANALYTIC FLOOR INTERSECTION (ZERO RAYMARCH COST FOR FLOOR PIXELS)
    // ------------------------------------------------------------------------
    float tFloor = MAX_DIST;
    bool hitFloor = false;
    if (rd.y < -1e-4) {
        float tf = -ro.y / rd.y;
        if (tf > 0.05 && tf < MAX_DIST) {
            tFloor = tf;
            hitFloor = true;
        }
    }

    // Background deep matte charcoal arena backdrop
    vec3 col = mix(COL_FLOOR_LIN * 0.45, COL_FLOOR_LIN * 0.80, smoothstep(-0.15, 0.55, rd.y));
    if (uLightMode == 1) {
        col = vec3(dot(col, vec3(0.2126, 0.7152, 0.0722)));
    }
    if (hitFloor) {
        col = shadeFloor(ro + rd * tFloor, lightDir, phase, openAmt);
    }

    // ------------------------------------------------------------------------
    // 2. BOUNDED RAYMARCH OF VORTEX GEOMETRY ONLY (TIGHT CYLINDER, <=64 STEPS)
    // ------------------------------------------------------------------------
    float tHit = tFloor;
    vec2 cyl = intersectCylinder(ro, rd, 3.0, 0.0, 3.3);
    float tStart = cyl.x;
    float tEnd = min(cyl.y, tFloor);

    if (tEnd > tStart) {
        float t = tStart;
        float matID = 0.0;
        bool hitVortex = false;
        float minEdge = 1e5;

        for (int i = 0; i < 64; i++) {
            vec3 p = ro + rd * t;
            vec2 m = mapVortex(p, phase, openAmt);
            minEdge = min(minEdge, m.x);
            if (m.x < 0.0018) {
                matID = m.y;
                hitVortex = true;
                break;
            }
            t += m.x * 0.90;
            if (t > tEnd) break;
        }

        if (hitVortex) {
            tHit = t;
            vec3 p = ro + rd * t;
            vec3 n = calcNormal(p, phase, openAmt);
            col = shadeVortex(p, n, -rd, lightDir, matID, minEdge, phase, openAmt);
        }
    }

    // ------------------------------------------------------------------------
    // 3. SUBTLE STYLIZED JADE ATMOSPHERIC VORTEX GLOW + CONCENTRIC EDDY RINGS
    // ------------------------------------------------------------------------
    if (uLightMode != 1) {
        vec3 coreCenter = vec3(0.0, 1.35, 0.0);
        vec3 toCore = coreCenter - ro;
        float tCore = clamp(dot(toCore, rd), 0.0, tHit);
        float dCore = length(ro + rd * tCore - coreCenter);
        float aura = exp(-dCore * dCore * 0.90) * 0.12 * mix(0.65, 1.15, openAmt);
        col += mix(COL_JADE_MID, COL_JADE_BRIGHT, 0.45) * aura;

        col += evalWindEddyRings(ro, rd, tHit, phase, openAmt);
    }

    // ------------------------------------------------------------------------
    // 4. POST-PROCESSING: ACES TONE MAP + GAMMA + SAFE BLACK FLOOR (<2% BLACK)
    // ------------------------------------------------------------------------
    float vig = 1.0 - 0.16 * dot(uv, uv);
    col *= clamp(vig, 0.74, 1.0);

    col = acesToneMap(col * 0.94);
    col = pow(max(col, vec3(0.0)), vec3(1.0 / 2.2));

    if (uLightMode == 1) {
        float lum = dot(col, vec3(0.2126, 0.7152, 0.0722));
        col = vec3(max(lum, 0.032));
    } else {
        col = max(col, vec3(0.024, 0.030, 0.038));
    }

    fragColor = vec4(col, 1.0);
}

Mathematical models & shader specifications

Identifierjade-wind-tornado-ribbons
CategoryGame VFX Shaders · Stylized Cel VFX
Upstream studyvfx_stylized/lib/09_jade_wind_tornado_ribbons.glsl (commit f5bfb61)
Animation cycle3.0 s seamless harmonic loop
Declared uniformsuResolution, uTime, uOpen, uLightMode, uCamMode
Source size701 lines · 26.3 KB standalone GLSL ES 3.00
PNG baker outputs512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key)
Companion pixel VFXFree MIT weather 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, quadratic distance blend · Inigo Quilez, tetrahedral SDF normal

All game vfx shaders