Crystal Core

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

Octahedral crystal with fresnel rim lighting and orbiting spheres

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)

// Crystal Core - Octahedral crystal with fresnel rim
#define PI 3.14159265359
#define MAX_STEPS 80
#define MAX_DIST 20.0
#define EPS 0.001

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

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 map(vec3 p, float t) {
    vec3 crystalP = p;
    crystalP.xz *= rot(t * 0.2);
    crystalP.yz *= rot(t * 0.15);
    float crystal = sdOctahedron(crystalP, 1.2);
    
    float t1 = t * 0.5;
    vec3 s1Pos = vec3(cos(t1) * 2.0, sin(t1 * 0.7) * 0.5, sin(t1) * 2.0);
    float s1 = sdSphere(p - s1Pos, 0.25);
    
    float t2 = t * 0.7 + 2.0;
    vec3 s2Pos = vec3(cos(t2) * 2.5, sin(t2 * 0.4) * 0.3, sin(t2) * 2.5);
    float s2 = sdSphere(p - s2Pos, 0.2);
    
    float t3 = t * 0.4 + 4.0;
    vec3 s3Pos = vec3(cos(t3) * 1.7, sin(t3 * 0.6) * 0.4, sin(t3) * 1.7);
    float s3 = sdSphere(p - s3Pos, 0.15);
    
    return min(min(min(crystal, s1), s2), s3);
}

vec3 calcNormal(vec3 p, float t) {
    vec2 e = vec2(EPS, 0.0);
    return normalize(vec3(
        map(p + e.xyy, t) - map(p - e.xyy, t),
        map(p + e.yxy, t) - map(p - e.yxy, t),
        map(p + e.yyx, t) - map(p - e.yyx, t)
    ));
}

vec3 crystalColor(vec3 p, float t) {
    float angle = atan(p.z, p.x) + t * 0.3;
    float height = p.y * 0.5;
    return vec3(
        0.5 + 0.4 * sin(angle + height),
        0.4 + 0.4 * sin(angle + height + 2.09),
        0.6 + 0.3 * sin(angle + height + 4.18)
    );
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
    float t = iTime;
    
    float camAngle = t * 0.1;
    vec3 ro = vec3(cos(camAngle) * 5.0, 2.0 + sin(t * 0.1), sin(camAngle) * 5.0);
    vec3 lookAt = vec3(0.0, 0.0, 0.0);
    
    vec3 fwd = normalize(lookAt - ro);
    vec3 right = normalize(cross(fwd, vec3(0.0, 1.0, 0.0)));
    vec3 up = cross(right, fwd);
    vec3 rd = normalize(fwd + right * uv.x + up * uv.y);
    
    float dist = 0.0;
    vec3 p = ro;
    bool hit = false;
    
    for(int i = 0; i < MAX_STEPS; i++) {
        p = ro + rd * dist;
        float d = map(p, t);
        if(d < EPS) {
            hit = true;
            break;
        }
        dist += d;
        if(dist > MAX_DIST) break;
    }
    
    vec3 col = vec3(0.0);
    
    if(hit) {
        vec3 normal = calcNormal(p, t);
        vec3 viewDir = normalize(ro - p);
        vec3 lightDir = normalize(vec3(1.0, 1.0, 0.5));
        vec3 baseColor = crystalColor(p, t);
        float diffuse = max(0.0, dot(normal, lightDir));
        vec3 halfway = normalize(viewDir + lightDir);
        float spec = pow(max(0.0, dot(normal, halfway)), 64.0);
        float fresnel = pow(1.0 - abs(dot(normal, viewDir)), 4.0);
        col = baseColor * (0.1 + diffuse * 0.7) + vec3(1.0) * spec * 0.5 + vec3(0.8, 0.9, 1.0) * fresnel * 0.6;
    } else {
        col = vec3(0.05, 0.08, 0.12) * (1.0 - length(uv) * 0.3);
    }
    
    col *= 1.0 - length(uv) * 0.4;
    col *= 1.5;
    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