Turbulent Flow

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

Curl noise fluid dynamics with domain warping and vorticity visualization.

Tags: 2D, Fluid, Curl Noise, FBM

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)

// Turbulent Flow - Complex curl noise with fbm layering
// Fluid dynamics visualization

// Hash function
float hash(vec2 p) {
    return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
}

// 2D Noise
float noise(vec2 p) {
    vec2 i = floor(p);
    vec2 f = fract(p);
    f = f * f * (3.0 - 2.0 * f);
    
    float a = hash(i);
    float b = hash(i + vec2(1.0, 0.0));
    float c = hash(i + vec2(0.0, 1.0));
    float d = hash(i + vec2(1.0, 1.0));
    
    return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
}

// FBM - Fractal Brownian Motion
float fbm(vec2 p) {
    float value = 0.0;
    float amplitude = 0.5;
    float frequency = 1.0;
    
    for(int i = 0; i < 5; i++) {
        value += amplitude * noise(p * frequency);
        amplitude *= 0.5;
        frequency *= 2.0;
    }
    return value;
}

// Curl noise - returns divergence-free velocity field
vec2 curl(vec2 p) {
    float eps = 0.01;
    
    // Sample potential field
    float n1 = fbm(p + vec2(eps, 0.0));
    float n2 = fbm(p - vec2(eps, 0.0));
    float n3 = fbm(p + vec2(0.0, eps));
    float n4 = fbm(p - vec2(0.0, eps));
    
    // Curl = (dP/dy, -dP/dx) where P is potential
    float dx = (n1 - n2) / (2.0 * eps);
    float dy = (n3 - n4) / (2.0 * eps);
    
    return vec2(dy, -dx);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
    vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
    float t = iTime * 0.15;
    
    // Domain warp for complexity
    vec2 q = vec2(fbm(uv + t), fbm(uv + vec2(5.2, 1.3) + t * 0.7));
    vec2 r = vec2(fbm(uv + q + vec2(1.7, 9.2) + t * 0.5), 
                  fbm(uv + q + vec2(8.3, 2.8) + t * 0.3));
    
    // Get curl velocity at warped position
    vec2 vel = curl(uv + r * 2.0 + t);
    
    // Velocity magnitude and direction
    float mag = length(vel);
    float angle = atan(vel.y, vel.x);
    
    // Color by velocity
    vec3 col = 0.5 + 0.5 * cos(vec3(0.0, 2.09, 4.18) + angle + mag * 2.0 + t);
    
    // Add streamlines (advect particles)
    float stream = 0.0;
    vec2 p = uv * 3.0;
    for(int i = 0; i < 20; i++) {
        vec2 v = curl(p + t);
        p += v * 0.02;
        float d = length(uv - p * 0.33);
        stream += smoothstep(0.02, 0.0, d) * 0.05;
    }
    col += vec3(0.9, 0.95, 1.0) * stream;
    
    // Vorticity visualization (curl magnitude)
    float vort = fbm(uv * 2.0 + r) * mag;
    col = mix(col, vec3(1.0, 0.6, 0.3), vort * 0.3);
    
    // Boost and tone map
    col *= 1.2;
    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