Skip to main content

Module water

Module water 

Source
Expand description

Analytic water-surface geometry helpers.

The water is rendered analytically in a fragment shader (no tessellated surface): a coarse proxy sphere spawns fragments, and the shader ray-intersects the mathematical sea-level sphere whose radius is computed here. The level matches the exact radius at which the terrain noise crosses water_height, so seas/lakes line up with the terrain’s own water coloring.

Mirror of the displacement math in ChunkRealize.slang::displace: pos = dir * (radius + (h - 0.5) * 2.4 * radius * height_scale). Evaluated at h = water_height that is the sea-level radius below. The same formula is used for every builder (noise or custom) so the water level slider means the same thing everywhere — water_height = 0.5 is the baseline (the noise midpoint AND the custom h = 0 line), where the sea sits exactly at radius.

Constants§

HEIGHT_CENTER_SCALE
The displacement shader maps a normalized height h to a centered offset (h - 0.5) * HEIGHT_CENTER_SCALE. Keep in sync with displace in ChunkRealize.slang (and ChunkTileBake / TileViewer / ScatterPlace).
PROXY_MARGIN
Radius of the coarse render-proxy sphere: the analytic water radius inflated by a small margin so the proxy’s faceted silhouette always covers the true (smooth) sphere’s silhouette — rays that miss the analytic sphere are discarded in-shader, so the proxy only needs to over-cover, never under.

Functions§

proxy_radius
Convenience: proxy sphere radius from the analytic water radius.
water_radius
World radius of the analytic sea-level sphere: the terrain surface radius evaluated at water_height. water_height = 0.5 is the baseline — the noise midpoint / custom h = 0 line — at which the sea sits exactly at radius. At the shipped defaults (CesBuilder::water_height 0.549, CesGPUNoiseExample’s height_scale 0.0585) it sits slightly above, at 1.0069 * radius, so terrain pokes through to form seas/lakes wherever the height rises above water. Lowering the level drains the seas; raising it floods low land.