Builtin Library
- ..
- README.md2.2 KB
- bindings.yaml1.7 KB
- shader.wgsl10.7 KB
README.md
terrain_water_mesh
Builds one node of the water surface from the water / waterMask channels,
into the same 23-word vertex layout and the same slot-addressed pool
terrain_mesh writes.
The baked column
Alongside altitude, each vertex bakes the WATER COLUMN — how far the surface
stands above the bed — into the vertex colour's red channel (word 19):
max(water - height, 0) where covered, 0 where not, and a sentinel standing
for open ocean on a flat skirt vertex, which has no channel to measure
against. terrainWater.shader reads it back as an interpolated attribute
instead of reconstructing it from the scene depth buffer, which a plain
material draws with no depth copy behind it.
Where a vertex's altitude comes from
| the cell under the vertex | y |
|---|---|
| covered by water | water — the surface itself |
| not covered | min(water, height - sink) |
The uncovered branch is what ends the surface at the shore. height - sink is
under the terrain by construction, so a vertex with no water above it is buried
whatever the water channel holds there; taking the lesser of the two keeps the
plane flat right up to the last covered vertex, so the waterline falls where
the plane and the ground cross rather than on a node boundary.
Coverage is read from the nearest cell rather than interpolated: a cell either carries a surface or it does not, and half-covered is not a state the surface has.
The skirt
A node with flat set reads no channel and sits at flatLevel. That is the
outer skirt — the ring of nodes carrying the sea from the field's rect out to
the horizon, so an island has water all the way around it instead of stopping
at the grid. Skirt vertices meet the rect's edge vertices at exactly the sea
level, which is what makes the join seamless rather than merely close.
Because the skirt's edge pieces are as long as the field and as deep as the
horizon is far, a node here is a rectangle: nodeSizeX and nodeSizeZ are
separate.
Stitching
Boundary stitching is the same rule as terrain_mesh: on an edge whose
neighbour is one level coarser, the odd boundary vertices snap onto the
previous even one. There is no geomorph — a level surface has nothing to pop.