How it works
Ink is a little heavier than water, and that is almost the whole page. A Navier–Stokes solver carries the ink’s weight in a spare channel of its velocity texture and pulls down wherever there is ink. Nothing here draws a mushroom or a finger. The caps that roll up into twin lobes, the stems they trail, and the fingers that keep splitting off them all come out of gravity plus the pressure projection: Rayleigh–Taylor instability, solved on a 455×256 grid. The colour stores pigment concentrations, not colours, and the display turns them into light with Beer–Lambert absorption. That gives pale veils, near-black cores and true subtractive mixing for free.
Pipeline (per frame)
pointer segment (shell capsule) · click = drop sim 455×256 · dye 1820×1024 · canvas 2560×1440
│
├─▶ SPLAT sim vel RGBA16F 455×256 xy → mix(v, v_ptr, 1−(1−w′·stir)^(60Δt)),
│ |v_ptr| ≤ 1.6 h/s, w′ = w (drops) or exp(−d²/(1.5r)²)
│ z (mass) += 1.6·ink·w·k w = exp(−(d²/r²)²)
│ k = 1 ± noise at 9.6/5.4 cells (pours 13/7.5)
├─▶ SPLAT dye dye RGBA16F 1820×1024 drops add, pours blend MAX, scissored to the capsule
│ cᵢ = inkᵢ·edge(d/r)·lumps; 2.5-texel edge, warped
├─▶ CURL curl R32F 455×256 ω = ∂v/∂x − ∂u/∂y
├─▶ FORCES v₀ RGBA16F v += ε(N×ω)Δt (confinement) v.y −= g′·m·Δt (buoyancy)
├─▶ VISCOUS ×8 vel Jacobi on (I − νΔt∇²)v = v₀ for xy; mass passes through
├─▶ DIVERGENCE div R32F mirror v at the walls · floor: zero-gradient outflow
├─▶ PRESSURE ×24 pres R32F ping-pong red-black SOR, ω = 1.8, first pass warm-starts ×0.85,
│ Neumann at the walls, p = 0 below the floor
├─▶ GRADIENT vel v −= ½(R−L, T−B) (the consistent factor)
├─▶ ADVECT dye hat RGBA16F 1820×1024 forward semi-Lagrangian, by the projected velocity
├─▶ MACCORMACK dye step back, correct by 0.92·½·error, clamp to 4 source
│ texels, ÷(1 + fade·Δt), −0.006·Δt bleed, floor sponge
├─▶ ADVECT vel vhat RGBA16F 455×256 forward semi-Lagrangian of (v, m)
└─▶ MACCORMACK vel v: plain result ÷(1 + 0.3·Δt); m: clamped correction
÷(1 + 0.6·fade·Δt), floor sponge
┌──────────────────────────────── display, every frame ────────────────────────────────┐
│ SOFT dye → ¼-res 4×4 box → H + V 5-tap Gaussian RGBA16F 455×256 │
│ DISPLAY → canvas, opaque RGBA8 │
│ c += e·(1.6 + 2.4e²)·max(c − soft, 0) pigment gathers at the rims (e = edges) │
│ c ×= granulation(tooth) · smoothstep(cut, 4·cut, c) ; c ← c^contrast │
│ ink: paper(tooth, fibres, mottling) · exp(−0.45·depth·Σ softᵢ(uv + off)·σᵢ) │
│ · exp(−Σ cᵢ·σᵢ) all in linear light │
│ glow: min(water, 1)·e^(−0.7Σc) + (1 − e^(−1.35E)) + hot core + 0.45·depth·halo │
│ → sRGB, ±1 LSB triangular dither │
└──────────────────────────────────────────────────────────────────────────────────────┘
PAPER (once at load) 1024² RGBA8, REPEAT + mipmaps: lit tooth · tooth height · mottling · fibres
PRE-ROLL (first frame only) 96 steps: 3 drops + the first 1.4 s of the ghost pour
44 draws per frame, +2 per pour segment, +2 per drop
The ideas that matter
- The weight rides in the velocity texture. Buoyancy needs to know where the ink is, but sampling the 1820×1024 pigment from a 455×256 grid aliases. So every splat also adds mass to the velocity texture’s spare z channel. The mass is advected with the velocity in the same pass and feeds
v.y −= g′·m·Δtin the forces pass. Every velocity shader passes z through untouched. Only the mass gets the MacCormack correction; velocity keeps the plain semi-Lagrangian result, whose numerical viscosity is part of the calm look. - Gravity alone makes the mushrooms. In 2D, a downward force that varies sideways injects vorticity along each side of a sinking blob (baroclinic torque). Those shear layers roll up into the cap’s twin lobes, a 2D slice of a vortex ring. The heavy-over-light underside then goes Rayleigh–Taylor unstable: ripples grow roughly like
exp(√(g′k)·t), each finger grows its own cap, and those split again. Vorticity confinement stays low (6). Past about 15 the ink starts to read as smoke. - Finger width is set by viscosity and the noise seeds. Rayleigh–Taylor growth is fastest at the shortest wavelength (roughly
√(g′k), an e-fold every 0.1s at 6 cells), so whatever scale the splat is seeded at shows up first. Seeds at 2.2 cells grew grid-scale “fur” on every fresh ribbon; seeds at 3–6 cells still grew slanted teeth on a fresh pour and a fuzzy crown on a fresh drop within 0.2s. The mass noise now sits at 9.6 + 5.4 cells for drops and 13 + 7.5 cells (and 0.7× the amplitude) for pours, and a light implicit viscosity (4.5, in 128-cell units, scaled by (grid/128)²) damps anything finer. More viscosity gives fewer, fatter, syrupier lobes. That is the Viscosity slider (log scale, 0.3–40), and why the Bioluminescent preset raises it to 7. At Finger noise 0 a drop rolls into a perfectly symmetric cup. - Concentrations, not colours. Each ink has an absorption coefficient σ = −ln(mass tone), computed in linear light. The display computes
T = exp(−Σ cᵢσᵢ)and multiplies the paper by it. Sumi’s tone#25272dgives σ ≈ (4.2, 4.1, 3.8): a quarter-strength veil is mid-grey and a full-strength core is near black, so the ramp by thickness comes from physics, not a hand-tuned gradient. Inks mix the way pigment does. Indigo and vermilion at half strength each come out deep aubergine (≈#4f3647). Process cyan over yellow comes out a clean green (≈#40ab3b). Adding RGB and inverting it would turn both a muddy grey-brown. - Hard edges, because Beer–Lambert stretches tails. Absorption makes faint ink visible, so a Gaussian splat’s long tail turns into a 12-CSS-pixel grey fringe and fresh drops look airbrushed. Even a super-Gaussian
exp(−(d²/r²)⁴)left about 8px of fuzz at a drop’s concentration (1.4, so cσ ≈ 6), which read as pom-poms for the first 0.3s. The pigment splat is therefore a hard disc or capsule, smoothstepped over 2.5 dye texels. The sim splat keeps the super-Gaussianexp(−(d²/r²)²), since the grid is coarse anyway. Noise warps the outline’s radius at about 7 cells rather than multiplying the tail, so beads start as crisp, irregular blobs, the way real ink enters water, and MacCormack keeps them that way. - Pours blend with MAX, drops add. A pour is a chain of overlapping capsules, one per frame. Added together, a slow stroke stacked up to c ≈ 1.5–2.5 (solid black, T ≈ e−6) and a fast one left beads at every joint. With
blendEquation(MAX)the overlaps can’t stack, so a fresh ribbon holds the strength it was laid at, about 1.1 for a slow pour down to 0.8 for a fast flick (a real brush lays less ink when it moves faster), smoothed over 0.12s so frame jitter can’t print seams. That leaves a grey-to-black ramp between fast strokes, slow strokes and the denser drops. The buoyant mass is still added and normalised by distance travelled, so the sinking doesn’t depend on speed either. - Pressure that doesn’t breathe. Large sinking plumes need a well-converged projection, or they visibly compress. Plain Jacobi barely moves screen-scale error, so this page uses red-black SOR: each pass updates one checkerboard colour from fresh neighbours and over-relaxes by 1.8. That over-relaxation is the whole gain, since plain Jacobi diverges if you try it. The gradient uses the consistent ½ factor. The research notes measured cold-start residuals of about 54% (large-scale) and 14% (mid-scale) after 20 RB-SOR passes, against 90% and 52% for 20 Jacobi passes. Here the solve runs 24 passes, warm-started from 0.85× the previous pressure.
- An open floor. With four walls, every drop ends as a black pool along the bottom. The floor is an outflow instead: pressure is 0 below the grid (Dirichlet), the divergence copies the cell’s own vertical velocity, and a sponge in the bottom 7% fades pigment and mass. Plumes rain off the page. The sides and top stay free-slip walls.
- Splats without full-screen passes. The pigment splat is drawn with blending (
FUNC_ADDorMAX) straight into the current dye texture, with a scissor box around the capsule (1.7 radii of padding, enough for the steep profile). A drop touches about 2% of the 1.9M-texel field and a pour segment well under 1%, instead of reading and writing all of it every time. Half-float blending, MAX included, is core withEXT_color_buffer_float, so this needs no extra extension. The sim-grid splat stays a ping-pong pass, because velocity has to be blended toward the pointer while mass is added. - Slightly less than full MacCormack. 2D advection conserves concentration: a filament stretched a hundredfold is still full strength, only thinner. With the full clamped correction, everything stayed solid black or blank, like marbling. A correction of 0.92 lets old wisps soften and go grey, the way ink slowly diffuses in water, while fresh structure stays crisp. Fade (÷(1 + 0.14·Δt)), a tiny linear bleed and a
smoothstep(cut, 4·cut)display cut make faint traces disappear cleanly instead of leaving a veil. - A gentle stir, so the ribbon is left behind. The pointer blends the water toward its own velocity with a grip of only 0.1, frame-rate independent, and the push is capped at 1.6 screen heights per second, so a fast flick can’t fire a jet. For pours the grip uses a plain Gaussian 1.5× wider than the ribbon, so the drag doesn’t shear the ribbon’s edge into streaks. The ribbon is therefore left in nearly still water, where it sags into hanging curtains that drip fingers: a wake that falls away from the cursor instead of covering it.
- Depth on paper, without bloom. Light passing through ink is coloured, so the shadow is too. The quarter-resolution blurred pigment, sampled toward the light (up and left), attenuates the paper with the same σ before the ink in front absorbs again. Black ink casts a grey shadow, vermilion a warm one. The paper is baked once from periodic value noise: lit tooth, a slow mottling and short bent fibres. Pigment settles into the tooth (granulation) and gathers at bloom rims (Curtis et al.’s edge darkening, here an unsharp mask in concentration space), both kept subtle by default so it reads as ink in water. The rim gain rises as e·(1.6 + 2.4e²), which leaves the presets’ low values where they were and outlines every bloom near 1.
- Glow is the same field, scattering instead of absorbing. On dark water an absorbing ink would be invisible, so glow mode lets each concentration emit its colour through a hue-preserving
1 − e−xshoulder. Dense heads burn toward white, the blurred copy adds a halo, and the water behind is dimmed bye−0.7Σc. The water term is clamped to 1, and the output is opaque, so it never depends on how a browser composites superluminous premultiplied colour. Switching Light by hand swaps in a matching paper (dark water for glow, rice paper for ink) and any ink that would vanish in the new mode (a dark ink can’t glow, a near-white ink can’t absorb), and the page theme follows the paper’s brightness, so the HUD always reads. - The water stills before the loop stops. The shell stops rendering 9s after the last activity. Over the final 2.4s the time step eases to zero, so plumes slow to a still frame instead of freezing mid-fall. The next touch resumes at full speed.
- A first frame that is already in bloom. Before the first frame is shown, the sim runs 96 steps (1.6s) off-screen. Three drops land at staggered steps, two of them in the middle of the screen, and the last 84 steps pour the first 1.4s of the ghost path, starting at the far left. The page therefore opens on a ribbon already sagging into hooked curtains, caps rolling at three depths, and a pour already moving at speed (the path’s phase puts its slow turning point inside the pre-roll). The live ghost carries on from where the pre-roll stopped and crosses the upper third while four more drops land, all in the rotating inks. On portrait screens the path and the drops sit up to 0.1 lower. Measured on untouched loads, ink spans 19–79% of the stage height at 1.0s on desktop and 22–73% on a 390px phone. The pre-roll costs about 2.5ms of JS and roughly 50ms of GPU, once.
Parameters
Presets
Performance & compatibility
- Measured by the harness (Chrome, ANGLE-Metal, Apple-silicon Mac, 1280×720 at DPR 2, so a 2560×1440 backing store), during its 1.5s pointer sweep with the default Sumi preset: GPU 2.5–4.9ms mean and 2.8–8.0ms p95 per frame across seven serial runs made while no other harness was running (one full harness run in a quiet moment read 2.6 / 2.8ms), JS 0.07–0.12ms, a steady 60 fps (p95 frame time 16.7–16.8ms, no frames over 25ms). These are round-2 numbers, after the splat and intro changes; the per-frame passes are the same as before, and the first-frame pre-roll is a one-off outside the sweep. A/B runs with passes removed give the split: the simulation step is about 2ms (red-black SOR about 0.6ms, pigment MacCormack about 0.5ms), and the display, soft copy and splats about 1.7ms. All four presets run the same passes; glow mode skips the shadow tap. The per-frame GPU timer counts work from other pages sharing the GPU: runs made while other agents’ harnesses were using it read 6.1–14.4ms mean and 12.6–22ms p95, still at 60 fps (full harness runs made with another page’s harness running alongside read 6.1–9.8ms mean and 13.8–18.3ms p95). That was contention, not this page.
- What scales the cost. 44 draws per frame, 32 of them Jacobi or SOR passes on the 116k-cell grid, where fixed per-draw overhead outweighs bandwidth. After those come the two 1820×1024 MacCormack passes and the full-resolution display, which makes six texture taps per pixel. Memory: about 45MB for the pigment (two RGBA16F ping-pong textures plus the MacCormack temporary), 5.6MB for the sim grid, 1.9MB for the soft copy and 5.6MB for the paper with mipmaps.
- Requirements. WebGL2 with
EXT_color_buffer_float, to render to RGBA16F and R32F and to blend into half floats. Without it, the page shows a message card over the captured poster frame instead. - Mobile. Tap to drop, drag to pour. On coarse pointers the canvas is capped at 1.5× DPR (585×1266 on a 390px phone), the sim at 176 cells on the short side, and the pigment at 640 (in practice the canvas’s 585). The solver drops to 16 SOR and 6 viscous passes. Sizes are in units of the short side and gravity is in screen heights, so a portrait phone keeps the same proportions and fall time. In the harness’s 390px touch run (emulated on the Mac’s GPU) dragging ran at 48–51 fps, the page has no horizontal overflow, and the controls become a bottom sheet.
- Idle and visibility. The loop eases to a stop 9s after the last activity (measured: stopped 9.05–9.07s after the last move, with no frames after). It pauses off-screen and in hidden tabs. The gallery embed renders at DPR 1 with a 144-cell sim and 400-texel pigment, and keeps dripping new drops every 1.1–2.1s.
- Reduced motion. 170 frames (2.8s) of the intro are simulated off-screen, with the pre-roll, ghost pour and drops, and shown as one still, with a “Play anyway” button. A resize resamples the fields into the new size and redraws the still, so the ink is never wiped.
References & credits
- Jos Stam, “Stable Fluids”, SIGGRAPH 1999: semi-Lagrangian advection and implicit diffusion. dgp.toronto.edu/…/ns.pdf (paper).
- Mark J. Harris, “Fast Fluid Dynamics Simulation on the GPU”, GPU Gems ch. 38, 2004: the render-to-texture formulation, Poisson solves and boundaries. developer.nvidia.com/gpugems (book text, free online).
- Ronald Fedkiw, Jos Stam, Henrik Wann Jensen, “Visual Simulation of Smoke”, SIGGRAPH 2001: vorticity confinement and the buoyancy force. web.stanford.edu/…/smoke.pdf (paper).
- Andrew Selle, Ronald Fedkiw, ByungMoon Kim, Yingjie Liu, Jarek Rossignac, “An Unconditionally Stable MacCormack Method”, J. Sci. Comput. 2008: the clamped MacCormack scheme for pigment and mass. yingjie.math.gatech.edu/…/SFKLR.pdf (paper). GPU form after Crane, Llamas & Tariq, GPU Gems 3 ch. 30 (developer.nvidia.com/gpugems3).
- Cassidy Curtis, Sean Anderson, Joshua Seims, Kurt Fleischer, David Salesin, “Computer-Generated Watercolor”, SIGGRAPH 1997: edge darkening and pigment granulation. grail.cs.washington.edu/projects/watercolor (paper).
- Robert Bridson, Fluid Simulation course notes: Boussinesq buoyancy, boundary conditions and Gauss–Seidel/SOR. cs.ubc.ca/~rbridson/… (notes).
- Pavel Dobryakov, WebGL-Fluid-Simulation: the common WebGL pass layout (curl → vorticity → divergence → pressure → gradient → advect). github.com/PavelDoGreat/WebGL-Fluid-Simulation, MIT. No code is copied; this page is written from the papers above.
- Tom Larkworthy, “Ink in water” (Observable), the cautionary example: ink faked by inverting RGB dye, whose mixes go muddy. Beer–Lambert on concentrations is the fix. observablehq.com/@tomlarkworthy/ink.
- Hash: Dave Hoskins, “Hash without Sine”. shadertoy.com/view/4djSRW, MIT.
- Engine lineage and tuning lessons: the stable-fluids cursor trail in the Russ Hype Machine page (the library’s reference implementation). Research:
research/smoke-fire-ink.md(ink-in-water recipe, Beer–Lambert, mass invel.z) andresearch/eulerian-fluids.md(projection-factor and SOR measurements, MacCormack sharpness) in this library.