How it works
The picture on this page is wet paint. Drag through it and a small, viscous, incompressible flow carries the paint along, curling it into eddies behind the brush and stretching it into glossy ribbons. After about three seconds it relaxes back to exactly the picture it was. What gets moved is not the image but a field of offsets D: the paint shown at x is the untouched picture read at x + D(x). Only that smooth warp field is ever advected and resampled. The picture is read fresh from a pristine texture every frame, so the type, the brush bristles and the film grain stay razor-sharp however long you swirl them.
Pipeline (per frame)
pointer segment (shell) at 1280×720 @2×: canvas 2560×1440 · flow 228×128 · smear 910×512
│
├─▶ SPLAT vel RG16F 228×128 capsule a→b: v ← mix(v, v_pointer, w·grip) (while moving)
├─▶ CURL curl R16F ω = ∂v_y/∂x − ∂v_x/∂y
├─▶ VORTICITY v0 RG16F v += swirl·ω·(N_y, −N_x)·dt, N = ∇|ω| / |∇|ω||
├─▶ VISCOSITY ×n vel RG16F Jacobi on (I − ν·dt·∇²) v = v0, n = ⌈4 + 4·log2(1 + α)⌉ ≤ 24 (10 here)
├─▶ DIVERGENCE div R16F solid walls at the frame
├─▶ PRESSURE ×20 p R16F ping-pong warm start from 0.8 × last frame
├─▶ GRADIENT vel v −= ∇p → divergence-free: swirls, no bulges
├─▶ ADVECT vel semi-Lagrangian, × e^(−dt / momentum)
│
├─▶ D FORWARD tmp RG16F 910×512 D̂ = D(x − u·dt) − u·dt, u = strength·v (uv units, v read as a B-spline)
├─▶ D CORRECT D RG16F 910×512 MacCormack: D̂ + ½(D − D̃), clamped to the 4 source texels
│ × e^(−dt·(1/τ + 3·(|D|/reach)⁴)), hard cap 1.4·reach
├─▶ H BLUR x, y tmp → hb R16F wet height h = smoothstep(|D| / 0.3·reach), binomial σ ≈ 2 texels
├─▶ FIELD F RGBA16F 910×512 (D, ∇h), ∇h = Sobel of the blurred h at ±1.5 texels
└─▶ COMPOSITE canvas 2560×1440, opaque
F through a cubic B-spline (4 bilinear taps) → uv' = uv + D
picture: textureGrad(uv', ∂uv'/∂x, ∂uv'/∂y), trilinear + 8× anisotropic
split: along 0.085·D + 0.014·v; 1 tap < 0.4 px, R/G/B < 4 px, else 5 spectral
relief: picture alpha one pixel right and up through the warp (impasto, ink)
wet: darker, +22% saturation · Lambert relief · cast shadow (1 tap toward light)
sheen: key light as a disc in slope space + broad lobe, × wet
(on dark pages the lobe only lights paint with colour, tinted by it)
highlight shoulder → sRGB → ±1 LSB triangular dither
41 draws per frame (42 while the pointer moves)
PICTURE baked on load, resize and content change (12–53 ms once, measured)
oil painting GUIDE 640×360 RGBA16F (underpainting + stroke angle) → PAINT: 4 stroke layers
photograph PHOTO shader (dunes, sun, haze, grain)
editorial, poster Canvas2D → RGBA8 → FINISH (paper fibre / grain, height from ink or luminance)
→ SRGB8_ALPHA8 2560×1440 + mipmaps, MIRRORED_REPEAT; alpha holds the picture's height
The ideas that matter
- Advect the warp, never the picture. A dye-style smear advects the image itself. Every frame resamples it bilinearly, and after a second of swirling the type is soup. Here the paint is a material map:
φ(x) = x + D(x)says where the paint now atxcame from. It is carried by the flow like any passive scalar,φ'(x) = φ(x − u·dt), which rearranges toD'(x) = D(x − u·dt) − u·dt. The composite reads the pristine picture once, atuv + D. The warp is smooth, so resampling it costs nothing visible, and the picture is never touched. You can see it in the editorial preset: a word dragged into a spiral keeps hairline serifs. - Store the offset, in half floats. Absolute UVs near 1.0 resolve to about 1/2048 in half precision, about 1.25 px on a 2560 px canvas. Offsets live near zero, where RG16F is fine-grained. Relaxing in 8 bits would stall: multiplicative decay rounds 3/255 back to 3/255 forever and leaves a permanent faint warp. With half floats,
e^(−dt/τ)runs all the way down. - Relax with a time constant, not a per-frame factor. The healing is
D *= e^(−dt/τ), so a 120 Hz display heals exactly as fast as a 60 Hz one. A per-frame 0.98 would halve the smear's life on a ProMotion Mac. The same goes for the flow's momentum and the brush grip. Grip is a mix per splat, so it is converted with1 − (1 − grip)^(60·Δt), where Δt is the real time since the last splat, and the brush pulls toward the shell's smoothed pointer velocity, not the segment length divided by this frame's dt. A 120 Hz display fed 60 Hz pointer events splats only every other frame. Each splat then pulls exactly as hard as at 60 Hz, instead of the brush alternating between no pull and a target twice as fast. A second decay term,3·(|D|/reach)⁴, is negligible for small smears but steep near the reach, so long drags saturate softly. There is no hard plateau whose edge would light up as a false crease. - A real incompressible flow under the brush. The brush mixes the velocity toward the pointer's (capped grip, never added), so the paint under your finger travels with it. The pressure projection then forces the displaced paint to go somewhere. It returns along both sides of the stroke as a pair of counter-rotating eddies, which is where the S-curves and folds come from. Implicit viscosity, Jacobi steps on
(I − ν·dt·∇²) v = v₀, makes those eddies big and syrupy instead of fine and smoky. Jacobi spreads about one cell per step, so the step count grows withα = ν·dtper cell² (10 at the default, up to 24 on a fine flow grid or a 30 Hz frame). With a fixed count, the slider would saturate and the paint would get thinner at a higher flow resolution. The divergence-free flow is why the warp reads as liquid rather than rubber: nothing bulges or pinches. - MacCormack on the warp. A plain semi-Lagrangian step blurs the warp a little each frame, so tight curls unwind into mush. One extra backward pass estimates that error and cancels half of it. Clamping to the four texels the forward step read from keeps the correction from inventing new extremes. The cost is a 910×512 pass. The same lesson applies to dye in the library's fluid trails, applied here to the offsets.
- Smooth reconstruction, honest filtering. The field is read through a cubic B-spline built from four bilinear taps (Sigg & Hadwiger). Lines bent by the smear therefore have no kinks every 2.8 px where the field texels change, and the highlights don't facet. The D passes read the velocity through the same B-spline. A bilinear velocity has a gradient that jumps at every flow cell, and the warp would inherit those kinks as faint creases. The picture is read with
textureGradusing the screen derivatives of the warped coordinate. Paint compressed into a fold drops to a coarser mip instead of sparkling, stretched paint stays at full detail, and the derivatives are taken outside the RGB-split branch, where they are still defined. - RGB split along the flow, only where paint moved. The fringe vector is
0.085·D + 0.014·v, so fringes appear along the direction the paint travelled, bloom during fast strokes and fade as it heals. Above 4 px of spread it takes 5 taps with triangular R/G/B weights normalised per channel. That gives a smooth spectral smear with no colour cast. Under 4 px, one tap per channel is indistinguishable, and under 0.4 px it is a single tap. In an A/B run, tiering cut about 0.7 ms per frame at the default preset. - Wetness is height, and light lives in slope space. The displaced paint is treated as a raised layer,
h = smoothstep(|D| / (0.3·reach)). Its gradient tilts the normal, and so does the picture's own height (stroke impasto, ink coverage, dune relief), which is differentiated in screen space through the warp. So a smeared brush stroke shows its bristle ridges catching the light. The key light is a disc placed where the slope equals the half-vector's tilt (−0.24, 0.29). Flat paint sits 0.38 away and can never catch it, so there is no haze over the still picture. Gloss sets both the disc's edge and its peak: satin is a soft, dim cone over a broad sheen, lacquer a crisp, bright disc. The disc edge also widens byfwidthof the slope distance, so fast-turning creases antialias. On dark pages the broad lobe lights only paint that has colour of its own, and takes its tint. Black paint shows just the crisp glint, never a milky grey sheet. Wet paint is also darker and more saturated, and a single extra field tap toward the light casts a soft shadow below-right of the raised smear. On the light editorial page that shadow is what makes the stroke read as raised. - Light a smoothed height, warp with the sharp one. A fold squeezes paint into a filament far thinner than the 128-cell flow that made it. Its exact width wobbles with the flow grid along its length. Differentiated raw, that wobble breaks the highlight into a beaded "string of pearls", and the texel-scale crinkle that MacCormack and half-float rounding leave in
Dfrays highlight edges. So the wet height is blurred once (binomial, σ ≈ 2 field texels) and then differentiated with a Sobel at ±1.5 texels. Only the lighting sees the blur. The warp, and with it the picture's geometry, stays exactly as sharp. - Pictures you can smear. Over flat colour a warp is invisible. Everything here has structure at several scales: stroke edges, bristles, serifs, grid lines, dune ripples. The oil painting is four layers of strokes, coarse to fine, each grid cell owning one stroke. With a centre jitter of ±0.3 cell and a half-length under 1.2 cells, a 3×3 neighbourhood finds every stroke that can reach a pixel. Strokes take the underpainting colour at their centre (flat colour per stroke is what reads as painted), follow a direction field (streamlines of the sky's swirl, circles round the sun, horizontals on the sea), and blend by a weighted z-order, so the topmost dominates with soft edges. The dusk photograph gets the same treatment at photographic scale. Wind-sheared cirrus runs across the whole sky, two hazy far ranges sit on the horizon, every dune face carries wind ripples, and the silhouettes are antialiased. Dune crests are rounded: the windward rise and the slip face are joined by a smooth min, so a fold bends a curve instead of stepping a cusp into a saw-toothed mesa. Bristle frequency is capped by the stroke's width in pixels, because sub-pixel streaks would alias the moment the warp moves them.
- Grain is part of the picture. The photograph's film grain and the poster's print grain are baked into the texture, so they smear with the emulsion instead of sitting on top as a screen-space overlay. Heights are computed before the grain is added, so the grain never glitters in the wet highlight. The final pass adds a static ±1 LSB triangular dither after the sRGB encode, which keeps the large dusk gradients free of banding without visible shimmer.
- Stopping cleanly. The shell stops the loop 7 s after the last activity. The page keeps itself awake beyond that until even a full-reach smear,
reach · e^(−t/τ), has healed to under half a pixel (capped at 40 s), so the picture never freezes half-healed. At the default 1.2 s relax time that is about 7.8 s after the last stir. With an 8 s relax time it is the 40 s cap.
Parameters
Presets
Performance & compatibility
- Measured by the harness on 2026-10-31: Chrome, ANGLE-Metal, an Apple-silicon Mac, 1280×720 at DPR 2 (a 2560×1440 backing store), during its 1.5 s pointer sweep with the default Oil painting preset. There was no quiet window: two to eight other pages’ harnesses and capture scripts shared the GPU throughout, and the same build swung by 2–3× from one run to the next. Over 15 runs of this build the GPU read 3.6–11.4 ms mean and 6.0–21.9 ms p95 per frame. The three least contended runs read 3.6–4.0 ms mean and 6.0–8.6 ms p95, and the final full run, started with one other harness active, read 4.35 / 6.21 ms. For a quiet reference, the previous build, without the two lighting blur passes and the B-spline velocity reads, measured 2.5 / 4.7 ms on an idle machine. An interleaved A/B of the two builds on the same shared GPU found the difference smaller than the run-to-run noise (median 4.3 vs 4.7 ms). JS took 0.05–0.10 ms per frame at a steady 60 fps (p95 frame time 16.7–16.8 ms).
- Where the time goes. A/B runs under the same sweep: turning the RGB split off saves about 0.5 ms now that it is tiered (about 1 ms before). Dropping the smear resolution to 256 saves about 0.6 ms. Switching viscosity off, which skips 10 of the 41 draws, saves about 0.1 ms. The 35 solver passes touch only 29k texels each, and the six 910×512 smear passes (MacCormack, the two lighting blurs, the field) are cheap too. The cost is the full-resolution composite: 4 field taps, 1 velocity tap, 1 shadow tap and 3–7 trilinear-anisotropic picture taps over 3.7 MP. Memory: the picture is 19.7 MB (2560×1440 sRGB8 plus mips), the smear fields 10.2 MB, the flow under 1 MB.
- Baking the picture happens only on load, resize and content change. Measured with a forced GPU sync at 2560×1440: oil painting 25–33 ms, photograph 13–23 ms, editorial 12–19 ms (88 ms the first time, while system fonts load), poster 29–79 ms (Canvas2D glow blur). The editorial and poster layouts reflow for portrait screens. A resize, or a change of either resolution, keeps the smear:
Dand the velocity are resampled into the new targets (velocity rescaled to the new cell size) before the old ones are freed. - Requirements. WebGL2 with
EXT_color_buffer_float, for the RG16F/R16F/RGBA16F targets. Half-float linear filtering is core WebGL2, so nothing depends onOES_texture_float_linear. Anisotropic filtering is used when present. Without WebGL2 the shell shows a message card over the poster frame. - Mobile. On coarse pointers the canvas is capped at DPR 1.5 (585×1266 on a 390 px phone). The Flow and Smear resolution sliders top out at 112 and 384 there, so the values shown are the values used; the embed caps them further, at 96 and 256. The page has no horizontal overflow, and the controls become a bottom sheet. The effect plays while you drag. In an isolated emulated 390 px probe it held 60 fps both during the ghost stroke and during a scripted touch drag, at 2.1–4.7 ms GPU mean. The harness’s own touch run read 44–46 fps while other harnesses shared the GPU.
- Idle, reduced motion, embed. The loop stopped 8.8–9.1 s after the harness’s last pointer move (the shell’s 7 s idle timer plus the settle margin described above), with no frames after. It also pauses off-screen and in hidden tabs. Under
prefers-reduced-motionthe page simulates 130 frames of the ghost stroke and shows that single smeared frame, with a “Play anyway” button. The gallery embed renders at DPR 1 with the flow grid capped at 96 and the smear field at 256, and the ghost brush keeps stirring (30–31 frames per 500 ms in the harness).
References & credits
- Jos Stam, “Stable Fluids”, SIGGRAPH 1999: dgp.toronto.edu/…/ns.pdf. The semi-Lagrangian advection and pressure projection behind the flow. Paper, no code used.
- Mark Harris, “Fast Fluid Dynamics Simulation on the GPU”, GPU Gems ch. 38 (NVIDIA, 2004): developer.nvidia.com/gpugems. The source of the Jacobi pressure and viscosity passes.
- Pavel Dobryakov, WebGL-Fluid-Simulation: github.com/PavelDoGreat/WebGL-Fluid-Simulation (MIT). The canonical WebGL formulation of curl and vorticity confinement that the library's reference trail follows. This page's solver is written from scratch in that style.
- A. Selle, R. Fedkiw, B. Kim, Y. Liu, J. Rossignac, “An Unconditionally Stable MacCormack Method”, J. Sci. Comput. 35 (2008): doi.org/10.1007/s10915-007-9166-4. Paper, no code used. The source of the forward/backward error correction with the limiter clamp, applied here to the warp field.
- OGL
Flowmap: github.com/oframe/ogl (Unlicense). The idea of a bounded mix-toward-velocity cursor stamp. The stamp-only flowmap it uses (distortion fades in place) is the simpler alternative this page goes beyond. No code used. - C. Sigg and M. Hadwiger, “Fast Third-Order Texture Filtering”, GPU Gems 2 ch. 20 (NVIDIA, 2005): developer.nvidia.com/gpugems. The cubic B-spline from four bilinear taps.
- M. Jarzynski and M. Olano, “Hash Functions for GPU Rendering”, JCGT 9(3), 2020: jcgt.org/published/0009/03/02. The pcg2d hash used for noise, stroke placement and dither.
- Mikkel Gjøl, “Banding in Games: A Noisy Rant”: loopit.dk/banding_in_games.pdf. Triangular dither applied after the display encode.
- Alex Vlachos, “Water Flow in Portal 2”, SIGGRAPH 2010: advances.realtimerendering.com. The classic flowmap and the warning that distortion only convinces over about a third of the pattern size, which is why the reach is soft-capped.
- The library's reference cursor trail (grip splats, capsule segments, implicit viscosity) and the research notes behind this page:
research/distortion-glass-post.md(flowmap and displacement distortion, the advected-displacement variant, theliquid-smearcandidate) andresearch/gradient-mesh.md(dithering and grain). Typefaces are the visitor's system fonts (Didot, Iowan Old Style, Avenir Next and their fallbacks). Nothing is downloaded.