70. Rivers, ponds and the sea
Status: unimplemented — design draft. Today water is a complete private system in
metaverse/: phases W1–W11 of docs/metaverse/water.md are done in `metaverse/water.coax` and its sibling modules, and Everglade and the water lab (/realms/waterlab) use them. No other realm can load water through the OpenAgents Metaverse Engine. This chapter plans water as a Metaverse Engine module with the same formulas and checks. The Metaverse Engine now has the bounded gameplay volume/surface queries described below; the full wave, force, rendering and realm-adoption chapter remains a design draft.
Water touches most of the engine at once: physics pushes bodies, the renderer draws a surface and what is under it, the camera can go below the line, and the character can wade, swim or row. This chapter makes water one module that any realm declares, instead of code that belongs to Everglade.
What this chapter teaches
- How to describe water bodies as data: kind, outline, level, density, waves and current.
- How to keep a wave surface deterministic by snapping every frequency to a whole multiple of 2π/T, so a phase is an integer counter.
- How buoyancy, drag and currents enter the momentum ledger as named terms.
- How to split the gameplay surface, which every client computes bit for bit, from the visual detail, which each client chooses.
Outline
- Water bodies. A
WaterBodyis a pond, river, waterfall, ocean, pool, puddle or marsh. It has an outline (a polygon, a riverCoursewith widths, or everywhere), a level (constant, or a profile along the course), a density (FRESH,SALT), up to eight Gerstner terms and an optional current. - A surface on the clock.
WaveSetfrequencies snap to whole multiples of 2π/T.water_body_sampleat tick N equals steppingwater_advancefrom tick 0 bit for bit, and the clock folds on the period. A period of 2^32 ticks or more is refused, so the phase products stay exact inu64. - Point queries.
WaterSetgrids a zone's bodies sowater_sampleandwater_bodies_overlappingtest only bodies whose bounds cover a cell. This plugs into chapter 7's query module as one more query kind. - Flow. A
FlowGridis still, uniform, orwater_flow_river: divergence-free potential flow round obstacles, solved from the stream function by successive over-relaxation. - Forces.
water_submergedcomputes exact spherical caps, sliced capsules and clipped cuboids.water_applyadds buoyancy at the centre of buoyancy, linear and quadratic drag relative to the water, and angular damping. Each force is aPushunderwater.buoyancyorwater.drag, recorded bywater_recordin the momentum ledger. - The spectral sea. JONSWAP from wind speed and fetch with the TMA depth factor, finite-depth dispersion, and directional spreading. Mode amplitudes come from the spectrum integrated over each cell, and a radix-2 inverse FFT makes height, choppy displacement, slopes and the Jacobian per tile (`metaverse/water-spectrum.coax`).
- The ocean at scale. A clipmap of nested grids whose levels snap to twice their spacing, with no cracks at level seams, a skirt to 40 km, and streamed 8 m cells in a pool of 48 slots (`metaverse/water-ocean.coax`). Streaming changes cost, never what is drawn.
- The look and under the water. Seven presets (Jerlov absorption, in-scatter, foam, roughness, shore band, crest scattering), phone and desktop tiers (6 against 16 detail waves), the waterline across the near plane, and Beer–Lambert fog per channel (`metaverse/water-look.coax`, `metaverse/water-under.coax`).
- People in the water. Wading, swimming, diving and rowing as media the character controller of chapter 9 switches between (
MEDIUM_BOATand the wade rules in `metaverse/water-wade.coax`); ripples, wakes and spray as effects from chapter 72.
What exists today
- `metaverse-engine/physics/query-fluid.coax`: checked box/capsule trigger containment and gameplay fluid boxes with no surface, a flat surface or an existing heightfield sampler. Explicit rectangular holes remove fluid occupancy. Samples carry body identity, surface/depth, flow, kind, density, buoyancy and drag. Resistance is independent of buoyancy:
flow + (velocity - flow) / (1 + drag * dt)slows a body without adding lift. Results publish whole or refuse. This is the bounded query profile from chapter 7, not completion of the waves, force ledger or rendering requirements in this chapter.
- docs/metaverse/water.md: phases W1–W11, each with its port notes and differences from the previous Rust engine.
- metaverse/water.coax and metaverse-engine/physics/sim/rigid.coax: the W1 physics, with all fifteen of the old tests as
#testchecks. - everglade/world/river.coax: Everglade's 4 m river, its current round the bridge piles, and its rowboats.
- metaverse-engine/world/water-weather.coax and everglade/legacy/v1/water-spells.coax: rising water in rain, and spells that act on water.
What it builds
metaverse-engine/water/body.coax: bodies, wave sets, sets and point queries.metaverse-engine/water/force.coax: submersion, buoyancy, drag and ledger terms over Part IV's rigid bodies.metaverse-engine/water/sea.coax: the spectrum, synthesis and the clipmap.metaverse-engine/render/water.coax: presets, tiers and the underwater pass, as Coax shaders emitted by chapter 11's renderer.
Acceptance checks and oracles
The chapter is done when:
- Every
#testin today'smetaverse/water*.coaxmodules passes against the Metaverse Engine modules with the same tolerances. - The gameplay surface is the same bit for bit on a phone client and a desktop client at every tick, and a late joiner folds to the same tick.
- A body at rest on still water sleeps; waves or a current wake it.
- The momentum ledger balances for a floating body over a recorded run.
- The water lab stays under its budgets: 1 ms GPU on the phone tier, 3 ms on the desktop, and 64 KiB of uniforms.
- Everglade holds 60 FPS in all eight
perf.tscases with water in view.
Dependencies
Chapters 7 (queries), 9 (the character), 11–13 (renderer, materials and light), 16 (budgets), 18 (rigid bodies) and 38 (streaming, for the ocean's cells). From Coax: R12 quantities for densities and levels, and R15 strict math for the bit-for-bit surface.