3D engine that AI agents drive
Measure the water shadow scene and record the numbers (part of #349)
Nguyen Xuan Anbc9f7117d500
diff --git a/bench/reference/README.md b/bench/reference/README.mdindex 50530a73..f5fbb69a 100644--- a/bench/reference/README.md+++ b/bench/reference/README.md@@ -1534,3 +1534,20 @@ Fix: `harness.js` renders the reference frame with `wind: 0`. Re-run with 67js o| mountain-valley-c (grand) | 0.1836 to 0.1775 | 0.223 to 0.2182 | 0.1522 |`foliage` now sits 0.0086 under EEVEE against Cycles (was 0.0055 over). Every other default and grand scene has no leaf cards and was not re-rendered; the only score that rose is a GPU against CPU difference (`gpu-vs-cpu` of `foliage` 0.0095 to 0.0097, `mountain-valley-b` 0.0158 to 0.0164). The Cycles and EEVEE columns did not move, so this is a change on the 67js side of the comparison and not a new reference. The score no longer includes the wind, which a real scene still has by default (`wind` 0.3); that is by design and is not scored here.++## Water shadows (2026-11-03, part of issue #349)++A post stands in a 12 m pool and the camera looks straight down (`scripts/water-shadow-scene.js`, run by `node scripts/measure-water-shadows.mjs`). Shadow contrast is the lit minus the shadowed bed, per channel, against the same pool dry, so the absorption of the column is what is left. Measured in Chrome with 8 bit output, inverted to linear:++| Preset | Depth | Red | Green | Blue | `exp(-absorption * depth)` for the clear lake (red, green, blue) |+| --- | --- | --- | --- | --- | --- |+| lake | 0.2 m | 0.928 | 0.978 | 1.010 | 0.932, 0.986, 0.992 |+| lake | 1 m | 0.699 | 0.907 | 0.948 | 0.705, 0.932, 0.961 |+| lake | 4 m | 0.227 | 0.694 | 0.785 | 0.247, 0.756, 0.852 |+| sea | 4 m | 0.139 | 0.520 | 0.619 | |+| river | 1 m | 0.204 | 0.190 | 0.087 | |+| river | 4 m | 0.005 | 0.005 | 0.000 | |++The clear lake stays within 10 percent of the formula (the largest gap, 8 percent at 4 m, is the in-scatter of turbidity 0.02). `RENDER_TESTS=1 node --test tests/water-shadows-render.test.js` checks it. On an opaque water surface the post's shadow darkened the steep view by 9.5 to 14 percent before and darkens it by 3 to 4 percent now (river 1.5 percent); the grazing view, which is nearly all reflection, shows 0 percent both times, so the shadow never reaches the mirrored sky.++The reference scenes draw their water as a smooth `surface` part with the planar reflection, not the `water` tag, and the shader code they run is unchanged, so they were not rescored. The Blender Cycles reference of the pool (volume absorption and scatter) and its FLIP score are not taken yet; they wait for a look at the preview.diff --git a/scripts/measure-water-shadows.mjs b/scripts/measure-water-shadows.mjsindex 40cde96f..2dda1630 100644--- a/scripts/measure-water-shadows.mjs+++ b/scripts/measure-water-shadows.mjs@@ -129,10 +129,14 @@ if (import.meta.url === pathToFileURL(process.argv[1]).href) {await composePreview(beforeCells, afterCells, previewPath);console.log(`wrote ${previewPath}`);} else {- const report = await measureWaterShadows();+ const report = await measureWaterShadows(option('--root') ?? process.cwd());for (const row of report.rows) {console.log(row.preset, row.depth, 'contrast', row.contrast.map(value => value.toFixed(3)).join(' '));}- console.log(JSON.stringify(report.surface));+ for (const [preset, views] of Object.entries(report.surface)) {+ for (const [view, { lit, shadowed }] of Object.entries(views)) {+ console.log(preset, view, 'surface shadow darkening', lit.map((value, channel) => (1 - shadowed[channel] / value).toFixed(3)).join(' '));+ }+ }}}diff --git a/scripts/water-shadow-scene.js b/scripts/water-shadow-scene.jsindex 7b6cfcde..92d8da04 100644--- a/scripts/water-shadow-scene.js+++ b/scripts/water-shadow-scene.js@@ -70,14 +70,20 @@ export function measureBed(canvas, depth, water) {}const GRAZING = { eye: [4, 0.8, 6], target: [0, -0.05, 0.5] };+const STEEP = { eye: [1.5, 9, 3], target: [0, -0.05, 0.5] };-/** Linear RGB of an opaque water surface in and out of the post's shadow, from a grazing and from a steep view. */+/** Linear RGB of one point of an opaque water surface, with the post (shadowed) and without it (lit), from a grazing and a steep view. */export function measureSurface(canvas, water) {const result = {};- for (const [label, view] of [['grazing', GRAZING], ['steep', { eye: [1.5, 9, 3], target: [0, -0.05, 0.5] }]]) {- const renderer = drawFrame(canvas, poolParts(1, water, { visible: true }), { ...view, fov: 30 });- result[label] = { lit: readLinear(renderer, canvas, [LIT_OFFSET, -0.05, 2]), shadowed: readLinear(renderer, canvas, [SHADOW_OFFSET, -0.05, 0]) };- renderer.dispose?.();+ for (const [label, view] of [['grazing', GRAZING], ['steep', STEEP]]) {+ const read = parts => {+ const renderer = drawFrame(canvas, parts, { ...view, fov: 30 });+ const color = readLinear(renderer, canvas, [SHADOW_OFFSET, -0.05, 0]);+ renderer.dispose?.();+ return color;+ };+ const parts = poolParts(1, water, { visible: true });+ result[label] = { lit: read(parts.filter(part => part.name !== 'post')), shadowed: read(parts) };}return result;}diff --git a/tests/water-shadows-render.test.js b/tests/water-shadows-render.test.jsnew file mode 100644index 00000000..5d7b8010--- /dev/null+++ b/tests/water-shadows-render.test.js@@ -0,0 +1,26 @@+import test from 'node:test';+import assert from 'node:assert/strict';+import { existsSync } from 'node:fs';+import { measureWaterShadows } from '../scripts/measure-water-shadows.mjs';+import { WATER_PRESETS } from '../src/world-material-shader.js';++// Draws the pool in Chrome, so it runs only when asked:+// RENDER_TESTS=1 bash ~/.agents/tools/gpu-lock.sh node --test tests/water-shadows-render.test.js+const chromePath = process.env.CHROME_PATH ?? 'C:/Program Files/Google/Chrome/Application/chrome.exe';+const enabled = process.env.RENDER_TESTS === '1' && existsSync(chromePath);++test('bed shadow contrast follows exp(-absorption * depth) within 10% for clear water, and the surface shadow stays faint', { skip: !enabled, timeout: 240000 }, async () => {+ const report = await measureWaterShadows();+ for (const row of report.rows.filter(candidate => candidate.preset === 'lake')) {+ row.contrast.forEach((measured, channel) => {+ const expected = Math.exp(-WATER_PRESETS.lake.absorption[channel] * row.depth);+ assert.ok(Math.abs(measured - expected) / expected < 0.1, `lake ${row.depth} m channel ${channel}: measured ${measured.toFixed(3)}, expected ${expected.toFixed(3)}`);+ });+ }+ const murky = report.rows.find(row => row.preset === 'river' && row.depth === 4);+ assert.ok(Math.max(...murky.contrast) < 0.05, 'a shadow on a murky bed 4 m down is gone');+ const surface = report.surface.lake;+ const darkening = view => Math.max(...surface[view].lit.map((value, channel) => 1 - surface[view].shadowed[channel] / value));+ assert.ok(darkening('grazing') < 0.01, 'the reflection at a grazing angle is not darkened by the shadow');+ assert.ok(darkening('steep') < 0.06, 'a shadow on the surface is faint');+});