How it works
The cursor is a smouldering incense stick. It lays heat and smoke into a 2D fluid. Buoyancy lifts the warm thread, a cooling clock decides where the thread stops being laminar and starts to curl, and once it has cooled, drag slows it into hanging wisps. As the smoke ages it spreads wider and thinner. It is then lit as if it had depth: every pixel measures how much smoke lies between it and each lamp. That is why the ribbons have bright faces, shadowed undersides and folds that darken one another, instead of reading as a flat grey haze.
Pipeline (per frame, 2560×1440)
pointer path ─ shell segment (gaps under 0.4 s bridged) · fixed 60 Hz sim step (120 Hz frames reuse the last image)
│
├─ STATE gentle grip toward the stick's velocity · heat (saturating) + clock line-integral splat
│ resting stick: lift, heat and clock eased toward a target in a small puff
│ Boussinesq lift · drag on cooled air, more in the top fifth · Newtonian cooling
│ curl noise on smoke (masked by the smoke's mip)
│ state RGBA16F 455×256 (vel.xy in texels/s, temperature T, laminar clock C)
├─ CURL ω = ∂v/∂x − ∂u/∂y R16F 455×256
├─ VORTICITY confinement ε·(N × ω), weak while C is high, |v| clamp RGBA16F 455×256
├─ VISCOSITY Jacobi ×6 on (I − ν·dt·∇²)u = u₀ state ping-pong
├─ DIVERGENCE ½(∂u/∂x + ∂v/∂y), zero-gradient (open) edges R16F 455×256
├─ PRESSURE red-black SOR, ω = 1.8, 18 passes, warm start ×0.85,
│ p = 0 outside the screen (smoke leaves freely) R16F ping-pong
├─ GRADIENT u −= ½∇p
├─ SMOKE A forward trace by u + dye-only detail (curl-noise tex) R16F 1820×1024
├─ SMOKE B MacCormack correction, eased off in sheared folds,
│ clamped to the 4 source texels · age spread (mip tap)
│ fade + bleed · line-integral deposit (tapers as the
│ stick slows) · smoulder puff toward a target density R16F 1820×1024
├─ MIPMAPS generateMipmap on the smoke (shadow taps, spread, turbulence mask)
├─ ADVECT semi-Lagrangian self-advection of the state, edge sponge
│
├─ LIGHT 10-tap optical-depth march toward each of 2 lights,
│ IGN-jittered, each tap blurred more with distance,
│ blended 50/50 with last frame (fresh after a resize,
│ an idle stop or for the still) · cast-shadow density
│ of the smoke that survives the cut · blurred AO density RGBA16F 640×360 ping-pong
└─ DISPLAY tent upsample of the light · Beer–Lambert α, crisp cut on optical depth
light-wall contrast curve · clear zone above the pointer
near-field τ at full res · directional-derivative diffuse
multiple-scatter octave · forward-scatter rim
backdrop pools, vignette, cast shadow · linear → sRGB · triangular dither
canvas 2560×1440
30 sim passes + 2 smoke passes + light + display = 34 draws and 1 mip build per frame
about 21 MB of render targets
The ideas that matter
- Heat and smoke are separate fields. Temperature (and the velocity it drives) lives on a coarse 455×256 grid. The visible smoke is a separate density at 1820×1024, so threads stay far thinner than a velocity cell. The heat is splatted wider than the smoke (2.2× the ribbon width). Each thread then rides a broad warm updraft, as in real air, and rises at a believable speed. A heat footprint as thin as the visible ribbon barely moved: viscosity smeared its momentum into the still air around it. Heat also saturates,
T += 2·w·(1 − T/1.8): one pass leaves T ≈ 1.2, and a dense scribble over the same spot reaches at most 1.8, so it cannot build one hot bulk plume that races off the screen. - Rise, then hang. Buoyancy alone accelerates the smoke until it leaves the screen: in the previous build the harness's scribble had gone within about 2 s. Now cooled air feels a vertical drag,
v.y /= 1 + (1·(1 − smoothstep(0.05, 0.4, T)) + 2.5·smoothstep(0.8, 1, y))·dt. The hot thread rises freely and stretches thin, then decelerates into hanging wisps. Extra drag in the top fifth holds them a little longer before they exit. Fade then decides how long they hang, which is why it defaults to 0.3. One fluid-dynamics fact shaped the intro: in 2D incompressible flow a long horizontal warm ribbon rises slowly, because it has to push the whole column of air above it aside. A near-vertical thread climbs much faster. So the intro path is a wave whose upstrokes lay vertical threads. - Laminar first, turbulent later, on a clock. Next to temperature, the state carries a laminar clock C. It is splatted with the heat and cools at the same rate, but it has no buoyancy: it only decides when the thread may break up. Vorticity confinement is scaled by
0.06 + 0.94·(1 − smoothstep(0, 0.6, C))², so the fresh thread leaves the stick as a nearly clean line (a 6% floor keeps a trace of curl) and rolls up later. Curl-noise turbulence ramps in earlier and more gently,1 − smoothstep(0.15, 1.1, C), so the thread starts to wobble within half a second. With these terms ungated, the whole trail shattered into small paisley curls within half a second. - Where the thorns came from. An earlier version broke every stroke into a row of identical hooks, like a thorny vine. Switching terms off one at a time showed the cause: the stick's grip on the air. Blending the air toward the stick's velocity inside a narrow footprint makes a thin jet. A thin shear layer rolls up by Kelvin–Helmholtz instability at a wavelength set by its thickness, so the hooks came out evenly spaced. The grip is now a quarter as strong, over a footprint twice as wide (6 ribbon widths). That leaves a gentle wake instead of a jet. The remaining regularity is then broken on purpose. Heat is modulated by low-frequency noise (about 2.5 cycles per screen height), and the clock by separate noise (about 4 cycles), both with a new random phase for every stroke. The heat width also wanders ±35% along the stroke's arc length. Breakup starts at staggered times and at different scales.
- A seamless deposit, through hitches too. Round-capped capsule splats (the usual cursor brush) overlap at every frame joint and double the density there. On fast strokes that leaves a row of beads, and shear turns the beads into comb-like stripes. Instead, each segment deposits the exact integral of a Gaussian brush along its length,
exp(−d⊥²/σ²)·½[erf((L−t)/σ) + erf(t/σ)](erf via Winitzki's approximation). Consecutive segments tile perfectly, and smoke per unit length is the same at any speed above about 0.2 screen heights/s. Below that it thins, down to 20% at rest, so a stroke starts and ends in a taper instead of a round cap. The shell starts a new stroke after any 150 ms gap between pointer events, which a garbage-collection pause or a tab hitch can cause. The effect keeps its own last deposit point and bridges such a gap when it is under 0.4 s and 0.2 screen heights, so the ribbon never turns dashed. - Smouldering without a blob. The previous build added a round puff at the tip on every step, scaled down only by how far the tip moved per step. At moderate speeds that left it at about 40% strength, so the freshest part of every stroke was a fat, self-shadowed worm. At a stop it piled up to an opaque ball. Now the puff only runs when the smoothed stick speed is really low (under about 0.05 screen heights/s). It approaches a target instead of adding to it:
ρ = mix(ρ, max(ρ, amount), r·g)over a Gaussian half the ribbon width, and heat and clock likewise. Inside the same footprint the air is eased toward an upward 0.3 screen heights/s. A resting stick therefore streams a thin thread that curls over as it cools, and the envelope tapers it off within 3 s. - Crisp threads, clean folds. The smoke is advected with clamped MacCormack (Selle et al. 2008): two passes, with the correction clamped to the four texels the forward trace blended. Thin threads keep their peak density, and with it their crisp edge, for their whole life. Where the correction is large compared with the local peak (sheared folds only a few texels thick), it is eased off toward plain semi-Lagrangian; there it only added a fibrous grain. A dye-only detail velocity adds wisps below the grid scale without touching the simulation. It is two taps of a baked, tileable curl-noise texture drifting in different directions, scaled by local speed and by the clock.
- Translucent with age. As the clock runs down, each step blends the smoke toward a trilinear tap of its own mip chain (level 1.5) at the backtraced point. That is diffusion: old smoke widens and thins, so it turns translucent before the cut erases it, while the fresh thread stays narrow and dense. A sparse ring of four taps did the same job but left 3-texel frequencies undamped, and the MacCormack correction sharpened them into a lattice of dots.
- Optical depth, not normals, makes the volume. At quarter resolution, each pixel integrates smoke density toward each lamp. The steps are spaced quadratically (dense near the pixel), jittered per pixel and per frame with interleaved gradient noise, and each tap reads a blurrier mip level the farther it is. The cone blur gives soft penumbrae and hides the step count. The result is blended 50/50 with the previous frame, so the jitter accumulates instead of crawling. The display reads it through a 4-tap tent (about 3×3 quarter-res texels); with a plain bilinear tap the jitter pattern showed through as a faint 4 px lattice inside dense smoke. The first few texels of the path are integrated at full resolution in the display pass, so a single thin ribbon still gets a sharp terminator. Transmittance is
e−τ + 0.3·e−0.2τ: the second, weakly attenuated octave stands in for multiple scattering. Deep shadow stays soft and luminous instead of turning to soot. - Directional derivative. Diffuse light uses one extra tap toward each lamp (Quilez). Where opacity thins toward the light, the smoke "faces" it and lights up. Combined with the cool second light mirrored across the frame, every ribbon gets a warm face and a cool shadow side.
- Scatter and a hard edge, never haze. Opacity is Beer–Lambert,
1 − e−τwithτ = kρ. The cut is a smoothstep on τ itself, so it is a cut on opacity, and its width never drops below 1.5×fwidth: edges are anti-aliased, but faint smoke disappears instead of fogging the page. Edge crispness moves the threshold from τ = 0.03 to 0.36 and the soft width from 1.2 down to 0.03. Cutting on optical depth rather than density also lets the Density slider decide how much faint smoke survives. On a light backdrop the threshold rises by up to τ = 0.9 as the clock runs down, because translucent old smoke on a pale wall reads as dirty grey veils, and opacity goes throughA(2 − A), so a ribbon's fringe firms up instead of reading as a smudge. A forward-scatter term,4α(1 − α), peaks at mid opacity, so the thin edges glow in the lamp colours. - A lit room, not a flat colour. The backdrop gets a soft pool of light from each lamp, a vignette, and a cast shadow taken from blurred smoke density 0.07 screen heights toward the key light. On the Studio seamless, that cast shadow is what makes dark smoke read as an object in front of the wall. It is displaced far enough and blurred little enough (two taps around mip 3.5 at a 1024 field) to read as a shadow on the wall rather than a grey halo hugging the ribbon. On a light wall it is also gated by the same age term as the cut, so smoke that has been erased leaves no shadow behind. Everything is computed in linear light and dithered on output, so gradients never band.
- Smoke in the very first frame. Before the first paint, the page simulates 1.4 s of the ghost stroke synchronously, including its rising loop. The first frame therefore already shows a risen, curling ribbon above the fresh one. That costs about 0.1 s: the first paint lands 0.18–0.28 s after navigation. The 3.5 s live intro continues as a wave to the right edge, turns back beneath the risen smoke and smoulders into a thread at the centre. On portrait screens it is a zig-zag down the stage instead. The ghost stick draws ribbons 1.1× the default width. On portrait screens every ribbon is narrowed by √aspect, because a width set as a fraction of a tall screen's height is too fat for its narrow width.
- Engineering details. The simulation runs on a fixed 60 Hz step, so a 120 Hz display neither speeds it up nor smears the smoke more. The open boundaries let smoke drift off the top of the screen instead of piling up into a ceiling fog. Red-black SOR converges two to four times faster per pass than Jacobi. The light history is marked invalid after every re-allocation and idle stop, so the first frame never blends with an empty or stale buffer. The reduced-motion still renders its light four times, so it is not at half strength. The user's pointer keeps a clear zone: no smoke within 0.015–0.06 screen heights of it, and the column rising out of it is thinned to a quarter for 0.1 screen heights, so smoke never covers what is just above the cursor. Finally, in the two seconds before the shell's idle stop, the fade rate ramps up and the layer fades out. The loop never freezes smoke mid-air.
Parameters
Presets
Performance & compatibility
3.8–5.3 msGPU per frame (mean) at 2560×1440
7.5–8.5 msGPU p95, same sweeps
≈0.1 msJavaScript per frame
60 fpsduring the scripted pointer sweep
- Measured in headless Chrome (ANGLE on Metal, Apple M-series) with the library harness's 1.5 s pointer sweep and a 2560×1440 backing store. Other agents share this GPU, so the figures come from quiet windows. Three sweeps with no other harness or benchmark running read 3.84 / 8.00, 4.96 / 7.52 and 5.33 / 8.49 ms (mean / p95): those are the tiles above. Sweeps that overlapped other agents' GPU benchmarks read 6–14 ms mean and 12–29 ms p95, always at 60 fps. This build adds one texture tap to the light pass and a few ALU operations to the state, smoke and display passes, so its cost matches the previous build's 3.1–5.5 / 7.2–8.3 ms within the noise. The longer 1.4 s pre-roll (84 sim steps before the first paint) adds about 0.1 s of GPU work at load. CPU-side JavaScript stays at 0.06–0.13 ms per frame, with no allocations in the frame loop (uniform objects are created once and mutated).
- What scales the cost: the smoke resolution, above all. Dropping it from 1024 to 512 roughly halves the GPU time, because the two MacCormack passes, the mip build and the light taps all work at that size. The slider stops at 1280. Above 1024, a 1440p canvas gets a smoke field close to full size, which roughly doubles the dominant cost. The 30 sim passes on the 455×256 grid and the quarter-res light pass come next. Setting the second light to 0 skips its march.
- Requirements: WebGL2 with
EXT_color_buffer_float(render to R16F/RG16F/RGBA16F). Half-float textures filter and mipmap in core WebGL2. Nothing needs 32-bit float filtering or float blending. Without WebGL2 or float targets the shell shows its fallback card, over the poster frame when one exists. - Mobile: on coarse-pointer devices the backing store is capped at 1.5× DPR, the sim grid at 160 cells and the smoke at 640 texels on the short side (both capped by the canvas), with 12 pressure passes. On a 390 px wide phone that is a 585×1266 canvas, a 160×346 sim and a 585×1266 smoke field, and the intro is the portrait zig-zag. The harness's emulated touch drag ran at 55 fps. That ran on the desktop GPU, so treat it as a layout and logic check, not a phone benchmark. The sim stops 7 s after the last touch, and the smoke dissolves before it does.
- Reduced motion: under
prefers-reduced-motionthe page renders one still. It runs the whole intro, plus 1 s of smouldering, synchronously at 1.6× speed (about 220 sim steps), so the sweep, the loop and the smouldering thread are on screen together. Nothing then animates until you press Play. The gallery thumbnail (?embed) runs at DPR 1 with a 200-cell sim, a 400-texel smoke field, ribbons 1.15× wider and its own wide figure-8 path in the lower half, so several layered ribbons are on screen at once, and it pre-rolls like the page.
References & credits
- Fedkiw, Stam & Jensen, “Visual Simulation of Smoke”, SIGGRAPH 2001: vorticity confinement and Boussinesq buoyancy. This page uses the temperature term only. The paper's density weight
κ·ρis left out, because incense smoke is far too light for it to show. cseweb.ucsd.edu/~henrik/papers/smoke (paper; method only). - Stam, “Stable Fluids”, SIGGRAPH 1999, and Harris, “Fast Fluid Dynamics Simulation on the GPU”, GPU Gems ch. 38: the operator-split grid solver as fragment passes. developer.nvidia.com/gpugems (book chapter, free to read; method only).
- Selle, Fedkiw, Kim, Liu & Rossignac, “An Unconditionally Stable MacCormack Method”, J. Sci. Comput. 2008: the smoke advection and its clamp limiter. yingjie.math.gatech.edu/publications/SFKLR.pdf (paper; method only).
- Crane, Llamas & Tariq, “Real-Time Simulation and Rendering of 3D Fluids”, GPU Gems 3 ch. 30: MacCormack on the GPU and low-res jittered volume lighting. developer.nvidia.com/gpugems/gpugems3 (book chapter, free to read; method only).
- Bridson, Hourihan & Nordenstam, “Curl-Noise for Procedural Fluid Flow”, SIGGRAPH 2007: divergence-free turbulence. cs.ubc.ca/~rbridson (paper; method only).
- Perlin & Neyret, “Flow Noise”, SIGGRAPH 2001 Technical Sketches: noise whose lattice gradients rotate over time, so it evolves without sliding. evasion.inrialpes.fr/Publications/2001/PN01 (sketch; method only).
- Inigo Quilez, “Directional derivative” and “Gradient noise derivatives”: the one-tap lighting and the analytic noise gradient. iquilezles.org/articles/derivative, iquilezles.org/articles/gradientnoise (articles; method only).
- Jimenez, “Next Generation Post Processing in Call of Duty: Advanced Warfare”, SIGGRAPH 2014 Advances in Real-Time Rendering course: interleaved gradient noise, used for the march jitter and the output dither. iryoku.com (slides; the one-line formula).
- Wrenninge, Kulla & Lundqvist, “Oz: The Great and Volumetric”, SIGGRAPH 2013 Talks: approximating multiple scattering with extra, weakly attenuated octaves. doi.org/10.1145/2504459.2504518 (talk; idea only).
- Winitzki, “A handy approximation for the error function and its inverse” (2008): the erf used in the line-integral deposit. academia.edu/9730974 (note; formula only).
- Wellons, “Prospecting for Hash Functions” (2018): the
lowbias32integer hash behind the noise lattice. nullprogram.com/blog/2018/07/31 (public domain). - The pass layout follows the common WebGL stable-fluids arrangement popularised by Pavel Dobryakov's WebGL-Fluid-Simulation (MIT) and the library's reference cursor trail. Everything on this page was written from scratch; no third-party code is included.