Skip to content

cvc::ocean: the sea's spectrum and the cascades' h0 on the CPU (O2) - #1116

Merged
transfix merged 2 commits into
masterfrom
feat/ocean-model
Nov 10, 2026
Merged

transfix merged 2 commits into
masterfrom
feat/ocean-model

Conversation

@transfix

Copy link
Copy Markdown
Owner

O2 of docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md (B1, E1, §10.1). The sea's spectrum now lives on the CPU, in a module every consumer can link. The GPU ocean uploads the h0 it builds, so the picture and the physics band (O6) will evolve the same numbers (R3). This PR doesn't depend on #1109.

What it adds

cvc::ocean, a new module of the core library (decision D1). It depends on the standard library only, and a configure-time check fails the build if it includes another libcvc library.

  • cvc/ocean/spectrum.h ports ABYSSAL's spectrum (src/ocean/OceanFFT.js at 849ff7f4, MIT, credited in the headers and THIRD_PARTY_NOTICES.md):
    • JONSWAP with the TMA shallow-water correction, carried to wavenumber through the finite-depth dispersion relation;
    • Donelan–Banner spreading blended with cos², with the cos² term rotated with the wind (D10: ABYSSAL leaves it unrotated);
    • the wind sea's fetch law, with the fetch clamped at a fully developed sea;
    • the swell (E1): DNV-RP-C205's α from Hs and Tp, narrowed in direction and cut off below its long waves;
    • significant_wave_height, and the wind sea's and swell's heights separately.
  • cvc/ocean/h0.h builds each cascade's h0, paying two debts the roadmap lists in §1.1:
    • make_cascades gives each cascade a band edge at 8π/L of the next tile, as ABYSSAL does. The bands partition the wavenumbers, so the sum holds the spectrum once; before, every cascade carried a whole spectrum, so the peak was counted up to three times.
    • Each cascade gets its own seed. Before, all three drew the same noise.
    • build_h0 writes h0(k) and conj h0(−k) in the texel layout OceanFFT's time evolution already reads. It is bit-identical across runs.

OceanFFT drops its spectrum shader pass and its noise texture. setH0() holds the CPU h0 and uploads it (at init() if it hasn't run yet). With no h0 the sea is flat.

lsystem_coast builds its three cascades (tiles 251, 83 and 29 m) from one sea_state:

  • Amplitudes: all three are 1. The old weights (0.55, 0.32) tamed cascades that each held the whole spectrum; band-limited, the small cascades hold only short waves.
  • Swell: coast.water.swell_hs, swell_period and swell_dir_x / _z are new knobs, with height and period sliders in the Ocean panel. The swell is off by default.

Looks

I compared 40-frame --capture orbit renders before and after (fixed capture clock).

  • Similar: the chop's texture.
  • Calmer: the long waves and the foam streaks. They were the peak energy the old cascades counted two and three times, which is the roadmap's expected "minus the overlapping-band energy".
  • Tried and dropped: keeping the old 0.55 / 0.32 weights on the band-limited cascades. That left the sea glassy.

Not yet

  • Cross-platform h0. h0 is bit-identical across runs but not yet across platforms: std::log, exp, sin and cos come from each platform's libm. O6 puts the surface into the physics state_hash, so it needs correctly rounded versions first. cvc::physics's private det_math has no exp or log; moving it to cvc::algo (added in cvc::world: water_bodies, the sea, lakes and ponds and the shore grid (O1) #1109) and adding them is the likely route. The roadmap's B1 now says so.
  • Swell in a capture. The swell isn't shown in one, because lsystem_coast has no --set. Its spectrum is covered by the unit tests.
  • Crossfade. A spectrum change still rebuilds h0 at once, now on the CPU (the band texels of three 256² tiles, tens of ms). The crossfade is E4 (O13).

Tests

ocean_spectrum_test has 13 tests:

  • dispersion and its derivative (deep, intermediate, shallow);
  • the fetch law and its fully developed clamp;
  • the JONSWAP peak;
  • TMA damping in shallow water;
  • the swell's α, peak and Hs, and its energy at its own wavenumber and direction;
  • the spread's normalisation, and the swell narrowing it;
  • the wind sea downwind, turning with the wind;
  • the plane variance against Hs;
  • cascades partitioning the wavenumbers, with distinct seeds;
  • h0 zero outside its band, with the conjugate layout;
  • h0 bit-identical across builds, a different sea per seed;
  • h0's energy against twice the spectrum's variance per band, averaged over 8 seeds;
  • bad tiles rejected.

cvcgl_ocean_fft now feeds the GPU ocean through setH0. It checks that the wrong resolution is refused, that a re-upload after init() makes the wind knob live, and that an ocean with no h0 is flat, alongside the existing FFT invariants.

Run locally (Windows Release, GL build) and passing: ocean_spectrum_test (13), cvcgl_ocean_fft (all checks). git clang-format 18.1.8 is clean on the changed lines.

O2 of docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md (B1, E1, decision D1 as a new standard-library
module, with a configure-time check that it includes no other libcvc library).

cvc/ocean/spectrum.h ports ABYSSAL's spectrum: JONSWAP with the TMA correction, Donelan-Banner
spreading blended with cos^2 (rotated with the wind, D10), the fetch law clamped at a fully
developed sea, and the swell term (DNV-RP-C205 from Hs and Tp, narrowed and cut off).
cvc/ocean/h0.h builds a cascade's h0 from it: make_cascades gives bands at 8 pi / L that partition
the wavenumbers and a seed per cascade, paying the two port debts (shared noise, overlapping
bands); build_h0 writes the texel layout OceanFFT's time evolution reads, bit-identical across runs.

OceanFFT drops its spectrum shader pass and noise texture for setH0. lsystem_coast builds its
three cascades from one sea state, all at amplitude 1 (the old 0.55 / 0.32 weights tamed cascades
that each held the whole spectrum), with swell height and period sliders, the swell off by default.
@transfix
transfix enabled auto-merge (squash) November 10, 2026 02:42
@transfix
transfix merged commit a3e7f24 into master Nov 10, 2026
19 of 30 checks passed
@transfix
transfix deleted the feat/ocean-model branch November 10, 2026 04:20
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