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(terrain): a cliff's beds can wander - a layer read from the side lies by height, so its beds ran dead straight along a whole wall; Terrain Layers' u_strataWarp moves them up and down by slow noise u_strataSpan wide, and 0, the default, leaves them straight

yhhad08bc9e4b63
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b6db1c7c8..46af16453 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ published separately; it ships inside the editor.
### Added
+- **A cliff's beds can wander.** A terrain layer seen from the side is read by height, so the beds of a cliff texture lie level, and ran dead straight along a whole wall like lines on ruled paper. The Terrain Layers material's `u_strataWarp` is how far they wander up and down, by slow noise `u_strataSpan` wide. At 0, the default, they are straight as before.
- **The tonemap has the fitted ACES curve too.** The `tonemap` effect ran one curve, the engine's (Narkowicz's fit). A picture made for the other ACES fit in wide use (Hill's RRT and ODT, what three.js calls ACES Filmic) came out with shadows about a third brighter at the same mid tones, and with the hue kept in bright colours that curve sends to white. **Fitted ACES** (`u_curve` 1) runs that fit; off, which is the default, nothing changes.
- **An anchor on a waterfall.** A `Waterfall` lands wherever the ground or the water under it is, and nothing said where that was, so the mist at its foot had to be placed by hand and stayed behind when the fall moved. A child of the fall's with a `WaterfallAnchor` is kept on the middle of its path: at the foot (`at` 1), at the lip (0) or a share of the time down, `lift` above it. A `ParticleEmitter` on that child is the mist.
- **A waterfall.** A river's surface lies over the ground and stopped at the edge of a cliff with nothing after it. A `Waterfall` on an entity at the lip, facing the way the water leaves, throws sheets of water level at `speed` and lets gravity take them: each ends where it meets the ground, or water that is not the water it left, or `maxDrop` under the lip, and is made again when what is under it changes. It is the entity's own `MeshRenderer`; with no material it takes the stock Waterfall shader, glass at the lip that tears into strands and then veils, its pattern riding down with the water at the water's own speed.
diff --git a/docs/astro/src/content/docs/graphics/terrain.mdx b/docs/astro/src/content/docs/graphics/terrain.mdx
index 78253d583..f1f2a28a4 100644
--- a/docs/astro/src/content/docs/graphics/terrain.mdx
+++ b/docs/astro/src/content/docs/graphics/terrain.mdx
@@ -89,6 +89,8 @@ near the eye, with a wider tile mixed in far off; where layers meet, the one who
between stones); on a slope each is also projected from the sides, so a cliff is not stretched. The normal maps and the masks'
occlusion and roughness light it. Its material sets how: `u_sharpness`, `u_heightBlend`, `u_blendNoise`, `u_antiTile`, `u_farScale`,
`u_macroVariation`, `u_triplanarFrom` (how steep before the sides are read) and `u_wetLevel`/`u_wetBand`, as the Terrain shader's below.
+A layer seen from the side is read by height, so a cliff texture's beds lie level, and dead straight along the whole wall:
+`u_strataWarp` is how far they wander up and down, by slow noise `u_strataSpan` wide (0, the default, leaves them straight).
What an artist delivers, per layer: the three textures, square, a power of two (1024 is plenty; they are packed at the largest
layer's size, at most 1024, 512 on a minigame), tiling seamlessly, the normal and mask saved as data (not colour-managed). A layer's
diff --git a/docs/astro/src/content/docs/zh-cn/graphics/terrain.mdx b/docs/astro/src/content/docs/zh-cn/graphics/terrain.mdx
index 542294f39..00afd725a 100644
--- a/docs/astro/src/content/docs/zh-cn/graphics/terrain.mdx
+++ b/docs/astro/src/content/docs/zh-cn/graphics/terrain.mdx
@@ -66,7 +66,7 @@ description: 一个 Terrain 组件,用高度图或噪声生成地面,可以是
| `normalStrength` | 法线贴图的强度:1 为原样,0 为平坦。 |
| `heightBlend` | 可选。这一层自己的高度在与别的层相交处起多大作用:0 只按涂色混合(草到沙),1 按各层高度混合(石头从草里露出)。多层相遇时,每层按它在此处所占的比例计入。缺省则用材质的 `u_heightBlend`。 |
-地面由 **Terrain Layers** 着色器(`builtin:terrain-layers`)绘制。每一层按世界位置铺设,近处去除重复,远处混入更大的平铺;层与层交界处遮罩高度更高的一层显露(草间露出石头、石缝里填着沙);坡面上同时从侧面投影,悬崖不会被拉伸。法线贴图和遮罩的遮蔽、粗糙度参与光照。材质控制效果:`u_sharpness`、`u_heightBlend`、`u_blendNoise`、`u_antiTile`、`u_farScale`、`u_macroVariation`、`u_triplanarFrom`(多陡开始读侧面)和 `u_wetLevel`/`u_wetBand`,含义同下文 Terrain 着色器。
+地面由 **Terrain Layers** 着色器(`builtin:terrain-layers`)绘制。每一层按世界位置铺设,近处去除重复,远处混入更大的平铺;层与层交界处遮罩高度更高的一层显露(草间露出石头、石缝里填着沙);坡面上同时从侧面投影,悬崖不会被拉伸。法线贴图和遮罩的遮蔽、粗糙度参与光照。材质控制效果:`u_sharpness`、`u_heightBlend`、`u_blendNoise`、`u_antiTile`、`u_farScale`、`u_macroVariation`、`u_triplanarFrom`(多陡开始读侧面)和 `u_wetLevel`/`u_wetBand`,含义同下文 Terrain 着色器。从侧面读的层按高度取样,所以崖壁贴图的岩层是水平的,而且沿整面墙笔直:`u_strataWarp` 是岩层上下起伏的幅度,由宽度为 `u_strataSpan` 的缓慢噪声决定(默认 0,保持笔直)。
美术每层交付:三张贴图,正方形,边长为 2 的幂(1024 足够;打包时取最大一层的尺寸,最大 1024,小游戏上 512),四方连续,法线和遮罩按数据保存(不做色彩管理)。地形构建时各层贴图会打包成纹理数组,地形层文件或其贴图保存后会重新打包。
diff --git a/sdk/src/terrain/terrainShader.ts b/sdk/src/terrain/terrainShader.ts
index 7f1ebdf72..627b033db 100644
--- a/sdk/src/terrain/terrainShader.ts
+++ b/sdk/src/terrain/terrainShader.ts
@@ -543,6 +543,10 @@ const TERRAIN_LAYERS = `#pragma shader "Terrain Layers"
#pragma param u_macroVariation float default(0.25) range(0,1) ui(slider)
// How steep the ground must be (1 minus its normal's up) before the layers are also projected from the sides.
#pragma param u_triplanarFrom float default(0.15) range(0,1) ui(slider)
+// A layer seen from the side is read by height, so its beds lie level and dead straight. u_strataWarp is how far they wander up and
+// down along a wall, by slow noise u_strataSpan wide; 0 leaves them straight.
+#pragma param u_strataWarp float default(0) range(0,100000) ui(slider) unit(length)
+#pragma param u_strataSpan float default(4000) range(1,10000000) ui(slider) unit(length)
// Ground at the water: below u_wetLevel + u_wetBand (world heights) it darkens and shines, most at the waterline. A band of 0 draws none.
#pragma param u_wetLevel float default(0) range(-100000,100000) ui(slider) unit(length)
#pragma param u_wetBand float default(0) range(0,100000) ui(slider) unit(length)
@@ -709,6 +713,8 @@ void main() {
axis /= dot(axis, vec3(1.0));
float side = smoothstep(u_triplanarFrom, u_triplanarFrom + 0.15, 1.0 - abs(N.y));
vec3 planes = mix(vec3(0.0, 1.0, 0.0), axis, side);
+ float bedY = Pw.y;
+ if (u_strataWarp > 0.0) bedY += (tnNoise(Pw.xz / u_strataSpan + 41.0) * 0.65 + tnNoise(Pw.xz / (u_strataSpan * 0.31) + 7.0) * 0.35 - 0.5) * 2.0 * u_strataWarp;
vec3 albedo[8];
vec3 bend[8];
@@ -731,12 +737,12 @@ void main() {
mask[i] = top.mask * planes.y;
bend[i] = tnBend(top.slope, vec3(1.0, 0.0, 0.0), vec3(0.0, 0.0, 1.0), N) * planes.y;
if (planes.x > 0.02) {
- TnTap x = tnPlain(Pw.zy / tile, layer, dpx.zy / tile, dpy.zy / tile);
+ TnTap x = tnPlain(vec2(Pw.z, bedY) / tile, layer, dpx.zy / tile, dpy.zy / tile);
albedo[i] += x.albedo * planes.x; mask[i] += x.mask * planes.x;
bend[i] += tnBend(x.slope, vec3(0.0, 0.0, 1.0), vec3(0.0, 1.0, 0.0), N) * planes.x;
}
if (planes.z > 0.02) {
- TnTap z = tnPlain(Pw.xy / tile, layer, dpx.xy / tile, dpy.xy / tile);
+ TnTap z = tnPlain(vec2(Pw.x, bedY) / tile, layer, dpx.xy / tile, dpy.xy / tile);
albedo[i] += z.albedo * planes.z; mask[i] += z.mask * planes.z;
bend[i] += tnBend(z.slope, vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), N) * planes.z;
}
@@ -927,6 +933,8 @@ fn packNormal(n : vec3f) -> vec2f {
axis = axis / dot(axis, vec3f(1.0));
let side = smoothstep(mc.u_triplanarFrom, mc.u_triplanarFrom + 0.15, 1.0 - abs(N.y));
let planes = mix(vec3f(0.0, 1.0, 0.0), axis, vec3f(side));
+ var bedY = Pw.y;
+ if (mc.u_strataWarp > 0.0) { bedY = bedY + (tnNoise(Pw.xz / mc.u_strataSpan + vec2f(41.0)) * 0.65 + tnNoise(Pw.xz / (mc.u_strataSpan * 0.31) + vec2f(7.0)) * 0.35 - 0.5) * 2.0 * mc.u_strataWarp; }
var albedo : array<vec3f, 8>;
var bend : array<vec3f, 8>;
@@ -950,13 +958,13 @@ fn packNormal(n : vec3f) -> vec2f {
mask[i] = top.mask * planes.y;
bend[i] = tnBend(top.slope, vec3f(1.0, 0.0, 0.0), vec3f(0.0, 0.0, 1.0), N) * planes.y;
if (planes.x > 0.02) {
- let x = tnPlain(Pw.zy / tile, i, dpx.zy / tile, dpy.zy / tile);
+ let x = tnPlain(vec2f(Pw.z, bedY) / tile, i, dpx.zy / tile, dpy.zy / tile);
albedo[i] = albedo[i] + x.albedo * planes.x;
mask[i] = mask[i] + x.mask * planes.x;
bend[i] = bend[i] + tnBend(x.slope, vec3f(0.0, 0.0, 1.0), vec3f(0.0, 1.0, 0.0), N) * planes.x;
}
if (planes.z > 0.02) {
- let z = tnPlain(Pw.xy / tile, i, dpx.xy / tile, dpy.xy / tile);
+ let z = tnPlain(vec2f(Pw.x, bedY) / tile, i, dpx.xy / tile, dpy.xy / tile);
albedo[i] = albedo[i] + z.albedo * planes.z;
mask[i] = mask[i] + z.mask * planes.z;
bend[i] = bend[i] + tnBend(z.slope, vec3f(1.0, 0.0, 0.0), vec3f(0.0, 1.0, 0.0), N) * planes.z;
diff --git a/sdk/tests/area-map-rows.test.ts b/sdk/tests/area-map-rows.test.ts
index ddb2db58d..7da8bb9bd 100644
--- a/sdk/tests/area-map-rows.test.ts
+++ b/sdk/tests/area-map-rows.test.ts
@@ -27,4 +27,16 @@ describe('the rows of an image over an area', () => {
}
}
});
+
+ it('a layer read from the side takes its height through the strata warp, in both languages, and the warp is off by default', () => {
+ const source = TERRAIN_LAYERS_SHADER_TEMPLATE.source;
+ expect(source).toContain('#pragma param u_strataWarp float default(0)');
+ for (const read of ['tnPlain(vec2(Pw.z, bedY) / tile', 'tnPlain(vec2(Pw.x, bedY) / tile', 'tnPlain(vec2f(Pw.z, bedY) / tile', 'tnPlain(vec2f(Pw.x, bedY) / tile']) {
+ expect(source).toContain(read);
+ }
+ expect(source).not.toContain('tnPlain(Pw.zy');
+ expect(source).not.toContain('tnPlain(Pw.xy');
+ expect(source).toContain('if (u_strataWarp > 0.0) bedY +=');
+ expect(source).toContain('if (mc.u_strataWarp > 0.0) { bedY = bedY +');
+ });
});
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index cef41ac49..e9fe1d4a6 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -4578,6 +4578,8 @@ export const NOTED = {
{"note": "An anchor on a waterfall."},
"feat(post): the tonemap has the fitted ACES curve too - Tonemap's Fitted ACES (u_curve 1) runs Hill's fit of the RRT and ODT, the one three.js calls ACES Filmic, in place of the engine's curve: a picture made for it was a third brighter in its shadows and kept colours it sends to white":
{"note": "The tonemap has the fitted ACES curve too."},
+ "feat(terrain): a cliff's beds can wander - a layer read from the side lies by height, so its beds ran dead straight along a whole wall; Terrain Layers' u_strataWarp moves them up and down by slow noise u_strataSpan wide, and 0, the default, leaves them straight":
+ {"note": "A cliff's beds can wander."},
"fix(terrain): a detail the pages cannot hold no longer cracks the ground - a tree that wanted more nodes than the atlas has pages was drawn in part by coarser pages standing in, which do not meet their finer neighbours' edges, and the pages were fought over every frame; the ground is now drawn at the share of its detail's range that fits, and says so once":
{"note": "A detail the pages cannot hold no longer cracks the ground."},
"fix(foliage): a far plant grows across the ground, not taller - a mesh plant kept in a far version was grown the same every way to cover the ground of those left out, so a flower that stood for ten stood ten times as high and a far meadow was a field of poles; it now grows across the ground only, and Foliage.farGrowUp gives its height a share of the growth back":