Gerstner (Trochoidal) Waves
An analytic water surface made of a few sine-like waves in which each point also moves in a circle, yielding sharp crests and flat troughs with a closed-form displacement and normal.
Also known as trochoidal waves, sum of Gerstner waves
In the family Atmosphere, water & volumes, ocean
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 | Official add-on | Package Manager > Shader Graph > Samples > Production Ready Shaders > Water (Gerstner) docs Shader Graph sample content (Gerstner subgraphs); not the HDRP Water System. |
| Unreal 5.7 | Official add-on | Enable the Water plugin; Water Body Ocean/Lake/River with a Water Waves asset (default uses Gerstner waves) docs |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Each wave i has a direction D, wavenumber k, amplitude A and a speed from the deep-water dispersion relation, omega = sqrt(g k). For a point at rest position x0 and time t, the phase is theta = k D.x0 - omega t. The surface point is x0 minus D times Q A cos(theta) horizontally and A sin(theta) vertically, where Q is a steepness factor; the sum over waves gives the final surface. The horizontal term pulls vertices toward the crests, and keeping the sum of Q k A below one prevents loops. Normals come analytically from the partial derivatives, so shading needs no finite differences. The displacement is applied in a vertex shader on a dense grid, or the field can be ray-marched in a fragment shader by inverting the horizontal term with a few fixed-point iterations.
When to choose it
Reach for it when
- need cheap stylised water with sharp crests
- boats need a height query on the cpu for buoyancy
- mobile water that still looks like moving waves
- sine waves look too round and smooth
- a few controllable swell directions on a lake
Choose it for stylised or mobile water, for a handful of directional swells on a lake or harbour, and wherever the height at a point must be cheaply and exactly queryable on the CPU for buoyancy.
Prefer FFT Ocean (Tessendorf) when you need a realistic spectrum with hundreds of waves and tiling statistics. Prefer Shallow Water Equations (Height-field Water) for ripples and wakes that react to objects. Use JONSWAP Wave Spectrum to choose wave amplitudes and wavelengths statistically.
Field marks
- Self-intersecting loops at crests when the steepness sum exceeds one
- Visible regular repetition: with few waves the pattern looks periodic and synthetic
- Height at a world position requires inverting the horizontal displacement, otherwise buoyancy queries drift
- No foam, breaking or shoreline interaction on its own
- Aliasing and shimmering for short wavelengths when mesh density is low
- Mesh vertex density must be high or the displaced geometry shows faceting at the crests
Presets
Four Gerstner waves, ray-marched ocean
{
"waves": 4,
"steepness": 0.7,
"gravity": 9.81
}Show GLSL (75 lines)
// GLSL ES 3.0, Shadertoy-style. Sum of four Gerstner waves, heightfield ray-march, Fresnel sky reflection.
const float GRAV = 9.81;
const float STEEP = 0.7;
const vec3 SUN_DIR = vec3(-0.45, 0.28, -0.85);
// each wave: direction.xy, amplitude, wavelength
const vec4 WAVES[4] = vec4[4](
vec4(0.96, 0.28, 0.55, 16.0),
vec4(0.60, -0.80, 0.30, 9.0),
vec4(-0.30, 0.95, 0.16, 5.0),
vec4(0.85, 0.52, 0.07, 2.6));
vec3 sky(vec3 rd) {
float t = clamp(rd.y, 0.0, 1.0);
vec3 c = mix(vec3(0.75, 0.82, 0.90), vec3(0.18, 0.37, 0.70), pow(t, 0.5));
float s = max(dot(rd, normalize(SUN_DIR)), 0.0);
return c + vec3(1.0, 0.8, 0.5) * (pow(s, 600.0) * 6.0 + pow(s, 8.0) * 0.25);
}
// Gerstner displacement at rest position q. xy = horizontal offset, z = height.
vec3 gerstner(vec2 q) {
vec3 r = vec3(0.0);
for (int i = 0; i < 4; i++) {
vec2 d = normalize(WAVES[i].xy);
float A = WAVES[i].z;
float k = 6.2831853 / WAVES[i].w;
float th = k * dot(d, q) - sqrt(GRAV * k) * iTime;
float Q = STEEP / (k * A * 4.0);
r.xy += d * (Q * A * cos(th));
r.z += A * sin(th);
}
return r;
}
// Height at world xz: undo the horizontal displacement with fixed-point iteration.
float height(vec2 xz) {
vec2 q = xz;
for (int i = 0; i < 3; i++) q = xz - gerstner(q).xy;
return gerstner(q).z;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
vec3 ro = vec3(0.0, 3.2, 0.0);
vec3 rd = normalize(vec3(uv.x, uv.y - 0.22, -1.0));
vec3 col;
float t = 0.0;
bool hit = false;
for (int i = 0; i < 90; i++) {
vec3 p = ro + rd * t;
float d = p.y - height(p.xz);
if (d < 0.02 * (1.0 + t * 0.02)) { hit = true; break; }
t += max(d * 0.6, 0.02);
if (t > 250.0) break;
}
if (hit) {
vec3 p = ro + rd * t;
float e = 0.05 + t * 0.002;
float h0 = height(p.xz);
vec3 n = normalize(vec3(h0 - height(p.xz + vec2(e, 0.0)), e, h0 - height(p.xz + vec2(0.0, e))));
float cosT = clamp(dot(n, -rd), 0.0, 1.0);
float F = 0.02 + 0.98 * pow(1.0 - cosT, 5.0);
vec3 refl = sky(reflect(rd, n));
vec3 deep = vec3(0.01, 0.12, 0.17);
vec3 shallow = vec3(0.06, 0.35, 0.38);
vec3 body = mix(deep, shallow, clamp(0.5 + p.y * 0.8, 0.0, 1.0));
col = mix(body, refl, F);
col = mix(col, sky(vec3(rd.x, 0.02, rd.z)), 1.0 - exp(-t * 0.006));
} else {
col = sky(rd);
}
col = col / (1.0 + col);
col = pow(col, vec3(1.0 / 2.2));
fragColor = vec4(col, 1.0);
}
Attribution: written for this index; wave parameters are original sensible defaults
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| gerstner-waves-4-wave-ocean | Tesla T4 1920x1080 | 98.1× baseline (extreme) · 3.23 ms / 3.29 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| gerstner-waves-4-wave-ocean | NVIDIA L4 1920x1080 | 77.9× baseline (extreme) · 1.24 ms / 1.25 ms · 2.6× faster on L4 | opengl-timer-query · Cross-architecture validation |
| gerstner-waves-4-wave-ocean | NVIDIA A100-SXM4-40GB 1920x1080 | 65.6× baseline (extreme) · 1.89 ms / 1.93 ms · 1.7× faster on A100 | opengl-timer-query · Cross-architecture validation |
Crosses
- FFT Ocean (Tessendorf): Gerstner swells provide large-scale controllable motion while the FFT adds fine, statistically correct detail.
- Real-time Water Caustics: Surface normals from the analytic derivative drive the refracted light that makes caustics.
Sources
- primaryMark Finch, Cyan Worlds. Effective Water Simulation from Physical Models. GPU Gems, 2004.Verified via live page · 2026-11-29