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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
tools(perf): what the water costs the Terrain & Water example, with its world generation left alone
yhhb46d878f0cfc
diff --git a/docs/TERRAIN_WATER_GPU_COST.md b/docs/TERRAIN_WATER_GPU_COST.mdindex 140a624d1..a4ab63976 100644--- a/docs/TERRAIN_WATER_GPU_COST.md+++ b/docs/TERRAIN_WATER_GPU_COST.md@@ -57,7 +57,7 @@## 没量到或有牵连的-- **水没有单独量出来。**拿掉水体时植物也消失大半(绘制数 610 → 50),因为世界生成读了水的数据,所以“无水”那行混着植物。要量水,得在不改世界生成的前提下把水藏起来。+- **水在第一轮没有单独量出来**(拿掉水体时植物也消失大半),后来量了,见最后一节。- WebGPU 没量;一块显卡,一个分辨率。- 在“湖与河口”机位拿掉水体,页面崩溃(`Target crashed`),重试同样崩;默认机位的同一变体第一次跑也崩过一次,重跑正常。没有查原因。- `tools/terrain-water-cost.mjs` 把导出目录里的场景与配置改写后在退出时还原;原始数据在 `output/perf/`(被忽略,不入库)。@@ -216,3 +216,23 @@加上前面的结果(把太阳设成没有大小、走 9 个采样的硬边路径并不更便宜):**这个函数的成本不随采样数线性走**,少读几个采样不是杠杆;所以镂空叶片的每次着色在阴影接收上没有可以不改画面就拿走的东西。要再省,方向只剩着色次数(多重采样和镂空卡片的边缘像素)和阴影本身的范围(`shadowDistance`、级联数)。另:构建会重新生成并被 git 跟踪的 `ShaderEmbeds.generated.hpp`,预通道那次提交没有带上它的更新(原生构建读它),这次补上。++## 水(2026-10-26)++**怎么在不动世界生成的前提下量水:**拿掉水体、或者把水体设成不可见,植物都会跟着消失(绘制数 610 → 50):世界生成每次读的是活着的水体。所以不碰实体,把 `WaterZone.rings` 设为 0:水面的网格环没有了(截图里海床干着,植物、木箱、地形都在,网格数不变),水体和水场还在。变体 `water-norings`。++| 机位 | 基准 ms | 去掉水面 | 占帧 |+|---|---|---|---|+| 默认 | 29.1 | −3.5 | 12% |+| 花海 | 41.2 | −2.3 | 6% |+| 湖边 | 42.3 | −1.0 | 2% |+| 湖与河口 | 43.0 | −1.3 | 3% |+| 沿河 | 37.2 | −5.2 | 14% |++这个数里还含着水面带来的整帧开销:水折射要看见身后的画面,场景得分成两遍画,中间拷一份颜色(和深度)。++**水的质量档位没有一个动得了它**(`waterDisplacement`、`waterCaustics`、`waterMirror`、`waterRippleCells`、`waterWaves`,相对基准都在 −1.2 到 +1.5 ms 之间,同一个包两次基准就差 1 到 3 ms):在这些机位上它们要么作用在水下(镜面、焦散),要么作用在顶点上(位移、波数、涟漪),而成本在像素和那次分遍。++多重采样关掉后水的成本:默认机位 3.0 → 2.4,沿河 3.1 → 6.1(这一组的基准漂得厉害,不下结论)。++**结论:不值得现在优化。**水一共 1 到 5 ms(平均 2.7),是这个示例里最小的一块(植物 22 到 68,阴影 12 到 38,多重采样 5 到 8),而且没有一个现成的旋钮可以动它。真要动,杠杆只有两个,都得先单独量:折射用的场景拷贝(缩小分辨率或只拷水面范围),和水面片元里的反射步进(20 步)。diff --git a/tools/terrain-water-cost.mjs b/tools/terrain-water-cost.mjsindex 98e00e501..7582db868 100644--- a/tools/terrain-water-cost.mjs+++ b/tools/terrain-water-cost.mjs@@ -75,6 +75,9 @@ const VARIANTS = [// Whole families{ id: 'no-post', label: 'no post-process volume at all', scene: (d) => { volume(d).effects = []; } },{ id: 'no-water', label: 'no water (zone, bodies, crates)', scene: dropEntities(...WATER) },+ // The water's surface drawn by nothing, its bodies and field left as they are: the plants read those, so they stay (a hidden or removed body takes them with it).+ { id: 'water-norings', label: 'the water surface has no mesh rings (bodies and field stay)', scene: (d) => { for (const z of comp(d, 'WaterZone')) z.data.rings = 0; } },+ { id: 'water-norings-msaa-1', label: 'no water surface, no multisampling', scene: (d) => { for (const z of comp(d, 'WaterZone')) z.data.rings = 0; }, config: quality('high', { msaaSamples: 1 }) },{ id: 'no-plants', label: 'no plants (world generation)', scene: dropEntities(...PLANTS) },{ id: 'no-terrain', label: 'no terrain (and no plants on it)', scene: dropEntities('Ground', ...PLANTS) },{ id: 'no-shadows', label: 'the sun casts no shadow', scene: (d) => { for (const l of comp(d, 'Light')) l.data.meshShadows = false; } },