3D engine that AI agents drive
Find why the river read bright: the Cycles river shared a plane with the ground (part of #232)
Nguyen Xuan Anfa2bd8e9e683
diff --git a/bench/reference/README.md b/bench/reference/README.mdindex fc3396b9..cd4659e4 100644--- a/bench/reference/README.md+++ b/bench/reference/README.md@@ -901,3 +901,28 @@ Issue #231 inferred that surfaces between the towers get the whole sky in 67js wRow bands of 60 rows, 67js over Cycles with the sun off: 0.99, 0.98, 0.96, 0.94, 0.92, 0.90 down to row 360, then 1.55, 3.31 and 3.65 over the river. Full light gives the same bottom bands (1.75, 3.13, 3.37).The towers and the quay are slightly darker in 67js than in Cycles with only the sky, not brighter, so the canyon walls and the street do not get too much sky light. The river is 3 to 4 times brighter, but taking all the sky's diffuse light away (`--ambient 0`) removes only 0.007 to 0.010 of an excess of 0.021 to 0.037, so 67js stays 2.6 to 2.8 times over Cycles with no ambient at all. Even a perfect occlusion of the sky light in the river could close about a third of the gap, and the walls give no sign that the occlusion is missing. The rest comes from what the water draws besides diffuse sky: the reflection of the lit windows and the lamps (`src/water-reflection.js`), which is the part #195 works on. No sky visibility grid was built.++Correction to the table above: the sun was never on in `megacity-dusk-a` (`keyColor` is 0, 0, 0 in `grand-scenes.js`), so `--key 0` and `--sun-strength 0` change nothing there. The two Cycles arrays are the same render and the 67js `--key 0` image equals the full one pixel for pixel. The "sky only" numbers above are the plain comparison, and the sky was the only light all along.++## The Cycles river was dark, not the 67js river bright (2026-11-03, issue #232)++The cause of the bright river and street bands is measured, and it is on the reference side. In `grand-scenes.js` the `river` box (centre y -1.2, height 1.4) and the `city-ground` box (centre y -1.5, height 2) both have their top at y = -0.5. Two surfaces in one plane: Cycles picks one of them at random per ray, so part of the rays that should mirror the sky and the towers hit the dark ground instead. `megacity-dusk-b` has the same pair for its bay. 67js draws the same scene without that noise.++Mean linear luminance over the river of `megacity-dusk-a` (960 x 540, GPU, no sun, river middle rows 420 to 540 and columns 280 to 680, sides rows 400 to 540 and columns 0 to 280):++| Render | River, middle | River, sides |+| --- | --- | --- |+| Cycles, as it was (coplanar) | 0.0130 | 0.0212 |+| Cycles, river 1 cm higher | 0.0385 | 0.0584 |+| 67js, shipped (reflection and sky specular) | 0.0317 | 0.0476 |++One term at a time in 67js (river middle, linear): reflection gain 0 gives 0.0032 (the diffuse sky light on the body colour and nothing else); gain 0 and body colour 0 gives 0.0000; reflection on with body colour 0 gives 0.0285; reflection off with body colour 0 (only the sky's specular) gives 0.0224; reflection off with body colour 0.02, 0.05, 0.08 gives 0.0256; with `--ambient 0` as well the reflection alone gives 0.0248 and with the reflection off the river is 0.0000, so there is no emission, no sun and no direct term on the water. The 67js river is the reflection weighted by Fresnel and nothing else. In the middle band 67js equals the exact Fresnel for IOR 1.5 times the picture at the mirrored row to within 3 percent (row 430: 0.0363 against 0.0351; row 538: 0.0124 against 0.0128). Cycles with the river as a pure mirror (Metallic 1, white) returns 0.0488 in the middle band, and the stored Cycles river was 0.267 of it, where the exact Fresnel at these angles (12 to 27 percent) says about 0.2 plus the diffuse part. A river raised 1 cm gives the Cycles values above. So the Fresnel curve, the double counting of reflection and sky, the exposure of the reflected windows and the diffuse colour are not the cause; the earlier tables of #195 and #232 compared 67js with a Cycles river that was dim by an artefact.++Both water boxes now stand 1 cm above the ground. Cycles is re-rendered for `megacity-dusk-a` and `-b` (the other scenes are unchanged), `grand.json` and the two images hold the new rows:++| FLIP against Cycles | before | now |+| --- | --- | --- |+| `megacity-dusk-a` GPU / CPU | 0.1999 / 0.1992 | 0.1507 / 0.1502 |+| `megacity-dusk-b` GPU / CPU | 0.1242 / 0.1258 | 0.1108 / 0.1120 |++Mean linear luminance of 67js over Cycles after the change, `megacity-dusk-a`: towers 0.92, street 0.90, river middle 0.82, river sides 0.82. The river is now slightly dark in 67js instead of 2.4 times bright. The scores of `mountain-valley-a` and the default suite are not touched: no engine file changed, and neither scene uses these boxes (inferred; not re-run). The measuring switch `render-gpu.mjs --water off|ssr` is new. Done-when 1 of #232 holds (the cause is measured); the sky visibility grid of its scope is not needed, and the issue's second item is moot.diff --git a/bench/reference/grand-scenes.js b/bench/reference/grand-scenes.jsindex 54ace992..6b25531f 100644--- a/bench/reference/grand-scenes.js+++ b/bench/reference/grand-scenes.js@@ -374,7 +374,7 @@ async function megacityDuskA() {const riverHalf = 70;const parts = [part('city-ground', UNIT_BOX, [0, -1.5, -500], [9000, 2, 9000], GROUND),- part('river', UNIT_BOX, [0, -1.2, -500], [riverHalf * 2, 1.4, 3200], WATER),+ part('river', UNIT_BOX, [0, -1.19, -500], [riverHalf * 2, 1.4, 3200], WATER),];for (const side of [-1, 1]) {parts.push(part(`quay-${side}`, UNIT_BOX, [side * (riverHalf + 18), 0.1, -500], [36, 0.3, 3200], ROAD));@@ -414,7 +414,7 @@ async function megacityDuskB() {const sunDirection = [0.18, 0.1, -0.98];const parts = [part('land', UNIT_BOX, [0, -1.5, -1600], [6000, 2, 2400], GROUND),- part('bay', UNIT_BOX, [0, -1.2, 150], [6000, 1.4, 1100], WATER),+ part('bay', UNIT_BOX, [0, -1.19, 150], [6000, 1.4, 1100], WATER),part('harbour-quay', UNIT_BOX, [0, 0.1, -400], [6000, 0.5, 40], ROAD),];parts.push(part('pier', UNIT_BOX, [0, 1.6, 300], [6, 0.5, 420], { color: [0.4, 0.3, 0.22], roughness: 0.7 }));diff --git a/bench/reference/grand.json b/bench/reference/grand.jsonindex ea27c89f..d3318d79 100644--- a/bench/reference/grand.json+++ b/bench/reference/grand.json@@ -3,11 +3,11 @@"blenderVersion": "5.2.2 LTS","seconds": {"megacity-dusk-a": {- "cycles": 28.9,+ "cycles": 8.9,"eevee": 42.4},"megacity-dusk-b": {- "cycles": 33.2,+ "cycles": 10.8,"eevee": 27.7},"megacity-dusk-c": {@@ -36,7 +36,7 @@},"mountain-valley-a": {"cycles": 26.3,- "eevee": 20.0+ "eevee": 20}},"graphics": {@@ -45,20 +45,20 @@},"scores": {"megacity-dusk-a": {- "gpu-vs-cycles": 0.1999,- "gpu-vs-eevee": 0.1688,- "cpu-vs-cycles": 0.1992,- "cpu-vs-eevee": 0.1703,- "eevee-vs-cycles": 0.1404,- "gpu-vs-cpu": 0.0229+ "gpu-vs-cycles": 0.1507,+ "gpu-vs-eevee": 0.1141,+ "cpu-vs-cycles": 0.1502,+ "cpu-vs-eevee": 0.1152,+ "eevee-vs-cycles": 0.1455,+ "gpu-vs-cpu": 0.0224},"megacity-dusk-b": {- "gpu-vs-cycles": 0.1242,- "gpu-vs-eevee": 0.1307,- "cpu-vs-cycles": 0.1258,- "cpu-vs-eevee": 0.1317,+ "gpu-vs-cycles": 0.1108,+ "gpu-vs-eevee": 0.1246,+ "cpu-vs-cycles": 0.112,+ "cpu-vs-eevee": 0.1268,"eevee-vs-cycles": 0.1041,- "gpu-vs-cpu": 0.0428+ "gpu-vs-cpu": 0.0368},"megacity-dusk-c": {"gpu-vs-cycles": 0.1149,diff --git a/bench/reference/images/grand-megacity-dusk-a.jpg b/bench/reference/images/grand-megacity-dusk-a.jpgindex bd2661c5..b87df1b3 100644Binary files a/bench/reference/images/grand-megacity-dusk-a.jpg and b/bench/reference/images/grand-megacity-dusk-a.jpg differdiff --git a/bench/reference/images/grand-megacity-dusk-b.jpg b/bench/reference/images/grand-megacity-dusk-b.jpgindex ccc0c1cb..35588555 100644Binary files a/bench/reference/images/grand-megacity-dusk-b.jpg and b/bench/reference/images/grand-megacity-dusk-b.jpg differdiff --git a/bench/reference/render-gpu.mjs b/bench/reference/render-gpu.mjsindex da09f6cf..41a873ff 100644--- a/bench/reference/render-gpu.mjs+++ b/bench/reference/render-gpu.mjs@@ -16,6 +16,8 @@ const outputDirectory = resolve(argumentsGiven[0]);const sceneIds = argumentsGiven[1].split(',');// Ids of the grand options end in -a, -b or -c and live in their own scene set.const setOf = id => (/-[abc]$/.test(id) ? 'grand' : null);+const waterIndex = argumentsGiven.indexOf('--water');+const waterOption = waterIndex >= 0 ? argumentsGiven[waterIndex + 1] : null;function numberAfter(flag) {const index = argumentsGiven.indexOf(flag);@@ -40,7 +42,7 @@ try {const page = await browser.newPage({ viewport: { width: WIDTH, height: HEIGHT } });page.on('pageerror', error => console.log('PAGE ERROR', error.message));for (const id of sceneIds) {- await page.goto(`${serverUrl}/bench/reference/harness.html${setOf(id) ? `?set=${setOf(id)}` : ''}`, { timeout: 180000 });+ await page.goto(`${serverUrl}/bench/reference/harness.html?${[setOf(id) ? `set=${setOf(id)}` : '', waterOption ? `water=${waterOption}` : ''].filter(Boolean).join('&')}`, { timeout: 180000 });await page.waitForFunction(() => window.renderReferenceScene, null, { timeout: 180000 });const result = await page.evaluate(([sceneId, renderOptions]) => window.renderReferenceScene(sceneId, { describe: false, ...renderOptions }), [id, options]);if (result.glError !== 0) throw new Error(`${id} gave WebGL error ${result.glError}.`);diff --git a/changes/232-river.md b/changes/232-river.mdnew file mode 100644index 00000000..88d2d12f--- /dev/null+++ b/changes/232-river.md@@ -0,0 +1 @@+- Fix the "bright river" of `megacity-dusk-a` (part of issue #232): the river, and the bay of `megacity-dusk-b`, stood in the same plane as the ground box, and Cycles picked one of the two surfaces at random per ray, so the Cycles river reflected about a third of a mirror and 67js looked too bright by comparison. Both water boxes now stand 1 cm above the ground, in the reference scenes only; the engine is unchanged. See `bench/reference/README.md`.diff --git a/tests/reference-baseline.test.js b/tests/reference-baseline.test.jsindex 64082bce..b801c930 100644--- a/tests/reference-baseline.test.js+++ b/tests/reference-baseline.test.js@@ -33,3 +33,16 @@ test('the baseline records real hardware and a software renderer, and no local passert.match(baseline.graphics.cpu, /swiftshader/i);assert.doesNotMatch(JSON.stringify(baseline), /[A-Z]:[\\/]Users/);});++test('the water of the megacity scenes stands above the ground box, not in the same plane', () => {+ // Cycles resolves two surfaces in one plane at random per ray, which dimmed the river to about a third of a mirror (#232).+ const source = readFileSync(new URL('grand-scenes.js', REFERENCE_DIRECTORY), 'utf8');+ const topOf = (name, thickness) => {+ const match = source.match(new RegExp(`part\\('${name}', UNIT_BOX, \\[[^,]+, (-?[\\d.]+), `));+ assert.ok(match, `${name} is declared in grand-scenes.js`);+ return Number((Number(match[1]) + thickness / 2).toFixed(3));+ };+ const groundTop = topOf('city-ground', 2);+ assert.ok(topOf('river', 1.4) > groundTop, 'the river top is above the ground top');+ assert.ok(topOf('bay', 1.4) > groundTop, 'the bay top is above the ground top');+});