3s LoopDirectional rolling fire wave surging down stone tiles with trailing scorched embers.
orbiting-elemental-trinity-rings.glsl · 870 lines · GLSL ES 3.00 · MIT
#version 300 es
// Orbiting Elemental Trinity Rings (orbiting-elemental-trinity-rings.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_animated/lib/02_orbiting_elemental_trinity_rings.glsl
// License: MIT (Copyright 2026 Gokay Aydogan) + MIT/CC0 helpers — https://pixelfx.io/LICENSE-SHADERS.txt
// Uniforms: uResolution (vec2), uTime (float), uOpen (0..1), uLightMode (0..3), uCamMode (0..1)
precision highp float;
precision highp int;
uniform vec2 uResolution;
uniform float uTime;
uniform float uOpen;
uniform int uLightMode;
uniform int uCamMode;
out vec4 fragColor;
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
// Exact 3.0s seamless loop state
float gPhase;
float gLoop;
// Ring transforms (world -> ring-local) and centers
mat3 gR1, gR2, gR3;
vec3 gC1, gC2, gC3;
vec3 gCrysPos;
mat2 gCrysRot;
// --- Utility math ---
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
mat3 rotX(float a) {
float c = cos(a), s = sin(a);
return mat3(1.0, 0.0, 0.0,
0.0, c, s,
0.0, -s, c);
}
mat3 rotZ(float a) {
float c = cos(a), s = sin(a);
return mat3( c, s, 0.0,
-s, c, 0.0,
0.0, 0.0, 1.0);
}
float smin(float a, float b, float k) {
float h = max(k - abs(a - b), 0.0) / k;
return min(a, b) - h * h * k * 0.25;
}
float smax(float a, float b, float k) {
return -smin(-a, -b, k);
}
float sdBox2(vec2 p, vec2 b, float r) {
vec2 d = abs(p) - b;
return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - r;
}
float triWave(float x) {
return abs(fract(x / TAU) * 2.0 - 1.0) * 2.0 - 1.0;
}
float hash21(vec2 p) {
p = fract(p * vec2(123.34, 456.21));
p += dot(p, p + 45.32);
return fract(p.x * p.y);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
f = f * f * (3.0 - 2.0 * f);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
}
// Fast 3D Gyroid & Domain-Warped Curl-fBM (zero seams, fast on SwiftShader)
float gyroid(vec3 p) {
return dot(sin(p), cos(p.yzx));
}
float fbmCurl(vec3 p) {
// Domain warp for roaring turbulent curling motion
vec3 w = vec3(
gyroid(p),
gyroid(p + vec3(1.7, 3.1, 2.3)),
gyroid(p - vec3(2.4, 1.3, 3.7))
);
p += 0.45 * w;
float v = 0.0;
float a = 0.54;
const mat3 mRot = mat3(
0.80, 0.48, 0.36,
-0.60, 0.64, 0.48,
0.00, -0.60, 0.80
);
for (int i = 0; i < 3; i++) {
v += a * gyroid(p);
p = mRot * p * 2.05 + vec3(1.3, 2.7, 0.9);
a *= 0.48;
}
return v;
}
// High-frequency lacy foam / filament ridge pattern
float fbmLace(vec3 p) {
float g1 = 1.0 - abs(gyroid(p) * 0.65);
p = p * 2.15 + vec3(1.9, -2.3, 1.1);
float g2 = 1.0 - abs(gyroid(p) * 0.65);
return clamp(g1 * 0.60 + g2 * 0.40, 0.0, 1.0);
}
// --- Frame rig setup (exact 3.0s seamless loop, clean 3D separation at t=1.2) ---
void setupRig() {
gPhase = fract(uTime / 3.0);
gLoop = gPhase * TAU;
gCrysPos = vec3(0.0, 0.02 + 0.045 * sin(gLoop), 0.0);
gCrysRot = rot2(gLoop);
// Ring 1 (Top): Sapphire-cyan crashing water wave ring
gC1 = vec3(0.0, 0.74 + 0.04 * sin(gLoop), 0.0);
float r1x = 0.25 + 0.08 * cos(gLoop);
float r1z = -0.14 + 0.10 * sin(gLoop);
gR1 = rotZ(-r1z) * rotX(r1x);
// Ring 2 (Middle): Blazing crimson-orange volumetric fire ring
gC2 = vec3(0.0, 0.04 + 0.03 * cos(gLoop), 0.0);
float r2x = -0.32 + 0.12 * sin(gLoop);
float r2z = 0.42 - 0.14 * cos(gLoop);
gR2 = rotZ(-r2z) * rotX(r2x);
// Ring 3 (Bottom): Electric emerald-green wind & lightning vortex ring
gC3 = vec3(0.0, -0.80 + 0.04 * sin(gLoop + 2.094395), 0.0);
float r3x = -0.27 - 0.07 * cos(gLoop + 1.047198);
float r3z = 0.15 + 0.10 * sin(gLoop + 1.047198);
gR3 = rotZ(-r3z) * rotX(r3x);
}
// --- Solid & Sculpted Geometry SDFs ---
// Double-terminated faceted hexagonal crystal core
float sdCrystal(vec3 p) {
vec3 q = p - gCrysPos;
q.xz = gCrysRot * q.xz;
float ay = abs(q.y);
const vec2 h1 = vec2(1.0, 0.0);
const vec2 h2 = vec2(0.5, 0.8660254);
const vec2 h3 = vec2(-0.5, 0.8660254);
float hexR = max(abs(dot(q.xz, h1)), max(abs(dot(q.xz, h2)), abs(dot(q.xz, h3))));
vec2 qRot = vec2(q.x * 0.8660254 - q.z * 0.5, q.x * 0.5 + q.z * 0.8660254);
float hexR2 = max(abs(dot(qRot, h1)), max(abs(dot(qRot, h2)), abs(dot(qRot, h3))));
float dPrism = hexR - 0.255;
float dPyr = (hexR * 0.76822 + (ay - 0.255) * 0.64018) - 0.255 * 0.76822;
float dCrown = (hexR2 * 0.83205 + (ay - 0.205) * 0.55470) - 0.266 * 0.83205;
float dBelt = hexR2 - 0.266;
float d = smax(dPrism, dPyr, 0.003);
d = smax(d, dCrown, 0.0025);
d = smax(d, dBelt, 0.0025);
return d;
}
// Ring 1: Razor-thin dark-chrome inner edge (plus sculpted crashing water wave in clay mode)
vec2 sdRing1(vec3 p) {
vec3 q = gR1 * (p - gC1);
float r = length(q.xz);
vec2 cp = vec2(r - 1.62, q.y);
float bound = length(cp) - 0.44;
if (bound > 0.24) return vec2(bound, 11.0);
// Razor-thin dark-chrome inner accent edge
float dRim = sdBox2(cp - vec2(-0.105, -0.020), vec2(0.011, 0.030), 0.004);
if (uLightMode != 1) {
return vec2(dRim, 11.0);
}
// Clay mode: thick sculpted crashing turbulent water wave so form reads cleanly
float th = atan(q.z, q.x);
float thSpin = th - 1.0 * gLoop;
vec3 wCoord = vec3(cos(thSpin) * 2.8, sin(thSpin) * 2.8, cp.y * 4.5 + cp.x * 3.0);
float turb = fbmCurl(wCoord);
float swell = 0.5 + 0.5 * sin(th * 4.0 - 2.0 * gLoop + 0.7 * turb);
vec2 wp = cp - vec2(0.055 + 0.050 * swell + 0.035 * turb, 0.025 + 0.055 * swell + 0.028 * turb);
wp = rot2(-0.26 + 0.16 * swell) * wp;
float dWave = (sdBox2(wp, vec2(0.140 + 0.032 * swell, 0.042 + 0.020 * swell), 0.024) - 0.022 * turb) * 0.52;
if (dRim < dWave) return vec2(dRim, 11.0);
return vec2(dWave, 2.0);
}
// Ring 2: Razor-thin dark-iron inner edge (plus sculpted turbulent flame band in clay mode)
vec2 sdRing2(vec3 p) {
vec3 q = gR2 * (p - gC2);
float r = length(q.xz);
vec2 cp = vec2(r - 1.18, q.y);
float bound = length(cp) - 0.42;
if (bound > 0.22) return vec2(bound, 12.0);
// Subtle razor-thin dark charred-iron inner edge
float dRim = sdBox2(cp - vec2(-0.075, -0.015), vec2(0.009, 0.026), 0.003);
if (uLightMode != 1) {
return vec2(dRim, 12.0);
}
// Clay mode: thick roaring sculpted flame ribbon so form reads cleanly
float th = atan(q.z, q.x);
float thSpin = th + 1.0 * gLoop;
vec3 fCoord = vec3(cos(thSpin) * 3.2, sin(thSpin) * 3.2, cp.y * 5.0);
float turb = fbmCurl(fCoord);
float tongue = pow(0.5 + 0.5 * sin(th * 5.0 + 2.0 * gLoop + 0.9 * turb), 1.6);
vec2 fp = cp - vec2(0.040 + 0.030 * tongue, 0.045 * tongue + 0.025 * turb);
fp = rot2(0.18 - 0.16 * tongue) * fp;
float dFire = (sdBox2(fp, vec2(0.115 + 0.028 * tongue, 0.040 + 0.075 * tongue), 0.018) - 0.024 * turb) * 0.52;
if (dRim < dFire) return vec2(dRim, 12.0);
return vec2(dFire, 3.0);
}
// Ring 3: Razor-thin dark-emerald metallic inner edge (plus sculpted vortex band in clay mode)
vec2 sdRing3(vec3 p) {
vec3 q = gR3 * (p - gC3);
float r = length(q.xz);
vec2 cp = vec2(r - 1.74, q.y);
float bound = length(cp) - 0.42;
if (bound > 0.22) return vec2(bound, 13.0);
float dRim = sdBox2(cp - vec2(-0.105, 0.010), vec2(0.010, 0.028), 0.003);
if (uLightMode != 1) {
return vec2(dRim, 13.0);
}
// Clay mode: thick sculpted swirling wind-vortex band
float th = atan(q.z, q.x);
float thSpin = th - 1.0 * gLoop;
vec3 eCoord = vec3(cos(thSpin) * 3.0, sin(thSpin) * 3.0, cp.y * 4.5 + cp.x * 3.0);
float turb = fbmCurl(eCoord);
float gust = 0.5 + 0.5 * sin(th * 4.0 - 2.0 * gLoop + 0.6 * turb);
vec2 ep = cp - vec2(0.055 + 0.032 * gust, 0.020 * turb);
ep = rot2(0.24 + 0.12 * gust) * ep;
float dWind = (sdBox2(ep, vec2(0.135 + 0.030 * gust, 0.038 + 0.016 * gust), 0.016) - 0.020 * turb) * 0.55;
if (dRim < dWind) return vec2(dRim, 13.0);
return vec2(dWind, 4.0);
}
// Dark stone circular colosseum arena floor with carved concentric rings
float sdFloor(vec3 p) {
float yFloor = -1.82;
float d = p.y - yFloor;
if (d < 0.16) {
float r = length(p.xz);
float a = atan(p.z, p.x);
float g1 = abs(r - 1.15);
float g2 = abs(r - 1.94);
float g3 = abs(r - 2.74);
float g4 = abs(r - 3.62);
float groove = smoothstep(0.034, 0.007, min(min(g1, g2), min(g3, g4)));
float rad = abs(sin(a * 6.0)) * r;
float seam = smoothstep(0.026, 0.006, rad) * smoothstep(1.12, 1.28, r);
d += 0.012 * max(groove, seam * 0.72);
}
return d;
}
vec2 mapScene(vec3 p) {
vec2 res = vec2(sdFloor(p), 5.0);
float dC = sdCrystal(p);
if (dC < res.x) res = vec2(dC, 1.0);
vec2 d1 = sdRing1(p);
if (d1.x < res.x) res = d1;
vec2 d2 = sdRing2(p);
if (d2.x < res.x) res = d2;
vec2 d3 = sdRing3(p);
if (d3.x < res.x) res = d3;
return res;
}
float mapDist(vec3 p) {
float d = sdFloor(p);
d = min(d, sdCrystal(p));
d = min(d, sdRing1(p).x);
d = min(d, sdRing2(p).x);
d = min(d, sdRing3(p).x);
return d;
}
// Unit-sign tetrahedral normal
vec3 calcNormal(vec3 p) {
const float h = 0.0014;
const vec2 k = vec2(1.0, -1.0);
return normalize(
k.xyy * mapDist(p + k.xyy * h) +
k.yyx * mapDist(p + k.yyx * h) +
k.yxy * mapDist(p + k.yxy * h) +
k.xxx * mapDist(p + k.xxx * h)
);
}
// Fast 4-tap ambient occlusion
float calcAO(vec3 p, vec3 n) {
float occ = 0.0;
float sca = 1.0;
for (int i = 0; i < 4; i++) {
float h = 0.03 + 0.085 * float(i);
float d = mapDist(p + n * h);
occ += (h - d) * sca;
sca *= 0.65;
}
return clamp(1.0 - 2.6 * occ, 0.12, 1.0);
}
// Fast soft shadow
float calcShadow(vec3 ro, vec3 rd, float maxT) {
float res = 1.0;
float t = 0.05;
for (int i = 0; i < 24; i++) {
float h = mapDist(ro + rd * t);
res = min(res, 7.0 * h / t);
t += clamp(h, 0.04, 0.35);
if (res < 0.02 || t > maxT) break;
}
return clamp(res, 0.0, 1.0);
}
// --- Roaring Volumetric Elemental Streams (Fire, Lightning/Wind, Water Mist) ---
// Returns vec4(emissiveRGB, desiredMaxStep)
vec4 evalVolumetricStreams(vec3 p, inout float trans) {
vec3 acc = vec3(0.0);
float maxStep = 0.36;
// 1. Compact bright core halo tightly hugging the central crystal
float dC = length(p - gCrysPos);
if (dC < 0.90) {
float pulse = 0.90 + 0.10 * sin(gLoop * 2.0);
acc += vec3(0.16, 0.68, 1.00) * exp(-dC * 6.2) * 0.34 * pulse;
}
// 2. WATER/ICE RING (Top): Translucent crashing sapphire-cyan water wave + lacy white seafoam crests
vec3 q1 = gR1 * (p - gC1);
vec2 cp1 = vec2(length(q1.xz) - 1.62, q1.y);
float d1 = length(cp1);
if (d1 < 0.56) {
maxStep = min(maxStep, (d1 < 0.36) ? 0.024 : 0.044);
float th = atan(q1.z, q1.x);
float thSpin = th - 1.0 * gLoop;
// 3D curled ocean wave turbulence & fine lacy seafoam web
vec3 wCoord = vec3(cos(thSpin) * 3.4, sin(thSpin) * 3.4, cp1.y * 4.8 + cp1.x * 3.4);
float wTurb = fbmCurl(wCoord);
float swell = 0.5 + 0.5 * sin(th * 4.0 - 2.0 * gLoop + 0.85 * wTurb);
// Curling barrel wave cross-section wrapping outside the dark-chrome inner rim
vec2 wp = cp1 - vec2(0.085 + 0.055 * swell + 0.040 * wTurb, 0.025 + 0.065 * swell + 0.032 * wTurb);
wp = rot2(-0.28 + 0.18 * swell) * wp;
float barrelD = length(wp * vec2(1.0, 2.35)) - (0.145 + 0.035 * swell);
// Sculpted translucent liquid body with crisp turbulent wave edges
float liquidEnv = exp(-max(barrelD, 0.0) * 18.0) * smoothstep(-0.11, 0.02, cp1.x);
float waveBody = smoothstep(0.08, 0.72, liquidEnv * (0.78 + 0.52 * wTurb));
// High-frequency lacy white seafoam crests concentrated on upper breaking ridges
vec3 foamCoord = vec3(cos(thSpin) * 7.5, sin(thSpin) * 7.5, cp1.y * 13.0 + cp1.x * 9.5);
float lace = fbmLace(foamCoord);
float crestZone = smoothstep(-0.02, 0.14, cp1.y + 0.06 * swell) * exp(-abs(barrelD) * 26.0);
float foam = pow(lace, 2.6) * (0.35 + 0.65 * crestZone) * smoothstep(-0.06, 0.06, cp1.x);
// Deep cobalt-sapphire translucent interior -> luminous azure-cyan wave sheets -> crisp lacy white foam
vec3 deepCobalt = vec3(0.012, 0.12, 0.58);
vec3 vividAzure = vec3(0.06, 0.58, 1.00);
vec3 seafoam = vec3(0.84, 0.96, 1.00);
float sheet = clamp(0.45 + 0.55 * wTurb + 0.30 * crestZone, 0.0, 1.0);
vec3 wCol = mix(deepCobalt, vividAzure, sheet);
wCol = mix(wCol, seafoam, clamp(foam * 1.15, 0.0, 0.92));
float wEmit = waveBody * (0.85 + 0.95 * sheet) + foam * 2.2;
acc += wCol * wEmit * trans;
// Translucent optical absorption keeps sapphire depth rich instead of milky white
trans *= exp(-waveBody * 0.065);
}
// 3. FIRE RING (Middle): Saturated roaring curled-fBM volumetric fire tongues (crimson -> orange -> amber-gold)
vec3 q2 = gR2 * (p - gC2);
vec2 cp2 = vec2(length(q2.xz) - 1.18, q2.y);
float d2 = length(cp2);
if (d2 < 0.56) {
maxStep = min(maxStep, 0.028);
float th = atan(q2.z, q2.x);
float thSpin = th + 1.0 * gLoop;
// Advected 3D curl-fBM coordinates (roaring swirl + sharp upward-licking tongues)
vec3 fCoord = vec3(cos(thSpin) * 4.0, sin(thSpin) * 4.0, cp2.y * 4.6 - 0.60 * cp2.x);
float turb = fbmCurl(fCoord);
float fine = gyroid(fCoord * 2.6 + vec3(0.0, 2.0 * sin(gLoop), 2.0 * cos(gLoop)));
float yRise = cp2.y + 0.05;
float flameH = 0.22 + 0.22 * (0.5 + 0.5 * turb) + 0.08 * fine;
float yNorm = clamp(yRise / max(flameH, 0.08), 0.0, 1.4);
float radCenter = 0.040 + 0.105 * yNorm + 0.055 * turb * yNorm;
float radHalfW = mix(0.105, 0.028, clamp(yNorm, 0.0, 1.0));
float radD = abs(cp2.x - radCenter) / max(radHalfW, 0.02);
float baseEnv = smoothstep(-0.07, 0.03, yRise) * smoothstep(1.22, 0.12, yNorm) * exp(-radD * radD * 1.75);
// Sharp sculpted flame tongues with crisp turbulent dark cutouts (zero milky haze!)
float dens = smoothstep(0.16, 0.78, baseEnv * (0.85 + 0.75 * turb + 0.32 * fine));
// Tight molten core strictly along the inner iron rim
float coreBand = exp(-length(cp2 - vec2(0.022, 0.008)) * 24.0) * (0.65 + 0.35 * turb);
// Hyper-saturated blackbody fire ramp (reserves white-gold ONLY for tiny inner core so ACES stays rich!)
float temp = clamp(1.0 - yNorm * 1.05 + 0.28 * coreBand + 0.16 * fine, 0.0, 1.0);
vec3 fCol = mix(vec3(0.72, 0.025, 0.004), vec3(1.00, 0.22, 0.010), smoothstep(0.08, 0.52, temp));
fCol = mix(fCol, vec3(1.00, 0.60, 0.05), smoothstep(0.54, 0.86, temp));
fCol = mix(fCol, vec3(1.00, 0.90, 0.42), smoothstep(0.88, 0.99, temp));
float emit = (dens * 2.25 + coreBand * 1.15);
acc += fCol * emit * trans;
trans *= exp(-dens * 0.095);
}
// 4. WIND / LIGHTNING RING: Thick turbulent emerald wind vortex + 5 razor-sharp branching electric arcs
vec3 q3 = gR3 * (p - gC3);
vec2 cp3 = vec2(length(q3.xz) - 1.74, q3.y);
float d3 = length(cp3);
if (d3 < 0.54) {
// Fine adaptive step so rays NEVER skip over razor-thin lightning bolts!
maxStep = min(maxStep, (d3 < 0.34) ? 0.019 : 0.042);
float th = atan(q3.z, q3.x);
float thSpin = th - 2.0 * gLoop;
// Thick roaring translucent emerald-jade swirling wind vortex ribbon
vec3 wCoord = vec3(cos(thSpin) * 3.2, sin(thSpin) * 3.2, cp3.y * 5.2 + cp3.x * 3.5);
float wTurb = fbmCurl(wCoord);
vec2 wp3 = cp3 - vec2(0.075 + 0.035 * wTurb, 0.025 * wTurb);
wp3 = rot2(0.22) * wp3;
float vortexEnv = exp(-length(wp3 * vec2(1.0, 2.3)) * 8.5) * smoothstep(-0.10, 0.04, cp3.x);
float windStreaks = smoothstep(-0.25, 0.75, wTurb + 0.35 * sin(th * 9.0 - 3.0 * gLoop + cp3.x * 16.0));
vec3 vortexCol = mix(vec3(0.02, 0.44, 0.24), vec3(0.14, 0.95, 0.56), windStreaks);
acc += vortexCol * vortexEnv * (0.75 + 1.35 * windStreaks) * 1.45;
// 5 dense, razor-sharp crackling & branching electric lightning bolts!
// Bolt 1: Primary high-voltage jagged arc wrapping 360 deg
vec2 b1 = vec2(
0.055 + 0.105 * triWave(th * 6.0 - 3.0 * gLoop) + 0.048 * triWave(th * 17.0 + 4.0 * gLoop) + 0.020 * triWave(th * 35.0 - 5.0 * gLoop),
0.010 + 0.090 * triWave(th * 8.0 - 3.0 * gLoop + 1.1) + 0.038 * triWave(th * 21.0 - 4.0 * gLoop) + 0.016 * triWave(th * 43.0 + 3.0 * gLoop)
);
float db1 = length(cp3 - b1);
float m1 = 0.45 + 0.55 * smoothstep(-0.35, 0.45, sin(th * 2.0 - gLoop) + 0.45 * sin(th * 5.0 + 2.0 * gLoop));
acc += (vec3(0.92, 1.00, 0.97) * exp(-db1 * 76.0) * 9.5 +
vec3(0.08, 1.00, 0.52) * exp(-db1 * 20.0) * 1.85) * m1;
// Bolt 2: Secondary counter-winding jagged arc
vec2 b2 = vec2(
0.085 - 0.095 * triWave(th * 7.0 + 2.0 * gLoop + 0.7) + 0.042 * triWave(th * 19.0 - 3.0 * gLoop) + 0.018 * triWave(th * 39.0 + 5.0 * gLoop),
-0.015 - 0.075 * triWave(th * 10.0 + 2.0 * gLoop) + 0.034 * triWave(th * 23.0 + 4.0 * gLoop)
);
float db2 = length(cp3 - b2);
float m2 = 0.40 + 0.60 * smoothstep(-0.25, 0.50, cos(th * 3.0 - 2.0 * gLoop) + 0.35 * sin(th * 7.0 - gLoop));
acc += (vec3(0.88, 1.00, 0.95) * exp(-db2 * 74.0) * 8.5 +
vec3(0.06, 0.98, 0.50) * exp(-db2 * 19.0) * 1.65) * m2;
// Bolt 3: Outer crackling fork leaping outward
vec2 b3 = vec2(
0.185 + 0.110 * triWave(th * 11.0 - 4.0 * gLoop) + 0.045 * triWave(th * 27.0 + 5.0 * gLoop),
0.065 * triWave(th * 13.0 - 3.0 * gLoop + 2.2) + 0.028 * triWave(th * 31.0 - 4.0 * gLoop)
);
float db3 = length(cp3 - b3);
float m3 = pow(max(0.0, sin(th * 3.0 - 2.0 * gLoop + 0.6)), 1.8);
acc += (vec3(0.94, 1.00, 0.97) * exp(-db3 * 82.0) * 8.0 +
vec3(0.10, 1.00, 0.56) * exp(-db3 * 22.0) * 1.35) * m3;
// Bolt 4: Tight inner high-frequency arc snapping off the inner rim
vec2 b4 = vec2(
-0.025 + 0.060 * triWave(th * 13.0 + 3.0 * gLoop) + 0.025 * triWave(th * 29.0 - 4.0 * gLoop),
0.045 * triWave(th * 9.0 + 3.0 * gLoop + 1.7)
);
float db4 = length(cp3 - b4);
float m4 = pow(max(0.0, cos(th * 4.0 + gLoop - 0.5)), 2.0);
acc += (vec3(0.90, 1.00, 0.96) * exp(-db4 * 85.0) * 7.2 +
vec3(0.12, 1.00, 0.60) * exp(-db4 * 24.0) * 1.20) * m4;
}
return vec4(acc, maxStep);
}
// --- Flying elemental sparks, embers & water spray droplets (36 analytical 3D streaks) ---
vec3 evalElementalSparks(vec3 ro, vec3 rd, float maxT) {
vec3 col = vec3(0.0);
for (int i = 0; i < 36; i++) {
float fi = float(i);
int family = i % 3; // 0=fire ember, 1=water spray droplet, 2=lightning spark
float seed = fi * 1.6180339;
float speed = (family == 0) ? 1.0 : ((family == 1) ? -1.0 : 2.0);
float ang = fract(seed) * TAU + speed * gLoop;
float rad = (family == 1) ? (1.42 + 0.68 * fract(seed * 3.17)) :
(family == 0) ? (1.05 + 1.15 * fract(seed * 3.17)) :
(1.45 + 0.95 * fract(seed * 3.17));
float yBase = (family == 1) ? (0.68 + 0.58 * sin(seed * 7.3)) :
(family == 0) ? (0.14 + 0.85 * cos(seed * 5.1)) :
(-0.78 + 0.60 * sin(seed * 9.7));
float yPos = yBase + 0.16 * sin(gLoop + seed * TAU);
vec3 sp = vec3(cos(ang) * rad, yPos, sin(ang) * rad);
vec3 tang = normalize(vec3(-sin(ang) * speed, 0.14 * cos(gLoop + seed * TAU), cos(ang) * speed));
vec3 w = sp - ro;
float tRay = dot(w, rd);
if (tRay < 0.25 || tRay > maxT) continue;
vec3 closest = ro + rd * tRay;
vec3 diff = closest - sp;
float streakLen = (family == 1) ? 0.022 : 0.085; // crisp droplets for water, streaks for embers/sparks
float along = clamp(dot(diff, tang), -streakLen, streakLen);
float d = length(diff - tang * along);
float core = exp(-d * 98.0);
float halo = exp(-d * 24.0) * 0.18;
float twinkle = 0.60 + 0.40 * sin(gLoop * 3.0 + fi * 2.7);
vec3 sCol = (family == 0) ? vec3(1.00, 0.54, 0.12) :
(family == 1) ? vec3(0.65, 0.94, 1.00) :
vec3(0.45, 1.00, 0.72);
col += sCol * (core * 1.65 + halo) * twinkle;
}
return col;
}
// --- Dark moody colosseum arena backdrop ---
vec3 evalBackdrop(vec3 rd) {
if (uLightMode == 1) {
float grad = 0.22 + 0.12 * clamp(rd.y * 0.8 + 0.5, 0.0, 1.0);
return vec3(grad);
}
float up = clamp(rd.y * 0.5 + 0.5, 0.0, 1.0);
vec3 col = mix(vec3(0.0026, 0.0038, 0.0058), vec3(0.0012, 0.0018, 0.0032), up);
// Subtle circular colosseum gallery tiers & arches
float az = atan(rd.z, rd.x);
float tier1 = smoothstep(0.16, 0.03, abs(rd.y + 0.03));
float tier2 = smoothstep(0.12, 0.02, abs(rd.y - 0.18));
float pillars = 0.5 + 0.5 * cos(az * 24.0);
col += vec3(0.0032, 0.0044, 0.0066) * (tier1 + 0.6 * tier2) * (0.35 + 0.65 * pillars);
// Subtle distant overhead arena spotlights
float spotBand = smoothstep(0.16, 0.04, abs(rd.y - 0.36));
float spots = pow(max(0.0, cos(az * 8.0 + 0.35)), 26.0);
col += vec3(0.032, 0.044, 0.062) * spotBand * spots;
float centerGlow = exp(-length(rd.xy - vec2(0.0, -0.02)) * 3.0);
if (uLightMode == 3) {
col += vec3(0.14, 0.24, 0.38) * pow(centerGlow, 1.3);
} else if (uLightMode == 2) {
col += vec3(0.007, 0.011, 0.018) * centerGlow;
} else {
col += vec3(0.005, 0.011, 0.020) * centerGlow;
}
return col;
}
// --- ACES Filmic Tonemapping ---
vec3 acesTonemap(vec3 x) {
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
vec3 y = clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0.0, 1.0);
return y * 0.965;
}
// --- Surface Shading ---
vec3 shadeSurface(vec3 p, vec3 n, vec3 v, float matID, float tHit) {
float ao = calcAO(p, n);
vec3 keyDir, keyCol, fillDir, fillCol, rimDir, rimCol;
if (uLightMode == 1) {
keyDir = normalize(vec3(0.62, 0.72, 0.52));
keyCol = vec3(1.15);
fillDir = normalize(vec3(-0.75, 0.30, 0.45));
fillCol = vec3(0.36);
rimDir = normalize(vec3(-0.20, 0.55, -0.82));
rimCol = vec3(0.55);
} else if (uLightMode == 2) {
keyDir = normalize(vec3(0.92, 0.22, 0.32));
keyCol = vec3(1.75, 1.52, 1.28);
fillDir = normalize(vec3(-0.70, 0.38, 0.50));
fillCol = vec3(0.12, 0.18, 0.28);
rimDir = normalize(vec3(-0.35, 0.50, -0.80));
rimCol = vec3(0.30, 0.50, 0.78);
} else if (uLightMode == 3) {
keyDir = normalize(vec3(0.18, 0.42, -0.89));
keyCol = vec3(1.65, 1.80, 2.00);
fillDir = normalize(vec3(0.35, 0.45, 0.80));
fillCol = vec3(0.10, 0.15, 0.22);
rimDir = normalize(vec3(-0.28, 0.35, -0.89));
rimCol = vec3(0.95, 1.10, 1.35);
} else {
keyDir = normalize(vec3(0.52, 0.78, 0.48));
keyCol = vec3(0.95, 1.02, 1.18);
fillDir = normalize(vec3(-0.68, 0.35, 0.52));
fillCol = vec3(0.14, 0.22, 0.36);
rimDir = normalize(vec3(-0.25, 0.55, -0.80));
rimCol = vec3(0.45, 0.70, 1.05);
}
float sh = calcShadow(p + n * 0.015, keyDir, 5.5);
float ndl = max(dot(n, keyDir), 0.0);
float ndf = max(dot(n, fillDir), 0.0);
float ndv = max(dot(n, v), 0.0);
float fres = pow(1.0 - ndv, 3.8);
vec3 hKey = normalize(keyDir + v);
vec3 hRim = normalize(rimDir + v);
// --- Mode 1: Pure neutral grayscale clay/form study (R == G == B, emission muted) ---
if (uLightMode == 1) {
float alb = 0.56;
float specPow = 28.0;
float specStr = 0.22;
if (matID < 1.5) {
alb = 0.76; specPow = 72.0; specStr = 0.42;
} else if (matID > 10.5) {
alb = 0.38; specPow = 48.0; specStr = 0.32;
} else if (matID > 4.5) {
alb = 0.44; specPow = 18.0; specStr = 0.12;
} else if (matID < 2.5) {
alb = 0.68; specPow = 42.0; specStr = 0.32;
} else if (matID < 3.5) {
alb = 0.62; specPow = 24.0; specStr = 0.24;
} else {
alb = 0.65; specPow = 32.0; specStr = 0.26;
}
float diff = alb * (ndl * sh * keyCol.x + ndf * fillCol.x + 0.15 * ao);
float spec = pow(max(dot(n, hKey), 0.0), specPow) * specStr * sh;
float rim = fres * (0.26 + 0.48 * max(dot(n, rimDir), 0.0)) * rimCol.x;
return vec3(diff + spec + rim);
}
float emitScale = (uLightMode == 2) ? 0.72 : ((uLightMode == 3) ? 0.85 : 1.0);
vec3 col = vec3(0.0);
// 1. Central Faceted Crystal Core (dramatic dark-sapphire vs dazzling specular facet contrast)
if (matID < 1.5) {
float pulse = 0.90 + 0.10 * sin(gLoop * 2.0);
// Tight razor-thin edge sparkle (not thick white outlines)
vec3 tAxis = normalize(abs(n.y) < 0.9 ? cross(n, vec3(0.0, 1.0, 0.0)) : cross(n, vec3(1.0, 0.0, 0.0)));
vec3 bAxis = cross(n, tAxis);
float edgeCurv = length(n - calcNormal(p + tAxis * 0.0045)) + length(n - calcNormal(p + bAxis * 0.0045));
float bevelGlint = smoothstep(0.18, 0.75, edgeCurv);
// Refracted internal ray for focused heart glow & internal caustic veins
vec3 rIn = refract(-v, n, 1.0 / 1.60);
vec3 pMid = p + rIn * 0.16;
vec3 pFar = p + rIn * 0.32;
// Core glow concentrated toward lower-center heart like 02.png
float coreDist = length((pMid - (gCrysPos - vec3(0.0, 0.06, 0.0))) * vec3(2.2, 1.35, 2.2));
float coreGlow = exp(-coreDist * 5.2) * pulse;
vec3 qFar = pFar - gCrysPos;
qFar.xz = gCrysRot * qFar.xz;
float caustic = pow(abs(sin(qFar.x * 18.0 + qFar.y * 14.0) * cos(qFar.z * 18.0 - qFar.y * 12.0)), 2.2);
float backFacet = smoothstep(-0.07, 0.015, sdCrystal(pFar));
float dispPhase = dot(n, v) * 6.5 + dot(rIn, vec3(1.2, 2.1, -1.6)) * 3.2;
vec3 prism = 0.50 + 0.50 * cos(vec3(0.0, 1.9, 3.8) + dispPhase);
// High-contrast facet shading: deep indigo-sapphire shadow facets vs bright lit facets
vec3 facetBase = mix(vec3(0.015, 0.055, 0.20), vec3(0.12, 0.54, 0.98), pow(ndl, 1.3) * 0.85 + ndf * 0.25);
vec3 internalLight = mix(vec3(0.08, 0.62, 1.00), vec3(0.95, 0.99, 1.00), coreGlow) * (0.12 + 1.85 * coreGlow);
internalLight += prism * (0.32 * caustic + 0.42 * backFacet) * emitScale;
float spec = pow(max(dot(n, hKey), 0.0), 160.0) * 3.0;
float rimSpec = pow(max(dot(n, hRim), 0.0), 72.0) * 1.5;
col = facetBase * (0.50 + 0.50 * ao) + internalLight * emitScale;
col += vec3(0.45, 0.85, 1.00) * fres * 1.15;
col += vec3(0.96, 0.99, 1.00) * (spec * sh + rimSpec + bevelGlint * 0.85);
// Reflected fire & emerald highlights on grazing crystal facets
col += vec3(1.00, 0.36, 0.08) * pow(max(dot(n, normalize(vec3(0.7, 0.1, 0.5))), 0.0), 3.5) * 0.42 * emitScale;
col += vec3(0.10, 0.95, 0.52) * pow(max(-n.y, 0.0), 2.4) * 0.36 * emitScale;
return col;
}
// 2. Sculpted Crashing Translucent Sapphire-Cyan Water Wave (Top Ring)
if (matID < 2.5) {
vec3 q1 = gR1 * (p - gC1);
float th = atan(q1.z, q1.x);
float thSpin = th - 1.0 * gLoop;
vec2 cp1 = vec2(length(q1.xz) - 1.62, q1.y);
// Lacy white seafoam crests via ridged 3D gyroid lace
vec3 foamCoord = vec3(cos(thSpin) * 6.5, sin(thSpin) * 6.5, cp1.y * 12.0 + cp1.x * 9.0);
float lace = fbmLace(foamCoord);
float crestHeight = smoothstep(-0.02, 0.12, cp1.y + 0.05 * n.y);
float foam = smoothstep(0.48, 0.88, lace * 0.72 + crestHeight * 0.48 + fres * 0.25);
// Optical translucency: deep sapphire in thick interior, luminous aqua-cyan at thin edges/backlit
float thinEdge = pow(1.0 - ndv, 2.0);
vec3 refrCol = evalBackdrop(refract(-v, n, 1.0 / 1.333));
vec3 deepWater = vec3(0.015, 0.14, 0.52);
vec3 brightAqua = vec3(0.14, 0.76, 1.00);
vec3 waterBody = mix(deepWater, brightAqua, clamp(thinEdge * 0.75 + crestHeight * 0.45 + ndl * 0.35, 0.0, 1.0));
waterBody = mix(waterBody, refrCol + vec3(0.06, 0.36, 0.82), 0.32 * (1.0 - foam));
// Crisp wet speculars + reflected fiery orange glints on water crests
float spec = pow(max(dot(n, hKey), 0.0), 128.0) * 2.4;
float rimS = pow(max(dot(n, hRim), 0.0), 56.0) * 1.25;
col = waterBody * (0.45 + 0.75 * ndl * sh + 0.35 * emitScale);
col = mix(col, vec3(0.86, 0.97, 1.00) * (0.85 + 0.55 * ndl), foam * 0.86);
col += vec3(0.55, 0.90, 1.00) * fres * 1.05 * emitScale;
col += vec3(0.95, 0.99, 1.00) * (spec * sh + rimS * 0.8);
// Subtle reflected orange fire glow on the underside of the water wave
col += vec3(1.00, 0.40, 0.08) * pow(max(-n.y, 0.0), 2.0) * 0.22 * emitScale;
return col;
}
// 11, 12, 13: Razor-thin dark gunmetal-chrome inner edge accents (NOT bright pastel plastic!)
if (matID > 10.5) {
vec3 elemTint = (matID < 11.5) ? vec3(0.25, 0.78, 1.00) :
(matID < 12.5) ? vec3(1.00, 0.42, 0.06) :
vec3(0.14, 0.96, 0.54);
vec3 darkChrome = vec3(0.018, 0.022, 0.028);
float spec = pow(max(dot(n, hKey), 0.0), 120.0) * 2.2;
float rimS = pow(max(dot(n, hRim), 0.0), 64.0) * 1.1;
col = darkChrome * (ndl * sh * keyCol + ndf * fillCol + 0.18 * ao);
col += elemTint * (fres * 0.65 + 0.08 * emitScale);
col += vec3(0.92, 0.96, 1.00) * (spec * sh + rimS * 0.65);
return col;
}
// 5. Dark Atmospheric Colosseum Arena Floor
float r = length(p.xz);
float a = atan(p.z, p.x);
float grain = vnoise2(p.xz * 7.5) * 0.55 + vnoise2(p.xz * 21.0) * 0.45;
float gLine = smoothstep(0.034, 0.008, min(min(abs(r - 1.15), abs(r - 1.94)), min(abs(r - 2.74), abs(r - 3.62))));
float radLine = smoothstep(0.028, 0.007, abs(sin(a * 6.0)) * r) * smoothstep(1.12, 1.28, r);
vec3 stone = mix(vec3(0.013, 0.017, 0.024), vec3(0.026, 0.032, 0.042), grain);
stone *= (1.0 - 0.55 * max(gLine, radLine * 0.75));
float spec = pow(max(dot(n, hKey), 0.0), 36.0) * (0.22 + 0.28 * grain);
col = stone * (ndl * sh * keyCol + ndf * fillCol + 0.28 * ao);
col += vec3(0.28, 0.36, 0.48) * spec * sh;
// Vivid elemental floor reflections
float emeraldBounce = exp(-abs(r - 1.74) * 1.45) * 0.38;
float crysBounce = exp(-r * 1.15) * 0.22;
float fireBounce = exp(-abs(r - 1.18) * 1.75) * 0.18;
float waterBounce = exp(-abs(r - 1.62) * 1.20) * 0.12;
col += vec3(0.06, 0.94, 0.50) * emeraldBounce * (0.45 + 0.55 * grain) * emitScale;
col += vec3(0.20, 0.78, 1.00) * crysBounce * emitScale;
col += vec3(1.00, 0.34, 0.04) * fireBounce * emitScale;
col += vec3(0.12, 0.54, 1.00) * waterBounce * emitScale;
float fog = 1.0 - exp(-max(tHit - 5.2, 0.0) * 0.16);
col = mix(col, vec3(0.0026, 0.0038, 0.0058), clamp(fog, 0.0, 0.95));
return col;
}
void main() {
setupRig();
vec2 uv = (gl_FragCoord.xy - 0.5 * uResolution.xy) / uResolution.y;
// Camera framing: 0 = hero full framing, 1 = ~2.6x macro close-up
vec3 ro, ta;
float focal;
if (uCamMode == 1) {
ro = vec3(0.38 + 0.08 * sin(gLoop), 0.18 + 0.03 * cos(gLoop), 2.74);
ta = vec3(0.0, 0.02, 0.0);
focal = 1.72;
} else {
ro = vec3(0.12 * sin(gLoop), 0.38 + 0.04 * cos(gLoop), 6.42);
ta = vec3(0.0, -0.06, 0.0);
focal = 1.48;
}
vec3 ww = normalize(ta - ro);
vec3 uu = normalize(cross(ww, vec3(0.0, 1.0, 0.0)));
vec3 vv = cross(uu, ww);
vec3 rd = normalize(uu * uv.x + vv * uv.y + ww * focal);
// Raymarch solid geometry + simultaneous roaring volumetric elemental streams
float t = 0.0;
float tMax = 20.0;
float matID = -1.0;
vec3 volVFX = vec3(0.0);
float trans = 1.0;
bool doVol = (uLightMode != 1);
float volScale = (uLightMode == 2) ? 0.72 : ((uLightMode == 3) ? 0.86 : 1.0);
for (int i = 0; i < 112; i++) {
vec3 p = ro + rd * t;
vec2 h = mapScene(p);
float d = h.x;
if (d < 0.0016) {
matID = h.y;
break;
}
float stepLen = clamp(d, 0.018, 0.38);
if (doVol && t > 0.30 && t < 10.8 && length(p) < 2.95) {
vec4 vfx = evalVolumetricStreams(p, trans);
stepLen = min(stepLen, vfx.w);
volVFX += vfx.rgb * stepLen;
}
t += (d < 0.08) ? min(d, stepLen) : stepLen;
if (t > tMax) break;
}
vec3 col;
if (matID > 0.0) {
vec3 p = ro + rd * t;
vec3 n = calcNormal(p);
col = shadeSurface(p, n, -rd, matID, t);
} else {
col = evalBackdrop(rd);
}
if (doVol) {
// Blend surface with flame transmittance + add roaring volumetric streams & sparks
col = col * mix(1.0, trans, 0.55) + volVFX * volScale;
col += evalElementalSparks(ro, rd, (matID > 0.0) ? t : tMax) * volScale;
}
if (uLightMode == 1) {
float g = acesTonemap(col).x;
g = pow(clamp(g, 0.0, 1.0), 1.0 / 2.2);
fragColor = vec4(vec3(g), 1.0);
} else {
col = acesTonemap(col);
col = max(col, vec3(0.0014, 0.0019, 0.0028));
col = pow(clamp(col, 0.0, 1.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;
// Orbiting Elemental Trinity Rings — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/vfx_animated/lib/02_orbiting_elemental_trinity_rings.glsl (MIT License)
// Drive uTime from GDScript if animating helper functions: material.set_shader_parameter("uTime", Time.get_ticks_msec() * 0.001 * u_speed)
uniform vec2 uResolution = vec2(1024.0, 1024.0);
uniform float uTime = 1.2;
uniform float u_speed : hint_range(0.0, 3.0, 0.05) = 1.0;
uniform float u_tiling : hint_range(0.25, 8.0, 0.25) = 1.0;
uniform vec4 u_tint : source_color = vec4(1.0, 0.722, 0.42, 1.0);
uniform float u_tint_mix : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform float uOpen : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform int uLightMode : hint_range(0, 3, 1) = 0;
uniform int uCamMode : hint_range(0, 1, 1) = 0;
uniform bool u_luma_alpha_key = false;
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
// Exact 3.0s seamless loop state
float gPhase;
float gLoop;
// Ring transforms (world -> ring-local) and centers
mat3 gR1, gR2, gR3;
vec3 gC1, gC2, gC3;
vec3 gCrysPos;
mat2 gCrysRot;
// --- Utility math ---
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
mat3 rotX(float a) {
float c = cos(a), s = sin(a);
return mat3(1.0, 0.0, 0.0,
0.0, c, s,
0.0, -s, c);
}
mat3 rotZ(float a) {
float c = cos(a), s = sin(a);
return mat3( c, s, 0.0,
-s, c, 0.0,
0.0, 0.0, 1.0);
}
float smin(float a, float b, float k) {
float h = max(k - abs(a - b), 0.0) / k;
return min(a, b) - h * h * k * 0.25;
}
float smax(float a, float b, float k) {
return -smin(-a, -b, k);
}
float sdBox2(vec2 p, vec2 b, float r) {
vec2 d = abs(p) - b;
return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - r;
}
float triWave(float x) {
return abs(fract(x / TAU) * 2.0 - 1.0) * 2.0 - 1.0;
}
float hash21(vec2 p) {
p = fract(p * vec2(123.34, 456.21));
p += dot(p, p + 45.32);
return fract(p.x * p.y);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
f = f * f * (3.0 - 2.0 * f);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
}
// Fast 3D Gyroid & Domain-Warped Curl-fBM (zero seams, fast on SwiftShader)
float gyroid(vec3 p) {
return dot(sin(p), cos(p.yzx));
}
float fbmCurl(vec3 p) {
// Domain warp for roaring turbulent curling motion
vec3 w = vec3(
gyroid(p),
gyroid(p + vec3(1.7, 3.1, 2.3)),
gyroid(p - vec3(2.4, 1.3, 3.7))
);
p += 0.45 * w;
float v = 0.0;
float a = 0.54;
const mat3 mRot = mat3(
0.80, 0.48, 0.36,
-0.60, 0.64, 0.48,
0.00, -0.60, 0.80
);
for (int i = 0; i < 3; i++) {
v += a * gyroid(p);
p = mRot * p * 2.05 + vec3(1.3, 2.7, 0.9);
a *= 0.48;
}
return v;
}
// High-frequency lacy foam / filament ridge pattern
float fbmLace(vec3 p) {
float g1 = 1.0 - abs(gyroid(p) * 0.65);
p = p * 2.15 + vec3(1.9, -2.3, 1.1);
float g2 = 1.0 - abs(gyroid(p) * 0.65);
return clamp(g1 * 0.60 + g2 * 0.40, 0.0, 1.0);
}
// --- Frame rig setup (exact 3.0s seamless loop, clean 3D separation at t=1.2) ---
void setupRig() {
gPhase = fract(uTime / 3.0);
gLoop = gPhase * TAU;
gCrysPos = vec3(0.0, 0.02 + 0.045 * sin(gLoop), 0.0);
gCrysRot = rot2(gLoop);
// Ring 1 (Top): Sapphire-cyan crashing water wave ring
gC1 = vec3(0.0, 0.74 + 0.04 * sin(gLoop), 0.0);
float r1x = 0.25 + 0.08 * cos(gLoop);
float r1z = -0.14 + 0.10 * sin(gLoop);
gR1 = rotZ(-r1z) * rotX(r1x);
// Ring 2 (Middle): Blazing crimson-orange volumetric fire ring
gC2 = vec3(0.0, 0.04 + 0.03 * cos(gLoop), 0.0);
float r2x = -0.32 + 0.12 * sin(gLoop);
float r2z = 0.42 - 0.14 * cos(gLoop);
gR2 = rotZ(-r2z) * rotX(r2x);
// Ring 3 (Bottom): Electric emerald-green wind & lightning vortex ring
gC3 = vec3(0.0, -0.80 + 0.04 * sin(gLoop + 2.094395), 0.0);
float r3x = -0.27 - 0.07 * cos(gLoop + 1.047198);
float r3z = 0.15 + 0.10 * sin(gLoop + 1.047198);
gR3 = rotZ(-r3z) * rotX(r3x);
}
// --- Solid & Sculpted Geometry SDFs ---
// Double-terminated faceted hexagonal crystal core
float sdCrystal(vec3 p) {
vec3 q = p - gCrysPos;
q.xz = gCrysRot * q.xz;
float ay = abs(q.y);
const vec2 h1 = vec2(1.0, 0.0);
const vec2 h2 = vec2(0.5, 0.8660254);
const vec2 h3 = vec2(-0.5, 0.8660254);
float hexR = max(abs(dot(q.xz, h1)), max(abs(dot(q.xz, h2)), abs(dot(q.xz, h3))));
vec2 qRot = vec2(q.x * 0.8660254 - q.z * 0.5, q.x * 0.5 + q.z * 0.8660254);
float hexR2 = max(abs(dot(qRot, h1)), max(abs(dot(qRot, h2)), abs(dot(qRot, h3))));
float dPrism = hexR - 0.255;
float dPyr = (hexR * 0.76822 + (ay - 0.255) * 0.64018) - 0.255 * 0.76822;
float dCrown = (hexR2 * 0.83205 + (ay - 0.205) * 0.55470) - 0.266 * 0.83205;
float dBelt = hexR2 - 0.266;
float d = smax(dPrism, dPyr, 0.003);
d = smax(d, dCrown, 0.0025);
d = smax(d, dBelt, 0.0025);
return d;
}
// Ring 1: Razor-thin dark-chrome inner edge (plus sculpted crashing water wave in clay mode)
vec2 sdRing1(vec3 p) {
vec3 q = gR1 * (p - gC1);
float r = length(q.xz);
vec2 cp = vec2(r - 1.62, q.y);
float bound = length(cp) - 0.44;
if (bound > 0.24) return vec2(bound, 11.0);
// Razor-thin dark-chrome inner accent edge
float dRim = sdBox2(cp - vec2(-0.105, -0.020), vec2(0.011, 0.030), 0.004);
if (uLightMode != 1) {
return vec2(dRim, 11.0);
}
// Clay mode: thick sculpted crashing turbulent water wave so form reads cleanly
float th = atan(q.z, q.x);
float thSpin = th - 1.0 * gLoop;
vec3 wCoord = vec3(cos(thSpin) * 2.8, sin(thSpin) * 2.8, cp.y * 4.5 + cp.x * 3.0);
float turb = fbmCurl(wCoord);
float swell = 0.5 + 0.5 * sin(th * 4.0 - 2.0 * gLoop + 0.7 * turb);
vec2 wp = cp - vec2(0.055 + 0.050 * swell + 0.035 * turb, 0.025 + 0.055 * swell + 0.028 * turb);
wp = rot2(-0.26 + 0.16 * swell) * wp;
float dWave = (sdBox2(wp, vec2(0.140 + 0.032 * swell, 0.042 + 0.020 * swell), 0.024) - 0.022 * turb) * 0.52;
if (dRim < dWave) return vec2(dRim, 11.0);
return vec2(dWave, 2.0);
}
// Ring 2: Razor-thin dark-iron inner edge (plus sculpted turbulent flame band in clay mode)
vec2 sdRing2(vec3 p) {
vec3 q = gR2 * (p - gC2);
float r = length(q.xz);
vec2 cp = vec2(r - 1.18, q.y);
float bound = length(cp) - 0.42;
if (bound > 0.22) return vec2(bound, 12.0);
// Subtle razor-thin dark charred-iron inner edge
float dRim = sdBox2(cp - vec2(-0.075, -0.015), vec2(0.009, 0.026), 0.003);
if (uLightMode != 1) {
return vec2(dRim, 12.0);
}
// Clay mode: thick roaring sculpted flame ribbon so form reads cleanly
float th = atan(q.z, q.x);
float thSpin = th + 1.0 * gLoop;
vec3 fCoord = vec3(cos(thSpin) * 3.2, sin(thSpin) * 3.2, cp.y * 5.0);
float turb = fbmCurl(fCoord);
float tongue = pow(0.5 + 0.5 * sin(th * 5.0 + 2.0 * gLoop + 0.9 * turb), 1.6);
vec2 fp = cp - vec2(0.040 + 0.030 * tongue, 0.045 * tongue + 0.025 * turb);
fp = rot2(0.18 - 0.16 * tongue) * fp;
float dFire = (sdBox2(fp, vec2(0.115 + 0.028 * tongue, 0.040 + 0.075 * tongue), 0.018) - 0.024 * turb) * 0.52;
if (dRim < dFire) return vec2(dRim, 12.0);
return vec2(dFire, 3.0);
}
// Ring 3: Razor-thin dark-emerald metallic inner edge (plus sculpted vortex band in clay mode)
vec2 sdRing3(vec3 p) {
vec3 q = gR3 * (p - gC3);
float r = length(q.xz);
vec2 cp = vec2(r - 1.74, q.y);
float bound = length(cp) - 0.42;
if (bound > 0.22) return vec2(bound, 13.0);
float dRim = sdBox2(cp - vec2(-0.105, 0.010), vec2(0.010, 0.028), 0.003);
if (uLightMode != 1) {
return vec2(dRim, 13.0);
}
// Clay mode: thick sculpted swirling wind-vortex band
float th = atan(q.z, q.x);
float thSpin = th - 1.0 * gLoop;
vec3 eCoord = vec3(cos(thSpin) * 3.0, sin(thSpin) * 3.0, cp.y * 4.5 + cp.x * 3.0);
float turb = fbmCurl(eCoord);
float gust = 0.5 + 0.5 * sin(th * 4.0 - 2.0 * gLoop + 0.6 * turb);
vec2 ep = cp - vec2(0.055 + 0.032 * gust, 0.020 * turb);
ep = rot2(0.24 + 0.12 * gust) * ep;
float dWind = (sdBox2(ep, vec2(0.135 + 0.030 * gust, 0.038 + 0.016 * gust), 0.016) - 0.020 * turb) * 0.55;
if (dRim < dWind) return vec2(dRim, 13.0);
return vec2(dWind, 4.0);
}
// Dark stone circular colosseum arena floor with carved concentric rings
float sdFloor(vec3 p) {
float yFloor = -1.82;
float d = p.y - yFloor;
if (d < 0.16) {
float r = length(p.xz);
float a = atan(p.z, p.x);
float g1 = abs(r - 1.15);
float g2 = abs(r - 1.94);
float g3 = abs(r - 2.74);
float g4 = abs(r - 3.62);
float groove = smoothstep(0.034, 0.007, min(min(g1, g2), min(g3, g4)));
float rad = abs(sin(a * 6.0)) * r;
float seam = smoothstep(0.026, 0.006, rad) * smoothstep(1.12, 1.28, r);
d += 0.012 * max(groove, seam * 0.72);
}
return d;
}
vec2 mapScene(vec3 p) {
vec2 res = vec2(sdFloor(p), 5.0);
float dC = sdCrystal(p);
if (dC < res.x) res = vec2(dC, 1.0);
vec2 d1 = sdRing1(p);
if (d1.x < res.x) res = d1;
vec2 d2 = sdRing2(p);
if (d2.x < res.x) res = d2;
vec2 d3 = sdRing3(p);
if (d3.x < res.x) res = d3;
return res;
}
float mapDist(vec3 p) {
float d = sdFloor(p);
d = min(d, sdCrystal(p));
d = min(d, sdRing1(p).x);
d = min(d, sdRing2(p).x);
d = min(d, sdRing3(p).x);
return d;
}
// Unit-sign tetrahedral normal
vec3 calcNormal(vec3 p) {
const float h = 0.0014;
const vec2 k = vec2(1.0, -1.0);
return normalize(
k.xyy * mapDist(p + k.xyy * h) +
k.yyx * mapDist(p + k.yyx * h) +
k.yxy * mapDist(p + k.yxy * h) +
k.xxx * mapDist(p + k.xxx * h)
);
}
// Fast 4-tap ambient occlusion
float calcAO(vec3 p, vec3 n) {
float occ = 0.0;
float sca = 1.0;
for (int i = 0; i < 4; i++) {
float h = 0.03 + 0.085 * float(i);
float d = mapDist(p + n * h);
occ += (h - d) * sca;
sca *= 0.65;
}
return clamp(1.0 - 2.6 * occ, 0.12, 1.0);
}
// Fast soft shadow
float calcShadow(vec3 ro, vec3 rd, float maxT) {
float res = 1.0;
float t = 0.05;
for (int i = 0; i < 24; i++) {
float h = mapDist(ro + rd * t);
res = min(res, 7.0 * h / t);
t += clamp(h, 0.04, 0.35);
if (res < 0.02 || t > maxT) break;
}
return clamp(res, 0.0, 1.0);
}
// --- Roaring Volumetric Elemental Streams (Fire, Lightning/Wind, Water Mist) ---
// Returns vec4(emissiveRGB, desiredMaxStep)
vec4 evalVolumetricStreams(vec3 p, inout float trans) {
vec3 acc = vec3(0.0);
float maxStep = 0.36;
// 1. Compact bright core halo tightly hugging the central crystal
float dC = length(p - gCrysPos);
if (dC < 0.90) {
float pulse = 0.90 + 0.10 * sin(gLoop * 2.0);
acc += vec3(0.16, 0.68, 1.00) * exp(-dC * 6.2) * 0.34 * pulse;
}
// 2. WATER/ICE RING (Top): Translucent crashing sapphire-cyan water wave + lacy white seafoam crests
vec3 q1 = gR1 * (p - gC1);
vec2 cp1 = vec2(length(q1.xz) - 1.62, q1.y);
float d1 = length(cp1);
if (d1 < 0.56) {
maxStep = min(maxStep, (d1 < 0.36) ? 0.024 : 0.044);
float th = atan(q1.z, q1.x);
float thSpin = th - 1.0 * gLoop;
// 3D curled ocean wave turbulence & fine lacy seafoam web
vec3 wCoord = vec3(cos(thSpin) * 3.4, sin(thSpin) * 3.4, cp1.y * 4.8 + cp1.x * 3.4);
float wTurb = fbmCurl(wCoord);
float swell = 0.5 + 0.5 * sin(th * 4.0 - 2.0 * gLoop + 0.85 * wTurb);
// Curling barrel wave cross-section wrapping outside the dark-chrome inner rim
vec2 wp = cp1 - vec2(0.085 + 0.055 * swell + 0.040 * wTurb, 0.025 + 0.065 * swell + 0.032 * wTurb);
wp = rot2(-0.28 + 0.18 * swell) * wp;
float barrelD = length(wp * vec2(1.0, 2.35)) - (0.145 + 0.035 * swell);
// Sculpted translucent liquid body with crisp turbulent wave edges
float liquidEnv = exp(-max(barrelD, 0.0) * 18.0) * smoothstep(-0.11, 0.02, cp1.x);
float waveBody = smoothstep(0.08, 0.72, liquidEnv * (0.78 + 0.52 * wTurb));
// High-frequency lacy white seafoam crests concentrated on upper breaking ridges
vec3 foamCoord = vec3(cos(thSpin) * 7.5, sin(thSpin) * 7.5, cp1.y * 13.0 + cp1.x * 9.5);
float lace = fbmLace(foamCoord);
float crestZone = smoothstep(-0.02, 0.14, cp1.y + 0.06 * swell) * exp(-abs(barrelD) * 26.0);
float foam = pow(lace, 2.6) * (0.35 + 0.65 * crestZone) * smoothstep(-0.06, 0.06, cp1.x);
// Deep cobalt-sapphire translucent interior -> luminous azure-cyan wave sheets -> crisp lacy white foam
vec3 deepCobalt = vec3(0.012, 0.12, 0.58);
vec3 vividAzure = vec3(0.06, 0.58, 1.00);
vec3 seafoam = vec3(0.84, 0.96, 1.00);
float sheet = clamp(0.45 + 0.55 * wTurb + 0.30 * crestZone, 0.0, 1.0);
vec3 wCol = mix(deepCobalt, vividAzure, sheet);
wCol = mix(wCol, seafoam, clamp(foam * 1.15, 0.0, 0.92));
float wEmit = waveBody * (0.85 + 0.95 * sheet) + foam * 2.2;
acc += wCol * wEmit * trans;
// Translucent optical absorption keeps sapphire depth rich instead of milky white
trans *= exp(-waveBody * 0.065);
}
// 3. FIRE RING (Middle): Saturated roaring curled-fBM volumetric fire tongues (crimson -> orange -> amber-gold)
vec3 q2 = gR2 * (p - gC2);
vec2 cp2 = vec2(length(q2.xz) - 1.18, q2.y);
float d2 = length(cp2);
if (d2 < 0.56) {
maxStep = min(maxStep, 0.028);
float th = atan(q2.z, q2.x);
float thSpin = th + 1.0 * gLoop;
// Advected 3D curl-fBM coordinates (roaring swirl + sharp upward-licking tongues)
vec3 fCoord = vec3(cos(thSpin) * 4.0, sin(thSpin) * 4.0, cp2.y * 4.6 - 0.60 * cp2.x);
float turb = fbmCurl(fCoord);
float fine = gyroid(fCoord * 2.6 + vec3(0.0, 2.0 * sin(gLoop), 2.0 * cos(gLoop)));
float yRise = cp2.y + 0.05;
float flameH = 0.22 + 0.22 * (0.5 + 0.5 * turb) + 0.08 * fine;
float yNorm = clamp(yRise / max(flameH, 0.08), 0.0, 1.4);
float radCenter = 0.040 + 0.105 * yNorm + 0.055 * turb * yNorm;
float radHalfW = mix(0.105, 0.028, clamp(yNorm, 0.0, 1.0));
float radD = abs(cp2.x - radCenter) / max(radHalfW, 0.02);
float baseEnv = smoothstep(-0.07, 0.03, yRise) * smoothstep(1.22, 0.12, yNorm) * exp(-radD * radD * 1.75);
// Sharp sculpted flame tongues with crisp turbulent dark cutouts (zero milky haze!)
float dens = smoothstep(0.16, 0.78, baseEnv * (0.85 + 0.75 * turb + 0.32 * fine));
// Tight molten core strictly along the inner iron rim
float coreBand = exp(-length(cp2 - vec2(0.022, 0.008)) * 24.0) * (0.65 + 0.35 * turb);
// Hyper-saturated blackbody fire ramp (reserves white-gold ONLY for tiny inner core so ACES stays rich!)
float temp = clamp(1.0 - yNorm * 1.05 + 0.28 * coreBand + 0.16 * fine, 0.0, 1.0);
vec3 fCol = mix(vec3(0.72, 0.025, 0.004), vec3(1.00, 0.22, 0.010), smoothstep(0.08, 0.52, temp));
fCol = mix(fCol, vec3(1.00, 0.60, 0.05), smoothstep(0.54, 0.86, temp));
fCol = mix(fCol, vec3(1.00, 0.90, 0.42), smoothstep(0.88, 0.99, temp));
float emit = (dens * 2.25 + coreBand * 1.15);
acc += fCol * emit * trans;
trans *= exp(-dens * 0.095);
}
// 4. WIND / LIGHTNING RING: Thick turbulent emerald wind vortex + 5 razor-sharp branching electric arcs
vec3 q3 = gR3 * (p - gC3);
vec2 cp3 = vec2(length(q3.xz) - 1.74, q3.y);
float d3 = length(cp3);
if (d3 < 0.54) {
// Fine adaptive step so rays NEVER skip over razor-thin lightning bolts!
maxStep = min(maxStep, (d3 < 0.34) ? 0.019 : 0.042);
float th = atan(q3.z, q3.x);
float thSpin = th - 2.0 * gLoop;
// Thick roaring translucent emerald-jade swirling wind vortex ribbon
vec3 wCoord = vec3(cos(thSpin) * 3.2, sin(thSpin) * 3.2, cp3.y * 5.2 + cp3.x * 3.5);
float wTurb = fbmCurl(wCoord);
vec2 wp3 = cp3 - vec2(0.075 + 0.035 * wTurb, 0.025 * wTurb);
wp3 = rot2(0.22) * wp3;
float vortexEnv = exp(-length(wp3 * vec2(1.0, 2.3)) * 8.5) * smoothstep(-0.10, 0.04, cp3.x);
float windStreaks = smoothstep(-0.25, 0.75, wTurb + 0.35 * sin(th * 9.0 - 3.0 * gLoop + cp3.x * 16.0));
vec3 vortexCol = mix(vec3(0.02, 0.44, 0.24), vec3(0.14, 0.95, 0.56), windStreaks);
acc += vortexCol * vortexEnv * (0.75 + 1.35 * windStreaks) * 1.45;
// 5 dense, razor-sharp crackling & branching electric lightning bolts!
// Bolt 1: Primary high-voltage jagged arc wrapping 360 deg
vec2 b1 = vec2(
0.055 + 0.105 * triWave(th * 6.0 - 3.0 * gLoop) + 0.048 * triWave(th * 17.0 + 4.0 * gLoop) + 0.020 * triWave(th * 35.0 - 5.0 * gLoop),
0.010 + 0.090 * triWave(th * 8.0 - 3.0 * gLoop + 1.1) + 0.038 * triWave(th * 21.0 - 4.0 * gLoop) + 0.016 * triWave(th * 43.0 + 3.0 * gLoop)
);
float db1 = length(cp3 - b1);
float m1 = 0.45 + 0.55 * smoothstep(-0.35, 0.45, sin(th * 2.0 - gLoop) + 0.45 * sin(th * 5.0 + 2.0 * gLoop));
acc += (vec3(0.92, 1.00, 0.97) * exp(-db1 * 76.0) * 9.5 +
vec3(0.08, 1.00, 0.52) * exp(-db1 * 20.0) * 1.85) * m1;
// Bolt 2: Secondary counter-winding jagged arc
vec2 b2 = vec2(
0.085 - 0.095 * triWave(th * 7.0 + 2.0 * gLoop + 0.7) + 0.042 * triWave(th * 19.0 - 3.0 * gLoop) + 0.018 * triWave(th * 39.0 + 5.0 * gLoop),
-0.015 - 0.075 * triWave(th * 10.0 + 2.0 * gLoop) + 0.034 * triWave(th * 23.0 + 4.0 * gLoop)
);
float db2 = length(cp3 - b2);
float m2 = 0.40 + 0.60 * smoothstep(-0.25, 0.50, cos(th * 3.0 - 2.0 * gLoop) + 0.35 * sin(th * 7.0 - gLoop));
acc += (vec3(0.88, 1.00, 0.95) * exp(-db2 * 74.0) * 8.5 +
vec3(0.06, 0.98, 0.50) * exp(-db2 * 19.0) * 1.65) * m2;
// Bolt 3: Outer crackling fork leaping outward
vec2 b3 = vec2(
0.185 + 0.110 * triWave(th * 11.0 - 4.0 * gLoop) + 0.045 * triWave(th * 27.0 + 5.0 * gLoop),
0.065 * triWave(th * 13.0 - 3.0 * gLoop + 2.2) + 0.028 * triWave(th * 31.0 - 4.0 * gLoop)
);
float db3 = length(cp3 - b3);
float m3 = pow(max(0.0, sin(th * 3.0 - 2.0 * gLoop + 0.6)), 1.8);
acc += (vec3(0.94, 1.00, 0.97) * exp(-db3 * 82.0) * 8.0 +
vec3(0.10, 1.00, 0.56) * exp(-db3 * 22.0) * 1.35) * m3;
// Bolt 4: Tight inner high-frequency arc snapping off the inner rim
vec2 b4 = vec2(
-0.025 + 0.060 * triWave(th * 13.0 + 3.0 * gLoop) + 0.025 * triWave(th * 29.0 - 4.0 * gLoop),
0.045 * triWave(th * 9.0 + 3.0 * gLoop + 1.7)
);
float db4 = length(cp3 - b4);
float m4 = pow(max(0.0, cos(th * 4.0 + gLoop - 0.5)), 2.0);
acc += (vec3(0.90, 1.00, 0.96) * exp(-db4 * 85.0) * 7.2 +
vec3(0.12, 1.00, 0.60) * exp(-db4 * 24.0) * 1.20) * m4;
}
return vec4(acc, maxStep);
}
// --- Flying elemental sparks, embers & water spray droplets (36 analytical 3D streaks) ---
vec3 evalElementalSparks(vec3 ro, vec3 rd, float maxT) {
vec3 col = vec3(0.0);
for (int i = 0; i < 36; i++) {
float fi = float(i);
int family = i % 3; // 0=fire ember, 1=water spray droplet, 2=lightning spark
float seed = fi * 1.6180339;
float speed = (family == 0) ? 1.0 : ((family == 1) ? -1.0 : 2.0);
float ang = fract(seed) * TAU + speed * gLoop;
float rad = (family == 1) ? (1.42 + 0.68 * fract(seed * 3.17)) :
(family == 0) ? (1.05 + 1.15 * fract(seed * 3.17)) :
(1.45 + 0.95 * fract(seed * 3.17));
float yBase = (family == 1) ? (0.68 + 0.58 * sin(seed * 7.3)) :
(family == 0) ? (0.14 + 0.85 * cos(seed * 5.1)) :
(-0.78 + 0.60 * sin(seed * 9.7));
float yPos = yBase + 0.16 * sin(gLoop + seed * TAU);
vec3 sp = vec3(cos(ang) * rad, yPos, sin(ang) * rad);
vec3 tang = normalize(vec3(-sin(ang) * speed, 0.14 * cos(gLoop + seed * TAU), cos(ang) * speed));
vec3 w = sp - ro;
float tRay = dot(w, rd);
if (tRay < 0.25 || tRay > maxT) continue;
vec3 closest = ro + rd * tRay;
vec3 diff = closest - sp;
float streakLen = (family == 1) ? 0.022 : 0.085; // crisp droplets for water, streaks for embers/sparks
float along = clamp(dot(diff, tang), -streakLen, streakLen);
float d = length(diff - tang * along);
float core = exp(-d * 98.0);
float halo = exp(-d * 24.0) * 0.18;
float twinkle = 0.60 + 0.40 * sin(gLoop * 3.0 + fi * 2.7);
vec3 sCol = (family == 0) ? vec3(1.00, 0.54, 0.12) :
(family == 1) ? vec3(0.65, 0.94, 1.00) :
vec3(0.45, 1.00, 0.72);
col += sCol * (core * 1.65 + halo) * twinkle;
}
return col;
}
// --- Dark moody colosseum arena backdrop ---
vec3 evalBackdrop(vec3 rd) {
if (uLightMode == 1) {
float grad = 0.22 + 0.12 * clamp(rd.y * 0.8 + 0.5, 0.0, 1.0);
return vec3(grad);
}
float up = clamp(rd.y * 0.5 + 0.5, 0.0, 1.0);
vec3 col = mix(vec3(0.0026, 0.0038, 0.0058), vec3(0.0012, 0.0018, 0.0032), up);
// Subtle circular colosseum gallery tiers & arches
float az = atan(rd.z, rd.x);
float tier1 = smoothstep(0.16, 0.03, abs(rd.y + 0.03));
float tier2 = smoothstep(0.12, 0.02, abs(rd.y - 0.18));
float pillars = 0.5 + 0.5 * cos(az * 24.0);
col += vec3(0.0032, 0.0044, 0.0066) * (tier1 + 0.6 * tier2) * (0.35 + 0.65 * pillars);
// Subtle distant overhead arena spotlights
float spotBand = smoothstep(0.16, 0.04, abs(rd.y - 0.36));
float spots = pow(max(0.0, cos(az * 8.0 + 0.35)), 26.0);
col += vec3(0.032, 0.044, 0.062) * spotBand * spots;
float centerGlow = exp(-length(rd.xy - vec2(0.0, -0.02)) * 3.0);
if (uLightMode == 3) {
col += vec3(0.14, 0.24, 0.38) * pow(centerGlow, 1.3);
} else if (uLightMode == 2) {
col += vec3(0.007, 0.011, 0.018) * centerGlow;
} else {
col += vec3(0.005, 0.011, 0.020) * centerGlow;
}
return col;
}
// --- ACES Filmic Tonemapping ---
vec3 acesTonemap(vec3 x) {
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
vec3 y = clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0.0, 1.0);
return y * 0.965;
}
// --- Surface Shading ---
vec3 shadeSurface(vec3 p, vec3 n, vec3 v, float matID, float tHit) {
float ao = calcAO(p, n);
vec3 keyDir, keyCol, fillDir, fillCol, rimDir, rimCol;
if (uLightMode == 1) {
keyDir = normalize(vec3(0.62, 0.72, 0.52));
keyCol = vec3(1.15);
fillDir = normalize(vec3(-0.75, 0.30, 0.45));
fillCol = vec3(0.36);
rimDir = normalize(vec3(-0.20, 0.55, -0.82));
rimCol = vec3(0.55);
} else if (uLightMode == 2) {
keyDir = normalize(vec3(0.92, 0.22, 0.32));
keyCol = vec3(1.75, 1.52, 1.28);
fillDir = normalize(vec3(-0.70, 0.38, 0.50));
fillCol = vec3(0.12, 0.18, 0.28);
rimDir = normalize(vec3(-0.35, 0.50, -0.80));
rimCol = vec3(0.30, 0.50, 0.78);
} else if (uLightMode == 3) {
keyDir = normalize(vec3(0.18, 0.42, -0.89));
keyCol = vec3(1.65, 1.80, 2.00);
fillDir = normalize(vec3(0.35, 0.45, 0.80));
fillCol = vec3(0.10, 0.15, 0.22);
rimDir = normalize(vec3(-0.28, 0.35, -0.89));
rimCol = vec3(0.95, 1.10, 1.35);
} else {
keyDir = normalize(vec3(0.52, 0.78, 0.48));
keyCol = vec3(0.95, 1.02, 1.18);
fillDir = normalize(vec3(-0.68, 0.35, 0.52));
fillCol = vec3(0.14, 0.22, 0.36);
rimDir = normalize(vec3(-0.25, 0.55, -0.80));
rimCol = vec3(0.45, 0.70, 1.05);
}
float sh = calcShadow(p + n * 0.015, keyDir, 5.5);
float ndl = max(dot(n, keyDir), 0.0);
float ndf = max(dot(n, fillDir), 0.0);
float ndv = max(dot(n, v), 0.0);
float fres = pow(1.0 - ndv, 3.8);
vec3 hKey = normalize(keyDir + v);
vec3 hRim = normalize(rimDir + v);
// --- Mode 1: Pure neutral grayscale clay/form study (R == G == B, emission muted) ---
if (uLightMode == 1) {
float alb = 0.56;
float specPow = 28.0;
float specStr = 0.22;
if (matID < 1.5) {
alb = 0.76; specPow = 72.0; specStr = 0.42;
} else if (matID > 10.5) {
alb = 0.38; specPow = 48.0; specStr = 0.32;
} else if (matID > 4.5) {
alb = 0.44; specPow = 18.0; specStr = 0.12;
} else if (matID < 2.5) {
alb = 0.68; specPow = 42.0; specStr = 0.32;
} else if (matID < 3.5) {
alb = 0.62; specPow = 24.0; specStr = 0.24;
} else {
alb = 0.65; specPow = 32.0; specStr = 0.26;
}
float diff = alb * (ndl * sh * keyCol.x + ndf * fillCol.x + 0.15 * ao);
float spec = pow(max(dot(n, hKey), 0.0), specPow) * specStr * sh;
float rim = fres * (0.26 + 0.48 * max(dot(n, rimDir), 0.0)) * rimCol.x;
return vec3(diff + spec + rim);
}
float emitScale = (uLightMode == 2) ? 0.72 : ((uLightMode == 3) ? 0.85 : 1.0);
vec3 col = vec3(0.0);
// 1. Central Faceted Crystal Core (dramatic dark-sapphire vs dazzling specular facet contrast)
if (matID < 1.5) {
float pulse = 0.90 + 0.10 * sin(gLoop * 2.0);
// Tight razor-thin edge sparkle (not thick white outlines)
vec3 tAxis = normalize(abs(n.y) < 0.9 ? cross(n, vec3(0.0, 1.0, 0.0)) : cross(n, vec3(1.0, 0.0, 0.0)));
vec3 bAxis = cross(n, tAxis);
float edgeCurv = length(n - calcNormal(p + tAxis * 0.0045)) + length(n - calcNormal(p + bAxis * 0.0045));
float bevelGlint = smoothstep(0.18, 0.75, edgeCurv);
// Refracted internal ray for focused heart glow & internal caustic veins
vec3 rIn = refract(-v, n, 1.0 / 1.60);
vec3 pMid = p + rIn * 0.16;
vec3 pFar = p + rIn * 0.32;
// Core glow concentrated toward lower-center heart like 02.png
float coreDist = length((pMid - (gCrysPos - vec3(0.0, 0.06, 0.0))) * vec3(2.2, 1.35, 2.2));
float coreGlow = exp(-coreDist * 5.2) * pulse;
vec3 qFar = pFar - gCrysPos;
qFar.xz = gCrysRot * qFar.xz;
float caustic = pow(abs(sin(qFar.x * 18.0 + qFar.y * 14.0) * cos(qFar.z * 18.0 - qFar.y * 12.0)), 2.2);
float backFacet = smoothstep(-0.07, 0.015, sdCrystal(pFar));
float dispPhase = dot(n, v) * 6.5 + dot(rIn, vec3(1.2, 2.1, -1.6)) * 3.2;
vec3 prism = 0.50 + 0.50 * cos(vec3(0.0, 1.9, 3.8) + dispPhase);
// High-contrast facet shading: deep indigo-sapphire shadow facets vs bright lit facets
vec3 facetBase = mix(vec3(0.015, 0.055, 0.20), vec3(0.12, 0.54, 0.98), pow(ndl, 1.3) * 0.85 + ndf * 0.25);
vec3 internalLight = mix(vec3(0.08, 0.62, 1.00), vec3(0.95, 0.99, 1.00), coreGlow) * (0.12 + 1.85 * coreGlow);
internalLight += prism * (0.32 * caustic + 0.42 * backFacet) * emitScale;
float spec = pow(max(dot(n, hKey), 0.0), 160.0) * 3.0;
float rimSpec = pow(max(dot(n, hRim), 0.0), 72.0) * 1.5;
col = facetBase * (0.50 + 0.50 * ao) + internalLight * emitScale;
col += vec3(0.45, 0.85, 1.00) * fres * 1.15;
col += vec3(0.96, 0.99, 1.00) * (spec * sh + rimSpec + bevelGlint * 0.85);
// Reflected fire & emerald highlights on grazing crystal facets
col += vec3(1.00, 0.36, 0.08) * pow(max(dot(n, normalize(vec3(0.7, 0.1, 0.5))), 0.0), 3.5) * 0.42 * emitScale;
col += vec3(0.10, 0.95, 0.52) * pow(max(-n.y, 0.0), 2.4) * 0.36 * emitScale;
return col;
}
// 2. Sculpted Crashing Translucent Sapphire-Cyan Water Wave (Top Ring)
if (matID < 2.5) {
vec3 q1 = gR1 * (p - gC1);
float th = atan(q1.z, q1.x);
float thSpin = th - 1.0 * gLoop;
vec2 cp1 = vec2(length(q1.xz) - 1.62, q1.y);
// Lacy white seafoam crests via ridged 3D gyroid lace
vec3 foamCoord = vec3(cos(thSpin) * 6.5, sin(thSpin) * 6.5, cp1.y * 12.0 + cp1.x * 9.0);
float lace = fbmLace(foamCoord);
float crestHeight = smoothstep(-0.02, 0.12, cp1.y + 0.05 * n.y);
float foam = smoothstep(0.48, 0.88, lace * 0.72 + crestHeight * 0.48 + fres * 0.25);
// Optical translucency: deep sapphire in thick interior, luminous aqua-cyan at thin edges/backlit
float thinEdge = pow(1.0 - ndv, 2.0);
vec3 refrCol = evalBackdrop(refract(-v, n, 1.0 / 1.333));
vec3 deepWater = vec3(0.015, 0.14, 0.52);
vec3 brightAqua = vec3(0.14, 0.76, 1.00);
vec3 waterBody = mix(deepWater, brightAqua, clamp(thinEdge * 0.75 + crestHeight * 0.45 + ndl * 0.35, 0.0, 1.0));
waterBody = mix(waterBody, refrCol + vec3(0.06, 0.36, 0.82), 0.32 * (1.0 - foam));
// Crisp wet speculars + reflected fiery orange glints on water crests
float spec = pow(max(dot(n, hKey), 0.0), 128.0) * 2.4;
float rimS = pow(max(dot(n, hRim), 0.0), 56.0) * 1.25;
col = waterBody * (0.45 + 0.75 * ndl * sh + 0.35 * emitScale);
col = mix(col, vec3(0.86, 0.97, 1.00) * (0.85 + 0.55 * ndl), foam * 0.86);
col += vec3(0.55, 0.90, 1.00) * fres * 1.05 * emitScale;
col += vec3(0.95, 0.99, 1.00) * (spec * sh + rimS * 0.8);
// Subtle reflected orange fire glow on the underside of the water wave
col += vec3(1.00, 0.40, 0.08) * pow(max(-n.y, 0.0), 2.0) * 0.22 * emitScale;
return col;
}
// 11, 12, 13: Razor-thin dark gunmetal-chrome inner edge accents (NOT bright pastel plastic!)
if (matID > 10.5) {
vec3 elemTint = (matID < 11.5) ? vec3(0.25, 0.78, 1.00) :
(matID < 12.5) ? vec3(1.00, 0.42, 0.06) :
vec3(0.14, 0.96, 0.54);
vec3 darkChrome = vec3(0.018, 0.022, 0.028);
float spec = pow(max(dot(n, hKey), 0.0), 120.0) * 2.2;
float rimS = pow(max(dot(n, hRim), 0.0), 64.0) * 1.1;
col = darkChrome * (ndl * sh * keyCol + ndf * fillCol + 0.18 * ao);
col += elemTint * (fres * 0.65 + 0.08 * emitScale);
col += vec3(0.92, 0.96, 1.00) * (spec * sh + rimS * 0.65);
return col;
}
// 5. Dark Atmospheric Colosseum Arena Floor
float r = length(p.xz);
float a = atan(p.z, p.x);
float grain = vnoise2(p.xz * 7.5) * 0.55 + vnoise2(p.xz * 21.0) * 0.45;
float gLine = smoothstep(0.034, 0.008, min(min(abs(r - 1.15), abs(r - 1.94)), min(abs(r - 2.74), abs(r - 3.62))));
float radLine = smoothstep(0.028, 0.007, abs(sin(a * 6.0)) * r) * smoothstep(1.12, 1.28, r);
vec3 stone = mix(vec3(0.013, 0.017, 0.024), vec3(0.026, 0.032, 0.042), grain);
stone *= (1.0 - 0.55 * max(gLine, radLine * 0.75));
float spec = pow(max(dot(n, hKey), 0.0), 36.0) * (0.22 + 0.28 * grain);
col = stone * (ndl * sh * keyCol + ndf * fillCol + 0.28 * ao);
col += vec3(0.28, 0.36, 0.48) * spec * sh;
// Vivid elemental floor reflections
float emeraldBounce = exp(-abs(r - 1.74) * 1.45) * 0.38;
float crysBounce = exp(-r * 1.15) * 0.22;
float fireBounce = exp(-abs(r - 1.18) * 1.75) * 0.18;
float waterBounce = exp(-abs(r - 1.62) * 1.20) * 0.12;
col += vec3(0.06, 0.94, 0.50) * emeraldBounce * (0.45 + 0.55 * grain) * emitScale;
col += vec3(0.20, 0.78, 1.00) * crysBounce * emitScale;
col += vec3(1.00, 0.34, 0.04) * fireBounce * emitScale;
col += vec3(0.12, 0.54, 1.00) * waterBounce * emitScale;
float fog = 1.0 - exp(-max(tHit - 5.2, 0.0) * 0.16);
col = mix(col, vec3(0.0026, 0.0038, 0.0058), clamp(fog, 0.0, 0.95));
return col;
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
setupRig();
vec2 uv = (pfx_frag_xy - 0.5 * uResolution.xy) / uResolution.y;
// Camera framing: 0 = hero full framing, 1 = ~2.6x macro close-up
vec3 ro, ta;
float focal;
if (uCamMode == 1) {
ro = vec3(0.38 + 0.08 * sin(gLoop), 0.18 + 0.03 * cos(gLoop), 2.74);
ta = vec3(0.0, 0.02, 0.0);
focal = 1.72;
} else {
ro = vec3(0.12 * sin(gLoop), 0.38 + 0.04 * cos(gLoop), 6.42);
ta = vec3(0.0, -0.06, 0.0);
focal = 1.48;
}
vec3 ww = normalize(ta - ro);
vec3 uu = normalize(cross(ww, vec3(0.0, 1.0, 0.0)));
vec3 vv = cross(uu, ww);
vec3 rd = normalize(uu * uv.x + vv * uv.y + ww * focal);
// Raymarch solid geometry + simultaneous roaring volumetric elemental streams
float t = 0.0;
float tMax = 20.0;
float matID = -1.0;
vec3 volVFX = vec3(0.0);
float trans = 1.0;
bool doVol = (uLightMode != 1);
float volScale = (uLightMode == 2) ? 0.72 : ((uLightMode == 3) ? 0.86 : 1.0);
for (int i = 0; i < 112; i++) {
vec3 p = ro + rd * t;
vec2 h = mapScene(p);
float d = h.x;
if (d < 0.0016) {
matID = h.y;
break;
}
float stepLen = clamp(d, 0.018, 0.38);
if (doVol && t > 0.30 && t < 10.8 && length(p) < 2.95) {
vec4 vfx = evalVolumetricStreams(p, trans);
stepLen = min(stepLen, vfx.w);
volVFX += vfx.rgb * stepLen;
}
t += (d < 0.08) ? min(d, stepLen) : stepLen;
if (t > tMax) break;
}
vec3 col;
if (matID > 0.0) {
vec3 p = ro + rd * t;
vec3 n = calcNormal(p);
col = shadeSurface(p, n, -rd, matID, t);
} else {
col = evalBackdrop(rd);
}
if (doVol) {
// Blend surface with flame transmittance + add roaring volumetric streams & sparks
col = col * mix(1.0, trans, 0.55) + volVFX * volScale;
col += evalElementalSparks(ro, rd, (matID > 0.0) ? t : tMax) * volScale;
}
if (uLightMode == 1) {
float g = acesTonemap(col).x;
g = pow(clamp(g, 0.0, 1.0), 1.0 / 2.2);
fragColor = vec4(vec3(g), 1.0);
} else {
col = acesTonemap(col);
col = max(col, vec3(0.0014, 0.0019, 0.0028));
col = pow(clamp(col, 0.0, 1.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;
// Orbiting Elemental Trinity Rings — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/vfx_animated/lib/02_orbiting_elemental_trinity_rings.glsl (MIT License)
// Drive uTime from GDScript if animating helper functions: material.set_shader_parameter("uTime", Time.get_ticks_msec() * 0.001 * u_speed)
uniform vec2 uResolution = vec2(1024.0, 1024.0);
uniform float uTime = 1.2;
uniform float u_speed : hint_range(0.0, 3.0, 0.05) = 1.0;
uniform float u_tiling : hint_range(0.25, 8.0, 0.25) = 1.0;
uniform vec4 u_tint : source_color = vec4(1.0, 0.722, 0.42, 1.0);
uniform float u_tint_mix : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform float uOpen : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform int uLightMode : hint_range(0, 3, 1) = 0;
uniform int uCamMode : hint_range(0, 1, 1) = 0;
uniform bool u_luma_alpha_key = false;
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
// Exact 3.0s seamless loop state
float gPhase;
float gLoop;
// Ring transforms (world -> ring-local) and centers
mat3 gR1, gR2, gR3;
vec3 gC1, gC2, gC3;
vec3 gCrysPos;
mat2 gCrysRot;
// --- Utility math ---
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
mat3 rotX(float a) {
float c = cos(a), s = sin(a);
return mat3(1.0, 0.0, 0.0,
0.0, c, s,
0.0, -s, c);
}
mat3 rotZ(float a) {
float c = cos(a), s = sin(a);
return mat3( c, s, 0.0,
-s, c, 0.0,
0.0, 0.0, 1.0);
}
float smin(float a, float b, float k) {
float h = max(k - abs(a - b), 0.0) / k;
return min(a, b) - h * h * k * 0.25;
}
float smax(float a, float b, float k) {
return -smin(-a, -b, k);
}
float sdBox2(vec2 p, vec2 b, float r) {
vec2 d = abs(p) - b;
return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - r;
}
float triWave(float x) {
return abs(fract(x / TAU) * 2.0 - 1.0) * 2.0 - 1.0;
}
float hash21(vec2 p) {
p = fract(p * vec2(123.34, 456.21));
p += dot(p, p + 45.32);
return fract(p.x * p.y);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
f = f * f * (3.0 - 2.0 * f);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
}
// Fast 3D Gyroid & Domain-Warped Curl-fBM (zero seams, fast on SwiftShader)
float gyroid(vec3 p) {
return dot(sin(p), cos(p.yzx));
}
float fbmCurl(vec3 p) {
// Domain warp for roaring turbulent curling motion
vec3 w = vec3(
gyroid(p),
gyroid(p + vec3(1.7, 3.1, 2.3)),
gyroid(p - vec3(2.4, 1.3, 3.7))
);
p += 0.45 * w;
float v = 0.0;
float a = 0.54;
const mat3 mRot = mat3(
0.80, 0.48, 0.36,
-0.60, 0.64, 0.48,
0.00, -0.60, 0.80
);
for (int i = 0; i < 3; i++) {
v += a * gyroid(p);
p = mRot * p * 2.05 + vec3(1.3, 2.7, 0.9);
a *= 0.48;
}
return v;
}
// High-frequency lacy foam / filament ridge pattern
float fbmLace(vec3 p) {
float g1 = 1.0 - abs(gyroid(p) * 0.65);
p = p * 2.15 + vec3(1.9, -2.3, 1.1);
float g2 = 1.0 - abs(gyroid(p) * 0.65);
return clamp(g1 * 0.60 + g2 * 0.40, 0.0, 1.0);
}
// --- Frame rig setup (exact 3.0s seamless loop, clean 3D separation at t=1.2) ---
void setupRig() {
gPhase = fract(uTime / 3.0);
gLoop = gPhase * TAU;
gCrysPos = vec3(0.0, 0.02 + 0.045 * sin(gLoop), 0.0);
gCrysRot = rot2(gLoop);
// Ring 1 (Top): Sapphire-cyan crashing water wave ring
gC1 = vec3(0.0, 0.74 + 0.04 * sin(gLoop), 0.0);
float r1x = 0.25 + 0.08 * cos(gLoop);
float r1z = -0.14 + 0.10 * sin(gLoop);
gR1 = rotZ(-r1z) * rotX(r1x);
// Ring 2 (Middle): Blazing crimson-orange volumetric fire ring
gC2 = vec3(0.0, 0.04 + 0.03 * cos(gLoop), 0.0);
float r2x = -0.32 + 0.12 * sin(gLoop);
float r2z = 0.42 - 0.14 * cos(gLoop);
gR2 = rotZ(-r2z) * rotX(r2x);
// Ring 3 (Bottom): Electric emerald-green wind & lightning vortex ring
gC3 = vec3(0.0, -0.80 + 0.04 * sin(gLoop + 2.094395), 0.0);
float r3x = -0.27 - 0.07 * cos(gLoop + 1.047198);
float r3z = 0.15 + 0.10 * sin(gLoop + 1.047198);
gR3 = rotZ(-r3z) * rotX(r3x);
}
// --- Solid & Sculpted Geometry SDFs ---
// Double-terminated faceted hexagonal crystal core
float sdCrystal(vec3 p) {
vec3 q = p - gCrysPos;
q.xz = gCrysRot * q.xz;
float ay = abs(q.y);
const vec2 h1 = vec2(1.0, 0.0);
const vec2 h2 = vec2(0.5, 0.8660254);
const vec2 h3 = vec2(-0.5, 0.8660254);
float hexR = max(abs(dot(q.xz, h1)), max(abs(dot(q.xz, h2)), abs(dot(q.xz, h3))));
vec2 qRot = vec2(q.x * 0.8660254 - q.z * 0.5, q.x * 0.5 + q.z * 0.8660254);
float hexR2 = max(abs(dot(qRot, h1)), max(abs(dot(qRot, h2)), abs(dot(qRot, h3))));
float dPrism = hexR - 0.255;
float dPyr = (hexR * 0.76822 + (ay - 0.255) * 0.64018) - 0.255 * 0.76822;
float dCrown = (hexR2 * 0.83205 + (ay - 0.205) * 0.55470) - 0.266 * 0.83205;
float dBelt = hexR2 - 0.266;
float d = smax(dPrism, dPyr, 0.003);
d = smax(d, dCrown, 0.0025);
d = smax(d, dBelt, 0.0025);
return d;
}
// Ring 1: Razor-thin dark-chrome inner edge (plus sculpted crashing water wave in clay mode)
vec2 sdRing1(vec3 p) {
vec3 q = gR1 * (p - gC1);
float r = length(q.xz);
vec2 cp = vec2(r - 1.62, q.y);
float bound = length(cp) - 0.44;
if (bound > 0.24) return vec2(bound, 11.0);
// Razor-thin dark-chrome inner accent edge
float dRim = sdBox2(cp - vec2(-0.105, -0.020), vec2(0.011, 0.030), 0.004);
if (uLightMode != 1) {
return vec2(dRim, 11.0);
}
// Clay mode: thick sculpted crashing turbulent water wave so form reads cleanly
float th = atan(q.z, q.x);
float thSpin = th - 1.0 * gLoop;
vec3 wCoord = vec3(cos(thSpin) * 2.8, sin(thSpin) * 2.8, cp.y * 4.5 + cp.x * 3.0);
float turb = fbmCurl(wCoord);
float swell = 0.5 + 0.5 * sin(th * 4.0 - 2.0 * gLoop + 0.7 * turb);
vec2 wp = cp - vec2(0.055 + 0.050 * swell + 0.035 * turb, 0.025 + 0.055 * swell + 0.028 * turb);
wp = rot2(-0.26 + 0.16 * swell) * wp;
float dWave = (sdBox2(wp, vec2(0.140 + 0.032 * swell, 0.042 + 0.020 * swell), 0.024) - 0.022 * turb) * 0.52;
if (dRim < dWave) return vec2(dRim, 11.0);
return vec2(dWave, 2.0);
}
// Ring 2: Razor-thin dark-iron inner edge (plus sculpted turbulent flame band in clay mode)
vec2 sdRing2(vec3 p) {
vec3 q = gR2 * (p - gC2);
float r = length(q.xz);
vec2 cp = vec2(r - 1.18, q.y);
float bound = length(cp) - 0.42;
if (bound > 0.22) return vec2(bound, 12.0);
// Subtle razor-thin dark charred-iron inner edge
float dRim = sdBox2(cp - vec2(-0.075, -0.015), vec2(0.009, 0.026), 0.003);
if (uLightMode != 1) {
return vec2(dRim, 12.0);
}
// Clay mode: thick roaring sculpted flame ribbon so form reads cleanly
float th = atan(q.z, q.x);
float thSpin = th + 1.0 * gLoop;
vec3 fCoord = vec3(cos(thSpin) * 3.2, sin(thSpin) * 3.2, cp.y * 5.0);
float turb = fbmCurl(fCoord);
float tongue = pow(0.5 + 0.5 * sin(th * 5.0 + 2.0 * gLoop + 0.9 * turb), 1.6);
vec2 fp = cp - vec2(0.040 + 0.030 * tongue, 0.045 * tongue + 0.025 * turb);
fp = rot2(0.18 - 0.16 * tongue) * fp;
float dFire = (sdBox2(fp, vec2(0.115 + 0.028 * tongue, 0.040 + 0.075 * tongue), 0.018) - 0.024 * turb) * 0.52;
if (dRim < dFire) return vec2(dRim, 12.0);
return vec2(dFire, 3.0);
}
// Ring 3: Razor-thin dark-emerald metallic inner edge (plus sculpted vortex band in clay mode)
vec2 sdRing3(vec3 p) {
vec3 q = gR3 * (p - gC3);
float r = length(q.xz);
vec2 cp = vec2(r - 1.74, q.y);
float bound = length(cp) - 0.42;
if (bound > 0.22) return vec2(bound, 13.0);
float dRim = sdBox2(cp - vec2(-0.105, 0.010), vec2(0.010, 0.028), 0.003);
if (uLightMode != 1) {
return vec2(dRim, 13.0);
}
// Clay mode: thick sculpted swirling wind-vortex band
float th = atan(q.z, q.x);
float thSpin = th - 1.0 * gLoop;
vec3 eCoord = vec3(cos(thSpin) * 3.0, sin(thSpin) * 3.0, cp.y * 4.5 + cp.x * 3.0);
float turb = fbmCurl(eCoord);
float gust = 0.5 + 0.5 * sin(th * 4.0 - 2.0 * gLoop + 0.6 * turb);
vec2 ep = cp - vec2(0.055 + 0.032 * gust, 0.020 * turb);
ep = rot2(0.24 + 0.12 * gust) * ep;
float dWind = (sdBox2(ep, vec2(0.135 + 0.030 * gust, 0.038 + 0.016 * gust), 0.016) - 0.020 * turb) * 0.55;
if (dRim < dWind) return vec2(dRim, 13.0);
return vec2(dWind, 4.0);
}
// Dark stone circular colosseum arena floor with carved concentric rings
float sdFloor(vec3 p) {
float yFloor = -1.82;
float d = p.y - yFloor;
if (d < 0.16) {
float r = length(p.xz);
float a = atan(p.z, p.x);
float g1 = abs(r - 1.15);
float g2 = abs(r - 1.94);
float g3 = abs(r - 2.74);
float g4 = abs(r - 3.62);
float groove = smoothstep(0.034, 0.007, min(min(g1, g2), min(g3, g4)));
float rad = abs(sin(a * 6.0)) * r;
float seam = smoothstep(0.026, 0.006, rad) * smoothstep(1.12, 1.28, r);
d += 0.012 * max(groove, seam * 0.72);
}
return d;
}
vec2 mapScene(vec3 p) {
vec2 res = vec2(sdFloor(p), 5.0);
float dC = sdCrystal(p);
if (dC < res.x) res = vec2(dC, 1.0);
vec2 d1 = sdRing1(p);
if (d1.x < res.x) res = d1;
vec2 d2 = sdRing2(p);
if (d2.x < res.x) res = d2;
vec2 d3 = sdRing3(p);
if (d3.x < res.x) res = d3;
return res;
}
float mapDist(vec3 p) {
float d = sdFloor(p);
d = min(d, sdCrystal(p));
d = min(d, sdRing1(p).x);
d = min(d, sdRing2(p).x);
d = min(d, sdRing3(p).x);
return d;
}
// Unit-sign tetrahedral normal
vec3 calcNormal(vec3 p) {
const float h = 0.0014;
const vec2 k = vec2(1.0, -1.0);
return normalize(
k.xyy * mapDist(p + k.xyy * h) +
k.yyx * mapDist(p + k.yyx * h) +
k.yxy * mapDist(p + k.yxy * h) +
k.xxx * mapDist(p + k.xxx * h)
);
}
// Fast 4-tap ambient occlusion
float calcAO(vec3 p, vec3 n) {
float occ = 0.0;
float sca = 1.0;
for (int i = 0; i < 4; i++) {
float h = 0.03 + 0.085 * float(i);
float d = mapDist(p + n * h);
occ += (h - d) * sca;
sca *= 0.65;
}
return clamp(1.0 - 2.6 * occ, 0.12, 1.0);
}
// Fast soft shadow
float calcShadow(vec3 ro, vec3 rd, float maxT) {
float res = 1.0;
float t = 0.05;
for (int i = 0; i < 24; i++) {
float h = mapDist(ro + rd * t);
res = min(res, 7.0 * h / t);
t += clamp(h, 0.04, 0.35);
if (res < 0.02 || t > maxT) break;
}
return clamp(res, 0.0, 1.0);
}
// --- Roaring Volumetric Elemental Streams (Fire, Lightning/Wind, Water Mist) ---
// Returns vec4(emissiveRGB, desiredMaxStep)
vec4 evalVolumetricStreams(vec3 p, inout float trans) {
vec3 acc = vec3(0.0);
float maxStep = 0.36;
// 1. Compact bright core halo tightly hugging the central crystal
float dC = length(p - gCrysPos);
if (dC < 0.90) {
float pulse = 0.90 + 0.10 * sin(gLoop * 2.0);
acc += vec3(0.16, 0.68, 1.00) * exp(-dC * 6.2) * 0.34 * pulse;
}
// 2. WATER/ICE RING (Top): Translucent crashing sapphire-cyan water wave + lacy white seafoam crests
vec3 q1 = gR1 * (p - gC1);
vec2 cp1 = vec2(length(q1.xz) - 1.62, q1.y);
float d1 = length(cp1);
if (d1 < 0.56) {
maxStep = min(maxStep, (d1 < 0.36) ? 0.024 : 0.044);
float th = atan(q1.z, q1.x);
float thSpin = th - 1.0 * gLoop;
// 3D curled ocean wave turbulence & fine lacy seafoam web
vec3 wCoord = vec3(cos(thSpin) * 3.4, sin(thSpin) * 3.4, cp1.y * 4.8 + cp1.x * 3.4);
float wTurb = fbmCurl(wCoord);
float swell = 0.5 + 0.5 * sin(th * 4.0 - 2.0 * gLoop + 0.85 * wTurb);
// Curling barrel wave cross-section wrapping outside the dark-chrome inner rim
vec2 wp = cp1 - vec2(0.085 + 0.055 * swell + 0.040 * wTurb, 0.025 + 0.065 * swell + 0.032 * wTurb);
wp = rot2(-0.28 + 0.18 * swell) * wp;
float barrelD = length(wp * vec2(1.0, 2.35)) - (0.145 + 0.035 * swell);
// Sculpted translucent liquid body with crisp turbulent wave edges
float liquidEnv = exp(-max(barrelD, 0.0) * 18.0) * smoothstep(-0.11, 0.02, cp1.x);
float waveBody = smoothstep(0.08, 0.72, liquidEnv * (0.78 + 0.52 * wTurb));
// High-frequency lacy white seafoam crests concentrated on upper breaking ridges
vec3 foamCoord = vec3(cos(thSpin) * 7.5, sin(thSpin) * 7.5, cp1.y * 13.0 + cp1.x * 9.5);
float lace = fbmLace(foamCoord);
float crestZone = smoothstep(-0.02, 0.14, cp1.y + 0.06 * swell) * exp(-abs(barrelD) * 26.0);
float foam = pow(lace, 2.6) * (0.35 + 0.65 * crestZone) * smoothstep(-0.06, 0.06, cp1.x);
// Deep cobalt-sapphire translucent interior -> luminous azure-cyan wave sheets -> crisp lacy white foam
vec3 deepCobalt = vec3(0.012, 0.12, 0.58);
vec3 vividAzure = vec3(0.06, 0.58, 1.00);
vec3 seafoam = vec3(0.84, 0.96, 1.00);
float sheet = clamp(0.45 + 0.55 * wTurb + 0.30 * crestZone, 0.0, 1.0);
vec3 wCol = mix(deepCobalt, vividAzure, sheet);
wCol = mix(wCol, seafoam, clamp(foam * 1.15, 0.0, 0.92));
float wEmit = waveBody * (0.85 + 0.95 * sheet) + foam * 2.2;
acc += wCol * wEmit * trans;
// Translucent optical absorption keeps sapphire depth rich instead of milky white
trans *= exp(-waveBody * 0.065);
}
// 3. FIRE RING (Middle): Saturated roaring curled-fBM volumetric fire tongues (crimson -> orange -> amber-gold)
vec3 q2 = gR2 * (p - gC2);
vec2 cp2 = vec2(length(q2.xz) - 1.18, q2.y);
float d2 = length(cp2);
if (d2 < 0.56) {
maxStep = min(maxStep, 0.028);
float th = atan(q2.z, q2.x);
float thSpin = th + 1.0 * gLoop;
// Advected 3D curl-fBM coordinates (roaring swirl + sharp upward-licking tongues)
vec3 fCoord = vec3(cos(thSpin) * 4.0, sin(thSpin) * 4.0, cp2.y * 4.6 - 0.60 * cp2.x);
float turb = fbmCurl(fCoord);
float fine = gyroid(fCoord * 2.6 + vec3(0.0, 2.0 * sin(gLoop), 2.0 * cos(gLoop)));
float yRise = cp2.y + 0.05;
float flameH = 0.22 + 0.22 * (0.5 + 0.5 * turb) + 0.08 * fine;
float yNorm = clamp(yRise / max(flameH, 0.08), 0.0, 1.4);
float radCenter = 0.040 + 0.105 * yNorm + 0.055 * turb * yNorm;
float radHalfW = mix(0.105, 0.028, clamp(yNorm, 0.0, 1.0));
float radD = abs(cp2.x - radCenter) / max(radHalfW, 0.02);
float baseEnv = smoothstep(-0.07, 0.03, yRise) * smoothstep(1.22, 0.12, yNorm) * exp(-radD * radD * 1.75);
// Sharp sculpted flame tongues with crisp turbulent dark cutouts (zero milky haze!)
float dens = smoothstep(0.16, 0.78, baseEnv * (0.85 + 0.75 * turb + 0.32 * fine));
// Tight molten core strictly along the inner iron rim
float coreBand = exp(-length(cp2 - vec2(0.022, 0.008)) * 24.0) * (0.65 + 0.35 * turb);
// Hyper-saturated blackbody fire ramp (reserves white-gold ONLY for tiny inner core so ACES stays rich!)
float temp = clamp(1.0 - yNorm * 1.05 + 0.28 * coreBand + 0.16 * fine, 0.0, 1.0);
vec3 fCol = mix(vec3(0.72, 0.025, 0.004), vec3(1.00, 0.22, 0.010), smoothstep(0.08, 0.52, temp));
fCol = mix(fCol, vec3(1.00, 0.60, 0.05), smoothstep(0.54, 0.86, temp));
fCol = mix(fCol, vec3(1.00, 0.90, 0.42), smoothstep(0.88, 0.99, temp));
float emit = (dens * 2.25 + coreBand * 1.15);
acc += fCol * emit * trans;
trans *= exp(-dens * 0.095);
}
// 4. WIND / LIGHTNING RING: Thick turbulent emerald wind vortex + 5 razor-sharp branching electric arcs
vec3 q3 = gR3 * (p - gC3);
vec2 cp3 = vec2(length(q3.xz) - 1.74, q3.y);
float d3 = length(cp3);
if (d3 < 0.54) {
// Fine adaptive step so rays NEVER skip over razor-thin lightning bolts!
maxStep = min(maxStep, (d3 < 0.34) ? 0.019 : 0.042);
float th = atan(q3.z, q3.x);
float thSpin = th - 2.0 * gLoop;
// Thick roaring translucent emerald-jade swirling wind vortex ribbon
vec3 wCoord = vec3(cos(thSpin) * 3.2, sin(thSpin) * 3.2, cp3.y * 5.2 + cp3.x * 3.5);
float wTurb = fbmCurl(wCoord);
vec2 wp3 = cp3 - vec2(0.075 + 0.035 * wTurb, 0.025 * wTurb);
wp3 = rot2(0.22) * wp3;
float vortexEnv = exp(-length(wp3 * vec2(1.0, 2.3)) * 8.5) * smoothstep(-0.10, 0.04, cp3.x);
float windStreaks = smoothstep(-0.25, 0.75, wTurb + 0.35 * sin(th * 9.0 - 3.0 * gLoop + cp3.x * 16.0));
vec3 vortexCol = mix(vec3(0.02, 0.44, 0.24), vec3(0.14, 0.95, 0.56), windStreaks);
acc += vortexCol * vortexEnv * (0.75 + 1.35 * windStreaks) * 1.45;
// 5 dense, razor-sharp crackling & branching electric lightning bolts!
// Bolt 1: Primary high-voltage jagged arc wrapping 360 deg
vec2 b1 = vec2(
0.055 + 0.105 * triWave(th * 6.0 - 3.0 * gLoop) + 0.048 * triWave(th * 17.0 + 4.0 * gLoop) + 0.020 * triWave(th * 35.0 - 5.0 * gLoop),
0.010 + 0.090 * triWave(th * 8.0 - 3.0 * gLoop + 1.1) + 0.038 * triWave(th * 21.0 - 4.0 * gLoop) + 0.016 * triWave(th * 43.0 + 3.0 * gLoop)
);
float db1 = length(cp3 - b1);
float m1 = 0.45 + 0.55 * smoothstep(-0.35, 0.45, sin(th * 2.0 - gLoop) + 0.45 * sin(th * 5.0 + 2.0 * gLoop));
acc += (vec3(0.92, 1.00, 0.97) * exp(-db1 * 76.0) * 9.5 +
vec3(0.08, 1.00, 0.52) * exp(-db1 * 20.0) * 1.85) * m1;
// Bolt 2: Secondary counter-winding jagged arc
vec2 b2 = vec2(
0.085 - 0.095 * triWave(th * 7.0 + 2.0 * gLoop + 0.7) + 0.042 * triWave(th * 19.0 - 3.0 * gLoop) + 0.018 * triWave(th * 39.0 + 5.0 * gLoop),
-0.015 - 0.075 * triWave(th * 10.0 + 2.0 * gLoop) + 0.034 * triWave(th * 23.0 + 4.0 * gLoop)
);
float db2 = length(cp3 - b2);
float m2 = 0.40 + 0.60 * smoothstep(-0.25, 0.50, cos(th * 3.0 - 2.0 * gLoop) + 0.35 * sin(th * 7.0 - gLoop));
acc += (vec3(0.88, 1.00, 0.95) * exp(-db2 * 74.0) * 8.5 +
vec3(0.06, 0.98, 0.50) * exp(-db2 * 19.0) * 1.65) * m2;
// Bolt 3: Outer crackling fork leaping outward
vec2 b3 = vec2(
0.185 + 0.110 * triWave(th * 11.0 - 4.0 * gLoop) + 0.045 * triWave(th * 27.0 + 5.0 * gLoop),
0.065 * triWave(th * 13.0 - 3.0 * gLoop + 2.2) + 0.028 * triWave(th * 31.0 - 4.0 * gLoop)
);
float db3 = length(cp3 - b3);
float m3 = pow(max(0.0, sin(th * 3.0 - 2.0 * gLoop + 0.6)), 1.8);
acc += (vec3(0.94, 1.00, 0.97) * exp(-db3 * 82.0) * 8.0 +
vec3(0.10, 1.00, 0.56) * exp(-db3 * 22.0) * 1.35) * m3;
// Bolt 4: Tight inner high-frequency arc snapping off the inner rim
vec2 b4 = vec2(
-0.025 + 0.060 * triWave(th * 13.0 + 3.0 * gLoop) + 0.025 * triWave(th * 29.0 - 4.0 * gLoop),
0.045 * triWave(th * 9.0 + 3.0 * gLoop + 1.7)
);
float db4 = length(cp3 - b4);
float m4 = pow(max(0.0, cos(th * 4.0 + gLoop - 0.5)), 2.0);
acc += (vec3(0.90, 1.00, 0.96) * exp(-db4 * 85.0) * 7.2 +
vec3(0.12, 1.00, 0.60) * exp(-db4 * 24.0) * 1.20) * m4;
}
return vec4(acc, maxStep);
}
// --- Flying elemental sparks, embers & water spray droplets (36 analytical 3D streaks) ---
vec3 evalElementalSparks(vec3 ro, vec3 rd, float maxT) {
vec3 col = vec3(0.0);
for (int i = 0; i < 36; i++) {
float fi = float(i);
int family = i % 3; // 0=fire ember, 1=water spray droplet, 2=lightning spark
float seed = fi * 1.6180339;
float speed = (family == 0) ? 1.0 : ((family == 1) ? -1.0 : 2.0);
float ang = fract(seed) * TAU + speed * gLoop;
float rad = (family == 1) ? (1.42 + 0.68 * fract(seed * 3.17)) :
(family == 0) ? (1.05 + 1.15 * fract(seed * 3.17)) :
(1.45 + 0.95 * fract(seed * 3.17));
float yBase = (family == 1) ? (0.68 + 0.58 * sin(seed * 7.3)) :
(family == 0) ? (0.14 + 0.85 * cos(seed * 5.1)) :
(-0.78 + 0.60 * sin(seed * 9.7));
float yPos = yBase + 0.16 * sin(gLoop + seed * TAU);
vec3 sp = vec3(cos(ang) * rad, yPos, sin(ang) * rad);
vec3 tang = normalize(vec3(-sin(ang) * speed, 0.14 * cos(gLoop + seed * TAU), cos(ang) * speed));
vec3 w = sp - ro;
float tRay = dot(w, rd);
if (tRay < 0.25 || tRay > maxT) continue;
vec3 closest = ro + rd * tRay;
vec3 diff = closest - sp;
float streakLen = (family == 1) ? 0.022 : 0.085; // crisp droplets for water, streaks for embers/sparks
float along = clamp(dot(diff, tang), -streakLen, streakLen);
float d = length(diff - tang * along);
float core = exp(-d * 98.0);
float halo = exp(-d * 24.0) * 0.18;
float twinkle = 0.60 + 0.40 * sin(gLoop * 3.0 + fi * 2.7);
vec3 sCol = (family == 0) ? vec3(1.00, 0.54, 0.12) :
(family == 1) ? vec3(0.65, 0.94, 1.00) :
vec3(0.45, 1.00, 0.72);
col += sCol * (core * 1.65 + halo) * twinkle;
}
return col;
}
// --- Dark moody colosseum arena backdrop ---
vec3 evalBackdrop(vec3 rd) {
if (uLightMode == 1) {
float grad = 0.22 + 0.12 * clamp(rd.y * 0.8 + 0.5, 0.0, 1.0);
return vec3(grad);
}
float up = clamp(rd.y * 0.5 + 0.5, 0.0, 1.0);
vec3 col = mix(vec3(0.0026, 0.0038, 0.0058), vec3(0.0012, 0.0018, 0.0032), up);
// Subtle circular colosseum gallery tiers & arches
float az = atan(rd.z, rd.x);
float tier1 = smoothstep(0.16, 0.03, abs(rd.y + 0.03));
float tier2 = smoothstep(0.12, 0.02, abs(rd.y - 0.18));
float pillars = 0.5 + 0.5 * cos(az * 24.0);
col += vec3(0.0032, 0.0044, 0.0066) * (tier1 + 0.6 * tier2) * (0.35 + 0.65 * pillars);
// Subtle distant overhead arena spotlights
float spotBand = smoothstep(0.16, 0.04, abs(rd.y - 0.36));
float spots = pow(max(0.0, cos(az * 8.0 + 0.35)), 26.0);
col += vec3(0.032, 0.044, 0.062) * spotBand * spots;
float centerGlow = exp(-length(rd.xy - vec2(0.0, -0.02)) * 3.0);
if (uLightMode == 3) {
col += vec3(0.14, 0.24, 0.38) * pow(centerGlow, 1.3);
} else if (uLightMode == 2) {
col += vec3(0.007, 0.011, 0.018) * centerGlow;
} else {
col += vec3(0.005, 0.011, 0.020) * centerGlow;
}
return col;
}
// --- ACES Filmic Tonemapping ---
vec3 acesTonemap(vec3 x) {
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
vec3 y = clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0.0, 1.0);
return y * 0.965;
}
// --- Surface Shading ---
vec3 shadeSurface(vec3 p, vec3 n, vec3 v, float matID, float tHit) {
float ao = calcAO(p, n);
vec3 keyDir, keyCol, fillDir, fillCol, rimDir, rimCol;
if (uLightMode == 1) {
keyDir = normalize(vec3(0.62, 0.72, 0.52));
keyCol = vec3(1.15);
fillDir = normalize(vec3(-0.75, 0.30, 0.45));
fillCol = vec3(0.36);
rimDir = normalize(vec3(-0.20, 0.55, -0.82));
rimCol = vec3(0.55);
} else if (uLightMode == 2) {
keyDir = normalize(vec3(0.92, 0.22, 0.32));
keyCol = vec3(1.75, 1.52, 1.28);
fillDir = normalize(vec3(-0.70, 0.38, 0.50));
fillCol = vec3(0.12, 0.18, 0.28);
rimDir = normalize(vec3(-0.35, 0.50, -0.80));
rimCol = vec3(0.30, 0.50, 0.78);
} else if (uLightMode == 3) {
keyDir = normalize(vec3(0.18, 0.42, -0.89));
keyCol = vec3(1.65, 1.80, 2.00);
fillDir = normalize(vec3(0.35, 0.45, 0.80));
fillCol = vec3(0.10, 0.15, 0.22);
rimDir = normalize(vec3(-0.28, 0.35, -0.89));
rimCol = vec3(0.95, 1.10, 1.35);
} else {
keyDir = normalize(vec3(0.52, 0.78, 0.48));
keyCol = vec3(0.95, 1.02, 1.18);
fillDir = normalize(vec3(-0.68, 0.35, 0.52));
fillCol = vec3(0.14, 0.22, 0.36);
rimDir = normalize(vec3(-0.25, 0.55, -0.80));
rimCol = vec3(0.45, 0.70, 1.05);
}
float sh = calcShadow(p + n * 0.015, keyDir, 5.5);
float ndl = max(dot(n, keyDir), 0.0);
float ndf = max(dot(n, fillDir), 0.0);
float ndv = max(dot(n, v), 0.0);
float fres = pow(1.0 - ndv, 3.8);
vec3 hKey = normalize(keyDir + v);
vec3 hRim = normalize(rimDir + v);
// --- Mode 1: Pure neutral grayscale clay/form study (R == G == B, emission muted) ---
if (uLightMode == 1) {
float alb = 0.56;
float specPow = 28.0;
float specStr = 0.22;
if (matID < 1.5) {
alb = 0.76; specPow = 72.0; specStr = 0.42;
} else if (matID > 10.5) {
alb = 0.38; specPow = 48.0; specStr = 0.32;
} else if (matID > 4.5) {
alb = 0.44; specPow = 18.0; specStr = 0.12;
} else if (matID < 2.5) {
alb = 0.68; specPow = 42.0; specStr = 0.32;
} else if (matID < 3.5) {
alb = 0.62; specPow = 24.0; specStr = 0.24;
} else {
alb = 0.65; specPow = 32.0; specStr = 0.26;
}
float diff = alb * (ndl * sh * keyCol.x + ndf * fillCol.x + 0.15 * ao);
float spec = pow(max(dot(n, hKey), 0.0), specPow) * specStr * sh;
float rim = fres * (0.26 + 0.48 * max(dot(n, rimDir), 0.0)) * rimCol.x;
return vec3(diff + spec + rim);
}
float emitScale = (uLightMode == 2) ? 0.72 : ((uLightMode == 3) ? 0.85 : 1.0);
vec3 col = vec3(0.0);
// 1. Central Faceted Crystal Core (dramatic dark-sapphire vs dazzling specular facet contrast)
if (matID < 1.5) {
float pulse = 0.90 + 0.10 * sin(gLoop * 2.0);
// Tight razor-thin edge sparkle (not thick white outlines)
vec3 tAxis = normalize(abs(n.y) < 0.9 ? cross(n, vec3(0.0, 1.0, 0.0)) : cross(n, vec3(1.0, 0.0, 0.0)));
vec3 bAxis = cross(n, tAxis);
float edgeCurv = length(n - calcNormal(p + tAxis * 0.0045)) + length(n - calcNormal(p + bAxis * 0.0045));
float bevelGlint = smoothstep(0.18, 0.75, edgeCurv);
// Refracted internal ray for focused heart glow & internal caustic veins
vec3 rIn = refract(-v, n, 1.0 / 1.60);
vec3 pMid = p + rIn * 0.16;
vec3 pFar = p + rIn * 0.32;
// Core glow concentrated toward lower-center heart like 02.png
float coreDist = length((pMid - (gCrysPos - vec3(0.0, 0.06, 0.0))) * vec3(2.2, 1.35, 2.2));
float coreGlow = exp(-coreDist * 5.2) * pulse;
vec3 qFar = pFar - gCrysPos;
qFar.xz = gCrysRot * qFar.xz;
float caustic = pow(abs(sin(qFar.x * 18.0 + qFar.y * 14.0) * cos(qFar.z * 18.0 - qFar.y * 12.0)), 2.2);
float backFacet = smoothstep(-0.07, 0.015, sdCrystal(pFar));
float dispPhase = dot(n, v) * 6.5 + dot(rIn, vec3(1.2, 2.1, -1.6)) * 3.2;
vec3 prism = 0.50 + 0.50 * cos(vec3(0.0, 1.9, 3.8) + dispPhase);
// High-contrast facet shading: deep indigo-sapphire shadow facets vs bright lit facets
vec3 facetBase = mix(vec3(0.015, 0.055, 0.20), vec3(0.12, 0.54, 0.98), pow(ndl, 1.3) * 0.85 + ndf * 0.25);
vec3 internalLight = mix(vec3(0.08, 0.62, 1.00), vec3(0.95, 0.99, 1.00), coreGlow) * (0.12 + 1.85 * coreGlow);
internalLight += prism * (0.32 * caustic + 0.42 * backFacet) * emitScale;
float spec = pow(max(dot(n, hKey), 0.0), 160.0) * 3.0;
float rimSpec = pow(max(dot(n, hRim), 0.0), 72.0) * 1.5;
col = facetBase * (0.50 + 0.50 * ao) + internalLight * emitScale;
col += vec3(0.45, 0.85, 1.00) * fres * 1.15;
col += vec3(0.96, 0.99, 1.00) * (spec * sh + rimSpec + bevelGlint * 0.85);
// Reflected fire & emerald highlights on grazing crystal facets
col += vec3(1.00, 0.36, 0.08) * pow(max(dot(n, normalize(vec3(0.7, 0.1, 0.5))), 0.0), 3.5) * 0.42 * emitScale;
col += vec3(0.10, 0.95, 0.52) * pow(max(-n.y, 0.0), 2.4) * 0.36 * emitScale;
return col;
}
// 2. Sculpted Crashing Translucent Sapphire-Cyan Water Wave (Top Ring)
if (matID < 2.5) {
vec3 q1 = gR1 * (p - gC1);
float th = atan(q1.z, q1.x);
float thSpin = th - 1.0 * gLoop;
vec2 cp1 = vec2(length(q1.xz) - 1.62, q1.y);
// Lacy white seafoam crests via ridged 3D gyroid lace
vec3 foamCoord = vec3(cos(thSpin) * 6.5, sin(thSpin) * 6.5, cp1.y * 12.0 + cp1.x * 9.0);
float lace = fbmLace(foamCoord);
float crestHeight = smoothstep(-0.02, 0.12, cp1.y + 0.05 * n.y);
float foam = smoothstep(0.48, 0.88, lace * 0.72 + crestHeight * 0.48 + fres * 0.25);
// Optical translucency: deep sapphire in thick interior, luminous aqua-cyan at thin edges/backlit
float thinEdge = pow(1.0 - ndv, 2.0);
vec3 refrCol = evalBackdrop(refract(-v, n, 1.0 / 1.333));
vec3 deepWater = vec3(0.015, 0.14, 0.52);
vec3 brightAqua = vec3(0.14, 0.76, 1.00);
vec3 waterBody = mix(deepWater, brightAqua, clamp(thinEdge * 0.75 + crestHeight * 0.45 + ndl * 0.35, 0.0, 1.0));
waterBody = mix(waterBody, refrCol + vec3(0.06, 0.36, 0.82), 0.32 * (1.0 - foam));
// Crisp wet speculars + reflected fiery orange glints on water crests
float spec = pow(max(dot(n, hKey), 0.0), 128.0) * 2.4;
float rimS = pow(max(dot(n, hRim), 0.0), 56.0) * 1.25;
col = waterBody * (0.45 + 0.75 * ndl * sh + 0.35 * emitScale);
col = mix(col, vec3(0.86, 0.97, 1.00) * (0.85 + 0.55 * ndl), foam * 0.86);
col += vec3(0.55, 0.90, 1.00) * fres * 1.05 * emitScale;
col += vec3(0.95, 0.99, 1.00) * (spec * sh + rimS * 0.8);
// Subtle reflected orange fire glow on the underside of the water wave
col += vec3(1.00, 0.40, 0.08) * pow(max(-n.y, 0.0), 2.0) * 0.22 * emitScale;
return col;
}
// 11, 12, 13: Razor-thin dark gunmetal-chrome inner edge accents (NOT bright pastel plastic!)
if (matID > 10.5) {
vec3 elemTint = (matID < 11.5) ? vec3(0.25, 0.78, 1.00) :
(matID < 12.5) ? vec3(1.00, 0.42, 0.06) :
vec3(0.14, 0.96, 0.54);
vec3 darkChrome = vec3(0.018, 0.022, 0.028);
float spec = pow(max(dot(n, hKey), 0.0), 120.0) * 2.2;
float rimS = pow(max(dot(n, hRim), 0.0), 64.0) * 1.1;
col = darkChrome * (ndl * sh * keyCol + ndf * fillCol + 0.18 * ao);
col += elemTint * (fres * 0.65 + 0.08 * emitScale);
col += vec3(0.92, 0.96, 1.00) * (spec * sh + rimS * 0.65);
return col;
}
// 5. Dark Atmospheric Colosseum Arena Floor
float r = length(p.xz);
float a = atan(p.z, p.x);
float grain = vnoise2(p.xz * 7.5) * 0.55 + vnoise2(p.xz * 21.0) * 0.45;
float gLine = smoothstep(0.034, 0.008, min(min(abs(r - 1.15), abs(r - 1.94)), min(abs(r - 2.74), abs(r - 3.62))));
float radLine = smoothstep(0.028, 0.007, abs(sin(a * 6.0)) * r) * smoothstep(1.12, 1.28, r);
vec3 stone = mix(vec3(0.013, 0.017, 0.024), vec3(0.026, 0.032, 0.042), grain);
stone *= (1.0 - 0.55 * max(gLine, radLine * 0.75));
float spec = pow(max(dot(n, hKey), 0.0), 36.0) * (0.22 + 0.28 * grain);
col = stone * (ndl * sh * keyCol + ndf * fillCol + 0.28 * ao);
col += vec3(0.28, 0.36, 0.48) * spec * sh;
// Vivid elemental floor reflections
float emeraldBounce = exp(-abs(r - 1.74) * 1.45) * 0.38;
float crysBounce = exp(-r * 1.15) * 0.22;
float fireBounce = exp(-abs(r - 1.18) * 1.75) * 0.18;
float waterBounce = exp(-abs(r - 1.62) * 1.20) * 0.12;
col += vec3(0.06, 0.94, 0.50) * emeraldBounce * (0.45 + 0.55 * grain) * emitScale;
col += vec3(0.20, 0.78, 1.00) * crysBounce * emitScale;
col += vec3(1.00, 0.34, 0.04) * fireBounce * emitScale;
col += vec3(0.12, 0.54, 1.00) * waterBounce * emitScale;
float fog = 1.0 - exp(-max(tHit - 5.2, 0.0) * 0.16);
col = mix(col, vec3(0.0026, 0.0038, 0.0058), clamp(fog, 0.0, 0.95));
return col;
}
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
setupRig();
vec2 uv = (pfx_frag_xy - 0.5 * uResolution.xy) / uResolution.y;
// Camera framing: 0 = hero full framing, 1 = ~2.6x macro close-up
vec3 ro, ta;
float focal;
if (uCamMode == 1) {
ro = vec3(0.38 + 0.08 * sin(gLoop), 0.18 + 0.03 * cos(gLoop), 2.74);
ta = vec3(0.0, 0.02, 0.0);
focal = 1.72;
} else {
ro = vec3(0.12 * sin(gLoop), 0.38 + 0.04 * cos(gLoop), 6.42);
ta = vec3(0.0, -0.06, 0.0);
focal = 1.48;
}
vec3 ww = normalize(ta - ro);
vec3 uu = normalize(cross(ww, vec3(0.0, 1.0, 0.0)));
vec3 vv = cross(uu, ww);
vec3 rd = normalize(uu * uv.x + vv * uv.y + ww * focal);
// Raymarch solid geometry + simultaneous roaring volumetric elemental streams
float t = 0.0;
float tMax = 20.0;
float matID = -1.0;
vec3 volVFX = vec3(0.0);
float trans = 1.0;
bool doVol = (uLightMode != 1);
float volScale = (uLightMode == 2) ? 0.72 : ((uLightMode == 3) ? 0.86 : 1.0);
for (int i = 0; i < 112; i++) {
vec3 p = ro + rd * t;
vec2 h = mapScene(p);
float d = h.x;
if (d < 0.0016) {
matID = h.y;
break;
}
float stepLen = clamp(d, 0.018, 0.38);
if (doVol && t > 0.30 && t < 10.8 && length(p) < 2.95) {
vec4 vfx = evalVolumetricStreams(p, trans);
stepLen = min(stepLen, vfx.w);
volVFX += vfx.rgb * stepLen;
}
t += (d < 0.08) ? min(d, stepLen) : stepLen;
if (t > tMax) break;
}
vec3 col;
if (matID > 0.0) {
vec3 p = ro + rd * t;
vec3 n = calcNormal(p);
col = shadeSurface(p, n, -rd, matID, t);
} else {
col = evalBackdrop(rd);
}
if (doVol) {
// Blend surface with flame transmittance + add roaring volumetric streams & sparks
col = col * mix(1.0, trans, 0.55) + volVFX * volScale;
col += evalElementalSparks(ro, rd, (matID > 0.0) ? t : tMax) * volScale;
}
if (uLightMode == 1) {
float g = acesTonemap(col).x;
g = pow(clamp(g, 0.0, 1.0), 1.0 / 2.2);
fragColor = vec4(vec3(g), 1.0);
} else {
col = acesTonemap(col);
col = max(col, vec3(0.0014, 0.0019, 0.0028));
col = pow(clamp(col, 0.0, 1.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);
}
}
// Orbiting Elemental Trinity Rings — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_animated/lib/02_orbiting_elemental_trinity_rings.glsl (MIT License)
import * as THREE from 'three';
const vertexShader = /* glsl */ `
out vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;
const fragmentShader = /* glsl */ `
precision highp float;
precision highp int;
uniform vec2 uResolution;
uniform float uTime;
uniform float uOpen;
uniform int uLightMode;
uniform int uCamMode;
out vec4 fragColor;
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
// Exact 3.0s seamless loop state
float gPhase;
float gLoop;
// Ring transforms (world -> ring-local) and centers
mat3 gR1, gR2, gR3;
vec3 gC1, gC2, gC3;
vec3 gCrysPos;
mat2 gCrysRot;
// --- Utility math ---
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
mat3 rotX(float a) {
float c = cos(a), s = sin(a);
return mat3(1.0, 0.0, 0.0,
0.0, c, s,
0.0, -s, c);
}
mat3 rotZ(float a) {
float c = cos(a), s = sin(a);
return mat3( c, s, 0.0,
-s, c, 0.0,
0.0, 0.0, 1.0);
}
float smin(float a, float b, float k) {
float h = max(k - abs(a - b), 0.0) / k;
return min(a, b) - h * h * k * 0.25;
}
float smax(float a, float b, float k) {
return -smin(-a, -b, k);
}
float sdBox2(vec2 p, vec2 b, float r) {
vec2 d = abs(p) - b;
return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - r;
}
float triWave(float x) {
return abs(fract(x / TAU) * 2.0 - 1.0) * 2.0 - 1.0;
}
float hash21(vec2 p) {
p = fract(p * vec2(123.34, 456.21));
p += dot(p, p + 45.32);
return fract(p.x * p.y);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
f = f * f * (3.0 - 2.0 * f);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
}
// Fast 3D Gyroid & Domain-Warped Curl-fBM (zero seams, fast on SwiftShader)
float gyroid(vec3 p) {
return dot(sin(p), cos(p.yzx));
}
float fbmCurl(vec3 p) {
// Domain warp for roaring turbulent curling motion
vec3 w = vec3(
gyroid(p),
gyroid(p + vec3(1.7, 3.1, 2.3)),
gyroid(p - vec3(2.4, 1.3, 3.7))
);
p += 0.45 * w;
float v = 0.0;
float a = 0.54;
const mat3 mRot = mat3(
0.80, 0.48, 0.36,
-0.60, 0.64, 0.48,
0.00, -0.60, 0.80
);
for (int i = 0; i < 3; i++) {
v += a * gyroid(p);
p = mRot * p * 2.05 + vec3(1.3, 2.7, 0.9);
a *= 0.48;
}
return v;
}
// High-frequency lacy foam / filament ridge pattern
float fbmLace(vec3 p) {
float g1 = 1.0 - abs(gyroid(p) * 0.65);
p = p * 2.15 + vec3(1.9, -2.3, 1.1);
float g2 = 1.0 - abs(gyroid(p) * 0.65);
return clamp(g1 * 0.60 + g2 * 0.40, 0.0, 1.0);
}
// --- Frame rig setup (exact 3.0s seamless loop, clean 3D separation at t=1.2) ---
void setupRig() {
gPhase = fract(uTime / 3.0);
gLoop = gPhase * TAU;
gCrysPos = vec3(0.0, 0.02 + 0.045 * sin(gLoop), 0.0);
gCrysRot = rot2(gLoop);
// Ring 1 (Top): Sapphire-cyan crashing water wave ring
gC1 = vec3(0.0, 0.74 + 0.04 * sin(gLoop), 0.0);
float r1x = 0.25 + 0.08 * cos(gLoop);
float r1z = -0.14 + 0.10 * sin(gLoop);
gR1 = rotZ(-r1z) * rotX(r1x);
// Ring 2 (Middle): Blazing crimson-orange volumetric fire ring
gC2 = vec3(0.0, 0.04 + 0.03 * cos(gLoop), 0.0);
float r2x = -0.32 + 0.12 * sin(gLoop);
float r2z = 0.42 - 0.14 * cos(gLoop);
gR2 = rotZ(-r2z) * rotX(r2x);
// Ring 3 (Bottom): Electric emerald-green wind & lightning vortex ring
gC3 = vec3(0.0, -0.80 + 0.04 * sin(gLoop + 2.094395), 0.0);
float r3x = -0.27 - 0.07 * cos(gLoop + 1.047198);
float r3z = 0.15 + 0.10 * sin(gLoop + 1.047198);
gR3 = rotZ(-r3z) * rotX(r3x);
}
// --- Solid & Sculpted Geometry SDFs ---
// Double-terminated faceted hexagonal crystal core
float sdCrystal(vec3 p) {
vec3 q = p - gCrysPos;
q.xz = gCrysRot * q.xz;
float ay = abs(q.y);
const vec2 h1 = vec2(1.0, 0.0);
const vec2 h2 = vec2(0.5, 0.8660254);
const vec2 h3 = vec2(-0.5, 0.8660254);
float hexR = max(abs(dot(q.xz, h1)), max(abs(dot(q.xz, h2)), abs(dot(q.xz, h3))));
vec2 qRot = vec2(q.x * 0.8660254 - q.z * 0.5, q.x * 0.5 + q.z * 0.8660254);
float hexR2 = max(abs(dot(qRot, h1)), max(abs(dot(qRot, h2)), abs(dot(qRot, h3))));
float dPrism = hexR - 0.255;
float dPyr = (hexR * 0.76822 + (ay - 0.255) * 0.64018) - 0.255 * 0.76822;
float dCrown = (hexR2 * 0.83205 + (ay - 0.205) * 0.55470) - 0.266 * 0.83205;
float dBelt = hexR2 - 0.266;
float d = smax(dPrism, dPyr, 0.003);
d = smax(d, dCrown, 0.0025);
d = smax(d, dBelt, 0.0025);
return d;
}
// Ring 1: Razor-thin dark-chrome inner edge (plus sculpted crashing water wave in clay mode)
vec2 sdRing1(vec3 p) {
vec3 q = gR1 * (p - gC1);
float r = length(q.xz);
vec2 cp = vec2(r - 1.62, q.y);
float bound = length(cp) - 0.44;
if (bound > 0.24) return vec2(bound, 11.0);
// Razor-thin dark-chrome inner accent edge
float dRim = sdBox2(cp - vec2(-0.105, -0.020), vec2(0.011, 0.030), 0.004);
if (uLightMode != 1) {
return vec2(dRim, 11.0);
}
// Clay mode: thick sculpted crashing turbulent water wave so form reads cleanly
float th = atan(q.z, q.x);
float thSpin = th - 1.0 * gLoop;
vec3 wCoord = vec3(cos(thSpin) * 2.8, sin(thSpin) * 2.8, cp.y * 4.5 + cp.x * 3.0);
float turb = fbmCurl(wCoord);
float swell = 0.5 + 0.5 * sin(th * 4.0 - 2.0 * gLoop + 0.7 * turb);
vec2 wp = cp - vec2(0.055 + 0.050 * swell + 0.035 * turb, 0.025 + 0.055 * swell + 0.028 * turb);
wp = rot2(-0.26 + 0.16 * swell) * wp;
float dWave = (sdBox2(wp, vec2(0.140 + 0.032 * swell, 0.042 + 0.020 * swell), 0.024) - 0.022 * turb) * 0.52;
if (dRim < dWave) return vec2(dRim, 11.0);
return vec2(dWave, 2.0);
}
// Ring 2: Razor-thin dark-iron inner edge (plus sculpted turbulent flame band in clay mode)
vec2 sdRing2(vec3 p) {
vec3 q = gR2 * (p - gC2);
float r = length(q.xz);
vec2 cp = vec2(r - 1.18, q.y);
float bound = length(cp) - 0.42;
if (bound > 0.22) return vec2(bound, 12.0);
// Subtle razor-thin dark charred-iron inner edge
float dRim = sdBox2(cp - vec2(-0.075, -0.015), vec2(0.009, 0.026), 0.003);
if (uLightMode != 1) {
return vec2(dRim, 12.0);
}
// Clay mode: thick roaring sculpted flame ribbon so form reads cleanly
float th = atan(q.z, q.x);
float thSpin = th + 1.0 * gLoop;
vec3 fCoord = vec3(cos(thSpin) * 3.2, sin(thSpin) * 3.2, cp.y * 5.0);
float turb = fbmCurl(fCoord);
float tongue = pow(0.5 + 0.5 * sin(th * 5.0 + 2.0 * gLoop + 0.9 * turb), 1.6);
vec2 fp = cp - vec2(0.040 + 0.030 * tongue, 0.045 * tongue + 0.025 * turb);
fp = rot2(0.18 - 0.16 * tongue) * fp;
float dFire = (sdBox2(fp, vec2(0.115 + 0.028 * tongue, 0.040 + 0.075 * tongue), 0.018) - 0.024 * turb) * 0.52;
if (dRim < dFire) return vec2(dRim, 12.0);
return vec2(dFire, 3.0);
}
// Ring 3: Razor-thin dark-emerald metallic inner edge (plus sculpted vortex band in clay mode)
vec2 sdRing3(vec3 p) {
vec3 q = gR3 * (p - gC3);
float r = length(q.xz);
vec2 cp = vec2(r - 1.74, q.y);
float bound = length(cp) - 0.42;
if (bound > 0.22) return vec2(bound, 13.0);
float dRim = sdBox2(cp - vec2(-0.105, 0.010), vec2(0.010, 0.028), 0.003);
if (uLightMode != 1) {
return vec2(dRim, 13.0);
}
// Clay mode: thick sculpted swirling wind-vortex band
float th = atan(q.z, q.x);
float thSpin = th - 1.0 * gLoop;
vec3 eCoord = vec3(cos(thSpin) * 3.0, sin(thSpin) * 3.0, cp.y * 4.5 + cp.x * 3.0);
float turb = fbmCurl(eCoord);
float gust = 0.5 + 0.5 * sin(th * 4.0 - 2.0 * gLoop + 0.6 * turb);
vec2 ep = cp - vec2(0.055 + 0.032 * gust, 0.020 * turb);
ep = rot2(0.24 + 0.12 * gust) * ep;
float dWind = (sdBox2(ep, vec2(0.135 + 0.030 * gust, 0.038 + 0.016 * gust), 0.016) - 0.020 * turb) * 0.55;
if (dRim < dWind) return vec2(dRim, 13.0);
return vec2(dWind, 4.0);
}
// Dark stone circular colosseum arena floor with carved concentric rings
float sdFloor(vec3 p) {
float yFloor = -1.82;
float d = p.y - yFloor;
if (d < 0.16) {
float r = length(p.xz);
float a = atan(p.z, p.x);
float g1 = abs(r - 1.15);
float g2 = abs(r - 1.94);
float g3 = abs(r - 2.74);
float g4 = abs(r - 3.62);
float groove = smoothstep(0.034, 0.007, min(min(g1, g2), min(g3, g4)));
float rad = abs(sin(a * 6.0)) * r;
float seam = smoothstep(0.026, 0.006, rad) * smoothstep(1.12, 1.28, r);
d += 0.012 * max(groove, seam * 0.72);
}
return d;
}
vec2 mapScene(vec3 p) {
vec2 res = vec2(sdFloor(p), 5.0);
float dC = sdCrystal(p);
if (dC < res.x) res = vec2(dC, 1.0);
vec2 d1 = sdRing1(p);
if (d1.x < res.x) res = d1;
vec2 d2 = sdRing2(p);
if (d2.x < res.x) res = d2;
vec2 d3 = sdRing3(p);
if (d3.x < res.x) res = d3;
return res;
}
float mapDist(vec3 p) {
float d = sdFloor(p);
d = min(d, sdCrystal(p));
d = min(d, sdRing1(p).x);
d = min(d, sdRing2(p).x);
d = min(d, sdRing3(p).x);
return d;
}
// Unit-sign tetrahedral normal
vec3 calcNormal(vec3 p) {
const float h = 0.0014;
const vec2 k = vec2(1.0, -1.0);
return normalize(
k.xyy * mapDist(p + k.xyy * h) +
k.yyx * mapDist(p + k.yyx * h) +
k.yxy * mapDist(p + k.yxy * h) +
k.xxx * mapDist(p + k.xxx * h)
);
}
// Fast 4-tap ambient occlusion
float calcAO(vec3 p, vec3 n) {
float occ = 0.0;
float sca = 1.0;
for (int i = 0; i < 4; i++) {
float h = 0.03 + 0.085 * float(i);
float d = mapDist(p + n * h);
occ += (h - d) * sca;
sca *= 0.65;
}
return clamp(1.0 - 2.6 * occ, 0.12, 1.0);
}
// Fast soft shadow
float calcShadow(vec3 ro, vec3 rd, float maxT) {
float res = 1.0;
float t = 0.05;
for (int i = 0; i < 24; i++) {
float h = mapDist(ro + rd * t);
res = min(res, 7.0 * h / t);
t += clamp(h, 0.04, 0.35);
if (res < 0.02 || t > maxT) break;
}
return clamp(res, 0.0, 1.0);
}
// --- Roaring Volumetric Elemental Streams (Fire, Lightning/Wind, Water Mist) ---
// Returns vec4(emissiveRGB, desiredMaxStep)
vec4 evalVolumetricStreams(vec3 p, inout float trans) {
vec3 acc = vec3(0.0);
float maxStep = 0.36;
// 1. Compact bright core halo tightly hugging the central crystal
float dC = length(p - gCrysPos);
if (dC < 0.90) {
float pulse = 0.90 + 0.10 * sin(gLoop * 2.0);
acc += vec3(0.16, 0.68, 1.00) * exp(-dC * 6.2) * 0.34 * pulse;
}
// 2. WATER/ICE RING (Top): Translucent crashing sapphire-cyan water wave + lacy white seafoam crests
vec3 q1 = gR1 * (p - gC1);
vec2 cp1 = vec2(length(q1.xz) - 1.62, q1.y);
float d1 = length(cp1);
if (d1 < 0.56) {
maxStep = min(maxStep, (d1 < 0.36) ? 0.024 : 0.044);
float th = atan(q1.z, q1.x);
float thSpin = th - 1.0 * gLoop;
// 3D curled ocean wave turbulence & fine lacy seafoam web
vec3 wCoord = vec3(cos(thSpin) * 3.4, sin(thSpin) * 3.4, cp1.y * 4.8 + cp1.x * 3.4);
float wTurb = fbmCurl(wCoord);
float swell = 0.5 + 0.5 * sin(th * 4.0 - 2.0 * gLoop + 0.85 * wTurb);
// Curling barrel wave cross-section wrapping outside the dark-chrome inner rim
vec2 wp = cp1 - vec2(0.085 + 0.055 * swell + 0.040 * wTurb, 0.025 + 0.065 * swell + 0.032 * wTurb);
wp = rot2(-0.28 + 0.18 * swell) * wp;
float barrelD = length(wp * vec2(1.0, 2.35)) - (0.145 + 0.035 * swell);
// Sculpted translucent liquid body with crisp turbulent wave edges
float liquidEnv = exp(-max(barrelD, 0.0) * 18.0) * smoothstep(-0.11, 0.02, cp1.x);
float waveBody = smoothstep(0.08, 0.72, liquidEnv * (0.78 + 0.52 * wTurb));
// High-frequency lacy white seafoam crests concentrated on upper breaking ridges
vec3 foamCoord = vec3(cos(thSpin) * 7.5, sin(thSpin) * 7.5, cp1.y * 13.0 + cp1.x * 9.5);
float lace = fbmLace(foamCoord);
float crestZone = smoothstep(-0.02, 0.14, cp1.y + 0.06 * swell) * exp(-abs(barrelD) * 26.0);
float foam = pow(lace, 2.6) * (0.35 + 0.65 * crestZone) * smoothstep(-0.06, 0.06, cp1.x);
// Deep cobalt-sapphire translucent interior -> luminous azure-cyan wave sheets -> crisp lacy white foam
vec3 deepCobalt = vec3(0.012, 0.12, 0.58);
vec3 vividAzure = vec3(0.06, 0.58, 1.00);
vec3 seafoam = vec3(0.84, 0.96, 1.00);
float sheet = clamp(0.45 + 0.55 * wTurb + 0.30 * crestZone, 0.0, 1.0);
vec3 wCol = mix(deepCobalt, vividAzure, sheet);
wCol = mix(wCol, seafoam, clamp(foam * 1.15, 0.0, 0.92));
float wEmit = waveBody * (0.85 + 0.95 * sheet) + foam * 2.2;
acc += wCol * wEmit * trans;
// Translucent optical absorption keeps sapphire depth rich instead of milky white
trans *= exp(-waveBody * 0.065);
}
// 3. FIRE RING (Middle): Saturated roaring curled-fBM volumetric fire tongues (crimson -> orange -> amber-gold)
vec3 q2 = gR2 * (p - gC2);
vec2 cp2 = vec2(length(q2.xz) - 1.18, q2.y);
float d2 = length(cp2);
if (d2 < 0.56) {
maxStep = min(maxStep, 0.028);
float th = atan(q2.z, q2.x);
float thSpin = th + 1.0 * gLoop;
// Advected 3D curl-fBM coordinates (roaring swirl + sharp upward-licking tongues)
vec3 fCoord = vec3(cos(thSpin) * 4.0, sin(thSpin) * 4.0, cp2.y * 4.6 - 0.60 * cp2.x);
float turb = fbmCurl(fCoord);
float fine = gyroid(fCoord * 2.6 + vec3(0.0, 2.0 * sin(gLoop), 2.0 * cos(gLoop)));
float yRise = cp2.y + 0.05;
float flameH = 0.22 + 0.22 * (0.5 + 0.5 * turb) + 0.08 * fine;
float yNorm = clamp(yRise / max(flameH, 0.08), 0.0, 1.4);
float radCenter = 0.040 + 0.105 * yNorm + 0.055 * turb * yNorm;
float radHalfW = mix(0.105, 0.028, clamp(yNorm, 0.0, 1.0));
float radD = abs(cp2.x - radCenter) / max(radHalfW, 0.02);
float baseEnv = smoothstep(-0.07, 0.03, yRise) * smoothstep(1.22, 0.12, yNorm) * exp(-radD * radD * 1.75);
// Sharp sculpted flame tongues with crisp turbulent dark cutouts (zero milky haze!)
float dens = smoothstep(0.16, 0.78, baseEnv * (0.85 + 0.75 * turb + 0.32 * fine));
// Tight molten core strictly along the inner iron rim
float coreBand = exp(-length(cp2 - vec2(0.022, 0.008)) * 24.0) * (0.65 + 0.35 * turb);
// Hyper-saturated blackbody fire ramp (reserves white-gold ONLY for tiny inner core so ACES stays rich!)
float temp = clamp(1.0 - yNorm * 1.05 + 0.28 * coreBand + 0.16 * fine, 0.0, 1.0);
vec3 fCol = mix(vec3(0.72, 0.025, 0.004), vec3(1.00, 0.22, 0.010), smoothstep(0.08, 0.52, temp));
fCol = mix(fCol, vec3(1.00, 0.60, 0.05), smoothstep(0.54, 0.86, temp));
fCol = mix(fCol, vec3(1.00, 0.90, 0.42), smoothstep(0.88, 0.99, temp));
float emit = (dens * 2.25 + coreBand * 1.15);
acc += fCol * emit * trans;
trans *= exp(-dens * 0.095);
}
// 4. WIND / LIGHTNING RING: Thick turbulent emerald wind vortex + 5 razor-sharp branching electric arcs
vec3 q3 = gR3 * (p - gC3);
vec2 cp3 = vec2(length(q3.xz) - 1.74, q3.y);
float d3 = length(cp3);
if (d3 < 0.54) {
// Fine adaptive step so rays NEVER skip over razor-thin lightning bolts!
maxStep = min(maxStep, (d3 < 0.34) ? 0.019 : 0.042);
float th = atan(q3.z, q3.x);
float thSpin = th - 2.0 * gLoop;
// Thick roaring translucent emerald-jade swirling wind vortex ribbon
vec3 wCoord = vec3(cos(thSpin) * 3.2, sin(thSpin) * 3.2, cp3.y * 5.2 + cp3.x * 3.5);
float wTurb = fbmCurl(wCoord);
vec2 wp3 = cp3 - vec2(0.075 + 0.035 * wTurb, 0.025 * wTurb);
wp3 = rot2(0.22) * wp3;
float vortexEnv = exp(-length(wp3 * vec2(1.0, 2.3)) * 8.5) * smoothstep(-0.10, 0.04, cp3.x);
float windStreaks = smoothstep(-0.25, 0.75, wTurb + 0.35 * sin(th * 9.0 - 3.0 * gLoop + cp3.x * 16.0));
vec3 vortexCol = mix(vec3(0.02, 0.44, 0.24), vec3(0.14, 0.95, 0.56), windStreaks);
acc += vortexCol * vortexEnv * (0.75 + 1.35 * windStreaks) * 1.45;
// 5 dense, razor-sharp crackling & branching electric lightning bolts!
// Bolt 1: Primary high-voltage jagged arc wrapping 360 deg
vec2 b1 = vec2(
0.055 + 0.105 * triWave(th * 6.0 - 3.0 * gLoop) + 0.048 * triWave(th * 17.0 + 4.0 * gLoop) + 0.020 * triWave(th * 35.0 - 5.0 * gLoop),
0.010 + 0.090 * triWave(th * 8.0 - 3.0 * gLoop + 1.1) + 0.038 * triWave(th * 21.0 - 4.0 * gLoop) + 0.016 * triWave(th * 43.0 + 3.0 * gLoop)
);
float db1 = length(cp3 - b1);
float m1 = 0.45 + 0.55 * smoothstep(-0.35, 0.45, sin(th * 2.0 - gLoop) + 0.45 * sin(th * 5.0 + 2.0 * gLoop));
acc += (vec3(0.92, 1.00, 0.97) * exp(-db1 * 76.0) * 9.5 +
vec3(0.08, 1.00, 0.52) * exp(-db1 * 20.0) * 1.85) * m1;
// Bolt 2: Secondary counter-winding jagged arc
vec2 b2 = vec2(
0.085 - 0.095 * triWave(th * 7.0 + 2.0 * gLoop + 0.7) + 0.042 * triWave(th * 19.0 - 3.0 * gLoop) + 0.018 * triWave(th * 39.0 + 5.0 * gLoop),
-0.015 - 0.075 * triWave(th * 10.0 + 2.0 * gLoop) + 0.034 * triWave(th * 23.0 + 4.0 * gLoop)
);
float db2 = length(cp3 - b2);
float m2 = 0.40 + 0.60 * smoothstep(-0.25, 0.50, cos(th * 3.0 - 2.0 * gLoop) + 0.35 * sin(th * 7.0 - gLoop));
acc += (vec3(0.88, 1.00, 0.95) * exp(-db2 * 74.0) * 8.5 +
vec3(0.06, 0.98, 0.50) * exp(-db2 * 19.0) * 1.65) * m2;
// Bolt 3: Outer crackling fork leaping outward
vec2 b3 = vec2(
0.185 + 0.110 * triWave(th * 11.0 - 4.0 * gLoop) + 0.045 * triWave(th * 27.0 + 5.0 * gLoop),
0.065 * triWave(th * 13.0 - 3.0 * gLoop + 2.2) + 0.028 * triWave(th * 31.0 - 4.0 * gLoop)
);
float db3 = length(cp3 - b3);
float m3 = pow(max(0.0, sin(th * 3.0 - 2.0 * gLoop + 0.6)), 1.8);
acc += (vec3(0.94, 1.00, 0.97) * exp(-db3 * 82.0) * 8.0 +
vec3(0.10, 1.00, 0.56) * exp(-db3 * 22.0) * 1.35) * m3;
// Bolt 4: Tight inner high-frequency arc snapping off the inner rim
vec2 b4 = vec2(
-0.025 + 0.060 * triWave(th * 13.0 + 3.0 * gLoop) + 0.025 * triWave(th * 29.0 - 4.0 * gLoop),
0.045 * triWave(th * 9.0 + 3.0 * gLoop + 1.7)
);
float db4 = length(cp3 - b4);
float m4 = pow(max(0.0, cos(th * 4.0 + gLoop - 0.5)), 2.0);
acc += (vec3(0.90, 1.00, 0.96) * exp(-db4 * 85.0) * 7.2 +
vec3(0.12, 1.00, 0.60) * exp(-db4 * 24.0) * 1.20) * m4;
}
return vec4(acc, maxStep);
}
// --- Flying elemental sparks, embers & water spray droplets (36 analytical 3D streaks) ---
vec3 evalElementalSparks(vec3 ro, vec3 rd, float maxT) {
vec3 col = vec3(0.0);
for (int i = 0; i < 36; i++) {
float fi = float(i);
int family = i % 3; // 0=fire ember, 1=water spray droplet, 2=lightning spark
float seed = fi * 1.6180339;
float speed = (family == 0) ? 1.0 : ((family == 1) ? -1.0 : 2.0);
float ang = fract(seed) * TAU + speed * gLoop;
float rad = (family == 1) ? (1.42 + 0.68 * fract(seed * 3.17)) :
(family == 0) ? (1.05 + 1.15 * fract(seed * 3.17)) :
(1.45 + 0.95 * fract(seed * 3.17));
float yBase = (family == 1) ? (0.68 + 0.58 * sin(seed * 7.3)) :
(family == 0) ? (0.14 + 0.85 * cos(seed * 5.1)) :
(-0.78 + 0.60 * sin(seed * 9.7));
float yPos = yBase + 0.16 * sin(gLoop + seed * TAU);
vec3 sp = vec3(cos(ang) * rad, yPos, sin(ang) * rad);
vec3 tang = normalize(vec3(-sin(ang) * speed, 0.14 * cos(gLoop + seed * TAU), cos(ang) * speed));
vec3 w = sp - ro;
float tRay = dot(w, rd);
if (tRay < 0.25 || tRay > maxT) continue;
vec3 closest = ro + rd * tRay;
vec3 diff = closest - sp;
float streakLen = (family == 1) ? 0.022 : 0.085; // crisp droplets for water, streaks for embers/sparks
float along = clamp(dot(diff, tang), -streakLen, streakLen);
float d = length(diff - tang * along);
float core = exp(-d * 98.0);
float halo = exp(-d * 24.0) * 0.18;
float twinkle = 0.60 + 0.40 * sin(gLoop * 3.0 + fi * 2.7);
vec3 sCol = (family == 0) ? vec3(1.00, 0.54, 0.12) :
(family == 1) ? vec3(0.65, 0.94, 1.00) :
vec3(0.45, 1.00, 0.72);
col += sCol * (core * 1.65 + halo) * twinkle;
}
return col;
}
// --- Dark moody colosseum arena backdrop ---
vec3 evalBackdrop(vec3 rd) {
if (uLightMode == 1) {
float grad = 0.22 + 0.12 * clamp(rd.y * 0.8 + 0.5, 0.0, 1.0);
return vec3(grad);
}
float up = clamp(rd.y * 0.5 + 0.5, 0.0, 1.0);
vec3 col = mix(vec3(0.0026, 0.0038, 0.0058), vec3(0.0012, 0.0018, 0.0032), up);
// Subtle circular colosseum gallery tiers & arches
float az = atan(rd.z, rd.x);
float tier1 = smoothstep(0.16, 0.03, abs(rd.y + 0.03));
float tier2 = smoothstep(0.12, 0.02, abs(rd.y - 0.18));
float pillars = 0.5 + 0.5 * cos(az * 24.0);
col += vec3(0.0032, 0.0044, 0.0066) * (tier1 + 0.6 * tier2) * (0.35 + 0.65 * pillars);
// Subtle distant overhead arena spotlights
float spotBand = smoothstep(0.16, 0.04, abs(rd.y - 0.36));
float spots = pow(max(0.0, cos(az * 8.0 + 0.35)), 26.0);
col += vec3(0.032, 0.044, 0.062) * spotBand * spots;
float centerGlow = exp(-length(rd.xy - vec2(0.0, -0.02)) * 3.0);
if (uLightMode == 3) {
col += vec3(0.14, 0.24, 0.38) * pow(centerGlow, 1.3);
} else if (uLightMode == 2) {
col += vec3(0.007, 0.011, 0.018) * centerGlow;
} else {
col += vec3(0.005, 0.011, 0.020) * centerGlow;
}
return col;
}
// --- ACES Filmic Tonemapping ---
vec3 acesTonemap(vec3 x) {
const float a = 2.51;
const float b = 0.03;
const float c = 2.43;
const float d = 0.59;
const float e = 0.14;
vec3 y = clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0.0, 1.0);
return y * 0.965;
}
// --- Surface Shading ---
vec3 shadeSurface(vec3 p, vec3 n, vec3 v, float matID, float tHit) {
float ao = calcAO(p, n);
vec3 keyDir, keyCol, fillDir, fillCol, rimDir, rimCol;
if (uLightMode == 1) {
keyDir = normalize(vec3(0.62, 0.72, 0.52));
keyCol = vec3(1.15);
fillDir = normalize(vec3(-0.75, 0.30, 0.45));
fillCol = vec3(0.36);
rimDir = normalize(vec3(-0.20, 0.55, -0.82));
rimCol = vec3(0.55);
} else if (uLightMode == 2) {
keyDir = normalize(vec3(0.92, 0.22, 0.32));
keyCol = vec3(1.75, 1.52, 1.28);
fillDir = normalize(vec3(-0.70, 0.38, 0.50));
fillCol = vec3(0.12, 0.18, 0.28);
rimDir = normalize(vec3(-0.35, 0.50, -0.80));
rimCol = vec3(0.30, 0.50, 0.78);
} else if (uLightMode == 3) {
keyDir = normalize(vec3(0.18, 0.42, -0.89));
keyCol = vec3(1.65, 1.80, 2.00);
fillDir = normalize(vec3(0.35, 0.45, 0.80));
fillCol = vec3(0.10, 0.15, 0.22);
rimDir = normalize(vec3(-0.28, 0.35, -0.89));
rimCol = vec3(0.95, 1.10, 1.35);
} else {
keyDir = normalize(vec3(0.52, 0.78, 0.48));
keyCol = vec3(0.95, 1.02, 1.18);
fillDir = normalize(vec3(-0.68, 0.35, 0.52));
fillCol = vec3(0.14, 0.22, 0.36);
rimDir = normalize(vec3(-0.25, 0.55, -0.80));
rimCol = vec3(0.45, 0.70, 1.05);
}
float sh = calcShadow(p + n * 0.015, keyDir, 5.5);
float ndl = max(dot(n, keyDir), 0.0);
float ndf = max(dot(n, fillDir), 0.0);
float ndv = max(dot(n, v), 0.0);
float fres = pow(1.0 - ndv, 3.8);
vec3 hKey = normalize(keyDir + v);
vec3 hRim = normalize(rimDir + v);
// --- Mode 1: Pure neutral grayscale clay/form study (R == G == B, emission muted) ---
if (uLightMode == 1) {
float alb = 0.56;
float specPow = 28.0;
float specStr = 0.22;
if (matID < 1.5) {
alb = 0.76; specPow = 72.0; specStr = 0.42;
} else if (matID > 10.5) {
alb = 0.38; specPow = 48.0; specStr = 0.32;
} else if (matID > 4.5) {
alb = 0.44; specPow = 18.0; specStr = 0.12;
} else if (matID < 2.5) {
alb = 0.68; specPow = 42.0; specStr = 0.32;
} else if (matID < 3.5) {
alb = 0.62; specPow = 24.0; specStr = 0.24;
} else {
alb = 0.65; specPow = 32.0; specStr = 0.26;
}
float diff = alb * (ndl * sh * keyCol.x + ndf * fillCol.x + 0.15 * ao);
float spec = pow(max(dot(n, hKey), 0.0), specPow) * specStr * sh;
float rim = fres * (0.26 + 0.48 * max(dot(n, rimDir), 0.0)) * rimCol.x;
return vec3(diff + spec + rim);
}
float emitScale = (uLightMode == 2) ? 0.72 : ((uLightMode == 3) ? 0.85 : 1.0);
vec3 col = vec3(0.0);
// 1. Central Faceted Crystal Core (dramatic dark-sapphire vs dazzling specular facet contrast)
if (matID < 1.5) {
float pulse = 0.90 + 0.10 * sin(gLoop * 2.0);
// Tight razor-thin edge sparkle (not thick white outlines)
vec3 tAxis = normalize(abs(n.y) < 0.9 ? cross(n, vec3(0.0, 1.0, 0.0)) : cross(n, vec3(1.0, 0.0, 0.0)));
vec3 bAxis = cross(n, tAxis);
float edgeCurv = length(n - calcNormal(p + tAxis * 0.0045)) + length(n - calcNormal(p + bAxis * 0.0045));
float bevelGlint = smoothstep(0.18, 0.75, edgeCurv);
// Refracted internal ray for focused heart glow & internal caustic veins
vec3 rIn = refract(-v, n, 1.0 / 1.60);
vec3 pMid = p + rIn * 0.16;
vec3 pFar = p + rIn * 0.32;
// Core glow concentrated toward lower-center heart like 02.png
float coreDist = length((pMid - (gCrysPos - vec3(0.0, 0.06, 0.0))) * vec3(2.2, 1.35, 2.2));
float coreGlow = exp(-coreDist * 5.2) * pulse;
vec3 qFar = pFar - gCrysPos;
qFar.xz = gCrysRot * qFar.xz;
float caustic = pow(abs(sin(qFar.x * 18.0 + qFar.y * 14.0) * cos(qFar.z * 18.0 - qFar.y * 12.0)), 2.2);
float backFacet = smoothstep(-0.07, 0.015, sdCrystal(pFar));
float dispPhase = dot(n, v) * 6.5 + dot(rIn, vec3(1.2, 2.1, -1.6)) * 3.2;
vec3 prism = 0.50 + 0.50 * cos(vec3(0.0, 1.9, 3.8) + dispPhase);
// High-contrast facet shading: deep indigo-sapphire shadow facets vs bright lit facets
vec3 facetBase = mix(vec3(0.015, 0.055, 0.20), vec3(0.12, 0.54, 0.98), pow(ndl, 1.3) * 0.85 + ndf * 0.25);
vec3 internalLight = mix(vec3(0.08, 0.62, 1.00), vec3(0.95, 0.99, 1.00), coreGlow) * (0.12 + 1.85 * coreGlow);
internalLight += prism * (0.32 * caustic + 0.42 * backFacet) * emitScale;
float spec = pow(max(dot(n, hKey), 0.0), 160.0) * 3.0;
float rimSpec = pow(max(dot(n, hRim), 0.0), 72.0) * 1.5;
col = facetBase * (0.50 + 0.50 * ao) + internalLight * emitScale;
col += vec3(0.45, 0.85, 1.00) * fres * 1.15;
col += vec3(0.96, 0.99, 1.00) * (spec * sh + rimSpec + bevelGlint * 0.85);
// Reflected fire & emerald highlights on grazing crystal facets
col += vec3(1.00, 0.36, 0.08) * pow(max(dot(n, normalize(vec3(0.7, 0.1, 0.5))), 0.0), 3.5) * 0.42 * emitScale;
col += vec3(0.10, 0.95, 0.52) * pow(max(-n.y, 0.0), 2.4) * 0.36 * emitScale;
return col;
}
// 2. Sculpted Crashing Translucent Sapphire-Cyan Water Wave (Top Ring)
if (matID < 2.5) {
vec3 q1 = gR1 * (p - gC1);
float th = atan(q1.z, q1.x);
float thSpin = th - 1.0 * gLoop;
vec2 cp1 = vec2(length(q1.xz) - 1.62, q1.y);
// Lacy white seafoam crests via ridged 3D gyroid lace
vec3 foamCoord = vec3(cos(thSpin) * 6.5, sin(thSpin) * 6.5, cp1.y * 12.0 + cp1.x * 9.0);
float lace = fbmLace(foamCoord);
float crestHeight = smoothstep(-0.02, 0.12, cp1.y + 0.05 * n.y);
float foam = smoothstep(0.48, 0.88, lace * 0.72 + crestHeight * 0.48 + fres * 0.25);
// Optical translucency: deep sapphire in thick interior, luminous aqua-cyan at thin edges/backlit
float thinEdge = pow(1.0 - ndv, 2.0);
vec3 refrCol = evalBackdrop(refract(-v, n, 1.0 / 1.333));
vec3 deepWater = vec3(0.015, 0.14, 0.52);
vec3 brightAqua = vec3(0.14, 0.76, 1.00);
vec3 waterBody = mix(deepWater, brightAqua, clamp(thinEdge * 0.75 + crestHeight * 0.45 + ndl * 0.35, 0.0, 1.0));
waterBody = mix(waterBody, refrCol + vec3(0.06, 0.36, 0.82), 0.32 * (1.0 - foam));
// Crisp wet speculars + reflected fiery orange glints on water crests
float spec = pow(max(dot(n, hKey), 0.0), 128.0) * 2.4;
float rimS = pow(max(dot(n, hRim), 0.0), 56.0) * 1.25;
col = waterBody * (0.45 + 0.75 * ndl * sh + 0.35 * emitScale);
col = mix(col, vec3(0.86, 0.97, 1.00) * (0.85 + 0.55 * ndl), foam * 0.86);
col += vec3(0.55, 0.90, 1.00) * fres * 1.05 * emitScale;
col += vec3(0.95, 0.99, 1.00) * (spec * sh + rimS * 0.8);
// Subtle reflected orange fire glow on the underside of the water wave
col += vec3(1.00, 0.40, 0.08) * pow(max(-n.y, 0.0), 2.0) * 0.22 * emitScale;
return col;
}
// 11, 12, 13: Razor-thin dark gunmetal-chrome inner edge accents (NOT bright pastel plastic!)
if (matID > 10.5) {
vec3 elemTint = (matID < 11.5) ? vec3(0.25, 0.78, 1.00) :
(matID < 12.5) ? vec3(1.00, 0.42, 0.06) :
vec3(0.14, 0.96, 0.54);
vec3 darkChrome = vec3(0.018, 0.022, 0.028);
float spec = pow(max(dot(n, hKey), 0.0), 120.0) * 2.2;
float rimS = pow(max(dot(n, hRim), 0.0), 64.0) * 1.1;
col = darkChrome * (ndl * sh * keyCol + ndf * fillCol + 0.18 * ao);
col += elemTint * (fres * 0.65 + 0.08 * emitScale);
col += vec3(0.92, 0.96, 1.00) * (spec * sh + rimS * 0.65);
return col;
}
// 5. Dark Atmospheric Colosseum Arena Floor
float r = length(p.xz);
float a = atan(p.z, p.x);
float grain = vnoise2(p.xz * 7.5) * 0.55 + vnoise2(p.xz * 21.0) * 0.45;
float gLine = smoothstep(0.034, 0.008, min(min(abs(r - 1.15), abs(r - 1.94)), min(abs(r - 2.74), abs(r - 3.62))));
float radLine = smoothstep(0.028, 0.007, abs(sin(a * 6.0)) * r) * smoothstep(1.12, 1.28, r);
vec3 stone = mix(vec3(0.013, 0.017, 0.024), vec3(0.026, 0.032, 0.042), grain);
stone *= (1.0 - 0.55 * max(gLine, radLine * 0.75));
float spec = pow(max(dot(n, hKey), 0.0), 36.0) * (0.22 + 0.28 * grain);
col = stone * (ndl * sh * keyCol + ndf * fillCol + 0.28 * ao);
col += vec3(0.28, 0.36, 0.48) * spec * sh;
// Vivid elemental floor reflections
float emeraldBounce = exp(-abs(r - 1.74) * 1.45) * 0.38;
float crysBounce = exp(-r * 1.15) * 0.22;
float fireBounce = exp(-abs(r - 1.18) * 1.75) * 0.18;
float waterBounce = exp(-abs(r - 1.62) * 1.20) * 0.12;
col += vec3(0.06, 0.94, 0.50) * emeraldBounce * (0.45 + 0.55 * grain) * emitScale;
col += vec3(0.20, 0.78, 1.00) * crysBounce * emitScale;
col += vec3(1.00, 0.34, 0.04) * fireBounce * emitScale;
col += vec3(0.12, 0.54, 1.00) * waterBounce * emitScale;
float fog = 1.0 - exp(-max(tHit - 5.2, 0.0) * 0.16);
col = mix(col, vec3(0.0026, 0.0038, 0.0058), clamp(fog, 0.0, 0.95));
return col;
}
void main() {
setupRig();
vec2 uv = (gl_FragCoord.xy - 0.5 * uResolution.xy) / uResolution.y;
// Camera framing: 0 = hero full framing, 1 = ~2.6x macro close-up
vec3 ro, ta;
float focal;
if (uCamMode == 1) {
ro = vec3(0.38 + 0.08 * sin(gLoop), 0.18 + 0.03 * cos(gLoop), 2.74);
ta = vec3(0.0, 0.02, 0.0);
focal = 1.72;
} else {
ro = vec3(0.12 * sin(gLoop), 0.38 + 0.04 * cos(gLoop), 6.42);
ta = vec3(0.0, -0.06, 0.0);
focal = 1.48;
}
vec3 ww = normalize(ta - ro);
vec3 uu = normalize(cross(ww, vec3(0.0, 1.0, 0.0)));
vec3 vv = cross(uu, ww);
vec3 rd = normalize(uu * uv.x + vv * uv.y + ww * focal);
// Raymarch solid geometry + simultaneous roaring volumetric elemental streams
float t = 0.0;
float tMax = 20.0;
float matID = -1.0;
vec3 volVFX = vec3(0.0);
float trans = 1.0;
bool doVol = (uLightMode != 1);
float volScale = (uLightMode == 2) ? 0.72 : ((uLightMode == 3) ? 0.86 : 1.0);
for (int i = 0; i < 112; i++) {
vec3 p = ro + rd * t;
vec2 h = mapScene(p);
float d = h.x;
if (d < 0.0016) {
matID = h.y;
break;
}
float stepLen = clamp(d, 0.018, 0.38);
if (doVol && t > 0.30 && t < 10.8 && length(p) < 2.95) {
vec4 vfx = evalVolumetricStreams(p, trans);
stepLen = min(stepLen, vfx.w);
volVFX += vfx.rgb * stepLen;
}
t += (d < 0.08) ? min(d, stepLen) : stepLen;
if (t > tMax) break;
}
vec3 col;
if (matID > 0.0) {
vec3 p = ro + rd * t;
vec3 n = calcNormal(p);
col = shadeSurface(p, n, -rd, matID, t);
} else {
col = evalBackdrop(rd);
}
if (doVol) {
// Blend surface with flame transmittance + add roaring volumetric streams & sparks
col = col * mix(1.0, trans, 0.55) + volVFX * volScale;
col += evalElementalSparks(ro, rd, (matID > 0.0) ? t : tMax) * volScale;
}
if (uLightMode == 1) {
float g = acesTonemap(col).x;
g = pow(clamp(g, 0.0, 1.0), 1.0 / 2.2);
fragColor = vec4(vec3(g), 1.0);
} else {
col = acesTonemap(col);
col = max(col, vec3(0.0014, 0.0019, 0.0028));
col = pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2));
fragColor = vec4(col, 1.0);
}
}
`;
export function createOrbitingElementalTrinityRingsMaterial(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 | orbiting-elemental-trinity-rings |
|---|---|
| Category | Game VFX Shaders · Choreographed Loop VFX |
| Upstream study | vfx_animated/lib/02_orbiting_elemental_trinity_rings.glsl (commit f3d2025) |
| Animation cycle | 3.0 s seamless harmonic loop |
| Declared uniforms | uResolution, uTime, uOpen, uLightMode, uCamMode |
| Source size | 870 lines · 33.2 KB standalone GLSL ES 3.00 |
| PNG baker outputs | 512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key) |
| Companion pixel VFX | Free MIT status sprite sheets |
| License | MIT License + CC0 / MIT Helpers |
Schlick Fresnel reflectance (1994); Beer–Lambert volumetric absorption/attenuation; Planck blackbody radiation color approximation
Krzysztof Narkowicz, filmic curve · Inigo Quilez, quadratic distance blend · Inigo Quilez, tetrahedral SDF normal
3s LoopDirectional rolling fire wave surging down stone tiles with trailing scorched embers.
3s LoopPulsating cosmic glass orb enclosing volumetric star-cloud filaments and Fresnel caustics.
3s LoopMulti-angle anime sword combo ribbons criss-crossing with impact flashes in a 3s loop.
3s LoopSweeping twin solar-flame wings unfurling upward with molten feather embers.
AnimatedExpanding sci-fi holo-grid scan wave snapping across metallic floor tiles with electric arcs.
AnimatedHelical translucent water torrent coiling skyward with white foam crests and spray droplets.