Skip to content

Shore foam - #1253

Open
Jin-Jiyunsun wants to merge 40 commits into
117HD:masterfrom
Jin-Jiyunsun:shore-foam
Open

Jin-Jiyunsun wants to merge 40 commits into
117HD:masterfrom
Jin-Jiyunsun:shore-foam

Conversation

@Jin-Jiyunsun

@Jin-Jiyunsun Jin-Jiyunsun commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Does what it says on the tin!

Boat wake:

java_1Edj2QL5Hy.mp4

Sea gets rougher in "stormy" areas

java_Yh6WwSHAvx.mp4

Reworked shore foam with lapping waves:

java_Ry7mJiLTSV.mp4

Civitas docks:

java_yPVJ6t4uZn.mp4

Shore foam now better follows edges and has fewer harsh edges:
java_HThKXGcrSY
java_DrzheKMvQm

Still of redrock:

java_xdaajJCDl3

Rework the water shader's shore foam, behind a new experimental
"Improved shore foam" option which keeps the original for comparison:

- Calculate each water vertex's distance and direction to the nearest
  land at scene load, so foam can extend several tiles from the shore
  and follow the shoreline's shape rather than the tile grid
- Work out the distance within square tiles touching land per pixel,
  so channels one tile wide no longer fill completely with foam
- Blend three continuously changing copies of the foam texture, gently
  warped and swaying towards the shore, over a faint cloudy layer
- Roll uneven waves of foam in towards the shore, which surge the
  shore foam outwards as they arrive
- Weight foam by luminance instead of its red channel

Also stop the depth bias for water tiles flush with underwater terrain
from turning a corner which isn't on the shore into a square of foam.
- Define the shore data color layout once in SceneContext and pass it
  to the water shader as defines, instead of repeating bit literals
- Share square water tile packing between both uploaders, and check
  shore vertices directly for the depth bias
- Track land tiles with a tile flag rather than a separate array
- Read each vertex's shore data with a single hash lookup, and skip
  the foam luminance conversion on water without foam
- Tidy the foam shader and shorten comments
Waves are now separate segments spawned along stretches of the shore at
random times, each with its own place, length, thickness, speed and
strength, coming in sets and lulls and slowing evenly towards the shore.
They only form where there's enough open water, from a room value baked
at scene load, so small ponds and narrow channels stay calm.

Removes the shore haze and surge.
Only check the slots and stretches whose waves could cover each point, doing the
cheapest checks first, and skip waves where there's no room or they'd be invisible.
Measure shore distance and room with one distance transform, and pack the room
into the shore data so each water vertex needs one lookup.
Split wave thickness into start and end settings.
A churning lace of foam lines on open water, from swirled, animated Voronoi cell
edges broken up by its own drifting foam texture, with gaps and varying width.
Whitecaps break across it: crests sweep downwind, easing in and out, leaving
trails which fade from when the crest passed, streaked and broken up unevenly.
Only on open water, keeping clear of the shore.
The foam drifts and breaks with each area's wind, accumulated on the CPU so a
change in the wind doesn't shift it, and whitecaps which would run too close to
the shore don't form, using shore distances now measured out to 12 tiles.

The lace fades out with distance from the camera like shadows, with its finest
detail closer in, and skips lines broken off into gaps. Whitecaps only work out
their noise when one is nearby. Faces away from the shore skip the shore foam.
Search the neighbouring stretches with a plain 3x3 loop, and skip the shore
direction where no corner of a face is within range of the shore, and the
square tile distance away from it.
… changing light and wind

The lace and ocean waves are now independent, each with its own strength, softness,
stretch and on/off, and whitecaps are renamed to ocean waves. Both stretch along the
wind only locally, so a change in the wind no longer swings the patterns around. The
water's wind eases slowly towards each environment's, and each ocean wave keeps the
wind from when it spawned, from a per-second history.

Foam stays visible at sunrise and sunset, at least FOAM_WATER_BRIGHTNESS times as
bright as the water under it, and only fades in real darkness. Comments are trimmed.
Each environment's wind strength, relative to the overworld's, times a new
waterRoughness field sets how rough open water is, easing in over a few seconds
and capped at 2. Rougher water spawns more, stronger and bigger ocean waves, and
strengthens, thickens and churns the lace faster. Ocean waves spawn from the
roughness at their spawn time, recorded per second alongside the wind, so waves
already going don't pop in or change size. The Tempoross storm is set rough.
Wakes follow one path per boat, from the bow along the hull, then curving
from the stern into the path it took, so there's no seam. The foam uses
the ocean waves' specks, flow warping and fade, at a little under their
brightness, and its tail ends in a ragged, patchy fade.

When a boat stops, its whole wake breaks up evenly in fine patches and
turns see-through. If it moves off again first, the old wake is left
where it was to finish fading, and the new one fades in. The timing and
look are set in water.glsl, so they reload live.

Shore foam, open water lace, open water waves and boat wakes each get
their own switch.
The wake's arms turn see-through gradually towards their outer edges,
leaving the inner edges as they were. As a wake disappears, it turns
see-through in soft patches rather than all at once, and once the boat
stops, its tail wipes away towards the boat more slowly.
Boats now count as stopped once their position stops changing, replacing
the speed thresholds, the speed ramp and the speed tracking. The tail's
end slides smoothly instead of stepping back as old points are dropped,
and fades out see-through as it breaks up.

The strip behind the stern is now the boat wash, with its own start,
width, length and taper to a point, and it can outlast the wake's arms
on a longer recorded path. The arms get a denser, brighter rim along
their outer edge and start a little further forward. A boat going
backwards leaves just the wash.

Removes redundant settings and packs each boat's point count into its
uniform data.
Wakes now scale to each boat's size, from its bounds, against the medium
sloop they were tuned on. Shorter boats' wakes sit a little further
forward, and rafts get a square front.

Wakes are also updated by the legacy renderer, survive the plugin
restarting, and take their brightness from the ocean waves' strength
rather than their fronts.

The ocean waves get a little extra brightness right at their crest's
edge, the lace is slightly brighter, and the open water foam drops its
"0 turns it off" checks now that it has its own switches.
Foam gets more opaque as the sun drops below about 30 degrees, easing back
off as it sets, so the sky's bright reflection doesn't wash it out. In dim
light it takes the light's colour instead of going grey, and on bright water
it can get a little brighter.
Wakes now go only on the world entity types the wiki lists as boats, so
trawling shoals don't get one. Up to 16 wakes are drawn, and stopped boats
whose wakes have faded give up their slot. The charter ship, the Rock
Island Prison pirate ship and the strange ship keep a longer path and get
their own arm angle, arm length and wash settings.

Each wake's bounds now fit its own path, the shader stops at the first
empty slot and works out each noise once per pixel, and the start of the
path is bent onto the hull's line while turning, so the tail meets the
hull without a step.
Ease towards the environment being moved to rather than the faded one, more slowly as it roughens than as it calms, and roughen the Tempoross cove.
The lace reaches no further than the detail distance setting, up to 70
tiles, measured across the water so looking down doesn't hide it. The
fine lines were too faint to see, so they're gone, along with a second
cell search per pixel. The lace takes 2 square roots instead of 9, and
ocean wave cells too far away are skipped before their roughness lookup.
The ocean and wake specks share their UVs, and the wake loop exits early
rather than nesting its fades.
Boat wakes: work out each wake's bounds in BoatWakes, with its bow and
room for its foam, so the shader rejects on them before anything else,
and leave out path points along straight, steady stretches.

Ocean waves: only work out the ragged edge noise where a wave's foam
could reach, and the breakup noise once a wave has some cover.

Shore waves: work out each wave's random numbers only once the check
before them passes.

Lace: return before the dense area noise where there's no line, and
measure cell distances along and across the wind directly.

Also drop an ocean wave check that could never fire, and work out the
shore waves' start distance and the foam's low sun opacity once.
Finishes the part way commit before this, which moved the water's wind,
roughness and history out of HdPlugin into WaterSurfaceManager, sent
from one place for both renderers.

Remove what the main foam path already covers: IMPROVED_SHORE_FOAM and
its copies of the original shore fade, the shader's fallbacks for values
that are now always set, the shore waves' unused spawn window, and the
check for finished wakes, which BoatWakes now stops sending.

Rougher water now scales the waves and lace directly rather than through
powers of 1, and SHORE_DISTANCE_MAX also covers the room for waves.

Boat wakes: name the shared noise and the big ships' shape rather than
packing them into vectors, and loop over just the wake's points.
The edge noise was fixed to the world, so as a wake's edge drifted
outwards it slid across the noise, and the wiggles came and went about
once a second. Now each wake shifts the noise by how far its foam has
drifted, so the wiggles keep their shape as they ride out.
Ocean waves stop where they run into a wake's arms, their foam adding to
the arm's there rather than one showing through the other, and the lace
and waves are left out where a boat has churned up the water.

Waves that were already there when a boat swept over them stay broken up
there for the rest of their lives, as far back as its path is recorded,
fading back in as a stopped boat's wake breaks up. How much each spot
was swept, and when, comes from every part of each path rather than just
the nearest, so it doesn't jump where the nearest switches on a turn.
The area a wake has swept, where the waves it passed over stay broken up,
now fades in with the wake as the boat moves off, rather than appearing all
at once. It stops growing outwards where the arms' foam has broken up, rather
than carrying on to where the arms would have reached, so it no longer takes
out waves the visible foam never touched. Only the parts of the path about as
near as the nearest one, which the arms are drawn from, sweep a spot, so slow
boats' bunched-up older points don't push it out further.
Water types' foam colors were tuned for the original shore fade, where their
brightness also sets how strong the foam is, so dark ones like PLAIN_WATER's
gave the ocean waves, lace and boat wakes foam darker than the water. Those
now take only the color's hue, at the default foam color's brightness, so
normal water looks the same. Shore foam keeps the full color, blending
between the two by how much of the foam is open water foam.
Shore waves no longer search each stretch of shore for waves. Like the ocean
waves, each now rushes in, eases to a stop short of the shore and leaves its
foam to break up where it was laid. They come in on three steady cycles, each
out of step along the shore in its own way, with every wave covering its own
pieces of shore.

Lace has its own, gentler shore fade and room requirement, so it reaches
into narrower water, and fades rather than thins towards the shore. It finds
its lines among the 2x2 nearest cells rather than all 3x3, which drops a
little of the pattern for a quarter of the cost. Ocean waves skip cells that
can't spawn or reach a pixel before reading their history, read the first
second of it while the wind is steady, and are stretched along their own
direction rather than the wind's.

Environments can scroll the waves, lace and ripples with waveScrollDirection
and waveScrollSpeed, repeat them in every region with waveRegionRepeat, and
set waveRoughness, renamed from waterRoughness. The water's wind snaps to the
new one on instant transitions. Water types can inherit from a parent, keep
waves and lace off with hasWaves, and stay still with scrolls. Open water
foam takes only the hue of a water type's foam colour.
The trawler's sea scrolls past as if the boat is sailing, repeats its waves
in each of its regions so moving between them doesn't jump the pattern, and
keeps its wind steady. The water inside the boat gets its own water type,
without waves or scrolling. Plain water's foam colour is now black.

Also hides the inactive fishing spot and the waterfall droplets in the
trawler, lowers its sacks into the water, and hides the fake ripples around
shark fins.
All the foam is now worked out before the water's normals and lighting,
rather than in the middle of them, so the lighting's values no longer have
to be kept through the foam's loops and noise. The wakes' own foam is also
settled before the lace and waves, leaving only its amount, specks and churn
to carry through them.

Boat wakes first mark which boats' bounds hold the pixel, and only go through
those. They skip the second pass over a path, for the area it has swept,
where no other part of it is near enough to add anything, as along any
straight stretch.

The output is unchanged. In game, with everything on, the foam costs 21% less
in open water with no boats, and 27% less with 16 boats, where the wakes on
top of the other foam cost 65% less. Having wakes on with no boats nearby no
longer costs anything measurable.
… face

The zone renderer's vertex shader now works out which of the 5x5 wave cells
around each water face can reach it, and passes the face that list. Its
pixels only check the listed cells, and stop at once when there are none.
Pixels further from the face's vertex than the list covers, as on larger
faces or water that doesn't scroll, still check all nine cells around them,
so no wave is ever missed. The legacy renderer has no list and checks all
nine as before.

Where and when a cell has a wave is now worked out in one place,
ocean_wave_cells.glsl, shared by both shaders so they can't disagree. The
wave check also skips sooner: a wave's front is less ragged than the rest
of it, and trails whose foam has fully faded are skipped. Shore waves only
work out their breakup noise once a wave needs it.

The waves look the same, apart from rounding along their fronts. In game at
Port Khazard, wherever the GPU is the limit, the ocean waves cost 21% to 34%
less, and all the foam 16% to 24% less.
HdPlugin makes a small tiling texture of random values at startup, from the
plugin's fixed seed, and the scene programs read it as waterNoise. The lace,
ocean waves, boat wakes and shore foam read their value noise from it, one
filtered read in place of hashing four corners. Moving the read by the
smoothstep curve within each cell keeps the noise's smooth blend. The lace's
cell points take their random offsets from it too.

The foam looks the same, though its patterns fall in different places, since
the random values are new. In game at Port Khazard at 150%, the lace costs
about half as much, and all the foam about a fifth less with no boats.
No change to how the foam looks or what it costs.

- Remove the unused noise2, and pass WATER_NOISE_SIZE to the shaders as a
  define instead of repeating it
- Rename boatWakeHulls to boatWakeStates, since it holds each wake's point
  count and timers
- Give BoatWakes' copies of the shader's wake settings the same names as in
  water.glsl, and group its constants and fields
- Regroup the foam settings at the top of water.glsl
- Shorten comments, and describe intent rather than earlier versions
Its config key changes from experimentalImprovedShoreFoam to
experimentalShoreFoam, so a saved value for it resets to the default.
@Jin-Jiyunsun
Jin-Jiyunsun marked this pull request as ready for review November 18, 2026 03:51
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