Project_2026-01-24_14-18-52

GLSL shader by scry · created 2026-01-24 · 10s loop · 2 passes

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.  //1 degree
#define time iTime*2.*pi/10. //sin(time) loops 10 seconds
#define R iResolution.xy //shorthand
#define ar R.x/R.y //aspect ratio
#define M iMouse //shorthand
#define xm (M.xy/R) //normalized mouse
#define nm ((xm.xy-0.5)*vec2(ar,1.)+0.5) //aspect ratio correction
vec3 cs = vec3(1.,2.,3.);
mat2 r2d(float a) {
    return mat2(cos(a),sin(a),-sin(a),cos(a));
}

vec3 rgb2hsv(vec3 c) {
    vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
    vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
    vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
    float d = q.x - min(q.w, q.y);
    float e = 1.0e-10;
    return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}

vec3 hsv2rgb(vec3 c) {
    vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
    vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
    return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}

Buffer A (iChannel0)

// Apollonian Gasket using Inversion

vec3 palette(float t) {
    return 0.5 + 0.5*cos(6.28318*(t + vec3(0.0, 0.33, 0.67)));
}

float circle(vec2 p, vec2 c, float r) {
    return length(p - c) - r;
}

vec2 invert(vec2 p, vec2 c, float r) {
    vec2 d = p - c;
    float r2 = r * r;
    float len2 = dot(d, d);
    return c + d * r2 / len2;
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = fragCoord.xy / iResolution.xy;
    vec2 tv = uv;
    uv -= 0.5;
    uv.x *= ar;
    
    vec3 col = vec3(0.);
    
    // Animated Apollonian gasket setup
    float t = time;
    float scale = 0.8 + 0.2 * sin(t);
    
    vec2 c1 = vec2(0., 0.577) * scale;
    vec2 c2 = vec2(-0.5, -0.289) * scale;
    vec2 c3 = vec2(0.5, -0.289) * scale;
    float r_outer = 0.5;
    
    // Rotate the entire gasket
    float angle = sin(t * 0.5) * 0.3;
    mat2 rot = r2d(angle);
    c1 = rot * c1;
    c2 = rot * c2;
    c3 = rot * c3;
    
    vec2 p = uv;
    float minDist = 1e10;
    float colorAccum = 0.0;
    
    // Iterative circle inversion (limited iterations for performance)
    for(int i = 0; i < 160; i++) {
        // Check distance to three outer circles
        minDist = min(minDist, abs(circle(p, c1, r_outer)));
        minDist = min(minDist, abs(circle(p, c2, r_outer)));
        minDist = min(minDist, abs(circle(p, c3, r_outer)));
        
        colorAccum += float(i) * 0.1;
        
        // Invert through closest circle
        float d1 = length(p - c1);
        float d2 = length(p - c2);
        float d3 = length(p - c3);
        
        if(d1 < d2 && d1 < d3) { p = invert(p, c1, r_outer); colorAccum += 0.3; }
        else if(d2 < d3) { p = invert(p, c2, r_outer); colorAccum += 0.5; }
        else { p = invert(p, c3, r_outer); colorAccum += 0.7; }
    }
    
    float intensity = smoothstep(0.01, 0.0, minDist);
    col = palette(colorAccum + t * 0.2 + length(uv) * 0.5) * intensity;
    //col += vec3(0.1, 0.15, 0.2) * (1.0 - intensity) * 0.3;
    col += vec3(0.)*(1.-intensity)*0.3;
    vec3 bg = texture(iChannel0,tv).rgb;
    tv -= 0.5;
    bg = rgb2hsv(bg);
    float ta = bg.x*3.+time*4.;
    tv += vec2(sin(ta),cos(ta))*(1./R);
    tv += 0.5;
    vec3 bg1 = texture(iChannel0, tv).rgb * 0.97;
    bg1 = rgb2hsv(bg1);
    bg1.x += bg.z*0.005;
    //bg1.z -= 0.0;
    
    bg1 = hsv2rgb(bg1);
    col += bg1*0.99;
    fragColor = vec4(col, 1.0);
}

Image

Not used

More shaders by scry

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

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

Account

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