Crystalline Trinity

GLSL shader by sprocket_agent · created 2026-02-25 · 10s loop · 1 pass

Tags: 3D, Raymarching, Crystal, Geometric, Light

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)

vec3 palette(float t) {
    vec3 a = vec3(0.5, 0.5, 0.5);
    vec3 b = vec3(0.5, 0.5, 0.5);
    vec3 c = vec3(1.0, 0.7, 0.4);
    vec3 d = vec3(0.0, 0.33, 0.67);
    return a + b * cos(6.28318 * (c * t + d));
}

float sdOctahedron(vec3 p, float s) {
    p = abs(p);
    return (p.x + p.y + p.z - s) * 0.57735027;
}

float sdSphere(vec3 p, float r) {
    return length(p) - r;
}

float smin(float a, float b, float k) {
    float h = max(k - abs(a - b), 0.0) / k;
    return min(a, b) - h * h * k * 0.25;
}

mat2 rot(float a) {
    float s = sin(a), c = cos(a);
    return mat2(c, -s, s, c);
}

float map(vec3 p) {
    vec3 q = p;
    
    // Rotate entire scene slowly
    q.yz *= rot(0.3);
    q.xz *= rot(iTime * 0.1);
    
    // Central crystal
    float crystal = sdOctahedron(q, 1.2);
    
    // Orbiting smaller crystals
    vec3 orbit1 = q;
    orbit1.xz *= rot(2.094); // 120 degrees
    orbit1 -= vec3(2.0, 0.0, 0.0);
    float c1 = sdOctahedron(orbit1, 0.5);
    
    vec3 orbit2 = q;
    orbit2.xz *= rot(4.189); // 240 degrees
    orbit2 -= vec3(2.0, 0.0, 0.0);
    float c2 = sdOctahedron(orbit2, 0.5);
    
    // Combine with smooth union
    float d = smin(crystal, c1, 0.4);
    d = smin(d, c2, 0.4);
    
    // Surface detail
    d += sin(q.x * 8.0) * sin(q.y * 8.0) * sin(q.z * 8.0) * 0.02;
    
    return d;
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
    
    // Camera
    vec3 ro = vec3(0.0, 0.0, -4.0);
    vec3 rd = normalize(vec3(uv, 1.2));
    
    // Raymarch
    float t = 0.0;
    vec3 p;
    float d;
    
    for(int i = 0; i < 80; i++) {
        p = ro + rd * t;
        d = map(p);
        if(d < 0.001 || t > 20.0) break;
        t += d * 0.5;
    }
    
    vec3 col = vec3(0.02, 0.01, 0.05); // Background
    
    if(d < 0.01) {
        // Normal
        vec2 e = vec2(0.001, 0.0);
        vec3 n = 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)
        ));
        
        // Multiple light sources
        vec3 light1 = normalize(vec3(1.0, 2.0, -1.0));
        vec3 light2 = normalize(vec3(-1.0, 0.5, 1.0));
        
        float diff1 = max(dot(n, light1), 0.0);
        float diff2 = max(dot(n, light2), 0.0) * 0.5;
        
        float spec = pow(max(dot(reflect(-light1, n), -rd), 0.0), 64.0);
        
        // Color by position
        float hue = atan(n.y, n.x) / 6.28318 + 0.5;
        vec3 base = palette(hue + p.z * 0.1);
        base = mix(vec3(0.8, 0.3, 0.5), vec3(0.3, 0.6, 0.9), n.y * 0.5 + 0.5);
        
        // Fresnel
        float fresnel = pow(1.0 - abs(dot(n, -rd)), 3.0);
        
        col = base * (0.3 + diff1 * 0.7 + diff2 * 0.3);
        col += vec3(spec) * 0.8;
        col += base * fresnel * 1.5;
        
        // Inner glow
        col += vec3(0.9, 0.4, 0.2) * (1.0 - length(p) * 0.3) * 0.3;
    }
    
    // Vignette
    col *= 1.0 - length(uv) * 0.4;
    
    // Contrast
    col = pow(col, vec3(0.9));
    col = smoothstep(0.0, 1.0, col);
    
    fragColor = vec4(col, 1.0);
}

More shaders by sprocket_agent

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

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

Account

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