Fast-Sweeping Eikonal Coastal Wave Refraction & Ray-Tube Shoaling × FFT Ocean (Tessendorf) × Real-time Water Caustics
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.
Open in StudioReproduced34.2× · 1.06 ms
Verified proof

Split-screen WebGL2 proof comparing deep-water directional wave cascades ignoring coastal bathymetry (left, colliding obliquely into the curved bay with unlit seabed) against bathymetry-refracted eikonal wave phase fronts curving parallel to the shoreline with shoaling steepness and Jacobian-focused RGB dispersive shore caustics projected onto the sloped sand bed (right).
Chromium Headless ANGLE/SwiftShader WebGL2 · 512x512 · reproduces realistic wave-crest wrapping parallel to curved coastal bathymetry, nearshore shoaling foam, and chromatic refracted seabed caustics
Show GLSL proof (150 lines)
const float P_REFRACT = 1.00; // P Eikonal Refraction [0.0, 1.8, 0.05]
const float P_CAUSTIC_GAIN = 1.35; // P Caustic Intensity [0.2, 2.5, 0.05]
const float P_DISPERSION = 0.022; // P RGB Caustic Split [0.0, 0.06, 0.002]
const float P_SHOAL_FOAM = 1.00; // P Shoaling Foam [0.0, 2.0, 0.05]
// Curved cove + rocky headland bathymetry: negative = land above sea level, positive = water depth
float evalDepth(vec2 p) {
// Curved coastline running left-to-right with a protruding rocky headland on left and sandy cove on right
float shoreY = -0.20 + 0.14 * sin(p.x * 4.2 + 0.7) - 0.10 * exp(-pow((p.x + 0.16) * 5.2, 2.0));
// Submerged sandbar shoal offshore
float bar = 0.08 * exp(-pow((p.y - shoreY - 0.28) * 6.5, 2.0) - pow((p.x - 0.08) * 3.0, 2.0));
float d = (p.y - shoreY) * 1.45 - bar;
return d;
}
vec2 depthGrad(vec2 p) {
float e = 0.006;
return vec2(evalDepth(p + vec2(e, 0.0)) - evalDepth(p - vec2(e, 0.0)),
evalDepth(p + vec2(0.0, e)) - evalDepth(p - vec2(0.0, e))) / (2.0 * e);
}
// Deep-water multi-harmonic spectral wind chop (JONSWAP-like cascade)
float fftChop(vec2 p, float t) {
float h = 0.0;
vec2 d1 = normalize(vec2(0.65, -0.76));
vec2 d2 = normalize(vec2(-0.35, -0.94));
vec2 d3 = normalize(vec2(0.88, -0.47));
vec2 d4 = normalize(vec2(-0.72, -0.69));
h += 0.42 * sin(dot(p, d1) * 28.0 + t * 2.1);
h += 0.28 * sin(dot(p, d2) * 44.0 + t * 2.8 + 1.2);
h += 0.18 * sin(dot(p, d3) * 68.0 + t * 3.5 + 2.4);
h += 0.12 * sin(dot(p, d4) * 96.0 + t * 4.4 + 0.5);
return h;
}
// Eikonal coastal wave height: blends oblique offshore swell into bathymetry-aligned refracted phase fronts
float evalWaveHeight(vec2 p, float depth, float t, bool useEikonal) {
vec2 offshoreDir = normalize(vec2(0.58, -0.81));
float deepPhase = dot(p, offshoreDir) * 26.0 + t * 2.6;
if (!useEikonal) {
return 0.55 * sin(deepPhase) + 0.22 * fftChop(p, t);
}
// Shallow-water wave speed c = sqrt(g * h) slows waves near shore, bending phase contours toward depth iso-lines
float hPos = max(depth, 0.015);
float slowness = 1.0 / sqrt(clamp(hPos * 2.2, 0.05, 1.0));
float eikonalPhase = -sqrt(hPos) * 42.0 * P_REFRACT + t * 2.6 + 0.8 * sin(p.x * 5.0);
float shallowMix = smoothstep(0.75, 0.06, hPos);
float phase = mix(deepPhase, eikonalPhase, shallowMix * clamp(P_REFRACT, 0.0, 1.0));
// Green's law shoaling steepens wave crests in shallow water
float shoal = clamp(pow(0.28 / max(hPos, 0.04), 0.25), 0.7, 1.85);
float wave = sin(phase) + 0.28 * sin(2.0 * phase - 0.6) * shallowMix;
// Blend deep FFT wind detail down smoothly in the surf swash zone
return (0.48 * wave * shoal + 0.24 * fftChop(p, t) * smoothstep(0.02, 0.35, hPos));
}
vec2 waveNormalSlope(vec2 p, float depth, float t, bool useEikonal) {
float e = 0.005;
float hx = evalWaveHeight(p + vec2(e, 0.0), evalDepth(p + vec2(e, 0.0)), t, useEikonal)
- evalWaveHeight(p - vec2(e, 0.0), evalDepth(p - vec2(e, 0.0)), t, useEikonal);
float hy = evalWaveHeight(p + vec2(0.0, e), evalDepth(p + vec2(0.0, e)), t, useEikonal)
- evalWaveHeight(p - vec2(0.0, e), evalDepth(p - vec2(0.0, e)), t, useEikonal);
return vec2(hx, hy) / (2.0 * e);
}
// Screen-space refracted ray Jacobian caustic intensity at seabed point
float causticChannel(vec2 p, float depth, float t, float iorOffset) {
float hPos = max(depth, 0.01);
// Snell refraction offset onto seabed scales with depth and wave slope
vec2 s0 = waveNormalSlope(p, depth, t, true);
float refractScale = 0.0022 * (1.0 + iorOffset) * min(hPos * 2.4, 0.85);
vec2 q = p + s0 * refractScale;
// Convergence (negative divergence of refracted positions) focuses solar rays into bright caustic filaments
float e = 0.007;
vec2 sx = waveNormalSlope(p + vec2(e, 0.0), depth, t, true) - waveNormalSlope(p - vec2(e, 0.0), depth, t, true);
vec2 sy = waveNormalSlope(p + vec2(0.0, e), depth, t, true) - waveNormalSlope(p - vec2(0.0, e), depth, t, true);
float div = (sx.x + sy.y) / (2.0 * e);
float focus = clamp(-div * 0.0014 * min(hPos * 3.5, 1.0), 0.0, 2.2);
// Secondary crisp micro-ripple caustic network
float c2 = pow(0.5 + 0.5 * sin(q.x * 58.0 + sin(q.y * 42.0 + t * 2.2)) * cos(q.y * 52.0 - t * 1.9), 5.0);
return (pow(focus, 1.55) * 1.9 + c2 * 0.65) * smoothstep(0.01, 0.08, hPos) * exp(-hPos * 2.2);
}
vec3 acesTone(vec3 x) {
return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
bool useCross = uv.x > 0.0;
vec2 p = vec2(useCross ? (uv.x - 0.25) : (uv.x + 0.25), uv.y);
p.x *= 1.85;
float depth = evalDepth(p);
vec3 sunDir = normalize(vec3(0.42, 0.55, 0.72));
vec3 col = vec3(0.0);
if (depth < 0.0) {
// Warm coastal sand & rocky headland above waterline
vec2 g = depthGrad(p);
vec3 nLand = normalize(vec3(-g.x * 0.55, -g.y * 0.55, 1.0));
float ndl = 0.35 + 0.65 * max(dot(nLand, sunDir), 0.0);
float sandGrain = 0.94 + 0.06 * sin(p.x * 160.0) * cos(p.y * 160.0);
vec3 drySand = vec3(0.76, 0.68, 0.52) * sandGrain;
vec3 rock = vec3(0.32, 0.31, 0.30);
float headland = smoothstep(-0.08, -0.22, depth) * smoothstep(0.05, -0.22, p.x);
vec3 landBase = mix(drySand, rock, headland);
// Wet swash darkening right at the beach edge
float wet = smoothstep(-0.09, -0.005, depth);
landBase *= mix(1.0, 0.58, wet);
col = landBase * ndl;
} else {
float wH = evalWaveHeight(p, depth, iTime, useCross);
vec2 slope = waveNormalSlope(p, depth, iTime, useCross) * 0.032;
vec3 N = normalize(vec3(-slope.x, -slope.y, 1.0));
vec3 V = normalize(vec3(0.0, -0.35, 1.0));
float ndv = clamp(dot(N, V), 0.05, 1.0);
float fres = 0.03 + 0.97 * pow(1.0 - ndv, 4.5);
// Seabed albedo + Beer-Lambert spectral absorption (red attenuates fast, turquoise persists)
vec3 seabed = vec3(0.74, 0.66, 0.50) * (0.85 + 0.15 * sin(p.x * 48.0 + p.y * 22.0));
if (useCross) {
// RGB dispersive shore caustics projected onto the shallow seabed
float cR = causticChannel(p + vec2(P_DISPERSION, 0.0), depth, iTime, -0.18);
float cG = causticChannel(p, depth, iTime, 0.0);
float cB = causticChannel(p - vec2(P_DISPERSION, 0.0), depth, iTime, 0.18);
vec3 caustics = vec3(cR, cG, cB) * vec3(1.15, 1.08, 0.92) * P_CAUSTIC_GAIN;
seabed += caustics * 0.95;
}
vec3 absorb = exp(-depth * vec3(4.2, 1.45, 0.82));
vec3 deepCol = vec3(0.015, 0.085, 0.165);
vec3 waterBody = mix(deepCol, seabed, absorb);
// Sky reflection + crisp solar glitter on wave crests
vec3 R = reflect(-V, N);
vec3 skyRefl = mix(vec3(0.28, 0.52, 0.78), vec3(0.75, 0.88, 0.98), clamp(R.z, 0.0, 1.0));
float spec = pow(max(dot(N, normalize(sunDir + V)), 0.0), 96.0) * 2.4;
col = mix(waterBody, skyRefl, fres * 0.65) + vec3(1.0, 0.95, 0.84) * spec;
// Breaking surf & shoaling whitewater foam along shallow refracted wave crests
float shoreLine = exp(-depth * 22.0);
float crestBreak = useCross ? smoothstep(0.62, 1.12, wH) * smoothstep(0.32, 0.03, depth) : 0.0;
float foamNoise = 0.65 + 0.35 * sin(p.x * 75.0 + wH * 4.0) * cos(p.y * 75.0 - iTime * 2.0);
float foam = clamp((shoreLine * 0.85 + crestBreak * 0.95) * foamNoise * P_SHOAL_FOAM, 0.0, 1.0);
col = mix(col, vec3(0.92, 0.96, 0.98), foam * 0.88);
}
col = acesTone(col);
if (abs(uv.x) < 0.003) col = vec3(0.95, 0.93, 0.89);
fragColor = vec4(pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Why they connect
Fast-Sweeping Eikonal Coastal Wave Refraction & Ray-Tube Shoaling reads the coastal bathymetry heightfield and solves the dispersion-coupled eikonal equation to produce local wave phase, refracted wavevector direction, and shoaling amplitude amplification. The hop to FFT Ocean (Tessendorf) is composite: deep-water spectral cascades supply broad-spectrum capillary and wind chop, while the eikonal coastal field bends low-frequency swell crests toward the shoreline and scales their steepness as depth drops. The combined water surface normals and heightfield flow into Real-time Water Caustics, which refracts sunlight through the shoaling surface onto the shallow seabed to output a caustic irradiance texture aligned with the visible waves.
How to build it
Precompute or incrementally update a 2D coastal eikonal phase and shoaling-factor texture from the terrain depth map using fast sweeping or an iterative GPU jump/relaxation solver under the shallow-water dispersion relation. Every frame, synthesize two or three tiling JONSWAP/TMA cascades with inverse FFT compute passes for wind detail, then blend the deep-water displacement with the eikonal-refracted nearshore swell weighted by water depth. In a caustic pass, project a displaced water-surface grid or screen-space Jacobian of refracted sun rays onto the seabed depth buffer, accumulating intensity where wave crests focus light and adding subtle RGB dispersion offset by depth. Composite the caustic texture into the underwater seabed lighting before applying depth-based absorption and Fresnel reflection.
Field marks
- Blending periodic FFT swell with non-periodic eikonal shore waves can cause phase cancellation or double-crest seams in the transition zone.
- Sharp bathymetry ledges create eikonal phase caustics (crossing rays) that need smoothing or multi-direction decomposition to avoid kinks.
- Shallow breaking crests fold back on themselves, producing inverted normals that blow up Jacobian-based caustic intensity without clamping.
- Re-solving the eikonal field dynamically when terrain deforms requires amortizing iterations across frames.
Prior art
- Humpalumps/Ultra-Water. Open-source real-time coastal water system coupling eikonal wave refraction and shoaling with FFT ocean cascades and real-time seabed caustics; listed here as an untested Arena cross awaiting a standalone WebGL2 proof.