3s LoopGeodesic hexagonal forcefield dome with Fresnel rim energy, impact ripple rings, and rune lattice.
arcane-slash-arc.glsl · 1017 lines · GLSL ES 3.00 · MIT
#version 300 es
// Arcane Slash Arc (arcane-slash-arc.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_palette/lib/01_arcane_slash_arc.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;
// ============================================================================
// 01_arcane_slash_arc.glsl
// Sweeping 3D crescent arcane sword-slash ribbon above a dark wet tiled
// obsidian arena floor.
// Unified Arcane Palette:
// Obsidian floor : vec3(0.03, 0.05, 0.12)
// Deep cobalt : vec3(0.08, 0.32, 0.98)
// Luminous cyan : vec3(0.10, 0.85, 1.00)
// Warm gold : vec3(1.00, 0.68, 0.18)
// White-gold core: vec3(1.00, 0.96, 0.86)
// ============================================================================
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
const vec3 COL_OBSIDIAN = vec3(0.03, 0.05, 0.12);
const vec3 COL_COBALT = vec3(0.08, 0.32, 0.98);
const vec3 COL_CYAN = vec3(0.10, 0.85, 1.00);
const vec3 COL_GOLD = vec3(1.00, 0.68, 0.18);
const vec3 COL_CORE = vec3(1.00, 0.96, 0.86);
// Smooth 3-second loop phase in [0, 1)
float loopPhase() {
return fract(uTime / 3.0);
}
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
float hash11(float p) {
p = fract(p * 0.1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
float hash21(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
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 hash31(vec3 p3) {
p3 = fract(p3 * 0.1031);
p3 += dot(p3, p3.zyx + 31.32);
return fract((p3.x + p3.y) * p3.z);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}
float vnoise3(vec3 p) {
vec3 i = floor(p);
vec3 f = fract(p);
vec3 u = f * f * (3.0 - 2.0 * f);
float n000 = hash31(i + vec3(0.0, 0.0, 0.0));
float n100 = hash31(i + vec3(1.0, 0.0, 0.0));
float n010 = hash31(i + vec3(0.0, 1.0, 0.0));
float n110 = hash31(i + vec3(1.0, 1.0, 0.0));
float n001 = hash31(i + vec3(0.0, 0.0, 1.0));
float n101 = hash31(i + vec3(1.0, 0.0, 1.0));
float n011 = hash31(i + vec3(0.0, 1.0, 1.0));
float n111 = hash31(i + vec3(1.0, 1.0, 1.0));
float nx00 = mix(n000, n100, u.x);
float nx10 = mix(n010, n110, u.x);
float nx01 = mix(n001, n101, u.x);
float nx11 = mix(n011, n111, u.x);
return mix(mix(nx00, nx10, u.y), mix(nx01, nx11, u.y), u.z);
}
float fbm2(vec2 p) {
float v = 0.0;
float a = 0.5;
mat2 m = mat2(0.8, 0.6, -0.6, 0.8);
for (int i = 0; i < 4; i++) {
v += a * vnoise2(p);
p = m * p * 2.03 + vec2(17.1, 31.7);
a *= 0.5;
}
return v;
}
float fbm3(vec3 p) {
float v = 0.0;
float a = 0.5;
for (int i = 0; i < 3; i++) {
v += a * vnoise3(p);
p = p * 2.07 + vec3(11.3, 23.7, 7.1);
a *= 0.5;
}
return v;
}
// Smooth periodic 3D turbulence using two time-blended scrolling layers
// so the 3-second loop is 100% seamless.
float periodicTurb3(vec3 p, vec3 flow, float phase) {
float p0 = fract(phase);
float p1 = fract(phase + 0.5);
float w0 = 1.0 - abs(2.0 * p0 - 1.0);
float w1 = 1.0 - w0;
float n0 = fbm3(p + flow * p0);
float n1 = fbm3(p + flow * p1 + vec3(19.3, 7.7, 13.1));
return n0 * w0 + n1 * w1;
}
float smin(float a, float b, float k) {
float h = clamp(0.5 + 0.5 * (b - a) / max(k, 1e-4), 0.0, 1.0);
return mix(b, a, h) - k * h * (1.0 - h);
}
// ============================================================================
// ARC COORDINATE FRAME
// Sweeps in a tilted 3D plane above the wet obsidian floor (y = 0):
// s = 0.0 : blazing white-gold crescent tip (front-right, low over floor)
// s = 0.19 : ornate golden arcane crossguard/collar
// s = 0.19..0.46 : sculpted luminous cyan-to-cobalt blade body
// s = 0.46..1.00 : sweeping cobalt volumetric energy ribbon tapering to tail
// ============================================================================
const vec3 ARC_CENTER = vec3(-0.02, 0.78, -0.06);
void getArcBasis(out vec3 ax, out vec3 ay, out vec3 az) {
// Tilt arc plane so front-right (+X, +Z) dips close to the wet floor
// and back-left (-X, -Z) rises gracefully into the dark studio space.
ay = normalize(vec3(0.22, 0.90, 0.37));
ax = normalize(cross(ay, vec3(0.0, 0.0, 1.0)));
az = normalize(cross(ax, ay));
}
vec3 worldToArc(vec3 p) {
vec3 ax, ay, az;
getArcBasis(ax, ay, az);
vec3 d = p - ARC_CENTER;
return vec3(dot(d, ax), dot(d, ay), dot(d, az));
}
vec3 arcToWorld(vec3 q) {
vec3 ax, ay, az;
getArcBasis(ax, ay, az);
return ARC_CENTER + ax * q.x + ay * q.y + az * q.z;
}
// Arc angular span:
// thetaStart (tip, s=0) = +0.25 rad (front-right, curving slightly up-right)
// thetaEnd (tail, s=1) = +0.25 + 4.25 rad (~245 deg dramatic crescent sweep)
const float ARC_START = 0.25;
const float ARC_SPAN = 4.25;
// Nominal spiral radius along s in [0, 1]
float arcRadius(float s) {
// Slight graceful scimitar spiral with gentle inward hook at the crescent tip
float r = 1.18 - 0.12 * s;
// Tip flares gently outward then hooks sharp
float tipCurve = smoothstep(0.22, 0.0, s);
r += 0.07 * tipCurve * (1.0 - 0.85 * tipCurve);
return r;
}
// Subtle 3s breathing/sweeping motion offset in arc angle
float slashAnimOffset() {
float ph = loopPhase();
return 0.06 * sin(TAU * ph);
}
// Evaluate world position on the arc centerline for parameter s in [0, 1]
vec3 arcPointWorld(float s) {
float theta = ARC_START + slashAnimOffset() + s * ARC_SPAN;
float r = arcRadius(s);
// Slight vertical wave along the ribbon so it feels dynamically swept in 3D
float lift = 0.04 * sin(s * PI * 1.5) - 0.06 * smoothstep(0.25, 0.0, s);
// Subtle upward flick right at the crescent blade tip
lift += 0.10 * pow(clamp(1.0 - s / 0.14, 0.0, 1.0), 2.2);
vec3 q = vec3(r * cos(theta), lift, r * sin(theta));
return arcToWorld(q);
}
// Given world point p, return:
// s : normalized arc parameter in [0, 1] (clamped)
// dr : signed radial offset from centerline (positive = outer edge)
// dy : signed normal offset from arc ribbon surface
// over: how far outside [0, 1] in arc-length units the angle fell
struct ArcCoord {
float s;
float sRaw;
float dr;
float dy;
float over;
};
ArcCoord evalArcCoord(vec3 p) {
vec3 q = worldToArc(p);
float r = length(q.xz);
float ang = atan(q.z, q.x); // [-PI, PI]
float a0 = ARC_START + slashAnimOffset();
// Unwrap angle relative to a0 into [-0.65, TAU - 0.65]
float dAng = mod(ang - a0 + 0.65, TAU) - 0.65;
float sRaw = dAng / ARC_SPAN;
float s = clamp(sRaw, 0.0, 1.0);
float r0 = arcRadius(s);
float lift = 0.04 * sin(s * PI * 1.5) - 0.06 * smoothstep(0.25, 0.0, s);
lift += 0.10 * pow(clamp(1.0 - s / 0.14, 0.0, 1.0), 2.2);
float over = 0.0;
if (sRaw < 0.0) over = -sRaw * ARC_SPAN * r0;
else if (sRaw > 1.0) over = (sRaw - 1.0) * ARC_SPAN * r0;
ArcCoord ac;
ac.s = s;
ac.sRaw = sRaw;
ac.dr = r - r0;
ac.dy = q.y - lift;
ac.over = over;
return ac;
}
// ============================================================================
// WET OBSIDIAN TILED FLOOR SDF & SURFACE ATTRIBUTES
// ============================================================================
struct FloorInfo {
float grout; // 1 in grout seam, 0 on stone face
float bevel; // beveled edge profile
float wetness; // 0 = damp stone, 1 = glossy mirror puddle
float tileId; // per-tile hash
float microBump; // fine basalt texture
float height; // surface height displacement
};
FloorInfo evalFloorInfo(vec2 xz) {
// Rotate tiles ~34 deg for dramatic diagonal perspective like the ref
vec2 uv = rot2(0.59) * xz;
float tileScale = 0.92;
vec2 g = uv / tileScale;
vec2 id = floor(g);
vec2 f = fract(g) - 0.5;
vec2 af = abs(f);
float tileHash = hash21(id);
// Grout seam distance
float edgeDist = 0.5 - max(af.x, af.y);
float grout = 1.0 - smoothstep(0.010, 0.024, edgeDist);
float bevel = smoothstep(0.012, 0.052, edgeDist);
// Subtle organic puddle mask (large wet pools + pooling near seams)
float puddleNoise = fbm2(xz * 0.72 + vec2(2.4, -1.7));
float puddleDetail = fbm2(xz * 2.15 + vec2(-5.1, 3.3));
float wet = smoothstep(0.36, 0.64, puddleNoise * 0.78 + puddleDetail * 0.22 + 0.12 * (1.0 - bevel));
// Extra sheen near center arena where the slash strikes
float centerWet = exp(-dot(xz - vec2(0.4, 0.5), xz - vec2(0.4, 0.5)) * 0.22);
wet = clamp(wet + 0.25 * centerWet, 0.0, 1.0);
// Fine basalt/obsidian stone grain (damped inside puddles)
float grain = fbm2(uv * 9.5 + tileHash * 13.7) * 0.65 + vnoise2(uv * 24.0) * 0.35;
float perTileH = (tileHash - 0.5) * 0.005;
FloorInfo fi;
fi.grout = grout;
fi.bevel = bevel;
fi.wetness = wet;
fi.tileId = tileHash;
fi.microBump = grain;
fi.height = perTileH - grout * 0.016 - (1.0 - bevel) * 0.005 + (grain - 0.5) * 0.004 * (1.0 - wet * 0.85);
return fi;
}
float sdFloor(vec3 p) {
FloorInfo fi = evalFloorInfo(p.xz);
return p.y - fi.height;
}
// ============================================================================
// SOLID SCULPTED ARCANE CRESCENT BLADE, COLLAR & RIBBON CORE SDF
// Material IDs:
// 1.0 = Wet obsidian floor
// 2.0 = Blazing crescent blade tip (s < 0.185)
// 3.0 = Ornate golden arcane crossguard / collar (s ~ 0.185)
// 4.0 = Sculpted cyan-to-cobalt energy blade & ribbon core (s > 0.185)
// ============================================================================
vec2 mapScene(vec3 p) {
// 1. Wet obsidian floor
float dFloor = sdFloor(p);
vec2 res = vec2(dFloor, 1.0);
// Quick bounding sphere cull around the arc
if (length(p - ARC_CENTER) > 2.25) {
return res;
}
ArcCoord ac = evalArcCoord(p);
float s = ac.s;
float openW = 1.0 + 0.32 * clamp(uOpen, 0.0, 1.0);
// 2. Sculpted crescent blade & swept ribbon core (s in [0.0, 0.86])
// Width profile along s:
float tipTaper = pow(smoothstep(0.0, 0.16, s), 0.72);
float collarPinch = 1.0 - 0.25 * exp(-pow((s - 0.185) / 0.025, 2.0));
float bodyWidth = mix(0.115, 0.075, smoothstep(0.18, 0.65, s)) * openW;
float tailTaper = smoothstep(0.90, 0.55, s);
float halfW = bodyWidth * tipTaper * collarPinch * tailTaper;
halfW = max(halfW, 0.001);
// Thickness profile (diamond beveled blade cross-section)
float halfT = mix(0.024, 0.010, smoothstep(0.18, 0.75, s)) * tipTaper * tailTaper;
halfT = max(halfT, 0.001);
// Bank/roll the blade slightly so the cutting edge leans outward dynamically
float bank = mix(0.32, 0.55, smoothstep(0.18, 0.70, s));
vec2 cs = rot2(bank) * vec2(ac.dr, ac.dy);
// Diamond-bevel blade cross-section SDF (sharp leading edge + fuller groove)
float dDiamond = (abs(cs.x) / halfW + abs(cs.y) / halfT - 1.0) * min(halfW, halfT) * 0.72;
// Fuller ridge along the blade spine (s in 0.18..0.52)
float fullerMask = smoothstep(0.17, 0.22, s) * smoothstep(0.55, 0.38, s);
float fuller = exp(-pow(cs.x / (halfW * 0.28 + 1e-4), 2.0)) * 0.004 * fullerMask;
dDiamond -= fuller;
// Combine with endcap distance (over)
float dBlade = length(vec2(max(dDiamond, 0.0), ac.over)) + min(dDiamond, 0.0);
// Bound tail cleanly
dBlade = max(dBlade, (ac.sRaw - 0.88) * ARC_SPAN * 1.1);
float bladeMat = (s < 0.185) ? 2.0 : 4.0;
if (dBlade < res.x) {
res = vec2(dBlade, bladeMat);
}
// 3. Ornate sculpted golden arcane crossguard / collar at s = 0.188
float sCollar = 0.188;
float dsCol = (ac.sRaw - sCollar) * ARC_SPAN * arcRadius(sCollar);
if (abs(dsCol) < 0.28 && abs(ac.dr) < 0.35 && abs(ac.dy) < 0.25) {
vec2 c2 = rot2(0.32) * vec2(ac.dr, ac.dy);
// Central sculpted octagonal collar ring around the blade
float dCollarCore = length(vec3(dsCol * 1.35, c2.x * 0.92, c2.y * 1.65)) - 0.068;
// Curved S-guard quillon wings flaring outward on both sides of the blade
float wingSpan = abs(c2.x);
float wingCurve = dsCol - 0.055 * sin(c2.x * 9.5) - 0.03 * wingSpan;
float wingR = mix(0.026, 0.010, smoothstep(0.04, 0.19, wingSpan));
float dWings = length(vec2(wingCurve, c2.y * 1.35)) - wingR;
dWings = max(dWings, wingSpan - 0.195);
// Finial buds at tips of the crossguard wings
float dFinial = length(vec3(dsCol - 0.04 * sign(c2.x), abs(c2.x) - 0.195, c2.y)) - 0.022;
float dCollar = smin(dCollarCore, dWings, 0.022);
dCollar = smin(dCollar, dFinial, 0.015);
if (dCollar < res.x) {
res = vec2(dCollar, 3.0);
}
}
return res;
}
// Unit-weight tetrahedral normal (zero-bug rule)
vec3 calcNormal(vec3 p) {
const float eps = 0.0012;
const vec2 k = vec2(1.0, -1.0);
return normalize(
k.xyy * mapScene(p + k.xyy * eps).x +
k.yyx * mapScene(p + k.yyx * eps).x +
k.yxy * mapScene(p + k.yxy * eps).x +
k.xxx * mapScene(p + k.xxx * eps).x
);
}
// Analytic perturbed wet-floor normal for crisp tile bevels & basalt grain
vec3 calcFloorNormal(vec3 p, FloorInfo fi) {
const float e = 0.003;
float hx = evalFloorInfo(p.xz + vec2(e, 0.0)).height - fi.height;
float hz = evalFloorInfo(p.xz + vec2(0.0, e)).height - fi.height;
// Slight puddle surface tension smoothing
float flatScale = mix(1.0, 0.22, fi.wetness * fi.bevel);
vec3 n = normalize(vec3(-hx * flatScale, e, -hz * flatScale));
return n;
}
// ============================================================================
// PROCEDURAL ARCANE RUNE GLYPHS (4-point diamond star, hourglass sigil, ring)
// ============================================================================
float sdSegment2(vec2 p, vec2 a, vec2 b) {
vec2 pa = p - a, ba = b - a;
float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-6), 0.0, 1.0);
return length(pa - ba * h);
}
float evalRuneGlyph(vec2 uv, int type) {
// uv in [-1, 1]
float d = 10.0;
if (type == 0) {
// 4-point concave arcane diamond star
vec2 a = abs(uv);
float star = abs(pow(max(a.x, 1e-4), 0.62) + pow(max(a.y, 1e-4), 0.62) - 0.72);
d = star * 0.48;
// Inner dot
d = min(d, length(uv) - 0.09);
} else if (type == 1) {
// Hourglass / Gemini arcane sigil (matches ref runes!)
float topBar = sdSegment2(uv, vec2(-0.55, 0.58), vec2(0.55, 0.58));
float botBar = sdSegment2(uv, vec2(-0.55, -0.58), vec2(0.55, -0.58));
float leftCurve = abs(uv.x + 0.34 - 0.16 * uv.y * uv.y);
leftCurve = max(leftCurve, abs(uv.y) - 0.58);
float rightCurve = abs(uv.x - 0.34 + 0.16 * uv.y * uv.y);
rightCurve = max(rightCurve, abs(uv.y) - 0.58);
float midBar = sdSegment2(uv, vec2(-0.22, 0.0), vec2(0.22, 0.0));
d = min(min(topBar, botBar), min(min(leftCurve, rightCurve), midBar));
} else {
// Ringed crescent rune
float ring = abs(length(uv) - 0.50);
float crossV = sdSegment2(uv, vec2(0.0, -0.72), vec2(0.0, 0.72));
float crossH = sdSegment2(uv, vec2(-0.62, 0.12), vec2(0.62, 0.12));
d = min(ring, min(crossV, crossH));
}
return smoothstep(0.11, 0.025, d);
}
// ============================================================================
// VOLUMETRIC ARCANE ENERGY SWEEP + WISPY FILAMENTS + SPARKS + RUNES
// Used for BOTH primary camera rays and real-time wet-floor reflection rays!
// ============================================================================
vec3 evalVolumetricVFX(vec3 ro, vec3 rd, float tMax, int steps, bool isRefl) {
if (uLightMode == 1) {
return vec3(0.0); // Pure neutral clay mode: mute emission
}
// Bounding sphere intersection around ARC_CENTER (radius 2.15)
vec3 oc = ro - ARC_CENTER;
float b = dot(oc, rd);
float c = dot(oc, oc) - 2.15 * 2.15;
float disc = b * b - c;
if (disc < 0.0) return vec3(0.0);
float sq = sqrt(disc);
float t0 = max(0.02, -b - sq);
float t1 = min(tMax, -b + sq);
if (t1 <= t0) return vec3(0.0);
float phase = loopPhase();
float openAmt = clamp(uOpen, 0.0, 1.0);
float widthBoost = 1.0 + 0.45 * openAmt;
float emberBoost = 1.0 + 0.65 * openAmt;
// Slight blue-noise-like jitter to eliminate banding
float jitter = hash21(gl_FragCoord.xy + (isRefl ? vec2(37.0, 19.0) : vec2(0.0)));
float dt = (t1 - t0) / float(steps);
float t = t0 + dt * jitter;
vec3 accum = vec3(0.0);
for (int i = 0; i < 56; i++) {
if (i >= steps) break;
vec3 p = ro + rd * t;
// Skip below floor on primary ray
if (!isRefl && p.y < 0.0) {
t += dt;
continue;
}
ArcCoord ac = evalArcCoord(p);
float s = ac.s;
// Distance from the ribbon envelope
float ribbonW = mix(0.22, 0.34, smoothstep(0.15, 0.72, s)) * widthBoost;
ribbonW *= smoothstep(0.0, 0.06, s) * smoothstep(1.0, 0.78, s);
float ribbonH = mix(0.11, 0.19, smoothstep(0.15, 0.72, s)) * widthBoost;
float bank = mix(0.32, 0.55, smoothstep(0.18, 0.70, s));
vec2 cs = rot2(bank) * vec2(ac.dr, ac.dy);
// Quick spatial skip when far from arc tube
float quickR2 = cs.x * cs.x + cs.y * cs.y + ac.over * ac.over;
if (quickR2 < 0.42) {
// 1. Volumetric turbulent energy sweep
vec3 flowCoord = vec3(s * 7.5, cs.x * 4.5, cs.y * 5.0);
float turb = periodicTurb3(flowCoord, vec3(-3.2, 0.9, 0.6), phase);
float turb2 = periodicTurb3(flowCoord * 1.9 + vec3(4.1, 1.7, 2.3), vec3(-5.0, -1.2, 0.8), phase);
// Wispy displacement of the ribbon cross-section
vec2 wcs = cs;
wcs.x += (turb - 0.5) * 0.20 * smoothstep(0.12, 0.45, s);
wcs.y += (turb2 - 0.5) * 0.14 * smoothstep(0.10, 0.45, s);
float ellip = (wcs.x * wcs.x) / max(ribbonW * ribbonW, 1e-4)
+ (wcs.y * wcs.y) / max(ribbonH * ribbonH, 1e-4)
+ (ac.over * ac.over) * 18.0;
float env = exp(-ellip * 2.2);
float wisps = smoothstep(0.28, 0.82, turb * 0.65 + turb2 * 0.35);
float volDens = env * (0.35 + 1.15 * wisps);
// Color palette transition along the sweeping arc:
// Tip (0..0.18): White-gold core -> Warm arcane gold
// Mid (0.18..0.44): Luminous cyan
// Sweep (0.44..1.0): Deep cobalt -> indigo wisps
vec3 cTip = mix(COL_CORE, COL_GOLD, smoothstep(0.04, 0.22, ellip));
vec3 cMid = mix(COL_CYAN, COL_COBALT, smoothstep(0.22, 0.54, s));
vec3 cTail = mix(COL_COBALT, vec3(0.04, 0.12, 0.55), smoothstep(0.68, 1.0, s));
vec3 energyCol = mix(cTip, cMid, smoothstep(0.14, 0.24, s));
energyCol = mix(energyCol, cTail, smoothstep(0.48, 0.78, s));
// Bright hot core glow around the blazing front-right crescent blade tip
float tipGlow = exp(-(cs.x * cs.x * 36.0 + cs.y * cs.y * 55.0 + ac.over * ac.over * 45.0))
* smoothstep(0.24, 0.02, s) * smoothstep(-0.02, 0.03, ac.sRaw);
vec3 tipAura = mix(COL_GOLD, COL_CORE, clamp(tipGlow * 1.4, 0.0, 1.0)) * tipGlow * 2.6;
// Golden surge burst right around the ornate crossguard collar
float collarBurst = exp(-((ac.sRaw - 0.175) * (ac.sRaw - 0.175) * 260.0 + cs.x * cs.x * 26.0 + cs.y * cs.y * 32.0));
tipAura += mix(COL_GOLD, COL_CORE, 0.55) * collarBurst * (2.4 * emberBoost);
// 2. Crackling electric energy vein along the spine (s in [0.22, 0.88])
float veinMask = smoothstep(0.20, 0.28, s) * smoothstep(0.90, 0.72, s);
float jx = (vnoise2(vec2(s * 24.0 - phase * 6.0, 3.1)) - 0.5) * 0.085
+ (vnoise2(vec2(s * 52.0 - phase * 12.0, 9.7)) - 0.5) * 0.035;
float jy = (vnoise2(vec2(s * 26.0 - phase * 6.0, 11.4)) - 0.5) * 0.055;
float dVein = length(vec2(cs.x - jx, cs.y - jy));
float vein = exp(-dVein * dVein * 2800.0) * veinMask;
float veinHalo = exp(-dVein * dVein * 260.0) * veinMask * 0.45;
vec3 veinCol = mix(COL_CYAN, vec3(0.82, 0.94, 1.0), 0.72) * (vein * 3.8 + veinHalo);
// 3. Swirling golden embers & sparkling motes in the wake (3D cellular grid in arc space)
vec3 sparkCoord = vec3(s * 22.0 - phase * 2.0, ac.dr * 13.0, ac.dy * 13.0);
vec3 sid = floor(sparkCoord);
vec3 sf = fract(sparkCoord) - 0.5;
float sh = hash31(sid);
float sparkEnv = exp(-(ac.dr * ac.dr * 5.2 + ac.dy * ac.dy * 10.5 + ac.over * ac.over * 12.0));
// Denser golden spark spray near the blazing tip & collar
float tipSparkBoost = 1.0 + 2.2 * exp(-pow((s - 0.14) / 0.14, 2.0));
float sparkThresh = mix(0.76, 0.62, openAmt);
vec3 sparkCol = vec3(0.0);
if (sh > sparkThresh && sparkEnv > 0.04) {
vec3 jitterP = vec3(
hash31(sid + 1.3) - 0.5,
hash31(sid + 2.7) - 0.5,
hash31(sid + 4.1) - 0.5
) * 0.68;
float sd = length(sf - jitterP);
float twinkle = 0.55 + 0.45 * sin(TAU * (phase + sh * 3.0));
float pt = exp(-sd * sd * 135.0) * twinkle * sparkEnv * tipSparkBoost;
sparkCol = mix(COL_GOLD, COL_CORE, smoothstep(0.84, 0.98, sh)) * pt * (3.6 * emberBoost);
}
// Combine volumetric contribution
float ribbonGain = isRefl ? 1.55 : 1.35;
accum += (energyCol * volDens * ribbonGain + tipAura + veinCol + sparkCol) * dt;
}
t += dt;
}
// 4. Crisp floating golden arcane rune motes along the outer wake
// Evaluate 12 curated rune billboards analytically along the ray (ultra-crisp!)
int runeCount = isRefl ? 8 : 12;
for (int i = 0; i < 12; i++) {
if (i >= runeCount) break;
float fi = float(i);
float sBase = mix(0.08, 0.90, fi / 11.0);
// Gentle periodic drift along the arc & subtle bobbing
float drift = 0.018 * sin(TAU * (phase + fi * 0.17));
float sR = clamp(sBase + drift, 0.04, 0.94);
vec3 center = arcPointWorld(sR);
// Offset slightly outside the arc ribbon & slightly above/below
vec3 ax, ay, az;
getArcBasis(ax, ay, az);
float theta = ARC_START + slashAnimOffset() + sR * ARC_SPAN;
vec3 radDir = ax * cos(theta) + az * sin(theta);
float side = (mod(fi, 2.0) < 0.5) ? 1.0 : -0.55;
float rOff = mix(0.24, 0.36, hash11(fi * 3.7 + 1.1)) * side;
float yOff = (hash11(fi * 5.3 + 2.1) - 0.42) * 0.18 + 0.025 * cos(TAU * (phase + fi * 0.23));
vec3 runePos = center + radDir * rOff + ay * yOff;
runePos.y = max(runePos.y, 0.09);
// Intersect ray with camera-facing / floor-tilted rune disc
vec3 rNorm = normalize(mix(-rd, vec3(0.0, 1.0, 0.0), 0.25));
float denom = dot(rd, rNorm);
if (abs(denom) > 1e-4) {
float tHit = dot(runePos - ro, rNorm) / denom;
if (tHit > 0.05 && tHit < tMax) {
vec3 hitP = ro + rd * tHit;
vec3 dP = hitP - runePos;
float size = mix(0.058, 0.082, hash11(fi * 7.1 + 0.5)) * (1.0 + 0.18 * openAmt);
if (dot(dP, dP) < size * size * 1.45) {
vec3 uDir = normalize(cross(vec3(0.0, 1.0, 0.0), rNorm));
vec3 vDir = cross(rNorm, uDir);
vec2 ruv = vec2(dot(dP, uDir), dot(dP, vDir)) / size;
ruv = rot2(0.35 * sin(TAU * phase + fi)) * ruv;
int rType = int(mod(fi, 3.0));
float glyph = evalRuneGlyph(ruv, rType);
float halo = exp(-dot(ruv, ruv) * 2.2) * 0.22;
float pulse = 0.72 + 0.28 * sin(TAU * (phase + fi * 0.31));
float fade = smoothstep(0.95, 0.70, sR);
vec3 rCol = mix(COL_GOLD, COL_CORE, glyph * 0.65) * (glyph * 2.4 + halo) * pulse * fade * emberBoost;
accum += rCol * (isRefl ? 0.78 : 1.0);
}
}
}
}
return accum;
}
// ============================================================================
// PBR LIGHTING & STUDIO ENVIRONMENT
// ============================================================================
float D_GGX(float NoH, float rough) {
float a = max(rough * rough, 0.002);
float a2 = a * a;
float d = NoH * NoH * (a2 - 1.0) + 1.0;
return a2 / max(PI * d * d, 1e-6);
}
float G_SchlickGGX(float NoV, float NoL, float rough) {
float r = rough + 1.0;
float k = (r * r) / 8.0;
float gv = NoV / max(NoV * (1.0 - k) + k, 1e-5);
float gl = NoL / max(NoL * (1.0 - k) + k, 1e-5);
return gv * gl;
}
vec3 F_Schlick(float cosTheta, vec3 F0) {
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
}
vec3 evalLightPBR(vec3 N, vec3 V, vec3 L, vec3 lightCol, vec3 albedo, float rough, float metal) {
float NoL = max(dot(N, L), 0.0);
if (NoL <= 0.0) return vec3(0.0);
float NoV = max(dot(N, V), 1e-4);
vec3 H = normalize(V + L);
float NoH = max(dot(N, H), 0.0);
float VoH = max(dot(V, H), 0.0);
vec3 F0 = mix(vec3(0.04), albedo, metal);
vec3 F = F_Schlick(VoH, F0);
float D = D_GGX(NoH, rough);
float G = G_SchlickGGX(NoV, NoL, rough);
vec3 spec = (D * G * F) / max(4.0 * NoV * NoL, 1e-4);
vec3 kD = (1.0 - F) * (1.0 - metal);
vec3 diff = kD * albedo / PI;
return (diff + spec) * lightCol * NoL;
}
// Soft studio environment sky/softbox reflection for obsidian wet tiles & metal
vec3 evalStudioEnv(vec3 dir, int lightMode) {
float y = clamp(dir.y, 0.0, 1.0);
if (lightMode == 1) {
// Pure neutral studio softbox
float softbox = smoothstep(0.35, 0.85, dot(dir, normalize(vec3(0.35, 0.78, 0.52))));
float rimBox = smoothstep(0.45, 0.90, dot(dir, normalize(vec3(-0.65, 0.55, -0.52))));
float v = mix(0.14, 0.34, y) + 0.55 * softbox + 0.25 * rimBox;
return vec3(v);
}
// Dark obsidian studio ceiling with moody cool-slate overhead rim softboxes
// (gives crisp silvery-blue puddle highlights while keeping obsidian dark #0B0E12)
vec3 base = mix(COL_OBSIDIAN * 0.42, vec3(0.032, 0.052, 0.105), pow(y, 0.72));
// Overhead cool slate studio strip lights
float strip1 = smoothstep(0.52, 0.94, dot(dir, normalize(vec3(0.28, 0.62, -0.73))));
float strip2 = smoothstep(0.60, 0.95, dot(dir, normalize(vec3(-0.55, 0.48, -0.68))));
float strip3 = smoothstep(0.50, 0.90, dot(dir, normalize(vec3(0.75, 0.35, -0.55))));
vec3 skyCol = base
+ vec3(0.22, 0.32, 0.48) * strip1 * 0.55
+ vec3(0.12, 0.21, 0.38) * strip2 * 0.42
+ vec3(0.16, 0.25, 0.40) * strip3 * 0.36;
if (lightMode == 2) {
// Grazing mode: boost low-angle cool-gold rim
float graze = smoothstep(0.58, 0.96, dot(dir, normalize(vec3(0.82, 0.20, -0.52))));
skyCol += vec3(0.38, 0.44, 0.58) * graze;
} else if (lightMode == 3) {
// Backlit mode: crisp studio backlight behind the arc without washing out darks
float back = smoothstep(0.45, 0.92, dot(dir, normalize(vec3(-0.15, 0.35, -0.92))));
skyCol += mix(COL_CYAN, vec3(0.65, 0.80, 0.98), 0.50) * back * 0.78;
}
return skyCol;
}
// ============================================================================
// RAYMARCHING & SHADING
// ============================================================================
vec2 raymarch(vec3 ro, vec3 rd, float tMax) {
float t = 0.02;
for (int i = 0; i < 96; i++) {
vec3 p = ro + rd * t;
vec2 h = mapScene(p);
if (h.x < 0.0012 * (1.0 + t * 0.25)) {
return vec2(t, h.y);
}
t += clamp(h.x * 0.85, 0.004, 0.25);
if (t > tMax) break;
}
return vec2(-1.0, 0.0);
}
// Analytical arcane area lights distributed along the sweeping slash arc
// to cast rich cyan/cobalt/gold light spill & specular highlights onto the wet floor.
vec3 evalArcaneSpill(vec3 p, vec3 N, vec3 V, vec3 albedo, float rough, float metal) {
if (uLightMode == 1) return vec3(0.0);
float openBoost = 1.0 + 0.35 * clamp(uOpen, 0.0, 1.0);
vec3 total = vec3(0.0);
// 6 weighted point emitters along the sweeping slash
const float sPos[6] = float[6](0.06, 0.16, 0.28, 0.44, 0.62, 0.80);
for (int i = 0; i < 6; i++) {
float s = sPos[i];
vec3 lPos = arcPointWorld(s);
vec3 toL = lPos - p;
float d2 = dot(toL, toL) + 0.08;
float dist = sqrt(d2);
vec3 L = toL / dist;
vec3 lCol;
float power;
if (i == 0) {
lCol = mix(COL_CORE, COL_GOLD, 0.35);
power = 2.6 * openBoost;
} else if (i == 1) {
lCol = COL_GOLD;
power = 2.2 * openBoost;
} else if (i == 2) {
lCol = COL_CYAN;
power = 1.8 * openBoost;
} else if (i == 3) {
lCol = mix(COL_CYAN, COL_COBALT, 0.55);
power = 1.45 * openBoost;
} else if (i == 4) {
lCol = COL_COBALT;
power = 1.15 * openBoost;
} else {
lCol = COL_COBALT * 0.85;
power = 0.75 * openBoost;
}
float atten = power / (d2 + 0.18 * dist);
total += evalLightPBR(N, V, L, lCol * atten, albedo, rough, metal);
}
return total;
}
vec3 shadeHit(vec3 p, vec3 rd, float matId, float tHit) {
vec3 V = -rd;
vec3 N = calcNormal(p);
bool neutral = (uLightMode == 1);
// Primary studio directional light setup per uLightMode
vec3 keyDir, keyCol, rimDir, rimCol;
if (uLightMode == 1) {
keyDir = normalize(vec3(0.55, 0.78, 0.45));
keyCol = vec3(1.55);
rimDir = normalize(vec3(-0.65, 0.48, -0.58));
rimCol = vec3(0.65);
} else if (uLightMode == 2) {
// Grazing mode
keyDir = normalize(vec3(0.86, 0.16, 0.48));
keyCol = vec3(0.65, 0.74, 0.92) * 0.95;
rimDir = normalize(vec3(-0.78, 0.22, -0.58));
rimCol = vec3(0.62, 0.52, 0.40) * 0.65;
} else if (uLightMode == 3) {
// Backlit mode
keyDir = normalize(vec3(-0.20, 0.42, -0.88));
keyCol = vec3(0.38, 0.60, 0.88) * 1.10;
rimDir = normalize(vec3(0.65, 0.35, -0.68));
rimCol = COL_GOLD * 0.60;
} else {
// Hero mode: moody cool-slate studio overhead fill so dark obsidian tiles read with high contrast
keyDir = normalize(vec3(0.35, 0.82, -0.45));
keyCol = vec3(0.16, 0.23, 0.36) * 0.78;
rimDir = normalize(vec3(-0.62, 0.52, -0.58));
rimCol = vec3(0.12, 0.20, 0.34) * 0.55;
}
vec3 col = vec3(0.0);
if (matId < 1.5) {
// --------------------------------------------------------------------
// MATERIAL 1: Wet Obsidian Tiled Arena Floor
// --------------------------------------------------------------------
FloorInfo fi = evalFloorInfo(p.xz);
N = calcFloorNormal(p, fi);
vec3 baseObsidian = COL_OBSIDIAN * 0.42 * (0.86 + 0.34 * fi.microBump + 0.16 * (fi.tileId - 0.5));
baseObsidian = mix(baseObsidian, COL_OBSIDIAN * 0.18, fi.grout);
// Darken wet stone slightly (physically accurate wet porosity)
baseObsidian *= mix(1.0, 0.68, fi.wetness);
vec3 albedo = neutral
? vec3(mix(0.34, 0.44, fi.microBump) * mix(1.0, 0.55, fi.grout))
: baseObsidian;
float rough = mix(0.34, 0.052, fi.wetness * fi.bevel);
rough = mix(rough, 0.68, fi.grout);
if (neutral) rough = mix(0.42, 0.16, fi.wetness * fi.bevel);
// Studio key & rim
col += evalLightPBR(N, V, keyDir, keyCol, albedo, rough, 0.0);
col += evalLightPBR(N, V, rimDir, rimCol, albedo, rough, 0.0);
// Controlled ambient bounce: deep #0B0E12 obsidian floor without dead-black crush
vec3 ambCol = neutral ? vec3(0.16) : vec3(0.022, 0.032, 0.062);
col += albedo * ambCol * (0.8 + 0.4 * fi.bevel);
// Arcane VFX light spill across the wet tiles
col += evalArcaneSpill(p, N, V, albedo, rough, 0.0);
// Real-time glossy specular reflection of studio + sweeping arcane VFX!
vec3 R = reflect(-V, N);
R.y = max(R.y, 0.01);
float NoV = max(dot(N, V), 1e-4);
vec3 F0 = vec3(mix(0.04, 0.085, fi.wetness));
vec3 fresnel = F_Schlick(NoV, F0);
float reflGloss = mix(0.22, 1.0, pow(1.0 - rough, 1.5)) * (1.0 - fi.grout * 0.78);
vec3 envRefl = evalStudioEnv(R, uLightMode);
vec3 vfxRefl = vec3(0.0);
if (!neutral) {
// Secondary volumetric + rune reflection ray off the wet puddle!
vfxRefl = evalVolumetricVFX(p + N * 0.012, R, 5.5, 26, true);
// Boost crispness inside glossy wet puddles
vfxRefl *= mix(0.55, 1.40, fi.wetness);
}
// Fresnel-weighted reflection (rich VFX mirror reflections, restrained studio sky)
vec3 reflWeight = mix(fresnel, vec3(0.32), fi.wetness * 0.36) * reflGloss;
col += envRefl * reflWeight * 0.56 + vfxRefl * reflGloss * (0.52 + 0.60 * fresnel);
} else if (matId < 2.5) {
// --------------------------------------------------------------------
// MATERIAL 2: Sculpted Blazing White-Gold Crescent Blade Tip
// --------------------------------------------------------------------
ArcCoord ac = evalArcCoord(p);
vec3 albedo = neutral ? vec3(0.68) : COL_CORE;
float rough = neutral ? 0.24 : 0.14;
float metal = neutral ? 0.15 : 0.35;
col += evalLightPBR(N, V, keyDir, keyCol, albedo, rough, metal);
col += evalLightPBR(N, V, rimDir, rimCol, albedo, rough, metal);
col += albedo * (neutral ? vec3(0.20) : vec3(0.12));
if (!neutral) {
float NoV = clamp(dot(N, V), 0.0, 1.0);
float rim = pow(1.0 - NoV, 2.0);
// White-gold hot core with warm arcane gold grazing edge & subtle cyan ice sheen
vec3 bladeGlow = mix(COL_CORE * 2.4, COL_GOLD * 1.9, rim * 0.65);
bladeGlow = mix(bladeGlow, mix(COL_CORE, COL_CYAN, 0.35) * 2.2, smoothstep(0.12, 0.02, ac.s) * 0.35);
// Extra heat right near the collar junction
float collarHeat = exp(-pow((ac.s - 0.17) / 0.055, 2.0));
bladeGlow += COL_GOLD * collarHeat * 1.4;
col += bladeGlow;
}
} else if (matId < 3.5) {
// --------------------------------------------------------------------
// MATERIAL 3: Ornate Sculpted Golden Arcane Crossguard / Collar
// --------------------------------------------------------------------
vec3 goldAlbedo = vec3(0.96, 0.72, 0.26);
vec3 albedo = neutral ? vec3(0.56) : goldAlbedo;
float rough = neutral ? 0.28 : 0.22;
float metal = neutral ? 0.15 : 0.92;
col += evalLightPBR(N, V, keyDir, keyCol * 1.35, albedo, rough, metal);
col += evalLightPBR(N, V, rimDir, rimCol * 1.25, albedo, rough, metal);
col += evalArcaneSpill(p, N, V, albedo, rough, metal);
vec3 R = reflect(-V, N);
col += evalStudioEnv(R, uLightMode) * albedo * (neutral ? 0.22 : 0.65);
if (!neutral) {
// Subtle warm emissive bounce from adjacent blazing blade
float NoV = clamp(dot(N, V), 0.0, 1.0);
col += COL_GOLD * (0.28 + 0.55 * pow(1.0 - NoV, 2.5));
}
} else {
// --------------------------------------------------------------------
// MATERIAL 4: Sculpted Luminous Cyan-to-Cobalt Blade & Ribbon Core
// --------------------------------------------------------------------
ArcCoord ac = evalArcCoord(p);
float s = ac.s;
vec3 baseCol = mix(COL_CYAN, COL_COBALT, smoothstep(0.22, 0.54, s));
vec3 albedo = neutral ? vec3(0.60) : baseCol;
float rough = neutral ? 0.26 : 0.16;
float metal = neutral ? 0.10 : 0.45;
col += evalLightPBR(N, V, keyDir, keyCol, albedo, rough, metal);
col += evalLightPBR(N, V, rimDir, rimCol, albedo, rough, metal);
col += albedo * (neutral ? vec3(0.18) : vec3(0.10));
if (!neutral) {
float NoV = clamp(dot(N, V), 0.0, 1.0);
float fres = pow(1.0 - NoV, 2.2);
float tailFade = smoothstep(0.88, 0.35, s);
// Intense cyan near collar, transitioning into deep cobalt with bright electric bevel rim
vec3 coreGlow = mix(COL_CYAN * 1.75, COL_COBALT * 1.35, smoothstep(0.22, 0.52, s));
coreGlow += mix(COL_CORE, COL_CYAN, 0.55) * fres * 1.25;
// Subtle flowing energy striations along the blade fuller
float stripe = 0.75 + 0.25 * sin(s * 38.0 - loopPhase() * TAU * 2.0);
col += coreGlow * tailFade * stripe;
}
}
// Subtle distance atmospheric perspective on the wet arena floor
float fogAmt = 1.0 - exp(-tHit * tHit * 0.015);
vec3 fogCol = neutral ? vec3(0.16) : (COL_OBSIDIAN * 0.46);
col = mix(col, fogCol, clamp(fogAmt, 0.0, 0.65));
return col;
}
// ============================================================================
// CAMERA & ACES FILMIC TONE MAPPING
// ============================================================================
vec3 acesToneMap(vec3 x) {
// Controlled soft-shoulder rolloff before ACES to prevent >1% clipping
x = max(x, vec3(0.0));
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
return clamp((x * (a * x + b)) / max(x * (c * x + d) + e, vec3(1e-5)), 0.0, 1.0);
}
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * uResolution.xy) / max(uResolution.y, 1.0);
// Camera framing:
// uCamMode == 0 : Hero 3/4 high-angle cinematic view matching 01.png (full arc inside frame)
// uCamMode == 1 : ~2.5x Macro close-up on blazing crescent tip, golden collar & wet reflection
vec3 ro, ta;
float fov;
if (uCamMode == 1) {
ro = vec3(0.92, 0.96, 1.88);
ta = vec3(0.68, 0.28, 0.56);
fov = 1.85;
} else {
ro = vec3(0.18, 2.38, 3.65);
ta = vec3(-0.04, 0.50, 0.02);
fov = 1.48;
}
vec3 cw = normalize(ta - ro);
vec3 cu = normalize(cross(cw, vec3(0.0, 1.0, 0.0)));
vec3 cv = cross(cu, cw);
vec3 rd = normalize(uv.x * cu + uv.y * cv + fov * cw);
float tMax = 18.0;
vec2 hit = raymarch(ro, rd, tMax);
vec3 col;
float volMaxT = tMax;
if (hit.x > 0.0) {
vec3 p = ro + rd * hit.x;
col = shadeHit(p, rd, hit.y, hit.x);
volMaxT = hit.x;
} else {
col = evalStudioEnv(rd, uLightMode);
}
// Primary volumetric VFX sweep, wispy filaments, electric vein, sparks & runes
vec3 vfx = evalVolumetricVFX(ro, rd, volMaxT, 48, false);
col += vfx;
// Gentle exposure & controlled cinematic vignette (kept mild so corners never crush to black)
float exposure = (uLightMode == 1) ? 1.05 : 1.08;
col *= exposure;
float vig = 1.0 - 0.16 * dot(uv, uv);
col *= clamp(vig, 0.78, 1.0);
// ACES Filmic Tone Mapping
col = acesToneMap(col);
// Enforce pure neutral grayscale in uLightMode == 1
if (uLightMode == 1) {
float lum = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(lum);
}
// sRGB gamma encode
col = pow(max(col, vec3(0.0)), vec3(1.0 / 2.2));
fragColor = vec4(col, 1.0);
}
shader_type canvas_item;
// Tip: uncomment the next line for zero-overdraw additive 2D combat/spell glow:
// render_mode blend_add;
// Arcane Slash Arc — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/vfx_palette/lib/01_arcane_slash_arc.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;
// ============================================================================
// 01_arcane_slash_arc.glsl
// Sweeping 3D crescent arcane sword-slash ribbon above a dark wet tiled
// obsidian arena floor.
// Unified Arcane Palette:
// Obsidian floor : vec3(0.03, 0.05, 0.12)
// Deep cobalt : vec3(0.08, 0.32, 0.98)
// Luminous cyan : vec3(0.10, 0.85, 1.00)
// Warm gold : vec3(1.00, 0.68, 0.18)
// White-gold core: vec3(1.00, 0.96, 0.86)
// ============================================================================
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
const vec3 COL_OBSIDIAN = vec3(0.03, 0.05, 0.12);
const vec3 COL_COBALT = vec3(0.08, 0.32, 0.98);
const vec3 COL_CYAN = vec3(0.10, 0.85, 1.00);
const vec3 COL_GOLD = vec3(1.00, 0.68, 0.18);
const vec3 COL_CORE = vec3(1.00, 0.96, 0.86);
// Smooth 3-second loop phase in [0, 1)
float loopPhase() {
return fract(uTime / 3.0);
}
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
float hash11(float p) {
p = fract(p * 0.1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
float hash21(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
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 hash31(vec3 p3) {
p3 = fract(p3 * 0.1031);
p3 += dot(p3, p3.zyx + 31.32);
return fract((p3.x + p3.y) * p3.z);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}
float vnoise3(vec3 p) {
vec3 i = floor(p);
vec3 f = fract(p);
vec3 u = f * f * (3.0 - 2.0 * f);
float n000 = hash31(i + vec3(0.0, 0.0, 0.0));
float n100 = hash31(i + vec3(1.0, 0.0, 0.0));
float n010 = hash31(i + vec3(0.0, 1.0, 0.0));
float n110 = hash31(i + vec3(1.0, 1.0, 0.0));
float n001 = hash31(i + vec3(0.0, 0.0, 1.0));
float n101 = hash31(i + vec3(1.0, 0.0, 1.0));
float n011 = hash31(i + vec3(0.0, 1.0, 1.0));
float n111 = hash31(i + vec3(1.0, 1.0, 1.0));
float nx00 = mix(n000, n100, u.x);
float nx10 = mix(n010, n110, u.x);
float nx01 = mix(n001, n101, u.x);
float nx11 = mix(n011, n111, u.x);
return mix(mix(nx00, nx10, u.y), mix(nx01, nx11, u.y), u.z);
}
float fbm2(vec2 p) {
float v = 0.0;
float a = 0.5;
mat2 m = mat2(0.8, 0.6, -0.6, 0.8);
for (int i = 0; i < 4; i++) {
v += a * vnoise2(p);
p = m * p * 2.03 + vec2(17.1, 31.7);
a *= 0.5;
}
return v;
}
float fbm3(vec3 p) {
float v = 0.0;
float a = 0.5;
for (int i = 0; i < 3; i++) {
v += a * vnoise3(p);
p = p * 2.07 + vec3(11.3, 23.7, 7.1);
a *= 0.5;
}
return v;
}
// Smooth periodic 3D turbulence using two time-blended scrolling layers
// so the 3-second loop is 100% seamless.
float periodicTurb3(vec3 p, vec3 flow, float phase) {
float p0 = fract(phase);
float p1 = fract(phase + 0.5);
float w0 = 1.0 - abs(2.0 * p0 - 1.0);
float w1 = 1.0 - w0;
float n0 = fbm3(p + flow * p0);
float n1 = fbm3(p + flow * p1 + vec3(19.3, 7.7, 13.1));
return n0 * w0 + n1 * w1;
}
float smin(float a, float b, float k) {
float h = clamp(0.5 + 0.5 * (b - a) / max(k, 1e-4), 0.0, 1.0);
return mix(b, a, h) - k * h * (1.0 - h);
}
// ============================================================================
// ARC COORDINATE FRAME
// Sweeps in a tilted 3D plane above the wet obsidian floor (y = 0):
// s = 0.0 : blazing white-gold crescent tip (front-right, low over floor)
// s = 0.19 : ornate golden arcane crossguard/collar
// s = 0.19..0.46 : sculpted luminous cyan-to-cobalt blade body
// s = 0.46..1.00 : sweeping cobalt volumetric energy ribbon tapering to tail
// ============================================================================
const vec3 ARC_CENTER = vec3(-0.02, 0.78, -0.06);
void getArcBasis(out vec3 ax, out vec3 ay, out vec3 az) {
// Tilt arc plane so front-right (+X, +Z) dips close to the wet floor
// and back-left (-X, -Z) rises gracefully into the dark studio space.
ay = normalize(vec3(0.22, 0.90, 0.37));
ax = normalize(cross(ay, vec3(0.0, 0.0, 1.0)));
az = normalize(cross(ax, ay));
}
vec3 worldToArc(vec3 p) {
vec3 ax, ay, az;
getArcBasis(ax, ay, az);
vec3 d = p - ARC_CENTER;
return vec3(dot(d, ax), dot(d, ay), dot(d, az));
}
vec3 arcToWorld(vec3 q) {
vec3 ax, ay, az;
getArcBasis(ax, ay, az);
return ARC_CENTER + ax * q.x + ay * q.y + az * q.z;
}
// Arc angular span:
// thetaStart (tip, s=0) = +0.25 rad (front-right, curving slightly up-right)
// thetaEnd (tail, s=1) = +0.25 + 4.25 rad (~245 deg dramatic crescent sweep)
const float ARC_START = 0.25;
const float ARC_SPAN = 4.25;
// Nominal spiral radius along s in [0, 1]
float arcRadius(float s) {
// Slight graceful scimitar spiral with gentle inward hook at the crescent tip
float r = 1.18 - 0.12 * s;
// Tip flares gently outward then hooks sharp
float tipCurve = smoothstep(0.22, 0.0, s);
r += 0.07 * tipCurve * (1.0 - 0.85 * tipCurve);
return r;
}
// Subtle 3s breathing/sweeping motion offset in arc angle
float slashAnimOffset() {
float ph = loopPhase();
return 0.06 * sin(TAU * ph);
}
// Evaluate world position on the arc centerline for parameter s in [0, 1]
vec3 arcPointWorld(float s) {
float theta = ARC_START + slashAnimOffset() + s * ARC_SPAN;
float r = arcRadius(s);
// Slight vertical wave along the ribbon so it feels dynamically swept in 3D
float lift = 0.04 * sin(s * PI * 1.5) - 0.06 * smoothstep(0.25, 0.0, s);
// Subtle upward flick right at the crescent blade tip
lift += 0.10 * pow(clamp(1.0 - s / 0.14, 0.0, 1.0), 2.2);
vec3 q = vec3(r * cos(theta), lift, r * sin(theta));
return arcToWorld(q);
}
// Given world point p, return:
// s : normalized arc parameter in [0, 1] (clamped)
// dr : signed radial offset from centerline (positive = outer edge)
// dy : signed normal offset from arc ribbon surface
// over: how far outside [0, 1] in arc-length units the angle fell
struct ArcCoord {
float s;
float sRaw;
float dr;
float dy;
float over;
};
ArcCoord evalArcCoord(vec3 p) {
vec3 q = worldToArc(p);
float r = length(q.xz);
float ang = atan(q.z, q.x); // [-PI, PI]
float a0 = ARC_START + slashAnimOffset();
// Unwrap angle relative to a0 into [-0.65, TAU - 0.65]
float dAng = mod(ang - a0 + 0.65, TAU) - 0.65;
float sRaw = dAng / ARC_SPAN;
float s = clamp(sRaw, 0.0, 1.0);
float r0 = arcRadius(s);
float lift = 0.04 * sin(s * PI * 1.5) - 0.06 * smoothstep(0.25, 0.0, s);
lift += 0.10 * pow(clamp(1.0 - s / 0.14, 0.0, 1.0), 2.2);
float over = 0.0;
if (sRaw < 0.0) over = -sRaw * ARC_SPAN * r0;
else if (sRaw > 1.0) over = (sRaw - 1.0) * ARC_SPAN * r0;
ArcCoord ac;
ac.s = s;
ac.sRaw = sRaw;
ac.dr = r - r0;
ac.dy = q.y - lift;
ac.over = over;
return ac;
}
// ============================================================================
// WET OBSIDIAN TILED FLOOR SDF & SURFACE ATTRIBUTES
// ============================================================================
struct FloorInfo {
float grout; // 1 in grout seam, 0 on stone face
float bevel; // beveled edge profile
float wetness; // 0 = damp stone, 1 = glossy mirror puddle
float tileId; // per-tile hash
float microBump; // fine basalt texture
float height; // surface height displacement
};
FloorInfo evalFloorInfo(vec2 xz) {
// Rotate tiles ~34 deg for dramatic diagonal perspective like the ref
vec2 uv = rot2(0.59) * xz;
float tileScale = 0.92;
vec2 g = uv / tileScale;
vec2 id = floor(g);
vec2 f = fract(g) - 0.5;
vec2 af = abs(f);
float tileHash = hash21(id);
// Grout seam distance
float edgeDist = 0.5 - max(af.x, af.y);
float grout = 1.0 - smoothstep(0.010, 0.024, edgeDist);
float bevel = smoothstep(0.012, 0.052, edgeDist);
// Subtle organic puddle mask (large wet pools + pooling near seams)
float puddleNoise = fbm2(xz * 0.72 + vec2(2.4, -1.7));
float puddleDetail = fbm2(xz * 2.15 + vec2(-5.1, 3.3));
float wet = smoothstep(0.36, 0.64, puddleNoise * 0.78 + puddleDetail * 0.22 + 0.12 * (1.0 - bevel));
// Extra sheen near center arena where the slash strikes
float centerWet = exp(-dot(xz - vec2(0.4, 0.5), xz - vec2(0.4, 0.5)) * 0.22);
wet = clamp(wet + 0.25 * centerWet, 0.0, 1.0);
// Fine basalt/obsidian stone grain (damped inside puddles)
float grain = fbm2(uv * 9.5 + tileHash * 13.7) * 0.65 + vnoise2(uv * 24.0) * 0.35;
float perTileH = (tileHash - 0.5) * 0.005;
FloorInfo fi;
fi.grout = grout;
fi.bevel = bevel;
fi.wetness = wet;
fi.tileId = tileHash;
fi.microBump = grain;
fi.height = perTileH - grout * 0.016 - (1.0 - bevel) * 0.005 + (grain - 0.5) * 0.004 * (1.0 - wet * 0.85);
return fi;
}
float sdFloor(vec3 p) {
FloorInfo fi = evalFloorInfo(p.xz);
return p.y - fi.height;
}
// ============================================================================
// SOLID SCULPTED ARCANE CRESCENT BLADE, COLLAR & RIBBON CORE SDF
// Material IDs:
// 1.0 = Wet obsidian floor
// 2.0 = Blazing crescent blade tip (s < 0.185)
// 3.0 = Ornate golden arcane crossguard / collar (s ~ 0.185)
// 4.0 = Sculpted cyan-to-cobalt energy blade & ribbon core (s > 0.185)
// ============================================================================
vec2 mapScene(vec3 p) {
// 1. Wet obsidian floor
float dFloor = sdFloor(p);
vec2 res = vec2(dFloor, 1.0);
// Quick bounding sphere cull around the arc
if (length(p - ARC_CENTER) > 2.25) {
return res;
}
ArcCoord ac = evalArcCoord(p);
float s = ac.s;
float openW = 1.0 + 0.32 * clamp(uOpen, 0.0, 1.0);
// 2. Sculpted crescent blade & swept ribbon core (s in [0.0, 0.86])
// Width profile along s:
float tipTaper = pow(smoothstep(0.0, 0.16, s), 0.72);
float collarPinch = 1.0 - 0.25 * exp(-pow((s - 0.185) / 0.025, 2.0));
float bodyWidth = mix(0.115, 0.075, smoothstep(0.18, 0.65, s)) * openW;
float tailTaper = smoothstep(0.90, 0.55, s);
float halfW = bodyWidth * tipTaper * collarPinch * tailTaper;
halfW = max(halfW, 0.001);
// Thickness profile (diamond beveled blade cross-section)
float halfT = mix(0.024, 0.010, smoothstep(0.18, 0.75, s)) * tipTaper * tailTaper;
halfT = max(halfT, 0.001);
// Bank/roll the blade slightly so the cutting edge leans outward dynamically
float bank = mix(0.32, 0.55, smoothstep(0.18, 0.70, s));
vec2 cs = rot2(bank) * vec2(ac.dr, ac.dy);
// Diamond-bevel blade cross-section SDF (sharp leading edge + fuller groove)
float dDiamond = (abs(cs.x) / halfW + abs(cs.y) / halfT - 1.0) * min(halfW, halfT) * 0.72;
// Fuller ridge along the blade spine (s in 0.18..0.52)
float fullerMask = smoothstep(0.17, 0.22, s) * smoothstep(0.55, 0.38, s);
float fuller = exp(-pow(cs.x / (halfW * 0.28 + 1e-4), 2.0)) * 0.004 * fullerMask;
dDiamond -= fuller;
// Combine with endcap distance (over)
float dBlade = length(vec2(max(dDiamond, 0.0), ac.over)) + min(dDiamond, 0.0);
// Bound tail cleanly
dBlade = max(dBlade, (ac.sRaw - 0.88) * ARC_SPAN * 1.1);
float bladeMat = (s < 0.185) ? 2.0 : 4.0;
if (dBlade < res.x) {
res = vec2(dBlade, bladeMat);
}
// 3. Ornate sculpted golden arcane crossguard / collar at s = 0.188
float sCollar = 0.188;
float dsCol = (ac.sRaw - sCollar) * ARC_SPAN * arcRadius(sCollar);
if (abs(dsCol) < 0.28 && abs(ac.dr) < 0.35 && abs(ac.dy) < 0.25) {
vec2 c2 = rot2(0.32) * vec2(ac.dr, ac.dy);
// Central sculpted octagonal collar ring around the blade
float dCollarCore = length(vec3(dsCol * 1.35, c2.x * 0.92, c2.y * 1.65)) - 0.068;
// Curved S-guard quillon wings flaring outward on both sides of the blade
float wingSpan = abs(c2.x);
float wingCurve = dsCol - 0.055 * sin(c2.x * 9.5) - 0.03 * wingSpan;
float wingR = mix(0.026, 0.010, smoothstep(0.04, 0.19, wingSpan));
float dWings = length(vec2(wingCurve, c2.y * 1.35)) - wingR;
dWings = max(dWings, wingSpan - 0.195);
// Finial buds at tips of the crossguard wings
float dFinial = length(vec3(dsCol - 0.04 * sign(c2.x), abs(c2.x) - 0.195, c2.y)) - 0.022;
float dCollar = smin(dCollarCore, dWings, 0.022);
dCollar = smin(dCollar, dFinial, 0.015);
if (dCollar < res.x) {
res = vec2(dCollar, 3.0);
}
}
return res;
}
// Unit-weight tetrahedral normal (zero-bug rule)
vec3 calcNormal(vec3 p) {
const float eps = 0.0012;
const vec2 k = vec2(1.0, -1.0);
return normalize(
k.xyy * mapScene(p + k.xyy * eps).x +
k.yyx * mapScene(p + k.yyx * eps).x +
k.yxy * mapScene(p + k.yxy * eps).x +
k.xxx * mapScene(p + k.xxx * eps).x
);
}
// Analytic perturbed wet-floor normal for crisp tile bevels & basalt grain
vec3 calcFloorNormal(vec3 p, FloorInfo fi) {
const float e = 0.003;
float hx = evalFloorInfo(p.xz + vec2(e, 0.0)).height - fi.height;
float hz = evalFloorInfo(p.xz + vec2(0.0, e)).height - fi.height;
// Slight puddle surface tension smoothing
float flatScale = mix(1.0, 0.22, fi.wetness * fi.bevel);
vec3 n = normalize(vec3(-hx * flatScale, e, -hz * flatScale));
return n;
}
// ============================================================================
// PROCEDURAL ARCANE RUNE GLYPHS (4-point diamond star, hourglass sigil, ring)
// ============================================================================
float sdSegment2(vec2 p, vec2 a, vec2 b) {
vec2 pa = p - a, ba = b - a;
float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-6), 0.0, 1.0);
return length(pa - ba * h);
}
float evalRuneGlyph(vec2 uv, int type) {
// uv in [-1, 1]
float d = 10.0;
if (type == 0) {
// 4-point concave arcane diamond star
vec2 a = abs(uv);
float star = abs(pow(max(a.x, 1e-4), 0.62) + pow(max(a.y, 1e-4), 0.62) - 0.72);
d = star * 0.48;
// Inner dot
d = min(d, length(uv) - 0.09);
} else if (type == 1) {
// Hourglass / Gemini arcane sigil (matches ref runes!)
float topBar = sdSegment2(uv, vec2(-0.55, 0.58), vec2(0.55, 0.58));
float botBar = sdSegment2(uv, vec2(-0.55, -0.58), vec2(0.55, -0.58));
float leftCurve = abs(uv.x + 0.34 - 0.16 * uv.y * uv.y);
leftCurve = max(leftCurve, abs(uv.y) - 0.58);
float rightCurve = abs(uv.x - 0.34 + 0.16 * uv.y * uv.y);
rightCurve = max(rightCurve, abs(uv.y) - 0.58);
float midBar = sdSegment2(uv, vec2(-0.22, 0.0), vec2(0.22, 0.0));
d = min(min(topBar, botBar), min(min(leftCurve, rightCurve), midBar));
} else {
// Ringed crescent rune
float ring = abs(length(uv) - 0.50);
float crossV = sdSegment2(uv, vec2(0.0, -0.72), vec2(0.0, 0.72));
float crossH = sdSegment2(uv, vec2(-0.62, 0.12), vec2(0.62, 0.12));
d = min(ring, min(crossV, crossH));
}
return smoothstep(0.11, 0.025, d);
}
// ============================================================================
// VOLUMETRIC ARCANE ENERGY SWEEP + WISPY FILAMENTS + SPARKS + RUNES
// Used for BOTH primary camera rays and real-time wet-floor reflection rays!
// ============================================================================
vec3 evalVolumetricVFX(vec3 ro, vec3 rd, float tMax, int steps, bool isRefl) {
if (uLightMode == 1) {
return vec3(0.0); // Pure neutral clay mode: mute emission
}
// Bounding sphere intersection around ARC_CENTER (radius 2.15)
vec3 oc = ro - ARC_CENTER;
float b = dot(oc, rd);
float c = dot(oc, oc) - 2.15 * 2.15;
float disc = b * b - c;
if (disc < 0.0) return vec3(0.0);
float sq = sqrt(disc);
float t0 = max(0.02, -b - sq);
float t1 = min(tMax, -b + sq);
if (t1 <= t0) return vec3(0.0);
float phase = loopPhase();
float openAmt = clamp(uOpen, 0.0, 1.0);
float widthBoost = 1.0 + 0.45 * openAmt;
float emberBoost = 1.0 + 0.65 * openAmt;
// Slight blue-noise-like jitter to eliminate banding
float jitter = hash21(pfx_frag_xy + (isRefl ? vec2(37.0, 19.0) : vec2(0.0)));
float dt = (t1 - t0) / float(steps);
float t = t0 + dt * jitter;
vec3 accum = vec3(0.0);
for (int i = 0; i < 56; i++) {
if (i >= steps) break;
vec3 p = ro + rd * t;
// Skip below floor on primary ray
if (!isRefl && p.y < 0.0) {
t += dt;
continue;
}
ArcCoord ac = evalArcCoord(p);
float s = ac.s;
// Distance from the ribbon envelope
float ribbonW = mix(0.22, 0.34, smoothstep(0.15, 0.72, s)) * widthBoost;
ribbonW *= smoothstep(0.0, 0.06, s) * smoothstep(1.0, 0.78, s);
float ribbonH = mix(0.11, 0.19, smoothstep(0.15, 0.72, s)) * widthBoost;
float bank = mix(0.32, 0.55, smoothstep(0.18, 0.70, s));
vec2 cs = rot2(bank) * vec2(ac.dr, ac.dy);
// Quick spatial skip when far from arc tube
float quickR2 = cs.x * cs.x + cs.y * cs.y + ac.over * ac.over;
if (quickR2 < 0.42) {
// 1. Volumetric turbulent energy sweep
vec3 flowCoord = vec3(s * 7.5, cs.x * 4.5, cs.y * 5.0);
float turb = periodicTurb3(flowCoord, vec3(-3.2, 0.9, 0.6), phase);
float turb2 = periodicTurb3(flowCoord * 1.9 + vec3(4.1, 1.7, 2.3), vec3(-5.0, -1.2, 0.8), phase);
// Wispy displacement of the ribbon cross-section
vec2 wcs = cs;
wcs.x += (turb - 0.5) * 0.20 * smoothstep(0.12, 0.45, s);
wcs.y += (turb2 - 0.5) * 0.14 * smoothstep(0.10, 0.45, s);
float ellip = (wcs.x * wcs.x) / max(ribbonW * ribbonW, 1e-4)
+ (wcs.y * wcs.y) / max(ribbonH * ribbonH, 1e-4)
+ (ac.over * ac.over) * 18.0;
float env = exp(-ellip * 2.2);
float wisps = smoothstep(0.28, 0.82, turb * 0.65 + turb2 * 0.35);
float volDens = env * (0.35 + 1.15 * wisps);
// Color palette transition along the sweeping arc:
// Tip (0..0.18): White-gold core -> Warm arcane gold
// Mid (0.18..0.44): Luminous cyan
// Sweep (0.44..1.0): Deep cobalt -> indigo wisps
vec3 cTip = mix(COL_CORE, COL_GOLD, smoothstep(0.04, 0.22, ellip));
vec3 cMid = mix(COL_CYAN, COL_COBALT, smoothstep(0.22, 0.54, s));
vec3 cTail = mix(COL_COBALT, vec3(0.04, 0.12, 0.55), smoothstep(0.68, 1.0, s));
vec3 energyCol = mix(cTip, cMid, smoothstep(0.14, 0.24, s));
energyCol = mix(energyCol, cTail, smoothstep(0.48, 0.78, s));
// Bright hot core glow around the blazing front-right crescent blade tip
float tipGlow = exp(-(cs.x * cs.x * 36.0 + cs.y * cs.y * 55.0 + ac.over * ac.over * 45.0))
* smoothstep(0.24, 0.02, s) * smoothstep(-0.02, 0.03, ac.sRaw);
vec3 tipAura = mix(COL_GOLD, COL_CORE, clamp(tipGlow * 1.4, 0.0, 1.0)) * tipGlow * 2.6;
// Golden surge burst right around the ornate crossguard collar
float collarBurst = exp(-((ac.sRaw - 0.175) * (ac.sRaw - 0.175) * 260.0 + cs.x * cs.x * 26.0 + cs.y * cs.y * 32.0));
tipAura += mix(COL_GOLD, COL_CORE, 0.55) * collarBurst * (2.4 * emberBoost);
// 2. Crackling electric energy vein along the spine (s in [0.22, 0.88])
float veinMask = smoothstep(0.20, 0.28, s) * smoothstep(0.90, 0.72, s);
float jx = (vnoise2(vec2(s * 24.0 - phase * 6.0, 3.1)) - 0.5) * 0.085
+ (vnoise2(vec2(s * 52.0 - phase * 12.0, 9.7)) - 0.5) * 0.035;
float jy = (vnoise2(vec2(s * 26.0 - phase * 6.0, 11.4)) - 0.5) * 0.055;
float dVein = length(vec2(cs.x - jx, cs.y - jy));
float vein = exp(-dVein * dVein * 2800.0) * veinMask;
float veinHalo = exp(-dVein * dVein * 260.0) * veinMask * 0.45;
vec3 veinCol = mix(COL_CYAN, vec3(0.82, 0.94, 1.0), 0.72) * (vein * 3.8 + veinHalo);
// 3. Swirling golden embers & sparkling motes in the wake (3D cellular grid in arc space)
vec3 sparkCoord = vec3(s * 22.0 - phase * 2.0, ac.dr * 13.0, ac.dy * 13.0);
vec3 sid = floor(sparkCoord);
vec3 sf = fract(sparkCoord) - 0.5;
float sh = hash31(sid);
float sparkEnv = exp(-(ac.dr * ac.dr * 5.2 + ac.dy * ac.dy * 10.5 + ac.over * ac.over * 12.0));
// Denser golden spark spray near the blazing tip & collar
float tipSparkBoost = 1.0 + 2.2 * exp(-pow((s - 0.14) / 0.14, 2.0));
float sparkThresh = mix(0.76, 0.62, openAmt);
vec3 sparkCol = vec3(0.0);
if (sh > sparkThresh && sparkEnv > 0.04) {
vec3 jitterP = vec3(
hash31(sid + 1.3) - 0.5,
hash31(sid + 2.7) - 0.5,
hash31(sid + 4.1) - 0.5
) * 0.68;
float sd = length(sf - jitterP);
float twinkle = 0.55 + 0.45 * sin(TAU * (phase + sh * 3.0));
float pt = exp(-sd * sd * 135.0) * twinkle * sparkEnv * tipSparkBoost;
sparkCol = mix(COL_GOLD, COL_CORE, smoothstep(0.84, 0.98, sh)) * pt * (3.6 * emberBoost);
}
// Combine volumetric contribution
float ribbonGain = isRefl ? 1.55 : 1.35;
accum += (energyCol * volDens * ribbonGain + tipAura + veinCol + sparkCol) * dt;
}
t += dt;
}
// 4. Crisp floating golden arcane rune motes along the outer wake
// Evaluate 12 curated rune billboards analytically along the ray (ultra-crisp!)
int runeCount = isRefl ? 8 : 12;
for (int i = 0; i < 12; i++) {
if (i >= runeCount) break;
float fi = float(i);
float sBase = mix(0.08, 0.90, fi / 11.0);
// Gentle periodic drift along the arc & subtle bobbing
float drift = 0.018 * sin(TAU * (phase + fi * 0.17));
float sR = clamp(sBase + drift, 0.04, 0.94);
vec3 center = arcPointWorld(sR);
// Offset slightly outside the arc ribbon & slightly above/below
vec3 ax, ay, az;
getArcBasis(ax, ay, az);
float theta = ARC_START + slashAnimOffset() + sR * ARC_SPAN;
vec3 radDir = ax * cos(theta) + az * sin(theta);
float side = (mod(fi, 2.0) < 0.5) ? 1.0 : -0.55;
float rOff = mix(0.24, 0.36, hash11(fi * 3.7 + 1.1)) * side;
float yOff = (hash11(fi * 5.3 + 2.1) - 0.42) * 0.18 + 0.025 * cos(TAU * (phase + fi * 0.23));
vec3 runePos = center + radDir * rOff + ay * yOff;
runePos.y = max(runePos.y, 0.09);
// Intersect ray with camera-facing / floor-tilted rune disc
vec3 rNorm = normalize(mix(-rd, vec3(0.0, 1.0, 0.0), 0.25));
float denom = dot(rd, rNorm);
if (abs(denom) > 1e-4) {
float tHit = dot(runePos - ro, rNorm) / denom;
if (tHit > 0.05 && tHit < tMax) {
vec3 hitP = ro + rd * tHit;
vec3 dP = hitP - runePos;
float size = mix(0.058, 0.082, hash11(fi * 7.1 + 0.5)) * (1.0 + 0.18 * openAmt);
if (dot(dP, dP) < size * size * 1.45) {
vec3 uDir = normalize(cross(vec3(0.0, 1.0, 0.0), rNorm));
vec3 vDir = cross(rNorm, uDir);
vec2 ruv = vec2(dot(dP, uDir), dot(dP, vDir)) / size;
ruv = rot2(0.35 * sin(TAU * phase + fi)) * ruv;
int rType = int(mod(fi, 3.0));
float glyph = evalRuneGlyph(ruv, rType);
float halo = exp(-dot(ruv, ruv) * 2.2) * 0.22;
float pulse = 0.72 + 0.28 * sin(TAU * (phase + fi * 0.31));
float fade = smoothstep(0.95, 0.70, sR);
vec3 rCol = mix(COL_GOLD, COL_CORE, glyph * 0.65) * (glyph * 2.4 + halo) * pulse * fade * emberBoost;
accum += rCol * (isRefl ? 0.78 : 1.0);
}
}
}
}
return accum;
}
// ============================================================================
// PBR LIGHTING & STUDIO ENVIRONMENT
// ============================================================================
float D_GGX(float NoH, float rough) {
float a = max(rough * rough, 0.002);
float a2 = a * a;
float d = NoH * NoH * (a2 - 1.0) + 1.0;
return a2 / max(PI * d * d, 1e-6);
}
float G_SchlickGGX(float NoV, float NoL, float rough) {
float r = rough + 1.0;
float k = (r * r) / 8.0;
float gv = NoV / max(NoV * (1.0 - k) + k, 1e-5);
float gl = NoL / max(NoL * (1.0 - k) + k, 1e-5);
return gv * gl;
}
vec3 F_Schlick(float cosTheta, vec3 F0) {
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
}
vec3 evalLightPBR(vec3 N, vec3 V, vec3 L, vec3 lightCol, vec3 albedo, float rough, float metal) {
float NoL = max(dot(N, L), 0.0);
if (NoL <= 0.0) return vec3(0.0);
float NoV = max(dot(N, V), 1e-4);
vec3 H = normalize(V + L);
float NoH = max(dot(N, H), 0.0);
float VoH = max(dot(V, H), 0.0);
vec3 F0 = mix(vec3(0.04), albedo, metal);
vec3 F = F_Schlick(VoH, F0);
float D = D_GGX(NoH, rough);
float G = G_SchlickGGX(NoV, NoL, rough);
vec3 spec = (D * G * F) / max(4.0 * NoV * NoL, 1e-4);
vec3 kD = (1.0 - F) * (1.0 - metal);
vec3 diff = kD * albedo / PI;
return (diff + spec) * lightCol * NoL;
}
// Soft studio environment sky/softbox reflection for obsidian wet tiles & metal
vec3 evalStudioEnv(vec3 dir, int lightMode) {
float y = clamp(dir.y, 0.0, 1.0);
if (lightMode == 1) {
// Pure neutral studio softbox
float softbox = smoothstep(0.35, 0.85, dot(dir, normalize(vec3(0.35, 0.78, 0.52))));
float rimBox = smoothstep(0.45, 0.90, dot(dir, normalize(vec3(-0.65, 0.55, -0.52))));
float v = mix(0.14, 0.34, y) + 0.55 * softbox + 0.25 * rimBox;
return vec3(v);
}
// Dark obsidian studio ceiling with moody cool-slate overhead rim softboxes
// (gives crisp silvery-blue puddle highlights while keeping obsidian dark #0B0E12)
vec3 base = mix(COL_OBSIDIAN * 0.42, vec3(0.032, 0.052, 0.105), pow(y, 0.72));
// Overhead cool slate studio strip lights
float strip1 = smoothstep(0.52, 0.94, dot(dir, normalize(vec3(0.28, 0.62, -0.73))));
float strip2 = smoothstep(0.60, 0.95, dot(dir, normalize(vec3(-0.55, 0.48, -0.68))));
float strip3 = smoothstep(0.50, 0.90, dot(dir, normalize(vec3(0.75, 0.35, -0.55))));
vec3 skyCol = base
+ vec3(0.22, 0.32, 0.48) * strip1 * 0.55
+ vec3(0.12, 0.21, 0.38) * strip2 * 0.42
+ vec3(0.16, 0.25, 0.40) * strip3 * 0.36;
if (lightMode == 2) {
// Grazing mode: boost low-angle cool-gold rim
float graze = smoothstep(0.58, 0.96, dot(dir, normalize(vec3(0.82, 0.20, -0.52))));
skyCol += vec3(0.38, 0.44, 0.58) * graze;
} else if (lightMode == 3) {
// Backlit mode: crisp studio backlight behind the arc without washing out darks
float back = smoothstep(0.45, 0.92, dot(dir, normalize(vec3(-0.15, 0.35, -0.92))));
skyCol += mix(COL_CYAN, vec3(0.65, 0.80, 0.98), 0.50) * back * 0.78;
}
return skyCol;
}
// ============================================================================
// RAYMARCHING & SHADING
// ============================================================================
vec2 raymarch(vec3 ro, vec3 rd, float tMax) {
float t = 0.02;
for (int i = 0; i < 96; i++) {
vec3 p = ro + rd * t;
vec2 h = mapScene(p);
if (h.x < 0.0012 * (1.0 + t * 0.25)) {
return vec2(t, h.y);
}
t += clamp(h.x * 0.85, 0.004, 0.25);
if (t > tMax) break;
}
return vec2(-1.0, 0.0);
}
// Analytical arcane area lights distributed along the sweeping slash arc
// to cast rich cyan/cobalt/gold light spill & specular highlights onto the wet floor.
vec3 evalArcaneSpill(vec3 p, vec3 N, vec3 V, vec3 albedo, float rough, float metal) {
if (uLightMode == 1) return vec3(0.0);
float openBoost = 1.0 + 0.35 * clamp(uOpen, 0.0, 1.0);
vec3 total = vec3(0.0);
// 6 weighted point emitters along the sweeping slash
const float sPos[6] = float[6](0.06, 0.16, 0.28, 0.44, 0.62, 0.80);
for (int i = 0; i < 6; i++) {
float s = sPos[i];
vec3 lPos = arcPointWorld(s);
vec3 toL = lPos - p;
float d2 = dot(toL, toL) + 0.08;
float dist = sqrt(d2);
vec3 L = toL / dist;
vec3 lCol;
float power;
if (i == 0) {
lCol = mix(COL_CORE, COL_GOLD, 0.35);
power = 2.6 * openBoost;
} else if (i == 1) {
lCol = COL_GOLD;
power = 2.2 * openBoost;
} else if (i == 2) {
lCol = COL_CYAN;
power = 1.8 * openBoost;
} else if (i == 3) {
lCol = mix(COL_CYAN, COL_COBALT, 0.55);
power = 1.45 * openBoost;
} else if (i == 4) {
lCol = COL_COBALT;
power = 1.15 * openBoost;
} else {
lCol = COL_COBALT * 0.85;
power = 0.75 * openBoost;
}
float atten = power / (d2 + 0.18 * dist);
total += evalLightPBR(N, V, L, lCol * atten, albedo, rough, metal);
}
return total;
}
vec3 shadeHit(vec3 p, vec3 rd, float matId, float tHit) {
vec3 V = -rd;
vec3 N = calcNormal(p);
bool neutral = (uLightMode == 1);
// Primary studio directional light setup per uLightMode
vec3 keyDir, keyCol, rimDir, rimCol;
if (uLightMode == 1) {
keyDir = normalize(vec3(0.55, 0.78, 0.45));
keyCol = vec3(1.55);
rimDir = normalize(vec3(-0.65, 0.48, -0.58));
rimCol = vec3(0.65);
} else if (uLightMode == 2) {
// Grazing mode
keyDir = normalize(vec3(0.86, 0.16, 0.48));
keyCol = vec3(0.65, 0.74, 0.92) * 0.95;
rimDir = normalize(vec3(-0.78, 0.22, -0.58));
rimCol = vec3(0.62, 0.52, 0.40) * 0.65;
} else if (uLightMode == 3) {
// Backlit mode
keyDir = normalize(vec3(-0.20, 0.42, -0.88));
keyCol = vec3(0.38, 0.60, 0.88) * 1.10;
rimDir = normalize(vec3(0.65, 0.35, -0.68));
rimCol = COL_GOLD * 0.60;
} else {
// Hero mode: moody cool-slate studio overhead fill so dark obsidian tiles read with high contrast
keyDir = normalize(vec3(0.35, 0.82, -0.45));
keyCol = vec3(0.16, 0.23, 0.36) * 0.78;
rimDir = normalize(vec3(-0.62, 0.52, -0.58));
rimCol = vec3(0.12, 0.20, 0.34) * 0.55;
}
vec3 col = vec3(0.0);
if (matId < 1.5) {
// --------------------------------------------------------------------
// MATERIAL 1: Wet Obsidian Tiled Arena Floor
// --------------------------------------------------------------------
FloorInfo fi = evalFloorInfo(p.xz);
N = calcFloorNormal(p, fi);
vec3 baseObsidian = COL_OBSIDIAN * 0.42 * (0.86 + 0.34 * fi.microBump + 0.16 * (fi.tileId - 0.5));
baseObsidian = mix(baseObsidian, COL_OBSIDIAN * 0.18, fi.grout);
// Darken wet stone slightly (physically accurate wet porosity)
baseObsidian *= mix(1.0, 0.68, fi.wetness);
vec3 albedo = neutral
? vec3(mix(0.34, 0.44, fi.microBump) * mix(1.0, 0.55, fi.grout))
: baseObsidian;
float rough = mix(0.34, 0.052, fi.wetness * fi.bevel);
rough = mix(rough, 0.68, fi.grout);
if (neutral) rough = mix(0.42, 0.16, fi.wetness * fi.bevel);
// Studio key & rim
col += evalLightPBR(N, V, keyDir, keyCol, albedo, rough, 0.0);
col += evalLightPBR(N, V, rimDir, rimCol, albedo, rough, 0.0);
// Controlled ambient bounce: deep #0B0E12 obsidian floor without dead-black crush
vec3 ambCol = neutral ? vec3(0.16) : vec3(0.022, 0.032, 0.062);
col += albedo * ambCol * (0.8 + 0.4 * fi.bevel);
// Arcane VFX light spill across the wet tiles
col += evalArcaneSpill(p, N, V, albedo, rough, 0.0);
// Real-time glossy specular reflection of studio + sweeping arcane VFX!
vec3 R = reflect(-V, N);
R.y = max(R.y, 0.01);
float NoV = max(dot(N, V), 1e-4);
vec3 F0 = vec3(mix(0.04, 0.085, fi.wetness));
vec3 fresnel = F_Schlick(NoV, F0);
float reflGloss = mix(0.22, 1.0, pow(1.0 - rough, 1.5)) * (1.0 - fi.grout * 0.78);
vec3 envRefl = evalStudioEnv(R, uLightMode);
vec3 vfxRefl = vec3(0.0);
if (!neutral) {
// Secondary volumetric + rune reflection ray off the wet puddle!
vfxRefl = evalVolumetricVFX(p + N * 0.012, R, 5.5, 26, true);
// Boost crispness inside glossy wet puddles
vfxRefl *= mix(0.55, 1.40, fi.wetness);
}
// Fresnel-weighted reflection (rich VFX mirror reflections, restrained studio sky)
vec3 reflWeight = mix(fresnel, vec3(0.32), fi.wetness * 0.36) * reflGloss;
col += envRefl * reflWeight * 0.56 + vfxRefl * reflGloss * (0.52 + 0.60 * fresnel);
} else if (matId < 2.5) {
// --------------------------------------------------------------------
// MATERIAL 2: Sculpted Blazing White-Gold Crescent Blade Tip
// --------------------------------------------------------------------
ArcCoord ac = evalArcCoord(p);
vec3 albedo = neutral ? vec3(0.68) : COL_CORE;
float rough = neutral ? 0.24 : 0.14;
float metal = neutral ? 0.15 : 0.35;
col += evalLightPBR(N, V, keyDir, keyCol, albedo, rough, metal);
col += evalLightPBR(N, V, rimDir, rimCol, albedo, rough, metal);
col += albedo * (neutral ? vec3(0.20) : vec3(0.12));
if (!neutral) {
float NoV = clamp(dot(N, V), 0.0, 1.0);
float rim = pow(1.0 - NoV, 2.0);
// White-gold hot core with warm arcane gold grazing edge & subtle cyan ice sheen
vec3 bladeGlow = mix(COL_CORE * 2.4, COL_GOLD * 1.9, rim * 0.65);
bladeGlow = mix(bladeGlow, mix(COL_CORE, COL_CYAN, 0.35) * 2.2, smoothstep(0.12, 0.02, ac.s) * 0.35);
// Extra heat right near the collar junction
float collarHeat = exp(-pow((ac.s - 0.17) / 0.055, 2.0));
bladeGlow += COL_GOLD * collarHeat * 1.4;
col += bladeGlow;
}
} else if (matId < 3.5) {
// --------------------------------------------------------------------
// MATERIAL 3: Ornate Sculpted Golden Arcane Crossguard / Collar
// --------------------------------------------------------------------
vec3 goldAlbedo = vec3(0.96, 0.72, 0.26);
vec3 albedo = neutral ? vec3(0.56) : goldAlbedo;
float rough = neutral ? 0.28 : 0.22;
float metal = neutral ? 0.15 : 0.92;
col += evalLightPBR(N, V, keyDir, keyCol * 1.35, albedo, rough, metal);
col += evalLightPBR(N, V, rimDir, rimCol * 1.25, albedo, rough, metal);
col += evalArcaneSpill(p, N, V, albedo, rough, metal);
vec3 R = reflect(-V, N);
col += evalStudioEnv(R, uLightMode) * albedo * (neutral ? 0.22 : 0.65);
if (!neutral) {
// Subtle warm emissive bounce from adjacent blazing blade
float NoV = clamp(dot(N, V), 0.0, 1.0);
col += COL_GOLD * (0.28 + 0.55 * pow(1.0 - NoV, 2.5));
}
} else {
// --------------------------------------------------------------------
// MATERIAL 4: Sculpted Luminous Cyan-to-Cobalt Blade & Ribbon Core
// --------------------------------------------------------------------
ArcCoord ac = evalArcCoord(p);
float s = ac.s;
vec3 baseCol = mix(COL_CYAN, COL_COBALT, smoothstep(0.22, 0.54, s));
vec3 albedo = neutral ? vec3(0.60) : baseCol;
float rough = neutral ? 0.26 : 0.16;
float metal = neutral ? 0.10 : 0.45;
col += evalLightPBR(N, V, keyDir, keyCol, albedo, rough, metal);
col += evalLightPBR(N, V, rimDir, rimCol, albedo, rough, metal);
col += albedo * (neutral ? vec3(0.18) : vec3(0.10));
if (!neutral) {
float NoV = clamp(dot(N, V), 0.0, 1.0);
float fres = pow(1.0 - NoV, 2.2);
float tailFade = smoothstep(0.88, 0.35, s);
// Intense cyan near collar, transitioning into deep cobalt with bright electric bevel rim
vec3 coreGlow = mix(COL_CYAN * 1.75, COL_COBALT * 1.35, smoothstep(0.22, 0.52, s));
coreGlow += mix(COL_CORE, COL_CYAN, 0.55) * fres * 1.25;
// Subtle flowing energy striations along the blade fuller
float stripe = 0.75 + 0.25 * sin(s * 38.0 - loopPhase() * TAU * 2.0);
col += coreGlow * tailFade * stripe;
}
}
// Subtle distance atmospheric perspective on the wet arena floor
float fogAmt = 1.0 - exp(-tHit * tHit * 0.015);
vec3 fogCol = neutral ? vec3(0.16) : (COL_OBSIDIAN * 0.46);
col = mix(col, fogCol, clamp(fogAmt, 0.0, 0.65));
return col;
}
// ============================================================================
// CAMERA & ACES FILMIC TONE MAPPING
// ============================================================================
vec3 acesToneMap(vec3 x) {
// Controlled soft-shoulder rolloff before ACES to prevent >1% clipping
x = max(x, vec3(0.0));
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
return clamp((x * (a * x + b)) / max(x * (c * x + d) + e, vec3(1e-5)), 0.0, 1.0);
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 uv = (pfx_frag_xy - 0.5 * uResolution.xy) / max(uResolution.y, 1.0);
// Camera framing:
// uCamMode == 0 : Hero 3/4 high-angle cinematic view matching 01.png (full arc inside frame)
// uCamMode == 1 : ~2.5x Macro close-up on blazing crescent tip, golden collar & wet reflection
vec3 ro, ta;
float fov;
if (uCamMode == 1) {
ro = vec3(0.92, 0.96, 1.88);
ta = vec3(0.68, 0.28, 0.56);
fov = 1.85;
} else {
ro = vec3(0.18, 2.38, 3.65);
ta = vec3(-0.04, 0.50, 0.02);
fov = 1.48;
}
vec3 cw = normalize(ta - ro);
vec3 cu = normalize(cross(cw, vec3(0.0, 1.0, 0.0)));
vec3 cv = cross(cu, cw);
vec3 rd = normalize(uv.x * cu + uv.y * cv + fov * cw);
float tMax = 18.0;
vec2 hit = raymarch(ro, rd, tMax);
vec3 col;
float volMaxT = tMax;
if (hit.x > 0.0) {
vec3 p = ro + rd * hit.x;
col = shadeHit(p, rd, hit.y, hit.x);
volMaxT = hit.x;
} else {
col = evalStudioEnv(rd, uLightMode);
}
// Primary volumetric VFX sweep, wispy filaments, electric vein, sparks & runes
vec3 vfx = evalVolumetricVFX(ro, rd, volMaxT, 48, false);
col += vfx;
// Gentle exposure & controlled cinematic vignette (kept mild so corners never crush to black)
float exposure = (uLightMode == 1) ? 1.05 : 1.08;
col *= exposure;
float vig = 1.0 - 0.16 * dot(uv, uv);
col *= clamp(vig, 0.78, 1.0);
// ACES Filmic Tone Mapping
col = acesToneMap(col);
// Enforce pure neutral grayscale in uLightMode == 1
if (uLightMode == 1) {
float lum = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(lum);
}
// sRGB gamma encode
col = pow(max(col, vec3(0.0)), vec3(1.0 / 2.2));
fragColor = vec4(col, 1.0);
}
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;
// Arcane Slash Arc — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/vfx_palette/lib/01_arcane_slash_arc.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;
// ============================================================================
// 01_arcane_slash_arc.glsl
// Sweeping 3D crescent arcane sword-slash ribbon above a dark wet tiled
// obsidian arena floor.
// Unified Arcane Palette:
// Obsidian floor : vec3(0.03, 0.05, 0.12)
// Deep cobalt : vec3(0.08, 0.32, 0.98)
// Luminous cyan : vec3(0.10, 0.85, 1.00)
// Warm gold : vec3(1.00, 0.68, 0.18)
// White-gold core: vec3(1.00, 0.96, 0.86)
// ============================================================================
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
const vec3 COL_OBSIDIAN = vec3(0.03, 0.05, 0.12);
const vec3 COL_COBALT = vec3(0.08, 0.32, 0.98);
const vec3 COL_CYAN = vec3(0.10, 0.85, 1.00);
const vec3 COL_GOLD = vec3(1.00, 0.68, 0.18);
const vec3 COL_CORE = vec3(1.00, 0.96, 0.86);
// Smooth 3-second loop phase in [0, 1)
float loopPhase() {
return fract(uTime / 3.0);
}
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
float hash11(float p) {
p = fract(p * 0.1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
float hash21(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
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 hash31(vec3 p3) {
p3 = fract(p3 * 0.1031);
p3 += dot(p3, p3.zyx + 31.32);
return fract((p3.x + p3.y) * p3.z);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}
float vnoise3(vec3 p) {
vec3 i = floor(p);
vec3 f = fract(p);
vec3 u = f * f * (3.0 - 2.0 * f);
float n000 = hash31(i + vec3(0.0, 0.0, 0.0));
float n100 = hash31(i + vec3(1.0, 0.0, 0.0));
float n010 = hash31(i + vec3(0.0, 1.0, 0.0));
float n110 = hash31(i + vec3(1.0, 1.0, 0.0));
float n001 = hash31(i + vec3(0.0, 0.0, 1.0));
float n101 = hash31(i + vec3(1.0, 0.0, 1.0));
float n011 = hash31(i + vec3(0.0, 1.0, 1.0));
float n111 = hash31(i + vec3(1.0, 1.0, 1.0));
float nx00 = mix(n000, n100, u.x);
float nx10 = mix(n010, n110, u.x);
float nx01 = mix(n001, n101, u.x);
float nx11 = mix(n011, n111, u.x);
return mix(mix(nx00, nx10, u.y), mix(nx01, nx11, u.y), u.z);
}
float fbm2(vec2 p) {
float v = 0.0;
float a = 0.5;
mat2 m = mat2(0.8, 0.6, -0.6, 0.8);
for (int i = 0; i < 4; i++) {
v += a * vnoise2(p);
p = m * p * 2.03 + vec2(17.1, 31.7);
a *= 0.5;
}
return v;
}
float fbm3(vec3 p) {
float v = 0.0;
float a = 0.5;
for (int i = 0; i < 3; i++) {
v += a * vnoise3(p);
p = p * 2.07 + vec3(11.3, 23.7, 7.1);
a *= 0.5;
}
return v;
}
// Smooth periodic 3D turbulence using two time-blended scrolling layers
// so the 3-second loop is 100% seamless.
float periodicTurb3(vec3 p, vec3 flow, float phase) {
float p0 = fract(phase);
float p1 = fract(phase + 0.5);
float w0 = 1.0 - abs(2.0 * p0 - 1.0);
float w1 = 1.0 - w0;
float n0 = fbm3(p + flow * p0);
float n1 = fbm3(p + flow * p1 + vec3(19.3, 7.7, 13.1));
return n0 * w0 + n1 * w1;
}
float smin(float a, float b, float k) {
float h = clamp(0.5 + 0.5 * (b - a) / max(k, 1e-4), 0.0, 1.0);
return mix(b, a, h) - k * h * (1.0 - h);
}
// ============================================================================
// ARC COORDINATE FRAME
// Sweeps in a tilted 3D plane above the wet obsidian floor (y = 0):
// s = 0.0 : blazing white-gold crescent tip (front-right, low over floor)
// s = 0.19 : ornate golden arcane crossguard/collar
// s = 0.19..0.46 : sculpted luminous cyan-to-cobalt blade body
// s = 0.46..1.00 : sweeping cobalt volumetric energy ribbon tapering to tail
// ============================================================================
const vec3 ARC_CENTER = vec3(-0.02, 0.78, -0.06);
void getArcBasis(out vec3 ax, out vec3 ay, out vec3 az) {
// Tilt arc plane so front-right (+X, +Z) dips close to the wet floor
// and back-left (-X, -Z) rises gracefully into the dark studio space.
ay = normalize(vec3(0.22, 0.90, 0.37));
ax = normalize(cross(ay, vec3(0.0, 0.0, 1.0)));
az = normalize(cross(ax, ay));
}
vec3 worldToArc(vec3 p) {
vec3 ax, ay, az;
getArcBasis(ax, ay, az);
vec3 d = p - ARC_CENTER;
return vec3(dot(d, ax), dot(d, ay), dot(d, az));
}
vec3 arcToWorld(vec3 q) {
vec3 ax, ay, az;
getArcBasis(ax, ay, az);
return ARC_CENTER + ax * q.x + ay * q.y + az * q.z;
}
// Arc angular span:
// thetaStart (tip, s=0) = +0.25 rad (front-right, curving slightly up-right)
// thetaEnd (tail, s=1) = +0.25 + 4.25 rad (~245 deg dramatic crescent sweep)
const float ARC_START = 0.25;
const float ARC_SPAN = 4.25;
// Nominal spiral radius along s in [0, 1]
float arcRadius(float s) {
// Slight graceful scimitar spiral with gentle inward hook at the crescent tip
float r = 1.18 - 0.12 * s;
// Tip flares gently outward then hooks sharp
float tipCurve = smoothstep(0.22, 0.0, s);
r += 0.07 * tipCurve * (1.0 - 0.85 * tipCurve);
return r;
}
// Subtle 3s breathing/sweeping motion offset in arc angle
float slashAnimOffset() {
float ph = loopPhase();
return 0.06 * sin(TAU * ph);
}
// Evaluate world position on the arc centerline for parameter s in [0, 1]
vec3 arcPointWorld(float s) {
float theta = ARC_START + slashAnimOffset() + s * ARC_SPAN;
float r = arcRadius(s);
// Slight vertical wave along the ribbon so it feels dynamically swept in 3D
float lift = 0.04 * sin(s * PI * 1.5) - 0.06 * smoothstep(0.25, 0.0, s);
// Subtle upward flick right at the crescent blade tip
lift += 0.10 * pow(clamp(1.0 - s / 0.14, 0.0, 1.0), 2.2);
vec3 q = vec3(r * cos(theta), lift, r * sin(theta));
return arcToWorld(q);
}
// Given world point p, return:
// s : normalized arc parameter in [0, 1] (clamped)
// dr : signed radial offset from centerline (positive = outer edge)
// dy : signed normal offset from arc ribbon surface
// over: how far outside [0, 1] in arc-length units the angle fell
struct ArcCoord {
float s;
float sRaw;
float dr;
float dy;
float over;
};
ArcCoord evalArcCoord(vec3 p) {
vec3 q = worldToArc(p);
float r = length(q.xz);
float ang = atan(q.z, q.x); // [-PI, PI]
float a0 = ARC_START + slashAnimOffset();
// Unwrap angle relative to a0 into [-0.65, TAU - 0.65]
float dAng = mod(ang - a0 + 0.65, TAU) - 0.65;
float sRaw = dAng / ARC_SPAN;
float s = clamp(sRaw, 0.0, 1.0);
float r0 = arcRadius(s);
float lift = 0.04 * sin(s * PI * 1.5) - 0.06 * smoothstep(0.25, 0.0, s);
lift += 0.10 * pow(clamp(1.0 - s / 0.14, 0.0, 1.0), 2.2);
float over = 0.0;
if (sRaw < 0.0) over = -sRaw * ARC_SPAN * r0;
else if (sRaw > 1.0) over = (sRaw - 1.0) * ARC_SPAN * r0;
ArcCoord ac;
ac.s = s;
ac.sRaw = sRaw;
ac.dr = r - r0;
ac.dy = q.y - lift;
ac.over = over;
return ac;
}
// ============================================================================
// WET OBSIDIAN TILED FLOOR SDF & SURFACE ATTRIBUTES
// ============================================================================
struct FloorInfo {
float grout; // 1 in grout seam, 0 on stone face
float bevel; // beveled edge profile
float wetness; // 0 = damp stone, 1 = glossy mirror puddle
float tileId; // per-tile hash
float microBump; // fine basalt texture
float height; // surface height displacement
};
FloorInfo evalFloorInfo(vec2 xz) {
// Rotate tiles ~34 deg for dramatic diagonal perspective like the ref
vec2 uv = rot2(0.59) * xz;
float tileScale = 0.92;
vec2 g = uv / tileScale;
vec2 id = floor(g);
vec2 f = fract(g) - 0.5;
vec2 af = abs(f);
float tileHash = hash21(id);
// Grout seam distance
float edgeDist = 0.5 - max(af.x, af.y);
float grout = 1.0 - smoothstep(0.010, 0.024, edgeDist);
float bevel = smoothstep(0.012, 0.052, edgeDist);
// Subtle organic puddle mask (large wet pools + pooling near seams)
float puddleNoise = fbm2(xz * 0.72 + vec2(2.4, -1.7));
float puddleDetail = fbm2(xz * 2.15 + vec2(-5.1, 3.3));
float wet = smoothstep(0.36, 0.64, puddleNoise * 0.78 + puddleDetail * 0.22 + 0.12 * (1.0 - bevel));
// Extra sheen near center arena where the slash strikes
float centerWet = exp(-dot(xz - vec2(0.4, 0.5), xz - vec2(0.4, 0.5)) * 0.22);
wet = clamp(wet + 0.25 * centerWet, 0.0, 1.0);
// Fine basalt/obsidian stone grain (damped inside puddles)
float grain = fbm2(uv * 9.5 + tileHash * 13.7) * 0.65 + vnoise2(uv * 24.0) * 0.35;
float perTileH = (tileHash - 0.5) * 0.005;
FloorInfo fi;
fi.grout = grout;
fi.bevel = bevel;
fi.wetness = wet;
fi.tileId = tileHash;
fi.microBump = grain;
fi.height = perTileH - grout * 0.016 - (1.0 - bevel) * 0.005 + (grain - 0.5) * 0.004 * (1.0 - wet * 0.85);
return fi;
}
float sdFloor(vec3 p) {
FloorInfo fi = evalFloorInfo(p.xz);
return p.y - fi.height;
}
// ============================================================================
// SOLID SCULPTED ARCANE CRESCENT BLADE, COLLAR & RIBBON CORE SDF
// Material IDs:
// 1.0 = Wet obsidian floor
// 2.0 = Blazing crescent blade tip (s < 0.185)
// 3.0 = Ornate golden arcane crossguard / collar (s ~ 0.185)
// 4.0 = Sculpted cyan-to-cobalt energy blade & ribbon core (s > 0.185)
// ============================================================================
vec2 mapScene(vec3 p) {
// 1. Wet obsidian floor
float dFloor = sdFloor(p);
vec2 res = vec2(dFloor, 1.0);
// Quick bounding sphere cull around the arc
if (length(p - ARC_CENTER) > 2.25) {
return res;
}
ArcCoord ac = evalArcCoord(p);
float s = ac.s;
float openW = 1.0 + 0.32 * clamp(uOpen, 0.0, 1.0);
// 2. Sculpted crescent blade & swept ribbon core (s in [0.0, 0.86])
// Width profile along s:
float tipTaper = pow(smoothstep(0.0, 0.16, s), 0.72);
float collarPinch = 1.0 - 0.25 * exp(-pow((s - 0.185) / 0.025, 2.0));
float bodyWidth = mix(0.115, 0.075, smoothstep(0.18, 0.65, s)) * openW;
float tailTaper = smoothstep(0.90, 0.55, s);
float halfW = bodyWidth * tipTaper * collarPinch * tailTaper;
halfW = max(halfW, 0.001);
// Thickness profile (diamond beveled blade cross-section)
float halfT = mix(0.024, 0.010, smoothstep(0.18, 0.75, s)) * tipTaper * tailTaper;
halfT = max(halfT, 0.001);
// Bank/roll the blade slightly so the cutting edge leans outward dynamically
float bank = mix(0.32, 0.55, smoothstep(0.18, 0.70, s));
vec2 cs = rot2(bank) * vec2(ac.dr, ac.dy);
// Diamond-bevel blade cross-section SDF (sharp leading edge + fuller groove)
float dDiamond = (abs(cs.x) / halfW + abs(cs.y) / halfT - 1.0) * min(halfW, halfT) * 0.72;
// Fuller ridge along the blade spine (s in 0.18..0.52)
float fullerMask = smoothstep(0.17, 0.22, s) * smoothstep(0.55, 0.38, s);
float fuller = exp(-pow(cs.x / (halfW * 0.28 + 1e-4), 2.0)) * 0.004 * fullerMask;
dDiamond -= fuller;
// Combine with endcap distance (over)
float dBlade = length(vec2(max(dDiamond, 0.0), ac.over)) + min(dDiamond, 0.0);
// Bound tail cleanly
dBlade = max(dBlade, (ac.sRaw - 0.88) * ARC_SPAN * 1.1);
float bladeMat = (s < 0.185) ? 2.0 : 4.0;
if (dBlade < res.x) {
res = vec2(dBlade, bladeMat);
}
// 3. Ornate sculpted golden arcane crossguard / collar at s = 0.188
float sCollar = 0.188;
float dsCol = (ac.sRaw - sCollar) * ARC_SPAN * arcRadius(sCollar);
if (abs(dsCol) < 0.28 && abs(ac.dr) < 0.35 && abs(ac.dy) < 0.25) {
vec2 c2 = rot2(0.32) * vec2(ac.dr, ac.dy);
// Central sculpted octagonal collar ring around the blade
float dCollarCore = length(vec3(dsCol * 1.35, c2.x * 0.92, c2.y * 1.65)) - 0.068;
// Curved S-guard quillon wings flaring outward on both sides of the blade
float wingSpan = abs(c2.x);
float wingCurve = dsCol - 0.055 * sin(c2.x * 9.5) - 0.03 * wingSpan;
float wingR = mix(0.026, 0.010, smoothstep(0.04, 0.19, wingSpan));
float dWings = length(vec2(wingCurve, c2.y * 1.35)) - wingR;
dWings = max(dWings, wingSpan - 0.195);
// Finial buds at tips of the crossguard wings
float dFinial = length(vec3(dsCol - 0.04 * sign(c2.x), abs(c2.x) - 0.195, c2.y)) - 0.022;
float dCollar = smin(dCollarCore, dWings, 0.022);
dCollar = smin(dCollar, dFinial, 0.015);
if (dCollar < res.x) {
res = vec2(dCollar, 3.0);
}
}
return res;
}
// Unit-weight tetrahedral normal (zero-bug rule)
vec3 calcNormal(vec3 p) {
const float eps = 0.0012;
const vec2 k = vec2(1.0, -1.0);
return normalize(
k.xyy * mapScene(p + k.xyy * eps).x +
k.yyx * mapScene(p + k.yyx * eps).x +
k.yxy * mapScene(p + k.yxy * eps).x +
k.xxx * mapScene(p + k.xxx * eps).x
);
}
// Analytic perturbed wet-floor normal for crisp tile bevels & basalt grain
vec3 calcFloorNormal(vec3 p, FloorInfo fi) {
const float e = 0.003;
float hx = evalFloorInfo(p.xz + vec2(e, 0.0)).height - fi.height;
float hz = evalFloorInfo(p.xz + vec2(0.0, e)).height - fi.height;
// Slight puddle surface tension smoothing
float flatScale = mix(1.0, 0.22, fi.wetness * fi.bevel);
vec3 n = normalize(vec3(-hx * flatScale, e, -hz * flatScale));
return n;
}
// ============================================================================
// PROCEDURAL ARCANE RUNE GLYPHS (4-point diamond star, hourglass sigil, ring)
// ============================================================================
float sdSegment2(vec2 p, vec2 a, vec2 b) {
vec2 pa = p - a, ba = b - a;
float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-6), 0.0, 1.0);
return length(pa - ba * h);
}
float evalRuneGlyph(vec2 uv, int type) {
// uv in [-1, 1]
float d = 10.0;
if (type == 0) {
// 4-point concave arcane diamond star
vec2 a = abs(uv);
float star = abs(pow(max(a.x, 1e-4), 0.62) + pow(max(a.y, 1e-4), 0.62) - 0.72);
d = star * 0.48;
// Inner dot
d = min(d, length(uv) - 0.09);
} else if (type == 1) {
// Hourglass / Gemini arcane sigil (matches ref runes!)
float topBar = sdSegment2(uv, vec2(-0.55, 0.58), vec2(0.55, 0.58));
float botBar = sdSegment2(uv, vec2(-0.55, -0.58), vec2(0.55, -0.58));
float leftCurve = abs(uv.x + 0.34 - 0.16 * uv.y * uv.y);
leftCurve = max(leftCurve, abs(uv.y) - 0.58);
float rightCurve = abs(uv.x - 0.34 + 0.16 * uv.y * uv.y);
rightCurve = max(rightCurve, abs(uv.y) - 0.58);
float midBar = sdSegment2(uv, vec2(-0.22, 0.0), vec2(0.22, 0.0));
d = min(min(topBar, botBar), min(min(leftCurve, rightCurve), midBar));
} else {
// Ringed crescent rune
float ring = abs(length(uv) - 0.50);
float crossV = sdSegment2(uv, vec2(0.0, -0.72), vec2(0.0, 0.72));
float crossH = sdSegment2(uv, vec2(-0.62, 0.12), vec2(0.62, 0.12));
d = min(ring, min(crossV, crossH));
}
return smoothstep(0.11, 0.025, d);
}
// ============================================================================
// VOLUMETRIC ARCANE ENERGY SWEEP + WISPY FILAMENTS + SPARKS + RUNES
// Used for BOTH primary camera rays and real-time wet-floor reflection rays!
// ============================================================================
vec3 evalVolumetricVFX(vec3 ro, vec3 rd, float tMax, int steps, bool isRefl) {
if (uLightMode == 1) {
return vec3(0.0); // Pure neutral clay mode: mute emission
}
// Bounding sphere intersection around ARC_CENTER (radius 2.15)
vec3 oc = ro - ARC_CENTER;
float b = dot(oc, rd);
float c = dot(oc, oc) - 2.15 * 2.15;
float disc = b * b - c;
if (disc < 0.0) return vec3(0.0);
float sq = sqrt(disc);
float t0 = max(0.02, -b - sq);
float t1 = min(tMax, -b + sq);
if (t1 <= t0) return vec3(0.0);
float phase = loopPhase();
float openAmt = clamp(uOpen, 0.0, 1.0);
float widthBoost = 1.0 + 0.45 * openAmt;
float emberBoost = 1.0 + 0.65 * openAmt;
// Slight blue-noise-like jitter to eliminate banding
float jitter = hash21(pfx_frag_xy + (isRefl ? vec2(37.0, 19.0) : vec2(0.0)));
float dt = (t1 - t0) / float(steps);
float t = t0 + dt * jitter;
vec3 accum = vec3(0.0);
for (int i = 0; i < 56; i++) {
if (i >= steps) break;
vec3 p = ro + rd * t;
// Skip below floor on primary ray
if (!isRefl && p.y < 0.0) {
t += dt;
continue;
}
ArcCoord ac = evalArcCoord(p);
float s = ac.s;
// Distance from the ribbon envelope
float ribbonW = mix(0.22, 0.34, smoothstep(0.15, 0.72, s)) * widthBoost;
ribbonW *= smoothstep(0.0, 0.06, s) * smoothstep(1.0, 0.78, s);
float ribbonH = mix(0.11, 0.19, smoothstep(0.15, 0.72, s)) * widthBoost;
float bank = mix(0.32, 0.55, smoothstep(0.18, 0.70, s));
vec2 cs = rot2(bank) * vec2(ac.dr, ac.dy);
// Quick spatial skip when far from arc tube
float quickR2 = cs.x * cs.x + cs.y * cs.y + ac.over * ac.over;
if (quickR2 < 0.42) {
// 1. Volumetric turbulent energy sweep
vec3 flowCoord = vec3(s * 7.5, cs.x * 4.5, cs.y * 5.0);
float turb = periodicTurb3(flowCoord, vec3(-3.2, 0.9, 0.6), phase);
float turb2 = periodicTurb3(flowCoord * 1.9 + vec3(4.1, 1.7, 2.3), vec3(-5.0, -1.2, 0.8), phase);
// Wispy displacement of the ribbon cross-section
vec2 wcs = cs;
wcs.x += (turb - 0.5) * 0.20 * smoothstep(0.12, 0.45, s);
wcs.y += (turb2 - 0.5) * 0.14 * smoothstep(0.10, 0.45, s);
float ellip = (wcs.x * wcs.x) / max(ribbonW * ribbonW, 1e-4)
+ (wcs.y * wcs.y) / max(ribbonH * ribbonH, 1e-4)
+ (ac.over * ac.over) * 18.0;
float env = exp(-ellip * 2.2);
float wisps = smoothstep(0.28, 0.82, turb * 0.65 + turb2 * 0.35);
float volDens = env * (0.35 + 1.15 * wisps);
// Color palette transition along the sweeping arc:
// Tip (0..0.18): White-gold core -> Warm arcane gold
// Mid (0.18..0.44): Luminous cyan
// Sweep (0.44..1.0): Deep cobalt -> indigo wisps
vec3 cTip = mix(COL_CORE, COL_GOLD, smoothstep(0.04, 0.22, ellip));
vec3 cMid = mix(COL_CYAN, COL_COBALT, smoothstep(0.22, 0.54, s));
vec3 cTail = mix(COL_COBALT, vec3(0.04, 0.12, 0.55), smoothstep(0.68, 1.0, s));
vec3 energyCol = mix(cTip, cMid, smoothstep(0.14, 0.24, s));
energyCol = mix(energyCol, cTail, smoothstep(0.48, 0.78, s));
// Bright hot core glow around the blazing front-right crescent blade tip
float tipGlow = exp(-(cs.x * cs.x * 36.0 + cs.y * cs.y * 55.0 + ac.over * ac.over * 45.0))
* smoothstep(0.24, 0.02, s) * smoothstep(-0.02, 0.03, ac.sRaw);
vec3 tipAura = mix(COL_GOLD, COL_CORE, clamp(tipGlow * 1.4, 0.0, 1.0)) * tipGlow * 2.6;
// Golden surge burst right around the ornate crossguard collar
float collarBurst = exp(-((ac.sRaw - 0.175) * (ac.sRaw - 0.175) * 260.0 + cs.x * cs.x * 26.0 + cs.y * cs.y * 32.0));
tipAura += mix(COL_GOLD, COL_CORE, 0.55) * collarBurst * (2.4 * emberBoost);
// 2. Crackling electric energy vein along the spine (s in [0.22, 0.88])
float veinMask = smoothstep(0.20, 0.28, s) * smoothstep(0.90, 0.72, s);
float jx = (vnoise2(vec2(s * 24.0 - phase * 6.0, 3.1)) - 0.5) * 0.085
+ (vnoise2(vec2(s * 52.0 - phase * 12.0, 9.7)) - 0.5) * 0.035;
float jy = (vnoise2(vec2(s * 26.0 - phase * 6.0, 11.4)) - 0.5) * 0.055;
float dVein = length(vec2(cs.x - jx, cs.y - jy));
float vein = exp(-dVein * dVein * 2800.0) * veinMask;
float veinHalo = exp(-dVein * dVein * 260.0) * veinMask * 0.45;
vec3 veinCol = mix(COL_CYAN, vec3(0.82, 0.94, 1.0), 0.72) * (vein * 3.8 + veinHalo);
// 3. Swirling golden embers & sparkling motes in the wake (3D cellular grid in arc space)
vec3 sparkCoord = vec3(s * 22.0 - phase * 2.0, ac.dr * 13.0, ac.dy * 13.0);
vec3 sid = floor(sparkCoord);
vec3 sf = fract(sparkCoord) - 0.5;
float sh = hash31(sid);
float sparkEnv = exp(-(ac.dr * ac.dr * 5.2 + ac.dy * ac.dy * 10.5 + ac.over * ac.over * 12.0));
// Denser golden spark spray near the blazing tip & collar
float tipSparkBoost = 1.0 + 2.2 * exp(-pow((s - 0.14) / 0.14, 2.0));
float sparkThresh = mix(0.76, 0.62, openAmt);
vec3 sparkCol = vec3(0.0);
if (sh > sparkThresh && sparkEnv > 0.04) {
vec3 jitterP = vec3(
hash31(sid + 1.3) - 0.5,
hash31(sid + 2.7) - 0.5,
hash31(sid + 4.1) - 0.5
) * 0.68;
float sd = length(sf - jitterP);
float twinkle = 0.55 + 0.45 * sin(TAU * (phase + sh * 3.0));
float pt = exp(-sd * sd * 135.0) * twinkle * sparkEnv * tipSparkBoost;
sparkCol = mix(COL_GOLD, COL_CORE, smoothstep(0.84, 0.98, sh)) * pt * (3.6 * emberBoost);
}
// Combine volumetric contribution
float ribbonGain = isRefl ? 1.55 : 1.35;
accum += (energyCol * volDens * ribbonGain + tipAura + veinCol + sparkCol) * dt;
}
t += dt;
}
// 4. Crisp floating golden arcane rune motes along the outer wake
// Evaluate 12 curated rune billboards analytically along the ray (ultra-crisp!)
int runeCount = isRefl ? 8 : 12;
for (int i = 0; i < 12; i++) {
if (i >= runeCount) break;
float fi = float(i);
float sBase = mix(0.08, 0.90, fi / 11.0);
// Gentle periodic drift along the arc & subtle bobbing
float drift = 0.018 * sin(TAU * (phase + fi * 0.17));
float sR = clamp(sBase + drift, 0.04, 0.94);
vec3 center = arcPointWorld(sR);
// Offset slightly outside the arc ribbon & slightly above/below
vec3 ax, ay, az;
getArcBasis(ax, ay, az);
float theta = ARC_START + slashAnimOffset() + sR * ARC_SPAN;
vec3 radDir = ax * cos(theta) + az * sin(theta);
float side = (mod(fi, 2.0) < 0.5) ? 1.0 : -0.55;
float rOff = mix(0.24, 0.36, hash11(fi * 3.7 + 1.1)) * side;
float yOff = (hash11(fi * 5.3 + 2.1) - 0.42) * 0.18 + 0.025 * cos(TAU * (phase + fi * 0.23));
vec3 runePos = center + radDir * rOff + ay * yOff;
runePos.y = max(runePos.y, 0.09);
// Intersect ray with camera-facing / floor-tilted rune disc
vec3 rNorm = normalize(mix(-rd, vec3(0.0, 1.0, 0.0), 0.25));
float denom = dot(rd, rNorm);
if (abs(denom) > 1e-4) {
float tHit = dot(runePos - ro, rNorm) / denom;
if (tHit > 0.05 && tHit < tMax) {
vec3 hitP = ro + rd * tHit;
vec3 dP = hitP - runePos;
float size = mix(0.058, 0.082, hash11(fi * 7.1 + 0.5)) * (1.0 + 0.18 * openAmt);
if (dot(dP, dP) < size * size * 1.45) {
vec3 uDir = normalize(cross(vec3(0.0, 1.0, 0.0), rNorm));
vec3 vDir = cross(rNorm, uDir);
vec2 ruv = vec2(dot(dP, uDir), dot(dP, vDir)) / size;
ruv = rot2(0.35 * sin(TAU * phase + fi)) * ruv;
int rType = int(mod(fi, 3.0));
float glyph = evalRuneGlyph(ruv, rType);
float halo = exp(-dot(ruv, ruv) * 2.2) * 0.22;
float pulse = 0.72 + 0.28 * sin(TAU * (phase + fi * 0.31));
float fade = smoothstep(0.95, 0.70, sR);
vec3 rCol = mix(COL_GOLD, COL_CORE, glyph * 0.65) * (glyph * 2.4 + halo) * pulse * fade * emberBoost;
accum += rCol * (isRefl ? 0.78 : 1.0);
}
}
}
}
return accum;
}
// ============================================================================
// PBR LIGHTING & STUDIO ENVIRONMENT
// ============================================================================
float D_GGX(float NoH, float rough) {
float a = max(rough * rough, 0.002);
float a2 = a * a;
float d = NoH * NoH * (a2 - 1.0) + 1.0;
return a2 / max(PI * d * d, 1e-6);
}
float G_SchlickGGX(float NoV, float NoL, float rough) {
float r = rough + 1.0;
float k = (r * r) / 8.0;
float gv = NoV / max(NoV * (1.0 - k) + k, 1e-5);
float gl = NoL / max(NoL * (1.0 - k) + k, 1e-5);
return gv * gl;
}
vec3 F_Schlick(float cosTheta, vec3 F0) {
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
}
vec3 evalLightPBR(vec3 N, vec3 V, vec3 L, vec3 lightCol, vec3 albedo, float rough, float metal) {
float NoL = max(dot(N, L), 0.0);
if (NoL <= 0.0) return vec3(0.0);
float NoV = max(dot(N, V), 1e-4);
vec3 H = normalize(V + L);
float NoH = max(dot(N, H), 0.0);
float VoH = max(dot(V, H), 0.0);
vec3 F0 = mix(vec3(0.04), albedo, metal);
vec3 F = F_Schlick(VoH, F0);
float D = D_GGX(NoH, rough);
float G = G_SchlickGGX(NoV, NoL, rough);
vec3 spec = (D * G * F) / max(4.0 * NoV * NoL, 1e-4);
vec3 kD = (1.0 - F) * (1.0 - metal);
vec3 diff = kD * albedo / PI;
return (diff + spec) * lightCol * NoL;
}
// Soft studio environment sky/softbox reflection for obsidian wet tiles & metal
vec3 evalStudioEnv(vec3 dir, int lightMode) {
float y = clamp(dir.y, 0.0, 1.0);
if (lightMode == 1) {
// Pure neutral studio softbox
float softbox = smoothstep(0.35, 0.85, dot(dir, normalize(vec3(0.35, 0.78, 0.52))));
float rimBox = smoothstep(0.45, 0.90, dot(dir, normalize(vec3(-0.65, 0.55, -0.52))));
float v = mix(0.14, 0.34, y) + 0.55 * softbox + 0.25 * rimBox;
return vec3(v);
}
// Dark obsidian studio ceiling with moody cool-slate overhead rim softboxes
// (gives crisp silvery-blue puddle highlights while keeping obsidian dark #0B0E12)
vec3 base = mix(COL_OBSIDIAN * 0.42, vec3(0.032, 0.052, 0.105), pow(y, 0.72));
// Overhead cool slate studio strip lights
float strip1 = smoothstep(0.52, 0.94, dot(dir, normalize(vec3(0.28, 0.62, -0.73))));
float strip2 = smoothstep(0.60, 0.95, dot(dir, normalize(vec3(-0.55, 0.48, -0.68))));
float strip3 = smoothstep(0.50, 0.90, dot(dir, normalize(vec3(0.75, 0.35, -0.55))));
vec3 skyCol = base
+ vec3(0.22, 0.32, 0.48) * strip1 * 0.55
+ vec3(0.12, 0.21, 0.38) * strip2 * 0.42
+ vec3(0.16, 0.25, 0.40) * strip3 * 0.36;
if (lightMode == 2) {
// Grazing mode: boost low-angle cool-gold rim
float graze = smoothstep(0.58, 0.96, dot(dir, normalize(vec3(0.82, 0.20, -0.52))));
skyCol += vec3(0.38, 0.44, 0.58) * graze;
} else if (lightMode == 3) {
// Backlit mode: crisp studio backlight behind the arc without washing out darks
float back = smoothstep(0.45, 0.92, dot(dir, normalize(vec3(-0.15, 0.35, -0.92))));
skyCol += mix(COL_CYAN, vec3(0.65, 0.80, 0.98), 0.50) * back * 0.78;
}
return skyCol;
}
// ============================================================================
// RAYMARCHING & SHADING
// ============================================================================
vec2 raymarch(vec3 ro, vec3 rd, float tMax) {
float t = 0.02;
for (int i = 0; i < 96; i++) {
vec3 p = ro + rd * t;
vec2 h = mapScene(p);
if (h.x < 0.0012 * (1.0 + t * 0.25)) {
return vec2(t, h.y);
}
t += clamp(h.x * 0.85, 0.004, 0.25);
if (t > tMax) break;
}
return vec2(-1.0, 0.0);
}
// Analytical arcane area lights distributed along the sweeping slash arc
// to cast rich cyan/cobalt/gold light spill & specular highlights onto the wet floor.
vec3 evalArcaneSpill(vec3 p, vec3 N, vec3 V, vec3 albedo, float rough, float metal) {
if (uLightMode == 1) return vec3(0.0);
float openBoost = 1.0 + 0.35 * clamp(uOpen, 0.0, 1.0);
vec3 total = vec3(0.0);
// 6 weighted point emitters along the sweeping slash
const float sPos[6] = float[6](0.06, 0.16, 0.28, 0.44, 0.62, 0.80);
for (int i = 0; i < 6; i++) {
float s = sPos[i];
vec3 lPos = arcPointWorld(s);
vec3 toL = lPos - p;
float d2 = dot(toL, toL) + 0.08;
float dist = sqrt(d2);
vec3 L = toL / dist;
vec3 lCol;
float power;
if (i == 0) {
lCol = mix(COL_CORE, COL_GOLD, 0.35);
power = 2.6 * openBoost;
} else if (i == 1) {
lCol = COL_GOLD;
power = 2.2 * openBoost;
} else if (i == 2) {
lCol = COL_CYAN;
power = 1.8 * openBoost;
} else if (i == 3) {
lCol = mix(COL_CYAN, COL_COBALT, 0.55);
power = 1.45 * openBoost;
} else if (i == 4) {
lCol = COL_COBALT;
power = 1.15 * openBoost;
} else {
lCol = COL_COBALT * 0.85;
power = 0.75 * openBoost;
}
float atten = power / (d2 + 0.18 * dist);
total += evalLightPBR(N, V, L, lCol * atten, albedo, rough, metal);
}
return total;
}
vec3 shadeHit(vec3 p, vec3 rd, float matId, float tHit) {
vec3 V = -rd;
vec3 N = calcNormal(p);
bool neutral = (uLightMode == 1);
// Primary studio directional light setup per uLightMode
vec3 keyDir, keyCol, rimDir, rimCol;
if (uLightMode == 1) {
keyDir = normalize(vec3(0.55, 0.78, 0.45));
keyCol = vec3(1.55);
rimDir = normalize(vec3(-0.65, 0.48, -0.58));
rimCol = vec3(0.65);
} else if (uLightMode == 2) {
// Grazing mode
keyDir = normalize(vec3(0.86, 0.16, 0.48));
keyCol = vec3(0.65, 0.74, 0.92) * 0.95;
rimDir = normalize(vec3(-0.78, 0.22, -0.58));
rimCol = vec3(0.62, 0.52, 0.40) * 0.65;
} else if (uLightMode == 3) {
// Backlit mode
keyDir = normalize(vec3(-0.20, 0.42, -0.88));
keyCol = vec3(0.38, 0.60, 0.88) * 1.10;
rimDir = normalize(vec3(0.65, 0.35, -0.68));
rimCol = COL_GOLD * 0.60;
} else {
// Hero mode: moody cool-slate studio overhead fill so dark obsidian tiles read with high contrast
keyDir = normalize(vec3(0.35, 0.82, -0.45));
keyCol = vec3(0.16, 0.23, 0.36) * 0.78;
rimDir = normalize(vec3(-0.62, 0.52, -0.58));
rimCol = vec3(0.12, 0.20, 0.34) * 0.55;
}
vec3 col = vec3(0.0);
if (matId < 1.5) {
// --------------------------------------------------------------------
// MATERIAL 1: Wet Obsidian Tiled Arena Floor
// --------------------------------------------------------------------
FloorInfo fi = evalFloorInfo(p.xz);
N = calcFloorNormal(p, fi);
vec3 baseObsidian = COL_OBSIDIAN * 0.42 * (0.86 + 0.34 * fi.microBump + 0.16 * (fi.tileId - 0.5));
baseObsidian = mix(baseObsidian, COL_OBSIDIAN * 0.18, fi.grout);
// Darken wet stone slightly (physically accurate wet porosity)
baseObsidian *= mix(1.0, 0.68, fi.wetness);
vec3 albedo = neutral
? vec3(mix(0.34, 0.44, fi.microBump) * mix(1.0, 0.55, fi.grout))
: baseObsidian;
float rough = mix(0.34, 0.052, fi.wetness * fi.bevel);
rough = mix(rough, 0.68, fi.grout);
if (neutral) rough = mix(0.42, 0.16, fi.wetness * fi.bevel);
// Studio key & rim
col += evalLightPBR(N, V, keyDir, keyCol, albedo, rough, 0.0);
col += evalLightPBR(N, V, rimDir, rimCol, albedo, rough, 0.0);
// Controlled ambient bounce: deep #0B0E12 obsidian floor without dead-black crush
vec3 ambCol = neutral ? vec3(0.16) : vec3(0.022, 0.032, 0.062);
col += albedo * ambCol * (0.8 + 0.4 * fi.bevel);
// Arcane VFX light spill across the wet tiles
col += evalArcaneSpill(p, N, V, albedo, rough, 0.0);
// Real-time glossy specular reflection of studio + sweeping arcane VFX!
vec3 R = reflect(-V, N);
R.y = max(R.y, 0.01);
float NoV = max(dot(N, V), 1e-4);
vec3 F0 = vec3(mix(0.04, 0.085, fi.wetness));
vec3 fresnel = F_Schlick(NoV, F0);
float reflGloss = mix(0.22, 1.0, pow(1.0 - rough, 1.5)) * (1.0 - fi.grout * 0.78);
vec3 envRefl = evalStudioEnv(R, uLightMode);
vec3 vfxRefl = vec3(0.0);
if (!neutral) {
// Secondary volumetric + rune reflection ray off the wet puddle!
vfxRefl = evalVolumetricVFX(p + N * 0.012, R, 5.5, 26, true);
// Boost crispness inside glossy wet puddles
vfxRefl *= mix(0.55, 1.40, fi.wetness);
}
// Fresnel-weighted reflection (rich VFX mirror reflections, restrained studio sky)
vec3 reflWeight = mix(fresnel, vec3(0.32), fi.wetness * 0.36) * reflGloss;
col += envRefl * reflWeight * 0.56 + vfxRefl * reflGloss * (0.52 + 0.60 * fresnel);
} else if (matId < 2.5) {
// --------------------------------------------------------------------
// MATERIAL 2: Sculpted Blazing White-Gold Crescent Blade Tip
// --------------------------------------------------------------------
ArcCoord ac = evalArcCoord(p);
vec3 albedo = neutral ? vec3(0.68) : COL_CORE;
float rough = neutral ? 0.24 : 0.14;
float metal = neutral ? 0.15 : 0.35;
col += evalLightPBR(N, V, keyDir, keyCol, albedo, rough, metal);
col += evalLightPBR(N, V, rimDir, rimCol, albedo, rough, metal);
col += albedo * (neutral ? vec3(0.20) : vec3(0.12));
if (!neutral) {
float NoV = clamp(dot(N, V), 0.0, 1.0);
float rim = pow(1.0 - NoV, 2.0);
// White-gold hot core with warm arcane gold grazing edge & subtle cyan ice sheen
vec3 bladeGlow = mix(COL_CORE * 2.4, COL_GOLD * 1.9, rim * 0.65);
bladeGlow = mix(bladeGlow, mix(COL_CORE, COL_CYAN, 0.35) * 2.2, smoothstep(0.12, 0.02, ac.s) * 0.35);
// Extra heat right near the collar junction
float collarHeat = exp(-pow((ac.s - 0.17) / 0.055, 2.0));
bladeGlow += COL_GOLD * collarHeat * 1.4;
col += bladeGlow;
}
} else if (matId < 3.5) {
// --------------------------------------------------------------------
// MATERIAL 3: Ornate Sculpted Golden Arcane Crossguard / Collar
// --------------------------------------------------------------------
vec3 goldAlbedo = vec3(0.96, 0.72, 0.26);
vec3 albedo = neutral ? vec3(0.56) : goldAlbedo;
float rough = neutral ? 0.28 : 0.22;
float metal = neutral ? 0.15 : 0.92;
col += evalLightPBR(N, V, keyDir, keyCol * 1.35, albedo, rough, metal);
col += evalLightPBR(N, V, rimDir, rimCol * 1.25, albedo, rough, metal);
col += evalArcaneSpill(p, N, V, albedo, rough, metal);
vec3 R = reflect(-V, N);
col += evalStudioEnv(R, uLightMode) * albedo * (neutral ? 0.22 : 0.65);
if (!neutral) {
// Subtle warm emissive bounce from adjacent blazing blade
float NoV = clamp(dot(N, V), 0.0, 1.0);
col += COL_GOLD * (0.28 + 0.55 * pow(1.0 - NoV, 2.5));
}
} else {
// --------------------------------------------------------------------
// MATERIAL 4: Sculpted Luminous Cyan-to-Cobalt Blade & Ribbon Core
// --------------------------------------------------------------------
ArcCoord ac = evalArcCoord(p);
float s = ac.s;
vec3 baseCol = mix(COL_CYAN, COL_COBALT, smoothstep(0.22, 0.54, s));
vec3 albedo = neutral ? vec3(0.60) : baseCol;
float rough = neutral ? 0.26 : 0.16;
float metal = neutral ? 0.10 : 0.45;
col += evalLightPBR(N, V, keyDir, keyCol, albedo, rough, metal);
col += evalLightPBR(N, V, rimDir, rimCol, albedo, rough, metal);
col += albedo * (neutral ? vec3(0.18) : vec3(0.10));
if (!neutral) {
float NoV = clamp(dot(N, V), 0.0, 1.0);
float fres = pow(1.0 - NoV, 2.2);
float tailFade = smoothstep(0.88, 0.35, s);
// Intense cyan near collar, transitioning into deep cobalt with bright electric bevel rim
vec3 coreGlow = mix(COL_CYAN * 1.75, COL_COBALT * 1.35, smoothstep(0.22, 0.52, s));
coreGlow += mix(COL_CORE, COL_CYAN, 0.55) * fres * 1.25;
// Subtle flowing energy striations along the blade fuller
float stripe = 0.75 + 0.25 * sin(s * 38.0 - loopPhase() * TAU * 2.0);
col += coreGlow * tailFade * stripe;
}
}
// Subtle distance atmospheric perspective on the wet arena floor
float fogAmt = 1.0 - exp(-tHit * tHit * 0.015);
vec3 fogCol = neutral ? vec3(0.16) : (COL_OBSIDIAN * 0.46);
col = mix(col, fogCol, clamp(fogAmt, 0.0, 0.65));
return col;
}
// ============================================================================
// CAMERA & ACES FILMIC TONE MAPPING
// ============================================================================
vec3 acesToneMap(vec3 x) {
// Controlled soft-shoulder rolloff before ACES to prevent >1% clipping
x = max(x, vec3(0.0));
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
return clamp((x * (a * x + b)) / max(x * (c * x + d) + e, vec3(1e-5)), 0.0, 1.0);
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 uv = (pfx_frag_xy - 0.5 * uResolution.xy) / max(uResolution.y, 1.0);
// Camera framing:
// uCamMode == 0 : Hero 3/4 high-angle cinematic view matching 01.png (full arc inside frame)
// uCamMode == 1 : ~2.5x Macro close-up on blazing crescent tip, golden collar & wet reflection
vec3 ro, ta;
float fov;
if (uCamMode == 1) {
ro = vec3(0.92, 0.96, 1.88);
ta = vec3(0.68, 0.28, 0.56);
fov = 1.85;
} else {
ro = vec3(0.18, 2.38, 3.65);
ta = vec3(-0.04, 0.50, 0.02);
fov = 1.48;
}
vec3 cw = normalize(ta - ro);
vec3 cu = normalize(cross(cw, vec3(0.0, 1.0, 0.0)));
vec3 cv = cross(cu, cw);
vec3 rd = normalize(uv.x * cu + uv.y * cv + fov * cw);
float tMax = 18.0;
vec2 hit = raymarch(ro, rd, tMax);
vec3 col;
float volMaxT = tMax;
if (hit.x > 0.0) {
vec3 p = ro + rd * hit.x;
col = shadeHit(p, rd, hit.y, hit.x);
volMaxT = hit.x;
} else {
col = evalStudioEnv(rd, uLightMode);
}
// Primary volumetric VFX sweep, wispy filaments, electric vein, sparks & runes
vec3 vfx = evalVolumetricVFX(ro, rd, volMaxT, 48, false);
col += vfx;
// Gentle exposure & controlled cinematic vignette (kept mild so corners never crush to black)
float exposure = (uLightMode == 1) ? 1.05 : 1.08;
col *= exposure;
float vig = 1.0 - 0.16 * dot(uv, uv);
col *= clamp(vig, 0.78, 1.0);
// ACES Filmic Tone Mapping
col = acesToneMap(col);
// Enforce pure neutral grayscale in uLightMode == 1
if (uLightMode == 1) {
float lum = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(lum);
}
// sRGB gamma encode
col = pow(max(col, vec3(0.0)), vec3(1.0 / 2.2));
fragColor = vec4(col, 1.0);
}
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);
}
}
// Arcane Slash Arc — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_palette/lib/01_arcane_slash_arc.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;
// ============================================================================
// 01_arcane_slash_arc.glsl
// Sweeping 3D crescent arcane sword-slash ribbon above a dark wet tiled
// obsidian arena floor.
// Unified Arcane Palette:
// Obsidian floor : vec3(0.03, 0.05, 0.12)
// Deep cobalt : vec3(0.08, 0.32, 0.98)
// Luminous cyan : vec3(0.10, 0.85, 1.00)
// Warm gold : vec3(1.00, 0.68, 0.18)
// White-gold core: vec3(1.00, 0.96, 0.86)
// ============================================================================
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
const vec3 COL_OBSIDIAN = vec3(0.03, 0.05, 0.12);
const vec3 COL_COBALT = vec3(0.08, 0.32, 0.98);
const vec3 COL_CYAN = vec3(0.10, 0.85, 1.00);
const vec3 COL_GOLD = vec3(1.00, 0.68, 0.18);
const vec3 COL_CORE = vec3(1.00, 0.96, 0.86);
// Smooth 3-second loop phase in [0, 1)
float loopPhase() {
return fract(uTime / 3.0);
}
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
float hash11(float p) {
p = fract(p * 0.1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
float hash21(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
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 hash31(vec3 p3) {
p3 = fract(p3 * 0.1031);
p3 += dot(p3, p3.zyx + 31.32);
return fract((p3.x + p3.y) * p3.z);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}
float vnoise3(vec3 p) {
vec3 i = floor(p);
vec3 f = fract(p);
vec3 u = f * f * (3.0 - 2.0 * f);
float n000 = hash31(i + vec3(0.0, 0.0, 0.0));
float n100 = hash31(i + vec3(1.0, 0.0, 0.0));
float n010 = hash31(i + vec3(0.0, 1.0, 0.0));
float n110 = hash31(i + vec3(1.0, 1.0, 0.0));
float n001 = hash31(i + vec3(0.0, 0.0, 1.0));
float n101 = hash31(i + vec3(1.0, 0.0, 1.0));
float n011 = hash31(i + vec3(0.0, 1.0, 1.0));
float n111 = hash31(i + vec3(1.0, 1.0, 1.0));
float nx00 = mix(n000, n100, u.x);
float nx10 = mix(n010, n110, u.x);
float nx01 = mix(n001, n101, u.x);
float nx11 = mix(n011, n111, u.x);
return mix(mix(nx00, nx10, u.y), mix(nx01, nx11, u.y), u.z);
}
float fbm2(vec2 p) {
float v = 0.0;
float a = 0.5;
mat2 m = mat2(0.8, 0.6, -0.6, 0.8);
for (int i = 0; i < 4; i++) {
v += a * vnoise2(p);
p = m * p * 2.03 + vec2(17.1, 31.7);
a *= 0.5;
}
return v;
}
float fbm3(vec3 p) {
float v = 0.0;
float a = 0.5;
for (int i = 0; i < 3; i++) {
v += a * vnoise3(p);
p = p * 2.07 + vec3(11.3, 23.7, 7.1);
a *= 0.5;
}
return v;
}
// Smooth periodic 3D turbulence using two time-blended scrolling layers
// so the 3-second loop is 100% seamless.
float periodicTurb3(vec3 p, vec3 flow, float phase) {
float p0 = fract(phase);
float p1 = fract(phase + 0.5);
float w0 = 1.0 - abs(2.0 * p0 - 1.0);
float w1 = 1.0 - w0;
float n0 = fbm3(p + flow * p0);
float n1 = fbm3(p + flow * p1 + vec3(19.3, 7.7, 13.1));
return n0 * w0 + n1 * w1;
}
float smin(float a, float b, float k) {
float h = clamp(0.5 + 0.5 * (b - a) / max(k, 1e-4), 0.0, 1.0);
return mix(b, a, h) - k * h * (1.0 - h);
}
// ============================================================================
// ARC COORDINATE FRAME
// Sweeps in a tilted 3D plane above the wet obsidian floor (y = 0):
// s = 0.0 : blazing white-gold crescent tip (front-right, low over floor)
// s = 0.19 : ornate golden arcane crossguard/collar
// s = 0.19..0.46 : sculpted luminous cyan-to-cobalt blade body
// s = 0.46..1.00 : sweeping cobalt volumetric energy ribbon tapering to tail
// ============================================================================
const vec3 ARC_CENTER = vec3(-0.02, 0.78, -0.06);
void getArcBasis(out vec3 ax, out vec3 ay, out vec3 az) {
// Tilt arc plane so front-right (+X, +Z) dips close to the wet floor
// and back-left (-X, -Z) rises gracefully into the dark studio space.
ay = normalize(vec3(0.22, 0.90, 0.37));
ax = normalize(cross(ay, vec3(0.0, 0.0, 1.0)));
az = normalize(cross(ax, ay));
}
vec3 worldToArc(vec3 p) {
vec3 ax, ay, az;
getArcBasis(ax, ay, az);
vec3 d = p - ARC_CENTER;
return vec3(dot(d, ax), dot(d, ay), dot(d, az));
}
vec3 arcToWorld(vec3 q) {
vec3 ax, ay, az;
getArcBasis(ax, ay, az);
return ARC_CENTER + ax * q.x + ay * q.y + az * q.z;
}
// Arc angular span:
// thetaStart (tip, s=0) = +0.25 rad (front-right, curving slightly up-right)
// thetaEnd (tail, s=1) = +0.25 + 4.25 rad (~245 deg dramatic crescent sweep)
const float ARC_START = 0.25;
const float ARC_SPAN = 4.25;
// Nominal spiral radius along s in [0, 1]
float arcRadius(float s) {
// Slight graceful scimitar spiral with gentle inward hook at the crescent tip
float r = 1.18 - 0.12 * s;
// Tip flares gently outward then hooks sharp
float tipCurve = smoothstep(0.22, 0.0, s);
r += 0.07 * tipCurve * (1.0 - 0.85 * tipCurve);
return r;
}
// Subtle 3s breathing/sweeping motion offset in arc angle
float slashAnimOffset() {
float ph = loopPhase();
return 0.06 * sin(TAU * ph);
}
// Evaluate world position on the arc centerline for parameter s in [0, 1]
vec3 arcPointWorld(float s) {
float theta = ARC_START + slashAnimOffset() + s * ARC_SPAN;
float r = arcRadius(s);
// Slight vertical wave along the ribbon so it feels dynamically swept in 3D
float lift = 0.04 * sin(s * PI * 1.5) - 0.06 * smoothstep(0.25, 0.0, s);
// Subtle upward flick right at the crescent blade tip
lift += 0.10 * pow(clamp(1.0 - s / 0.14, 0.0, 1.0), 2.2);
vec3 q = vec3(r * cos(theta), lift, r * sin(theta));
return arcToWorld(q);
}
// Given world point p, return:
// s : normalized arc parameter in [0, 1] (clamped)
// dr : signed radial offset from centerline (positive = outer edge)
// dy : signed normal offset from arc ribbon surface
// over: how far outside [0, 1] in arc-length units the angle fell
struct ArcCoord {
float s;
float sRaw;
float dr;
float dy;
float over;
};
ArcCoord evalArcCoord(vec3 p) {
vec3 q = worldToArc(p);
float r = length(q.xz);
float ang = atan(q.z, q.x); // [-PI, PI]
float a0 = ARC_START + slashAnimOffset();
// Unwrap angle relative to a0 into [-0.65, TAU - 0.65]
float dAng = mod(ang - a0 + 0.65, TAU) - 0.65;
float sRaw = dAng / ARC_SPAN;
float s = clamp(sRaw, 0.0, 1.0);
float r0 = arcRadius(s);
float lift = 0.04 * sin(s * PI * 1.5) - 0.06 * smoothstep(0.25, 0.0, s);
lift += 0.10 * pow(clamp(1.0 - s / 0.14, 0.0, 1.0), 2.2);
float over = 0.0;
if (sRaw < 0.0) over = -sRaw * ARC_SPAN * r0;
else if (sRaw > 1.0) over = (sRaw - 1.0) * ARC_SPAN * r0;
ArcCoord ac;
ac.s = s;
ac.sRaw = sRaw;
ac.dr = r - r0;
ac.dy = q.y - lift;
ac.over = over;
return ac;
}
// ============================================================================
// WET OBSIDIAN TILED FLOOR SDF & SURFACE ATTRIBUTES
// ============================================================================
struct FloorInfo {
float grout; // 1 in grout seam, 0 on stone face
float bevel; // beveled edge profile
float wetness; // 0 = damp stone, 1 = glossy mirror puddle
float tileId; // per-tile hash
float microBump; // fine basalt texture
float height; // surface height displacement
};
FloorInfo evalFloorInfo(vec2 xz) {
// Rotate tiles ~34 deg for dramatic diagonal perspective like the ref
vec2 uv = rot2(0.59) * xz;
float tileScale = 0.92;
vec2 g = uv / tileScale;
vec2 id = floor(g);
vec2 f = fract(g) - 0.5;
vec2 af = abs(f);
float tileHash = hash21(id);
// Grout seam distance
float edgeDist = 0.5 - max(af.x, af.y);
float grout = 1.0 - smoothstep(0.010, 0.024, edgeDist);
float bevel = smoothstep(0.012, 0.052, edgeDist);
// Subtle organic puddle mask (large wet pools + pooling near seams)
float puddleNoise = fbm2(xz * 0.72 + vec2(2.4, -1.7));
float puddleDetail = fbm2(xz * 2.15 + vec2(-5.1, 3.3));
float wet = smoothstep(0.36, 0.64, puddleNoise * 0.78 + puddleDetail * 0.22 + 0.12 * (1.0 - bevel));
// Extra sheen near center arena where the slash strikes
float centerWet = exp(-dot(xz - vec2(0.4, 0.5), xz - vec2(0.4, 0.5)) * 0.22);
wet = clamp(wet + 0.25 * centerWet, 0.0, 1.0);
// Fine basalt/obsidian stone grain (damped inside puddles)
float grain = fbm2(uv * 9.5 + tileHash * 13.7) * 0.65 + vnoise2(uv * 24.0) * 0.35;
float perTileH = (tileHash - 0.5) * 0.005;
FloorInfo fi;
fi.grout = grout;
fi.bevel = bevel;
fi.wetness = wet;
fi.tileId = tileHash;
fi.microBump = grain;
fi.height = perTileH - grout * 0.016 - (1.0 - bevel) * 0.005 + (grain - 0.5) * 0.004 * (1.0 - wet * 0.85);
return fi;
}
float sdFloor(vec3 p) {
FloorInfo fi = evalFloorInfo(p.xz);
return p.y - fi.height;
}
// ============================================================================
// SOLID SCULPTED ARCANE CRESCENT BLADE, COLLAR & RIBBON CORE SDF
// Material IDs:
// 1.0 = Wet obsidian floor
// 2.0 = Blazing crescent blade tip (s < 0.185)
// 3.0 = Ornate golden arcane crossguard / collar (s ~ 0.185)
// 4.0 = Sculpted cyan-to-cobalt energy blade & ribbon core (s > 0.185)
// ============================================================================
vec2 mapScene(vec3 p) {
// 1. Wet obsidian floor
float dFloor = sdFloor(p);
vec2 res = vec2(dFloor, 1.0);
// Quick bounding sphere cull around the arc
if (length(p - ARC_CENTER) > 2.25) {
return res;
}
ArcCoord ac = evalArcCoord(p);
float s = ac.s;
float openW = 1.0 + 0.32 * clamp(uOpen, 0.0, 1.0);
// 2. Sculpted crescent blade & swept ribbon core (s in [0.0, 0.86])
// Width profile along s:
float tipTaper = pow(smoothstep(0.0, 0.16, s), 0.72);
float collarPinch = 1.0 - 0.25 * exp(-pow((s - 0.185) / 0.025, 2.0));
float bodyWidth = mix(0.115, 0.075, smoothstep(0.18, 0.65, s)) * openW;
float tailTaper = smoothstep(0.90, 0.55, s);
float halfW = bodyWidth * tipTaper * collarPinch * tailTaper;
halfW = max(halfW, 0.001);
// Thickness profile (diamond beveled blade cross-section)
float halfT = mix(0.024, 0.010, smoothstep(0.18, 0.75, s)) * tipTaper * tailTaper;
halfT = max(halfT, 0.001);
// Bank/roll the blade slightly so the cutting edge leans outward dynamically
float bank = mix(0.32, 0.55, smoothstep(0.18, 0.70, s));
vec2 cs = rot2(bank) * vec2(ac.dr, ac.dy);
// Diamond-bevel blade cross-section SDF (sharp leading edge + fuller groove)
float dDiamond = (abs(cs.x) / halfW + abs(cs.y) / halfT - 1.0) * min(halfW, halfT) * 0.72;
// Fuller ridge along the blade spine (s in 0.18..0.52)
float fullerMask = smoothstep(0.17, 0.22, s) * smoothstep(0.55, 0.38, s);
float fuller = exp(-pow(cs.x / (halfW * 0.28 + 1e-4), 2.0)) * 0.004 * fullerMask;
dDiamond -= fuller;
// Combine with endcap distance (over)
float dBlade = length(vec2(max(dDiamond, 0.0), ac.over)) + min(dDiamond, 0.0);
// Bound tail cleanly
dBlade = max(dBlade, (ac.sRaw - 0.88) * ARC_SPAN * 1.1);
float bladeMat = (s < 0.185) ? 2.0 : 4.0;
if (dBlade < res.x) {
res = vec2(dBlade, bladeMat);
}
// 3. Ornate sculpted golden arcane crossguard / collar at s = 0.188
float sCollar = 0.188;
float dsCol = (ac.sRaw - sCollar) * ARC_SPAN * arcRadius(sCollar);
if (abs(dsCol) < 0.28 && abs(ac.dr) < 0.35 && abs(ac.dy) < 0.25) {
vec2 c2 = rot2(0.32) * vec2(ac.dr, ac.dy);
// Central sculpted octagonal collar ring around the blade
float dCollarCore = length(vec3(dsCol * 1.35, c2.x * 0.92, c2.y * 1.65)) - 0.068;
// Curved S-guard quillon wings flaring outward on both sides of the blade
float wingSpan = abs(c2.x);
float wingCurve = dsCol - 0.055 * sin(c2.x * 9.5) - 0.03 * wingSpan;
float wingR = mix(0.026, 0.010, smoothstep(0.04, 0.19, wingSpan));
float dWings = length(vec2(wingCurve, c2.y * 1.35)) - wingR;
dWings = max(dWings, wingSpan - 0.195);
// Finial buds at tips of the crossguard wings
float dFinial = length(vec3(dsCol - 0.04 * sign(c2.x), abs(c2.x) - 0.195, c2.y)) - 0.022;
float dCollar = smin(dCollarCore, dWings, 0.022);
dCollar = smin(dCollar, dFinial, 0.015);
if (dCollar < res.x) {
res = vec2(dCollar, 3.0);
}
}
return res;
}
// Unit-weight tetrahedral normal (zero-bug rule)
vec3 calcNormal(vec3 p) {
const float eps = 0.0012;
const vec2 k = vec2(1.0, -1.0);
return normalize(
k.xyy * mapScene(p + k.xyy * eps).x +
k.yyx * mapScene(p + k.yyx * eps).x +
k.yxy * mapScene(p + k.yxy * eps).x +
k.xxx * mapScene(p + k.xxx * eps).x
);
}
// Analytic perturbed wet-floor normal for crisp tile bevels & basalt grain
vec3 calcFloorNormal(vec3 p, FloorInfo fi) {
const float e = 0.003;
float hx = evalFloorInfo(p.xz + vec2(e, 0.0)).height - fi.height;
float hz = evalFloorInfo(p.xz + vec2(0.0, e)).height - fi.height;
// Slight puddle surface tension smoothing
float flatScale = mix(1.0, 0.22, fi.wetness * fi.bevel);
vec3 n = normalize(vec3(-hx * flatScale, e, -hz * flatScale));
return n;
}
// ============================================================================
// PROCEDURAL ARCANE RUNE GLYPHS (4-point diamond star, hourglass sigil, ring)
// ============================================================================
float sdSegment2(vec2 p, vec2 a, vec2 b) {
vec2 pa = p - a, ba = b - a;
float h = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-6), 0.0, 1.0);
return length(pa - ba * h);
}
float evalRuneGlyph(vec2 uv, int type) {
// uv in [-1, 1]
float d = 10.0;
if (type == 0) {
// 4-point concave arcane diamond star
vec2 a = abs(uv);
float star = abs(pow(max(a.x, 1e-4), 0.62) + pow(max(a.y, 1e-4), 0.62) - 0.72);
d = star * 0.48;
// Inner dot
d = min(d, length(uv) - 0.09);
} else if (type == 1) {
// Hourglass / Gemini arcane sigil (matches ref runes!)
float topBar = sdSegment2(uv, vec2(-0.55, 0.58), vec2(0.55, 0.58));
float botBar = sdSegment2(uv, vec2(-0.55, -0.58), vec2(0.55, -0.58));
float leftCurve = abs(uv.x + 0.34 - 0.16 * uv.y * uv.y);
leftCurve = max(leftCurve, abs(uv.y) - 0.58);
float rightCurve = abs(uv.x - 0.34 + 0.16 * uv.y * uv.y);
rightCurve = max(rightCurve, abs(uv.y) - 0.58);
float midBar = sdSegment2(uv, vec2(-0.22, 0.0), vec2(0.22, 0.0));
d = min(min(topBar, botBar), min(min(leftCurve, rightCurve), midBar));
} else {
// Ringed crescent rune
float ring = abs(length(uv) - 0.50);
float crossV = sdSegment2(uv, vec2(0.0, -0.72), vec2(0.0, 0.72));
float crossH = sdSegment2(uv, vec2(-0.62, 0.12), vec2(0.62, 0.12));
d = min(ring, min(crossV, crossH));
}
return smoothstep(0.11, 0.025, d);
}
// ============================================================================
// VOLUMETRIC ARCANE ENERGY SWEEP + WISPY FILAMENTS + SPARKS + RUNES
// Used for BOTH primary camera rays and real-time wet-floor reflection rays!
// ============================================================================
vec3 evalVolumetricVFX(vec3 ro, vec3 rd, float tMax, int steps, bool isRefl) {
if (uLightMode == 1) {
return vec3(0.0); // Pure neutral clay mode: mute emission
}
// Bounding sphere intersection around ARC_CENTER (radius 2.15)
vec3 oc = ro - ARC_CENTER;
float b = dot(oc, rd);
float c = dot(oc, oc) - 2.15 * 2.15;
float disc = b * b - c;
if (disc < 0.0) return vec3(0.0);
float sq = sqrt(disc);
float t0 = max(0.02, -b - sq);
float t1 = min(tMax, -b + sq);
if (t1 <= t0) return vec3(0.0);
float phase = loopPhase();
float openAmt = clamp(uOpen, 0.0, 1.0);
float widthBoost = 1.0 + 0.45 * openAmt;
float emberBoost = 1.0 + 0.65 * openAmt;
// Slight blue-noise-like jitter to eliminate banding
float jitter = hash21(gl_FragCoord.xy + (isRefl ? vec2(37.0, 19.0) : vec2(0.0)));
float dt = (t1 - t0) / float(steps);
float t = t0 + dt * jitter;
vec3 accum = vec3(0.0);
for (int i = 0; i < 56; i++) {
if (i >= steps) break;
vec3 p = ro + rd * t;
// Skip below floor on primary ray
if (!isRefl && p.y < 0.0) {
t += dt;
continue;
}
ArcCoord ac = evalArcCoord(p);
float s = ac.s;
// Distance from the ribbon envelope
float ribbonW = mix(0.22, 0.34, smoothstep(0.15, 0.72, s)) * widthBoost;
ribbonW *= smoothstep(0.0, 0.06, s) * smoothstep(1.0, 0.78, s);
float ribbonH = mix(0.11, 0.19, smoothstep(0.15, 0.72, s)) * widthBoost;
float bank = mix(0.32, 0.55, smoothstep(0.18, 0.70, s));
vec2 cs = rot2(bank) * vec2(ac.dr, ac.dy);
// Quick spatial skip when far from arc tube
float quickR2 = cs.x * cs.x + cs.y * cs.y + ac.over * ac.over;
if (quickR2 < 0.42) {
// 1. Volumetric turbulent energy sweep
vec3 flowCoord = vec3(s * 7.5, cs.x * 4.5, cs.y * 5.0);
float turb = periodicTurb3(flowCoord, vec3(-3.2, 0.9, 0.6), phase);
float turb2 = periodicTurb3(flowCoord * 1.9 + vec3(4.1, 1.7, 2.3), vec3(-5.0, -1.2, 0.8), phase);
// Wispy displacement of the ribbon cross-section
vec2 wcs = cs;
wcs.x += (turb - 0.5) * 0.20 * smoothstep(0.12, 0.45, s);
wcs.y += (turb2 - 0.5) * 0.14 * smoothstep(0.10, 0.45, s);
float ellip = (wcs.x * wcs.x) / max(ribbonW * ribbonW, 1e-4)
+ (wcs.y * wcs.y) / max(ribbonH * ribbonH, 1e-4)
+ (ac.over * ac.over) * 18.0;
float env = exp(-ellip * 2.2);
float wisps = smoothstep(0.28, 0.82, turb * 0.65 + turb2 * 0.35);
float volDens = env * (0.35 + 1.15 * wisps);
// Color palette transition along the sweeping arc:
// Tip (0..0.18): White-gold core -> Warm arcane gold
// Mid (0.18..0.44): Luminous cyan
// Sweep (0.44..1.0): Deep cobalt -> indigo wisps
vec3 cTip = mix(COL_CORE, COL_GOLD, smoothstep(0.04, 0.22, ellip));
vec3 cMid = mix(COL_CYAN, COL_COBALT, smoothstep(0.22, 0.54, s));
vec3 cTail = mix(COL_COBALT, vec3(0.04, 0.12, 0.55), smoothstep(0.68, 1.0, s));
vec3 energyCol = mix(cTip, cMid, smoothstep(0.14, 0.24, s));
energyCol = mix(energyCol, cTail, smoothstep(0.48, 0.78, s));
// Bright hot core glow around the blazing front-right crescent blade tip
float tipGlow = exp(-(cs.x * cs.x * 36.0 + cs.y * cs.y * 55.0 + ac.over * ac.over * 45.0))
* smoothstep(0.24, 0.02, s) * smoothstep(-0.02, 0.03, ac.sRaw);
vec3 tipAura = mix(COL_GOLD, COL_CORE, clamp(tipGlow * 1.4, 0.0, 1.0)) * tipGlow * 2.6;
// Golden surge burst right around the ornate crossguard collar
float collarBurst = exp(-((ac.sRaw - 0.175) * (ac.sRaw - 0.175) * 260.0 + cs.x * cs.x * 26.0 + cs.y * cs.y * 32.0));
tipAura += mix(COL_GOLD, COL_CORE, 0.55) * collarBurst * (2.4 * emberBoost);
// 2. Crackling electric energy vein along the spine (s in [0.22, 0.88])
float veinMask = smoothstep(0.20, 0.28, s) * smoothstep(0.90, 0.72, s);
float jx = (vnoise2(vec2(s * 24.0 - phase * 6.0, 3.1)) - 0.5) * 0.085
+ (vnoise2(vec2(s * 52.0 - phase * 12.0, 9.7)) - 0.5) * 0.035;
float jy = (vnoise2(vec2(s * 26.0 - phase * 6.0, 11.4)) - 0.5) * 0.055;
float dVein = length(vec2(cs.x - jx, cs.y - jy));
float vein = exp(-dVein * dVein * 2800.0) * veinMask;
float veinHalo = exp(-dVein * dVein * 260.0) * veinMask * 0.45;
vec3 veinCol = mix(COL_CYAN, vec3(0.82, 0.94, 1.0), 0.72) * (vein * 3.8 + veinHalo);
// 3. Swirling golden embers & sparkling motes in the wake (3D cellular grid in arc space)
vec3 sparkCoord = vec3(s * 22.0 - phase * 2.0, ac.dr * 13.0, ac.dy * 13.0);
vec3 sid = floor(sparkCoord);
vec3 sf = fract(sparkCoord) - 0.5;
float sh = hash31(sid);
float sparkEnv = exp(-(ac.dr * ac.dr * 5.2 + ac.dy * ac.dy * 10.5 + ac.over * ac.over * 12.0));
// Denser golden spark spray near the blazing tip & collar
float tipSparkBoost = 1.0 + 2.2 * exp(-pow((s - 0.14) / 0.14, 2.0));
float sparkThresh = mix(0.76, 0.62, openAmt);
vec3 sparkCol = vec3(0.0);
if (sh > sparkThresh && sparkEnv > 0.04) {
vec3 jitterP = vec3(
hash31(sid + 1.3) - 0.5,
hash31(sid + 2.7) - 0.5,
hash31(sid + 4.1) - 0.5
) * 0.68;
float sd = length(sf - jitterP);
float twinkle = 0.55 + 0.45 * sin(TAU * (phase + sh * 3.0));
float pt = exp(-sd * sd * 135.0) * twinkle * sparkEnv * tipSparkBoost;
sparkCol = mix(COL_GOLD, COL_CORE, smoothstep(0.84, 0.98, sh)) * pt * (3.6 * emberBoost);
}
// Combine volumetric contribution
float ribbonGain = isRefl ? 1.55 : 1.35;
accum += (energyCol * volDens * ribbonGain + tipAura + veinCol + sparkCol) * dt;
}
t += dt;
}
// 4. Crisp floating golden arcane rune motes along the outer wake
// Evaluate 12 curated rune billboards analytically along the ray (ultra-crisp!)
int runeCount = isRefl ? 8 : 12;
for (int i = 0; i < 12; i++) {
if (i >= runeCount) break;
float fi = float(i);
float sBase = mix(0.08, 0.90, fi / 11.0);
// Gentle periodic drift along the arc & subtle bobbing
float drift = 0.018 * sin(TAU * (phase + fi * 0.17));
float sR = clamp(sBase + drift, 0.04, 0.94);
vec3 center = arcPointWorld(sR);
// Offset slightly outside the arc ribbon & slightly above/below
vec3 ax, ay, az;
getArcBasis(ax, ay, az);
float theta = ARC_START + slashAnimOffset() + sR * ARC_SPAN;
vec3 radDir = ax * cos(theta) + az * sin(theta);
float side = (mod(fi, 2.0) < 0.5) ? 1.0 : -0.55;
float rOff = mix(0.24, 0.36, hash11(fi * 3.7 + 1.1)) * side;
float yOff = (hash11(fi * 5.3 + 2.1) - 0.42) * 0.18 + 0.025 * cos(TAU * (phase + fi * 0.23));
vec3 runePos = center + radDir * rOff + ay * yOff;
runePos.y = max(runePos.y, 0.09);
// Intersect ray with camera-facing / floor-tilted rune disc
vec3 rNorm = normalize(mix(-rd, vec3(0.0, 1.0, 0.0), 0.25));
float denom = dot(rd, rNorm);
if (abs(denom) > 1e-4) {
float tHit = dot(runePos - ro, rNorm) / denom;
if (tHit > 0.05 && tHit < tMax) {
vec3 hitP = ro + rd * tHit;
vec3 dP = hitP - runePos;
float size = mix(0.058, 0.082, hash11(fi * 7.1 + 0.5)) * (1.0 + 0.18 * openAmt);
if (dot(dP, dP) < size * size * 1.45) {
vec3 uDir = normalize(cross(vec3(0.0, 1.0, 0.0), rNorm));
vec3 vDir = cross(rNorm, uDir);
vec2 ruv = vec2(dot(dP, uDir), dot(dP, vDir)) / size;
ruv = rot2(0.35 * sin(TAU * phase + fi)) * ruv;
int rType = int(mod(fi, 3.0));
float glyph = evalRuneGlyph(ruv, rType);
float halo = exp(-dot(ruv, ruv) * 2.2) * 0.22;
float pulse = 0.72 + 0.28 * sin(TAU * (phase + fi * 0.31));
float fade = smoothstep(0.95, 0.70, sR);
vec3 rCol = mix(COL_GOLD, COL_CORE, glyph * 0.65) * (glyph * 2.4 + halo) * pulse * fade * emberBoost;
accum += rCol * (isRefl ? 0.78 : 1.0);
}
}
}
}
return accum;
}
// ============================================================================
// PBR LIGHTING & STUDIO ENVIRONMENT
// ============================================================================
float D_GGX(float NoH, float rough) {
float a = max(rough * rough, 0.002);
float a2 = a * a;
float d = NoH * NoH * (a2 - 1.0) + 1.0;
return a2 / max(PI * d * d, 1e-6);
}
float G_SchlickGGX(float NoV, float NoL, float rough) {
float r = rough + 1.0;
float k = (r * r) / 8.0;
float gv = NoV / max(NoV * (1.0 - k) + k, 1e-5);
float gl = NoL / max(NoL * (1.0 - k) + k, 1e-5);
return gv * gl;
}
vec3 F_Schlick(float cosTheta, vec3 F0) {
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
}
vec3 evalLightPBR(vec3 N, vec3 V, vec3 L, vec3 lightCol, vec3 albedo, float rough, float metal) {
float NoL = max(dot(N, L), 0.0);
if (NoL <= 0.0) return vec3(0.0);
float NoV = max(dot(N, V), 1e-4);
vec3 H = normalize(V + L);
float NoH = max(dot(N, H), 0.0);
float VoH = max(dot(V, H), 0.0);
vec3 F0 = mix(vec3(0.04), albedo, metal);
vec3 F = F_Schlick(VoH, F0);
float D = D_GGX(NoH, rough);
float G = G_SchlickGGX(NoV, NoL, rough);
vec3 spec = (D * G * F) / max(4.0 * NoV * NoL, 1e-4);
vec3 kD = (1.0 - F) * (1.0 - metal);
vec3 diff = kD * albedo / PI;
return (diff + spec) * lightCol * NoL;
}
// Soft studio environment sky/softbox reflection for obsidian wet tiles & metal
vec3 evalStudioEnv(vec3 dir, int lightMode) {
float y = clamp(dir.y, 0.0, 1.0);
if (lightMode == 1) {
// Pure neutral studio softbox
float softbox = smoothstep(0.35, 0.85, dot(dir, normalize(vec3(0.35, 0.78, 0.52))));
float rimBox = smoothstep(0.45, 0.90, dot(dir, normalize(vec3(-0.65, 0.55, -0.52))));
float v = mix(0.14, 0.34, y) + 0.55 * softbox + 0.25 * rimBox;
return vec3(v);
}
// Dark obsidian studio ceiling with moody cool-slate overhead rim softboxes
// (gives crisp silvery-blue puddle highlights while keeping obsidian dark #0B0E12)
vec3 base = mix(COL_OBSIDIAN * 0.42, vec3(0.032, 0.052, 0.105), pow(y, 0.72));
// Overhead cool slate studio strip lights
float strip1 = smoothstep(0.52, 0.94, dot(dir, normalize(vec3(0.28, 0.62, -0.73))));
float strip2 = smoothstep(0.60, 0.95, dot(dir, normalize(vec3(-0.55, 0.48, -0.68))));
float strip3 = smoothstep(0.50, 0.90, dot(dir, normalize(vec3(0.75, 0.35, -0.55))));
vec3 skyCol = base
+ vec3(0.22, 0.32, 0.48) * strip1 * 0.55
+ vec3(0.12, 0.21, 0.38) * strip2 * 0.42
+ vec3(0.16, 0.25, 0.40) * strip3 * 0.36;
if (lightMode == 2) {
// Grazing mode: boost low-angle cool-gold rim
float graze = smoothstep(0.58, 0.96, dot(dir, normalize(vec3(0.82, 0.20, -0.52))));
skyCol += vec3(0.38, 0.44, 0.58) * graze;
} else if (lightMode == 3) {
// Backlit mode: crisp studio backlight behind the arc without washing out darks
float back = smoothstep(0.45, 0.92, dot(dir, normalize(vec3(-0.15, 0.35, -0.92))));
skyCol += mix(COL_CYAN, vec3(0.65, 0.80, 0.98), 0.50) * back * 0.78;
}
return skyCol;
}
// ============================================================================
// RAYMARCHING & SHADING
// ============================================================================
vec2 raymarch(vec3 ro, vec3 rd, float tMax) {
float t = 0.02;
for (int i = 0; i < 96; i++) {
vec3 p = ro + rd * t;
vec2 h = mapScene(p);
if (h.x < 0.0012 * (1.0 + t * 0.25)) {
return vec2(t, h.y);
}
t += clamp(h.x * 0.85, 0.004, 0.25);
if (t > tMax) break;
}
return vec2(-1.0, 0.0);
}
// Analytical arcane area lights distributed along the sweeping slash arc
// to cast rich cyan/cobalt/gold light spill & specular highlights onto the wet floor.
vec3 evalArcaneSpill(vec3 p, vec3 N, vec3 V, vec3 albedo, float rough, float metal) {
if (uLightMode == 1) return vec3(0.0);
float openBoost = 1.0 + 0.35 * clamp(uOpen, 0.0, 1.0);
vec3 total = vec3(0.0);
// 6 weighted point emitters along the sweeping slash
const float sPos[6] = float[6](0.06, 0.16, 0.28, 0.44, 0.62, 0.80);
for (int i = 0; i < 6; i++) {
float s = sPos[i];
vec3 lPos = arcPointWorld(s);
vec3 toL = lPos - p;
float d2 = dot(toL, toL) + 0.08;
float dist = sqrt(d2);
vec3 L = toL / dist;
vec3 lCol;
float power;
if (i == 0) {
lCol = mix(COL_CORE, COL_GOLD, 0.35);
power = 2.6 * openBoost;
} else if (i == 1) {
lCol = COL_GOLD;
power = 2.2 * openBoost;
} else if (i == 2) {
lCol = COL_CYAN;
power = 1.8 * openBoost;
} else if (i == 3) {
lCol = mix(COL_CYAN, COL_COBALT, 0.55);
power = 1.45 * openBoost;
} else if (i == 4) {
lCol = COL_COBALT;
power = 1.15 * openBoost;
} else {
lCol = COL_COBALT * 0.85;
power = 0.75 * openBoost;
}
float atten = power / (d2 + 0.18 * dist);
total += evalLightPBR(N, V, L, lCol * atten, albedo, rough, metal);
}
return total;
}
vec3 shadeHit(vec3 p, vec3 rd, float matId, float tHit) {
vec3 V = -rd;
vec3 N = calcNormal(p);
bool neutral = (uLightMode == 1);
// Primary studio directional light setup per uLightMode
vec3 keyDir, keyCol, rimDir, rimCol;
if (uLightMode == 1) {
keyDir = normalize(vec3(0.55, 0.78, 0.45));
keyCol = vec3(1.55);
rimDir = normalize(vec3(-0.65, 0.48, -0.58));
rimCol = vec3(0.65);
} else if (uLightMode == 2) {
// Grazing mode
keyDir = normalize(vec3(0.86, 0.16, 0.48));
keyCol = vec3(0.65, 0.74, 0.92) * 0.95;
rimDir = normalize(vec3(-0.78, 0.22, -0.58));
rimCol = vec3(0.62, 0.52, 0.40) * 0.65;
} else if (uLightMode == 3) {
// Backlit mode
keyDir = normalize(vec3(-0.20, 0.42, -0.88));
keyCol = vec3(0.38, 0.60, 0.88) * 1.10;
rimDir = normalize(vec3(0.65, 0.35, -0.68));
rimCol = COL_GOLD * 0.60;
} else {
// Hero mode: moody cool-slate studio overhead fill so dark obsidian tiles read with high contrast
keyDir = normalize(vec3(0.35, 0.82, -0.45));
keyCol = vec3(0.16, 0.23, 0.36) * 0.78;
rimDir = normalize(vec3(-0.62, 0.52, -0.58));
rimCol = vec3(0.12, 0.20, 0.34) * 0.55;
}
vec3 col = vec3(0.0);
if (matId < 1.5) {
// --------------------------------------------------------------------
// MATERIAL 1: Wet Obsidian Tiled Arena Floor
// --------------------------------------------------------------------
FloorInfo fi = evalFloorInfo(p.xz);
N = calcFloorNormal(p, fi);
vec3 baseObsidian = COL_OBSIDIAN * 0.42 * (0.86 + 0.34 * fi.microBump + 0.16 * (fi.tileId - 0.5));
baseObsidian = mix(baseObsidian, COL_OBSIDIAN * 0.18, fi.grout);
// Darken wet stone slightly (physically accurate wet porosity)
baseObsidian *= mix(1.0, 0.68, fi.wetness);
vec3 albedo = neutral
? vec3(mix(0.34, 0.44, fi.microBump) * mix(1.0, 0.55, fi.grout))
: baseObsidian;
float rough = mix(0.34, 0.052, fi.wetness * fi.bevel);
rough = mix(rough, 0.68, fi.grout);
if (neutral) rough = mix(0.42, 0.16, fi.wetness * fi.bevel);
// Studio key & rim
col += evalLightPBR(N, V, keyDir, keyCol, albedo, rough, 0.0);
col += evalLightPBR(N, V, rimDir, rimCol, albedo, rough, 0.0);
// Controlled ambient bounce: deep #0B0E12 obsidian floor without dead-black crush
vec3 ambCol = neutral ? vec3(0.16) : vec3(0.022, 0.032, 0.062);
col += albedo * ambCol * (0.8 + 0.4 * fi.bevel);
// Arcane VFX light spill across the wet tiles
col += evalArcaneSpill(p, N, V, albedo, rough, 0.0);
// Real-time glossy specular reflection of studio + sweeping arcane VFX!
vec3 R = reflect(-V, N);
R.y = max(R.y, 0.01);
float NoV = max(dot(N, V), 1e-4);
vec3 F0 = vec3(mix(0.04, 0.085, fi.wetness));
vec3 fresnel = F_Schlick(NoV, F0);
float reflGloss = mix(0.22, 1.0, pow(1.0 - rough, 1.5)) * (1.0 - fi.grout * 0.78);
vec3 envRefl = evalStudioEnv(R, uLightMode);
vec3 vfxRefl = vec3(0.0);
if (!neutral) {
// Secondary volumetric + rune reflection ray off the wet puddle!
vfxRefl = evalVolumetricVFX(p + N * 0.012, R, 5.5, 26, true);
// Boost crispness inside glossy wet puddles
vfxRefl *= mix(0.55, 1.40, fi.wetness);
}
// Fresnel-weighted reflection (rich VFX mirror reflections, restrained studio sky)
vec3 reflWeight = mix(fresnel, vec3(0.32), fi.wetness * 0.36) * reflGloss;
col += envRefl * reflWeight * 0.56 + vfxRefl * reflGloss * (0.52 + 0.60 * fresnel);
} else if (matId < 2.5) {
// --------------------------------------------------------------------
// MATERIAL 2: Sculpted Blazing White-Gold Crescent Blade Tip
// --------------------------------------------------------------------
ArcCoord ac = evalArcCoord(p);
vec3 albedo = neutral ? vec3(0.68) : COL_CORE;
float rough = neutral ? 0.24 : 0.14;
float metal = neutral ? 0.15 : 0.35;
col += evalLightPBR(N, V, keyDir, keyCol, albedo, rough, metal);
col += evalLightPBR(N, V, rimDir, rimCol, albedo, rough, metal);
col += albedo * (neutral ? vec3(0.20) : vec3(0.12));
if (!neutral) {
float NoV = clamp(dot(N, V), 0.0, 1.0);
float rim = pow(1.0 - NoV, 2.0);
// White-gold hot core with warm arcane gold grazing edge & subtle cyan ice sheen
vec3 bladeGlow = mix(COL_CORE * 2.4, COL_GOLD * 1.9, rim * 0.65);
bladeGlow = mix(bladeGlow, mix(COL_CORE, COL_CYAN, 0.35) * 2.2, smoothstep(0.12, 0.02, ac.s) * 0.35);
// Extra heat right near the collar junction
float collarHeat = exp(-pow((ac.s - 0.17) / 0.055, 2.0));
bladeGlow += COL_GOLD * collarHeat * 1.4;
col += bladeGlow;
}
} else if (matId < 3.5) {
// --------------------------------------------------------------------
// MATERIAL 3: Ornate Sculpted Golden Arcane Crossguard / Collar
// --------------------------------------------------------------------
vec3 goldAlbedo = vec3(0.96, 0.72, 0.26);
vec3 albedo = neutral ? vec3(0.56) : goldAlbedo;
float rough = neutral ? 0.28 : 0.22;
float metal = neutral ? 0.15 : 0.92;
col += evalLightPBR(N, V, keyDir, keyCol * 1.35, albedo, rough, metal);
col += evalLightPBR(N, V, rimDir, rimCol * 1.25, albedo, rough, metal);
col += evalArcaneSpill(p, N, V, albedo, rough, metal);
vec3 R = reflect(-V, N);
col += evalStudioEnv(R, uLightMode) * albedo * (neutral ? 0.22 : 0.65);
if (!neutral) {
// Subtle warm emissive bounce from adjacent blazing blade
float NoV = clamp(dot(N, V), 0.0, 1.0);
col += COL_GOLD * (0.28 + 0.55 * pow(1.0 - NoV, 2.5));
}
} else {
// --------------------------------------------------------------------
// MATERIAL 4: Sculpted Luminous Cyan-to-Cobalt Blade & Ribbon Core
// --------------------------------------------------------------------
ArcCoord ac = evalArcCoord(p);
float s = ac.s;
vec3 baseCol = mix(COL_CYAN, COL_COBALT, smoothstep(0.22, 0.54, s));
vec3 albedo = neutral ? vec3(0.60) : baseCol;
float rough = neutral ? 0.26 : 0.16;
float metal = neutral ? 0.10 : 0.45;
col += evalLightPBR(N, V, keyDir, keyCol, albedo, rough, metal);
col += evalLightPBR(N, V, rimDir, rimCol, albedo, rough, metal);
col += albedo * (neutral ? vec3(0.18) : vec3(0.10));
if (!neutral) {
float NoV = clamp(dot(N, V), 0.0, 1.0);
float fres = pow(1.0 - NoV, 2.2);
float tailFade = smoothstep(0.88, 0.35, s);
// Intense cyan near collar, transitioning into deep cobalt with bright electric bevel rim
vec3 coreGlow = mix(COL_CYAN * 1.75, COL_COBALT * 1.35, smoothstep(0.22, 0.52, s));
coreGlow += mix(COL_CORE, COL_CYAN, 0.55) * fres * 1.25;
// Subtle flowing energy striations along the blade fuller
float stripe = 0.75 + 0.25 * sin(s * 38.0 - loopPhase() * TAU * 2.0);
col += coreGlow * tailFade * stripe;
}
}
// Subtle distance atmospheric perspective on the wet arena floor
float fogAmt = 1.0 - exp(-tHit * tHit * 0.015);
vec3 fogCol = neutral ? vec3(0.16) : (COL_OBSIDIAN * 0.46);
col = mix(col, fogCol, clamp(fogAmt, 0.0, 0.65));
return col;
}
// ============================================================================
// CAMERA & ACES FILMIC TONE MAPPING
// ============================================================================
vec3 acesToneMap(vec3 x) {
// Controlled soft-shoulder rolloff before ACES to prevent >1% clipping
x = max(x, vec3(0.0));
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
return clamp((x * (a * x + b)) / max(x * (c * x + d) + e, vec3(1e-5)), 0.0, 1.0);
}
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * uResolution.xy) / max(uResolution.y, 1.0);
// Camera framing:
// uCamMode == 0 : Hero 3/4 high-angle cinematic view matching 01.png (full arc inside frame)
// uCamMode == 1 : ~2.5x Macro close-up on blazing crescent tip, golden collar & wet reflection
vec3 ro, ta;
float fov;
if (uCamMode == 1) {
ro = vec3(0.92, 0.96, 1.88);
ta = vec3(0.68, 0.28, 0.56);
fov = 1.85;
} else {
ro = vec3(0.18, 2.38, 3.65);
ta = vec3(-0.04, 0.50, 0.02);
fov = 1.48;
}
vec3 cw = normalize(ta - ro);
vec3 cu = normalize(cross(cw, vec3(0.0, 1.0, 0.0)));
vec3 cv = cross(cu, cw);
vec3 rd = normalize(uv.x * cu + uv.y * cv + fov * cw);
float tMax = 18.0;
vec2 hit = raymarch(ro, rd, tMax);
vec3 col;
float volMaxT = tMax;
if (hit.x > 0.0) {
vec3 p = ro + rd * hit.x;
col = shadeHit(p, rd, hit.y, hit.x);
volMaxT = hit.x;
} else {
col = evalStudioEnv(rd, uLightMode);
}
// Primary volumetric VFX sweep, wispy filaments, electric vein, sparks & runes
vec3 vfx = evalVolumetricVFX(ro, rd, volMaxT, 48, false);
col += vfx;
// Gentle exposure & controlled cinematic vignette (kept mild so corners never crush to black)
float exposure = (uLightMode == 1) ? 1.05 : 1.08;
col *= exposure;
float vig = 1.0 - 0.16 * dot(uv, uv);
col *= clamp(vig, 0.78, 1.0);
// ACES Filmic Tone Mapping
col = acesToneMap(col);
// Enforce pure neutral grayscale in uLightMode == 1
if (uLightMode == 1) {
float lum = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(lum);
}
// sRGB gamma encode
col = pow(max(col, vec3(0.0)), vec3(1.0 / 2.2));
fragColor = vec4(col, 1.0);
}
`;
export function createArcaneSlashArcMaterial(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 | arcane-slash-arc |
|---|---|
| Category | Game VFX Shaders · Arcane Palette |
| Upstream study | vfx_palette/lib/01_arcane_slash_arc.glsl (commit 913ad1c) |
| Animation cycle | 3.0 s seamless harmonic loop |
| Declared uniforms | uResolution, uTime, uOpen, uLightMode, uCamMode |
| Source size | 1017 lines · 39.4 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 |
GGX microfacet specular (Trowbridge–Reitz 1975; Walter et al. 2007); Schlick Fresnel reflectance (1994); Beer–Lambert volumetric absorption/attenuation
David Hoskins, hash · Krzysztof Narkowicz, filmic curve · Inigo Quilez, quadratic distance blend · Inigo Quilez, tetrahedral SDF normal
3s LoopGeodesic hexagonal forcefield dome with Fresnel rim energy, impact ripple rings, and rune lattice.
3s LoopImploding spatial warp flash with vertical slipstream streaks and dissipating astral embers.
AnimatedConcentric inscribed magic circle erupting through fractured stone radial shockwaves.
3s LoopSwirling plasma core missile with helical ribbon wake and orbiting spark shards.
3s LoopSustained high-energy laser beam wrapped in dual helical plasma coils and impact flare.
3s LoopAscending spiral power-up cylinder with ground rune ring and rising crystalline motes.