How it works
The bright net on a pool floor is light that the waves have focused. Each wave crest acts as a weak lens, and where a lens brings its light to a line you get a caustic. This page traces that literally. Every frame, a grid of 126,000 sun rays (461×274 at 2560×1440) is bent by the slope of the water and dropped onto the floor. Each ray carries a small triangle of light. Where the triangles crowd together the floor is bright, and where a triangle folds flat you get a knife-edge filament. The water itself is 24 analytic wind waves plus a real wave-equation simulation that your cursor pushes through. Its wake is a set of rings that spread at walking pace, and a low swell along your path, filled with short chop, that takes about six seconds to settle. So a band of dense, bright filaments trails behind you.
Pipeline (per frame)
pointer ─▶ JS path since the last step → sim texels; |v − c| / c → trough gain; stroke length → ramps
wind + chop phases φᵢ += ωᵢ·speed·dt, wrapped
N = accumulator × 120 steps/s → 2 steps per 60 Hz frame (capped at 8)
┌── N × WAVE RGBA32F 461×274 ping-pong, NEAREST, texelFetch (screen + a 7% border on every side)
│ r,g leapfrog (h, h_prev), isotropic 9-point Laplacian, C² = 0.36, Kelvin–Voigt viscosity
│ amplitude e-fold = Wake linger (4 s) for long waves, absorbing sponge in the border
│ + fused moving trough A→B along the pointer path, impulse × 1/(1 + 8h²)
│ + release: where a stroke ended, h and h_prev relax toward 0 over 0.1 s
│ b wake swell: raised toward 0.42 by the capsule A→B, e-fold 1.5 × Wake linger (6 s)
└─────────────────────────────────────────────────────────────────────────────────────────────
SURF RGBA16F 461×274, LINEAR ∇h = Σ₂₄ crest-peaked wind waves × (1 − 0.35·band)
+ Σ₆ wake chop (0.38 × the wavelength) × band
+ tanh-limited slope of (ripple + swell)
CAUSTIC light mesh: one vertex per SURF texel, triangle strips + primitive restart, no vertex buffer
ray x lands at x + F·depth(y)·∇h(x); I = |det ∂(source)| / pixel area (flat = 1)
2 instances: red at F·(1−δ), blue at F·(1+δ) (502k triangles)
→ RG16F 1076×605, 4× MSAA renderbuffer (2× on touch), additive ONE+ONE, no culling → blit
BLUR RG16F 1076×605, separable Gaussian, ≤13 taps (9 in Pool), σ = sun disc × √focus × depth(y),
never below 0.3 of the mesh pitch
BLOOM RG16F 539×303, threshold (I − 1.4) + separable blur (skipped when Glow = 0)
DISPLAY canvas 2560×1440, opaque
bilinear ∇h → refracted view of the floor → albedo (mosaic, lane, rippled sand, plain)
green = min(r, b) + 0.35·|r − b|; water filter T = hue^(0.6·tint·depth)
× (fill · relief · T² + sun · I^γ · relief · T + glow) → in-scatter by depth
+ sun glitter: one facet per 20 px cell → shoulder tonemap → sRGB → ±1 LSB triangular dither
≈ 7 draws + 1 blit per frame (9 with Glow)
The ideas that matter
- Trace the light forward. The research notes offer two routes: evaluate
1/|det(I + F·Hessian(h))|per pixel, or rasterise a mesh of rays. The per-pixel version is one cheap pass, but it measures brightness at the point the ray left, not where it landed. Past the first fold it draws smooth loops around the folded regions instead of the real thing. The forward mesh puts each triangle where its light arrives. Folded regions collapse into thin bright lines that meet in cusps, the look of a real pool floor, and overlapping folds add up because blending is additive and culling is off (a fold flips a triangle's winding). - Brightness from derivatives. Each fragment takes the screen-space derivatives of the ray's source position.
|det(dFdx(src), dFdy(src))|is the area of water surface whose light landed in that pixel, and dividing by the pixel's own area gives the intensity. That is exact per triangle and exactly 1.0 for flat water, so the floor's average brightness never drifts. It is a determinant, not the product of two lengths, which would ignore shear. A collapsed triangle is soft-capped at 48 withI/√(1 + (I/48)²), which keeps it from flooding the 16-bit target without the flat-topped, square-looking knots a hardmin()leaves after upscaling. - Folds are thinner than a pixel. Squeezed triangles can be narrower than a pixel, and with one sample per pixel they either hit or miss pixel centres. That shows up as hatching inside the folded bands. A 4× MSAA renderbuffer (2× on touch screens) gives them fractional coverage instead. A small Gaussian blur then plays the sun's disc: the real sun is 0.53° wide, so its penumbra grows with depth. Sharpness sets the disc size, and the blur widens toward the deep end. It never drops below 0.3 of the mesh pitch, because each triangle is flat-shaded and a coarse mesh would otherwise show as a faint crosshatch in the dim cells. Because that blur is always wider than a target pixel, the caustic target can sit at 0.42 of the screen resolution with no visible loss.
- Sharp crests make thin lines. A sum of plain sines bends light as much in the troughs as on the crests, which gives soft, blotchy light. Real waves have sharp crests and flat troughs. Each wind wave here has the profile
e^(1.6·(cos θ − 1)), whose curvature is 1.6 at the crest but only 0.07 in the trough. The light gathers into thin lines under the crests, and the cells between them stay evenly dim. Each amplitude is set by curvature (Aᵢ = wᵢ/(1.6·k²)), so Wave size rescales the pattern without changing how hard it focuses. Focus distance sets where on the mush → creases → dense-web curve you sit. - Dispersion in two channels, not three. Water bends violet a little more than red. Drawing the mesh once per channel at three focus values costs three times the triangles. Here only red (at
F·(1−δ)) and blue (atF·(1+δ)) are drawn, as two instances of one draw call into anRG16Ftarget, and green is rebuilt asmin(r, b) + 0.35·|r − b|. Where the two coincide the light is white. Where they split, every filament gets an orange edge and an azure edge. Green as the plain mean would turn the warm edge yellow-green, which under cyan water reads as a lime smear. That saves a third of the triangles and half the bandwidth of every caustic pass. Deep blue water absorbs the warm edge, as it would in the sea, so the fringes read best in Prism (white light, almost no water colour), and Pool keeps its dispersion low. - A wake that adds light. The cursor drags a Gaussian trough through a real wave-equation sim, stepped at a fixed 120 steps per second whatever the display rate. It uses an isotropic 9-point Laplacian (round rings), viscous damping that kills fine chop but keeps the swells, and a sponge in the hidden border so nothing reflects off the screen edge. The trough is added to both time levels, so it displaces water without kicking it. The rings travel at 0.3 screen heights per second, slow enough to stay on screen for a few seconds. Rings alone still spread out and leave. So a third channel raises a low swell along the path, which relaxes like a viscous film (it decays 1.5 times slower than the rings, 6 s by default, and diffuses a little). The swell is a weak cylindrical lens that gathers light into the band, and it carries six short wake chop waves, at 0.38 of the wind wavelength and 1.7 times its curvature, that exist only inside it. So where you passed, the light folds into a band of tighter, brighter creases that is still clear three seconds later. Calming the wind waves instead, like the slick behind a boat, only takes light away: the first version of this page did that and left a dull stripe. The swell fades in over the first 0.2 screen heights of a stroke, so the band's tail is feathered rather than a capsule.
- Ripples that never blow up, and no eraser stamps. A cursor moving near the ring speed rides its own wave and piles it up into a deep dimple, which the light shows as a dark disc with a hard bright rim. So the impulse saturates as
1/(1 + 8h²), and it drops to 30% while the cursor's speed is within 15% of the ring speed. The swell saturates toward a fixed height (its deposit is normalised by distance travelled, so speed doesn't matter), and the slope is soft-limited withtanh. Strokes end without a stamp too: where the pointer stops, or where a frame hitch splits a stroke, the trough is released over 0.1 s, like a finger lifted slowly out of the water, and a new trough ramps in over its first brush width. The intro's ghost pointer traces a figure-8 at a steady 1.7 rad/s, which never drops below 0.6 screen heights per second, twice the ring speed. - Soft depth. The floor slopes, and it is about 58% deeper at the top edge than at the bottom (depth 0.775 to 1.225). Depth scales the focus, the sun-disc blur and the optical depth of the water together. The deep end has denser, softer and bluer light, and the shallows are crisper and brighter, which gives the picture depth without any perspective.
- Water colour without a muddy floor. Absorbing with the raw water colour (
T = colour^depth) turns a sand floor black under deep blue water. Instead the filter is normalised to the water's strongest channel, so the floor takes the water's hue but keeps its detail, and a separate in-scatter term fades it toward the water colour with depth. Skylight reaches the floor along long, slanted paths, so it goes through the filter twice (T²), while the direct sun goes through it once. The dim cells take the water's colour, and the sunlit filaments keep the floor's own: deep cyan cells under white light in Pool, and warm sand in Ocean floor's shallows turning blue toward the deep end. Sand ripples shade the skylight as well as the sun, so their ridges read in the dim cells too. They sit about 0.065 screen heights apart, finer than the light cells, so the eye separates the two patterns. Ocean floor also looks at them through less refraction, so the waves don't scramble them. - Glitter, not dust. Sun glints come from facets of capillary ripple far too small to simulate. The screen is divided into 20 px cells, each holding one facet at a random point with a random tilt that wanders over time. A facet flashes only where the wave slope plus its tilt mirrors the sun into the viewer. The sun's mirror slope sits among the steepest 7% of wind-wave slopes, so only the flanks that face the sun (about 7% of the surface) can catch it, and the sparkles cluster there and along the cursor's ripples. Surface glints sets the brightness and also widens the mirror tolerance, from about 1° to 3° of tilt. The default is a scattering of 3–4 px points with soft halos, and the top of the range is a dense glitter path. Pixels whose wave slope is far from the mirror angle skip the work, and the sparkles fade out where a cell would be smaller than about 7 px (embed, small screens).
- Precision and scale. The ripple state is fp32, because small waves vanish in fp16. Slopes are fp16, which is ample for a displacement of a few pixels. Wind-wave phases advance on the CPU and wrap at 2π, so hours on the page never cost the GPU's
sin()any precision. On tall portrait screens the scene unit shrinks, so tiles, waves and ripples keep their size relative to the narrow width, and the lane line moves right, clear of the hint.
Parameters
Presets
Performance & compatibility
- Measured by the harness (Chrome, ANGLE Metal on an Apple M5, 1280×720 at DPR 2, so a 2560×1440 backing store). Default preset (Gold light) during a pointer sweep: GPU 2.8–4.4ms mean / 5.4–5.9ms p95, JS 0.04–0.06ms per frame, 60 fps, over the last three full runs (2.81/5.39, 3.51/5.37 and 4.38/5.91ms), each started once no other harness run had been active for 16 s. Other agents' probes may still have been using the GPU, and no fully idle window came up. So here is the spread instead of the best run. Over 11–14 sweeps per preset, with other effects' tools running, the means were 3.1–6.1ms (Gold light), 3.5–9.4ms (Pool), 2.8–9.0ms (Ocean floor) and 4.3–7.1ms (Prism), and the p95s 6.3–12.2, 5.6–12.6, 5.2–12.7 and 5.4–11.9ms. The fastest tenth of frames, the least disturbed by other work, sat at 3–5ms for every preset. Pool at Resolution 320, the top of the range, measured 4.4–10.5ms mean and 6.2–13.3ms p95 over five sweeps in the same sessions, so it can cross 12ms when the GPU is shared.
- Where the time goes. Repeating one pass several times per frame, under load, showed the light mesh at about 1.1ms (2ms at the old 288 cells), the blur and the display pass at about 1ms each, and the ripple steps, slopes and MSAA resolve under 1ms together. The savings came from an RG16F caustic chain (half the bandwidth of RGBA), a caustic target at 0.42 of the screen instead of 0.5, a 240-cell mesh (502k triangles instead of 724k, with no visible change), half as many ripple steps (the slower waves allow it), a blur that drops taps for a narrow sun disc, a display pass with a bilinear slope lookup and gated glitter instead of B-splines and eight capillary waves, and no bloom in Pool.
- What scales it. The mesh grows with Resolution squared: 126k vertices and 502k triangles per frame at 240, 893k at 320, the top of the range. The range used to reach 480, but higher settings crossed the 12ms p95 limit whenever the GPU was shared: Pool at 384 measured 7.5–13.2ms p95 over twelve passes, most of them above 11ms. Dispersion 0 drops to one instance, and Glow 0 skips the bloom passes. The ripple sim runs 2 steps per 60 Hz frame at any refresh rate, on a fixed 120 steps/s clock that rises at high resolutions to stay stable. The wake chop is evaluated only inside the wake band, so it costs nothing on still water.
- Memory at 2560×1440: ripple state 4.0MB, slopes 1.0MB, caustic targets 5.2MB plus the 10.4MB MSAA renderbuffer, bloom 1.3MB and the strip index buffer 1.0MB, about 23MB in total (touch screens use 2× MSAA and a smaller grid, a few MB).
- Always alive while visible. The wind waves never stop, 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(fp32 ripple state, fp16 additive caustics). If 16-bit float MSAA isn't offered, the mesh draws straight into the texture and the blur does the anti-aliasing. Without WebGL2 or float targets, the shell shows its fallback card over the poster frame. - Mobile. Drag to play. On touch screens the backing store is capped at DPR 1.5, the mesh at 152 cells across (the Resolution slider stops there), the caustic target at 340 and the MSAA at 2× (the blur covers the rest). The ghost pointer's figure-8 stands upright on portrait screens, and the lane line moves to the right, clear of the hint. The research notes suggest the mesh-free Jacobian pass for phones; this page keeps the mesh, which holds the frame rate at these sizes. At 390px the harness drew a 585px-wide canvas with no overflow and measured a 44.2–46.3 fps touch drag over six runs (just under the harness's 45 fps warning line in two of them), in a test that takes a full-resolution screenshot mid-drag. The panel's meter read about 48 fps and 2.6ms GPU.
- Reduced motion. One still frame of the wind-wave light, with no ghost ripples, and a “Play anyway” button. The shell renders its still only once, so this page draws the still again after a resize (which clears the canvas) and after any control or preset change. The gallery embed runs at DPR 1 with the mesh capped at 176 cells and the ghost pointer drawing ripples forever (harness: 30 frames per 500ms). There the glitter cells would be smaller than about 7px, so the glitter fades out.
References & credits
- Evan Wallace, “Rendering Realtime Caustics in WebGL” (2016): the area-ratio idea and computing it from fragment derivatives of a projected light mesh. medium.com/@evanwallace (article). His WebGL Water demo, github.com/evanw/webgl-water, is MIT. No code was copied. The determinant form, additive folds, MSAA and dispersion instances here are this page's own.
- Maxime Heckel, “Shining a light on Caustics with Shaders and React Three Fiber” (2024): a post-pass blur, and raising the area ratio to a power for contrast (the Contrast control). blog.maximeheckel.com (article).
- Hugo Elias, “2D Water”, the classic two-buffer leapfrog ripple. web.archive.org (article; the algorithm is folklore). The 9-point Laplacian, Kelvin–Voigt damping, sponge, fused moving trough and pile-up analysis come from this library's research notes. The viscous wake swell, the wake chop and the trough release are this page's own.
- Jerry Tessendorf, “Simulating Ocean Water”, SIGGRAPH course notes: deep-water dispersion
ω = √(gk), used for the wind waves' relative speeds. jtessen.people.clemson.edu (paper). - Hashes: Chris Wellons'
lowbias32integer hash, nullprogram.com (public domain), and Tommy Ettinger'smulberry32PRNG for the wave seeds, gist.github.com/tommyettinger (public domain). - Research:
research/waves-lbm-caustics.mdin this library (the heightfield ripples and caustics sections, and thecaustic-filamentsandpool-light-litecandidates). The conventions (fixed-step sim, capsule pointer path, dither, no haze) come from the stable-fluids cursor trail in the Russ Hype Machine page. All shaders on this page are written from scratch.