3s LoopTectonic rock slabs heaving upward over glowing amber fault cracks and dust plumes.
frost-teal-ice-nova-spikes.glsl · 787 lines · GLSL ES 3.00 · MIT
#version 300 es
// Frost Teal Ice Nova Spikes (frost-teal-ice-nova-spikes.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_stylized/lib/05_frost_teal_ice_nova_spikes.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;
// ============================================================================
// FROST-TEAL ICE NOVA SPIKES — STYLIZED CEL-SHADED VFX
// ============================================================================
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
// Shared style contract & Glacial Frost-Teal palette
const vec3 COL_FLOOR_BASE = vec3(0.08, 0.09, 0.12);
const vec3 COL_INK = vec3(0.032, 0.042, 0.062); // Deep comic ink (avoids pure-black clip)
const vec3 COL_ABYSS = vec3(0.045, 0.22, 0.34);
const vec3 COL_ICE_SHADOW = vec3(0.11, 0.44, 0.66);
const vec3 COL_ICE_MID = vec3(0.36, 0.81, 0.96);
const vec3 COL_ICE_LIGHT = vec3(0.82, 0.95, 1.00);
const vec3 COL_ICE_WHITE = vec3(0.95, 0.99, 1.00);
const vec3 COL_SLAB_TOP = vec3(0.68, 0.86, 0.95);
const vec3 COL_SLAB_SIDE = vec3(0.24, 0.64, 0.84);
const vec3 COL_CORE_CYAN = vec3(0.18, 0.88, 1.00);
// Material IDs
const float MAT_FLOOR = 1.0;
const float MAT_SLAB = 2.0;
const float MAT_SPIKE = 3.0;
const float MAT_SHARD = 4.0;
const float MAT_ABYSS = 5.0;
const float MAT_RIM = 6.0;
// ============================================================================
// MATH & NOISE UTILITIES
// ============================================================================
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
float hash11(float p) {
p = fract(p * 0.1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
float hash12(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(
mix(hash12(i + vec2(0.0, 0.0)), hash12(i + vec2(1.0, 0.0)), u.x),
mix(hash12(i + vec2(0.0, 1.0)), hash12(i + vec2(1.0, 1.0)), u.x),
u.y
);
}
float fbm2(vec2 p) {
float v = 0.0;
float a = 0.5;
mat2 m = mat2(0.80, -0.60, 0.60, 0.80);
for (int i = 0; i < 4; i++) {
v += a * vnoise2(p);
p = m * p * 2.03 + vec2(11.3, 7.1);
a *= 0.5;
}
return v;
}
vec3 safeNorm(vec3 v) {
float l = length(v);
return l > 1e-6 ? v / l : vec3(0.0, 1.0, 0.0);
}
// ============================================================================
// FACETED CRYSTAL & CRATER SDF PRIMITIVES
// ============================================================================
// Exact hexagonal distance in XZ plane (flat-to-flat radius = r)
float sdHex2D(vec2 p) {
p = abs(p);
return max(p.x * 0.8660254 + p.y * 0.5, p.y);
}
// Faceted hexagonal crystal obelisk: base at y=0, tip at y=h, shaft radius r
float sdHexCrystal(vec3 p, float r, float h, float tipFrac) {
float tipY = h * (1.0 - tipFrac);
float tipH = max(h * tipFrac, 0.05);
float hexD = sdHex2D(p.xz);
// Slight outward flare along the shaft for stylized heroic silhouette
float shaftSlope = 0.05;
float rAtY = r * (0.90 + 0.14 * clamp(p.y / max(tipY, 0.05), 0.0, 1.0));
float dShaft = (hexD - rAtY) * 0.998;
// Exact 6-sided pyramidal tip planes
float rTop = r * 1.04;
vec2 tipN = normalize(vec2(tipH, rTop));
float dTip = dot(vec2(hexD, p.y - tipY), tipN) - rTop * tipN.x;
// Base cap
float dBase = -p.y;
return max(max(dShaft, dTip), dBase);
}
// Faceted hexagonal bipyramid (floating comic frost shard)
float sdHexShard(vec3 p, float r, float hTop, float hBot) {
float hexD = sdHex2D(p.xz);
vec2 nTop = normalize(vec2(hTop, r));
vec2 nBot = normalize(vec2(hBot, r));
float dTop = dot(vec2(hexD, p.y), nTop) - r * nTop.x;
float dBot = dot(vec2(hexD, -p.y), nBot) - r * nBot.x;
return max(dTop, dBot);
}
// Orient a point into a crystal's local frame (origin at pos, +Y along tilt)
vec3 toSpikeLocal(vec3 p, vec3 basePos, float yaw, float tilt, float spin) {
vec3 q = p - basePos;
q.xz = rot2(-yaw) * q.xz;
q.xy = rot2(-tilt) * q.xy;
q.xz = rot2(spin) * q.xz;
return q;
}
// ============================================================================
// SCENE PARAMETERS & ANIMATION (3s LOOP + uOpen)
// ============================================================================
float getPhase() {
return uTime * (TAU / 3.0);
}
float getErupt() {
float o = clamp(uOpen, 0.0, 1.0);
float pulse = 0.045 * sin(getPhase());
return mix(0.58, 1.12, o) + pulse;
}
// Jagged crater radius as a function of azimuth
float craterInnerR(float ang) {
float j = 0.11 * sin(ang * 5.0 + 0.4)
+ 0.07 * cos(ang * 9.0 - 1.1)
+ 0.04 * sin(ang * 13.0 + 2.3);
return 1.18 + j;
}
float craterOuterR(float ang) {
float j = 0.16 * sin(ang * 4.0 - 0.7)
+ 0.10 * cos(ang * 7.0 + 1.5)
+ 0.06 * sin(ang * 11.0 + 0.2);
return 1.88 + j;
}
// Angular fissure gap mask between cracked crater ice slabs (returns >0 inside crack)
float slabCrackDist(float ang, float r) {
// 9 irregular radial cracks around the crater ring
float aNorm = fract(ang / TAU + 1.0);
float seg = aNorm * 9.0;
float id = floor(seg);
float f = fract(seg);
float jitter = (hash11(id * 17.3 + 3.1) - 0.5) * 0.24;
// Zig-zag radial wobble
float zig = 0.055 * sin(r * 14.0 + id * 4.7) + 0.03 * cos(r * 25.0 - id * 2.1);
float dEdge = min(abs(f - 0.5 + jitter + zig), min(abs(f + jitter + zig), abs(f - 1.0 + jitter + zig)));
// Use distance to nearest seam (at f ~ 0 + jitter)
float seam = abs(fract(seg + 0.5 + jitter + zig) - 0.5);
return seam * (TAU / 9.0) * max(r, 0.8);
}
// ============================================================================
// SCENE SDF: returns vec2(distance, materialID)
// ============================================================================
vec2 opMin(vec2 a, vec2 b) {
return a.x < b.x ? a : b;
}
// Only the hero crystals & floating shards (with tight ring bounds for fast marching)
vec2 mapCrystals(vec3 p) {
float erupt = getErupt();
float phase = getPhase();
vec2 res = vec2(1e5, MAT_SPIKE);
// Quick bounding sphere for entire spike cluster
float boundAll = length(p - vec3(0.0, 1.35, 0.0)) - 4.1;
if (boundAll > 0.25) {
return vec2(boundAll, MAT_SPIKE);
}
float rXZ = length(p.xz);
// 1. HERO CENTRAL SPIRE (towering hexagonal obelisk)
if (rXZ < 0.85 && p.y > -0.35 && p.y < 3.65) {
vec3 q = p - vec3(0.0, -0.15, 0.0);
q.xz = rot2(0.28) * q.xz;
float h = 2.95 * erupt;
float r = 0.31;
float dMain = sdHexCrystal(q, r, h, 0.28);
float notch1 = length(q - vec3(0.29, 0.92 * erupt, 0.10)) - 0.14;
float notch2 = length(q - vec3(-0.27, 1.25 * erupt, -0.06)) - 0.12;
dMain = max(dMain, -min(notch1, notch2));
res = opMin(res, vec2(dMain, MAT_SPIKE));
}
// 2. PRIMARY RADIAL CRYSTAL SPIKES (10 bold spikes jutting around crater)
if (rXZ > 0.65 && rXZ < 3.95 && p.y > -0.35 && p.y < 2.65) {
float spAngles[10] = float[10](
-0.55, 0.08, 0.62, 1.28, 1.95, 2.52, 3.05, 3.68, 4.32, 5.02
);
float spHeights[10] = float[10](
1.78, 1.65, 1.48, 1.35, 1.85, 1.68, 1.32, 1.45, 1.92, 1.15
);
float spRadii[10] = float[10](
0.24, 0.22, 0.19, 0.18, 0.23, 0.22, 0.18, 0.19, 0.25, 0.16
);
float spTilts[10] = float[10](
0.96, 1.16, 0.86, 0.62, 0.78, 0.92, 1.12, 1.05, 1.08, 1.22
);
float spDist[10] = float[10](
1.48, 1.55, 1.42, 1.26, 1.38, 1.46, 1.50, 1.45, 1.52, 1.58
);
for (int i = 0; i < 10; i++) {
float ang = spAngles[i];
float ca = cos(ang), sa = sin(ang);
vec3 base = vec3(ca * spDist[i], -0.04, sa * spDist[i]);
float breathe = 1.0 + 0.03 * sin(phase + float(i) * 0.9);
float h = spHeights[i] * erupt * breathe;
vec3 mid = base + vec3(ca * sin(spTilts[i]), cos(spTilts[i]), sa * sin(spTilts[i])) * (h * 0.5);
if (length(p - mid) < h * 0.60 + 0.30) {
vec3 q = toSpikeLocal(p, base, -ang, spTilts[i], float(i) * 0.53);
float d = sdHexCrystal(q, spRadii[i], h, 0.36);
res = opMin(res, vec2(d, MAT_SPIKE));
}
}
}
// 3. INNER NEEDLE SPIKES (6 sleek sharp spikes framing the central spire)
if (rXZ > 0.35 && rXZ < 2.15 && p.y > -0.25 && p.y < 2.25) {
for (int i = 0; i < 6; i++) {
float fi = float(i);
float ang = fi * (TAU / 6.0) + 0.36;
float ca = cos(ang), sa = sin(ang);
vec3 base = vec3(ca * 0.82, -0.05, sa * 0.82);
float h = (1.30 + 0.38 * hash11(fi * 5.7 + 1.2)) * erupt;
float tilt = 0.34 + 0.14 * hash11(fi * 9.3 + 2.4);
vec3 mid = base + vec3(ca * sin(tilt), cos(tilt), sa * sin(tilt)) * (h * 0.5);
if (length(p - mid) < h * 0.60 + 0.22) {
vec3 q = toSpikeLocal(p, base, -ang, tilt, fi * 0.8);
float d = sdHexCrystal(q, 0.115, h, 0.42);
res = opMin(res, vec2(d, MAT_SPIKE));
}
}
}
// 4. FLOATING / LEVITATING ANGULAR COMIC FROST SHARDS (8 outer shards)
if (rXZ > 1.45 && rXZ < 3.40 && p.y > 0.35 && p.y < 3.25) {
float shAngles[8] = float[8](
-2.25, -1.55, -0.82, 0.35, 1.12, 2.08, 2.75, 3.85
);
float shR[8] = float[8](
2.15, 2.55, 2.25, 2.35, 2.60, 2.30, 2.45, 2.20
);
float shY[8] = float[8](
1.85, 2.35, 1.55, 1.10, 2.10, 1.75, 0.95, 1.35
);
float shSize[8] = float[8](
0.21, 0.15, 0.17, 0.13, 0.18, 0.14, 0.12, 0.16
);
float openY = mix(0.75, 1.05, clamp(uOpen, 0.0, 1.0));
for (int i = 0; i < 8; i++) {
float fi = float(i);
float ang = shAngles[i] + 0.08 * sin(phase + fi * 1.1);
float bob = 0.18 * sin(phase + fi * 1.37);
float rad = shR[i] + 0.08 * cos(phase + fi * 0.83);
vec3 cPos = vec3(cos(ang) * rad, shY[i] * openY + bob, sin(ang) * rad);
float sz = shSize[i];
if (length(p - cPos) < sz * 3.1 + 0.18) {
vec3 q = p - cPos;
q.xz = rot2(-ang + phase * 0.25 * (mod(fi, 2.0) < 0.5 ? 1.0 : -1.0)) * q.xz;
q.xy = rot2(0.45 + 0.2 * sin(fi * 2.1)) * q.xy;
float d = sdHexShard(q, sz * 0.72, sz * 2.35, sz * 1.65);
res = opMin(res, vec2(d, MAT_SHARD));
}
}
}
return res;
}
vec2 mapScene(vec3 p) {
vec2 res = mapCrystals(p);
float r = length(p.xz);
float ang = atan(p.z, p.x);
float rIn = craterInnerR(ang);
float rOut = craterOuterR(ang);
// Arena floor with sunken circular-jagged crater hole
float dFloorPlane = p.y;
// Inside the crater, push floor down to abyss depth (-0.58)
float dCraterHole = r - rIn;
float dAbyss = max(p.y + 0.56, dCraterHole);
float dFloor = max(dFloorPlane, -dCraterHole);
// Raised curved arena parapet rim at R ~ 5.6
float dRim = max(abs(r - 5.65) - 0.32, p.y - 0.24);
dRim = max(dRim, -p.y - 0.1);
res = opMin(res, vec2(dFloor, MAT_FLOOR));
res = opMin(res, vec2(dAbyss, MAT_ABYSS));
res = opMin(res, vec2(dRim, MAT_RIM));
// Cracked polygonal ice crust slabs around crater rim (rIn .. rOut)
if (r > rIn - 0.35 && r < rOut + 0.35 && abs(p.y) < 0.65) {
float crack = slabCrackDist(ang, r);
float slabId = floor(fract(ang / TAU + 1.0) * 9.0);
float slabTilt = (hash11(slabId * 13.1 + 2.0) - 0.5) * 0.09;
float slabH = 0.17 + 0.06 * hash11(slabId * 7.3 + 5.0) + slabTilt * (r - 1.5);
// Slightly raised outer lip & jagged bevel
float dOuter = r - rOut;
float dInner = rIn - r;
float dTop = p.y - slabH;
float dBot = -p.y - 0.58;
float dSlab = max(max(dOuter, dInner), max(dTop, dBot));
// Carve crisp dark-ink fissures between slabs
float crackWidth = 0.055 + 0.02 * (r - rIn);
float dCrackCarve = crackWidth - crack;
dSlab = max(dSlab, dCrackCarve);
// Subtle chamfer on top edge
dSlab = max(dSlab, (p.y - slabH + 0.03) * 0.707 + max(dInner, dOuter) * 0.707);
res = opMin(res, vec2(dSlab, MAT_SLAB));
}
return res;
}
// ============================================================================
// NORMALS & SHADOWS
// ============================================================================
vec3 calcNormal(vec3 p) {
vec2 e = vec2(0.0022, -0.0022);
return safeNorm(
e.xyy * mapScene(p + e.xyy).x +
e.yyx * mapScene(p + e.yyx).x +
e.yxy * mapScene(p + e.yxy).x +
e.xxx * mapScene(p + e.xxx).x
);
}
// Crisp comic cel-shaded hard shadow (16 steps, fast)
float calcShadow(vec3 ro, vec3 rd, float maxT) {
if (length(ro.xz) > 4.6) return 1.0;
float t = 0.05;
float sh = 1.0;
for (int i = 0; i < 16; i++) {
float h = mapCrystals(ro + rd * t).x;
if (h < 0.005) return 0.0;
sh = min(sh, 16.0 * h / t);
t += clamp(h, 0.05, 0.45);
if (t > maxT) break;
}
return smoothstep(0.15, 0.55, sh);
}
// ============================================================================
// JAGGED COMIC STARBURST FLASH CORE (3D BILLBOARD AT CRATER CENTER)
// ============================================================================
// Returns vec4(rgb, alpha) and out hit depth tStar
vec4 evalStarburst(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, vec3 camFwd, out float tStar) {
float phase = getPhase();
float erupt = getErupt();
vec3 center = vec3(0.0, 0.42 * erupt, 0.0);
// Intersect camera-facing plane passing through center
float denom = dot(rd, camFwd);
tStar = 1e5;
if (abs(denom) < 1e-4) return vec4(0.0);
float t = dot(center - ro, camFwd) / denom;
if (t <= 0.05) return vec4(0.0);
tStar = t;
vec3 hitP = ro + rd * t;
vec3 rel = hitP - center;
vec2 uv = vec2(dot(rel, camRight), dot(rel, camUp));
float r = length(uv);
float ang = atan(uv.y, uv.x);
// Scale with eruption and 3s loop pulse
float scale = mix(0.72, 1.08, clamp(uOpen, 0.0, 1.0)) * (1.0 + 0.075 * sin(phase));
float rn = r / max(scale, 0.1);
if (rn > 1.75) return vec4(0.0);
// Sharp jagged 16-ray primary + 9-ray secondary starburst profile
float a1 = ang + 0.06 * sin(phase);
float spike1 = pow(abs(cos(a1 * 8.0 + 0.35 * sin(a1 * 3.0))), 6.0);
float spike2 = pow(abs(sin(a1 * 5.0 - 0.65)), 8.0);
float spike3 = pow(abs(cos(a1 * 13.0 + 1.2 - 0.12 * cos(phase))), 9.0);
// Elongate horizontal & upward rays slightly like 05.png
float dirBias = 0.85 + 0.25 * abs(cos(ang)) + 0.22 * max(sin(ang), 0.0);
float outerR = (0.34 + 0.92 * max(spike1, 0.78 * spike2) + 0.38 * spike3) * dirBias;
float innerR = (0.20 + 0.58 * max(spike1, 0.72 * spike2) + 0.22 * spike3) * dirBias;
float dOut = rn - outerR;
float dIn = rn - innerR;
float aa = 0.018;
float inkMask = 1.0 - smoothstep(0.015, 0.015 + aa, dOut);
float cyanMask = 1.0 - smoothstep(-0.022, -0.022 + aa, dOut);
float whiteMask = 1.0 - smoothstep(0.0, aa, dIn);
// Soft additive halo right around core
float glow = exp(-rn * 2.2) * 0.42;
vec3 col = COL_INK;
col = mix(col, COL_CORE_CYAN, cyanMask);
col = mix(col, COL_ICE_WHITE, whiteMask);
float alpha = clamp(inkMask + glow * (1.0 - inkMask), 0.0, 1.0);
vec3 outCol = mix(COL_CORE_CYAN, col, inkMask);
return vec4(outCol, alpha);
}
// ============================================================================
// COMIC 4-POINT DIAMOND SPARKLES (WORLD-ANCHORED BILLBOARDS)
// ============================================================================
vec3 evalSparkles(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float sceneT) {
float phase = getPhase();
vec3 acc = vec3(0.0);
for (int i = 0; i < 14; i++) {
float fi = float(i);
float ang = fi * (TAU / 14.0) + 0.21;
float rad = 1.95 + 1.25 * hash11(fi * 11.7 + 3.0);
float h = 0.22 + 2.35 * hash11(fi * 7.3 + 9.1);
float bob = 0.14 * sin(phase + fi * 1.6);
vec3 spPos = vec3(cos(ang) * rad, h + bob, sin(ang) * rad);
float t = dot(spPos - ro, rd);
if (t < 0.2 || t > sceneT) continue;
vec3 dVec = ro + rd * t - spPos;
vec2 uv = vec2(dot(dVec, camRight), dot(dVec, camUp));
float twinkle = 0.65 + 0.35 * sin(phase * 2.0 + fi * 2.3);
float sz = (0.08 + 0.06 * hash11(fi * 4.1)) * twinkle;
vec2 a = abs(uv) / max(sz, 0.01);
// Crisp 4-point astroid diamond star
float starD = pow(max(a.x, 1e-4), 0.55) + pow(max(a.y, 1e-4), 0.55);
float fill = 1.0 - smoothstep(0.82, 0.96, starD);
float halo = exp(-length(a) * 1.8) * 0.45;
acc += COL_ICE_WHITE * fill + COL_CORE_CYAN * halo;
}
return acc;
}
// ============================================================================
// ARENA FLOOR SHADING (INK-GROUTED CHARCOAL TILES + RADIAL CRATER CRACKS)
// ============================================================================
vec3 shadeFloor(vec3 p, vec3 N, vec3 L, float sh, float matID) {
float r = length(p.xz);
float ang = atan(p.z, p.x);
// Polar-radial + grid arena tiles (charcoal matte slabs with ink grout)
vec2 tileUV = p.xz * 0.62;
vec2 tileId = floor(tileUV);
vec2 tileF = fract(tileUV);
float groutX = min(tileF.x, 1.0 - tileF.x);
float groutY = min(tileF.y, 1.0 - tileF.y);
float grout = min(groutX, groutY);
// Subtle per-tile matte tonal variation around shared COL_FLOOR_BASE
float tileTone = 0.90 + 0.22 * hash12(tileId * 13.7);
vec3 baseCol = COL_FLOOR_BASE * tileTone;
// Slight matte roughness grain
float grain = (vnoise2(p.xz * 7.5) - 0.5) * 0.018;
baseCol += vec3(grain);
// Parapet rim coloring
if (matID == MAT_RIM) {
float seg = fract(ang * 12.0 / TAU);
float rimGrout = min(seg, 1.0 - seg);
baseCol = COL_FLOOR_BASE * (N.y > 0.5 ? 1.45 : 1.15);
float gMask = 1.0 - smoothstep(0.02, 0.05, rimGrout);
baseCol = mix(baseCol, COL_INK, gMask);
// Top bevel ink line
float edgeInk = smoothstep(0.28, 0.32, abs(r - 5.65));
baseCol = mix(baseCol, COL_INK, edgeInk * 0.85);
} else {
// Ink grout lines
float groutMask = 1.0 - smoothstep(0.018, 0.038, grout);
baseCol = mix(baseCol, COL_INK, groutMask * 0.92);
}
// Radial jagged floor fracture cracks extending from crater slabs
if (r > 1.55 && r < 4.35 && matID == MAT_FLOOR) {
float crackD = slabCrackDist(ang, r);
float fade = smoothstep(4.2, 1.9, r);
float crackW = 0.028 * fade;
float crackLine = (1.0 - smoothstep(crackW * 0.5, crackW + 0.014, crackD)) * fade;
baseCol = mix(baseCol, COL_INK, crackLine * 0.95);
// Subtle frost-cyan lip along near cracks (muted in neutral grayscale mode)
if (uLightMode != 1) {
float frostLip = smoothstep(crackW + 0.06, crackW, crackD) * (1.0 - crackLine) * smoothstep(3.1, 1.75, r);
baseCol += COL_CORE_CYAN * frostLip * 0.14;
}
}
// Quantized cel-shaded key light + hard cast shadow
float ndl = max(dot(N, L), 0.0);
float celLit = mix(0.68, 1.28, step(0.35, ndl) * sh);
vec3 col = baseCol * celLit;
// Stylized cel-banded cyan bounce glow from crater center (muted in uLightMode == 1)
if (uLightMode != 1) {
float coreDist = max(r - 1.2, 0.0);
float bounce = exp(-coreDist * 0.85);
float bounceBand = floor(bounce * 3.0 + 0.2) / 3.0;
col += COL_CORE_CYAN * bounceBand * 0.22 * (0.45 + 0.55 * sh);
}
return col;
}
// ============================================================================
// CRATER ICE SLAB & ABYSS SHADING
// ============================================================================
vec3 shadeSlab(vec3 p, vec3 N, vec3 V, vec3 L, float sh) {
float ndl = dot(N, L);
// 3-band cel shading
vec3 col;
if (N.y > 0.55) {
// Top of broken ice slab
float speckle = fbm2(p.xz * 4.5);
col = mix(COL_SLAB_TOP * 0.84, COL_ICE_LIGHT, smoothstep(0.45, 0.72, speckle));
col *= mix(0.74, 1.06, sh * smoothstep(-0.1, 0.15, ndl));
} else {
// Vertical jagged cliff face into crater
float band = step(0.15, ndl * sh);
col = mix(COL_ICE_SHADOW, COL_SLAB_SIDE, band);
// Subtle inner crater cyan bounce (muted in uLightMode == 1)
if (uLightMode != 1) {
col += COL_CORE_CYAN * 0.22 * smoothstep(1.65, 1.15, length(p.xz));
}
}
// Crisp Fresnel ink contour on slab edges
float fres = 1.0 - max(dot(N, V), 0.0);
float inkF = smoothstep(0.68, 0.82, fres);
col = mix(col, COL_INK, inkF * 0.88);
return col;
}
vec3 shadeAbyss(vec3 p) {
float r = length(p.xz);
float ang = atan(p.z, p.x);
float swirl = fbm2(p.xz * 3.2 + vec2(0.0, uTime * 0.25));
float coreGlow = exp(-r * 1.15);
float glowAmt = (uLightMode == 1) ? 0.15 : clamp(coreGlow * 0.85 + swirl * 0.25, 0.0, 1.0);
vec3 col = mix(COL_ABYSS, COL_CORE_CYAN, glowAmt);
// Crisp cyan-white frost flecks in the abyss
float flecks = smoothstep(0.76, 0.82, vnoise2(p.xz * 12.0 + ang));
col = mix(col, COL_ICE_LIGHT, flecks * ((uLightMode == 1) ? 0.20 : 0.65));
return col;
}
// ============================================================================
// FACETED CRYSTAL SPIKE & SHARD SHADING (3-BAND CEL + FAST SDF CREASE INK)
// ============================================================================
vec3 shadeCrystal(vec3 p, vec3 N, vec3 V, vec3 L, float sh, float matID) {
float ndl = dot(N, L);
float shadowFactor = mix(0.45, 1.0, sh);
float lit = ndl * shadowFactor;
// Quantized 3-band cel shading: shadow teal / mid frost-cyan / bright sky-ice
vec3 col;
if (lit > 0.42) {
col = COL_ICE_LIGHT;
} else if (lit > -0.08) {
col = COL_ICE_MID;
} else {
col = COL_ICE_SHADOW;
}
// Stylized comic frost texture / hand-painted crystalline mottling inside facets
float frostTex = fbm2(p.xy * 5.2 + p.zz * 3.7);
if (lit > -0.08 && lit <= 0.42) {
col = mix(col, COL_ICE_LIGHT, smoothstep(0.58, 0.72, frostTex) * 0.55);
col = mix(col, COL_ICE_SHADOW, smoothstep(0.32, 0.22, frostTex) * 0.35);
} else if (lit <= -0.08) {
col = mix(col, COL_ICE_MID, smoothstep(0.62, 0.75, frostTex) * 0.35);
}
// Sharp cel-quantized specular highlight on lit facets
vec3 H = safeNorm(L + V);
float spec = pow(max(dot(N, H), 0.0), 24.0);
float specBand = step(0.45, spec) * sh;
col = mix(col, COL_ICE_WHITE, specBand * 0.88);
// Core emissive frost bounce near the crater center (muted in uLightMode == 1)
if (uLightMode != 1) {
float coreDist = length(p - vec3(0.0, 0.45, 0.0));
float coreGlow = exp(-coreDist * 0.72);
col = mix(col, COL_ICE_WHITE, smoothstep(0.42, 0.88, coreGlow) * 0.55);
}
// Crisp rim highlight on backlit facets
float fres = 1.0 - max(dot(N, V), 0.0);
float rimStr = (uLightMode == 3) ? 0.85 : ((uLightMode == 1) ? 0.20 : 0.40);
float rimBand = step(0.58, fres) * step(-0.2, dot(N, vec3(0.0, 1.0, 0.0)));
col = mix(col, COL_ICE_WHITE, rimBand * rimStr * 0.55);
// FAST INTERNAL FACET CREASE INK: 3-tap tangent SDF Laplacian check
// On a flat facet d(p +- t*eps) == 0; near a convex crystal ridge it rises > 0
vec3 t1 = safeNorm(cross(N, abs(N.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0)));
vec3 t2 = safeNorm(cross(N, t1));
float eps = (matID == MAT_SHARD) ? 0.018 : 0.028;
float dLap = max(mapCrystals(p + t1 * eps).x, mapCrystals(p - t1 * eps).x)
+ max(mapCrystals(p + t2 * eps).x, 0.0);
float creaseInk = smoothstep(eps * 0.16, eps * 0.46, dLap);
// Bold Fresnel outer contour ink
float fresInk = smoothstep(0.76, 0.88, fres);
float totalInk = clamp(max(creaseInk * 0.88, fresInk), 0.0, 1.0);
col = mix(col, COL_INK, totalInk);
return col;
}
// ============================================================================
// MAIN RENDERER
// ============================================================================
void main() {
vec2 res = max(uResolution, vec2(1.0));
vec2 uv = (gl_FragCoord.xy - 0.5 * res) / min(res.x, res.y);
// Camera presets (uCamMode 0: hero 3/4 ref view, 1: low dramatic angle, 2: top-down)
vec3 ro, ta;
float fov = 1.28;
if (uCamMode == 1) {
ro = vec3(2.8, 1.55, 4.3);
ta = vec3(0.0, 1.05, 0.0);
fov = 1.22;
} else if (uCamMode == 2) {
ro = vec3(0.0, 7.6, 1.85);
ta = vec3(0.0, 0.2, 0.0);
fov = 1.32;
} else {
ro = vec3(0.0, 4.35, 5.25);
ta = vec3(0.0, 0.72, 0.0);
fov = 1.26;
}
vec3 camFwd = safeNorm(ta - ro);
vec3 camRight = safeNorm(cross(camFwd, vec3(0.0, 1.0, 0.0)));
vec3 camUp = safeNorm(cross(camRight, camFwd));
vec3 rd = safeNorm(camFwd * fov + camRight * uv.x + camUp * uv.y);
// Lighting presets:
// 0 = hero upper-left key, 1 = neutral grayscale studio (emission muted),
// 2 = high-key right, 3 = backlit rim
vec3 L;
if (uLightMode == 3) {
L = safeNorm(vec3(-0.35, 0.65, -0.75));
} else if (uLightMode == 2) {
L = safeNorm(vec3(0.65, 0.82, 0.45));
} else {
L = safeNorm(vec3(-0.62, 0.85, 0.48));
}
// Raymarch scene (64 steps, single mapScene call per step — reuses h.x for crystal silhouette)
float t = 0.0;
float tMax = 22.0;
float matID = 0.0;
bool hit = false;
float minCrysRatio = 1e5;
float minCrysT = 1e5;
bool passedCrystal = false;
for (int i = 0; i < 64; i++) {
vec3 p = ro + rd * t;
vec2 h = mapScene(p);
// Reuse crystal distance from mapScene when crystal is nearest (zero extra evals)
if ((h.y == MAT_SPIKE || h.y == MAT_SHARD) && h.x < 0.16 && t > 0.2) {
float ratio = h.x / max(t, 0.5);
if (ratio < minCrysRatio) {
minCrysRatio = ratio;
minCrysT = t;
}
if (h.x < 0.05) passedCrystal = true;
}
if (h.x < 0.0028) {
hit = true;
matID = h.y;
break;
}
t += clamp(h.x, 0.012, 0.72);
if (t > tMax) break;
}
// Background sky above arena parapet (cool stylized glacial mist, zero clip & zero black)
float skyGrad = clamp(rd.y * 2.2 + 0.25, 0.0, 1.0);
vec3 col = mix(vec3(0.14, 0.18, 0.24), vec3(0.28, 0.36, 0.46), skyGrad);
if (uLightMode != 1) {
float horizonGlow = exp(-abs(rd.y + 0.08) * 14.0);
col += COL_CORE_CYAN * horizonGlow * 0.12;
}
float sceneT = hit ? t : tMax;
if (hit) {
vec3 p = ro + rd * t;
vec3 N = calcNormal(p);
vec3 V = -rd;
float sh = (matID == MAT_ABYSS) ? 1.0 : calcShadow(p + N * 0.015, L, 6.0);
if (matID == MAT_FLOOR || matID == MAT_RIM) {
col = shadeFloor(p, N, L, sh, matID);
} else if (matID == MAT_SLAB) {
col = shadeSlab(p, N, V, L, sh);
} else if (matID == MAT_ABYSS) {
col = shadeAbyss(p);
} else {
col = shadeCrystal(p, N, V, L, sh, matID);
}
// Apply crisp external black-ink silhouette outline when ray grazed a crystal in front
if (passedCrystal && ((matID != MAT_SPIKE && matID != MAT_SHARD) || t > minCrysT + 0.18)) {
float outlineMask = 1.0 - smoothstep(0.0045, 0.0078, minCrysRatio);
col = mix(col, COL_INK, outlineMask * 0.96);
}
} else if (passedCrystal) {
// Crystal silhouette against sky
float outlineMask = 1.0 - smoothstep(0.0045, 0.0078, minCrysRatio);
col = mix(col, COL_INK, outlineMask * 0.96);
}
// Composite jagged comic starburst flash core & 4-point sparkles (muted in uLightMode == 1)
if (uLightMode != 1) {
float tStar;
vec4 star = evalStarburst(ro, rd, camRight, camUp, camFwd, tStar);
if (star.a > 0.001) {
float depthFade = smoothstep(-0.35, 0.28, sceneT - tStar);
if (hit && matID == MAT_ABYSS) depthFade = 1.0;
col = mix(col, star.rgb, star.a * depthFade);
}
vec3 sparks = evalSparkles(ro, rd, camRight, camUp, sceneT);
col += sparks;
}
// Subtle comic radial vignette (preserves dark floor > black threshold)
float vig = 1.0 - 0.14 * dot(uv, uv);
col *= clamp(vig, 0.82, 1.0);
// Gentle soft-shoulder tonemap to prevent clipping (<1% clip) & avoid NaN
col = max(col, vec3(0.0));
col = col / (1.0 + col * 0.16);
col = clamp(col, vec3(0.025, 0.032, 0.048), vec3(0.975));
// Pure neutral grayscale output for uLightMode == 1
if (uLightMode == 1) {
float lum = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(lum);
}
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;
// Frost Teal Ice Nova Spikes — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/vfx_stylized/lib/05_frost_teal_ice_nova_spikes.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;
// ============================================================================
// FROST-TEAL ICE NOVA SPIKES — STYLIZED CEL-SHADED VFX
// ============================================================================
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
// Shared style contract & Glacial Frost-Teal palette
const vec3 COL_FLOOR_BASE = vec3(0.08, 0.09, 0.12);
const vec3 COL_INK = vec3(0.032, 0.042, 0.062); // Deep comic ink (avoids pure-black clip)
const vec3 COL_ABYSS = vec3(0.045, 0.22, 0.34);
const vec3 COL_ICE_SHADOW = vec3(0.11, 0.44, 0.66);
const vec3 COL_ICE_MID = vec3(0.36, 0.81, 0.96);
const vec3 COL_ICE_LIGHT = vec3(0.82, 0.95, 1.00);
const vec3 COL_ICE_WHITE = vec3(0.95, 0.99, 1.00);
const vec3 COL_SLAB_TOP = vec3(0.68, 0.86, 0.95);
const vec3 COL_SLAB_SIDE = vec3(0.24, 0.64, 0.84);
const vec3 COL_CORE_CYAN = vec3(0.18, 0.88, 1.00);
// Material IDs
const float MAT_FLOOR = 1.0;
const float MAT_SLAB = 2.0;
const float MAT_SPIKE = 3.0;
const float MAT_SHARD = 4.0;
const float MAT_ABYSS = 5.0;
const float MAT_RIM = 6.0;
// ============================================================================
// MATH & NOISE UTILITIES
// ============================================================================
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
float hash11(float p) {
p = fract(p * 0.1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
float hash12(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(
mix(hash12(i + vec2(0.0, 0.0)), hash12(i + vec2(1.0, 0.0)), u.x),
mix(hash12(i + vec2(0.0, 1.0)), hash12(i + vec2(1.0, 1.0)), u.x),
u.y
);
}
float fbm2(vec2 p) {
float v = 0.0;
float a = 0.5;
mat2 m = mat2(0.80, -0.60, 0.60, 0.80);
for (int i = 0; i < 4; i++) {
v += a * vnoise2(p);
p = m * p * 2.03 + vec2(11.3, 7.1);
a *= 0.5;
}
return v;
}
vec3 safeNorm(vec3 v) {
float l = length(v);
return l > 1e-6 ? v / l : vec3(0.0, 1.0, 0.0);
}
// ============================================================================
// FACETED CRYSTAL & CRATER SDF PRIMITIVES
// ============================================================================
// Exact hexagonal distance in XZ plane (flat-to-flat radius = r)
float sdHex2D(vec2 p) {
p = abs(p);
return max(p.x * 0.8660254 + p.y * 0.5, p.y);
}
// Faceted hexagonal crystal obelisk: base at y=0, tip at y=h, shaft radius r
float sdHexCrystal(vec3 p, float r, float h, float tipFrac) {
float tipY = h * (1.0 - tipFrac);
float tipH = max(h * tipFrac, 0.05);
float hexD = sdHex2D(p.xz);
// Slight outward flare along the shaft for stylized heroic silhouette
float shaftSlope = 0.05;
float rAtY = r * (0.90 + 0.14 * clamp(p.y / max(tipY, 0.05), 0.0, 1.0));
float dShaft = (hexD - rAtY) * 0.998;
// Exact 6-sided pyramidal tip planes
float rTop = r * 1.04;
vec2 tipN = normalize(vec2(tipH, rTop));
float dTip = dot(vec2(hexD, p.y - tipY), tipN) - rTop * tipN.x;
// Base cap
float dBase = -p.y;
return max(max(dShaft, dTip), dBase);
}
// Faceted hexagonal bipyramid (floating comic frost shard)
float sdHexShard(vec3 p, float r, float hTop, float hBot) {
float hexD = sdHex2D(p.xz);
vec2 nTop = normalize(vec2(hTop, r));
vec2 nBot = normalize(vec2(hBot, r));
float dTop = dot(vec2(hexD, p.y), nTop) - r * nTop.x;
float dBot = dot(vec2(hexD, -p.y), nBot) - r * nBot.x;
return max(dTop, dBot);
}
// Orient a point into a crystal's local frame (origin at pos, +Y along tilt)
vec3 toSpikeLocal(vec3 p, vec3 basePos, float yaw, float tilt, float spin) {
vec3 q = p - basePos;
q.xz = rot2(-yaw) * q.xz;
q.xy = rot2(-tilt) * q.xy;
q.xz = rot2(spin) * q.xz;
return q;
}
// ============================================================================
// SCENE PARAMETERS & ANIMATION (3s LOOP + uOpen)
// ============================================================================
float getPhase() {
return uTime * (TAU / 3.0);
}
float getErupt() {
float o = clamp(uOpen, 0.0, 1.0);
float pulse = 0.045 * sin(getPhase());
return mix(0.58, 1.12, o) + pulse;
}
// Jagged crater radius as a function of azimuth
float craterInnerR(float ang) {
float j = 0.11 * sin(ang * 5.0 + 0.4)
+ 0.07 * cos(ang * 9.0 - 1.1)
+ 0.04 * sin(ang * 13.0 + 2.3);
return 1.18 + j;
}
float craterOuterR(float ang) {
float j = 0.16 * sin(ang * 4.0 - 0.7)
+ 0.10 * cos(ang * 7.0 + 1.5)
+ 0.06 * sin(ang * 11.0 + 0.2);
return 1.88 + j;
}
// Angular fissure gap mask between cracked crater ice slabs (returns >0 inside crack)
float slabCrackDist(float ang, float r) {
// 9 irregular radial cracks around the crater ring
float aNorm = fract(ang / TAU + 1.0);
float seg = aNorm * 9.0;
float id = floor(seg);
float f = fract(seg);
float jitter = (hash11(id * 17.3 + 3.1) - 0.5) * 0.24;
// Zig-zag radial wobble
float zig = 0.055 * sin(r * 14.0 + id * 4.7) + 0.03 * cos(r * 25.0 - id * 2.1);
float dEdge = min(abs(f - 0.5 + jitter + zig), min(abs(f + jitter + zig), abs(f - 1.0 + jitter + zig)));
// Use distance to nearest seam (at f ~ 0 + jitter)
float seam = abs(fract(seg + 0.5 + jitter + zig) - 0.5);
return seam * (TAU / 9.0) * max(r, 0.8);
}
// ============================================================================
// SCENE SDF: returns vec2(distance, materialID)
// ============================================================================
vec2 opMin(vec2 a, vec2 b) {
return a.x < b.x ? a : b;
}
// Only the hero crystals & floating shards (with tight ring bounds for fast marching)
vec2 mapCrystals(vec3 p) {
float erupt = getErupt();
float phase = getPhase();
vec2 res = vec2(1e5, MAT_SPIKE);
// Quick bounding sphere for entire spike cluster
float boundAll = length(p - vec3(0.0, 1.35, 0.0)) - 4.1;
if (boundAll > 0.25) {
return vec2(boundAll, MAT_SPIKE);
}
float rXZ = length(p.xz);
// 1. HERO CENTRAL SPIRE (towering hexagonal obelisk)
if (rXZ < 0.85 && p.y > -0.35 && p.y < 3.65) {
vec3 q = p - vec3(0.0, -0.15, 0.0);
q.xz = rot2(0.28) * q.xz;
float h = 2.95 * erupt;
float r = 0.31;
float dMain = sdHexCrystal(q, r, h, 0.28);
float notch1 = length(q - vec3(0.29, 0.92 * erupt, 0.10)) - 0.14;
float notch2 = length(q - vec3(-0.27, 1.25 * erupt, -0.06)) - 0.12;
dMain = max(dMain, -min(notch1, notch2));
res = opMin(res, vec2(dMain, MAT_SPIKE));
}
// 2. PRIMARY RADIAL CRYSTAL SPIKES (10 bold spikes jutting around crater)
if (rXZ > 0.65 && rXZ < 3.95 && p.y > -0.35 && p.y < 2.65) {
float spAngles[10] = float[10](
-0.55, 0.08, 0.62, 1.28, 1.95, 2.52, 3.05, 3.68, 4.32, 5.02
);
float spHeights[10] = float[10](
1.78, 1.65, 1.48, 1.35, 1.85, 1.68, 1.32, 1.45, 1.92, 1.15
);
float spRadii[10] = float[10](
0.24, 0.22, 0.19, 0.18, 0.23, 0.22, 0.18, 0.19, 0.25, 0.16
);
float spTilts[10] = float[10](
0.96, 1.16, 0.86, 0.62, 0.78, 0.92, 1.12, 1.05, 1.08, 1.22
);
float spDist[10] = float[10](
1.48, 1.55, 1.42, 1.26, 1.38, 1.46, 1.50, 1.45, 1.52, 1.58
);
for (int i = 0; i < 10; i++) {
float ang = spAngles[i];
float ca = cos(ang), sa = sin(ang);
vec3 base = vec3(ca * spDist[i], -0.04, sa * spDist[i]);
float breathe = 1.0 + 0.03 * sin(phase + float(i) * 0.9);
float h = spHeights[i] * erupt * breathe;
vec3 mid = base + vec3(ca * sin(spTilts[i]), cos(spTilts[i]), sa * sin(spTilts[i])) * (h * 0.5);
if (length(p - mid) < h * 0.60 + 0.30) {
vec3 q = toSpikeLocal(p, base, -ang, spTilts[i], float(i) * 0.53);
float d = sdHexCrystal(q, spRadii[i], h, 0.36);
res = opMin(res, vec2(d, MAT_SPIKE));
}
}
}
// 3. INNER NEEDLE SPIKES (6 sleek sharp spikes framing the central spire)
if (rXZ > 0.35 && rXZ < 2.15 && p.y > -0.25 && p.y < 2.25) {
for (int i = 0; i < 6; i++) {
float fi = float(i);
float ang = fi * (TAU / 6.0) + 0.36;
float ca = cos(ang), sa = sin(ang);
vec3 base = vec3(ca * 0.82, -0.05, sa * 0.82);
float h = (1.30 + 0.38 * hash11(fi * 5.7 + 1.2)) * erupt;
float tilt = 0.34 + 0.14 * hash11(fi * 9.3 + 2.4);
vec3 mid = base + vec3(ca * sin(tilt), cos(tilt), sa * sin(tilt)) * (h * 0.5);
if (length(p - mid) < h * 0.60 + 0.22) {
vec3 q = toSpikeLocal(p, base, -ang, tilt, fi * 0.8);
float d = sdHexCrystal(q, 0.115, h, 0.42);
res = opMin(res, vec2(d, MAT_SPIKE));
}
}
}
// 4. FLOATING / LEVITATING ANGULAR COMIC FROST SHARDS (8 outer shards)
if (rXZ > 1.45 && rXZ < 3.40 && p.y > 0.35 && p.y < 3.25) {
float shAngles[8] = float[8](
-2.25, -1.55, -0.82, 0.35, 1.12, 2.08, 2.75, 3.85
);
float shR[8] = float[8](
2.15, 2.55, 2.25, 2.35, 2.60, 2.30, 2.45, 2.20
);
float shY[8] = float[8](
1.85, 2.35, 1.55, 1.10, 2.10, 1.75, 0.95, 1.35
);
float shSize[8] = float[8](
0.21, 0.15, 0.17, 0.13, 0.18, 0.14, 0.12, 0.16
);
float openY = mix(0.75, 1.05, clamp(uOpen, 0.0, 1.0));
for (int i = 0; i < 8; i++) {
float fi = float(i);
float ang = shAngles[i] + 0.08 * sin(phase + fi * 1.1);
float bob = 0.18 * sin(phase + fi * 1.37);
float rad = shR[i] + 0.08 * cos(phase + fi * 0.83);
vec3 cPos = vec3(cos(ang) * rad, shY[i] * openY + bob, sin(ang) * rad);
float sz = shSize[i];
if (length(p - cPos) < sz * 3.1 + 0.18) {
vec3 q = p - cPos;
q.xz = rot2(-ang + phase * 0.25 * (mod(fi, 2.0) < 0.5 ? 1.0 : -1.0)) * q.xz;
q.xy = rot2(0.45 + 0.2 * sin(fi * 2.1)) * q.xy;
float d = sdHexShard(q, sz * 0.72, sz * 2.35, sz * 1.65);
res = opMin(res, vec2(d, MAT_SHARD));
}
}
}
return res;
}
vec2 mapScene(vec3 p) {
vec2 res = mapCrystals(p);
float r = length(p.xz);
float ang = atan(p.z, p.x);
float rIn = craterInnerR(ang);
float rOut = craterOuterR(ang);
// Arena floor with sunken circular-jagged crater hole
float dFloorPlane = p.y;
// Inside the crater, push floor down to abyss depth (-0.58)
float dCraterHole = r - rIn;
float dAbyss = max(p.y + 0.56, dCraterHole);
float dFloor = max(dFloorPlane, -dCraterHole);
// Raised curved arena parapet rim at R ~ 5.6
float dRim = max(abs(r - 5.65) - 0.32, p.y - 0.24);
dRim = max(dRim, -p.y - 0.1);
res = opMin(res, vec2(dFloor, MAT_FLOOR));
res = opMin(res, vec2(dAbyss, MAT_ABYSS));
res = opMin(res, vec2(dRim, MAT_RIM));
// Cracked polygonal ice crust slabs around crater rim (rIn .. rOut)
if (r > rIn - 0.35 && r < rOut + 0.35 && abs(p.y) < 0.65) {
float crack = slabCrackDist(ang, r);
float slabId = floor(fract(ang / TAU + 1.0) * 9.0);
float slabTilt = (hash11(slabId * 13.1 + 2.0) - 0.5) * 0.09;
float slabH = 0.17 + 0.06 * hash11(slabId * 7.3 + 5.0) + slabTilt * (r - 1.5);
// Slightly raised outer lip & jagged bevel
float dOuter = r - rOut;
float dInner = rIn - r;
float dTop = p.y - slabH;
float dBot = -p.y - 0.58;
float dSlab = max(max(dOuter, dInner), max(dTop, dBot));
// Carve crisp dark-ink fissures between slabs
float crackWidth = 0.055 + 0.02 * (r - rIn);
float dCrackCarve = crackWidth - crack;
dSlab = max(dSlab, dCrackCarve);
// Subtle chamfer on top edge
dSlab = max(dSlab, (p.y - slabH + 0.03) * 0.707 + max(dInner, dOuter) * 0.707);
res = opMin(res, vec2(dSlab, MAT_SLAB));
}
return res;
}
// ============================================================================
// NORMALS & SHADOWS
// ============================================================================
vec3 calcNormal(vec3 p) {
vec2 e = vec2(0.0022, -0.0022);
return safeNorm(
e.xyy * mapScene(p + e.xyy).x +
e.yyx * mapScene(p + e.yyx).x +
e.yxy * mapScene(p + e.yxy).x +
e.xxx * mapScene(p + e.xxx).x
);
}
// Crisp comic cel-shaded hard shadow (16 steps, fast)
float calcShadow(vec3 ro, vec3 rd, float maxT) {
if (length(ro.xz) > 4.6) return 1.0;
float t = 0.05;
float sh = 1.0;
for (int i = 0; i < 16; i++) {
float h = mapCrystals(ro + rd * t).x;
if (h < 0.005) return 0.0;
sh = min(sh, 16.0 * h / t);
t += clamp(h, 0.05, 0.45);
if (t > maxT) break;
}
return smoothstep(0.15, 0.55, sh);
}
// ============================================================================
// JAGGED COMIC STARBURST FLASH CORE (3D BILLBOARD AT CRATER CENTER)
// ============================================================================
// Returns vec4(rgb, alpha) and out hit depth tStar
vec4 evalStarburst(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, vec3 camFwd, out float tStar) {
float phase = getPhase();
float erupt = getErupt();
vec3 center = vec3(0.0, 0.42 * erupt, 0.0);
// Intersect camera-facing plane passing through center
float denom = dot(rd, camFwd);
tStar = 1e5;
if (abs(denom) < 1e-4) return vec4(0.0);
float t = dot(center - ro, camFwd) / denom;
if (t <= 0.05) return vec4(0.0);
tStar = t;
vec3 hitP = ro + rd * t;
vec3 rel = hitP - center;
vec2 uv = vec2(dot(rel, camRight), dot(rel, camUp));
float r = length(uv);
float ang = atan(uv.y, uv.x);
// Scale with eruption and 3s loop pulse
float scale = mix(0.72, 1.08, clamp(uOpen, 0.0, 1.0)) * (1.0 + 0.075 * sin(phase));
float rn = r / max(scale, 0.1);
if (rn > 1.75) return vec4(0.0);
// Sharp jagged 16-ray primary + 9-ray secondary starburst profile
float a1 = ang + 0.06 * sin(phase);
float spike1 = pow(abs(cos(a1 * 8.0 + 0.35 * sin(a1 * 3.0))), 6.0);
float spike2 = pow(abs(sin(a1 * 5.0 - 0.65)), 8.0);
float spike3 = pow(abs(cos(a1 * 13.0 + 1.2 - 0.12 * cos(phase))), 9.0);
// Elongate horizontal & upward rays slightly like 05.png
float dirBias = 0.85 + 0.25 * abs(cos(ang)) + 0.22 * max(sin(ang), 0.0);
float outerR = (0.34 + 0.92 * max(spike1, 0.78 * spike2) + 0.38 * spike3) * dirBias;
float innerR = (0.20 + 0.58 * max(spike1, 0.72 * spike2) + 0.22 * spike3) * dirBias;
float dOut = rn - outerR;
float dIn = rn - innerR;
float aa = 0.018;
float inkMask = 1.0 - smoothstep(0.015, 0.015 + aa, dOut);
float cyanMask = 1.0 - smoothstep(-0.022, -0.022 + aa, dOut);
float whiteMask = 1.0 - smoothstep(0.0, aa, dIn);
// Soft additive halo right around core
float glow = exp(-rn * 2.2) * 0.42;
vec3 col = COL_INK;
col = mix(col, COL_CORE_CYAN, cyanMask);
col = mix(col, COL_ICE_WHITE, whiteMask);
float alpha = clamp(inkMask + glow * (1.0 - inkMask), 0.0, 1.0);
vec3 outCol = mix(COL_CORE_CYAN, col, inkMask);
return vec4(outCol, alpha);
}
// ============================================================================
// COMIC 4-POINT DIAMOND SPARKLES (WORLD-ANCHORED BILLBOARDS)
// ============================================================================
vec3 evalSparkles(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float sceneT) {
float phase = getPhase();
vec3 acc = vec3(0.0);
for (int i = 0; i < 14; i++) {
float fi = float(i);
float ang = fi * (TAU / 14.0) + 0.21;
float rad = 1.95 + 1.25 * hash11(fi * 11.7 + 3.0);
float h = 0.22 + 2.35 * hash11(fi * 7.3 + 9.1);
float bob = 0.14 * sin(phase + fi * 1.6);
vec3 spPos = vec3(cos(ang) * rad, h + bob, sin(ang) * rad);
float t = dot(spPos - ro, rd);
if (t < 0.2 || t > sceneT) continue;
vec3 dVec = ro + rd * t - spPos;
vec2 uv = vec2(dot(dVec, camRight), dot(dVec, camUp));
float twinkle = 0.65 + 0.35 * sin(phase * 2.0 + fi * 2.3);
float sz = (0.08 + 0.06 * hash11(fi * 4.1)) * twinkle;
vec2 a = abs(uv) / max(sz, 0.01);
// Crisp 4-point astroid diamond star
float starD = pow(max(a.x, 1e-4), 0.55) + pow(max(a.y, 1e-4), 0.55);
float fill = 1.0 - smoothstep(0.82, 0.96, starD);
float halo = exp(-length(a) * 1.8) * 0.45;
acc += COL_ICE_WHITE * fill + COL_CORE_CYAN * halo;
}
return acc;
}
// ============================================================================
// ARENA FLOOR SHADING (INK-GROUTED CHARCOAL TILES + RADIAL CRATER CRACKS)
// ============================================================================
vec3 shadeFloor(vec3 p, vec3 N, vec3 L, float sh, float matID) {
float r = length(p.xz);
float ang = atan(p.z, p.x);
// Polar-radial + grid arena tiles (charcoal matte slabs with ink grout)
vec2 tileUV = p.xz * 0.62;
vec2 tileId = floor(tileUV);
vec2 tileF = fract(tileUV);
float groutX = min(tileF.x, 1.0 - tileF.x);
float groutY = min(tileF.y, 1.0 - tileF.y);
float grout = min(groutX, groutY);
// Subtle per-tile matte tonal variation around shared COL_FLOOR_BASE
float tileTone = 0.90 + 0.22 * hash12(tileId * 13.7);
vec3 baseCol = COL_FLOOR_BASE * tileTone;
// Slight matte roughness grain
float grain = (vnoise2(p.xz * 7.5) - 0.5) * 0.018;
baseCol += vec3(grain);
// Parapet rim coloring
if (matID == MAT_RIM) {
float seg = fract(ang * 12.0 / TAU);
float rimGrout = min(seg, 1.0 - seg);
baseCol = COL_FLOOR_BASE * (N.y > 0.5 ? 1.45 : 1.15);
float gMask = 1.0 - smoothstep(0.02, 0.05, rimGrout);
baseCol = mix(baseCol, COL_INK, gMask);
// Top bevel ink line
float edgeInk = smoothstep(0.28, 0.32, abs(r - 5.65));
baseCol = mix(baseCol, COL_INK, edgeInk * 0.85);
} else {
// Ink grout lines
float groutMask = 1.0 - smoothstep(0.018, 0.038, grout);
baseCol = mix(baseCol, COL_INK, groutMask * 0.92);
}
// Radial jagged floor fracture cracks extending from crater slabs
if (r > 1.55 && r < 4.35 && matID == MAT_FLOOR) {
float crackD = slabCrackDist(ang, r);
float fade = smoothstep(4.2, 1.9, r);
float crackW = 0.028 * fade;
float crackLine = (1.0 - smoothstep(crackW * 0.5, crackW + 0.014, crackD)) * fade;
baseCol = mix(baseCol, COL_INK, crackLine * 0.95);
// Subtle frost-cyan lip along near cracks (muted in neutral grayscale mode)
if (uLightMode != 1) {
float frostLip = smoothstep(crackW + 0.06, crackW, crackD) * (1.0 - crackLine) * smoothstep(3.1, 1.75, r);
baseCol += COL_CORE_CYAN * frostLip * 0.14;
}
}
// Quantized cel-shaded key light + hard cast shadow
float ndl = max(dot(N, L), 0.0);
float celLit = mix(0.68, 1.28, step(0.35, ndl) * sh);
vec3 col = baseCol * celLit;
// Stylized cel-banded cyan bounce glow from crater center (muted in uLightMode == 1)
if (uLightMode != 1) {
float coreDist = max(r - 1.2, 0.0);
float bounce = exp(-coreDist * 0.85);
float bounceBand = floor(bounce * 3.0 + 0.2) / 3.0;
col += COL_CORE_CYAN * bounceBand * 0.22 * (0.45 + 0.55 * sh);
}
return col;
}
// ============================================================================
// CRATER ICE SLAB & ABYSS SHADING
// ============================================================================
vec3 shadeSlab(vec3 p, vec3 N, vec3 V, vec3 L, float sh) {
float ndl = dot(N, L);
// 3-band cel shading
vec3 col;
if (N.y > 0.55) {
// Top of broken ice slab
float speckle = fbm2(p.xz * 4.5);
col = mix(COL_SLAB_TOP * 0.84, COL_ICE_LIGHT, smoothstep(0.45, 0.72, speckle));
col *= mix(0.74, 1.06, sh * smoothstep(-0.1, 0.15, ndl));
} else {
// Vertical jagged cliff face into crater
float band = step(0.15, ndl * sh);
col = mix(COL_ICE_SHADOW, COL_SLAB_SIDE, band);
// Subtle inner crater cyan bounce (muted in uLightMode == 1)
if (uLightMode != 1) {
col += COL_CORE_CYAN * 0.22 * smoothstep(1.65, 1.15, length(p.xz));
}
}
// Crisp Fresnel ink contour on slab edges
float fres = 1.0 - max(dot(N, V), 0.0);
float inkF = smoothstep(0.68, 0.82, fres);
col = mix(col, COL_INK, inkF * 0.88);
return col;
}
vec3 shadeAbyss(vec3 p) {
float r = length(p.xz);
float ang = atan(p.z, p.x);
float swirl = fbm2(p.xz * 3.2 + vec2(0.0, uTime * 0.25));
float coreGlow = exp(-r * 1.15);
float glowAmt = (uLightMode == 1) ? 0.15 : clamp(coreGlow * 0.85 + swirl * 0.25, 0.0, 1.0);
vec3 col = mix(COL_ABYSS, COL_CORE_CYAN, glowAmt);
// Crisp cyan-white frost flecks in the abyss
float flecks = smoothstep(0.76, 0.82, vnoise2(p.xz * 12.0 + ang));
col = mix(col, COL_ICE_LIGHT, flecks * ((uLightMode == 1) ? 0.20 : 0.65));
return col;
}
// ============================================================================
// FACETED CRYSTAL SPIKE & SHARD SHADING (3-BAND CEL + FAST SDF CREASE INK)
// ============================================================================
vec3 shadeCrystal(vec3 p, vec3 N, vec3 V, vec3 L, float sh, float matID) {
float ndl = dot(N, L);
float shadowFactor = mix(0.45, 1.0, sh);
float lit = ndl * shadowFactor;
// Quantized 3-band cel shading: shadow teal / mid frost-cyan / bright sky-ice
vec3 col;
if (lit > 0.42) {
col = COL_ICE_LIGHT;
} else if (lit > -0.08) {
col = COL_ICE_MID;
} else {
col = COL_ICE_SHADOW;
}
// Stylized comic frost texture / hand-painted crystalline mottling inside facets
float frostTex = fbm2(p.xy * 5.2 + p.zz * 3.7);
if (lit > -0.08 && lit <= 0.42) {
col = mix(col, COL_ICE_LIGHT, smoothstep(0.58, 0.72, frostTex) * 0.55);
col = mix(col, COL_ICE_SHADOW, smoothstep(0.32, 0.22, frostTex) * 0.35);
} else if (lit <= -0.08) {
col = mix(col, COL_ICE_MID, smoothstep(0.62, 0.75, frostTex) * 0.35);
}
// Sharp cel-quantized specular highlight on lit facets
vec3 H = safeNorm(L + V);
float spec = pow(max(dot(N, H), 0.0), 24.0);
float specBand = step(0.45, spec) * sh;
col = mix(col, COL_ICE_WHITE, specBand * 0.88);
// Core emissive frost bounce near the crater center (muted in uLightMode == 1)
if (uLightMode != 1) {
float coreDist = length(p - vec3(0.0, 0.45, 0.0));
float coreGlow = exp(-coreDist * 0.72);
col = mix(col, COL_ICE_WHITE, smoothstep(0.42, 0.88, coreGlow) * 0.55);
}
// Crisp rim highlight on backlit facets
float fres = 1.0 - max(dot(N, V), 0.0);
float rimStr = (uLightMode == 3) ? 0.85 : ((uLightMode == 1) ? 0.20 : 0.40);
float rimBand = step(0.58, fres) * step(-0.2, dot(N, vec3(0.0, 1.0, 0.0)));
col = mix(col, COL_ICE_WHITE, rimBand * rimStr * 0.55);
// FAST INTERNAL FACET CREASE INK: 3-tap tangent SDF Laplacian check
// On a flat facet d(p +- t*eps) == 0; near a convex crystal ridge it rises > 0
vec3 t1 = safeNorm(cross(N, abs(N.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0)));
vec3 t2 = safeNorm(cross(N, t1));
float eps = (matID == MAT_SHARD) ? 0.018 : 0.028;
float dLap = max(mapCrystals(p + t1 * eps).x, mapCrystals(p - t1 * eps).x)
+ max(mapCrystals(p + t2 * eps).x, 0.0);
float creaseInk = smoothstep(eps * 0.16, eps * 0.46, dLap);
// Bold Fresnel outer contour ink
float fresInk = smoothstep(0.76, 0.88, fres);
float totalInk = clamp(max(creaseInk * 0.88, fresInk), 0.0, 1.0);
col = mix(col, COL_INK, totalInk);
return col;
}
// ============================================================================
// MAIN RENDERER
// ============================================================================
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 res = max(uResolution, vec2(1.0));
vec2 uv = (pfx_frag_xy - 0.5 * res) / min(res.x, res.y);
// Camera presets (uCamMode 0: hero 3/4 ref view, 1: low dramatic angle, 2: top-down)
vec3 ro, ta;
float fov = 1.28;
if (uCamMode == 1) {
ro = vec3(2.8, 1.55, 4.3);
ta = vec3(0.0, 1.05, 0.0);
fov = 1.22;
} else if (uCamMode == 2) {
ro = vec3(0.0, 7.6, 1.85);
ta = vec3(0.0, 0.2, 0.0);
fov = 1.32;
} else {
ro = vec3(0.0, 4.35, 5.25);
ta = vec3(0.0, 0.72, 0.0);
fov = 1.26;
}
vec3 camFwd = safeNorm(ta - ro);
vec3 camRight = safeNorm(cross(camFwd, vec3(0.0, 1.0, 0.0)));
vec3 camUp = safeNorm(cross(camRight, camFwd));
vec3 rd = safeNorm(camFwd * fov + camRight * uv.x + camUp * uv.y);
// Lighting presets:
// 0 = hero upper-left key, 1 = neutral grayscale studio (emission muted),
// 2 = high-key right, 3 = backlit rim
vec3 L;
if (uLightMode == 3) {
L = safeNorm(vec3(-0.35, 0.65, -0.75));
} else if (uLightMode == 2) {
L = safeNorm(vec3(0.65, 0.82, 0.45));
} else {
L = safeNorm(vec3(-0.62, 0.85, 0.48));
}
// Raymarch scene (64 steps, single mapScene call per step — reuses h.x for crystal silhouette)
float t = 0.0;
float tMax = 22.0;
float matID = 0.0;
bool hit = false;
float minCrysRatio = 1e5;
float minCrysT = 1e5;
bool passedCrystal = false;
for (int i = 0; i < 64; i++) {
vec3 p = ro + rd * t;
vec2 h = mapScene(p);
// Reuse crystal distance from mapScene when crystal is nearest (zero extra evals)
if ((h.y == MAT_SPIKE || h.y == MAT_SHARD) && h.x < 0.16 && t > 0.2) {
float ratio = h.x / max(t, 0.5);
if (ratio < minCrysRatio) {
minCrysRatio = ratio;
minCrysT = t;
}
if (h.x < 0.05) passedCrystal = true;
}
if (h.x < 0.0028) {
hit = true;
matID = h.y;
break;
}
t += clamp(h.x, 0.012, 0.72);
if (t > tMax) break;
}
// Background sky above arena parapet (cool stylized glacial mist, zero clip & zero black)
float skyGrad = clamp(rd.y * 2.2 + 0.25, 0.0, 1.0);
vec3 col = mix(vec3(0.14, 0.18, 0.24), vec3(0.28, 0.36, 0.46), skyGrad);
if (uLightMode != 1) {
float horizonGlow = exp(-abs(rd.y + 0.08) * 14.0);
col += COL_CORE_CYAN * horizonGlow * 0.12;
}
float sceneT = hit ? t : tMax;
if (hit) {
vec3 p = ro + rd * t;
vec3 N = calcNormal(p);
vec3 V = -rd;
float sh = (matID == MAT_ABYSS) ? 1.0 : calcShadow(p + N * 0.015, L, 6.0);
if (matID == MAT_FLOOR || matID == MAT_RIM) {
col = shadeFloor(p, N, L, sh, matID);
} else if (matID == MAT_SLAB) {
col = shadeSlab(p, N, V, L, sh);
} else if (matID == MAT_ABYSS) {
col = shadeAbyss(p);
} else {
col = shadeCrystal(p, N, V, L, sh, matID);
}
// Apply crisp external black-ink silhouette outline when ray grazed a crystal in front
if (passedCrystal && ((matID != MAT_SPIKE && matID != MAT_SHARD) || t > minCrysT + 0.18)) {
float outlineMask = 1.0 - smoothstep(0.0045, 0.0078, minCrysRatio);
col = mix(col, COL_INK, outlineMask * 0.96);
}
} else if (passedCrystal) {
// Crystal silhouette against sky
float outlineMask = 1.0 - smoothstep(0.0045, 0.0078, minCrysRatio);
col = mix(col, COL_INK, outlineMask * 0.96);
}
// Composite jagged comic starburst flash core & 4-point sparkles (muted in uLightMode == 1)
if (uLightMode != 1) {
float tStar;
vec4 star = evalStarburst(ro, rd, camRight, camUp, camFwd, tStar);
if (star.a > 0.001) {
float depthFade = smoothstep(-0.35, 0.28, sceneT - tStar);
if (hit && matID == MAT_ABYSS) depthFade = 1.0;
col = mix(col, star.rgb, star.a * depthFade);
}
vec3 sparks = evalSparkles(ro, rd, camRight, camUp, sceneT);
col += sparks;
}
// Subtle comic radial vignette (preserves dark floor > black threshold)
float vig = 1.0 - 0.14 * dot(uv, uv);
col *= clamp(vig, 0.82, 1.0);
// Gentle soft-shoulder tonemap to prevent clipping (<1% clip) & avoid NaN
col = max(col, vec3(0.0));
col = col / (1.0 + col * 0.16);
col = clamp(col, vec3(0.025, 0.032, 0.048), vec3(0.975));
// Pure neutral grayscale output for uLightMode == 1
if (uLightMode == 1) {
float lum = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(lum);
}
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;
// Frost Teal Ice Nova Spikes — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/vfx_stylized/lib/05_frost_teal_ice_nova_spikes.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;
// ============================================================================
// FROST-TEAL ICE NOVA SPIKES — STYLIZED CEL-SHADED VFX
// ============================================================================
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
// Shared style contract & Glacial Frost-Teal palette
const vec3 COL_FLOOR_BASE = vec3(0.08, 0.09, 0.12);
const vec3 COL_INK = vec3(0.032, 0.042, 0.062); // Deep comic ink (avoids pure-black clip)
const vec3 COL_ABYSS = vec3(0.045, 0.22, 0.34);
const vec3 COL_ICE_SHADOW = vec3(0.11, 0.44, 0.66);
const vec3 COL_ICE_MID = vec3(0.36, 0.81, 0.96);
const vec3 COL_ICE_LIGHT = vec3(0.82, 0.95, 1.00);
const vec3 COL_ICE_WHITE = vec3(0.95, 0.99, 1.00);
const vec3 COL_SLAB_TOP = vec3(0.68, 0.86, 0.95);
const vec3 COL_SLAB_SIDE = vec3(0.24, 0.64, 0.84);
const vec3 COL_CORE_CYAN = vec3(0.18, 0.88, 1.00);
// Material IDs
const float MAT_FLOOR = 1.0;
const float MAT_SLAB = 2.0;
const float MAT_SPIKE = 3.0;
const float MAT_SHARD = 4.0;
const float MAT_ABYSS = 5.0;
const float MAT_RIM = 6.0;
// ============================================================================
// MATH & NOISE UTILITIES
// ============================================================================
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
float hash11(float p) {
p = fract(p * 0.1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
float hash12(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(
mix(hash12(i + vec2(0.0, 0.0)), hash12(i + vec2(1.0, 0.0)), u.x),
mix(hash12(i + vec2(0.0, 1.0)), hash12(i + vec2(1.0, 1.0)), u.x),
u.y
);
}
float fbm2(vec2 p) {
float v = 0.0;
float a = 0.5;
mat2 m = mat2(0.80, -0.60, 0.60, 0.80);
for (int i = 0; i < 4; i++) {
v += a * vnoise2(p);
p = m * p * 2.03 + vec2(11.3, 7.1);
a *= 0.5;
}
return v;
}
vec3 safeNorm(vec3 v) {
float l = length(v);
return l > 1e-6 ? v / l : vec3(0.0, 1.0, 0.0);
}
// ============================================================================
// FACETED CRYSTAL & CRATER SDF PRIMITIVES
// ============================================================================
// Exact hexagonal distance in XZ plane (flat-to-flat radius = r)
float sdHex2D(vec2 p) {
p = abs(p);
return max(p.x * 0.8660254 + p.y * 0.5, p.y);
}
// Faceted hexagonal crystal obelisk: base at y=0, tip at y=h, shaft radius r
float sdHexCrystal(vec3 p, float r, float h, float tipFrac) {
float tipY = h * (1.0 - tipFrac);
float tipH = max(h * tipFrac, 0.05);
float hexD = sdHex2D(p.xz);
// Slight outward flare along the shaft for stylized heroic silhouette
float shaftSlope = 0.05;
float rAtY = r * (0.90 + 0.14 * clamp(p.y / max(tipY, 0.05), 0.0, 1.0));
float dShaft = (hexD - rAtY) * 0.998;
// Exact 6-sided pyramidal tip planes
float rTop = r * 1.04;
vec2 tipN = normalize(vec2(tipH, rTop));
float dTip = dot(vec2(hexD, p.y - tipY), tipN) - rTop * tipN.x;
// Base cap
float dBase = -p.y;
return max(max(dShaft, dTip), dBase);
}
// Faceted hexagonal bipyramid (floating comic frost shard)
float sdHexShard(vec3 p, float r, float hTop, float hBot) {
float hexD = sdHex2D(p.xz);
vec2 nTop = normalize(vec2(hTop, r));
vec2 nBot = normalize(vec2(hBot, r));
float dTop = dot(vec2(hexD, p.y), nTop) - r * nTop.x;
float dBot = dot(vec2(hexD, -p.y), nBot) - r * nBot.x;
return max(dTop, dBot);
}
// Orient a point into a crystal's local frame (origin at pos, +Y along tilt)
vec3 toSpikeLocal(vec3 p, vec3 basePos, float yaw, float tilt, float spin) {
vec3 q = p - basePos;
q.xz = rot2(-yaw) * q.xz;
q.xy = rot2(-tilt) * q.xy;
q.xz = rot2(spin) * q.xz;
return q;
}
// ============================================================================
// SCENE PARAMETERS & ANIMATION (3s LOOP + uOpen)
// ============================================================================
float getPhase() {
return uTime * (TAU / 3.0);
}
float getErupt() {
float o = clamp(uOpen, 0.0, 1.0);
float pulse = 0.045 * sin(getPhase());
return mix(0.58, 1.12, o) + pulse;
}
// Jagged crater radius as a function of azimuth
float craterInnerR(float ang) {
float j = 0.11 * sin(ang * 5.0 + 0.4)
+ 0.07 * cos(ang * 9.0 - 1.1)
+ 0.04 * sin(ang * 13.0 + 2.3);
return 1.18 + j;
}
float craterOuterR(float ang) {
float j = 0.16 * sin(ang * 4.0 - 0.7)
+ 0.10 * cos(ang * 7.0 + 1.5)
+ 0.06 * sin(ang * 11.0 + 0.2);
return 1.88 + j;
}
// Angular fissure gap mask between cracked crater ice slabs (returns >0 inside crack)
float slabCrackDist(float ang, float r) {
// 9 irregular radial cracks around the crater ring
float aNorm = fract(ang / TAU + 1.0);
float seg = aNorm * 9.0;
float id = floor(seg);
float f = fract(seg);
float jitter = (hash11(id * 17.3 + 3.1) - 0.5) * 0.24;
// Zig-zag radial wobble
float zig = 0.055 * sin(r * 14.0 + id * 4.7) + 0.03 * cos(r * 25.0 - id * 2.1);
float dEdge = min(abs(f - 0.5 + jitter + zig), min(abs(f + jitter + zig), abs(f - 1.0 + jitter + zig)));
// Use distance to nearest seam (at f ~ 0 + jitter)
float seam = abs(fract(seg + 0.5 + jitter + zig) - 0.5);
return seam * (TAU / 9.0) * max(r, 0.8);
}
// ============================================================================
// SCENE SDF: returns vec2(distance, materialID)
// ============================================================================
vec2 opMin(vec2 a, vec2 b) {
return a.x < b.x ? a : b;
}
// Only the hero crystals & floating shards (with tight ring bounds for fast marching)
vec2 mapCrystals(vec3 p) {
float erupt = getErupt();
float phase = getPhase();
vec2 res = vec2(1e5, MAT_SPIKE);
// Quick bounding sphere for entire spike cluster
float boundAll = length(p - vec3(0.0, 1.35, 0.0)) - 4.1;
if (boundAll > 0.25) {
return vec2(boundAll, MAT_SPIKE);
}
float rXZ = length(p.xz);
// 1. HERO CENTRAL SPIRE (towering hexagonal obelisk)
if (rXZ < 0.85 && p.y > -0.35 && p.y < 3.65) {
vec3 q = p - vec3(0.0, -0.15, 0.0);
q.xz = rot2(0.28) * q.xz;
float h = 2.95 * erupt;
float r = 0.31;
float dMain = sdHexCrystal(q, r, h, 0.28);
float notch1 = length(q - vec3(0.29, 0.92 * erupt, 0.10)) - 0.14;
float notch2 = length(q - vec3(-0.27, 1.25 * erupt, -0.06)) - 0.12;
dMain = max(dMain, -min(notch1, notch2));
res = opMin(res, vec2(dMain, MAT_SPIKE));
}
// 2. PRIMARY RADIAL CRYSTAL SPIKES (10 bold spikes jutting around crater)
if (rXZ > 0.65 && rXZ < 3.95 && p.y > -0.35 && p.y < 2.65) {
float spAngles[10] = float[10](
-0.55, 0.08, 0.62, 1.28, 1.95, 2.52, 3.05, 3.68, 4.32, 5.02
);
float spHeights[10] = float[10](
1.78, 1.65, 1.48, 1.35, 1.85, 1.68, 1.32, 1.45, 1.92, 1.15
);
float spRadii[10] = float[10](
0.24, 0.22, 0.19, 0.18, 0.23, 0.22, 0.18, 0.19, 0.25, 0.16
);
float spTilts[10] = float[10](
0.96, 1.16, 0.86, 0.62, 0.78, 0.92, 1.12, 1.05, 1.08, 1.22
);
float spDist[10] = float[10](
1.48, 1.55, 1.42, 1.26, 1.38, 1.46, 1.50, 1.45, 1.52, 1.58
);
for (int i = 0; i < 10; i++) {
float ang = spAngles[i];
float ca = cos(ang), sa = sin(ang);
vec3 base = vec3(ca * spDist[i], -0.04, sa * spDist[i]);
float breathe = 1.0 + 0.03 * sin(phase + float(i) * 0.9);
float h = spHeights[i] * erupt * breathe;
vec3 mid = base + vec3(ca * sin(spTilts[i]), cos(spTilts[i]), sa * sin(spTilts[i])) * (h * 0.5);
if (length(p - mid) < h * 0.60 + 0.30) {
vec3 q = toSpikeLocal(p, base, -ang, spTilts[i], float(i) * 0.53);
float d = sdHexCrystal(q, spRadii[i], h, 0.36);
res = opMin(res, vec2(d, MAT_SPIKE));
}
}
}
// 3. INNER NEEDLE SPIKES (6 sleek sharp spikes framing the central spire)
if (rXZ > 0.35 && rXZ < 2.15 && p.y > -0.25 && p.y < 2.25) {
for (int i = 0; i < 6; i++) {
float fi = float(i);
float ang = fi * (TAU / 6.0) + 0.36;
float ca = cos(ang), sa = sin(ang);
vec3 base = vec3(ca * 0.82, -0.05, sa * 0.82);
float h = (1.30 + 0.38 * hash11(fi * 5.7 + 1.2)) * erupt;
float tilt = 0.34 + 0.14 * hash11(fi * 9.3 + 2.4);
vec3 mid = base + vec3(ca * sin(tilt), cos(tilt), sa * sin(tilt)) * (h * 0.5);
if (length(p - mid) < h * 0.60 + 0.22) {
vec3 q = toSpikeLocal(p, base, -ang, tilt, fi * 0.8);
float d = sdHexCrystal(q, 0.115, h, 0.42);
res = opMin(res, vec2(d, MAT_SPIKE));
}
}
}
// 4. FLOATING / LEVITATING ANGULAR COMIC FROST SHARDS (8 outer shards)
if (rXZ > 1.45 && rXZ < 3.40 && p.y > 0.35 && p.y < 3.25) {
float shAngles[8] = float[8](
-2.25, -1.55, -0.82, 0.35, 1.12, 2.08, 2.75, 3.85
);
float shR[8] = float[8](
2.15, 2.55, 2.25, 2.35, 2.60, 2.30, 2.45, 2.20
);
float shY[8] = float[8](
1.85, 2.35, 1.55, 1.10, 2.10, 1.75, 0.95, 1.35
);
float shSize[8] = float[8](
0.21, 0.15, 0.17, 0.13, 0.18, 0.14, 0.12, 0.16
);
float openY = mix(0.75, 1.05, clamp(uOpen, 0.0, 1.0));
for (int i = 0; i < 8; i++) {
float fi = float(i);
float ang = shAngles[i] + 0.08 * sin(phase + fi * 1.1);
float bob = 0.18 * sin(phase + fi * 1.37);
float rad = shR[i] + 0.08 * cos(phase + fi * 0.83);
vec3 cPos = vec3(cos(ang) * rad, shY[i] * openY + bob, sin(ang) * rad);
float sz = shSize[i];
if (length(p - cPos) < sz * 3.1 + 0.18) {
vec3 q = p - cPos;
q.xz = rot2(-ang + phase * 0.25 * (mod(fi, 2.0) < 0.5 ? 1.0 : -1.0)) * q.xz;
q.xy = rot2(0.45 + 0.2 * sin(fi * 2.1)) * q.xy;
float d = sdHexShard(q, sz * 0.72, sz * 2.35, sz * 1.65);
res = opMin(res, vec2(d, MAT_SHARD));
}
}
}
return res;
}
vec2 mapScene(vec3 p) {
vec2 res = mapCrystals(p);
float r = length(p.xz);
float ang = atan(p.z, p.x);
float rIn = craterInnerR(ang);
float rOut = craterOuterR(ang);
// Arena floor with sunken circular-jagged crater hole
float dFloorPlane = p.y;
// Inside the crater, push floor down to abyss depth (-0.58)
float dCraterHole = r - rIn;
float dAbyss = max(p.y + 0.56, dCraterHole);
float dFloor = max(dFloorPlane, -dCraterHole);
// Raised curved arena parapet rim at R ~ 5.6
float dRim = max(abs(r - 5.65) - 0.32, p.y - 0.24);
dRim = max(dRim, -p.y - 0.1);
res = opMin(res, vec2(dFloor, MAT_FLOOR));
res = opMin(res, vec2(dAbyss, MAT_ABYSS));
res = opMin(res, vec2(dRim, MAT_RIM));
// Cracked polygonal ice crust slabs around crater rim (rIn .. rOut)
if (r > rIn - 0.35 && r < rOut + 0.35 && abs(p.y) < 0.65) {
float crack = slabCrackDist(ang, r);
float slabId = floor(fract(ang / TAU + 1.0) * 9.0);
float slabTilt = (hash11(slabId * 13.1 + 2.0) - 0.5) * 0.09;
float slabH = 0.17 + 0.06 * hash11(slabId * 7.3 + 5.0) + slabTilt * (r - 1.5);
// Slightly raised outer lip & jagged bevel
float dOuter = r - rOut;
float dInner = rIn - r;
float dTop = p.y - slabH;
float dBot = -p.y - 0.58;
float dSlab = max(max(dOuter, dInner), max(dTop, dBot));
// Carve crisp dark-ink fissures between slabs
float crackWidth = 0.055 + 0.02 * (r - rIn);
float dCrackCarve = crackWidth - crack;
dSlab = max(dSlab, dCrackCarve);
// Subtle chamfer on top edge
dSlab = max(dSlab, (p.y - slabH + 0.03) * 0.707 + max(dInner, dOuter) * 0.707);
res = opMin(res, vec2(dSlab, MAT_SLAB));
}
return res;
}
// ============================================================================
// NORMALS & SHADOWS
// ============================================================================
vec3 calcNormal(vec3 p) {
vec2 e = vec2(0.0022, -0.0022);
return safeNorm(
e.xyy * mapScene(p + e.xyy).x +
e.yyx * mapScene(p + e.yyx).x +
e.yxy * mapScene(p + e.yxy).x +
e.xxx * mapScene(p + e.xxx).x
);
}
// Crisp comic cel-shaded hard shadow (16 steps, fast)
float calcShadow(vec3 ro, vec3 rd, float maxT) {
if (length(ro.xz) > 4.6) return 1.0;
float t = 0.05;
float sh = 1.0;
for (int i = 0; i < 16; i++) {
float h = mapCrystals(ro + rd * t).x;
if (h < 0.005) return 0.0;
sh = min(sh, 16.0 * h / t);
t += clamp(h, 0.05, 0.45);
if (t > maxT) break;
}
return smoothstep(0.15, 0.55, sh);
}
// ============================================================================
// JAGGED COMIC STARBURST FLASH CORE (3D BILLBOARD AT CRATER CENTER)
// ============================================================================
// Returns vec4(rgb, alpha) and out hit depth tStar
vec4 evalStarburst(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, vec3 camFwd, out float tStar) {
float phase = getPhase();
float erupt = getErupt();
vec3 center = vec3(0.0, 0.42 * erupt, 0.0);
// Intersect camera-facing plane passing through center
float denom = dot(rd, camFwd);
tStar = 1e5;
if (abs(denom) < 1e-4) return vec4(0.0);
float t = dot(center - ro, camFwd) / denom;
if (t <= 0.05) return vec4(0.0);
tStar = t;
vec3 hitP = ro + rd * t;
vec3 rel = hitP - center;
vec2 uv = vec2(dot(rel, camRight), dot(rel, camUp));
float r = length(uv);
float ang = atan(uv.y, uv.x);
// Scale with eruption and 3s loop pulse
float scale = mix(0.72, 1.08, clamp(uOpen, 0.0, 1.0)) * (1.0 + 0.075 * sin(phase));
float rn = r / max(scale, 0.1);
if (rn > 1.75) return vec4(0.0);
// Sharp jagged 16-ray primary + 9-ray secondary starburst profile
float a1 = ang + 0.06 * sin(phase);
float spike1 = pow(abs(cos(a1 * 8.0 + 0.35 * sin(a1 * 3.0))), 6.0);
float spike2 = pow(abs(sin(a1 * 5.0 - 0.65)), 8.0);
float spike3 = pow(abs(cos(a1 * 13.0 + 1.2 - 0.12 * cos(phase))), 9.0);
// Elongate horizontal & upward rays slightly like 05.png
float dirBias = 0.85 + 0.25 * abs(cos(ang)) + 0.22 * max(sin(ang), 0.0);
float outerR = (0.34 + 0.92 * max(spike1, 0.78 * spike2) + 0.38 * spike3) * dirBias;
float innerR = (0.20 + 0.58 * max(spike1, 0.72 * spike2) + 0.22 * spike3) * dirBias;
float dOut = rn - outerR;
float dIn = rn - innerR;
float aa = 0.018;
float inkMask = 1.0 - smoothstep(0.015, 0.015 + aa, dOut);
float cyanMask = 1.0 - smoothstep(-0.022, -0.022 + aa, dOut);
float whiteMask = 1.0 - smoothstep(0.0, aa, dIn);
// Soft additive halo right around core
float glow = exp(-rn * 2.2) * 0.42;
vec3 col = COL_INK;
col = mix(col, COL_CORE_CYAN, cyanMask);
col = mix(col, COL_ICE_WHITE, whiteMask);
float alpha = clamp(inkMask + glow * (1.0 - inkMask), 0.0, 1.0);
vec3 outCol = mix(COL_CORE_CYAN, col, inkMask);
return vec4(outCol, alpha);
}
// ============================================================================
// COMIC 4-POINT DIAMOND SPARKLES (WORLD-ANCHORED BILLBOARDS)
// ============================================================================
vec3 evalSparkles(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float sceneT) {
float phase = getPhase();
vec3 acc = vec3(0.0);
for (int i = 0; i < 14; i++) {
float fi = float(i);
float ang = fi * (TAU / 14.0) + 0.21;
float rad = 1.95 + 1.25 * hash11(fi * 11.7 + 3.0);
float h = 0.22 + 2.35 * hash11(fi * 7.3 + 9.1);
float bob = 0.14 * sin(phase + fi * 1.6);
vec3 spPos = vec3(cos(ang) * rad, h + bob, sin(ang) * rad);
float t = dot(spPos - ro, rd);
if (t < 0.2 || t > sceneT) continue;
vec3 dVec = ro + rd * t - spPos;
vec2 uv = vec2(dot(dVec, camRight), dot(dVec, camUp));
float twinkle = 0.65 + 0.35 * sin(phase * 2.0 + fi * 2.3);
float sz = (0.08 + 0.06 * hash11(fi * 4.1)) * twinkle;
vec2 a = abs(uv) / max(sz, 0.01);
// Crisp 4-point astroid diamond star
float starD = pow(max(a.x, 1e-4), 0.55) + pow(max(a.y, 1e-4), 0.55);
float fill = 1.0 - smoothstep(0.82, 0.96, starD);
float halo = exp(-length(a) * 1.8) * 0.45;
acc += COL_ICE_WHITE * fill + COL_CORE_CYAN * halo;
}
return acc;
}
// ============================================================================
// ARENA FLOOR SHADING (INK-GROUTED CHARCOAL TILES + RADIAL CRATER CRACKS)
// ============================================================================
vec3 shadeFloor(vec3 p, vec3 N, vec3 L, float sh, float matID) {
float r = length(p.xz);
float ang = atan(p.z, p.x);
// Polar-radial + grid arena tiles (charcoal matte slabs with ink grout)
vec2 tileUV = p.xz * 0.62;
vec2 tileId = floor(tileUV);
vec2 tileF = fract(tileUV);
float groutX = min(tileF.x, 1.0 - tileF.x);
float groutY = min(tileF.y, 1.0 - tileF.y);
float grout = min(groutX, groutY);
// Subtle per-tile matte tonal variation around shared COL_FLOOR_BASE
float tileTone = 0.90 + 0.22 * hash12(tileId * 13.7);
vec3 baseCol = COL_FLOOR_BASE * tileTone;
// Slight matte roughness grain
float grain = (vnoise2(p.xz * 7.5) - 0.5) * 0.018;
baseCol += vec3(grain);
// Parapet rim coloring
if (matID == MAT_RIM) {
float seg = fract(ang * 12.0 / TAU);
float rimGrout = min(seg, 1.0 - seg);
baseCol = COL_FLOOR_BASE * (N.y > 0.5 ? 1.45 : 1.15);
float gMask = 1.0 - smoothstep(0.02, 0.05, rimGrout);
baseCol = mix(baseCol, COL_INK, gMask);
// Top bevel ink line
float edgeInk = smoothstep(0.28, 0.32, abs(r - 5.65));
baseCol = mix(baseCol, COL_INK, edgeInk * 0.85);
} else {
// Ink grout lines
float groutMask = 1.0 - smoothstep(0.018, 0.038, grout);
baseCol = mix(baseCol, COL_INK, groutMask * 0.92);
}
// Radial jagged floor fracture cracks extending from crater slabs
if (r > 1.55 && r < 4.35 && matID == MAT_FLOOR) {
float crackD = slabCrackDist(ang, r);
float fade = smoothstep(4.2, 1.9, r);
float crackW = 0.028 * fade;
float crackLine = (1.0 - smoothstep(crackW * 0.5, crackW + 0.014, crackD)) * fade;
baseCol = mix(baseCol, COL_INK, crackLine * 0.95);
// Subtle frost-cyan lip along near cracks (muted in neutral grayscale mode)
if (uLightMode != 1) {
float frostLip = smoothstep(crackW + 0.06, crackW, crackD) * (1.0 - crackLine) * smoothstep(3.1, 1.75, r);
baseCol += COL_CORE_CYAN * frostLip * 0.14;
}
}
// Quantized cel-shaded key light + hard cast shadow
float ndl = max(dot(N, L), 0.0);
float celLit = mix(0.68, 1.28, step(0.35, ndl) * sh);
vec3 col = baseCol * celLit;
// Stylized cel-banded cyan bounce glow from crater center (muted in uLightMode == 1)
if (uLightMode != 1) {
float coreDist = max(r - 1.2, 0.0);
float bounce = exp(-coreDist * 0.85);
float bounceBand = floor(bounce * 3.0 + 0.2) / 3.0;
col += COL_CORE_CYAN * bounceBand * 0.22 * (0.45 + 0.55 * sh);
}
return col;
}
// ============================================================================
// CRATER ICE SLAB & ABYSS SHADING
// ============================================================================
vec3 shadeSlab(vec3 p, vec3 N, vec3 V, vec3 L, float sh) {
float ndl = dot(N, L);
// 3-band cel shading
vec3 col;
if (N.y > 0.55) {
// Top of broken ice slab
float speckle = fbm2(p.xz * 4.5);
col = mix(COL_SLAB_TOP * 0.84, COL_ICE_LIGHT, smoothstep(0.45, 0.72, speckle));
col *= mix(0.74, 1.06, sh * smoothstep(-0.1, 0.15, ndl));
} else {
// Vertical jagged cliff face into crater
float band = step(0.15, ndl * sh);
col = mix(COL_ICE_SHADOW, COL_SLAB_SIDE, band);
// Subtle inner crater cyan bounce (muted in uLightMode == 1)
if (uLightMode != 1) {
col += COL_CORE_CYAN * 0.22 * smoothstep(1.65, 1.15, length(p.xz));
}
}
// Crisp Fresnel ink contour on slab edges
float fres = 1.0 - max(dot(N, V), 0.0);
float inkF = smoothstep(0.68, 0.82, fres);
col = mix(col, COL_INK, inkF * 0.88);
return col;
}
vec3 shadeAbyss(vec3 p) {
float r = length(p.xz);
float ang = atan(p.z, p.x);
float swirl = fbm2(p.xz * 3.2 + vec2(0.0, uTime * 0.25));
float coreGlow = exp(-r * 1.15);
float glowAmt = (uLightMode == 1) ? 0.15 : clamp(coreGlow * 0.85 + swirl * 0.25, 0.0, 1.0);
vec3 col = mix(COL_ABYSS, COL_CORE_CYAN, glowAmt);
// Crisp cyan-white frost flecks in the abyss
float flecks = smoothstep(0.76, 0.82, vnoise2(p.xz * 12.0 + ang));
col = mix(col, COL_ICE_LIGHT, flecks * ((uLightMode == 1) ? 0.20 : 0.65));
return col;
}
// ============================================================================
// FACETED CRYSTAL SPIKE & SHARD SHADING (3-BAND CEL + FAST SDF CREASE INK)
// ============================================================================
vec3 shadeCrystal(vec3 p, vec3 N, vec3 V, vec3 L, float sh, float matID) {
float ndl = dot(N, L);
float shadowFactor = mix(0.45, 1.0, sh);
float lit = ndl * shadowFactor;
// Quantized 3-band cel shading: shadow teal / mid frost-cyan / bright sky-ice
vec3 col;
if (lit > 0.42) {
col = COL_ICE_LIGHT;
} else if (lit > -0.08) {
col = COL_ICE_MID;
} else {
col = COL_ICE_SHADOW;
}
// Stylized comic frost texture / hand-painted crystalline mottling inside facets
float frostTex = fbm2(p.xy * 5.2 + p.zz * 3.7);
if (lit > -0.08 && lit <= 0.42) {
col = mix(col, COL_ICE_LIGHT, smoothstep(0.58, 0.72, frostTex) * 0.55);
col = mix(col, COL_ICE_SHADOW, smoothstep(0.32, 0.22, frostTex) * 0.35);
} else if (lit <= -0.08) {
col = mix(col, COL_ICE_MID, smoothstep(0.62, 0.75, frostTex) * 0.35);
}
// Sharp cel-quantized specular highlight on lit facets
vec3 H = safeNorm(L + V);
float spec = pow(max(dot(N, H), 0.0), 24.0);
float specBand = step(0.45, spec) * sh;
col = mix(col, COL_ICE_WHITE, specBand * 0.88);
// Core emissive frost bounce near the crater center (muted in uLightMode == 1)
if (uLightMode != 1) {
float coreDist = length(p - vec3(0.0, 0.45, 0.0));
float coreGlow = exp(-coreDist * 0.72);
col = mix(col, COL_ICE_WHITE, smoothstep(0.42, 0.88, coreGlow) * 0.55);
}
// Crisp rim highlight on backlit facets
float fres = 1.0 - max(dot(N, V), 0.0);
float rimStr = (uLightMode == 3) ? 0.85 : ((uLightMode == 1) ? 0.20 : 0.40);
float rimBand = step(0.58, fres) * step(-0.2, dot(N, vec3(0.0, 1.0, 0.0)));
col = mix(col, COL_ICE_WHITE, rimBand * rimStr * 0.55);
// FAST INTERNAL FACET CREASE INK: 3-tap tangent SDF Laplacian check
// On a flat facet d(p +- t*eps) == 0; near a convex crystal ridge it rises > 0
vec3 t1 = safeNorm(cross(N, abs(N.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0)));
vec3 t2 = safeNorm(cross(N, t1));
float eps = (matID == MAT_SHARD) ? 0.018 : 0.028;
float dLap = max(mapCrystals(p + t1 * eps).x, mapCrystals(p - t1 * eps).x)
+ max(mapCrystals(p + t2 * eps).x, 0.0);
float creaseInk = smoothstep(eps * 0.16, eps * 0.46, dLap);
// Bold Fresnel outer contour ink
float fresInk = smoothstep(0.76, 0.88, fres);
float totalInk = clamp(max(creaseInk * 0.88, fresInk), 0.0, 1.0);
col = mix(col, COL_INK, totalInk);
return col;
}
// ============================================================================
// MAIN RENDERER
// ============================================================================
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 res = max(uResolution, vec2(1.0));
vec2 uv = (pfx_frag_xy - 0.5 * res) / min(res.x, res.y);
// Camera presets (uCamMode 0: hero 3/4 ref view, 1: low dramatic angle, 2: top-down)
vec3 ro, ta;
float fov = 1.28;
if (uCamMode == 1) {
ro = vec3(2.8, 1.55, 4.3);
ta = vec3(0.0, 1.05, 0.0);
fov = 1.22;
} else if (uCamMode == 2) {
ro = vec3(0.0, 7.6, 1.85);
ta = vec3(0.0, 0.2, 0.0);
fov = 1.32;
} else {
ro = vec3(0.0, 4.35, 5.25);
ta = vec3(0.0, 0.72, 0.0);
fov = 1.26;
}
vec3 camFwd = safeNorm(ta - ro);
vec3 camRight = safeNorm(cross(camFwd, vec3(0.0, 1.0, 0.0)));
vec3 camUp = safeNorm(cross(camRight, camFwd));
vec3 rd = safeNorm(camFwd * fov + camRight * uv.x + camUp * uv.y);
// Lighting presets:
// 0 = hero upper-left key, 1 = neutral grayscale studio (emission muted),
// 2 = high-key right, 3 = backlit rim
vec3 L;
if (uLightMode == 3) {
L = safeNorm(vec3(-0.35, 0.65, -0.75));
} else if (uLightMode == 2) {
L = safeNorm(vec3(0.65, 0.82, 0.45));
} else {
L = safeNorm(vec3(-0.62, 0.85, 0.48));
}
// Raymarch scene (64 steps, single mapScene call per step — reuses h.x for crystal silhouette)
float t = 0.0;
float tMax = 22.0;
float matID = 0.0;
bool hit = false;
float minCrysRatio = 1e5;
float minCrysT = 1e5;
bool passedCrystal = false;
for (int i = 0; i < 64; i++) {
vec3 p = ro + rd * t;
vec2 h = mapScene(p);
// Reuse crystal distance from mapScene when crystal is nearest (zero extra evals)
if ((h.y == MAT_SPIKE || h.y == MAT_SHARD) && h.x < 0.16 && t > 0.2) {
float ratio = h.x / max(t, 0.5);
if (ratio < minCrysRatio) {
minCrysRatio = ratio;
minCrysT = t;
}
if (h.x < 0.05) passedCrystal = true;
}
if (h.x < 0.0028) {
hit = true;
matID = h.y;
break;
}
t += clamp(h.x, 0.012, 0.72);
if (t > tMax) break;
}
// Background sky above arena parapet (cool stylized glacial mist, zero clip & zero black)
float skyGrad = clamp(rd.y * 2.2 + 0.25, 0.0, 1.0);
vec3 col = mix(vec3(0.14, 0.18, 0.24), vec3(0.28, 0.36, 0.46), skyGrad);
if (uLightMode != 1) {
float horizonGlow = exp(-abs(rd.y + 0.08) * 14.0);
col += COL_CORE_CYAN * horizonGlow * 0.12;
}
float sceneT = hit ? t : tMax;
if (hit) {
vec3 p = ro + rd * t;
vec3 N = calcNormal(p);
vec3 V = -rd;
float sh = (matID == MAT_ABYSS) ? 1.0 : calcShadow(p + N * 0.015, L, 6.0);
if (matID == MAT_FLOOR || matID == MAT_RIM) {
col = shadeFloor(p, N, L, sh, matID);
} else if (matID == MAT_SLAB) {
col = shadeSlab(p, N, V, L, sh);
} else if (matID == MAT_ABYSS) {
col = shadeAbyss(p);
} else {
col = shadeCrystal(p, N, V, L, sh, matID);
}
// Apply crisp external black-ink silhouette outline when ray grazed a crystal in front
if (passedCrystal && ((matID != MAT_SPIKE && matID != MAT_SHARD) || t > minCrysT + 0.18)) {
float outlineMask = 1.0 - smoothstep(0.0045, 0.0078, minCrysRatio);
col = mix(col, COL_INK, outlineMask * 0.96);
}
} else if (passedCrystal) {
// Crystal silhouette against sky
float outlineMask = 1.0 - smoothstep(0.0045, 0.0078, minCrysRatio);
col = mix(col, COL_INK, outlineMask * 0.96);
}
// Composite jagged comic starburst flash core & 4-point sparkles (muted in uLightMode == 1)
if (uLightMode != 1) {
float tStar;
vec4 star = evalStarburst(ro, rd, camRight, camUp, camFwd, tStar);
if (star.a > 0.001) {
float depthFade = smoothstep(-0.35, 0.28, sceneT - tStar);
if (hit && matID == MAT_ABYSS) depthFade = 1.0;
col = mix(col, star.rgb, star.a * depthFade);
}
vec3 sparks = evalSparkles(ro, rd, camRight, camUp, sceneT);
col += sparks;
}
// Subtle comic radial vignette (preserves dark floor > black threshold)
float vig = 1.0 - 0.14 * dot(uv, uv);
col *= clamp(vig, 0.82, 1.0);
// Gentle soft-shoulder tonemap to prevent clipping (<1% clip) & avoid NaN
col = max(col, vec3(0.0));
col = col / (1.0 + col * 0.16);
col = clamp(col, vec3(0.025, 0.032, 0.048), vec3(0.975));
// Pure neutral grayscale output for uLightMode == 1
if (uLightMode == 1) {
float lum = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(lum);
}
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);
}
}
// Frost Teal Ice Nova Spikes — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_stylized/lib/05_frost_teal_ice_nova_spikes.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;
// ============================================================================
// FROST-TEAL ICE NOVA SPIKES — STYLIZED CEL-SHADED VFX
// ============================================================================
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
// Shared style contract & Glacial Frost-Teal palette
const vec3 COL_FLOOR_BASE = vec3(0.08, 0.09, 0.12);
const vec3 COL_INK = vec3(0.032, 0.042, 0.062); // Deep comic ink (avoids pure-black clip)
const vec3 COL_ABYSS = vec3(0.045, 0.22, 0.34);
const vec3 COL_ICE_SHADOW = vec3(0.11, 0.44, 0.66);
const vec3 COL_ICE_MID = vec3(0.36, 0.81, 0.96);
const vec3 COL_ICE_LIGHT = vec3(0.82, 0.95, 1.00);
const vec3 COL_ICE_WHITE = vec3(0.95, 0.99, 1.00);
const vec3 COL_SLAB_TOP = vec3(0.68, 0.86, 0.95);
const vec3 COL_SLAB_SIDE = vec3(0.24, 0.64, 0.84);
const vec3 COL_CORE_CYAN = vec3(0.18, 0.88, 1.00);
// Material IDs
const float MAT_FLOOR = 1.0;
const float MAT_SLAB = 2.0;
const float MAT_SPIKE = 3.0;
const float MAT_SHARD = 4.0;
const float MAT_ABYSS = 5.0;
const float MAT_RIM = 6.0;
// ============================================================================
// MATH & NOISE UTILITIES
// ============================================================================
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
float hash11(float p) {
p = fract(p * 0.1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
float hash12(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(
mix(hash12(i + vec2(0.0, 0.0)), hash12(i + vec2(1.0, 0.0)), u.x),
mix(hash12(i + vec2(0.0, 1.0)), hash12(i + vec2(1.0, 1.0)), u.x),
u.y
);
}
float fbm2(vec2 p) {
float v = 0.0;
float a = 0.5;
mat2 m = mat2(0.80, -0.60, 0.60, 0.80);
for (int i = 0; i < 4; i++) {
v += a * vnoise2(p);
p = m * p * 2.03 + vec2(11.3, 7.1);
a *= 0.5;
}
return v;
}
vec3 safeNorm(vec3 v) {
float l = length(v);
return l > 1e-6 ? v / l : vec3(0.0, 1.0, 0.0);
}
// ============================================================================
// FACETED CRYSTAL & CRATER SDF PRIMITIVES
// ============================================================================
// Exact hexagonal distance in XZ plane (flat-to-flat radius = r)
float sdHex2D(vec2 p) {
p = abs(p);
return max(p.x * 0.8660254 + p.y * 0.5, p.y);
}
// Faceted hexagonal crystal obelisk: base at y=0, tip at y=h, shaft radius r
float sdHexCrystal(vec3 p, float r, float h, float tipFrac) {
float tipY = h * (1.0 - tipFrac);
float tipH = max(h * tipFrac, 0.05);
float hexD = sdHex2D(p.xz);
// Slight outward flare along the shaft for stylized heroic silhouette
float shaftSlope = 0.05;
float rAtY = r * (0.90 + 0.14 * clamp(p.y / max(tipY, 0.05), 0.0, 1.0));
float dShaft = (hexD - rAtY) * 0.998;
// Exact 6-sided pyramidal tip planes
float rTop = r * 1.04;
vec2 tipN = normalize(vec2(tipH, rTop));
float dTip = dot(vec2(hexD, p.y - tipY), tipN) - rTop * tipN.x;
// Base cap
float dBase = -p.y;
return max(max(dShaft, dTip), dBase);
}
// Faceted hexagonal bipyramid (floating comic frost shard)
float sdHexShard(vec3 p, float r, float hTop, float hBot) {
float hexD = sdHex2D(p.xz);
vec2 nTop = normalize(vec2(hTop, r));
vec2 nBot = normalize(vec2(hBot, r));
float dTop = dot(vec2(hexD, p.y), nTop) - r * nTop.x;
float dBot = dot(vec2(hexD, -p.y), nBot) - r * nBot.x;
return max(dTop, dBot);
}
// Orient a point into a crystal's local frame (origin at pos, +Y along tilt)
vec3 toSpikeLocal(vec3 p, vec3 basePos, float yaw, float tilt, float spin) {
vec3 q = p - basePos;
q.xz = rot2(-yaw) * q.xz;
q.xy = rot2(-tilt) * q.xy;
q.xz = rot2(spin) * q.xz;
return q;
}
// ============================================================================
// SCENE PARAMETERS & ANIMATION (3s LOOP + uOpen)
// ============================================================================
float getPhase() {
return uTime * (TAU / 3.0);
}
float getErupt() {
float o = clamp(uOpen, 0.0, 1.0);
float pulse = 0.045 * sin(getPhase());
return mix(0.58, 1.12, o) + pulse;
}
// Jagged crater radius as a function of azimuth
float craterInnerR(float ang) {
float j = 0.11 * sin(ang * 5.0 + 0.4)
+ 0.07 * cos(ang * 9.0 - 1.1)
+ 0.04 * sin(ang * 13.0 + 2.3);
return 1.18 + j;
}
float craterOuterR(float ang) {
float j = 0.16 * sin(ang * 4.0 - 0.7)
+ 0.10 * cos(ang * 7.0 + 1.5)
+ 0.06 * sin(ang * 11.0 + 0.2);
return 1.88 + j;
}
// Angular fissure gap mask between cracked crater ice slabs (returns >0 inside crack)
float slabCrackDist(float ang, float r) {
// 9 irregular radial cracks around the crater ring
float aNorm = fract(ang / TAU + 1.0);
float seg = aNorm * 9.0;
float id = floor(seg);
float f = fract(seg);
float jitter = (hash11(id * 17.3 + 3.1) - 0.5) * 0.24;
// Zig-zag radial wobble
float zig = 0.055 * sin(r * 14.0 + id * 4.7) + 0.03 * cos(r * 25.0 - id * 2.1);
float dEdge = min(abs(f - 0.5 + jitter + zig), min(abs(f + jitter + zig), abs(f - 1.0 + jitter + zig)));
// Use distance to nearest seam (at f ~ 0 + jitter)
float seam = abs(fract(seg + 0.5 + jitter + zig) - 0.5);
return seam * (TAU / 9.0) * max(r, 0.8);
}
// ============================================================================
// SCENE SDF: returns vec2(distance, materialID)
// ============================================================================
vec2 opMin(vec2 a, vec2 b) {
return a.x < b.x ? a : b;
}
// Only the hero crystals & floating shards (with tight ring bounds for fast marching)
vec2 mapCrystals(vec3 p) {
float erupt = getErupt();
float phase = getPhase();
vec2 res = vec2(1e5, MAT_SPIKE);
// Quick bounding sphere for entire spike cluster
float boundAll = length(p - vec3(0.0, 1.35, 0.0)) - 4.1;
if (boundAll > 0.25) {
return vec2(boundAll, MAT_SPIKE);
}
float rXZ = length(p.xz);
// 1. HERO CENTRAL SPIRE (towering hexagonal obelisk)
if (rXZ < 0.85 && p.y > -0.35 && p.y < 3.65) {
vec3 q = p - vec3(0.0, -0.15, 0.0);
q.xz = rot2(0.28) * q.xz;
float h = 2.95 * erupt;
float r = 0.31;
float dMain = sdHexCrystal(q, r, h, 0.28);
float notch1 = length(q - vec3(0.29, 0.92 * erupt, 0.10)) - 0.14;
float notch2 = length(q - vec3(-0.27, 1.25 * erupt, -0.06)) - 0.12;
dMain = max(dMain, -min(notch1, notch2));
res = opMin(res, vec2(dMain, MAT_SPIKE));
}
// 2. PRIMARY RADIAL CRYSTAL SPIKES (10 bold spikes jutting around crater)
if (rXZ > 0.65 && rXZ < 3.95 && p.y > -0.35 && p.y < 2.65) {
float spAngles[10] = float[10](
-0.55, 0.08, 0.62, 1.28, 1.95, 2.52, 3.05, 3.68, 4.32, 5.02
);
float spHeights[10] = float[10](
1.78, 1.65, 1.48, 1.35, 1.85, 1.68, 1.32, 1.45, 1.92, 1.15
);
float spRadii[10] = float[10](
0.24, 0.22, 0.19, 0.18, 0.23, 0.22, 0.18, 0.19, 0.25, 0.16
);
float spTilts[10] = float[10](
0.96, 1.16, 0.86, 0.62, 0.78, 0.92, 1.12, 1.05, 1.08, 1.22
);
float spDist[10] = float[10](
1.48, 1.55, 1.42, 1.26, 1.38, 1.46, 1.50, 1.45, 1.52, 1.58
);
for (int i = 0; i < 10; i++) {
float ang = spAngles[i];
float ca = cos(ang), sa = sin(ang);
vec3 base = vec3(ca * spDist[i], -0.04, sa * spDist[i]);
float breathe = 1.0 + 0.03 * sin(phase + float(i) * 0.9);
float h = spHeights[i] * erupt * breathe;
vec3 mid = base + vec3(ca * sin(spTilts[i]), cos(spTilts[i]), sa * sin(spTilts[i])) * (h * 0.5);
if (length(p - mid) < h * 0.60 + 0.30) {
vec3 q = toSpikeLocal(p, base, -ang, spTilts[i], float(i) * 0.53);
float d = sdHexCrystal(q, spRadii[i], h, 0.36);
res = opMin(res, vec2(d, MAT_SPIKE));
}
}
}
// 3. INNER NEEDLE SPIKES (6 sleek sharp spikes framing the central spire)
if (rXZ > 0.35 && rXZ < 2.15 && p.y > -0.25 && p.y < 2.25) {
for (int i = 0; i < 6; i++) {
float fi = float(i);
float ang = fi * (TAU / 6.0) + 0.36;
float ca = cos(ang), sa = sin(ang);
vec3 base = vec3(ca * 0.82, -0.05, sa * 0.82);
float h = (1.30 + 0.38 * hash11(fi * 5.7 + 1.2)) * erupt;
float tilt = 0.34 + 0.14 * hash11(fi * 9.3 + 2.4);
vec3 mid = base + vec3(ca * sin(tilt), cos(tilt), sa * sin(tilt)) * (h * 0.5);
if (length(p - mid) < h * 0.60 + 0.22) {
vec3 q = toSpikeLocal(p, base, -ang, tilt, fi * 0.8);
float d = sdHexCrystal(q, 0.115, h, 0.42);
res = opMin(res, vec2(d, MAT_SPIKE));
}
}
}
// 4. FLOATING / LEVITATING ANGULAR COMIC FROST SHARDS (8 outer shards)
if (rXZ > 1.45 && rXZ < 3.40 && p.y > 0.35 && p.y < 3.25) {
float shAngles[8] = float[8](
-2.25, -1.55, -0.82, 0.35, 1.12, 2.08, 2.75, 3.85
);
float shR[8] = float[8](
2.15, 2.55, 2.25, 2.35, 2.60, 2.30, 2.45, 2.20
);
float shY[8] = float[8](
1.85, 2.35, 1.55, 1.10, 2.10, 1.75, 0.95, 1.35
);
float shSize[8] = float[8](
0.21, 0.15, 0.17, 0.13, 0.18, 0.14, 0.12, 0.16
);
float openY = mix(0.75, 1.05, clamp(uOpen, 0.0, 1.0));
for (int i = 0; i < 8; i++) {
float fi = float(i);
float ang = shAngles[i] + 0.08 * sin(phase + fi * 1.1);
float bob = 0.18 * sin(phase + fi * 1.37);
float rad = shR[i] + 0.08 * cos(phase + fi * 0.83);
vec3 cPos = vec3(cos(ang) * rad, shY[i] * openY + bob, sin(ang) * rad);
float sz = shSize[i];
if (length(p - cPos) < sz * 3.1 + 0.18) {
vec3 q = p - cPos;
q.xz = rot2(-ang + phase * 0.25 * (mod(fi, 2.0) < 0.5 ? 1.0 : -1.0)) * q.xz;
q.xy = rot2(0.45 + 0.2 * sin(fi * 2.1)) * q.xy;
float d = sdHexShard(q, sz * 0.72, sz * 2.35, sz * 1.65);
res = opMin(res, vec2(d, MAT_SHARD));
}
}
}
return res;
}
vec2 mapScene(vec3 p) {
vec2 res = mapCrystals(p);
float r = length(p.xz);
float ang = atan(p.z, p.x);
float rIn = craterInnerR(ang);
float rOut = craterOuterR(ang);
// Arena floor with sunken circular-jagged crater hole
float dFloorPlane = p.y;
// Inside the crater, push floor down to abyss depth (-0.58)
float dCraterHole = r - rIn;
float dAbyss = max(p.y + 0.56, dCraterHole);
float dFloor = max(dFloorPlane, -dCraterHole);
// Raised curved arena parapet rim at R ~ 5.6
float dRim = max(abs(r - 5.65) - 0.32, p.y - 0.24);
dRim = max(dRim, -p.y - 0.1);
res = opMin(res, vec2(dFloor, MAT_FLOOR));
res = opMin(res, vec2(dAbyss, MAT_ABYSS));
res = opMin(res, vec2(dRim, MAT_RIM));
// Cracked polygonal ice crust slabs around crater rim (rIn .. rOut)
if (r > rIn - 0.35 && r < rOut + 0.35 && abs(p.y) < 0.65) {
float crack = slabCrackDist(ang, r);
float slabId = floor(fract(ang / TAU + 1.0) * 9.0);
float slabTilt = (hash11(slabId * 13.1 + 2.0) - 0.5) * 0.09;
float slabH = 0.17 + 0.06 * hash11(slabId * 7.3 + 5.0) + slabTilt * (r - 1.5);
// Slightly raised outer lip & jagged bevel
float dOuter = r - rOut;
float dInner = rIn - r;
float dTop = p.y - slabH;
float dBot = -p.y - 0.58;
float dSlab = max(max(dOuter, dInner), max(dTop, dBot));
// Carve crisp dark-ink fissures between slabs
float crackWidth = 0.055 + 0.02 * (r - rIn);
float dCrackCarve = crackWidth - crack;
dSlab = max(dSlab, dCrackCarve);
// Subtle chamfer on top edge
dSlab = max(dSlab, (p.y - slabH + 0.03) * 0.707 + max(dInner, dOuter) * 0.707);
res = opMin(res, vec2(dSlab, MAT_SLAB));
}
return res;
}
// ============================================================================
// NORMALS & SHADOWS
// ============================================================================
vec3 calcNormal(vec3 p) {
vec2 e = vec2(0.0022, -0.0022);
return safeNorm(
e.xyy * mapScene(p + e.xyy).x +
e.yyx * mapScene(p + e.yyx).x +
e.yxy * mapScene(p + e.yxy).x +
e.xxx * mapScene(p + e.xxx).x
);
}
// Crisp comic cel-shaded hard shadow (16 steps, fast)
float calcShadow(vec3 ro, vec3 rd, float maxT) {
if (length(ro.xz) > 4.6) return 1.0;
float t = 0.05;
float sh = 1.0;
for (int i = 0; i < 16; i++) {
float h = mapCrystals(ro + rd * t).x;
if (h < 0.005) return 0.0;
sh = min(sh, 16.0 * h / t);
t += clamp(h, 0.05, 0.45);
if (t > maxT) break;
}
return smoothstep(0.15, 0.55, sh);
}
// ============================================================================
// JAGGED COMIC STARBURST FLASH CORE (3D BILLBOARD AT CRATER CENTER)
// ============================================================================
// Returns vec4(rgb, alpha) and out hit depth tStar
vec4 evalStarburst(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, vec3 camFwd, out float tStar) {
float phase = getPhase();
float erupt = getErupt();
vec3 center = vec3(0.0, 0.42 * erupt, 0.0);
// Intersect camera-facing plane passing through center
float denom = dot(rd, camFwd);
tStar = 1e5;
if (abs(denom) < 1e-4) return vec4(0.0);
float t = dot(center - ro, camFwd) / denom;
if (t <= 0.05) return vec4(0.0);
tStar = t;
vec3 hitP = ro + rd * t;
vec3 rel = hitP - center;
vec2 uv = vec2(dot(rel, camRight), dot(rel, camUp));
float r = length(uv);
float ang = atan(uv.y, uv.x);
// Scale with eruption and 3s loop pulse
float scale = mix(0.72, 1.08, clamp(uOpen, 0.0, 1.0)) * (1.0 + 0.075 * sin(phase));
float rn = r / max(scale, 0.1);
if (rn > 1.75) return vec4(0.0);
// Sharp jagged 16-ray primary + 9-ray secondary starburst profile
float a1 = ang + 0.06 * sin(phase);
float spike1 = pow(abs(cos(a1 * 8.0 + 0.35 * sin(a1 * 3.0))), 6.0);
float spike2 = pow(abs(sin(a1 * 5.0 - 0.65)), 8.0);
float spike3 = pow(abs(cos(a1 * 13.0 + 1.2 - 0.12 * cos(phase))), 9.0);
// Elongate horizontal & upward rays slightly like 05.png
float dirBias = 0.85 + 0.25 * abs(cos(ang)) + 0.22 * max(sin(ang), 0.0);
float outerR = (0.34 + 0.92 * max(spike1, 0.78 * spike2) + 0.38 * spike3) * dirBias;
float innerR = (0.20 + 0.58 * max(spike1, 0.72 * spike2) + 0.22 * spike3) * dirBias;
float dOut = rn - outerR;
float dIn = rn - innerR;
float aa = 0.018;
float inkMask = 1.0 - smoothstep(0.015, 0.015 + aa, dOut);
float cyanMask = 1.0 - smoothstep(-0.022, -0.022 + aa, dOut);
float whiteMask = 1.0 - smoothstep(0.0, aa, dIn);
// Soft additive halo right around core
float glow = exp(-rn * 2.2) * 0.42;
vec3 col = COL_INK;
col = mix(col, COL_CORE_CYAN, cyanMask);
col = mix(col, COL_ICE_WHITE, whiteMask);
float alpha = clamp(inkMask + glow * (1.0 - inkMask), 0.0, 1.0);
vec3 outCol = mix(COL_CORE_CYAN, col, inkMask);
return vec4(outCol, alpha);
}
// ============================================================================
// COMIC 4-POINT DIAMOND SPARKLES (WORLD-ANCHORED BILLBOARDS)
// ============================================================================
vec3 evalSparkles(vec3 ro, vec3 rd, vec3 camRight, vec3 camUp, float sceneT) {
float phase = getPhase();
vec3 acc = vec3(0.0);
for (int i = 0; i < 14; i++) {
float fi = float(i);
float ang = fi * (TAU / 14.0) + 0.21;
float rad = 1.95 + 1.25 * hash11(fi * 11.7 + 3.0);
float h = 0.22 + 2.35 * hash11(fi * 7.3 + 9.1);
float bob = 0.14 * sin(phase + fi * 1.6);
vec3 spPos = vec3(cos(ang) * rad, h + bob, sin(ang) * rad);
float t = dot(spPos - ro, rd);
if (t < 0.2 || t > sceneT) continue;
vec3 dVec = ro + rd * t - spPos;
vec2 uv = vec2(dot(dVec, camRight), dot(dVec, camUp));
float twinkle = 0.65 + 0.35 * sin(phase * 2.0 + fi * 2.3);
float sz = (0.08 + 0.06 * hash11(fi * 4.1)) * twinkle;
vec2 a = abs(uv) / max(sz, 0.01);
// Crisp 4-point astroid diamond star
float starD = pow(max(a.x, 1e-4), 0.55) + pow(max(a.y, 1e-4), 0.55);
float fill = 1.0 - smoothstep(0.82, 0.96, starD);
float halo = exp(-length(a) * 1.8) * 0.45;
acc += COL_ICE_WHITE * fill + COL_CORE_CYAN * halo;
}
return acc;
}
// ============================================================================
// ARENA FLOOR SHADING (INK-GROUTED CHARCOAL TILES + RADIAL CRATER CRACKS)
// ============================================================================
vec3 shadeFloor(vec3 p, vec3 N, vec3 L, float sh, float matID) {
float r = length(p.xz);
float ang = atan(p.z, p.x);
// Polar-radial + grid arena tiles (charcoal matte slabs with ink grout)
vec2 tileUV = p.xz * 0.62;
vec2 tileId = floor(tileUV);
vec2 tileF = fract(tileUV);
float groutX = min(tileF.x, 1.0 - tileF.x);
float groutY = min(tileF.y, 1.0 - tileF.y);
float grout = min(groutX, groutY);
// Subtle per-tile matte tonal variation around shared COL_FLOOR_BASE
float tileTone = 0.90 + 0.22 * hash12(tileId * 13.7);
vec3 baseCol = COL_FLOOR_BASE * tileTone;
// Slight matte roughness grain
float grain = (vnoise2(p.xz * 7.5) - 0.5) * 0.018;
baseCol += vec3(grain);
// Parapet rim coloring
if (matID == MAT_RIM) {
float seg = fract(ang * 12.0 / TAU);
float rimGrout = min(seg, 1.0 - seg);
baseCol = COL_FLOOR_BASE * (N.y > 0.5 ? 1.45 : 1.15);
float gMask = 1.0 - smoothstep(0.02, 0.05, rimGrout);
baseCol = mix(baseCol, COL_INK, gMask);
// Top bevel ink line
float edgeInk = smoothstep(0.28, 0.32, abs(r - 5.65));
baseCol = mix(baseCol, COL_INK, edgeInk * 0.85);
} else {
// Ink grout lines
float groutMask = 1.0 - smoothstep(0.018, 0.038, grout);
baseCol = mix(baseCol, COL_INK, groutMask * 0.92);
}
// Radial jagged floor fracture cracks extending from crater slabs
if (r > 1.55 && r < 4.35 && matID == MAT_FLOOR) {
float crackD = slabCrackDist(ang, r);
float fade = smoothstep(4.2, 1.9, r);
float crackW = 0.028 * fade;
float crackLine = (1.0 - smoothstep(crackW * 0.5, crackW + 0.014, crackD)) * fade;
baseCol = mix(baseCol, COL_INK, crackLine * 0.95);
// Subtle frost-cyan lip along near cracks (muted in neutral grayscale mode)
if (uLightMode != 1) {
float frostLip = smoothstep(crackW + 0.06, crackW, crackD) * (1.0 - crackLine) * smoothstep(3.1, 1.75, r);
baseCol += COL_CORE_CYAN * frostLip * 0.14;
}
}
// Quantized cel-shaded key light + hard cast shadow
float ndl = max(dot(N, L), 0.0);
float celLit = mix(0.68, 1.28, step(0.35, ndl) * sh);
vec3 col = baseCol * celLit;
// Stylized cel-banded cyan bounce glow from crater center (muted in uLightMode == 1)
if (uLightMode != 1) {
float coreDist = max(r - 1.2, 0.0);
float bounce = exp(-coreDist * 0.85);
float bounceBand = floor(bounce * 3.0 + 0.2) / 3.0;
col += COL_CORE_CYAN * bounceBand * 0.22 * (0.45 + 0.55 * sh);
}
return col;
}
// ============================================================================
// CRATER ICE SLAB & ABYSS SHADING
// ============================================================================
vec3 shadeSlab(vec3 p, vec3 N, vec3 V, vec3 L, float sh) {
float ndl = dot(N, L);
// 3-band cel shading
vec3 col;
if (N.y > 0.55) {
// Top of broken ice slab
float speckle = fbm2(p.xz * 4.5);
col = mix(COL_SLAB_TOP * 0.84, COL_ICE_LIGHT, smoothstep(0.45, 0.72, speckle));
col *= mix(0.74, 1.06, sh * smoothstep(-0.1, 0.15, ndl));
} else {
// Vertical jagged cliff face into crater
float band = step(0.15, ndl * sh);
col = mix(COL_ICE_SHADOW, COL_SLAB_SIDE, band);
// Subtle inner crater cyan bounce (muted in uLightMode == 1)
if (uLightMode != 1) {
col += COL_CORE_CYAN * 0.22 * smoothstep(1.65, 1.15, length(p.xz));
}
}
// Crisp Fresnel ink contour on slab edges
float fres = 1.0 - max(dot(N, V), 0.0);
float inkF = smoothstep(0.68, 0.82, fres);
col = mix(col, COL_INK, inkF * 0.88);
return col;
}
vec3 shadeAbyss(vec3 p) {
float r = length(p.xz);
float ang = atan(p.z, p.x);
float swirl = fbm2(p.xz * 3.2 + vec2(0.0, uTime * 0.25));
float coreGlow = exp(-r * 1.15);
float glowAmt = (uLightMode == 1) ? 0.15 : clamp(coreGlow * 0.85 + swirl * 0.25, 0.0, 1.0);
vec3 col = mix(COL_ABYSS, COL_CORE_CYAN, glowAmt);
// Crisp cyan-white frost flecks in the abyss
float flecks = smoothstep(0.76, 0.82, vnoise2(p.xz * 12.0 + ang));
col = mix(col, COL_ICE_LIGHT, flecks * ((uLightMode == 1) ? 0.20 : 0.65));
return col;
}
// ============================================================================
// FACETED CRYSTAL SPIKE & SHARD SHADING (3-BAND CEL + FAST SDF CREASE INK)
// ============================================================================
vec3 shadeCrystal(vec3 p, vec3 N, vec3 V, vec3 L, float sh, float matID) {
float ndl = dot(N, L);
float shadowFactor = mix(0.45, 1.0, sh);
float lit = ndl * shadowFactor;
// Quantized 3-band cel shading: shadow teal / mid frost-cyan / bright sky-ice
vec3 col;
if (lit > 0.42) {
col = COL_ICE_LIGHT;
} else if (lit > -0.08) {
col = COL_ICE_MID;
} else {
col = COL_ICE_SHADOW;
}
// Stylized comic frost texture / hand-painted crystalline mottling inside facets
float frostTex = fbm2(p.xy * 5.2 + p.zz * 3.7);
if (lit > -0.08 && lit <= 0.42) {
col = mix(col, COL_ICE_LIGHT, smoothstep(0.58, 0.72, frostTex) * 0.55);
col = mix(col, COL_ICE_SHADOW, smoothstep(0.32, 0.22, frostTex) * 0.35);
} else if (lit <= -0.08) {
col = mix(col, COL_ICE_MID, smoothstep(0.62, 0.75, frostTex) * 0.35);
}
// Sharp cel-quantized specular highlight on lit facets
vec3 H = safeNorm(L + V);
float spec = pow(max(dot(N, H), 0.0), 24.0);
float specBand = step(0.45, spec) * sh;
col = mix(col, COL_ICE_WHITE, specBand * 0.88);
// Core emissive frost bounce near the crater center (muted in uLightMode == 1)
if (uLightMode != 1) {
float coreDist = length(p - vec3(0.0, 0.45, 0.0));
float coreGlow = exp(-coreDist * 0.72);
col = mix(col, COL_ICE_WHITE, smoothstep(0.42, 0.88, coreGlow) * 0.55);
}
// Crisp rim highlight on backlit facets
float fres = 1.0 - max(dot(N, V), 0.0);
float rimStr = (uLightMode == 3) ? 0.85 : ((uLightMode == 1) ? 0.20 : 0.40);
float rimBand = step(0.58, fres) * step(-0.2, dot(N, vec3(0.0, 1.0, 0.0)));
col = mix(col, COL_ICE_WHITE, rimBand * rimStr * 0.55);
// FAST INTERNAL FACET CREASE INK: 3-tap tangent SDF Laplacian check
// On a flat facet d(p +- t*eps) == 0; near a convex crystal ridge it rises > 0
vec3 t1 = safeNorm(cross(N, abs(N.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0)));
vec3 t2 = safeNorm(cross(N, t1));
float eps = (matID == MAT_SHARD) ? 0.018 : 0.028;
float dLap = max(mapCrystals(p + t1 * eps).x, mapCrystals(p - t1 * eps).x)
+ max(mapCrystals(p + t2 * eps).x, 0.0);
float creaseInk = smoothstep(eps * 0.16, eps * 0.46, dLap);
// Bold Fresnel outer contour ink
float fresInk = smoothstep(0.76, 0.88, fres);
float totalInk = clamp(max(creaseInk * 0.88, fresInk), 0.0, 1.0);
col = mix(col, COL_INK, totalInk);
return col;
}
// ============================================================================
// MAIN RENDERER
// ============================================================================
void main() {
vec2 res = max(uResolution, vec2(1.0));
vec2 uv = (gl_FragCoord.xy - 0.5 * res) / min(res.x, res.y);
// Camera presets (uCamMode 0: hero 3/4 ref view, 1: low dramatic angle, 2: top-down)
vec3 ro, ta;
float fov = 1.28;
if (uCamMode == 1) {
ro = vec3(2.8, 1.55, 4.3);
ta = vec3(0.0, 1.05, 0.0);
fov = 1.22;
} else if (uCamMode == 2) {
ro = vec3(0.0, 7.6, 1.85);
ta = vec3(0.0, 0.2, 0.0);
fov = 1.32;
} else {
ro = vec3(0.0, 4.35, 5.25);
ta = vec3(0.0, 0.72, 0.0);
fov = 1.26;
}
vec3 camFwd = safeNorm(ta - ro);
vec3 camRight = safeNorm(cross(camFwd, vec3(0.0, 1.0, 0.0)));
vec3 camUp = safeNorm(cross(camRight, camFwd));
vec3 rd = safeNorm(camFwd * fov + camRight * uv.x + camUp * uv.y);
// Lighting presets:
// 0 = hero upper-left key, 1 = neutral grayscale studio (emission muted),
// 2 = high-key right, 3 = backlit rim
vec3 L;
if (uLightMode == 3) {
L = safeNorm(vec3(-0.35, 0.65, -0.75));
} else if (uLightMode == 2) {
L = safeNorm(vec3(0.65, 0.82, 0.45));
} else {
L = safeNorm(vec3(-0.62, 0.85, 0.48));
}
// Raymarch scene (64 steps, single mapScene call per step — reuses h.x for crystal silhouette)
float t = 0.0;
float tMax = 22.0;
float matID = 0.0;
bool hit = false;
float minCrysRatio = 1e5;
float minCrysT = 1e5;
bool passedCrystal = false;
for (int i = 0; i < 64; i++) {
vec3 p = ro + rd * t;
vec2 h = mapScene(p);
// Reuse crystal distance from mapScene when crystal is nearest (zero extra evals)
if ((h.y == MAT_SPIKE || h.y == MAT_SHARD) && h.x < 0.16 && t > 0.2) {
float ratio = h.x / max(t, 0.5);
if (ratio < minCrysRatio) {
minCrysRatio = ratio;
minCrysT = t;
}
if (h.x < 0.05) passedCrystal = true;
}
if (h.x < 0.0028) {
hit = true;
matID = h.y;
break;
}
t += clamp(h.x, 0.012, 0.72);
if (t > tMax) break;
}
// Background sky above arena parapet (cool stylized glacial mist, zero clip & zero black)
float skyGrad = clamp(rd.y * 2.2 + 0.25, 0.0, 1.0);
vec3 col = mix(vec3(0.14, 0.18, 0.24), vec3(0.28, 0.36, 0.46), skyGrad);
if (uLightMode != 1) {
float horizonGlow = exp(-abs(rd.y + 0.08) * 14.0);
col += COL_CORE_CYAN * horizonGlow * 0.12;
}
float sceneT = hit ? t : tMax;
if (hit) {
vec3 p = ro + rd * t;
vec3 N = calcNormal(p);
vec3 V = -rd;
float sh = (matID == MAT_ABYSS) ? 1.0 : calcShadow(p + N * 0.015, L, 6.0);
if (matID == MAT_FLOOR || matID == MAT_RIM) {
col = shadeFloor(p, N, L, sh, matID);
} else if (matID == MAT_SLAB) {
col = shadeSlab(p, N, V, L, sh);
} else if (matID == MAT_ABYSS) {
col = shadeAbyss(p);
} else {
col = shadeCrystal(p, N, V, L, sh, matID);
}
// Apply crisp external black-ink silhouette outline when ray grazed a crystal in front
if (passedCrystal && ((matID != MAT_SPIKE && matID != MAT_SHARD) || t > minCrysT + 0.18)) {
float outlineMask = 1.0 - smoothstep(0.0045, 0.0078, minCrysRatio);
col = mix(col, COL_INK, outlineMask * 0.96);
}
} else if (passedCrystal) {
// Crystal silhouette against sky
float outlineMask = 1.0 - smoothstep(0.0045, 0.0078, minCrysRatio);
col = mix(col, COL_INK, outlineMask * 0.96);
}
// Composite jagged comic starburst flash core & 4-point sparkles (muted in uLightMode == 1)
if (uLightMode != 1) {
float tStar;
vec4 star = evalStarburst(ro, rd, camRight, camUp, camFwd, tStar);
if (star.a > 0.001) {
float depthFade = smoothstep(-0.35, 0.28, sceneT - tStar);
if (hit && matID == MAT_ABYSS) depthFade = 1.0;
col = mix(col, star.rgb, star.a * depthFade);
}
vec3 sparks = evalSparkles(ro, rd, camRight, camUp, sceneT);
col += sparks;
}
// Subtle comic radial vignette (preserves dark floor > black threshold)
float vig = 1.0 - 0.14 * dot(uv, uv);
col *= clamp(vig, 0.82, 1.0);
// Gentle soft-shoulder tonemap to prevent clipping (<1% clip) & avoid NaN
col = max(col, vec3(0.0));
col = col / (1.0 + col * 0.16);
col = clamp(col, vec3(0.025, 0.032, 0.048), vec3(0.975));
// Pure neutral grayscale output for uLightMode == 1
if (uLightMode == 1) {
float lum = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(lum);
}
fragColor = vec4(col, 1.0);
}
`;
export function createFrostTealIceNovaSpikesMaterial(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 | frost-teal-ice-nova-spikes |
|---|---|
| Category | Game VFX Shaders · Stylized Cel VFX |
| Upstream study | vfx_stylized/lib/05_frost_teal_ice_nova_spikes.glsl (commit f5bfb61) |
| Animation cycle | Continuous procedural uTime |
| Declared uniforms | uResolution, uTime, uOpen, uLightMode, uCamMode |
| Source size | 787 lines · 28.9 KB standalone GLSL ES 3.00 |
| PNG baker outputs | 512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key) |
| Companion pixel VFX | Free MIT ice sprite sheets |
| License | MIT License + CC0 / MIT Helpers |
GGX microfacet specular (Trowbridge–Reitz 1975; Walter et al. 2007); Schlick Fresnel reflectance (1994); Beer–Lambert volumetric absorption/attenuation
David Hoskins, hash
3s LoopTectonic rock slabs heaving upward over glowing amber fault cracks and dust plumes.
3s LoopBlooming cherry-blossom sanctuary ring with spiraling pink petals and warm restorative shimmer.
3s LoopCyberpunk magenta-cyan plasma detonation with quantized shock rings and electric arcs.
3s LoopWhip-fast cel-shaded jade wind vortex with crisp white slipstream bands and swirling leaves.
3s LoopNinjutsu indigo smoke bomb cloud with cel-stepped billowing lobes and glowing ember eyes.
AnimatedVolumetric blackbody fireball mushrooming into self-shadowed soot lobes with Beer–Lambert absorption.