3s LoopWhip-fast cel-shaded jade wind vortex with crisp white slipstream bands and swirling leaves.
neon-magenta-plasma-grenade.glsl · 896 lines · GLSL ES 3.00 · MIT
#version 300 es
// Neon Magenta Plasma Grenade (neon-magenta-plasma-grenade.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_stylized/lib/08_neon_magenta_plasma_grenade.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_neon_magenta_plasma_grenade.glsl
// Punchy 3D NEON HOT-MAGENTA & ELECTRIC PURPLE stylized plasma grenade
// starburst explosion on a dark matte ink-grouted charcoal tiled arena floor.
//
// Features:
// - Dark charcoal ink-grouted tiled arena floor vec3(0.08, 0.09, 0.12)
// with circular arena trim, subtle cel grunge, and hard ink drop shadows
// - Crisp concentric hot-pink & white comic shockwave rings with jagged
// starburst radial spikes and crawling surface lightning tendrils
// - 3D vertical zig-zag magenta-white lightning strike hitting the epicenter
// with secondary forks and comic energy shards
// - Chunky 3D raymarched ink-outlined flat-shaded violet smoke clouds
// with 3-band quantized cel shading, Fresnel + silhouette ink contours,
// and internal comic crease lines
// - Seamless 3-second loop on uTime; uOpen (0..1) expands the starburst blast
// ============================================================================
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
// Palette (linear-friendly vibrant stylized colors)
const vec3 COL_FLOOR_BASE = vec3(0.08, 0.09, 0.12);
const vec3 COL_FLOOR_DARK = vec3(0.048, 0.052, 0.075);
const vec3 COL_INK = vec3(0.012, 0.010, 0.020);
const vec3 COL_ARENA_TRIM = vec3(0.68, 0.09, 0.36);
const vec3 COL_MAGENTA_HOT = vec3(1.00, 0.11, 0.62);
const vec3 COL_MAGENTA_NEON = vec3(1.00, 0.28, 0.78);
const vec3 COL_MAGENTA_DEEP = vec3(0.55, 0.04, 0.38);
const vec3 COL_WHITE_CORE = vec3(1.00, 0.94, 0.99);
const vec3 COL_SMOKE_LIT = vec3(0.62, 0.25, 0.96);
const vec3 COL_SMOKE_MID = vec3(0.36, 0.12, 0.72);
const vec3 COL_SMOKE_SHAD = vec3(0.17, 0.055, 0.40);
const vec3 COL_SMOKE_RIM = vec3(0.95, 0.32, 0.88);
// ----------------------------------------------------------------------------
// Math & Noise Utilities
// ----------------------------------------------------------------------------
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 hash31(vec3 p3) {
p3 = fract(p3 * 0.1031);
p3 += dot(p3, p3.zyx + 31.32);
return fract((p3.x + p3.y) * p3.z);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
return mix(mix(a, b, u.x), mix(c, d, 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(17.1, 31.7);
a *= 0.5;
}
return v;
}
float smin(float a, float b, float k) {
float h = max(k - abs(a - b), 0.0) / max(k, 1e-5);
return min(a, b) - h * h * k * 0.25;
}
// Distance from point p to 2D segment ab, returning vec2(dist, t)
vec2 segDist2D(vec2 p, vec2 a, vec2 b) {
vec2 pa = p - a;
vec2 ba = b - a;
float denom = max(dot(ba, ba), 1e-6);
float t = clamp(dot(pa, ba) / denom, 0.0, 1.0);
return vec2(length(pa - ba * t), t);
}
// Closest distance between a ray (ro, rd) and a 3D line segment (a, b)
// Returns vec3(minDist, segT, rayT)
vec3 raySegDist(vec3 ro, vec3 rd, vec3 a, vec3 b) {
vec3 u = rd;
vec3 v = b - a;
vec3 w = ro - a;
float aDot = dot(u, u); // 1.0
float bDot = dot(u, v);
float cDot = dot(v, v);
float dDot = dot(u, w);
float eDot = dot(v, w);
float D = aDot * cDot - bDot * bDot;
float sc, tc;
if (D < 1e-6) {
sc = 0.0;
tc = (bDot > cDot ? dDot / max(bDot, 1e-6) : eDot / max(cDot, 1e-6));
} else {
sc = (bDot * eDot - cDot * dDot) / D;
tc = (aDot * eDot - bDot * dDot) / D;
}
tc = clamp(tc, 0.0, 1.0);
// Recompute optimal ray parameter sc for clamped tc
sc = max(dot(a + v * tc - ro, u), 0.0);
vec3 pRay = ro + u * sc;
vec3 pSeg = a + v * tc;
return vec3(length(pRay - pSeg), tc, sc);
}
// ----------------------------------------------------------------------------
// Animation Parameters (3-second seamless loop + uOpen 0..1 blast expansion)
// ----------------------------------------------------------------------------
struct AnimState {
float phase; // 0..1 seamless 3s loop
float openAmt; // 0..1 uOpen
float blastScale; // overall radial expansion of rings & spikes
float pulse; // smooth rhythmic pulse
float boltJitter; // stepped comic frame seed for lightning snap
};
AnimState getAnim() {
AnimState a;
a.phase = loopPhase();
a.openAmt = clamp(uOpen, 0.0, 1.0);
float breathe = 0.035 * sin(TAU * a.phase);
a.blastScale = mix(0.58, 1.12, smoothstep(0.0, 1.0, a.openAmt)) + breathe;
a.pulse = 0.5 + 0.5 * sin(TAU * a.phase);
// Quantize lightning flicker to 12 comic frames per 3s loop (seamless!)
float frameIdx = floor(a.phase * 12.0);
a.boltJitter = frameIdx;
return a;
}
// ----------------------------------------------------------------------------
// 3D Stylized Chunky Violet Smoke Clouds SDF
// Returns vec2(sdf, creaseFactor)
// ----------------------------------------------------------------------------
// Helper to blend a puff and track lobe seam proximity for comic crease ink
void addPuff(inout float d, inout float seam, vec3 p, vec3 c, float r, float k) {
float dp = length(p - c) - r;
// Detect intersection crease between adjacent puffs
float diff = abs(d - dp);
float nearBoth = smoothstep(0.14, 0.0, max(d, dp) - 0.02);
float crease = smoothstep(0.09, 0.01, diff) * nearBoth;
seam = max(seam, crease);
d = smin(d, dp, k);
}
// Tapered swirling smoke tendril along a floor curve
void addTail(inout float d, inout float seam, vec3 p, vec3 a, vec3 b, float ra, float rb, float k) {
vec3 pa = p - a, ba = b - a;
float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-6), 0.0, 1.0);
// Subtle wavy comic curl
vec3 q = pa - ba * h;
float r = mix(ra, rb, h);
float dp = length(q) - r;
float diff = abs(d - dp);
float nearBoth = smoothstep(0.12, 0.0, max(d, dp) - 0.02);
seam = max(seam, smoothstep(0.07, 0.01, diff) * nearBoth);
d = smin(d, dp, k);
}
vec2 mapSmoke(vec3 p, AnimState anim) {
// Early vertical bound check
if (p.y > 2.2 || p.y < -0.5) {
return vec2(max(p.y - 2.0, -0.35 - p.y) + 0.4, 0.0);
}
float d = 1e5;
float seam = 0.0;
float sc = anim.blastScale;
float drift = 0.06 * sin(TAU * anim.phase);
float drift2 = 0.05 * cos(TAU * anim.phase);
// Subtle chunky stylization warp so puffs feel hand-sculpted
vec3 pw = p;
pw.x += 0.04 * sin(p.z * 2.5 + TAU * anim.phase);
pw.z += 0.04 * cos(p.x * 2.5 - TAU * anim.phase);
// ------------------------------------------------------------------------
// 1. INNER BILLOWING SMOKE RING (hugging the outer shockwave perimeter)
// ------------------------------------------------------------------------
float ringR = 1.48 * sc;
// Back-left inner cluster (around angle 2.25 rad)
vec3 bl = vec3(-1.18 * sc, 0.24, -0.78 * sc);
addPuff(d, seam, pw, bl + vec3(0.0, 0.05 + drift * 0.4, 0.0), 0.44 * sc, 0.14);
addPuff(d, seam, pw, bl + vec3(-0.34 * sc, -0.02, 0.24 * sc), 0.34 * sc, 0.12);
addPuff(d, seam, pw, bl + vec3(0.36 * sc, -0.04, -0.18 * sc), 0.30 * sc, 0.12);
// Back-right inner cluster
vec3 br = vec3(1.12 * sc, 0.22, -0.76 * sc);
addPuff(d, seam, pw, br + vec3(0.0, 0.04 - drift * 0.4, 0.0), 0.40 * sc, 0.14);
addPuff(d, seam, pw, br + vec3(0.32 * sc, -0.04, 0.22 * sc), 0.30 * sc, 0.12);
addPuff(d, seam, pw, br + vec3(-0.32 * sc, -0.06, -0.16 * sc), 0.26 * sc, 0.12);
// Front-bottom low billowing rim puffs (under the front of the shockwave ring)
addPuff(d, seam, pw, vec3(-0.55 * sc, 0.10, 1.22 * sc), 0.32 * sc, 0.13);
addPuff(d, seam, pw, vec3( 0.04 * sc, 0.08, 1.32 * sc), 0.34 * sc, 0.13);
addPuff(d, seam, pw, vec3( 0.62 * sc, 0.11, 1.18 * sc), 0.31 * sc, 0.13);
addPuff(d, seam, pw, vec3(-1.05 * sc, 0.12, 0.88 * sc), 0.29 * sc, 0.12);
addPuff(d, seam, pw, vec3( 1.05 * sc, 0.12, 0.84 * sc), 0.28 * sc, 0.12);
// ------------------------------------------------------------------------
// 2. HERO FOREGROUND LEFT SWIRLING CLOUD (matches 08.png bottom-left)
// ------------------------------------------------------------------------
vec3 flBase = vec3(-2.35 - 0.25 * anim.openAmt, 0.46, 0.92 + drift2);
addPuff(d, seam, pw, flBase + vec3(-0.22, 0.16, -0.12), 0.66, 0.18);
addPuff(d, seam, pw, flBase + vec3( 0.28, -0.05, 0.14), 0.50, 0.16);
addPuff(d, seam, pw, flBase + vec3( 0.68, -0.18, -0.12), 0.36, 0.14);
addPuff(d, seam, pw, flBase + vec3( 0.52, -0.16, 0.48), 0.38, 0.15);
addTail(d, seam, pw, flBase + vec3(0.58, -0.24, 0.55), flBase + vec3(1.38, -0.34, 1.08), 0.26, 0.04, 0.12);
// ------------------------------------------------------------------------
// 3. HERO MID-RIGHT BILLOWING CLOUD (matches 08.png right edge)
// ------------------------------------------------------------------------
vec3 mrBase = vec3(2.58 + 0.20 * anim.openAmt, 0.44, 0.15 - drift2);
addPuff(d, seam, pw, mrBase + vec3( 0.25, 0.18, -0.06), 0.62, 0.18);
addPuff(d, seam, pw, mrBase + vec3(-0.26, -0.04, 0.16), 0.42, 0.15);
addTail(d, seam, pw, mrBase + vec3(-0.38, -0.16, 0.16), mrBase + vec3(-1.05, -0.26, 0.18), 0.24, 0.04, 0.12);
// ------------------------------------------------------------------------
// 4. HERO UPPER-RIGHT SWIRLING CLOUD (matches 08.png top-right)
// ------------------------------------------------------------------------
vec3 urBase = vec3(2.45 + 0.18 * anim.openAmt, 0.58, -1.85 + drift);
addPuff(d, seam, pw, urBase + vec3( 0.30, 0.26, -0.18), 0.72, 0.20);
addPuff(d, seam, pw, urBase + vec3(-0.28, 0.02, 0.14), 0.48, 0.16);
addPuff(d, seam, pw, urBase + vec3( 0.15, -0.08, 0.32), 0.42, 0.15);
addTail(d, seam, pw, urBase + vec3(-0.48, -0.18, 0.22), urBase + vec3(-1.35, -0.36, 0.34), 0.22, 0.035, 0.12);
// Flatten slightly underneath so clouds sit firmly on the arena floor
d = max(d, -p.y + 0.02);
return vec2(d, clamp(seam, 0.0, 1.0));
}
float mapSmokeDist(vec3 p, AnimState anim) {
return mapSmoke(p, anim).x;
}
vec3 calcSmokeNormal(vec3 p, AnimState anim) {
const vec2 e = vec2(0.004, -0.004);
vec3 n = e.xyy * mapSmokeDist(p + e.xyy, anim)
+ e.yyx * mapSmokeDist(p + e.yyx, anim)
+ e.yxy * mapSmokeDist(p + e.yxy, anim)
+ e.xxx * mapSmokeDist(p + e.xxx, anim);
return normalize(n + vec3(1e-6));
}
// ----------------------------------------------------------------------------
// Ground Shockwave Rings, Starburst Spikes, Epicenter Flash & Surface Bolts
// Evaluated cleanly on the arena floor plane (xz)
// ----------------------------------------------------------------------------
struct BlastGround {
vec3 emissive; // blazing magenta/white emissive energy
float alpha; // opaque coverage of crisp comic energy shapes
float inkMask; // dark ink outline around rings/spikes
float floorGlow; // cel-banded magenta bounce light on floor
};
BlastGround evalGroundBlast(vec2 xz, AnimState anim) {
BlastGround res;
res.emissive = vec3(0.0);
res.alpha = 0.0;
res.inkMask = 0.0;
res.floorGlow = 0.0;
float sc = anim.blastScale;
vec2 p = xz / max(sc, 0.15);
float r = length(p);
float ang = atan(p.y, p.x);
// Smooth outward-travelling wave phase inside the 3s loop
float wavePhase = anim.phase;
// ------------------------------------------------------------------------
// 1. Concentric Hot-Pink & White Shockwave Rings
// ------------------------------------------------------------------------
// 4 crisp rings matching 08.png: innermost, mid-inner, mid-outer, thick outer
float r1 = 0.56 + 0.03 * sin(TAU * wavePhase);
float r2 = 0.88 + 0.035 * sin(TAU * wavePhase - 0.9);
float r3 = 1.18 + 0.03 * sin(TAU * wavePhase - 1.8);
float r4 = 1.38 + 0.025 * sin(TAU * wavePhase - 2.6);
// Slight organic comic wobble on rings
float ringWob = 0.012 * sin(ang * 7.0 + TAU * wavePhase) + 0.008 * cos(ang * 13.0);
float d1 = abs(r - r1 + ringWob * 0.6);
float d2 = abs(r - r2 - ringWob * 0.8);
float d3 = abs(r - r3 + ringWob * 0.7);
float d4 = abs(r - r4 - ringWob * 0.5);
// Ring thicknesses (outer ring is thickest & boldest, inner rings crisp)
float ringCore = 0.0;
ringCore = max(ringCore, 1.0 - smoothstep(0.018, 0.030, d1));
ringCore = max(ringCore, 1.0 - smoothstep(0.024, 0.038, d2));
ringCore = max(ringCore, 1.0 - smoothstep(0.016, 0.028, d3));
ringCore = max(ringCore, 1.0 - smoothstep(0.044, 0.062, d4));
// Hot magenta aura immediately framing each white ring
float ringGlow = 0.0;
ringGlow = max(ringGlow, 1.0 - smoothstep(0.026, 0.085, d1));
ringGlow = max(ringGlow, 1.0 - smoothstep(0.034, 0.105, d2));
ringGlow = max(ringGlow, 1.0 - smoothstep(0.024, 0.075, d3));
ringGlow = max(ringGlow, 1.0 - smoothstep(0.056, 0.155, d4));
// Travelling pulse wave sweeping radially outward from center to outer ring
float pulseR = mix(0.25, 1.50, fract(wavePhase * 2.0));
float pulseBand = exp(-pow((r - pulseR) * 5.0, 2.0)) * smoothstep(1.58, 1.28, r);
// Dark ink outer edge right outside the outermost ring (comic grounding)
float outerInk = smoothstep(0.11, 0.06, abs(r - (r4 + 0.095)));
// ------------------------------------------------------------------------
// 2. Jagged Starburst Radial Spikes (10 iconic lance/arrow spikes!)
// ------------------------------------------------------------------------
float spikeCore = 0.0;
float spikeGlow = 0.0;
float spikeInk = 0.0;
const int NUM_SPIKES = 10;
for (int i = 0; i < NUM_SPIKES; i++) {
float fi = float(i);
// Uneven comic spacing so it feels hand-drawn, not robotic
float baseAng = fi * (TAU / float(NUM_SPIKES)) + 0.18 * sin(fi * 2.7) + 0.16;
float ca = cos(baseAng), sa = sin(baseAng);
// Local coordinates along spike axis (lx = outward, ly = perpendicular)
float lx = p.x * ca + p.y * sa;
float ly = -p.x * sa + p.y * ca;
// Alternating long dramatic spikes and medium spikes
float spikeLen = mix(1.88, 2.38, hash11(fi * 7.31 + 1.2));
// Make front-pointing spike extra dramatic (matches 08.png bottom center)
if (i == 2) spikeLen = 2.52;
spikeLen += 0.08 * sin(TAU * wavePhase + fi * 1.7);
float startR = 1.18;
float t = (lx - startR) / max(spikeLen - startR, 0.1);
if (t > -0.08 && t < 1.08) {
// Arrow/lance profile: flares out slightly near base with a comic notch, tapers to razor tip
float tClamped = clamp(t, 0.0, 1.0);
float baseW = mix(0.115, 0.155, hash11(fi * 3.1 + 4.0));
float notch = 1.0 - 0.35 * exp(-pow((tClamped - 0.14) * 14.0, 2.0));
float halfW = baseW * pow(max(1.0 - tClamped, 0.0), 1.15) * notch;
// Taper smoothly at the inner root
halfW *= smoothstep(-0.06, 0.08, t);
float dSpike = abs(ly) - halfW;
// Sharp outer tip cutoff
float tipMask = smoothstep(1.03, 0.96, t) * smoothstep(-0.06, 0.04, t);
float scMask = (1.0 - smoothstep(-0.012, 0.008, dSpike)) * tipMask;
float sgMask = (1.0 - smoothstep(0.005, 0.068, dSpike)) * tipMask;
float siMask = smoothstep(0.075, 0.035, abs(dSpike - 0.045)) * smoothstep(0.02, 0.15, t) * tipMask;
spikeCore = max(spikeCore, scMask);
spikeGlow = max(spikeGlow, sgMask);
spikeInk = max(spikeInk, siMask * 0.75);
}
}
// Secondary tiny razor needles between main spikes
for (int i = 0; i < 8; i++) {
float fi = float(i);
float baseAng = (fi + 0.5) * (TAU / 8.0) + 0.25 * cos(fi * 4.1);
float ca = cos(baseAng), sa = sin(baseAng);
float lx = p.x * ca + p.y * sa;
float ly = -p.x * sa + p.y * ca;
float t = (lx - 1.32) / 0.42;
if (t > 0.0 && t < 1.0) {
float halfW = 0.035 * (1.0 - t);
float dMini = abs(ly) - halfW;
spikeCore = max(spikeCore, 1.0 - smoothstep(-0.004, 0.008, dMini));
spikeGlow = max(spikeGlow, 1.0 - smoothstep(0.004, 0.035, dMini));
}
}
// ------------------------------------------------------------------------
// 3. Central Jagged Comic Starburst Flash at the Epicenter
// ------------------------------------------------------------------------
float starRays = 0.28
+ 0.22 * pow(0.5 + 0.5 * sin(ang * 9.0 + 0.4), 3.0)
+ 0.18 * pow(0.5 + 0.5 * sin(ang * 15.0 - 1.2 + TAU * wavePhase * 0.0), 4.0)
+ 0.10 * sin(ang * 5.0 + 2.1);
starRays *= (0.94 + 0.10 * anim.pulse);
float dStar = r - starRays;
float centerCore = 1.0 - smoothstep(-0.03, 0.02, dStar);
float centerGlow = 1.0 - smoothstep(0.01, 0.19, dStar);
// ------------------------------------------------------------------------
// 4. Radial Ground Lightning Tendrils crawling from center out to spikes
// ------------------------------------------------------------------------
float boltCore = 0.0;
float boltGlow = 0.0;
const int NUM_BOLTS = 6;
for (int i = 0; i < NUM_BOLTS; i++) {
float fi = float(i);
float bAng = fi * (TAU / float(NUM_BOLTS)) + 0.35 + 0.22 * sin(fi * 3.7);
float ca = cos(bAng), sa = sin(bAng);
float lx = p.x * ca + p.y * sa;
float ly = -p.x * sa + p.y * ca;
if (lx > 0.12 && lx < 1.85) {
// Sharp zig-zag polyline offset
float segPos = lx * 4.2;
float segIdx = floor(segPos);
float segF = fract(segPos);
float j0 = (hash11(segIdx * 13.7 + fi * 41.3 + anim.boltJitter * 0.17) - 0.5) * 0.26;
float j1 = (hash11((segIdx + 1.0) * 13.7 + fi * 41.3 + anim.boltJitter * 0.17) - 0.5) * 0.26;
float zigY = mix(j0, j1, segF) * smoothstep(0.12, 0.45, lx) * smoothstep(1.85, 1.45, lx);
float dBolt = abs(ly - zigY);
float thick = mix(0.024, 0.008, lx / 1.85);
boltCore = max(boltCore, 1.0 - smoothstep(thick * 0.5, thick * 1.4, dBolt));
boltGlow = max(boltGlow, 1.0 - smoothstep(thick, thick * 4.5, dBolt));
}
}
// ------------------------------------------------------------------------
// 5. Detached Flying Comic Spark Dashes around outer perimeter
// ------------------------------------------------------------------------
float sparkMask = 0.0;
for (int i = 0; i < 8; i++) {
float fi = float(i);
float sAng = fi * (TAU / 8.0) + 0.65;
float ca = cos(sAng), sa = sin(sAng);
float lx = p.x * ca + p.y * sa;
float ly = -p.x * sa + p.y * ca;
float travel = fract(wavePhase + hash11(fi * 5.9));
float sr = mix(1.52, 2.15, travel);
vec2 sd = segDist2D(vec2(lx, ly), vec2(sr, 0.0), vec2(sr + 0.18, 0.0));
float fade = smoothstep(0.0, 0.15, travel) * smoothstep(1.0, 0.65, travel);
sparkMask = max(sparkMask, (1.0 - smoothstep(0.008, 0.022, sd.x)) * fade);
}
// Combine crisp cel layers
float totalCore = clamp(max(max(ringCore, spikeCore), max(centerCore, max(boltCore, sparkMask))), 0.0, 1.0);
float totalGlow = clamp(max(max(ringGlow, spikeGlow), max(centerGlow, boltGlow)), 0.0, 1.0);
// Stylized 2-tier energy color: hot neon magenta halo + blazing white-pink core
vec3 glowCol = mix(COL_MAGENTA_DEEP, COL_MAGENTA_HOT, smoothstep(0.15, 0.65, totalGlow));
glowCol = mix(glowCol, COL_MAGENTA_NEON, smoothstep(0.55, 0.92, totalGlow));
vec3 coreCol = mix(glowCol, COL_WHITE_CORE, smoothstep(0.25, 0.72, totalCore));
// Boost brightness cleanly (will be soft-tonemapped below 1.0 clip)
float energyBoost = 1.35 + 0.25 * pulseBand + 0.20 * centerCore;
res.emissive = coreCol * energyBoost * max(totalGlow, totalCore);
res.alpha = clamp(max(totalCore, totalGlow * 0.92), 0.0, 1.0);
res.inkMask = clamp(max(outerInk, spikeInk) * (1.0 - totalGlow * 0.85), 0.0, 1.0);
// Quantized cel-banded floor illumination from the plasma blast
float rawGlow = exp(-r * 0.78) * 1.15 + 0.35 * exp(-abs(r - r4) * 2.4);
float qGlow = floor(clamp(rawGlow, 0.0, 1.0) * 3.5) / 3.5;
res.floorGlow = mix(rawGlow, qGlow, 0.65);
return res;
}
// ----------------------------------------------------------------------------
// 3D Vertical Zig-Zag Magenta-White Lightning Strike + Secondary Forks
// ----------------------------------------------------------------------------
vec4 evalVerticalLightning(vec3 ro, vec3 rd, float maxT, AnimState anim) {
// 6-vertex dramatic zig-zag bolt from y = 0.04 up to y = 2.75
// Matches the iconic jagged S-curve spear silhouette in 08.png
float j = anim.boltJitter;
float sway = 0.06 * sin(TAU * anim.phase);
float flick1 = (hash11(j * 3.7 + 1.1) - 0.5) * 0.08;
float flick2 = (hash11(j * 5.3 + 2.7) - 0.5) * 0.08;
float flick3 = (hash11(j * 7.1 + 4.3) - 0.5) * 0.06;
vec3 pts[6];
pts[0] = vec3( 0.00, 0.02, 0.00);
pts[1] = vec3( 0.07 + sway + flick1, 0.52, -0.04);
pts[2] = vec3(-0.08 - sway + flick2, 1.04, 0.05);
pts[3] = vec3( 0.16 + sway + flick3, 1.56, -0.05);
pts[4] = vec3(-0.09 + flick1 * 0.7, 2.12, 0.03);
pts[5] = vec3( 0.02, 2.82, 0.00);
float coreMask = 0.0;
float glowMask = 0.0;
float hitT = maxT;
// Main vertical bolt segments
for (int i = 0; i < 5; i++) {
vec3 dInfo = raySegDist(ro, rd, pts[i], pts[i + 1]);
float dist = dInfo.x;
float segT = dInfo.y;
float rayT = dInfo.z;
if (rayT < maxT && rayT > 0.05) {
float hFrac = (float(i) + segT) / 5.0;
// Thickest at impact base, tapering to a needle spear at the top
float baseRad = mix(0.085, 0.008, pow(hFrac, 0.85));
// Slight flare at sharp elbow bends
float elbow = 1.0 + 0.25 * exp(-pow((segT - 0.5) * 4.0, 2.0)) * (1.0 - hFrac);
float rad = baseRad * elbow;
float c = 1.0 - smoothstep(rad * 0.55, rad * 1.15, dist);
float g = 1.0 - smoothstep(rad * 1.05, rad * 3.20, dist);
if (g > glowMask) hitT = min(hitT, rayT);
coreMask = max(coreMask, c);
glowMask = max(glowMask, g);
}
}
// Secondary forked electric crackles branching off the main bolt
vec3 f1a = pts[1];
vec3 f1b = pts[1] + vec3(0.24, 0.38, 0.08);
vec3 f1c = f1b + vec3(-0.06, 0.34, -0.05);
vec3 f2a = pts[2];
vec3 f2b = pts[2] + vec3(-0.26, 0.34, -0.06);
vec3 f2c = f2b + vec3(-0.10, 0.36, 0.08);
vec3 f3a = pts[3];
vec3 f3b = pts[3] + vec3(-0.22, -0.26, 0.06);
vec3 forksA[5];
vec3 forksB[5];
forksA[0] = f1a; forksB[0] = f1b;
forksA[1] = f1b; forksB[1] = f1c;
forksA[2] = f2a; forksB[2] = f2b;
forksA[3] = f2b; forksB[3] = f2c;
forksA[4] = f3a; forksB[4] = f3b;
for (int i = 0; i < 5; i++) {
vec3 dInfo = raySegDist(ro, rd, forksA[i], forksB[i]);
if (dInfo.z < maxT && dInfo.z > 0.05) {
float rad = mix(0.016, 0.004, dInfo.y);
coreMask = max(coreMask, 1.0 - smoothstep(rad * 0.5, rad * 1.2, dInfo.x));
glowMask = max(glowMask, 1.0 - smoothstep(rad, rad * 3.8, dInfo.x));
}
}
// Floating vertical pink spark shards around the bolt (just like 08.png)
for (int i = 0; i < 6; i++) {
float fi = float(i);
float a = fi * 1.15 + 0.4;
float radR = mix(0.32, 0.58, hash11(fi * 9.3 + 1.0));
float rise = fract(anim.phase + hash11(fi * 4.7));
float y0 = mix(0.55, 2.05, rise);
vec3 sa = vec3(cos(a) * radR, y0, sin(a) * radR * 0.55);
vec3 sb = sa + vec3(cos(a) * 0.05, 0.22, sin(a) * 0.03);
vec3 dInfo = raySegDist(ro, rd, sa, sb);
if (dInfo.z < maxT && dInfo.z > 0.05) {
float fade = smoothstep(0.0, 0.15, rise) * smoothstep(1.0, 0.7, rise);
float sc = (1.0 - smoothstep(0.006, 0.015, dInfo.x)) * fade;
float sg = (1.0 - smoothstep(0.012, 0.045, dInfo.x)) * fade;
coreMask = max(coreMask, sc);
glowMask = max(glowMask, sg);
}
}
vec3 boltCol = mix(COL_MAGENTA_HOT * 1.35, COL_MAGENTA_NEON * 1.55, smoothstep(0.25, 0.8, glowMask));
boltCol = mix(boltCol, COL_WHITE_CORE * 1.75, smoothstep(0.18, 0.72, coreMask));
float alpha = clamp(max(coreMask, glowMask * 0.95), 0.0, 1.0);
return vec4(boltCol * alpha, alpha);
}
// ----------------------------------------------------------------------------
// Dark Ink-Grouted Charcoal Tiled Arena Floor Shading
// ----------------------------------------------------------------------------
vec3 shadeArenaFloor(vec3 p, vec3 rd, AnimState anim, vec3 lightDir) {
// Rotate tile grid slightly for dynamic diagonal comic composition (matches 08.png)
vec2 gPos = rot2(0.32) * p.xz;
vec2 tileScale = vec2(1.45, 1.45);
vec2 cellId = floor(gPos / tileScale);
vec2 cellUv = fract(gPos / tileScale) - 0.5;
// Distance to grout lines (bold dark comic ink seams)
vec2 edgeDist = 0.5 - abs(cellUv);
float minEdge = min(edgeDist.x, edgeDist.y);
float groutWidth = 0.022;
float groutInk = 1.0 - smoothstep(groutWidth * 0.75, groutWidth * 1.35, minEdge);
// Subtle secondary bevel highlight next to grout lines
float bevelEdge = smoothstep(groutWidth * 1.2, groutWidth * 2.2, minEdge)
* (1.0 - smoothstep(groutWidth * 2.2, groutWidth * 4.0, minEdge));
// Per-tile tonal variation + subtle quantized comic concrete grunge
float tileVar = (hash21(cellId) - 0.5) * 0.022;
float grunge = fbm2(gPos * 3.8);
float grungeQ = floor(grunge * 3.0) / 3.0;
vec3 floorCol = COL_FLOOR_BASE + vec3(tileVar) + (grungeQ - 0.5) * vec3(0.018, 0.019, 0.024);
floorCol += bevelEdge * vec3(0.025, 0.028, 0.038);
// Circular outer arena rim + hot-magenta trim panels (seen at top of 08.png)
float arenaR = length(p.xz);
float rimInner = 4.35;
float rimOuter = 4.75;
if (arenaR > rimInner - 0.15) {
float rimBand = smoothstep(rimInner - 0.04, rimInner + 0.02, arenaR)
* (1.0 - smoothstep(rimOuter - 0.02, rimOuter + 0.04, arenaR));
float rimAng = atan(p.z, p.x);
float panelSeg = fract(rimAng * 12.0 / TAU);
float panelSeam = 1.0 - smoothstep(0.03, 0.06, min(panelSeg, 1.0 - panelSeg));
float litPanel = step(0.18, hash11(floor(rimAng * 12.0 / TAU) * 7.3 + 2.0));
vec3 rimCol = mix(vec3(0.11, 0.12, 0.16), COL_ARENA_TRIM * 0.85, litPanel);
rimCol = mix(rimCol, COL_INK, panelSeam * 0.9);
floorCol = mix(floorCol, rimCol, rimBand);
// Bold ink borders on the arena curb
float curbInk = (1.0 - smoothstep(0.02, 0.05, abs(arenaR - rimInner)))
+ (1.0 - smoothstep(0.02, 0.05, abs(arenaR - rimOuter)));
floorCol = mix(floorCol, COL_INK, clamp(curbInk, 0.0, 1.0));
// Darker matte outer arena void beyond the curb
float beyond = smoothstep(rimOuter, rimOuter + 0.15, arenaR);
floorCol = mix(floorCol, COL_FLOOR_DARK, beyond);
}
// Apply bold ink grout lines inside the arena
float insideArena = 1.0 - smoothstep(rimInner - 0.05, rimInner + 0.02, arenaR);
floorCol = mix(floorCol, COL_INK, groutInk * insideArena * 0.92);
// LightMode directional tint on floor
if (uLightMode == 2) {
floorCol *= vec3(0.92, 1.00, 1.18);
}
// Crisp hard-edged comic drop shadow cast by the smoke clouds onto the floor
vec3 shPos = p + vec3(lightDir.x * 0.18, 0.18, lightDir.z * 0.18);
float dSmoke = mapSmokeDist(shPos, anim);
float dropShadow = 1.0 - smoothstep(0.02, 0.16, dSmoke);
floorCol = mix(floorCol, COL_INK * 1.15, dropShadow * 0.78);
// Evaluate the neon magenta plasma blast on the floor
BlastGround blast = evalGroundBlast(p.xz, anim);
float emitScale = (uLightMode == 1) ? 0.38 : 1.0;
// Add cel-banded neon magenta bounce light onto the charcoal tiles
vec3 bounceCol = mix(COL_MAGENTA_DEEP, COL_MAGENTA_HOT, 0.6) * blast.floorGlow * 0.42 * emitScale;
// Slight magenta rim glow in the grout lines near the explosion!
float neonGrout = groutInk * insideArena * smoothstep(2.6, 1.2, arenaR) * 0.55 * emitScale;
floorCol += bounceCol * (1.0 - dropShadow * 0.5) + COL_MAGENTA_HOT * neonGrout * 0.35;
// Apply dark comic ink edge around rings/spikes
floorCol = mix(floorCol, COL_INK, blast.inkMask * 0.85);
// Composite crisp blazing shockwave rings, spikes, and ground bolts
floorCol = mix(floorCol, blast.emissive * mix(0.55, 1.0, emitScale), blast.alpha);
// Atmospheric depth fade into dark charcoal-violet arena wall at far distance
float distFade = smoothstep(5.5, 12.5, length(p.xz));
vec3 farBg = vec3(0.042, 0.040, 0.062);
floorCol = mix(floorCol, farBg, distFade);
return floorCol;
}
// ----------------------------------------------------------------------------
// Cel-Shaded 3-Band Stylized Violet Smoke Shading with Ink Contours
// ----------------------------------------------------------------------------
vec3 shadeSmoke(vec3 p, vec3 N, vec3 V, float crease, AnimState anim, vec3 keyDir) {
// 1. Primary light from overhead key + strong magenta light from epicenter (0, 0.35, 0)
vec3 toCenter = vec3(0.0, 0.35, 0.0) - p;
float distCenter = length(toCenter);
vec3 blastDir = toCenter / max(distCenter, 1e-5);
float ndlKey = dot(N, keyDir);
float ndlBlast = dot(N, blastDir);
float blastAtten = 1.0 / (1.0 + 0.18 * distCenter * distCenter);
// Combine lighting scalar for 3-band quantized cel shading
float lit = ndlKey * 0.55 + ndlBlast * blastAtten * 0.85 + 0.25;
// Quantize into 3 crisp stylized comic bands (Shadow -> Mid -> Lit)
float band1 = smoothstep(0.14, 0.18, lit);
float band2 = smoothstep(0.54, 0.59, lit);
vec3 col = mix(COL_SMOKE_SHAD, COL_SMOKE_MID, band1);
col = mix(col, COL_SMOKE_LIT, band2);
// LightMode adjustments
if (uLightMode == 2) {
col = mix(col, col * vec3(0.84, 0.96, 1.22), 0.7);
}
// Hot-magenta rim highlight on puff edges facing the plasma epicenter
float ndv = clamp(dot(N, V), 0.0, 1.0);
float fresnel = 1.0 - ndv;
float rimScale = (uLightMode == 1) ? 0.25 : 0.85;
float blastRim = smoothstep(0.45, 0.75, fresnel) * smoothstep(0.05, 0.45, ndlBlast) * blastAtten;
col = mix(col, COL_SMOKE_RIM * 1.15, clamp(blastRim * rimScale, 0.0, 0.85));
// Bold black-ink Fresnel contour + internal lobe crease lines
float inkFresnel = smoothstep(0.27, 0.17, ndv);
float inkCrease = smoothstep(0.42, 0.72, crease) * 0.92;
float inkMask = clamp(max(inkFresnel, inkCrease), 0.0, 1.0);
col = mix(col, COL_INK, inkMask);
return col;
}
// ----------------------------------------------------------------------------
// Camera Setup (4 uCamMode presets)
// ----------------------------------------------------------------------------
void setupCamera(out vec3 ro, out vec3 ta, out float fl, AnimState anim) {
if (uCamMode == 1) {
// Low dramatic heroic angle looking across the shockwave rings up at the strike
ro = vec3(0.45, 1.42, 3.95);
ta = vec3(0.00, 0.62, 0.00);
fl = 1.45;
} else if (uCamMode == 2) {
// High tactical top-down view showing full concentric starburst & smoke ring
ro = vec3(0.00, 5.10, 1.55);
ta = vec3(0.00, 0.05, 0.10);
fl = 1.60;
} else if (uCamMode == 3) {
// Smooth 3-second orbital showcase
float a = TAU * anim.phase * 0.5 - 0.35;
ro = vec3(sin(a) * 3.85, 2.75, cos(a) * 3.85);
ta = vec3(0.00, 0.38, 0.00);
fl = 1.55;
} else {
// Default Hero 3/4 Elevated Arena View (matches 08.png composition)
ro = vec3(0.00, 3.12, 3.62);
ta = vec3(0.00, 0.34, 0.05);
fl = 1.56;
}
}
// ----------------------------------------------------------------------------
// Stylized Filmic Tone Mapping (punchy neon saturation, <1% clip, <2% black)
// ----------------------------------------------------------------------------
vec3 stylizedTonemap(vec3 c) {
// Soft shoulder curve that preserves vibrant magenta/violet hue and prevents clipping
c = max(c, vec3(0.0));
if (uLightMode == 1) {
float lum = dot(c, vec3(0.2126, 0.7152, 0.0722));
c = vec3(lum);
}
vec3 mapped = (c * (2.51 * c + 0.03)) / (c * (2.43 * c + 0.59) + 0.14);
// Keep peak safely under 0.975 so <1% clip is guaranteed even at white-hot core
mapped = mapped * 0.965;
// Gamma encode to sRGB
vec3 srgb = pow(clamp(mapped, 0.0, 0.98), vec3(1.0 / 2.2));
// Subtle dark ink floor lift so deep ink reads crisp jet-black without pure-black crush
vec3 inkFloor = (uLightMode == 1) ? vec3(0.036) : vec3(0.032, 0.030, 0.044);
srgb = max(srgb, inkFloor);
if (uLightMode == 1) {
srgb = vec3(dot(srgb, vec3(0.2126, 0.7152, 0.0722)));
}
return clamp(srgb, 0.0, 0.985);
}
// ----------------------------------------------------------------------------
// Main
// ----------------------------------------------------------------------------
void main() {
vec2 res = max(uResolution, vec2(1.0));
vec2 uv = (gl_FragCoord.xy - 0.5 * res) / min(res.x, res.y);
AnimState anim = getAnim();
vec3 ro, ta;
float fl;
setupCamera(ro, ta, fl, anim);
vec3 ww = normalize(ta - ro);
vec3 uu = normalize(cross(ww, vec3(0.0, 1.0, 0.0)));
vec3 vv = cross(uu, ww);
vec3 rd = normalize(uv.x * uu + uv.y * vv + fl * ww);
// Key light direction by uLightMode
vec3 keyDir = normalize(vec3(-0.35, 0.85, 0.40));
if (uLightMode == 1) {
keyDir = normalize(vec3(0.45, 0.78, 0.42));
} else if (uLightMode == 2) {
keyDir = normalize(vec3(-0.62, 0.65, -0.44));
}
// 1. Background sky / upper arena wall gradient (dark matte charcoal-indigo)
float skyGrad = clamp(rd.y * 1.5 + 0.35, 0.0, 1.0);
vec3 col = mix(vec3(0.042, 0.040, 0.062), vec3(0.022, 0.020, 0.036), skyGrad);
// Subtle distant magenta atmospheric glow behind the vertical strike
float bgGlow = exp(-length(uv - vec2(0.0, 0.10)) * 2.2) * ((uLightMode == 1) ? 0.03 : 0.12);
col += COL_MAGENTA_DEEP * bgGlow;
// 2. Analytic intersection with the arena floor plane (y = 0)
float tFloor = 1e5;
if (rd.y < -1e-4) {
float tf = -ro.y / rd.y;
if (tf > 0.0 && tf < 30.0) {
tFloor = tf;
vec3 pFloor = ro + rd * tFloor;
col = shadeArenaFloor(pFloor, rd, anim, keyDir);
}
}
// 3. Raymarch 3D chunky ink-outlined violet smoke clouds
float tMax = min(tFloor, 14.0);
float t = 0.25;
bool hitSmoke = false;
vec3 pHit = vec3(0.0);
float hitCrease = 0.0;
float minRatio = 1e5;
float prevD = 1e5;
for (int i = 0; i < 68; i++) {
if (t > tMax) break;
vec3 p = ro + rd * t;
vec2 m = mapSmoke(p, anim);
float d = m.x;
// Track near-miss silhouette edge for crisp uniform comic ink outline
if (d > prevD && t > 0.5) {
minRatio = min(minRatio, prevD / t);
}
prevD = d;
if (d < 0.0035) {
hitSmoke = true;
pHit = p;
hitCrease = m.y;
break;
}
t += max(d * 0.85, 0.015);
}
float sceneDepth = tFloor;
if (hitSmoke) {
sceneDepth = t;
vec3 N = calcSmokeNormal(pHit, anim);
vec3 smokeCol = shadeSmoke(pHit, N, -rd, hitCrease, anim, keyDir);
// Allow inner shockwave ring glow to subtly kiss the lower edge of inner smoke
float edgeKiss = smoothstep(0.28, 0.02, pHit.y) * smoothstep(2.0, 1.2, length(pHit.xz));
smokeCol += COL_MAGENTA_HOT * edgeKiss * ((uLightMode == 1) ? 0.06 : 0.28);
col = smokeCol;
} else if (minRatio < 0.011) {
// Crisp outer black-ink comic silhouette halo around missed grazing smoke edges
float outlineMask = 1.0 - smoothstep(0.004, 0.011, minRatio);
col = mix(col, COL_INK, outlineMask * 0.90);
}
// 4. Composite 3D vertical zig-zag magenta-white lightning strike + forks + shards
vec4 bolt = evalVerticalLightning(ro, rd, sceneDepth + 0.35, anim);
float boltScale = (uLightMode == 1) ? 0.55 : 1.0;
vec3 boltRgb = bolt.rgb * boltScale;
col = mix(col, col + boltRgb, clamp(bolt.a, 0.0, 1.0));
// Ensure crisp opaque white core punches right over dark background & smoke
col = mix(col, boltRgb, smoothstep(0.65, 0.95, bolt.a));
// Subtle vignette to frame the arena blast without crushing corners
float vig = 1.0 - 0.18 * dot(uv, uv);
col *= clamp(vig, 0.72, 1.0);
fragColor = vec4(stylizedTonemap(col), 1.0);
}
shader_type canvas_item;
// Tip: uncomment the next line for zero-overdraw additive 2D combat/spell glow:
// render_mode blend_add;
// Neon Magenta Plasma Grenade — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/vfx_stylized/lib/08_neon_magenta_plasma_grenade.glsl (MIT License)
// Drive uTime from GDScript if animating helper functions: material.set_shader_parameter("uTime", Time.get_ticks_msec() * 0.001 * u_speed)
uniform vec2 uResolution = vec2(1024.0, 1024.0);
uniform float uTime = 1.2;
uniform float u_speed : hint_range(0.0, 3.0, 0.05) = 1.0;
uniform float u_tiling : hint_range(0.25, 8.0, 0.25) = 1.0;
uniform vec4 u_tint : source_color = vec4(1.0, 0.722, 0.42, 1.0);
uniform float u_tint_mix : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform float uOpen : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform int uLightMode : hint_range(0, 3, 1) = 0;
uniform int uCamMode : hint_range(0, 1, 1) = 0;
uniform bool u_luma_alpha_key = false;
// ============================================================================
// 08_neon_magenta_plasma_grenade.glsl
// Punchy 3D NEON HOT-MAGENTA & ELECTRIC PURPLE stylized plasma grenade
// starburst explosion on a dark matte ink-grouted charcoal tiled arena floor.
//
// Features:
// - Dark charcoal ink-grouted tiled arena floor vec3(0.08, 0.09, 0.12)
// with circular arena trim, subtle cel grunge, and hard ink drop shadows
// - Crisp concentric hot-pink & white comic shockwave rings with jagged
// starburst radial spikes and crawling surface lightning tendrils
// - 3D vertical zig-zag magenta-white lightning strike hitting the epicenter
// with secondary forks and comic energy shards
// - Chunky 3D raymarched ink-outlined flat-shaded violet smoke clouds
// with 3-band quantized cel shading, Fresnel + silhouette ink contours,
// and internal comic crease lines
// - Seamless 3-second loop on uTime; uOpen (0..1) expands the starburst blast
// ============================================================================
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
// Palette (linear-friendly vibrant stylized colors)
const vec3 COL_FLOOR_BASE = vec3(0.08, 0.09, 0.12);
const vec3 COL_FLOOR_DARK = vec3(0.048, 0.052, 0.075);
const vec3 COL_INK = vec3(0.012, 0.010, 0.020);
const vec3 COL_ARENA_TRIM = vec3(0.68, 0.09, 0.36);
const vec3 COL_MAGENTA_HOT = vec3(1.00, 0.11, 0.62);
const vec3 COL_MAGENTA_NEON = vec3(1.00, 0.28, 0.78);
const vec3 COL_MAGENTA_DEEP = vec3(0.55, 0.04, 0.38);
const vec3 COL_WHITE_CORE = vec3(1.00, 0.94, 0.99);
const vec3 COL_SMOKE_LIT = vec3(0.62, 0.25, 0.96);
const vec3 COL_SMOKE_MID = vec3(0.36, 0.12, 0.72);
const vec3 COL_SMOKE_SHAD = vec3(0.17, 0.055, 0.40);
const vec3 COL_SMOKE_RIM = vec3(0.95, 0.32, 0.88);
// ----------------------------------------------------------------------------
// Math & Noise Utilities
// ----------------------------------------------------------------------------
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 hash31(vec3 p3) {
p3 = fract(p3 * 0.1031);
p3 += dot(p3, p3.zyx + 31.32);
return fract((p3.x + p3.y) * p3.z);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
return mix(mix(a, b, u.x), mix(c, d, 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(17.1, 31.7);
a *= 0.5;
}
return v;
}
float smin(float a, float b, float k) {
float h = max(k - abs(a - b), 0.0) / max(k, 1e-5);
return min(a, b) - h * h * k * 0.25;
}
// Distance from point p to 2D segment ab, returning vec2(dist, t)
vec2 segDist2D(vec2 p, vec2 a, vec2 b) {
vec2 pa = p - a;
vec2 ba = b - a;
float denom = max(dot(ba, ba), 1e-6);
float t = clamp(dot(pa, ba) / denom, 0.0, 1.0);
return vec2(length(pa - ba * t), t);
}
// Closest distance between a ray (ro, rd) and a 3D line segment (a, b)
// Returns vec3(minDist, segT, rayT)
vec3 raySegDist(vec3 ro, vec3 rd, vec3 a, vec3 b) {
vec3 u = rd;
vec3 v = b - a;
vec3 w = ro - a;
float aDot = dot(u, u); // 1.0
float bDot = dot(u, v);
float cDot = dot(v, v);
float dDot = dot(u, w);
float eDot = dot(v, w);
float D = aDot * cDot - bDot * bDot;
float sc, tc;
if (D < 1e-6) {
sc = 0.0;
tc = (bDot > cDot ? dDot / max(bDot, 1e-6) : eDot / max(cDot, 1e-6));
} else {
sc = (bDot * eDot - cDot * dDot) / D;
tc = (aDot * eDot - bDot * dDot) / D;
}
tc = clamp(tc, 0.0, 1.0);
// Recompute optimal ray parameter sc for clamped tc
sc = max(dot(a + v * tc - ro, u), 0.0);
vec3 pRay = ro + u * sc;
vec3 pSeg = a + v * tc;
return vec3(length(pRay - pSeg), tc, sc);
}
// ----------------------------------------------------------------------------
// Animation Parameters (3-second seamless loop + uOpen 0..1 blast expansion)
// ----------------------------------------------------------------------------
struct AnimState {
float phase; // 0..1 seamless 3s loop
float openAmt; // 0..1 uOpen
float blastScale; // overall radial expansion of rings & spikes
float pulse; // smooth rhythmic pulse
float boltJitter; // stepped comic frame seed for lightning snap
};
AnimState getAnim() {
AnimState a;
a.phase = loopPhase();
a.openAmt = clamp(uOpen, 0.0, 1.0);
float breathe = 0.035 * sin(TAU * a.phase);
a.blastScale = mix(0.58, 1.12, smoothstep(0.0, 1.0, a.openAmt)) + breathe;
a.pulse = 0.5 + 0.5 * sin(TAU * a.phase);
// Quantize lightning flicker to 12 comic frames per 3s loop (seamless!)
float frameIdx = floor(a.phase * 12.0);
a.boltJitter = frameIdx;
return a;
}
// ----------------------------------------------------------------------------
// 3D Stylized Chunky Violet Smoke Clouds SDF
// Returns vec2(sdf, creaseFactor)
// ----------------------------------------------------------------------------
// Helper to blend a puff and track lobe seam proximity for comic crease ink
void addPuff(inout float d, inout float seam, vec3 p, vec3 c, float r, float k) {
float dp = length(p - c) - r;
// Detect intersection crease between adjacent puffs
float diff = abs(d - dp);
float nearBoth = smoothstep(0.14, 0.0, max(d, dp) - 0.02);
float crease = smoothstep(0.09, 0.01, diff) * nearBoth;
seam = max(seam, crease);
d = smin(d, dp, k);
}
// Tapered swirling smoke tendril along a floor curve
void addTail(inout float d, inout float seam, vec3 p, vec3 a, vec3 b, float ra, float rb, float k) {
vec3 pa = p - a, ba = b - a;
float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-6), 0.0, 1.0);
// Subtle wavy comic curl
vec3 q = pa - ba * h;
float r = mix(ra, rb, h);
float dp = length(q) - r;
float diff = abs(d - dp);
float nearBoth = smoothstep(0.12, 0.0, max(d, dp) - 0.02);
seam = max(seam, smoothstep(0.07, 0.01, diff) * nearBoth);
d = smin(d, dp, k);
}
vec2 mapSmoke(vec3 p, AnimState anim) {
// Early vertical bound check
if (p.y > 2.2 || p.y < -0.5) {
return vec2(max(p.y - 2.0, -0.35 - p.y) + 0.4, 0.0);
}
float d = 1e5;
float seam = 0.0;
float sc = anim.blastScale;
float drift = 0.06 * sin(TAU * anim.phase);
float drift2 = 0.05 * cos(TAU * anim.phase);
// Subtle chunky stylization warp so puffs feel hand-sculpted
vec3 pw = p;
pw.x += 0.04 * sin(p.z * 2.5 + TAU * anim.phase);
pw.z += 0.04 * cos(p.x * 2.5 - TAU * anim.phase);
// ------------------------------------------------------------------------
// 1. INNER BILLOWING SMOKE RING (hugging the outer shockwave perimeter)
// ------------------------------------------------------------------------
float ringR = 1.48 * sc;
// Back-left inner cluster (around angle 2.25 rad)
vec3 bl = vec3(-1.18 * sc, 0.24, -0.78 * sc);
addPuff(d, seam, pw, bl + vec3(0.0, 0.05 + drift * 0.4, 0.0), 0.44 * sc, 0.14);
addPuff(d, seam, pw, bl + vec3(-0.34 * sc, -0.02, 0.24 * sc), 0.34 * sc, 0.12);
addPuff(d, seam, pw, bl + vec3(0.36 * sc, -0.04, -0.18 * sc), 0.30 * sc, 0.12);
// Back-right inner cluster
vec3 br = vec3(1.12 * sc, 0.22, -0.76 * sc);
addPuff(d, seam, pw, br + vec3(0.0, 0.04 - drift * 0.4, 0.0), 0.40 * sc, 0.14);
addPuff(d, seam, pw, br + vec3(0.32 * sc, -0.04, 0.22 * sc), 0.30 * sc, 0.12);
addPuff(d, seam, pw, br + vec3(-0.32 * sc, -0.06, -0.16 * sc), 0.26 * sc, 0.12);
// Front-bottom low billowing rim puffs (under the front of the shockwave ring)
addPuff(d, seam, pw, vec3(-0.55 * sc, 0.10, 1.22 * sc), 0.32 * sc, 0.13);
addPuff(d, seam, pw, vec3( 0.04 * sc, 0.08, 1.32 * sc), 0.34 * sc, 0.13);
addPuff(d, seam, pw, vec3( 0.62 * sc, 0.11, 1.18 * sc), 0.31 * sc, 0.13);
addPuff(d, seam, pw, vec3(-1.05 * sc, 0.12, 0.88 * sc), 0.29 * sc, 0.12);
addPuff(d, seam, pw, vec3( 1.05 * sc, 0.12, 0.84 * sc), 0.28 * sc, 0.12);
// ------------------------------------------------------------------------
// 2. HERO FOREGROUND LEFT SWIRLING CLOUD (matches 08.png bottom-left)
// ------------------------------------------------------------------------
vec3 flBase = vec3(-2.35 - 0.25 * anim.openAmt, 0.46, 0.92 + drift2);
addPuff(d, seam, pw, flBase + vec3(-0.22, 0.16, -0.12), 0.66, 0.18);
addPuff(d, seam, pw, flBase + vec3( 0.28, -0.05, 0.14), 0.50, 0.16);
addPuff(d, seam, pw, flBase + vec3( 0.68, -0.18, -0.12), 0.36, 0.14);
addPuff(d, seam, pw, flBase + vec3( 0.52, -0.16, 0.48), 0.38, 0.15);
addTail(d, seam, pw, flBase + vec3(0.58, -0.24, 0.55), flBase + vec3(1.38, -0.34, 1.08), 0.26, 0.04, 0.12);
// ------------------------------------------------------------------------
// 3. HERO MID-RIGHT BILLOWING CLOUD (matches 08.png right edge)
// ------------------------------------------------------------------------
vec3 mrBase = vec3(2.58 + 0.20 * anim.openAmt, 0.44, 0.15 - drift2);
addPuff(d, seam, pw, mrBase + vec3( 0.25, 0.18, -0.06), 0.62, 0.18);
addPuff(d, seam, pw, mrBase + vec3(-0.26, -0.04, 0.16), 0.42, 0.15);
addTail(d, seam, pw, mrBase + vec3(-0.38, -0.16, 0.16), mrBase + vec3(-1.05, -0.26, 0.18), 0.24, 0.04, 0.12);
// ------------------------------------------------------------------------
// 4. HERO UPPER-RIGHT SWIRLING CLOUD (matches 08.png top-right)
// ------------------------------------------------------------------------
vec3 urBase = vec3(2.45 + 0.18 * anim.openAmt, 0.58, -1.85 + drift);
addPuff(d, seam, pw, urBase + vec3( 0.30, 0.26, -0.18), 0.72, 0.20);
addPuff(d, seam, pw, urBase + vec3(-0.28, 0.02, 0.14), 0.48, 0.16);
addPuff(d, seam, pw, urBase + vec3( 0.15, -0.08, 0.32), 0.42, 0.15);
addTail(d, seam, pw, urBase + vec3(-0.48, -0.18, 0.22), urBase + vec3(-1.35, -0.36, 0.34), 0.22, 0.035, 0.12);
// Flatten slightly underneath so clouds sit firmly on the arena floor
d = max(d, -p.y + 0.02);
return vec2(d, clamp(seam, 0.0, 1.0));
}
float mapSmokeDist(vec3 p, AnimState anim) {
return mapSmoke(p, anim).x;
}
vec3 calcSmokeNormal(vec3 p, AnimState anim) {
const vec2 e = vec2(0.004, -0.004);
vec3 n = e.xyy * mapSmokeDist(p + e.xyy, anim)
+ e.yyx * mapSmokeDist(p + e.yyx, anim)
+ e.yxy * mapSmokeDist(p + e.yxy, anim)
+ e.xxx * mapSmokeDist(p + e.xxx, anim);
return normalize(n + vec3(1e-6));
}
// ----------------------------------------------------------------------------
// Ground Shockwave Rings, Starburst Spikes, Epicenter Flash & Surface Bolts
// Evaluated cleanly on the arena floor plane (xz)
// ----------------------------------------------------------------------------
struct BlastGround {
vec3 emissive; // blazing magenta/white emissive energy
float alpha; // opaque coverage of crisp comic energy shapes
float inkMask; // dark ink outline around rings/spikes
float floorGlow; // cel-banded magenta bounce light on floor
};
BlastGround evalGroundBlast(vec2 xz, AnimState anim) {
BlastGround res;
res.emissive = vec3(0.0);
res.alpha = 0.0;
res.inkMask = 0.0;
res.floorGlow = 0.0;
float sc = anim.blastScale;
vec2 p = xz / max(sc, 0.15);
float r = length(p);
float ang = atan(p.y, p.x);
// Smooth outward-travelling wave phase inside the 3s loop
float wavePhase = anim.phase;
// ------------------------------------------------------------------------
// 1. Concentric Hot-Pink & White Shockwave Rings
// ------------------------------------------------------------------------
// 4 crisp rings matching 08.png: innermost, mid-inner, mid-outer, thick outer
float r1 = 0.56 + 0.03 * sin(TAU * wavePhase);
float r2 = 0.88 + 0.035 * sin(TAU * wavePhase - 0.9);
float r3 = 1.18 + 0.03 * sin(TAU * wavePhase - 1.8);
float r4 = 1.38 + 0.025 * sin(TAU * wavePhase - 2.6);
// Slight organic comic wobble on rings
float ringWob = 0.012 * sin(ang * 7.0 + TAU * wavePhase) + 0.008 * cos(ang * 13.0);
float d1 = abs(r - r1 + ringWob * 0.6);
float d2 = abs(r - r2 - ringWob * 0.8);
float d3 = abs(r - r3 + ringWob * 0.7);
float d4 = abs(r - r4 - ringWob * 0.5);
// Ring thicknesses (outer ring is thickest & boldest, inner rings crisp)
float ringCore = 0.0;
ringCore = max(ringCore, 1.0 - smoothstep(0.018, 0.030, d1));
ringCore = max(ringCore, 1.0 - smoothstep(0.024, 0.038, d2));
ringCore = max(ringCore, 1.0 - smoothstep(0.016, 0.028, d3));
ringCore = max(ringCore, 1.0 - smoothstep(0.044, 0.062, d4));
// Hot magenta aura immediately framing each white ring
float ringGlow = 0.0;
ringGlow = max(ringGlow, 1.0 - smoothstep(0.026, 0.085, d1));
ringGlow = max(ringGlow, 1.0 - smoothstep(0.034, 0.105, d2));
ringGlow = max(ringGlow, 1.0 - smoothstep(0.024, 0.075, d3));
ringGlow = max(ringGlow, 1.0 - smoothstep(0.056, 0.155, d4));
// Travelling pulse wave sweeping radially outward from center to outer ring
float pulseR = mix(0.25, 1.50, fract(wavePhase * 2.0));
float pulseBand = exp(-pow((r - pulseR) * 5.0, 2.0)) * smoothstep(1.58, 1.28, r);
// Dark ink outer edge right outside the outermost ring (comic grounding)
float outerInk = smoothstep(0.11, 0.06, abs(r - (r4 + 0.095)));
// ------------------------------------------------------------------------
// 2. Jagged Starburst Radial Spikes (10 iconic lance/arrow spikes!)
// ------------------------------------------------------------------------
float spikeCore = 0.0;
float spikeGlow = 0.0;
float spikeInk = 0.0;
const int NUM_SPIKES = 10;
for (int i = 0; i < NUM_SPIKES; i++) {
float fi = float(i);
// Uneven comic spacing so it feels hand-drawn, not robotic
float baseAng = fi * (TAU / float(NUM_SPIKES)) + 0.18 * sin(fi * 2.7) + 0.16;
float ca = cos(baseAng), sa = sin(baseAng);
// Local coordinates along spike axis (lx = outward, ly = perpendicular)
float lx = p.x * ca + p.y * sa;
float ly = -p.x * sa + p.y * ca;
// Alternating long dramatic spikes and medium spikes
float spikeLen = mix(1.88, 2.38, hash11(fi * 7.31 + 1.2));
// Make front-pointing spike extra dramatic (matches 08.png bottom center)
if (i == 2) spikeLen = 2.52;
spikeLen += 0.08 * sin(TAU * wavePhase + fi * 1.7);
float startR = 1.18;
float t = (lx - startR) / max(spikeLen - startR, 0.1);
if (t > -0.08 && t < 1.08) {
// Arrow/lance profile: flares out slightly near base with a comic notch, tapers to razor tip
float tClamped = clamp(t, 0.0, 1.0);
float baseW = mix(0.115, 0.155, hash11(fi * 3.1 + 4.0));
float notch = 1.0 - 0.35 * exp(-pow((tClamped - 0.14) * 14.0, 2.0));
float halfW = baseW * pow(max(1.0 - tClamped, 0.0), 1.15) * notch;
// Taper smoothly at the inner root
halfW *= smoothstep(-0.06, 0.08, t);
float dSpike = abs(ly) - halfW;
// Sharp outer tip cutoff
float tipMask = smoothstep(1.03, 0.96, t) * smoothstep(-0.06, 0.04, t);
float scMask = (1.0 - smoothstep(-0.012, 0.008, dSpike)) * tipMask;
float sgMask = (1.0 - smoothstep(0.005, 0.068, dSpike)) * tipMask;
float siMask = smoothstep(0.075, 0.035, abs(dSpike - 0.045)) * smoothstep(0.02, 0.15, t) * tipMask;
spikeCore = max(spikeCore, scMask);
spikeGlow = max(spikeGlow, sgMask);
spikeInk = max(spikeInk, siMask * 0.75);
}
}
// Secondary tiny razor needles between main spikes
for (int i = 0; i < 8; i++) {
float fi = float(i);
float baseAng = (fi + 0.5) * (TAU / 8.0) + 0.25 * cos(fi * 4.1);
float ca = cos(baseAng), sa = sin(baseAng);
float lx = p.x * ca + p.y * sa;
float ly = -p.x * sa + p.y * ca;
float t = (lx - 1.32) / 0.42;
if (t > 0.0 && t < 1.0) {
float halfW = 0.035 * (1.0 - t);
float dMini = abs(ly) - halfW;
spikeCore = max(spikeCore, 1.0 - smoothstep(-0.004, 0.008, dMini));
spikeGlow = max(spikeGlow, 1.0 - smoothstep(0.004, 0.035, dMini));
}
}
// ------------------------------------------------------------------------
// 3. Central Jagged Comic Starburst Flash at the Epicenter
// ------------------------------------------------------------------------
float starRays = 0.28
+ 0.22 * pow(0.5 + 0.5 * sin(ang * 9.0 + 0.4), 3.0)
+ 0.18 * pow(0.5 + 0.5 * sin(ang * 15.0 - 1.2 + TAU * wavePhase * 0.0), 4.0)
+ 0.10 * sin(ang * 5.0 + 2.1);
starRays *= (0.94 + 0.10 * anim.pulse);
float dStar = r - starRays;
float centerCore = 1.0 - smoothstep(-0.03, 0.02, dStar);
float centerGlow = 1.0 - smoothstep(0.01, 0.19, dStar);
// ------------------------------------------------------------------------
// 4. Radial Ground Lightning Tendrils crawling from center out to spikes
// ------------------------------------------------------------------------
float boltCore = 0.0;
float boltGlow = 0.0;
const int NUM_BOLTS = 6;
for (int i = 0; i < NUM_BOLTS; i++) {
float fi = float(i);
float bAng = fi * (TAU / float(NUM_BOLTS)) + 0.35 + 0.22 * sin(fi * 3.7);
float ca = cos(bAng), sa = sin(bAng);
float lx = p.x * ca + p.y * sa;
float ly = -p.x * sa + p.y * ca;
if (lx > 0.12 && lx < 1.85) {
// Sharp zig-zag polyline offset
float segPos = lx * 4.2;
float segIdx = floor(segPos);
float segF = fract(segPos);
float j0 = (hash11(segIdx * 13.7 + fi * 41.3 + anim.boltJitter * 0.17) - 0.5) * 0.26;
float j1 = (hash11((segIdx + 1.0) * 13.7 + fi * 41.3 + anim.boltJitter * 0.17) - 0.5) * 0.26;
float zigY = mix(j0, j1, segF) * smoothstep(0.12, 0.45, lx) * smoothstep(1.85, 1.45, lx);
float dBolt = abs(ly - zigY);
float thick = mix(0.024, 0.008, lx / 1.85);
boltCore = max(boltCore, 1.0 - smoothstep(thick * 0.5, thick * 1.4, dBolt));
boltGlow = max(boltGlow, 1.0 - smoothstep(thick, thick * 4.5, dBolt));
}
}
// ------------------------------------------------------------------------
// 5. Detached Flying Comic Spark Dashes around outer perimeter
// ------------------------------------------------------------------------
float sparkMask = 0.0;
for (int i = 0; i < 8; i++) {
float fi = float(i);
float sAng = fi * (TAU / 8.0) + 0.65;
float ca = cos(sAng), sa = sin(sAng);
float lx = p.x * ca + p.y * sa;
float ly = -p.x * sa + p.y * ca;
float travel = fract(wavePhase + hash11(fi * 5.9));
float sr = mix(1.52, 2.15, travel);
vec2 sd = segDist2D(vec2(lx, ly), vec2(sr, 0.0), vec2(sr + 0.18, 0.0));
float fade = smoothstep(0.0, 0.15, travel) * smoothstep(1.0, 0.65, travel);
sparkMask = max(sparkMask, (1.0 - smoothstep(0.008, 0.022, sd.x)) * fade);
}
// Combine crisp cel layers
float totalCore = clamp(max(max(ringCore, spikeCore), max(centerCore, max(boltCore, sparkMask))), 0.0, 1.0);
float totalGlow = clamp(max(max(ringGlow, spikeGlow), max(centerGlow, boltGlow)), 0.0, 1.0);
// Stylized 2-tier energy color: hot neon magenta halo + blazing white-pink core
vec3 glowCol = mix(COL_MAGENTA_DEEP, COL_MAGENTA_HOT, smoothstep(0.15, 0.65, totalGlow));
glowCol = mix(glowCol, COL_MAGENTA_NEON, smoothstep(0.55, 0.92, totalGlow));
vec3 coreCol = mix(glowCol, COL_WHITE_CORE, smoothstep(0.25, 0.72, totalCore));
// Boost brightness cleanly (will be soft-tonemapped below 1.0 clip)
float energyBoost = 1.35 + 0.25 * pulseBand + 0.20 * centerCore;
res.emissive = coreCol * energyBoost * max(totalGlow, totalCore);
res.alpha = clamp(max(totalCore, totalGlow * 0.92), 0.0, 1.0);
res.inkMask = clamp(max(outerInk, spikeInk) * (1.0 - totalGlow * 0.85), 0.0, 1.0);
// Quantized cel-banded floor illumination from the plasma blast
float rawGlow = exp(-r * 0.78) * 1.15 + 0.35 * exp(-abs(r - r4) * 2.4);
float qGlow = floor(clamp(rawGlow, 0.0, 1.0) * 3.5) / 3.5;
res.floorGlow = mix(rawGlow, qGlow, 0.65);
return res;
}
// ----------------------------------------------------------------------------
// 3D Vertical Zig-Zag Magenta-White Lightning Strike + Secondary Forks
// ----------------------------------------------------------------------------
vec4 evalVerticalLightning(vec3 ro, vec3 rd, float maxT, AnimState anim) {
// 6-vertex dramatic zig-zag bolt from y = 0.04 up to y = 2.75
// Matches the iconic jagged S-curve spear silhouette in 08.png
float j = anim.boltJitter;
float sway = 0.06 * sin(TAU * anim.phase);
float flick1 = (hash11(j * 3.7 + 1.1) - 0.5) * 0.08;
float flick2 = (hash11(j * 5.3 + 2.7) - 0.5) * 0.08;
float flick3 = (hash11(j * 7.1 + 4.3) - 0.5) * 0.06;
vec3 pts[6];
pts[0] = vec3( 0.00, 0.02, 0.00);
pts[1] = vec3( 0.07 + sway + flick1, 0.52, -0.04);
pts[2] = vec3(-0.08 - sway + flick2, 1.04, 0.05);
pts[3] = vec3( 0.16 + sway + flick3, 1.56, -0.05);
pts[4] = vec3(-0.09 + flick1 * 0.7, 2.12, 0.03);
pts[5] = vec3( 0.02, 2.82, 0.00);
float coreMask = 0.0;
float glowMask = 0.0;
float hitT = maxT;
// Main vertical bolt segments
for (int i = 0; i < 5; i++) {
vec3 dInfo = raySegDist(ro, rd, pts[i], pts[i + 1]);
float dist = dInfo.x;
float segT = dInfo.y;
float rayT = dInfo.z;
if (rayT < maxT && rayT > 0.05) {
float hFrac = (float(i) + segT) / 5.0;
// Thickest at impact base, tapering to a needle spear at the top
float baseRad = mix(0.085, 0.008, pow(hFrac, 0.85));
// Slight flare at sharp elbow bends
float elbow = 1.0 + 0.25 * exp(-pow((segT - 0.5) * 4.0, 2.0)) * (1.0 - hFrac);
float rad = baseRad * elbow;
float c = 1.0 - smoothstep(rad * 0.55, rad * 1.15, dist);
float g = 1.0 - smoothstep(rad * 1.05, rad * 3.20, dist);
if (g > glowMask) hitT = min(hitT, rayT);
coreMask = max(coreMask, c);
glowMask = max(glowMask, g);
}
}
// Secondary forked electric crackles branching off the main bolt
vec3 f1a = pts[1];
vec3 f1b = pts[1] + vec3(0.24, 0.38, 0.08);
vec3 f1c = f1b + vec3(-0.06, 0.34, -0.05);
vec3 f2a = pts[2];
vec3 f2b = pts[2] + vec3(-0.26, 0.34, -0.06);
vec3 f2c = f2b + vec3(-0.10, 0.36, 0.08);
vec3 f3a = pts[3];
vec3 f3b = pts[3] + vec3(-0.22, -0.26, 0.06);
vec3 forksA[5];
vec3 forksB[5];
forksA[0] = f1a; forksB[0] = f1b;
forksA[1] = f1b; forksB[1] = f1c;
forksA[2] = f2a; forksB[2] = f2b;
forksA[3] = f2b; forksB[3] = f2c;
forksA[4] = f3a; forksB[4] = f3b;
for (int i = 0; i < 5; i++) {
vec3 dInfo = raySegDist(ro, rd, forksA[i], forksB[i]);
if (dInfo.z < maxT && dInfo.z > 0.05) {
float rad = mix(0.016, 0.004, dInfo.y);
coreMask = max(coreMask, 1.0 - smoothstep(rad * 0.5, rad * 1.2, dInfo.x));
glowMask = max(glowMask, 1.0 - smoothstep(rad, rad * 3.8, dInfo.x));
}
}
// Floating vertical pink spark shards around the bolt (just like 08.png)
for (int i = 0; i < 6; i++) {
float fi = float(i);
float a = fi * 1.15 + 0.4;
float radR = mix(0.32, 0.58, hash11(fi * 9.3 + 1.0));
float rise = fract(anim.phase + hash11(fi * 4.7));
float y0 = mix(0.55, 2.05, rise);
vec3 sa = vec3(cos(a) * radR, y0, sin(a) * radR * 0.55);
vec3 sb = sa + vec3(cos(a) * 0.05, 0.22, sin(a) * 0.03);
vec3 dInfo = raySegDist(ro, rd, sa, sb);
if (dInfo.z < maxT && dInfo.z > 0.05) {
float fade = smoothstep(0.0, 0.15, rise) * smoothstep(1.0, 0.7, rise);
float sc = (1.0 - smoothstep(0.006, 0.015, dInfo.x)) * fade;
float sg = (1.0 - smoothstep(0.012, 0.045, dInfo.x)) * fade;
coreMask = max(coreMask, sc);
glowMask = max(glowMask, sg);
}
}
vec3 boltCol = mix(COL_MAGENTA_HOT * 1.35, COL_MAGENTA_NEON * 1.55, smoothstep(0.25, 0.8, glowMask));
boltCol = mix(boltCol, COL_WHITE_CORE * 1.75, smoothstep(0.18, 0.72, coreMask));
float alpha = clamp(max(coreMask, glowMask * 0.95), 0.0, 1.0);
return vec4(boltCol * alpha, alpha);
}
// ----------------------------------------------------------------------------
// Dark Ink-Grouted Charcoal Tiled Arena Floor Shading
// ----------------------------------------------------------------------------
vec3 shadeArenaFloor(vec3 p, vec3 rd, AnimState anim, vec3 lightDir) {
// Rotate tile grid slightly for dynamic diagonal comic composition (matches 08.png)
vec2 gPos = rot2(0.32) * p.xz;
vec2 tileScale = vec2(1.45, 1.45);
vec2 cellId = floor(gPos / tileScale);
vec2 cellUv = fract(gPos / tileScale) - 0.5;
// Distance to grout lines (bold dark comic ink seams)
vec2 edgeDist = 0.5 - abs(cellUv);
float minEdge = min(edgeDist.x, edgeDist.y);
float groutWidth = 0.022;
float groutInk = 1.0 - smoothstep(groutWidth * 0.75, groutWidth * 1.35, minEdge);
// Subtle secondary bevel highlight next to grout lines
float bevelEdge = smoothstep(groutWidth * 1.2, groutWidth * 2.2, minEdge)
* (1.0 - smoothstep(groutWidth * 2.2, groutWidth * 4.0, minEdge));
// Per-tile tonal variation + subtle quantized comic concrete grunge
float tileVar = (hash21(cellId) - 0.5) * 0.022;
float grunge = fbm2(gPos * 3.8);
float grungeQ = floor(grunge * 3.0) / 3.0;
vec3 floorCol = COL_FLOOR_BASE + vec3(tileVar) + (grungeQ - 0.5) * vec3(0.018, 0.019, 0.024);
floorCol += bevelEdge * vec3(0.025, 0.028, 0.038);
// Circular outer arena rim + hot-magenta trim panels (seen at top of 08.png)
float arenaR = length(p.xz);
float rimInner = 4.35;
float rimOuter = 4.75;
if (arenaR > rimInner - 0.15) {
float rimBand = smoothstep(rimInner - 0.04, rimInner + 0.02, arenaR)
* (1.0 - smoothstep(rimOuter - 0.02, rimOuter + 0.04, arenaR));
float rimAng = atan(p.z, p.x);
float panelSeg = fract(rimAng * 12.0 / TAU);
float panelSeam = 1.0 - smoothstep(0.03, 0.06, min(panelSeg, 1.0 - panelSeg));
float litPanel = step(0.18, hash11(floor(rimAng * 12.0 / TAU) * 7.3 + 2.0));
vec3 rimCol = mix(vec3(0.11, 0.12, 0.16), COL_ARENA_TRIM * 0.85, litPanel);
rimCol = mix(rimCol, COL_INK, panelSeam * 0.9);
floorCol = mix(floorCol, rimCol, rimBand);
// Bold ink borders on the arena curb
float curbInk = (1.0 - smoothstep(0.02, 0.05, abs(arenaR - rimInner)))
+ (1.0 - smoothstep(0.02, 0.05, abs(arenaR - rimOuter)));
floorCol = mix(floorCol, COL_INK, clamp(curbInk, 0.0, 1.0));
// Darker matte outer arena void beyond the curb
float beyond = smoothstep(rimOuter, rimOuter + 0.15, arenaR);
floorCol = mix(floorCol, COL_FLOOR_DARK, beyond);
}
// Apply bold ink grout lines inside the arena
float insideArena = 1.0 - smoothstep(rimInner - 0.05, rimInner + 0.02, arenaR);
floorCol = mix(floorCol, COL_INK, groutInk * insideArena * 0.92);
// LightMode directional tint on floor
if (uLightMode == 2) {
floorCol *= vec3(0.92, 1.00, 1.18);
}
// Crisp hard-edged comic drop shadow cast by the smoke clouds onto the floor
vec3 shPos = p + vec3(lightDir.x * 0.18, 0.18, lightDir.z * 0.18);
float dSmoke = mapSmokeDist(shPos, anim);
float dropShadow = 1.0 - smoothstep(0.02, 0.16, dSmoke);
floorCol = mix(floorCol, COL_INK * 1.15, dropShadow * 0.78);
// Evaluate the neon magenta plasma blast on the floor
BlastGround blast = evalGroundBlast(p.xz, anim);
float emitScale = (uLightMode == 1) ? 0.38 : 1.0;
// Add cel-banded neon magenta bounce light onto the charcoal tiles
vec3 bounceCol = mix(COL_MAGENTA_DEEP, COL_MAGENTA_HOT, 0.6) * blast.floorGlow * 0.42 * emitScale;
// Slight magenta rim glow in the grout lines near the explosion!
float neonGrout = groutInk * insideArena * smoothstep(2.6, 1.2, arenaR) * 0.55 * emitScale;
floorCol += bounceCol * (1.0 - dropShadow * 0.5) + COL_MAGENTA_HOT * neonGrout * 0.35;
// Apply dark comic ink edge around rings/spikes
floorCol = mix(floorCol, COL_INK, blast.inkMask * 0.85);
// Composite crisp blazing shockwave rings, spikes, and ground bolts
floorCol = mix(floorCol, blast.emissive * mix(0.55, 1.0, emitScale), blast.alpha);
// Atmospheric depth fade into dark charcoal-violet arena wall at far distance
float distFade = smoothstep(5.5, 12.5, length(p.xz));
vec3 farBg = vec3(0.042, 0.040, 0.062);
floorCol = mix(floorCol, farBg, distFade);
return floorCol;
}
// ----------------------------------------------------------------------------
// Cel-Shaded 3-Band Stylized Violet Smoke Shading with Ink Contours
// ----------------------------------------------------------------------------
vec3 shadeSmoke(vec3 p, vec3 N, vec3 V, float crease, AnimState anim, vec3 keyDir) {
// 1. Primary light from overhead key + strong magenta light from epicenter (0, 0.35, 0)
vec3 toCenter = vec3(0.0, 0.35, 0.0) - p;
float distCenter = length(toCenter);
vec3 blastDir = toCenter / max(distCenter, 1e-5);
float ndlKey = dot(N, keyDir);
float ndlBlast = dot(N, blastDir);
float blastAtten = 1.0 / (1.0 + 0.18 * distCenter * distCenter);
// Combine lighting scalar for 3-band quantized cel shading
float lit = ndlKey * 0.55 + ndlBlast * blastAtten * 0.85 + 0.25;
// Quantize into 3 crisp stylized comic bands (Shadow -> Mid -> Lit)
float band1 = smoothstep(0.14, 0.18, lit);
float band2 = smoothstep(0.54, 0.59, lit);
vec3 col = mix(COL_SMOKE_SHAD, COL_SMOKE_MID, band1);
col = mix(col, COL_SMOKE_LIT, band2);
// LightMode adjustments
if (uLightMode == 2) {
col = mix(col, col * vec3(0.84, 0.96, 1.22), 0.7);
}
// Hot-magenta rim highlight on puff edges facing the plasma epicenter
float ndv = clamp(dot(N, V), 0.0, 1.0);
float fresnel = 1.0 - ndv;
float rimScale = (uLightMode == 1) ? 0.25 : 0.85;
float blastRim = smoothstep(0.45, 0.75, fresnel) * smoothstep(0.05, 0.45, ndlBlast) * blastAtten;
col = mix(col, COL_SMOKE_RIM * 1.15, clamp(blastRim * rimScale, 0.0, 0.85));
// Bold black-ink Fresnel contour + internal lobe crease lines
float inkFresnel = smoothstep(0.27, 0.17, ndv);
float inkCrease = smoothstep(0.42, 0.72, crease) * 0.92;
float inkMask = clamp(max(inkFresnel, inkCrease), 0.0, 1.0);
col = mix(col, COL_INK, inkMask);
return col;
}
// ----------------------------------------------------------------------------
// Camera Setup (4 uCamMode presets)
// ----------------------------------------------------------------------------
void setupCamera(out vec3 ro, out vec3 ta, out float fl, AnimState anim) {
if (uCamMode == 1) {
// Low dramatic heroic angle looking across the shockwave rings up at the strike
ro = vec3(0.45, 1.42, 3.95);
ta = vec3(0.00, 0.62, 0.00);
fl = 1.45;
} else if (uCamMode == 2) {
// High tactical top-down view showing full concentric starburst & smoke ring
ro = vec3(0.00, 5.10, 1.55);
ta = vec3(0.00, 0.05, 0.10);
fl = 1.60;
} else if (uCamMode == 3) {
// Smooth 3-second orbital showcase
float a = TAU * anim.phase * 0.5 - 0.35;
ro = vec3(sin(a) * 3.85, 2.75, cos(a) * 3.85);
ta = vec3(0.00, 0.38, 0.00);
fl = 1.55;
} else {
// Default Hero 3/4 Elevated Arena View (matches 08.png composition)
ro = vec3(0.00, 3.12, 3.62);
ta = vec3(0.00, 0.34, 0.05);
fl = 1.56;
}
}
// ----------------------------------------------------------------------------
// Stylized Filmic Tone Mapping (punchy neon saturation, <1% clip, <2% black)
// ----------------------------------------------------------------------------
vec3 stylizedTonemap(vec3 c) {
// Soft shoulder curve that preserves vibrant magenta/violet hue and prevents clipping
c = max(c, vec3(0.0));
if (uLightMode == 1) {
float lum = dot(c, vec3(0.2126, 0.7152, 0.0722));
c = vec3(lum);
}
vec3 mapped = (c * (2.51 * c + 0.03)) / (c * (2.43 * c + 0.59) + 0.14);
// Keep peak safely under 0.975 so <1% clip is guaranteed even at white-hot core
mapped = mapped * 0.965;
// Gamma encode to sRGB
vec3 srgb = pow(clamp(mapped, 0.0, 0.98), vec3(1.0 / 2.2));
// Subtle dark ink floor lift so deep ink reads crisp jet-black without pure-black crush
vec3 inkFloor = (uLightMode == 1) ? vec3(0.036) : vec3(0.032, 0.030, 0.044);
srgb = max(srgb, inkFloor);
if (uLightMode == 1) {
srgb = vec3(dot(srgb, vec3(0.2126, 0.7152, 0.0722)));
}
return clamp(srgb, 0.0, 0.985);
}
// ----------------------------------------------------------------------------
// Main
// ----------------------------------------------------------------------------
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 res = max(uResolution, vec2(1.0));
vec2 uv = (pfx_frag_xy - 0.5 * res) / min(res.x, res.y);
AnimState anim = getAnim();
vec3 ro, ta;
float fl;
setupCamera(ro, ta, fl, anim);
vec3 ww = normalize(ta - ro);
vec3 uu = normalize(cross(ww, vec3(0.0, 1.0, 0.0)));
vec3 vv = cross(uu, ww);
vec3 rd = normalize(uv.x * uu + uv.y * vv + fl * ww);
// Key light direction by uLightMode
vec3 keyDir = normalize(vec3(-0.35, 0.85, 0.40));
if (uLightMode == 1) {
keyDir = normalize(vec3(0.45, 0.78, 0.42));
} else if (uLightMode == 2) {
keyDir = normalize(vec3(-0.62, 0.65, -0.44));
}
// 1. Background sky / upper arena wall gradient (dark matte charcoal-indigo)
float skyGrad = clamp(rd.y * 1.5 + 0.35, 0.0, 1.0);
vec3 col = mix(vec3(0.042, 0.040, 0.062), vec3(0.022, 0.020, 0.036), skyGrad);
// Subtle distant magenta atmospheric glow behind the vertical strike
float bgGlow = exp(-length(uv - vec2(0.0, 0.10)) * 2.2) * ((uLightMode == 1) ? 0.03 : 0.12);
col += COL_MAGENTA_DEEP * bgGlow;
// 2. Analytic intersection with the arena floor plane (y = 0)
float tFloor = 1e5;
if (rd.y < -1e-4) {
float tf = -ro.y / rd.y;
if (tf > 0.0 && tf < 30.0) {
tFloor = tf;
vec3 pFloor = ro + rd * tFloor;
col = shadeArenaFloor(pFloor, rd, anim, keyDir);
}
}
// 3. Raymarch 3D chunky ink-outlined violet smoke clouds
float tMax = min(tFloor, 14.0);
float t = 0.25;
bool hitSmoke = false;
vec3 pHit = vec3(0.0);
float hitCrease = 0.0;
float minRatio = 1e5;
float prevD = 1e5;
for (int i = 0; i < 68; i++) {
if (t > tMax) break;
vec3 p = ro + rd * t;
vec2 m = mapSmoke(p, anim);
float d = m.x;
// Track near-miss silhouette edge for crisp uniform comic ink outline
if (d > prevD && t > 0.5) {
minRatio = min(minRatio, prevD / t);
}
prevD = d;
if (d < 0.0035) {
hitSmoke = true;
pHit = p;
hitCrease = m.y;
break;
}
t += max(d * 0.85, 0.015);
}
float sceneDepth = tFloor;
if (hitSmoke) {
sceneDepth = t;
vec3 N = calcSmokeNormal(pHit, anim);
vec3 smokeCol = shadeSmoke(pHit, N, -rd, hitCrease, anim, keyDir);
// Allow inner shockwave ring glow to subtly kiss the lower edge of inner smoke
float edgeKiss = smoothstep(0.28, 0.02, pHit.y) * smoothstep(2.0, 1.2, length(pHit.xz));
smokeCol += COL_MAGENTA_HOT * edgeKiss * ((uLightMode == 1) ? 0.06 : 0.28);
col = smokeCol;
} else if (minRatio < 0.011) {
// Crisp outer black-ink comic silhouette halo around missed grazing smoke edges
float outlineMask = 1.0 - smoothstep(0.004, 0.011, minRatio);
col = mix(col, COL_INK, outlineMask * 0.90);
}
// 4. Composite 3D vertical zig-zag magenta-white lightning strike + forks + shards
vec4 bolt = evalVerticalLightning(ro, rd, sceneDepth + 0.35, anim);
float boltScale = (uLightMode == 1) ? 0.55 : 1.0;
vec3 boltRgb = bolt.rgb * boltScale;
col = mix(col, col + boltRgb, clamp(bolt.a, 0.0, 1.0));
// Ensure crisp opaque white core punches right over dark background & smoke
col = mix(col, boltRgb, smoothstep(0.65, 0.95, bolt.a));
// Subtle vignette to frame the arena blast without crushing corners
float vig = 1.0 - 0.18 * dot(uv, uv);
col *= clamp(vig, 0.72, 1.0);
fragColor = vec4(stylizedTonemap(col), 1.0);
}
void fragment() {
vec2 tiled_uv = fract(UV * u_tiling);
vec2 frag_xy = vec2(tiled_uv.x, 1.0 - tiled_uv.y) * uResolution;
vec4 study_col = vec4(0.0, 0.0, 0.0, 1.0);
pixelfx_study_eval(frag_xy, study_col);
vec3 tinted = clamp(mix(study_col.rgb, study_col.rgb * u_tint.rgb * 1.35, u_tint_mix), 0.0, 1.0);
float out_alpha = study_col.a * COLOR.a;
if (u_luma_alpha_key) {
float luma = dot(tinted, vec3(0.2126, 0.7152, 0.0722));
out_alpha *= smoothstep(0.035, 0.22, luma);
}
COLOR = vec4(tinted, out_alpha);
}
shader_type spatial;
render_mode unshaded, cull_disabled;
// Neon Magenta Plasma Grenade — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/vfx_stylized/lib/08_neon_magenta_plasma_grenade.glsl (MIT License)
// Drive uTime from GDScript if animating helper functions: material.set_shader_parameter("uTime", Time.get_ticks_msec() * 0.001 * u_speed)
uniform vec2 uResolution = vec2(1024.0, 1024.0);
uniform float uTime = 1.2;
uniform float u_speed : hint_range(0.0, 3.0, 0.05) = 1.0;
uniform float u_tiling : hint_range(0.25, 8.0, 0.25) = 1.0;
uniform vec4 u_tint : source_color = vec4(1.0, 0.722, 0.42, 1.0);
uniform float u_tint_mix : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform float uOpen : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform int uLightMode : hint_range(0, 3, 1) = 0;
uniform int uCamMode : hint_range(0, 1, 1) = 0;
uniform bool u_luma_alpha_key = false;
// ============================================================================
// 08_neon_magenta_plasma_grenade.glsl
// Punchy 3D NEON HOT-MAGENTA & ELECTRIC PURPLE stylized plasma grenade
// starburst explosion on a dark matte ink-grouted charcoal tiled arena floor.
//
// Features:
// - Dark charcoal ink-grouted tiled arena floor vec3(0.08, 0.09, 0.12)
// with circular arena trim, subtle cel grunge, and hard ink drop shadows
// - Crisp concentric hot-pink & white comic shockwave rings with jagged
// starburst radial spikes and crawling surface lightning tendrils
// - 3D vertical zig-zag magenta-white lightning strike hitting the epicenter
// with secondary forks and comic energy shards
// - Chunky 3D raymarched ink-outlined flat-shaded violet smoke clouds
// with 3-band quantized cel shading, Fresnel + silhouette ink contours,
// and internal comic crease lines
// - Seamless 3-second loop on uTime; uOpen (0..1) expands the starburst blast
// ============================================================================
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
// Palette (linear-friendly vibrant stylized colors)
const vec3 COL_FLOOR_BASE = vec3(0.08, 0.09, 0.12);
const vec3 COL_FLOOR_DARK = vec3(0.048, 0.052, 0.075);
const vec3 COL_INK = vec3(0.012, 0.010, 0.020);
const vec3 COL_ARENA_TRIM = vec3(0.68, 0.09, 0.36);
const vec3 COL_MAGENTA_HOT = vec3(1.00, 0.11, 0.62);
const vec3 COL_MAGENTA_NEON = vec3(1.00, 0.28, 0.78);
const vec3 COL_MAGENTA_DEEP = vec3(0.55, 0.04, 0.38);
const vec3 COL_WHITE_CORE = vec3(1.00, 0.94, 0.99);
const vec3 COL_SMOKE_LIT = vec3(0.62, 0.25, 0.96);
const vec3 COL_SMOKE_MID = vec3(0.36, 0.12, 0.72);
const vec3 COL_SMOKE_SHAD = vec3(0.17, 0.055, 0.40);
const vec3 COL_SMOKE_RIM = vec3(0.95, 0.32, 0.88);
// ----------------------------------------------------------------------------
// Math & Noise Utilities
// ----------------------------------------------------------------------------
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 hash31(vec3 p3) {
p3 = fract(p3 * 0.1031);
p3 += dot(p3, p3.zyx + 31.32);
return fract((p3.x + p3.y) * p3.z);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
return mix(mix(a, b, u.x), mix(c, d, 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(17.1, 31.7);
a *= 0.5;
}
return v;
}
float smin(float a, float b, float k) {
float h = max(k - abs(a - b), 0.0) / max(k, 1e-5);
return min(a, b) - h * h * k * 0.25;
}
// Distance from point p to 2D segment ab, returning vec2(dist, t)
vec2 segDist2D(vec2 p, vec2 a, vec2 b) {
vec2 pa = p - a;
vec2 ba = b - a;
float denom = max(dot(ba, ba), 1e-6);
float t = clamp(dot(pa, ba) / denom, 0.0, 1.0);
return vec2(length(pa - ba * t), t);
}
// Closest distance between a ray (ro, rd) and a 3D line segment (a, b)
// Returns vec3(minDist, segT, rayT)
vec3 raySegDist(vec3 ro, vec3 rd, vec3 a, vec3 b) {
vec3 u = rd;
vec3 v = b - a;
vec3 w = ro - a;
float aDot = dot(u, u); // 1.0
float bDot = dot(u, v);
float cDot = dot(v, v);
float dDot = dot(u, w);
float eDot = dot(v, w);
float D = aDot * cDot - bDot * bDot;
float sc, tc;
if (D < 1e-6) {
sc = 0.0;
tc = (bDot > cDot ? dDot / max(bDot, 1e-6) : eDot / max(cDot, 1e-6));
} else {
sc = (bDot * eDot - cDot * dDot) / D;
tc = (aDot * eDot - bDot * dDot) / D;
}
tc = clamp(tc, 0.0, 1.0);
// Recompute optimal ray parameter sc for clamped tc
sc = max(dot(a + v * tc - ro, u), 0.0);
vec3 pRay = ro + u * sc;
vec3 pSeg = a + v * tc;
return vec3(length(pRay - pSeg), tc, sc);
}
// ----------------------------------------------------------------------------
// Animation Parameters (3-second seamless loop + uOpen 0..1 blast expansion)
// ----------------------------------------------------------------------------
struct AnimState {
float phase; // 0..1 seamless 3s loop
float openAmt; // 0..1 uOpen
float blastScale; // overall radial expansion of rings & spikes
float pulse; // smooth rhythmic pulse
float boltJitter; // stepped comic frame seed for lightning snap
};
AnimState getAnim() {
AnimState a;
a.phase = loopPhase();
a.openAmt = clamp(uOpen, 0.0, 1.0);
float breathe = 0.035 * sin(TAU * a.phase);
a.blastScale = mix(0.58, 1.12, smoothstep(0.0, 1.0, a.openAmt)) + breathe;
a.pulse = 0.5 + 0.5 * sin(TAU * a.phase);
// Quantize lightning flicker to 12 comic frames per 3s loop (seamless!)
float frameIdx = floor(a.phase * 12.0);
a.boltJitter = frameIdx;
return a;
}
// ----------------------------------------------------------------------------
// 3D Stylized Chunky Violet Smoke Clouds SDF
// Returns vec2(sdf, creaseFactor)
// ----------------------------------------------------------------------------
// Helper to blend a puff and track lobe seam proximity for comic crease ink
void addPuff(inout float d, inout float seam, vec3 p, vec3 c, float r, float k) {
float dp = length(p - c) - r;
// Detect intersection crease between adjacent puffs
float diff = abs(d - dp);
float nearBoth = smoothstep(0.14, 0.0, max(d, dp) - 0.02);
float crease = smoothstep(0.09, 0.01, diff) * nearBoth;
seam = max(seam, crease);
d = smin(d, dp, k);
}
// Tapered swirling smoke tendril along a floor curve
void addTail(inout float d, inout float seam, vec3 p, vec3 a, vec3 b, float ra, float rb, float k) {
vec3 pa = p - a, ba = b - a;
float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-6), 0.0, 1.0);
// Subtle wavy comic curl
vec3 q = pa - ba * h;
float r = mix(ra, rb, h);
float dp = length(q) - r;
float diff = abs(d - dp);
float nearBoth = smoothstep(0.12, 0.0, max(d, dp) - 0.02);
seam = max(seam, smoothstep(0.07, 0.01, diff) * nearBoth);
d = smin(d, dp, k);
}
vec2 mapSmoke(vec3 p, AnimState anim) {
// Early vertical bound check
if (p.y > 2.2 || p.y < -0.5) {
return vec2(max(p.y - 2.0, -0.35 - p.y) + 0.4, 0.0);
}
float d = 1e5;
float seam = 0.0;
float sc = anim.blastScale;
float drift = 0.06 * sin(TAU * anim.phase);
float drift2 = 0.05 * cos(TAU * anim.phase);
// Subtle chunky stylization warp so puffs feel hand-sculpted
vec3 pw = p;
pw.x += 0.04 * sin(p.z * 2.5 + TAU * anim.phase);
pw.z += 0.04 * cos(p.x * 2.5 - TAU * anim.phase);
// ------------------------------------------------------------------------
// 1. INNER BILLOWING SMOKE RING (hugging the outer shockwave perimeter)
// ------------------------------------------------------------------------
float ringR = 1.48 * sc;
// Back-left inner cluster (around angle 2.25 rad)
vec3 bl = vec3(-1.18 * sc, 0.24, -0.78 * sc);
addPuff(d, seam, pw, bl + vec3(0.0, 0.05 + drift * 0.4, 0.0), 0.44 * sc, 0.14);
addPuff(d, seam, pw, bl + vec3(-0.34 * sc, -0.02, 0.24 * sc), 0.34 * sc, 0.12);
addPuff(d, seam, pw, bl + vec3(0.36 * sc, -0.04, -0.18 * sc), 0.30 * sc, 0.12);
// Back-right inner cluster
vec3 br = vec3(1.12 * sc, 0.22, -0.76 * sc);
addPuff(d, seam, pw, br + vec3(0.0, 0.04 - drift * 0.4, 0.0), 0.40 * sc, 0.14);
addPuff(d, seam, pw, br + vec3(0.32 * sc, -0.04, 0.22 * sc), 0.30 * sc, 0.12);
addPuff(d, seam, pw, br + vec3(-0.32 * sc, -0.06, -0.16 * sc), 0.26 * sc, 0.12);
// Front-bottom low billowing rim puffs (under the front of the shockwave ring)
addPuff(d, seam, pw, vec3(-0.55 * sc, 0.10, 1.22 * sc), 0.32 * sc, 0.13);
addPuff(d, seam, pw, vec3( 0.04 * sc, 0.08, 1.32 * sc), 0.34 * sc, 0.13);
addPuff(d, seam, pw, vec3( 0.62 * sc, 0.11, 1.18 * sc), 0.31 * sc, 0.13);
addPuff(d, seam, pw, vec3(-1.05 * sc, 0.12, 0.88 * sc), 0.29 * sc, 0.12);
addPuff(d, seam, pw, vec3( 1.05 * sc, 0.12, 0.84 * sc), 0.28 * sc, 0.12);
// ------------------------------------------------------------------------
// 2. HERO FOREGROUND LEFT SWIRLING CLOUD (matches 08.png bottom-left)
// ------------------------------------------------------------------------
vec3 flBase = vec3(-2.35 - 0.25 * anim.openAmt, 0.46, 0.92 + drift2);
addPuff(d, seam, pw, flBase + vec3(-0.22, 0.16, -0.12), 0.66, 0.18);
addPuff(d, seam, pw, flBase + vec3( 0.28, -0.05, 0.14), 0.50, 0.16);
addPuff(d, seam, pw, flBase + vec3( 0.68, -0.18, -0.12), 0.36, 0.14);
addPuff(d, seam, pw, flBase + vec3( 0.52, -0.16, 0.48), 0.38, 0.15);
addTail(d, seam, pw, flBase + vec3(0.58, -0.24, 0.55), flBase + vec3(1.38, -0.34, 1.08), 0.26, 0.04, 0.12);
// ------------------------------------------------------------------------
// 3. HERO MID-RIGHT BILLOWING CLOUD (matches 08.png right edge)
// ------------------------------------------------------------------------
vec3 mrBase = vec3(2.58 + 0.20 * anim.openAmt, 0.44, 0.15 - drift2);
addPuff(d, seam, pw, mrBase + vec3( 0.25, 0.18, -0.06), 0.62, 0.18);
addPuff(d, seam, pw, mrBase + vec3(-0.26, -0.04, 0.16), 0.42, 0.15);
addTail(d, seam, pw, mrBase + vec3(-0.38, -0.16, 0.16), mrBase + vec3(-1.05, -0.26, 0.18), 0.24, 0.04, 0.12);
// ------------------------------------------------------------------------
// 4. HERO UPPER-RIGHT SWIRLING CLOUD (matches 08.png top-right)
// ------------------------------------------------------------------------
vec3 urBase = vec3(2.45 + 0.18 * anim.openAmt, 0.58, -1.85 + drift);
addPuff(d, seam, pw, urBase + vec3( 0.30, 0.26, -0.18), 0.72, 0.20);
addPuff(d, seam, pw, urBase + vec3(-0.28, 0.02, 0.14), 0.48, 0.16);
addPuff(d, seam, pw, urBase + vec3( 0.15, -0.08, 0.32), 0.42, 0.15);
addTail(d, seam, pw, urBase + vec3(-0.48, -0.18, 0.22), urBase + vec3(-1.35, -0.36, 0.34), 0.22, 0.035, 0.12);
// Flatten slightly underneath so clouds sit firmly on the arena floor
d = max(d, -p.y + 0.02);
return vec2(d, clamp(seam, 0.0, 1.0));
}
float mapSmokeDist(vec3 p, AnimState anim) {
return mapSmoke(p, anim).x;
}
vec3 calcSmokeNormal(vec3 p, AnimState anim) {
const vec2 e = vec2(0.004, -0.004);
vec3 n = e.xyy * mapSmokeDist(p + e.xyy, anim)
+ e.yyx * mapSmokeDist(p + e.yyx, anim)
+ e.yxy * mapSmokeDist(p + e.yxy, anim)
+ e.xxx * mapSmokeDist(p + e.xxx, anim);
return normalize(n + vec3(1e-6));
}
// ----------------------------------------------------------------------------
// Ground Shockwave Rings, Starburst Spikes, Epicenter Flash & Surface Bolts
// Evaluated cleanly on the arena floor plane (xz)
// ----------------------------------------------------------------------------
struct BlastGround {
vec3 emissive; // blazing magenta/white emissive energy
float alpha; // opaque coverage of crisp comic energy shapes
float inkMask; // dark ink outline around rings/spikes
float floorGlow; // cel-banded magenta bounce light on floor
};
BlastGround evalGroundBlast(vec2 xz, AnimState anim) {
BlastGround res;
res.emissive = vec3(0.0);
res.alpha = 0.0;
res.inkMask = 0.0;
res.floorGlow = 0.0;
float sc = anim.blastScale;
vec2 p = xz / max(sc, 0.15);
float r = length(p);
float ang = atan(p.y, p.x);
// Smooth outward-travelling wave phase inside the 3s loop
float wavePhase = anim.phase;
// ------------------------------------------------------------------------
// 1. Concentric Hot-Pink & White Shockwave Rings
// ------------------------------------------------------------------------
// 4 crisp rings matching 08.png: innermost, mid-inner, mid-outer, thick outer
float r1 = 0.56 + 0.03 * sin(TAU * wavePhase);
float r2 = 0.88 + 0.035 * sin(TAU * wavePhase - 0.9);
float r3 = 1.18 + 0.03 * sin(TAU * wavePhase - 1.8);
float r4 = 1.38 + 0.025 * sin(TAU * wavePhase - 2.6);
// Slight organic comic wobble on rings
float ringWob = 0.012 * sin(ang * 7.0 + TAU * wavePhase) + 0.008 * cos(ang * 13.0);
float d1 = abs(r - r1 + ringWob * 0.6);
float d2 = abs(r - r2 - ringWob * 0.8);
float d3 = abs(r - r3 + ringWob * 0.7);
float d4 = abs(r - r4 - ringWob * 0.5);
// Ring thicknesses (outer ring is thickest & boldest, inner rings crisp)
float ringCore = 0.0;
ringCore = max(ringCore, 1.0 - smoothstep(0.018, 0.030, d1));
ringCore = max(ringCore, 1.0 - smoothstep(0.024, 0.038, d2));
ringCore = max(ringCore, 1.0 - smoothstep(0.016, 0.028, d3));
ringCore = max(ringCore, 1.0 - smoothstep(0.044, 0.062, d4));
// Hot magenta aura immediately framing each white ring
float ringGlow = 0.0;
ringGlow = max(ringGlow, 1.0 - smoothstep(0.026, 0.085, d1));
ringGlow = max(ringGlow, 1.0 - smoothstep(0.034, 0.105, d2));
ringGlow = max(ringGlow, 1.0 - smoothstep(0.024, 0.075, d3));
ringGlow = max(ringGlow, 1.0 - smoothstep(0.056, 0.155, d4));
// Travelling pulse wave sweeping radially outward from center to outer ring
float pulseR = mix(0.25, 1.50, fract(wavePhase * 2.0));
float pulseBand = exp(-pow((r - pulseR) * 5.0, 2.0)) * smoothstep(1.58, 1.28, r);
// Dark ink outer edge right outside the outermost ring (comic grounding)
float outerInk = smoothstep(0.11, 0.06, abs(r - (r4 + 0.095)));
// ------------------------------------------------------------------------
// 2. Jagged Starburst Radial Spikes (10 iconic lance/arrow spikes!)
// ------------------------------------------------------------------------
float spikeCore = 0.0;
float spikeGlow = 0.0;
float spikeInk = 0.0;
const int NUM_SPIKES = 10;
for (int i = 0; i < NUM_SPIKES; i++) {
float fi = float(i);
// Uneven comic spacing so it feels hand-drawn, not robotic
float baseAng = fi * (TAU / float(NUM_SPIKES)) + 0.18 * sin(fi * 2.7) + 0.16;
float ca = cos(baseAng), sa = sin(baseAng);
// Local coordinates along spike axis (lx = outward, ly = perpendicular)
float lx = p.x * ca + p.y * sa;
float ly = -p.x * sa + p.y * ca;
// Alternating long dramatic spikes and medium spikes
float spikeLen = mix(1.88, 2.38, hash11(fi * 7.31 + 1.2));
// Make front-pointing spike extra dramatic (matches 08.png bottom center)
if (i == 2) spikeLen = 2.52;
spikeLen += 0.08 * sin(TAU * wavePhase + fi * 1.7);
float startR = 1.18;
float t = (lx - startR) / max(spikeLen - startR, 0.1);
if (t > -0.08 && t < 1.08) {
// Arrow/lance profile: flares out slightly near base with a comic notch, tapers to razor tip
float tClamped = clamp(t, 0.0, 1.0);
float baseW = mix(0.115, 0.155, hash11(fi * 3.1 + 4.0));
float notch = 1.0 - 0.35 * exp(-pow((tClamped - 0.14) * 14.0, 2.0));
float halfW = baseW * pow(max(1.0 - tClamped, 0.0), 1.15) * notch;
// Taper smoothly at the inner root
halfW *= smoothstep(-0.06, 0.08, t);
float dSpike = abs(ly) - halfW;
// Sharp outer tip cutoff
float tipMask = smoothstep(1.03, 0.96, t) * smoothstep(-0.06, 0.04, t);
float scMask = (1.0 - smoothstep(-0.012, 0.008, dSpike)) * tipMask;
float sgMask = (1.0 - smoothstep(0.005, 0.068, dSpike)) * tipMask;
float siMask = smoothstep(0.075, 0.035, abs(dSpike - 0.045)) * smoothstep(0.02, 0.15, t) * tipMask;
spikeCore = max(spikeCore, scMask);
spikeGlow = max(spikeGlow, sgMask);
spikeInk = max(spikeInk, siMask * 0.75);
}
}
// Secondary tiny razor needles between main spikes
for (int i = 0; i < 8; i++) {
float fi = float(i);
float baseAng = (fi + 0.5) * (TAU / 8.0) + 0.25 * cos(fi * 4.1);
float ca = cos(baseAng), sa = sin(baseAng);
float lx = p.x * ca + p.y * sa;
float ly = -p.x * sa + p.y * ca;
float t = (lx - 1.32) / 0.42;
if (t > 0.0 && t < 1.0) {
float halfW = 0.035 * (1.0 - t);
float dMini = abs(ly) - halfW;
spikeCore = max(spikeCore, 1.0 - smoothstep(-0.004, 0.008, dMini));
spikeGlow = max(spikeGlow, 1.0 - smoothstep(0.004, 0.035, dMini));
}
}
// ------------------------------------------------------------------------
// 3. Central Jagged Comic Starburst Flash at the Epicenter
// ------------------------------------------------------------------------
float starRays = 0.28
+ 0.22 * pow(0.5 + 0.5 * sin(ang * 9.0 + 0.4), 3.0)
+ 0.18 * pow(0.5 + 0.5 * sin(ang * 15.0 - 1.2 + TAU * wavePhase * 0.0), 4.0)
+ 0.10 * sin(ang * 5.0 + 2.1);
starRays *= (0.94 + 0.10 * anim.pulse);
float dStar = r - starRays;
float centerCore = 1.0 - smoothstep(-0.03, 0.02, dStar);
float centerGlow = 1.0 - smoothstep(0.01, 0.19, dStar);
// ------------------------------------------------------------------------
// 4. Radial Ground Lightning Tendrils crawling from center out to spikes
// ------------------------------------------------------------------------
float boltCore = 0.0;
float boltGlow = 0.0;
const int NUM_BOLTS = 6;
for (int i = 0; i < NUM_BOLTS; i++) {
float fi = float(i);
float bAng = fi * (TAU / float(NUM_BOLTS)) + 0.35 + 0.22 * sin(fi * 3.7);
float ca = cos(bAng), sa = sin(bAng);
float lx = p.x * ca + p.y * sa;
float ly = -p.x * sa + p.y * ca;
if (lx > 0.12 && lx < 1.85) {
// Sharp zig-zag polyline offset
float segPos = lx * 4.2;
float segIdx = floor(segPos);
float segF = fract(segPos);
float j0 = (hash11(segIdx * 13.7 + fi * 41.3 + anim.boltJitter * 0.17) - 0.5) * 0.26;
float j1 = (hash11((segIdx + 1.0) * 13.7 + fi * 41.3 + anim.boltJitter * 0.17) - 0.5) * 0.26;
float zigY = mix(j0, j1, segF) * smoothstep(0.12, 0.45, lx) * smoothstep(1.85, 1.45, lx);
float dBolt = abs(ly - zigY);
float thick = mix(0.024, 0.008, lx / 1.85);
boltCore = max(boltCore, 1.0 - smoothstep(thick * 0.5, thick * 1.4, dBolt));
boltGlow = max(boltGlow, 1.0 - smoothstep(thick, thick * 4.5, dBolt));
}
}
// ------------------------------------------------------------------------
// 5. Detached Flying Comic Spark Dashes around outer perimeter
// ------------------------------------------------------------------------
float sparkMask = 0.0;
for (int i = 0; i < 8; i++) {
float fi = float(i);
float sAng = fi * (TAU / 8.0) + 0.65;
float ca = cos(sAng), sa = sin(sAng);
float lx = p.x * ca + p.y * sa;
float ly = -p.x * sa + p.y * ca;
float travel = fract(wavePhase + hash11(fi * 5.9));
float sr = mix(1.52, 2.15, travel);
vec2 sd = segDist2D(vec2(lx, ly), vec2(sr, 0.0), vec2(sr + 0.18, 0.0));
float fade = smoothstep(0.0, 0.15, travel) * smoothstep(1.0, 0.65, travel);
sparkMask = max(sparkMask, (1.0 - smoothstep(0.008, 0.022, sd.x)) * fade);
}
// Combine crisp cel layers
float totalCore = clamp(max(max(ringCore, spikeCore), max(centerCore, max(boltCore, sparkMask))), 0.0, 1.0);
float totalGlow = clamp(max(max(ringGlow, spikeGlow), max(centerGlow, boltGlow)), 0.0, 1.0);
// Stylized 2-tier energy color: hot neon magenta halo + blazing white-pink core
vec3 glowCol = mix(COL_MAGENTA_DEEP, COL_MAGENTA_HOT, smoothstep(0.15, 0.65, totalGlow));
glowCol = mix(glowCol, COL_MAGENTA_NEON, smoothstep(0.55, 0.92, totalGlow));
vec3 coreCol = mix(glowCol, COL_WHITE_CORE, smoothstep(0.25, 0.72, totalCore));
// Boost brightness cleanly (will be soft-tonemapped below 1.0 clip)
float energyBoost = 1.35 + 0.25 * pulseBand + 0.20 * centerCore;
res.emissive = coreCol * energyBoost * max(totalGlow, totalCore);
res.alpha = clamp(max(totalCore, totalGlow * 0.92), 0.0, 1.0);
res.inkMask = clamp(max(outerInk, spikeInk) * (1.0 - totalGlow * 0.85), 0.0, 1.0);
// Quantized cel-banded floor illumination from the plasma blast
float rawGlow = exp(-r * 0.78) * 1.15 + 0.35 * exp(-abs(r - r4) * 2.4);
float qGlow = floor(clamp(rawGlow, 0.0, 1.0) * 3.5) / 3.5;
res.floorGlow = mix(rawGlow, qGlow, 0.65);
return res;
}
// ----------------------------------------------------------------------------
// 3D Vertical Zig-Zag Magenta-White Lightning Strike + Secondary Forks
// ----------------------------------------------------------------------------
vec4 evalVerticalLightning(vec3 ro, vec3 rd, float maxT, AnimState anim) {
// 6-vertex dramatic zig-zag bolt from y = 0.04 up to y = 2.75
// Matches the iconic jagged S-curve spear silhouette in 08.png
float j = anim.boltJitter;
float sway = 0.06 * sin(TAU * anim.phase);
float flick1 = (hash11(j * 3.7 + 1.1) - 0.5) * 0.08;
float flick2 = (hash11(j * 5.3 + 2.7) - 0.5) * 0.08;
float flick3 = (hash11(j * 7.1 + 4.3) - 0.5) * 0.06;
vec3 pts[6];
pts[0] = vec3( 0.00, 0.02, 0.00);
pts[1] = vec3( 0.07 + sway + flick1, 0.52, -0.04);
pts[2] = vec3(-0.08 - sway + flick2, 1.04, 0.05);
pts[3] = vec3( 0.16 + sway + flick3, 1.56, -0.05);
pts[4] = vec3(-0.09 + flick1 * 0.7, 2.12, 0.03);
pts[5] = vec3( 0.02, 2.82, 0.00);
float coreMask = 0.0;
float glowMask = 0.0;
float hitT = maxT;
// Main vertical bolt segments
for (int i = 0; i < 5; i++) {
vec3 dInfo = raySegDist(ro, rd, pts[i], pts[i + 1]);
float dist = dInfo.x;
float segT = dInfo.y;
float rayT = dInfo.z;
if (rayT < maxT && rayT > 0.05) {
float hFrac = (float(i) + segT) / 5.0;
// Thickest at impact base, tapering to a needle spear at the top
float baseRad = mix(0.085, 0.008, pow(hFrac, 0.85));
// Slight flare at sharp elbow bends
float elbow = 1.0 + 0.25 * exp(-pow((segT - 0.5) * 4.0, 2.0)) * (1.0 - hFrac);
float rad = baseRad * elbow;
float c = 1.0 - smoothstep(rad * 0.55, rad * 1.15, dist);
float g = 1.0 - smoothstep(rad * 1.05, rad * 3.20, dist);
if (g > glowMask) hitT = min(hitT, rayT);
coreMask = max(coreMask, c);
glowMask = max(glowMask, g);
}
}
// Secondary forked electric crackles branching off the main bolt
vec3 f1a = pts[1];
vec3 f1b = pts[1] + vec3(0.24, 0.38, 0.08);
vec3 f1c = f1b + vec3(-0.06, 0.34, -0.05);
vec3 f2a = pts[2];
vec3 f2b = pts[2] + vec3(-0.26, 0.34, -0.06);
vec3 f2c = f2b + vec3(-0.10, 0.36, 0.08);
vec3 f3a = pts[3];
vec3 f3b = pts[3] + vec3(-0.22, -0.26, 0.06);
vec3 forksA[5];
vec3 forksB[5];
forksA[0] = f1a; forksB[0] = f1b;
forksA[1] = f1b; forksB[1] = f1c;
forksA[2] = f2a; forksB[2] = f2b;
forksA[3] = f2b; forksB[3] = f2c;
forksA[4] = f3a; forksB[4] = f3b;
for (int i = 0; i < 5; i++) {
vec3 dInfo = raySegDist(ro, rd, forksA[i], forksB[i]);
if (dInfo.z < maxT && dInfo.z > 0.05) {
float rad = mix(0.016, 0.004, dInfo.y);
coreMask = max(coreMask, 1.0 - smoothstep(rad * 0.5, rad * 1.2, dInfo.x));
glowMask = max(glowMask, 1.0 - smoothstep(rad, rad * 3.8, dInfo.x));
}
}
// Floating vertical pink spark shards around the bolt (just like 08.png)
for (int i = 0; i < 6; i++) {
float fi = float(i);
float a = fi * 1.15 + 0.4;
float radR = mix(0.32, 0.58, hash11(fi * 9.3 + 1.0));
float rise = fract(anim.phase + hash11(fi * 4.7));
float y0 = mix(0.55, 2.05, rise);
vec3 sa = vec3(cos(a) * radR, y0, sin(a) * radR * 0.55);
vec3 sb = sa + vec3(cos(a) * 0.05, 0.22, sin(a) * 0.03);
vec3 dInfo = raySegDist(ro, rd, sa, sb);
if (dInfo.z < maxT && dInfo.z > 0.05) {
float fade = smoothstep(0.0, 0.15, rise) * smoothstep(1.0, 0.7, rise);
float sc = (1.0 - smoothstep(0.006, 0.015, dInfo.x)) * fade;
float sg = (1.0 - smoothstep(0.012, 0.045, dInfo.x)) * fade;
coreMask = max(coreMask, sc);
glowMask = max(glowMask, sg);
}
}
vec3 boltCol = mix(COL_MAGENTA_HOT * 1.35, COL_MAGENTA_NEON * 1.55, smoothstep(0.25, 0.8, glowMask));
boltCol = mix(boltCol, COL_WHITE_CORE * 1.75, smoothstep(0.18, 0.72, coreMask));
float alpha = clamp(max(coreMask, glowMask * 0.95), 0.0, 1.0);
return vec4(boltCol * alpha, alpha);
}
// ----------------------------------------------------------------------------
// Dark Ink-Grouted Charcoal Tiled Arena Floor Shading
// ----------------------------------------------------------------------------
vec3 shadeArenaFloor(vec3 p, vec3 rd, AnimState anim, vec3 lightDir) {
// Rotate tile grid slightly for dynamic diagonal comic composition (matches 08.png)
vec2 gPos = rot2(0.32) * p.xz;
vec2 tileScale = vec2(1.45, 1.45);
vec2 cellId = floor(gPos / tileScale);
vec2 cellUv = fract(gPos / tileScale) - 0.5;
// Distance to grout lines (bold dark comic ink seams)
vec2 edgeDist = 0.5 - abs(cellUv);
float minEdge = min(edgeDist.x, edgeDist.y);
float groutWidth = 0.022;
float groutInk = 1.0 - smoothstep(groutWidth * 0.75, groutWidth * 1.35, minEdge);
// Subtle secondary bevel highlight next to grout lines
float bevelEdge = smoothstep(groutWidth * 1.2, groutWidth * 2.2, minEdge)
* (1.0 - smoothstep(groutWidth * 2.2, groutWidth * 4.0, minEdge));
// Per-tile tonal variation + subtle quantized comic concrete grunge
float tileVar = (hash21(cellId) - 0.5) * 0.022;
float grunge = fbm2(gPos * 3.8);
float grungeQ = floor(grunge * 3.0) / 3.0;
vec3 floorCol = COL_FLOOR_BASE + vec3(tileVar) + (grungeQ - 0.5) * vec3(0.018, 0.019, 0.024);
floorCol += bevelEdge * vec3(0.025, 0.028, 0.038);
// Circular outer arena rim + hot-magenta trim panels (seen at top of 08.png)
float arenaR = length(p.xz);
float rimInner = 4.35;
float rimOuter = 4.75;
if (arenaR > rimInner - 0.15) {
float rimBand = smoothstep(rimInner - 0.04, rimInner + 0.02, arenaR)
* (1.0 - smoothstep(rimOuter - 0.02, rimOuter + 0.04, arenaR));
float rimAng = atan(p.z, p.x);
float panelSeg = fract(rimAng * 12.0 / TAU);
float panelSeam = 1.0 - smoothstep(0.03, 0.06, min(panelSeg, 1.0 - panelSeg));
float litPanel = step(0.18, hash11(floor(rimAng * 12.0 / TAU) * 7.3 + 2.0));
vec3 rimCol = mix(vec3(0.11, 0.12, 0.16), COL_ARENA_TRIM * 0.85, litPanel);
rimCol = mix(rimCol, COL_INK, panelSeam * 0.9);
floorCol = mix(floorCol, rimCol, rimBand);
// Bold ink borders on the arena curb
float curbInk = (1.0 - smoothstep(0.02, 0.05, abs(arenaR - rimInner)))
+ (1.0 - smoothstep(0.02, 0.05, abs(arenaR - rimOuter)));
floorCol = mix(floorCol, COL_INK, clamp(curbInk, 0.0, 1.0));
// Darker matte outer arena void beyond the curb
float beyond = smoothstep(rimOuter, rimOuter + 0.15, arenaR);
floorCol = mix(floorCol, COL_FLOOR_DARK, beyond);
}
// Apply bold ink grout lines inside the arena
float insideArena = 1.0 - smoothstep(rimInner - 0.05, rimInner + 0.02, arenaR);
floorCol = mix(floorCol, COL_INK, groutInk * insideArena * 0.92);
// LightMode directional tint on floor
if (uLightMode == 2) {
floorCol *= vec3(0.92, 1.00, 1.18);
}
// Crisp hard-edged comic drop shadow cast by the smoke clouds onto the floor
vec3 shPos = p + vec3(lightDir.x * 0.18, 0.18, lightDir.z * 0.18);
float dSmoke = mapSmokeDist(shPos, anim);
float dropShadow = 1.0 - smoothstep(0.02, 0.16, dSmoke);
floorCol = mix(floorCol, COL_INK * 1.15, dropShadow * 0.78);
// Evaluate the neon magenta plasma blast on the floor
BlastGround blast = evalGroundBlast(p.xz, anim);
float emitScale = (uLightMode == 1) ? 0.38 : 1.0;
// Add cel-banded neon magenta bounce light onto the charcoal tiles
vec3 bounceCol = mix(COL_MAGENTA_DEEP, COL_MAGENTA_HOT, 0.6) * blast.floorGlow * 0.42 * emitScale;
// Slight magenta rim glow in the grout lines near the explosion!
float neonGrout = groutInk * insideArena * smoothstep(2.6, 1.2, arenaR) * 0.55 * emitScale;
floorCol += bounceCol * (1.0 - dropShadow * 0.5) + COL_MAGENTA_HOT * neonGrout * 0.35;
// Apply dark comic ink edge around rings/spikes
floorCol = mix(floorCol, COL_INK, blast.inkMask * 0.85);
// Composite crisp blazing shockwave rings, spikes, and ground bolts
floorCol = mix(floorCol, blast.emissive * mix(0.55, 1.0, emitScale), blast.alpha);
// Atmospheric depth fade into dark charcoal-violet arena wall at far distance
float distFade = smoothstep(5.5, 12.5, length(p.xz));
vec3 farBg = vec3(0.042, 0.040, 0.062);
floorCol = mix(floorCol, farBg, distFade);
return floorCol;
}
// ----------------------------------------------------------------------------
// Cel-Shaded 3-Band Stylized Violet Smoke Shading with Ink Contours
// ----------------------------------------------------------------------------
vec3 shadeSmoke(vec3 p, vec3 N, vec3 V, float crease, AnimState anim, vec3 keyDir) {
// 1. Primary light from overhead key + strong magenta light from epicenter (0, 0.35, 0)
vec3 toCenter = vec3(0.0, 0.35, 0.0) - p;
float distCenter = length(toCenter);
vec3 blastDir = toCenter / max(distCenter, 1e-5);
float ndlKey = dot(N, keyDir);
float ndlBlast = dot(N, blastDir);
float blastAtten = 1.0 / (1.0 + 0.18 * distCenter * distCenter);
// Combine lighting scalar for 3-band quantized cel shading
float lit = ndlKey * 0.55 + ndlBlast * blastAtten * 0.85 + 0.25;
// Quantize into 3 crisp stylized comic bands (Shadow -> Mid -> Lit)
float band1 = smoothstep(0.14, 0.18, lit);
float band2 = smoothstep(0.54, 0.59, lit);
vec3 col = mix(COL_SMOKE_SHAD, COL_SMOKE_MID, band1);
col = mix(col, COL_SMOKE_LIT, band2);
// LightMode adjustments
if (uLightMode == 2) {
col = mix(col, col * vec3(0.84, 0.96, 1.22), 0.7);
}
// Hot-magenta rim highlight on puff edges facing the plasma epicenter
float ndv = clamp(dot(N, V), 0.0, 1.0);
float fresnel = 1.0 - ndv;
float rimScale = (uLightMode == 1) ? 0.25 : 0.85;
float blastRim = smoothstep(0.45, 0.75, fresnel) * smoothstep(0.05, 0.45, ndlBlast) * blastAtten;
col = mix(col, COL_SMOKE_RIM * 1.15, clamp(blastRim * rimScale, 0.0, 0.85));
// Bold black-ink Fresnel contour + internal lobe crease lines
float inkFresnel = smoothstep(0.27, 0.17, ndv);
float inkCrease = smoothstep(0.42, 0.72, crease) * 0.92;
float inkMask = clamp(max(inkFresnel, inkCrease), 0.0, 1.0);
col = mix(col, COL_INK, inkMask);
return col;
}
// ----------------------------------------------------------------------------
// Camera Setup (4 uCamMode presets)
// ----------------------------------------------------------------------------
void setupCamera(out vec3 ro, out vec3 ta, out float fl, AnimState anim) {
if (uCamMode == 1) {
// Low dramatic heroic angle looking across the shockwave rings up at the strike
ro = vec3(0.45, 1.42, 3.95);
ta = vec3(0.00, 0.62, 0.00);
fl = 1.45;
} else if (uCamMode == 2) {
// High tactical top-down view showing full concentric starburst & smoke ring
ro = vec3(0.00, 5.10, 1.55);
ta = vec3(0.00, 0.05, 0.10);
fl = 1.60;
} else if (uCamMode == 3) {
// Smooth 3-second orbital showcase
float a = TAU * anim.phase * 0.5 - 0.35;
ro = vec3(sin(a) * 3.85, 2.75, cos(a) * 3.85);
ta = vec3(0.00, 0.38, 0.00);
fl = 1.55;
} else {
// Default Hero 3/4 Elevated Arena View (matches 08.png composition)
ro = vec3(0.00, 3.12, 3.62);
ta = vec3(0.00, 0.34, 0.05);
fl = 1.56;
}
}
// ----------------------------------------------------------------------------
// Stylized Filmic Tone Mapping (punchy neon saturation, <1% clip, <2% black)
// ----------------------------------------------------------------------------
vec3 stylizedTonemap(vec3 c) {
// Soft shoulder curve that preserves vibrant magenta/violet hue and prevents clipping
c = max(c, vec3(0.0));
if (uLightMode == 1) {
float lum = dot(c, vec3(0.2126, 0.7152, 0.0722));
c = vec3(lum);
}
vec3 mapped = (c * (2.51 * c + 0.03)) / (c * (2.43 * c + 0.59) + 0.14);
// Keep peak safely under 0.975 so <1% clip is guaranteed even at white-hot core
mapped = mapped * 0.965;
// Gamma encode to sRGB
vec3 srgb = pow(clamp(mapped, 0.0, 0.98), vec3(1.0 / 2.2));
// Subtle dark ink floor lift so deep ink reads crisp jet-black without pure-black crush
vec3 inkFloor = (uLightMode == 1) ? vec3(0.036) : vec3(0.032, 0.030, 0.044);
srgb = max(srgb, inkFloor);
if (uLightMode == 1) {
srgb = vec3(dot(srgb, vec3(0.2126, 0.7152, 0.0722)));
}
return clamp(srgb, 0.0, 0.985);
}
// ----------------------------------------------------------------------------
// Main
// ----------------------------------------------------------------------------
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 res = max(uResolution, vec2(1.0));
vec2 uv = (pfx_frag_xy - 0.5 * res) / min(res.x, res.y);
AnimState anim = getAnim();
vec3 ro, ta;
float fl;
setupCamera(ro, ta, fl, anim);
vec3 ww = normalize(ta - ro);
vec3 uu = normalize(cross(ww, vec3(0.0, 1.0, 0.0)));
vec3 vv = cross(uu, ww);
vec3 rd = normalize(uv.x * uu + uv.y * vv + fl * ww);
// Key light direction by uLightMode
vec3 keyDir = normalize(vec3(-0.35, 0.85, 0.40));
if (uLightMode == 1) {
keyDir = normalize(vec3(0.45, 0.78, 0.42));
} else if (uLightMode == 2) {
keyDir = normalize(vec3(-0.62, 0.65, -0.44));
}
// 1. Background sky / upper arena wall gradient (dark matte charcoal-indigo)
float skyGrad = clamp(rd.y * 1.5 + 0.35, 0.0, 1.0);
vec3 col = mix(vec3(0.042, 0.040, 0.062), vec3(0.022, 0.020, 0.036), skyGrad);
// Subtle distant magenta atmospheric glow behind the vertical strike
float bgGlow = exp(-length(uv - vec2(0.0, 0.10)) * 2.2) * ((uLightMode == 1) ? 0.03 : 0.12);
col += COL_MAGENTA_DEEP * bgGlow;
// 2. Analytic intersection with the arena floor plane (y = 0)
float tFloor = 1e5;
if (rd.y < -1e-4) {
float tf = -ro.y / rd.y;
if (tf > 0.0 && tf < 30.0) {
tFloor = tf;
vec3 pFloor = ro + rd * tFloor;
col = shadeArenaFloor(pFloor, rd, anim, keyDir);
}
}
// 3. Raymarch 3D chunky ink-outlined violet smoke clouds
float tMax = min(tFloor, 14.0);
float t = 0.25;
bool hitSmoke = false;
vec3 pHit = vec3(0.0);
float hitCrease = 0.0;
float minRatio = 1e5;
float prevD = 1e5;
for (int i = 0; i < 68; i++) {
if (t > tMax) break;
vec3 p = ro + rd * t;
vec2 m = mapSmoke(p, anim);
float d = m.x;
// Track near-miss silhouette edge for crisp uniform comic ink outline
if (d > prevD && t > 0.5) {
minRatio = min(minRatio, prevD / t);
}
prevD = d;
if (d < 0.0035) {
hitSmoke = true;
pHit = p;
hitCrease = m.y;
break;
}
t += max(d * 0.85, 0.015);
}
float sceneDepth = tFloor;
if (hitSmoke) {
sceneDepth = t;
vec3 N = calcSmokeNormal(pHit, anim);
vec3 smokeCol = shadeSmoke(pHit, N, -rd, hitCrease, anim, keyDir);
// Allow inner shockwave ring glow to subtly kiss the lower edge of inner smoke
float edgeKiss = smoothstep(0.28, 0.02, pHit.y) * smoothstep(2.0, 1.2, length(pHit.xz));
smokeCol += COL_MAGENTA_HOT * edgeKiss * ((uLightMode == 1) ? 0.06 : 0.28);
col = smokeCol;
} else if (minRatio < 0.011) {
// Crisp outer black-ink comic silhouette halo around missed grazing smoke edges
float outlineMask = 1.0 - smoothstep(0.004, 0.011, minRatio);
col = mix(col, COL_INK, outlineMask * 0.90);
}
// 4. Composite 3D vertical zig-zag magenta-white lightning strike + forks + shards
vec4 bolt = evalVerticalLightning(ro, rd, sceneDepth + 0.35, anim);
float boltScale = (uLightMode == 1) ? 0.55 : 1.0;
vec3 boltRgb = bolt.rgb * boltScale;
col = mix(col, col + boltRgb, clamp(bolt.a, 0.0, 1.0));
// Ensure crisp opaque white core punches right over dark background & smoke
col = mix(col, boltRgb, smoothstep(0.65, 0.95, bolt.a));
// Subtle vignette to frame the arena blast without crushing corners
float vig = 1.0 - 0.18 * dot(uv, uv);
col *= clamp(vig, 0.72, 1.0);
fragColor = vec4(stylizedTonemap(col), 1.0);
}
void fragment() {
vec2 tiled_uv = fract(UV * u_tiling);
vec2 frag_xy = vec2(tiled_uv.x, 1.0 - tiled_uv.y) * uResolution;
vec4 study_col = vec4(0.0, 0.0, 0.0, 1.0);
pixelfx_study_eval(frag_xy, study_col);
vec3 tinted = clamp(mix(study_col.rgb, study_col.rgb * u_tint.rgb * 1.35, u_tint_mix), 0.0, 1.0);
float luma = dot(tinted, vec3(0.2126, 0.7152, 0.0722));
ALBEDO = tinted;
if (u_luma_alpha_key) {
ALPHA = smoothstep(0.035, 0.22, luma);
}
}
// Neon Magenta Plasma Grenade — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_stylized/lib/08_neon_magenta_plasma_grenade.glsl (MIT License)
import * as THREE from 'three';
const vertexShader = /* glsl */ `
out vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;
const fragmentShader = /* glsl */ `
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_neon_magenta_plasma_grenade.glsl
// Punchy 3D NEON HOT-MAGENTA & ELECTRIC PURPLE stylized plasma grenade
// starburst explosion on a dark matte ink-grouted charcoal tiled arena floor.
//
// Features:
// - Dark charcoal ink-grouted tiled arena floor vec3(0.08, 0.09, 0.12)
// with circular arena trim, subtle cel grunge, and hard ink drop shadows
// - Crisp concentric hot-pink & white comic shockwave rings with jagged
// starburst radial spikes and crawling surface lightning tendrils
// - 3D vertical zig-zag magenta-white lightning strike hitting the epicenter
// with secondary forks and comic energy shards
// - Chunky 3D raymarched ink-outlined flat-shaded violet smoke clouds
// with 3-band quantized cel shading, Fresnel + silhouette ink contours,
// and internal comic crease lines
// - Seamless 3-second loop on uTime; uOpen (0..1) expands the starburst blast
// ============================================================================
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
// Palette (linear-friendly vibrant stylized colors)
const vec3 COL_FLOOR_BASE = vec3(0.08, 0.09, 0.12);
const vec3 COL_FLOOR_DARK = vec3(0.048, 0.052, 0.075);
const vec3 COL_INK = vec3(0.012, 0.010, 0.020);
const vec3 COL_ARENA_TRIM = vec3(0.68, 0.09, 0.36);
const vec3 COL_MAGENTA_HOT = vec3(1.00, 0.11, 0.62);
const vec3 COL_MAGENTA_NEON = vec3(1.00, 0.28, 0.78);
const vec3 COL_MAGENTA_DEEP = vec3(0.55, 0.04, 0.38);
const vec3 COL_WHITE_CORE = vec3(1.00, 0.94, 0.99);
const vec3 COL_SMOKE_LIT = vec3(0.62, 0.25, 0.96);
const vec3 COL_SMOKE_MID = vec3(0.36, 0.12, 0.72);
const vec3 COL_SMOKE_SHAD = vec3(0.17, 0.055, 0.40);
const vec3 COL_SMOKE_RIM = vec3(0.95, 0.32, 0.88);
// ----------------------------------------------------------------------------
// Math & Noise Utilities
// ----------------------------------------------------------------------------
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 hash31(vec3 p3) {
p3 = fract(p3 * 0.1031);
p3 += dot(p3, p3.zyx + 31.32);
return fract((p3.x + p3.y) * p3.z);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
return mix(mix(a, b, u.x), mix(c, d, 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(17.1, 31.7);
a *= 0.5;
}
return v;
}
float smin(float a, float b, float k) {
float h = max(k - abs(a - b), 0.0) / max(k, 1e-5);
return min(a, b) - h * h * k * 0.25;
}
// Distance from point p to 2D segment ab, returning vec2(dist, t)
vec2 segDist2D(vec2 p, vec2 a, vec2 b) {
vec2 pa = p - a;
vec2 ba = b - a;
float denom = max(dot(ba, ba), 1e-6);
float t = clamp(dot(pa, ba) / denom, 0.0, 1.0);
return vec2(length(pa - ba * t), t);
}
// Closest distance between a ray (ro, rd) and a 3D line segment (a, b)
// Returns vec3(minDist, segT, rayT)
vec3 raySegDist(vec3 ro, vec3 rd, vec3 a, vec3 b) {
vec3 u = rd;
vec3 v = b - a;
vec3 w = ro - a;
float aDot = dot(u, u); // 1.0
float bDot = dot(u, v);
float cDot = dot(v, v);
float dDot = dot(u, w);
float eDot = dot(v, w);
float D = aDot * cDot - bDot * bDot;
float sc, tc;
if (D < 1e-6) {
sc = 0.0;
tc = (bDot > cDot ? dDot / max(bDot, 1e-6) : eDot / max(cDot, 1e-6));
} else {
sc = (bDot * eDot - cDot * dDot) / D;
tc = (aDot * eDot - bDot * dDot) / D;
}
tc = clamp(tc, 0.0, 1.0);
// Recompute optimal ray parameter sc for clamped tc
sc = max(dot(a + v * tc - ro, u), 0.0);
vec3 pRay = ro + u * sc;
vec3 pSeg = a + v * tc;
return vec3(length(pRay - pSeg), tc, sc);
}
// ----------------------------------------------------------------------------
// Animation Parameters (3-second seamless loop + uOpen 0..1 blast expansion)
// ----------------------------------------------------------------------------
struct AnimState {
float phase; // 0..1 seamless 3s loop
float openAmt; // 0..1 uOpen
float blastScale; // overall radial expansion of rings & spikes
float pulse; // smooth rhythmic pulse
float boltJitter; // stepped comic frame seed for lightning snap
};
AnimState getAnim() {
AnimState a;
a.phase = loopPhase();
a.openAmt = clamp(uOpen, 0.0, 1.0);
float breathe = 0.035 * sin(TAU * a.phase);
a.blastScale = mix(0.58, 1.12, smoothstep(0.0, 1.0, a.openAmt)) + breathe;
a.pulse = 0.5 + 0.5 * sin(TAU * a.phase);
// Quantize lightning flicker to 12 comic frames per 3s loop (seamless!)
float frameIdx = floor(a.phase * 12.0);
a.boltJitter = frameIdx;
return a;
}
// ----------------------------------------------------------------------------
// 3D Stylized Chunky Violet Smoke Clouds SDF
// Returns vec2(sdf, creaseFactor)
// ----------------------------------------------------------------------------
// Helper to blend a puff and track lobe seam proximity for comic crease ink
void addPuff(inout float d, inout float seam, vec3 p, vec3 c, float r, float k) {
float dp = length(p - c) - r;
// Detect intersection crease between adjacent puffs
float diff = abs(d - dp);
float nearBoth = smoothstep(0.14, 0.0, max(d, dp) - 0.02);
float crease = smoothstep(0.09, 0.01, diff) * nearBoth;
seam = max(seam, crease);
d = smin(d, dp, k);
}
// Tapered swirling smoke tendril along a floor curve
void addTail(inout float d, inout float seam, vec3 p, vec3 a, vec3 b, float ra, float rb, float k) {
vec3 pa = p - a, ba = b - a;
float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-6), 0.0, 1.0);
// Subtle wavy comic curl
vec3 q = pa - ba * h;
float r = mix(ra, rb, h);
float dp = length(q) - r;
float diff = abs(d - dp);
float nearBoth = smoothstep(0.12, 0.0, max(d, dp) - 0.02);
seam = max(seam, smoothstep(0.07, 0.01, diff) * nearBoth);
d = smin(d, dp, k);
}
vec2 mapSmoke(vec3 p, AnimState anim) {
// Early vertical bound check
if (p.y > 2.2 || p.y < -0.5) {
return vec2(max(p.y - 2.0, -0.35 - p.y) + 0.4, 0.0);
}
float d = 1e5;
float seam = 0.0;
float sc = anim.blastScale;
float drift = 0.06 * sin(TAU * anim.phase);
float drift2 = 0.05 * cos(TAU * anim.phase);
// Subtle chunky stylization warp so puffs feel hand-sculpted
vec3 pw = p;
pw.x += 0.04 * sin(p.z * 2.5 + TAU * anim.phase);
pw.z += 0.04 * cos(p.x * 2.5 - TAU * anim.phase);
// ------------------------------------------------------------------------
// 1. INNER BILLOWING SMOKE RING (hugging the outer shockwave perimeter)
// ------------------------------------------------------------------------
float ringR = 1.48 * sc;
// Back-left inner cluster (around angle 2.25 rad)
vec3 bl = vec3(-1.18 * sc, 0.24, -0.78 * sc);
addPuff(d, seam, pw, bl + vec3(0.0, 0.05 + drift * 0.4, 0.0), 0.44 * sc, 0.14);
addPuff(d, seam, pw, bl + vec3(-0.34 * sc, -0.02, 0.24 * sc), 0.34 * sc, 0.12);
addPuff(d, seam, pw, bl + vec3(0.36 * sc, -0.04, -0.18 * sc), 0.30 * sc, 0.12);
// Back-right inner cluster
vec3 br = vec3(1.12 * sc, 0.22, -0.76 * sc);
addPuff(d, seam, pw, br + vec3(0.0, 0.04 - drift * 0.4, 0.0), 0.40 * sc, 0.14);
addPuff(d, seam, pw, br + vec3(0.32 * sc, -0.04, 0.22 * sc), 0.30 * sc, 0.12);
addPuff(d, seam, pw, br + vec3(-0.32 * sc, -0.06, -0.16 * sc), 0.26 * sc, 0.12);
// Front-bottom low billowing rim puffs (under the front of the shockwave ring)
addPuff(d, seam, pw, vec3(-0.55 * sc, 0.10, 1.22 * sc), 0.32 * sc, 0.13);
addPuff(d, seam, pw, vec3( 0.04 * sc, 0.08, 1.32 * sc), 0.34 * sc, 0.13);
addPuff(d, seam, pw, vec3( 0.62 * sc, 0.11, 1.18 * sc), 0.31 * sc, 0.13);
addPuff(d, seam, pw, vec3(-1.05 * sc, 0.12, 0.88 * sc), 0.29 * sc, 0.12);
addPuff(d, seam, pw, vec3( 1.05 * sc, 0.12, 0.84 * sc), 0.28 * sc, 0.12);
// ------------------------------------------------------------------------
// 2. HERO FOREGROUND LEFT SWIRLING CLOUD (matches 08.png bottom-left)
// ------------------------------------------------------------------------
vec3 flBase = vec3(-2.35 - 0.25 * anim.openAmt, 0.46, 0.92 + drift2);
addPuff(d, seam, pw, flBase + vec3(-0.22, 0.16, -0.12), 0.66, 0.18);
addPuff(d, seam, pw, flBase + vec3( 0.28, -0.05, 0.14), 0.50, 0.16);
addPuff(d, seam, pw, flBase + vec3( 0.68, -0.18, -0.12), 0.36, 0.14);
addPuff(d, seam, pw, flBase + vec3( 0.52, -0.16, 0.48), 0.38, 0.15);
addTail(d, seam, pw, flBase + vec3(0.58, -0.24, 0.55), flBase + vec3(1.38, -0.34, 1.08), 0.26, 0.04, 0.12);
// ------------------------------------------------------------------------
// 3. HERO MID-RIGHT BILLOWING CLOUD (matches 08.png right edge)
// ------------------------------------------------------------------------
vec3 mrBase = vec3(2.58 + 0.20 * anim.openAmt, 0.44, 0.15 - drift2);
addPuff(d, seam, pw, mrBase + vec3( 0.25, 0.18, -0.06), 0.62, 0.18);
addPuff(d, seam, pw, mrBase + vec3(-0.26, -0.04, 0.16), 0.42, 0.15);
addTail(d, seam, pw, mrBase + vec3(-0.38, -0.16, 0.16), mrBase + vec3(-1.05, -0.26, 0.18), 0.24, 0.04, 0.12);
// ------------------------------------------------------------------------
// 4. HERO UPPER-RIGHT SWIRLING CLOUD (matches 08.png top-right)
// ------------------------------------------------------------------------
vec3 urBase = vec3(2.45 + 0.18 * anim.openAmt, 0.58, -1.85 + drift);
addPuff(d, seam, pw, urBase + vec3( 0.30, 0.26, -0.18), 0.72, 0.20);
addPuff(d, seam, pw, urBase + vec3(-0.28, 0.02, 0.14), 0.48, 0.16);
addPuff(d, seam, pw, urBase + vec3( 0.15, -0.08, 0.32), 0.42, 0.15);
addTail(d, seam, pw, urBase + vec3(-0.48, -0.18, 0.22), urBase + vec3(-1.35, -0.36, 0.34), 0.22, 0.035, 0.12);
// Flatten slightly underneath so clouds sit firmly on the arena floor
d = max(d, -p.y + 0.02);
return vec2(d, clamp(seam, 0.0, 1.0));
}
float mapSmokeDist(vec3 p, AnimState anim) {
return mapSmoke(p, anim).x;
}
vec3 calcSmokeNormal(vec3 p, AnimState anim) {
const vec2 e = vec2(0.004, -0.004);
vec3 n = e.xyy * mapSmokeDist(p + e.xyy, anim)
+ e.yyx * mapSmokeDist(p + e.yyx, anim)
+ e.yxy * mapSmokeDist(p + e.yxy, anim)
+ e.xxx * mapSmokeDist(p + e.xxx, anim);
return normalize(n + vec3(1e-6));
}
// ----------------------------------------------------------------------------
// Ground Shockwave Rings, Starburst Spikes, Epicenter Flash & Surface Bolts
// Evaluated cleanly on the arena floor plane (xz)
// ----------------------------------------------------------------------------
struct BlastGround {
vec3 emissive; // blazing magenta/white emissive energy
float alpha; // opaque coverage of crisp comic energy shapes
float inkMask; // dark ink outline around rings/spikes
float floorGlow; // cel-banded magenta bounce light on floor
};
BlastGround evalGroundBlast(vec2 xz, AnimState anim) {
BlastGround res;
res.emissive = vec3(0.0);
res.alpha = 0.0;
res.inkMask = 0.0;
res.floorGlow = 0.0;
float sc = anim.blastScale;
vec2 p = xz / max(sc, 0.15);
float r = length(p);
float ang = atan(p.y, p.x);
// Smooth outward-travelling wave phase inside the 3s loop
float wavePhase = anim.phase;
// ------------------------------------------------------------------------
// 1. Concentric Hot-Pink & White Shockwave Rings
// ------------------------------------------------------------------------
// 4 crisp rings matching 08.png: innermost, mid-inner, mid-outer, thick outer
float r1 = 0.56 + 0.03 * sin(TAU * wavePhase);
float r2 = 0.88 + 0.035 * sin(TAU * wavePhase - 0.9);
float r3 = 1.18 + 0.03 * sin(TAU * wavePhase - 1.8);
float r4 = 1.38 + 0.025 * sin(TAU * wavePhase - 2.6);
// Slight organic comic wobble on rings
float ringWob = 0.012 * sin(ang * 7.0 + TAU * wavePhase) + 0.008 * cos(ang * 13.0);
float d1 = abs(r - r1 + ringWob * 0.6);
float d2 = abs(r - r2 - ringWob * 0.8);
float d3 = abs(r - r3 + ringWob * 0.7);
float d4 = abs(r - r4 - ringWob * 0.5);
// Ring thicknesses (outer ring is thickest & boldest, inner rings crisp)
float ringCore = 0.0;
ringCore = max(ringCore, 1.0 - smoothstep(0.018, 0.030, d1));
ringCore = max(ringCore, 1.0 - smoothstep(0.024, 0.038, d2));
ringCore = max(ringCore, 1.0 - smoothstep(0.016, 0.028, d3));
ringCore = max(ringCore, 1.0 - smoothstep(0.044, 0.062, d4));
// Hot magenta aura immediately framing each white ring
float ringGlow = 0.0;
ringGlow = max(ringGlow, 1.0 - smoothstep(0.026, 0.085, d1));
ringGlow = max(ringGlow, 1.0 - smoothstep(0.034, 0.105, d2));
ringGlow = max(ringGlow, 1.0 - smoothstep(0.024, 0.075, d3));
ringGlow = max(ringGlow, 1.0 - smoothstep(0.056, 0.155, d4));
// Travelling pulse wave sweeping radially outward from center to outer ring
float pulseR = mix(0.25, 1.50, fract(wavePhase * 2.0));
float pulseBand = exp(-pow((r - pulseR) * 5.0, 2.0)) * smoothstep(1.58, 1.28, r);
// Dark ink outer edge right outside the outermost ring (comic grounding)
float outerInk = smoothstep(0.11, 0.06, abs(r - (r4 + 0.095)));
// ------------------------------------------------------------------------
// 2. Jagged Starburst Radial Spikes (10 iconic lance/arrow spikes!)
// ------------------------------------------------------------------------
float spikeCore = 0.0;
float spikeGlow = 0.0;
float spikeInk = 0.0;
const int NUM_SPIKES = 10;
for (int i = 0; i < NUM_SPIKES; i++) {
float fi = float(i);
// Uneven comic spacing so it feels hand-drawn, not robotic
float baseAng = fi * (TAU / float(NUM_SPIKES)) + 0.18 * sin(fi * 2.7) + 0.16;
float ca = cos(baseAng), sa = sin(baseAng);
// Local coordinates along spike axis (lx = outward, ly = perpendicular)
float lx = p.x * ca + p.y * sa;
float ly = -p.x * sa + p.y * ca;
// Alternating long dramatic spikes and medium spikes
float spikeLen = mix(1.88, 2.38, hash11(fi * 7.31 + 1.2));
// Make front-pointing spike extra dramatic (matches 08.png bottom center)
if (i == 2) spikeLen = 2.52;
spikeLen += 0.08 * sin(TAU * wavePhase + fi * 1.7);
float startR = 1.18;
float t = (lx - startR) / max(spikeLen - startR, 0.1);
if (t > -0.08 && t < 1.08) {
// Arrow/lance profile: flares out slightly near base with a comic notch, tapers to razor tip
float tClamped = clamp(t, 0.0, 1.0);
float baseW = mix(0.115, 0.155, hash11(fi * 3.1 + 4.0));
float notch = 1.0 - 0.35 * exp(-pow((tClamped - 0.14) * 14.0, 2.0));
float halfW = baseW * pow(max(1.0 - tClamped, 0.0), 1.15) * notch;
// Taper smoothly at the inner root
halfW *= smoothstep(-0.06, 0.08, t);
float dSpike = abs(ly) - halfW;
// Sharp outer tip cutoff
float tipMask = smoothstep(1.03, 0.96, t) * smoothstep(-0.06, 0.04, t);
float scMask = (1.0 - smoothstep(-0.012, 0.008, dSpike)) * tipMask;
float sgMask = (1.0 - smoothstep(0.005, 0.068, dSpike)) * tipMask;
float siMask = smoothstep(0.075, 0.035, abs(dSpike - 0.045)) * smoothstep(0.02, 0.15, t) * tipMask;
spikeCore = max(spikeCore, scMask);
spikeGlow = max(spikeGlow, sgMask);
spikeInk = max(spikeInk, siMask * 0.75);
}
}
// Secondary tiny razor needles between main spikes
for (int i = 0; i < 8; i++) {
float fi = float(i);
float baseAng = (fi + 0.5) * (TAU / 8.0) + 0.25 * cos(fi * 4.1);
float ca = cos(baseAng), sa = sin(baseAng);
float lx = p.x * ca + p.y * sa;
float ly = -p.x * sa + p.y * ca;
float t = (lx - 1.32) / 0.42;
if (t > 0.0 && t < 1.0) {
float halfW = 0.035 * (1.0 - t);
float dMini = abs(ly) - halfW;
spikeCore = max(spikeCore, 1.0 - smoothstep(-0.004, 0.008, dMini));
spikeGlow = max(spikeGlow, 1.0 - smoothstep(0.004, 0.035, dMini));
}
}
// ------------------------------------------------------------------------
// 3. Central Jagged Comic Starburst Flash at the Epicenter
// ------------------------------------------------------------------------
float starRays = 0.28
+ 0.22 * pow(0.5 + 0.5 * sin(ang * 9.0 + 0.4), 3.0)
+ 0.18 * pow(0.5 + 0.5 * sin(ang * 15.0 - 1.2 + TAU * wavePhase * 0.0), 4.0)
+ 0.10 * sin(ang * 5.0 + 2.1);
starRays *= (0.94 + 0.10 * anim.pulse);
float dStar = r - starRays;
float centerCore = 1.0 - smoothstep(-0.03, 0.02, dStar);
float centerGlow = 1.0 - smoothstep(0.01, 0.19, dStar);
// ------------------------------------------------------------------------
// 4. Radial Ground Lightning Tendrils crawling from center out to spikes
// ------------------------------------------------------------------------
float boltCore = 0.0;
float boltGlow = 0.0;
const int NUM_BOLTS = 6;
for (int i = 0; i < NUM_BOLTS; i++) {
float fi = float(i);
float bAng = fi * (TAU / float(NUM_BOLTS)) + 0.35 + 0.22 * sin(fi * 3.7);
float ca = cos(bAng), sa = sin(bAng);
float lx = p.x * ca + p.y * sa;
float ly = -p.x * sa + p.y * ca;
if (lx > 0.12 && lx < 1.85) {
// Sharp zig-zag polyline offset
float segPos = lx * 4.2;
float segIdx = floor(segPos);
float segF = fract(segPos);
float j0 = (hash11(segIdx * 13.7 + fi * 41.3 + anim.boltJitter * 0.17) - 0.5) * 0.26;
float j1 = (hash11((segIdx + 1.0) * 13.7 + fi * 41.3 + anim.boltJitter * 0.17) - 0.5) * 0.26;
float zigY = mix(j0, j1, segF) * smoothstep(0.12, 0.45, lx) * smoothstep(1.85, 1.45, lx);
float dBolt = abs(ly - zigY);
float thick = mix(0.024, 0.008, lx / 1.85);
boltCore = max(boltCore, 1.0 - smoothstep(thick * 0.5, thick * 1.4, dBolt));
boltGlow = max(boltGlow, 1.0 - smoothstep(thick, thick * 4.5, dBolt));
}
}
// ------------------------------------------------------------------------
// 5. Detached Flying Comic Spark Dashes around outer perimeter
// ------------------------------------------------------------------------
float sparkMask = 0.0;
for (int i = 0; i < 8; i++) {
float fi = float(i);
float sAng = fi * (TAU / 8.0) + 0.65;
float ca = cos(sAng), sa = sin(sAng);
float lx = p.x * ca + p.y * sa;
float ly = -p.x * sa + p.y * ca;
float travel = fract(wavePhase + hash11(fi * 5.9));
float sr = mix(1.52, 2.15, travel);
vec2 sd = segDist2D(vec2(lx, ly), vec2(sr, 0.0), vec2(sr + 0.18, 0.0));
float fade = smoothstep(0.0, 0.15, travel) * smoothstep(1.0, 0.65, travel);
sparkMask = max(sparkMask, (1.0 - smoothstep(0.008, 0.022, sd.x)) * fade);
}
// Combine crisp cel layers
float totalCore = clamp(max(max(ringCore, spikeCore), max(centerCore, max(boltCore, sparkMask))), 0.0, 1.0);
float totalGlow = clamp(max(max(ringGlow, spikeGlow), max(centerGlow, boltGlow)), 0.0, 1.0);
// Stylized 2-tier energy color: hot neon magenta halo + blazing white-pink core
vec3 glowCol = mix(COL_MAGENTA_DEEP, COL_MAGENTA_HOT, smoothstep(0.15, 0.65, totalGlow));
glowCol = mix(glowCol, COL_MAGENTA_NEON, smoothstep(0.55, 0.92, totalGlow));
vec3 coreCol = mix(glowCol, COL_WHITE_CORE, smoothstep(0.25, 0.72, totalCore));
// Boost brightness cleanly (will be soft-tonemapped below 1.0 clip)
float energyBoost = 1.35 + 0.25 * pulseBand + 0.20 * centerCore;
res.emissive = coreCol * energyBoost * max(totalGlow, totalCore);
res.alpha = clamp(max(totalCore, totalGlow * 0.92), 0.0, 1.0);
res.inkMask = clamp(max(outerInk, spikeInk) * (1.0 - totalGlow * 0.85), 0.0, 1.0);
// Quantized cel-banded floor illumination from the plasma blast
float rawGlow = exp(-r * 0.78) * 1.15 + 0.35 * exp(-abs(r - r4) * 2.4);
float qGlow = floor(clamp(rawGlow, 0.0, 1.0) * 3.5) / 3.5;
res.floorGlow = mix(rawGlow, qGlow, 0.65);
return res;
}
// ----------------------------------------------------------------------------
// 3D Vertical Zig-Zag Magenta-White Lightning Strike + Secondary Forks
// ----------------------------------------------------------------------------
vec4 evalVerticalLightning(vec3 ro, vec3 rd, float maxT, AnimState anim) {
// 6-vertex dramatic zig-zag bolt from y = 0.04 up to y = 2.75
// Matches the iconic jagged S-curve spear silhouette in 08.png
float j = anim.boltJitter;
float sway = 0.06 * sin(TAU * anim.phase);
float flick1 = (hash11(j * 3.7 + 1.1) - 0.5) * 0.08;
float flick2 = (hash11(j * 5.3 + 2.7) - 0.5) * 0.08;
float flick3 = (hash11(j * 7.1 + 4.3) - 0.5) * 0.06;
vec3 pts[6];
pts[0] = vec3( 0.00, 0.02, 0.00);
pts[1] = vec3( 0.07 + sway + flick1, 0.52, -0.04);
pts[2] = vec3(-0.08 - sway + flick2, 1.04, 0.05);
pts[3] = vec3( 0.16 + sway + flick3, 1.56, -0.05);
pts[4] = vec3(-0.09 + flick1 * 0.7, 2.12, 0.03);
pts[5] = vec3( 0.02, 2.82, 0.00);
float coreMask = 0.0;
float glowMask = 0.0;
float hitT = maxT;
// Main vertical bolt segments
for (int i = 0; i < 5; i++) {
vec3 dInfo = raySegDist(ro, rd, pts[i], pts[i + 1]);
float dist = dInfo.x;
float segT = dInfo.y;
float rayT = dInfo.z;
if (rayT < maxT && rayT > 0.05) {
float hFrac = (float(i) + segT) / 5.0;
// Thickest at impact base, tapering to a needle spear at the top
float baseRad = mix(0.085, 0.008, pow(hFrac, 0.85));
// Slight flare at sharp elbow bends
float elbow = 1.0 + 0.25 * exp(-pow((segT - 0.5) * 4.0, 2.0)) * (1.0 - hFrac);
float rad = baseRad * elbow;
float c = 1.0 - smoothstep(rad * 0.55, rad * 1.15, dist);
float g = 1.0 - smoothstep(rad * 1.05, rad * 3.20, dist);
if (g > glowMask) hitT = min(hitT, rayT);
coreMask = max(coreMask, c);
glowMask = max(glowMask, g);
}
}
// Secondary forked electric crackles branching off the main bolt
vec3 f1a = pts[1];
vec3 f1b = pts[1] + vec3(0.24, 0.38, 0.08);
vec3 f1c = f1b + vec3(-0.06, 0.34, -0.05);
vec3 f2a = pts[2];
vec3 f2b = pts[2] + vec3(-0.26, 0.34, -0.06);
vec3 f2c = f2b + vec3(-0.10, 0.36, 0.08);
vec3 f3a = pts[3];
vec3 f3b = pts[3] + vec3(-0.22, -0.26, 0.06);
vec3 forksA[5];
vec3 forksB[5];
forksA[0] = f1a; forksB[0] = f1b;
forksA[1] = f1b; forksB[1] = f1c;
forksA[2] = f2a; forksB[2] = f2b;
forksA[3] = f2b; forksB[3] = f2c;
forksA[4] = f3a; forksB[4] = f3b;
for (int i = 0; i < 5; i++) {
vec3 dInfo = raySegDist(ro, rd, forksA[i], forksB[i]);
if (dInfo.z < maxT && dInfo.z > 0.05) {
float rad = mix(0.016, 0.004, dInfo.y);
coreMask = max(coreMask, 1.0 - smoothstep(rad * 0.5, rad * 1.2, dInfo.x));
glowMask = max(glowMask, 1.0 - smoothstep(rad, rad * 3.8, dInfo.x));
}
}
// Floating vertical pink spark shards around the bolt (just like 08.png)
for (int i = 0; i < 6; i++) {
float fi = float(i);
float a = fi * 1.15 + 0.4;
float radR = mix(0.32, 0.58, hash11(fi * 9.3 + 1.0));
float rise = fract(anim.phase + hash11(fi * 4.7));
float y0 = mix(0.55, 2.05, rise);
vec3 sa = vec3(cos(a) * radR, y0, sin(a) * radR * 0.55);
vec3 sb = sa + vec3(cos(a) * 0.05, 0.22, sin(a) * 0.03);
vec3 dInfo = raySegDist(ro, rd, sa, sb);
if (dInfo.z < maxT && dInfo.z > 0.05) {
float fade = smoothstep(0.0, 0.15, rise) * smoothstep(1.0, 0.7, rise);
float sc = (1.0 - smoothstep(0.006, 0.015, dInfo.x)) * fade;
float sg = (1.0 - smoothstep(0.012, 0.045, dInfo.x)) * fade;
coreMask = max(coreMask, sc);
glowMask = max(glowMask, sg);
}
}
vec3 boltCol = mix(COL_MAGENTA_HOT * 1.35, COL_MAGENTA_NEON * 1.55, smoothstep(0.25, 0.8, glowMask));
boltCol = mix(boltCol, COL_WHITE_CORE * 1.75, smoothstep(0.18, 0.72, coreMask));
float alpha = clamp(max(coreMask, glowMask * 0.95), 0.0, 1.0);
return vec4(boltCol * alpha, alpha);
}
// ----------------------------------------------------------------------------
// Dark Ink-Grouted Charcoal Tiled Arena Floor Shading
// ----------------------------------------------------------------------------
vec3 shadeArenaFloor(vec3 p, vec3 rd, AnimState anim, vec3 lightDir) {
// Rotate tile grid slightly for dynamic diagonal comic composition (matches 08.png)
vec2 gPos = rot2(0.32) * p.xz;
vec2 tileScale = vec2(1.45, 1.45);
vec2 cellId = floor(gPos / tileScale);
vec2 cellUv = fract(gPos / tileScale) - 0.5;
// Distance to grout lines (bold dark comic ink seams)
vec2 edgeDist = 0.5 - abs(cellUv);
float minEdge = min(edgeDist.x, edgeDist.y);
float groutWidth = 0.022;
float groutInk = 1.0 - smoothstep(groutWidth * 0.75, groutWidth * 1.35, minEdge);
// Subtle secondary bevel highlight next to grout lines
float bevelEdge = smoothstep(groutWidth * 1.2, groutWidth * 2.2, minEdge)
* (1.0 - smoothstep(groutWidth * 2.2, groutWidth * 4.0, minEdge));
// Per-tile tonal variation + subtle quantized comic concrete grunge
float tileVar = (hash21(cellId) - 0.5) * 0.022;
float grunge = fbm2(gPos * 3.8);
float grungeQ = floor(grunge * 3.0) / 3.0;
vec3 floorCol = COL_FLOOR_BASE + vec3(tileVar) + (grungeQ - 0.5) * vec3(0.018, 0.019, 0.024);
floorCol += bevelEdge * vec3(0.025, 0.028, 0.038);
// Circular outer arena rim + hot-magenta trim panels (seen at top of 08.png)
float arenaR = length(p.xz);
float rimInner = 4.35;
float rimOuter = 4.75;
if (arenaR > rimInner - 0.15) {
float rimBand = smoothstep(rimInner - 0.04, rimInner + 0.02, arenaR)
* (1.0 - smoothstep(rimOuter - 0.02, rimOuter + 0.04, arenaR));
float rimAng = atan(p.z, p.x);
float panelSeg = fract(rimAng * 12.0 / TAU);
float panelSeam = 1.0 - smoothstep(0.03, 0.06, min(panelSeg, 1.0 - panelSeg));
float litPanel = step(0.18, hash11(floor(rimAng * 12.0 / TAU) * 7.3 + 2.0));
vec3 rimCol = mix(vec3(0.11, 0.12, 0.16), COL_ARENA_TRIM * 0.85, litPanel);
rimCol = mix(rimCol, COL_INK, panelSeam * 0.9);
floorCol = mix(floorCol, rimCol, rimBand);
// Bold ink borders on the arena curb
float curbInk = (1.0 - smoothstep(0.02, 0.05, abs(arenaR - rimInner)))
+ (1.0 - smoothstep(0.02, 0.05, abs(arenaR - rimOuter)));
floorCol = mix(floorCol, COL_INK, clamp(curbInk, 0.0, 1.0));
// Darker matte outer arena void beyond the curb
float beyond = smoothstep(rimOuter, rimOuter + 0.15, arenaR);
floorCol = mix(floorCol, COL_FLOOR_DARK, beyond);
}
// Apply bold ink grout lines inside the arena
float insideArena = 1.0 - smoothstep(rimInner - 0.05, rimInner + 0.02, arenaR);
floorCol = mix(floorCol, COL_INK, groutInk * insideArena * 0.92);
// LightMode directional tint on floor
if (uLightMode == 2) {
floorCol *= vec3(0.92, 1.00, 1.18);
}
// Crisp hard-edged comic drop shadow cast by the smoke clouds onto the floor
vec3 shPos = p + vec3(lightDir.x * 0.18, 0.18, lightDir.z * 0.18);
float dSmoke = mapSmokeDist(shPos, anim);
float dropShadow = 1.0 - smoothstep(0.02, 0.16, dSmoke);
floorCol = mix(floorCol, COL_INK * 1.15, dropShadow * 0.78);
// Evaluate the neon magenta plasma blast on the floor
BlastGround blast = evalGroundBlast(p.xz, anim);
float emitScale = (uLightMode == 1) ? 0.38 : 1.0;
// Add cel-banded neon magenta bounce light onto the charcoal tiles
vec3 bounceCol = mix(COL_MAGENTA_DEEP, COL_MAGENTA_HOT, 0.6) * blast.floorGlow * 0.42 * emitScale;
// Slight magenta rim glow in the grout lines near the explosion!
float neonGrout = groutInk * insideArena * smoothstep(2.6, 1.2, arenaR) * 0.55 * emitScale;
floorCol += bounceCol * (1.0 - dropShadow * 0.5) + COL_MAGENTA_HOT * neonGrout * 0.35;
// Apply dark comic ink edge around rings/spikes
floorCol = mix(floorCol, COL_INK, blast.inkMask * 0.85);
// Composite crisp blazing shockwave rings, spikes, and ground bolts
floorCol = mix(floorCol, blast.emissive * mix(0.55, 1.0, emitScale), blast.alpha);
// Atmospheric depth fade into dark charcoal-violet arena wall at far distance
float distFade = smoothstep(5.5, 12.5, length(p.xz));
vec3 farBg = vec3(0.042, 0.040, 0.062);
floorCol = mix(floorCol, farBg, distFade);
return floorCol;
}
// ----------------------------------------------------------------------------
// Cel-Shaded 3-Band Stylized Violet Smoke Shading with Ink Contours
// ----------------------------------------------------------------------------
vec3 shadeSmoke(vec3 p, vec3 N, vec3 V, float crease, AnimState anim, vec3 keyDir) {
// 1. Primary light from overhead key + strong magenta light from epicenter (0, 0.35, 0)
vec3 toCenter = vec3(0.0, 0.35, 0.0) - p;
float distCenter = length(toCenter);
vec3 blastDir = toCenter / max(distCenter, 1e-5);
float ndlKey = dot(N, keyDir);
float ndlBlast = dot(N, blastDir);
float blastAtten = 1.0 / (1.0 + 0.18 * distCenter * distCenter);
// Combine lighting scalar for 3-band quantized cel shading
float lit = ndlKey * 0.55 + ndlBlast * blastAtten * 0.85 + 0.25;
// Quantize into 3 crisp stylized comic bands (Shadow -> Mid -> Lit)
float band1 = smoothstep(0.14, 0.18, lit);
float band2 = smoothstep(0.54, 0.59, lit);
vec3 col = mix(COL_SMOKE_SHAD, COL_SMOKE_MID, band1);
col = mix(col, COL_SMOKE_LIT, band2);
// LightMode adjustments
if (uLightMode == 2) {
col = mix(col, col * vec3(0.84, 0.96, 1.22), 0.7);
}
// Hot-magenta rim highlight on puff edges facing the plasma epicenter
float ndv = clamp(dot(N, V), 0.0, 1.0);
float fresnel = 1.0 - ndv;
float rimScale = (uLightMode == 1) ? 0.25 : 0.85;
float blastRim = smoothstep(0.45, 0.75, fresnel) * smoothstep(0.05, 0.45, ndlBlast) * blastAtten;
col = mix(col, COL_SMOKE_RIM * 1.15, clamp(blastRim * rimScale, 0.0, 0.85));
// Bold black-ink Fresnel contour + internal lobe crease lines
float inkFresnel = smoothstep(0.27, 0.17, ndv);
float inkCrease = smoothstep(0.42, 0.72, crease) * 0.92;
float inkMask = clamp(max(inkFresnel, inkCrease), 0.0, 1.0);
col = mix(col, COL_INK, inkMask);
return col;
}
// ----------------------------------------------------------------------------
// Camera Setup (4 uCamMode presets)
// ----------------------------------------------------------------------------
void setupCamera(out vec3 ro, out vec3 ta, out float fl, AnimState anim) {
if (uCamMode == 1) {
// Low dramatic heroic angle looking across the shockwave rings up at the strike
ro = vec3(0.45, 1.42, 3.95);
ta = vec3(0.00, 0.62, 0.00);
fl = 1.45;
} else if (uCamMode == 2) {
// High tactical top-down view showing full concentric starburst & smoke ring
ro = vec3(0.00, 5.10, 1.55);
ta = vec3(0.00, 0.05, 0.10);
fl = 1.60;
} else if (uCamMode == 3) {
// Smooth 3-second orbital showcase
float a = TAU * anim.phase * 0.5 - 0.35;
ro = vec3(sin(a) * 3.85, 2.75, cos(a) * 3.85);
ta = vec3(0.00, 0.38, 0.00);
fl = 1.55;
} else {
// Default Hero 3/4 Elevated Arena View (matches 08.png composition)
ro = vec3(0.00, 3.12, 3.62);
ta = vec3(0.00, 0.34, 0.05);
fl = 1.56;
}
}
// ----------------------------------------------------------------------------
// Stylized Filmic Tone Mapping (punchy neon saturation, <1% clip, <2% black)
// ----------------------------------------------------------------------------
vec3 stylizedTonemap(vec3 c) {
// Soft shoulder curve that preserves vibrant magenta/violet hue and prevents clipping
c = max(c, vec3(0.0));
if (uLightMode == 1) {
float lum = dot(c, vec3(0.2126, 0.7152, 0.0722));
c = vec3(lum);
}
vec3 mapped = (c * (2.51 * c + 0.03)) / (c * (2.43 * c + 0.59) + 0.14);
// Keep peak safely under 0.975 so <1% clip is guaranteed even at white-hot core
mapped = mapped * 0.965;
// Gamma encode to sRGB
vec3 srgb = pow(clamp(mapped, 0.0, 0.98), vec3(1.0 / 2.2));
// Subtle dark ink floor lift so deep ink reads crisp jet-black without pure-black crush
vec3 inkFloor = (uLightMode == 1) ? vec3(0.036) : vec3(0.032, 0.030, 0.044);
srgb = max(srgb, inkFloor);
if (uLightMode == 1) {
srgb = vec3(dot(srgb, vec3(0.2126, 0.7152, 0.0722)));
}
return clamp(srgb, 0.0, 0.985);
}
// ----------------------------------------------------------------------------
// Main
// ----------------------------------------------------------------------------
void main() {
vec2 res = max(uResolution, vec2(1.0));
vec2 uv = (gl_FragCoord.xy - 0.5 * res) / min(res.x, res.y);
AnimState anim = getAnim();
vec3 ro, ta;
float fl;
setupCamera(ro, ta, fl, anim);
vec3 ww = normalize(ta - ro);
vec3 uu = normalize(cross(ww, vec3(0.0, 1.0, 0.0)));
vec3 vv = cross(uu, ww);
vec3 rd = normalize(uv.x * uu + uv.y * vv + fl * ww);
// Key light direction by uLightMode
vec3 keyDir = normalize(vec3(-0.35, 0.85, 0.40));
if (uLightMode == 1) {
keyDir = normalize(vec3(0.45, 0.78, 0.42));
} else if (uLightMode == 2) {
keyDir = normalize(vec3(-0.62, 0.65, -0.44));
}
// 1. Background sky / upper arena wall gradient (dark matte charcoal-indigo)
float skyGrad = clamp(rd.y * 1.5 + 0.35, 0.0, 1.0);
vec3 col = mix(vec3(0.042, 0.040, 0.062), vec3(0.022, 0.020, 0.036), skyGrad);
// Subtle distant magenta atmospheric glow behind the vertical strike
float bgGlow = exp(-length(uv - vec2(0.0, 0.10)) * 2.2) * ((uLightMode == 1) ? 0.03 : 0.12);
col += COL_MAGENTA_DEEP * bgGlow;
// 2. Analytic intersection with the arena floor plane (y = 0)
float tFloor = 1e5;
if (rd.y < -1e-4) {
float tf = -ro.y / rd.y;
if (tf > 0.0 && tf < 30.0) {
tFloor = tf;
vec3 pFloor = ro + rd * tFloor;
col = shadeArenaFloor(pFloor, rd, anim, keyDir);
}
}
// 3. Raymarch 3D chunky ink-outlined violet smoke clouds
float tMax = min(tFloor, 14.0);
float t = 0.25;
bool hitSmoke = false;
vec3 pHit = vec3(0.0);
float hitCrease = 0.0;
float minRatio = 1e5;
float prevD = 1e5;
for (int i = 0; i < 68; i++) {
if (t > tMax) break;
vec3 p = ro + rd * t;
vec2 m = mapSmoke(p, anim);
float d = m.x;
// Track near-miss silhouette edge for crisp uniform comic ink outline
if (d > prevD && t > 0.5) {
minRatio = min(minRatio, prevD / t);
}
prevD = d;
if (d < 0.0035) {
hitSmoke = true;
pHit = p;
hitCrease = m.y;
break;
}
t += max(d * 0.85, 0.015);
}
float sceneDepth = tFloor;
if (hitSmoke) {
sceneDepth = t;
vec3 N = calcSmokeNormal(pHit, anim);
vec3 smokeCol = shadeSmoke(pHit, N, -rd, hitCrease, anim, keyDir);
// Allow inner shockwave ring glow to subtly kiss the lower edge of inner smoke
float edgeKiss = smoothstep(0.28, 0.02, pHit.y) * smoothstep(2.0, 1.2, length(pHit.xz));
smokeCol += COL_MAGENTA_HOT * edgeKiss * ((uLightMode == 1) ? 0.06 : 0.28);
col = smokeCol;
} else if (minRatio < 0.011) {
// Crisp outer black-ink comic silhouette halo around missed grazing smoke edges
float outlineMask = 1.0 - smoothstep(0.004, 0.011, minRatio);
col = mix(col, COL_INK, outlineMask * 0.90);
}
// 4. Composite 3D vertical zig-zag magenta-white lightning strike + forks + shards
vec4 bolt = evalVerticalLightning(ro, rd, sceneDepth + 0.35, anim);
float boltScale = (uLightMode == 1) ? 0.55 : 1.0;
vec3 boltRgb = bolt.rgb * boltScale;
col = mix(col, col + boltRgb, clamp(bolt.a, 0.0, 1.0));
// Ensure crisp opaque white core punches right over dark background & smoke
col = mix(col, boltRgb, smoothstep(0.65, 0.95, bolt.a));
// Subtle vignette to frame the arena blast without crushing corners
float vig = 1.0 - 0.18 * dot(uv, uv);
col *= clamp(vig, 0.72, 1.0);
fragColor = vec4(stylizedTonemap(col), 1.0);
}
`;
export function createNeonMagentaPlasmaGrenadeMaterial(width = 1024, height = 1024) {
const material = new THREE.ShaderMaterial({
glslVersion: THREE.GLSL3,
vertexShader,
fragmentShader,
uniforms: {
uResolution: { value: new THREE.Vector2(width, height) },
uTime: { value: 1.2 },
uOpen: { value: 0.0 },
uLightMode: { value: 0 },
uCamMode: { value: 0 },
},
});
return {
material,
update(elapsedSeconds) {
material.uniforms.uTime.value = elapsedSeconds * 1.0;
},
resize(nextW, nextH) {
material.uniforms.uResolution.value.set(nextW, nextH);
},
};
}
| Identifier | neon-magenta-plasma-grenade |
|---|---|
| Category | Game VFX Shaders · Stylized Cel VFX |
| Upstream study | vfx_stylized/lib/08_neon_magenta_plasma_grenade.glsl (commit f5bfb61) |
| Animation cycle | 3.0 s seamless harmonic loop |
| Declared uniforms | uResolution, uTime, uOpen, uLightMode, uCamMode |
| Source size | 896 lines · 37.1 KB standalone GLSL ES 3.00 |
| PNG baker outputs | 512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key) |
| Companion pixel VFX | Free MIT scifi sprite sheets |
| License | MIT License + CC0 / MIT Helpers |
Schlick Fresnel reflectance (1994); Beer–Lambert volumetric absorption/attenuation
David Hoskins, hash · Krzysztof Narkowicz, filmic curve · Inigo Quilez, quadratic distance blend
3s LoopWhip-fast cel-shaded jade wind vortex with crisp white slipstream bands and swirling leaves.
3s LoopNinjutsu indigo smoke bomb cloud with cel-stepped billowing lobes and glowing ember eyes.
AnimatedVolumetric blackbody fireball mushrooming into self-shadowed soot lobes with Beer–Lambert absorption.
AnimatedStar-shaped weapon muzzle jet with Mach shock cone, incandescent propellant gas, and sparks.
AnimatedHigh-explosive Wilson cloud condensation shell expanding ahead of incandescent core debris.
AnimatedTurbulent burning fuel pool casting orange blackbody illumination through thick rising soot.