AnimatedRadial ring of faceted glacial crystal spikes erupting through freezing ground mist.
violet-void-blackhole-pull.glsl · 704 lines · GLSL ES 3.00 · MIT
#version 300 es
// Violet Void Blackhole Pull (violet-void-blackhole-pull.glsl)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_stylized/lib/04_violet_void_blackhole_pull.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;
// ============================================================================
// 04_violet_void_blackhole_pull.glsl
// Stylized cel-shaded 3D deep-violet & electric-magenta void blackhole vortex
// levitating above a dark matte ink-grouted charcoal tiled arena floor.
// - Pitch-dark spherical event horizon with glowing magenta photon ring
// - Crisp ink-outlined magenta-violet swirling energy tendrils & arcs
// - 4 bold razor-sharp white-edged curved comic lensing crescents
// - Orbiting ink-outlined faceted purple & crimson crystal shards
// - uTime: seamless 3.0s loop spiraling crescents & shards inward
// - uOpen: 0..1 widens gravity pull radius, crescent sweep & shard surge
// ============================================================================
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
// Palette
const vec3 COL_FLOOR_BASE = vec3(0.08, 0.09, 0.12);
const vec3 COL_INK = vec3(0.018, 0.012, 0.030);
const vec3 COL_VOID_CORE = vec3(0.016, 0.008, 0.026);
const vec3 COL_DEEP_VIOLET = vec3(0.24, 0.06, 0.50);
const vec3 COL_MID_VIOLET = vec3(0.52, 0.14, 0.84);
const vec3 COL_MAGENTA = vec3(0.92, 0.28, 0.96);
const vec3 COL_LAVENDER = vec3(0.98, 0.68, 1.00);
const vec3 COL_CRESCENT = vec3(0.96, 0.95, 0.99);
const vec3 COL_CRIMSON_DK = vec3(0.46, 0.05, 0.11);
const vec3 COL_CRIMSON_MID = vec3(0.88, 0.14, 0.22);
const vec3 COL_CRIMSON_HI = vec3(1.00, 0.46, 0.50);
// Material IDs
const int MAT_NONE = 0;
const int MAT_HORIZON = 1;
const int MAT_CRESCENT = 2;
const int MAT_CRYSTAL_PURPLE = 3;
const int MAT_CRYSTAL_CRIMSON= 4;
const float VORTEX_Y = 1.18;
float sat(float x) { return clamp(x, 0.0, 1.0); }
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
vec3 safeNorm(vec3 v) {
float l = length(v);
return l > 1e-5 ? v / l : vec3(0.0, 1.0, 0.0);
}
float hash11(float p) {
p = fract(p * 0.1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
float hash21(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}
float fbm2(vec2 p) {
float v = 0.0;
float a = 0.55;
for (int i = 0; i < 3; i++) {
v += a * vnoise2(p);
p = p * 2.07 + vec2(13.1, 7.7);
a *= 0.48;
}
return v;
}
// 3-band quantized cel ramp with crisp comic transitions
float cel3(float x) {
float b1 = smoothstep(0.22, 0.26, x);
float b2 = smoothstep(0.60, 0.64, x);
return 0.18 + 0.44 * b1 + 0.38 * b2;
}
// Seamless 3.0-second loop phase in [0, 1)
float loopPhase() {
return fract(uTime / 3.0);
}
// Effective pull factor from uOpen (0..1)
float pullOpen() {
return clamp(uOpen, 0.0, 1.0);
}
// ----------------------------------------------------------------------------
// 3D Faceted Crystal Shard SDF (elongated hexagonal/tetragonal bipyramid)
// Uses plane intersections so every face has crisp flat unit-weight normals.
// ----------------------------------------------------------------------------
float sdCrystalLong(vec3 p, vec2 size) {
// size.x = radius, size.y = half-length along Y
// Slight asymmetry: sharper bottom tip, chunkier faceted top
vec3 q = p;
float ay = q.y;
float rScale = ay > 0.0
? max(0.001, 1.0 - ay / (size.y * 1.15))
: max(0.001, 1.0 + ay / (size.y * 0.85));
// 5-sided faceted cross-section using folded planes
vec2 xz = q.xz;
float d1 = abs(xz.x) * 0.92 + abs(xz.y) * 0.42;
float d2 = abs(xz.x) * 0.35 + abs(xz.y) * 0.94;
float d3 = dot(abs(xz), vec2(0.7071, 0.7071));
float hexR = max(max(d1, d2), d3 * 0.96);
float sideD = (hexR - size.x * rScale) * 0.78;
float capTop = q.y - size.y * 1.15;
float capBot = -q.y - size.y * 0.85;
return max(sideD, max(capTop, capBot));
}
// Faceted diamond / rhomboid crimson shard SDF
float sdDiamondShard(vec3 p, vec3 rad) {
// Crisp octahedral diamond with flattened depth
vec3 q = abs(p) / max(rad, vec3(0.001));
float d = (q.x + q.y + q.z - 1.0) * min(rad.x, min(rad.y, rad.z)) * 0.58;
return d;
}
// ----------------------------------------------------------------------------
// 4 Bold Razor-Sharp Curved Comic Lensing Crescents SDF
// Arranged in a 4-fold spiraling pinwheel around the black hole.
// ----------------------------------------------------------------------------
float sdCrescents(vec3 p, float phase, float openAmt) {
vec3 q = p - vec3(0.0, VORTEX_Y, 0.0);
// Subtle 3D tilt of the lensing plane so crescents feel dynamic in 3D
q.yz = rot2(0.10) * q.yz;
// Seamless 3-second spiral rotation (1/4 turn = exact 4-fold symmetry loop!)
float spin = -phase * (TAU * 0.25);
q.xz = rot2(spin) * q.xz;
float r = length(q.xz);
float a = atan(q.z, q.x); // -PI..PI
// 4-fold angular sector
float sector = TAU * 0.25;
float aMod = mod(a + PI + sector * 0.5, sector) - sector * 0.5;
// Evaluate across neighboring sectors (k = -1, 0, 1) because each crescent
// sweeps ~125 degrees (> 90 deg sector) for bold overlapping spiral drama.
float dBest = 1e5;
float scaleR = 0.88 + 0.34 * openAmt;
// Breathing inward pulse synced to 3s loop
float pulse = 1.0 - 0.06 * sin(phase * TAU);
for (int k = -1; k <= 1; k++) {
float ang = aMod + float(k) * sector;
// Parametric crescent arc: ang in [-1.15, 1.15]
float u = clamp(ang / 1.15, -1.0, 1.0);
// Logarithmic-style spiral radius: sweeps from inner tip to wide outer belly to sharp tail
float rMid = (0.76 + 0.52 * smoothstep(-1.0, 0.75, u) + 0.14 * (1.0 - u * u)) * scaleR * pulse;
// Asymmetric razor-sharp crescent width: thick in the middle, zero at both tips
float taper = max(0.0, 1.0 - u * u);
float halfW = 0.215 * pow(taper, 0.78) * (0.85 + 0.30 * (0.5 + 0.5 * u)) * scaleR;
// Slight inward curve offset at tips
float dr = abs(r - rMid) - halfW;
// End-cap distance along arc when outside [-1.15, 1.15]
float dAng = max(0.0, abs(ang) - 1.15) * max(r, 0.4);
float d2D = max(dr, dAng);
// Gentle 3D sculptural wave along the crescent so it catches 3D depth
float yOff = 0.09 * sin(u * 2.2) * scaleR;
float halfThick = (0.018 + 0.024 * taper);
float dy = abs(q.y - yOff) - halfThick;
// Combine 2D crescent ribbon with 3D bevel thickness
vec2 w = vec2(max(d2D, 0.0), max(dy, 0.0));
float d3D = min(max(d2D, dy), 0.0) + length(w);
// Scale down slightly for Lipschitz safety due to polar curvature
dBest = min(dBest, d3D * 0.72);
}
return dBest;
}
// ----------------------------------------------------------------------------
// Orbiting Faceted Purple & Crimson Crystal Shards SDF
// ----------------------------------------------------------------------------
struct Hit {
float d;
int mat;
float id;
};
Hit opMin(Hit a, Hit b) {
if (a.d < b.d) {
return a;
}
return b;
}
Hit mapScene(vec3 p, float phase, float openAmt) {
Hit res;
res.d = 1e5;
res.mat = MAT_NONE;
res.id = 0.0;
// 1. Pitch-dark spherical event horizon
float horizonR = 0.40 + 0.04 * openAmt + 0.012 * sin(phase * TAU);
float dHorizon = length(p - vec3(0.0, VORTEX_Y, 0.0)) - horizonR;
res = opMin(res, Hit(dHorizon, MAT_HORIZON, 0.0));
// 2. 4 Bold curved comic lensing crescents
float dCresc = sdCrescents(p, phase, openAmt);
res = opMin(res, Hit(dCresc, MAT_CRESCENT, 1.0));
// 3. Orbiting hero & medium faceted PURPLE crystal shards (8 shards)
// Seamless 3s inward-spiraling orbit using cyclic radial pull
float spread = 0.86 + 0.38 * openAmt;
for (int i = 0; i < 8; i++) {
float fi = float(i);
// Hero outer shards (0..3) and inner vortex shards (4..7)
bool isHero = (i < 4);
float baseAng = fi * (TAU / 4.0) + (isHero ? 0.55 : 0.12);
// Seamless orbit: 1 full turn or 1/2 turn per 3s? 1/4 turn with 4-fold symmetry is seamless,
// or 1 full turn for individual shards is always 100% seamless!
// Let's use 1 full inward-spiraling wave + 0.25*TAU base rotation synced cleanly:
float cyc = fract(phase + fi * 0.25);
// Smooth radial oscillation so shards surge inward toward the void
float pullWave = 0.5 - 0.5 * cos(cyc * TAU);
float orbitAng = baseAng - phase * TAU * (isHero ? 0.25 : 0.5) - pullWave * 0.35;
float rBase = isHero ? (2.15 - 0.30 * pullWave) : (1.12 - 0.22 * pullWave);
float rad = rBase * spread;
float hOff = isHero
? (0.28 * sin(fi * 1.9 + phase * TAU) + 0.25)
: (0.14 * cos(fi * 2.3 - phase * TAU) + 0.05);
vec3 cPos = vec3(cos(orbitAng) * rad, VORTEX_Y + hOff, sin(orbitAng) * rad);
vec3 q = p - cPos;
// Point crystal tip inward toward the black hole center!
vec3 toCenter = safeNorm(vec3(0.0, VORTEX_Y, 0.0) - cPos);
vec3 upRef = vec3(0.0, 1.0, 0.0);
vec3 rightV = safeNorm(cross(upRef, toCenter));
vec3 upV = cross(toCenter, rightV);
// Transform p into crystal local frame (Y axis points toward center)
vec3 lp = vec3(dot(q, rightV), dot(q, toCenter), dot(q, upV));
// Spin crystal gently around its own long axis (1 full turn per 3s loop)
lp.xz = rot2(phase * TAU + fi * 1.1) * lp.xz;
vec2 cSize = isHero ? vec2(0.185, 0.48) : vec2(0.088, 0.22);
float dCry = sdCrystalLong(lp, cSize);
res = opMin(res, Hit(dCry, MAT_CRYSTAL_PURPLE, 10.0 + fi));
}
// 4. Orbiting CRIMSON faceted diamond shards (6 shards)
for (int i = 0; i < 6; i++) {
float fi = float(i);
float baseAng = fi * (TAU / 6.0) + 0.38;
float cyc = fract(phase + fi / 6.0);
float pullWave = 0.5 - 0.5 * cos(cyc * TAU);
float orbitAng = baseAng - phase * TAU * (1.0 / 3.0);
float rad = (1.68 + 0.55 * mod(fi, 2.0) - 0.24 * pullWave) * spread;
float hOff = 0.22 * sin(fi * 2.1 + phase * TAU) + 0.12;
vec3 cPos = vec3(cos(orbitAng) * rad, VORTEX_Y + hOff, sin(orbitAng) * rad);
vec3 q = p - cPos;
q.xz = rot2(orbitAng + phase * TAU) * q.xz;
q.xy = rot2(0.55 + fi * 0.4) * q.xy;
float sc = (i == 0 || i == 3) ? 1.18 : 0.72;
vec3 dRad = vec3(0.15, 0.21, 0.085) * sc;
float dDia = sdDiamondShard(q, dRad);
res = opMin(res, Hit(dDia, MAT_CRYSTAL_CRIMSON, 30.0 + fi));
}
return res;
}
// Compute unit-weight surface normal via tetrahedron finite differences
vec3 calcNormal(vec3 p, float phase, float openAmt) {
const float h = 0.0018;
const vec2 k = vec2(1.0, -1.0);
vec3 n = k.xyy * mapScene(p + k.xyy * h, phase, openAmt).d
+ k.yyx * mapScene(p + k.yyx * h, phase, openAmt).d
+ k.yxy * mapScene(p + k.yxy * h, phase, openAmt).d
+ k.xxx * mapScene(p + k.xxx * h, phase, openAmt).d;
return safeNorm(n);
}
// ----------------------------------------------------------------------------
// Stylized Swirling Void Vortex Disk (Analytic 3D Funnel Layer)
// Crisp ink-outlined magenta-violet spiral tendrils + jagged lightning arcs.
// ----------------------------------------------------------------------------
vec4 evalVortexLayer(vec3 p, float phase, float openAmt) {
vec3 q = p - vec3(0.0, VORTEX_Y, 0.0);
float r = length(q.xz);
float a = atan(q.z, q.x);
float scaleR = 0.88 + 0.34 * openAmt;
float rn = r / max(scaleR, 0.1);
// Outer boundary of the vortex disk
if (rn > 2.25 || rn < 0.32) {
return vec4(0.0);
}
// Logarithmic spiral coordinates swirling inward seamlessly in 3s loop
float spin = phase * TAU; // 1 full turn per 3s
float logR = log(max(rn, 0.05));
// Primary bold 6-arm spiral tendrils
float sw1 = a + 3.4 * logR + spin * 0.5;
float arm1 = sin(sw1 * 4.0) * 0.5 + 0.5;
// Secondary finer jagged tongues
float sw2 = a + 5.2 * logR + spin;
float arm2 = sin(sw2 * 7.0 + 1.4) * 0.5 + 0.5;
// Comic warped noise for organic hand-inked tendril tips
vec2 nUV = vec2(cos(a + logR * 2.2), sin(a + logR * 2.2)) * (1.8 + rn * 1.4);
float nPer = fbm2(nUV + vec2(cos(spin), sin(spin)) * 0.35);
// Radial envelope with jagged tendril reach
float outerReach = 1.42 + 0.34 * arm1 + 0.18 * arm2 + 0.22 * (nPer - 0.5);
float edgeDist = outerReach - rn;
// Hard comic alpha mask + bold black-ink outer contour
float alpha = smoothstep(-0.02, 0.025, edgeDist);
if (alpha < 0.001) return vec4(0.0);
// Ink outline around outer tendril tips & between spiral layers
float outerInk = 1.0 - smoothstep(0.0, 0.085, edgeDist);
// Swirling energy value for 3-band cel shading
float innerHeat = exp(-max(0.0, rn - 0.42) * 3.1);
float swirlVal = innerHeat * 1.15
+ (0.52 * arm1 + 0.30 * arm2) * smoothstep(1.65, 0.48, rn)
+ 0.18 * (nPer - 0.5);
// Quantized 3-band comic palette (ink-black void -> deep violet -> mid violet -> electric lavender)
vec3 col = COL_INK;
float band1 = smoothstep(0.24, 0.28, swirlVal);
float band2 = smoothstep(0.54, 0.58, swirlVal);
float band3 = smoothstep(0.84, 0.89, swirlVal);
col = mix(col, COL_DEEP_VIOLET, band1);
col = mix(col, COL_MID_VIOLET, band2);
col = mix(col, COL_LAVENDER, band3);
// Crisp black ink separator streaks inside the violet swirl
float inkCrease = smoothstep(0.18, 0.23, abs(fract(sw1 * 4.0 / TAU) - 0.5))
* smoothstep(0.50, 0.95, rn);
col = mix(col, COL_INK, (1.0 - inkCrease) * 0.65 * (1.0 - band3));
// Inner glowing electric-magenta photon swirl tightly hugging the event horizon
float photonRing = exp(-pow((rn - 0.48) / 0.12, 2.0));
float ringStreak = 0.65 + 0.35 * sin(a * 6.0 + logR * 12.0 + spin);
col = mix(col, mix(COL_MAGENTA, COL_LAVENDER, 0.65), sat(photonRing * ringStreak));
// 4 Jagged electric-magenta comic lightning arcs crackling outward along the spiral
float arcTotal = 0.0;
for (int i = 0; i < 4; i++) {
float fi = float(i);
float arcAngle = a + 2.6 * logR + fi * (TAU * 0.25) + spin * 0.5;
// High-frequency zigzag displacement along radius
float zig = (vnoise2(vec2(rn * 9.5 + fi * 3.1, cos(spin) * 0.4 + 1.7)) - 0.5) * 0.42;
float dArc = abs(sin((arcAngle + zig) * 0.5));
float boltWidth = 0.016 + 0.012 * (1.0 - sat((rn - 0.45) / 1.1));
float bolt = (1.0 - smoothstep(boltWidth * 0.35, boltWidth, dArc))
* smoothstep(0.42, 0.52, rn)
* smoothstep(1.45, 0.68, rn);
arcTotal = max(arcTotal, bolt);
}
col = mix(col, COL_LAVENDER, sat(arcTotal));
// Magenta electric aura right around the lightning bolts
col += COL_MAGENTA * arcTotal * 0.28;
// Apply bold black-ink contour at outer tendril boundary
col = mix(col, COL_INK, outerInk * 0.92);
return vec4(col, alpha);
}
// ----------------------------------------------------------------------------
// Dark Matte Ink-Grouted Charcoal Tiled Arena Floor (y = 0)
// Base color: vec3(0.08, 0.09, 0.12)
// ----------------------------------------------------------------------------
vec3 renderFloor(vec3 p, vec3 rd, float phase, float openAmt, vec3 lightDir) {
float r = length(p.xz);
float a = atan(p.z, p.x);
// Architectural slab grid: large rectangular tiles + radial arena rings
vec2 tileUV = p.xz * 0.58;
vec2 tileF = abs(fract(tileUV + 0.5) - 0.5);
float dGrid = min(tileF.x, tileF.y);
// Radial arena border ring near outer perimeter (echoing reference top edge)
float dRing1 = abs(r - 3.95);
float dRing2 = abs(r - 4.35);
// Crisp anti-aliased ink grout seams
float fw = max(0.008, length(p.xz) * 0.0045);
float grout = 1.0 - smoothstep(0.016, 0.016 + fw, dGrid);
float ringSeam = 1.0 - smoothstep(0.03, 0.03 + fw * 2.0, min(dRing1, dRing2));
grout = max(grout, ringSeam);
// Subtle tile-to-tile tonal variation + matte concrete grunge speckles
vec2 tileID = floor(tileUV + 0.5);
float tileVar = (hash21(tileID) - 0.5) * 0.018;
float grunge = (fbm2(p.xz * 3.8) - 0.5) * 0.022;
float fineSpeck = (vnoise2(p.xz * 19.0) - 0.5) * 0.010;
vec3 baseCol = COL_FLOOR_BASE + vec3(tileVar + grunge + fineSpeck);
// Crimson arena accent band between r=4.00 and r=4.30 (like top of ref 04.png)
float crimsonBand = smoothstep(3.98, 4.02, r) * (1.0 - smoothstep(4.26, 4.30, r));
// Segmented gaps in the crimson trim
float trimSeg = smoothstep(0.08, 0.12, abs(fract(a * 6.0 / TAU) - 0.5));
baseCol = mix(baseCol, vec3(0.42, 0.09, 0.14), crimsonBand * trimSeg * 0.85);
// Stylized cel-shaded floor illumination from vortex above
float spread = 0.88 + 0.34 * openAmt;
float vortexGlow = exp(-r * r / (3.8 * spread * spread));
float glowCel = smoothstep(0.18, 0.24, vortexGlow) * 0.55
+ smoothstep(0.55, 0.62, vortexGlow) * 0.45;
vec3 lightTint = (uLightMode == 1) ? vec3(0.42, 0.20, 0.78)
: (uLightMode == 2) ? vec3(0.75, 0.18, 0.62)
: vec3(0.52, 0.16, 0.82);
vec3 col = baseCol * (0.88 + 0.25 * sat(lightDir.y))
+ lightTint * glowCel * 0.14;
// Crisp stylized contact shadow cast directly beneath the hovering vortex
float shadowR = 1.45 * spread;
float castShadow = 1.0 - smoothstep(shadowR * 0.55, shadowR * 1.15, r);
col *= (1.0 - 0.42 * castShadow);
// Subtle dark-ink grout lines (kept above pure black so <2% black metric is safe)
col = mix(col, vec3(0.022, 0.020, 0.032), grout * 0.88);
// Gentle distance fade into dark arena backdrop (stays slightly above pure black)
float fog = 1.0 - exp(-r * r * 0.018);
col = mix(col, vec3(0.032, 0.030, 0.045), fog * 0.72);
return col;
}
// ----------------------------------------------------------------------------
// Shading for 3D SDF Geometry (Horizon, Crescents, Faceted Shards)
// ----------------------------------------------------------------------------
vec3 shadeObject(vec3 p, vec3 N, vec3 V, Hit h, vec3 lightDir, float phase, float openAmt) {
float ndl = sat(dot(N, lightDir) * 0.5 + 0.5);
float ndv = sat(dot(N, V));
float fresnel = pow(1.0 - ndv, 2.4);
// Bold black-ink Fresnel contour
float inkRim = smoothstep(0.56, 0.74, 1.0 - ndv);
if (h.mat == MAT_HORIZON) {
// Pitch-dark spherical event horizon with luminous electric-magenta rim
vec3 col = COL_VOID_CORE;
float photonRim = smoothstep(0.52, 0.86, 1.0 - ndv);
float innerGlow = pow(1.0 - ndv, 3.5);
col = mix(col, COL_MID_VIOLET, photonRim * 0.55);
col = mix(col, COL_LAVENDER, innerGlow * 0.95);
return col;
}
if (h.mat == MAT_CRESCENT) {
// Bold razor-sharp white comic lensing crescent with crisp black-ink contour
// Subtle cool-lavender cel shadow on back-facing edge so it reads as 3D
float cel = cel3(ndl);
vec3 col = mix(vec3(0.84, 0.78, 0.94), COL_CRESCENT, smoothstep(0.35, 0.45, cel));
// Subtle magenta rim glint right inside the ink contour
col = mix(col, COL_LAVENDER, smoothstep(0.45, 0.65, 1.0 - ndv) * 0.45);
// Bold black-ink Fresnel outline
col = mix(col, COL_INK, smoothstep(0.62, 0.78, 1.0 - ndv));
return col;
}
if (h.mat == MAT_CRYSTAL_PURPLE) {
// 3-band quantized cel-shaded faceted purple crystal
float cel = cel3(ndl);
vec3 col = mix(COL_DEEP_VIOLET, COL_MID_VIOLET, smoothstep(0.25, 0.35, cel));
col = mix(col, COL_LAVENDER, smoothstep(0.72, 0.82, cel));
// Crisp stylized specular highlight facet
vec3 H = safeNorm(lightDir + V);
float spec = pow(sat(dot(N, H)), 18.0);
col = mix(col, vec3(0.98, 0.88, 1.00), smoothstep(0.35, 0.45, spec) * 0.75);
// Energy bounce from the blackhole center
vec3 toVoid = safeNorm(vec3(0.0, VORTEX_Y, 0.0) - p);
float voidBounce = sat(dot(N, toVoid));
col += COL_MAGENTA * smoothstep(0.35, 0.65, voidBounce) * 0.26;
// Bold black-ink Fresnel silhouette contour
col = mix(col, COL_INK, inkRim * 0.95);
return col;
}
if (h.mat == MAT_CRYSTAL_CRIMSON) {
// 3-band quantized cel-shaded faceted crimson diamond shard
float cel = cel3(ndl);
vec3 col = mix(COL_CRIMSON_DK, COL_CRIMSON_MID, smoothstep(0.25, 0.35, cel));
col = mix(col, COL_CRIMSON_HI, smoothstep(0.70, 0.80, cel));
vec3 H = safeNorm(lightDir + V);
float spec = pow(sat(dot(N, H)), 14.0);
col = mix(col, vec3(1.00, 0.76, 0.78), smoothstep(0.40, 0.50, spec) * 0.65);
// Bold black-ink Fresnel silhouette contour
col = mix(col, COL_INK, inkRim * 0.95);
return col;
}
return COL_FLOOR_BASE;
}
// ----------------------------------------------------------------------------
// Camera Setup (3 modes)
// ----------------------------------------------------------------------------
void getCamera(int camMode, out vec3 ro, out vec3 ta, out float fov) {
if (camMode == 1) {
// Dramatic low 3/4 view emphasizing levitation height above tiled floor
ro = vec3(2.55, 2.15, 3.45);
ta = vec3(0.0, 1.12, 0.0);
fov = 1.65;
} else if (camMode == 2) {
// Dynamic close-up hero angle
ro = vec3(-1.35, 3.10, 2.05);
ta = vec3(0.0, 1.18, 0.0);
fov = 1.55;
} else {
// Default hero high-angle 3/4 view matching reference 04.png
ro = vec3(0.0, 4.35, 2.05);
ta = vec3(0.0, 1.12, 0.0);
fov = 1.52;
}
}
vec3 getLightDir(int lightMode) {
if (lightMode == 1) {
return safeNorm(vec3(-0.65, 0.80, 0.45));
} else if (lightMode == 2) {
return safeNorm(vec3(0.35, 0.65, -0.70));
}
return safeNorm(vec3(0.55, 0.85, 0.42));
}
// ----------------------------------------------------------------------------
// Main
// ----------------------------------------------------------------------------
void main() {
vec2 res = max(uResolution, vec2(1.0));
vec2 uv = (gl_FragCoord.xy - 0.5 * res) / min(res.x, res.y);
float phase = loopPhase();
float openAmt = pullOpen();
vec3 ro, ta;
float fov;
getCamera(uCamMode, ro, ta, fov);
vec3 fwd = safeNorm(ta - ro);
vec3 rightV = safeNorm(cross(fwd, vec3(0.0, 1.0, 0.0)));
vec3 upV = cross(rightV, fwd);
vec3 rd = safeNorm(fwd * fov + rightV * uv.x + upV * uv.y);
vec3 lightDir = getLightDir(uLightMode);
// 1. Ray-floor intersection (y = 0)
float tFloor = (rd.y < -1e-4) ? (-ro.y / rd.y) : 40.0;
vec3 bgCol = vec3(0.032, 0.030, 0.048);
if (rd.y < -1e-4 && tFloor < 35.0) {
bgCol = renderFloor(ro + rd * tFloor, rd, phase, openAmt, lightDir);
}
// 2. Ray-vortex tilted plane intersection (y = VORTEX_Y, slight tilt 0.10 rad)
vec3 vNorm = safeNorm(vec3(0.0, cos(0.10), -sin(0.10)));
float denom = dot(rd, vNorm);
float tVortex = 1e5;
vec4 vortexCol = vec4(0.0);
if (abs(denom) > 1e-4) {
float tv = dot(vec3(0.0, VORTEX_Y, 0.0) - ro, vNorm) / denom;
if (tv > 0.1 && tv < tFloor) {
tVortex = tv;
vortexCol = evalVortexLayer(ro + rd * tv, phase, openAmt);
}
}
// 3. Raymarch 3D SDF scene (event horizon, 4 curved crescents, faceted crystals)
float t = 0.0;
float tMax = min(tFloor, 18.0);
Hit hit = Hit(1e5, MAT_NONE, 0.0);
// Track closest approach to crescents & crystals for crisp comic ink outlines!
float minOutlineD = 1e5;
float minOutlineT = 1e5;
for (int i = 0; i < 96; i++) {
vec3 p = ro + rd * t;
Hit h = mapScene(p, phase, openAmt);
if (h.mat != MAT_HORIZON && h.d < minOutlineD) {
minOutlineD = h.d;
minOutlineT = t;
}
if (h.d < 0.0022) {
hit = h;
break;
}
t += max(h.d * 0.85, 0.006);
if (t > tMax) break;
}
// 4. Composite in proper 3D depth order: Floor -> Vortex -> SDF Objects + Ink Contours
vec3 col = bgCol;
// Composite vortex behind SDF hit (or when nothing hit)
bool vortexInFront = (vortexCol.a > 0.001) && (tVortex < t && hit.mat != MAT_NONE);
if (vortexCol.a > 0.001 && !vortexInFront) {
col = mix(col, vortexCol.rgb, vortexCol.a);
}
// Crisp proximity ink outline around crescents & crystals when ray grazes their silhouette
if (hit.mat == MAT_NONE && minOutlineD < 0.036) {
float inkStroke = 1.0 - smoothstep(0.010, 0.032, minOutlineD);
if (minOutlineT < tFloor) {
col = mix(col, COL_INK, inkStroke * 0.94);
}
}
// Shade hit SDF object
if (hit.mat != MAT_NONE) {
vec3 p = ro + rd * t;
vec3 N = calcNormal(p, phase, openAmt);
vec3 V = -rd;
vec3 objCol = shadeObject(p, N, V, hit, lightDir, phase, openAmt);
col = objCol;
}
// If vortex plane is closer than the hit object (e.g. tendrils in front of back crystals)
if (vortexInFront) {
// Keep the pitch-dark event horizon & bold white crescents razor-sharp on top
float vAlpha = (hit.mat == MAT_HORIZON || hit.mat == MAT_CRESCENT)
? vortexCol.a * 0.08
: vortexCol.a;
col = mix(col, vortexCol.rgb, vAlpha);
}
// 5. Subtle electric-magenta gravitational aura around the black hole center
vec3 toCenter = vec3(0.0, VORTEX_Y, 0.0) - ro;
float tClosest = max(0.0, dot(toCenter, rd));
float dCenter = length(ro + rd * tClosest - vec3(0.0, VORTEX_Y, 0.0));
float auraR = 0.72 + 0.18 * openAmt;
float halo = exp(-pow(max(0.0, dCenter - 0.36) / auraR, 2.0));
if (hit.mat != MAT_HORIZON) {
col += vec3(0.46, 0.12, 0.72) * halo * 0.16;
}
// 6. Stylized comic display shoulder (preserves rich dark charcoal floor vec3(0.08,0.09,0.12),
// crisp white crescents <1% clip, and deep ink above pure-black <2% black)
col = max(col, vec3(0.0));
col = col / (vec3(1.0) + col * 0.10) * 1.04;
col = clamp(col, vec3(0.018, 0.014, 0.028), vec3(0.975));
// Neutral grayscale lighting inspection mode (uLightMode == 1)
if (uLightMode == 1) {
float lum = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(clamp(lum, 0.018, 0.96));
}
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;
// Violet Void Blackhole Pull — Godot 4 (canvas_item) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/vfx_stylized/lib/04_violet_void_blackhole_pull.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;
// ============================================================================
// 04_violet_void_blackhole_pull.glsl
// Stylized cel-shaded 3D deep-violet & electric-magenta void blackhole vortex
// levitating above a dark matte ink-grouted charcoal tiled arena floor.
// - Pitch-dark spherical event horizon with glowing magenta photon ring
// - Crisp ink-outlined magenta-violet swirling energy tendrils & arcs
// - 4 bold razor-sharp white-edged curved comic lensing crescents
// - Orbiting ink-outlined faceted purple & crimson crystal shards
// - uTime: seamless 3.0s loop spiraling crescents & shards inward
// - uOpen: 0..1 widens gravity pull radius, crescent sweep & shard surge
// ============================================================================
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
// Palette
const vec3 COL_FLOOR_BASE = vec3(0.08, 0.09, 0.12);
const vec3 COL_INK = vec3(0.018, 0.012, 0.030);
const vec3 COL_VOID_CORE = vec3(0.016, 0.008, 0.026);
const vec3 COL_DEEP_VIOLET = vec3(0.24, 0.06, 0.50);
const vec3 COL_MID_VIOLET = vec3(0.52, 0.14, 0.84);
const vec3 COL_MAGENTA = vec3(0.92, 0.28, 0.96);
const vec3 COL_LAVENDER = vec3(0.98, 0.68, 1.00);
const vec3 COL_CRESCENT = vec3(0.96, 0.95, 0.99);
const vec3 COL_CRIMSON_DK = vec3(0.46, 0.05, 0.11);
const vec3 COL_CRIMSON_MID = vec3(0.88, 0.14, 0.22);
const vec3 COL_CRIMSON_HI = vec3(1.00, 0.46, 0.50);
// Material IDs
const int MAT_NONE = 0;
const int MAT_HORIZON = 1;
const int MAT_CRESCENT = 2;
const int MAT_CRYSTAL_PURPLE = 3;
const int MAT_CRYSTAL_CRIMSON= 4;
const float VORTEX_Y = 1.18;
float sat(float x) { return clamp(x, 0.0, 1.0); }
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
vec3 safeNorm(vec3 v) {
float l = length(v);
return l > 1e-5 ? v / l : vec3(0.0, 1.0, 0.0);
}
float hash11(float p) {
p = fract(p * 0.1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
float hash21(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}
float fbm2(vec2 p) {
float v = 0.0;
float a = 0.55;
for (int i = 0; i < 3; i++) {
v += a * vnoise2(p);
p = p * 2.07 + vec2(13.1, 7.7);
a *= 0.48;
}
return v;
}
// 3-band quantized cel ramp with crisp comic transitions
float cel3(float x) {
float b1 = smoothstep(0.22, 0.26, x);
float b2 = smoothstep(0.60, 0.64, x);
return 0.18 + 0.44 * b1 + 0.38 * b2;
}
// Seamless 3.0-second loop phase in [0, 1)
float loopPhase() {
return fract(uTime / 3.0);
}
// Effective pull factor from uOpen (0..1)
float pullOpen() {
return clamp(uOpen, 0.0, 1.0);
}
// ----------------------------------------------------------------------------
// 3D Faceted Crystal Shard SDF (elongated hexagonal/tetragonal bipyramid)
// Uses plane intersections so every face has crisp flat unit-weight normals.
// ----------------------------------------------------------------------------
float sdCrystalLong(vec3 p, vec2 size) {
// size.x = radius, size.y = half-length along Y
// Slight asymmetry: sharper bottom tip, chunkier faceted top
vec3 q = p;
float ay = q.y;
float rScale = ay > 0.0
? max(0.001, 1.0 - ay / (size.y * 1.15))
: max(0.001, 1.0 + ay / (size.y * 0.85));
// 5-sided faceted cross-section using folded planes
vec2 xz = q.xz;
float d1 = abs(xz.x) * 0.92 + abs(xz.y) * 0.42;
float d2 = abs(xz.x) * 0.35 + abs(xz.y) * 0.94;
float d3 = dot(abs(xz), vec2(0.7071, 0.7071));
float hexR = max(max(d1, d2), d3 * 0.96);
float sideD = (hexR - size.x * rScale) * 0.78;
float capTop = q.y - size.y * 1.15;
float capBot = -q.y - size.y * 0.85;
return max(sideD, max(capTop, capBot));
}
// Faceted diamond / rhomboid crimson shard SDF
float sdDiamondShard(vec3 p, vec3 rad) {
// Crisp octahedral diamond with flattened depth
vec3 q = abs(p) / max(rad, vec3(0.001));
float d = (q.x + q.y + q.z - 1.0) * min(rad.x, min(rad.y, rad.z)) * 0.58;
return d;
}
// ----------------------------------------------------------------------------
// 4 Bold Razor-Sharp Curved Comic Lensing Crescents SDF
// Arranged in a 4-fold spiraling pinwheel around the black hole.
// ----------------------------------------------------------------------------
float sdCrescents(vec3 p, float phase, float openAmt) {
vec3 q = p - vec3(0.0, VORTEX_Y, 0.0);
// Subtle 3D tilt of the lensing plane so crescents feel dynamic in 3D
q.yz = rot2(0.10) * q.yz;
// Seamless 3-second spiral rotation (1/4 turn = exact 4-fold symmetry loop!)
float spin = -phase * (TAU * 0.25);
q.xz = rot2(spin) * q.xz;
float r = length(q.xz);
float a = atan(q.z, q.x); // -PI..PI
// 4-fold angular sector
float sector = TAU * 0.25;
float aMod = mod(a + PI + sector * 0.5, sector) - sector * 0.5;
// Evaluate across neighboring sectors (k = -1, 0, 1) because each crescent
// sweeps ~125 degrees (> 90 deg sector) for bold overlapping spiral drama.
float dBest = 1e5;
float scaleR = 0.88 + 0.34 * openAmt;
// Breathing inward pulse synced to 3s loop
float pulse = 1.0 - 0.06 * sin(phase * TAU);
for (int k = -1; k <= 1; k++) {
float ang = aMod + float(k) * sector;
// Parametric crescent arc: ang in [-1.15, 1.15]
float u = clamp(ang / 1.15, -1.0, 1.0);
// Logarithmic-style spiral radius: sweeps from inner tip to wide outer belly to sharp tail
float rMid = (0.76 + 0.52 * smoothstep(-1.0, 0.75, u) + 0.14 * (1.0 - u * u)) * scaleR * pulse;
// Asymmetric razor-sharp crescent width: thick in the middle, zero at both tips
float taper = max(0.0, 1.0 - u * u);
float halfW = 0.215 * pow(taper, 0.78) * (0.85 + 0.30 * (0.5 + 0.5 * u)) * scaleR;
// Slight inward curve offset at tips
float dr = abs(r - rMid) - halfW;
// End-cap distance along arc when outside [-1.15, 1.15]
float dAng = max(0.0, abs(ang) - 1.15) * max(r, 0.4);
float d2D = max(dr, dAng);
// Gentle 3D sculptural wave along the crescent so it catches 3D depth
float yOff = 0.09 * sin(u * 2.2) * scaleR;
float halfThick = (0.018 + 0.024 * taper);
float dy = abs(q.y - yOff) - halfThick;
// Combine 2D crescent ribbon with 3D bevel thickness
vec2 w = vec2(max(d2D, 0.0), max(dy, 0.0));
float d3D = min(max(d2D, dy), 0.0) + length(w);
// Scale down slightly for Lipschitz safety due to polar curvature
dBest = min(dBest, d3D * 0.72);
}
return dBest;
}
// ----------------------------------------------------------------------------
// Orbiting Faceted Purple & Crimson Crystal Shards SDF
// ----------------------------------------------------------------------------
struct Hit {
float d;
int mat;
float id;
};
Hit opMin(Hit a, Hit b) {
if (a.d < b.d) {
return a;
}
return b;
}
Hit mapScene(vec3 p, float phase, float openAmt) {
Hit res;
res.d = 1e5;
res.mat = MAT_NONE;
res.id = 0.0;
// 1. Pitch-dark spherical event horizon
float horizonR = 0.40 + 0.04 * openAmt + 0.012 * sin(phase * TAU);
float dHorizon = length(p - vec3(0.0, VORTEX_Y, 0.0)) - horizonR;
res = opMin(res, Hit(dHorizon, MAT_HORIZON, 0.0));
// 2. 4 Bold curved comic lensing crescents
float dCresc = sdCrescents(p, phase, openAmt);
res = opMin(res, Hit(dCresc, MAT_CRESCENT, 1.0));
// 3. Orbiting hero & medium faceted PURPLE crystal shards (8 shards)
// Seamless 3s inward-spiraling orbit using cyclic radial pull
float spread = 0.86 + 0.38 * openAmt;
for (int i = 0; i < 8; i++) {
float fi = float(i);
// Hero outer shards (0..3) and inner vortex shards (4..7)
bool isHero = (i < 4);
float baseAng = fi * (TAU / 4.0) + (isHero ? 0.55 : 0.12);
// Seamless orbit: 1 full turn or 1/2 turn per 3s? 1/4 turn with 4-fold symmetry is seamless,
// or 1 full turn for individual shards is always 100% seamless!
// Let's use 1 full inward-spiraling wave + 0.25*TAU base rotation synced cleanly:
float cyc = fract(phase + fi * 0.25);
// Smooth radial oscillation so shards surge inward toward the void
float pullWave = 0.5 - 0.5 * cos(cyc * TAU);
float orbitAng = baseAng - phase * TAU * (isHero ? 0.25 : 0.5) - pullWave * 0.35;
float rBase = isHero ? (2.15 - 0.30 * pullWave) : (1.12 - 0.22 * pullWave);
float rad = rBase * spread;
float hOff = isHero
? (0.28 * sin(fi * 1.9 + phase * TAU) + 0.25)
: (0.14 * cos(fi * 2.3 - phase * TAU) + 0.05);
vec3 cPos = vec3(cos(orbitAng) * rad, VORTEX_Y + hOff, sin(orbitAng) * rad);
vec3 q = p - cPos;
// Point crystal tip inward toward the black hole center!
vec3 toCenter = safeNorm(vec3(0.0, VORTEX_Y, 0.0) - cPos);
vec3 upRef = vec3(0.0, 1.0, 0.0);
vec3 rightV = safeNorm(cross(upRef, toCenter));
vec3 upV = cross(toCenter, rightV);
// Transform p into crystal local frame (Y axis points toward center)
vec3 lp = vec3(dot(q, rightV), dot(q, toCenter), dot(q, upV));
// Spin crystal gently around its own long axis (1 full turn per 3s loop)
lp.xz = rot2(phase * TAU + fi * 1.1) * lp.xz;
vec2 cSize = isHero ? vec2(0.185, 0.48) : vec2(0.088, 0.22);
float dCry = sdCrystalLong(lp, cSize);
res = opMin(res, Hit(dCry, MAT_CRYSTAL_PURPLE, 10.0 + fi));
}
// 4. Orbiting CRIMSON faceted diamond shards (6 shards)
for (int i = 0; i < 6; i++) {
float fi = float(i);
float baseAng = fi * (TAU / 6.0) + 0.38;
float cyc = fract(phase + fi / 6.0);
float pullWave = 0.5 - 0.5 * cos(cyc * TAU);
float orbitAng = baseAng - phase * TAU * (1.0 / 3.0);
float rad = (1.68 + 0.55 * mod(fi, 2.0) - 0.24 * pullWave) * spread;
float hOff = 0.22 * sin(fi * 2.1 + phase * TAU) + 0.12;
vec3 cPos = vec3(cos(orbitAng) * rad, VORTEX_Y + hOff, sin(orbitAng) * rad);
vec3 q = p - cPos;
q.xz = rot2(orbitAng + phase * TAU) * q.xz;
q.xy = rot2(0.55 + fi * 0.4) * q.xy;
float sc = (i == 0 || i == 3) ? 1.18 : 0.72;
vec3 dRad = vec3(0.15, 0.21, 0.085) * sc;
float dDia = sdDiamondShard(q, dRad);
res = opMin(res, Hit(dDia, MAT_CRYSTAL_CRIMSON, 30.0 + fi));
}
return res;
}
// Compute unit-weight surface normal via tetrahedron finite differences
vec3 calcNormal(vec3 p, float phase, float openAmt) {
const float h = 0.0018;
const vec2 k = vec2(1.0, -1.0);
vec3 n = k.xyy * mapScene(p + k.xyy * h, phase, openAmt).d
+ k.yyx * mapScene(p + k.yyx * h, phase, openAmt).d
+ k.yxy * mapScene(p + k.yxy * h, phase, openAmt).d
+ k.xxx * mapScene(p + k.xxx * h, phase, openAmt).d;
return safeNorm(n);
}
// ----------------------------------------------------------------------------
// Stylized Swirling Void Vortex Disk (Analytic 3D Funnel Layer)
// Crisp ink-outlined magenta-violet spiral tendrils + jagged lightning arcs.
// ----------------------------------------------------------------------------
vec4 evalVortexLayer(vec3 p, float phase, float openAmt) {
vec3 q = p - vec3(0.0, VORTEX_Y, 0.0);
float r = length(q.xz);
float a = atan(q.z, q.x);
float scaleR = 0.88 + 0.34 * openAmt;
float rn = r / max(scaleR, 0.1);
// Outer boundary of the vortex disk
if (rn > 2.25 || rn < 0.32) {
return vec4(0.0);
}
// Logarithmic spiral coordinates swirling inward seamlessly in 3s loop
float spin = phase * TAU; // 1 full turn per 3s
float logR = log(max(rn, 0.05));
// Primary bold 6-arm spiral tendrils
float sw1 = a + 3.4 * logR + spin * 0.5;
float arm1 = sin(sw1 * 4.0) * 0.5 + 0.5;
// Secondary finer jagged tongues
float sw2 = a + 5.2 * logR + spin;
float arm2 = sin(sw2 * 7.0 + 1.4) * 0.5 + 0.5;
// Comic warped noise for organic hand-inked tendril tips
vec2 nUV = vec2(cos(a + logR * 2.2), sin(a + logR * 2.2)) * (1.8 + rn * 1.4);
float nPer = fbm2(nUV + vec2(cos(spin), sin(spin)) * 0.35);
// Radial envelope with jagged tendril reach
float outerReach = 1.42 + 0.34 * arm1 + 0.18 * arm2 + 0.22 * (nPer - 0.5);
float edgeDist = outerReach - rn;
// Hard comic alpha mask + bold black-ink outer contour
float alpha = smoothstep(-0.02, 0.025, edgeDist);
if (alpha < 0.001) return vec4(0.0);
// Ink outline around outer tendril tips & between spiral layers
float outerInk = 1.0 - smoothstep(0.0, 0.085, edgeDist);
// Swirling energy value for 3-band cel shading
float innerHeat = exp(-max(0.0, rn - 0.42) * 3.1);
float swirlVal = innerHeat * 1.15
+ (0.52 * arm1 + 0.30 * arm2) * smoothstep(1.65, 0.48, rn)
+ 0.18 * (nPer - 0.5);
// Quantized 3-band comic palette (ink-black void -> deep violet -> mid violet -> electric lavender)
vec3 col = COL_INK;
float band1 = smoothstep(0.24, 0.28, swirlVal);
float band2 = smoothstep(0.54, 0.58, swirlVal);
float band3 = smoothstep(0.84, 0.89, swirlVal);
col = mix(col, COL_DEEP_VIOLET, band1);
col = mix(col, COL_MID_VIOLET, band2);
col = mix(col, COL_LAVENDER, band3);
// Crisp black ink separator streaks inside the violet swirl
float inkCrease = smoothstep(0.18, 0.23, abs(fract(sw1 * 4.0 / TAU) - 0.5))
* smoothstep(0.50, 0.95, rn);
col = mix(col, COL_INK, (1.0 - inkCrease) * 0.65 * (1.0 - band3));
// Inner glowing electric-magenta photon swirl tightly hugging the event horizon
float photonRing = exp(-pow((rn - 0.48) / 0.12, 2.0));
float ringStreak = 0.65 + 0.35 * sin(a * 6.0 + logR * 12.0 + spin);
col = mix(col, mix(COL_MAGENTA, COL_LAVENDER, 0.65), sat(photonRing * ringStreak));
// 4 Jagged electric-magenta comic lightning arcs crackling outward along the spiral
float arcTotal = 0.0;
for (int i = 0; i < 4; i++) {
float fi = float(i);
float arcAngle = a + 2.6 * logR + fi * (TAU * 0.25) + spin * 0.5;
// High-frequency zigzag displacement along radius
float zig = (vnoise2(vec2(rn * 9.5 + fi * 3.1, cos(spin) * 0.4 + 1.7)) - 0.5) * 0.42;
float dArc = abs(sin((arcAngle + zig) * 0.5));
float boltWidth = 0.016 + 0.012 * (1.0 - sat((rn - 0.45) / 1.1));
float bolt = (1.0 - smoothstep(boltWidth * 0.35, boltWidth, dArc))
* smoothstep(0.42, 0.52, rn)
* smoothstep(1.45, 0.68, rn);
arcTotal = max(arcTotal, bolt);
}
col = mix(col, COL_LAVENDER, sat(arcTotal));
// Magenta electric aura right around the lightning bolts
col += COL_MAGENTA * arcTotal * 0.28;
// Apply bold black-ink contour at outer tendril boundary
col = mix(col, COL_INK, outerInk * 0.92);
return vec4(col, alpha);
}
// ----------------------------------------------------------------------------
// Dark Matte Ink-Grouted Charcoal Tiled Arena Floor (y = 0)
// Base color: vec3(0.08, 0.09, 0.12)
// ----------------------------------------------------------------------------
vec3 renderFloor(vec3 p, vec3 rd, float phase, float openAmt, vec3 lightDir) {
float r = length(p.xz);
float a = atan(p.z, p.x);
// Architectural slab grid: large rectangular tiles + radial arena rings
vec2 tileUV = p.xz * 0.58;
vec2 tileF = abs(fract(tileUV + 0.5) - 0.5);
float dGrid = min(tileF.x, tileF.y);
// Radial arena border ring near outer perimeter (echoing reference top edge)
float dRing1 = abs(r - 3.95);
float dRing2 = abs(r - 4.35);
// Crisp anti-aliased ink grout seams
float fw = max(0.008, length(p.xz) * 0.0045);
float grout = 1.0 - smoothstep(0.016, 0.016 + fw, dGrid);
float ringSeam = 1.0 - smoothstep(0.03, 0.03 + fw * 2.0, min(dRing1, dRing2));
grout = max(grout, ringSeam);
// Subtle tile-to-tile tonal variation + matte concrete grunge speckles
vec2 tileID = floor(tileUV + 0.5);
float tileVar = (hash21(tileID) - 0.5) * 0.018;
float grunge = (fbm2(p.xz * 3.8) - 0.5) * 0.022;
float fineSpeck = (vnoise2(p.xz * 19.0) - 0.5) * 0.010;
vec3 baseCol = COL_FLOOR_BASE + vec3(tileVar + grunge + fineSpeck);
// Crimson arena accent band between r=4.00 and r=4.30 (like top of ref 04.png)
float crimsonBand = smoothstep(3.98, 4.02, r) * (1.0 - smoothstep(4.26, 4.30, r));
// Segmented gaps in the crimson trim
float trimSeg = smoothstep(0.08, 0.12, abs(fract(a * 6.0 / TAU) - 0.5));
baseCol = mix(baseCol, vec3(0.42, 0.09, 0.14), crimsonBand * trimSeg * 0.85);
// Stylized cel-shaded floor illumination from vortex above
float spread = 0.88 + 0.34 * openAmt;
float vortexGlow = exp(-r * r / (3.8 * spread * spread));
float glowCel = smoothstep(0.18, 0.24, vortexGlow) * 0.55
+ smoothstep(0.55, 0.62, vortexGlow) * 0.45;
vec3 lightTint = (uLightMode == 1) ? vec3(0.42, 0.20, 0.78)
: (uLightMode == 2) ? vec3(0.75, 0.18, 0.62)
: vec3(0.52, 0.16, 0.82);
vec3 col = baseCol * (0.88 + 0.25 * sat(lightDir.y))
+ lightTint * glowCel * 0.14;
// Crisp stylized contact shadow cast directly beneath the hovering vortex
float shadowR = 1.45 * spread;
float castShadow = 1.0 - smoothstep(shadowR * 0.55, shadowR * 1.15, r);
col *= (1.0 - 0.42 * castShadow);
// Subtle dark-ink grout lines (kept above pure black so <2% black metric is safe)
col = mix(col, vec3(0.022, 0.020, 0.032), grout * 0.88);
// Gentle distance fade into dark arena backdrop (stays slightly above pure black)
float fog = 1.0 - exp(-r * r * 0.018);
col = mix(col, vec3(0.032, 0.030, 0.045), fog * 0.72);
return col;
}
// ----------------------------------------------------------------------------
// Shading for 3D SDF Geometry (Horizon, Crescents, Faceted Shards)
// ----------------------------------------------------------------------------
vec3 shadeObject(vec3 p, vec3 N, vec3 V, Hit h, vec3 lightDir, float phase, float openAmt) {
float ndl = sat(dot(N, lightDir) * 0.5 + 0.5);
float ndv = sat(dot(N, V));
float fresnel = pow(1.0 - ndv, 2.4);
// Bold black-ink Fresnel contour
float inkRim = smoothstep(0.56, 0.74, 1.0 - ndv);
if (h.mat == MAT_HORIZON) {
// Pitch-dark spherical event horizon with luminous electric-magenta rim
vec3 col = COL_VOID_CORE;
float photonRim = smoothstep(0.52, 0.86, 1.0 - ndv);
float innerGlow = pow(1.0 - ndv, 3.5);
col = mix(col, COL_MID_VIOLET, photonRim * 0.55);
col = mix(col, COL_LAVENDER, innerGlow * 0.95);
return col;
}
if (h.mat == MAT_CRESCENT) {
// Bold razor-sharp white comic lensing crescent with crisp black-ink contour
// Subtle cool-lavender cel shadow on back-facing edge so it reads as 3D
float cel = cel3(ndl);
vec3 col = mix(vec3(0.84, 0.78, 0.94), COL_CRESCENT, smoothstep(0.35, 0.45, cel));
// Subtle magenta rim glint right inside the ink contour
col = mix(col, COL_LAVENDER, smoothstep(0.45, 0.65, 1.0 - ndv) * 0.45);
// Bold black-ink Fresnel outline
col = mix(col, COL_INK, smoothstep(0.62, 0.78, 1.0 - ndv));
return col;
}
if (h.mat == MAT_CRYSTAL_PURPLE) {
// 3-band quantized cel-shaded faceted purple crystal
float cel = cel3(ndl);
vec3 col = mix(COL_DEEP_VIOLET, COL_MID_VIOLET, smoothstep(0.25, 0.35, cel));
col = mix(col, COL_LAVENDER, smoothstep(0.72, 0.82, cel));
// Crisp stylized specular highlight facet
vec3 H = safeNorm(lightDir + V);
float spec = pow(sat(dot(N, H)), 18.0);
col = mix(col, vec3(0.98, 0.88, 1.00), smoothstep(0.35, 0.45, spec) * 0.75);
// Energy bounce from the blackhole center
vec3 toVoid = safeNorm(vec3(0.0, VORTEX_Y, 0.0) - p);
float voidBounce = sat(dot(N, toVoid));
col += COL_MAGENTA * smoothstep(0.35, 0.65, voidBounce) * 0.26;
// Bold black-ink Fresnel silhouette contour
col = mix(col, COL_INK, inkRim * 0.95);
return col;
}
if (h.mat == MAT_CRYSTAL_CRIMSON) {
// 3-band quantized cel-shaded faceted crimson diamond shard
float cel = cel3(ndl);
vec3 col = mix(COL_CRIMSON_DK, COL_CRIMSON_MID, smoothstep(0.25, 0.35, cel));
col = mix(col, COL_CRIMSON_HI, smoothstep(0.70, 0.80, cel));
vec3 H = safeNorm(lightDir + V);
float spec = pow(sat(dot(N, H)), 14.0);
col = mix(col, vec3(1.00, 0.76, 0.78), smoothstep(0.40, 0.50, spec) * 0.65);
// Bold black-ink Fresnel silhouette contour
col = mix(col, COL_INK, inkRim * 0.95);
return col;
}
return COL_FLOOR_BASE;
}
// ----------------------------------------------------------------------------
// Camera Setup (3 modes)
// ----------------------------------------------------------------------------
void getCamera(int camMode, out vec3 ro, out vec3 ta, out float fov) {
if (camMode == 1) {
// Dramatic low 3/4 view emphasizing levitation height above tiled floor
ro = vec3(2.55, 2.15, 3.45);
ta = vec3(0.0, 1.12, 0.0);
fov = 1.65;
} else if (camMode == 2) {
// Dynamic close-up hero angle
ro = vec3(-1.35, 3.10, 2.05);
ta = vec3(0.0, 1.18, 0.0);
fov = 1.55;
} else {
// Default hero high-angle 3/4 view matching reference 04.png
ro = vec3(0.0, 4.35, 2.05);
ta = vec3(0.0, 1.12, 0.0);
fov = 1.52;
}
}
vec3 getLightDir(int lightMode) {
if (lightMode == 1) {
return safeNorm(vec3(-0.65, 0.80, 0.45));
} else if (lightMode == 2) {
return safeNorm(vec3(0.35, 0.65, -0.70));
}
return safeNorm(vec3(0.55, 0.85, 0.42));
}
// ----------------------------------------------------------------------------
// Main
// ----------------------------------------------------------------------------
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 res = max(uResolution, vec2(1.0));
vec2 uv = (pfx_frag_xy - 0.5 * res) / min(res.x, res.y);
float phase = loopPhase();
float openAmt = pullOpen();
vec3 ro, ta;
float fov;
getCamera(uCamMode, ro, ta, fov);
vec3 fwd = safeNorm(ta - ro);
vec3 rightV = safeNorm(cross(fwd, vec3(0.0, 1.0, 0.0)));
vec3 upV = cross(rightV, fwd);
vec3 rd = safeNorm(fwd * fov + rightV * uv.x + upV * uv.y);
vec3 lightDir = getLightDir(uLightMode);
// 1. Ray-floor intersection (y = 0)
float tFloor = (rd.y < -1e-4) ? (-ro.y / rd.y) : 40.0;
vec3 bgCol = vec3(0.032, 0.030, 0.048);
if (rd.y < -1e-4 && tFloor < 35.0) {
bgCol = renderFloor(ro + rd * tFloor, rd, phase, openAmt, lightDir);
}
// 2. Ray-vortex tilted plane intersection (y = VORTEX_Y, slight tilt 0.10 rad)
vec3 vNorm = safeNorm(vec3(0.0, cos(0.10), -sin(0.10)));
float denom = dot(rd, vNorm);
float tVortex = 1e5;
vec4 vortexCol = vec4(0.0);
if (abs(denom) > 1e-4) {
float tv = dot(vec3(0.0, VORTEX_Y, 0.0) - ro, vNorm) / denom;
if (tv > 0.1 && tv < tFloor) {
tVortex = tv;
vortexCol = evalVortexLayer(ro + rd * tv, phase, openAmt);
}
}
// 3. Raymarch 3D SDF scene (event horizon, 4 curved crescents, faceted crystals)
float t = 0.0;
float tMax = min(tFloor, 18.0);
Hit hit = Hit(1e5, MAT_NONE, 0.0);
// Track closest approach to crescents & crystals for crisp comic ink outlines!
float minOutlineD = 1e5;
float minOutlineT = 1e5;
for (int i = 0; i < 96; i++) {
vec3 p = ro + rd * t;
Hit h = mapScene(p, phase, openAmt);
if (h.mat != MAT_HORIZON && h.d < minOutlineD) {
minOutlineD = h.d;
minOutlineT = t;
}
if (h.d < 0.0022) {
hit = h;
break;
}
t += max(h.d * 0.85, 0.006);
if (t > tMax) break;
}
// 4. Composite in proper 3D depth order: Floor -> Vortex -> SDF Objects + Ink Contours
vec3 col = bgCol;
// Composite vortex behind SDF hit (or when nothing hit)
bool vortexInFront = (vortexCol.a > 0.001) && (tVortex < t && hit.mat != MAT_NONE);
if (vortexCol.a > 0.001 && !vortexInFront) {
col = mix(col, vortexCol.rgb, vortexCol.a);
}
// Crisp proximity ink outline around crescents & crystals when ray grazes their silhouette
if (hit.mat == MAT_NONE && minOutlineD < 0.036) {
float inkStroke = 1.0 - smoothstep(0.010, 0.032, minOutlineD);
if (minOutlineT < tFloor) {
col = mix(col, COL_INK, inkStroke * 0.94);
}
}
// Shade hit SDF object
if (hit.mat != MAT_NONE) {
vec3 p = ro + rd * t;
vec3 N = calcNormal(p, phase, openAmt);
vec3 V = -rd;
vec3 objCol = shadeObject(p, N, V, hit, lightDir, phase, openAmt);
col = objCol;
}
// If vortex plane is closer than the hit object (e.g. tendrils in front of back crystals)
if (vortexInFront) {
// Keep the pitch-dark event horizon & bold white crescents razor-sharp on top
float vAlpha = (hit.mat == MAT_HORIZON || hit.mat == MAT_CRESCENT)
? vortexCol.a * 0.08
: vortexCol.a;
col = mix(col, vortexCol.rgb, vAlpha);
}
// 5. Subtle electric-magenta gravitational aura around the black hole center
vec3 toCenter = vec3(0.0, VORTEX_Y, 0.0) - ro;
float tClosest = max(0.0, dot(toCenter, rd));
float dCenter = length(ro + rd * tClosest - vec3(0.0, VORTEX_Y, 0.0));
float auraR = 0.72 + 0.18 * openAmt;
float halo = exp(-pow(max(0.0, dCenter - 0.36) / auraR, 2.0));
if (hit.mat != MAT_HORIZON) {
col += vec3(0.46, 0.12, 0.72) * halo * 0.16;
}
// 6. Stylized comic display shoulder (preserves rich dark charcoal floor vec3(0.08,0.09,0.12),
// crisp white crescents <1% clip, and deep ink above pure-black <2% black)
col = max(col, vec3(0.0));
col = col / (vec3(1.0) + col * 0.10) * 1.04;
col = clamp(col, vec3(0.018, 0.014, 0.028), vec3(0.975));
// Neutral grayscale lighting inspection mode (uLightMode == 1)
if (uLightMode == 1) {
float lum = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(clamp(lum, 0.018, 0.96));
}
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;
// Violet Void Blackhole Pull — Godot 4 (spatial) wrapper
// Source: https://github.com/gokayfem/glsl-studies/blob/main/vfx_stylized/lib/04_violet_void_blackhole_pull.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;
// ============================================================================
// 04_violet_void_blackhole_pull.glsl
// Stylized cel-shaded 3D deep-violet & electric-magenta void blackhole vortex
// levitating above a dark matte ink-grouted charcoal tiled arena floor.
// - Pitch-dark spherical event horizon with glowing magenta photon ring
// - Crisp ink-outlined magenta-violet swirling energy tendrils & arcs
// - 4 bold razor-sharp white-edged curved comic lensing crescents
// - Orbiting ink-outlined faceted purple & crimson crystal shards
// - uTime: seamless 3.0s loop spiraling crescents & shards inward
// - uOpen: 0..1 widens gravity pull radius, crescent sweep & shard surge
// ============================================================================
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
// Palette
const vec3 COL_FLOOR_BASE = vec3(0.08, 0.09, 0.12);
const vec3 COL_INK = vec3(0.018, 0.012, 0.030);
const vec3 COL_VOID_CORE = vec3(0.016, 0.008, 0.026);
const vec3 COL_DEEP_VIOLET = vec3(0.24, 0.06, 0.50);
const vec3 COL_MID_VIOLET = vec3(0.52, 0.14, 0.84);
const vec3 COL_MAGENTA = vec3(0.92, 0.28, 0.96);
const vec3 COL_LAVENDER = vec3(0.98, 0.68, 1.00);
const vec3 COL_CRESCENT = vec3(0.96, 0.95, 0.99);
const vec3 COL_CRIMSON_DK = vec3(0.46, 0.05, 0.11);
const vec3 COL_CRIMSON_MID = vec3(0.88, 0.14, 0.22);
const vec3 COL_CRIMSON_HI = vec3(1.00, 0.46, 0.50);
// Material IDs
const int MAT_NONE = 0;
const int MAT_HORIZON = 1;
const int MAT_CRESCENT = 2;
const int MAT_CRYSTAL_PURPLE = 3;
const int MAT_CRYSTAL_CRIMSON= 4;
const float VORTEX_Y = 1.18;
float sat(float x) { return clamp(x, 0.0, 1.0); }
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
vec3 safeNorm(vec3 v) {
float l = length(v);
return l > 1e-5 ? v / l : vec3(0.0, 1.0, 0.0);
}
float hash11(float p) {
p = fract(p * 0.1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
float hash21(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}
float fbm2(vec2 p) {
float v = 0.0;
float a = 0.55;
for (int i = 0; i < 3; i++) {
v += a * vnoise2(p);
p = p * 2.07 + vec2(13.1, 7.7);
a *= 0.48;
}
return v;
}
// 3-band quantized cel ramp with crisp comic transitions
float cel3(float x) {
float b1 = smoothstep(0.22, 0.26, x);
float b2 = smoothstep(0.60, 0.64, x);
return 0.18 + 0.44 * b1 + 0.38 * b2;
}
// Seamless 3.0-second loop phase in [0, 1)
float loopPhase() {
return fract(uTime / 3.0);
}
// Effective pull factor from uOpen (0..1)
float pullOpen() {
return clamp(uOpen, 0.0, 1.0);
}
// ----------------------------------------------------------------------------
// 3D Faceted Crystal Shard SDF (elongated hexagonal/tetragonal bipyramid)
// Uses plane intersections so every face has crisp flat unit-weight normals.
// ----------------------------------------------------------------------------
float sdCrystalLong(vec3 p, vec2 size) {
// size.x = radius, size.y = half-length along Y
// Slight asymmetry: sharper bottom tip, chunkier faceted top
vec3 q = p;
float ay = q.y;
float rScale = ay > 0.0
? max(0.001, 1.0 - ay / (size.y * 1.15))
: max(0.001, 1.0 + ay / (size.y * 0.85));
// 5-sided faceted cross-section using folded planes
vec2 xz = q.xz;
float d1 = abs(xz.x) * 0.92 + abs(xz.y) * 0.42;
float d2 = abs(xz.x) * 0.35 + abs(xz.y) * 0.94;
float d3 = dot(abs(xz), vec2(0.7071, 0.7071));
float hexR = max(max(d1, d2), d3 * 0.96);
float sideD = (hexR - size.x * rScale) * 0.78;
float capTop = q.y - size.y * 1.15;
float capBot = -q.y - size.y * 0.85;
return max(sideD, max(capTop, capBot));
}
// Faceted diamond / rhomboid crimson shard SDF
float sdDiamondShard(vec3 p, vec3 rad) {
// Crisp octahedral diamond with flattened depth
vec3 q = abs(p) / max(rad, vec3(0.001));
float d = (q.x + q.y + q.z - 1.0) * min(rad.x, min(rad.y, rad.z)) * 0.58;
return d;
}
// ----------------------------------------------------------------------------
// 4 Bold Razor-Sharp Curved Comic Lensing Crescents SDF
// Arranged in a 4-fold spiraling pinwheel around the black hole.
// ----------------------------------------------------------------------------
float sdCrescents(vec3 p, float phase, float openAmt) {
vec3 q = p - vec3(0.0, VORTEX_Y, 0.0);
// Subtle 3D tilt of the lensing plane so crescents feel dynamic in 3D
q.yz = rot2(0.10) * q.yz;
// Seamless 3-second spiral rotation (1/4 turn = exact 4-fold symmetry loop!)
float spin = -phase * (TAU * 0.25);
q.xz = rot2(spin) * q.xz;
float r = length(q.xz);
float a = atan(q.z, q.x); // -PI..PI
// 4-fold angular sector
float sector = TAU * 0.25;
float aMod = mod(a + PI + sector * 0.5, sector) - sector * 0.5;
// Evaluate across neighboring sectors (k = -1, 0, 1) because each crescent
// sweeps ~125 degrees (> 90 deg sector) for bold overlapping spiral drama.
float dBest = 1e5;
float scaleR = 0.88 + 0.34 * openAmt;
// Breathing inward pulse synced to 3s loop
float pulse = 1.0 - 0.06 * sin(phase * TAU);
for (int k = -1; k <= 1; k++) {
float ang = aMod + float(k) * sector;
// Parametric crescent arc: ang in [-1.15, 1.15]
float u = clamp(ang / 1.15, -1.0, 1.0);
// Logarithmic-style spiral radius: sweeps from inner tip to wide outer belly to sharp tail
float rMid = (0.76 + 0.52 * smoothstep(-1.0, 0.75, u) + 0.14 * (1.0 - u * u)) * scaleR * pulse;
// Asymmetric razor-sharp crescent width: thick in the middle, zero at both tips
float taper = max(0.0, 1.0 - u * u);
float halfW = 0.215 * pow(taper, 0.78) * (0.85 + 0.30 * (0.5 + 0.5 * u)) * scaleR;
// Slight inward curve offset at tips
float dr = abs(r - rMid) - halfW;
// End-cap distance along arc when outside [-1.15, 1.15]
float dAng = max(0.0, abs(ang) - 1.15) * max(r, 0.4);
float d2D = max(dr, dAng);
// Gentle 3D sculptural wave along the crescent so it catches 3D depth
float yOff = 0.09 * sin(u * 2.2) * scaleR;
float halfThick = (0.018 + 0.024 * taper);
float dy = abs(q.y - yOff) - halfThick;
// Combine 2D crescent ribbon with 3D bevel thickness
vec2 w = vec2(max(d2D, 0.0), max(dy, 0.0));
float d3D = min(max(d2D, dy), 0.0) + length(w);
// Scale down slightly for Lipschitz safety due to polar curvature
dBest = min(dBest, d3D * 0.72);
}
return dBest;
}
// ----------------------------------------------------------------------------
// Orbiting Faceted Purple & Crimson Crystal Shards SDF
// ----------------------------------------------------------------------------
struct Hit {
float d;
int mat;
float id;
};
Hit opMin(Hit a, Hit b) {
if (a.d < b.d) {
return a;
}
return b;
}
Hit mapScene(vec3 p, float phase, float openAmt) {
Hit res;
res.d = 1e5;
res.mat = MAT_NONE;
res.id = 0.0;
// 1. Pitch-dark spherical event horizon
float horizonR = 0.40 + 0.04 * openAmt + 0.012 * sin(phase * TAU);
float dHorizon = length(p - vec3(0.0, VORTEX_Y, 0.0)) - horizonR;
res = opMin(res, Hit(dHorizon, MAT_HORIZON, 0.0));
// 2. 4 Bold curved comic lensing crescents
float dCresc = sdCrescents(p, phase, openAmt);
res = opMin(res, Hit(dCresc, MAT_CRESCENT, 1.0));
// 3. Orbiting hero & medium faceted PURPLE crystal shards (8 shards)
// Seamless 3s inward-spiraling orbit using cyclic radial pull
float spread = 0.86 + 0.38 * openAmt;
for (int i = 0; i < 8; i++) {
float fi = float(i);
// Hero outer shards (0..3) and inner vortex shards (4..7)
bool isHero = (i < 4);
float baseAng = fi * (TAU / 4.0) + (isHero ? 0.55 : 0.12);
// Seamless orbit: 1 full turn or 1/2 turn per 3s? 1/4 turn with 4-fold symmetry is seamless,
// or 1 full turn for individual shards is always 100% seamless!
// Let's use 1 full inward-spiraling wave + 0.25*TAU base rotation synced cleanly:
float cyc = fract(phase + fi * 0.25);
// Smooth radial oscillation so shards surge inward toward the void
float pullWave = 0.5 - 0.5 * cos(cyc * TAU);
float orbitAng = baseAng - phase * TAU * (isHero ? 0.25 : 0.5) - pullWave * 0.35;
float rBase = isHero ? (2.15 - 0.30 * pullWave) : (1.12 - 0.22 * pullWave);
float rad = rBase * spread;
float hOff = isHero
? (0.28 * sin(fi * 1.9 + phase * TAU) + 0.25)
: (0.14 * cos(fi * 2.3 - phase * TAU) + 0.05);
vec3 cPos = vec3(cos(orbitAng) * rad, VORTEX_Y + hOff, sin(orbitAng) * rad);
vec3 q = p - cPos;
// Point crystal tip inward toward the black hole center!
vec3 toCenter = safeNorm(vec3(0.0, VORTEX_Y, 0.0) - cPos);
vec3 upRef = vec3(0.0, 1.0, 0.0);
vec3 rightV = safeNorm(cross(upRef, toCenter));
vec3 upV = cross(toCenter, rightV);
// Transform p into crystal local frame (Y axis points toward center)
vec3 lp = vec3(dot(q, rightV), dot(q, toCenter), dot(q, upV));
// Spin crystal gently around its own long axis (1 full turn per 3s loop)
lp.xz = rot2(phase * TAU + fi * 1.1) * lp.xz;
vec2 cSize = isHero ? vec2(0.185, 0.48) : vec2(0.088, 0.22);
float dCry = sdCrystalLong(lp, cSize);
res = opMin(res, Hit(dCry, MAT_CRYSTAL_PURPLE, 10.0 + fi));
}
// 4. Orbiting CRIMSON faceted diamond shards (6 shards)
for (int i = 0; i < 6; i++) {
float fi = float(i);
float baseAng = fi * (TAU / 6.0) + 0.38;
float cyc = fract(phase + fi / 6.0);
float pullWave = 0.5 - 0.5 * cos(cyc * TAU);
float orbitAng = baseAng - phase * TAU * (1.0 / 3.0);
float rad = (1.68 + 0.55 * mod(fi, 2.0) - 0.24 * pullWave) * spread;
float hOff = 0.22 * sin(fi * 2.1 + phase * TAU) + 0.12;
vec3 cPos = vec3(cos(orbitAng) * rad, VORTEX_Y + hOff, sin(orbitAng) * rad);
vec3 q = p - cPos;
q.xz = rot2(orbitAng + phase * TAU) * q.xz;
q.xy = rot2(0.55 + fi * 0.4) * q.xy;
float sc = (i == 0 || i == 3) ? 1.18 : 0.72;
vec3 dRad = vec3(0.15, 0.21, 0.085) * sc;
float dDia = sdDiamondShard(q, dRad);
res = opMin(res, Hit(dDia, MAT_CRYSTAL_CRIMSON, 30.0 + fi));
}
return res;
}
// Compute unit-weight surface normal via tetrahedron finite differences
vec3 calcNormal(vec3 p, float phase, float openAmt) {
const float h = 0.0018;
const vec2 k = vec2(1.0, -1.0);
vec3 n = k.xyy * mapScene(p + k.xyy * h, phase, openAmt).d
+ k.yyx * mapScene(p + k.yyx * h, phase, openAmt).d
+ k.yxy * mapScene(p + k.yxy * h, phase, openAmt).d
+ k.xxx * mapScene(p + k.xxx * h, phase, openAmt).d;
return safeNorm(n);
}
// ----------------------------------------------------------------------------
// Stylized Swirling Void Vortex Disk (Analytic 3D Funnel Layer)
// Crisp ink-outlined magenta-violet spiral tendrils + jagged lightning arcs.
// ----------------------------------------------------------------------------
vec4 evalVortexLayer(vec3 p, float phase, float openAmt) {
vec3 q = p - vec3(0.0, VORTEX_Y, 0.0);
float r = length(q.xz);
float a = atan(q.z, q.x);
float scaleR = 0.88 + 0.34 * openAmt;
float rn = r / max(scaleR, 0.1);
// Outer boundary of the vortex disk
if (rn > 2.25 || rn < 0.32) {
return vec4(0.0);
}
// Logarithmic spiral coordinates swirling inward seamlessly in 3s loop
float spin = phase * TAU; // 1 full turn per 3s
float logR = log(max(rn, 0.05));
// Primary bold 6-arm spiral tendrils
float sw1 = a + 3.4 * logR + spin * 0.5;
float arm1 = sin(sw1 * 4.0) * 0.5 + 0.5;
// Secondary finer jagged tongues
float sw2 = a + 5.2 * logR + spin;
float arm2 = sin(sw2 * 7.0 + 1.4) * 0.5 + 0.5;
// Comic warped noise for organic hand-inked tendril tips
vec2 nUV = vec2(cos(a + logR * 2.2), sin(a + logR * 2.2)) * (1.8 + rn * 1.4);
float nPer = fbm2(nUV + vec2(cos(spin), sin(spin)) * 0.35);
// Radial envelope with jagged tendril reach
float outerReach = 1.42 + 0.34 * arm1 + 0.18 * arm2 + 0.22 * (nPer - 0.5);
float edgeDist = outerReach - rn;
// Hard comic alpha mask + bold black-ink outer contour
float alpha = smoothstep(-0.02, 0.025, edgeDist);
if (alpha < 0.001) return vec4(0.0);
// Ink outline around outer tendril tips & between spiral layers
float outerInk = 1.0 - smoothstep(0.0, 0.085, edgeDist);
// Swirling energy value for 3-band cel shading
float innerHeat = exp(-max(0.0, rn - 0.42) * 3.1);
float swirlVal = innerHeat * 1.15
+ (0.52 * arm1 + 0.30 * arm2) * smoothstep(1.65, 0.48, rn)
+ 0.18 * (nPer - 0.5);
// Quantized 3-band comic palette (ink-black void -> deep violet -> mid violet -> electric lavender)
vec3 col = COL_INK;
float band1 = smoothstep(0.24, 0.28, swirlVal);
float band2 = smoothstep(0.54, 0.58, swirlVal);
float band3 = smoothstep(0.84, 0.89, swirlVal);
col = mix(col, COL_DEEP_VIOLET, band1);
col = mix(col, COL_MID_VIOLET, band2);
col = mix(col, COL_LAVENDER, band3);
// Crisp black ink separator streaks inside the violet swirl
float inkCrease = smoothstep(0.18, 0.23, abs(fract(sw1 * 4.0 / TAU) - 0.5))
* smoothstep(0.50, 0.95, rn);
col = mix(col, COL_INK, (1.0 - inkCrease) * 0.65 * (1.0 - band3));
// Inner glowing electric-magenta photon swirl tightly hugging the event horizon
float photonRing = exp(-pow((rn - 0.48) / 0.12, 2.0));
float ringStreak = 0.65 + 0.35 * sin(a * 6.0 + logR * 12.0 + spin);
col = mix(col, mix(COL_MAGENTA, COL_LAVENDER, 0.65), sat(photonRing * ringStreak));
// 4 Jagged electric-magenta comic lightning arcs crackling outward along the spiral
float arcTotal = 0.0;
for (int i = 0; i < 4; i++) {
float fi = float(i);
float arcAngle = a + 2.6 * logR + fi * (TAU * 0.25) + spin * 0.5;
// High-frequency zigzag displacement along radius
float zig = (vnoise2(vec2(rn * 9.5 + fi * 3.1, cos(spin) * 0.4 + 1.7)) - 0.5) * 0.42;
float dArc = abs(sin((arcAngle + zig) * 0.5));
float boltWidth = 0.016 + 0.012 * (1.0 - sat((rn - 0.45) / 1.1));
float bolt = (1.0 - smoothstep(boltWidth * 0.35, boltWidth, dArc))
* smoothstep(0.42, 0.52, rn)
* smoothstep(1.45, 0.68, rn);
arcTotal = max(arcTotal, bolt);
}
col = mix(col, COL_LAVENDER, sat(arcTotal));
// Magenta electric aura right around the lightning bolts
col += COL_MAGENTA * arcTotal * 0.28;
// Apply bold black-ink contour at outer tendril boundary
col = mix(col, COL_INK, outerInk * 0.92);
return vec4(col, alpha);
}
// ----------------------------------------------------------------------------
// Dark Matte Ink-Grouted Charcoal Tiled Arena Floor (y = 0)
// Base color: vec3(0.08, 0.09, 0.12)
// ----------------------------------------------------------------------------
vec3 renderFloor(vec3 p, vec3 rd, float phase, float openAmt, vec3 lightDir) {
float r = length(p.xz);
float a = atan(p.z, p.x);
// Architectural slab grid: large rectangular tiles + radial arena rings
vec2 tileUV = p.xz * 0.58;
vec2 tileF = abs(fract(tileUV + 0.5) - 0.5);
float dGrid = min(tileF.x, tileF.y);
// Radial arena border ring near outer perimeter (echoing reference top edge)
float dRing1 = abs(r - 3.95);
float dRing2 = abs(r - 4.35);
// Crisp anti-aliased ink grout seams
float fw = max(0.008, length(p.xz) * 0.0045);
float grout = 1.0 - smoothstep(0.016, 0.016 + fw, dGrid);
float ringSeam = 1.0 - smoothstep(0.03, 0.03 + fw * 2.0, min(dRing1, dRing2));
grout = max(grout, ringSeam);
// Subtle tile-to-tile tonal variation + matte concrete grunge speckles
vec2 tileID = floor(tileUV + 0.5);
float tileVar = (hash21(tileID) - 0.5) * 0.018;
float grunge = (fbm2(p.xz * 3.8) - 0.5) * 0.022;
float fineSpeck = (vnoise2(p.xz * 19.0) - 0.5) * 0.010;
vec3 baseCol = COL_FLOOR_BASE + vec3(tileVar + grunge + fineSpeck);
// Crimson arena accent band between r=4.00 and r=4.30 (like top of ref 04.png)
float crimsonBand = smoothstep(3.98, 4.02, r) * (1.0 - smoothstep(4.26, 4.30, r));
// Segmented gaps in the crimson trim
float trimSeg = smoothstep(0.08, 0.12, abs(fract(a * 6.0 / TAU) - 0.5));
baseCol = mix(baseCol, vec3(0.42, 0.09, 0.14), crimsonBand * trimSeg * 0.85);
// Stylized cel-shaded floor illumination from vortex above
float spread = 0.88 + 0.34 * openAmt;
float vortexGlow = exp(-r * r / (3.8 * spread * spread));
float glowCel = smoothstep(0.18, 0.24, vortexGlow) * 0.55
+ smoothstep(0.55, 0.62, vortexGlow) * 0.45;
vec3 lightTint = (uLightMode == 1) ? vec3(0.42, 0.20, 0.78)
: (uLightMode == 2) ? vec3(0.75, 0.18, 0.62)
: vec3(0.52, 0.16, 0.82);
vec3 col = baseCol * (0.88 + 0.25 * sat(lightDir.y))
+ lightTint * glowCel * 0.14;
// Crisp stylized contact shadow cast directly beneath the hovering vortex
float shadowR = 1.45 * spread;
float castShadow = 1.0 - smoothstep(shadowR * 0.55, shadowR * 1.15, r);
col *= (1.0 - 0.42 * castShadow);
// Subtle dark-ink grout lines (kept above pure black so <2% black metric is safe)
col = mix(col, vec3(0.022, 0.020, 0.032), grout * 0.88);
// Gentle distance fade into dark arena backdrop (stays slightly above pure black)
float fog = 1.0 - exp(-r * r * 0.018);
col = mix(col, vec3(0.032, 0.030, 0.045), fog * 0.72);
return col;
}
// ----------------------------------------------------------------------------
// Shading for 3D SDF Geometry (Horizon, Crescents, Faceted Shards)
// ----------------------------------------------------------------------------
vec3 shadeObject(vec3 p, vec3 N, vec3 V, Hit h, vec3 lightDir, float phase, float openAmt) {
float ndl = sat(dot(N, lightDir) * 0.5 + 0.5);
float ndv = sat(dot(N, V));
float fresnel = pow(1.0 - ndv, 2.4);
// Bold black-ink Fresnel contour
float inkRim = smoothstep(0.56, 0.74, 1.0 - ndv);
if (h.mat == MAT_HORIZON) {
// Pitch-dark spherical event horizon with luminous electric-magenta rim
vec3 col = COL_VOID_CORE;
float photonRim = smoothstep(0.52, 0.86, 1.0 - ndv);
float innerGlow = pow(1.0 - ndv, 3.5);
col = mix(col, COL_MID_VIOLET, photonRim * 0.55);
col = mix(col, COL_LAVENDER, innerGlow * 0.95);
return col;
}
if (h.mat == MAT_CRESCENT) {
// Bold razor-sharp white comic lensing crescent with crisp black-ink contour
// Subtle cool-lavender cel shadow on back-facing edge so it reads as 3D
float cel = cel3(ndl);
vec3 col = mix(vec3(0.84, 0.78, 0.94), COL_CRESCENT, smoothstep(0.35, 0.45, cel));
// Subtle magenta rim glint right inside the ink contour
col = mix(col, COL_LAVENDER, smoothstep(0.45, 0.65, 1.0 - ndv) * 0.45);
// Bold black-ink Fresnel outline
col = mix(col, COL_INK, smoothstep(0.62, 0.78, 1.0 - ndv));
return col;
}
if (h.mat == MAT_CRYSTAL_PURPLE) {
// 3-band quantized cel-shaded faceted purple crystal
float cel = cel3(ndl);
vec3 col = mix(COL_DEEP_VIOLET, COL_MID_VIOLET, smoothstep(0.25, 0.35, cel));
col = mix(col, COL_LAVENDER, smoothstep(0.72, 0.82, cel));
// Crisp stylized specular highlight facet
vec3 H = safeNorm(lightDir + V);
float spec = pow(sat(dot(N, H)), 18.0);
col = mix(col, vec3(0.98, 0.88, 1.00), smoothstep(0.35, 0.45, spec) * 0.75);
// Energy bounce from the blackhole center
vec3 toVoid = safeNorm(vec3(0.0, VORTEX_Y, 0.0) - p);
float voidBounce = sat(dot(N, toVoid));
col += COL_MAGENTA * smoothstep(0.35, 0.65, voidBounce) * 0.26;
// Bold black-ink Fresnel silhouette contour
col = mix(col, COL_INK, inkRim * 0.95);
return col;
}
if (h.mat == MAT_CRYSTAL_CRIMSON) {
// 3-band quantized cel-shaded faceted crimson diamond shard
float cel = cel3(ndl);
vec3 col = mix(COL_CRIMSON_DK, COL_CRIMSON_MID, smoothstep(0.25, 0.35, cel));
col = mix(col, COL_CRIMSON_HI, smoothstep(0.70, 0.80, cel));
vec3 H = safeNorm(lightDir + V);
float spec = pow(sat(dot(N, H)), 14.0);
col = mix(col, vec3(1.00, 0.76, 0.78), smoothstep(0.40, 0.50, spec) * 0.65);
// Bold black-ink Fresnel silhouette contour
col = mix(col, COL_INK, inkRim * 0.95);
return col;
}
return COL_FLOOR_BASE;
}
// ----------------------------------------------------------------------------
// Camera Setup (3 modes)
// ----------------------------------------------------------------------------
void getCamera(int camMode, out vec3 ro, out vec3 ta, out float fov) {
if (camMode == 1) {
// Dramatic low 3/4 view emphasizing levitation height above tiled floor
ro = vec3(2.55, 2.15, 3.45);
ta = vec3(0.0, 1.12, 0.0);
fov = 1.65;
} else if (camMode == 2) {
// Dynamic close-up hero angle
ro = vec3(-1.35, 3.10, 2.05);
ta = vec3(0.0, 1.18, 0.0);
fov = 1.55;
} else {
// Default hero high-angle 3/4 view matching reference 04.png
ro = vec3(0.0, 4.35, 2.05);
ta = vec3(0.0, 1.12, 0.0);
fov = 1.52;
}
}
vec3 getLightDir(int lightMode) {
if (lightMode == 1) {
return safeNorm(vec3(-0.65, 0.80, 0.45));
} else if (lightMode == 2) {
return safeNorm(vec3(0.35, 0.65, -0.70));
}
return safeNorm(vec3(0.55, 0.85, 0.42));
}
// ----------------------------------------------------------------------------
// Main
// ----------------------------------------------------------------------------
void pixelfx_study_eval(vec2 pfx_frag_xy, out vec4 fragColor) {
vec2 res = max(uResolution, vec2(1.0));
vec2 uv = (pfx_frag_xy - 0.5 * res) / min(res.x, res.y);
float phase = loopPhase();
float openAmt = pullOpen();
vec3 ro, ta;
float fov;
getCamera(uCamMode, ro, ta, fov);
vec3 fwd = safeNorm(ta - ro);
vec3 rightV = safeNorm(cross(fwd, vec3(0.0, 1.0, 0.0)));
vec3 upV = cross(rightV, fwd);
vec3 rd = safeNorm(fwd * fov + rightV * uv.x + upV * uv.y);
vec3 lightDir = getLightDir(uLightMode);
// 1. Ray-floor intersection (y = 0)
float tFloor = (rd.y < -1e-4) ? (-ro.y / rd.y) : 40.0;
vec3 bgCol = vec3(0.032, 0.030, 0.048);
if (rd.y < -1e-4 && tFloor < 35.0) {
bgCol = renderFloor(ro + rd * tFloor, rd, phase, openAmt, lightDir);
}
// 2. Ray-vortex tilted plane intersection (y = VORTEX_Y, slight tilt 0.10 rad)
vec3 vNorm = safeNorm(vec3(0.0, cos(0.10), -sin(0.10)));
float denom = dot(rd, vNorm);
float tVortex = 1e5;
vec4 vortexCol = vec4(0.0);
if (abs(denom) > 1e-4) {
float tv = dot(vec3(0.0, VORTEX_Y, 0.0) - ro, vNorm) / denom;
if (tv > 0.1 && tv < tFloor) {
tVortex = tv;
vortexCol = evalVortexLayer(ro + rd * tv, phase, openAmt);
}
}
// 3. Raymarch 3D SDF scene (event horizon, 4 curved crescents, faceted crystals)
float t = 0.0;
float tMax = min(tFloor, 18.0);
Hit hit = Hit(1e5, MAT_NONE, 0.0);
// Track closest approach to crescents & crystals for crisp comic ink outlines!
float minOutlineD = 1e5;
float minOutlineT = 1e5;
for (int i = 0; i < 96; i++) {
vec3 p = ro + rd * t;
Hit h = mapScene(p, phase, openAmt);
if (h.mat != MAT_HORIZON && h.d < minOutlineD) {
minOutlineD = h.d;
minOutlineT = t;
}
if (h.d < 0.0022) {
hit = h;
break;
}
t += max(h.d * 0.85, 0.006);
if (t > tMax) break;
}
// 4. Composite in proper 3D depth order: Floor -> Vortex -> SDF Objects + Ink Contours
vec3 col = bgCol;
// Composite vortex behind SDF hit (or when nothing hit)
bool vortexInFront = (vortexCol.a > 0.001) && (tVortex < t && hit.mat != MAT_NONE);
if (vortexCol.a > 0.001 && !vortexInFront) {
col = mix(col, vortexCol.rgb, vortexCol.a);
}
// Crisp proximity ink outline around crescents & crystals when ray grazes their silhouette
if (hit.mat == MAT_NONE && minOutlineD < 0.036) {
float inkStroke = 1.0 - smoothstep(0.010, 0.032, minOutlineD);
if (minOutlineT < tFloor) {
col = mix(col, COL_INK, inkStroke * 0.94);
}
}
// Shade hit SDF object
if (hit.mat != MAT_NONE) {
vec3 p = ro + rd * t;
vec3 N = calcNormal(p, phase, openAmt);
vec3 V = -rd;
vec3 objCol = shadeObject(p, N, V, hit, lightDir, phase, openAmt);
col = objCol;
}
// If vortex plane is closer than the hit object (e.g. tendrils in front of back crystals)
if (vortexInFront) {
// Keep the pitch-dark event horizon & bold white crescents razor-sharp on top
float vAlpha = (hit.mat == MAT_HORIZON || hit.mat == MAT_CRESCENT)
? vortexCol.a * 0.08
: vortexCol.a;
col = mix(col, vortexCol.rgb, vAlpha);
}
// 5. Subtle electric-magenta gravitational aura around the black hole center
vec3 toCenter = vec3(0.0, VORTEX_Y, 0.0) - ro;
float tClosest = max(0.0, dot(toCenter, rd));
float dCenter = length(ro + rd * tClosest - vec3(0.0, VORTEX_Y, 0.0));
float auraR = 0.72 + 0.18 * openAmt;
float halo = exp(-pow(max(0.0, dCenter - 0.36) / auraR, 2.0));
if (hit.mat != MAT_HORIZON) {
col += vec3(0.46, 0.12, 0.72) * halo * 0.16;
}
// 6. Stylized comic display shoulder (preserves rich dark charcoal floor vec3(0.08,0.09,0.12),
// crisp white crescents <1% clip, and deep ink above pure-black <2% black)
col = max(col, vec3(0.0));
col = col / (vec3(1.0) + col * 0.10) * 1.04;
col = clamp(col, vec3(0.018, 0.014, 0.028), vec3(0.975));
// Neutral grayscale lighting inspection mode (uLightMode == 1)
if (uLightMode == 1) {
float lum = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(clamp(lum, 0.018, 0.96));
}
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);
}
}
// Violet Void Blackhole Pull — Three.js WebGL2 ShaderMaterial (GLSL3)
// Upstream study: https://github.com/gokayfem/glsl-studies/blob/main/vfx_stylized/lib/04_violet_void_blackhole_pull.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;
// ============================================================================
// 04_violet_void_blackhole_pull.glsl
// Stylized cel-shaded 3D deep-violet & electric-magenta void blackhole vortex
// levitating above a dark matte ink-grouted charcoal tiled arena floor.
// - Pitch-dark spherical event horizon with glowing magenta photon ring
// - Crisp ink-outlined magenta-violet swirling energy tendrils & arcs
// - 4 bold razor-sharp white-edged curved comic lensing crescents
// - Orbiting ink-outlined faceted purple & crimson crystal shards
// - uTime: seamless 3.0s loop spiraling crescents & shards inward
// - uOpen: 0..1 widens gravity pull radius, crescent sweep & shard surge
// ============================================================================
const float PI = 3.14159265359;
const float TAU = 6.28318530718;
// Palette
const vec3 COL_FLOOR_BASE = vec3(0.08, 0.09, 0.12);
const vec3 COL_INK = vec3(0.018, 0.012, 0.030);
const vec3 COL_VOID_CORE = vec3(0.016, 0.008, 0.026);
const vec3 COL_DEEP_VIOLET = vec3(0.24, 0.06, 0.50);
const vec3 COL_MID_VIOLET = vec3(0.52, 0.14, 0.84);
const vec3 COL_MAGENTA = vec3(0.92, 0.28, 0.96);
const vec3 COL_LAVENDER = vec3(0.98, 0.68, 1.00);
const vec3 COL_CRESCENT = vec3(0.96, 0.95, 0.99);
const vec3 COL_CRIMSON_DK = vec3(0.46, 0.05, 0.11);
const vec3 COL_CRIMSON_MID = vec3(0.88, 0.14, 0.22);
const vec3 COL_CRIMSON_HI = vec3(1.00, 0.46, 0.50);
// Material IDs
const int MAT_NONE = 0;
const int MAT_HORIZON = 1;
const int MAT_CRESCENT = 2;
const int MAT_CRYSTAL_PURPLE = 3;
const int MAT_CRYSTAL_CRIMSON= 4;
const float VORTEX_Y = 1.18;
float sat(float x) { return clamp(x, 0.0, 1.0); }
mat2 rot2(float a) {
float c = cos(a), s = sin(a);
return mat2(c, -s, s, c);
}
vec3 safeNorm(vec3 v) {
float l = length(v);
return l > 1e-5 ? v / l : vec3(0.0, 1.0, 0.0);
}
float hash11(float p) {
p = fract(p * 0.1031);
p *= p + 33.33;
p *= p + p;
return fract(p);
}
float hash21(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
float vnoise2(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u = f * f * (3.0 - 2.0 * f);
float a = hash21(i);
float b = hash21(i + vec2(1.0, 0.0));
float c = hash21(i + vec2(0.0, 1.0));
float d = hash21(i + vec2(1.0, 1.0));
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}
float fbm2(vec2 p) {
float v = 0.0;
float a = 0.55;
for (int i = 0; i < 3; i++) {
v += a * vnoise2(p);
p = p * 2.07 + vec2(13.1, 7.7);
a *= 0.48;
}
return v;
}
// 3-band quantized cel ramp with crisp comic transitions
float cel3(float x) {
float b1 = smoothstep(0.22, 0.26, x);
float b2 = smoothstep(0.60, 0.64, x);
return 0.18 + 0.44 * b1 + 0.38 * b2;
}
// Seamless 3.0-second loop phase in [0, 1)
float loopPhase() {
return fract(uTime / 3.0);
}
// Effective pull factor from uOpen (0..1)
float pullOpen() {
return clamp(uOpen, 0.0, 1.0);
}
// ----------------------------------------------------------------------------
// 3D Faceted Crystal Shard SDF (elongated hexagonal/tetragonal bipyramid)
// Uses plane intersections so every face has crisp flat unit-weight normals.
// ----------------------------------------------------------------------------
float sdCrystalLong(vec3 p, vec2 size) {
// size.x = radius, size.y = half-length along Y
// Slight asymmetry: sharper bottom tip, chunkier faceted top
vec3 q = p;
float ay = q.y;
float rScale = ay > 0.0
? max(0.001, 1.0 - ay / (size.y * 1.15))
: max(0.001, 1.0 + ay / (size.y * 0.85));
// 5-sided faceted cross-section using folded planes
vec2 xz = q.xz;
float d1 = abs(xz.x) * 0.92 + abs(xz.y) * 0.42;
float d2 = abs(xz.x) * 0.35 + abs(xz.y) * 0.94;
float d3 = dot(abs(xz), vec2(0.7071, 0.7071));
float hexR = max(max(d1, d2), d3 * 0.96);
float sideD = (hexR - size.x * rScale) * 0.78;
float capTop = q.y - size.y * 1.15;
float capBot = -q.y - size.y * 0.85;
return max(sideD, max(capTop, capBot));
}
// Faceted diamond / rhomboid crimson shard SDF
float sdDiamondShard(vec3 p, vec3 rad) {
// Crisp octahedral diamond with flattened depth
vec3 q = abs(p) / max(rad, vec3(0.001));
float d = (q.x + q.y + q.z - 1.0) * min(rad.x, min(rad.y, rad.z)) * 0.58;
return d;
}
// ----------------------------------------------------------------------------
// 4 Bold Razor-Sharp Curved Comic Lensing Crescents SDF
// Arranged in a 4-fold spiraling pinwheel around the black hole.
// ----------------------------------------------------------------------------
float sdCrescents(vec3 p, float phase, float openAmt) {
vec3 q = p - vec3(0.0, VORTEX_Y, 0.0);
// Subtle 3D tilt of the lensing plane so crescents feel dynamic in 3D
q.yz = rot2(0.10) * q.yz;
// Seamless 3-second spiral rotation (1/4 turn = exact 4-fold symmetry loop!)
float spin = -phase * (TAU * 0.25);
q.xz = rot2(spin) * q.xz;
float r = length(q.xz);
float a = atan(q.z, q.x); // -PI..PI
// 4-fold angular sector
float sector = TAU * 0.25;
float aMod = mod(a + PI + sector * 0.5, sector) - sector * 0.5;
// Evaluate across neighboring sectors (k = -1, 0, 1) because each crescent
// sweeps ~125 degrees (> 90 deg sector) for bold overlapping spiral drama.
float dBest = 1e5;
float scaleR = 0.88 + 0.34 * openAmt;
// Breathing inward pulse synced to 3s loop
float pulse = 1.0 - 0.06 * sin(phase * TAU);
for (int k = -1; k <= 1; k++) {
float ang = aMod + float(k) * sector;
// Parametric crescent arc: ang in [-1.15, 1.15]
float u = clamp(ang / 1.15, -1.0, 1.0);
// Logarithmic-style spiral radius: sweeps from inner tip to wide outer belly to sharp tail
float rMid = (0.76 + 0.52 * smoothstep(-1.0, 0.75, u) + 0.14 * (1.0 - u * u)) * scaleR * pulse;
// Asymmetric razor-sharp crescent width: thick in the middle, zero at both tips
float taper = max(0.0, 1.0 - u * u);
float halfW = 0.215 * pow(taper, 0.78) * (0.85 + 0.30 * (0.5 + 0.5 * u)) * scaleR;
// Slight inward curve offset at tips
float dr = abs(r - rMid) - halfW;
// End-cap distance along arc when outside [-1.15, 1.15]
float dAng = max(0.0, abs(ang) - 1.15) * max(r, 0.4);
float d2D = max(dr, dAng);
// Gentle 3D sculptural wave along the crescent so it catches 3D depth
float yOff = 0.09 * sin(u * 2.2) * scaleR;
float halfThick = (0.018 + 0.024 * taper);
float dy = abs(q.y - yOff) - halfThick;
// Combine 2D crescent ribbon with 3D bevel thickness
vec2 w = vec2(max(d2D, 0.0), max(dy, 0.0));
float d3D = min(max(d2D, dy), 0.0) + length(w);
// Scale down slightly for Lipschitz safety due to polar curvature
dBest = min(dBest, d3D * 0.72);
}
return dBest;
}
// ----------------------------------------------------------------------------
// Orbiting Faceted Purple & Crimson Crystal Shards SDF
// ----------------------------------------------------------------------------
struct Hit {
float d;
int mat;
float id;
};
Hit opMin(Hit a, Hit b) {
if (a.d < b.d) {
return a;
}
return b;
}
Hit mapScene(vec3 p, float phase, float openAmt) {
Hit res;
res.d = 1e5;
res.mat = MAT_NONE;
res.id = 0.0;
// 1. Pitch-dark spherical event horizon
float horizonR = 0.40 + 0.04 * openAmt + 0.012 * sin(phase * TAU);
float dHorizon = length(p - vec3(0.0, VORTEX_Y, 0.0)) - horizonR;
res = opMin(res, Hit(dHorizon, MAT_HORIZON, 0.0));
// 2. 4 Bold curved comic lensing crescents
float dCresc = sdCrescents(p, phase, openAmt);
res = opMin(res, Hit(dCresc, MAT_CRESCENT, 1.0));
// 3. Orbiting hero & medium faceted PURPLE crystal shards (8 shards)
// Seamless 3s inward-spiraling orbit using cyclic radial pull
float spread = 0.86 + 0.38 * openAmt;
for (int i = 0; i < 8; i++) {
float fi = float(i);
// Hero outer shards (0..3) and inner vortex shards (4..7)
bool isHero = (i < 4);
float baseAng = fi * (TAU / 4.0) + (isHero ? 0.55 : 0.12);
// Seamless orbit: 1 full turn or 1/2 turn per 3s? 1/4 turn with 4-fold symmetry is seamless,
// or 1 full turn for individual shards is always 100% seamless!
// Let's use 1 full inward-spiraling wave + 0.25*TAU base rotation synced cleanly:
float cyc = fract(phase + fi * 0.25);
// Smooth radial oscillation so shards surge inward toward the void
float pullWave = 0.5 - 0.5 * cos(cyc * TAU);
float orbitAng = baseAng - phase * TAU * (isHero ? 0.25 : 0.5) - pullWave * 0.35;
float rBase = isHero ? (2.15 - 0.30 * pullWave) : (1.12 - 0.22 * pullWave);
float rad = rBase * spread;
float hOff = isHero
? (0.28 * sin(fi * 1.9 + phase * TAU) + 0.25)
: (0.14 * cos(fi * 2.3 - phase * TAU) + 0.05);
vec3 cPos = vec3(cos(orbitAng) * rad, VORTEX_Y + hOff, sin(orbitAng) * rad);
vec3 q = p - cPos;
// Point crystal tip inward toward the black hole center!
vec3 toCenter = safeNorm(vec3(0.0, VORTEX_Y, 0.0) - cPos);
vec3 upRef = vec3(0.0, 1.0, 0.0);
vec3 rightV = safeNorm(cross(upRef, toCenter));
vec3 upV = cross(toCenter, rightV);
// Transform p into crystal local frame (Y axis points toward center)
vec3 lp = vec3(dot(q, rightV), dot(q, toCenter), dot(q, upV));
// Spin crystal gently around its own long axis (1 full turn per 3s loop)
lp.xz = rot2(phase * TAU + fi * 1.1) * lp.xz;
vec2 cSize = isHero ? vec2(0.185, 0.48) : vec2(0.088, 0.22);
float dCry = sdCrystalLong(lp, cSize);
res = opMin(res, Hit(dCry, MAT_CRYSTAL_PURPLE, 10.0 + fi));
}
// 4. Orbiting CRIMSON faceted diamond shards (6 shards)
for (int i = 0; i < 6; i++) {
float fi = float(i);
float baseAng = fi * (TAU / 6.0) + 0.38;
float cyc = fract(phase + fi / 6.0);
float pullWave = 0.5 - 0.5 * cos(cyc * TAU);
float orbitAng = baseAng - phase * TAU * (1.0 / 3.0);
float rad = (1.68 + 0.55 * mod(fi, 2.0) - 0.24 * pullWave) * spread;
float hOff = 0.22 * sin(fi * 2.1 + phase * TAU) + 0.12;
vec3 cPos = vec3(cos(orbitAng) * rad, VORTEX_Y + hOff, sin(orbitAng) * rad);
vec3 q = p - cPos;
q.xz = rot2(orbitAng + phase * TAU) * q.xz;
q.xy = rot2(0.55 + fi * 0.4) * q.xy;
float sc = (i == 0 || i == 3) ? 1.18 : 0.72;
vec3 dRad = vec3(0.15, 0.21, 0.085) * sc;
float dDia = sdDiamondShard(q, dRad);
res = opMin(res, Hit(dDia, MAT_CRYSTAL_CRIMSON, 30.0 + fi));
}
return res;
}
// Compute unit-weight surface normal via tetrahedron finite differences
vec3 calcNormal(vec3 p, float phase, float openAmt) {
const float h = 0.0018;
const vec2 k = vec2(1.0, -1.0);
vec3 n = k.xyy * mapScene(p + k.xyy * h, phase, openAmt).d
+ k.yyx * mapScene(p + k.yyx * h, phase, openAmt).d
+ k.yxy * mapScene(p + k.yxy * h, phase, openAmt).d
+ k.xxx * mapScene(p + k.xxx * h, phase, openAmt).d;
return safeNorm(n);
}
// ----------------------------------------------------------------------------
// Stylized Swirling Void Vortex Disk (Analytic 3D Funnel Layer)
// Crisp ink-outlined magenta-violet spiral tendrils + jagged lightning arcs.
// ----------------------------------------------------------------------------
vec4 evalVortexLayer(vec3 p, float phase, float openAmt) {
vec3 q = p - vec3(0.0, VORTEX_Y, 0.0);
float r = length(q.xz);
float a = atan(q.z, q.x);
float scaleR = 0.88 + 0.34 * openAmt;
float rn = r / max(scaleR, 0.1);
// Outer boundary of the vortex disk
if (rn > 2.25 || rn < 0.32) {
return vec4(0.0);
}
// Logarithmic spiral coordinates swirling inward seamlessly in 3s loop
float spin = phase * TAU; // 1 full turn per 3s
float logR = log(max(rn, 0.05));
// Primary bold 6-arm spiral tendrils
float sw1 = a + 3.4 * logR + spin * 0.5;
float arm1 = sin(sw1 * 4.0) * 0.5 + 0.5;
// Secondary finer jagged tongues
float sw2 = a + 5.2 * logR + spin;
float arm2 = sin(sw2 * 7.0 + 1.4) * 0.5 + 0.5;
// Comic warped noise for organic hand-inked tendril tips
vec2 nUV = vec2(cos(a + logR * 2.2), sin(a + logR * 2.2)) * (1.8 + rn * 1.4);
float nPer = fbm2(nUV + vec2(cos(spin), sin(spin)) * 0.35);
// Radial envelope with jagged tendril reach
float outerReach = 1.42 + 0.34 * arm1 + 0.18 * arm2 + 0.22 * (nPer - 0.5);
float edgeDist = outerReach - rn;
// Hard comic alpha mask + bold black-ink outer contour
float alpha = smoothstep(-0.02, 0.025, edgeDist);
if (alpha < 0.001) return vec4(0.0);
// Ink outline around outer tendril tips & between spiral layers
float outerInk = 1.0 - smoothstep(0.0, 0.085, edgeDist);
// Swirling energy value for 3-band cel shading
float innerHeat = exp(-max(0.0, rn - 0.42) * 3.1);
float swirlVal = innerHeat * 1.15
+ (0.52 * arm1 + 0.30 * arm2) * smoothstep(1.65, 0.48, rn)
+ 0.18 * (nPer - 0.5);
// Quantized 3-band comic palette (ink-black void -> deep violet -> mid violet -> electric lavender)
vec3 col = COL_INK;
float band1 = smoothstep(0.24, 0.28, swirlVal);
float band2 = smoothstep(0.54, 0.58, swirlVal);
float band3 = smoothstep(0.84, 0.89, swirlVal);
col = mix(col, COL_DEEP_VIOLET, band1);
col = mix(col, COL_MID_VIOLET, band2);
col = mix(col, COL_LAVENDER, band3);
// Crisp black ink separator streaks inside the violet swirl
float inkCrease = smoothstep(0.18, 0.23, abs(fract(sw1 * 4.0 / TAU) - 0.5))
* smoothstep(0.50, 0.95, rn);
col = mix(col, COL_INK, (1.0 - inkCrease) * 0.65 * (1.0 - band3));
// Inner glowing electric-magenta photon swirl tightly hugging the event horizon
float photonRing = exp(-pow((rn - 0.48) / 0.12, 2.0));
float ringStreak = 0.65 + 0.35 * sin(a * 6.0 + logR * 12.0 + spin);
col = mix(col, mix(COL_MAGENTA, COL_LAVENDER, 0.65), sat(photonRing * ringStreak));
// 4 Jagged electric-magenta comic lightning arcs crackling outward along the spiral
float arcTotal = 0.0;
for (int i = 0; i < 4; i++) {
float fi = float(i);
float arcAngle = a + 2.6 * logR + fi * (TAU * 0.25) + spin * 0.5;
// High-frequency zigzag displacement along radius
float zig = (vnoise2(vec2(rn * 9.5 + fi * 3.1, cos(spin) * 0.4 + 1.7)) - 0.5) * 0.42;
float dArc = abs(sin((arcAngle + zig) * 0.5));
float boltWidth = 0.016 + 0.012 * (1.0 - sat((rn - 0.45) / 1.1));
float bolt = (1.0 - smoothstep(boltWidth * 0.35, boltWidth, dArc))
* smoothstep(0.42, 0.52, rn)
* smoothstep(1.45, 0.68, rn);
arcTotal = max(arcTotal, bolt);
}
col = mix(col, COL_LAVENDER, sat(arcTotal));
// Magenta electric aura right around the lightning bolts
col += COL_MAGENTA * arcTotal * 0.28;
// Apply bold black-ink contour at outer tendril boundary
col = mix(col, COL_INK, outerInk * 0.92);
return vec4(col, alpha);
}
// ----------------------------------------------------------------------------
// Dark Matte Ink-Grouted Charcoal Tiled Arena Floor (y = 0)
// Base color: vec3(0.08, 0.09, 0.12)
// ----------------------------------------------------------------------------
vec3 renderFloor(vec3 p, vec3 rd, float phase, float openAmt, vec3 lightDir) {
float r = length(p.xz);
float a = atan(p.z, p.x);
// Architectural slab grid: large rectangular tiles + radial arena rings
vec2 tileUV = p.xz * 0.58;
vec2 tileF = abs(fract(tileUV + 0.5) - 0.5);
float dGrid = min(tileF.x, tileF.y);
// Radial arena border ring near outer perimeter (echoing reference top edge)
float dRing1 = abs(r - 3.95);
float dRing2 = abs(r - 4.35);
// Crisp anti-aliased ink grout seams
float fw = max(0.008, length(p.xz) * 0.0045);
float grout = 1.0 - smoothstep(0.016, 0.016 + fw, dGrid);
float ringSeam = 1.0 - smoothstep(0.03, 0.03 + fw * 2.0, min(dRing1, dRing2));
grout = max(grout, ringSeam);
// Subtle tile-to-tile tonal variation + matte concrete grunge speckles
vec2 tileID = floor(tileUV + 0.5);
float tileVar = (hash21(tileID) - 0.5) * 0.018;
float grunge = (fbm2(p.xz * 3.8) - 0.5) * 0.022;
float fineSpeck = (vnoise2(p.xz * 19.0) - 0.5) * 0.010;
vec3 baseCol = COL_FLOOR_BASE + vec3(tileVar + grunge + fineSpeck);
// Crimson arena accent band between r=4.00 and r=4.30 (like top of ref 04.png)
float crimsonBand = smoothstep(3.98, 4.02, r) * (1.0 - smoothstep(4.26, 4.30, r));
// Segmented gaps in the crimson trim
float trimSeg = smoothstep(0.08, 0.12, abs(fract(a * 6.0 / TAU) - 0.5));
baseCol = mix(baseCol, vec3(0.42, 0.09, 0.14), crimsonBand * trimSeg * 0.85);
// Stylized cel-shaded floor illumination from vortex above
float spread = 0.88 + 0.34 * openAmt;
float vortexGlow = exp(-r * r / (3.8 * spread * spread));
float glowCel = smoothstep(0.18, 0.24, vortexGlow) * 0.55
+ smoothstep(0.55, 0.62, vortexGlow) * 0.45;
vec3 lightTint = (uLightMode == 1) ? vec3(0.42, 0.20, 0.78)
: (uLightMode == 2) ? vec3(0.75, 0.18, 0.62)
: vec3(0.52, 0.16, 0.82);
vec3 col = baseCol * (0.88 + 0.25 * sat(lightDir.y))
+ lightTint * glowCel * 0.14;
// Crisp stylized contact shadow cast directly beneath the hovering vortex
float shadowR = 1.45 * spread;
float castShadow = 1.0 - smoothstep(shadowR * 0.55, shadowR * 1.15, r);
col *= (1.0 - 0.42 * castShadow);
// Subtle dark-ink grout lines (kept above pure black so <2% black metric is safe)
col = mix(col, vec3(0.022, 0.020, 0.032), grout * 0.88);
// Gentle distance fade into dark arena backdrop (stays slightly above pure black)
float fog = 1.0 - exp(-r * r * 0.018);
col = mix(col, vec3(0.032, 0.030, 0.045), fog * 0.72);
return col;
}
// ----------------------------------------------------------------------------
// Shading for 3D SDF Geometry (Horizon, Crescents, Faceted Shards)
// ----------------------------------------------------------------------------
vec3 shadeObject(vec3 p, vec3 N, vec3 V, Hit h, vec3 lightDir, float phase, float openAmt) {
float ndl = sat(dot(N, lightDir) * 0.5 + 0.5);
float ndv = sat(dot(N, V));
float fresnel = pow(1.0 - ndv, 2.4);
// Bold black-ink Fresnel contour
float inkRim = smoothstep(0.56, 0.74, 1.0 - ndv);
if (h.mat == MAT_HORIZON) {
// Pitch-dark spherical event horizon with luminous electric-magenta rim
vec3 col = COL_VOID_CORE;
float photonRim = smoothstep(0.52, 0.86, 1.0 - ndv);
float innerGlow = pow(1.0 - ndv, 3.5);
col = mix(col, COL_MID_VIOLET, photonRim * 0.55);
col = mix(col, COL_LAVENDER, innerGlow * 0.95);
return col;
}
if (h.mat == MAT_CRESCENT) {
// Bold razor-sharp white comic lensing crescent with crisp black-ink contour
// Subtle cool-lavender cel shadow on back-facing edge so it reads as 3D
float cel = cel3(ndl);
vec3 col = mix(vec3(0.84, 0.78, 0.94), COL_CRESCENT, smoothstep(0.35, 0.45, cel));
// Subtle magenta rim glint right inside the ink contour
col = mix(col, COL_LAVENDER, smoothstep(0.45, 0.65, 1.0 - ndv) * 0.45);
// Bold black-ink Fresnel outline
col = mix(col, COL_INK, smoothstep(0.62, 0.78, 1.0 - ndv));
return col;
}
if (h.mat == MAT_CRYSTAL_PURPLE) {
// 3-band quantized cel-shaded faceted purple crystal
float cel = cel3(ndl);
vec3 col = mix(COL_DEEP_VIOLET, COL_MID_VIOLET, smoothstep(0.25, 0.35, cel));
col = mix(col, COL_LAVENDER, smoothstep(0.72, 0.82, cel));
// Crisp stylized specular highlight facet
vec3 H = safeNorm(lightDir + V);
float spec = pow(sat(dot(N, H)), 18.0);
col = mix(col, vec3(0.98, 0.88, 1.00), smoothstep(0.35, 0.45, spec) * 0.75);
// Energy bounce from the blackhole center
vec3 toVoid = safeNorm(vec3(0.0, VORTEX_Y, 0.0) - p);
float voidBounce = sat(dot(N, toVoid));
col += COL_MAGENTA * smoothstep(0.35, 0.65, voidBounce) * 0.26;
// Bold black-ink Fresnel silhouette contour
col = mix(col, COL_INK, inkRim * 0.95);
return col;
}
if (h.mat == MAT_CRYSTAL_CRIMSON) {
// 3-band quantized cel-shaded faceted crimson diamond shard
float cel = cel3(ndl);
vec3 col = mix(COL_CRIMSON_DK, COL_CRIMSON_MID, smoothstep(0.25, 0.35, cel));
col = mix(col, COL_CRIMSON_HI, smoothstep(0.70, 0.80, cel));
vec3 H = safeNorm(lightDir + V);
float spec = pow(sat(dot(N, H)), 14.0);
col = mix(col, vec3(1.00, 0.76, 0.78), smoothstep(0.40, 0.50, spec) * 0.65);
// Bold black-ink Fresnel silhouette contour
col = mix(col, COL_INK, inkRim * 0.95);
return col;
}
return COL_FLOOR_BASE;
}
// ----------------------------------------------------------------------------
// Camera Setup (3 modes)
// ----------------------------------------------------------------------------
void getCamera(int camMode, out vec3 ro, out vec3 ta, out float fov) {
if (camMode == 1) {
// Dramatic low 3/4 view emphasizing levitation height above tiled floor
ro = vec3(2.55, 2.15, 3.45);
ta = vec3(0.0, 1.12, 0.0);
fov = 1.65;
} else if (camMode == 2) {
// Dynamic close-up hero angle
ro = vec3(-1.35, 3.10, 2.05);
ta = vec3(0.0, 1.18, 0.0);
fov = 1.55;
} else {
// Default hero high-angle 3/4 view matching reference 04.png
ro = vec3(0.0, 4.35, 2.05);
ta = vec3(0.0, 1.12, 0.0);
fov = 1.52;
}
}
vec3 getLightDir(int lightMode) {
if (lightMode == 1) {
return safeNorm(vec3(-0.65, 0.80, 0.45));
} else if (lightMode == 2) {
return safeNorm(vec3(0.35, 0.65, -0.70));
}
return safeNorm(vec3(0.55, 0.85, 0.42));
}
// ----------------------------------------------------------------------------
// Main
// ----------------------------------------------------------------------------
void main() {
vec2 res = max(uResolution, vec2(1.0));
vec2 uv = (gl_FragCoord.xy - 0.5 * res) / min(res.x, res.y);
float phase = loopPhase();
float openAmt = pullOpen();
vec3 ro, ta;
float fov;
getCamera(uCamMode, ro, ta, fov);
vec3 fwd = safeNorm(ta - ro);
vec3 rightV = safeNorm(cross(fwd, vec3(0.0, 1.0, 0.0)));
vec3 upV = cross(rightV, fwd);
vec3 rd = safeNorm(fwd * fov + rightV * uv.x + upV * uv.y);
vec3 lightDir = getLightDir(uLightMode);
// 1. Ray-floor intersection (y = 0)
float tFloor = (rd.y < -1e-4) ? (-ro.y / rd.y) : 40.0;
vec3 bgCol = vec3(0.032, 0.030, 0.048);
if (rd.y < -1e-4 && tFloor < 35.0) {
bgCol = renderFloor(ro + rd * tFloor, rd, phase, openAmt, lightDir);
}
// 2. Ray-vortex tilted plane intersection (y = VORTEX_Y, slight tilt 0.10 rad)
vec3 vNorm = safeNorm(vec3(0.0, cos(0.10), -sin(0.10)));
float denom = dot(rd, vNorm);
float tVortex = 1e5;
vec4 vortexCol = vec4(0.0);
if (abs(denom) > 1e-4) {
float tv = dot(vec3(0.0, VORTEX_Y, 0.0) - ro, vNorm) / denom;
if (tv > 0.1 && tv < tFloor) {
tVortex = tv;
vortexCol = evalVortexLayer(ro + rd * tv, phase, openAmt);
}
}
// 3. Raymarch 3D SDF scene (event horizon, 4 curved crescents, faceted crystals)
float t = 0.0;
float tMax = min(tFloor, 18.0);
Hit hit = Hit(1e5, MAT_NONE, 0.0);
// Track closest approach to crescents & crystals for crisp comic ink outlines!
float minOutlineD = 1e5;
float minOutlineT = 1e5;
for (int i = 0; i < 96; i++) {
vec3 p = ro + rd * t;
Hit h = mapScene(p, phase, openAmt);
if (h.mat != MAT_HORIZON && h.d < minOutlineD) {
minOutlineD = h.d;
minOutlineT = t;
}
if (h.d < 0.0022) {
hit = h;
break;
}
t += max(h.d * 0.85, 0.006);
if (t > tMax) break;
}
// 4. Composite in proper 3D depth order: Floor -> Vortex -> SDF Objects + Ink Contours
vec3 col = bgCol;
// Composite vortex behind SDF hit (or when nothing hit)
bool vortexInFront = (vortexCol.a > 0.001) && (tVortex < t && hit.mat != MAT_NONE);
if (vortexCol.a > 0.001 && !vortexInFront) {
col = mix(col, vortexCol.rgb, vortexCol.a);
}
// Crisp proximity ink outline around crescents & crystals when ray grazes their silhouette
if (hit.mat == MAT_NONE && minOutlineD < 0.036) {
float inkStroke = 1.0 - smoothstep(0.010, 0.032, minOutlineD);
if (minOutlineT < tFloor) {
col = mix(col, COL_INK, inkStroke * 0.94);
}
}
// Shade hit SDF object
if (hit.mat != MAT_NONE) {
vec3 p = ro + rd * t;
vec3 N = calcNormal(p, phase, openAmt);
vec3 V = -rd;
vec3 objCol = shadeObject(p, N, V, hit, lightDir, phase, openAmt);
col = objCol;
}
// If vortex plane is closer than the hit object (e.g. tendrils in front of back crystals)
if (vortexInFront) {
// Keep the pitch-dark event horizon & bold white crescents razor-sharp on top
float vAlpha = (hit.mat == MAT_HORIZON || hit.mat == MAT_CRESCENT)
? vortexCol.a * 0.08
: vortexCol.a;
col = mix(col, vortexCol.rgb, vAlpha);
}
// 5. Subtle electric-magenta gravitational aura around the black hole center
vec3 toCenter = vec3(0.0, VORTEX_Y, 0.0) - ro;
float tClosest = max(0.0, dot(toCenter, rd));
float dCenter = length(ro + rd * tClosest - vec3(0.0, VORTEX_Y, 0.0));
float auraR = 0.72 + 0.18 * openAmt;
float halo = exp(-pow(max(0.0, dCenter - 0.36) / auraR, 2.0));
if (hit.mat != MAT_HORIZON) {
col += vec3(0.46, 0.12, 0.72) * halo * 0.16;
}
// 6. Stylized comic display shoulder (preserves rich dark charcoal floor vec3(0.08,0.09,0.12),
// crisp white crescents <1% clip, and deep ink above pure-black <2% black)
col = max(col, vec3(0.0));
col = col / (vec3(1.0) + col * 0.10) * 1.04;
col = clamp(col, vec3(0.018, 0.014, 0.028), vec3(0.975));
// Neutral grayscale lighting inspection mode (uLightMode == 1)
if (uLightMode == 1) {
float lum = dot(col, vec3(0.2126, 0.7152, 0.0722));
col = vec3(clamp(lum, 0.018, 0.96));
}
fragColor = vec4(col, 1.0);
}
`;
export function createVioletVoidBlackholePullMaterial(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 | violet-void-blackhole-pull |
|---|---|
| Category | Game VFX Shaders · Stylized Cel VFX |
| Upstream study | vfx_stylized/lib/04_violet_void_blackhole_pull.glsl (commit f5bfb61) |
| Animation cycle | 3.0 s seamless harmonic loop |
| Declared uniforms | uResolution, uTime, uOpen, uLightMode, uCamMode |
| Source size | 704 lines · 26.5 KB standalone GLSL ES 3.00 |
| PNG baker outputs | 512px · 1024px · 2048px RGBA8 (4-tap seamless + alpha key) |
| Companion pixel VFX | Free MIT shadow sprite sheets |
| License | MIT License + CC0 / MIT Helpers |
Schlick Fresnel reflectance (1994); Beer–Lambert volumetric absorption/attenuation
David Hoskins, hash · Inigo Quilez, tetrahedral SDF normal
AnimatedRadial ring of faceted glacial crystal spikes erupting through freezing ground mist.
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.