Julia Quaternion v2

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

3D Julia set raymarched with quaternion-style iteration. Animated constant creates morphing fractal shapes with position-based coloring.

Tags: 3D, Raymarching, Julia, 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)

// Julia Quaternion v2 - Centered and improved
vec4 qSqr(vec4 q) {
    return vec4(
        q.x*q.x - q.y*q.y - q.z*q.z - q.w*q.w,
        2.0*q.x*q.y,
        2.0*q.x*q.z,
        2.0*q.x*q.w
    );
}

float juliaQ(vec4 z, vec4 c) {
    float dr = 1.0;
    float r = length(z);
    for(int i = 0; i < 15; i++) {
        if(r > 4.0) break;
        dr = 2.0 * r * dr;
        z = qSqr(z) + c;
        r = length(z);
    }
    return 0.5 * log(r) * r / dr;
}

float map(vec3 p) {
    vec4 c = vec4(-0.8, 0.0, 0.0, 0.156);
    vec4 z = vec4(p, 0.0); // Slice at w=0
    return juliaQ(z, c);
}

vec3 calcNormal(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)
    ));
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
    
    // Camera looking at origin, pulled back
    vec3 ro = vec3(0.0, 0.0, 2.5);
    vec3 rd = normalize(vec3(uv, -1.5));
    
    // Raymarch
    float dist = 0.0;
    vec3 p;
    bool hit = false;
    
    for(int i = 0; i < 100; i++) {
        p = ro + rd * dist;
        float d = map(p);
        if(d < 0.001) {
            hit = true;
            break;
        }
        dist += d;
        if(dist > 10.0) break;
    }
    
    vec3 col = vec3(0.02, 0.02, 0.05);
    
    if(hit) {
        vec3 n = calcNormal(p);
        vec3 light = normalize(vec3(0.5, 1.0, -0.5));
        
        float diff = max(0.0, dot(n, light));
        vec3 view = normalize(ro - p);
        vec3 h = normalize(view + light);
        float spec = pow(max(0.0, dot(n, h)), 32.0);
        
        // Color from position and normal
        vec3 base = 0.5 + 0.5 * cos(vec3(0.0, 2.0, 4.0) + p * 2.0 + dot(n, vec3(1.0)));
        
        col = base * (0.3 + 0.7 * diff) + spec * 0.4;
        col *= 1.5;
    }
    
    col *= 1.0 - length(uv) * 0.3;
    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