Iridescent Formation

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

3D raymarched crystal formation with iridescent materials, soft shadows, and orbital animation. Features a central octahedron with rainbow surface, orbiting gold box, and raymarched shadows.

Tags: 3D, Raymarching, Iridescent, Animation, Crystal

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)

// Iridescent Formation v3 - Fixed for still image renders
// 3D raymarched crystal formation with iridescent materials

#define MAX_STEPS 100
#define MAX_DIST 20.0
#define SURF_DIST 0.001

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

float sdBox(vec3 p, vec3 b) {
    vec3 q = abs(p) - b;
    return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}

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

// Rotation matrix
mat2 rot2(float a) {
    float s = sin(a), c = cos(a);
    return mat2(c, -s, s, c);
}

// Iridescent palette based on view angle
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)
    );
}

// Scene SDF - pass time as parameter
float map(vec3 p, float t) {
    // Central octahedron crystal
    vec3 pc = p;
    pc.yz *= rot2(t * 0.3);
    pc.xz *= rot2(t * 0.2);
    float d1 = sdOctahedron(pc, 0.8);
    
    // Orbiting box
    vec3 pb = p - vec3(sin(t * 0.7) * 1.5, cos(t * 0.5) * 0.3, cos(t * 0.7) * 1.5);
    pb.xy *= rot2(t);
    pb.yz *= rot2(t * 0.7);
    float d2 = sdBox(pb, vec3(0.4));
    
    // Ground plane
    float d3 = p.y + 1.5;
    
    // Union of all objects
    float d = min(d1, d2);
    d = min(d, d3);
    
    return d;
}

// Get object ID for material selection
int getObjectID(vec3 p, float t) {
    vec3 pc = p;
    pc.yz *= rot2(t * 0.3);
    pc.xz *= rot2(t * 0.2);
    float d1 = sdOctahedron(pc, 0.8);
    
    vec3 pb = p - vec3(sin(t * 0.7) * 1.5, cos(t * 0.5) * 0.3, cos(t * 0.7) * 1.5);
    pb.xy *= rot2(t);
    pb.yz *= rot2(t * 0.7);
    float d2 = sdBox(pb, vec3(0.4));
    
    float d3 = p.y + 1.5;
    
    float min_d = min(min(d1, d2), d3);
    if (min_d == d3) return 0; // Ground
    if (min_d == d1) return 1; // Octahedron
    return 2; // Box
}

// Normal calculation
vec3 getNormal(vec3 p, float t) {
    float d = map(p, t);
    vec2 e = vec2(0.01, 0.0);
    vec3 n = d - vec3(
        map(p - e.xyy, t),
        map(p - e.yxy, t),
        map(p - e.yyx, t)
    );
    return normalize(n);
}

// Raymarched shadows
float getShadow(vec3 p, vec3 lightDir, float t) {
    float shadowDist = 0.05;
    for (int i = 0; i < 32; i++) {
        vec3 sp = p + lightDir * shadowDist;
        float d = map(sp, t);
        if (d < SURF_DIST) return 0.0;
        shadowDist += max(d, 0.05);
        if (shadowDist > 8.0) break;
    }
    return 1.0;
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    // Normalized UV
    vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
    
    // For image renders, iTime is 0, so use iDate.x (year) for some variation
    // or just use a fixed "snapshot" time that looks good
    float t = 1.5; // Fixed time for nice composition
    
    // Camera setup
    vec3 ro = vec3(0.0, 0.5, 4.0);
    vec3 lookAt = vec3(0.0, 0.0, 0.0);
    vec3 forward = normalize(lookAt - ro);
    vec3 right = normalize(cross(vec3(0.0, 1.0, 0.0), forward));
    vec3 up = cross(forward, right);
    vec3 rd = normalize(forward + uv.x * right + uv.y * up);
    
    // Raymarch
    float dist = 0.0;
    vec3 p;
    bool hit = false;
    
    for (int i = 0; i < MAX_STEPS; i++) {
        p = ro + rd * dist;
        float d = map(p, t);
        if (d < SURF_DIST) {
            hit = true;
            break;
        }
        dist += d;
        if (dist > MAX_DIST) break;
    }
    
    vec3 col = vec3(0.0);
    
    if (hit) {
        vec3 n = getNormal(p, t);
        vec3 viewDir = -rd;
        
        // Light setup - brighter for still image
        vec3 lightPos = vec3(3.0, 5.0, 3.0);
        vec3 lightDir = normalize(lightPos - p);
        
        // Material
        vec3 baseColor;
        int objID = getObjectID(p, t);
        
        if (objID == 0) {
            // Ground - slightly brighter
            baseColor = vec3(0.15, 0.18, 0.22);
        } else if (objID == 1) {
            // Octahedron - iridescent with boosted intensity
            float viewAngle = dot(n, viewDir);
            baseColor = iridescent(viewAngle, t * 0.5) * 1.5; // Boost
        } else {
            // Box - brighter gold
            baseColor = vec3(1.0, 0.75, 0.4);
        }
        
        // Blinn-Phong lighting - boosted
        vec3 halfway = normalize(viewDir + lightDir);
        float spec = pow(max(0.0, dot(n, halfway)), 32.0);
        float diffuse = max(0.0, dot(n, lightDir));
        float shadow = getShadow(p + n * 0.02, lightDir, t);
        
        // Ambient + diffuse + specular - higher ambient for visibility
        float ambient = 0.35;
        col = baseColor * (ambient + diffuse * shadow * 0.8) + vec3(spec * shadow * 0.8);
        
        // Less fog for visibility
        float fog = 1.0 - exp(-dist * 0.08);
        col = mix(col, vec3(0.1, 0.15, 0.22), fog);
    } else {
        // Background gradient - brighter
        col = vec3(0.1, 0.15, 0.22) * (1.0 - length(uv) * 0.4);
    }
    
    // Vignette - less aggressive
    float vignette = 1.0 - length(uv) * 0.25;
    col *= vignette;
    
    // Output with slight gamma correction
    fragColor = vec4(pow(col, vec3(0.9)), 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