Skip to content

cvc::ocean: the swash, runup up the beach, a film and wet sand (O4b) - #1131

Merged
transfix merged 11 commits into
masterfrom
feat/ocean-swash
Nov 10, 2026
Merged

transfix merged 11 commits into
masterfrom
feat/ocean-swash

Conversation

@transfix

Copy link
Copy Markdown
Owner

O4b of docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md: the swash. Each wave runs up the beach and drains back, drawn as a thin film over the sand, and the sand it has just left is darker and glossy until it dries. This finishes A3 (decision D4).

This branch includes #1128 (O4a) underneath its own commit, c79e3a7, because O4b extends the shore layer and lsystem_coast's shaders. Once #1128 merges, I'll merge master in and the diff drops to this commit.

cvc::ocean::shore_layer

  • The runup field. It holds Hunt's R = min(ξ, 2.5)·H₀, as shadowed as the swell, at each reached cell. It is carried, with the phase, swash_reach_m (30 m) up the dry beach, ring by ring from the waterline. A steep shore surges no higher than 2.5·H₀.
  • swash(x, y, t, ground_z, level). Each wave's front runs up to R(1 + cos θ)/2 on the first train's phase and drains back. The ground is under the film while the front stands above it. It returns:
    • the film (thicker behind the front);
    • the foam lace at the front's edge;
    • the wetness exp(−age/T_dry), the age being the time since the front last left the ground.
  • New params: swash_reach_m, runup_xi_max, dry_time_s.
  • Texture layout: dir_texels()'s third channel is now the runup. The shader never read the wavenumber.

No wetness texture, a deviation from the roadmap. The roadmap asks for a texture that records when each texel was last wet. For the swash that time follows from the wave's phase, so it is computed directly:

  • no texture state and no per-frame ping-pong pass, which suits WebGL2;
  • the CPU (and later physics: a crate on wet sand) knows exactly where it is wet.

Rain's wetness (F3) will need a real texture, and the swash can feed it then. The roadmap's A3 notes this.

lsystem_coast

  • Drawing. The swash is drawn in the terrain's fragment shader, not as geometry (D4), after VTK's texture (albedo × cloud shade):
    • wet sand darkens and gains a glossy sky sheen toward grazing angles;
    • the film tints it with water;
    • foam marks the front, scaled by coast.water.shore_foam.
  • Inputs. It reads the shore layer's two textures, and the arithmetic is shore_layer::swash's.
  • New knob: coast.water.dry_time (6 s). Changing it rebuilds the shore layer.
  • The shore check now reports the swash, evaluated on the CPU as the shader draws it.

Checked

  • ocean_shore_test, 15 tests. The 3 new ones:
    • the runup is Hunt's at a 1:10 beach's waterline, carried 30 m up the beach and no further, and capped at 2.5·H₀ on a steep shore;
    • an island's lee gets no runup and its windward shore does;
    • on the beach, the share of each wave the ground spends under the film is α/π (α = acos(2z/R − 1)) to within 1 %, the wetness is exp(−age/T_dry) and decays between waves, ground above the runup stays dry, ground under the still water is wet, and low ground is wet most of the time.
  • ocean_spectrum_test: 13 tests still pass.
  • lsystem_coast --shore-check:
    • At default weather: still no vertex onto dry ground. Runup reaches 3.0 m on the windward beaches, with about 1000 beach cells in its reach and 500–580 under the film at a given moment.
    • With --set coast.water.wind_speed=2 --set coast.water.swell_hs=2.5: runup reaches 6.25 m and about 1000 cells are under the film.
  • Frames (fly captures): a dark, glossy wet band with a film and foam runs up the beaches facing the swell, and the lee beaches stay dry. No shader errors.

Built and run locally (Windows Release, GL build). git clang-format 18.1.8 is clean on the changed lines. Not yet measured in the browser.

Next

That completes A3 (O4). Next in the roadmap's order: O5 (shading: GGX, light through backlit crests, footprint roughness, persistent foam), O6 (the fluid_surface hook in cvc::physics, which also needs h0 to be cross-platform deterministic), or O10 / O17 / O21, the independent quick ones.

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.
O4b of docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md (A3's runup and swash, D4). The shore layer gains a
runup field, Hunt's R = min(xi, 2.5) H0 as shadowed as the swell, carried with the phase
swash_reach_m (30 m) up the dry beach. shore_layer::swash(x, y, t, ground_z) runs each wave's front
up to R (1 + cos theta) / 2 on the first train's phase and back: the film under it, the foam lace at
its edge, and the wetness exp(-age / dry_time), the age since the front last left the ground. That
age follows from the phase, so the swash needs no wetness texture or ping-pong pass and the CPU
knows where it is wet; rain's texture (F3) can take it as a writer.

lsystem_coast draws it in the terrain's fragment shader after VTK's texture: wet sand darkens and
shines toward grazing angles, the film tints it, foam marks the front; coast.water.dry_time sets the
drying. The direction texture's third channel is now the runup (the shader never read k). The
shore check reports the swash: at the default 1.2 m swell, runup to 3 m on the windward beaches,
about 1000 beach cells within its reach, the lee dry.
…/ocean-swash

# Conflicts:
#	docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md
#	examples/cvcgl/lsystem_coast.cpp
#	inc/cvc/ocean/shore.h
#	src/cvc/ocean/shore.cpp
#	src/cvc/tests/ocean_shore_test.cpp
…arsed bodies

The writable-data scan failed on package-linux / libcvc-release-grpc:
- #1109 moved nav's per-thread EDT scratch into cvc::algo (edt_scratch) and
  left grid_nav its own sdf_scratch; both are thread_local scratch buffers,
  the same objects as the two stale grid_nav edt_scratch lines they replace.
- script_engine.cpp's SlicedCall constructor and locked_call each hold a
  static const parsed program (`body`), built once and never written.

The new list is the one the scan emitted for this build.
package-macos / libcvc-debug failed ScriptEngineTest.AKeyHookTakesEveryKeyInOrder
(finished 4, not 3) and AFailedEventLetsTheNextOneGo (3 outcomes, not 2),
the same on every retry. ScriptLane::take_queue moved on_done out of its
copy of the hook's options into the QueueDelivery, then passed the options
on to start(). libc++ moves a std::function whose callable sits in its
small buffer by copying it, so the moved-from on_done still held the
test's lambda. The activation then called it once more when its process
ended, on top of the one call per event. libstdc++ and MSVC leave a
moved-from std::function empty, so Linux and Windows passed.

std::exchange leaves the options without it on every standard library.
…/ocean-swash

# Conflicts:
#	src/cvc/ariadne/script_engine.cpp
#	tools/singleton_scan/allowlist.txt
@transfix
transfix enabled auto-merge (squash) November 10, 2026 20:09
@transfix
transfix merged commit 1aa2490 into master Nov 10, 2026
14 of 32 checks passed
@transfix
transfix deleted the feat/ocean-swash branch November 10, 2026 20:36
transfix added a commit that referenced this pull request Nov 10, 2026
)

One conflict, in src/cvc/tests/CMakeLists.txt, where both sides added a
test after physics_replay_test: master's permissive_libs_test and this
branch's threaded runs of the two Ariadne suites. Both are kept; ctest
registers permissive_libs_test, ariadne_runtime_test_threads_auto and
ariadne_host_test_threads_auto.

Neither PR adds a static or thread_local to a scanned target's sources, so
the writable-data allowlist is unchanged. Rebuilt cvc; ocean_shore_test 15
passes, permissive_libs_test runs (its libraries are absent from this
build, so it skips), and ariadne_runtime_test (291) and ariadne_host_test
(48) pass with CVC_EXEC_THREADS=auto.
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