Particle Flow

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

Flowing particles with trails in a curl noise flow field. Divergence-free fluid-like motion.

Tags: 2D, Particles, Flow, Noise

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)

// Particle Flow - Flowing particles with trails and glow
// Curl noise-based flow field

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

float hash(vec2 p) {
    return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453);
}

// Simplex noise for flow field
vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
vec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
vec3 permute(vec3 x) { return mod289(((x*34.0)+1.0)*x); }

float snoise(vec2 v) {
    const vec4 C = vec4(0.211324865405187, 0.366025403784439,
                        -0.577350269189626, 0.024390243902439);
    vec2 i = floor(v + dot(v, C.yy));
    vec2 x0 = v - i + dot(i, C.xx);
    vec2 i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
    vec4 x12 = x0.xyxy + C.xxzz;
    x12.xy -= i1;
    i = mod289(i);
    vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0)) + i.x + vec3(0.0, i1.x, 1.0));
    vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
    m = m*m; m = m*m;
    vec3 x = 2.0 * fract(p * C.www) - 1.0;
    vec3 h = abs(x) - 0.5;
    vec3 ox = floor(x + 0.5);
    vec3 a0 = x - ox;
    m *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);
    vec3 g;
    g.x = a0.x * x0.x + h.x * x0.y;
    g.yz = a0.yz * x12.xz + h.yz * x12.yw;
    return 130.0 * dot(m, g);
}

// Curl noise for divergence-free flow
vec2 curlNoise(vec2 p) {
    float eps = 0.01;
    float n1 = snoise(p + vec2(eps, 0.0));
    float n2 = snoise(p - vec2(eps, 0.0));
    float n3 = snoise(p + vec2(0.0, eps));
    float n4 = snoise(p - vec2(0.0, eps));
    
    float dy = (n1 - n2) / (2.0 * eps);
    float dx = (n3 - n4) / (2.0 * eps);
    
    return vec2(dx, -dy);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
    float t = iTime * 0.1;
    
    vec3 col = vec3(0.02, 0.03, 0.05);
    
    // Flow field evaluation at this point
    vec2 flow = curlNoise(uv * 2.0 + t * 0.5);
    
    // Multiple particle layers
    for(float i = 0.0; i < 5.0; i++) {
        float fi = i / 5.0;
        
        // Particle grid
        vec2 grid = uv * (3.0 + fi * 2.0);
        vec2 cell = floor(grid);
        vec2 frac = fract(grid);
        
        // Random offset per cell
        vec2 offset = hash2(cell + i * 10.0 + floor(t * 2.0));
        vec2 particlePos = offset;
        
        // Move particle along flow field
        vec2 flowAtParticle = curlNoise(cell + offset + t * (1.0 + fi));
        particlePos += flowAtParticle * 0.3 * fract(t * 2.0);
        
        // Distance to particle
        float d = length(frac - particlePos);
        
        // Particle glow
        float glow = smoothstep(0.15, 0.0, d);
        
        // Color by layer
        vec3 layerCol = 0.5 + 0.5 * cos(vec3(0.0, 2.09, 4.18) + fi * 3.0 + t);
        col += layerCol * glow * 0.5 * (1.0 - fi * 0.3);
        
        // Trail effect (elongated along flow)
        vec2 trailDir = normalize(flowAtParticle + 0.001);
        vec2 toParticle = frac - particlePos;
        float trailDist = length(toParticle - dot(toParticle, trailDir) * trailDir);
        float trailLen = abs(dot(toParticle, trailDir));
        
        float trail = smoothstep(0.05, 0.0, trailDist) * smoothstep(0.3, 0.0, trailLen);
        col += layerCol * trail * 0.3 * (1.0 - fi * 0.2);
    }
    
    // Flow field visualization (subtle background)
    float fieldMag = length(flow);
    vec2 fieldDir = flow / (fieldMag + 0.001);
    float angle = atan(fieldDir.y, fieldDir.x);
    vec3 fieldCol = 0.5 + 0.5 * cos(vec3(0.0, 2.09, 4.18) + angle + t);
    col += fieldCol * fieldMag * 0.1;
    
    // Vignette
    col *= 1.0 - length(uv) * 0.3;
    
    // Boost
    col *= 1.4;
    col = col / (1.0 + col * 0.4);
    
    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