Voronoi Interference v3

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

True voronoi without grid quantization

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)

// Voronoi Interference v3 - True voronoi, no grid
#define PI 3.14159265359

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

float hash(float n) {
    return fract(sin(n) * 43758.5453);
}

vec2 hash2(vec2 p) {
    return fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))) * 43758.5453);
}

// True voronoi - cell points scattered in continuous space
vec4 voronoi(vec2 uv, float density) {
    // Scale so we get ~density cells across the space
    uv *= density;
    
    vec2 cell = floor(uv);
    vec2 frac = fract(uv);
    
    float minDist = 8.0;
    float secondMinDist = 8.0;
    vec2 nearestCell = cell;
    vec2 localUV = frac;
    float cellHash = 0.0;
    
    // Check neighboring cells for nearest point
    for(int y = -1; y <= 1; y++) {
        for(int x = -1; x <= 1; x++) {
            vec2 gridCell = cell + vec2(float(x), float(y));
            // Random point within this grid cell
            vec2 cellPoint = gridCell + hash2(gridCell);
            // Vector from our position to the cell point
            vec2 delta = uv - cellPoint;
            float dist = length(delta);
            
            if(dist < minDist) {
                secondMinDist = minDist;
                minDist = dist;
                nearestCell = gridCell;
                localUV = delta;  // Local coords relative to cell center
                cellHash = hash(dot(gridCell, vec2(12.9898, 78.233)));
            } else if(dist < secondMinDist) {
                secondMinDist = dist;
            }
        }
    }
    
    return vec4(localUV, minDist, cellHash);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
    
    // True voronoi with ~4 cells across
    vec4 voro = voronoi(uv, 4.0);
    vec2 cellUV = voro.xy;
    float cellDist = voro.z;
    float cellHash = voro.w;
    
    // Rotate based on cell hash
    float angle = cellHash * PI * 2.0 + iTime * 0.3;
    cellUV *= rot(angle);
    
    // Two wave sources per cell
    vec2 src1 = vec2(0.3 * sin(iTime + cellHash * 5.0), 0.0);
    vec2 src2 = vec2(-0.3 * cos(iTime + cellHash * 3.0), 0.0);
    
    float d1 = length(cellUV - src1);
    float d2 = length(cellUV - src2);
    
    // Per-source coloring
    vec3 col;
    bool is_src1 = d1 < d2;
    float wave;
    
    if(is_src1) {
        wave = sin(d1 * 20.0 - iTime * 2.0);
        col = vec3(0.9, 0.3, 0.5) * (0.5 + 0.5 * wave);
    } else {
        wave = sin(d2 * 20.0 + iTime * 2.0);
        col = vec3(0.2, 0.7, 1.0) * (0.5 + 0.5 * wave);
    }
    
    // Glow
    float glow = exp(-min(d1, d2) * 4.0);
    col += vec3(1.0, 0.9, 0.6) * glow * 0.5;
    
    // Subtle cell edge
    col *= 0.9 + 0.1 * smoothstep(0.0, 0.5, cellDist);
    
    // Vignette
    float vignette = 1.0 - length(uv) * 0.4;
    col *= vignette;
    
    // Boost
    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