garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/notes/water-splashes.md

raw


topic: water-splashes triggers: [splashes.rs, systems::splashes, WaterFx, water_effects, "Splashes and spray", SWIM_STROKE_PHASE, swim_phase, assets/sounds/water, particles.wesl, ParticleMaterial::rings, splash.wesl, SplashMaterial, materials/src/splash.rs, "splash", "fountain jet", "fountain sound"] updated: 2026-11-16

Water reacts: splashes, strokes, ripples and fountain jets

Asked for by the owner on 2026-11-16 ("Water en fonteinen"): the avatar swam since 2026-11-14 (avatar-locomotion.md), but going in, swimming and the fountains made no splash and no sound.

What happens when

MomentDrawnHeard
A body goes into the watera crown of water rising and collapsing, a column up its middle after a real drop, foam left on the surface, three throws of streaked drops and two or three faint ripples, all sized by the entry speedsplash-big-* (size ≥ 0.45) or splash-small-*, louder with size
A swimmer's strokea small throw of drops and two faint ripples ahead of the feet, where the head and hands meet the waterstroke-*
Treading water (in it, not moving)gentle continuous rings at the body—
Swimming at all (own avatar)—tread.ogg loop, eased in; footsteps are off and the landing thud is not played
Another swimmer nearthe same, from this viewer's maptread.ogg by distance, strokes and splashes by distance
A fountain jet (amenity=fountain in open water)a plume of streaked drops from the column's top and faint ripples at its foot, for the six jets nearest the camera within 300 mfountain.ogg loop by distance to the nearest jet (full within 4 m, gone at 60 m)
A swimmer reaches a jet (within 1 m)a medium splash, once on the way ina small splash

Nothing went on the wire. Who is in the water is each viewer's own reading (AvatarState::swimming, RemoteAvatar::swimming), as the swimming itself is.

How big a splash is

entry_speed is the speed of a fall from where the feet were the frame before the water was reached, under motion::GRAVITY (22 m/s², the avatar's own fall offline), combined with the speed across the ground. The frame before matters: the lift into the water eases (WATER_SINK_RATE), and a capture flown frame by frame has already put the feet at the water by the time the flag flips. splash_size maps 1 m/s (a wade) to 0 and 8 m/s to 1; a walk off a 1.5 m quay is 8.2 m/s, i.e. the biggest; running down a bank into a pond is about a third. The drop is clamped to 6 m so a teleport into the water is not a meteor — it does still splash, which reads as arriving in the water.

Where is where the feet go through the surface (within 5 cm of it), not where the body crossed into the water body: off a quay that crossing is the wall's own line, and half of every splash was drawn inside the wall. The lift sinks the feet at 4 m/s, so a walk off a 1.4 m quay goes through about half a metre out, and the sound starts then too. A body whose feet never get there (a remote drawn without the lift) splashes after 45 frames anyway. A --shot capture does not carry the body forward while it sinks, so there the splash still stands on the bank's line.

A stroke is timed by the arms

cartopolis_human::build::SWIM_STROKE_PHASE (0.95) is where in the swim loop the hands shoot forward through the surface, measured on the shipped pack as the frame of the hands' fastest forward travel (the_stroke_splashes_where_the_hands_shoot_forward, 2026-11-16: phase 0.953; the hands are also at their highest there). AvatarAnimations::swim_phase reads the phase off the animation player that is playing the stroke — its seek time over the clip's own length (swim_secs) — so the splash follows a re-cut pack, a playback-rate change and a pinned capture alike. A rebuilt pack whose stroke moves fails that test rather than splashing at the wrong moment.

Drawn with the particle shader, plus two shapes

systems::particles' closed form and quad pool, unchanged in principle (particles-are-a-function-of-time.md). Two shapes are added, chosen by the spare sizing.w; a prim's effect never sets it, so neither is on the wire.

What it is meant to look like, and how it first did not (owner review, 2026-11-16): the first rings were crisp thin white circles that read as UI drawn on the water, and the spray was round soft blobs of one size that read as snow. The reference photos (CC0, Wikimedia Commons: a girl jumping into the sea at Röe Sandvik; ripples on a foggy lake) show a splash as a dense white crown with fine streaked drops flung off it and white water on the surface, and ripples as a faint brightening of the reflection. So the ripples became faint (alpha ≤ 0.3, a test holds it), and a body going in became four bursts: fine drops, a "crown" of bigger slower drops, the ripples, and a foam "ring" whose band was wider than it was, i.e. a soft disc. A stroke is fine drops and two ripples. Judged on mac-1's GPU, which is evidence for the shape and not for exact colour.

That was still not a splash (owner, comparing it with the photo the same day: "a scatter of streaks over a glowing disc with a round edge"). What the photo is mostly made of is a sheet — water thrown up as a ragged wall, clear between white streaks, breaking into fingers and beads at the top — and no number of particles draws a sheet. So a body going in is now:

How the sheets are drawn. One shared grid mesh (64 segments round, 12 rows up: 845 vertices) is shaped in assets/shaders/splash.wesl from the clock and two vec4s, as the particles are. A splash writes one small uniform and uploads no vertices. The vertex stage gives only the broad shape. Everything small is cut per pixel: the rim's fingers, the beads they break into, the white streaks up the sheet, the torn foot, the holes as it falls apart, and the foam's lace and edge. The first version shaped the rim from vertices, and with 64 segments the fingers came out as straight-edged white shards over a smooth white bowl. The fragment keeps the rim under the grid's top row for the same reason. It is alpha-blended (white water covers what is behind it, clear water tints it). It is lit by the directional lights, two-sided and wrapped, plus the ambient, so it follows the hour, and a noisy facet normal gives sun glints.

Cost. Six slots of three sheets (six bodies going in within one crown's life), re-armed in turn like the bursts. A live entry is three draws of 1,536 triangles and four particle draws; nothing is drawn once it is over. The fragment work is three to four layers of 3D value noise over what the crown covers on screen, which is a large area only when the camera is within a few metres. No GPU timing: the Mac VM nodes have no Metal counters (gpu-timings-on-the-mac-workstation.md).

Where it stands: on the water as drawn. The sheet is clamped above the ground under it (map_geometry's water clamp, level.max(sunk_at)). Where a bank sample was not carved, that ground is the bank's, and at Noorderhaven it is 0.86 m over the registered level at the entry point. A splash on the level there was buried, and only the highest drops showed. The splash and the treading rings stand on the drawn height. Flat foam on a sloping sheet cut into it along straight lines. Foam tilted to the slope was worse: the slope, read off the bank, stood it up as a white wedge. So the foam stays level and fades out, in each of eight directions, before the drawn sheet leaves its level by 8 cm (foam_reach, two more vec4s on the material). The ripples are still flat on a sheet that slopes there.

Sounds

CC0 recordings, Freesound HQ previews, cut and credited as the city sounds were (city-soundscape.md, assets/sounds/LICENSE.md). Levels follow AppPrefs::effects_volume; heard only while the camera follows the avatar, with the avatar as the ear, as the ambience is. At most three one-shots start in a frame.

RUST_LOG=cartopolis::splashes=debug logs every splash found (drop, speed, size), every sound started (take, volume, and the animation clock, which is a --video-fps movie's own time) and the two loops' levels four times a second — enough to rebuild the soundtrack of a capture, which is how it was checked: nobody can listen in the agent container.

Not done