Skip to content

ocean: the physics band residual, M chosen; OceanFFT's scissor and Nyquist fixes (O7b) - #1149

Merged
transfix merged 1 commit into
masterfrom
feat/ocean-band-residual
Nov 11, 2026
Merged

transfix merged 1 commit into
masterfrom
feat/ocean-band-residual

Conversation

@transfix

Copy link
Copy Markdown
Owner

O7b in docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md (B2, B6): this measures how far the sea physics feels is from the sea lsystem_coast draws, and chooses the band size M against that residual. It also fixes two OceanFFT bugs the harness found, and halves the residual by fixing how the shader samples.

cvcgl_ocean_band, the residual harness

lsystem_coast's three cascades (the 251, 83 and 29 m tiles, the default 9 m/s wind sea) run on the GPU in OceanFFT at 256² and are read back. cvc::ocean::sea_surface (#1142) evaluates the same h0 on the CPU, and the harness compares the two three ways:

  1. On the GPU's own lattice. This is the waves each M drops. With every mode kept, the remainder is float arithmetic alone.
  2. Read between lattice points by the splines. This is what sea_surface::height gives physics.
  3. The drawn sum. The cascades are sampled where the shader samples them.

The harness prints the table the roadmap records. It fails if:

  • the CPU's twin disagrees with the GPU;
  • keeping more modes ever misses by more;
  • the default band misses by more than 1.1 times the floor that the shader's own sampling sets.

It skips without float render targets, as cvcgl_ocean_fft does.

Two OceanFFT bugs it found first

  • The scissor box. The renderer leaves the scissor test on, boxed to the window, and OceanFFT's passes never turned it off.
    • In a window smaller than the FFT (the harness's 64-pixel one, or a small browser canvas), every pass was clipped to the window's corner and the rest of each texture stayed stale.
    • The long cascades' modes sit near texel 128, so they came back flat.
    • OceanFFT now disables the scissor test for its passes (ScopedglEnableDisable in step() and selfTest()).
    • cvcgl_ocean_fft never saw this, because it runs N = 64 in a 64-pixel window.
  • The Nyquist row and column. These have no −k partner on the grid, so their fields are not real.
    • The packing (two real fields to one complex transform) leaked the slope field into the height there, scaled by k_x up to the Nyquist: a faint checkerboard in the 29 m cascade.
    • The time-evolution passes now drop those modes, as the CPU's band does. After that fix, the CPU's twin matches the GPU to 0.0005 % on every cascade.

The residual

On the GPU's lattice (height, RMS of GPU − CPU over the RMS height):

cascade height RMS M = 8 16 32 64 128 256
251 m 1.17 m 75 % 30 % 0.00 % 0.00 % 0.00 % 0.00 %
83 m 0.36 m 97 % 37 % 0.00 % 0.00 % 0.00 % 0.00 %
29 m 0.14 m 99 % 42 % 21 % 10 % 4.5 % 0.00 %

The drawn sum, over 211² points of the 251 m tile:

band splines, per cascade drawn drawn, as sampled before
32 on 64 0.37 / 0.42 / 20 % 4.41 % (55 mm) 8.72 % (109 mm)
32 on 128 0.00 / 0.00 / 20 % 4.39 % 8.71 %
64 on 64 0.37 / 0.42 / 11 % 3.99 % (50 mm) 8.54 %
64 on 128 0.00 / 0.00 / 9.9 % 3.93 % 8.52 %
every mode 0 3.78 % (47 mm) 8.50 % (106 mm)
  • The floor. Even the band with every mode misses by 3.78 %. That is the shader's own nearest-texel steps: the texels are 1 m on the 251 m tile, and WebGL2 filters no float texture.
  • lsystem_coast's sampling. The shader took the texel at or before each point, so its steps trailed the field by half a texel. That doubled the floor, to 106 mm.
    • oDisp now takes the texel nearest the point, half a texel over, and the shore check samples the same way.
    • The picture moves by a fraction of a metre. --shore-check still finds no vertex on dry ground, and the frames look as before.
  • M chosen: 64 modes on a 64 lattice. This is the new band_params default and the roadmap's first estimate.
    • It misses the drawn sea by 3.99 %, within 6 % of the floor.
    • 32 modes miss by 4.41 %, 17 % over the floor, for 0.19 ms less a step (0.64 against 0.83 ms for three cascades).
    • A 128 lattice gains 0.06 points for four times the cost.
    • What the band leaves out is the 29 m cascade's waves under 0.9 m.

No pin changes: the tests pin their bands explicitly.

Checked locally (Windows Release, GL build)

  • cvcgl_ocean_band passes (7 checks) and cvcgl_ocean_fft passes.
  • ocean_sea_test 16 and physics_field_test 21 pass.
  • lsystem_coast --shore-check finds 0 vertices on dry ground, and an offscreen frame renders as before.
  • git clang-format is clean.

Next

O7c: crates and barrels in lsystem_coast that ride the swell, are carried by the breakers and the swash, and settle on calm lake water.

…quist fixes (O7b)

cvcgl_ocean_band runs lsystem_coast's three cascades on the GPU (OceanFFT at 256^2, read back)
against cvc::ocean::sea_surface on the CPU at several band sizes and prints the residual table.

It found two OceanFFT bugs first:
- The renderer leaves the scissor test boxed to the window, so in a window smaller than the FFT
  every pass was clipped to the window's corner (the long cascades came back flat). OceanFFT now
  disables it for its passes and restores it afterwards.
- The Nyquist row and column have no -k partner, so the packing leaked the slope field into the
  height there (a faint checkerboard in the 29 m cascade). OceanFFT drops them, as the CPU does.

With every mode the CPU's twin is the GPU to 0.0005 %. The drawn sum's floor is the shader's own
nearest-texel sampling, which took the texel at or before each point and so trailed the field by
half a texel: 106 mm RMS. lsystem_coast's oDisp now takes the texel nearest the point (and the
shore check samples the same way), which halves that floor to 47 mm; the shore check still finds
no vertex on dry ground.

M chosen: 64 modes on a 64 lattice (band_params' new default) misses the drawn sea by 3.99 % RMS,
within 6 % of the 3.78 % floor; 32 modes miss by 4.41 %. The harness holds the default within
1.1 times the floor.
@transfix
transfix enabled auto-merge (squash) November 11, 2026 20:28
@transfix
transfix merged commit 24c8ab4 into master Nov 11, 2026
13 of 33 checks passed
@transfix
transfix deleted the feat/ocean-band-residual branch November 11, 2026 21:21
transfix added a commit that referenced this pull request Nov 12, 2026
Only job_intrinsics_test.cpp conflicted. Master's #1150 fixed the same
pre-#1137 calls this branch fixed in 600c144, but kept a ProviderGuard that
clears the app's providers on the way out; this takes master's version, so the
file matches master.

The rest merged cleanly: #1151's spawn points (world_spawns.cpp, the world
rules' spawns, the loader and scene-world tests), #1145's macOS libcurl with
WebSockets (CMake and a ci.yml configure assertion), #1148's wasmtime in the
arix and ariglx recipes, and #1149's ocean band. None of them registers an
action-intrinsic provider, and none adds writable process-wide state: their
only new statics are vehicle_view.cpp's constant colour tables.
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