Ink in water
glint · Examples · Tutorials · Gallery
Coloured ink dropped into swirling water: a feedback pass carries the ink along a curl-noise flow, a second pass shows it on white paper. Click to drop ink.

An example in glint, a free live shader editor in the browser: the GLSL code floats over the running picture and recompiles as you type.
The code
2 passes, drawn in this order each frame, in GLSL.
Ink: fragment shader
#version 300 es
precision highp float;
uniform sampler2D feedback;
uniform vec2 resolution;
uniform float time;
uniform float timeDelta;
uniform int frame;
uniform vec2 mouse;
uniform vec3 mouseButtons;
in vec2 v_texcoord;
out vec4 fragColor;
float hash(float n) { return fract(sin(n * 127.1) * 43758.5453); }
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
vec2 hash2(float n) { return fract(sin(vec2(n * 127.1, n * 269.5)) * 43758.5453); }
mat2 rot(float a) { float c = cos(a), s = sin(a); return mat2(c, s, -s, c); }
vec3 pal(float t) { return 0.5 + 0.5 * cos(6.28318 * (t + vec3(0.0, 0.33, 0.67))); }
float noise(vec2 p) {
vec2 i = floor(p), f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(mix(hash(i), hash(i + vec2(1, 0)), f.x), mix(hash(i + vec2(0, 1)), hash(i + 1.0), f.x), f.y);
}
// Curl of a noise field: a flow that swirls without piling up.
vec2 flow(vec2 p) {
float e = 0.01;
float n = noise(p + vec2(0, e)) - noise(p - vec2(0, e));
float m = noise(p + vec2(e, 0)) - noise(p - vec2(e, 0));
return vec2(n, -m) / (2.0 * e);
}
void main() {
vec2 st = gl_FragCoord.xy / resolution;
if (frame < 2) { fragColor = vec4(0.0); return; }
// Everything per frame is scaled by the frame's length (1 at 60 fps), so it flows the same at any frame rate.
float s = min(timeDelta * 60.0, 4.0);
vec2 p = st * vec2(resolution.x / resolution.y, 1.0) * 2.5;
vec2 v = flow(p + time * 0.05) * 0.0012 * s;
vec3 ink = texture(feedback, st - v).rgb * pow(0.997, s);
// Drops from three wandering pipettes, and the mouse.
for (int i = 0; i < 3; i++) {
float fi = float(i);
vec2 at = 0.5 + 0.3 * vec2(sin(time * (0.21 + fi * 0.07) + fi * 2.0), cos(time * (0.17 + fi * 0.05) + fi));
float drip = exp(-dot(st - at, st - at) * 3000.0) * (0.5 + 0.5 * sin(time * 1.3 + fi * 2.1));
ink += drip * 0.08 * s * (1.0 - pal(fi * 0.33 + 0.1));
}
if (mouseButtons.x > 0.5) ink += exp(-dot(st - mouse, st - mouse) * 2000.0) * 0.2 * s * (1.0 - pal(time * 0.1));
fragColor = vec4(min(ink, vec3(3.0)), 1.0);
}Paper: fragment shader
#version 300 es
precision highp float;
uniform sampler2D prevPass;
uniform vec2 resolution;
in vec2 v_texcoord;
out vec4 fragColor;
void main() {
vec2 st = gl_FragCoord.xy / resolution;
vec3 ink = texture(prevPass, st).rgb;
// Ink absorbs light: subtract from white paper.
vec3 col = vec3(0.96, 0.94, 0.9) * exp(-ink * 2.2);
fragColor = vec4(col, 1.0);
}More More GLSL examples
Mandelbrot zoom · Lava lamp · Circuit board · Snowfall · Infinite spheres · Night sky · Dithered retro · Chrome balls