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
test(gi): spot lights on the GPU - a spot lab held to the CPU reference in the cone, the penumbra and out of it
yhh0a7fded18d55
diff --git a/docs/GI_LUMEN_DESIGN.md b/docs/GI_LUMEN_DESIGN.mdindex de52a64a4..42b93263c 100644--- a/docs/GI_LUMEN_DESIGN.md+++ b/docs/GI_LUMEN_DESIGN.md@@ -132,7 +132,8 @@对 Cycles(`dgil`:2.5 cm 细格,房间的后半部分只在粗级里):`gi_room` 0.55–1.25、`gi_away` 0.51–0.87、`gi_leak` 室内 0,与单窗口一致。- **点光和聚光**:场景里最近相机的至多 8 盏,按引擎自己的衰减(`distanceFalloff`:线性斜坡、反平方、内径,聚光的 smoothstep 锥)给卡面直接光,阴影也是穿过距离场的射线,到灯为止。CPU 参考在 `surfaceCache.ts`(`PointLight`),对闭式值有 5 个测试;GPU 在 `lightsDirect`。验证:`gi_point` 实验室(密闭房间,一盏 0.3 强度的灯)。Cycles 的点光是反平方的瓦特,单位对不上,所以参照是 CPU 求解器(与 Cycles 对过太阳的那个)。GPU 对 CPU 参照 0.89–1.06;`dgim`(网格版)和 `dgil`(多级)同样通过。-- **没测**:聚光在 GPU 上(只有 CPU 单元测试)、点光阴影在大场景、多级场相机移动时的重建与上传成本、手机。+- **聚光 GPU 已验证(2026-11-11,`gi_spot` 实验室)**:房间里一盏朝下的聚光(内角 25°、外角 50°,强度 0.5,线性衰减到 600),对 CPU 参照:锥内地面 0.99、半影 1.02、锥外(只有反弹)0.80–0.89,墙 1.2;网格版与多级版同样通过。注意半影区梯度陡,CPU 参照取的是 25 cm 的卡面像素,所以半影点选在卡面像素中心(x=98),不然读到的是两种采样的差而不是聚光。+- **没测**:点光阴影在大场景、多级场相机移动时的重建与上传成本、手机。- 帧时间:720p 约 3.6–3.8 ms(多级与一盏灯),比单窗口无灯多约 0.3 ms。## 5.3 手机实测(2026-11-11,小米 24129PN74C,骁龙 8 Elite,2530×1200,原生 Dawn)diff --git a/pipeline/tests/gi-lab.test.ts b/pipeline/tests/gi-lab.test.tsindex 0c7e8bf84..29db4a8ba 100644--- a/pipeline/tests/gi-lab.test.ts+++ b/pipeline/tests/gi-lab.test.ts@@ -148,4 +148,25 @@ describe('the dynamic GI over the render lab rooms', () => {}if (process.env.WRITE_REF) writeFileSync(path.resolve(import.meta.dirname, '../../tools/render-lab/gi_point_reference.json'), JSON.stringify({ source: 'the CPU solver of pipeline/tests/gi-lab.test.ts (distance field + surface cache + probes, 5 bounces), linear radiance at each region', regions: out }, null, 1));}, 300000);++ it('lights the room of gi_spot by a spot aimed down: the CPU reference for the cone', () => {+ // tools/render-lab/gi_specs.py: at (0, 250, 50), aimed straight down, 25 degrees inner and 50 outer (full angles), intensity 0.5, linear falloff to 600.+ const half = (deg: number) => Math.cos((deg * Math.PI) / 360);+ const spot: PointLight = { position: [0, 250, 50], radiance: [0.5, 0.5, 0.5], reach: 600, innerRadius: 0, falloff: 1, spot: { axis: [0, -1, 0], innerCos: half(25), outerCos: half(50) } };+ const { cache } = solve(room(), null, 5, 0, [spot]);+ const rows: Array<[string, [number, number, number], [number, number, number]]> = [+ ['floor, in the cone', [0, 1, 50], [0, 1, 0]], ['floor, penumbra', [98, 1, 50], [0, 1, 0]], ['floor, out of the cone', [170, 1, 50], [0, 1, 0]],+ ['back wall', [0, 150, 249], [0, 0, -1]], ['red wall', [199, 150, 50], [-1, 0, 0]], ['ceiling', [0, 299, 50], [0, -1, 0]],+ ];+ const out: Record<string, number[]> = {};+ for (const [name, p, n] of rows) {+ const e = share(cache, p, n, [1, 1, 1]).e;+ out[name] = e;+ console.log(`gi_spot ${name.padEnd(24)} ${e.map((v) => v.toFixed(3)).join(' ')}`);+ expect(Math.max(...e)).toBeGreaterThan(0.005);+ }+ // The cone is the point: the floor in it is far brighter than the floor out of it, which only bounce reaches.+ expect(out['floor, in the cone']![1]!).toBeGreaterThan(4 * out['floor, out of the cone']![1]!);+ if (process.env.WRITE_REF) writeFileSync(path.resolve(import.meta.dirname, '../../tools/render-lab/gi_spot_reference.json'), JSON.stringify({ source: 'the CPU solver of pipeline/tests/gi-lab.test.ts (distance field + surface cache + probes, 5 bounces), linear radiance at each region', regions: out }, null, 1));+ }, 300000);});diff --git a/tools/render-lab/gi_oracle.py b/tools/render-lab/gi_oracle.pyindex e2c542217..3c9571fa4 100644--- a/tools/render-lab/gi_oracle.py+++ b/tools/render-lab/gi_oracle.py@@ -59,6 +59,9 @@ BANDS = {('gi_away', 'dgil'): (0.45, 1.30),('gi_leak', 'dgil'): ('zero', 0.0005),('gi_point', 'dgil'): (0.7, 1.4),+ ('gi_spot', 'dgi'): (0.75, 1.3),+ ('gi_spot', 'dgim'): (0.7, 1.6),+ ('gi_spot', 'dgil'): (0.7, 1.4),('gi_emissive', 'dgim'): (0.75, 1.50),}# Wrong today, on purpose written down: the lightmap baker has no notion of an emissive surface (tools/lightmap-wasm/kernel.cpp carries albedo@@ -73,7 +76,7 @@ KNOWN_GAP = {# A lab with no Cycles picture (a lamp) is for the methods that light from the scene's own lights.-ONLY = {'gi_point': ['dgi', 'dgim', 'dgil']}+ONLY = {'gi_point': ['dgi', 'dgim', 'dgil'], 'gi_spot': ['dgi', 'dgim', 'dgil']}def lin(img):diff --git a/tools/render-lab/gi_project.py b/tools/render-lab/gi_project.pyindex 9594b1723..5d68dc7b8 100644--- a/tools/render-lab/gi_project.py+++ b/tools/render-lab/gi_project.py@@ -61,6 +61,15 @@ if spec.get('point'):{'type': 'Light', 'data': {'type': 0, 'color': {'r': 1, 'g': 1, 'b': 1, 'a': 1}, 'intensity': pt['intensity'], 'radius': pt['radius'],'innerRadius': 0.0, 'falloff': 1.0, 'inverseSquare': False, 'enabled': True, 'meshShadows': True, 'shadowStrength': 1.0}}]})+if spec.get('spot'):+ sp = spec['spot']+ # Aimed down: the rotation of -45 degrees about X takes the light's forward (-Z) to -Y.+ entities.append({'id': 8, 'name': 'Spot', 'parent': None, 'children': [], 'visible': True, 'components': [+ {'type': 'Transform', 'data': {'position': {'x': sp['pos'][0], 'y': sp['pos'][1], 'z': sp['pos'][2]}, 'rotation': {'w': 0.70710678, 'x': -0.70710678, 'y': 0.0, 'z': 0.0}}},+ {'type': 'Light', 'data': {'type': 3, 'color': {'r': 1, 'g': 1, 'b': 1, 'a': 1}, 'intensity': sp['intensity'], 'radius': sp['radius'],+ 'innerRadius': 0.0, 'falloff': 1.0, 'inverseSquare': False, 'innerAngle': sp['inner'], 'outerAngle': sp['outer'],+ 'enabled': True, 'meshShadows': True, 'shadowStrength': 1.0}}]})+if spec['sun']:sw, sx, sy, sz = L.sun_quaternion(spec['sun']['dir'])entities.append({'id': 5, 'name': 'Sun', 'parent': None, 'children': [], 'visible': True, 'components': [diff --git a/tools/render-lab/gi_reference.json b/tools/render-lab/gi_reference.jsonindex 49b733861..9ecf0be2c 100644--- a/tools/render-lab/gi_reference.json+++ b/tools/render-lab/gi_reference.json@@ -150,9 +150,42 @@0.2366098314523697,0.17272616922855377]+ },+ "gi_spot": {+ "floor, in the cone": [+ 0.2844533324241638,+ 0.27987661957740784,+ 0.278847336769104+ ],+ "floor, penumbra": [+ 0.07574715465307236,+ 0.07048594206571579,+ 0.06914962828159332+ ],+ "floor, out of the cone": [+ 0.021014686673879623,+ 0.012942289933562279,+ 0.011831202544271946+ ],+ "back wall": [+ 0.019766028970479965,+ 0.01717907376587391,+ 0.01577451452612877+ ],+ "red wall": [+ 0.020654188469052315,+ 0.0045111351646482944,+ 0.0033426841255277395+ ],+ "ceiling": [+ 0.03363505005836487,+ 0.030868973582983017,+ 0.029185950756072998+ ]}},"sources": {- "gi_point": "the CPU solver of pipeline/tests/gi-lab.test.ts (distance field + surface cache + probes, 5 bounces), linear radiance at each region"+ "gi_point": "the CPU solver of pipeline/tests/gi-lab.test.ts (distance field + surface cache + probes, 5 bounces), linear radiance at each region",+ "gi_spot": "the CPU solver of pipeline/tests/gi-lab.test.ts (distance field + surface cache + probes, 5 bounces), linear radiance at each region"}}\ No newline at end of filediff --git a/tools/render-lab/gi_specs.py b/tools/render-lab/gi_specs.pyindex 713b40633..2d5cadac0 100644--- a/tools/render-lab/gi_specs.py+++ b/tools/render-lab/gi_specs.py@@ -71,6 +71,9 @@ GI = {# The room closed and lit by one lamp inside it (linear falloff to its radius): the engine lights what the lamp reaches, and the GI adds what those# surfaces bounce. No Cycles reference (its point lights are inverse-square watts); the reference is the CPU solver the GI is held to, tools/render-lab/gi_point_reference.json.'gi_point': dict(cam=CAM_IN, boxes=room(), sun=None, point=dict(pos=(0.0, 200.0, 50.0), intensity=0.3, radius=600.0)),+ # The same room lit by a spot aimed straight down from 2.5 m (a 25 degree cone, falling off to 50): the floor under it in the light, in the penumbra and out of it, and+ # the rest by what the floor bounces. The reference is the CPU solver (tools/render-lab/gi_spot_reference.json), as for the lamp.+ 'gi_spot': dict(cam=CAM_IN, boxes=room(), sun=None, spot=dict(pos=(0.0, 250.0, 50.0), intensity=0.5, radius=600.0, inner=25.0, outer=50.0)),'gi_emissive': dict(cam=CAM_IN, boxes=room(emissive=dict(centre=(0.0, 150.0, 248.0), size=(120.0, 70.0, 4.0))), sun=None, emission=4.0),}@@ -94,6 +97,10 @@ REGIONS = {('ceiling', (0.0, 299.0, 50.0)), ('red wall', (199.0, 150.0, 50.0)), ('green wall', (-199.0, 150.0, 50.0)),('back wall', (0.0, 150.0, 249.0)), ('floor', (0.0, 1.0, 50.0)), ('block, lit side', (-90.0, 50.0, 29.0)),],+ 'gi_spot': [+ ('floor, in the cone', (0.0, 1.0, 50.0)), ('floor, penumbra', (98.0, 1.0, 50.0)), ('floor, out of the cone', (170.0, 1.0, 50.0)),+ ('back wall', (0.0, 150.0, 249.0)), ('red wall', (199.0, 150.0, 50.0)), ('ceiling', (0.0, 299.0, 50.0)),+ ],'gi_emissive': [('panel (emitter)', (0.0, 150.0, 246.0)), ('ceiling', (0.0, 299.0, 150.0)), ('red wall', (199.0, 120.0, 150.0)),('green wall', (-199.0, 120.0, 150.0)), ('floor', (60.0, 1.0, 150.0)), ('block, top', (-90.0, 100.5, 80.0)),diff --git a/tools/render-lab/gi_spot_reference.json b/tools/render-lab/gi_spot_reference.jsonnew file mode 100644index 000000000..1a8bb4df5--- /dev/null+++ b/tools/render-lab/gi_spot_reference.json@@ -0,0 +1,35 @@+{+ "source": "the CPU solver of pipeline/tests/gi-lab.test.ts (distance field + surface cache + probes, 5 bounces), linear radiance at each region",+ "regions": {+ "floor, in the cone": [+ 0.2844533324241638,+ 0.27987661957740784,+ 0.278847336769104+ ],+ "floor, penumbra": [+ 0.07574715465307236,+ 0.07048594206571579,+ 0.06914962828159332+ ],+ "floor, out of the cone": [+ 0.021014686673879623,+ 0.012942289933562279,+ 0.011831202544271946+ ],+ "back wall": [+ 0.019766028970479965,+ 0.01717907376587391,+ 0.01577451452612877+ ],+ "red wall": [+ 0.020654188469052315,+ 0.0045111351646482944,+ 0.0033426841255277395+ ],+ "ceiling": [+ 0.03363505005836487,+ 0.030868973582983017,+ 0.029185950756072998+ ]+ }+}\ No newline at end of file