open .fs {
"DESCRIPTION" : "Laser Mandelbox: a box-fold/sphere-fold KIFS field that slowly tumbles and resolves into glowing cathedral shapes, raymarched in near-black with bold hot laser lines etched along its folds. Electric neon, real-time, seamless 16s loop." ,
"CREDIT" : "glslop agent (Claude)" ,
"CATEGORIES" : [ "fractal" , "raymarch" , "neon" , "mandelbox" ] ,
"INPUTS" : [
{ "NAME" : "speed" , "TYPE" : "float" , "DEFAULT" : 1.0 , "MIN" : 0.0 , "MAX" : 3.0 } ,
{ "NAME" : "glow" , "TYPE" : "float" , "DEFAULT" : 1.0 , "MIN" : 0.3 , "MAX" : 3.0 } ,
{ "NAME" : "hue" , "TYPE" : "float" , "DEFAULT" : 0.0 , "MIN" : 0.0 , "MAX" : 1.0 } ,
{ "NAME" : "boxScale" , "TYPE" : "float" , "DEFAULT" : 2.05 , "MIN" : -3.0 , "MAX" : 3.0 } ,
{ "NAME" : "tumble" , "TYPE" : "float" , "DEFAULT" : 0.5 , "MIN" : 0.0 , "MAX" : 1.5 } ,
{ "NAME" : "zoom" , "TYPE" : "float" , "DEFAULT" : 1.0 , "MIN" : 0.5 , "MAX" : 2.0 } ,
{ "NAME" : "iterCount" , "TYPE" : "long" , "DEFAULT" : 8 , "MIN" : 4 , "MAX" : 14 }
]
}
#define PI 3.14159265359
#define TAU 6.28318530718
const float PERIOD = 16.0 ;
const int MAXI = 14 ;
const int STEPS = 100 ;
mat2 rot (float a){ float c = cos (a), s = sin (a); return mat2 (c, -s, s, c); }
vec3 pal (float t){
return 0.5 + 0.5 * cos (TAU * (t + vec3 (0.55 , 0.40 , 0.18 )));
}
float map (vec3 p, mat2 R1, mat2 R2, out float trap, out float lineT2){
float fs = 3.8 ;
vec3 c = p * fs;
c.xz = R1 * c.xz;
c.xy = R2 * c.xy;
vec3 z = c;
float dr = 1.0 ;
trap = 1.0e9 ; lineT2 = 1.0e9 ;
for (int i = 0 ; i < MAXI; i++){
if (i >= iterCount) break ;
z = clamp (z, -1.0 , 1.0 ) * 2.0 - z;
float r2 = dot (z, z);
if (r2 < 0.25 ){ z *= 4.0 ; dr *= 4.0 ; }
else if (r2 < 1.0 ){ float s = 1.0 / r2; z *= s; dr *= s; }
z = z * boxScale + c;
dr = dr * abs (boxScale) + 1.0 ;
trap = min (trap, dot (z, z));
lineT2 = min (lineT2, min (min (dot (z.xy, z.xy), dot (z.yz, z.yz)), dot (z.xz, z.xz)));
}
return length (z) / abs (dr) / fs;
}
void main (){
vec2 uv = (gl_FragCoord .xy - 0.5 * RENDERSIZE .xy) / RENDERSIZE .y;
float ph = fract (TIME * speed / PERIOD);
float th = TAU * ph;
mat2 R1 = rot (th);
mat2 R2 = rot (0.4 + 0.18 * tumble * sin (th));
float camDist = 8.0 * zoom;
float az = 0.18 * sin (th);
float el = 0.32 + 0.10 * sin (th);
vec3 ro = camDist * vec3 (sin (az) * cos (el), sin (el), cos (az) * cos (el));
vec3 ta = vec3 (0.0 );
vec3 fwd = normalize (ta - ro);
vec3 rgt = normalize (cross (vec3 (0.0 , 1.0 , 0.0 ), fwd));
vec3 upv = cross (fwd, rgt);
vec3 rd = normalize (uv.x * rgt + uv.y * upv + 1.6 * fwd);
float t = 0.05 ;
float tcap = camDist + 8.0 ;
float trap = 1.0e9 , lineT2 = 1.0e9 , trapHit = 1.0e9 , lineHit2 = 1.0e9 , te = 0.0 ;
bool hit = false ;
for (int i = 0 ; i < STEPS; i++){
vec3 p = ro + rd * t;
float tr, l2;
float d = map (p, R1, R2, tr, l2);
if (d < 0.0005 * t){ hit = true ; trapHit = tr; lineHit2 = l2; te = t; break ; }
t += d * 0.85 ;
if (t > tcap) break ;
}
vec3 col = vec3 (0.0 );
if (hit){
vec3 p = ro + rd * te;
vec2 k = vec2 (1.0 , -1.0 );
float e = 0.0013 , tr, l2;
vec3 n = normalize (
k.xyy * map (p + k.xyy * e, R1, R2, tr, l2) +
k.yyx * map (p + k.yyx * e, R1, R2, tr, l2) +
k.yxy * map (p + k.yxy * e, R1, R2, tr, l2) +
k.xxx * map (p + k.xxx * e, R1, R2, tr, l2));
vec3 body = pal (hue + 0.55 * sqrt (trapHit) + 0.14 * te);
vec3 lig = normalize (vec3 (0.4 , 0.8 , 0.45 ));
float dif = max (dot (n, lig), 0.0 );
float fres = pow (1.0 - max (dot (n, -rd), 0.0 ), 2.3 );
float laser = 1.0 / (1.0 + 110.0 * lineHit2);
laser = pow (laser, 1.6 );
vec3 laserCol = mix (vec3 (0.9 , 0.97 , 1.0 ), body + 0.4 , 0.3 );
col += body * 0.025 ;
col += body * dif * 0.07 ;
col += body * fres * 2.1 * glow;
col += laserCol * laser * 8.0 * glow;
col *= exp (-0.20 * max (te - camDist + 3.5 , 0.0 ));
}
col *= 1.08 ;
col = col / (1.0 + col);
col = pow (col, vec3 (0.76 ));
col *= 1.0 - 0.24 * dot (uv, uv);
gl_FragColor = vec4 (col, 1.0 );
}