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.

fix(gi): the dynamic GI has no dark seam in a wall corner and a quieter picture - probes are taken from the nine nearest with a tent weight, history blend 0.15

yhh8ab01be5c539
diff --git a/docs/GI_LUMEN_DESIGN.md b/docs/GI_LUMEN_DESIGN.md
index 1f08d4616..0ac70961d 100644
--- a/docs/GI_LUMEN_DESIGN.md
+++ b/docs/GI_LUMEN_DESIGN.md
@@ -113,7 +113,7 @@
|---|---|---|
| P0 | 网格 SDF 烘焙 + `.esmeshsdf` 资源类型与加载器 + 全局距离场 clipmap + 公共 WGSL 追踪 | 球、盒、薄墙的距离和追踪与闭式解比对;WGSL 追踪由 `tools/gi/check-sdf-wgsl.mjs` 在无头 WebGPU 上校验。**已落地(2026-11-11)**:`pipeline/src/assets/meshSdf.ts`、`MeshSdfAssetLoader`、`sdk/src/gi/globalSdf.ts`;导入设置 `dynamicGI`(默认关)。**未做**:clipmap 接到渲染帧的网格实例、上传 GPU 存储缓冲、编辑器导入开关 |
| P1 | 表面缓存:card 烘焙、直接光 + 自发光、命中点取光 | 卡面亮度与 Lambert 闭式值一致,SDF 遮挡产生阴影,自发光出现在命中点取光里。**CPU 参考已落地(2026-11-11)**:`pipeline/src/assets/meshCards.ts`(`.esmeshcards`,6 个轴向 card)、`MeshCardsAssetLoader`、`sdk/src/gi/surfaceCache.ts`(`light`、`lookup`)、`pipeline/tests/surface-cache.test.ts`。**未做**:基色贴图不读(只用材质基色与顶点色)、图集分配、GPU 刷新通道 |
-| P2 | 屏幕探针 + SDF 追踪 + 时间/空间滤波,单次反弹 | `gi_leak` 为 0;`gi_room` 阴影区 0.6–1.1。**CPU 参考已落地并对 Cycles 验证(2026-11-11)**:`sdk/src/gi/screenProbes.ts`(8×8 八面体探针、半球积分、多次反弹迭代),`pipeline/tests/gi-lab.test.ts`。实测:`gi_leak` 室内最亮 0(体素 GI 为 0.005);`gi_room` 与 `gi_away` 为 Cycles 的 0.46–1.89 倍,屏幕内外一致(体素 GI 是 0.1–1.7 与 0.31–0.52)。**未做**:GPU 通道(探针追踪/插值到像素/时间滤波)、渲染帧实例接入;精度偏差(天花板 1.9、侧墙 0.5)主要来自 25 cm 的 card 和每探针 64 条光线 | **GPU 通道已落地(2026-11-11)**:`DynamicGI.cpp`(卡面光照、8×8 探针、应用三个 compute 通道)、`postprocess_setGIScene` 绑定、`dynamicGISystem.ts`(把 MeshRenderer 的内置立方体喂给 GPU)、后效 `dynamicGI`。无头 WebGPU(swiftshader)上对 Cycles 实测:`gi_leak` 室内 0;`gi_room` 阴影区 0.54–1.08(遮挡面 0.6,体素 GI 为 0.1);`gi_away` 0.54–0.86(体素 GI 为 0.31–0.52)。**随后补上(2026-11-11)**:材质 `u_emissive` 进 card(`gi_emissive` 从 0 到 Cycles 的 0.9–1.14 倍);带 `.esmeshsdf/.esmeshcards` 的网格接入(`buildInstances`,打包时由依赖扫描随网格带上,运行时按创作路径找旁文件;`gi_oracle.py --methods dgim` 用网格版房间验证,0.5–1.4 倍、`gi_leak` 为 0)。**未做**:多级 clipmap、点光/聚光、时间重投影、手机成本
+| P2 | 屏幕探针 + SDF 追踪 + 时间/空间滤波,单次反弹 | `gi_leak` 为 0;`gi_room` 阴影区 0.6–1.1。**CPU 参考已落地并对 Cycles 验证(2026-11-11)**:`sdk/src/gi/screenProbes.ts`(8×8 八面体探针、半球积分、多次反弹迭代),`pipeline/tests/gi-lab.test.ts`。实测:`gi_leak` 室内最亮 0(体素 GI 为 0.005);`gi_room` 与 `gi_away` 为 Cycles 的 0.46–1.89 倍,屏幕内外一致(体素 GI 是 0.1–1.7 与 0.31–0.52)。**未做**:GPU 通道(探针追踪/插值到像素/时间滤波)、渲染帧实例接入;精度偏差(天花板 1.9、侧墙 0.5)主要来自 25 cm 的 card 和每探针 64 条光线 | **GPU 通道已落地(2026-11-11)**:`DynamicGI.cpp`(卡面光照、8×8 探针、应用三个 compute 通道)、`postprocess_setGIScene` 绑定、`dynamicGISystem.ts`(把 MeshRenderer 的内置立方体喂给 GPU)、后效 `dynamicGI`。无头 WebGPU(swiftshader)上对 Cycles 实测:`gi_leak` 室内 0;`gi_room` 阴影区 0.54–1.08(遮挡面 0.6,体素 GI 为 0.1);`gi_away` 0.54–0.86(体素 GI 为 0.31–0.52)。**随后补上(2026-11-11)**:材质 `u_emissive` 进 card(`gi_emissive` 从 0 到 Cycles 的 0.9–1.14 倍);带 `.esmeshsdf/.esmeshcards` 的网格接入(`buildInstances`,打包时由依赖扫描随网格带上,运行时按创作路径找旁文件;`gi_oracle.py --methods dgim` 用网格版房间验证,0.5–1.4 倍、`gi_leak` 为 0)。**未做**:多级 clipmap、点光/聚光、时间重投影、手机成本 **画质(2026-11-11)**:apply 改为看周围 16 个探针(3x3 外一圈,帐篷权重 1.6 个 tile)并在邻居全不同向时去掉法线权重,墙角的黑带消失;时间混合默认 0.3→0.15,噪点明显下降;对 Cycles 的占比不变(`dgi`)。`dgim` 的红/绿通道占比不一致(例如 `gi_away` 前墙 R 0.71 G 1.29),卡面反照率已核对无误,原因未查明
| P3 | 表面缓存吃上一帧间接光(多次反弹)+ 世界辐射缓存 | `gi_room` 0.8–1.1;`gi_away` ≥ 0.8;`gi_emissive` ≥ 0.8 |
| P4 | 成本:自适应探针、光线预算、QualityConfig 档位、手机与桌面实测 | 帧时间达标;gate 内加成本断言(同阴影通道做法) |
| P5 | 编辑器:设置面板、调试视图(SDF、card、探针)、文档;`esengine/fx-gi` 分组与包体 | 编辑器检查;包体断言 |
diff --git a/sdk/src/postprocess/effects.ts b/sdk/src/postprocess/effects.ts
index e25b7f971..b452c5cb9 100644
--- a/sdk/src/postprocess/effects.ts
+++ b/sdk/src/postprocess/effects.ts
@@ -576,7 +576,7 @@ registerEffect({
// How much of the gathered light is added over the picture.
{ name: 'u_intensity', label: 'Intensity', min: 0, max: 4, step: 0.01, defaultValue: 1, neutralValue: 0 },
// How much of each frame replaces what the cards and probes held; lower is smoother and slower to follow a change.
- { name: 'u_blend', label: 'Temporal Blend', min: 0.02, max: 1, step: 0.01, defaultValue: 0.3 },
+ { name: 'u_blend', label: 'Temporal Blend', min: 0.02, max: 1, step: 0.01, defaultValue: 0.15 },
],
});
diff --git a/src/esengine/renderer/frame/DynamicGI.cpp b/src/esengine/renderer/frame/DynamicGI.cpp
index cc28fa88b..f4ef64b69 100644
--- a/src/esengine/renderer/frame/DynamicGI.cpp
+++ b/src/esengine/renderer/frame/DynamicGI.cpp
@@ -369,17 +369,19 @@ fn main(@builtin(global_invocation_id) id : vec3u) {
let pos = worldFromDepth((vec2f(p) + 0.5) / vec2f(size), depth);
if (dot(n, viewDirection(pos)) < 0.0) { n = -n; }
let tiles = vec2i(gi.counts.zw);
- // The four probes round the pixel: probe (tx, ty) stands at pixel (tx * 8 + 4, ty * 8 + 4).
+ // The probes round the pixel: probe (tx, ty) stands at pixel (tx * 8 + 4, ty * 8 + 4). The nine nearest are looked at, since in the
+ // corner of two walls the four nearest can all be on the other wall, and a probe on another plane has nothing to say about this one.
let q = (vec2f(p) - vec2f(4.0)) / 8.0;
let q0 = vec2i(floor(q));
- let f = q - vec2f(q0);
+ let eye = max(length(pos - frame.camera.xyz), 1.0);
var E = vec3f(0.0);
var total = 0.0;
- var nearestE = vec3f(0.0);
- var nearestW = -1.0;
- for (var k = 0; k < 4; k = k + 1) {
- let o = vec2i(k & 1, k >> 1);
- let tile = clamp(q0 + o, vec2i(0), tiles - vec2i(1));
+ var Erelaxed = vec3f(0.0);
+ var totalRelaxed = 0.0;
+ for (var k = 0; k < 16; k = k + 1) {
+ let o = vec2i(k & 3, k >> 2) - vec2i(1);
+ let tile = q0 + o;
+ if (any(tile < vec2i(0)) || any(tile >= tiles)) { continue; }
let pp = min(tile * 8 + vec2i(4), size - vec2i(1));
let pd = textureLoad(depthTex, pp, 0);
let pg = textureLoad(gbuffer, pp, 0);
@@ -387,20 +389,25 @@ fn main(@builtin(global_invocation_id) id : vec3u) {
let ppos = worldFromDepth((vec2f(pp) + 0.5) / vec2f(size), pd);
var pn = decodeNormal(pg);
if (dot(pn, viewDirection(ppos)) < 0.0) { pn = -pn; }
- let eye = max(length(pos - frame.camera.xyz), 1.0);
+ // A tent over a tile and a half round the pixel, so a probe two tiles away does not count.
+ let d = abs(vec2f(tile) - q);
+ let tent = max(1.0 - d.x / 1.6, 0.0) * max(1.0 - d.y / 1.6, 0.0);
+ if (tent <= 0.0) { continue; }
let plane = abs(dot(n, ppos - pos)) / (0.02 * eye);
- let bilinear = select(1.0 - f.x, f.x, o.x == 1) * select(1.0 - f.y, f.y, o.y == 1);
- let w = bilinear / (1.0 + plane * plane) * pow(max(dot(pn, n), 0.0), 8.0);
+ let wPlane = tent / (1.0 + plane * plane);
+ let wNormal = pow(max(dot(pn, n), 0.0), 4.0);
let base = vec2i(tile.x * 3, tile.y);
let vr = textureLoad(probes, base, 0).xyz;
let vg = textureLoad(probes, base + vec2i(1, 0), 0).xyz;
let vb = textureLoad(probes, base + vec2i(2, 0), 0).xyz;
let e = max(vec3f(dot(vr, n), dot(vg, n), dot(vb, n)), vec3f(0.0));
- E = E + e * w;
- total = total + w;
- if (w > nearestW) { nearestW = w; nearestE = e; }
+ E = E + e * wPlane * wNormal;
+ total = total + wPlane * wNormal;
+ // The same without the normal, for a pixel whose every neighbour faces another way.
+ Erelaxed = Erelaxed + e * wPlane;
+ totalRelaxed = totalRelaxed + wPlane;
}
- if (total > 1e-5) { E = E / total; } else { E = nearestE; }
+ if (total > 0.05) { E = E / total; } else if (totalRelaxed > 1e-5) { E = Erelaxed / totalRelaxed; } else { E = vec3f(0.0); }
textureStore(outTex, p, vec4f(scene.rgb + albedo.rgb * E * gi.sdf.w, scene.a));
}
)WGSL";
diff --git a/src/esengine/renderer/frame/DynamicGI.hpp b/src/esengine/renderer/frame/DynamicGI.hpp
index 325c3c778..408cd026d 100644
--- a/src/esengine/renderer/frame/DynamicGI.hpp
+++ b/src/esengine/renderer/frame/DynamicGI.hpp
@@ -36,7 +36,7 @@ struct DynamicGIParams {
/// How much of the gathered light is added over the picture.
f32 intensity = 1.0f;
/// How much of each frame's card lighting replaces what the card held (the rest is history, which is what smooths the noise).
- f32 blend = 0.3f;
+ f32 blend = 0.15f;
};
/**