---
id: "eikonal-coastal-wave-refraction-shoaling"
title: "Fast-Sweeping Eikonal Coastal Wave Refraction & Ray-Tube Shoaling"
aliases: [eikonal wave refraction, fast-sweeping shore breakers, bathymetry wave shoaling]
domain: "volumes"
stage: "volume"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal]
year_introduced: 2002
inputs: [heightfield, texture]
outputs: [heightfield, normals, mesh]
style: "photoreal"
dynamic: "both"
cost: "cheap"
authority: "Zhao, 2004"
url: "https://texelatlas.vercel.app/t/eikonal-coastal-wave-refraction-shoaling/"
sources_verified_at: "2026-11-30"
---
# Fast-Sweeping Eikonal Coastal Wave Refraction & Ray-Tube Shoaling (Zhao, 2004)

> 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.

## 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

## 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 use it

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](fft-ocean) for open deep-water wind seas where bathymetry is uniform and periodic spectral synthesis excels. Prefer [shallow-water-equations](shallow-water-equations) when you need two-way dynamic fluid interactions, wakes, or rapidly changing water levels rather than steady-state swell refraction. Prefer [gerstner-waves](gerstner-waves) when a handful of unrefracted analytic wave trains suffice.

## Cost

cheap — Fast-sweeping Eikonal baking runs once per bathymetry change in milliseconds on CPU or GPU; runtime evaluation needs only texture lookups per vertex/pixel (Ultra-Water reports ~1.9–3.0 ms total for its full water pass at 1440p on an RTX 3060).
Measured GPU Weight: 5.29× baseline (light) — 0.1741 ms median / 0.1809 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 5.12× baseline (light) — 0.0814 ms median (2.14× faster on L4).
Ampere A100 scaling: 3.69× baseline (light) — 0.1063 ms median (1.64× faster on A100).

## Failure modes

- 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

## Dataflow

- Inputs: heightfield, texture
- Outputs: heightfield, normals, mesh
- Platforms: webgl2, webgpu, desktop-gpu, mobile-gpu, unity, unreal

## Presets

### Eikonal Coastal Wave Refraction & Shoaling — travel-time fronts & bathymetry (left) vs refracted breaking surf (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_WAVE_PERIOD": 18,
  "P_SHOAL_GAIN": 1.15,
  "P_SWELL_DIR": 0.28,
  "P_SPLIT": 0.48
}
```

```glsl
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.

## Combines with

- [FFT Ocean (Tessendorf)](https://texelatlas.vercel.app/t/fft-ocean.md): Provides multi-cascade deep-water wind waves that blend seamlessly into Eikonal refracted breakers as seabed depth shoals.
- [Real-time Water Caustics](https://texelatlas.vercel.app/t/water-caustics-realtime.md): Uses the refracted surface slopes and shallow bathymetry map to project depth-accurate animated caustics onto the seabed.

## Combination ideas

- [Bathymetry-refracted coastal ocean with shore caustics](https://texelatlas.vercel.app/ideas/eikonal-refracted-fft-shore-caustics/)

## Sources

1. [primary] Hongkai Zhao (2004) A fast sweeping method for Eikonal equations. Mathematics of Computation. https://doi.org/10.1090/s0025-5718-04-01678-3 (verified via crossref on 2026-11-30)
2. [primary] Manuel N. Gamito, F.Kenton Musgrave (2002) An accurate model of wave refraction over shallow water. Computers &amp; Graphics. https://doi.org/10.1016/s0097-8493(01)00181-9 (verified via crossref on 2026-11-30)
3. [secondary] Stefan Jeschke, Chris Wojtan (2017) Water wave packets. ACM Transactions on Graphics. https://doi.org/10.1145/3072959.3073678 (verified via crossref on 2026-11-30)
4. [implementation] Humpalumps (2026) Humpalumps/Ultra-Water. https://github.com/Humpalumps/Ultra-Water License: MIT. (verified via github on 2026-11-30)

## Cite this entry

Texel. "Fast-Sweeping Eikonal Coastal Wave Refraction & Ray-Tube Shoaling." https://texelatlas.vercel.app/t/eikonal-coastal-wave-refraction-shoaling/ (accessed 2026-12-01).
