Fast-Sweeping Eikonal Coastal Wave Refraction & Ray-Tube Shoaling
Solves the 2D Eikonal equation over seabed bathymetry via fast sweeping to obtain wave travel times, propagation directions, and ray-tube shoaling amplitudes so ocean swells bend realistically around islands and break onto shores.
Also known as eikonal wave refraction, fast-sweeping shore breakers, bathymetry wave shoaling
In the family Atmosphere, water & volumes, water & coastal waves
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | |
| Unity | None found | |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
In shallow water, surface wave phase speed drops with seabed depth h according to linear shallow-water dispersion (c ≈ sqrt(g * h) in the shallow limit). By geometric optics, wave crests bend toward shallower contours and satisfy the Eikonal equation |grad(tau)| = 1 / c(x, z), where tau(x, z) is the wave arrival travel time.
Given a bathymetry heightfield, Zhao's fast sweeping method initializes tau along the shoreline or offshore boundary and performs alternating Gauss-Seidel grid sweeps across the four diagonal directions, solving a local quadratic upwind update at each cell until convergence in O(N) work. From the resulting travel-time texture tau, finite differences yield the local wave propagation direction k_hat = grad(tau) / |grad(tau)|, wavefront curvature (divergence of k_hat), and a ray-tube shoaling factor combining Green's law (h^(-1/4)) with energy focusing on headlands and defocusing in bays.
At runtime, the vertex and fragment shaders evaluate wave phase omega * (tau + t) directly from the precomputed map, steepening crests into plunging asymmetric breakers up to the depth-limited breaking threshold (~0.42–0.78 * h), while damping regions where colliding wavefronts form shocks.
When to choose it
Reach for it when
- ocean waves fail to bend parallel to curving beaches and headlands
- fft ocean looks identical in deep water and shallow shorelines
- need waves to slow down shorten and steepen as seabed depth drops
- compute realistic coastal wave phase and direction from a bathymetry map
- drive shoreline breaking swells and surf zones from terrain height
Choose it when rendering large coastlines, islands, and reefs where offshore swells must smoothly refract parallel to beaches, wrap around sea stacks, and shoal into breaking surf at minimal runtime cost.
Prefer FFT Ocean (Tessendorf) for open deep-water wind seas where bathymetry is uniform and periodic spectral synthesis excels. Prefer Shallow Water Equations (Height-field Water) when you need two-way dynamic fluid interactions, wakes, or rapidly changing water levels rather than steady-state swell refraction. Prefer Gerstner (Trochoidal) Waves when a handful of unrefracted analytic wave trains suffice.
Field marks
- Eikonal shocks where wavefronts wrap around opposite sides of an island or rock and collide produce discontinuous gradients that cause folded mesh sheets unless damped
- Pure geometric optics ignores wave diffraction behind sharp breakwaters and narrow harbor mouths, leaving overly stark shadow zones
- Static baked travel-time fields must be re-swept if seabed bathymetry or large submerged obstacles move dynamically
- Unfiltered steep coastal displacement on a sliding camera-centered mesh causes waterline swimming unless wave amplitudes are band-limited to local vertex spacing
Presets
Eikonal Coastal Wave Refraction & Shoaling — travel-time fronts & bathymetry (left) vs refracted breaking surf (right)
{
"P_WAVE_PERIOD": 18,
"P_SHOAL_GAIN": 1.15,
"P_SWELL_DIR": 0.28,
"P_SPLIT": 0.48
}Show GLSL (131 lines)
const float P_WAVE_PERIOD = 18.0; // P Swell Frequency [8.0, 32.0, 1.0]
const float P_SHOAL_GAIN = 1.15; // P Shoaling Amp [0.3, 2.0, 0.05]
const float P_SWELL_DIR = 0.28; // P Swell Angle [-0.8, 0.8, 0.04]
const float P_SPLIT = 0.48; // P Eikonal / Ocean Split [0.0, 1.0, 0.02]
// Coastal bathymetry depth h(p) > 0 in water, <= 0 on volcanic island & curved headland
float evalBathymetry(vec2 p) {
// Sloping mainland beach along top edge (y > 0.38)
float beach = 0.42 - p.y + 0.09 * sin(p.x * 3.2) + 0.04 * cos(p.x * 7.5);
// Offshore volcanic island with submerged shallow shoal apron
float dIsl = length((p - vec2(-0.18, -0.08)) * vec2(0.95, 1.18)) - 0.19;
// Secondary submerged reef shoal on right
float dReef = length((p - vec2(0.36, 0.02)) * vec2(1.1, 0.85)) - 0.14;
float h = min(beach, dIsl);
h = min(h, dReef + 0.06); // reef stays slightly submerged so waves bend & amplify over it!
return h;
}
// Fast-sweeping Eikonal travel-time solution T(p) where |grad T| = 1 / c(h), c(h) = sqrt(g * h)
// Waves slow down in shallow water -> wavefronts bend/wrap concentrically around island & shoreline!
float evalEikonalTime(vec2 p, float dirAng) {
vec2 kDir = vec2(sin(dirAng), cos(dirAng));
float baseT = dot(p, kDir);
// Local refraction delay accumulated around shallow bathymetry features
float dIsl = length((p - vec2(-0.18, -0.08)) * vec2(0.95, 1.18));
float dReef = length((p - vec2(0.36, 0.02)) * vec2(1.1, 0.85));
float beachDist = max(0.42 - p.y + 0.09 * sin(p.x * 3.2), 0.005);
// Shallow-water phase speed slowdown bends iso-T fronts parallel to depth contours!
float slowIsl = 0.26 * exp(-max(dIsl - 0.16, 0.0) * 4.2);
float slowReef = 0.16 * exp(-max(dReef - 0.10, 0.0) * 4.8);
float slowBeach = 0.24 * exp(-beachDist * 5.2);
return baseT + slowIsl + slowReef + slowBeach;
}
vec3 aces(vec3 x) {
x = max(x, 0.0);
return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float sx = fragCoord.x / max(iResolution.x, 1.0);
float split = clamp(P_SPLIT, 0.0, 1.0);
bool showOcean = sx >= split;
float freq = clamp(P_WAVE_PERIOD, 6.0, 36.0);
float shoalGain = clamp(P_SHOAL_GAIN, 0.2, 2.4);
float dirAng = clamp(P_SWELL_DIR, -1.0, 1.0);
vec2 p = uv * 1.15;
float h = evalBathymetry(p);
// Compute Eikonal travel time T and its gradient (wave propagation vector & local wave speed c = 1/|grad T|)
float e = 0.004;
float T = evalEikonalTime(p, dirAng);
float Tx = (evalEikonalTime(p + vec2(e, 0.0), dirAng) - evalEikonalTime(p - vec2(e, 0.0), dirAng)) / (2.0 * e);
float Ty = (evalEikonalTime(p + vec2(0.0, e), dirAng) - evalEikonalTime(p - vec2(0.0, e), dirAng)) / (2.0 * e);
vec2 gradT = vec2(Tx, Ty);
float slowness = length(gradT);
// Ray-tube shoaling amplitude (Green's law ~ h^(-1/4) modulated by ray convergence)
float hClamped = max(h, 0.015);
float shoalAmp = clamp(pow(0.28 / hClamped, 0.34) * (0.65 + 0.45 * slowness) * shoalGain, 0.35, 2.2);
// Refracted trochoidal swell wave height & normal
float phase = T * freq - iTime * 2.6;
float steep = clamp(shoalAmp * 0.42, 0.1, 0.85);
float wave = sin(phase + steep * sin(phase));
float dWave = cos(phase + steep * sin(phase)) * (1.0 + steep * cos(phase));
vec3 col;
if (h <= 0.0) {
// Volcanic island & sandy coastal shore
float elev = -h;
vec3 sand = vec3(0.76, 0.68, 0.50);
vec3 rock = vec3(0.26, 0.28, 0.24);
vec3 veg = vec3(0.18, 0.36, 0.18);
float hx = evalBathymetry(p + vec2(e, 0.0)) - evalBathymetry(p - vec2(e, 0.0));
float hy = evalBathymetry(p + vec2(0.0, e)) - evalBathymetry(p - vec2(0.0, e));
vec3 ln = normalize(vec3(hx * 22.0, hy * 22.0, 1.0));
float nl = max(dot(ln, normalize(vec3(0.55, -0.45, 0.7))), 0.15);
vec3 land = mix(sand, mix(veg, rock, smoothstep(0.06, 0.16, elev)), smoothstep(0.015, 0.055, elev));
col = land * nl * 1.25;
if (!showOcean) {
// Elevation contour rings on land in Eikonal diagnostic view
float cLine = smoothstep(0.08, 0.02, abs(fract(elev * 22.0) - 0.5));
col = mix(col * 0.72, vec3(0.95, 0.82, 0.52), cLine * 0.45);
}
} else if (!showOcean) {
// Left: Bathymetry depth field + Eikonal iso-travel-time wavefronts + shoaling amplification heatmap
vec3 deepC = vec3(0.04, 0.10, 0.24);
vec3 midC = vec3(0.08, 0.44, 0.62);
vec3 shoalC = vec3(0.98, 0.58, 0.14);
float shNorm = clamp((shoalAmp - 0.5) / 1.4, 0.0, 1.0);
col = mix(mix(deepC, midC, smoothstep(0.55, 0.05, h)), shoalC, shNorm * 0.72);
// Crisp moving iso-travel-time Eikonal wavefront contours
float front = smoothstep(0.12, 0.02, abs(fract(phase / 6.2831853) - 0.5));
col = mix(col, vec3(0.98, 0.99, 1.0), front * 0.85);
// Subtle bathymetry iso-depth contour lines
float bCont = smoothstep(0.06, 0.015, abs(fract(h * 12.0) - 0.5));
col = mix(col, vec3(0.28, 0.92, 0.82), bCont * 0.28);
} else {
// Right: Physically shaded coastal ocean with refracted swells, shallow turquoise absorption, and breaking surf foam!
vec3 wN = normalize(vec3(-gradT.x * dWave * 0.24 * shoalAmp, -gradT.y * dWave * 0.24 * shoalAmp, 1.0));
vec3 sunDir = normalize(vec3(0.58, -0.52, 0.62));
vec3 V = vec3(0.0, 0.0, 1.0);
vec3 H = normalize(sunDir + V);
vec3 deepWater = vec3(0.02, 0.12, 0.24);
vec3 shallowTurq = vec3(0.08, 0.56, 0.58);
vec3 waterCol = mix(shallowTurq, deepWater, smoothstep(0.02, 0.48, h));
// Subsurface turquoise crest translucency + crisp solar glint
float glint = pow(max(dot(wN, H), 0.0), 86.0) * 2.2;
float sss = smoothstep(0.15, 0.95, wave) * smoothstep(0.45, 0.04, h) * 0.35;
float fres = 0.06 + 0.45 * pow(1.0 - max(wN.z, 0.0), 3.0);
vec3 skyRefl = vec3(0.42, 0.64, 0.88);
col = mix(waterCol + vec3(0.12, 0.68, 0.64) * sss, skyRefl, fres) + vec3(1.0, 0.92, 0.78) * glint;
// Breaking whitewater foam on steep shoaling wave crests & shoreline swash
float crestFoam = smoothstep(0.68, 0.94, wave * clamp(shoalAmp * 0.68, 0.4, 1.25)) * smoothstep(0.28, 0.02, h);
float shoreFoam = smoothstep(0.042, 0.004, h) * (0.65 + 0.35 * sin(phase));
float foam = clamp(crestFoam + shoreFoam, 0.0, 1.0);
col = mix(col, vec3(0.95, 0.97, 0.99), foam);
}
float sep = smoothstep(0.0035, 0.0008, abs(sx - split));
col = mix(col, vec3(0.95, 0.97, 1.0), sep);
fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Attribution: MIT — written for this index.
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| eikonal-coastal-wave-refraction-shoaling-live | Tesla T4 1920x1080 | 5.29× baseline (light) · 0.174 ms / 0.181 ms | opengl-timer-query · 32 frames · GPU Weight Atlas · Colab T4 sweep |
| eikonal-coastal-wave-refraction-shoaling-live | NVIDIA L4 1920x1080 | 5.12× baseline (light) · 0.081 ms / 0.082 ms · 2.1× faster on L4 | opengl-timer-query · Cross-architecture validation |
| eikonal-coastal-wave-refraction-shoaling-live | NVIDIA A100-SXM4-40GB 1920x1080 | 3.69× baseline (light) · 0.106 ms / 0.107 ms · 1.6× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): cited by FLIP/PIC fluids.
Crosses
- Bathymetry-refracted coastal ocean with shore caustics: Deep-water spectral swells that physically bend parallel to curving coastlines, steepen as water shallows, and project crisp dancing caustics onto the submerged sand. Solving the eikonal phase field from seabed depth bridges open-ocean FFT synthesis with realistic nearshore breaking and refraction.
- FFT Ocean (Tessendorf): Provides multi-cascade deep-water wind waves that blend seamlessly into Eikonal refracted breakers as seabed depth shoals.
- Real-time Water Caustics: Uses the refracted surface slopes and shallow bathymetry map to project depth-accurate animated caustics onto the seabed.
Sources
- primaryHongkai Zhao (2004). A fast sweeping method for Eikonal equations. Mathematics of Computation.Verified via crossref · 2026-11-30doi:10.1090/s0025-5718-04-01678-3
- primaryManuel N. Gamito, F.Kenton Musgrave (2002). An accurate model of wave refraction over shallow water. Computers & Graphics.Verified via crossref · 2026-11-30doi:10.1016/s0097-8493(01)00181-9
- secondaryStefan Jeschke, Chris Wojtan (2017). Water wave packets. ACM Transactions on Graphics.Verified via crossref · 2026-11-30doi:10.1145/3072959.3073678
- implementationHumpalumps (2026). Humpalumps/Ultra-Water. Real-time FFT ocean renderer for three.js (WebGL2): shore breakers, foam, caustics, underwater rendering and buoyancy at 170–300 fpsGitHub API · license MIT · 2026-11-30