How it works
This is a real wind tunnel: a lattice Boltzmann simulation with 41,600 cells (228×128 on screen at 2560×1440, plus a hidden border), stepped 1,920 times a second, and your cursor is a cylinder standing in its current. Past a Reynolds number of about 47 the flow behind any cylinder becomes unstable. It sheds vortices alternately off the top and bottom, and they drift away in two staggered rows: the von Kármán vortex street. Nothing here is animated by hand. The ink released at the cylinder’s rim just rides the simulated flow. At the default settings (Re ≈ 160) a probe measured one shedding cycle every 1.17 s, a Strouhal number of 0.191, close to the textbook 0.2.
Pipeline (per frame)
pointer ─▶ JS follower: chase the pointer (0.09 s), |v| ≤ 0.1 cells/step, 35 ms velocity smoothing
free stream u∞ eased (0.4 s) toward flow·(cos θ, sin θ); θ turns with wake steering
N = accumulator(substeps × 60 steps/s), capped at 2 × substeps (≈32 per 60 Hz frame)
┌── repeat N times: one fixed lattice step ─────────────────────────────────────────────────
│ LBM 3 × RGBA32F, NEAREST, 260×160 = 228×128 visible + a hidden 16-cell sponge each side
│ (g0 g1 g2 g3)(g4 g5 g6 g7)(g8 ρ ux uy), g = f − w, one draw with 3 MRT outputs
│ pull-stream (9 texelFetch) → ρ, u → BGK collide, τ_eff = Smagorinsky(τ, |Π_neq|)
│ → cylinder: mix to f_eq(ρ, u_cyl) by its soft solid fraction (2×2 supersampled)
│ → sponge: mix to f_eq(1, u∞) (inlet + outlet + far field) → guard: reset bad cells
└───────────────────────────────────────────────────────────────────────────────────────────
VEL RGBA16F 228×128, LINEAR (ux, uy, ω = ∂uy/∂x − ∂ux/∂y, ρ − 1)
DYE A RG16F 1920×1080 hat = dye(x − d(x − ½d(x))) d = u·N, u: cubic B-spline
DYE B RG16F 1920×1080 dye = limit(hat + ½(dye − hat(x + d(x + ½d(x))))) MacCormack
· e^(−Δt/life) → release on the swept rim / rake inflow
GLOW RGBA16F 640×360 → 320×180 → 160×90 bright pass + separable 9-tap Gaussian per level
DISPLAY canvas 2560×1440, opaque
dark bg + shoulder(A·colA + B·colB) + bloom
light paper · (1 − cast shadow) · exp(−A·ln(1/colA) − B·ln(1/colB)) + wet sheen
ω / |u − u∞| B-spline field, quadratic fill + iso-contours (fwidth)
cylinder from its exact SDF, ±1 LSB dither
≈ 43 draws per frame, 32 of them lattice steps
The ideas that matter
- Particles, not pressure. A lattice Boltzmann fluid does not solve for pressure. Each cell holds nine populations of fictitious particles, one at rest and eight moving to the neighbouring cells. Each step they stream one cell and collide, relaxing toward a local equilibrium with time constant τ, which sets the viscosity
ν = (τ − ½)/3. Nothing is interpolated and no Jacobi iterations go unconverged, so shear layers stay thin and roll up on their own. That is why the street is so regular without any vorticity confinement. - One fused pass per step. The nine populations, plus density and velocity in the spare channels, are packed into three RGBA32F textures and written in a single draw with three outputs (MRT). Streaming is a pull: each texel fetches the one population it needs from each neighbour, then collides in registers. The populations are stored shifted,
g = f − w(Lehmann et al.). The ~1e-4 deviations that carry the flow then aren’t swamped by the 0.03–0.44 weights. - The Mach limit fights the cursor. Lattice velocities have to stay well below the lattice sound speed (0.577 cells/step). A cursor flick can be 0.3 cells/step and would blow the simulation up. So the cylinder is a follower. It chases the pointer with a 0.09 s time constant, never faster than 0.1 cells/step, and its velocity is smoothed over 35 ms, because jerks radiate sound waves. Because that cap is per step, the default trades lattice resolution for steps: 128 cells across and 32 steps per 1/60 s let the cylinder keep up with about 1,100 CSS px/s on a 720 px-tall window. A probe’s 1,030 px/s stroke ends with the cylinder about 60 px behind the pointer; at 176 cells and 20 steps, for about the same GPU cost, it was 460 px. Steps are counted in time, not frames (capped at twice the substeps per frame), so 120 Hz screens run the same flow.
- A soft cylinder. Staircase bounce-back on a moving disc flips cells between solid and fluid every few steps, and each flip is a small pressure pulse. Here the cylinder is a penalised solid instead. After collision every cell is mixed toward the equilibrium at the cylinder’s velocity, weighted by a solid fraction that ramps over three cells and is supersampled 2×2 per cell, so a disc moving by a fraction of a cell never quantises the velocity next to it. Moving it is perfectly smooth, uncovered cells are already at equilibrium, and the clear zone you see is drawn from the exact circle.
- A hidden sponge is the whole wind tunnel. The lattice is 16 cells larger than the screen on every side. In that border, populations relax ever harder toward the free stream. Upstream it acts as the inlet; downstream it absorbs vortices and sound before they can reflect; at the sides it is the far field. Because none of it is direction-specific, the current can point anywhere and turn smoothly.
- The street trails behind you. With a fixed current the wake can only go downstream, so a cylinder parked at the downstream edge sheds straight off-screen. Wake steering turns the free stream, while you move, to come from where the cylinder is heading. That is exactly the cylinder’s own frame when it moves through still water, so the physics is unchanged. The turn rate grows with speed squared and stops when you stop, so the street keeps its direction at rest. The smoke tunnel turns it off.
- Never blows up. The viscosity slider is ν on a log scale, and τ = ½ + 3ν is clamped to [0.505, 0.9]. Smagorinsky subgrid viscosity raises the effective τ wherever strain is high, which is what keeps the default τ ≈ 0.516 (and the minimum 0.505) from going to a checkerboard. Velocity is clamped to 0.3 inside the equilibrium, and any cell whose density leaves [0.3, 3] (NaN included) is reset to the free stream. The harness drives every slider to both ends, and the worst combinations were also tested together with aggressive pointer loops: ν 0.0017 (τ 0.505), flow 0.12, cap 0.15, steering 1 and 40 substeps, at radius 0.02 on a 96 grid and radius 0.12 on a 256 grid.
- Warm start. From a symmetric start a street takes 5 s or more to develop. So the page simulates 3 s behind the scenes before its first frame, with the cylinder following the ghost path: 5,760 lattice steps, and dye every 1/30 s. The first frame (60–100ms after navigation in the harness) already shows a developed street, and the intro stroke continues seamlessly from it. A resize, a grid change or a switch to the rake warms up over the following frames instead, two 1/30 s chunks per frame (about 4× real time), while the picture fades in, so nothing freezes. A restarted lattice also gets a small sideways nudge just behind the cylinder, so it sheds within one period.
- Ink that keeps its edges. Two dyes, one per side of the oncoming flow, ride the velocity in RG16F at 1920×1080 with MacCormack advection and a min/max limiter. A frame moves the fluid up to about 3 cells. Traced in a straight line that far through a vortex, the forward and backward traces disagree by about a cell, and the correction prints that mismatch as teeth along every filament edge, spaced like the lattice. Both traces take a midpoint (RK2) step, which removes the teeth and lets the correction use its full weight of ½. Three more details remove artefacts you would otherwise see. Bilinear velocity has a gradient jump at every cell edge, which kinks stretched filaments with the cell period; a cubic B-spline does not. Dye released once per frame at the cylinder’s current position scallops the ribbons, so it is released along the capsule swept since the last frame, graded from the surface outward so each ribbon carries a gradient across its width. And fluid that enters across a screen edge carries no dye. The exception is the upstream edge with the rake on: the rake sits just off-screen, so that fluid brings its streaklines in, and the lines stay continuous at any speed.
- Light and ink. On dark the dyes emit: a hue-preserving shoulder keeps saturated cores from clipping to beige, and a three-level bloom adds the halo. On paper they absorb (Beer–Lambert) with optical depth
ln(1/colour)per unit of dye. At concentration 1 the ink is exactly the palette colour, and thicker ink deepens naturally. Its wet sheen is lit from the blurred thickness (the ¼-resolution bloom level), because differences between neighbouring dye texels would amplify the dye’s grain into stipple. The blurred thickness also casts a soft shadow about 2% of the screen down and to the right, which lifts the ink off the paper. Faint dye is cut with a smoothstep, so nothing turns to haze. Vorticity and speed are drawn from a B-spline field with anti-aliased iso-contours (fwidth), a topographic map of each vortex. Weak vorticity is cut so decayed vortices drop out cleanly, and speed is drawn mostly as contours that ramp from colour A in the outer wake to B in its core.
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). Default preset during a pointer sweep: GPU 5.4ms mean / 9.0ms p95, JS 0.07ms per frame, a steady 60 fps (final full run). Every run shared the GPU with other agents’ browsers (load average 3–4), and an idle machine was not available, so these whole-frame numbers include interleaved foreign work; across six runs they ranged from 5.4 to 6.4ms mean and 8.6 to 11.8ms p95. Timing each pass on its own, back to back, gives the cleaner figure (minimum / median of 25): 32 lattice steps with the velocity pass 0.83 / 1.0ms, the two dye passes 0.53 / 0.6ms, bloom and display 0.55 / 0.7ms, about 1.9 / 2.3ms per frame. The previous tuning (176 cells, 20 steps, straight-line dye trace) measured about 1.75ms the same way. On this GPU each lattice step costs about 0.03ms almost regardless of grid size, because each pass has a fixed cost, so trading resolution for steps (for the faster cylinder) is roughly cost-neutral. The midpoint dye trace adds about 0.2ms. Cutting the dye to 0.8× or the bright pass to one tap did not change the whole-frame numbers measurably, so both stay at full quality.
- Memory. Lattice 4.0MB (2 × 3 × 260×160 RGBA32F); dye 24.9MB (3 × 1920×1080 RG16F); velocity 0.2MB; bloom pyramid 4.8MB.
- Always alive while visible. The stream never really stops, so this is an ambient page. It runs while it is on screen and pauses when it is scrolled away or the tab is hidden (harness: 0 frames while off-screen, running again on return).
- Requirements. WebGL2 with
EXT_color_buffer_float, and three RGBA32F draw buffers in one framebuffer. fp16 is too coarse for the populations unless they are heavily shifted. Without WebGL2 or float targets, the shell shows its fallback card over the poster frame. If the RGBA32F MRT framebuffer is incomplete, the page says so specifically (tested by forcingcheckFramebufferStatusto fail). - Mobile. Drag to play. On coarse pointers the lattice is capped at 96 cells across, substeps at 24 and the dye at 720 on the short side, so the cylinder can still keep up with a finger (about 580 px/s on a 390px-wide phone). Portrait screens turn the current to run down the long side, so the street has room. At 390px the harness measured a 48.8–49.5 fps touch drag on a 780×1688 canvas, and the page issued its first frame 46ms after navigation. Rotating the phone re-warms the lattice over about 18 frames instead of freezing.
- Reduced motion. The 3 s warm start is rendered once as a still, with a “Play anyway” button. The gallery embed runs the ghost path forever at DPR 1, with the lattice capped at 88 cells, 20 substeps and dye at 400.
References & credits
- Daniel V. Schroeder, “Fluid Dynamics Simulation” (JavaScript D2Q9 BGK), the clearest readable reference for collide/stream, slider ranges and the Mach caps: physics.weber.edu/schroeder/fluids, X11-style licence. No code was copied.
- Wei Li, Zhe Fan, Xiaoming Wei, Arie Kaufman, “Flow Simulation with Complex Boundaries”, GPU Gems 2 ch. 47: packing lattice populations into RGBA textures. developer.nvidia.com/gpugems2 (book text, free online).
- Moritz Lehmann et al., “On the accuracy and performance of the lattice Boltzmann method with 64-bit, 32-bit and novel 16-bit number formats”, Phys. Rev. E 106, 015308 (2022): the shifted populations
f − w. arxiv.org/abs/2112.08926 (paper). - Shuling Hou, James Sterling, Shiyi Chen, Gary D. Doolen, “A lattice Boltzmann subgrid model for high Reynolds number flows” (1994; Fields Institute Communications 6, 1996): the Smagorinsky effective relaxation time
½(τ + √(τ² + 18√2·C·|Π|/ρ)), with the 18√2 factor as in that paper. Here C plays the role of the Smagorinsky constant squared, Cs² (C = 0.017, so Cs ≈ 0.13). arxiv.org/abs/comp-gas/9401004, doi:10.48550/arXiv.comp-gas/9401004 (paper). - Andrew Selle, Ronald Fedkiw, ByungMoon Kim, Yingjie Liu, Jarek Rossignac, “An Unconditionally Stable MacCormack Method”, J. Sci. Comput. 2008: the limited MacCormack dye. yingjie.math.gatech.edu/…/SFKLR.pdf (paper).
- Christian Sigg, Markus Hadwiger, “Fast Third-Order Texture Filtering”, GPU Gems 2 ch. 20: the cubic B-spline from four bilinear taps. developer.nvidia.com/gpugems2 (book text, free online).
- Dither and noise hash: Dave Hoskins, “Hash without Sine”. shadertoy.com/view/4djSRW, MIT.
- Research and lessons:
research/waves-lbm-caustics.mdin this library (LBM section and thekarman-wakecandidate), and the stable-fluids cursor trail in the Russ Hype Machine page, whose rendering lessons (alpha cut, Beer–Lambert-style colour by thickness, capsule deposits, dither) carry over. The simulation code on this page is written from scratch.