Apollonian raymarch

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

Apollonian raymarch — 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 · Apollonian raymarch ────────────────────────────────────────────────
// Slide: DMT-world gallery. Spheres packed in the gaps of spheres, forever —
// the "jeweled, self-bejeweling" lattice. (Apollonian DE after iq.)
// ShaderKit: single pass.
// ───────────────────────────────────────────────────────────────────────────

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(6.2831*(t+vec3(0.0,0.35,0.7))); }

float g_orb;
float map(vec3 p){
    float scale = 1.0;
    float orb = 1e9;
    for(int i=0;i<8;i++){
        p = -1.0 + 2.0*fract(0.5*p + 0.5);
        float k = 1.15/dot(p,p);
        p *= k; scale *= k;
        orb = min(orb, dot(p,p));
    }
    g_orb = orb;
    return 0.25*abs(p.y)/scale;
}
vec3 calcNormal(vec3 p){
    vec2 e = vec2(0.0005, 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.15;

    vec3 ro = vec3(1.4*sin(t), 0.4*sin(t*0.7), 1.4*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.6*ww);

    float d = 0.0; float orb = 0.0; int steps=0;
    for(int i=0;i<90;i++){
        vec3 p = ro + rd*d;
        float h = map(p);
        orb = g_orb; steps=i;
        if(h < 0.0006*d) break;
        d += h;
        if(d > 6.0) break;
    }

    vec3 col = vec3(0.02);
    if(d < 6.0){
        vec3 p = ro + rd*d;
        vec3 n = calcNormal(p);
        vec3 lig = normalize(vec3(0.8,0.7,0.4));
        float dif = clamp(dot(n,lig),0.0,1.0);
        float ao = 1.0 - float(steps)/90.0;
        vec3 base = pal(0.4 + orb*2.0);
        col = base*(0.2 + 0.8*dif)*ao;
        col += base*pow(clamp(dot(reflect(rd,n),lig),0.0,1.0), 16.0)*0.4;
    }
    col = mix(col, vec3(0.02,0.02,0.05), smoothstep(3.0,6.0,d));   // fog
    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