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.

tools(perf): what 4x multisampling and FXAA cost the Terrain & Water example after the prepass

yhhdb81d9bf73fc
diff --git a/docs/TERRAIN_WATER_GPU_COST.md b/docs/TERRAIN_WATER_GPU_COST.md
index 7da2ef1d5..84e5bf27f 100644
--- a/docs/TERRAIN_WATER_GPU_COST.md
+++ b/docs/TERRAIN_WATER_GPU_COST.md
@@ -171,3 +171,22 @@
和地形不参加时(上一节)比,差别在机器的波动里:地形自己几乎没有过度绘制,所以它参加与否对速度没有可见影响;这一步的意义是:任何带顶点钩子的不透明材质(风吹的植被、被弯曲的网格)现在都能参加预通道,且深度是对的。
镂空且带顶点钩子的材质仍不参加(它的覆盖率程序只为 `Model` 着色器写)。
+
+## 多重采样与 FXAA(2026-10-26,预通道之后)
+
+先量,没有改引擎。同一个包,`quality` 档位 high 的配置里只改 `msaaSamples` / `skipEffects`;每个机位 5 组 12 帧,基准取两次平均。
+
+| 机位 | 基准 ms | MSAA 2× | MSAA 1× | 去掉 FXAA | MSAA 1× 去掉 FXAA | MSAA 4× 去掉 FXAA |
+|---|---|---|---|---|---|---|
+| 默认 | 30.4 | −4.1 | −5.0 | −1.0 | −5.1 | +0.1 |
+| 花海 | 41.8 | −2.8 | −7.2 | +0.5 | −6.4 | +1.6 |
+| 湖边 | 47.6 | −3.3 | −8.4 | −0.1 | −8.5 | +1.2 |
+
+- **FXAA 的成本在噪声里**(−1.0 到 +0.5 ms,同一个包两次基准就差 1 到 3 ms)。和 4× MSAA 重复是画面上的事(两遍抗锯齿),不是帧耗时的事,所以没有为它改任何东西。
+- **4× MSAA 在预通道之后仍是 5.0、7.2、8.4 ms(帧的 16% 到 18%)**;2× 只拿回其中一半或更少(4.1、2.8、3.3)。
+- **花在场景那一遍,不在解析和后处理:**把后处理体积整个拿掉后 4× 与 1× 的差还在(默认机位 17.4 对 12.8,花海 31.3 对 21.9),带着后处理时差是 5.4 与 7.7。解析(深度加颜色)加起来不会超过拿掉阴影后剩下的差:默认机位 0.7 ms,花海 3.8 ms。
+- **和接收阴影的片元绑在一起:**拿掉阴影,默认机位 4× 与 1× 只差 0.7 ms(有阴影时 5.4)。镂空的叶片卡片在边缘上被更多的像素碰到,多重采样下每个被碰到的像素都要着色一次,每次都付一遍阴影接收;采样数增加的是着色次数,不是每次着色的价格。
+- **软阴影的搜索不是杠杆:**把太阳的 `sourceAngle` 设为 0(硬边,九个采样)并没有更便宜(32.5 对 30.8,42.4 对 40.1 ms),4× 与 1× 的差仍有 5.2 与 6.6 ms。所以让远处的片元改走硬边路径,或者再减采样数,在这里没有收益。
+- 这个场景的后处理链没有任何效果会要求场景写第二个表面附件(`ssr`、`ssgi`、`rain` 才会),所以多重采样的第二个附件不在这笔账里。
+
+**结论:**MSAA 的剩余成本是画面质量与着色次数的交换,引擎里没有一处可以不改画面就省下来的浪费。能做的是档位的选择:要这部分时间就用 2×(medium 已经是 2×,省 3 到 4 ms)或 1× 加 FXAA(省 5 到 8 ms,边缘质量不同,需要有人看);要省着色次数而不省采样,方向是让每次着色更便宜(例如镂空卡片的接收阴影),不是动 MSAA。
diff --git a/tools/terrain-water-cost.mjs b/tools/terrain-water-cost.mjs
index 41ddb3daa..98e00e501 100644
--- a/tools/terrain-water-cost.mjs
+++ b/tools/terrain-water-cost.mjs
@@ -104,6 +104,15 @@ const VARIANTS = [
// Quality knobs, one at a time from high
{ id: 'no-prepass', label: 'no depth prepass (what the example drew before it)', config: quality('high', { depthPrepass: false }) },
{ id: 'msaa-1', label: 'no multisampling', config: quality('high', { msaaSamples: 1 }) },
+ { id: 'nopost-msaa-4', label: 'no post volume, msaa 4x', scene: (d) => { volume(d).effects = []; } },
+ { id: 'nopost-msaa-1', label: 'no post volume, no multisampling', scene: (d) => { volume(d).effects = []; }, config: quality('high', { msaaSamples: 1 }) },
+ { id: 'noshadow-msaa-4', label: 'no shadows, msaa 4x', scene: (d) => { for (const l of comp(d, 'Light')) l.data.meshShadows = false; } },
+ { id: 'noshadow-msaa-1', label: 'no shadows, no multisampling', scene: (d) => { for (const l of comp(d, 'Light')) l.data.meshShadows = false; }, config: quality('high', { msaaSamples: 1 }) },
+ { id: 'hard-shadow-msaa-4', label: 'a sun with no size (a hard edge, nine taps), msaa 4x', scene: (d) => { for (const l of comp(d, 'Light')) l.data.sourceAngle = 0; } },
+ { id: 'hard-shadow-msaa-1', label: 'a sun with no size, no multisampling', scene: (d) => { for (const l of comp(d, 'Light')) l.data.sourceAngle = 0; }, config: quality('high', { msaaSamples: 1 }) },
+ { id: 'msaa-1-nofxaa', label: 'no multisampling, no fxaa', config: quality('high', { msaaSamples: 1, skipEffects: ['fxaa'] }) },
+ { id: 'msaa-2-nofxaa', label: 'msaa 2x, no fxaa', config: quality('high', { msaaSamples: 2, skipEffects: ['fxaa'] }) },
+ { id: 'msaa-4-nofxaa', label: 'msaa 4x, no fxaa', config: quality('high', { skipEffects: ['fxaa'] }) },
{ id: 'msaa-2', label: 'msaa 2x', config: quality('high', { msaaSamples: 2 }) },
{ id: 'cascades-2', label: 'two shadow cascades', config: quality('high', { shadowCascades: 2 }) },
{ id: 'atlas-2048', label: 'shadow atlas 2048', config: quality('high', { shadowAtlasSize: 2048, shadowCellSize: 512 }) },