Arcane Ground Slam Sigil shader

arcane-ground-slam-sigil.glsl · 934 lines · GLSL ES 3.00 · MIT

Arcane Ground Slam SigilGame VFX
Arcane Ground Slam Sigil WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 934 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

Arcane Palette
arcane-ground-slam-sigil.glsl (934 lines)
#version 300 es
// Arcane Ground Slam Sigil (arcane-ground-slam-sigil.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_palette/lib/04_arcane_ground_slam_sigil.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;

// ============================================================================
// UNIFIED ARCANE PALETTE (LOCKED)
// ============================================================================
const vec3 COL_OBSIDIAN   = vec3(0.03, 0.05, 0.12);
const vec3 COL_COBALT     = vec3(0.08, 0.32, 0.98);
const vec3 COL_CYAN       = vec3(0.10, 0.85, 1.00);
const vec3 COL_GOLD       = vec3(1.00, 0.68, 0.18);
const vec3 COL_WHITE_GOLD = vec3(1.00, 0.96, 0.86);

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

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

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 vnoise2(vec2 p) {
    vec2 i = floor(p);
    vec2 f = fract(p);
    vec2 u = f * f * (3.0 - 2.0 * f);
    return mix(
        mix(hash12(i + vec2(0.0, 0.0)), hash12(i + vec2(1.0, 0.0)), u.x),
        mix(hash12(i + vec2(0.0, 1.0)), hash12(i + vec2(1.0, 1.0)), u.x),
        u.y
    );
}

float fbm2(vec2 p) {
    float v = 0.0;
    float a = 0.5;
    mat2 m = mat2(0.80, -0.60, 0.60, 0.80);
    for (int i = 0; i < 4; i++) {
        v += a * vnoise2(p);
        p = m * p * 2.03 + vec2(13.7, 7.3);
        a *= 0.5;
    }
    return v;
}

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 + vec3(0, 0, 0));
    float n100 = hash13(i + vec3(1, 0, 0));
    float n010 = hash13(i + vec3(0, 1, 0));
    float n110 = hash13(i + vec3(1, 1, 0));
    float n001 = hash13(i + vec3(0, 0, 1));
    float n101 = hash13(i + vec3(1, 0, 1));
    float n011 = hash13(i + vec3(0, 1, 1));
    float n111 = hash13(i + vec3(1, 1, 1));
    return mix(
        mix(mix(n000, n100, u.x), mix(n010, n110, u.x), u.y),
        mix(mix(n001, n101, u.x), mix(n011, n111, u.x), u.y),
        u.z
    );
}

// ============================================================================
// 2D DISTANCE PRIMITIVES FOR RUNES & SIGIL
// ============================================================================
float sdSeg2(vec2 p, vec2 a, vec2 b) {
    vec2 pa = p - a, ba = b - a;
    float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-6), 0.0, 1.0);
    return length(pa - ba * h);
}

float sdEqTri2(vec2 p, float r) {
    const float k = 1.7320508;
    p.x = abs(p.x) - r;
    p.y = p.y + r / k;
    if (p.x + k * p.y > 0.0) p = vec2(p.x - k * p.y, -k * p.x - p.y) * 0.5;
    p.x -= clamp(p.x, -2.0 * r, 0.0);
    return -length(p) * sign(p.y);
}

// Procedural geometric rune in local box [-0.5, 0.5]^2
float sdArcaneRune(vec2 p, int id) {
    float d = 1e5;
    int m = id % 12;
    if (m == 0) {
        // Hourglass / Dagaz
        d = min(d, sdSeg2(p, vec2(-0.32, -0.35), vec2(0.32, 0.35)));
        d = min(d, sdSeg2(p, vec2(-0.32, 0.35), vec2(0.32, -0.35)));
        d = min(d, sdSeg2(p, vec2(-0.32, -0.35), vec2(0.32, -0.35)));
        d = min(d, sdSeg2(p, vec2(-0.32, 0.35), vec2(0.32, 0.35)));
    } else if (m == 1) {
        // Solar circle with center dot & bars
        d = min(d, abs(length(p) - 0.28));
        d = min(d, length(p) - 0.05);
        d = min(d, sdSeg2(p, vec2(-0.38, 0.0), vec2(-0.28, 0.0)));
        d = min(d, sdSeg2(p, vec2(0.28, 0.0), vec2(0.38, 0.0)));
    } else if (m == 2) {
        // Othala-like diamond with legs
        vec2 q = vec2(abs(p.x), p.y);
        d = min(d, sdSeg2(q, vec2(0.0, 0.36), vec2(0.28, 0.06)));
        d = min(d, sdSeg2(q, vec2(0.28, 0.06), vec2(0.0, -0.18)));
        d = min(d, sdSeg2(q, vec2(0.0, -0.18), vec2(0.30, -0.36)));
    } else if (m == 3) {
        // Arcane A / compass glyph
        vec2 q = vec2(abs(p.x), p.y);
        d = min(d, sdSeg2(q, vec2(0.0, 0.36), vec2(0.30, -0.36)));
        d = min(d, sdSeg2(p, vec2(-0.22, -0.06), vec2(0.22, -0.06)));
        d = min(d, sdSeg2(p, vec2(-0.18, 0.22), vec2(0.18, 0.22)));
    } else if (m == 4) {
        // K-rune / Kenaz twin
        d = min(d, sdSeg2(p, vec2(-0.22, -0.36), vec2(-0.22, 0.36)));
        d = min(d, sdSeg2(p, vec2(-0.22, 0.02), vec2(0.28, 0.34)));
        d = min(d, sdSeg2(p, vec2(-0.22, -0.02), vec2(0.28, -0.34)));
        d = min(d, sdSeg2(p, vec2(0.06, -0.16), vec2(0.32, 0.0)));
    } else if (m == 5) {
        // Berkano / B-sigil
        d = min(d, sdSeg2(p, vec2(-0.24, -0.36), vec2(-0.24, 0.36)));
        d = min(d, sdSeg2(p, vec2(-0.24, 0.36), vec2(0.22, 0.18)));
        d = min(d, sdSeg2(p, vec2(0.22, 0.18), vec2(-0.24, 0.0)));
        d = min(d, sdSeg2(p, vec2(-0.24, 0.0), vec2(0.26, -0.18)));
        d = min(d, sdSeg2(p, vec2(0.26, -0.18), vec2(-0.24, -0.36)));
    } else if (m == 6) {
        // Algiz / trident star
        vec2 q = vec2(abs(p.x), p.y);
        d = min(d, sdSeg2(p, vec2(0.0, -0.36), vec2(0.0, 0.36)));
        d = min(d, sdSeg2(q, vec2(0.0, 0.02), vec2(0.30, 0.34)));
        d = min(d, sdSeg2(q, vec2(0.0, -0.12), vec2(0.24, -0.34)));
    } else if (m == 7) {
        // Ansuz / twin chevron staff
        d = min(d, sdSeg2(p, vec2(-0.22, -0.36), vec2(-0.22, 0.36)));
        d = min(d, sdSeg2(p, vec2(-0.22, 0.36), vec2(0.28, 0.10)));
        d = min(d, sdSeg2(p, vec2(-0.22, 0.06), vec2(0.28, -0.20)));
        d = min(d, sdSeg2(p, vec2(-0.34, -0.36), vec2(0.08, -0.36)));
    } else if (m == 8) {
        // Wheel / 6-spoke rune
        d = min(d, abs(length(p) - 0.30));
        d = min(d, sdSeg2(p, vec2(-0.30, 0.0), vec2(0.30, 0.0)));
        d = min(d, sdSeg2(p, vec2(-0.15, -0.26), vec2(0.15, 0.26)));
        d = min(d, sdSeg2(p, vec2(-0.15, 0.26), vec2(0.15, -0.26)));
    } else if (m == 9) {
        // Gate / Pi pillars
        d = min(d, sdSeg2(p, vec2(-0.34, 0.32), vec2(0.34, 0.32)));
        d = min(d, sdSeg2(p, vec2(-0.18, 0.32), vec2(-0.18, -0.36)));
        d = min(d, sdSeg2(p, vec2(0.18, 0.32), vec2(0.18, -0.36)));
        d = min(d, sdSeg2(p, vec2(-0.34, -0.36), vec2(0.34, -0.36)));
    } else if (m == 10) {
        // Crossed twin spear
        d = min(d, sdSeg2(p, vec2(-0.30, -0.34), vec2(0.30, 0.34)));
        d = min(d, sdSeg2(p, vec2(-0.30, 0.34), vec2(0.30, -0.34)));
        d = min(d, sdSeg2(p, vec2(-0.34, 0.0), vec2(0.34, 0.0)));
    } else {
        // Crescent & staff
        d = min(d, sdSeg2(p, vec2(0.0, -0.36), vec2(0.0, 0.36)));
        d = min(d, abs(length(p - vec2(0.0, 0.14)) - 0.20));
        d = min(d, sdSeg2(p, vec2(-0.28, -0.18), vec2(0.28, -0.18)));
    }
    return d;
}

// ============================================================================
// RADIAL GROUND-SLAM CRACK FIELD (WORLD XZ)
// ============================================================================
// Returns vec2(crackDepth 0..1, crackGlow 0..1)
vec2 evalFloorCracks(vec2 xz, float openAmt) {
    float r = length(xz);
    float ang = atan(xz.y, xz.x);

    // 6 main irregular radial fracture angles matching reference
    float angles[6];
    angles[0] = -2.85;
    angles[1] = -1.92;
    angles[2] = -0.78;
    angles[3] =  0.12;
    angles[4] =  1.28;
    angles[5] =  2.35;

    float minDist = 1e5;
    float crackMask = 0.0;
    float maxReach = mix(1.55, 2.25, openAmt);

    for (int i = 0; i < 6; i++) {
        float a0 = angles[i];
        // Jagged domain-warped deviation along radius
        float jig = (vnoise2(vec2(r * 4.5 + float(i) * 7.1, float(i) * 3.7)) - 0.5) * 0.28
                  + (vnoise2(vec2(r * 11.0 + float(i) * 2.3, 1.9)) - 0.5) * 0.10;
        float da = mod(ang - a0 + jig * smoothstep(0.15, 0.9, r) + PI, TAU) - PI;
        float arcD = abs(da) * max(r, 0.12);

        // Taper crack width from center outward
        float reach = maxReach * (0.78 + 0.28 * fract(sin(float(i) * 19.3) * 43758.5));
        float taper = smoothstep(reach, 0.18, r);
        float w = (0.042 * taper + 0.006) * mix(0.85, 1.15, openAmt);

        float c = smoothstep(w, w * 0.15, arcD) * smoothstep(reach, reach - 0.25, r);
        crackMask = max(crackMask, c);
        minDist = min(minDist, arcD / max(w, 0.004));
    }

    // Central shattered crater pit
    float crater = smoothstep(0.54, 0.24, r + (vnoise2(xz * 6.5) - 0.5) * 0.14);
    crackMask = max(crackMask, crater);

    // Arcane cyan energy seeping along crack edges
    float edgeGlow = smoothstep(2.4, 0.35, minDist) * smoothstep(maxReach, 0.15, r);
    edgeGlow = max(edgeGlow, smoothstep(0.68, 0.18, r));

    return vec2(clamp(crackMask, 0.0, 1.0), clamp(edgeGlow, 0.0, 1.0));
}

// ============================================================================
// CRISP FWIDTH-ANTIALIASED GOLDEN FLOOR SIGIL
// ============================================================================
// Returns vec2(crispLine 0..1, softBloom 0..1)
vec2 evalFloorSigil(vec2 xz, float tLoop, float openAmt) {
    float r = length(xz);
    float ang = atan(xz.y, xz.x);

    // Filter width for crisp AA at grazing perspective angles
    float fw = max(length(fwidth(xz)) * 1.15, 0.0025);

    // Concentric rings
    float dRingOuter1 = abs(r - 1.50) - 0.022;
    float dRingOuter2 = abs(r - 1.43) - 0.007;
    float dRingInner1 = abs(r - 1.11) - 0.016;
    float dRingInner2 = abs(r - 1.05) - 0.006;
    float dRingCore   = abs(r - 0.62) - 0.011;

    // 12-sector rune ring between r = 1.11 and r = 1.43
    float dRunes = 1e5;
    float dDividers = 1e5;
    if (r > 1.04 && r < 1.54) {
        float secAng = TAU / 12.0;
        float aRot = ang + 0.15;
        float idF = floor((aRot + PI) / secAng);
        int id = int(mod(idF, 12.0));
        float localA = mod(aRot + PI, secAng) - 0.5 * secAng;

        // Radial divider bars between sectors
        float divA = abs(abs(localA) - 0.5 * secAng) * r;
        float divR = max(1.12 - r, r - 1.42);
        dDividers = max(divA - 0.008, divR);

        // Local rune coordinates mapped cleanly onto the annulus
        vec2 runeUV = vec2(localA * 1.27 / 0.44, (r - 1.27) / 0.24);
        if (abs(runeUV.x) < 0.62 && abs(runeUV.y) < 0.62) {
            dRunes = (sdArcaneRune(runeUV, id) - 0.036) * 0.24;
        }
    }

    // Hexagram (Star of David: two opposing equilateral triangles) inside r = 1.05
    vec2 pStar = rot2(0.22) * xz;
    float tri1 = abs(sdEqTri2(pStar, 0.90)) - 0.013;
    float tri2 = abs(sdEqTri2(-pStar, 0.90)) - 0.013;
    float tri1In = abs(sdEqTri2(pStar, 0.78)) - 0.006;
    float tri2In = abs(sdEqTri2(-pStar, 0.78)) - 0.006;
    float dHex = min(min(tri1, tri2), min(tri1In, tri2In));

    // Combine all geometric line distances
    float dSigil = min(dRingOuter1, dRingOuter2);
    dSigil = min(dSigil, min(dRingInner1, dRingInner2));
    dSigil = min(dSigil, dRingCore);
    dSigil = min(dSigil, min(dDividers, dRunes));
    dSigil = min(dSigil, dHex);

    // Crisp fwidth-antialiased core
    float crisp = 1.0 - smoothstep(-fw * 0.5, fw * 1.25, dSigil);

    // Subtle traveling energy pulse around the ring & radial breathing (3s loop)
    float pulse = 0.86 + 0.14 * sin(tLoop + r * 3.5);
    float ringShimmer = 0.92 + 0.08 * sin(ang * 6.0 - tLoop * 2.0);

    // Soft bloom halo around lines
    float bloom = exp(-max(dSigil, 0.0) * 14.0) * 0.65
                + exp(-max(dSigil, 0.0) * 4.5) * 0.22;
    bloom *= smoothstep(2.2, 1.35, r);

    // Slightly modulate sigil where deep cracks break it
    float intensity = mix(0.85, 1.22, openAmt) * pulse * ringShimmer;
    return vec2(crisp * intensity, bloom * intensity);
}

// ============================================================================
// 3D HEXAGONAL DOUBLE-TERMINATED CRYSTAL PRIMITIVE
// ============================================================================
// Sharp hexagonal quartz prism with pointed pyramidal top & bottom tips
float sdHexCrystal(vec3 p, float rad, float halfBody, float tipLen) {
    // Hexagonal radial distance in XZ
    vec2 q = abs(p.xz);
    float hexR = max(q.x * 0.8660254 + q.y * 0.5, q.y);

    // Taper radius linearly to 0 along the tips above/below halfBody
    float ay = abs(p.y);
    float t = clamp((ay - halfBody) / max(tipLen, 0.001), 0.0, 1.0);
    float localRad = rad * (1.0 - t);

    // Compensate distance for pyramid slope
    float slope = rad / max(tipLen, 0.001);
    float dSide = (hexR - localRad) / sqrt(1.0 + slope * slope * step(halfBody, ay));
    float dCap  = ay - (halfBody + tipLen);

    // Subtle crisp bevel (0.004) for specular edge highlights
    return max(dSide, dCap) - 0.003;
}

// Transform point into crystal local space
vec3 xformCrystal(vec3 p, vec3 pos, float yaw, float pitch, float roll) {
    p -= pos;
    p.xz = rot2(-yaw) * p.xz;
    p.yz = rot2(-pitch) * p.yz;
    p.xy = rot2(-roll) * p.xy;
    return p;
}

// ============================================================================
// SCENE SDF: CRYSTALS (ID = 2.0) AND FLOOR (ID = 1.0)
// ============================================================================
// Returns vec2(dist, matId) where matId: 1.0 = floor, 2.0..12.0 = crystal index
vec2 mapCrystals(vec3 p, float tLoop, float openAmt) {
    float erupt = mix(0.72, 1.18, openAmt);
    float bob   = sin(tLoop) * 0.065;
    float bob2  = sin(tLoop + 2.1) * 0.055;
    float bob3  = cos(tLoop + 0.8) * 0.050;

    vec2 res = vec2(1e5, 0.0);
    float d;

    // 1. HERO FLOATING CENTRAL TOP CRYSTAL (iconic vertical double-terminated spire)
    {
        vec3 cp = vec3(0.02, 1.24 * erupt + 0.20 + bob, -0.02);
        vec3 q = xformCrystal(p, cp, 0.35 + 0.08 * sin(tLoop), 0.03, -0.02);
        d = sdHexCrystal(q, 0.148, 0.28 * erupt, 0.20);
        if (d < res.x) res = vec2(d, 2.0);
    }

    // 2. MAIN ERUPTING RIGHT-CENTER SPIRE (tall, leaning slightly right/forward)
    {
        vec3 cp = vec3(0.20, 0.56 * erupt, 0.05);
        vec3 q = xformCrystal(p, cp, -0.45, -0.14, -0.22);
        d = sdHexCrystal(q, 0.135, 0.44 * erupt, 0.20);
        if (d < res.x) res = vec2(d, 3.0);
    }

    // 3. SECONDARY ERUPTING LEFT-CENTER SPIRE (leaning left)
    {
        vec3 cp = vec3(-0.22, 0.40 * erupt, 0.10);
        vec3 q = xformCrystal(p, cp, 0.65, 0.08, 0.30);
        d = sdHexCrystal(q, 0.105, 0.30 * erupt, 0.16);
        if (d < res.x) res = vec2(d, 4.0);
    }

    // 4. BACK-CENTER SUPPORT SPIRE
    {
        vec3 cp = vec3(-0.04, 0.34 * erupt, -0.22);
        vec3 q = xformCrystal(p, cp, 1.10, -0.24, 0.08);
        d = sdHexCrystal(q, 0.095, 0.24 * erupt, 0.14);
        if (d < res.x) res = vec2(d, 5.0);
    }

    // 5. FRONT-RIGHT LOW SPIRE
    {
        vec3 cp = vec3(0.32, 0.26 * erupt, 0.22);
        vec3 q = xformCrystal(p, cp, -0.90, 0.22, -0.46);
        d = sdHexCrystal(q, 0.078, 0.20 * erupt, 0.12);
        if (d < res.x) res = vec2(d, 6.0);
    }

    // 6. FRONT-LEFT LOW SHARD
    {
        vec3 cp = vec3(-0.36, 0.24 * erupt, 0.24);
        vec3 q = xformCrystal(p, cp, 0.25, 0.26, 0.56);
        d = sdHexCrystal(q, 0.068, 0.17 * erupt, 0.11);
        if (d < res.x) res = vec2(d, 7.0);
    }

    // 7. LEVITATING LARGE LEFT OUTER SHARD (dramatic diagonal float)
    {
        vec3 cp = vec3(-0.98 - 0.10 * openAmt, 0.96 + 0.18 * openAmt + bob2, 0.28);
        vec3 q = xformCrystal(p, cp, 0.40, 0.18, 0.62 + 0.05 * sin(tLoop));
        d = sdHexCrystal(q, 0.085, 0.22, 0.15);
        if (d < res.x) res = vec2(d, 8.0);
    }

    // 8. LEVITATING UPPER-RIGHT SHARD
    {
        vec3 cp = vec3(0.56 + 0.08 * openAmt, 1.24 + 0.22 * openAmt + bob3, -0.22);
        vec3 q = xformCrystal(p, cp, -0.60, -0.10, -0.24);
        d = sdHexCrystal(q, 0.062, 0.15, 0.11);
        if (d < res.x) res = vec2(d, 9.0);
    }

    // 9. LEVITATING MID-RIGHT DIAGONAL SHARD
    {
        vec3 cp = vec3(0.68 + 0.08 * openAmt, 0.48 + 0.12 * openAmt - bob2 * 0.7, 0.18);
        vec3 q = xformCrystal(p, cp, -0.35, 0.12, -0.68);
        d = sdHexCrystal(q, 0.055, 0.14, 0.10);
        if (d < res.x) res = vec2(d, 10.0);
    }

    // 10. SMALL FLOATING INNER-LEFT SHARD
    {
        vec3 cp = vec3(-0.56, 0.58 + 0.14 * openAmt + bob3 * 0.8, 0.34);
        vec3 q = xformCrystal(p, cp, 0.85, 0.15, 0.48);
        d = sdHexCrystal(q, 0.042, 0.09, 0.07);
        if (d < res.x) res = vec2(d, 11.0);
    }

    // 11. TINY FLOATING UPPER-LEFT SHARD
    {
        vec3 cp = vec3(-0.22, 0.94 + 0.16 * openAmt - bob * 0.8, 0.08);
        vec3 q = xformCrystal(p, cp, 0.20, -0.10, 0.18);
        d = sdHexCrystal(q, 0.036, 0.08, 0.06);
        if (d < res.x) res = vec2(d, 12.0);
    }

    return res;
}

// Floor height displacement (tiled seams + radial cracks)
float floorDisplacement(vec2 xz, float openAmt) {
    vec2 tp = rot2(0.46) * xz * 0.82;
    vec2 f = abs(fract(tp) - 0.5);
    float grout = smoothstep(0.475, 0.495, max(f.x, f.y));
    vec2 cracks = evalFloorCracks(xz, openAmt);
    float micro = (vnoise2(xz * 12.0) - 0.5) * 0.004;
    return -grout * 0.018 - cracks.x * 0.055 + micro;
}

vec2 mapScene(vec3 p, float tLoop, float openAmt) {
    float dFloor = p.y - floorDisplacement(p.xz, openAmt);
    vec2 res = vec2(dFloor, 1.0);

    // Bounding sphere cull for crystal cluster
    if (length(p - vec3(0.0, 0.95, 0.0)) < 2.4) {
        vec2 dc = mapCrystals(p, tLoop, openAmt);
        if (dc.x < res.x) res = dc;
    }
    return res;
}

// Unit-weight tetrahedron normals (strictly matching QA contract)
vec3 calcNormal(vec3 p, float tLoop, float openAmt) {
    const float h = 0.0018;
    const vec2 k = vec2(1.0, -1.0);
    return normalize(
        k.xyy * mapScene(p + k.xyy * h, tLoop, openAmt).x +
        k.yyx * mapScene(p + k.yyx * h, tLoop, openAmt).x +
        k.yxy * mapScene(p + k.yxy * h, tLoop, openAmt).x +
        k.xxx * mapScene(p + k.xxx * h, tLoop, openAmt).x
    );
}

vec3 calcCrystalNormal(vec3 p, float tLoop, float openAmt) {
    const float h = 0.0015;
    const vec2 k = vec2(1.0, -1.0);
    return normalize(
        k.xyy * mapCrystals(p + k.xyy * h, tLoop, openAmt).x +
        k.yyx * mapCrystals(p + k.yyx * h, tLoop, openAmt).x +
        k.yxy * mapCrystals(p + k.yxy * h, tLoop, openAmt).x +
        k.xxx * mapCrystals(p + k.xxx * h, tLoop, openAmt).x
    );
}

// ============================================================================
// SOFT SHADOWS & AO
// ============================================================================
float calcShadow(vec3 ro, vec3 rd, float tmin, float tmax, float tLoop, float openAmt) {
    float res = 1.0;
    float t = tmin;
    for (int i = 0; i < 24; i++) {
        float h = mapScene(ro + rd * t, tLoop, openAmt).x;
        res = min(res, 8.0 * h / max(t, 0.001));
        t += clamp(h, 0.03, 0.25);
        if (res < 0.01 || t > tmax) break;
    }
    return clamp(res, 0.0, 1.0);
}

float calcAO(vec3 pos, vec3 nor, float tLoop, float openAmt) {
    float occ = 0.0;
    float sca = 1.0;
    for (int i = 0; i < 4; i++) {
        float h = 0.03 + 0.09 * float(i);
        float d = mapScene(pos + h * nor, tLoop, openAmt).x;
        occ += (h - d) * sca;
        sca *= 0.65;
    }
    return clamp(1.0 - 2.2 * occ, 0.15, 1.0);
}

// ============================================================================
// ENVIRONMENT STUDIO SKYLIGHT (FOR WET FLOOR & CRYSTAL REFLECTIONS)
// ============================================================================
vec3 sampleEnv(vec3 rd, int lightMode) {
    float up = clamp(rd.y, 0.0, 1.0);
    if (lightMode == 1) {
        // Pure neutral studio sky dome
        return mix(vec3(0.18), vec3(0.58), pow(up, 0.65));
    }
    vec3 sky = mix(COL_OBSIDIAN * 0.28, vec3(0.05, 0.09, 0.18), pow(up, 0.60));
    // Crisp overhead studio softbox reflections (gives wet floor realistic high-contrast sheen)
    float box1 = smoothstep(0.68, 0.95, dot(rd, normalize(vec3(-0.35, 0.78, -0.52))));
    float box2 = smoothstep(0.72, 0.96, dot(rd, normalize(vec3(0.55, 0.65, -0.45))));
    sky += vec3(0.24, 0.36, 0.56) * box1 * 0.65;
    sky += vec3(0.18, 0.28, 0.48) * box2 * 0.45;
    if (lightMode == 2) {
        float graze = smoothstep(0.78, 0.98, dot(rd, normalize(vec3(0.85, 0.18, -0.45))));
        sky += COL_WHITE_GOLD * graze * 0.95;
    } else if (lightMode == 3) {
        float rim = smoothstep(0.70, 0.97, dot(rd, normalize(vec3(0.0, 0.32, -0.94))));
        sky += mix(COL_CYAN, COL_WHITE_GOLD, 0.45) * rim * 1.1;
    }
    return sky;
}

// ============================================================================
// VOLUMETRIC ARCANE LIGHTNING ARC + FLOATING GOLDEN RUNE MOTES
// ============================================================================
// Distance from ray (ro, rd) to 3D point p
float rayPointDist(vec3 ro, vec3 rd, vec3 p, out float tRay) {
    vec3 v = p - ro;
    tRay = max(dot(v, rd), 0.0);
    return length(ro + rd * tRay - p);
}

// Evaluate crackling cyan lightning arc from epicenter to floating hero crystal
vec3 evalLightningArc(vec3 ro, vec3 rd, float maxT, float tLoop, float openAmt) {
    float erupt = mix(0.72, 1.18, openAmt);
    float yTop = 1.24 * erupt + 0.20 + sin(tLoop) * 0.065 - 0.28 * erupt - 0.14;
    float minD = 1e5;

    // 10 jagged segments from (0, 0.12, 0) up to floating crystal tip
    vec3 prevP = vec3(0.0, 0.10, 0.0);
    float flicker = floor(tLoop * 6.0 / TAU * 4.0);
    for (int i = 1; i <= 10; i++) {
        float fi = float(i) / 10.0;
        float env = sin(fi * PI);
        float jx = (sin(fi * 17.0 + tLoop * 3.0 + flicker * 1.7) * 0.075
                  + cos(fi * 31.0 - tLoop * 2.0) * 0.035) * env;
        float jz = (cos(fi * 19.0 - tLoop * 3.0 + flicker * 2.3) * 0.065) * env;
        vec3 curP = vec3(0.02 * fi + jx, mix(0.10, yTop, fi), -0.02 * fi + jz);

        // Closest approach between ray and segment [prevP, curP]
        vec3 u = rd;
        vec3 v = curP - prevP;
        vec3 w = ro - prevP;
        float a = dot(u, u);
        float b = dot(u, v);
        float c = dot(v, v);
        float d = dot(u, w);
        float e = dot(v, w);
        float denom = max(a * c - b * b, 1e-6);
        float sc = clamp((b * e - c * d) / denom, 0.0, maxT);
        float tc = clamp((a * e - b * d) / denom, 0.0, 1.0);
        // Re-project sc onto ray for exact distance
        vec3 segPt = prevP + v * tc;
        float rayT = clamp(dot(segPt - ro, rd), 0.0, maxT);
        float dist = length(ro + rd * rayT - segPt);
        minD = min(minD, dist);
        prevP = curP;
    }

    float core = exp(-minD * 95.0);
    float glow = exp(-minD * 22.0) * 0.45;
    float pulse = 0.78 + 0.22 * sin(tLoop * 4.0);
    return (COL_WHITE_GOLD * core * 1.6 + COL_CYAN * glow * 1.3) * pulse * mix(0.7, 1.25, openAmt);
}

// Evaluate swirling golden motes & tiny levitating rune sparkles
vec3 evalGoldenMotes(vec3 ro, vec3 rd, float maxT, float tLoop, float openAmt) {
    vec3 acc = vec3(0.0);

    // 22 swirling golden motes along an ascending spiral arc
    for (int i = 0; i < 22; i++) {
        float fi = float(i) / 22.0;
        float phase = fract(fi + tLoop / TAU * 0.25);
        float ang = phase * TAU * 1.15 + 1.65 + sin(float(i) * 3.1) * 0.35;
        float rad = mix(1.48, 0.78, phase) + sin(float(i) * 5.7 + tLoop) * 0.18;
        float y   = mix(0.12, 2.25, phase) + cos(float(i) * 4.3 + tLoop) * 0.08;
        vec3 mp   = vec3(cos(ang) * rad, y, sin(ang) * rad);

        float tRay;
        float dist = rayPointDist(ro, rd, mp, tRay);
        if (tRay > 0.2 && tRay < maxT) {
            float fade = sin(phase * PI);
            float twinkle = 0.65 + 0.35 * sin(tLoop * 2.0 + float(i) * 2.7);
            float sz = (i % 4 == 0) ? 0.022 : 0.011;
            float g = exp(-dist / sz);

            // Every 4th mote gets a crisp 4-point star / mini-rune silhouette
            if (i % 4 == 0 && dist < 0.14) {
                vec3 right = normalize(cross(vec3(0.0, 1.0, 0.0), rd));
                vec3 up    = cross(rd, right);
                vec3 rel   = (ro + rd * tRay) - mp;
                vec2 uv    = vec2(dot(rel, right), dot(rel, up)) / 0.065;
                // 4-point star diamond
                vec2 auv = abs(uv);
                float starD = abs(pow(auv.x + 0.01, 0.6) + pow(auv.y + 0.01, 0.6) - 0.85);
                float runeLine = smoothstep(0.16, 0.03, starD) * smoothstep(1.2, 0.5, length(uv));
                acc += COL_GOLD * runeLine * fade * twinkle * 1.35;
            }

            acc += mix(COL_GOLD, COL_WHITE_GOLD, g * 0.6) * g * fade * twinkle * 0.95;
        }
    }

    // Incandescent epicenter volumetric bloom (where crystals erupt from floor)
    vec3 corePos = vec3(0.0, 0.14, 0.0);
    float tCore;
    float dCore = rayPointDist(ro, rd, corePos, tCore);
    if (tCore > 0.1 && tCore < maxT + 0.35) {
        float bloomCore = exp(-dCore * 5.8) * 0.82 + exp(-dCore * 2.4) * 0.14;
        float pulse = 0.92 + 0.08 * sin(tLoop * 2.0);
        acc += mix(COL_CYAN, COL_WHITE_GOLD, exp(-dCore * 6.5)) * bloomCore * pulse * mix(0.72, 1.20, openAmt);
    }

    return acc;
}

// ============================================================================
// SHADING: WET TILED OBSIDIAN FLOOR + SIGIL + REFLECTIONS
// ============================================================================
vec3 shadeFloor(vec3 pos, vec3 nor, vec3 rd, float tLoop, float openAmt, int lightMode) {
    // Tiled obsidian coordinates
    vec2 tp = rot2(0.46) * pos.xz * 0.82;
    vec2 tileId = floor(tp);
    vec2 f = abs(fract(tp) - 0.5);
    float grout = smoothstep(0.472, 0.494, max(f.x, f.y));

    // Per-tile subtle tonal variation + multi-scale wet puddle mask
    float tileVar = 0.88 + 0.24 * hash12(tileId);
    float puddleNoise = fbm2(pos.xz * 1.35 + vec2(2.4, -1.7));
    float microNoise  = vnoise2(pos.xz * 18.0);
    float wetness = smoothstep(0.36, 0.64, puddleNoise) * (1.0 - grout);
    float rough = mix(0.34, 0.06, wetness) + microNoise * 0.04;

    // Perturb normal slightly for matte stone grain; keep puddles mirror-smooth
    vec3 nMicro = normalize(nor + vec3(
        vnoise2(pos.xz * 26.0) - 0.5,
        0.0,
        vnoise2(pos.xz * 26.0 + 19.3) - 0.5
    ) * mix(0.07, 0.008, wetness));

    // Radial cracks & golden floor sigil
    vec2 cracks = evalFloorCracks(pos.xz, openAmt);
    vec2 sigil  = evalFloorSigil(pos.xz, tLoop, openAmt);

    // Shadows & AO
    vec3 keyDir = (lightMode == 2) ? normalize(vec3(0.86, 0.16, -0.48))
                : (lightMode == 3) ? normalize(vec3(0.05, 0.34, -0.94))
                : normalize(vec3(-0.45, 0.72, -0.52));
    float sh = calcShadow(pos + nMicro * 0.012, keyDir, 0.04, 4.5, tLoop, openAmt);
    float ao = calcAO(pos, nMicro, tLoop, openAmt);

    // Base albedo
    vec3 albedo = (lightMode == 1)
        ? vec3(0.28) * tileVar * (1.0 - 0.45 * grout) * (1.0 - 0.55 * cracks.x)
        : COL_OBSIDIAN * tileVar * (1.0 - 0.55 * grout) * (1.0 - 0.65 * cracks.x);

    // Direct studio key + fill
    vec3 V = -rd;
    vec3 H = normalize(keyDir + V);
    float NdotL = max(dot(nMicro, keyDir), 0.0);
    float NdotV = max(dot(nMicro, V), 0.001);
    float fres = 0.04 + 0.96 * pow(1.0 - NdotV, 5.0);
    float specPow = mix(24.0, 220.0, 1.0 - rough);
    float spec = pow(max(dot(nMicro, H), 0.0), specPow) * (specPow + 8.0) * 0.025;

    vec3 keyCol = (lightMode == 1) ? vec3(1.15)
                : (lightMode == 2) ? vec3(1.10, 1.00, 0.92)
                : (lightMode == 3) ? vec3(0.60, 0.80, 1.10)
                : vec3(0.32, 0.44, 0.68);

    vec3 col = albedo * ((lightMode == 1 ? 0.26 : 0.10) * ao + NdotL * sh * keyCol);
    col += keyCol * spec * sh * mix(0.18, 0.95, wetness);

    // Environment reflection in wet puddles
    vec3 reflDir = reflect(rd, nMicro);
    vec3 envRefl = sampleEnv(reflDir, lightMode);
    col += envRefl * fres * mix(0.12, 0.78, wetness) * ao;

    if (lightMode == 1) {
        // Pure neutral grayscale mode with emission muted:
        // Show subtle engraved relief of the sigil without any color emission
        col += vec3(0.12) * sigil.x;
        float lum = dot(col, vec3(0.299, 0.587, 0.114));
        return vec3(lum);
    }

    // Wet reflection of the glowing crystal cluster on the obsidian floor
    float rFloor = length(pos.xz);
    float crystalReflMask = smoothstep(2.6, 0.25, rFloor) * mix(0.14, 0.85, wetness);
    // Point-light bounce from incandescent epicenter
    vec3 toCore = vec3(0.0, 0.28, 0.0) - pos;
    float dCore = length(toCore);
    vec3 lCore = toCore / max(dCore, 0.001);
    float attCore = 1.0 / (1.0 + dCore * dCore * 2.1);
    float coreDiff = max(dot(nMicro, lCore), 0.0);
    vec3 hCore = normalize(lCore + V);
    float coreSpec = pow(max(dot(nMicro, hCore), 0.0), mix(24.0, 160.0, wetness));
    vec3 coreCol = mix(COL_CYAN, COL_WHITE_GOLD, exp(-dCore * 2.2));
    col += (albedo * coreDiff * 1.4 + coreCol * coreSpec * 0.48) * coreCol * attCore * mix(0.75, 1.25, openAmt);
    col += COL_COBALT * crystalReflMask * 0.16 * fres;

    // Arcane cyan energy glowing inside radial cracks
    float crackEmiss = cracks.y * (0.45 + 0.55 * cracks.x) * mix(0.75, 1.30, openAmt);
    col += mix(COL_COBALT, COL_CYAN, cracks.x) * crackEmiss * 1.25;
    col += COL_WHITE_GOLD * exp(-rFloor * 5.2) * 0.88 * mix(0.7, 1.2, openAmt);

    // Rich warm amber-gold sigil ring emission + warm bounce on wet obsidian
    vec3 amberHalo = vec3(1.00, 0.52, 0.06);
    vec3 sigilCol = mix(COL_GOLD, COL_WHITE_GOLD, clamp(sigil.x * 0.28, 0.0, 1.0));
    col += sigilCol * sigil.x * 1.85;
    col += mix(amberHalo, COL_GOLD, 0.45) * sigil.y * (0.46 + 0.42 * wetness);

    // Subtle distance fog blending seamlessly into deep dark obsidian arena
    float fog = 1.0 - exp(-rFloor * rFloor * 0.036);
    vec3 fogCol = COL_OBSIDIAN * 0.22;
    col = mix(col, fogCol, clamp(fog, 0.0, 0.88));

    return col;
}

// ============================================================================
// SHADING: 3D REFRACTIVE COBALT-CYAN ARCANE CRYSTALS
// ============================================================================
vec3 shadeCrystal(vec3 pos, vec3 nor, vec3 rd, float matId, float tLoop, float openAmt, int lightMode) {
    vec3 V = -rd;
    float NdotV = max(dot(nor, V), 0.001);
    float fres = 0.06 + 0.94 * pow(1.0 - NdotV, 4.0);

    vec3 keyDir = (lightMode == 2) ? normalize(vec3(0.86, 0.16, -0.48))
                : (lightMode == 3) ? normalize(vec3(0.05, 0.34, -0.94))
                : normalize(vec3(-0.45, 0.78, -0.45));
    vec3 rimDir = normalize(vec3(0.65, 0.35, -0.68));

    if (lightMode == 1) {
        // Pure neutral grayscale mode: crisp faceted quartz sculpture
        float diff = max(dot(nor, keyDir), 0.0);
        float fill = max(dot(nor, normalize(vec3(0.6, 0.3, 0.7))), 0.0);
        vec3 H = normalize(keyDir + V);
        float spec = pow(max(dot(nor, H), 0.0), 96.0);
        float lum = 0.18 + 0.52 * diff + 0.16 * fill + 0.25 * fres + 0.45 * spec;
        return vec3(lum);
    }

    // Internal refraction ray through the crystal (IOR ~ 1.54 quartz)
    vec3 refrDir = refract(rd, nor, 1.0 / 1.54);
    if (dot(refrDir, refrDir) < 0.01) refrDir = reflect(rd, nor);

    // Estimate internal thickness via short step inside the crystal
    float innerSample = -mapCrystals(pos + refrDir * 0.14, tLoop, openAmt).x;
    float thickness = clamp(innerSample * 4.5 + 0.22, 0.15, 1.0);

    // Internal volumetric galaxy / caustic / arcane filament inclusions
    vec3 pInt = pos * 5.5 + refrDir * 1.2 + vec3(0.0, -tLoop * 0.08, 0.0);
    float neb1 = vnoise3(pInt);
    float neb2 = vnoise3(pInt * 2.3 + vec3(4.1, 1.7, 8.2));
    float sparkle = pow(vnoise3(pos * 24.0 + refrDir * 2.0), 9.0) * 3.5;

    // Height-based internal gradient: blazing white-cyan near epicenter, deep cobalt-sapphire higher up
    float hBase = clamp(1.0 - pos.y / (1.35 * mix(0.72, 1.18, openAmt)), 0.0, 1.0);
    float isHeroTop = (abs(matId - 2.0) < 0.2) ? 1.0 : 0.0;

    // Beer-Lambert colored crystal interior (deep rich cobalt-indigo body with crisp cyan filaments)
    vec3 deepIndigo = vec3(0.02, 0.05, 0.24);
    vec3 deepCol = mix(deepIndigo, COL_COBALT * 0.92, neb1);
    vec3 midCol  = mix(deepCol, COL_CYAN * 0.88, clamp(neb2 * 0.52 + hBase * 0.48, 0.0, 1.0));
    vec3 interior = midCol * exp(-thickness * vec3(2.35, 1.05, 0.22));

    // Incandescent base core glow propagating up into the crystal cluster
    float coreGlow = exp(-length(pos - vec3(0.0, 0.16, 0.0)) * 2.15) * mix(0.70, 1.22, openAmt);
    interior += mix(COL_CYAN, COL_WHITE_GOLD, clamp(coreGlow * 0.75, 0.0, 1.0)) * coreGlow * 0.95;

    // Hero floating crystal gets a vivid internal cyan arcane energy core in its lower half
    if (isHeroTop > 0.5) {
        float heroCore = exp(-abs(pos.y - (1.16 * mix(0.72, 1.18, openAmt))) * 3.8);
        interior += COL_CYAN * heroCore * (0.45 + 0.55 * neb2) * 0.85;
    }

    // Internal micro-star glints
    interior += COL_WHITE_GOLD * sparkle * (0.45 + 0.55 * hBase);

    // Crisp planar facet reflections + razor sky/rim specular
    vec3 reflDir = reflect(rd, nor);
    vec3 envRefl = sampleEnv(reflDir, lightMode);

    vec3 Hkey = normalize(keyDir + V);
    vec3 Hrim = normalize(rimDir + V);
    float specKey = pow(max(dot(nor, Hkey), 0.0), 180.0);
    float specRim = pow(max(dot(nor, Hrim), 0.0), 64.0);

    // Warm golden sigil bounce on downward-facing crystal facets
    float downFacing = clamp(-nor.y * 0.65 + 0.35, 0.0, 1.0);
    float sigilNear  = exp(-pos.y * 1.25) * smoothstep(2.1, 0.3, length(pos.xz));
    vec3 goldBounce  = COL_GOLD * downFacing * sigilNear * 0.42;

    // Combine deep translucent interior + crisp Fresnel facet reflections
    vec3 col = mix(interior, envRefl * 0.95 + COL_COBALT * 0.18, clamp(fres * 0.70, 0.04, 0.76));
    col += goldBounce;
    col += mix(COL_WHITE_GOLD, COL_CYAN, 0.25) * specKey * 1.75;
    col += COL_CYAN * specRim * 0.65;

    // Crisp bright Fresnel edge-rim
    col += mix(COL_CYAN, COL_WHITE_GOLD, 0.35) * pow(1.0 - NdotV, 3.6) * 0.52;

    if (lightMode == 3) {
        // Backlit mode boosts translucent rim transmission
        float back = pow(max(dot(rd, keyDir), 0.0), 3.0);
        col += mix(COL_CYAN, COL_WHITE_GOLD, 0.4) * back * 0.72;
    }

    return col;
}

// ============================================================================
// ACES FILMIC TONE MAPPING
// ============================================================================
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);
}

// ============================================================================
// MAIN RENDERER
// ============================================================================
void main() {
    vec2 uv = (gl_FragCoord.xy - 0.5 * uResolution.xy) / max(uResolution.y, 1.0);

    // 3-second seamless loop phase
    float tLoop = mod(uTime, 3.0) * (TAU / 3.0);
    float openAmt = clamp(uOpen, 0.0, 1.0);

    // Camera setup: uCamMode 0 = hero 3/4 view (headroom for uOpen=1 top crystal), 1 = ~2.5x macro
    vec3 ro, ta;
    float fov;
    if (uCamMode == 1) {
        ro  = vec3(0.16, 1.18, 1.88);
        ta  = vec3(0.02, 0.38, 0.04);
        fov = 2.05;
    } else {
        ro  = vec3(0.08, 2.55, 3.85);
        ta  = vec3(0.00, 0.72, 0.00);
        fov = 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 + fov * cw);

    // Raymarch scene
    float t = 0.0;
    float matId = 0.0;
    const float tMax = 16.0;
    for (int i = 0; i < 96; i++) {
        vec3 p = ro + rd * t;
        vec2 h = mapScene(p, tLoop, openAmt);
        if (h.x < 0.0012) {
            matId = h.y;
            break;
        }
        t += h.x * 0.88;
        if (t > tMax) break;
    }

    vec3 col;
    float hitT = tMax;
    if (matId > 0.5) {
        hitT = t;
        vec3 pos = ro + rd * t;
        if (matId < 1.5) {
            vec3 nor = calcNormal(pos, tLoop, openAmt);
            col = shadeFloor(pos, nor, rd, tLoop, openAmt, uLightMode);
        } else {
            vec3 nor = calcCrystalNormal(pos, tLoop, openAmt);
            col = shadeCrystal(pos, nor, rd, matId, tLoop, openAmt, uLightMode);
        }
    } else {
        col = sampleEnv(rd, uLightMode) * 0.45;
    }

    // Additive volumetric VFX (disabled in neutral grayscale clay mode uLightMode == 1)
    if (uLightMode != 1) {
        col += evalLightningArc(ro, rd, hitT, tLoop, openAmt);
        col += evalGoldenMotes(ro, rd, hitT, tLoop, openAmt);
    }

    // Subtle filmic vignette & minimal obsidian floor-lift (deep obsidian lumMin ~10-18, 0% pure black)
    float vig = 1.0 - 0.18 * dot(uv, uv);
    col *= clamp(vig, 0.68, 1.0);
    if (uLightMode == 1) {
        col = max(col, vec3(0.02));
    } else {
        col = max(col, COL_OBSIDIAN * 0.08);
    }

    // Exposure & ACES filmic tone mapping (prevent >1% clipped highlights)
    col = acesToneMap(col * 0.85);

    // Gamma correction (linear -> sRGB)
    col = pow(max(col, vec3(0.0)), vec3(1.0 / 2.2));

    fragColor = vec4(col, 1.0);
}

Mathematical models & shader specifications

Identifierarcane-ground-slam-sigil
CategoryGame VFX Shaders · Arcane Palette
Upstream studyvfx_palette/lib/04_arcane_ground_slam_sigil.glsl (commit 913ad1c)
Animation cycleContinuous procedural uTime
Declared uniformsuResolution, uTime, uOpen, uLightMode, uCamMode
Source size934 lines · 36.6 KB standalone GLSL ES 3.00
PNG baker outputs512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key)
Companion pixel VFXFree MIT impacts 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

All game vfx shaders