Arcane Meteor Impact Dome shader

arcane-meteor-impact-dome.glsl · 956 lines · GLSL ES 3.00 · MIT

Arcane Meteor Impact DomeGame VFX3s Loop
Arcane Meteor Impact Dome WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 956 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-meteor-impact-dome.glsl (956 lines)
#version 300 es
// Arcane Meteor Impact Dome (arcane-meteor-impact-dome.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_palette/lib/08_arcane_meteor_impact_dome.glsl
// License: MIT (Copyright 2026 Gokay Aydogan) + MIT/CC0 helpers — https://pixelfx.io/LICENSE-SHADERS.txt
// Uniforms: uResolution (vec2), uTime (float), uOpen (0..1), uLightMode (0..3), uCamMode (0..1)
precision highp float;
precision highp int;

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

out vec4 fragColor;

// ============================================================================
// 08_arcane_meteor_impact_dome.glsl
// Craggy dark obsidian arcane meteor rock embedded at the center of a dark wet
// tiled obsidian arena floor, enclosed in a translucent hemispherical
// refractive cyan-cobalt shockwave dome with Fresnel rim highlight, concentric
// glowing white-cyan and cobalt ground plasma shock rings, and rising golden
// ember sparks.
// ============================================================================

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

// Locked Unified Arcane Palette
const vec3 PAL_OBSIDIAN   = vec3(0.03, 0.05, 0.12);
const vec3 PAL_COBALT     = vec3(0.08, 0.32, 0.98);
const vec3 PAL_CYAN       = vec3(0.10, 0.85, 1.00);
const vec3 PAL_GOLD       = vec3(1.00, 0.68, 0.18);
const vec3 PAL_WHITE_GOLD = vec3(1.00, 0.96, 0.86);

// ============================================================================
// Hashing & Procedural Noise
// ============================================================================
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);
}

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

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

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

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

    float n000 = hash12(i.xy + vec2(0.0, 0.0) + i.z * 17.13);
    float n100 = hash12(i.xy + vec2(1.0, 0.0) + i.z * 17.13);
    float n010 = hash12(i.xy + vec2(0.0, 1.0) + i.z * 17.13);
    float n110 = hash12(i.xy + vec2(1.0, 1.0) + i.z * 17.13);

    float n001 = hash12(i.xy + vec2(0.0, 0.0) + (i.z + 1.0) * 17.13);
    float n101 = hash12(i.xy + vec2(1.0, 0.0) + (i.z + 1.0) * 17.13);
    float n011 = hash12(i.xy + vec2(0.0, 1.0) + (i.z + 1.0) * 17.13);
    float n111 = hash12(i.xy + vec2(1.0, 1.0) + (i.z + 1.0) * 17.13);

    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 v = 0.0;
    float a = 0.5;
    mat2 rot = mat2(0.80, 0.60, -0.60, 0.80);
    for (int i = 0; i < 4; i++) {
        v += a * noise2D(p);
        p = rot * p * 2.03 + vec2(11.7, 5.3);
        a *= 0.5;
    }
    return v;
}

float fbm3(vec3 p) {
    float v = 0.0;
    float a = 0.5;
    for (int i = 0; i < 4; i++) {
        v += a * noise3D(p);
        p = p * 2.04 + vec3(7.3, 13.1, 5.7);
        a *= 0.5;
    }
    return v;
}

// 3D Voronoi returning (F1, F2 - F1) for meteor craters and arcane cracks
vec2 voronoi3D(vec3 x) {
    vec3 n = floor(x);
    vec3 f = fract(x);
    float f1 = 8.0;
    float f2 = 8.0;
    for (int k = -1; k <= 1; k++) {
        for (int j = -1; j <= 1; j++) {
            for (int i = -1; i <= 1; i++) {
                vec3 g = vec3(float(i), float(j), float(k));
                vec3 o = hash33(n + g);
                vec3 r = g + o - f;
                float d = dot(r, r);
                if (d < f1) {
                    f2 = f1;
                    f1 = d;
                } else if (d < f2) {
                    f2 = d;
                }
            }
        }
    }
    float s1 = sqrt(max(0.0, f1));
    float s2 = sqrt(max(0.0, f2));
    return vec2(s1, s2 - s1);
}

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

// ============================================================================
// Scene Parameters (3s Seamless Loop + uOpen 0..1)
// ============================================================================
float getLoopPhase() {
    return fract(uTime / 3.0);
}

float getOpenAmount() {
    return clamp(uOpen, 0.0, 1.0);
}

float getDomeRadius(float openAmt, float phase) {
    float pulse = 0.025 * sin(phase * TAU);
    return mix(1.08, 1.34, openAmt) + pulse;
}

vec3 getMeteorCenter(float phase) {
    return vec3(0.0, 0.44 + 0.015 * sin(phase * TAU), 0.0);
}

// ============================================================================
// Meteor & Orbiting Obsidian Debris SDF
// ============================================================================
float meteorDisp(vec3 dir, out float crackMask) {
    // Macro craggy asteroid facets
    float macro = fbm3(dir * 2.6 + vec3(1.2, 3.4, 2.1));
    // Crater field via 3D Voronoi
    vec2 vor1 = voronoi3D(dir * 3.8 + vec3(0.7, 1.3, 2.5));
    vec2 vor2 = voronoi3D(dir * 7.5 + vec3(4.1, 2.2, 0.9));

    // Bowl-shaped craters with subtle raised rims
    float crater1 = smoothstep(0.05, 0.42, vor1.x) - 0.18 * exp(-pow((vor1.x - 0.36) * 8.0, 2.0));
    float crater2 = smoothstep(0.04, 0.36, vor2.x);

    // Craggy obsidian micro-detail
    float crag = fbm3(dir * 8.2 + vec3(2.0));

    // Sharp glowing arcane crack network along Voronoi edges
    crackMask = smoothstep(0.095, 0.015, vor1.y) * smoothstep(0.35, 0.72, macro);
    crackMask += 0.55 * smoothstep(0.07, 0.01, vor2.y) * smoothstep(0.45, 0.80, crag);
    crackMask = clamp(crackMask, 0.0, 1.0);

    float d = 0.0;
    d += (macro - 0.5) * 0.085;
    d += (crater1 - 0.65) * 0.055;
    d += (crater2 - 0.65) * 0.024;
    d += (crag - 0.5) * 0.022;
    return d;
}

vec2 mapScene(vec3 p, float phase, out float crackMask) {
    vec3 mc = getMeteorCenter(phase);
    vec3 q = p - mc;
    // Slight static heroic orientation
    q.xz = rot2(0.35) * q.xz;
    float r = length(q);
    vec3 dir = q / max(r, 1e-4);

    float cm = 0.0;
    float disp = 0.0;
    // Only evaluate expensive displacement near the meteor shell
    if (r < 0.72) {
        disp = meteorDisp(dir, cm);
    }
    float dMeteor = (r - (0.435 + disp)) * 0.78;
    vec2 res = vec2(dMeteor, 1.0); // matID 1 = meteor
    crackMask = cm;

    // 3 small levitating obsidian debris pebbles inside the dome
    float a0 = phase * TAU;
    vec3 p1 = vec3(-0.62, 0.68 + 0.04 * sin(a0), 0.14);
    vec3 p2 = vec3(0.42, 0.86 + 0.03 * cos(a0), -0.32);
    vec3 p3 = vec3(-0.24, 0.96 + 0.03 * sin(a0 + 2.1), -0.45);

    vec3 d1v = p - p1;
    float d1 = length(d1v) - (0.062 + 0.014 * (noise3D(d1v * 22.0) - 0.5));
    if (d1 < res.x) { res = vec2(d1, 2.0); crackMask = 0.0; }

    vec3 d2v = p - p2;
    float d2 = length(d2v) - (0.042 + 0.010 * (noise3D(d2v * 26.0) - 0.5));
    if (d2 < res.x) { res = vec2(d2, 2.0); crackMask = 0.0; }

    vec3 d3v = p - p3;
    float d3 = length(d3v) - (0.034 + 0.008 * (noise3D(d3v * 30.0) - 0.5));
    if (d3 < res.x) { res = vec2(d3, 2.0); crackMask = 0.0; }

    return res;
}

float mapDist(vec3 p, float phase) {
    float dummy;
    return mapScene(p, phase, dummy).x;
}

// Unit-weight tetrahedral normal (exact contract)
vec3 calcNormal(vec3 p, float phase) {
    const float h = 0.0018;
    const vec2 k = vec2(1.0, -1.0);
    return normalize(
        k.xyy * mapDist(p + k.xyy * h, phase) +
        k.yyx * mapDist(p + k.yyx * h, phase) +
        k.yxy * mapDist(p + k.yxy * h, phase) +
        k.xxx * mapDist(p + k.xxx * h, phase)
    );
}

// ============================================================================
// Analytic Intersections
// ============================================================================
vec2 intersectSphere(vec3 ro, vec3 rd, vec3 center, float radius) {
    vec3 oc = ro - center;
    float b = dot(oc, rd);
    float c = dot(oc, oc) - radius * radius;
    float h = b * b - c;
    if (h < 0.0) return vec2(-1.0);
    h = sqrt(h);
    return vec2(-b - h, -b + h);
}

// ============================================================================
// Wet Tiled Obsidian Floor Surface Properties
// ============================================================================
struct FloorMat {
    vec3 albedo;
    vec3 normal;
    float roughness;
    float grout;
    float wetness;
};

FloorMat evalObsidianFloor(vec2 xz) {
    // Rotate tile grid ~28 deg for dramatic arena perspective
    vec2 p = rot2(0.49) * xz;
    float tileSize = 1.25;
    vec2 gp = p / tileSize;
    vec2 id = floor(gp);
    vec2 f = fract(gp) - 0.5;

    // Beveled grout lines between large obsidian slabs
    vec2 edgeDist = 0.5 - abs(f);
    float minEdge = min(edgeDist.x, edgeDist.y);
    float grout = 1.0 - smoothstep(0.008, 0.024, minEdge);

    // Per-tile slight tonal & tilt variation
    float tileHash = hash12(id);
    vec2 tileTilt = (hash22(id + 13.7) - 0.5) * 0.018;

    // Wetness puddles & damp micro-stone texture
    float puddleNoise = fbm2(p * 0.65 + vec2(3.1, 1.7));
    float microNoise = fbm2(p * 5.2 + tileHash * 17.0);
    float fineNoise = noise2D(p * 18.0 + tileHash * 7.0);

    float wetness = smoothstep(0.36, 0.66, puddleNoise) * (1.0 - grout);
    float roughness = mix(0.28, 0.045, wetness);
    roughness = mix(roughness, 0.65, grout);
    roughness += (microNoise - 0.5) * 0.06 * (1.0 - wetness * 0.7);
    roughness = clamp(roughness, 0.035, 0.78);

    // Micro-bump + tile bevel normal
    float eps = 0.012;
    float h0 = fbm2(p * 6.5) * 0.65 + noise2D(p * 20.0) * 0.35;
    float hx = fbm2((p + vec2(eps, 0.0)) * 6.5) * 0.65 + noise2D((p + vec2(eps, 0.0)) * 20.0) * 0.35;
    float hz = fbm2((p + vec2(0.0, eps)) * 6.5) * 0.65 + noise2D((p + vec2(0.0, eps)) * 20.0) * 0.35;

    // Flatten bump inside wet puddles for crisp mirror-like reflections
    float bumpAmp = mix(0.042, 0.007, wetness);
    vec2 grad = vec2(hx - h0, hz - h0) / eps * bumpAmp;

    // Bevel slope right next to grout seams
    vec2 bevel = vec2(0.0);
    float bZone = smoothstep(0.045, 0.012, minEdge) * (1.0 - grout);
    if (edgeDist.x < edgeDist.y) {
        bevel.x = sign(f.x) * bZone * 0.22;
    } else {
        bevel.y = sign(f.y) * bZone * 0.22;
    }

    vec2 totalSlope = rot2(-0.49) * (grad + bevel + tileTilt);
    vec3 n = normalize(vec3(-totalSlope.x, 1.0, -totalSlope.y));

    vec3 baseCol = PAL_OBSIDIAN * (0.85 + 0.35 * tileHash + 0.18 * (microNoise - 0.5) + 0.08 * fineNoise);
    baseCol *= mix(1.0, 0.45, grout);
    // Wet darkening
    baseCol *= mix(1.0, 0.78, wetness);

    FloorMat fm;
    fm.albedo = baseCol;
    fm.normal = n;
    fm.roughness = roughness;
    fm.grout = grout;
    fm.wetness = wetness;
    return fm;
}

// ============================================================================
// Concentric Ground Plasma Shock Rings & Electric Filaments
// ============================================================================
vec3 evalGroundShockRings(vec2 xz, float domeR, float phase, float openAmt) {
    float r = length(xz);
    float ang = atan(xz.y, xz.x);

    // Subtle organic wave warp on the shock rings
    float warp = 0.016 * sin(ang * 7.0 + phase * TAU) + 0.010 * (noise2D(xz * 3.5) - 0.5);
    float rw = r + warp;

    vec3 col = vec3(0.0);

    // 1. Intense white-cyan impact core directly under the meteor
    float corePower = mix(0.85, 1.35, openAmt);
    float core = exp(-r * r * 6.8) * 3.4 * corePower;
    float coreHalo = exp(-r * r * 1.9) * 1.05 * corePower;
    col += mix(PAL_CYAN, PAL_WHITE_GOLD, 0.72) * core;
    col += PAL_CYAN * coreHalo;

    // 2. Radiating electric crackle tendrils from the impact core
    float radialNoise = noise2D(vec2(ang * 6.5, r * 4.5 - phase * 6.0));
    float arc1 = abs(sin(ang * 9.0 + fbm2(vec2(ang * 3.0, r * 3.5 - phase * 3.0)) * 5.2));
    float filaments = pow(clamp(1.0 - arc1, 0.0, 1.0), 10.0);
    float filMask = smoothstep(0.12, 0.32, r) * smoothstep(domeR * 1.55, 0.45, r);
    col += mix(PAL_COBALT, PAL_CYAN, 0.65 + 0.35 * radialNoise) * filaments * filMask * (1.8 + 0.9 * openAmt);

    // 3. Tight inner concentric cyan-white rings inside the dome footprint
    for (int i = 0; i < 4; i++) {
        float fi = float(i);
        float t = fract(phase + fi * 0.25);
        float ringR = mix(0.42, domeR * 0.96, t);
        float dist = abs(rw - ringR);
        float sharpness = exp(-dist * dist * 1600.0);
        float glow = exp(-dist * dist * 140.0);
        float fade = smoothstep(0.0, 0.15, t) * smoothstep(1.0, 0.85, t);
        float azMod = 0.75 + 0.25 * sin(ang * 5.0 + fi * 2.1 - phase * TAU);
        col += mix(PAL_CYAN, vec3(0.85, 0.97, 1.0), 0.55) * (sharpness * 1.45 + glow * 0.38) * fade * azMod;
    }

    // 4. Blazing dome-base contact plasma seam right at r = domeR
    float dBase = abs(rw - domeR);
    float baseCore = exp(-dBase * dBase * 680.0);
    float baseHalo = exp(-dBase * dBase * 45.0);
    float baseCrackle = 0.82 + 0.28 * noise2D(vec2(ang * 12.0, phase * 18.0));
    col += mix(PAL_CYAN, PAL_WHITE_GOLD, 0.68) * baseCore * 3.2 * baseCrackle * (0.85 + 0.35 * openAmt);
    col += mix(PAL_COBALT, PAL_CYAN, 0.72) * baseHalo * 1.15 * (0.85 + 0.35 * openAmt);

    // 5. Expanding outer shockwave rings racing across the wet obsidian tiles
    float maxOuter = mix(2.25, 2.85, openAmt);
    for (int i = 0; i < 3; i++) {
        float fi = float(i);
        float t = fract(phase + fi / 3.0);
        // Ease-out radial expansion
        float ease = 1.0 - pow(1.0 - t, 1.75);
        float ringR = mix(domeR * 1.02, maxOuter, ease);
        float dist = abs(rw - ringR);
        float line = exp(-dist * dist * 950.0);
        float halo = exp(-dist * dist * 75.0);
        float fade = smoothstep(0.0, 0.12, t) * smoothstep(1.0, 0.18, t);
        // Transition from bright cyan near dome to deep electric cobalt further out
        vec3 ringCol = mix(PAL_CYAN, PAL_COBALT, smoothstep(0.15, 0.85, t));
        vec3 coreCol = mix(vec3(0.75, 0.96, 1.0), PAL_CYAN, t);
        col += (coreCol * line * 1.75 + ringCol * halo * 0.52) * fade * (0.8 + 0.4 * openAmt);
    }

    // 6. Outer secondary cobalt electric arc ring
    float outerR = domeR * 1.52 + 0.06 * sin(phase * TAU);
    float dOuter = abs(rw - outerR);
    float outerLine = exp(-dOuter * dOuter * 520.0);
    float outerGlow = exp(-dOuter * dOuter * 40.0);
    float arcBreak = 0.55 + 0.45 * noise2D(vec2(ang * 8.0 - phase * TAU, 2.3));
    col += mix(PAL_COBALT, PAL_CYAN, 0.45) * (outerLine * 1.1 + outerGlow * 0.32) * arcBreak;

    return col;
}

// ============================================================================
// Arena Environment Skylight & Softbox Reflection
// ============================================================================
vec3 evalArenaEnv(vec3 rd, float lightModeF, vec3 keyDir) {
    float y = clamp(rd.y, 0.0, 1.0);
    // Rich dark midnight-blue arena studio backdrop (never crushed pure black)
    vec3 skyLow = PAL_OBSIDIAN * 0.72;
    vec3 skyHigh = vec3(0.04, 0.08, 0.19);
    vec3 env = mix(skyLow, skyHigh, pow(y, 0.65));

    // Broad cool studio overhead skylight reflection (creates glossy wet-tile sheen)
    vec3 softboxDir1 = normalize(vec3(0.42, 0.62, -0.66));
    float sb1 = smoothstep(0.74, 0.96, dot(rd, softboxDir1));
    env += vec3(0.24, 0.36, 0.56) * sb1 * 1.45;

    vec3 softboxDir2 = normalize(vec3(-0.55, 0.48, 0.68));
    float sb2 = smoothstep(0.78, 0.97, dot(rd, softboxDir2));
    env += vec3(0.16, 0.28, 0.48) * sb2 * 0.95;

    // Key light specular glint
    float keySpec = pow(max(0.0, dot(rd, keyDir)), 28.0);
    env += vec3(0.55, 0.72, 0.95) * keySpec * 0.85;

    if (lightModeF > 0.5 && lightModeF < 1.5) {
        float lum = dot(env, vec3(0.299, 0.587, 0.114));
        env = vec3(max(lum, 0.055));
    }
    return env;
}

// ============================================================================
// Lighting Setup by uLightMode
// ============================================================================
void getLighting(out vec3 keyDir, out vec3 keyCol, out vec3 rimDir, out vec3 rimCol, out float emScale, out bool neutralGray) {
    neutralGray = (uLightMode == 1);
    emScale = neutralGray ? 0.04 : 1.0;

    if (uLightMode == 1) {
        // Pure neutral grayscale with emission muted
        keyDir = normalize(vec3(0.55, 0.78, 0.30));
        keyCol = vec3(1.15);
        rimDir = normalize(vec3(-0.60, 0.45, -0.66));
        rimCol = vec3(0.45);
    } else if (uLightMode == 2) {
        // Grazing low-angle raking light
        keyDir = normalize(vec3(0.88, 0.22, 0.42));
        keyCol = vec3(1.25, 1.38, 1.65);
        rimDir = normalize(vec3(-0.82, 0.20, -0.54));
        rimCol = vec3(0.35, 0.75, 1.15);
    } else if (uLightMode == 3) {
        // Dramatic backlit silhouette
        keyDir = normalize(vec3(-0.22, 0.35, -0.91));
        keyCol = vec3(0.75, 1.25, 1.85);
        rimDir = normalize(vec3(0.40, 0.55, -0.73));
        rimCol = vec3(1.15, 1.45, 1.75);
    } else {
        // 0: Hero Pixar/DreamWorks lighting
        keyDir = normalize(vec3(0.52, 0.76, 0.38));
        keyCol = vec3(0.95, 1.12, 1.42);
        rimDir = normalize(vec3(-0.58, 0.48, -0.66));
        rimCol = vec3(0.35, 0.75, 1.25);
    }
}

// ============================================================================
// Shade Solid Scene (Meteor, Debris, Wet Obsidian Floor)
// ============================================================================
vec3 shadeSolid(
    vec3 ro, vec3 rd, float phase, float openAmt, float domeR,
    vec3 keyDir, vec3 keyCol, vec3 rimDir, vec3 rimCol,
    float emScale, bool neutralGray, out float hitDist
) {
    hitDist = 1e5;

    // 1. Floor analytic intersection (y = 0)
    float tFloor = -1.0;
    if (rd.y < -1e-4) {
        float tf = -ro.y / rd.y;
        if (tf > 0.0 && tf < 45.0) {
            tFloor = tf;
        }
    }

    // 2. Raymarch meteor & levitating debris inside bounding sphere
    vec3 mc = getMeteorCenter(phase);
    vec2 bound = intersectSphere(ro, rd, vec3(0.0, 0.60, 0.0), 1.15);
    float tSolid = -1.0;
    float matID = 0.0;
    float crackMask = 0.0;

    if (bound.y > 0.0) {
        float t = max(0.02, bound.x);
        float tEnd = min(bound.y, (tFloor > 0.0) ? tFloor : 20.0);
        for (int i = 0; i < 64; i++) {
            vec3 p = ro + rd * t;
            vec2 res = mapScene(p, phase, crackMask);
            if (res.x < 0.0014) {
                tSolid = t;
                matID = res.y;
                break;
            }
            t += max(res.x, 0.004);
            if (t > tEnd) break;
        }
    }

    // Determine closest opaque hit
    if (tSolid > 0.0 && (tFloor < 0.0 || tSolid < tFloor)) {
        // --- METEOR / DEBRIS SHADING ---
        hitDist = tSolid;
        vec3 p = ro + rd * tSolid;
        vec3 n = calcNormal(p, phase);
        vec3 v = -rd;

        // Craggy obsidian-basalt albedo
        float rockVar = fbm3(p * 6.5);
        vec3 albedo = mix(vec3(0.045, 0.055, 0.085), vec3(0.11, 0.13, 0.18), rockVar);
        if (neutralGray) {
            albedo = vec3(mix(0.20, 0.42, rockVar));
        }

        // Approximate ambient occlusion in crater crevices
        float ao = clamp(0.5 + 0.5 * mapDist(p + n * 0.045, phase) / 0.045, 0.22, 1.0);

        // Key light (GGX-like specular + wrapped diffuse)
        float ndl = max(0.0, dot(n, keyDir));
        vec3 h = normalize(keyDir + v);
        float ndh = max(0.0, dot(n, h));
        float rough = mix(0.58, 0.34, rockVar);
        float specPow = mix(12.0, 48.0, 1.0 - rough);
        float spec = pow(ndh, specPow) * (0.28 + 0.35 * (1.0 - rough));

        vec3 col = albedo * keyCol * (ndl * 0.95 + 0.06) * ao;
        col += keyCol * spec * ndl * ao;

        // Rim light
        float ndr = max(0.0, dot(n, rimDir));
        float fres = pow(clamp(1.0 - max(0.0, dot(n, v)), 0.0, 1.0), 3.2);
        col += albedo * rimCol * ndr * 0.45 * ao;
        col += rimCol * fres * 0.32;

        // Ambient sky bounce
        vec3 skyAmb = neutralGray ? vec3(0.14) : vec3(0.05, 0.09, 0.18);
        col += albedo * skyAmb * (0.5 + 0.5 * n.y) * ao;

        // Strong upward cyan-white impact core bounce light on underside of meteor
        vec3 toCore = vec3(0.0, 0.02, 0.0) - p;
        float coreDist = length(toCore);
        vec3 coreDir = toCore / max(coreDist, 1e-4);
        float coreAtten = 1.0 / (0.25 + coreDist * coreDist * 2.4);
        float coreNdl = clamp(dot(n, coreDir) * 0.7 + 0.35, 0.0, 1.0);
        vec3 coreLightCol = neutralGray ? vec3(0.25) : mix(PAL_COBALT, PAL_CYAN, 0.65);
        col += (albedo * 1.4 + vec3(0.15) * fres) * coreLightCol * coreNdl * coreAtten * (1.5 + 0.7 * openAmt) * mix(0.25, 1.0, emScale);

        // Dome cyan-cobalt ambient wrap
        if (!neutralGray) {
            col += mix(PAL_COBALT, PAL_CYAN, 0.45) * fres * 0.55 * emScale;
        }

        // Glowing arcane meteor cracks & golden ember pores driven by uOpen
        if (matID < 1.5 && emScale > 0.05) {
            float crackGlow = crackMask * mix(0.25, 1.85, openAmt);
            float pulse = 0.85 + 0.15 * sin(phase * TAU + p.y * 6.0);
            // Hotter near bottom (cyan-white) and golden-amber on upper facets
            float heightBlend = smoothstep(0.18, 0.68, p.y);
            vec3 crackCol = mix(PAL_CYAN, PAL_GOLD, heightBlend);
            col += crackCol * crackGlow * pulse * emScale;

            // Tiny hot golden ember spots embedded on the meteor surface
            float spotNoise = noise3D(p * 14.0 + vec3(2.3));
            float emberDot = smoothstep(0.84, 0.95, spotNoise) * smoothstep(0.25, 0.75, p.y);
            col += PAL_WHITE_GOLD * emberDot * (0.8 + 1.2 * openAmt) * emScale;
        }

        return col;
    }

    if (tFloor > 0.0) {
        // --- WET TILED OBSIDIAN ARENA FLOOR ---
        hitDist = tFloor;
        vec3 p = ro + rd * tFloor;
        vec3 v = -rd;
        FloorMat fm = evalObsidianFloor(p.xz);
        vec3 n = fm.normal;

        vec3 albedo = fm.albedo;
        if (neutralGray) {
            float g = dot(albedo, vec3(0.299, 0.587, 0.114));
            albedo = vec3(max(0.16, g * 4.5));
        }

        // Fresnel Schlick for wet obsidian
        float ndv = max(0.0, dot(n, v));
        float F0 = mix(0.04, 0.09, fm.wetness);
        float fresnel = F0 + (1.0 - F0) * pow(clamp(1.0 - ndv, 0.0, 1.0), 4.2);

        // Soft contact shadow directly beneath meteor
        float rCenter = length(p.xz);
        float meteorShadow = smoothstep(0.18, 0.58, rCenter);

        // Key light diffuse + crisp wet specular
        float ndl = max(0.0, dot(n, keyDir));
        vec3 h = normalize(keyDir + v);
        float ndh = max(0.0, dot(n, h));
        float specExp = mix(24.0, 180.0, 1.0 - fm.roughness);
        float spec = pow(ndh, specExp) * mix(0.25, 2.2, fm.wetness);

        vec3 col = albedo * keyCol * (ndl * 0.75 + 0.10) * mix(0.45, 1.0, meteorShadow);
        col += keyCol * spec * ndl * fresnel * 1.4;

        // Wet floor environment reflections (gives those glossy wet-tile sheen patches)
        vec3 rDir = reflect(rd, n);
        vec3 envRefl = evalArenaEnv(rDir, float(uLightMode), keyDir);
        // Glossy roughness attenuation
        float reflStrength = mix(0.32, 1.05, fm.wetness) * (1.0 - fm.grout * 0.85);
        col += envRefl * fresnel * reflStrength;

        // Wet reflection of the glowing dome & impact plasma onto the dark tiles
        if (!neutralGray) {
            // Distance from reflected ray to the dome center/ring
            vec2 rDome = intersectSphere(p + n * 0.01, rDir, vec3(0.0), domeR);
            if (rDome.y > 0.0) {
                vec3 rp = p + rDir * max(0.0, rDome.x);
                if (rp.y > 0.0) {
                    vec3 rn = normalize(rp);
                    float rFres = pow(clamp(1.0 - abs(dot(rn, -rDir)), 0.0, 1.0), 2.2);
                    vec3 domeReflCol = mix(PAL_COBALT, PAL_CYAN, rFres) * (0.55 + 1.35 * rFres);
                    domeReflCol *= exp(-rCenter * 0.28);
                    col += domeReflCol * fresnel * reflStrength * emScale;
                }
            }
            // Diffuse & specular floor illumination from the impact core + shock rings
            float lightAtten = 1.0 / (0.35 + rCenter * rCenter * 0.55);
            vec3 toCore = normalize(vec3(0.0, 0.35, 0.0) - p);
            float cNdl = max(0.0, dot(n, toCore));
            vec3 hCore = normalize(toCore + v);
            float cSpec = pow(max(0.0, dot(n, hCore)), mix(16.0, 96.0, fm.wetness));
            vec3 plasmaLight = mix(PAL_COBALT, PAL_CYAN, exp(-rCenter * 0.45));
            col += albedo * plasmaLight * cNdl * lightAtten * 2.2 * emScale;
            col += plasmaLight * cSpec * lightAtten * mix(0.25, 1.35, fm.wetness) * emScale;
        }

        // Concentric glowing white-cyan and cobalt ground plasma shock rings
        vec3 rings = evalGroundShockRings(p.xz, domeR, phase, openAmt);
        // Rings slightly catch grout seams & wet sheen
        rings *= mix(1.0, 1.18, fm.wetness);
        col += rings * emScale;

        // Subtle atmospheric distance fog into deep arena obsidian (never pure black)
        float fog = 1.0 - exp(-tFloor * tFloor * 0.0085);
        vec3 fogCol = neutralGray ? vec3(0.09) : PAL_OBSIDIAN * 0.65;
        col = mix(col, fogCol, clamp(fog, 0.0, 0.85));

        return col;
    }

    // Sky background
    return evalArenaEnv(rd, float(uLightMode), keyDir);
}

// ============================================================================
// Translucent Hemispherical Refractive Cyan-Cobalt Shockwave Dome
// ============================================================================
vec3 shadeDomeOverlay(
    vec3 ro, vec3 rd, vec3 baseCol, float baseDist,
    float domeR, float phase, float openAmt,
    vec3 keyDir, vec3 keyCol, vec3 rimDir, vec3 rimCol,
    float emScale, bool neutralGray
) {
    vec2 hit = intersectSphere(ro, rd, vec3(0.0), domeR);
    if (hit.y <= 0.0) return baseCol;

    float tNear = max(0.0, hit.x);
    float tFar = hit.y;

    // Check if the ray actually intersects the upper hemisphere (y >= 0)
    vec3 pNear = ro + rd * tNear;
    vec3 pFar = ro + rd * tFar;
    if (pNear.y < 0.0 && pFar.y < 0.0) return baseCol;

    // Clip entry/exit to y >= 0 plane
    float tPlane = (abs(rd.y) > 1e-4) ? (-ro.y / rd.y) : -1.0;
    float tEntry = tNear;
    float tExit = tFar;
    bool hitOuterShell = (hit.x > 0.0 && pNear.y >= 0.0 && hit.x < baseDist);

    if (pNear.y < 0.0 && tPlane > tNear && tPlane < tFar) {
        tEntry = tPlane;
    }
    if (pFar.y < 0.0 && tPlane > tNear && tPlane < tFar) {
        tExit = tPlane;
    }
    tExit = min(tExit, baseDist);
    float pathLen = max(0.0, tExit - tEntry);

    vec3 col = baseCol;

    // 1. Refractive interior sampling when ray enters the outer dome shell
    if (hitOuterShell) {
        vec3 nOut = normalize(pNear);
        // Physical glass-like refraction (IOR ~ 1.14)
        vec3 refrDir = refract(rd, nOut, 1.0 / 1.14);
        if (length(refrDir) > 0.001) {
            float refrDist;
            vec3 refrCol = shadeSolid(
                pNear + refrDir * 0.002, refrDir, phase, openAmt, domeR,
                keyDir, keyCol, rimDir, rimCol, emScale, neutralGray, refrDist
            );
            // Subtle chromatic dispersion along dome rim
            float fres = pow(clamp(1.0 - max(0.0, dot(nOut, -rd)), 0.0, 1.0), 2.8);
            col = mix(refrCol, baseCol, 0.15 * (1.0 - fres));
        }
    }

    // 2. Soft volumetric interior cobalt-cyan plasma haze
    if (pathLen > 0.001) {
        vec3 midP = ro + rd * (0.5 * (tEntry + tExit));
        float hFade = exp(-max(0.0, midP.y) * 1.85);
        float volDensity = pathLen * (0.14 + 0.24 * hFade);
        vec3 volCol = neutralGray ? vec3(0.22) : mix(PAL_COBALT, PAL_CYAN, 0.35 + 0.45 * hFade);
        col += volCol * volDensity * (0.75 + 0.35 * openAmt) * mix(0.2, 1.0, emScale);
    }

    // 3. Crisp outer dome shell Fresnel rim, specular highlight, & lightning arcs
    if (hitOuterShell) {
        vec3 nOut = normalize(pNear);
        vec3 v = -rd;
        float ndv = max(0.0, dot(nOut, v));
        float fresnel = pow(clamp(1.0 - ndv, 0.0, 1.0), 2.9);
        float rimSharp = pow(clamp(1.0 - ndv, 0.0, 1.0), 6.5);

        // Ground contact plasma brightening near y = 0
        float baseSeam = exp(-pNear.y * pNear.y * 24.0);

        // Crawling surface arcane lightning arcs on the dome shell
        float ang = atan(nOut.z, nOut.x);
        float elev = asin(clamp(nOut.y, 0.0, 1.0));
        vec2 domeUV = vec2(ang * 2.5, elev * 4.0);
        float w1 = fbm2(domeUV * 1.8 + vec2(phase * 2.0, -phase * 3.0));
        float arcA = abs(sin(ang * 4.0 + elev * 5.0 + w1 * 6.5 - phase * TAU));
        float lightning = pow(clamp(1.0 - arcA, 0.0, 1.0), 16.0);
        // Second crossing tendril
        float arcB = abs(sin(ang * 6.0 - elev * 4.0 + w1 * 5.0 + phase * TAU));
        lightning += 0.7 * pow(clamp(1.0 - arcB, 0.0, 1.0), 18.0);
        lightning *= (0.45 + 0.55 * smoothstep(0.0, 0.35, nOut.y));

        // Subtle energy ripples traveling up the dome
        float wave = 0.5 + 0.5 * sin(elev * 18.0 - phase * TAU * 2.0 + w1 * 3.0);
        float ripple = pow(wave, 6.0) * 0.16;

        // Crisp studio softbox specular reflection on the glass dome (iconic Pixar look)
        vec3 rDir = reflect(rd, nOut);
        vec3 studioLight = normalize(vec3(0.46, 0.68, 0.57));
        float domeSpec = pow(max(0.0, dot(rDir, studioLight)), 42.0);
        float domeSoftPatch = smoothstep(0.84, 0.95, dot(rDir, normalize(vec3(0.55, 0.52, -0.65))));
        vec3 envRefl = evalArenaEnv(rDir, float(uLightMode), keyDir);

        if (neutralGray) {
            // Pure neutral grayscale translucent glass shell
            col += vec3(0.55) * fresnel * 0.45;
            col += vec3(0.95) * (domeSpec * 0.75 + domeSoftPatch * 0.45);
            col += envRefl * fresnel * 0.35;
        } else {
            // Translucent cobalt-cyan glass tint + razor-crisp Fresnel rim
            vec3 rimColDome = mix(PAL_COBALT, PAL_CYAN, 0.55 + 0.45 * fresnel);
            col += rimColDome * fresnel * 1.65 * emScale;
            col += mix(PAL_CYAN, PAL_WHITE_GOLD, 0.55) * rimSharp * 1.85 * emScale;

            // Dome base plasma glow
            col += mix(PAL_CYAN, PAL_WHITE_GOLD, 0.45) * baseSeam * (0.95 + 0.75 * fresnel) * (0.85 + 0.35 * openAmt) * emScale;

            // Electric lightning tendrils across the dome
            col += mix(PAL_COBALT, vec3(0.75, 0.96, 1.0), 0.68) * lightning * (1.25 + 0.55 * openAmt) * emScale;
            col += PAL_CYAN * ripple * (0.35 + 0.65 * fresnel) * emScale;

            // Glossy glass reflections
            col += mix(vec3(0.65, 0.90, 1.0), vec3(1.0), 0.6) * (domeSpec * 1.15 + domeSoftPatch * 0.62);
            col += envRefl * fresnel * 0.55;
        }
    }

    return col;
}

// ============================================================================
// Rising Golden Ember Sparks & Arcane Trail (3D Analytic Depth-Tested)
// ============================================================================
vec3 evalGoldenEmbers(vec3 ro, vec3 rd, float maxDist, float domeR, float phase, float openAmt, float emScale) {
    if (emScale < 0.05) return vec3(0.0);

    vec3 acc = vec3(0.0);
    // 32 golden embers: half along the sweeping foreground-to-upper-left arcane ribbon,
    // half rising organically around the dome & meteor impact zone.
    for (int i = 0; i < 32; i++) {
        float fi = float(i);
        float h1 = hash11(fi * 17.3 + 1.1);
        float h2 = hash11(fi * 31.7 + 2.3);
        float h3 = hash11(fi * 47.9 + 5.7);

        float t = fract(h1 + phase);
        vec3 pos;
        float size;

        if (i < 18) {
            // Sweeping 3D helical ribbon curving from lower-right foreground up around left sky
            float s = mix(-0.2, 1.15, t);
            float ang = mix(-0.75, 3.35, s);
            float rad = mix(domeR * 1.65, domeR * 1.18, sin(s * PI * 0.75)) + (h2 - 0.5) * 0.42;
            float y = mix(0.05, 2.35, pow(clamp(s, 0.0, 1.0), 1.35)) + (h3 - 0.5) * 0.28;
            pos = vec3(cos(ang) * rad, y, sin(ang) * rad);
            size = mix(0.012, 0.032, h2);
        } else {
            // Rising golden sparks drifting upward around the dome & impact
            float ang = h2 * TAU + phase * TAU * (0.25 + 0.25 * h3);
            float rad = mix(0.35, domeR * 1.38, h3);
            float y = 0.08 + t * 1.95;
            pos = vec3(cos(ang) * rad, y, sin(ang) * rad);
            size = mix(0.009, 0.024, h2);
        }

        // Ray-to-point closest approach
        vec3 oc = pos - ro;
        float proj = dot(oc, rd);
        if (proj <= 0.1 || proj > maxDist + 0.15) continue;

        vec3 closest = ro + rd * proj;
        vec3 diff = pos - closest;
        float d2 = dot(diff, diff);

        float fade = smoothstep(0.0, 0.14, t) * smoothstep(1.0, 0.78, t);
        float twinkle = 0.65 + 0.35 * sin(phase * TAU * 3.0 + fi * 4.3);

        // Crisp white-gold core + warm arcane gold halo
        float core = exp(-d2 / max(1e-6, size * size * 0.45));
        float halo = exp(-d2 / max(1e-6, size * size * 5.2));

        // Subtle 4-point arcane star glint on larger ribbon sparks
        float star = 0.0;
        if (i < 10) {
            float dx = abs(diff.x) + abs(diff.z);
            float dy = abs(diff.y);
            star = exp(-(dx * 16.0 + dy * 1.5) / max(0.01, size * 4.0))
                 + exp(-(dy * 16.0 + dx * 1.5) / max(0.01, size * 4.0));
            star *= exp(-d2 / max(1e-6, size * size * 18.0)) * 0.42;
        }

        vec3 sparkCol = PAL_WHITE_GOLD * (core * 2.2 + star * 1.2) + PAL_GOLD * (halo * 1.15 + star * 0.9);
        acc += sparkCol * fade * twinkle * (0.85 + 0.35 * openAmt);
    }

    return acc * emScale;
}

// ============================================================================
// ACES Filmic Tone Mapping
// ============================================================================
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
// ============================================================================
void main() {
    vec2 res = max(uResolution, vec2(1.0));
    vec2 uv = (gl_FragCoord.xy - 0.5 * res) / res.y;

    float phase = getLoopPhase();
    float openAmt = getOpenAmount();
    float domeR = getDomeRadius(openAmt, phase);

    // Camera setup (uCamMode: 0 = hero 3/4 view, 1 = ~2.5x macro close-up)
    vec3 ro;
    vec3 ta;
    float fov;
    if (uCamMode == 1) {
        // ~2.5x macro close-up on meteor craters, arcane cracks, impact core & dome rim
        ro = vec3(0.42, 0.96, 1.88);
        ta = vec3(0.0, 0.44, 0.0);
        fov = 1.95;
    } else {
        // Hero 3/4 elevated view matching 08.png composition
        ro = vec3(0.18, 2.38, 4.15);
        ta = vec3(0.0, 0.36, 0.0);
        fov = 1.48;
    }

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

    vec3 keyDir, keyCol, rimDir, rimCol;
    float emScale;
    bool neutralGray;
    getLighting(keyDir, keyCol, rimDir, rimCol, emScale, neutralGray);

    // 1. Trace solid scene (meteor, debris, wet obsidian floor, ground shock rings)
    float solidDist;
    vec3 col = shadeSolid(
        ro, rd, phase, openAmt, domeR,
        keyDir, keyCol, rimDir, rimCol,
        emScale, neutralGray, solidDist
    );

    // 2. Overlay translucent refractive cyan-cobalt shockwave dome
    col = shadeDomeOverlay(
        ro, rd, col, solidDist, domeR, phase, openAmt,
        keyDir, keyCol, rimDir, rimCol,
        emScale, neutralGray
    );

    // 3. Add depth-tested rising golden ember sparks & arcane trail
    col += evalGoldenEmbers(ro, rd, solidDist, domeR, phase, openAmt, emScale);

    // 4. Subtle vignette (gentle so corners stay above pure black)
    float vig = 1.0 - 0.22 * dot(uv, uv);
    col *= clamp(vig, 0.72, 1.0);

    // 5. Exposure + ACES Filmic Tone Mapping + Gamma
    col = max(col, vec3(0.0));
    col *= 0.92;
    col = acesFilm(col);
    col = pow(col, vec3(1.0 / 2.2));

    // Gentle shadow floor lift (<2% black guarantee)
    col = max(col, neutralGray ? vec3(0.04) : vec3(0.016, 0.024, 0.048));

    fragColor = vec4(col, 1.0);
}

Mathematical models & shader specifications

Identifierarcane-meteor-impact-dome
CategoryGame VFX Shaders · Arcane Palette
Upstream studyvfx_palette/lib/08_arcane_meteor_impact_dome.glsl (commit 913ad1c)
Animation cycle3.0 s seamless harmonic loop
Declared uniformsuResolution, uTime, uOpen, uLightMode, uCamMode
Source size956 lines · 36.2 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

Voronoi/Worley cellular fields (Voronoi 1908; Worley 1996); GGX microfacet specular (Trowbridge–Reitz 1975; Walter et al. 2007); Schlick Fresnel reflectance (1994); Beer–Lambert volumetric absorption/attenuation

Adapted upstream mathematical helpers

David Hoskins, hash · Krzysztof Narkowicz, filmic curve · Inigo Quilez, tetrahedral SDF normal

All game vfx shaders