3s LoopSweeping twin solar-flame wings unfurling upward with molten feather embers.
rapid-combo-slash-flurry.glsl · 835 lines · GLSL ES 3.00 · MIT
#version 300 es
// Rapid Combo Slash Flurry (rapid-combo-slash-flurry.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_animated/lib/05_rapid_combo_slash_flurry.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;
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
const vec3 CENTER = vec3(0.0, 1.24, 0.0);
// -----------------------------------------------------------------------------
// Fast procedural hashes, value noise & domain-warped fBM (zero textures)
// -----------------------------------------------------------------------------
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);
}
vec2 hash22(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.xx + p3.yz) * p3.zy);
}
float vnoise(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
f = 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, f.x), mix(c, d, f.x), f.y);
}
float fbm3(vec2 p) {
float v = 0.0;
float a = 0.5;
mat2 rot = mat2(0.80, 0.60, -0.60, 0.80);
for (int i = 0; i < 3; i++) {
v += a * vnoise(p);
p = rot * p * 2.05 + vec2(13.7, 29.3);
a *= 0.5;
}
return v;
}
// Turbulent domain-warped fBM for painterly smoky plasma wakes
float warpedFbm(vec2 p, float flow) {
vec2 q = vec2(
fbm3(p + vec2(flow * 0.7, 1.4)),
fbm3(p + vec2(5.2, flow * 0.5 + 8.3))
);
return fbm3(p + 1.85 * q);
}
// -----------------------------------------------------------------------------
// 3D & 2D rotation helpers
// -----------------------------------------------------------------------------
mat3 rotX(float a) {
float c = cos(a), s = sin(a);
return mat3(1.0, 0.0, 0.0, 0.0, c, -s, 0.0, s, c);
}
mat3 rotY(float a) {
float c = cos(a), s = sin(a);
return mat3(c, 0.0, s, 0.0, 1.0, 0.0, -s, 0.0, c);
}
mat3 rotZ(float a) {
float c = cos(a), s = sin(a);
return mat3(c, -s, 0.0, s, c, 0.0, 0.0, 0.0, 1.0);
}
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
// -----------------------------------------------------------------------------
// ACES Filmic Tonemapping (%clip < 1%)
// -----------------------------------------------------------------------------
vec3 acesFilm(vec3 x) {
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
return clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0.0, 1.0);
}
// -----------------------------------------------------------------------------
// 5 Dramatic Sweeping 3D Painterly-Volumetric Sword-Slash Ribbons
// Bold perspective tilts + expanding spiral-crescent curvature (NOT flat hoops!)
// -----------------------------------------------------------------------------
struct SlashDef {
mat3 basis; // columns: U, V, N
vec3 offset; // 3D center offset for dynamic depth layering
vec2 radii; // (rx, ry) major/minor sweep scale
float maxWidth; // wide dramatic crescent belly (0.34..0.44)
float spiral; // radial expansion from tail to head (breaks circular hoop look!)
float startAng; // strike start angle
float dir; // +1 or -1 sweep direction
float phaseOff; // staggered k/5.0 combo offset
vec3 colCore; // incandescent leading blade spine
vec3 colMid; // vibrant plasma body
vec3 colSmoke; // deep turbulent smoky wake
float electric; // crackling lightning arc intensity
};
SlashDef getSlash(int k) {
SlashDef s;
if (k == 0) {
// 1. Electric Cyan Hero Slash: dramatic sweeping upper-left to lower-right
s.basis = rotZ(-0.48) * rotX(0.58) * rotY(0.28);
s.offset = vec3(-0.08, 0.10, 0.06);
s.radii = vec2(1.66, 1.12);
s.maxWidth = 0.42;
s.spiral = 0.24;
s.startAng = 2.75;
s.dir = -1.0;
s.phaseOff = 0.06;
s.colCore = vec3(0.86, 0.99, 1.00);
s.colMid = vec3(0.02, 0.86, 1.00);
s.colSmoke = vec3(0.01, 0.22, 0.72);
s.electric = 1.0;
} else if (k == 1) {
// 2. Solar Gold Hero Slash: bold counter-diagonal lower-left to upper-right
s.basis = rotZ(0.42) * rotX(0.56) * rotY(-0.30);
s.offset = vec3(0.06, 0.02, -0.05);
s.radii = vec2(1.62, 1.08);
s.maxWidth = 0.40;
s.spiral = 0.22;
s.startAng = -2.20;
s.dir = 1.0;
s.phaseOff = 0.86;
s.colCore = vec3(1.00, 0.97, 0.80);
s.colMid = vec3(1.00, 0.64, 0.06);
s.colSmoke = vec3(0.76, 0.16, 0.01);
s.electric = 0.35;
} else if (k == 2) {
// 3. Hot Magenta-Crimson Slash: steep whipping diagonal across front-center
s.basis = rotZ(0.68) * rotX(-0.50) * rotY(0.26);
s.offset = vec3(0.04, 0.04, 0.12);
s.radii = vec2(1.48, 0.96);
s.maxWidth = 0.38;
s.spiral = 0.26;
s.startAng = -1.45;
s.dir = 1.0;
s.phaseOff = 0.26;
s.colCore = vec3(1.00, 0.84, 0.94);
s.colMid = vec3(1.00, 0.08, 0.54);
s.colSmoke = vec3(0.55, 0.02, 0.36);
s.electric = 0.75;
} else if (k == 3) {
// 4. Fiery Crimson-Scarlet Cross-Slash: sweeping low-to-high foreground arc
s.basis = rotZ(-0.22) * rotX(0.68) * rotY(-0.36);
s.offset = vec3(-0.02, 0.00, 0.14);
s.radii = vec2(1.46, 0.88);
s.maxWidth = 0.35;
s.spiral = 0.20;
s.startAng = 2.05;
s.dir = -1.0;
s.phaseOff = 0.46;
s.colCore = vec3(1.00, 0.86, 0.68);
s.colMid = vec3(1.00, 0.18, 0.05);
s.colSmoke = vec3(0.58, 0.02, 0.02);
s.electric = 0.25;
} else {
// 5. Electric Cyan-Gold High Orbital Slash: deep background/foreground weave
s.basis = rotZ(-0.76) * rotX(-0.46) * rotY(-0.32);
s.offset = vec3(0.08, 0.08, -0.10);
s.radii = vec2(1.38, 0.98);
s.maxWidth = 0.36;
s.spiral = 0.25;
s.startAng = 0.75;
s.dir = -1.0;
s.phaseOff = 0.66;
s.colCore = vec3(0.90, 0.99, 1.00);
s.colMid = vec3(0.08, 0.78, 1.00);
s.colSmoke = vec3(0.04, 0.20, 0.68);
s.electric = 0.85;
}
return s;
}
// -----------------------------------------------------------------------------
// Evaluate a single volumetric slice of a painterly 3D sword-slash smear ribbon
// -----------------------------------------------------------------------------
vec4 evalSlashSlice(
SlashDef sl,
vec3 ro,
vec3 rd,
float pk,
float maxT,
float sliceOff, // volumetric offset along normal N
float sliceWeight, // Gaussian thickness weight
bool isReflection,
out float hitT
) {
hitT = 1e6;
vec3 U = sl.basis[0];
vec3 V = sl.basis[1];
vec3 N = sl.basis[2];
vec3 C = CENTER + sl.offset + N * sliceOff;
float denom = dot(rd, N);
float absDenom = abs(denom);
if (absDenom < 0.03) return vec4(0.0);
float t = dot(C - ro, N) / denom;
if (t <= 0.08 || t >= maxT) return vec4(0.0);
vec3 P = ro + rd * t;
// Smooth height fade above floor eliminates any plane/floor clip line
float floorFade = smoothstep(0.04, 0.30, P.y);
if (floorFade <= 0.001) return vec4(0.0);
vec2 p2 = vec2(dot(P - C, U), dot(P - C, V));
vec2 q = p2 / sl.radii;
float rad = length(q);
if (rad < 0.08 || rad > 1.44) return vec4(0.0);
hitT = t;
float ang = atan(q.y, q.x);
// Explosive whip-out sweep ease
float whipT = clamp(pk / 0.48, 0.0, 1.0);
float sweep = 1.0 - pow(1.0 - whipT, 2.85);
float headAng = sl.startAng + sl.dir * (sweep * 4.50 + pk * 1.15);
// Sweeping crescent angular span (strictly < 3.6 rad so head & tail never touch)
float arcLen = mix(0.65, 3.45, smoothstep(0.0, 0.18, pk))
* mix(1.0, 0.70, smoothstep(0.60, 0.96, pk));
float env = smoothstep(0.0, 0.04, pk) * (1.0 - smoothstep(0.68, 0.98, pk));
if (env <= 0.002) return vec4(0.0);
// Continuous angular distance behind the leading blade tip in [0, TAU)
float da = mod(sl.dir * (headAng - ang) + TAU * 6.0, TAU);
float u = da / max(arcLen, 0.001);
if (u <= 0.0 || u >= 1.0) return vec4(0.0);
// Smooth razor tip entry & turbulent wispy tail exit
float headFade = smoothstep(0.0, 0.035, u);
float tailFade = 1.0 - smoothstep(0.55, 1.0, u);
float inArc = headFade * tailFade;
if (inArc <= 0.001) return vec4(0.0);
// Expanding spiral-crescent outer blade contour (NOT a circular hula-hoop!)
float twist = sliceOff * 0.55 * sin(u * PI * 1.5);
float rOut = 1.08 - sl.spiral * pow(u, 0.85) + 0.04 * sin(u * PI) + twist;
// Dramatic wide crescent belly tapering to razor tip and feathered smoky wake
float belly = pow(u, 0.36) * pow(1.0 - u, 1.15) * 2.10;
float w = sl.maxWidth * clamp(belly, 0.0, 1.12);
w *= mix(1.0, 0.65, smoothstep(0.58, 0.96, pk));
// Normalized radial wake coordinate: v=0 razor leading edge, v>0 deep smoky wake
float v = (rOut - rad) / max(w, 0.004);
if (v > 1.75) return vec4(0.0);
// Domain-warped painterly brush-stroke turbulence (continuous in da, zero seam!)
float flow = da * 2.4 - pk * 8.5 + sliceOff * 6.0;
vec2 smearUV = vec2(flow * 0.85, clamp(v, -0.2, 1.6) * 5.0 + sliceOff * 2.5);
float turb = isReflection
? fbm3(smearUV * vec2(1.0, 1.4))
: warpedFbm(smearUV, flow * 0.45);
// High-frequency brushed ink/plasma motion streaks stretched along the swing
float fineStreaks = vnoise(vec2(flow * 2.6, clamp(v, -0.2, 1.6) * 20.0 + turb * 3.2));
float brushFibers = smoothstep(0.20, 0.82, turb * 0.68 + fineStreaks * 0.32);
// Razor-sharp outer cut, ZERO hard inner circular cutout!
// Exponential + domain-warped turbulent feather dissolves organically into darkness
float outerCut = smoothstep(-0.012, 0.005, rOut - rad);
float vPos = max(v, 0.0);
float innerSoftFeather = exp(-vPos * (1.75 + 2.20 * (1.0 - turb)))
* (1.0 - smoothstep(0.45, 1.45, vPos - (turb - 0.5) * 0.55))
* smoothstep(0.10, 0.36, rad);
float wakeMask = outerCut * innerSoftFeather * inArc;
// Progressive smoky dissolution across v (wake depth), u (tail), and pk (lifecycle)
float dissolve = smoothstep(0.54, 0.96, pk);
float smokeBreakup = smoothstep(
0.14 + 0.34 * vPos + 0.24 * u + 0.35 * dissolve,
0.86,
turb * 0.72 + fineStreaks * 0.28
);
float wakeDensity = wakeMask * mix(0.58 + 0.42 * brushFibers, smokeBreakup, smoothstep(0.06, 0.58, vPos));
// Incandescent razor-sharp leading blade spine & scorching tip glint
float razorSpine = exp(-abs(rad - (rOut - 0.007)) * 115.0) * headFade * (1.0 - smoothstep(0.25, 0.78, u));
float subSpine = exp(-abs(rad - (rOut - 0.028 * (1.0 + turb * 0.6))) * 65.0) * headFade * (1.0 - smoothstep(0.35, 0.85, u)) * brushFibers;
float tipFlare = exp(-abs(rad - rOut) * 48.0) * exp(-u * 14.0) * headFade;
// Hot metallic sparks & glowing embers shedding tangentially ALONG the blade trail!
float trailSparks = 0.0;
if (!isReflection && abs(sliceOff) < 0.01 && v > -0.18 && v < 1.15) {
vec2 spGrid = vec2(da * 11.0 - pk * 14.0, (rOut - rad) * 24.0);
vec2 spCell = floor(spGrid);
vec2 spF = fract(spGrid) - 0.5;
vec2 rnd = hash22(spCell + vec2(sl.phaseOff * 37.0, 11.3));
if (rnd.x > 0.62) {
vec2 off = (rnd - 0.5) * 0.52;
vec2 dSp = spF - off;
// Elongated tangential ember streak following the blade sweep
float dStreak = length(vec2(dSp.x * 0.42, dSp.y * 2.4));
trailSparks = exp(-dStreak * 13.5) * inArc * (1.0 - smoothstep(0.85, 1.15, vPos)) * (0.6 + 0.4 * rnd.y);
}
}
// 3D perspective depth emphasis: closer foreground sweeps feel bolder & richer
float depthBoost = clamp(3.5 / max(t, 1.2), 0.72, 1.45);
float angleFade = smoothstep(0.03, 0.20, absDenom) * floorFade;
// -------------------------------------------------------------------------
// uLightMode == 1: Neutral grayscale sculptural form/ribbon study (R==G==B)
// -------------------------------------------------------------------------
if (uLightMode == 1) {
vec3 Nface = (denom < 0.0) ? N : -N;
vec3 L1 = normalize(vec3(0.55, 0.80, 0.65));
vec3 L2 = normalize(vec3(-0.70, 0.35, -0.45));
float ndl1 = max(dot(Nface, L1), 0.0);
float ndl2 = max(dot(Nface, L2), 0.0);
float fres = pow(1.0 - clamp(absDenom, 0.0, 1.0), 2.4);
float shade = 0.16 + 0.54 * ndl1 + 0.18 * ndl2 + 0.24 * fres;
float val = shade * wakeDensity * 0.90 + (0.58 * razorSpine + 0.28 * subSpine + 0.40 * tipFlare + 0.55 * trailSparks);
val *= env * angleFade * sliceWeight * depthBoost;
float alpha = clamp((wakeDensity * 0.82 + razorSpine * 0.65) * env * angleFade * sliceWeight, 0.0, 1.0);
return vec4(vec3(val), alpha);
}
// -------------------------------------------------------------------------
// Hero & Lighting Modes (0, 2, 3): Painterly Volumetric Plasma + Smoke Wake
// -------------------------------------------------------------------------
float dEdge = max(rad - rOut, 0.0);
float tightAura = exp(-dEdge * (isReflection ? 20.0 : 34.0)) * inArc * (1.0 - 0.55 * u) * (0.45 + 0.55 * brushFibers);
// Localized organic branching lightning arcs peeling off the blade wake
float bolt = 0.0;
if (sl.electric > 0.15 && !isReflection && abs(sliceOff) < 0.01) {
float bFlow = da * 7.5 + pk * 11.0;
float pocket = smoothstep(0.46, 0.78, vnoise(vec2(da * 1.9 - pk * 3.5, 4.7)));
float jag1 = (fbm3(vec2(bFlow, 2.3)) - 0.5) * 0.16;
float jag2 = (vnoise(vec2(bFlow * 2.8, 9.1)) - 0.5) * 0.07;
float boltR = rOut + 0.035 + (jag1 + jag2) * pocket;
float bMask = smoothstep(0.06, 0.16, u) * (1.0 - smoothstep(0.45, 0.80, u)) * pocket;
bolt = exp(-abs(rad - boltR) * 165.0) * bMask * sl.electric;
float forkR = rOut + 0.075 + (jag1 * 1.4 - jag2 * 1.2) * pocket;
bolt += exp(-abs(rad - forkR) * 195.0) * bMask * smoothstep(0.62, 0.88, pocket) * sl.electric * 0.72;
}
// Painterly color gradient: incandescent white-hot spine -> vivid plasma -> deep smoky wake
float wakeGrad = clamp(vPos * 1.05 + (1.0 - brushFibers) * 0.35 + u * 0.25, 0.0, 1.0);
vec3 bodyCol = mix(sl.colMid, sl.colSmoke, wakeGrad);
bodyCol = mix(bodyCol, sl.colCore, clamp(exp(-vPos * 11.0) * 0.55 + subSpine * 0.50, 0.0, 1.0));
float modeGain = 1.0;
if (uLightMode == 2) {
vec3 Nface = (denom < 0.0) ? N : -N;
vec3 Lg = normalize(vec3(0.92, 0.22, 0.32));
float graze = pow(max(dot(Nface, Lg), 0.0), 2.2);
bodyCol += vec3(1.0, 0.86, 0.62) * graze * 0.42 * wakeDensity;
modeGain = 0.94;
} else if (uLightMode == 3) {
float rim = pow(1.0 - clamp(absDenom, 0.0, 1.0), 1.8);
bodyCol += vec3(0.32, 0.78, 1.0) * rim * 0.48 * wakeDensity;
modeGain = 0.96;
}
vec3 sparkTint = mix(vec3(1.0, 0.82, 0.38), sl.colCore, 0.45);
vec3 energy = bodyCol * (wakeDensity * (0.95 + 0.80 * brushFibers) * 1.32)
+ sl.colSmoke * (tightAura * 0.28)
+ sl.colMid * (tightAura * 0.16 + subSpine * 0.85)
+ sl.colCore * (razorSpine * 1.75 + tipFlare * 1.45)
+ mix(sl.colMid, sl.colCore, 0.62) * bolt * 1.95
+ sparkTint * trailSparks * 2.20;
energy *= env * angleFade * sliceWeight * depthBoost * modeGain;
float alpha = clamp((wakeDensity * 0.72 + razorSpine * 0.55) * env * angleFade * sliceWeight, 0.0, 0.95);
return vec4(energy, alpha);
}
// -----------------------------------------------------------------------------
// Multi-slice 3D Volumetric Slash Ribbon Evaluator (3 slices for hero, 1 for reflection)
// -----------------------------------------------------------------------------
vec4 evalVolumetricSlash(
SlashDef sl,
vec3 ro,
vec3 rd,
float phase,
float maxT,
bool isReflection,
out float hitT
) {
hitT = 1e6;
float pk = fract(phase + sl.phaseOff);
// Quick center-plane bounding reject before volumetric multi-slice integration
float t0;
vec4 centerHit = evalSlashSlice(sl, ro, rd, pk, maxT, 0.0, isReflection ? 1.0 : 0.52, isReflection, t0);
hitT = t0;
if (isReflection) {
return centerHit;
}
// If center plane completely missed the bounding volume, skip side slices
if (t0 > 1e5) return vec4(0.0);
// Accumulate front & back volumetric plasma thickness slices for true 3D painterly depth
float tFront, tBack;
vec4 frontHit = evalSlashSlice(sl, ro, rd, pk, maxT, 0.048, 0.34, false, tFront);
vec4 backHit = evalSlashSlice(sl, ro, rd, pk, maxT, -0.048, 0.34, false, tBack);
hitT = min(t0, min(tFront, tBack));
vec3 rgb = centerHit.rgb + frontHit.rgb + backHit.rgb;
float a = clamp(centerHit.a + frontHit.a * 0.65 + backHit.a * 0.65, 0.0, 0.96);
return vec4(rgb, a);
}
// -----------------------------------------------------------------------------
// Dynamic Clash Vortex & Kinetic Blade-Cross Core (NO generic white sunburst!)
// -----------------------------------------------------------------------------
vec3 evalClashNexus(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float phase, float maxT, bool isReflection) {
vec3 camFwd = normalize(cross(camRight, camUp));
float denom = dot(rd, camFwd);
if (abs(denom) < 0.05) return vec3(0.0);
float t = dot(CENTER - ro, camFwd) / denom;
if (t <= 0.08 || t >= maxT) return vec3(0.0);
vec3 P = ro + rd * t;
float floorFade = smoothstep(0.06, 0.40, P.y);
if (floorFade <= 0.001) return vec3(0.0);
vec3 rel = P - CENTER;
vec2 uv = vec2(dot(rel, camRight), dot(rel, camUp));
float r = length(uv);
if (r > 1.35) return vec3(0.0);
// 5-beat rapid combo strike pulse synced to the 5 ribbons
float beat = fract(phase * 5.0 + 0.06);
float hitPulse = 0.55 + 0.72 * exp(-beat * 7.5);
// 1. Swirling turbulent clash plasma vortex (compact, painterly, NOT a smooth white blob)
vec2 swirlP = rot2(r * 2.6 - phase * TAU) * uv * 3.4;
float vortexNoise = isReflection
? fbm3(swirlP)
: warpedFbm(swirlP, phase * TAU * 0.5);
float vortexMask = exp(-r * 3.4) * smoothstep(0.28, 0.82, vortexNoise);
float hotPinpoint = exp(-r * 22.0) * 1.45;
// 2. Razor-sharp kinetic cross-slash blade glints (echoing crossed katana strikes)
vec3 bladeCol = vec3(0.0);
float bladeLum = 0.0;
for (int b = 0; b < 3; b++) {
float fb = float(b);
float bBeat = fract(phase * 5.0 + fb * 0.33 + 0.04);
float bEnv = 0.38 + 0.62 * exp(-bBeat * 5.5);
float bAng = (b == 0) ? -0.78 : ((b == 1) ? 0.56 : 1.02);
vec2 bu = rot2(bAng) * uv;
float along = smoothstep(-0.18, 0.14, bu.x) * (1.0 - smoothstep(0.55, 1.05, bu.x));
float halfW = mix(0.013, 0.0012, clamp((bu.x + 0.18) / 1.22, 0.0, 1.0));
float dBlade = abs(bu.y) / max(halfW, 0.001);
float core = exp(-dBlade * 3.2) * along * bEnv;
float glow = exp(-abs(bu.y) * 52.0) * along * bEnv * 0.22;
vec3 bc = (b == 0) ? vec3(0.35, 0.88, 1.0) : ((b == 1) ? vec3(1.0, 0.36, 0.78) : vec3(1.0, 0.76, 0.24));
bladeCol += mix(bc, vec3(1.0, 0.98, 0.94), core * 0.78) * (core * 1.35 + glow);
bladeLum += core * 0.85;
}
// 3. Turbulent ragged shockwave wisp (domain-warped, NOT a rigid geometric circle)
float shockR = 0.18 + beat * 0.92 + (vortexNoise - 0.5) * 0.12;
float shockWisp = exp(-abs(r - shockR) * 42.0) * smoothstep(0.35, 0.80, vortexNoise) * pow(1.0 - beat, 2.0) * 0.62;
if (uLightMode == 1) {
float lum = (hotPinpoint * 0.45 + vortexMask * 0.38 + shockWisp * 0.45 + bladeLum * 0.65) * (0.7 + 0.3 * hitPulse);
return vec3(lum) * floorFade;
}
vec3 col = vec3(1.0, 0.95, 0.82) * hotPinpoint * hitPulse
+ mix(vec3(1.0, 0.52, 0.08), vec3(0.14, 0.82, 1.0), smoothstep(0.3, 0.8, vortexNoise)) * vortexMask * 0.85 * hitPulse
+ vec3(1.0, 0.72, 0.28) * shockWisp
+ bladeCol * (isReflection ? 0.55 : 0.92);
return col * floorFade;
}
// -----------------------------------------------------------------------------
// Sparse Asymmetric Hot Metallic Clash Sparks (NO dandelion bicycle-wheel!)
// Smooth floor-height fade prevents any horizontal floor guillotine line
// -----------------------------------------------------------------------------
vec3 evalMetallicSparks(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float phase, float maxT) {
vec3 camFwd = normalize(cross(camRight, camUp));
float denom = dot(rd, camFwd);
if (abs(denom) < 0.05) return vec3(0.0);
vec3 acc = vec3(0.0);
// 2 sparse asymmetric parallax planes (cut radial spokes by >65%)
for (int layer = 0; layer < 2; layer++) {
float fl = float(layer);
float zOff = (layer == 0) ? 0.28 : -0.22;
vec3 planeC = CENTER + camFwd * zOff;
float t = dot(planeC - ro, camFwd) / denom;
if (t <= 0.1 || t >= maxT) continue;
vec3 P = ro + rd * t;
// Smooth floor proximity fade eliminates horizontal guillotine cutoff!
float floorFade = smoothstep(0.08, 0.46, P.y);
if (floorFade <= 0.001) continue;
vec3 rel = P - planeC;
vec2 uv = vec2(dot(rel, camRight), dot(rel, camUp));
float r = length(uv);
if (r < 0.10 || r > 1.85) continue;
vec2 cUV = rot2(r * 0.26 * (layer == 1 ? -1.0 : 1.0)) * uv;
float ang = atan(cUV.y, cUV.x);
float sectors = (layer == 0) ? 28.0 : 22.0;
float secId = floor((ang + PI) / TAU * sectors);
float h1 = hash21(vec2(secId, fl * 17.3 + 1.1));
float h2 = hash21(vec2(secId, fl * 31.7 + 6.7));
float h3 = hash21(vec2(secId, fl * 47.9 + 2.9));
float h4 = hash21(vec2(secId, fl * 61.1 + 9.3));
// Randomly skip ~62% of sectors for organic, asymmetric clash bursts
if (h1 < 0.62) continue;
float sectorStep = TAU / sectors;
float secCenter = (secId + 0.5 + (h4 - 0.5) * 0.45) * sectorStep - PI;
float angDiff = abs(ang - secCenter);
if (angDiff > sectorStep * 0.48) continue;
float speedMult = (h2 < 0.45) ? 2.0 : 3.0;
float sp = fract(phase * speedMult + h1 * 2.7);
// Varied asymmetric reach & streak length per spark
float maxReach = 0.72 + 1.05 * h3 * h3;
float sparkR = 0.16 + pow(sp, 0.68) * maxReach;
float streakLen = 0.024 + 0.068 * (1.0 - sp) * (0.35 + 0.65 * h2);
float dAng = angDiff * r;
float dRad = abs(r - sparkR);
float needle = exp(-dAng * 260.0) * exp(-dRad / max(streakLen, 0.006));
float hotHead = exp(-dAng * 150.0) * exp(-abs(r - (sparkR + streakLen * 0.42)) * 135.0);
float env = smoothstep(0.0, 0.06, sp) * (1.0 - smoothstep(0.54, 1.0, sp)) * floorFade;
vec3 sCol;
if (h3 < 0.66) {
sCol = mix(vec3(1.0, 0.44, 0.05), vec3(1.0, 0.84, 0.30), 1.0 - sp);
} else if (h3 < 0.84) {
sCol = vec3(0.16, 0.90, 1.0);
} else {
sCol = vec3(1.0, 0.22, 0.64);
}
if (uLightMode == 1) {
acc += vec3((needle * 0.38 + hotHead * 0.60) * env);
} else {
acc += (sCol * needle * 1.45 + mix(sCol, vec3(1.0, 0.99, 0.94), 0.78) * hotHead * 1.85) * env;
}
}
return acc;
}
// -----------------------------------------------------------------------------
// Composite all 3D VFX (5 volumetric slash ribbons + clash nexus + metallic sparks)
// -----------------------------------------------------------------------------
vec3 evalVFX(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float phase, float maxT, bool isReflection) {
vec4 rCol[5];
float rT[5];
for (int k = 0; k < 5; k++) {
rCol[k] = evalVolumetricSlash(getSlash(k), ro, rd, phase, maxT, isReflection, rT[k]);
}
vec3 camFwd = normalize(cross(camRight, camUp));
float coreT = dot(CENTER - ro, camFwd) / (dot(rd, camFwd) + 1e-5);
vec3 behindCore = vec3(0.0);
vec3 frontCore = vec3(0.0);
float frontAlpha = 0.0;
for (int k = 0; k < 5; k++) {
if (rCol[k].a <= 0.0005 && dot(rCol[k].rgb, vec3(1.0)) <= 0.0005) continue;
if (rT[k] < coreT) {
if (uLightMode == 1) {
frontCore = mix(frontCore, rCol[k].rgb, rCol[k].a * (1.0 - frontAlpha * 0.42))
+ rCol[k].rgb * (1.0 - rCol[k].a) * 0.16;
frontAlpha = clamp(frontAlpha + rCol[k].a * 0.55, 0.0, 0.92);
} else {
frontCore += rCol[k].rgb;
frontAlpha = clamp(frontAlpha + rCol[k].a * 0.34, 0.0, 0.74);
}
} else {
if (uLightMode == 1) {
behindCore = max(behindCore, rCol[k].rgb);
} else {
behindCore += rCol[k].rgb;
}
}
}
vec3 coreCol = evalClashNexus(ro, rd, camRight, camUp, phase, maxT, isReflection);
vec3 sparkCol = isReflection ? vec3(0.0) : evalMetallicSparks(ro, rd, camRight, camUp, phase, maxT);
if (uLightMode == 1) {
vec3 base = max(behindCore, coreCol * 0.72);
vec3 res = mix(base, frontCore, clamp(frontAlpha, 0.0, 0.88)) + frontCore * 0.20;
res += sparkCol * 0.48;
return res;
}
return behindCore * 0.92 + coreCol * (1.0 - frontAlpha * 0.25) + frontCore + sparkCol;
}
// -----------------------------------------------------------------------------
// Deep Moody Combat Arena Backdrop (lumMin ~ 8-14 sRGB, zero washed-out fog)
// -----------------------------------------------------------------------------
vec3 evalArenaBackdrop(vec3 ro, vec3 rd, float phase) {
float elev = clamp(rd.y * 0.5 + 0.5, 0.0, 1.0);
vec3 skyLow = vec3(0.0050, 0.0058, 0.0098);
vec3 skyHigh = vec3(0.0024, 0.0030, 0.0055);
vec3 col = mix(skyLow, skyHigh, smoothstep(0.42, 0.92, elev));
// Distant cylindrical stadium arena wall & steel trusses
float horiz = max(length(rd.xz), 0.001);
float wallT = 6.8 / horiz;
vec3 wallP = ro + rd * wallT;
float wallY = wallP.y;
float wallAng = atan(wallP.z, wallP.x);
// Subtle overhead arena spotlight shaft
float spotCone = exp(-abs(rd.x) * 5.2) * smoothstep(0.02, 0.62, rd.y) * 0.015;
col += vec3(0.45, 0.60, 0.88) * spotCone;
// Dark structural arena trusses
float ribV = smoothstep(0.93, 0.99, abs(sin(wallAng * 14.0)));
float ribH = smoothstep(0.94, 0.99, abs(sin(wallY * 4.2)));
float wallMask = smoothstep(-0.01, 0.14, rd.y) * (1.0 - smoothstep(0.50, 0.82, rd.y));
col += vec3(0.0042, 0.0055, 0.0092) * (ribV * 0.65 + ribH * 0.55) * wallMask;
// Crisp distant perimeter arena floodlights
float lightSlot = fract(wallAng / TAU * 14.0 + 0.5) - 0.5;
float dLight = length(vec2(lightSlot * 4.0, (wallY - 1.48) * 1.4));
float bokeh = exp(-dLight * dLight * 58.0) * 0.085 * wallMask;
col += vec3(0.66, 0.78, 1.0) * bokeh;
// Low perimeter stage rim lights near floor horizon
float lowSlot = fract(wallAng / TAU * 10.0) - 0.5;
float dLow = length(vec2(lowSlot * 4.2, (wallY - 0.18) * 3.6));
float lowGlow = exp(-dLow * dLow * 40.0) * 0.075 * smoothstep(-0.02, 0.08, rd.y);
col += vec3(0.84, 0.80, 0.96) * lowGlow;
vec3 toCenter = normalize(CENTER - ro);
float centerAlign = max(dot(rd, toCenter), 0.0);
float beat = fract(phase * 5.0 + 0.06);
float hazePulse = 0.85 + 0.25 * exp(-beat * 6.0);
if (uLightMode == 0) {
col += vec3(0.012, 0.010, 0.016) * pow(centerAlign, 8.0) * hazePulse;
} else if (uLightMode == 1) {
col = mix(vec3(0.018), vec3(0.006), smoothstep(0.0, 0.72, max(rd.y, 0.0)));
col += vec3(0.014) * pow(centerAlign, 5.0);
} else if (uLightMode == 2) {
float keyAlign = max(dot(rd, normalize(vec3(0.92, 0.18, 0.35))), 0.0);
col += vec3(0.055, 0.038, 0.020) * pow(keyAlign, 8.0);
col += vec3(0.012, 0.010, 0.008) * pow(centerAlign, 8.0);
} else if (uLightMode == 3) {
// Soft, localized cool backlit rim glow (fades smoothly to horizon — zero blue rectangle or seam!)
float horizSoft = smoothstep(-0.02, 0.22, rd.y);
col += vec3(0.018, 0.046, 0.085) * pow(centerAlign, 9.0) * horizSoft;
col += vec3(0.055, 0.115, 0.205) * pow(centerAlign, 24.0) * horizSoft;
}
return col;
}
// -----------------------------------------------------------------------------
// Dark Reflective Dojo / Arena Stage Floor with Crisp Colored Slash Reflections
// -----------------------------------------------------------------------------
vec3 evalArenaFloor(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float phase, float tFloor) {
vec3 p = ro + rd * tFloor;
float r = length(p.xz);
float ang = atan(p.z, p.x);
float grain1 = fbm3(p.xz * 3.2);
float grain2 = vnoise(vec2(ang * 20.0, r * 7.0));
float plank = 0.5 + 0.5 * sin(p.x * 10.0 + grain1 * 0.5);
vec3 baseAlbedo = mix(vec3(0.0055, 0.0062, 0.0092), vec3(0.010, 0.011, 0.015), grain1 * 0.6 + plank * 0.4);
// Concentric brushed-gold dojo stage rings
float ring1 = exp(-abs(r - 1.50) * 48.0);
float ring2 = exp(-abs(r - 2.12) * 38.0);
float ring3 = exp(-abs(r - 2.24) * 32.0);
float rings = clamp(ring1 * 0.60 + ring2 * 0.92 + ring3 * 0.72, 0.0, 1.0);
vec3 ringCol = (uLightMode == 1) ? vec3(0.12) : vec3(0.56, 0.40, 0.16);
vec3 N = normalize(vec3((grain1 - 0.5) * 0.032, 1.0, (grain2 - 0.5) * 0.032));
float ndv = max(-dot(rd, N), 0.001);
float fresnel = mix(0.24, 0.82, pow(1.0 - ndv, 3.0));
float beat = fract(phase * 5.0 + 0.06);
float hitPulse = 0.72 + 0.42 * exp(-beat * 6.5);
float centerPool = exp(-r * r * 0.85) * hitPulse;
vec3 directLight = vec3(0.0);
if (uLightMode == 0) {
directLight += vec3(0.50, 0.32, 0.12) * centerPool * 0.36;
directLight += vec3(0.05, 0.24, 0.40) * exp(-abs(r - 1.32) * 2.4) * 0.14;
directLight += vec3(0.32, 0.05, 0.24) * exp(-abs(r - 1.08) * 2.8) * 0.10;
directLight += vec3(0.0045, 0.0055, 0.0090);
} else if (uLightMode == 1) {
directLight += vec3(0.12) * centerPool + vec3(0.018);
} else if (uLightMode == 2) {
vec3 Lg = normalize(vec3(0.92, 0.18, 0.34));
vec3 H = normalize(Lg - rd);
float spec = pow(max(dot(N, H), 0.0), 48.0);
directLight += vec3(0.85, 0.68, 0.45) * (0.04 + spec * 0.65);
directLight += vec3(0.28, 0.20, 0.10) * centerPool * 0.25 + vec3(0.006);
} else if (uLightMode == 3) {
vec3 Lb = normalize(vec3(0.0, 0.28, -0.96));
vec3 H = normalize(Lb - rd);
float spec = pow(max(dot(N, H), 0.0), 32.0);
directLight += vec3(0.32, 0.62, 0.96) * (0.04 + spec * 0.72);
directLight += vec3(0.24, 0.30, 0.40) * centerPool * 0.22 + vec3(0.005);
}
vec3 floorCol = baseAlbedo * (1.0 + directLight * 2.8) + directLight * 0.16;
floorCol += ringCol * rings * (0.14 + 0.38 * centerPool);
// True planar reflection of the 3D slash ribbons & clash nexus
vec3 rdRef = reflect(rd, N);
vec3 refUp = vec3(0.0, 1.0, 0.0);
vec3 refRight = normalize(cross(rdRef, refUp));
refUp = normalize(cross(refRight, rdRef));
vec3 vfxRef = evalVFX(p, rdRef, refRight, refUp, phase, 20.0, true);
float gloss = mix(0.68, 0.96, 1.0 - grain1 * 0.45) * exp(-r * 0.18);
float refGain = (uLightMode == 1) ? 0.46 : 0.80;
floorCol += vfxRef * fresnel * gloss * refGain;
float fog = 1.0 - exp(-tFloor * 0.09);
vec3 fogCol = (uLightMode == 1) ? vec3(0.014) : vec3(0.0042, 0.0050, 0.0085);
floorCol = mix(floorCol, fogCol, clamp(fog, 0.0, 0.88));
return floorCol;
}
// -----------------------------------------------------------------------------
// Main Entry Point
// -----------------------------------------------------------------------------
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * uResolution.xy) / uResolution.y;
// Strictly periodic 3.0s seamless animation phase in [0, 1)
float phase = fract(uTime / 3.0);
// Subtle periodic camera breathing & impact micro-shake synced to the 5 hits
float beat = fract(phase * 5.0 + 0.06);
float shakeEnv = exp(-beat * 14.0) * 0.010;
vec2 microShake = vec2(sin(phase * TAU * 15.0), cos(phase * TAU * 20.0)) * shakeEnv;
// Camera setup: 0 = hero dramatic low-angle arena framing, 1 = ~2.5x macro close-up
vec3 ro, ta;
float fov;
if (uCamMode == 1) {
ro = vec3(0.32 + 0.04 * sin(phase * TAU), 1.26 + 0.02 * cos(phase * TAU), 1.70);
ta = vec3(0.02, 1.24, 0.0);
fov = 1.62;
} else {
ro = vec3(0.05 * sin(phase * TAU), 0.82 + 0.02 * cos(phase * TAU), 3.62);
ta = vec3(0.0, 1.15, 0.0);
fov = 1.28;
}
ro.xy += microShake;
vec3 camFwd = normalize(ta - ro);
vec3 camRight = normalize(cross(camFwd, vec3(0.0, 1.0, 0.0)));
vec3 camUp = normalize(cross(camRight, camFwd));
vec3 rd = normalize(camFwd * fov + camRight * uv.x + camUp * uv.y);
float tFloor = 1e6;
bool hitFloor = false;
if (rd.y < -0.0005) {
float tf = -ro.y / rd.y;
if (tf > 0.05 && tf < 32.0) {
tFloor = tf;
hitFloor = true;
}
}
vec3 bg = hitFloor
? evalArenaFloor(ro, rd, camRight, camUp, phase, tFloor)
: evalArenaBackdrop(ro, rd, phase);
vec3 vfx = evalVFX(ro, rd, camRight, camUp, phase, tFloor, false);
vec3 col = (uLightMode == 1) ? (bg + vfx * 0.85) : (bg + vfx);
float vig = 1.0 - 0.14 * dot(uv, uv);
col *= clamp(vig, 0.82, 1.0);
// Clean ACES filmic tonemapping with soft highlight knee (%clip < 1%)
float peak = max(col.r, max(col.g, col.b));
col *= 1.0 / (1.0 + 0.16 * peak);
col = acesFilm(col * 1.06) * 0.965;
// Gamma to sRGB
col = pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2));
// Strictly enforce R == G == B in neutral grayscale form study mode
if (uLightMode == 1) {
float g = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(g);
}
fragColor = vec4(col, 1.0);
}
shader_type canvas_item;
// Tip: uncomment the next line for zero-overdraw additive 2D combat/spell glow:
// render_mode blend_add;
// Rapid Combo Slash Flurry — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/vfx_animated/lib/05_rapid_combo_slash_flurry.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;
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
const vec3 CENTER = vec3(0.0, 1.24, 0.0);
// -----------------------------------------------------------------------------
// Fast procedural hashes, value noise & domain-warped fBM (zero textures)
// -----------------------------------------------------------------------------
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);
}
vec2 hash22(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.xx + p3.yz) * p3.zy);
}
float vnoise(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
f = 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, f.x), mix(c, d, f.x), f.y);
}
float fbm3(vec2 p) {
float v = 0.0;
float a = 0.5;
mat2 rot = mat2(0.80, 0.60, -0.60, 0.80);
for (int i = 0; i < 3; i++) {
v += a * vnoise(p);
p = rot * p * 2.05 + vec2(13.7, 29.3);
a *= 0.5;
}
return v;
}
// Turbulent domain-warped fBM for painterly smoky plasma wakes
float warpedFbm(vec2 p, float flow) {
vec2 q = vec2(
fbm3(p + vec2(flow * 0.7, 1.4)),
fbm3(p + vec2(5.2, flow * 0.5 + 8.3))
);
return fbm3(p + 1.85 * q);
}
// -----------------------------------------------------------------------------
// 3D & 2D rotation helpers
// -----------------------------------------------------------------------------
mat3 rotX(float a) {
float c = cos(a), s = sin(a);
return mat3(1.0, 0.0, 0.0, 0.0, c, -s, 0.0, s, c);
}
mat3 rotY(float a) {
float c = cos(a), s = sin(a);
return mat3(c, 0.0, s, 0.0, 1.0, 0.0, -s, 0.0, c);
}
mat3 rotZ(float a) {
float c = cos(a), s = sin(a);
return mat3(c, -s, 0.0, s, c, 0.0, 0.0, 0.0, 1.0);
}
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
// -----------------------------------------------------------------------------
// ACES Filmic Tonemapping (%clip < 1%)
// -----------------------------------------------------------------------------
vec3 acesFilm(vec3 x) {
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
return clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0.0, 1.0);
}
// -----------------------------------------------------------------------------
// 5 Dramatic Sweeping 3D Painterly-Volumetric Sword-Slash Ribbons
// Bold perspective tilts + expanding spiral-crescent curvature (NOT flat hoops!)
// -----------------------------------------------------------------------------
struct SlashDef {
mat3 basis; // columns: U, V, N
vec3 offset; // 3D center offset for dynamic depth layering
vec2 radii; // (rx, ry) major/minor sweep scale
float maxWidth; // wide dramatic crescent belly (0.34..0.44)
float spiral; // radial expansion from tail to head (breaks circular hoop look!)
float startAng; // strike start angle
float dir; // +1 or -1 sweep direction
float phaseOff; // staggered k/5.0 combo offset
vec3 colCore; // incandescent leading blade spine
vec3 colMid; // vibrant plasma body
vec3 colSmoke; // deep turbulent smoky wake
float electric; // crackling lightning arc intensity
};
SlashDef getSlash(int k) {
SlashDef s;
if (k == 0) {
// 1. Electric Cyan Hero Slash: dramatic sweeping upper-left to lower-right
s.basis = rotZ(-0.48) * rotX(0.58) * rotY(0.28);
s.offset = vec3(-0.08, 0.10, 0.06);
s.radii = vec2(1.66, 1.12);
s.maxWidth = 0.42;
s.spiral = 0.24;
s.startAng = 2.75;
s.dir = -1.0;
s.phaseOff = 0.06;
s.colCore = vec3(0.86, 0.99, 1.00);
s.colMid = vec3(0.02, 0.86, 1.00);
s.colSmoke = vec3(0.01, 0.22, 0.72);
s.electric = 1.0;
} else if (k == 1) {
// 2. Solar Gold Hero Slash: bold counter-diagonal lower-left to upper-right
s.basis = rotZ(0.42) * rotX(0.56) * rotY(-0.30);
s.offset = vec3(0.06, 0.02, -0.05);
s.radii = vec2(1.62, 1.08);
s.maxWidth = 0.40;
s.spiral = 0.22;
s.startAng = -2.20;
s.dir = 1.0;
s.phaseOff = 0.86;
s.colCore = vec3(1.00, 0.97, 0.80);
s.colMid = vec3(1.00, 0.64, 0.06);
s.colSmoke = vec3(0.76, 0.16, 0.01);
s.electric = 0.35;
} else if (k == 2) {
// 3. Hot Magenta-Crimson Slash: steep whipping diagonal across front-center
s.basis = rotZ(0.68) * rotX(-0.50) * rotY(0.26);
s.offset = vec3(0.04, 0.04, 0.12);
s.radii = vec2(1.48, 0.96);
s.maxWidth = 0.38;
s.spiral = 0.26;
s.startAng = -1.45;
s.dir = 1.0;
s.phaseOff = 0.26;
s.colCore = vec3(1.00, 0.84, 0.94);
s.colMid = vec3(1.00, 0.08, 0.54);
s.colSmoke = vec3(0.55, 0.02, 0.36);
s.electric = 0.75;
} else if (k == 3) {
// 4. Fiery Crimson-Scarlet Cross-Slash: sweeping low-to-high foreground arc
s.basis = rotZ(-0.22) * rotX(0.68) * rotY(-0.36);
s.offset = vec3(-0.02, 0.00, 0.14);
s.radii = vec2(1.46, 0.88);
s.maxWidth = 0.35;
s.spiral = 0.20;
s.startAng = 2.05;
s.dir = -1.0;
s.phaseOff = 0.46;
s.colCore = vec3(1.00, 0.86, 0.68);
s.colMid = vec3(1.00, 0.18, 0.05);
s.colSmoke = vec3(0.58, 0.02, 0.02);
s.electric = 0.25;
} else {
// 5. Electric Cyan-Gold High Orbital Slash: deep background/foreground weave
s.basis = rotZ(-0.76) * rotX(-0.46) * rotY(-0.32);
s.offset = vec3(0.08, 0.08, -0.10);
s.radii = vec2(1.38, 0.98);
s.maxWidth = 0.36;
s.spiral = 0.25;
s.startAng = 0.75;
s.dir = -1.0;
s.phaseOff = 0.66;
s.colCore = vec3(0.90, 0.99, 1.00);
s.colMid = vec3(0.08, 0.78, 1.00);
s.colSmoke = vec3(0.04, 0.20, 0.68);
s.electric = 0.85;
}
return s;
}
// -----------------------------------------------------------------------------
// Evaluate a single volumetric slice of a painterly 3D sword-slash smear ribbon
// -----------------------------------------------------------------------------
vec4 evalSlashSlice(
SlashDef sl,
vec3 ro,
vec3 rd,
float pk,
float maxT,
float sliceOff, // volumetric offset along normal N
float sliceWeight, // Gaussian thickness weight
bool isReflection,
out float hitT
) {
hitT = 1e6;
vec3 U = sl.basis[0];
vec3 V = sl.basis[1];
vec3 N = sl.basis[2];
vec3 C = CENTER + sl.offset + N * sliceOff;
float denom = dot(rd, N);
float absDenom = abs(denom);
if (absDenom < 0.03) return vec4(0.0);
float t = dot(C - ro, N) / denom;
if (t <= 0.08 || t >= maxT) return vec4(0.0);
vec3 P = ro + rd * t;
// Smooth height fade above floor eliminates any plane/floor clip line
float floorFade = smoothstep(0.04, 0.30, P.y);
if (floorFade <= 0.001) return vec4(0.0);
vec2 p2 = vec2(dot(P - C, U), dot(P - C, V));
vec2 q = p2 / sl.radii;
float rad = length(q);
if (rad < 0.08 || rad > 1.44) return vec4(0.0);
hitT = t;
float ang = atan(q.y, q.x);
// Explosive whip-out sweep ease
float whipT = clamp(pk / 0.48, 0.0, 1.0);
float sweep = 1.0 - pow(1.0 - whipT, 2.85);
float headAng = sl.startAng + sl.dir * (sweep * 4.50 + pk * 1.15);
// Sweeping crescent angular span (strictly < 3.6 rad so head & tail never touch)
float arcLen = mix(0.65, 3.45, smoothstep(0.0, 0.18, pk))
* mix(1.0, 0.70, smoothstep(0.60, 0.96, pk));
float env = smoothstep(0.0, 0.04, pk) * (1.0 - smoothstep(0.68, 0.98, pk));
if (env <= 0.002) return vec4(0.0);
// Continuous angular distance behind the leading blade tip in [0, TAU)
float da = mod(sl.dir * (headAng - ang) + TAU * 6.0, TAU);
float u = da / max(arcLen, 0.001);
if (u <= 0.0 || u >= 1.0) return vec4(0.0);
// Smooth razor tip entry & turbulent wispy tail exit
float headFade = smoothstep(0.0, 0.035, u);
float tailFade = 1.0 - smoothstep(0.55, 1.0, u);
float inArc = headFade * tailFade;
if (inArc <= 0.001) return vec4(0.0);
// Expanding spiral-crescent outer blade contour (NOT a circular hula-hoop!)
float twist = sliceOff * 0.55 * sin(u * PI * 1.5);
float rOut = 1.08 - sl.spiral * pow(u, 0.85) + 0.04 * sin(u * PI) + twist;
// Dramatic wide crescent belly tapering to razor tip and feathered smoky wake
float belly = pow(u, 0.36) * pow(1.0 - u, 1.15) * 2.10;
float w = sl.maxWidth * clamp(belly, 0.0, 1.12);
w *= mix(1.0, 0.65, smoothstep(0.58, 0.96, pk));
// Normalized radial wake coordinate: v=0 razor leading edge, v>0 deep smoky wake
float v = (rOut - rad) / max(w, 0.004);
if (v > 1.75) return vec4(0.0);
// Domain-warped painterly brush-stroke turbulence (continuous in da, zero seam!)
float flow = da * 2.4 - pk * 8.5 + sliceOff * 6.0;
vec2 smearUV = vec2(flow * 0.85, clamp(v, -0.2, 1.6) * 5.0 + sliceOff * 2.5);
float turb = isReflection
? fbm3(smearUV * vec2(1.0, 1.4))
: warpedFbm(smearUV, flow * 0.45);
// High-frequency brushed ink/plasma motion streaks stretched along the swing
float fineStreaks = vnoise(vec2(flow * 2.6, clamp(v, -0.2, 1.6) * 20.0 + turb * 3.2));
float brushFibers = smoothstep(0.20, 0.82, turb * 0.68 + fineStreaks * 0.32);
// Razor-sharp outer cut, ZERO hard inner circular cutout!
// Exponential + domain-warped turbulent feather dissolves organically into darkness
float outerCut = smoothstep(-0.012, 0.005, rOut - rad);
float vPos = max(v, 0.0);
float innerSoftFeather = exp(-vPos * (1.75 + 2.20 * (1.0 - turb)))
* (1.0 - smoothstep(0.45, 1.45, vPos - (turb - 0.5) * 0.55))
* smoothstep(0.10, 0.36, rad);
float wakeMask = outerCut * innerSoftFeather * inArc;
// Progressive smoky dissolution across v (wake depth), u (tail), and pk (lifecycle)
float dissolve = smoothstep(0.54, 0.96, pk);
float smokeBreakup = smoothstep(
0.14 + 0.34 * vPos + 0.24 * u + 0.35 * dissolve,
0.86,
turb * 0.72 + fineStreaks * 0.28
);
float wakeDensity = wakeMask * mix(0.58 + 0.42 * brushFibers, smokeBreakup, smoothstep(0.06, 0.58, vPos));
// Incandescent razor-sharp leading blade spine & scorching tip glint
float razorSpine = exp(-abs(rad - (rOut - 0.007)) * 115.0) * headFade * (1.0 - smoothstep(0.25, 0.78, u));
float subSpine = exp(-abs(rad - (rOut - 0.028 * (1.0 + turb * 0.6))) * 65.0) * headFade * (1.0 - smoothstep(0.35, 0.85, u)) * brushFibers;
float tipFlare = exp(-abs(rad - rOut) * 48.0) * exp(-u * 14.0) * headFade;
// Hot metallic sparks & glowing embers shedding tangentially ALONG the blade trail!
float trailSparks = 0.0;
if (!isReflection && abs(sliceOff) < 0.01 && v > -0.18 && v < 1.15) {
vec2 spGrid = vec2(da * 11.0 - pk * 14.0, (rOut - rad) * 24.0);
vec2 spCell = floor(spGrid);
vec2 spF = fract(spGrid) - 0.5;
vec2 rnd = hash22(spCell + vec2(sl.phaseOff * 37.0, 11.3));
if (rnd.x > 0.62) {
vec2 off = (rnd - 0.5) * 0.52;
vec2 dSp = spF - off;
// Elongated tangential ember streak following the blade sweep
float dStreak = length(vec2(dSp.x * 0.42, dSp.y * 2.4));
trailSparks = exp(-dStreak * 13.5) * inArc * (1.0 - smoothstep(0.85, 1.15, vPos)) * (0.6 + 0.4 * rnd.y);
}
}
// 3D perspective depth emphasis: closer foreground sweeps feel bolder & richer
float depthBoost = clamp(3.5 / max(t, 1.2), 0.72, 1.45);
float angleFade = smoothstep(0.03, 0.20, absDenom) * floorFade;
// -------------------------------------------------------------------------
// uLightMode == 1: Neutral grayscale sculptural form/ribbon study (R==G==B)
// -------------------------------------------------------------------------
if (uLightMode == 1) {
vec3 Nface = (denom < 0.0) ? N : -N;
vec3 L1 = normalize(vec3(0.55, 0.80, 0.65));
vec3 L2 = normalize(vec3(-0.70, 0.35, -0.45));
float ndl1 = max(dot(Nface, L1), 0.0);
float ndl2 = max(dot(Nface, L2), 0.0);
float fres = pow(1.0 - clamp(absDenom, 0.0, 1.0), 2.4);
float shade = 0.16 + 0.54 * ndl1 + 0.18 * ndl2 + 0.24 * fres;
float val = shade * wakeDensity * 0.90 + (0.58 * razorSpine + 0.28 * subSpine + 0.40 * tipFlare + 0.55 * trailSparks);
val *= env * angleFade * sliceWeight * depthBoost;
float alpha = clamp((wakeDensity * 0.82 + razorSpine * 0.65) * env * angleFade * sliceWeight, 0.0, 1.0);
return vec4(vec3(val), alpha);
}
// -------------------------------------------------------------------------
// Hero & Lighting Modes (0, 2, 3): Painterly Volumetric Plasma + Smoke Wake
// -------------------------------------------------------------------------
float dEdge = max(rad - rOut, 0.0);
float tightAura = exp(-dEdge * (isReflection ? 20.0 : 34.0)) * inArc * (1.0 - 0.55 * u) * (0.45 + 0.55 * brushFibers);
// Localized organic branching lightning arcs peeling off the blade wake
float bolt = 0.0;
if (sl.electric > 0.15 && !isReflection && abs(sliceOff) < 0.01) {
float bFlow = da * 7.5 + pk * 11.0;
float pocket = smoothstep(0.46, 0.78, vnoise(vec2(da * 1.9 - pk * 3.5, 4.7)));
float jag1 = (fbm3(vec2(bFlow, 2.3)) - 0.5) * 0.16;
float jag2 = (vnoise(vec2(bFlow * 2.8, 9.1)) - 0.5) * 0.07;
float boltR = rOut + 0.035 + (jag1 + jag2) * pocket;
float bMask = smoothstep(0.06, 0.16, u) * (1.0 - smoothstep(0.45, 0.80, u)) * pocket;
bolt = exp(-abs(rad - boltR) * 165.0) * bMask * sl.electric;
float forkR = rOut + 0.075 + (jag1 * 1.4 - jag2 * 1.2) * pocket;
bolt += exp(-abs(rad - forkR) * 195.0) * bMask * smoothstep(0.62, 0.88, pocket) * sl.electric * 0.72;
}
// Painterly color gradient: incandescent white-hot spine -> vivid plasma -> deep smoky wake
float wakeGrad = clamp(vPos * 1.05 + (1.0 - brushFibers) * 0.35 + u * 0.25, 0.0, 1.0);
vec3 bodyCol = mix(sl.colMid, sl.colSmoke, wakeGrad);
bodyCol = mix(bodyCol, sl.colCore, clamp(exp(-vPos * 11.0) * 0.55 + subSpine * 0.50, 0.0, 1.0));
float modeGain = 1.0;
if (uLightMode == 2) {
vec3 Nface = (denom < 0.0) ? N : -N;
vec3 Lg = normalize(vec3(0.92, 0.22, 0.32));
float graze = pow(max(dot(Nface, Lg), 0.0), 2.2);
bodyCol += vec3(1.0, 0.86, 0.62) * graze * 0.42 * wakeDensity;
modeGain = 0.94;
} else if (uLightMode == 3) {
float rim = pow(1.0 - clamp(absDenom, 0.0, 1.0), 1.8);
bodyCol += vec3(0.32, 0.78, 1.0) * rim * 0.48 * wakeDensity;
modeGain = 0.96;
}
vec3 sparkTint = mix(vec3(1.0, 0.82, 0.38), sl.colCore, 0.45);
vec3 energy = bodyCol * (wakeDensity * (0.95 + 0.80 * brushFibers) * 1.32)
+ sl.colSmoke * (tightAura * 0.28)
+ sl.colMid * (tightAura * 0.16 + subSpine * 0.85)
+ sl.colCore * (razorSpine * 1.75 + tipFlare * 1.45)
+ mix(sl.colMid, sl.colCore, 0.62) * bolt * 1.95
+ sparkTint * trailSparks * 2.20;
energy *= env * angleFade * sliceWeight * depthBoost * modeGain;
float alpha = clamp((wakeDensity * 0.72 + razorSpine * 0.55) * env * angleFade * sliceWeight, 0.0, 0.95);
return vec4(energy, alpha);
}
// -----------------------------------------------------------------------------
// Multi-slice 3D Volumetric Slash Ribbon Evaluator (3 slices for hero, 1 for reflection)
// -----------------------------------------------------------------------------
vec4 evalVolumetricSlash(
SlashDef sl,
vec3 ro,
vec3 rd,
float phase,
float maxT,
bool isReflection,
out float hitT
) {
hitT = 1e6;
float pk = fract(phase + sl.phaseOff);
// Quick center-plane bounding reject before volumetric multi-slice integration
float t0;
vec4 centerHit = evalSlashSlice(sl, ro, rd, pk, maxT, 0.0, isReflection ? 1.0 : 0.52, isReflection, t0);
hitT = t0;
if (isReflection) {
return centerHit;
}
// If center plane completely missed the bounding volume, skip side slices
if (t0 > 1e5) return vec4(0.0);
// Accumulate front & back volumetric plasma thickness slices for true 3D painterly depth
float tFront, tBack;
vec4 frontHit = evalSlashSlice(sl, ro, rd, pk, maxT, 0.048, 0.34, false, tFront);
vec4 backHit = evalSlashSlice(sl, ro, rd, pk, maxT, -0.048, 0.34, false, tBack);
hitT = min(t0, min(tFront, tBack));
vec3 rgb = centerHit.rgb + frontHit.rgb + backHit.rgb;
float a = clamp(centerHit.a + frontHit.a * 0.65 + backHit.a * 0.65, 0.0, 0.96);
return vec4(rgb, a);
}
// -----------------------------------------------------------------------------
// Dynamic Clash Vortex & Kinetic Blade-Cross Core (NO generic white sunburst!)
// -----------------------------------------------------------------------------
vec3 evalClashNexus(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float phase, float maxT, bool isReflection) {
vec3 camFwd = normalize(cross(camRight, camUp));
float denom = dot(rd, camFwd);
if (abs(denom) < 0.05) return vec3(0.0);
float t = dot(CENTER - ro, camFwd) / denom;
if (t <= 0.08 || t >= maxT) return vec3(0.0);
vec3 P = ro + rd * t;
float floorFade = smoothstep(0.06, 0.40, P.y);
if (floorFade <= 0.001) return vec3(0.0);
vec3 rel = P - CENTER;
vec2 uv = vec2(dot(rel, camRight), dot(rel, camUp));
float r = length(uv);
if (r > 1.35) return vec3(0.0);
// 5-beat rapid combo strike pulse synced to the 5 ribbons
float beat = fract(phase * 5.0 + 0.06);
float hitPulse = 0.55 + 0.72 * exp(-beat * 7.5);
// 1. Swirling turbulent clash plasma vortex (compact, painterly, NOT a smooth white blob)
vec2 swirlP = rot2(r * 2.6 - phase * TAU) * uv * 3.4;
float vortexNoise = isReflection
? fbm3(swirlP)
: warpedFbm(swirlP, phase * TAU * 0.5);
float vortexMask = exp(-r * 3.4) * smoothstep(0.28, 0.82, vortexNoise);
float hotPinpoint = exp(-r * 22.0) * 1.45;
// 2. Razor-sharp kinetic cross-slash blade glints (echoing crossed katana strikes)
vec3 bladeCol = vec3(0.0);
float bladeLum = 0.0;
for (int b = 0; b < 3; b++) {
float fb = float(b);
float bBeat = fract(phase * 5.0 + fb * 0.33 + 0.04);
float bEnv = 0.38 + 0.62 * exp(-bBeat * 5.5);
float bAng = (b == 0) ? -0.78 : ((b == 1) ? 0.56 : 1.02);
vec2 bu = rot2(bAng) * uv;
float along = smoothstep(-0.18, 0.14, bu.x) * (1.0 - smoothstep(0.55, 1.05, bu.x));
float halfW = mix(0.013, 0.0012, clamp((bu.x + 0.18) / 1.22, 0.0, 1.0));
float dBlade = abs(bu.y) / max(halfW, 0.001);
float core = exp(-dBlade * 3.2) * along * bEnv;
float glow = exp(-abs(bu.y) * 52.0) * along * bEnv * 0.22;
vec3 bc = (b == 0) ? vec3(0.35, 0.88, 1.0) : ((b == 1) ? vec3(1.0, 0.36, 0.78) : vec3(1.0, 0.76, 0.24));
bladeCol += mix(bc, vec3(1.0, 0.98, 0.94), core * 0.78) * (core * 1.35 + glow);
bladeLum += core * 0.85;
}
// 3. Turbulent ragged shockwave wisp (domain-warped, NOT a rigid geometric circle)
float shockR = 0.18 + beat * 0.92 + (vortexNoise - 0.5) * 0.12;
float shockWisp = exp(-abs(r - shockR) * 42.0) * smoothstep(0.35, 0.80, vortexNoise) * pow(1.0 - beat, 2.0) * 0.62;
if (uLightMode == 1) {
float lum = (hotPinpoint * 0.45 + vortexMask * 0.38 + shockWisp * 0.45 + bladeLum * 0.65) * (0.7 + 0.3 * hitPulse);
return vec3(lum) * floorFade;
}
vec3 col = vec3(1.0, 0.95, 0.82) * hotPinpoint * hitPulse
+ mix(vec3(1.0, 0.52, 0.08), vec3(0.14, 0.82, 1.0), smoothstep(0.3, 0.8, vortexNoise)) * vortexMask * 0.85 * hitPulse
+ vec3(1.0, 0.72, 0.28) * shockWisp
+ bladeCol * (isReflection ? 0.55 : 0.92);
return col * floorFade;
}
// -----------------------------------------------------------------------------
// Sparse Asymmetric Hot Metallic Clash Sparks (NO dandelion bicycle-wheel!)
// Smooth floor-height fade prevents any horizontal floor guillotine line
// -----------------------------------------------------------------------------
vec3 evalMetallicSparks(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float phase, float maxT) {
vec3 camFwd = normalize(cross(camRight, camUp));
float denom = dot(rd, camFwd);
if (abs(denom) < 0.05) return vec3(0.0);
vec3 acc = vec3(0.0);
// 2 sparse asymmetric parallax planes (cut radial spokes by >65%)
for (int layer = 0; layer < 2; layer++) {
float fl = float(layer);
float zOff = (layer == 0) ? 0.28 : -0.22;
vec3 planeC = CENTER + camFwd * zOff;
float t = dot(planeC - ro, camFwd) / denom;
if (t <= 0.1 || t >= maxT) continue;
vec3 P = ro + rd * t;
// Smooth floor proximity fade eliminates horizontal guillotine cutoff!
float floorFade = smoothstep(0.08, 0.46, P.y);
if (floorFade <= 0.001) continue;
vec3 rel = P - planeC;
vec2 uv = vec2(dot(rel, camRight), dot(rel, camUp));
float r = length(uv);
if (r < 0.10 || r > 1.85) continue;
vec2 cUV = rot2(r * 0.26 * (layer == 1 ? -1.0 : 1.0)) * uv;
float ang = atan(cUV.y, cUV.x);
float sectors = (layer == 0) ? 28.0 : 22.0;
float secId = floor((ang + PI) / TAU * sectors);
float h1 = hash21(vec2(secId, fl * 17.3 + 1.1));
float h2 = hash21(vec2(secId, fl * 31.7 + 6.7));
float h3 = hash21(vec2(secId, fl * 47.9 + 2.9));
float h4 = hash21(vec2(secId, fl * 61.1 + 9.3));
// Randomly skip ~62% of sectors for organic, asymmetric clash bursts
if (h1 < 0.62) continue;
float sectorStep = TAU / sectors;
float secCenter = (secId + 0.5 + (h4 - 0.5) * 0.45) * sectorStep - PI;
float angDiff = abs(ang - secCenter);
if (angDiff > sectorStep * 0.48) continue;
float speedMult = (h2 < 0.45) ? 2.0 : 3.0;
float sp = fract(phase * speedMult + h1 * 2.7);
// Varied asymmetric reach & streak length per spark
float maxReach = 0.72 + 1.05 * h3 * h3;
float sparkR = 0.16 + pow(sp, 0.68) * maxReach;
float streakLen = 0.024 + 0.068 * (1.0 - sp) * (0.35 + 0.65 * h2);
float dAng = angDiff * r;
float dRad = abs(r - sparkR);
float needle = exp(-dAng * 260.0) * exp(-dRad / max(streakLen, 0.006));
float hotHead = exp(-dAng * 150.0) * exp(-abs(r - (sparkR + streakLen * 0.42)) * 135.0);
float env = smoothstep(0.0, 0.06, sp) * (1.0 - smoothstep(0.54, 1.0, sp)) * floorFade;
vec3 sCol;
if (h3 < 0.66) {
sCol = mix(vec3(1.0, 0.44, 0.05), vec3(1.0, 0.84, 0.30), 1.0 - sp);
} else if (h3 < 0.84) {
sCol = vec3(0.16, 0.90, 1.0);
} else {
sCol = vec3(1.0, 0.22, 0.64);
}
if (uLightMode == 1) {
acc += vec3((needle * 0.38 + hotHead * 0.60) * env);
} else {
acc += (sCol * needle * 1.45 + mix(sCol, vec3(1.0, 0.99, 0.94), 0.78) * hotHead * 1.85) * env;
}
}
return acc;
}
// -----------------------------------------------------------------------------
// Composite all 3D VFX (5 volumetric slash ribbons + clash nexus + metallic sparks)
// -----------------------------------------------------------------------------
vec3 evalVFX(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float phase, float maxT, bool isReflection) {
vec4 rCol[5];
float rT[5];
for (int k = 0; k < 5; k++) {
rCol[k] = evalVolumetricSlash(getSlash(k), ro, rd, phase, maxT, isReflection, rT[k]);
}
vec3 camFwd = normalize(cross(camRight, camUp));
float coreT = dot(CENTER - ro, camFwd) / (dot(rd, camFwd) + 1e-5);
vec3 behindCore = vec3(0.0);
vec3 frontCore = vec3(0.0);
float frontAlpha = 0.0;
for (int k = 0; k < 5; k++) {
if (rCol[k].a <= 0.0005 && dot(rCol[k].rgb, vec3(1.0)) <= 0.0005) continue;
if (rT[k] < coreT) {
if (uLightMode == 1) {
frontCore = mix(frontCore, rCol[k].rgb, rCol[k].a * (1.0 - frontAlpha * 0.42))
+ rCol[k].rgb * (1.0 - rCol[k].a) * 0.16;
frontAlpha = clamp(frontAlpha + rCol[k].a * 0.55, 0.0, 0.92);
} else {
frontCore += rCol[k].rgb;
frontAlpha = clamp(frontAlpha + rCol[k].a * 0.34, 0.0, 0.74);
}
} else {
if (uLightMode == 1) {
behindCore = max(behindCore, rCol[k].rgb);
} else {
behindCore += rCol[k].rgb;
}
}
}
vec3 coreCol = evalClashNexus(ro, rd, camRight, camUp, phase, maxT, isReflection);
vec3 sparkCol = isReflection ? vec3(0.0) : evalMetallicSparks(ro, rd, camRight, camUp, phase, maxT);
if (uLightMode == 1) {
vec3 base = max(behindCore, coreCol * 0.72);
vec3 res = mix(base, frontCore, clamp(frontAlpha, 0.0, 0.88)) + frontCore * 0.20;
res += sparkCol * 0.48;
return res;
}
return behindCore * 0.92 + coreCol * (1.0 - frontAlpha * 0.25) + frontCore + sparkCol;
}
// -----------------------------------------------------------------------------
// Deep Moody Combat Arena Backdrop (lumMin ~ 8-14 sRGB, zero washed-out fog)
// -----------------------------------------------------------------------------
vec3 evalArenaBackdrop(vec3 ro, vec3 rd, float phase) {
float elev = clamp(rd.y * 0.5 + 0.5, 0.0, 1.0);
vec3 skyLow = vec3(0.0050, 0.0058, 0.0098);
vec3 skyHigh = vec3(0.0024, 0.0030, 0.0055);
vec3 col = mix(skyLow, skyHigh, smoothstep(0.42, 0.92, elev));
// Distant cylindrical stadium arena wall & steel trusses
float horiz = max(length(rd.xz), 0.001);
float wallT = 6.8 / horiz;
vec3 wallP = ro + rd * wallT;
float wallY = wallP.y;
float wallAng = atan(wallP.z, wallP.x);
// Subtle overhead arena spotlight shaft
float spotCone = exp(-abs(rd.x) * 5.2) * smoothstep(0.02, 0.62, rd.y) * 0.015;
col += vec3(0.45, 0.60, 0.88) * spotCone;
// Dark structural arena trusses
float ribV = smoothstep(0.93, 0.99, abs(sin(wallAng * 14.0)));
float ribH = smoothstep(0.94, 0.99, abs(sin(wallY * 4.2)));
float wallMask = smoothstep(-0.01, 0.14, rd.y) * (1.0 - smoothstep(0.50, 0.82, rd.y));
col += vec3(0.0042, 0.0055, 0.0092) * (ribV * 0.65 + ribH * 0.55) * wallMask;
// Crisp distant perimeter arena floodlights
float lightSlot = fract(wallAng / TAU * 14.0 + 0.5) - 0.5;
float dLight = length(vec2(lightSlot * 4.0, (wallY - 1.48) * 1.4));
float bokeh = exp(-dLight * dLight * 58.0) * 0.085 * wallMask;
col += vec3(0.66, 0.78, 1.0) * bokeh;
// Low perimeter stage rim lights near floor horizon
float lowSlot = fract(wallAng / TAU * 10.0) - 0.5;
float dLow = length(vec2(lowSlot * 4.2, (wallY - 0.18) * 3.6));
float lowGlow = exp(-dLow * dLow * 40.0) * 0.075 * smoothstep(-0.02, 0.08, rd.y);
col += vec3(0.84, 0.80, 0.96) * lowGlow;
vec3 toCenter = normalize(CENTER - ro);
float centerAlign = max(dot(rd, toCenter), 0.0);
float beat = fract(phase * 5.0 + 0.06);
float hazePulse = 0.85 + 0.25 * exp(-beat * 6.0);
if (uLightMode == 0) {
col += vec3(0.012, 0.010, 0.016) * pow(centerAlign, 8.0) * hazePulse;
} else if (uLightMode == 1) {
col = mix(vec3(0.018), vec3(0.006), smoothstep(0.0, 0.72, max(rd.y, 0.0)));
col += vec3(0.014) * pow(centerAlign, 5.0);
} else if (uLightMode == 2) {
float keyAlign = max(dot(rd, normalize(vec3(0.92, 0.18, 0.35))), 0.0);
col += vec3(0.055, 0.038, 0.020) * pow(keyAlign, 8.0);
col += vec3(0.012, 0.010, 0.008) * pow(centerAlign, 8.0);
} else if (uLightMode == 3) {
// Soft, localized cool backlit rim glow (fades smoothly to horizon — zero blue rectangle or seam!)
float horizSoft = smoothstep(-0.02, 0.22, rd.y);
col += vec3(0.018, 0.046, 0.085) * pow(centerAlign, 9.0) * horizSoft;
col += vec3(0.055, 0.115, 0.205) * pow(centerAlign, 24.0) * horizSoft;
}
return col;
}
// -----------------------------------------------------------------------------
// Dark Reflective Dojo / Arena Stage Floor with Crisp Colored Slash Reflections
// -----------------------------------------------------------------------------
vec3 evalArenaFloor(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float phase, float tFloor) {
vec3 p = ro + rd * tFloor;
float r = length(p.xz);
float ang = atan(p.z, p.x);
float grain1 = fbm3(p.xz * 3.2);
float grain2 = vnoise(vec2(ang * 20.0, r * 7.0));
float plank = 0.5 + 0.5 * sin(p.x * 10.0 + grain1 * 0.5);
vec3 baseAlbedo = mix(vec3(0.0055, 0.0062, 0.0092), vec3(0.010, 0.011, 0.015), grain1 * 0.6 + plank * 0.4);
// Concentric brushed-gold dojo stage rings
float ring1 = exp(-abs(r - 1.50) * 48.0);
float ring2 = exp(-abs(r - 2.12) * 38.0);
float ring3 = exp(-abs(r - 2.24) * 32.0);
float rings = clamp(ring1 * 0.60 + ring2 * 0.92 + ring3 * 0.72, 0.0, 1.0);
vec3 ringCol = (uLightMode == 1) ? vec3(0.12) : vec3(0.56, 0.40, 0.16);
vec3 N = normalize(vec3((grain1 - 0.5) * 0.032, 1.0, (grain2 - 0.5) * 0.032));
float ndv = max(-dot(rd, N), 0.001);
float fresnel = mix(0.24, 0.82, pow(1.0 - ndv, 3.0));
float beat = fract(phase * 5.0 + 0.06);
float hitPulse = 0.72 + 0.42 * exp(-beat * 6.5);
float centerPool = exp(-r * r * 0.85) * hitPulse;
vec3 directLight = vec3(0.0);
if (uLightMode == 0) {
directLight += vec3(0.50, 0.32, 0.12) * centerPool * 0.36;
directLight += vec3(0.05, 0.24, 0.40) * exp(-abs(r - 1.32) * 2.4) * 0.14;
directLight += vec3(0.32, 0.05, 0.24) * exp(-abs(r - 1.08) * 2.8) * 0.10;
directLight += vec3(0.0045, 0.0055, 0.0090);
} else if (uLightMode == 1) {
directLight += vec3(0.12) * centerPool + vec3(0.018);
} else if (uLightMode == 2) {
vec3 Lg = normalize(vec3(0.92, 0.18, 0.34));
vec3 H = normalize(Lg - rd);
float spec = pow(max(dot(N, H), 0.0), 48.0);
directLight += vec3(0.85, 0.68, 0.45) * (0.04 + spec * 0.65);
directLight += vec3(0.28, 0.20, 0.10) * centerPool * 0.25 + vec3(0.006);
} else if (uLightMode == 3) {
vec3 Lb = normalize(vec3(0.0, 0.28, -0.96));
vec3 H = normalize(Lb - rd);
float spec = pow(max(dot(N, H), 0.0), 32.0);
directLight += vec3(0.32, 0.62, 0.96) * (0.04 + spec * 0.72);
directLight += vec3(0.24, 0.30, 0.40) * centerPool * 0.22 + vec3(0.005);
}
vec3 floorCol = baseAlbedo * (1.0 + directLight * 2.8) + directLight * 0.16;
floorCol += ringCol * rings * (0.14 + 0.38 * centerPool);
// True planar reflection of the 3D slash ribbons & clash nexus
vec3 rdRef = reflect(rd, N);
vec3 refUp = vec3(0.0, 1.0, 0.0);
vec3 refRight = normalize(cross(rdRef, refUp));
refUp = normalize(cross(refRight, rdRef));
vec3 vfxRef = evalVFX(p, rdRef, refRight, refUp, phase, 20.0, true);
float gloss = mix(0.68, 0.96, 1.0 - grain1 * 0.45) * exp(-r * 0.18);
float refGain = (uLightMode == 1) ? 0.46 : 0.80;
floorCol += vfxRef * fresnel * gloss * refGain;
float fog = 1.0 - exp(-tFloor * 0.09);
vec3 fogCol = (uLightMode == 1) ? vec3(0.014) : vec3(0.0042, 0.0050, 0.0085);
floorCol = mix(floorCol, fogCol, clamp(fog, 0.0, 0.88));
return floorCol;
}
// -----------------------------------------------------------------------------
// Main Entry Point
// -----------------------------------------------------------------------------
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 uv = (pfx_frag_xy - 0.5 * uResolution.xy) / uResolution.y;
// Strictly periodic 3.0s seamless animation phase in [0, 1)
float phase = fract(uTime / 3.0);
// Subtle periodic camera breathing & impact micro-shake synced to the 5 hits
float beat = fract(phase * 5.0 + 0.06);
float shakeEnv = exp(-beat * 14.0) * 0.010;
vec2 microShake = vec2(sin(phase * TAU * 15.0), cos(phase * TAU * 20.0)) * shakeEnv;
// Camera setup: 0 = hero dramatic low-angle arena framing, 1 = ~2.5x macro close-up
vec3 ro, ta;
float fov;
if (uCamMode == 1) {
ro = vec3(0.32 + 0.04 * sin(phase * TAU), 1.26 + 0.02 * cos(phase * TAU), 1.70);
ta = vec3(0.02, 1.24, 0.0);
fov = 1.62;
} else {
ro = vec3(0.05 * sin(phase * TAU), 0.82 + 0.02 * cos(phase * TAU), 3.62);
ta = vec3(0.0, 1.15, 0.0);
fov = 1.28;
}
ro.xy += microShake;
vec3 camFwd = normalize(ta - ro);
vec3 camRight = normalize(cross(camFwd, vec3(0.0, 1.0, 0.0)));
vec3 camUp = normalize(cross(camRight, camFwd));
vec3 rd = normalize(camFwd * fov + camRight * uv.x + camUp * uv.y);
float tFloor = 1e6;
bool hitFloor = false;
if (rd.y < -0.0005) {
float tf = -ro.y / rd.y;
if (tf > 0.05 && tf < 32.0) {
tFloor = tf;
hitFloor = true;
}
}
vec3 bg = hitFloor
? evalArenaFloor(ro, rd, camRight, camUp, phase, tFloor)
: evalArenaBackdrop(ro, rd, phase);
vec3 vfx = evalVFX(ro, rd, camRight, camUp, phase, tFloor, false);
vec3 col = (uLightMode == 1) ? (bg + vfx * 0.85) : (bg + vfx);
float vig = 1.0 - 0.14 * dot(uv, uv);
col *= clamp(vig, 0.82, 1.0);
// Clean ACES filmic tonemapping with soft highlight knee (%clip < 1%)
float peak = max(col.r, max(col.g, col.b));
col *= 1.0 / (1.0 + 0.16 * peak);
col = acesFilm(col * 1.06) * 0.965;
// Gamma to sRGB
col = pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2));
// Strictly enforce R == G == B in neutral grayscale form study mode
if (uLightMode == 1) {
float g = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(g);
}
fragColor = vec4(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;
// Rapid Combo Slash Flurry — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/vfx_animated/lib/05_rapid_combo_slash_flurry.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;
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
const vec3 CENTER = vec3(0.0, 1.24, 0.0);
// -----------------------------------------------------------------------------
// Fast procedural hashes, value noise & domain-warped fBM (zero textures)
// -----------------------------------------------------------------------------
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);
}
vec2 hash22(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.xx + p3.yz) * p3.zy);
}
float vnoise(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
f = 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, f.x), mix(c, d, f.x), f.y);
}
float fbm3(vec2 p) {
float v = 0.0;
float a = 0.5;
mat2 rot = mat2(0.80, 0.60, -0.60, 0.80);
for (int i = 0; i < 3; i++) {
v += a * vnoise(p);
p = rot * p * 2.05 + vec2(13.7, 29.3);
a *= 0.5;
}
return v;
}
// Turbulent domain-warped fBM for painterly smoky plasma wakes
float warpedFbm(vec2 p, float flow) {
vec2 q = vec2(
fbm3(p + vec2(flow * 0.7, 1.4)),
fbm3(p + vec2(5.2, flow * 0.5 + 8.3))
);
return fbm3(p + 1.85 * q);
}
// -----------------------------------------------------------------------------
// 3D & 2D rotation helpers
// -----------------------------------------------------------------------------
mat3 rotX(float a) {
float c = cos(a), s = sin(a);
return mat3(1.0, 0.0, 0.0, 0.0, c, -s, 0.0, s, c);
}
mat3 rotY(float a) {
float c = cos(a), s = sin(a);
return mat3(c, 0.0, s, 0.0, 1.0, 0.0, -s, 0.0, c);
}
mat3 rotZ(float a) {
float c = cos(a), s = sin(a);
return mat3(c, -s, 0.0, s, c, 0.0, 0.0, 0.0, 1.0);
}
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
// -----------------------------------------------------------------------------
// ACES Filmic Tonemapping (%clip < 1%)
// -----------------------------------------------------------------------------
vec3 acesFilm(vec3 x) {
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
return clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0.0, 1.0);
}
// -----------------------------------------------------------------------------
// 5 Dramatic Sweeping 3D Painterly-Volumetric Sword-Slash Ribbons
// Bold perspective tilts + expanding spiral-crescent curvature (NOT flat hoops!)
// -----------------------------------------------------------------------------
struct SlashDef {
mat3 basis; // columns: U, V, N
vec3 offset; // 3D center offset for dynamic depth layering
vec2 radii; // (rx, ry) major/minor sweep scale
float maxWidth; // wide dramatic crescent belly (0.34..0.44)
float spiral; // radial expansion from tail to head (breaks circular hoop look!)
float startAng; // strike start angle
float dir; // +1 or -1 sweep direction
float phaseOff; // staggered k/5.0 combo offset
vec3 colCore; // incandescent leading blade spine
vec3 colMid; // vibrant plasma body
vec3 colSmoke; // deep turbulent smoky wake
float electric; // crackling lightning arc intensity
};
SlashDef getSlash(int k) {
SlashDef s;
if (k == 0) {
// 1. Electric Cyan Hero Slash: dramatic sweeping upper-left to lower-right
s.basis = rotZ(-0.48) * rotX(0.58) * rotY(0.28);
s.offset = vec3(-0.08, 0.10, 0.06);
s.radii = vec2(1.66, 1.12);
s.maxWidth = 0.42;
s.spiral = 0.24;
s.startAng = 2.75;
s.dir = -1.0;
s.phaseOff = 0.06;
s.colCore = vec3(0.86, 0.99, 1.00);
s.colMid = vec3(0.02, 0.86, 1.00);
s.colSmoke = vec3(0.01, 0.22, 0.72);
s.electric = 1.0;
} else if (k == 1) {
// 2. Solar Gold Hero Slash: bold counter-diagonal lower-left to upper-right
s.basis = rotZ(0.42) * rotX(0.56) * rotY(-0.30);
s.offset = vec3(0.06, 0.02, -0.05);
s.radii = vec2(1.62, 1.08);
s.maxWidth = 0.40;
s.spiral = 0.22;
s.startAng = -2.20;
s.dir = 1.0;
s.phaseOff = 0.86;
s.colCore = vec3(1.00, 0.97, 0.80);
s.colMid = vec3(1.00, 0.64, 0.06);
s.colSmoke = vec3(0.76, 0.16, 0.01);
s.electric = 0.35;
} else if (k == 2) {
// 3. Hot Magenta-Crimson Slash: steep whipping diagonal across front-center
s.basis = rotZ(0.68) * rotX(-0.50) * rotY(0.26);
s.offset = vec3(0.04, 0.04, 0.12);
s.radii = vec2(1.48, 0.96);
s.maxWidth = 0.38;
s.spiral = 0.26;
s.startAng = -1.45;
s.dir = 1.0;
s.phaseOff = 0.26;
s.colCore = vec3(1.00, 0.84, 0.94);
s.colMid = vec3(1.00, 0.08, 0.54);
s.colSmoke = vec3(0.55, 0.02, 0.36);
s.electric = 0.75;
} else if (k == 3) {
// 4. Fiery Crimson-Scarlet Cross-Slash: sweeping low-to-high foreground arc
s.basis = rotZ(-0.22) * rotX(0.68) * rotY(-0.36);
s.offset = vec3(-0.02, 0.00, 0.14);
s.radii = vec2(1.46, 0.88);
s.maxWidth = 0.35;
s.spiral = 0.20;
s.startAng = 2.05;
s.dir = -1.0;
s.phaseOff = 0.46;
s.colCore = vec3(1.00, 0.86, 0.68);
s.colMid = vec3(1.00, 0.18, 0.05);
s.colSmoke = vec3(0.58, 0.02, 0.02);
s.electric = 0.25;
} else {
// 5. Electric Cyan-Gold High Orbital Slash: deep background/foreground weave
s.basis = rotZ(-0.76) * rotX(-0.46) * rotY(-0.32);
s.offset = vec3(0.08, 0.08, -0.10);
s.radii = vec2(1.38, 0.98);
s.maxWidth = 0.36;
s.spiral = 0.25;
s.startAng = 0.75;
s.dir = -1.0;
s.phaseOff = 0.66;
s.colCore = vec3(0.90, 0.99, 1.00);
s.colMid = vec3(0.08, 0.78, 1.00);
s.colSmoke = vec3(0.04, 0.20, 0.68);
s.electric = 0.85;
}
return s;
}
// -----------------------------------------------------------------------------
// Evaluate a single volumetric slice of a painterly 3D sword-slash smear ribbon
// -----------------------------------------------------------------------------
vec4 evalSlashSlice(
SlashDef sl,
vec3 ro,
vec3 rd,
float pk,
float maxT,
float sliceOff, // volumetric offset along normal N
float sliceWeight, // Gaussian thickness weight
bool isReflection,
out float hitT
) {
hitT = 1e6;
vec3 U = sl.basis[0];
vec3 V = sl.basis[1];
vec3 N = sl.basis[2];
vec3 C = CENTER + sl.offset + N * sliceOff;
float denom = dot(rd, N);
float absDenom = abs(denom);
if (absDenom < 0.03) return vec4(0.0);
float t = dot(C - ro, N) / denom;
if (t <= 0.08 || t >= maxT) return vec4(0.0);
vec3 P = ro + rd * t;
// Smooth height fade above floor eliminates any plane/floor clip line
float floorFade = smoothstep(0.04, 0.30, P.y);
if (floorFade <= 0.001) return vec4(0.0);
vec2 p2 = vec2(dot(P - C, U), dot(P - C, V));
vec2 q = p2 / sl.radii;
float rad = length(q);
if (rad < 0.08 || rad > 1.44) return vec4(0.0);
hitT = t;
float ang = atan(q.y, q.x);
// Explosive whip-out sweep ease
float whipT = clamp(pk / 0.48, 0.0, 1.0);
float sweep = 1.0 - pow(1.0 - whipT, 2.85);
float headAng = sl.startAng + sl.dir * (sweep * 4.50 + pk * 1.15);
// Sweeping crescent angular span (strictly < 3.6 rad so head & tail never touch)
float arcLen = mix(0.65, 3.45, smoothstep(0.0, 0.18, pk))
* mix(1.0, 0.70, smoothstep(0.60, 0.96, pk));
float env = smoothstep(0.0, 0.04, pk) * (1.0 - smoothstep(0.68, 0.98, pk));
if (env <= 0.002) return vec4(0.0);
// Continuous angular distance behind the leading blade tip in [0, TAU)
float da = mod(sl.dir * (headAng - ang) + TAU * 6.0, TAU);
float u = da / max(arcLen, 0.001);
if (u <= 0.0 || u >= 1.0) return vec4(0.0);
// Smooth razor tip entry & turbulent wispy tail exit
float headFade = smoothstep(0.0, 0.035, u);
float tailFade = 1.0 - smoothstep(0.55, 1.0, u);
float inArc = headFade * tailFade;
if (inArc <= 0.001) return vec4(0.0);
// Expanding spiral-crescent outer blade contour (NOT a circular hula-hoop!)
float twist = sliceOff * 0.55 * sin(u * PI * 1.5);
float rOut = 1.08 - sl.spiral * pow(u, 0.85) + 0.04 * sin(u * PI) + twist;
// Dramatic wide crescent belly tapering to razor tip and feathered smoky wake
float belly = pow(u, 0.36) * pow(1.0 - u, 1.15) * 2.10;
float w = sl.maxWidth * clamp(belly, 0.0, 1.12);
w *= mix(1.0, 0.65, smoothstep(0.58, 0.96, pk));
// Normalized radial wake coordinate: v=0 razor leading edge, v>0 deep smoky wake
float v = (rOut - rad) / max(w, 0.004);
if (v > 1.75) return vec4(0.0);
// Domain-warped painterly brush-stroke turbulence (continuous in da, zero seam!)
float flow = da * 2.4 - pk * 8.5 + sliceOff * 6.0;
vec2 smearUV = vec2(flow * 0.85, clamp(v, -0.2, 1.6) * 5.0 + sliceOff * 2.5);
float turb = isReflection
? fbm3(smearUV * vec2(1.0, 1.4))
: warpedFbm(smearUV, flow * 0.45);
// High-frequency brushed ink/plasma motion streaks stretched along the swing
float fineStreaks = vnoise(vec2(flow * 2.6, clamp(v, -0.2, 1.6) * 20.0 + turb * 3.2));
float brushFibers = smoothstep(0.20, 0.82, turb * 0.68 + fineStreaks * 0.32);
// Razor-sharp outer cut, ZERO hard inner circular cutout!
// Exponential + domain-warped turbulent feather dissolves organically into darkness
float outerCut = smoothstep(-0.012, 0.005, rOut - rad);
float vPos = max(v, 0.0);
float innerSoftFeather = exp(-vPos * (1.75 + 2.20 * (1.0 - turb)))
* (1.0 - smoothstep(0.45, 1.45, vPos - (turb - 0.5) * 0.55))
* smoothstep(0.10, 0.36, rad);
float wakeMask = outerCut * innerSoftFeather * inArc;
// Progressive smoky dissolution across v (wake depth), u (tail), and pk (lifecycle)
float dissolve = smoothstep(0.54, 0.96, pk);
float smokeBreakup = smoothstep(
0.14 + 0.34 * vPos + 0.24 * u + 0.35 * dissolve,
0.86,
turb * 0.72 + fineStreaks * 0.28
);
float wakeDensity = wakeMask * mix(0.58 + 0.42 * brushFibers, smokeBreakup, smoothstep(0.06, 0.58, vPos));
// Incandescent razor-sharp leading blade spine & scorching tip glint
float razorSpine = exp(-abs(rad - (rOut - 0.007)) * 115.0) * headFade * (1.0 - smoothstep(0.25, 0.78, u));
float subSpine = exp(-abs(rad - (rOut - 0.028 * (1.0 + turb * 0.6))) * 65.0) * headFade * (1.0 - smoothstep(0.35, 0.85, u)) * brushFibers;
float tipFlare = exp(-abs(rad - rOut) * 48.0) * exp(-u * 14.0) * headFade;
// Hot metallic sparks & glowing embers shedding tangentially ALONG the blade trail!
float trailSparks = 0.0;
if (!isReflection && abs(sliceOff) < 0.01 && v > -0.18 && v < 1.15) {
vec2 spGrid = vec2(da * 11.0 - pk * 14.0, (rOut - rad) * 24.0);
vec2 spCell = floor(spGrid);
vec2 spF = fract(spGrid) - 0.5;
vec2 rnd = hash22(spCell + vec2(sl.phaseOff * 37.0, 11.3));
if (rnd.x > 0.62) {
vec2 off = (rnd - 0.5) * 0.52;
vec2 dSp = spF - off;
// Elongated tangential ember streak following the blade sweep
float dStreak = length(vec2(dSp.x * 0.42, dSp.y * 2.4));
trailSparks = exp(-dStreak * 13.5) * inArc * (1.0 - smoothstep(0.85, 1.15, vPos)) * (0.6 + 0.4 * rnd.y);
}
}
// 3D perspective depth emphasis: closer foreground sweeps feel bolder & richer
float depthBoost = clamp(3.5 / max(t, 1.2), 0.72, 1.45);
float angleFade = smoothstep(0.03, 0.20, absDenom) * floorFade;
// -------------------------------------------------------------------------
// uLightMode == 1: Neutral grayscale sculptural form/ribbon study (R==G==B)
// -------------------------------------------------------------------------
if (uLightMode == 1) {
vec3 Nface = (denom < 0.0) ? N : -N;
vec3 L1 = normalize(vec3(0.55, 0.80, 0.65));
vec3 L2 = normalize(vec3(-0.70, 0.35, -0.45));
float ndl1 = max(dot(Nface, L1), 0.0);
float ndl2 = max(dot(Nface, L2), 0.0);
float fres = pow(1.0 - clamp(absDenom, 0.0, 1.0), 2.4);
float shade = 0.16 + 0.54 * ndl1 + 0.18 * ndl2 + 0.24 * fres;
float val = shade * wakeDensity * 0.90 + (0.58 * razorSpine + 0.28 * subSpine + 0.40 * tipFlare + 0.55 * trailSparks);
val *= env * angleFade * sliceWeight * depthBoost;
float alpha = clamp((wakeDensity * 0.82 + razorSpine * 0.65) * env * angleFade * sliceWeight, 0.0, 1.0);
return vec4(vec3(val), alpha);
}
// -------------------------------------------------------------------------
// Hero & Lighting Modes (0, 2, 3): Painterly Volumetric Plasma + Smoke Wake
// -------------------------------------------------------------------------
float dEdge = max(rad - rOut, 0.0);
float tightAura = exp(-dEdge * (isReflection ? 20.0 : 34.0)) * inArc * (1.0 - 0.55 * u) * (0.45 + 0.55 * brushFibers);
// Localized organic branching lightning arcs peeling off the blade wake
float bolt = 0.0;
if (sl.electric > 0.15 && !isReflection && abs(sliceOff) < 0.01) {
float bFlow = da * 7.5 + pk * 11.0;
float pocket = smoothstep(0.46, 0.78, vnoise(vec2(da * 1.9 - pk * 3.5, 4.7)));
float jag1 = (fbm3(vec2(bFlow, 2.3)) - 0.5) * 0.16;
float jag2 = (vnoise(vec2(bFlow * 2.8, 9.1)) - 0.5) * 0.07;
float boltR = rOut + 0.035 + (jag1 + jag2) * pocket;
float bMask = smoothstep(0.06, 0.16, u) * (1.0 - smoothstep(0.45, 0.80, u)) * pocket;
bolt = exp(-abs(rad - boltR) * 165.0) * bMask * sl.electric;
float forkR = rOut + 0.075 + (jag1 * 1.4 - jag2 * 1.2) * pocket;
bolt += exp(-abs(rad - forkR) * 195.0) * bMask * smoothstep(0.62, 0.88, pocket) * sl.electric * 0.72;
}
// Painterly color gradient: incandescent white-hot spine -> vivid plasma -> deep smoky wake
float wakeGrad = clamp(vPos * 1.05 + (1.0 - brushFibers) * 0.35 + u * 0.25, 0.0, 1.0);
vec3 bodyCol = mix(sl.colMid, sl.colSmoke, wakeGrad);
bodyCol = mix(bodyCol, sl.colCore, clamp(exp(-vPos * 11.0) * 0.55 + subSpine * 0.50, 0.0, 1.0));
float modeGain = 1.0;
if (uLightMode == 2) {
vec3 Nface = (denom < 0.0) ? N : -N;
vec3 Lg = normalize(vec3(0.92, 0.22, 0.32));
float graze = pow(max(dot(Nface, Lg), 0.0), 2.2);
bodyCol += vec3(1.0, 0.86, 0.62) * graze * 0.42 * wakeDensity;
modeGain = 0.94;
} else if (uLightMode == 3) {
float rim = pow(1.0 - clamp(absDenom, 0.0, 1.0), 1.8);
bodyCol += vec3(0.32, 0.78, 1.0) * rim * 0.48 * wakeDensity;
modeGain = 0.96;
}
vec3 sparkTint = mix(vec3(1.0, 0.82, 0.38), sl.colCore, 0.45);
vec3 energy = bodyCol * (wakeDensity * (0.95 + 0.80 * brushFibers) * 1.32)
+ sl.colSmoke * (tightAura * 0.28)
+ sl.colMid * (tightAura * 0.16 + subSpine * 0.85)
+ sl.colCore * (razorSpine * 1.75 + tipFlare * 1.45)
+ mix(sl.colMid, sl.colCore, 0.62) * bolt * 1.95
+ sparkTint * trailSparks * 2.20;
energy *= env * angleFade * sliceWeight * depthBoost * modeGain;
float alpha = clamp((wakeDensity * 0.72 + razorSpine * 0.55) * env * angleFade * sliceWeight, 0.0, 0.95);
return vec4(energy, alpha);
}
// -----------------------------------------------------------------------------
// Multi-slice 3D Volumetric Slash Ribbon Evaluator (3 slices for hero, 1 for reflection)
// -----------------------------------------------------------------------------
vec4 evalVolumetricSlash(
SlashDef sl,
vec3 ro,
vec3 rd,
float phase,
float maxT,
bool isReflection,
out float hitT
) {
hitT = 1e6;
float pk = fract(phase + sl.phaseOff);
// Quick center-plane bounding reject before volumetric multi-slice integration
float t0;
vec4 centerHit = evalSlashSlice(sl, ro, rd, pk, maxT, 0.0, isReflection ? 1.0 : 0.52, isReflection, t0);
hitT = t0;
if (isReflection) {
return centerHit;
}
// If center plane completely missed the bounding volume, skip side slices
if (t0 > 1e5) return vec4(0.0);
// Accumulate front & back volumetric plasma thickness slices for true 3D painterly depth
float tFront, tBack;
vec4 frontHit = evalSlashSlice(sl, ro, rd, pk, maxT, 0.048, 0.34, false, tFront);
vec4 backHit = evalSlashSlice(sl, ro, rd, pk, maxT, -0.048, 0.34, false, tBack);
hitT = min(t0, min(tFront, tBack));
vec3 rgb = centerHit.rgb + frontHit.rgb + backHit.rgb;
float a = clamp(centerHit.a + frontHit.a * 0.65 + backHit.a * 0.65, 0.0, 0.96);
return vec4(rgb, a);
}
// -----------------------------------------------------------------------------
// Dynamic Clash Vortex & Kinetic Blade-Cross Core (NO generic white sunburst!)
// -----------------------------------------------------------------------------
vec3 evalClashNexus(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float phase, float maxT, bool isReflection) {
vec3 camFwd = normalize(cross(camRight, camUp));
float denom = dot(rd, camFwd);
if (abs(denom) < 0.05) return vec3(0.0);
float t = dot(CENTER - ro, camFwd) / denom;
if (t <= 0.08 || t >= maxT) return vec3(0.0);
vec3 P = ro + rd * t;
float floorFade = smoothstep(0.06, 0.40, P.y);
if (floorFade <= 0.001) return vec3(0.0);
vec3 rel = P - CENTER;
vec2 uv = vec2(dot(rel, camRight), dot(rel, camUp));
float r = length(uv);
if (r > 1.35) return vec3(0.0);
// 5-beat rapid combo strike pulse synced to the 5 ribbons
float beat = fract(phase * 5.0 + 0.06);
float hitPulse = 0.55 + 0.72 * exp(-beat * 7.5);
// 1. Swirling turbulent clash plasma vortex (compact, painterly, NOT a smooth white blob)
vec2 swirlP = rot2(r * 2.6 - phase * TAU) * uv * 3.4;
float vortexNoise = isReflection
? fbm3(swirlP)
: warpedFbm(swirlP, phase * TAU * 0.5);
float vortexMask = exp(-r * 3.4) * smoothstep(0.28, 0.82, vortexNoise);
float hotPinpoint = exp(-r * 22.0) * 1.45;
// 2. Razor-sharp kinetic cross-slash blade glints (echoing crossed katana strikes)
vec3 bladeCol = vec3(0.0);
float bladeLum = 0.0;
for (int b = 0; b < 3; b++) {
float fb = float(b);
float bBeat = fract(phase * 5.0 + fb * 0.33 + 0.04);
float bEnv = 0.38 + 0.62 * exp(-bBeat * 5.5);
float bAng = (b == 0) ? -0.78 : ((b == 1) ? 0.56 : 1.02);
vec2 bu = rot2(bAng) * uv;
float along = smoothstep(-0.18, 0.14, bu.x) * (1.0 - smoothstep(0.55, 1.05, bu.x));
float halfW = mix(0.013, 0.0012, clamp((bu.x + 0.18) / 1.22, 0.0, 1.0));
float dBlade = abs(bu.y) / max(halfW, 0.001);
float core = exp(-dBlade * 3.2) * along * bEnv;
float glow = exp(-abs(bu.y) * 52.0) * along * bEnv * 0.22;
vec3 bc = (b == 0) ? vec3(0.35, 0.88, 1.0) : ((b == 1) ? vec3(1.0, 0.36, 0.78) : vec3(1.0, 0.76, 0.24));
bladeCol += mix(bc, vec3(1.0, 0.98, 0.94), core * 0.78) * (core * 1.35 + glow);
bladeLum += core * 0.85;
}
// 3. Turbulent ragged shockwave wisp (domain-warped, NOT a rigid geometric circle)
float shockR = 0.18 + beat * 0.92 + (vortexNoise - 0.5) * 0.12;
float shockWisp = exp(-abs(r - shockR) * 42.0) * smoothstep(0.35, 0.80, vortexNoise) * pow(1.0 - beat, 2.0) * 0.62;
if (uLightMode == 1) {
float lum = (hotPinpoint * 0.45 + vortexMask * 0.38 + shockWisp * 0.45 + bladeLum * 0.65) * (0.7 + 0.3 * hitPulse);
return vec3(lum) * floorFade;
}
vec3 col = vec3(1.0, 0.95, 0.82) * hotPinpoint * hitPulse
+ mix(vec3(1.0, 0.52, 0.08), vec3(0.14, 0.82, 1.0), smoothstep(0.3, 0.8, vortexNoise)) * vortexMask * 0.85 * hitPulse
+ vec3(1.0, 0.72, 0.28) * shockWisp
+ bladeCol * (isReflection ? 0.55 : 0.92);
return col * floorFade;
}
// -----------------------------------------------------------------------------
// Sparse Asymmetric Hot Metallic Clash Sparks (NO dandelion bicycle-wheel!)
// Smooth floor-height fade prevents any horizontal floor guillotine line
// -----------------------------------------------------------------------------
vec3 evalMetallicSparks(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float phase, float maxT) {
vec3 camFwd = normalize(cross(camRight, camUp));
float denom = dot(rd, camFwd);
if (abs(denom) < 0.05) return vec3(0.0);
vec3 acc = vec3(0.0);
// 2 sparse asymmetric parallax planes (cut radial spokes by >65%)
for (int layer = 0; layer < 2; layer++) {
float fl = float(layer);
float zOff = (layer == 0) ? 0.28 : -0.22;
vec3 planeC = CENTER + camFwd * zOff;
float t = dot(planeC - ro, camFwd) / denom;
if (t <= 0.1 || t >= maxT) continue;
vec3 P = ro + rd * t;
// Smooth floor proximity fade eliminates horizontal guillotine cutoff!
float floorFade = smoothstep(0.08, 0.46, P.y);
if (floorFade <= 0.001) continue;
vec3 rel = P - planeC;
vec2 uv = vec2(dot(rel, camRight), dot(rel, camUp));
float r = length(uv);
if (r < 0.10 || r > 1.85) continue;
vec2 cUV = rot2(r * 0.26 * (layer == 1 ? -1.0 : 1.0)) * uv;
float ang = atan(cUV.y, cUV.x);
float sectors = (layer == 0) ? 28.0 : 22.0;
float secId = floor((ang + PI) / TAU * sectors);
float h1 = hash21(vec2(secId, fl * 17.3 + 1.1));
float h2 = hash21(vec2(secId, fl * 31.7 + 6.7));
float h3 = hash21(vec2(secId, fl * 47.9 + 2.9));
float h4 = hash21(vec2(secId, fl * 61.1 + 9.3));
// Randomly skip ~62% of sectors for organic, asymmetric clash bursts
if (h1 < 0.62) continue;
float sectorStep = TAU / sectors;
float secCenter = (secId + 0.5 + (h4 - 0.5) * 0.45) * sectorStep - PI;
float angDiff = abs(ang - secCenter);
if (angDiff > sectorStep * 0.48) continue;
float speedMult = (h2 < 0.45) ? 2.0 : 3.0;
float sp = fract(phase * speedMult + h1 * 2.7);
// Varied asymmetric reach & streak length per spark
float maxReach = 0.72 + 1.05 * h3 * h3;
float sparkR = 0.16 + pow(sp, 0.68) * maxReach;
float streakLen = 0.024 + 0.068 * (1.0 - sp) * (0.35 + 0.65 * h2);
float dAng = angDiff * r;
float dRad = abs(r - sparkR);
float needle = exp(-dAng * 260.0) * exp(-dRad / max(streakLen, 0.006));
float hotHead = exp(-dAng * 150.0) * exp(-abs(r - (sparkR + streakLen * 0.42)) * 135.0);
float env = smoothstep(0.0, 0.06, sp) * (1.0 - smoothstep(0.54, 1.0, sp)) * floorFade;
vec3 sCol;
if (h3 < 0.66) {
sCol = mix(vec3(1.0, 0.44, 0.05), vec3(1.0, 0.84, 0.30), 1.0 - sp);
} else if (h3 < 0.84) {
sCol = vec3(0.16, 0.90, 1.0);
} else {
sCol = vec3(1.0, 0.22, 0.64);
}
if (uLightMode == 1) {
acc += vec3((needle * 0.38 + hotHead * 0.60) * env);
} else {
acc += (sCol * needle * 1.45 + mix(sCol, vec3(1.0, 0.99, 0.94), 0.78) * hotHead * 1.85) * env;
}
}
return acc;
}
// -----------------------------------------------------------------------------
// Composite all 3D VFX (5 volumetric slash ribbons + clash nexus + metallic sparks)
// -----------------------------------------------------------------------------
vec3 evalVFX(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float phase, float maxT, bool isReflection) {
vec4 rCol[5];
float rT[5];
for (int k = 0; k < 5; k++) {
rCol[k] = evalVolumetricSlash(getSlash(k), ro, rd, phase, maxT, isReflection, rT[k]);
}
vec3 camFwd = normalize(cross(camRight, camUp));
float coreT = dot(CENTER - ro, camFwd) / (dot(rd, camFwd) + 1e-5);
vec3 behindCore = vec3(0.0);
vec3 frontCore = vec3(0.0);
float frontAlpha = 0.0;
for (int k = 0; k < 5; k++) {
if (rCol[k].a <= 0.0005 && dot(rCol[k].rgb, vec3(1.0)) <= 0.0005) continue;
if (rT[k] < coreT) {
if (uLightMode == 1) {
frontCore = mix(frontCore, rCol[k].rgb, rCol[k].a * (1.0 - frontAlpha * 0.42))
+ rCol[k].rgb * (1.0 - rCol[k].a) * 0.16;
frontAlpha = clamp(frontAlpha + rCol[k].a * 0.55, 0.0, 0.92);
} else {
frontCore += rCol[k].rgb;
frontAlpha = clamp(frontAlpha + rCol[k].a * 0.34, 0.0, 0.74);
}
} else {
if (uLightMode == 1) {
behindCore = max(behindCore, rCol[k].rgb);
} else {
behindCore += rCol[k].rgb;
}
}
}
vec3 coreCol = evalClashNexus(ro, rd, camRight, camUp, phase, maxT, isReflection);
vec3 sparkCol = isReflection ? vec3(0.0) : evalMetallicSparks(ro, rd, camRight, camUp, phase, maxT);
if (uLightMode == 1) {
vec3 base = max(behindCore, coreCol * 0.72);
vec3 res = mix(base, frontCore, clamp(frontAlpha, 0.0, 0.88)) + frontCore * 0.20;
res += sparkCol * 0.48;
return res;
}
return behindCore * 0.92 + coreCol * (1.0 - frontAlpha * 0.25) + frontCore + sparkCol;
}
// -----------------------------------------------------------------------------
// Deep Moody Combat Arena Backdrop (lumMin ~ 8-14 sRGB, zero washed-out fog)
// -----------------------------------------------------------------------------
vec3 evalArenaBackdrop(vec3 ro, vec3 rd, float phase) {
float elev = clamp(rd.y * 0.5 + 0.5, 0.0, 1.0);
vec3 skyLow = vec3(0.0050, 0.0058, 0.0098);
vec3 skyHigh = vec3(0.0024, 0.0030, 0.0055);
vec3 col = mix(skyLow, skyHigh, smoothstep(0.42, 0.92, elev));
// Distant cylindrical stadium arena wall & steel trusses
float horiz = max(length(rd.xz), 0.001);
float wallT = 6.8 / horiz;
vec3 wallP = ro + rd * wallT;
float wallY = wallP.y;
float wallAng = atan(wallP.z, wallP.x);
// Subtle overhead arena spotlight shaft
float spotCone = exp(-abs(rd.x) * 5.2) * smoothstep(0.02, 0.62, rd.y) * 0.015;
col += vec3(0.45, 0.60, 0.88) * spotCone;
// Dark structural arena trusses
float ribV = smoothstep(0.93, 0.99, abs(sin(wallAng * 14.0)));
float ribH = smoothstep(0.94, 0.99, abs(sin(wallY * 4.2)));
float wallMask = smoothstep(-0.01, 0.14, rd.y) * (1.0 - smoothstep(0.50, 0.82, rd.y));
col += vec3(0.0042, 0.0055, 0.0092) * (ribV * 0.65 + ribH * 0.55) * wallMask;
// Crisp distant perimeter arena floodlights
float lightSlot = fract(wallAng / TAU * 14.0 + 0.5) - 0.5;
float dLight = length(vec2(lightSlot * 4.0, (wallY - 1.48) * 1.4));
float bokeh = exp(-dLight * dLight * 58.0) * 0.085 * wallMask;
col += vec3(0.66, 0.78, 1.0) * bokeh;
// Low perimeter stage rim lights near floor horizon
float lowSlot = fract(wallAng / TAU * 10.0) - 0.5;
float dLow = length(vec2(lowSlot * 4.2, (wallY - 0.18) * 3.6));
float lowGlow = exp(-dLow * dLow * 40.0) * 0.075 * smoothstep(-0.02, 0.08, rd.y);
col += vec3(0.84, 0.80, 0.96) * lowGlow;
vec3 toCenter = normalize(CENTER - ro);
float centerAlign = max(dot(rd, toCenter), 0.0);
float beat = fract(phase * 5.0 + 0.06);
float hazePulse = 0.85 + 0.25 * exp(-beat * 6.0);
if (uLightMode == 0) {
col += vec3(0.012, 0.010, 0.016) * pow(centerAlign, 8.0) * hazePulse;
} else if (uLightMode == 1) {
col = mix(vec3(0.018), vec3(0.006), smoothstep(0.0, 0.72, max(rd.y, 0.0)));
col += vec3(0.014) * pow(centerAlign, 5.0);
} else if (uLightMode == 2) {
float keyAlign = max(dot(rd, normalize(vec3(0.92, 0.18, 0.35))), 0.0);
col += vec3(0.055, 0.038, 0.020) * pow(keyAlign, 8.0);
col += vec3(0.012, 0.010, 0.008) * pow(centerAlign, 8.0);
} else if (uLightMode == 3) {
// Soft, localized cool backlit rim glow (fades smoothly to horizon — zero blue rectangle or seam!)
float horizSoft = smoothstep(-0.02, 0.22, rd.y);
col += vec3(0.018, 0.046, 0.085) * pow(centerAlign, 9.0) * horizSoft;
col += vec3(0.055, 0.115, 0.205) * pow(centerAlign, 24.0) * horizSoft;
}
return col;
}
// -----------------------------------------------------------------------------
// Dark Reflective Dojo / Arena Stage Floor with Crisp Colored Slash Reflections
// -----------------------------------------------------------------------------
vec3 evalArenaFloor(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float phase, float tFloor) {
vec3 p = ro + rd * tFloor;
float r = length(p.xz);
float ang = atan(p.z, p.x);
float grain1 = fbm3(p.xz * 3.2);
float grain2 = vnoise(vec2(ang * 20.0, r * 7.0));
float plank = 0.5 + 0.5 * sin(p.x * 10.0 + grain1 * 0.5);
vec3 baseAlbedo = mix(vec3(0.0055, 0.0062, 0.0092), vec3(0.010, 0.011, 0.015), grain1 * 0.6 + plank * 0.4);
// Concentric brushed-gold dojo stage rings
float ring1 = exp(-abs(r - 1.50) * 48.0);
float ring2 = exp(-abs(r - 2.12) * 38.0);
float ring3 = exp(-abs(r - 2.24) * 32.0);
float rings = clamp(ring1 * 0.60 + ring2 * 0.92 + ring3 * 0.72, 0.0, 1.0);
vec3 ringCol = (uLightMode == 1) ? vec3(0.12) : vec3(0.56, 0.40, 0.16);
vec3 N = normalize(vec3((grain1 - 0.5) * 0.032, 1.0, (grain2 - 0.5) * 0.032));
float ndv = max(-dot(rd, N), 0.001);
float fresnel = mix(0.24, 0.82, pow(1.0 - ndv, 3.0));
float beat = fract(phase * 5.0 + 0.06);
float hitPulse = 0.72 + 0.42 * exp(-beat * 6.5);
float centerPool = exp(-r * r * 0.85) * hitPulse;
vec3 directLight = vec3(0.0);
if (uLightMode == 0) {
directLight += vec3(0.50, 0.32, 0.12) * centerPool * 0.36;
directLight += vec3(0.05, 0.24, 0.40) * exp(-abs(r - 1.32) * 2.4) * 0.14;
directLight += vec3(0.32, 0.05, 0.24) * exp(-abs(r - 1.08) * 2.8) * 0.10;
directLight += vec3(0.0045, 0.0055, 0.0090);
} else if (uLightMode == 1) {
directLight += vec3(0.12) * centerPool + vec3(0.018);
} else if (uLightMode == 2) {
vec3 Lg = normalize(vec3(0.92, 0.18, 0.34));
vec3 H = normalize(Lg - rd);
float spec = pow(max(dot(N, H), 0.0), 48.0);
directLight += vec3(0.85, 0.68, 0.45) * (0.04 + spec * 0.65);
directLight += vec3(0.28, 0.20, 0.10) * centerPool * 0.25 + vec3(0.006);
} else if (uLightMode == 3) {
vec3 Lb = normalize(vec3(0.0, 0.28, -0.96));
vec3 H = normalize(Lb - rd);
float spec = pow(max(dot(N, H), 0.0), 32.0);
directLight += vec3(0.32, 0.62, 0.96) * (0.04 + spec * 0.72);
directLight += vec3(0.24, 0.30, 0.40) * centerPool * 0.22 + vec3(0.005);
}
vec3 floorCol = baseAlbedo * (1.0 + directLight * 2.8) + directLight * 0.16;
floorCol += ringCol * rings * (0.14 + 0.38 * centerPool);
// True planar reflection of the 3D slash ribbons & clash nexus
vec3 rdRef = reflect(rd, N);
vec3 refUp = vec3(0.0, 1.0, 0.0);
vec3 refRight = normalize(cross(rdRef, refUp));
refUp = normalize(cross(refRight, rdRef));
vec3 vfxRef = evalVFX(p, rdRef, refRight, refUp, phase, 20.0, true);
float gloss = mix(0.68, 0.96, 1.0 - grain1 * 0.45) * exp(-r * 0.18);
float refGain = (uLightMode == 1) ? 0.46 : 0.80;
floorCol += vfxRef * fresnel * gloss * refGain;
float fog = 1.0 - exp(-tFloor * 0.09);
vec3 fogCol = (uLightMode == 1) ? vec3(0.014) : vec3(0.0042, 0.0050, 0.0085);
floorCol = mix(floorCol, fogCol, clamp(fog, 0.0, 0.88));
return floorCol;
}
// -----------------------------------------------------------------------------
// Main Entry Point
// -----------------------------------------------------------------------------
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 uv = (pfx_frag_xy - 0.5 * uResolution.xy) / uResolution.y;
// Strictly periodic 3.0s seamless animation phase in [0, 1)
float phase = fract(uTime / 3.0);
// Subtle periodic camera breathing & impact micro-shake synced to the 5 hits
float beat = fract(phase * 5.0 + 0.06);
float shakeEnv = exp(-beat * 14.0) * 0.010;
vec2 microShake = vec2(sin(phase * TAU * 15.0), cos(phase * TAU * 20.0)) * shakeEnv;
// Camera setup: 0 = hero dramatic low-angle arena framing, 1 = ~2.5x macro close-up
vec3 ro, ta;
float fov;
if (uCamMode == 1) {
ro = vec3(0.32 + 0.04 * sin(phase * TAU), 1.26 + 0.02 * cos(phase * TAU), 1.70);
ta = vec3(0.02, 1.24, 0.0);
fov = 1.62;
} else {
ro = vec3(0.05 * sin(phase * TAU), 0.82 + 0.02 * cos(phase * TAU), 3.62);
ta = vec3(0.0, 1.15, 0.0);
fov = 1.28;
}
ro.xy += microShake;
vec3 camFwd = normalize(ta - ro);
vec3 camRight = normalize(cross(camFwd, vec3(0.0, 1.0, 0.0)));
vec3 camUp = normalize(cross(camRight, camFwd));
vec3 rd = normalize(camFwd * fov + camRight * uv.x + camUp * uv.y);
float tFloor = 1e6;
bool hitFloor = false;
if (rd.y < -0.0005) {
float tf = -ro.y / rd.y;
if (tf > 0.05 && tf < 32.0) {
tFloor = tf;
hitFloor = true;
}
}
vec3 bg = hitFloor
? evalArenaFloor(ro, rd, camRight, camUp, phase, tFloor)
: evalArenaBackdrop(ro, rd, phase);
vec3 vfx = evalVFX(ro, rd, camRight, camUp, phase, tFloor, false);
vec3 col = (uLightMode == 1) ? (bg + vfx * 0.85) : (bg + vfx);
float vig = 1.0 - 0.14 * dot(uv, uv);
col *= clamp(vig, 0.82, 1.0);
// Clean ACES filmic tonemapping with soft highlight knee (%clip < 1%)
float peak = max(col.r, max(col.g, col.b));
col *= 1.0 / (1.0 + 0.16 * peak);
col = acesFilm(col * 1.06) * 0.965;
// Gamma to sRGB
col = pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2));
// Strictly enforce R == G == B in neutral grayscale form study mode
if (uLightMode == 1) {
float g = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(g);
}
fragColor = vec4(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);
}
}
// Rapid Combo Slash Flurry — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_animated/lib/05_rapid_combo_slash_flurry.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;
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
const vec3 CENTER = vec3(0.0, 1.24, 0.0);
// -----------------------------------------------------------------------------
// Fast procedural hashes, value noise & domain-warped fBM (zero textures)
// -----------------------------------------------------------------------------
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);
}
vec2 hash22(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.xx + p3.yz) * p3.zy);
}
float vnoise(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
f = 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, f.x), mix(c, d, f.x), f.y);
}
float fbm3(vec2 p) {
float v = 0.0;
float a = 0.5;
mat2 rot = mat2(0.80, 0.60, -0.60, 0.80);
for (int i = 0; i < 3; i++) {
v += a * vnoise(p);
p = rot * p * 2.05 + vec2(13.7, 29.3);
a *= 0.5;
}
return v;
}
// Turbulent domain-warped fBM for painterly smoky plasma wakes
float warpedFbm(vec2 p, float flow) {
vec2 q = vec2(
fbm3(p + vec2(flow * 0.7, 1.4)),
fbm3(p + vec2(5.2, flow * 0.5 + 8.3))
);
return fbm3(p + 1.85 * q);
}
// -----------------------------------------------------------------------------
// 3D & 2D rotation helpers
// -----------------------------------------------------------------------------
mat3 rotX(float a) {
float c = cos(a), s = sin(a);
return mat3(1.0, 0.0, 0.0, 0.0, c, -s, 0.0, s, c);
}
mat3 rotY(float a) {
float c = cos(a), s = sin(a);
return mat3(c, 0.0, s, 0.0, 1.0, 0.0, -s, 0.0, c);
}
mat3 rotZ(float a) {
float c = cos(a), s = sin(a);
return mat3(c, -s, 0.0, s, c, 0.0, 0.0, 0.0, 1.0);
}
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
// -----------------------------------------------------------------------------
// ACES Filmic Tonemapping (%clip < 1%)
// -----------------------------------------------------------------------------
vec3 acesFilm(vec3 x) {
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
return clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0.0, 1.0);
}
// -----------------------------------------------------------------------------
// 5 Dramatic Sweeping 3D Painterly-Volumetric Sword-Slash Ribbons
// Bold perspective tilts + expanding spiral-crescent curvature (NOT flat hoops!)
// -----------------------------------------------------------------------------
struct SlashDef {
mat3 basis; // columns: U, V, N
vec3 offset; // 3D center offset for dynamic depth layering
vec2 radii; // (rx, ry) major/minor sweep scale
float maxWidth; // wide dramatic crescent belly (0.34..0.44)
float spiral; // radial expansion from tail to head (breaks circular hoop look!)
float startAng; // strike start angle
float dir; // +1 or -1 sweep direction
float phaseOff; // staggered k/5.0 combo offset
vec3 colCore; // incandescent leading blade spine
vec3 colMid; // vibrant plasma body
vec3 colSmoke; // deep turbulent smoky wake
float electric; // crackling lightning arc intensity
};
SlashDef getSlash(int k) {
SlashDef s;
if (k == 0) {
// 1. Electric Cyan Hero Slash: dramatic sweeping upper-left to lower-right
s.basis = rotZ(-0.48) * rotX(0.58) * rotY(0.28);
s.offset = vec3(-0.08, 0.10, 0.06);
s.radii = vec2(1.66, 1.12);
s.maxWidth = 0.42;
s.spiral = 0.24;
s.startAng = 2.75;
s.dir = -1.0;
s.phaseOff = 0.06;
s.colCore = vec3(0.86, 0.99, 1.00);
s.colMid = vec3(0.02, 0.86, 1.00);
s.colSmoke = vec3(0.01, 0.22, 0.72);
s.electric = 1.0;
} else if (k == 1) {
// 2. Solar Gold Hero Slash: bold counter-diagonal lower-left to upper-right
s.basis = rotZ(0.42) * rotX(0.56) * rotY(-0.30);
s.offset = vec3(0.06, 0.02, -0.05);
s.radii = vec2(1.62, 1.08);
s.maxWidth = 0.40;
s.spiral = 0.22;
s.startAng = -2.20;
s.dir = 1.0;
s.phaseOff = 0.86;
s.colCore = vec3(1.00, 0.97, 0.80);
s.colMid = vec3(1.00, 0.64, 0.06);
s.colSmoke = vec3(0.76, 0.16, 0.01);
s.electric = 0.35;
} else if (k == 2) {
// 3. Hot Magenta-Crimson Slash: steep whipping diagonal across front-center
s.basis = rotZ(0.68) * rotX(-0.50) * rotY(0.26);
s.offset = vec3(0.04, 0.04, 0.12);
s.radii = vec2(1.48, 0.96);
s.maxWidth = 0.38;
s.spiral = 0.26;
s.startAng = -1.45;
s.dir = 1.0;
s.phaseOff = 0.26;
s.colCore = vec3(1.00, 0.84, 0.94);
s.colMid = vec3(1.00, 0.08, 0.54);
s.colSmoke = vec3(0.55, 0.02, 0.36);
s.electric = 0.75;
} else if (k == 3) {
// 4. Fiery Crimson-Scarlet Cross-Slash: sweeping low-to-high foreground arc
s.basis = rotZ(-0.22) * rotX(0.68) * rotY(-0.36);
s.offset = vec3(-0.02, 0.00, 0.14);
s.radii = vec2(1.46, 0.88);
s.maxWidth = 0.35;
s.spiral = 0.20;
s.startAng = 2.05;
s.dir = -1.0;
s.phaseOff = 0.46;
s.colCore = vec3(1.00, 0.86, 0.68);
s.colMid = vec3(1.00, 0.18, 0.05);
s.colSmoke = vec3(0.58, 0.02, 0.02);
s.electric = 0.25;
} else {
// 5. Electric Cyan-Gold High Orbital Slash: deep background/foreground weave
s.basis = rotZ(-0.76) * rotX(-0.46) * rotY(-0.32);
s.offset = vec3(0.08, 0.08, -0.10);
s.radii = vec2(1.38, 0.98);
s.maxWidth = 0.36;
s.spiral = 0.25;
s.startAng = 0.75;
s.dir = -1.0;
s.phaseOff = 0.66;
s.colCore = vec3(0.90, 0.99, 1.00);
s.colMid = vec3(0.08, 0.78, 1.00);
s.colSmoke = vec3(0.04, 0.20, 0.68);
s.electric = 0.85;
}
return s;
}
// -----------------------------------------------------------------------------
// Evaluate a single volumetric slice of a painterly 3D sword-slash smear ribbon
// -----------------------------------------------------------------------------
vec4 evalSlashSlice(
SlashDef sl,
vec3 ro,
vec3 rd,
float pk,
float maxT,
float sliceOff, // volumetric offset along normal N
float sliceWeight, // Gaussian thickness weight
bool isReflection,
out float hitT
) {
hitT = 1e6;
vec3 U = sl.basis[0];
vec3 V = sl.basis[1];
vec3 N = sl.basis[2];
vec3 C = CENTER + sl.offset + N * sliceOff;
float denom = dot(rd, N);
float absDenom = abs(denom);
if (absDenom < 0.03) return vec4(0.0);
float t = dot(C - ro, N) / denom;
if (t <= 0.08 || t >= maxT) return vec4(0.0);
vec3 P = ro + rd * t;
// Smooth height fade above floor eliminates any plane/floor clip line
float floorFade = smoothstep(0.04, 0.30, P.y);
if (floorFade <= 0.001) return vec4(0.0);
vec2 p2 = vec2(dot(P - C, U), dot(P - C, V));
vec2 q = p2 / sl.radii;
float rad = length(q);
if (rad < 0.08 || rad > 1.44) return vec4(0.0);
hitT = t;
float ang = atan(q.y, q.x);
// Explosive whip-out sweep ease
float whipT = clamp(pk / 0.48, 0.0, 1.0);
float sweep = 1.0 - pow(1.0 - whipT, 2.85);
float headAng = sl.startAng + sl.dir * (sweep * 4.50 + pk * 1.15);
// Sweeping crescent angular span (strictly < 3.6 rad so head & tail never touch)
float arcLen = mix(0.65, 3.45, smoothstep(0.0, 0.18, pk))
* mix(1.0, 0.70, smoothstep(0.60, 0.96, pk));
float env = smoothstep(0.0, 0.04, pk) * (1.0 - smoothstep(0.68, 0.98, pk));
if (env <= 0.002) return vec4(0.0);
// Continuous angular distance behind the leading blade tip in [0, TAU)
float da = mod(sl.dir * (headAng - ang) + TAU * 6.0, TAU);
float u = da / max(arcLen, 0.001);
if (u <= 0.0 || u >= 1.0) return vec4(0.0);
// Smooth razor tip entry & turbulent wispy tail exit
float headFade = smoothstep(0.0, 0.035, u);
float tailFade = 1.0 - smoothstep(0.55, 1.0, u);
float inArc = headFade * tailFade;
if (inArc <= 0.001) return vec4(0.0);
// Expanding spiral-crescent outer blade contour (NOT a circular hula-hoop!)
float twist = sliceOff * 0.55 * sin(u * PI * 1.5);
float rOut = 1.08 - sl.spiral * pow(u, 0.85) + 0.04 * sin(u * PI) + twist;
// Dramatic wide crescent belly tapering to razor tip and feathered smoky wake
float belly = pow(u, 0.36) * pow(1.0 - u, 1.15) * 2.10;
float w = sl.maxWidth * clamp(belly, 0.0, 1.12);
w *= mix(1.0, 0.65, smoothstep(0.58, 0.96, pk));
// Normalized radial wake coordinate: v=0 razor leading edge, v>0 deep smoky wake
float v = (rOut - rad) / max(w, 0.004);
if (v > 1.75) return vec4(0.0);
// Domain-warped painterly brush-stroke turbulence (continuous in da, zero seam!)
float flow = da * 2.4 - pk * 8.5 + sliceOff * 6.0;
vec2 smearUV = vec2(flow * 0.85, clamp(v, -0.2, 1.6) * 5.0 + sliceOff * 2.5);
float turb = isReflection
? fbm3(smearUV * vec2(1.0, 1.4))
: warpedFbm(smearUV, flow * 0.45);
// High-frequency brushed ink/plasma motion streaks stretched along the swing
float fineStreaks = vnoise(vec2(flow * 2.6, clamp(v, -0.2, 1.6) * 20.0 + turb * 3.2));
float brushFibers = smoothstep(0.20, 0.82, turb * 0.68 + fineStreaks * 0.32);
// Razor-sharp outer cut, ZERO hard inner circular cutout!
// Exponential + domain-warped turbulent feather dissolves organically into darkness
float outerCut = smoothstep(-0.012, 0.005, rOut - rad);
float vPos = max(v, 0.0);
float innerSoftFeather = exp(-vPos * (1.75 + 2.20 * (1.0 - turb)))
* (1.0 - smoothstep(0.45, 1.45, vPos - (turb - 0.5) * 0.55))
* smoothstep(0.10, 0.36, rad);
float wakeMask = outerCut * innerSoftFeather * inArc;
// Progressive smoky dissolution across v (wake depth), u (tail), and pk (lifecycle)
float dissolve = smoothstep(0.54, 0.96, pk);
float smokeBreakup = smoothstep(
0.14 + 0.34 * vPos + 0.24 * u + 0.35 * dissolve,
0.86,
turb * 0.72 + fineStreaks * 0.28
);
float wakeDensity = wakeMask * mix(0.58 + 0.42 * brushFibers, smokeBreakup, smoothstep(0.06, 0.58, vPos));
// Incandescent razor-sharp leading blade spine & scorching tip glint
float razorSpine = exp(-abs(rad - (rOut - 0.007)) * 115.0) * headFade * (1.0 - smoothstep(0.25, 0.78, u));
float subSpine = exp(-abs(rad - (rOut - 0.028 * (1.0 + turb * 0.6))) * 65.0) * headFade * (1.0 - smoothstep(0.35, 0.85, u)) * brushFibers;
float tipFlare = exp(-abs(rad - rOut) * 48.0) * exp(-u * 14.0) * headFade;
// Hot metallic sparks & glowing embers shedding tangentially ALONG the blade trail!
float trailSparks = 0.0;
if (!isReflection && abs(sliceOff) < 0.01 && v > -0.18 && v < 1.15) {
vec2 spGrid = vec2(da * 11.0 - pk * 14.0, (rOut - rad) * 24.0);
vec2 spCell = floor(spGrid);
vec2 spF = fract(spGrid) - 0.5;
vec2 rnd = hash22(spCell + vec2(sl.phaseOff * 37.0, 11.3));
if (rnd.x > 0.62) {
vec2 off = (rnd - 0.5) * 0.52;
vec2 dSp = spF - off;
// Elongated tangential ember streak following the blade sweep
float dStreak = length(vec2(dSp.x * 0.42, dSp.y * 2.4));
trailSparks = exp(-dStreak * 13.5) * inArc * (1.0 - smoothstep(0.85, 1.15, vPos)) * (0.6 + 0.4 * rnd.y);
}
}
// 3D perspective depth emphasis: closer foreground sweeps feel bolder & richer
float depthBoost = clamp(3.5 / max(t, 1.2), 0.72, 1.45);
float angleFade = smoothstep(0.03, 0.20, absDenom) * floorFade;
// -------------------------------------------------------------------------
// uLightMode == 1: Neutral grayscale sculptural form/ribbon study (R==G==B)
// -------------------------------------------------------------------------
if (uLightMode == 1) {
vec3 Nface = (denom < 0.0) ? N : -N;
vec3 L1 = normalize(vec3(0.55, 0.80, 0.65));
vec3 L2 = normalize(vec3(-0.70, 0.35, -0.45));
float ndl1 = max(dot(Nface, L1), 0.0);
float ndl2 = max(dot(Nface, L2), 0.0);
float fres = pow(1.0 - clamp(absDenom, 0.0, 1.0), 2.4);
float shade = 0.16 + 0.54 * ndl1 + 0.18 * ndl2 + 0.24 * fres;
float val = shade * wakeDensity * 0.90 + (0.58 * razorSpine + 0.28 * subSpine + 0.40 * tipFlare + 0.55 * trailSparks);
val *= env * angleFade * sliceWeight * depthBoost;
float alpha = clamp((wakeDensity * 0.82 + razorSpine * 0.65) * env * angleFade * sliceWeight, 0.0, 1.0);
return vec4(vec3(val), alpha);
}
// -------------------------------------------------------------------------
// Hero & Lighting Modes (0, 2, 3): Painterly Volumetric Plasma + Smoke Wake
// -------------------------------------------------------------------------
float dEdge = max(rad - rOut, 0.0);
float tightAura = exp(-dEdge * (isReflection ? 20.0 : 34.0)) * inArc * (1.0 - 0.55 * u) * (0.45 + 0.55 * brushFibers);
// Localized organic branching lightning arcs peeling off the blade wake
float bolt = 0.0;
if (sl.electric > 0.15 && !isReflection && abs(sliceOff) < 0.01) {
float bFlow = da * 7.5 + pk * 11.0;
float pocket = smoothstep(0.46, 0.78, vnoise(vec2(da * 1.9 - pk * 3.5, 4.7)));
float jag1 = (fbm3(vec2(bFlow, 2.3)) - 0.5) * 0.16;
float jag2 = (vnoise(vec2(bFlow * 2.8, 9.1)) - 0.5) * 0.07;
float boltR = rOut + 0.035 + (jag1 + jag2) * pocket;
float bMask = smoothstep(0.06, 0.16, u) * (1.0 - smoothstep(0.45, 0.80, u)) * pocket;
bolt = exp(-abs(rad - boltR) * 165.0) * bMask * sl.electric;
float forkR = rOut + 0.075 + (jag1 * 1.4 - jag2 * 1.2) * pocket;
bolt += exp(-abs(rad - forkR) * 195.0) * bMask * smoothstep(0.62, 0.88, pocket) * sl.electric * 0.72;
}
// Painterly color gradient: incandescent white-hot spine -> vivid plasma -> deep smoky wake
float wakeGrad = clamp(vPos * 1.05 + (1.0 - brushFibers) * 0.35 + u * 0.25, 0.0, 1.0);
vec3 bodyCol = mix(sl.colMid, sl.colSmoke, wakeGrad);
bodyCol = mix(bodyCol, sl.colCore, clamp(exp(-vPos * 11.0) * 0.55 + subSpine * 0.50, 0.0, 1.0));
float modeGain = 1.0;
if (uLightMode == 2) {
vec3 Nface = (denom < 0.0) ? N : -N;
vec3 Lg = normalize(vec3(0.92, 0.22, 0.32));
float graze = pow(max(dot(Nface, Lg), 0.0), 2.2);
bodyCol += vec3(1.0, 0.86, 0.62) * graze * 0.42 * wakeDensity;
modeGain = 0.94;
} else if (uLightMode == 3) {
float rim = pow(1.0 - clamp(absDenom, 0.0, 1.0), 1.8);
bodyCol += vec3(0.32, 0.78, 1.0) * rim * 0.48 * wakeDensity;
modeGain = 0.96;
}
vec3 sparkTint = mix(vec3(1.0, 0.82, 0.38), sl.colCore, 0.45);
vec3 energy = bodyCol * (wakeDensity * (0.95 + 0.80 * brushFibers) * 1.32)
+ sl.colSmoke * (tightAura * 0.28)
+ sl.colMid * (tightAura * 0.16 + subSpine * 0.85)
+ sl.colCore * (razorSpine * 1.75 + tipFlare * 1.45)
+ mix(sl.colMid, sl.colCore, 0.62) * bolt * 1.95
+ sparkTint * trailSparks * 2.20;
energy *= env * angleFade * sliceWeight * depthBoost * modeGain;
float alpha = clamp((wakeDensity * 0.72 + razorSpine * 0.55) * env * angleFade * sliceWeight, 0.0, 0.95);
return vec4(energy, alpha);
}
// -----------------------------------------------------------------------------
// Multi-slice 3D Volumetric Slash Ribbon Evaluator (3 slices for hero, 1 for reflection)
// -----------------------------------------------------------------------------
vec4 evalVolumetricSlash(
SlashDef sl,
vec3 ro,
vec3 rd,
float phase,
float maxT,
bool isReflection,
out float hitT
) {
hitT = 1e6;
float pk = fract(phase + sl.phaseOff);
// Quick center-plane bounding reject before volumetric multi-slice integration
float t0;
vec4 centerHit = evalSlashSlice(sl, ro, rd, pk, maxT, 0.0, isReflection ? 1.0 : 0.52, isReflection, t0);
hitT = t0;
if (isReflection) {
return centerHit;
}
// If center plane completely missed the bounding volume, skip side slices
if (t0 > 1e5) return vec4(0.0);
// Accumulate front & back volumetric plasma thickness slices for true 3D painterly depth
float tFront, tBack;
vec4 frontHit = evalSlashSlice(sl, ro, rd, pk, maxT, 0.048, 0.34, false, tFront);
vec4 backHit = evalSlashSlice(sl, ro, rd, pk, maxT, -0.048, 0.34, false, tBack);
hitT = min(t0, min(tFront, tBack));
vec3 rgb = centerHit.rgb + frontHit.rgb + backHit.rgb;
float a = clamp(centerHit.a + frontHit.a * 0.65 + backHit.a * 0.65, 0.0, 0.96);
return vec4(rgb, a);
}
// -----------------------------------------------------------------------------
// Dynamic Clash Vortex & Kinetic Blade-Cross Core (NO generic white sunburst!)
// -----------------------------------------------------------------------------
vec3 evalClashNexus(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float phase, float maxT, bool isReflection) {
vec3 camFwd = normalize(cross(camRight, camUp));
float denom = dot(rd, camFwd);
if (abs(denom) < 0.05) return vec3(0.0);
float t = dot(CENTER - ro, camFwd) / denom;
if (t <= 0.08 || t >= maxT) return vec3(0.0);
vec3 P = ro + rd * t;
float floorFade = smoothstep(0.06, 0.40, P.y);
if (floorFade <= 0.001) return vec3(0.0);
vec3 rel = P - CENTER;
vec2 uv = vec2(dot(rel, camRight), dot(rel, camUp));
float r = length(uv);
if (r > 1.35) return vec3(0.0);
// 5-beat rapid combo strike pulse synced to the 5 ribbons
float beat = fract(phase * 5.0 + 0.06);
float hitPulse = 0.55 + 0.72 * exp(-beat * 7.5);
// 1. Swirling turbulent clash plasma vortex (compact, painterly, NOT a smooth white blob)
vec2 swirlP = rot2(r * 2.6 - phase * TAU) * uv * 3.4;
float vortexNoise = isReflection
? fbm3(swirlP)
: warpedFbm(swirlP, phase * TAU * 0.5);
float vortexMask = exp(-r * 3.4) * smoothstep(0.28, 0.82, vortexNoise);
float hotPinpoint = exp(-r * 22.0) * 1.45;
// 2. Razor-sharp kinetic cross-slash blade glints (echoing crossed katana strikes)
vec3 bladeCol = vec3(0.0);
float bladeLum = 0.0;
for (int b = 0; b < 3; b++) {
float fb = float(b);
float bBeat = fract(phase * 5.0 + fb * 0.33 + 0.04);
float bEnv = 0.38 + 0.62 * exp(-bBeat * 5.5);
float bAng = (b == 0) ? -0.78 : ((b == 1) ? 0.56 : 1.02);
vec2 bu = rot2(bAng) * uv;
float along = smoothstep(-0.18, 0.14, bu.x) * (1.0 - smoothstep(0.55, 1.05, bu.x));
float halfW = mix(0.013, 0.0012, clamp((bu.x + 0.18) / 1.22, 0.0, 1.0));
float dBlade = abs(bu.y) / max(halfW, 0.001);
float core = exp(-dBlade * 3.2) * along * bEnv;
float glow = exp(-abs(bu.y) * 52.0) * along * bEnv * 0.22;
vec3 bc = (b == 0) ? vec3(0.35, 0.88, 1.0) : ((b == 1) ? vec3(1.0, 0.36, 0.78) : vec3(1.0, 0.76, 0.24));
bladeCol += mix(bc, vec3(1.0, 0.98, 0.94), core * 0.78) * (core * 1.35 + glow);
bladeLum += core * 0.85;
}
// 3. Turbulent ragged shockwave wisp (domain-warped, NOT a rigid geometric circle)
float shockR = 0.18 + beat * 0.92 + (vortexNoise - 0.5) * 0.12;
float shockWisp = exp(-abs(r - shockR) * 42.0) * smoothstep(0.35, 0.80, vortexNoise) * pow(1.0 - beat, 2.0) * 0.62;
if (uLightMode == 1) {
float lum = (hotPinpoint * 0.45 + vortexMask * 0.38 + shockWisp * 0.45 + bladeLum * 0.65) * (0.7 + 0.3 * hitPulse);
return vec3(lum) * floorFade;
}
vec3 col = vec3(1.0, 0.95, 0.82) * hotPinpoint * hitPulse
+ mix(vec3(1.0, 0.52, 0.08), vec3(0.14, 0.82, 1.0), smoothstep(0.3, 0.8, vortexNoise)) * vortexMask * 0.85 * hitPulse
+ vec3(1.0, 0.72, 0.28) * shockWisp
+ bladeCol * (isReflection ? 0.55 : 0.92);
return col * floorFade;
}
// -----------------------------------------------------------------------------
// Sparse Asymmetric Hot Metallic Clash Sparks (NO dandelion bicycle-wheel!)
// Smooth floor-height fade prevents any horizontal floor guillotine line
// -----------------------------------------------------------------------------
vec3 evalMetallicSparks(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float phase, float maxT) {
vec3 camFwd = normalize(cross(camRight, camUp));
float denom = dot(rd, camFwd);
if (abs(denom) < 0.05) return vec3(0.0);
vec3 acc = vec3(0.0);
// 2 sparse asymmetric parallax planes (cut radial spokes by >65%)
for (int layer = 0; layer < 2; layer++) {
float fl = float(layer);
float zOff = (layer == 0) ? 0.28 : -0.22;
vec3 planeC = CENTER + camFwd * zOff;
float t = dot(planeC - ro, camFwd) / denom;
if (t <= 0.1 || t >= maxT) continue;
vec3 P = ro + rd * t;
// Smooth floor proximity fade eliminates horizontal guillotine cutoff!
float floorFade = smoothstep(0.08, 0.46, P.y);
if (floorFade <= 0.001) continue;
vec3 rel = P - planeC;
vec2 uv = vec2(dot(rel, camRight), dot(rel, camUp));
float r = length(uv);
if (r < 0.10 || r > 1.85) continue;
vec2 cUV = rot2(r * 0.26 * (layer == 1 ? -1.0 : 1.0)) * uv;
float ang = atan(cUV.y, cUV.x);
float sectors = (layer == 0) ? 28.0 : 22.0;
float secId = floor((ang + PI) / TAU * sectors);
float h1 = hash21(vec2(secId, fl * 17.3 + 1.1));
float h2 = hash21(vec2(secId, fl * 31.7 + 6.7));
float h3 = hash21(vec2(secId, fl * 47.9 + 2.9));
float h4 = hash21(vec2(secId, fl * 61.1 + 9.3));
// Randomly skip ~62% of sectors for organic, asymmetric clash bursts
if (h1 < 0.62) continue;
float sectorStep = TAU / sectors;
float secCenter = (secId + 0.5 + (h4 - 0.5) * 0.45) * sectorStep - PI;
float angDiff = abs(ang - secCenter);
if (angDiff > sectorStep * 0.48) continue;
float speedMult = (h2 < 0.45) ? 2.0 : 3.0;
float sp = fract(phase * speedMult + h1 * 2.7);
// Varied asymmetric reach & streak length per spark
float maxReach = 0.72 + 1.05 * h3 * h3;
float sparkR = 0.16 + pow(sp, 0.68) * maxReach;
float streakLen = 0.024 + 0.068 * (1.0 - sp) * (0.35 + 0.65 * h2);
float dAng = angDiff * r;
float dRad = abs(r - sparkR);
float needle = exp(-dAng * 260.0) * exp(-dRad / max(streakLen, 0.006));
float hotHead = exp(-dAng * 150.0) * exp(-abs(r - (sparkR + streakLen * 0.42)) * 135.0);
float env = smoothstep(0.0, 0.06, sp) * (1.0 - smoothstep(0.54, 1.0, sp)) * floorFade;
vec3 sCol;
if (h3 < 0.66) {
sCol = mix(vec3(1.0, 0.44, 0.05), vec3(1.0, 0.84, 0.30), 1.0 - sp);
} else if (h3 < 0.84) {
sCol = vec3(0.16, 0.90, 1.0);
} else {
sCol = vec3(1.0, 0.22, 0.64);
}
if (uLightMode == 1) {
acc += vec3((needle * 0.38 + hotHead * 0.60) * env);
} else {
acc += (sCol * needle * 1.45 + mix(sCol, vec3(1.0, 0.99, 0.94), 0.78) * hotHead * 1.85) * env;
}
}
return acc;
}
// -----------------------------------------------------------------------------
// Composite all 3D VFX (5 volumetric slash ribbons + clash nexus + metallic sparks)
// -----------------------------------------------------------------------------
vec3 evalVFX(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float phase, float maxT, bool isReflection) {
vec4 rCol[5];
float rT[5];
for (int k = 0; k < 5; k++) {
rCol[k] = evalVolumetricSlash(getSlash(k), ro, rd, phase, maxT, isReflection, rT[k]);
}
vec3 camFwd = normalize(cross(camRight, camUp));
float coreT = dot(CENTER - ro, camFwd) / (dot(rd, camFwd) + 1e-5);
vec3 behindCore = vec3(0.0);
vec3 frontCore = vec3(0.0);
float frontAlpha = 0.0;
for (int k = 0; k < 5; k++) {
if (rCol[k].a <= 0.0005 && dot(rCol[k].rgb, vec3(1.0)) <= 0.0005) continue;
if (rT[k] < coreT) {
if (uLightMode == 1) {
frontCore = mix(frontCore, rCol[k].rgb, rCol[k].a * (1.0 - frontAlpha * 0.42))
+ rCol[k].rgb * (1.0 - rCol[k].a) * 0.16;
frontAlpha = clamp(frontAlpha + rCol[k].a * 0.55, 0.0, 0.92);
} else {
frontCore += rCol[k].rgb;
frontAlpha = clamp(frontAlpha + rCol[k].a * 0.34, 0.0, 0.74);
}
} else {
if (uLightMode == 1) {
behindCore = max(behindCore, rCol[k].rgb);
} else {
behindCore += rCol[k].rgb;
}
}
}
vec3 coreCol = evalClashNexus(ro, rd, camRight, camUp, phase, maxT, isReflection);
vec3 sparkCol = isReflection ? vec3(0.0) : evalMetallicSparks(ro, rd, camRight, camUp, phase, maxT);
if (uLightMode == 1) {
vec3 base = max(behindCore, coreCol * 0.72);
vec3 res = mix(base, frontCore, clamp(frontAlpha, 0.0, 0.88)) + frontCore * 0.20;
res += sparkCol * 0.48;
return res;
}
return behindCore * 0.92 + coreCol * (1.0 - frontAlpha * 0.25) + frontCore + sparkCol;
}
// -----------------------------------------------------------------------------
// Deep Moody Combat Arena Backdrop (lumMin ~ 8-14 sRGB, zero washed-out fog)
// -----------------------------------------------------------------------------
vec3 evalArenaBackdrop(vec3 ro, vec3 rd, float phase) {
float elev = clamp(rd.y * 0.5 + 0.5, 0.0, 1.0);
vec3 skyLow = vec3(0.0050, 0.0058, 0.0098);
vec3 skyHigh = vec3(0.0024, 0.0030, 0.0055);
vec3 col = mix(skyLow, skyHigh, smoothstep(0.42, 0.92, elev));
// Distant cylindrical stadium arena wall & steel trusses
float horiz = max(length(rd.xz), 0.001);
float wallT = 6.8 / horiz;
vec3 wallP = ro + rd * wallT;
float wallY = wallP.y;
float wallAng = atan(wallP.z, wallP.x);
// Subtle overhead arena spotlight shaft
float spotCone = exp(-abs(rd.x) * 5.2) * smoothstep(0.02, 0.62, rd.y) * 0.015;
col += vec3(0.45, 0.60, 0.88) * spotCone;
// Dark structural arena trusses
float ribV = smoothstep(0.93, 0.99, abs(sin(wallAng * 14.0)));
float ribH = smoothstep(0.94, 0.99, abs(sin(wallY * 4.2)));
float wallMask = smoothstep(-0.01, 0.14, rd.y) * (1.0 - smoothstep(0.50, 0.82, rd.y));
col += vec3(0.0042, 0.0055, 0.0092) * (ribV * 0.65 + ribH * 0.55) * wallMask;
// Crisp distant perimeter arena floodlights
float lightSlot = fract(wallAng / TAU * 14.0 + 0.5) - 0.5;
float dLight = length(vec2(lightSlot * 4.0, (wallY - 1.48) * 1.4));
float bokeh = exp(-dLight * dLight * 58.0) * 0.085 * wallMask;
col += vec3(0.66, 0.78, 1.0) * bokeh;
// Low perimeter stage rim lights near floor horizon
float lowSlot = fract(wallAng / TAU * 10.0) - 0.5;
float dLow = length(vec2(lowSlot * 4.2, (wallY - 0.18) * 3.6));
float lowGlow = exp(-dLow * dLow * 40.0) * 0.075 * smoothstep(-0.02, 0.08, rd.y);
col += vec3(0.84, 0.80, 0.96) * lowGlow;
vec3 toCenter = normalize(CENTER - ro);
float centerAlign = max(dot(rd, toCenter), 0.0);
float beat = fract(phase * 5.0 + 0.06);
float hazePulse = 0.85 + 0.25 * exp(-beat * 6.0);
if (uLightMode == 0) {
col += vec3(0.012, 0.010, 0.016) * pow(centerAlign, 8.0) * hazePulse;
} else if (uLightMode == 1) {
col = mix(vec3(0.018), vec3(0.006), smoothstep(0.0, 0.72, max(rd.y, 0.0)));
col += vec3(0.014) * pow(centerAlign, 5.0);
} else if (uLightMode == 2) {
float keyAlign = max(dot(rd, normalize(vec3(0.92, 0.18, 0.35))), 0.0);
col += vec3(0.055, 0.038, 0.020) * pow(keyAlign, 8.0);
col += vec3(0.012, 0.010, 0.008) * pow(centerAlign, 8.0);
} else if (uLightMode == 3) {
// Soft, localized cool backlit rim glow (fades smoothly to horizon — zero blue rectangle or seam!)
float horizSoft = smoothstep(-0.02, 0.22, rd.y);
col += vec3(0.018, 0.046, 0.085) * pow(centerAlign, 9.0) * horizSoft;
col += vec3(0.055, 0.115, 0.205) * pow(centerAlign, 24.0) * horizSoft;
}
return col;
}
// -----------------------------------------------------------------------------
// Dark Reflective Dojo / Arena Stage Floor with Crisp Colored Slash Reflections
// -----------------------------------------------------------------------------
vec3 evalArenaFloor(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float phase, float tFloor) {
vec3 p = ro + rd * tFloor;
float r = length(p.xz);
float ang = atan(p.z, p.x);
float grain1 = fbm3(p.xz * 3.2);
float grain2 = vnoise(vec2(ang * 20.0, r * 7.0));
float plank = 0.5 + 0.5 * sin(p.x * 10.0 + grain1 * 0.5);
vec3 baseAlbedo = mix(vec3(0.0055, 0.0062, 0.0092), vec3(0.010, 0.011, 0.015), grain1 * 0.6 + plank * 0.4);
// Concentric brushed-gold dojo stage rings
float ring1 = exp(-abs(r - 1.50) * 48.0);
float ring2 = exp(-abs(r - 2.12) * 38.0);
float ring3 = exp(-abs(r - 2.24) * 32.0);
float rings = clamp(ring1 * 0.60 + ring2 * 0.92 + ring3 * 0.72, 0.0, 1.0);
vec3 ringCol = (uLightMode == 1) ? vec3(0.12) : vec3(0.56, 0.40, 0.16);
vec3 N = normalize(vec3((grain1 - 0.5) * 0.032, 1.0, (grain2 - 0.5) * 0.032));
float ndv = max(-dot(rd, N), 0.001);
float fresnel = mix(0.24, 0.82, pow(1.0 - ndv, 3.0));
float beat = fract(phase * 5.0 + 0.06);
float hitPulse = 0.72 + 0.42 * exp(-beat * 6.5);
float centerPool = exp(-r * r * 0.85) * hitPulse;
vec3 directLight = vec3(0.0);
if (uLightMode == 0) {
directLight += vec3(0.50, 0.32, 0.12) * centerPool * 0.36;
directLight += vec3(0.05, 0.24, 0.40) * exp(-abs(r - 1.32) * 2.4) * 0.14;
directLight += vec3(0.32, 0.05, 0.24) * exp(-abs(r - 1.08) * 2.8) * 0.10;
directLight += vec3(0.0045, 0.0055, 0.0090);
} else if (uLightMode == 1) {
directLight += vec3(0.12) * centerPool + vec3(0.018);
} else if (uLightMode == 2) {
vec3 Lg = normalize(vec3(0.92, 0.18, 0.34));
vec3 H = normalize(Lg - rd);
float spec = pow(max(dot(N, H), 0.0), 48.0);
directLight += vec3(0.85, 0.68, 0.45) * (0.04 + spec * 0.65);
directLight += vec3(0.28, 0.20, 0.10) * centerPool * 0.25 + vec3(0.006);
} else if (uLightMode == 3) {
vec3 Lb = normalize(vec3(0.0, 0.28, -0.96));
vec3 H = normalize(Lb - rd);
float spec = pow(max(dot(N, H), 0.0), 32.0);
directLight += vec3(0.32, 0.62, 0.96) * (0.04 + spec * 0.72);
directLight += vec3(0.24, 0.30, 0.40) * centerPool * 0.22 + vec3(0.005);
}
vec3 floorCol = baseAlbedo * (1.0 + directLight * 2.8) + directLight * 0.16;
floorCol += ringCol * rings * (0.14 + 0.38 * centerPool);
// True planar reflection of the 3D slash ribbons & clash nexus
vec3 rdRef = reflect(rd, N);
vec3 refUp = vec3(0.0, 1.0, 0.0);
vec3 refRight = normalize(cross(rdRef, refUp));
refUp = normalize(cross(refRight, rdRef));
vec3 vfxRef = evalVFX(p, rdRef, refRight, refUp, phase, 20.0, true);
float gloss = mix(0.68, 0.96, 1.0 - grain1 * 0.45) * exp(-r * 0.18);
float refGain = (uLightMode == 1) ? 0.46 : 0.80;
floorCol += vfxRef * fresnel * gloss * refGain;
float fog = 1.0 - exp(-tFloor * 0.09);
vec3 fogCol = (uLightMode == 1) ? vec3(0.014) : vec3(0.0042, 0.0050, 0.0085);
floorCol = mix(floorCol, fogCol, clamp(fog, 0.0, 0.88));
return floorCol;
}
// -----------------------------------------------------------------------------
// Main Entry Point
// -----------------------------------------------------------------------------
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * uResolution.xy) / uResolution.y;
// Strictly periodic 3.0s seamless animation phase in [0, 1)
float phase = fract(uTime / 3.0);
// Subtle periodic camera breathing & impact micro-shake synced to the 5 hits
float beat = fract(phase * 5.0 + 0.06);
float shakeEnv = exp(-beat * 14.0) * 0.010;
vec2 microShake = vec2(sin(phase * TAU * 15.0), cos(phase * TAU * 20.0)) * shakeEnv;
// Camera setup: 0 = hero dramatic low-angle arena framing, 1 = ~2.5x macro close-up
vec3 ro, ta;
float fov;
if (uCamMode == 1) {
ro = vec3(0.32 + 0.04 * sin(phase * TAU), 1.26 + 0.02 * cos(phase * TAU), 1.70);
ta = vec3(0.02, 1.24, 0.0);
fov = 1.62;
} else {
ro = vec3(0.05 * sin(phase * TAU), 0.82 + 0.02 * cos(phase * TAU), 3.62);
ta = vec3(0.0, 1.15, 0.0);
fov = 1.28;
}
ro.xy += microShake;
vec3 camFwd = normalize(ta - ro);
vec3 camRight = normalize(cross(camFwd, vec3(0.0, 1.0, 0.0)));
vec3 camUp = normalize(cross(camRight, camFwd));
vec3 rd = normalize(camFwd * fov + camRight * uv.x + camUp * uv.y);
float tFloor = 1e6;
bool hitFloor = false;
if (rd.y < -0.0005) {
float tf = -ro.y / rd.y;
if (tf > 0.05 && tf < 32.0) {
tFloor = tf;
hitFloor = true;
}
}
vec3 bg = hitFloor
? evalArenaFloor(ro, rd, camRight, camUp, phase, tFloor)
: evalArenaBackdrop(ro, rd, phase);
vec3 vfx = evalVFX(ro, rd, camRight, camUp, phase, tFloor, false);
vec3 col = (uLightMode == 1) ? (bg + vfx * 0.85) : (bg + vfx);
float vig = 1.0 - 0.14 * dot(uv, uv);
col *= clamp(vig, 0.82, 1.0);
// Clean ACES filmic tonemapping with soft highlight knee (%clip < 1%)
float peak = max(col.r, max(col.g, col.b));
col *= 1.0 / (1.0 + 0.16 * peak);
col = acesFilm(col * 1.06) * 0.965;
// Gamma to sRGB
col = pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2));
// Strictly enforce R == G == B in neutral grayscale form study mode
if (uLightMode == 1) {
float g = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(g);
}
fragColor = vec4(col, 1.0);
}
`;
export function createRapidComboSlashFlurryMaterial(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 | rapid-combo-slash-flurry |
|---|---|
| Category | Game VFX Shaders · Choreographed Loop VFX |
| Upstream study | vfx_animated/lib/05_rapid_combo_slash_flurry.glsl (commit f3d2025) |
| Animation cycle | 3.0 s seamless harmonic loop |
| Declared uniforms | uResolution, uTime, uOpen, uLightMode, uCamMode |
| Source size | 835 lines · 33.9 KB standalone GLSL ES 3.00 |
| PNG baker outputs | 512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key) |
| Companion pixel VFX | Free MIT melee sprite sheets |
| License | MIT License + CC0 / MIT Helpers |
Schlick Fresnel reflectance (1994); Beer–Lambert volumetric absorption/attenuation
David Hoskins, hash · Krzysztof Narkowicz, filmic curve
3s LoopSweeping twin solar-flame wings unfurling upward with molten feather embers.
AnimatedExpanding sci-fi holo-grid scan wave snapping across metallic floor tiles with electric arcs.
AnimatedHelical translucent water torrent coiling skyward with white foam crests and spray droplets.
3s LoopChrome ferrofluid metaball core splitting and merging inside an orbiting metallic halo.
3s LoopRotating concentric rune rings igniting a vertical beam of ascension light.
3s LoopSweeping violet-cyan spell blade arc with glowing runes, trailing motes, and arena floor bounce.