{
 "id": "gerstner-waves",
 "title": "Gerstner (Trochoidal) Waves",
 "aliases": [
  "trochoidal waves",
  "sum of Gerstner waves"
 ],
 "domain": "volumes",
 "subdomain": "ocean",
 "stage": "volume",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot"
 ],
 "year_introduced": 2004,
 "inputs": [
  "material-params"
 ],
 "outputs": [
  "heightfield",
  "normals",
  "mesh"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "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.",
 "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_use": "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.\n\nPrefer `fft-ocean` when you need a realistic spectrum with hundreds of waves and tiling statistics. Prefer `shallow-water-equations` for ripples and wakes that react to objects. Use `jonswap-spectrum` to choose wave amplitudes and wavelengths statistically.",
 "cost": {
  "class": "cheap",
  "notes": "A few sine and cosine evaluations per wave per vertex or pixel."
 },
 "failure_modes": [
  "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://developer.nvidia.com/gpugems/gpugems/part-i-natural-effects/chapter-1-effective-water-simulation-physical-models",
   "type": "web",
   "title": "Effective Water Simulation from Physical Models",
   "authors": [
    "Mark Finch",
    "Cyan Worlds"
   ],
   "year": null,
   "venue": "GPU Gems, 2004",
   "url": "https://developer.nvidia.com/gpugems/gpugems/part-i-natural-effects/chapter-1-effective-water-simulation-physical-models",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261117181852/https://developer.nvidia.com/gpugems/gpugems/part-i-natural-effects/chapter-1-effective-water-simulation-physical-models",
     "timestamp": "20261117181852"
    },
    "page_title": "Chapter 1. Effective Water Simulation from Physical Models",
    "host": "developer.nvidia.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://developer.nvidia.com/gpugems/gpugems/part-i-natural-effects/chapter-1-effective-water-simulation-physical-models → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://developer.nvidia.com/gpugems/gpugems/part-i-natural-effects/chapter-1-effective-water-simulation-physical-models → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 0.95,
   "__bib": "fincheffective"
  }
 ],
 "presets": [
  {
   "id": "gerstner-waves-4-wave-ocean",
   "title": "Four Gerstner waves, ray-marched ocean",
   "runtime": "glsl-fragment",
   "params": {
    "waves": 4,
    "steepness": 0.7,
    "gravity": 9.81
   },
   "code": "// GLSL ES 3.0, Shadertoy-style. Sum of four Gerstner waves, heightfield ray-march, Fresnel sky reflection.\nconst float GRAV = 9.81;\nconst float STEEP = 0.7;\nconst vec3 SUN_DIR = vec3(-0.45, 0.28, -0.85);\n// each wave: direction.xy, amplitude, wavelength\nconst vec4 WAVES[4] = vec4[4](\n  vec4(0.96, 0.28, 0.55, 16.0),\n  vec4(0.60, -0.80, 0.30, 9.0),\n  vec4(-0.30, 0.95, 0.16, 5.0),\n  vec4(0.85, 0.52, 0.07, 2.6));\n\nvec3 sky(vec3 rd) {\n  float t = clamp(rd.y, 0.0, 1.0);\n  vec3 c = mix(vec3(0.75, 0.82, 0.90), vec3(0.18, 0.37, 0.70), pow(t, 0.5));\n  float s = max(dot(rd, normalize(SUN_DIR)), 0.0);\n  return c + vec3(1.0, 0.8, 0.5) * (pow(s, 600.0) * 6.0 + pow(s, 8.0) * 0.25);\n}\n\n// Gerstner displacement at rest position q. xy = horizontal offset, z = height.\nvec3 gerstner(vec2 q) {\n  vec3 r = vec3(0.0);\n  for (int i = 0; i < 4; i++) {\n    vec2 d = normalize(WAVES[i].xy);\n    float A = WAVES[i].z;\n    float k = 6.2831853 / WAVES[i].w;\n    float th = k * dot(d, q) - sqrt(GRAV * k) * iTime;\n    float Q = STEEP / (k * A * 4.0);\n    r.xy += d * (Q * A * cos(th));\n    r.z += A * sin(th);\n  }\n  return r;\n}\n\n// Height at world xz: undo the horizontal displacement with fixed-point iteration.\nfloat height(vec2 xz) {\n  vec2 q = xz;\n  for (int i = 0; i < 3; i++) q = xz - gerstner(q).xy;\n  return gerstner(q).z;\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  vec3 ro = vec3(0.0, 3.2, 0.0);\n  vec3 rd = normalize(vec3(uv.x, uv.y - 0.22, -1.0));\n  vec3 col;\n  float t = 0.0;\n  bool hit = false;\n  for (int i = 0; i < 90; i++) {\n    vec3 p = ro + rd * t;\n    float d = p.y - height(p.xz);\n    if (d < 0.02 * (1.0 + t * 0.02)) { hit = true; break; }\n    t += max(d * 0.6, 0.02);\n    if (t > 250.0) break;\n  }\n  if (hit) {\n    vec3 p = ro + rd * t;\n    float e = 0.05 + t * 0.002;\n    float h0 = height(p.xz);\n    vec3 n = normalize(vec3(h0 - height(p.xz + vec2(e, 0.0)), e, h0 - height(p.xz + vec2(0.0, e))));\n    float cosT = clamp(dot(n, -rd), 0.0, 1.0);\n    float F = 0.02 + 0.98 * pow(1.0 - cosT, 5.0);\n    vec3 refl = sky(reflect(rd, n));\n    vec3 deep = vec3(0.01, 0.12, 0.17);\n    vec3 shallow = vec3(0.06, 0.35, 0.38);\n    vec3 body = mix(deep, shallow, clamp(0.5 + p.y * 0.8, 0.0, 1.0));\n    col = mix(body, refl, F);\n    col = mix(col, sky(vec3(rd.x, 0.02, rd.z)), 1.0 - exp(-t * 0.006));\n  } else {\n    col = sky(rd);\n  }\n  col = col / (1.0 + col);\n  col = pow(col, vec3(1.0 / 2.2));\n  fragColor = vec4(col, 1.0);\n}\n",
   "basis": "original",
   "license_note": "written for this index; wave parameters are original sensible defaults",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "gerstner-waves",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-29T15:51:50.471Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.5591,
      "std": 0.1007,
      "unique_colors": 119
     },
     "image": "/specimens/gerstner-waves-4-wave-ocean.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "fft-ocean",
  "jonswap-spectrum",
  "shallow-water-equations"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "fft-ocean",
   "why": "Gerstner swells provide large-scale controllable motion while the FFT adds fine, statistically correct detail."
  },
  {
   "id": "water-caustics-realtime",
   "why": "Surface normals from the analytic derivative drive the refracted light that makes caustics."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/volumes/gerstner-waves.json"
 },
 "solves": [
  "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"
 ],
 "authority": "Finch & Worlds",
 "url": "https://texelatlas.vercel.app/t/gerstner-waves/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 98.07,
  "tier": "extreme",
  "p50_ms": 3.2266,
  "p95_ms": 3.289,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "gerstner-waves-4-wave-ocean",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 77.86,
   "tier": "extreme",
   "p50_ms": 1.238,
   "p95_ms": 1.2529,
   "speedup_x": 2.61,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 65.59,
   "tier": "extreme",
   "p50_ms": 1.889,
   "p95_ms": 1.9327,
   "speedup_x": 1.71,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}