How it works
The hero sits under a sheet of heavy water: a damped wave equation on a 356×200 height field, stepped at a fixed rate. The cursor is a moving dimple. Each step it fills the water back where it was and digs it where it is now, so it conserves volume and, moving faster than the waves, leaves a true Mach-cone V behind it. It also ploughs a furrow, a trough between two ridges that stays where you drew it and creeps flat over about three seconds while the V travels away. WebGL can’t see the DOM, so the page paints its own hero (the real, selectable HTML above, word by word from the browser’s line boxes) into a texture. The display then looks at that texture through the water: it is refracted (crests magnify, troughs shrink), shaded by light focused through the swells and by the shadow raised water casts, tinted by water depth, and it catches a small studio light as one soft crescent on every swell, with a bloom around it on the dark page.
Pipeline (per frame)
pointer segment (shell) · click = drop canvas 2560×1440 · sim 356×200 (Resolution 200)
│
│ fixed-step accumulator: rate from the CFL bound, 120–960 steps/s (Clear: 120/s = 2 per 60Hz frame),
│ the frame’s pointer segment is split evenly across the steps, at most 16 steps per frame
│
├─▶ WAVE ×n state RGBA32F (h, h_prev, f) 356×200 NEAREST, texelFetch, ping-pong
│ ∇² 9-point isotropic: (4·Σedges + Σcorners − 20·c) / 6
│ v = damp·(v + C2·∇²h + VISC·∇²v) h = (h + v)·keep (v = h − h_prev)
│ push = depth·(B(last segment) − B(this segment)) + drop + 0.02·∇²h (only with VISC passes)
│ B = (4/3)(Ḡ_r − ¼Ḡ_2r), Ḡ = a Gaussian averaged along the segment (closed form, erf)
│ h += push, h_prev += push (no kick)
│ furrow: f = (f + D·∇²f)·keep_f − plough·(∫G_r − ¼∫G_2r) ds / (√π r) (never enters the waves)
│ sponge: damping ramps up over the outer 10% of the short side, 4/s at the edge
├─▶ VISC ×2s after each WAVE, only when ν·Δt/Δx² > 0.12 (Glass: s = 2, 4 passes per step)
│ v ← v + aⱼ·∇²v in Chebyshev pairs: Π(1 + aⱼλ) = T_s(1 + 2λ/L′)²
├─▶ SURFACE 2 targets (MRT), RGBA16F 356×200 LINEAR, of the surface h + f
│ surf (h + f, Scharr ∂/∂x, ∂/∂y, det(I + F·Hess)) hess (h_xx, h_yy, h_xy, ·)
├─▶ GLINT RGBA16F 640×360: the key light alone (same code as DISPLAY)
├─▶ DOWN ×4 320×180 → 160×90 → 80×45 → 40×23 dual-filter 5-tap
├─▶ UP ×3 80×45 → 160×90 → 320×180 8-tap tent; r adds each level (bloom), g carries the widest (coverage)
└─▶ DISPLAY canvas 2560×1440, opaque
surf: cubic B-spline from 4 bilinear taps → slope g → tone-map → soft limit → clear zone
hess: 1 bilinear tap → J = D(tone-map)·Hess → shape of the key light’s image
page: 1 tap offset by g·R, plus 2 more for R and B on the steepest slopes (dispersion)
caustics: 1/|det| per pixel · folds ^1.5 · dark: scale + glow · paper: capped shade, warm lines
paper: cast shadow from 2 bilinear height taps, 0.03 short sides toward the light
water: Beer–Lambert by thickness + in-scattered colour on dark
surface: Fresnel (raw slope) · soft key disc × saddle, stripe and coverage fades · soft lobes
glow: 1 bilinear tap of the 320×180 level · bloom on dark, coverage cap everywhere
highlight shoulder → linear → sRGB → ±½ LSB dither
PAGE on load, resize and preset change: DOM layout → Canvas2D, glyphs at their Range rects
→ SRGB8_ALPHA8 2560×1440 + mipmaps
10 + n·(1 + 2s) draws per frame: 12 for Clear, 12–13 for Deep pool, 20 for Glass
The ideas that matter
- Displace the water; don’t kick it. The leapfrog stores two time levels, and velocity is implicit:
v = h − h_prev. Add the cursor’s dimple tohalone and every step also injects that much velocity. A sweep then piles up without bound. In the first build the surface sat pinned at the safety clamp, about 12× the brush depth, even during the gentle intro. The wave pass adds the samepushto both levels instead. That moves water without accelerating it, and the peak height stays at about one brush depth. - A moving dimple with its own rim makes the V. Each step fills the brush back in along the segment it was dug last step and digs it along this step’s, so a stroke telescopes to a dimple where it began and one under the cursor. The brush is
(4/3)(G_r − ¼G_2r), a dimple with a rim that holds the water it displaced, so it has zero volume. The first builds used a plain Gaussian, which carried water from the cursor all the way back to where the stroke began. That tilted the whole basin into a slow seiche, and after every stroke the entire page drifted by a pixel or two for seconds. Each Gaussian is averaged along its step’s segment in closed form (with an erf), so a small brush on a fast flick, which moves further than its radius in one step, draws a smooth capsule instead of beads. Faster than the wave speedc, the disturbance outruns its own waves and they pile into a cone of half-angleasin(c/v). At the default 0.28 short sides per second on a 720px-tall screen, a 360px/s stroke (Mach 1.8) trails a 34° V, a 500px/s stroke (Mach 2.5) a 24° one, and an 1100px/s flick (Mach 5.5) an 11° one. Slower thanc, rings run ahead. Near Mach 1 the source keeps feeding its own wavefront, so the push is eased by up to 60% there. Above Mach 3 it is eased by √(3/M), because a fast flick’s narrow V is almost all wall. The speed behind both is smoothed over about 50ms, because pointer events and frames don’t line up: one frame’s steps can be twice as long as the next one’s, and depths keyed to the raw step would bead the wake. - A furrow that stays where you drew it. The wave equation here has no dispersion, so everything the cursor puts into it travels away at
c. The V is beautiful, but 1.5–2s after a stroke the path itself was calm again. So each step also deposits the drop’s zero-volume profileG − ¼G(2r), integrated along the step’s segment in closed form, into a third channelf. Summed over a stroke this is a trough 0.75 × brush depth × Furrow deep, with ridges at ±1.66r that are 0.375 of its depth. Line integrals of consecutive steps join without seams, so it is equally deep at any speed. A creeping cursor (below about 0.2 short sides per second) barely ploughs, so easing onto a button leaves nothing in front of it, and a fast flick ploughs shallower, by √(1.2/v), so a big swipe can’t carve a canyon. The furrow never enters the wave equation. It is the creeping relaxation of a viscous film: it diffuses (widening √1.24× over its life) and fades with an e-fold time of Furrow life (3.5s by default, 4.5s in Glass), while the V radiates away. The surface everything else sees ish + f. - A fixed step chosen from the stability bound. With the 9-point stencil the most negative Laplacian eigenvalue is −16/3. The leapfrog with the explicit Kelvin–Voigt term
ν∇²h_tthen stays stable whileC2 + 2·VISC ≤ 0.75, withC2 = (c·Δt/Δx)²andVISC = ν·Δt/Δx². The page solves for the step rate that puts the sum at 0.6, with at most 0.12 of viscosity fused into the wave pass and never fewer than 120 steps per second. An accumulator then runs exactly that many steps per second, so a 120Hz display gets the same waves as a 60Hz one, not waves twice as fast. Clear and Glass run at 120 steps per second and Deep pool at 129. - Viscosity that never saturates. Any viscosity beyond the fused 0.12 goes to separate passes,
v ← v + a·∇²v. A single pass is only safe fora ≤ 3/16, because the leapfrog needs the viscous factor in [0, 1] for every mode: a negative factor makes it blow up. So the passes come in pairs whose product is a squared Chebyshev polynomial,T_s(1 + 2λ/L′)²: the step sizes of super-time-stepping (Alexiades, Amiez and Gremaud, 1996), each used twice. It is never negative and never above one on the stencil’s whole spectrum. Its slope at λ = 0 is exactlya, so long swells decay at the true rateν·k². Two passes reacha = 0.75, four reach 3 and six reach 6.75: 2×, 4× and 6× what the same passes manage one at a time. The small and large sub-steps alternate, so no intermediate state ever grows. One catch: the product is exactly zero at the Chebyshev nodes, so a mode there loses all its velocity every step, and its height can never relax. Near-grid-scale ripples froze into a static comb along the walls in Glass. While the passes run, the wave pass therefore also smooths the height by0.02·∇²h, on both time levels so it adds no velocity. That relaxes a 3.5-cell ripple in about 0.2s and is negligible at the brush’s wavelengths. Viscosity is set in physical units (10⁻³ short sides²/s), so it looks the same at every resolution. The slider’s top value, 8 at Resolution 320, needs six passes per step, and no value saturates. - Round rings and round highlights. The 5-point Laplacian lets diagonal waves travel at a different speed, so rings come out slightly square. The isotropic 9-point stencil fixes that. The slope uses Scharr weights (3, 10, 3), and the display reads it through a cubic B-spline built from 4 bilinear taps. At about 3.6 CSS px per cell, bilinear slopes would facet every highlight into a diamond grid.
- Glass creeps instead of ringing. The Kelvin–Voigt term damps a wavelength at about
ν·k²/2: at Glass’s ν = 3.5, a 70px ripple dies at about 7 per second. Glass also raises the velocity damping to 2.4 per second, which puts its brush’s own wavelength (about 0.6 short sides) close to critical damping. Shorter swells still ring but die within half a second, and longer ones no longer travel: they creep, diffusing at aboutc²/γ= 0.01 short sides²/s. What a stroke leaves is a heavy, slow furrow (brush 0.15 short sides, depth 3, Furrow 1.2, life 4.5s) under 2.5× refraction, over its own page of ruled paper and an arch poster, deepening in amber where the glass stands thick. - The hero is real HTML. The headline, copy and buttons are ordinary DOM laid out by CSS, and the HTML ships with the default layout’s copy, so the page reads with JavaScript off. Only once WebGL2 is up does the page add
html.fx-live, and only that class turns the glyphs (-webkit-text-fill-color: transparent), button fills and CSS art panel off. Visible text is the default, with no:has()needed, and a lost context or a runtime error takes the class off again. Text still selects, links still click and focus rings still show, and the effect never sits between the cursor and a target. The painter walks the text nodes, measures each word withRange.getClientRects(), and draws it with the element’s computed font, colour, letter-spacing and case at device resolution. Its baseline is placed from the font’s own ascent and descent. Engines withoutCanvasRenderingContext2D.letterSpacingget the letter-spaced runs glyph by glyph, from measured advances plus the spacing. The layout is therefore the browser’s, and responsive for free. Each preset picks one of three layouts (editorial, product, studio) through adata-layoutattribute. Fills that would show through the DOM, such as the button background, live in custom properties that only the painter reads. - Crests magnify, by physics. A ray looking straight down bends toward the uphill side of the surface. The page is therefore sampled at
uv + R·∇h, whose JacobianI + R·Hess hdrops below one at crests (magnify) and rises above it in troughs (shrink). Dispersion scales the offset per channel (1 − δ, 1, 1 + δ), masked to the steepest slopes, so it reads as prism light at the sharpest bends rather than as an RGB split. It shows best with high refraction (Glass uses 2.5). - Interpolate the caustic’s determinant, not its brightness. Light reaching the page is focused by the same map, so its density is
1/|det(I + F·Hess h)|: the mesh-free Jacobian form of Wallace’s area ratio. The surface pass stores the signed determinant, which is smooth, and the display takes the reciprocal per pixel after the 4× bicubic upsample. The fold lines, where det crosses zero, come out as crisp filaments at screen resolution instead of 4px blobs. Raising the excess to the power 1.5 keeps mild focusing dim and the folds bright. - Glints that read as light, not stickers. For small slopes the normal’s xy is just
−∇h. So the key light, about 5° off zenith toward the upper left, is a disc of radiuswin slope space centred on a 2.6° tilt, and every swell’s lit flank mirrors it as one crescent. Its edge falls off over the outer third ofw, widened to at least a pixel through the slope field’s analytic JacobianJ. (The surface pass writes the Hessian, and the display maps it through the tone curve’s own Jacobian.) Two fades come fromJ, and neither can vanish inside a glint. Long straight stripes, such as the walls of a fast V, fade because the slope barely changes along the front. Saddles fade wheredet J < 0, because there the disc’s preimage is a four-lobed star with a hole. The last build also faded glints whose|J|was small, which hollowed out every glint at a wave’s inflection line into a grey doughnut. Size is now measured directly. A glint pass renders the key alone at quarter resolution, and a dual-filter chain blurs it down four octaves and back up. Its widest level, carried up through the tents, is the fraction of the surrounding ~120 CSS px a glint covers. Crescents cover a few percent and stay, while a broad flat lobe that would mirror the light as one big white pill fades out evenly. On dark, the sum of the octaves is the glints’ bloom. - No grey on dark, no milk on paper. On paper nothing can get brighter than the paper, and a bright reflection only lifts the ink toward it, which reads as a milky film. So on paper the Fresnel ramp follows the raw slope (the tone curve lifts small slopes), starts later and stays lower. Its floor side is the paper’s own colour a shade darker, and its sky side is held to a quarter. The depth comes from a soft cast shadow instead: where water stands higher 0.03 short sides toward the light, the page is darkened by up to 21%. Like the caustic shade under troughs, it takes the colour of light that crossed more water: cool under Clear’s aqua, warm under Glass’s amber. Thickness tints the paper mostly where water stands above its rest depth, so crests and ridges read aqua and the paper keeps its own colour. Where light gathers there is a faint warm lift, only where it clearly gathers, so it draws lines of light rather than haze. On the dark page every soft term (halo, counter light, caustic glow, room reflection, bloom) takes the water’s own colour: mixed toward white, they turned the navy into smoke.
- Staying power, measured where you look. The probe is a straight stroke across the hero at 500px/s, with screenshots at its end and 1 and 3s later. Each is scored as the mean per-pixel difference from the flat page in 8-bit levels, over a 1040×220 CSS px band centred on the stroke. (The last build reported whole-frame means, which counted broad slosh and hairlines shifted by a pixel and overstated what a viewer sees.) Clear scores 19.7, 18.6 and 14.0, keeping 71% at +3s (before: 15.0, 9.8 and 7.7, or 52%). Glass scores 31.0, 30.1 and 25.5, keeping 82% (before: 26.8, 23.7 and 9.7, or 36%). Deep pool scores 38.5, 35.4 and 21.1, keeping 55% of a much stronger start (before: 9.0, 6.4 and 7.3). A straight furrow displaces the page across itself, so it bends nothing that runs along it. On paper it reads through the cast shadow, the shade under the trough and the thickness tint, and on the dark page through its lit flanks. A curved stroke also bends the type and rules it crosses.
- Calm before stillness. The shell stops the loop 8s after the last activity. Over the final 2.6s the damping ramps up, on the furrow too, so the last frame drawn is flat glass, never a frozen swell. A clear zone (default 0.08 short sides) keeps the water optically flat around a resting or slow cursor, so the button you are about to press is never distorted. During a fast stroke it shrinks to 30%, so the V starts right behind the cursor, and it grows back within about 0.2s as you slow to click.
Parameters
Presets
Performance & compatibility
- Measured by the harness: Chrome, ANGLE-Metal, an Apple-silicon Mac, 1280×720 at DPR 2 (a 2560×1440 backing store), during its 1.5s pointer sweep with the default Deep pool preset. Other pages’ harnesses were running on the same GPU throughout, so no idle run was available and these are contended numbers. Across nine runs of this build the GPU read 3.3–5.4ms mean and 5.5–9.1ms p95 per frame; the final full run read 3.3 / 6.8ms. JS took 0.04–0.14ms per frame, at 59.3–60fps (p95 frame time 16.7–16.8ms; one run had a single frame over 25ms). An interleaved A/B against the previous build, three runs each on the same 2.5s sweep and under the same load, put this build about 1ms higher on the mean and 2ms on the p95 (Clear 3.2–3.5 / 6.7–8.1 against 2.2–3.8 / 4.8–5.6; Deep pool 2.5–5.7 / 5.1–9.9 against 2.0–3.4 / 3.9–6.7; Glass 4.1–5.6 / 6.2–9.7 against 3.3–4.8 / 4.8–7.8). That covers the glint chain, the cast-shadow taps and more of the frame staying refracted for longer.
- Where the time goes. The display pass reads 4 surface taps, 1 Hessian tap, 1 glow tap and 1–3 trilinear-anisotropic page taps per pixel across 3.7 MP, plus 2 more surface taps on paper, and that is the cost. The glint pass reads 5 taps across 0.23 MP, and the 7 blur passes touch 0.17 MP in all. A wave or viscous pass touches 71k cells with 9 fetches each; the wave pass also evaluates six closed-form segment integrals per cell. Clear and Deep pool run 2 to 2.2 wave steps per frame, and Glass runs 2 steps plus 8 viscous passes per frame. The slider corner Resolution 320 with Viscosity 8 runs about 17 passes per frame. Memory: the page texture is about 19.7MB (2560×1440 sRGB8 plus mipmaps). The state is 2.3MB (two RGBA32F at 356×200), the two surface targets 1.1MB and the glint chain 3.1MB.
- Requirements. WebGL2 with
EXT_color_buffer_float, to render the RGBA32F state and the RGBA16F surface and glint targets (the surface pair written in one pass withdrawBuffers). If RGBA32F is not renderable, the state falls back to RGBA16F. Filtering of 32F is never needed, because the state is read withtexelFetch. Without WebGL2 (or with JavaScript off, or after a failure before GL starts) the hero is plain HTML: text, button fills and an approximate CSS art panel, unrefracted and clickable, with a small message card in the corner when JavaScript runs. The hero text stays in the DOM for screen readers either way. - Mobile. On coarse pointers the canvas now runs at DPR 2 (780×1688 on a 390px phone; it was capped at 1.5, which painted the hero copy at half a DPR-3 phone’s resolution), and the sim at 150 cells across (150×325). Tap drops a ring; dragging trails the wake. The layout stacks to one column and the art panel fills what the copy leaves, so a tall phone has no empty paper below it. The page has no horizontal overflow, and the controls become a bottom sheet. In the emulated 390px touch run a 1.5s drag held 60fps at 1.3–1.7ms GPU mean (one contended run 3.9ms). The harness’s own figure, which takes a full-resolution screenshot in the middle of the drag, read 41.7–47.7fps at DPR 2 against 50.1–50.9 at DPR 1.5 for this build.
- Idle, reduced motion, embed. The loop stopped 8.1s after the last activity, with no frames after. It pauses off-screen and in hidden tabs. Under
prefers-reduced-motionthe page simulates 1.5s of the ghost stroke plus one ring off-screen and shows that single frame, with a “Play anyway” button. Changing a control re-renders that still once the input settles (120ms), without re-allocating unless Resolution changed. The default preset, the gallery embed and the poster use Deep pool, the strongest first impression. The embed renders at DPR 1 with a sim of at most 128 cells across, and drops a ring every 2.9s while the ghost pointer keeps sailing.
References & credits
- Hugo Elias, “2D Water” (archived): web.archive.org/…/x_water.htm. This is the classic two-buffer height-field update, and the algorithm is folklore. The page is all rights reserved, and no code was taken from it.
- Evan Wallace, WebGL Water: github.com/evanw/webgl-water (MIT, per its file headers). Two ideas come from it: moving an object by adding its old volume and subtracting its new one, and caustics as an area ratio. Also his “Rendering Realtime Caustics in WebGL”: medium.com/@evanwallace. This page uses the mesh-free Jacobian variant and is written from scratch.
- V. Alexiades, G. Amiez and P.-A. Gremaud, “Super-time-stepping acceleration of explicit schemes for parabolic problems”, Communications in Numerical Methods in Engineering 12 (1996), 31–42: doi.org/10.1002/(SICI)1099-0887(199601)12:1<31::AID-CNM950>3.0.CO;2-5 (paper; no code used). The Chebyshev sub-step sizes of the viscous passes.
- M. Bjørge, “Bandwidth-Efficient Rendering”, SIGGRAPH 2015 course notes: community.arm.com (PDF). The dual-filter downsample and upsample kernels of the glint chain, written from the description.
- S. Winitzki, “Uniform approximations for transcendental functions”, ICCSA 2003, LNCS 2667, 780–789: doi.org/10.1007/3-540-44839-X_82, with the
a = 0.147refinement listed at en.wikipedia.org/wiki/Error_function. The erf in the closed-form segment integrals. - C. Sigg and M. Hadwiger, “Fast Third-Order Texture Filtering”, GPU Gems 2, ch. 20 (NVIDIA, 2005): developer.nvidia.com/gpugems. This is the source of the cubic B-spline from 4 bilinear taps.
- M. Patra and M. Karttunen, “Stencils with isotropic discretization error for differential operators”, Numerical Methods for Partial Differential Equations 22 (2006): doi.org/10.1002/num.20129 (paper, no code license; none used). This is the source of the 9-point isotropic Laplacian.
- Dave Hoskins, “Hash without Sine”: shadertoy.com/view/4djSRW (MIT). The dither’s hash12 is credited in the shader.
- J. Tessendorf, “Interactive Water Surfaces”: jtessen.people.clemson.edu. This is the upgrade path to dispersive, Kelvin-angle (19.5°) wakes. It is not used here.
- sirxemic/jquery.ripples: github.com/sirxemic/jquery.ripples (MIT). It is the familiar 2011 look this page sets out to improve on: small, fast and tied to the frame rate. No code was used.
- Research notes behind this page:
research/waves-lbm-caustics.md(height-field ripples, caustics, theripple-glasscandidate) andresearch/distortion-glass-post.md(refraction, Fresnel, dispersion, bloom, the content texture).