Octahedral Constellation

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

Exact octahedron SDF + iridescent materials

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)

// Octahedral Constellation - Raymarched Octahedra with Iridescent Orbitals

float iTime = 0.0;
vec3 g_ro;

// Exact octahedron SDF (Inigo Quilez)
float sdOctahedron(vec3 p, float s) {
    p = abs(p);
    float m = p.x + p.y + p.z - s;
    vec3 q;
    if(3.0 * p.x < m) q = p.xyz;
    else if(3.0 * p.y < m) q = p.yzx;
    else if(3.0 * p.z < m) q = p.zxy;
    else return m * 0.57735027;
    
    float k = clamp(0.5 * (q.z - q.y + s), 0.0, s);
    return length(vec3(q.x, q.y - s + k, q.z - k));
}

// Scene map
float map(vec3 p) {
    float d = 1e10;
    
    // Central large octahedron
    float d1 = sdOctahedron(p, 0.6);
    d = min(d, d1);
    
    // Orbiting octahedra
    float angle1 = iTime * 0.7;
    vec3 pos1 = vec3(cos(angle1) * 1.2, 0.0, sin(angle1) * 1.2);
    float d2 = sdOctahedron(p - pos1, 0.25);
    d = min(d, d2);
    
    float angle2 = iTime * 0.5 + 2.09;
    vec3 pos2 = vec3(cos(angle2) * 1.5, sin(angle2) * 0.5, sin(angle2) * 1.5);
    float d3 = sdOctahedron(p - pos2, 0.2);
    d = min(d, d3);
    
    float angle3 = iTime * 0.9 + 4.18;
    vec3 pos3 = vec3(cos(angle3) * 0.9, sin(angle3) * 0.8, sin(angle3) * 0.9);
    float d4 = sdOctahedron(p - pos3, 0.18);
    d = min(d, d4);
    
    // Ground plane (subtle)
    float ground = p.y + 1.5;
    d = min(d, ground);
    
    return d;
}

// Get normal
vec3 getNormal(vec3 p) {
    vec2 e = vec2(0.001, 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)
    ));
}

// Shadows
float getShadow(vec3 p, vec3 lightDir) {
    float shadow_dist = 0.02;
    for(int i = 0; i < 32; i++) {
        vec3 sp = p + lightDir * shadow_dist;
        float d = map(sp);
        if(d < 0.001) return 0.0;
        shadow_dist += max(d, 0.001);
        if(shadow_dist > 15.0) break;
    }
    return 1.0;
}

// Iridescent palette
vec3 iridescent(float angle, float t) {
    float a = angle * 3.0 + t;
    return vec3(
        0.5 + 0.5 * cos(a),
        0.5 + 0.5 * cos(a + 2.09),
        0.5 + 0.5 * cos(a + 4.18)
    );
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
    
    // Camera
    vec3 ro = vec3(cos(iTime * 0.2) * 3.0, 1.5 + sin(iTime * 0.1) * 0.5, sin(iTime * 0.2) * 3.0);
    vec3 lookAt = vec3(0.0, 0.0, 0.0);
    vec3 forward = normalize(lookAt - ro);
    vec3 right = normalize(cross(forward, vec3(0.0, 1.0, 0.0)));
    vec3 up = cross(right, forward);
    vec3 rd = normalize(forward + uv.x * right + uv.y * up);
    
    g_ro = ro;
    
    // Raymarch
    float dist = 0.0;
    vec3 hitPoint;
    bool hit = false;
    
    for(int i = 0; i < 80; i++) {
        vec3 p = ro + rd * dist;
        float d = map(p);
        if(d < 0.001) {
            hit = true;
            hitPoint = p;
            break;
        }
        dist += d;
        if(dist > 20.0) break;
    }
    
    vec3 col = vec3(0.0);
    
    if(hit) {
        vec3 n = getNormal(hitPoint);
        vec3 viewDir = -rd;
        
        // Two light sources
        vec3 lightDir1 = normalize(vec3(0.5, 1.0, 0.3));
        vec3 lightDir2 = normalize(vec3(-0.3, 0.8, -0.5));
        
        // Iridescent material based on view angle
        float viewAngle = dot(n, viewDir);
        vec3 baseColor = iridescent(viewAngle, iTime * 0.5);
        
        // Add some color variation based on position
        baseColor = mix(baseColor, vec3(0.8, 0.3, 0.6), 0.3 + 0.2 * sin(iTime + hitPoint.x));
        
        // Lighting
        vec3 halfway1 = normalize(viewDir + lightDir1);
        float spec1 = pow(max(0.0, dot(n, halfway1)), 64.0);
        float diff1 = max(0.0, dot(n, lightDir1));
        float shadow1 = getShadow(hitPoint + n * 0.01, lightDir1);
        
        vec3 halfway2 = normalize(viewDir + lightDir2);
        float spec2 = pow(max(0.0, dot(n, halfway2)), 32.0);
        float diff2 = max(0.0, dot(n, lightDir2));
        float shadow2 = getShadow(hitPoint + n * 0.01, lightDir2);
        
        float ambient = 0.15;
        col = baseColor * (ambient + diff1 * shadow1 * 0.6 + diff2 * shadow2 * 0.4) 
            + vec3(1.0) * (spec1 * shadow1 * 0.8 + spec2 * shadow2 * 0.5);
        
        // Fresnel rim
        float fresnel = pow(1.0 - abs(dot(n, viewDir)), 3.0);
        col += vec3(0.6, 0.9, 1.0) * fresnel * 0.5;
    } else {
        // Starfield background
        vec3 stars = vec3(0.02, 0.03, 0.06);
        float star = fract(sin(dot(uv, vec2(12.9898, 78.233))) * 43758.5453);
        if(star > 0.995) stars += vec3(0.8, 0.9, 1.0) * (star - 0.995) * 200.0;
        col = stars;
    }
    
    // Vignette
    float vignette = 1.0 - length(uv) * 0.5;
    col *= vignette;
    
    // Intensity boost
    col *= 1.4;
    
    // Gamma
    col = pow(col, vec3(0.9));
    
    fragColor = vec4(clamp(col, 0.0, 1.0), 1.0);
}

void main() {
    mainImage(gl_FragColor, gl_FragCoord.xy);
}

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