How it works
This page is moving 1,048,576 particles right now (a 1024×1024 RGBA32F texture), every one of them every frame. They ride a current that is the curl of a single scalar stream function, so the flow can neither compress nor tear them: they stay evenly spread and draw unbroken threads, the way silk does in deep water. Your cursor stirs a small viscous fluid of its own. It drags the water along its path into a jet, the jet's ends curl into a pair of big, slow counter-rotating eddies, and luminous threads are born along the stroke, so the path you drew glows and keeps coasting for a few seconds after you stop.
Pipeline (per frame)
per frame · 2560×1440 canvas · 1,048,576 particles (desktop tier)
JS hand velocity V = pointer travel ÷ time between events (80 ms attack, 90 ms release)
drag target u = grip·V, capped at grip·0.9 screen-h/s · this frame's capsule a→b
emitter: 655 luminous ids per screen-h of travel (≤ 8,192 per wake life) → ring head
α[o] = phase·(1, 1.7, 2.4, 3.1) mod 2π noise shift mod 289 (the hash period)
│
[W] WAKE FLUID 82×48, vorticity / stream function 3 passes
W1 ω, dye RG16F advect by last frame's v · blur of variance 2ν·dt (ν = R²/2)
· e^(−dt/linger) · grip mix in the capsule:
ω += k·(∇W × (u − v) − W·ω) W = e^(−d²/R²)
W2 ψ R32F 2 red–black SOR iterations on ∇²ψ = −ω (warm-started),
one pass each: a black cell recomputes its red neighbours
v_wake no pass (∂ψ/∂y, −∂ψ/∂x) by central differences, read from ψ by W1, F
│
[F] FIELD 437×256 RGBA16F, LINEAR 1 pass
ψnoise = Σo a·gainᵒ/2ᵒ · psrdnoise(2ᵒ·x/L + shift, αo) analytic ∇ per octave
ψ = ψc + A·(ψnoise − ψc) A = 1 − e^(−r²/R²): a resting hand is a calm
out v = (∂ψ/∂y, −∂ψ/∂x) + v_wake · calm = 1 − smoothstep(t0, t1, |octave 0|) · dye
│
[U] UPDATE 1024×1024 MRT, NEAREST, texelFetch 1 pass
out 0 RGBA32F x, y, streak start 2×12 bit, age 16 bit · life 8 bit
out 1 RGBA16F vx, vy, –, wake-born
v ← mix(F(p + ½dt·v), v, e^(−dt/0.35 s)) p += dt·(v_old + v)/2
ids in the ring's window this frame: reborn in the hand capsule
others: respawn on death or exit (0.05 margin); below the luminous rows
each 8×8 texel block respawns in its own box of a 128×127 grid
│
[A] ACCUMULATE 1690×950 RGBA16F (0.66 × backing) 1 pass
A1 fade blend ZERO·CONSTANT_ALPHA dst ×= 0.01^(dt/T)
A2 threads instanced quads (4 vertices): 8,192 luminous ids every frame
(70% of the light), satin sheen in 5 phases → 216k per frame
quad laid along streak start → now; smoothstep pair along, gaussian
across, tapered toward its start by fade^k (k frames since drawn)
light/length ∝ (1 − fade)·area/(N·2.2σ·U) · class · calm · sheen
· speed^1.2 with a knee at 2.5× (wake-born: 1.8 · speed^−½ when fast)
│
[B] BLOOM 422×237 → 52×29 RGBA16F, 3 dual-Kawase downs, 3 ups 7 passes
4×4 box first, with a soft-knee threshold (only light above 0.6 blooms)
│
[C] COMPOSITE canvas 2560×1440, opaque 1 pass
dark bg + (1 − bg)·shoulder(acc + bloom) hue-preserving ⊕ per-channel,
then the brightest accumulated light heats toward the palette's white-hot,
vignette, and a cut of residue below ½–2 LSB of the output
light paper · e^−ink · relief gated by ink density (grazing light, glint)
· e^−(1/8-res blurred ink, 11 CSS px down-right) Beer–Lambert + cast shadow
±½ LSB interleaved-gradient-noise dither
The ideas that matter
- Take the curl of a potential, never use noise as velocity. Velocity is
v = (∂ψ/∂y, −∂ψ/∂x)of one scalar field ψ, and the divergence of a curl is zero, so there are no sources or sinks: a million particles stay evenly spread for their whole 4.5–9 s lives instead of piling into clumps and leaving holes. ψ ispsrdnoise, simplex noise that returns its own analytic gradient (one evaluation per octave, no finite differences) and evolves by rotating its gradients. Each octave's angle is wrapped mod 2π and the drifting domain mod 289, the hash period, so the field never loses precision however long the page runs. I measured the mean gradient of the noise (2.3), so Flow speed is the mean speed of the swirling current; the steady Current adds to it, and brightness is normalised to the two combined, √(U² + D²), so neither one alone can wash the screen out. One honest caveat: the velocity is exact at each texel of the 437×256 field, but particles read it bilinearly, which keeps it divergence-free only approximately between texels. - The wake is a real viscous fluid, solved in vorticity / stream-function form. An earlier version wrote the hand into ψ as a trail of gaussian-windowed rigid translations. Each of those has closed streamlines about one hand-width across, so particles orbited them for seconds and drew fish-scale loops. Now the hand stirs a coarse 82×48 grid. Inside its capsule the velocity is mixed toward grip × its own (a capped mix, never an add), written as the vorticity of that mix,
∇W × (u − v) − W·ω. The vorticity is advected by the whole flow, spread by viscosity (ν = R²/2, so a hand-sized eddy doubles in width in about 1.5 s) and decays over Wake linger. ψ comes from∇²ψ = −ωby two red–black SOR iterations a frame, warm-started from the last frame. Each iteration is one pass, because a black cell recomputes its four red neighbours' new values itself. Because the velocity is the curl of ψ, it is divergence-free however far the solve has converged. Physically, the stroke's momentum stays in a jet along the path, and its return flow wraps round the ends at the scale of the stroke, so there are no closed cells at the scale of the hand. A fast lemniscate leaves two big, slow figure-eight eddies instead of frizz. The ambient noise is still blended out under the hand with Bridson's ramp in ψ, so a resting cursor is a soft calm that the current slides around. - Particles have mass. Each particle carries its own velocity in a second render target (RGBA16F, written in the same MRT pass) and keeps
e^(−dt/τ)of it each step, with τ = 0.35 s. It cannot follow a loop much smaller than its coasting distance, and a passing hand gives it a smooth push instead of a 0.1 s kick. Brightness is based on that smoothed speed, and an ambient particle's light output saturates at 2.5× a nominal one's (it was 9×), so a flick leaves no hot beads. At the ambient current's time scales (τ is 1/30 of an eddy's turnover) the lag is invisible, and the slight clustering that inertia allows is undone by the particles' 4.5–9 s lifetimes. - The bright threads draw the wake. The 8,192 luminous ids double as a ring buffer. Each frame the hand claims the next
kof them, where k is 655 per screen height of travel (normalised by distance, so a slow stroke and a fast one lay the same density). They are reborn inside the capsule, spread evenly along this frame's travel with a gaussian across it, and launched at the local water velocity.kis capped so the ring never laps a wake thread that is still alive (lives of linger + 2 to 1.5·linger + 2.5 s). A wake-born thread glows everywhere, calm water included, at 1.8× a luminous thread's light per unit length, falling as speed−½ when fast, so the fresh tongue does not blow out and the slowing one does not vanish. Meanwhile a dye advected with the wake dims the ambient silk by up to 65% where the hand has been, so three seconds later the tongue still stands out against its surroundings. - Calm water: about a third of the frame is left deep black. A uniformly busy texture reads as brushed hair. So the ambient light is masked by
1 − smoothstep(t0, t1, |octave 0|), where octave 0 is the first noise octave's value. It is large in the cores of the big eddies, and the streamlines there are closed loops of nearly constant ψ, so a thread circling an eddy keeps its brightness while the core sits in black. The silk gathers into bands between the eddies, and the bands move with them. At the default Calm water of 0.5, t1 = 0.6 and t0 = 0.4. In measured quantiles of |psrdnoise|, 20% of the domain lies above 0.6 and another 26% inside the ramp. On screen, with the speed contrast on top, 45–50% of 24-px cells read below 6% grey. - Deposit light per unit of length, not per frame. Each particle lays a capsule from where it was to where it is, with a smoothstep pair along the stroke. Smoothstep pairs form a partition of unity, so successive capsules tile into one seamless line, whatever the speed. A still particle deposits nothing (no hot dots at stagnation points), and brightness rises naturally with speed, so fast water glows. Across the stroke the gaussian is lowered by its value at the quad's edge, so it reaches exactly zero there and no quad shows a faint outline. Energy is normalised by
(1 − fade)·area / (N·2.197σ·U·dt)(2.197σ is that truncated gaussian's integral), so brightness stays the same at any particle count, thread width, trail length, resolution or frame rate (120 Hz included). The faint-residue cut acts only below about ½–2 LSB of the final output, after the tonemap, so every trail's exponential tail tapers into the black instead of ending in a blunt step. - Silk, not fur. A million equally bright threads overlap into velvet: every pixel is lit and nothing reads as a strand. So the light is concentrated: 8,192 particles (0.8% of a million, 12.5% of a small count) are luminous threads carrying 70% of the ambient light, each about 300× brighter than a sheen particle, and the other million lay a satin sheen between them. The bloom only takes light above a soft-knee threshold, so the hot cores glow and the calm silk stays crisp. Trails take 4.5 s to fade to 1%, so each thread is a long comet. And there is an in-plane Kajiya–Kay sheen: a fibre lying across the light glows and one lying along it dims, so silk turning around an eddy shimmers like satin. The lobe is a broad sin², so a curving thread shades smoothly along its length instead of lighting up in short dashes, and its mean over all directions is 1, so Sheen changes the texture, not the exposure.
- What the million adds. The luminous threads are the same 8,192 at any count, so the difference is in the sheen. At 131k (the mobile tier, left) each sheen particle carries 8× the light, and the satin breaks into separate short comets with black between them. At 1M (right) the same light is spread over 8× as many, finer strands, and fills into a continuous sheet that shows the flow's texture between the bright threads, including in the dim margins of the calm pools. Both crops are 1:1 device pixels at the default preset.
- Drawing costs more than simulating, so the sheen draws in phases. Timed pass by pass on this M5 (each pass repeated 40 times back to back and closed with a
readPixels, so the GPU runs at full clock), simulating all 1M particles takes about 0.4 ms and drawing one sheen phase of 208k quads plus the 8,192 luminous threads about 1.2 ms: roughly 0.4 ns a particle against 5 ns a quad. So every particle is simulated every frame, but a sheen particle deposits only every k-th frame. Each deposit covers all its travel since it was last drawn, starting from a streak-start position kept in its state, so trails stay continuous and total brightness is unchanged. Along the deposit the light tapers from 1 at the head to fadek at the start, exactly what k per-frame deposits would have faded to, so phased streaks join without steps. The 8,192 luminous threads, the ones the eye follows, deposit every frame, so their heads move smoothly at the display rate. The dim satin sheen deposits every 5th frame at 1M (every 6th at the 1.31M maximum): 216k quads per frame instead of 1M. The draw's cost follows the number of quads far more than their area: with random spawning, halving every quad's width saved about 5% of it, while phases of 8 frames instead of 5 saved about 35%. The phase stays at 5, so the sheen keeps the cadence it was tuned with. - Quads along the streak, not point sprites. Each deposit is one instanced quad (4 vertices) laid along the particle's capsule: from 1.1σ before the streak start to 1.1σ past the head, where the smoothstep pair reaches zero, and ±2.1σ across, where the truncated gaussian does, so it holds every lit pixel and few others. An earlier version drew
gl.POINTS(one vertex each), but a point sprite has to cover its capsule's bounding square, and with phased streaks covering five frames of travel and wake-driven particles up to 64 px long, most of each square was empty: mid-sweep the sprites covered about 23 million pixels a frame, the quads about 5 million. In the harness sweep the quads alone took the frame from about 10 to 7–8 ms of GPU time. Streaks are still capped at 64 px (thegl.POINTSlimit on M1/M2), so the rare extreme streak keeps only its head as it always has, and a still particle is culled in the vertex shader. - Neighbouring texels hold neighbouring particles. When every particle respawned at a random place, neighbouring texels of the state texture held particles scattered over the whole frame, so the update's field reads and the draw's stream of quads jumped across memory and screen from one particle to the next. Now, below the luminous rows, each 8×8 block of texels respawns inside its own box of a 128 × 127 grid that tiles the domain exactly once (128 × 15 on the 131k tier), at a fresh random spot in the box each life. Every box gets the share of respawns that uniform random spawning gives it on average, and ages and lives are as random as before, so the silk is statistically the same; only the bookkeeping is ordered. A block row's boxes sit at hashed heights in each column, and consecutive block rows step by a stride coprime with the grid (78 of 127, near the golden ratio), so any run of rows, such as a sheen phase, is spread over the whole frame rather than a band. The 8,192 luminous threads (the wake's ring buffer) still respawn anywhere at random. Timed at full clock, the update went from about 0.6 to 0.4 ms and the draw from about 1.9 to 1.2 ms.
- Two texels per particle, every packed field an exact integer. The position texel (RGBA32F) holds position as plain floats, the streak offset as 2×12-bit fields at 8·10⁻⁵ screen heights (±0.16, enough for a 6-frame sheen streak at full grip), and age and life as 16+8 bits, all as exact float32 integers below 2²⁴, so no bit pattern can become a NaN or a flushed denormal. The velocity texel (RGBA16F) holds the particle's own velocity and its wake-born flag. At 1M the update reads 16 + 8 MB and writes 16 + 8 MB per frame. A pass that only copies that state measured about 0.3 ms at full clock, so that traffic is most of the update's 0.4 ms and the field read is the rest. Either way, simulating is a small part of the frame.
- Colour that stays saturated. Giving each thread its own random hue averages every pixel to grey, because a million threads overlap. So hue comes from a slow gradient drifting across the screen, blended with speed. Neighbouring threads share a hue, and the Aurora preset gets curtains of violet, blue and green. Every deposited colour is saturated (Silk's fastest threads are
#4aa8ff, not a near-white), so a wake dims through its own hue and never turns slate grey as it fades. The dark-theme shoulder mixes a hue-preserving tonemap (deep, saturated mids) with a per-channel one (hot cores walk toward white, like black-body light). Only the brightest accumulated light then heats toward the palette's own white-hot, in the composite rather than in the deposit: ice for Silk, mint for Aurora, and a saturated gold (#ffcf6a, at a lighter 35% mix) for Ember, whose slow water is a glowing#c01c06rather than a rust brown. - Ink on paper. On light backgrounds the same buffer holds ink, not light. Each palette colour becomes an optical depth
−ln(ink/paper), so a density of 1 shows exactly that colour and denser threads deepen naturally (Beer–Lambert). Bloom means nothing on paper, so the ink is lit instead: its density is read as a height field (saturating, so dense cores round off), and a grazing light from the top left gives every thread a lit flank, a dark flank and a small glint, like raised wet graphite. The relief and the glint are gated by the ink's own density,smoothstep(0.15, 0.45, h), and thin residue below a higher faint cut is dropped, so faint wisps stay clean flat paper instead of embossed scratches. The ink blurred at 1/8 resolution, offset 11 CSS px down and to the right, casts a soft neutral shadow. - Never a blank first frame, never a hitch. At load the page simulates 24 steps of 1/30 s behind the scenes (0.8 s of flow, with the field's clock held still), so the first frame already shows grown silk. The intro ghost then draws a slow arc across the centre at about 0.4 screen heights per second, and the first seconds show the luminous tongue it lays. A light/dark switch flips what the trail buffer means (light versus ink), so instead of clearing and re-simulating, one pass re-reads the old trails as a density in the new palette's mid colour, and real trails replace them as they fade: no fast-forward, no dropped frame. A resize resamples the trail buffer, and a new particle count starts from random ages, so it deposits at once.
Parameters
Presets
Performance & compatibility
- Measured at 2560×1440 on an Apple M5 (harness, 1,048,576 particles). Serial runs, one at a time under the library's GPU lock, so no other harness shared the GPU (other apps and the animated wallpaper still did). 60 fps throughout, with JS at about 0.15 ms a frame. Default (Silk) during the harness sweep: 4.6–4.8 / 7.0–7.5 ms GPU mean / p95 in two full runs, and 4.9–5.7 / 7.3–8.8 ms in three desktop-only runs. Presets, two runs each: Aurora 4.4–6.0 / 5.9–10.0 ms, Graphite 5.2–6.1 / 6.1–10.3 ms, Ember 5.0–5.1 / 6.8–7.5 ms. Before the instanced quads and the spawn boxes (above), the same harness measured 10.3 / 13.2 ms for the default, and a probe running the same sweep measured Aurora, Graphite and Ember at about 9.2 / 12.1, 8.5 / 12.9 and 9.8 / 13.0 ms. The 131k tier now measures 3.9 / 6.5 ms, 16k 2.6 / 2.9 ms and the 1.31M maximum 5.8 / 9.1 ms. Frame times drift up and snap back every 20–25 frames as the GPU's clock steps, so the p95 tracks the top of that sawtooth.
- Where the time goes. Timed pass by pass at full clock (each pass repeated back to back and closed with a
readPixels): the draw (fade, 8,192 luminous quads and one 208k sheen phase) about 1.2 ms, the update about 0.4 ms, bloom and composite about 0.35 ms, the wake's 3 passes about 0.1 ms and the field about 0.02 ms, about 2.2 ms a frame in all. Before, the point-sprite draw took about 1.6–2.2 ms and the update 0.6 ms, about 3.2 ms a frame. The harness's timer reads 2–3× those numbers, because at 60 fps the GPU idles most of the frame and runs at a lower clock. The draw's cost follows the number of primitives more than their pixels: a trivial fragment shader, an RGBA8 target or half-width quads each saved under 10% of it. The frame has 14 render passes. On ANGLE/Metal, tiny dependent passes can cost far more than their own work: with 4 SOR iterations (16 passes) the frame measured about 4 ms more than with 2 or 3. So the solver runs 2 iterations a frame, and the wake looks no different. - Memory at 1M: particle state 48 MB (2 × 1024² RGBA32F position + 2 × 1024² RGBA16F velocity), trail buffer 12.8 MB (1690×950 RGBA16F), bloom pyramid 2.1 MB, field 0.9 MB, wake grid 0.1 MB: about 64 MB in all.
- Tiers. Desktop runs 1,048,576 particles (1024 rows). Coarse pointers (phones, tablets) and the gallery embed run 131,072 (128 rows), with the field at 180 or 130 rows instead of 256; the wake grid is 48 rows everywhere. The Particles slider goes from 16k to 1.31M; it re-allocates on release. Above 400k the sheen's deposit interval stretches with the count (5 frames at 1M, 6 at 1.31M), so the draw stays near 216k quads and the extra cost is mostly the update. The trail buffer is 0.66× the backing store whenever DPR ≥ 1.5: threads stay about 1.2 CSS px wide, and fill and the full-screen passes drop by 56%. All GL allocation happens on resize, on a count change or on a light/dark switch, never per frame. If a driver rejects mixed RGBA32F + RGBA16F attachments in one framebuffer, the velocity target falls back to RGBA32F.
- Mobile. The harness's 390 px touch run (DPR 3, capped at 2, so a 780×1688 backing store) gets the coarse-pointer tier: 131,072 particles, all drawn every frame, into a 515×1114 trail buffer, with a 180×352 field and a 48×94 wake grid. The harness reports 60 fps for that drag (its count includes a full-resolution screenshot taken mid-drag). The same drag without the screenshot ran at 60 fps with about 3 ms of GPU time (2.9–3.5 ms mean in two runs). That run uses the desktop GPU, so it checks layout, touch and the tier, not phone speed. A phone draws 131k quads (60% of the desktop's 216k) over about a third of the pixels.
- Ambient. The current never stops, so the page runs while it is visible and pauses when it is scrolled away or the tab is hidden (harness: 0 frames while off-screen, running again on return). The wake solver switches itself off once the wake has fully decayed (5 × linger + 1 s after the hand leaves), so the ambient page skips its 3 passes.
- Reduced motion. The warm start plus 120 frames of the ghost path are rendered once as a still, with a "Play anyway" button.
- Requirements. WebGL2 with
EXT_color_buffer_float. All blending happens in RGBA16F (iOS has noEXT_float_blend), and the 32-bit textures (particle state, the wake's ψ) are read only withtexelFetch(iOS has noOES_texture_float_linear). Without WebGL2 or float render targets, the shell shows its fallback card over the poster frame. The canvas sits under the page and listens onwindow, so it never takes a click.
References & credits
- Robert Bridson, Jim Hourihan, Marcus Nordenstam, “Curl-Noise for Procedural Fluid Flow”, SIGGRAPH 2007: stream-function curl and the ramp blend around the cursor. cs.ubc.ca/~rbridson/…/curlnoise.pdf (paper).
- Stefan Gustavson & Ian McEwan,
psrdnoise, tiling simplex noise with rotating gradients and analytic derivatives. The 2D function is adapted (non-tiling) with its attribution kept in the source. github.com/stegu/psrdnoise, MIT. - Jos Stam, “Stable Fluids”, SIGGRAPH 1999: semi-Lagrangian advection, used here for the wake's vorticity. doi.org/10.1145/311535.311548 (paper). The vorticity / stream-function form and red–black SOR are textbook numerics (e.g. Ferziger & Perić, Computational Methods for Fluid Dynamics).
- Mark Jarzynski & Marc Olano, “Hash Functions for GPU Rendering”, JCGT 9(3), 2020: the PCG hash used for respawns and per-thread variation. jcgt.org/published/0009/03/02 (paper).
- Marius Bjørge, “Bandwidth-Efficient Rendering”, SIGGRAPH 2015: the dual-filter (Kawase) bloom. community.arm.com, Moving Mobile Graphics (talk).
- James Kajiya & Timothy Kay, “Rendering Fur with Three Dimensional Textures”, SIGGRAPH 1989: the fibre-tangent highlight behind the sheen. doi.org/10.1145/74334.74361 (paper).
- Jorge Jimenez, “Next Generation Post Processing in Call of Duty: Advanced Warfare”, SIGGRAPH 2014: interleaved gradient noise for the dither. iryoku.com, Next Generation Post Processing (talk).
- Prior art read, not copied: Edan Kwan's The Spirit (MIT) and David Li's Flow (MIT), for GPGPU particle state and curl-noise particles; Amanda Ghassaei's gpu-io (MIT) fluid example, for particles carried by a coarse fluid grid.
- Research and lessons:
research/gpgpu-particles.mdin this library (the curl-noise and GPGPU sections, the ring-buffer emitter, inertia and the "coupling to the baseline fluid" note, and thecurl-silkcandidate), and the stable-fluids cursor trail in the Russ Hype Machine page. Its lessons carry over: a capped grip mix in a capsule, deposits normalised by distance travelled, dt-based fades, a faint-residue cut and dither. Everything on this page is written from scratch.