Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(water): foam bursts on steep shores and washes thinly up beaches, by how steep the shore is and how exposed the water

yhh470f59f76a4b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6ea9cd6e2..b0bd99e7b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -31,6 +31,7 @@ published separately; it ships inside the editor.
- **Rays against the terrain, anywhere.** `Terrains.raycast(origin, direction, maxDistance)` meets the ground's triangles exactly (the ones collision and `heightAt` use) wherever the ray goes, with no physics world and no collision tile there, for a line of sight, a pick or a landing spot.
- **Far versions for generated decoration.** A recipe member can name its far version (`far`: crossed cards, or a tent for a conifer, showing a rectangle of its texture), drawn past its layer's `lodDistance`, and decoration that leans with the ground (`attach: 'align'`) now leans in its merged mesh too.
- **Terrain modifiers, and zones that level their ground.** `Terrains.setModifier` lays a change over the ground (`flattenModifier` levels a circle or a turned box, blending back over its edge) that what is drawn, the queries, rays and collision all follow, remaking only the pages and collision tiles it reaches; `heightBeneathAt` reads the ground as it was made. A `WorldZone` with `flatten` levels its plot to the ground's height at its centre.
+- **Foam is where waves burst, not along every shore.** The zone bakes how steep each shore is: against rock and cliffs the shore foams and the breakers burst white; up a gentle beach the waves wash in a thin line only and run up a short way rather than spreading a white sheet over the sand; and the less room the wind has to raise them (a sheltered lake), the less of either.
- **Surf comes in from open water as lines.** Its crests followed every turn of the shore, bending into a river's mouth from far out; they now follow a distance of their own, the open water's edge with a river's water taken for land, smoothed over the surf's length, so they come in straight and turn to the shore only as they near it. Where the surf rises, breaks and runs up is still the real shore's, and a river's current calms it over a spread past the mouth rather than cutting it off at the river's side.
- **A river gives way where it runs into the sea or a lake.** Over half its width past their shore it fades into them, its current with it, where it used to stop within a texel and a half and leave its sides running on into the open water: the surf, which no current carries, broke off along those lines. The surf now runs on along the coast and round into the mouth.
- **Water meets the shore along a smooth line.** Close up, a river's banks and the surf on a beach ran in steps a texel of the water zone wide: the baked shore distance is now stored finely near the shore (a signed square root of it), and past the shore the surf's film and the shallows' foam are told dry from wet by the picture's depth at each pixel rather than by the baked depth, which only knew whole texels.
diff --git a/docs/astro/src/content/docs/graphics/water.mdx b/docs/astro/src/content/docs/graphics/water.mdx
index 23dcf88d4..cfe73b5ce 100644
--- a/docs/astro/src/content/docs/graphics/water.mdx
+++ b/docs/astro/src/content/docs/graphics/water.mdx
@@ -84,6 +84,10 @@ they break in the inner part of that band and stay white behind the crest a whil
too, a little above the water's rest height, and the depth test cuts it where the ground rises above it, so the waterline climbs a beach and falls back.
A breaker stands `surf` times the body's `waveHeight` (with the weather's waves in), times how open the water is: surf is swell come in from open water, so a
lake's shore laps where the sea's breaks; a current carries none, so a river and its mouth stay calm.
+The crests are lines of their own distance, the open water's edge (a river's water taken for land) smoothed over a `surfLength`, so they
+come in straight from open water and turn to the shore only near it, and run straight across a river's mouth; where they rise, break and
+run up is the real shore's. How white they burst is the shore's too: the zone bakes how steep each shore is, so waves burst and foam
+against rock and cliffs, wash up a gentle beach in a thin line, and run up only a short way.
`Waters.sample` adds the same surf, so what floats near a beach rides it.
## Geometry
diff --git a/docs/astro/src/content/docs/zh-cn/graphics/water.mdx b/docs/astro/src/content/docs/zh-cn/graphics/water.mdx
index 106ed6bad..3c42d83ef 100644
--- a/docs/astro/src/content/docs/zh-cn/graphics/water.mdx
+++ b/docs/astro/src/content/docs/zh-cn/graphics/water.mdx
@@ -59,7 +59,7 @@ description: 若干 WaterBody 组件说明海洋、湖泊或河流在哪里,一
## 拍岸浪
-水与地面相接处,浪朝岸边推进。区域量出每一处沿地面到最近岸线的距离(海洋漫过沙滩和湖泊都是同一种量法),在最后四个 `surfLength` 的水面上,拍岸浪按这个距离立起来:朝岸的一面陡、背面长,以同波长深水波的速度乘 `waveSpeed` 向岸推进。水变浅时浪变高,在这段水域的靠岸部分破碎发白,浪峰过后白沫还会留一阵;过了岸线浪会冲上地面:那里也画出水面,略高于静水面,地面高过它的地方由深度测试裁掉,所以水线会爬上沙滩再退回来。浪头高度是所在水体的 `waveHeight` 乘 `surf`(含天气对波浪的缩放),再乘水面的开阔程度:拍岸浪是从开阔水面传来的涌浪,所以海岸会破浪,湖岸只是轻拍;有水流的地方没有拍岸浪,所以河流和河口保持平静。`Waters.sample` 也加上同样的拍岸浪,沙滩附近的漂浮物会随之起伏。
+水与地面相接处,浪朝岸边推进。区域量出每一处沿地面到最近岸线的距离(海洋漫过沙滩和湖泊都是同一种量法),在最后四个 `surfLength` 的水面上,拍岸浪按这个距离立起来:朝岸的一面陡、背面长,以同波长深水波的速度乘 `waveSpeed` 向岸推进。水变浅时浪变高,在这段水域的靠岸部分破碎发白,浪峰过后白沫还会留一阵;过了岸线浪会冲上地面:那里也画出水面,略高于静水面,地面高过它的地方由深度测试裁掉,所以水线会爬上沙滩再退回来。浪头高度是所在水体的 `waveHeight` 乘 `surf`(含天气对波浪的缩放),再乘水面的开阔程度:拍岸浪是从开阔水面传来的涌浪,所以海岸会破浪,湖岸只是轻拍;有水流的地方没有拍岸浪,所以河流和河口保持平静。浪峰按自己的距离场排列:开阔水域的边缘(河里的水当作陆地)在一个 `surfLength` 范围内平滑,所以浪从开阔水面以直线涌来,近岸才转向贴合岸线,在河口处直线跨过;浪在哪里涌起、破碎、上滩仍按真实岸线。白水多少也由岸决定:区域烘焙时记录每段岸的陡度,浪拍在礁石和悬崖上碎成白沫,在缓坡沙滩上只冲出一条细线,上滩距离也很短。`Waters.sample` 也加上同样的拍岸浪,沙滩附近的漂浮物会随之起伏。
## 几何体
diff --git a/sdk/src/water/waterShader.ts b/sdk/src/water/waterShader.ts
index 4d9ffda6e..a398a6c7f 100644
--- a/sdk/src/water/waterShader.ts
+++ b/sdk/src/water/waterShader.ts
@@ -161,17 +161,22 @@ float waterZoneStill(vec2 p) {
vec2 uv = (p - u_zoneOrigin) / max(u_zoneSize, vec2(1e-4));
return textureLod(u_zoneExposure, clamp(uv, 0.0, 1.0), 0.0).b;
}
+// How steep the shore is at p: 0 a gentle beach (waves wash up it), 1 rock or a cliff (they burst white on it).
+float waterZoneSteep(vec2 p) {
+ vec2 uv = (p - u_zoneOrigin) / max(u_zoneSize, vec2(1e-4));
+ return textureLod(u_zoneExposure, clamp(uv, 0.0, 1.0), 0.0).a;
+}
// The surf (waves.ts surfHeight): its crests are lines of phase (the distance the surf runs in by), and it rises, breaks and runs up by
// shore, the real distance to the shore. x its height, y how broken it is (white water on and behind a breaking crest).
vec2 waterSurf(float phase, float shore, float height, float time) {
if (height <= 0.0 || u_surfLength <= 0.0) return vec2(0.0);
float reach = u_surfLength * 4.0;
- if (shore > reach || shore < -reach * 0.2) return vec2(0.0);
+ if (shore > reach || shore < -reach * 0.05) return vec2(0.0);
float celerity = sqrt(9.8 * u_surfLength / 6.2831853) * u_surfSpeed;
float u = fract(phase / u_surfLength + celerity * time / u_surfLength);
float g = u > 0.8 ? smoothstep(0.0, 1.0, (u - 0.8) / 0.2) : 1.0 - smoothstep(0.0, 1.0, u / 0.8);
float shoal = 1.0 - smoothstep(0.0, 1.0, (shore - reach * 0.25) / (reach * 0.75));
- float runUp = shore >= 0.0 ? 1.0 : 1.0 - smoothstep(0.0, 1.0, -shore / (reach * 0.2));
+ float runUp = shore >= 0.0 ? 1.0 : 1.0 - smoothstep(0.0, 1.0, -shore / (reach * 0.05));
float env = shoal * runUp;
// It breaks in the inner third: the crest whitens, and the water behind it stays white a while.
float breaking = 1.0 - smoothstep(reach * 0.15, reach * 0.4, shore);
@@ -259,17 +264,22 @@ fn waterZoneStill(p : vec2f) -> f32 {
let uv = (p - mc.u_zoneOrigin) / max(mc.u_zoneSize, vec2f(1e-4));
return textureSampleLevel(u_zoneExposure, u_zoneExposure_s, clamp(uv, vec2f(0.0), vec2f(1.0)), 0.0).b;
}
+// How steep the shore is at p: 0 a gentle beach (waves wash up it), 1 rock or a cliff (they burst white on it).
+fn waterZoneSteep(p : vec2f) -> f32 {
+ let uv = (p - mc.u_zoneOrigin) / max(mc.u_zoneSize, vec2f(1e-4));
+ return textureSampleLevel(u_zoneExposure, u_zoneExposure_s, clamp(uv, vec2f(0.0), vec2f(1.0)), 0.0).a;
+}
fn waterSurf(phase : f32, shore : f32, height : f32, time : f32) -> vec2f {
if (height <= 0.0 || mc.u_surfLength <= 0.0) { return vec2f(0.0); }
let reach = mc.u_surfLength * 4.0;
- if (shore > reach || shore < -reach * 0.2) { return vec2f(0.0); }
+ if (shore > reach || shore < -reach * 0.05) { return vec2f(0.0); }
let celerity = sqrt(9.8 * mc.u_surfLength / 6.2831853) * mc.u_surfSpeed;
let u = fract(phase / mc.u_surfLength + celerity * time / mc.u_surfLength);
var g = 1.0 - smoothstep(0.0, 1.0, u / 0.8);
if (u > 0.8) { g = smoothstep(0.0, 1.0, (u - 0.8) / 0.2); }
let shoal = 1.0 - smoothstep(0.0, 1.0, (shore - reach * 0.25) / (reach * 0.75));
var runUp = 1.0;
- if (shore < 0.0) { runUp = 1.0 - smoothstep(0.0, 1.0, -shore / (reach * 0.2)); }
+ if (shore < 0.0) { runUp = 1.0 - smoothstep(0.0, 1.0, -shore / (reach * 0.05)); }
let env = shoal * runUp;
let breaking = 1.0 - smoothstep(reach * 0.15, reach * 0.4, shore);
let steep = smoothstep(0.012, 0.045, height / mc.u_surfLength);
@@ -448,17 +458,22 @@ float waterZoneStill(vec2 p) {
vec2 uv = (p - u_zoneOrigin) / max(u_zoneSize, vec2(1e-4));
return textureLod(u_zoneExposure, clamp(uv, 0.0, 1.0), 0.0).b;
}
+// How steep the shore is at p: 0 a gentle beach (waves wash up it), 1 rock or a cliff (they burst white on it).
+float waterZoneSteep(vec2 p) {
+ vec2 uv = (p - u_zoneOrigin) / max(u_zoneSize, vec2(1e-4));
+ return textureLod(u_zoneExposure, clamp(uv, 0.0, 1.0), 0.0).a;
+}
// The surf (waves.ts surfHeight): its crests are lines of phase (the distance the surf runs in by), and it rises, breaks and runs up by
// shore, the real distance to the shore. x its height, y how broken it is (white water on and behind a breaking crest).
vec2 waterSurf(float phase, float shore, float height, float time) {
if (height <= 0.0 || u_surfLength <= 0.0) return vec2(0.0);
float reach = u_surfLength * 4.0;
- if (shore > reach || shore < -reach * 0.2) return vec2(0.0);
+ if (shore > reach || shore < -reach * 0.05) return vec2(0.0);
float celerity = sqrt(9.8 * u_surfLength / 6.2831853) * u_surfSpeed;
float u = fract(phase / u_surfLength + celerity * time / u_surfLength);
float g = u > 0.8 ? smoothstep(0.0, 1.0, (u - 0.8) / 0.2) : 1.0 - smoothstep(0.0, 1.0, u / 0.8);
float shoal = 1.0 - smoothstep(0.0, 1.0, (shore - reach * 0.25) / (reach * 0.75));
- float runUp = shore >= 0.0 ? 1.0 : 1.0 - smoothstep(0.0, 1.0, -shore / (reach * 0.2));
+ float runUp = shore >= 0.0 ? 1.0 : 1.0 - smoothstep(0.0, 1.0, -shore / (reach * 0.05));
float env = shoal * runUp;
// It breaks in the inner third: the crest whitens, and the water behind it stays white a while.
float breaking = 1.0 - smoothstep(reach * 0.15, reach * 0.4, shore);
@@ -682,9 +697,15 @@ void main() {
// With the picture's depth the shallows foam by it, pixel by pixel; the baked depth then adds only the traced outline, not its texels.
float baked = haveDepth ? shoreDist : min(shoreDist, shoreDepth);
shore = max(shore, clamp((1.0 - baked / (u_foamWidth * pulse)) * 1.25 - breakup * 1.15, 0.0, 1.0));
+ // How the shore takes its waves: against rock or a cliff they burst white; up a gentle beach they wash in a thin line only; and the
+ // less room the wind has to raise them (a sheltered lake), the less of either.
+ float pound = waterZoneSteep(wp);
+ float swash = 1.0 - smoothstep(0.0, surfStep * 1.5, shoreDist);
+ shore *= mix(swash * 0.6, 1.0, pound) * mix(0.3, 1.0, zone.w);
}
float onCrest = u_foamCrest > 0.0 ? smoothstep(1.0 - 0.3 * u_foamCrest, 1.0, crest) * smoothstep(0.35, 0.75, breakup) : 0.0;
- float surfFoam = surf.y * smoothstep(0.15, 0.6, breakup + surf.y * 0.4);
+ // A breaker whitens as much on a beach as the waves are big, but bursts whitest on rock.
+ float surfFoam = surf.y * smoothstep(0.15, 0.6, breakup + surf.y * 0.4) * mix(0.45, 1.0, zoneOn ? waterZoneSteep(wp) : 1.0);
float foam = clamp(max(max(max(shore, onCrest * u_foamCrest), ripFoam * (0.55 + 0.45 * breakup)), surfFoam), 0.0, 1.0);
// Foam floats on top: from under the water it is a thin shadow on the light, not a white sheet.
if (below) foam *= 0.2;
@@ -886,17 +907,22 @@ fn waterZoneStill(p : vec2f) -> f32 {
let uv = (p - mc.u_zoneOrigin) / max(mc.u_zoneSize, vec2f(1e-4));
return textureSampleLevel(u_zoneExposure, u_zoneExposure_s, clamp(uv, vec2f(0.0), vec2f(1.0)), 0.0).b;
}
+// How steep the shore is at p: 0 a gentle beach (waves wash up it), 1 rock or a cliff (they burst white on it).
+fn waterZoneSteep(p : vec2f) -> f32 {
+ let uv = (p - mc.u_zoneOrigin) / max(mc.u_zoneSize, vec2f(1e-4));
+ return textureSampleLevel(u_zoneExposure, u_zoneExposure_s, clamp(uv, vec2f(0.0), vec2f(1.0)), 0.0).a;
+}
fn waterSurf(phase : f32, shore : f32, height : f32, time : f32) -> vec2f {
if (height <= 0.0 || mc.u_surfLength <= 0.0) { return vec2f(0.0); }
let reach = mc.u_surfLength * 4.0;
- if (shore > reach || shore < -reach * 0.2) { return vec2f(0.0); }
+ if (shore > reach || shore < -reach * 0.05) { return vec2f(0.0); }
let celerity = sqrt(9.8 * mc.u_surfLength / 6.2831853) * mc.u_surfSpeed;
let u = fract(phase / mc.u_surfLength + celerity * time / mc.u_surfLength);
var g = 1.0 - smoothstep(0.0, 1.0, u / 0.8);
if (u > 0.8) { g = smoothstep(0.0, 1.0, (u - 0.8) / 0.2); }
let shoal = 1.0 - smoothstep(0.0, 1.0, (shore - reach * 0.25) / (reach * 0.75));
var runUp = 1.0;
- if (shore < 0.0) { runUp = 1.0 - smoothstep(0.0, 1.0, -shore / (reach * 0.2)); }
+ if (shore < 0.0) { runUp = 1.0 - smoothstep(0.0, 1.0, -shore / (reach * 0.05)); }
let env = shoal * runUp;
let breaking = 1.0 - smoothstep(reach * 0.15, reach * 0.4, shore);
let steep = smoothstep(0.012, 0.045, height / mc.u_surfLength);
@@ -1120,10 +1146,18 @@ fn waterSurface(p : vec2f, time : f32, dist : f32, amp : f32, calm : f32) -> vec
var baked = min(shoreDist, shoreDepth);
if (haveDepth) { baked = shoreDist; }
shore = max(shore, clamp((1.0 - baked / (mc.u_foamWidth * pulse)) * 1.25 - breakup * 1.15, 0.0, 1.0));
+ // How the shore takes its waves: against rock or a cliff they burst white; up a gentle beach they wash in a thin line only; and the
+ // less room the wind has to raise them (a sheltered lake), the less of either.
+ let pound = waterZoneSteep(wp);
+ let swash = 1.0 - smoothstep(0.0, surfStep * 1.5, shoreDist);
+ shore = shore * mix(swash * 0.6, 1.0, pound) * mix(0.3, 1.0, zone.w);
}
var onCrest = 0.0;
if (mc.u_foamCrest > 0.0) { onCrest = smoothstep(1.0 - 0.3 * mc.u_foamCrest, 1.0, waves.crest) * smoothstep(0.35, 0.75, breakup); }
- let surfFoam = surf.y * smoothstep(0.15, 0.6, breakup + surf.y * 0.4);
+ // A breaker whitens as much on a beach as the waves are big, but bursts whitest on rock.
+ var steepHere = 1.0;
+ if (zoneOn) { steepHere = waterZoneSteep(wp); }
+ let surfFoam = surf.y * smoothstep(0.15, 0.6, breakup + surf.y * 0.4) * mix(0.45, 1.0, steepHere);
var foam = clamp(max(max(max(shore, onCrest * mc.u_foamCrest), ripFoam * (0.55 + 0.45 * breakup)), surfFoam), 0.0, 1.0);
if (below) { foam = foam * 0.2; }
diff --git a/sdk/src/water/waves.ts b/sdk/src/water/waves.ts
index 5eb649313..85f442c93 100644
--- a/sdk/src/water/waves.ts
+++ b/sdk/src/water/waves.ts
@@ -96,7 +96,7 @@ export function waveSlope(p: WaveParams, x: number, z: number, time: number): [n
export function surfHeight(shore: number, height: number, length: number, speed: number, time: number, phase = shore): number {
if (height <= 0 || length <= 0) return 0;
const reach = length * 4;
- if (shore > reach || shore < -reach * 0.2) return 0;
+ if (shore > reach || shore < -reach * 0.05) return 0;
const celerity = Math.sqrt(GRAVITY * length / TAU) * speed;
const u = fract(phase / length + (celerity * time) / length);
// Seaward of a crest the water falls away slowly; shoreward its face is steep.
@@ -108,7 +108,7 @@ export function surfHeight(shore: number, height: number, length: number, speed:
/** How much of the surf stands at `shore`: none out past its reach, rising as the water shoals, and dying as it runs up the ground. */
export function surfEnvelope(shore: number, reach: number): number {
const shoal = 1 - smooth01((shore - reach * 0.25) / (reach * 0.75));
- const runUp = shore >= 0 ? 1 : 1 - smooth01(-shore / (reach * 0.2));
+ const runUp = shore >= 0 ? 1 : 1 - smooth01(-shore / (reach * 0.05));
return shoal * runUp;
}
diff --git a/sdk/src/water/zone.ts b/sdk/src/water/zone.ts
index 292f114fe..3a7600a84 100644
--- a/sdk/src/water/zone.ts
+++ b/sdk/src/water/zone.ts
@@ -153,6 +153,8 @@ export function currentShare(width: number, widest: number): number {
const DEEP = 1e6;
/** The gentlest slope a depth is turned into a distance by: flatter ground than this is deep water or dry land a long way from a shore. */
const MIN_SLOPE = 0.01;
+/** The slopes a shore goes from a beach (waves wash up it) to rock (they burst on it) over. */
+const STEEP_FROM = 0.25, STEEP_TO = 0.8;
/** The baked water of a zone. */
export class WaterField {
@@ -169,6 +171,8 @@ export class WaterField {
readonly surf: Float32Array;
/** How much of the surf a current leaves (see {@link FieldSample.still}). */
readonly still: Float32Array;
+ /** How steep the shore is, 0 (a gentle beach) to 1 (rock, a cliff): where waves burst white rather than wash up. */
+ readonly steep: Float32Array;
readonly exposure: Float32Array;
/** The body that owns the most of each texel, as its key; -1 where there is no water. */
readonly owner: Int32Array;
@@ -189,6 +193,7 @@ export class WaterField {
this.depth = new Float32Array(n);
this.surf = new Float32Array(n);
this.still = new Float32Array(n).fill(1);
+ this.steep = new Float32Array(n);
this.exposure = new Float32Array(n).fill(1);
this.owner = new Int32Array(n);
}
@@ -245,6 +250,7 @@ export class WaterField {
const z = grid.minZ + (j / Math.max(grid.nz - 1, 1)) * grid.sizeZ;
const g = Number.isNaN(grounds[k]!) ? null : grounds[k]!;
const slope = g === null ? MIN_SLOPE : slopeAt(i, j);
+ field.steep[k] = smooth(STEEP_FROM, STEEP_TO, slope);
let w = 0, h = 0, a = 0, c = 0, sw = 0, ex = 0, fx = 0, fz = 0, best = -Infinity, owner = -1, ownerW = 0, held = 0, lakeShore = -Infinity, riverW = 0;
// Ground below the sea's level that the open sea does not reach is a dry basin: as far above the sea as a texel.
const seaDeep = !ocean ? -DEEP : g === null ? DEEP : g < ocean.level && !sea![k] ? -texel : (ocean.level - g) / slope;
@@ -302,6 +308,9 @@ export class WaterField {
yield* levelShore(field, texel);
yield* fillDry(field);
surfDistance(field, rivers, texel, surfLength);
+ // The water beside a steep shore takes its steepness: a cliff's foot is a texel or two out in the water.
+ blur(field.steep, grid.nx, grid.nz, 2);
+ for (let k = 0; k < field.steep.length; k++) field.steep[k] = Math.min(field.steep[k]! * 2, 1);
return field;
}
@@ -363,7 +372,7 @@ export class WaterField {
/**
* The field as two RGBA8 images, rows from minZ. heights (read texel by texel: filtered bytes are no number): rg the height, high byte
* first; b the depth, as its square root (fine where the water is shallow, where the shore is drawn by it); a the swell (the body's waves' height). field (filtered): r the shore distance (0.5 at it, a signed square root); gb the current (0.5 still); a the calm.
- * exposure (filtered): r how open the water is to the wind; g the distance the surf runs in by; b how much surf a current leaves. Each over its range in `r`.
+ * exposure (filtered): r how open the water is to the wind; g the distance the surf runs in by; b how much surf a current leaves; a how steep the shore is. Each over its range in `r`.
*/
encode(r: ZoneRanges): { heights: Uint8Array; field: Uint8Array; exposure: Uint8Array } {
const n = this.height.length;
@@ -386,7 +395,7 @@ export class WaterField {
const surf = Math.max(Math.min(this.surf[k]! / r.shore, 1), -1);
exposure[k * 4 + 1] = byte(Math.sign(surf) * Math.sqrt(Math.abs(surf)) / 2 + 0.5);
exposure[k * 4 + 2] = byte(this.still[k]!);
- exposure[k * 4 + 3] = 255;
+ exposure[k * 4 + 3] = byte(this.steep[k]!);
}
return { heights, field, exposure };
}
diff --git a/sdk/tests/water-zone.test.ts b/sdk/tests/water-zone.test.ts
index f52b5d230..30e8e7de0 100644
--- a/sdk/tests/water-zone.test.ts
+++ b/sdk/tests/water-zone.test.ts
@@ -204,3 +204,15 @@ describe('the distance the surf runs in by', () => {
expect(field.sample(0, -50)!.shore).toBeGreaterThan(0);
});
});
+
+describe('how steep the shore is', () => {
+ it('is a beach where the ground shelves gently and rock where it drops away', () => {
+ // The sea to +z; west of x = 0 the ground shelves 1 in 20, east of it a cliff drops 2 in 1.
+ const g: ZoneGrid = { minX: -100, minZ: -50, sizeX: 200, sizeZ: 100, nx: 201, nz: 101 };
+ const ground = (x: number, z: number): number => (x < 0 ? -z * 0.05 : -z * 2);
+ const field = WaterField.bake(g, [{ kind: 'ocean', key: 3, level: 0, waveHeight: 2, shoreWidth: 6 }], ground, 20);
+ const at = (x: number, z: number): number => field.steep[Math.round(z - g.minZ) * g.nx + Math.round(x - g.minX)]!;
+ expect(at(-50, 2)).toBeLessThan(0.1);
+ expect(at(50, 2)).toBeGreaterThan(0.9);
+ });
+});
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 3b3a31e6e..71020d604 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -2816,4 +2816,8 @@ export const NOTED = {
{"note":"A river gives way where it runs into the sea or a lake."},
"fix(water): surf crests come in from open water as lines instead of tracing every turn of the shore":
{"note":"Surf comes in from open water as lines."},
+ "docs(water): surfHeight's comment within the prose limit":
+ {"internal":"Comment length only."},
+ "feat(water): foam bursts on steep shores and washes thinly up beaches, by how steep the shore is and how exposed the water":
+ {"note":"Foam is where waves burst, not along every shore."},
};