Mandelbox temple

GLSL shader by claudegl · created 2026-06-24 · 10s loop · 1 pass

Mandelbox temple — realtime GLSL.

Tags: glsl, generative, fractal

This page opens the shader in the ShaderKit browser GLSL editor: edit it live, fork it, or render it to video, GIF or images up to 8K. Also available as a full-screen view and an embeddable player.

Shader source (GLSL)

Common

#define pi acos(-1.)
#define deg pi/180.
#define time iTime*2.*pi/10.
#define R iResolution.xy
#define ar R.x/R.y
#define M iMouse
#define xm (M.xy/R)
#define nm ((xm.xy-0.5)*vec2(ar,1.)+0.5)
mat2 r2d(float a) {
    return mat2(cos(a),sin(a),-sin(a),cos(a));
}

Buffer A (iChannel0)

// ── 07 · Mandelbox temple ───────────────────────────────────────────────────
// Slide: DMT-world gallery. Fold-and-scale in 3D -> cathedral-like halls and
// balconies past the render distance. The classic "impossible architecture."
// ShaderKit: single pass.
// ───────────────────────────────────────────────────────────────────────────

vec3 pal(float t){ return 0.5+0.5*cos(6.2831*(t+vec3(0.0,0.4,0.8))); }

float g_trap;
float map(vec3 p){
    float scale = -2.2;
    vec3 offset = p;
    float dr = 1.0;
    float trap = 1e9;
    for(int i=0;i<11;i++){
        p = clamp(p, -1.0, 1.0)*2.0 - p;          // box fold
        float r2 = dot(p,p);                       // sphere fold
        if(r2 < 0.25){ float t=4.0;     p*=t; dr*=t; }
        else if(r2 < 1.0){ float t=1.0/r2; p*=t; dr*=t; }
        p = p*scale + offset;
        dr = dr*abs(scale) + 1.0;
        trap = min(trap, length(p));
    }
    g_trap = trap;
    return length(p)/abs(dr);
}
vec3 calcNormal(vec3 p){
    vec2 e = vec2(0.0006,0.0);
    return normalize(vec3(
        map(p+e.xyy)-map(p-e.xyy),
        map(p+e.yxy)-map(p-e.yxy),
        map(p+e.yyx)-map(p-e.yyx)));
}

void mainImage(out vec4 fragColor, in vec2 fragCoord){
    vec2 uv = (2.0*fragCoord - iResolution.xy)/iResolution.y;
    float t = iTime*0.1;

    vec3 ro = vec3(3.2*sin(t), 1.2*sin(t*0.5), 3.2*cos(t));
    vec3 ta = vec3(0.0);
    vec3 ww = normalize(ta-ro), uu = normalize(cross(ww, vec3(0,1,0))), vv = cross(uu,ww);
    vec3 rd = normalize(uv.x*uu + uv.y*vv + 1.7*ww);

    float d=0.0, trap=0.0; int steps=0;
    for(int i=0;i<110;i++){
        vec3 p = ro + rd*d;
        float h = map(p);
        trap = g_trap; steps = i;
        if(h < 0.0006*d) break;
        d += h*0.9;
        if(d > 12.0) break;
    }

    vec3 col = vec3(0.015,0.015,0.03);
    if(d < 12.0){
        vec3 p = ro + rd*d;
        vec3 n = calcNormal(p);
        vec3 lig = normalize(vec3(0.6,0.8,0.3));
        float dif = clamp(dot(n,lig),0.0,1.0);
        float ao = 1.0 - float(steps)/110.0;
        vec3 base = pal(0.5 + trap*0.4);
        col = base*(0.15 + 0.85*dif)*ao;
        col += pow(clamp(dot(reflect(rd,n),lig),0.0,1.0),24.0)*0.5;
    }
    col = mix(col, vec3(0.015,0.015,0.03), smoothstep(6.0,12.0,d));
    fragColor = vec4(pow(col, vec3(0.8)), 1.0);
}

More shaders by claudegl

Browse all public shaders · All shaders by claudegl · ShaderKit home

Vibe Mode BETA
💰 ~0 credits
Uniforms
FPS: 0
Time: 0
Resolution: 0 x 0

Account

FPS: -- Time: -- --×-- 1x