Indigo Shadow Smoke Decoy shader

indigo-shadow-smoke-decoy.glsl · 892 lines · GLSL ES 3.00 · MIT

Indigo Shadow Smoke DecoyGame VFX3s Loop
Indigo Shadow Smoke Decoy WebGL2 procedural shader preview
FPS 60BUFFER 960×540SOURCE 892 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
indigo-shadow-smoke-decoy.glsl (892 lines)
#version 300 es
// Indigo Shadow Smoke Decoy (indigo-shadow-smoke-decoy.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_stylized/lib/10_indigo_shadow_smoke_decoy.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;

// ============================================================================
// 10_indigo_shadow_smoke_decoy.glsl
// Stylized 3D midnight-indigo & ghostly-cyan ninja shadow-smoke decoy poof
// hovering above a dark matte ink-grouted charcoal tiled arena floor.
//   - Chunky clustered billowy cel-shaded deep-indigo smoke cloud
//   - Bold black-ink lobe contours & luminous electric-cyan rim-light outlines
//   - Piercing glowing cyan spectral eyes & forehead mystic glyph
//   - Wispy cyan tail curling down to a crisp graphic floor shadow
//   - 4 orbiting glowing cyan paper talismans (ofuda) with calligraphic seals
//   - uTime billows & floats talismans in a seamless 3s loop
//   - uOpen (0..1) flares eyes/glyph & expands the smoke cloud
// ============================================================================

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

// Stylized Palette
const vec3 COL_FLOOR_BASE   = vec3(0.08, 0.09, 0.12);
const vec3 COL_INK          = vec3(0.016, 0.020, 0.036);
const vec3 COL_INDIGO_DARK  = vec3(0.032, 0.044, 0.115);
const vec3 COL_INDIGO_MID   = vec3(0.085, 0.130, 0.305);
const vec3 COL_INDIGO_LIGHT = vec3(0.175, 0.255, 0.520);
const vec3 COL_COBALT       = vec3(0.090, 0.380, 0.850);
const vec3 COL_CYAN         = vec3(0.100, 0.880, 1.000);
const vec3 COL_CYAN_SOFT    = vec3(0.320, 0.960, 1.000);
const vec3 COL_CORE         = vec3(0.860, 0.985, 1.000);
const vec3 COL_ARENA_RED    = vec3(0.460, 0.100, 0.120);

const float MAT_FLOOR    = 1.0;
const float MAT_CLOUD    = 2.0;
const float MAT_TALISMAN = 3.0;

// ============================================================================
// UTILITY & NOISE
// ============================================================================

float loopPhase() {
    return fract(uTime / 3.0);
}

mat2 rot2(float a) {
    float c = cos(a), 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 hash21(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 vnoise2(vec2 p) {
    vec2 i = floor(p);
    vec2 f = fract(p);
    vec2 u = f * f * (3.0 - 2.0 * f);
    return mix(
        mix(hash21(i), hash21(i + vec2(1.0, 0.0)), u.x),
        mix(hash21(i + vec2(0.0, 1.0)), hash21(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.8, 0.6, -0.6, 0.8);
    for (int i = 0; i < 4; i++) {
        v += a * vnoise2(p);
        p = m * p * 2.03 + vec2(13.1, 7.7);
        a *= 0.5;
    }
    return v;
}

float smin(float a, float b, float k) {
    float h = clamp(0.5 + 0.5 * (b - a) / max(k, 1e-4), 0.0, 1.0);
    return mix(b, a, h) - k * h * (1.0 - h);
}

float sdSegment2(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 sdCapsule(vec3 p, vec3 a, vec3 b, float ra, float rb) {
    vec3 pa = p - a, ba = b - a;
    float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-6), 0.0, 1.0);
    float r = mix(ra, rb, h);
    return length(pa - ba * h) - r;
}

float sdBox(vec3 p, vec3 b) {
    vec3 q = abs(p) - b;
    return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}

// ============================================================================
// SMOKE CLOUD + WISPY TAIL SDF
// ============================================================================

struct CloudSample {
    float d;       // signed distance
    float crease;  // 0..1 lobe crease / seam factor for ink contours
    float tailFac; // 0..1 transition into glowing cyan wispy tail
};

vec3 cloudCenter() {
    float ang = loopPhase() * TAU;
    float hover = 0.045 * sin(ang);
    return vec3(0.0, 1.18 + hover, 0.0);
}

// Evaluates the chunky billowy cloud puffs + sinuous curling cyan tail
CloudSample mapCloud(vec3 p) {
    float ang = loopPhase() * TAU;
    float open = clamp(uOpen, 0.0, 1.0);
    float expScale = 1.0 + 0.16 * open;

    vec3 c0 = cloudCenter();
    vec3 q = p - c0;

    // Gentle sway of upper mass
    q.x -= 0.025 * sin(ang + q.y * 1.4);

    // Track smallest and second-smallest lobe distances for crisp ink creases
    float dMin = 1e5;
    float dSec = 1e5;

    // 17 sculpted chunky smoke puffs matching 10.png silhouette
    // Front/center face cushion (slightly flattened in Z so eyes sit cleanly)
    vec3 pFace = q - vec3(0.0, -0.02, 0.08);
    pFace.z *= 1.22;
    float dCore = length(pFace) - 0.56 * expScale;
    dMin = dCore;

    // Helper macro-like inline accumulation via loop over lobe descriptors
    // (xyz = offset, w = radius)
    const int NUM_LOBES = 16;
    vec4 lobes[NUM_LOBES];
    // Crown & top billows
    lobes[0]  = vec4( 0.24,  0.56, -0.04, 0.36);
    lobes[1]  = vec4(-0.08,  0.54,  0.00, 0.34);
    lobes[2]  = vec4(-0.34,  0.40, -0.05, 0.32);
    lobes[3]  = vec4( 0.48,  0.34, -0.02, 0.32);
    // Mid-side big puffy shoulders
    lobes[4]  = vec4(-0.66,  0.18,  0.02, 0.36);
    lobes[5]  = vec4( 0.72,  0.14,  0.03, 0.35);
    lobes[6]  = vec4(-0.74, -0.08,  0.05, 0.28);
    lobes[7]  = vec4( 0.76, -0.10,  0.06, 0.27);
    // Lower cheeks & under-puffs
    lobes[8]  = vec4(-0.48, -0.34,  0.08, 0.28);
    lobes[9]  = vec4( 0.50, -0.32,  0.08, 0.27);
    lobes[10] = vec4(-0.24, -0.46,  0.06, 0.23);
    lobes[11] = vec4( 0.26, -0.46,  0.06, 0.23);
    // Sculptural front-brow & inner curls for comic depth
    lobes[12] = vec4(-0.32,  0.22,  0.24, 0.26);
    lobes[13] = vec4( 0.34,  0.24,  0.22, 0.27);
    lobes[14] = vec4( 0.04,  0.34,  0.26, 0.25);
    lobes[15] = vec4( 0.00, -0.34,  0.16, 0.26);

    float dSmooth = dCore;
    for (int i = 0; i < NUM_LOBES; i++) {
        float fi = float(i);
        // Periodic 3s billowing motion
        vec3 billow = vec3(
            sin(ang + fi * 1.37),
            cos(ang + fi * 2.11),
            sin(ang * 2.0 + fi * 0.93) * 0.5
        ) * 0.024;
        vec3 lp = lobes[i].xyz * expScale + billow;
        float lr = lobes[i].w * (1.0 + 0.14 * open + 0.035 * sin(ang + fi * 1.9));
        float di = length(q - lp) - lr;

        // Track 1st and 2nd closest lobes for interior ink crease detection
        if (di < dMin) {
            dSec = dMin;
            dMin = di;
        } else if (di < dSec) {
            dSec = di;
        }
        dSmooth = smin(dSmooth, di, 0.085);
    }

    // Subtle sculpted curl displacement on the surface (keeps puffs chunky, not noisy)
    float curlDisp = 0.016 * sin(q.x * 7.5 + q.y * 5.0 + ang) * cos(q.z * 6.0 - q.y * 4.5);
    dSmooth += curlDisp;

    // Wispy curling cyan tail extending from beneath the cloud down near y = 0.10
    // Parametric sinuous spine in cloud-local Y from -0.42 down to -1.06
    float dTail = 1e5;
    vec3 t0 = vec3( 0.00, -0.42, 0.06);
    vec3 t1 = vec3(-0.07 + 0.025 * sin(ang),       -0.58, 0.05);
    vec3 t2 = vec3( 0.08 + 0.025 * cos(ang),       -0.74, 0.04);
    vec3 t3 = vec3(-0.05 + 0.030 * sin(ang + 1.0), -0.90, 0.03);
    vec3 t4 = vec3( 0.03 + 0.035 * cos(ang + 0.7), -1.04, 0.02);

    dTail = min(dTail, sdCapsule(q, t0, t1, 0.21, 0.16));
    dTail = smin(dTail, sdCapsule(q, t1, t2, 0.15, 0.11), 0.04);
    dTail = smin(dTail, sdCapsule(q, t2, t3, 0.10, 0.06), 0.035);
    dTail = smin(dTail, sdCapsule(q, t3, t4, 0.055, 0.012), 0.025);

    // Side wispy curl flares on the tail (like the twin little curls in 10.png)
    vec3 wL = vec3(-0.18 + 0.02 * sin(ang), -0.68, 0.05);
    vec3 wR = vec3( 0.20 + 0.02 * cos(ang), -0.62, 0.04);
    dTail = smin(dTail, length(q - wL) - 0.095, 0.05);
    dTail = smin(dTail, length(q - wR) - 0.090, 0.05);

    float dFinal = smin(dSmooth, dTail, 0.07);

    // Seam/crease factor where two puffs meet closely
    float gap = abs(dSec - dMin);
    float crease = 1.0 - smoothstep(0.0, 0.055, gap);
    // Reduce crease near the very smooth center face so eyes & glyph read super cleanly
    float faceClear = smoothstep(0.18, 0.42, length(q.xy - vec2(0.0, -0.02)));
    crease *= mix(0.18, 1.0, faceClear);

    // Tail factor: 0 on main indigo cloud, 1 down at the electric-cyan wispy tip
    float tailFac = smoothstep(-0.28, -0.88, q.y);
    // Boost tailFac where tail SDF dominates
    tailFac = clamp(tailFac + 0.35 * smoothstep(0.06, -0.04, dTail - dSmooth) * smoothstep(-0.32, -0.62, q.y), 0.0, 1.0);

    CloudSample cs;
    cs.d = dFinal;
    cs.crease = crease;
    cs.tailFac = tailFac;
    return cs;
}

// ============================================================================
// 4 ORBITING PAPER TALISMANS (OFUDA)
// ============================================================================

struct TalismanHit {
    float d;
    int id;
    vec2 uv; // local paper UV in [-1, 1]
};

// Returns local position of point p in talisman i's frame
vec3 talismanLocalPos(vec3 p, int i) {
    float ang = loopPhase() * TAU;
    float open = clamp(uOpen, 0.0, 1.0);
    float fi = float(i);

    // 4 framing positions matching 10.png: upper-left, upper-right, lower-left, lower-right
    vec3 basePos;
    float baseYaw, baseRoll, basePitch;
    if (i == 0) {
        // Upper-left
        basePos = vec3(-1.12, 1.72, 0.14);
        baseYaw = 0.24; baseRoll = 0.42; basePitch = -0.14;
    } else if (i == 1) {
        // Upper-right
        basePos = vec3( 1.14, 1.82, 0.10);
        baseYaw = -0.26; baseRoll = -0.34; basePitch = -0.12;
    } else if (i == 2) {
        // Lower-left
        basePos = vec3(-0.96, 0.72, 0.38);
        baseYaw = 0.22; baseRoll = -0.48; basePitch = -0.24;
    } else {
        // Lower-right
        basePos = vec3( 0.98, 0.72, 0.36);
        baseYaw = -0.22; baseRoll = 0.46; basePitch = -0.22;
    }

    // Expand slightly with uOpen and float/orbit smoothly in a 3s loop
    vec3 center = vec3(0.0, 1.18, 0.0);
    vec3 rel = (basePos - center) * (1.0 + 0.14 * open);
    // Gentle orbital sway + vertical bob
    float sway = 0.11 * sin(ang + fi * 1.57);
    rel.xz = rot2(sway) * rel.xz;
    vec3 pos = center + rel + vec3(
        0.04 * cos(ang + fi * 2.1),
        0.075 * sin(ang + fi * 1.57),
        0.04 * sin(ang + fi * 1.2)
    );

    vec3 q = p - pos;
    q.xz = rot2(-(baseYaw + 0.12 * sin(ang + fi))) * q.xz;
    q.xy = rot2(-(baseRoll + 0.08 * cos(ang + fi * 1.3))) * q.xy;
    q.yz = rot2(-(basePitch + 0.06 * sin(ang + fi * 1.7))) * q.yz;

    // Gentle paper flutter wave along length
    q.z -= 0.022 * sin(q.y * 9.0 + ang + fi * 1.6);
    return q;
}

TalismanHit mapTalismans(vec3 p) {
    TalismanHit best;
    best.d = 1e5;
    best.id = -1;
    best.uv = vec2(0.0);

    vec3 paperHalf = vec3(0.105, 0.195, 0.008);
    for (int i = 0; i < 4; i++) {
        vec3 q = talismanLocalPos(p, i);
        float d = sdBox(q, paperHalf) - 0.004;
        if (d < best.d) {
            best.d = d;
            best.id = i;
            best.uv = q.xy / paperHalf.xy;
        }
    }
    return best;
}

// Procedural calligraphic talisman ink runes in UV [-1, 1]
float talismanInkPattern(vec2 uv) {
    // Outer ink frame border
    vec2 a = abs(uv);
    float border = smoothstep(0.84, 0.90, max(a.x, a.y)) * (1.0 - smoothstep(0.95, 0.99, max(a.x, a.y)));

    // Inner thin rectangular frame
    float innerFrame = smoothstep(0.032, 0.012, abs(max(a.x * 1.06, a.y * 1.02) - 0.78));

    // Top circular seal
    float topRing = smoothstep(0.045, 0.018, abs(length((uv - vec2(0.0, 0.56)) * vec2(1.0, 1.35)) - 0.17));
    float topDot  = smoothstep(0.065, 0.035, length((uv - vec2(0.0, 0.56)) * vec2(1.0, 1.35)));

    // Central vertical calligraphic brush spine
    float spine = smoothstep(0.042, 0.015, sdSegment2(uv, vec2(0.0, -0.56), vec2(0.0, 0.34)));

    // Crossbar calligraphic strokes
    float s1 = smoothstep(0.040, 0.014, sdSegment2(uv, vec2(-0.42,  0.24), vec2(0.42,  0.18)));
    float s2 = smoothstep(0.038, 0.014, sdSegment2(uv, vec2(-0.36,  0.02), vec2(0.38,  0.07)));
    float s3 = smoothstep(0.038, 0.014, sdSegment2(uv, vec2(-0.34, -0.20), vec2(0.34, -0.15)));
    float s4 = smoothstep(0.036, 0.014, sdSegment2(uv, vec2(-0.28, -0.44), vec2(0.00, -0.34)));
    float s5 = smoothstep(0.036, 0.014, sdSegment2(uv, vec2( 0.28, -0.44), vec2(0.00, -0.34)));

    // Bottom diamond seal
    vec2 bd = uv - vec2(0.0, -0.62);
    float bDia = smoothstep(0.040, 0.015, abs(abs(bd.x) * 1.2 + abs(bd.y) * 1.6 - 0.16));

    float ink = max(border * 0.9, innerFrame * 0.85);
    ink = max(ink, max(topRing, topDot * 0.8));
    ink = max(ink, spine);
    ink = max(ink, max(max(s1, s2), max(s3, max(s4, s5))));
    ink = max(ink, bDia);
    return clamp(ink, 0.0, 1.0);
}

// ============================================================================
// COMBINED SCENE MAP & NORMALS
// ============================================================================

vec2 mapScene(vec3 p) {
    // Matte tiled arena floor at y = 0
    float dFloor = p.y;
    vec2 res = vec2(dFloor, MAT_FLOOR);

    CloudSample cs = mapCloud(p);
    if (cs.d < res.x) {
        res = vec2(cs.d, MAT_CLOUD);
    }

    TalismanHit th = mapTalismans(p);
    if (th.d < res.x) {
        res = vec2(th.d, MAT_TALISMAN);
    }

    return res;
}

vec3 calcNormal(vec3 p, float matId) {
    if (matId < 1.5) {
        return vec3(0.0, 1.0, 0.0);
    }
    vec2 e = vec2(0.0022, -0.0022);
    vec3 n;
    if (matId < 2.5) {
        n = e.xyy * mapCloud(p + e.xyy).d +
            e.yyx * mapCloud(p + e.yyx).d +
            e.yxy * mapCloud(p + e.yxy).d +
            e.xxx * mapCloud(p + e.xxx).d;
    } else {
        n = e.xyy * mapTalismans(p + e.xyy).d +
            e.yyx * mapTalismans(p + e.yyx).d +
            e.yxy * mapTalismans(p + e.yxy).d +
            e.xxx * mapTalismans(p + e.xxx).d;
    }
    float len = length(n);
    return (len > 1e-6) ? (n / len) : vec3(0.0, 1.0, 0.0);
}

// ============================================================================
// SPECTRAL EYES & FOREHEAD GLYPH (PROJECTED IN CLOUD FACE SPACE)
// ============================================================================

// Single sharp slanted spectral eye SDF (local coordinates centered on eye)
float sdSpectralEye(vec2 p, float flare) {
    // Scale slightly with uOpen
    p /= (1.0 + 0.20 * flare);
    // Curve upper lid upward into a sharp feline/ninja outer wing
    float wing = smoothstep(0.04, 0.22, p.x) * (p.x - 0.04) * 0.55;
    vec2 q = vec2(p.x, p.y - wing);
    // Almond/lens shape using intersection of two arcs
    float w = 0.165;
    float h = 0.072 * (1.0 + 0.18 * flare);
    float dTop = (q.y - h * (1.0 - (q.x * q.x) / (w * w)));
    float dBot = (-q.y - h * 0.85 * (1.0 - (q.x * q.x) / (w * w)));
    float d = max(dTop, dBot);
    // Keep within horizontal tips
    d = max(d, abs(q.x) - w * 1.15);
    return d;
}

// Forehead mystic glyph matching 10.png: vertical axis with top/bottom diamonds,
// central ring + horizontal bar
float sdForeheadGlyph(vec2 p) {
    float d = 1e5;
    // Vertical spine
    d = min(d, sdSegment2(p, vec2(0.0, -0.115), vec2(0.0, 0.125)));
    // Central oval/circle ring
    float rRing = abs(length((p - vec2(0.0, 0.015)) * vec2(1.0, 0.92)) - 0.062);
    d = min(d, rRing);
    // Inner smaller arc / dot accent
    float innerBar = sdSegment2(p, vec2(-0.068, 0.015), vec2(0.068, 0.015));
    d = min(d, innerBar);
    // Top small diamond
    vec2 pt = p - vec2(0.0, 0.115);
    d = min(d, abs(abs(pt.x) * 1.4 + abs(pt.y) - 0.022));
    // Bottom small diamond
    vec2 pb = p - vec2(0.0, -0.105);
    d = min(d, abs(abs(pb.x) * 1.4 + abs(pb.y) - 0.020));
    return d;
}

// Evaluates glowing spectral eyes & forehead glyph on the front surface of the cloud
void evalFaceFeatures(vec3 p, vec3 N, out float eyeMask, out float eyeGlow, out float glyphMask) {
    float open = clamp(uOpen, 0.0, 1.0);
    vec3 c0 = cloudCenter();
    vec3 q = p - c0;

    // Only project onto front-facing cloud surface
    float frontFace = smoothstep(0.10, 0.45, N.z) * smoothstep(-0.10, 0.15, q.z);

    // Mirror X for symmetric eyes
    vec2 ep = vec2(abs(q.x) - 0.205, q.y + 0.055);
    // Slight inward downward tilt toward nose bridge
    ep = rot2(-0.22) * ep;
    float dEye = sdSpectralEye(ep, open);

    eyeMask = smoothstep(0.014, -0.008, dEye) * frontFace;
    eyeGlow = exp(-max(dEye, 0.0) * 13.0) * frontFace;

    // Forehead glyph centered above eyes
    vec2 gp = vec2(q.x, q.y - 0.145);
    float dGlyph = sdForeheadGlyph(gp);
    glyphMask = smoothstep(0.014, 0.003, dGlyph) * frontFace;
    glyphMask += 0.35 * exp(-max(dGlyph, 0.0) * 42.0) * frontFace;
    glyphMask = clamp(glyphMask, 0.0, 1.0);
}

// ============================================================================
// FLOOR SHADING (DARK MATTE INK-GROUTED CHARCOAL TILED ARENA)
// ============================================================================

vec3 shadeFloor(vec3 p, vec3 rd, bool neutral) {
    float open = clamp(uOpen, 0.0, 1.0);
    float ang = loopPhase() * TAU;

    // Diagonal tiled grid matching 10.png perspective
    vec2 gPos = rot2(0.42) * p.xz;
    float tileSize = 1.05;
    vec2 tileUV = gPos / tileSize;
    vec2 tileID = floor(tileUV);
    vec2 f = fract(tileUV);

    // Crisp black-ink grout lines
    vec2 edgeDist = min(f, 1.0 - f);
    float minEdge = min(edgeDist.x, edgeDist.y);
    float grout = 1.0 - smoothstep(0.010, 0.026, minEdge);

    // Subtle per-tile tonal variation + stylized painterly edge scuffs
    float tileHash = hash21(tileID);
    float scuffNoise = fbm2(gPos * 5.2 + tileHash * 11.0);
    float edgeScuff = smoothstep(0.18, 0.02, minEdge) * smoothstep(0.46, 0.72, scuffNoise);

    // Matte charcoal base vec3(0.08, 0.09, 0.12) with subtle variation
    vec3 baseCol = COL_FLOOR_BASE * (0.90 + 0.22 * tileHash);
    baseCol *= (1.0 - 0.24 * edgeScuff);
    // Slight subtle tile bevel shading
    float bevel = smoothstep(0.02, 0.07, f.x) * smoothstep(0.02, 0.07, f.y);
    baseCol *= (0.94 + 0.10 * bevel);

    // Subtle red arena accent line & distant curved boundary ring (as seen in 10.png)
    float rDist = length(p.xz);
    float arenaRing = smoothstep(0.14, 0.04, abs(rDist - 4.75));
    float thinLine  = smoothstep(0.020, 0.006, abs(gPos.y - 1.55)) * smoothstep(3.8, 0.8, abs(gPos.x));
    if (!neutral) {
        baseCol = mix(baseCol, COL_ARENA_RED * 0.75, arenaRing * 0.65);
        baseCol = mix(baseCol, COL_ARENA_RED * 0.55, thinLine * 0.45);
    }

    // Apply crisp ink grout
    baseCol = mix(baseCol, COL_INK, grout * 0.88);

    // Crisp graphic puffy cloud shadow projected directly onto the floor
    vec2 sp = p.xz - vec2(0.0, 0.08);
    float expScale = 1.0 + 0.16 * open;
    float dSh = length(sp * vec2(0.92, 1.15)) - 0.68 * expScale;
    dSh = smin(dSh, length((sp - vec2(-0.52, -0.05)) * vec2(1.0, 1.15)) - 0.36 * expScale, 0.10);
    dSh = smin(dSh, length((sp - vec2( 0.54, -0.02)) * vec2(1.0, 1.15)) - 0.35 * expScale, 0.10);
    dSh = smin(dSh, length((sp - vec2(-0.28,  0.34)) * vec2(1.0, 1.15)) - 0.34 * expScale, 0.10);
    dSh = smin(dSh, length((sp - vec2( 0.30,  0.32)) * vec2(1.0, 1.15)) - 0.34 * expScale, 0.10);
    dSh = smin(dSh, length((sp - vec2( 0.02, -0.40)) * vec2(1.0, 1.15)) - 0.32 * expScale, 0.10);

    // Graphic cel-soft shadow (dark deep indigo-charcoal, never pure 0.0 black)
    float shadowMask = 1.0 - smoothstep(-0.04, 0.14, dSh);
    vec3 shadowCol = neutral ? vec3(0.038) : vec3(0.022, 0.032, 0.068);
    vec3 col = mix(baseCol, shadowCol, shadowMask * 0.78);

    // Subtle secondary shadows under the two lower floating talismans
    float dTShL = length((p.xz - vec2(-0.92, 0.42)) * vec2(1.0, 1.4)) - 0.18;
    float dTShR = length((p.xz - vec2( 0.94, 0.40)) * vec2(1.0, 1.4)) - 0.18;
    float tShadow = max(1.0 - smoothstep(-0.02, 0.14, dTShL), 1.0 - smoothstep(-0.02, 0.14, dTShR));
    col = mix(col, shadowCol, tShadow * 0.42);

    // Soft electric-cyan floor glow pool right beneath the curling wispy tail tip
    float tailPulse = 0.92 + 0.10 * sin(ang) + 0.25 * open;
    float rTail = length(p.xz - vec2(0.02, 0.04));
    float cyanPool = exp(-rTail * rTail * 5.2) * 0.48 * tailPulse
                   + exp(-rTail * rTail * 1.15) * 0.14 * tailPulse;
    vec3 glowTint = neutral ? vec3(0.55) : COL_CYAN;
    col += glowTint * cyanPool * (1.0 - 0.45 * grout);

    // Subtle cool overhead studio light falloff on the arena floor
    float arenaFalloff = 0.72 + 0.36 * exp(-rDist * rDist * 0.085);
    col *= arenaFalloff;

    // Gentle distance fog blending smoothly into dark arena backdrop
    float fog = 1.0 - exp(-rDist * rDist * 0.018);
    vec3 fogCol = neutral ? vec3(0.11) : vec3(0.048, 0.056, 0.082);
    col = mix(col, fogCol, clamp(fog, 0.0, 0.72));

    return col;
}

// ============================================================================
// CEL-SHADED CLOUD SHADING
// ============================================================================

vec3 shadeCloud(vec3 p, vec3 N, vec3 V, bool neutral) {
    float open = clamp(uOpen, 0.0, 1.0);
    float ang = loopPhase() * TAU;

    CloudSample cs = mapCloud(p);

    // Stylized key light from upper-right-front + cool cyan bottom bounce from tail
    vec3 L = normalize(vec3(0.45, 0.78, 0.44));
    float ndl = dot(N, L);

    // Subtle painterly ink-wash modulation on the cel band boundaries
    float brush = (fbm2(p.xy * 6.5 + vec2(p.z * 3.0, ang * 0.15)) - 0.5) * 0.18;
    float tone = ndl + brush;

    // Quantized 3-band cel shading (crisp graphic step transitions)
    float bandMid   = smoothstep(-0.12, -0.02, tone);
    float bandLight = smoothstep( 0.40,  0.50, tone);

    vec3 colDark  = neutral ? vec3(0.06) : COL_INDIGO_DARK;
    vec3 colMid   = neutral ? vec3(0.16) : COL_INDIGO_MID;
    vec3 colLight = neutral ? vec3(0.30) : COL_INDIGO_LIGHT;

    vec3 celCol = mix(colDark, colMid, bandMid);
    celCol = mix(celCol, colLight, bandLight);

    // Smooth gradient transition into cobalt -> electric cyan down the wispy curling tail
    vec3 tailMid  = neutral ? vec3(0.32) : COL_COBALT;
    vec3 tailTip  = neutral ? vec3(0.75) : COL_CYAN;
    vec3 tailCol  = mix(tailMid, tailTip, smoothstep(0.25, 0.92, cs.tailFac));
    // Keep cel-banded depth inside the tail too
    tailCol *= (0.72 + 0.38 * bandMid);
    celCol = mix(celCol, tailCol, smoothstep(0.08, 0.85, cs.tailFac));

    // Bold black-ink interior lobe creases & stylized curl contours
    float ndv = clamp(dot(N, V), 0.0, 1.0);
    float fres = 1.0 - ndv;

    // Crease ink lines between adjacent puffy lobes
    float inkCrease = smoothstep(0.38, 0.72, cs.crease) * (1.0 - 0.65 * cs.tailFac);
    // Subtle dark ink band just inside the outer cyan rim (classic comic double-outline)
    float innerInkRing = smoothstep(0.56, 0.70, fres) * (1.0 - smoothstep(0.74, 0.84, fres));
    float inkMask = clamp(max(inkCrease * 0.90, innerInkRing * 0.75), 0.0, 1.0);
    celCol = mix(celCol, COL_INK, inkMask);

    // Luminous electric-cyan rim-light outline along outer grazing Fresnel
    float rimWidth = 0.70 - 0.06 * open;
    float rimMask = smoothstep(rimWidth, rimWidth + 0.14, fres);
    float rimPulse = 0.95 + 0.08 * sin(ang * 2.0) + 0.25 * open;
    vec3 rimCol = neutral ? vec3(0.88) : mix(COL_CYAN, COL_CYAN_SOFT, 0.35);
    celCol = mix(celCol, rimCol * 1.15 * rimPulse, rimMask);

    // Piercing glowing cyan spectral eyes & forehead glyph
    float eyeMask, eyeGlow, glyphMask;
    evalFaceFeatures(p, N, eyeMask, eyeGlow, glyphMask);

    float flareBoost = 1.0 + 0.45 * open + 0.08 * sin(ang);
    vec3 eyeCoreCol = neutral ? vec3(0.95) : COL_CORE;
    vec3 eyeHaloCol = neutral ? vec3(0.60) : COL_CYAN;

    // Soft cyan light bleed onto the dark indigo smoke around the eyes
    celCol += eyeHaloCol * eyeGlow * 0.48 * flareBoost;
    // Crisp glowing eye interior
    celCol = mix(celCol, eyeCoreCol * 1.35 * flareBoost, eyeMask);
    // Forehead glyph
    vec3 glyphCol = neutral ? vec3(0.72) : mix(COL_CYAN, COL_CYAN_SOFT, 0.45);
    celCol = mix(celCol, glyphCol * (0.95 + 0.35 * open), glyphMask * 0.85);

    return celCol;
}

// ============================================================================
// PAPER TALISMAN SHADING
// ============================================================================

vec3 shadeTalisman(vec3 p, vec3 N, vec3 V, vec2 uv, bool neutral) {
    float open = clamp(uOpen, 0.0, 1.0);
    float ang = loopPhase() * TAU;

    float ink = talismanInkPattern(uv);

    // Glowing cyan paper base with subtle cel shading
    vec3 L = normalize(vec3(0.45, 0.78, 0.44));
    float ndl = abs(dot(N, L));
    float celPaper = 0.82 + 0.24 * smoothstep(0.35, 0.55, ndl);

    float pulse = 0.94 + 0.08 * sin(ang + p.x * 2.0) + 0.22 * open;
    vec3 paperCol = neutral ? vec3(0.76) : mix(COL_CYAN, COL_CYAN_SOFT, 0.42);
    vec3 runeCol  = neutral ? vec3(0.14) : vec3(0.04, 0.24, 0.42);

    vec3 col = paperCol * celPaper * pulse;
    col = mix(col, runeCol, ink * 0.82);

    // Subtle crisp edge contour
    float edge = smoothstep(0.90, 0.99, max(abs(uv.x), abs(uv.y)));
    col = mix(col, COL_CORE * 1.05, edge * 0.35);

    return col;
}

// ============================================================================
// BACKGROUND, SILHOUETTE HALO & FLOATING SPARKLES
// ============================================================================

vec3 evalBackdrop(vec3 rd, bool neutral) {
    float h = clamp(rd.y * 0.5 + 0.5, 0.0, 1.0);
    if (neutral) {
        return mix(vec3(0.08), vec3(0.16), h);
    }
    vec3 low = vec3(0.042, 0.048, 0.072);
    vec3 top = vec3(0.055, 0.068, 0.110);
    return mix(low, top, smoothstep(0.35, 0.90, h));
}

// 4-point comic star sparkles + tiny cyan diamond motes around the cloud
vec3 evalSparkles(vec2 uv, vec3 ro, vec3 rd, float tLimit, bool neutral) {
    float ang = loopPhase() * TAU;
    float open = clamp(uOpen, 0.0, 1.0);
    vec3 acc = vec3(0.0);

    // 10 floating 3D sparkle/shard positions around the decoy
    const int NUM_SPARKS = 10;
    vec3 spPos[NUM_SPARKS];
    spPos[0] = vec3(-0.75, 2.05,  0.10);
    spPos[1] = vec3( 1.32, 1.28,  0.15);
    spPos[2] = vec3(-1.18, 1.15,  0.22);
    spPos[3] = vec3( 0.82, 2.18,  0.05);
    spPos[4] = vec3(-0.55, 0.48,  0.35);
    spPos[5] = vec3( 0.58, 0.52,  0.30);
    spPos[6] = vec3( 1.24, 0.92,  0.20);
    spPos[7] = vec3(-1.05, 1.48, -0.05);
    spPos[8] = vec3( 0.18, 0.32,  0.25);
    spPos[9] = vec3(-0.22, 0.38,  0.22);

    vec3 sparkCol = neutral ? vec3(0.85) : COL_CORE;
    vec3 moteCol  = neutral ? vec3(0.65) : COL_CYAN;

    for (int i = 0; i < NUM_SPARKS; i++) {
        float fi = float(i);
        vec3 p = spPos[i];
        p.y += 0.07 * sin(ang + fi * 1.3);
        p.x += 0.04 * cos(ang + fi * 1.7);

        vec3 toP = p - ro;
        float tProj = dot(toP, rd);
        if (tProj <= 0.05 || tProj > tLimit) continue;

        vec3 closest = ro + rd * tProj;
        vec3 diff = closest - p;

        // Build billboard basis around rd
        vec3 right = normalize(cross(rd, vec3(0.0, 1.0, 0.0)));
        vec3 up    = cross(right, rd);
        vec2 bp = vec2(dot(diff, right), dot(diff, up));

        float twinkle = 0.65 + 0.35 * sin(ang * 2.0 + fi * 2.1);
        twinkle *= (1.0 + 0.35 * open);

        if (i < 4) {
            // Crisp 4-point star sparkle
            float sz = (i == 1) ? 0.075 : 0.048;
            float ax = abs(bp.x), ay = abs(bp.y);
            float star = exp(-ax * 38.0 / sz) * exp(-ay * 5.0 / sz)
                       + exp(-ay * 38.0 / sz) * exp(-ax * 5.0 / sz);
            float core = exp(-dot(bp, bp) / max(sz * sz * 0.08, 1e-5));
            acc += sparkCol * (star * 0.55 + core * 0.90) * twinkle;
        } else {
            // Tiny angled cyan diamond/shard mote
            vec2 rp = rot2(0.45 * sin(fi * 3.1)) * bp;
            float dDia = abs(rp.x) * 2.2 + abs(rp.y) * 0.9;
            float mote = smoothstep(0.032, 0.010, dDia);
            float halo = exp(-dDia * 38.0) * 0.35;
            acc += moteCol * (mote * 0.95 + halo) * twinkle;
        }
    }

    return acc;
}

// ============================================================================
// RAYMARCHING & ACES TONE MAPPING
// ============================================================================

struct TraceResult {
    float t;
    float matId;
    float minCloudDist;
    float minTalismanDist;
    float tAtMinCloud;
};

TraceResult raymarch(vec3 ro, vec3 rd, float tMax) {
    TraceResult tr;
    tr.t = -1.0;
    tr.matId = 0.0;
    tr.minCloudDist = 1e5;
    tr.minTalismanDist = 1e5;
    tr.tAtMinCloud = tMax;

    float t = 0.02;
    for (int i = 0; i < 110; i++) {
        vec3 p = ro + rd * t;
        float dFloor = p.y;
        CloudSample cs = mapCloud(p);
        TalismanHit th = mapTalismans(p);

        if (cs.d < tr.minCloudDist) {
            tr.minCloudDist = cs.d;
            tr.tAtMinCloud = t;
        }
        tr.minTalismanDist = min(tr.minTalismanDist, th.d);

        float d = dFloor;
        float m = MAT_FLOOR;
        if (cs.d < d) { d = cs.d; m = MAT_CLOUD; }
        if (th.d < d) { d = th.d; m = MAT_TALISMAN; }

        if (d < 0.0018) {
            tr.t = t;
            tr.matId = m;
            break;
        }
        t += clamp(d * 0.85, 0.004, 0.35);
        if (t > tMax) break;
    }
    return tr;
}

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)) / max(x * (c * x + d) + e, vec3(1e-5)), 0.0, 1.0);
}

void main() {
    vec2 uv = (gl_FragCoord.xy - 0.5 * uResolution.xy) / max(uResolution.y, 1.0);
    bool neutral = (uLightMode == 1);
    float open = clamp(uOpen, 0.0, 1.0);

    // Camera framing:
    //   uCamMode == 0 : Hero high-angle 3/4 view matching 10.png
    //   uCamMode == 1 : Macro close-up on glowing cyan spectral eyes, forehead glyph & ink curls
    vec3 ro, ta;
    float fov;
    if (uCamMode == 1) {
        ro = vec3(0.06, 1.32, 1.72);
        ta = vec3(0.00, 1.15, 0.10);
        fov = 1.85;
    } else {
        ro = vec3(0.04, 2.35, 3.45);
        ta = vec3(0.00, 1.02, 0.00);
        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);

    float tMax = 18.0;
    TraceResult tr = raymarch(ro, rd, tMax);

    vec3 col;
    float tHit = (tr.t > 0.0) ? tr.t : tMax;

    if (tr.t > 0.0) {
        vec3 p = ro + rd * tr.t;
        vec3 N = calcNormal(p, tr.matId);
        vec3 V = -rd;

        if (tr.matId < 1.5) {
            col = shadeFloor(p, rd, neutral);
        } else if (tr.matId < 2.5) {
            col = shadeCloud(p, N, V, neutral);
        } else {
            TalismanHit th = mapTalismans(p);
            col = shadeTalisman(p, N, V, th.uv, neutral);
        }
    } else {
        col = evalBackdrop(rd, neutral);
    }

    // Crisp luminous electric-cyan outer silhouette rim & soft halo around the smoke cloud
    // (only applied when the ray passes near the cloud without hitting it)
    if (tr.matId < 1.5 || tr.matId > 2.5) {
        float dOut = max(tr.minCloudDist, 0.0);
        // Only draw silhouette outline if the closest approach to the cloud is in front of the floor hit
        if (tr.tAtMinCloud < tHit + 0.05) {
            float rimStroke = 1.0 - smoothstep(0.002, 0.032 + 0.008 * open, dOut);
            float outerHalo = exp(-dOut * 14.0) * (0.42 + 0.22 * open);
            vec3 outlineCol = neutral ? vec3(0.86) : COL_CYAN;
            col = mix(col, outlineCol * 1.15, rimStroke * 0.92);
            col += outlineCol * outerHalo;
        }
    }

    // Subtle cyan glow halo around the orbiting paper talismans
    if (tr.matId < 2.5) {
        float dTal = max(tr.minTalismanDist, 0.0);
        float talGlow = exp(-dTal * 24.0) * (0.28 + 0.14 * open);
        col += (neutral ? vec3(0.70) : COL_CYAN) * talGlow;
    }

    // Floating comic star sparkles & tiny cyan diamond motes
    col += evalSparkles(uv, ro, rd, tHit, neutral);

    // Mild exposure & gentle vignette (never crushes corners to black)
    float exposure = neutral ? 1.05 : 1.06;
    col *= exposure;
    float vig = 1.0 - 0.14 * dot(uv, uv);
    col *= clamp(vig, 0.80, 1.0);

    // ACES Filmic Tone Mapping
    col = acesToneMap(col);

    // Pure neutral grayscale in uLightMode == 1
    if (neutral) {
        float lum = dot(col, vec3(0.2126, 0.7152, 0.0722));
        col = vec3(lum);
    }

    // sRGB gamma encode
    col = pow(max(col, vec3(0.0)), vec3(1.0 / 2.2));

    fragColor = vec4(col, 1.0);
}

Mathematical models & shader specifications

Identifierindigo-shadow-smoke-decoy
CategoryGame VFX Shaders · Stylized Cel VFX
Upstream studyvfx_stylized/lib/10_indigo_shadow_smoke_decoy.glsl (commit f5bfb61)
Animation cycle3.0 s seamless harmonic loop
Declared uniformsuResolution, uTime, uOpen, uLightMode, uCamMode
Source size892 lines · 32.1 KB standalone GLSL ES 3.00
PNG baker outputs512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key)
Companion pixel VFXFree MIT shadow 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, distance formulation · Inigo Quilez, quadratic distance blend

All game vfx shaders