Two demos of one wave system. The first is a shore break: swell rolling in, steepening over a rising bed and spilling on a straight beach. The second is a curved shore with eleven rocks in the surf and a rock pool that the waves keep filling. Both run below, and each is one file.
Three.js 0.187, WebGPU and TSL, no WebGL fallback. Nothing is simulated on the CPU. Every surface, every drop of spray and every wet patch of sand is a closed-form function of position and time, evaluated on the GPU.
Waves as functions, not meshes
The whole wave system is one module of pure TSL functions of x, z and time. It touches no DOM, no scene and no mesh. The surfaces ask it questions: how high is the water here, where is the swash tongue along this stretch of beach, is this point in a rock's lee, how much foam. That split was the point of the exercise. A module with no dependencies can be lifted into another project as it is, and that is where it is going.
The shoreline is a curve and the beach a slope, each written twice: once in JavaScript for the baked heightfield, once in TSL for the shaders, two one-liners kept side by side so they cannot drift apart. The beach is computed once in JavaScript, with its relief, its dips and the carved pool, and baked into a half-float texture. The shaders sample that. Seaward of the bake, the open sea floor is the analytic plane. One source of truth for the ground, and the wave functions read it everywhere.
Timing, shoaling and run-up
A wave's period is about five seconds. Its arrival time at any point comes from the distance it has travelled over a bed that shallows from seven metres at a hundred and twenty metres out to thirty centimetres at the still-water line, so the crest slows and steepens as it comes in, the way a real one does. Crests are not straight: a fine and a broad phase offset bend them along the shore, and a height factor gives sets of bigger and smaller waves, wave-to-wave variation, and peaks and lulls along one crest.
Run-up is the part people see. The tongue of water that a wave sends up the sand reaches 3.2 × height + 4.5 metres along the beach, rises, pauses, and pulls back a metre and a half in the backwash. Where two reach lines cross, a hard maximum left a sharp dry wedge on the sand, so the maximum is rounded over a few metres. The reach also varies more gently along the shore than the crest does, because the tongue spreads sideways as it runs. Those two details took longer than the waves themselves.
Rocks, dips and the pool
Every rock has a footprint on the water sheet: a lee shadow shoreward where the swash cannot reach, a pile-up on the sea face, a foam collar, and water squirting round the flanks once the tongue arrives. The shadow on the run-up is shallow, a quarter of the reach beyond the rock at most, and widens with the distance the water travels past it as it closes in behind. A deep notch here was the first version, and it read as a pointed wedge drawn on the sand with a ruler. The rocks are one instanced mesh with their wet line computed per vertex, so the wave graph runs on 1 280 vertices per rock rather than on every rock pixel.
Dips in the sand hold water. A hollow is filled when the tongue passes over it and remembers that for a set number of seconds, draining as it goes, so puddles are left behind each wave and dry out between them. The rock pool is the same idea scaled up: a carved basin whose level, ripples and foam are driven by the swash overflowing its lip.
Spray that costs nothing to think about
There are three particle emitters: spray off breaking crests, a tight plume leaving at close to the wave speed; shore splash, thrown up where the tongue starts its run and landing within a second; and a burst off each rock when the tongue or a wave front reaches it. Each particle's whole trajectory is a closed form in time. A compute pass evaluates it once per particle per frame and writes position, size and alpha to storage buffers, and the sprite shader only reads them. The first version evaluated the trajectory on all four vertices of every sprite, which is four times the work for the same picture. Drops that land rest on the swash film if it covers the sand, else on the sand or the sea, so a fleck is never hidden under the transparent water sheet whatever the camera angle. Sizes are mostly small with a few large, a cubic skew of a uniform random, and everything fades from birth so nothing pops.
The water itself
The sea sheet uses a copy of the Hard Road ocean shader: planar reflection, screen-space refraction, Beer-Lambert absorption, caustics, a subsurface lift, a GGX sun glint, and the foam stack of shore pulse, lace, Worley bubbles, whitewater billow and waterline foam. That shader is frozen in Hard Road, so this is a copy that takes its surface from the wave functions instead of a Gerstner sum. The sea grid is fine in the surf zone and coarse under the fog, and everything that depends only on z or only on the vertex grid, the swash, the rock footprints, the wave profile and the dip fills, is computed per vertex and interpolated. The fragment stage keeps the foam texture, the ripple normal and the heightfield sample.
The files
WebGPU only, on Three.js 0.187, with no WebGL fallback. If the browser has no WebGPU, the page says so and stops. Each demo is one HTML file with the wave module, the tunables and the scene inside it. Open them through a server, because file:// will not load the modules.
shore-break.html, the straight beachshore-pool.html, the curved shore with the rocks and the pool
The demos were built to answer one question: can a beach with rocks, pools and spray run as pure functions on the GPU, with the tunables in one file and the wave module portable? It can. The module is written to drop into the Hard Road engine next, under a frozen sea rather than a sandy one.