Skip to content

cvc::ocean: the shore layer, the swell refracting, shoaling, breaking and reflecting (O4a) - #1128

Merged
transfix merged 5 commits into
masterfrom
feat/ocean-shore-layer
Nov 10, 2026
Merged

transfix merged 5 commits into
masterfrom
feat/ocean-shore-layer

Conversation

@transfix

Copy link
Copy Markdown
Owner

O4a of docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md: the shore layer's waves (A3). The swell refracts, shoals, breaks on the shores that face it, and reflects off the steep ones. The runup film over the sand and the wetness texture are the next PR, O4b.

This branch includes #1125's and #1127's commits underneath its own (eca1513), because all three edit lsystem_coast and PRs aren't stacked in this repo. When those merge, the diff drops to this commit.

cvc/ocean/shore.h: cvc::ocean::shore_layer

It reads a shore_grid of plain planes: still-water depth, shore distance and offshore normal (what cvc::world::water_bodies holds). cvc::ocean still depends on no other library.

  • Phase. P solves the eikonal equation |∇P| = k(depth) by first-order fast marching.
    • It starts from the grid edge the swell enters by, as a plane wave, rather than from the waterline as the roadmap first said. On a shelf that reaches the horizon, starting at the waterline would ring the island with crests across the whole sea.
    • From the edge, crests stay straight offshore and turn toward the shore where it shoals, which is refraction coming from the physics, and they wrap round an island.
    • k is the exact dispersion relation: Newton's method from Eckart's approximation.
  • Amplitude. The deep-water amplitude (H_rms/2 of the swell's Hs) is:
    • shoaled by sqrt(c_g0/c_g), which is Green's law d^(−1/4) in shallow water;
    • shadowed near shores facing away from the swell, by max(0, −n·swell)^p, fading back to the open swell two local wavelengths out;
    • capped where a set's crest (√N trains summed) would pass γ_b·d (McCowan, 0.78). The excess becomes the breaking intensity.
  • Reflection. The Iribarren number uses the surf zone's mean slope (depth over shore distance). Battjes' K_r = min(1, 0.1ξ²) gives a reflected train that fades over two wavelengths offshore, so a cliff stands its swell (clapotis) and a beach doesn't.
  • Profile and evaluator.
    • Three regular trains, at T, T·1.06 and T·0.94, so waves come in sets.
    • A Gerstner profile whose steepness rises toward breaking, limited so the surface never loops.
    • evaluate(x, y, t) is the sum the GPU draws, from the same fields, so physics (B5) will read what is drawn.
    • wave_texels() / dir_texels() pack the fields for the GPU.
  • Helpers: shore_wavenumber, shoaling, iribarren, reflection_coefficient, and runup (Hunt, for O4b).

lsystem_coast

  • The swell is the shore layer's. The island's shelf is shallow everywhere, so the swell (coast.water.swell_*, now on by default at 1.2 m, 10 s) is drawn by the shore layer alone, and the FFT cascades draw only the wind sea. A coast with deep water offshore would hand the swell from a cascade of its own to the shore layer.
  • On the GPU.
    • The layer is uploaded as two RGBA32F textures on the shore grid and summed in the vertex shader with the cascades.
    • Breaking crests feed the foam.
    • The O3 sideways limit applies to the swell's Gerstner move too.
    • It is rebuilt (about 80 ms) when a swell knob changes.
  • wave_amp scales only the cascades. The shore layer stays at its true size, so its breaking cap holds at any setting. At wave_amp = 5 the cap was being defeated and the troughs exposed the shoals; that is fixed.
  • --set KEY=VALUE is a new option that seeds any knob, e.g. --set coast.water.wind_speed=1 --set coast.water.swell_hs=2.5.

Checked

  • ocean_shore_test, 12 tests:
    • the wavenumber solves the dispersion relation;
    • Green's law in shallow water;
    • cliffs reflect (K_r = 1) and 1:50 beaches don't (< 0.05);
    • over flat water the phase is a plane wave with the dispersion relation's wavelength;
    • on a shoaling shelf, k·sin θ is conserved to 2 % (Snell) and the crests turn toward the shore;
    • shoaling, then breaking at the cap, with H ≤ γ·d everywhere;
    • a cliff's standing wave: time-averaged variance over 1.3× the incident train's;
    • an island's lee is calm (< 10 % of its windward shore) while the phase wraps round it;
    • a lake the swell can't reach is still;
    • the evaluator equals the trains' sum by hand;
    • no swell gives no waves;
    • bad grids are rejected.
  • ocean_spectrum_test: 13 tests still pass.
  • lsystem_coast --shore-check:
    • At default weather: none of 44 722 offshore vertices lands on dry ground (the old shader: 60–76).
    • The shore layer reports a 0.42 m deep amplitude and 1861 breaking cells.
    • The island is steep (tan β ≈ 0.3 at the waterline, ξ ≈ 3.4 for this swell), so by Battjes it reflects along most of its shore.
  • Frames (orbit and fly captures):
    • At default weather the open sea keeps its chop and breakers line the shores facing the swell.
    • With --set coast.water.wind_speed=1 --set coast.water.swell_hs=2.5 the lee is calm and the windward shore breaks.
  • Frame cost (native): 600 offscreen frames take 15–22 s with the swell on or off, so the shore layer is within run-to-run noise. Not yet measured in the browser.

Built and run locally (Windows Release, GL build). git clang-format 18.1.8 is clean on the changed lines. The roadmap's A3 gets an "as built" note.

coast.water.weight_long, weight_mid and weight_short (the 251, 83 and 29 m cascades) set each
band's amplitude, baked into h0 so the physics band will see the same sea; a change rebuilds h0
like any spectrum knob. All default to 1, the one physical spectrum, so the default sea is
unchanged (an orbit capture's frame is byte-identical to before). The Ocean panel gains a slider
for each (0 to 2).
…red (O3)

O3 of docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md (A1, A2, W0.2's textures).

The seabed is a HeightFieldTexture of terrainH at 1 m over the ocean, and the shore grid is
cvc::world::water_bodies uploaded as an RGBA32F texture (distance to shore, offshore normal,
slope). The vertex shader fades each cascade as the still water shoals, over its band's half
wavelength capped by coast.water.shore_fade (3 m: the island's shelf is about 9 m deep to the
horizon, so the uncapped rule would calm the whole sea before the shore layer, O4, carries the
long waves in), and never moves a vertex sideways more than 0.8 of its distance to the shore.
The fragment shader's depth reads the seabed texture; coastH(), the GLSL copy of terrainH, is gone.

lsystem_coast --shore-check evaluates the vertex shader's displacement on the CPU over the
read-back cascades: at t = 1.3 s the old shader put 60 offshore vertices on dry ground, this one
none (76 and none at t = 5 s).
… and reflecting (O4a)

O4 of docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md, its waves (A3); the runup film and wetness are
O4b. cvc/ocean/shore.h builds, over a shore grid of plain planes (depth, shore distance and normal):
  * the phase, |grad P| = k(depth) by fast marching from the edge the swell enters, as a plane
    wave, so offshore crests stay straight and turn toward the shore as it shoals (Snell), wrapping
    round an island; k from the exact dispersion relation (Newton from Eckart);
  * the amplitude: shoaled by sqrt(c_g0 / c_g) (Green's law in shallow water), shadowed near shores
    facing away from the swell, capped where a set would break (gamma_b = 0.78), the excess the
    breaking intensity;
  * Battjes' reflection from the surf zone's mean slope, a reflected train fading offshore;
  * Gerstner steepness rising toward breaking; and evaluate(), the sum the GPU draws.

lsystem_coast draws it: the swell (coast.water.swell_*, now 1.2 m at 10 s by default) is the shore
layer's, uploaded as two RGBA32F textures and summed in the vertex shader with the wind-sea cascades,
breaking crests feeding foam; wave_amp scales the cascades only, so the breaking cap holds. A --set
KEY=VALUE option seeds any knob. The shore check counts the swell's sideways move too: none of the
44722 offshore vertices lands on dry ground.
@transfix
transfix enabled auto-merge (squash) November 10, 2026 07:50
@transfix
transfix merged commit 57897fe into master Nov 10, 2026
8 of 31 checks passed
@transfix
transfix deleted the feat/ocean-shore-layer branch November 10, 2026 09:19
transfix added a commit that referenced this pull request Nov 10, 2026
…ld panels (#1123), ocean shore (#1128)

Also #1124, #1115 and #1120.

Conflicts, both sides kept:
- ariadne.h: post_signal also hands the signal to the event tap, and
  stays a host-thread call outside a pump, as post_input is. The tap is
  set on the drain's thread, which is the host thread.
- ariadne.cpp: deliver_input and post_signal post to the document's
  scheduler (current_sched) when a resident takes the event, and queue it
  for the tap when the tap takes that kind. post_signal keeps its
  assert_outside_pump. The tap's events are handed over in drain_begin,
  after the input residents and before the has? snapshot, so what they
  start runs in the frame's pump.
- ariadne_script_engine_test.cpp: this branch's isolated-document tests
  and master's hook tests, all kept.

A lane's hook residents run on the host thread: a document that uses an
engine stays there (require_host_thread), so the hook queues and the
receiver's start_process need no more.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant