3D engine that AI agents drive
Derive ground bounce from the scene's floor, diffuse light only (closes #244)
Nguyen Xuan An15170f8035b4
diff --git a/bench/reference/README.md b/bench/reference/README.mdindex c7df24a0..1ba817c4 100644--- a/bench/reference/README.md+++ b/bench/reference/README.md@@ -20,8 +20,8 @@ All of them are against the Blender 5.2.2 renders taken on 2026-11-03 with the s| Scene | 67js against Cycles | EEVEE against Cycles | 67js against EEVEE | Baked 67js against Cycles | Path tracer against Cycles || --- | --- | --- | --- | --- | --- |-| `brick-flat` | 0.0636 | 0.1098 | 0.1117 | | 0.1152 |-| `brick-graph` | 0.1109 | 0.1221 | 0.1162 | | 0.1476 |+| `brick-flat` | 0.0547 | 0.1098 | 0.0961 | | 0.1152 |+| `brick-graph` | 0.0982 | 0.1221 | 0.1001 | | 0.1476 || `brick-room` | 0.5102 | 0.5020 | 0.0710 | 0.1423 | 0.2727 || `brushed-film` | 0.1029 | 0.0984 | 0.0855 | | 0.1524 || `car-paint` | 0.1038 | 0.0844 | 0.0650 | | 0.1343 |@@ -1059,7 +1059,7 @@ Bundle size: the two shader lines add 9 to 18 bytes gzip to eight bundles that c## Ground bounce (2026-11-03, issue #244)-Cause of the 10.7 percent gap on `brick-flat`, measured: light the ground bounces onto the wall. Main reproduced `baseline.json` first (GPU columns to 4 digits after a fresh render of every scene; `brick-flat` 0.1264, `brick-graph` 0.1518). Cycles of `brick-flat`, 256 samples, RTX 3060, mean display luminance over the wall (rows 110 to 430, columns 230 to 730; same tone map as 67js):+Cause of the 10.7 percent gap on `brick-flat`, measured: light the ground bounces onto the wall. Cycles of `brick-flat`, 256 samples, RTX 3060, mean display luminance over the wall (rows 110 to 430, columns 230 to 730; same tone map as 67js):| Cycles setting | wall luminance | linear || --- | --- | --- |@@ -1067,19 +1067,35 @@ Cause of the 10.7 percent gap on `brick-flat`, measured: light the ground bounce| floor painted black (`--floor-color 0`) | 0.5466 | 0.1854 || light bounces limited to 0 (`--max-bounces 0`, sun and sky only) | 0.5370 | 0.1791 || 67js before | 0.5558 | |+| 67js with the fix | 0.6091 | |-The ground adds 0.0535 linear (22 percent of the wall's light) in Cycles. With bounces off, Cycles is 0.019 below 67js (display), so the sun units and colour, the sky irradiance on a vertical wall, Lambert against Principled diffuse and the tone map are not the cause: they leave 67js slightly bright, not dark. 67js showed the lower half of the sky HDRI to the wall, where Cycles has the floor.+The ground adds 0.0535 linear (22 percent of the wall's light) in Cycles. With bounces off, Cycles is 0.019 below 67js (display), so the sun units and colour, the sky irradiance on a vertical wall, Lambert against Principled diffuse and the tone map are not the cause: they leave 67js slightly bright. 67js lit the wall with the lower half of the sky HDRI, where Cycles has the floor.-Fix: `withGroundBounce(map, { albedo, keyColor, lightDirection })` (`src/ground-bounce.js`, `67js/addons/ground-bounce`) replaces the lower half of the environment map with `albedo * (sun * max(l.y, 0) / pi + sky irradiance on a level surface)` once, when the scene is built. Nothing in the renderer or a shader changes, and a frame costs the same. The suite hands the brick scenes a map with the floor's colour `[0.4, 0.38, 0.32]`; Blender still gets the plain HDRI. Wall luminance 0.5558 to 0.6125 (Cycles 0.6149).+Fix, derived from the scene and not set per scene: `groundBounceEnvironment(parts, environment)` (`src/ground-bounce.js`, `67js/addons/ground-bounce`) finds the floor (the lowest thin part that spans the scene, the same test as the automatic floor of agent scenes; a plain coloured, non-metal, opaque, untextured material gives its albedo; water and textured floors give none) and adds an `irradianceSource` to the environment map: a copy whose lower half is `albedo * (sun * max(l.y, 0) / pi + sky irradiance on a level surface)`. The renderer reads only the diffuse spherical harmonics from that copy (`environment.js`, two lines, plus the key of the prefilter cache in `renderer.js`), so the background, the reflections and the path tracer keep the real sky. The harness applies it to every scene; the agent preview applies it to every frame, with the colour of the automatic floor when no part forms one, and keeps the answer per parts array (`scripts/agent-preview-browser.js`; the browser preview itself was not driven here, only the stubbed page script in `tests/agent-preview.test.js`). It is skipped for a scene with a baked part (the light map already holds the bounce), a closed room (`closedRoomShare`, a bake or its own walls give that light), a point, spot or area light, no map, or `environment.groundBounce: false`; `--no-ground-bounce` draws the suite without it.-| Scene (GPU, against Cycles) | before | after |-| --- | --- | --- |-| `brick-flat` | 0.1264 | 0.0636 |-| `brick-graph` | 0.1518 | 0.1109 |+What the first version got wrong, kept for the next try: putting the bounced map in the sky itself (background and reflections too) made `brushed-film` 0.0739, `car-paint` 0.0688 and `metal` 0.0701 worse against Cycles, because the 40 m floor ends before the horizon and the band between the floor edge and the horizon showed the ground colour instead of the sky. A diffuse-only copy removes that. A scene lit by point, spot or area lights still got worse (`light-linking` +0.0059, `spot-area` +0.0056 with a 0.01 world): the term counts the sun and the sky only, so on a floor those lights brighten it takes light away from the lower half; those scenes are skipped now.-Both are now closer to Cycles than EEVEE is (0.1098, 0.1221); against EEVEE they score 0.1117 and 0.1162 because EEVEE has no ground bounce on the wall. Every other scene is unchanged by construction: only `brickWallScene` calls the helper, and the full GPU run on main before the change gave the committed rows. Only these two scenes got the helper: the other scenes with a floor (`material-spheres`, `metal`, `character`, `outdoor-hdri` ...) were not tried, and their floors are not the infinite flat plane the term assumes. The floor's shadow under the wall is ignored, which is why a lower albedo is the way to correct a mostly shaded floor.+GPU against Cycles, main before and after, every scene rendered again on the same arrays (the committed `baseline.json` GPU columns reproduced to 4 digits first; the CPU columns of the other scenes come from older arrays and are not compared). Scenes not listed are unchanged to 4 digits.-`render-blender.py` gained `--max-bounces <n>` and `--floor-color <v>` (Cycles only, like `--world-strength`). Bundle size: `entry:ground-bounce` is new (2832 bytes gzip, budget 2850). `entry:core` measured 85952 on main with or without the new entry, so its budget rose by 5 bytes to 85955.+| Scene | before | after | change | against EEVEE before | after |+| --- | --- | --- | --- | --- | --- |+| `brick-flat` | 0.1264 | 0.0547 | -0.0717 | 0.0465 | 0.0961 |+| `brick-graph` | 0.1518 | 0.0982 | -0.0536 | 0.0844 | 0.1001 |+| `material-spheres` | 0.1180 | 0.0956 | -0.0224 | 0.0681 | 0.0741 |+| `fog` | 0.2207 | 0.2021 | -0.0186 | 0.1092 | 0.1324 |+| `character` | 0.0712 | 0.0567 | -0.0145 | 0.0438 | 0.0661 |+| `glass` | 0.1033 | 0.0913 | -0.0120 | 0.1001 | 0.1100 |+| `outdoor-hdri` | 0.0443 | 0.0333 | -0.0110 | 0.0282 | 0.0366 |+| `fog-valley` | 0.1859 | 0.1791 | -0.0068 | 0.1459 | 0.1563 |+| `car-paint` | 0.1021 | 0.0979 | -0.0042 | 0.0633 | 0.0662 |+| `long-street` | 0.1149 | 0.1121 | -0.0028 | 0.0911 | 0.1152 |+| `megacity-dusk` | 0.1584 | 0.1601 | +0.0017 | 0.1038 | 0.0947 |+| `metal` | 0.0957 | 0.0964 | +0.0007 | unchanged | unchanged |+| `brushed-film` | 0.1016 | 0.1017 | +0.0001 | 0.0835 | 0.0836 |++No scene is worse by more than 0.002 (`megacity-dusk` is the largest at 0.0017); ten are better. Scores against EEVEE rise for most scenes because EEVEE has no ground bounce; Cycles is the reference. The CPU columns were redrawn for the eleven scenes that are not `long-street` or `megacity-dusk` (SwiftShader is too slow for those two, so their CPU columns keep the older numbers). The grand and Khronos scenes were not run: their arrays are not in the work directory. Not tried: spot and area lit scenes with the lights' own bounce (a bounce that counts the lights would need the path tracer or a bake).++Bundle size: `entry:ground-bounce` is new (9318 bytes gzip, it brings the closed room test and the bounds code). The two core lines add 18 to 31 bytes to eight bundles (`entry:core` 85986, `entry:agent-asset`, `scene:lit-box`, `scene:gltf-box`, `scene:gltf-box+lazy`, `scene:agent-scene`, `scene:agent-scene+lazy`); their budgets rose by 4 to 35 bytes. `entry:core` measured 85952 on main before the change, 2 over its 85950 budget. `render-blender.py` gained `--max-bounces <n>` and `--floor-color <v>` (Cycles only, like `--world-strength`).## Bump scale per world unit and the brick-face colour (2026-11-03, part of issue #50)diff --git a/bench/reference/baseline.json b/bench/reference/baseline.jsonindex de31f706..66effb0c 100644--- a/bench/reference/baseline.json+++ b/bench/reference/baseline.json@@ -101,20 +101,20 @@},"scores": {"brick-flat": {- "gpu-vs-cycles": 0.0636,- "gpu-vs-eevee": 0.1117,- "cpu-vs-cycles": 0.0633,- "cpu-vs-eevee": 0.112,+ "gpu-vs-cycles": 0.0547,+ "gpu-vs-eevee": 0.0961,+ "cpu-vs-cycles": 0.0543,+ "cpu-vs-eevee": 0.0963,"eevee-vs-cycles": 0.1099,- "gpu-vs-cpu": 0.0066+ "gpu-vs-cpu": 0.0065},"brick-graph": {- "gpu-vs-cycles": 0.1109,- "gpu-vs-eevee": 0.1162,- "cpu-vs-cycles": 0.1109,- "cpu-vs-eevee": 0.1162,+ "gpu-vs-cycles": 0.0982,+ "gpu-vs-eevee": 0.1001,+ "cpu-vs-cycles": 0.0982,+ "cpu-vs-eevee": 0.1001,"eevee-vs-cycles": 0.1221,- "gpu-vs-cpu": 0.0072+ "gpu-vs-cpu": 0.0079},"brick-room": {"gpu-vs-cycles": 0.5096,@@ -125,28 +125,28 @@"gpu-vs-cpu": 0.0071},"brushed-film": {- "gpu-vs-cycles": 0.1016,- "gpu-vs-eevee": 0.0835,+ "gpu-vs-cycles": 0.1017,+ "gpu-vs-eevee": 0.0836,"cpu-vs-cycles": 0.1014,- "cpu-vs-eevee": 0.0835,+ "cpu-vs-eevee": 0.0836,"eevee-vs-cycles": 0.0985,- "gpu-vs-cpu": 0.0061+ "gpu-vs-cpu": 0.0064},"car-paint": {- "gpu-vs-cycles": 0.1021,- "gpu-vs-eevee": 0.0633,- "cpu-vs-cycles": 0.1018,- "cpu-vs-eevee": 0.0634,+ "gpu-vs-cycles": 0.0979,+ "gpu-vs-eevee": 0.0662,+ "cpu-vs-cycles": 0.0977,+ "cpu-vs-eevee": 0.0663,"eevee-vs-cycles": 0.0844,- "gpu-vs-cpu": 0.0058+ "gpu-vs-cpu": 0.0061},"character": {- "gpu-vs-cycles": 0.0712,- "gpu-vs-eevee": 0.0438,- "cpu-vs-cycles": 0.071,- "cpu-vs-eevee": 0.0437,+ "gpu-vs-cycles": 0.0567,+ "gpu-vs-eevee": 0.0661,+ "cpu-vs-cycles": 0.0565,+ "cpu-vs-eevee": 0.0663,"eevee-vs-cycles": 0.0622,- "gpu-vs-cpu": 0.0066+ "gpu-vs-cpu": 0.006},"dark-shaft": {"gpu-vs-cycles": 0.0559,@@ -161,12 +161,12 @@"region-eevee-vs-cycles": 0.2645},"fog": {- "gpu-vs-cycles": 0.2207,- "gpu-vs-eevee": 0.1092,- "cpu-vs-cycles": 0.2204,- "cpu-vs-eevee": 0.1097,+ "gpu-vs-cycles": 0.2021,+ "gpu-vs-eevee": 0.1324,+ "cpu-vs-cycles": 0.2017,+ "cpu-vs-eevee": 0.1328,"eevee-vs-cycles": 0.2662,- "gpu-vs-cpu": 0.0086+ "gpu-vs-cpu": 0.0087},"fog-room": {"gpu-vs-cycles": 0.1036,@@ -181,12 +181,12 @@"region-eevee-vs-cycles": 0.3147},"fog-valley": {- "gpu-vs-cycles": 0.1859,- "gpu-vs-eevee": 0.1459,- "cpu-vs-cycles": 0.1861,- "cpu-vs-eevee": 0.1463,+ "gpu-vs-cycles": 0.1791,+ "gpu-vs-eevee": 0.1563,+ "cpu-vs-cycles": 0.1794,+ "cpu-vs-eevee": 0.1568,"eevee-vs-cycles": 0.1952,- "gpu-vs-cpu": 0.0116+ "gpu-vs-cpu": 0.0114},"foliage": {"gpu-vs-cycles": 0.0979,@@ -197,12 +197,12 @@"gpu-vs-cpu": 0.0095},"glass": {- "gpu-vs-cycles": 0.1033,- "gpu-vs-eevee": 0.1001,- "cpu-vs-cycles": 0.1033,- "cpu-vs-eevee": 0.1003,+ "gpu-vs-cycles": 0.0913,+ "gpu-vs-eevee": 0.11,+ "cpu-vs-cycles": 0.0908,+ "cpu-vs-eevee": 0.1103,"eevee-vs-cycles": 0.1008,- "gpu-vs-cpu": 0.0078+ "gpu-vs-cpu": 0.0074},"light-linking": {"gpu-vs-cycles": 0.0993,@@ -221,36 +221,36 @@"gpu-vs-cpu": 0.0062},"long-street": {- "gpu-vs-cycles": 0.1149,- "gpu-vs-eevee": 0.0911,+ "gpu-vs-cycles": 0.1121,+ "gpu-vs-eevee": 0.1152,"cpu-vs-cycles": 0.115,"cpu-vs-eevee": 0.0919,"eevee-vs-cycles": 0.0976,"gpu-vs-cpu": 0.0066},"material-spheres": {- "gpu-vs-cycles": 0.118,- "gpu-vs-eevee": 0.0681,- "cpu-vs-cycles": 0.1179,- "cpu-vs-eevee": 0.0681,+ "gpu-vs-cycles": 0.0956,+ "gpu-vs-eevee": 0.0741,+ "cpu-vs-cycles": 0.0951,+ "cpu-vs-eevee": 0.074,"eevee-vs-cycles": 0.1053,- "gpu-vs-cpu": 0.0082+ "gpu-vs-cpu": 0.0067},"megacity-dusk": {- "gpu-vs-cycles": 0.1584,- "gpu-vs-eevee": 0.1038,+ "gpu-vs-cycles": 0.1601,+ "gpu-vs-eevee": 0.0947,"cpu-vs-cycles": 0.1577,"cpu-vs-eevee": 0.1076,"eevee-vs-cycles": 0.1524,"gpu-vs-cpu": 0.0276},"metal": {- "gpu-vs-cycles": 0.0957,+ "gpu-vs-cycles": 0.0964,"gpu-vs-eevee": 0.0806,- "cpu-vs-cycles": 0.0955,+ "cpu-vs-cycles": 0.0962,"cpu-vs-eevee": 0.0808,"eevee-vs-cycles": 0.0916,- "gpu-vs-cpu": 0.0064+ "gpu-vs-cpu": 0.0067},"metal-room": {"gpu-vs-cycles": 0.5071,@@ -269,12 +269,12 @@"gpu-vs-cpu": 0.0124},"outdoor-hdri": {- "gpu-vs-cycles": 0.0443,- "gpu-vs-eevee": 0.0282,- "cpu-vs-cycles": 0.0437,- "cpu-vs-eevee": 0.0281,+ "gpu-vs-cycles": 0.0333,+ "gpu-vs-eevee": 0.0366,+ "cpu-vs-cycles": 0.0328,+ "cpu-vs-eevee": 0.0363,"eevee-vs-cycles": 0.0403,- "gpu-vs-cpu": 0.0061+ "gpu-vs-cpu": 0.0066},"spot-area": {"gpu-vs-cycles": 0.1244,diff --git a/bench/reference/harness.js b/bench/reference/harness.jsindex 720aa2c7..ba3cb561 100644--- a/bench/reference/harness.js+++ b/bench/reference/harness.js@@ -11,8 +11,17 @@ import { createCascadedShadows } from '/src/cascaded-shadows.js';import { applyLightLinks } from '/src/light-linking.js';import { applyWaterReflection, attachWaterReflection } from '/src/water-reflection.js';import { attachScreenSpaceWater } from './ssr-water.js';+import { groundBounceEnvironment } from '/src/ground-bounce.js';// Water reflection is on the way a recipe gets it: found from the materials, no field. ?water=off draws the scenes without it, ?water=ssr with the screen-space reflection it was compared with.+// Ground bounce is on the way a recipe gets it: found from the floor part, no field. ?groundBounce=off draws the scenes without it.+const GROUND_BOUNCE = new URLSearchParams(location.search).get('groundBounce') !== 'off';++// The scene's environment with the light its floor bounces, when it has a plain one and nothing else gives that light (a bake, a closed room).+function withDerivedGroundBounce(scene, drawnParts) {+ return GROUND_BOUNCE ? groundBounceEnvironment(drawnParts, scene.environment) : scene.environment;+}+const WATER_REFLECTION = { off: false, ssr: 'ssr' }[new URLSearchParams(location.search).get('water')] ?? 'planar';// ?set=khronos draws the Khronos sample assets (npm run reference -- --khronos) and ?set=cloth the cloth scenes@@ -172,6 +181,7 @@ async function renderReferenceScene(id, { describe, ambientOcclusion = 0, ambienif (key !== null) scene.environment = { ...scene.environment, keyIntensity: key };const baked = bake ? await bakeScene(scene, bake) : null;const probed = probes ? await probeScene(scene, id, baked ? baked.parts : scene.parts, probes) : null;+ scene.environment = withDerivedGroundBounce(scene, probed ? probed.parts : baked ? baked.parts : scene.parts);const canvas = document.querySelector('canvas');// backgroundOnly draws the sky alone, so a score can be limited to the pixels the asset covers.const renderer = createSceneRenderer(backgroundOnly ? [] : probed ? probed.parts : baked ? baked.parts : scene.parts, scene, cascades);@@ -197,6 +207,7 @@ async function measureReferenceFrameTime(id, { bake, probes = false, cascades =const scene = await SCENES[id]();const baked = bake ? await bakeScene(scene, {}) : null;const probed = probes ? await probeScene(scene, id, baked ? baked.parts : scene.parts, probes) : null;+ scene.environment = withDerivedGroundBounce(scene, probed ? probed.parts : baked ? baked.parts : scene.parts);const renderer = createSceneRenderer(probed ? probed.parts : baked ? baked.parts : scene.parts, scene, cascades, { water });renderer.resize();const frame = { ...scene.camera, environment: scene.environment, time: 0, exposure: 1, effects: { ambientOcclusion: 0, ambientOcclusionRadius: 0.5 } };diff --git a/bench/reference/run.mjs b/bench/reference/run.mjsindex 8be588f8..e113687f 100644--- a/bench/reference/run.mjs+++ b/bench/reference/run.mjs@@ -20,6 +20,7 @@ import { createServer } from 'vite';// cloth bake, and scores them into cloth.json the same way (the pixels the scene covers, with the sky left out).const khronos = process.argv.includes('--khronos');const cloth = process.argv.includes('--cloth');+// --no-ground-bounce draws the scenes without the light their floor bounces (src/ground-bounce.js), which is otherwise found from the floor part.// --no-water draws the scenes without the water reflection (src/water-reflection.js), which is otherwise found from the materials; --ssr-water draws them with bench/reference/ssr-water.js instead.// --grand draws the options for the grand scenes (grand-scenes.js, issue #168) and scores them into grand.json.const grand = process.argv.includes('--grand');@@ -84,7 +85,7 @@ const sceneIdsGiven = sceneFlag >= 0 ? argumentsGiven[sceneFlag + 1].split(',')// The fresh bake.json lands in the work directory and is checked against the committed one (compare-scores.mjs); --update-baseline replaces// the committed bake.json and images/<id>-baked.jpg with it.const bakeScoreRun = bakedSceneIds !== null && !sceneSet && !pathTracerFlag;-const bakeVariantFlags = ['--sky-only', '--bake-preset', '--probes', '--ambient', '--ambient-occlusion', '--cascades', '--no-object-probes', '--object-probes', '--no-water', '--ssr-water'];+const bakeVariantFlags = ['--sky-only', '--bake-preset', '--probes', '--ambient', '--ambient-occlusion', '--cascades', '--no-object-probes', '--object-probes', '--no-water', '--ssr-water', '--no-ground-bounce'];const bakeScoreIsBaseline = bakeScoreRun && argumentsGiven.includes('--update-baseline') && !bakeVariantFlags.some(flag => argumentsGiven.includes(flag));const onlyScenes = sceneIdsGiven ?? (bakeScoreRun ? bakedSceneIds : null);const skipCpu = skipCpuFlag || bakeScoreRun;@@ -98,7 +99,7 @@ async function renderBackend(backend, serverUrl, graphics) {page.on('console', message => message.text().includes('GL_') && console.log('PAGE', message.text().slice(0, 200)));// Each scene gets a fresh page, so a large scene leaves no GL state or memory behind for the next one.const openHarness = async () => {- const harnessQuery = [sceneSet ? `set=${sceneSet}` : null, argumentsGiven.includes('--no-water') ? 'water=off' : argumentsGiven.includes('--ssr-water') ? 'water=ssr' : null].filter(Boolean).join('&');+ const harnessQuery = [sceneSet ? `set=${sceneSet}` : null, argumentsGiven.includes('--no-water') ? 'water=off' : argumentsGiven.includes('--ssr-water') ? 'water=ssr' : null, argumentsGiven.includes('--no-ground-bounce') ? 'groundBounce=off' : null].filter(Boolean).join('&');await page.goto(`${serverUrl}/bench/reference/harness.html${harnessQuery ? `?${harnessQuery}` : ''}`, { timeout: PAGE_LOAD_TIMEOUT });await page.waitForFunction(() => window.renderReferenceScene, null, { timeout: PAGE_LOAD_TIMEOUT });};diff --git a/bench/reference/scenes.js b/bench/reference/scenes.jsindex 85641693..6e6fe848 100644--- a/bench/reference/scenes.js+++ b/bench/reference/scenes.js@@ -6,7 +6,6 @@ import { parseGltf } from '/src/gltf.js';import { createTree, scatterVegetation, selectLevels, vegetationParts } from '/src/vegetation.js';import { createNoiseHeight, createTerrain } from '/src/terrain.js';import { createAgentScene, loadAgentSceneModules } from '/src/agent-scene.js';-import { withGroundBounce } from '/src/ground-bounce.js';import { materialPatternTextures, normalizeMaterialPattern } from '/src/material-patterns.js';const HDRI_FILE = 'public/hdri/kloofendal_48d_partly_cloudy_puresky_1k.hdr';@@ -107,12 +106,8 @@ function averageLinearColor(colorImage) {return sums.map(sum => sum / pixelCount);}-const BRICK_FLOOR_COLOR = [0.4, 0.38, 0.32];-async function brickWallScene({ withGraph }) {- const sky = await skyLighting();- const bouncedMap = withGroundBounce(sky.map, { albedo: BRICK_FLOOR_COLOR, keyColor: SUN_COLOR, lightDirection: DEFAULT_SUN_DIRECTION });- const lighting = { ...sky, map: bouncedMap };+ const lighting = await skyLighting();const pattern = normalizeMaterialPattern({ type: 'graph', graph: brickGraph(), mapping: 'uv', bump: 1, resolution: 512 });const { map, normalMap, boxMapScale, boxMapAxis } = materialPatternTextures(pattern);const wall = withGraph@@ -123,7 +118,7 @@ async function brickWallScene({ withGraph }) {wall.material.graphBump = pattern.bump;}return {- parts: [floor(BRICK_FLOOR_COLOR), wall], blenderWorld: lighting.blenderWorld,+ parts: [floor([0.4, 0.38, 0.32]), wall], blenderWorld: lighting.blenderWorld,environment: environment(lighting, { keyColor: SUN_COLOR }),camera: { eye: [0, 2, 8.5], target: [0, 2, 0], up: [0, 1, 0], fov: 40, near: 0.1, far: 100 },shadow: shadowAlongSun(DEFAULT_SUN_DIRECTION, { target: [0, 1, 0], distance: 13.45, extent: 8, near: 0.1, far: 40 }),diff --git a/bench/size/budgets.json b/bench/size/budgets.jsonindex f1d9b691..cbee5aa0 100644--- a/bench/size/budgets.json+++ b/bench/size/budgets.json@@ -6,7 +6,7 @@"agent-scene": 100000},"budgets": {- "entry:core": 85955,+ "entry:core": 85990,"entry:model": 14400,"entry:nature": 13200,"entry:motion": 13600,@@ -31,12 +31,12 @@"entry:grass": 4400,"entry:clutter": 5300,"entry:light-bake": 28500,- "entry:ground-bounce": 2850,+ "entry:ground-bounce": 9330,"entry:path-tracer": 14600,"entry:texture-set": 900,"entry:agent-scene": 77810,"entry:agent-scene+lazy": 259980,- "entry:agent-asset": 109160,+ "entry:agent-asset": 109170,"entry:agent-asset+lazy": 271380,"entry:hdri": 3300,"entry:camera-effects": 8600,@@ -45,10 +45,10 @@"entry:material-layer-shaders": 20700,"entry:light-linking": 19000,"entry:cascaded-shadows": 27730,- "scene:lit-box": 63330,- "scene:gltf-box": 84350,- "scene:gltf-box+lazy": 87680,- "scene:agent-scene": 105130,- "scene:agent-scene+lazy": 287300+ "scene:lit-box": 63360,+ "scene:gltf-box": 84380,+ "scene:gltf-box+lazy": 87710,+ "scene:agent-scene": 105160,+ "scene:agent-scene+lazy": 287330}}diff --git a/changes/244.md b/changes/244.mdindex 4c529cd3..111362f6 100644--- a/changes/244.md+++ b/changes/244.md@@ -1 +1 @@-- Add `withGroundBounce` (`67js/addons/ground-bounce`): the lower half of an environment map becomes the light a level ground sends back up, so a wall gets ground bounce with no bake and no frame cost; `brick-flat` moves from 0.1264 to 0.0636 against Cycles and `brick-graph` from 0.1518 to 0.1109 (closes #244).+- Derive ground bounce from the scene: `groundBounceEnvironment` (`67js/addons/ground-bounce`) finds the floor part and gives the environment map a diffuse-only copy whose lower half is the light the floor sends back up, so walls and figures on an open floor get bounce light with no bake and no frame cost (`brick-flat` 0.1264 to 0.0547 against Cycles, `brick-graph` 0.1518 to 0.0982, eight more scenes better, none worse by more than 0.002; closes #244).diff --git a/docs/light-bake.md b/docs/light-bake.mdindex de6e44de..1e2c4564 100644--- a/docs/light-bake.md+++ b/docs/light-bake.md@@ -63,7 +63,7 @@ GLB export writes `lightUvs` as `TEXCOORD_1` and the light map as the emissive t## Ground bounce without a bake-`withGroundBounce(map, { albedo, keyColor, lightDirection })` from `67js/addons/ground-bounce` returns a copy of an environment map whose lower half is what a level, unshadowed ground sends back up: `albedo * (keyColor * max(lightDirection.y, 0) / pi + sky irradiance on a level surface)`. Hand it to `environment.map` and walls, figures and reflections get the ground's light through the same diffuse and reflection lookups as the sky, with no bake and no cost per frame. Pass the sun the environment already has; `albedo` is the linear colour of the ground. It assumes an infinite floor, so give a small or mostly shaded floor a lower albedo. On the `brick-flat` wall it moves the mean luminance from 0.556 to 0.613 (Cycles 0.615), see "Ground bounce" in `bench/reference/README.md`.+An open scene with a floor gets the light the floor bounces without a bake and without a frame of extra cost. `groundBounceEnvironment(parts, environment)` from `67js/addons/ground-bounce` finds the floor (the lowest thin part that spans the scene, with a plain coloured, non-metal, opaque, untextured material) and returns the environment with an `irradianceSource` on its map: a copy whose lower half is `albedo * (keyColor * keyIntensity * max(lightDirection.y, 0) / pi + sky irradiance on a level surface)`. Only the diffuse light reads that copy, so walls and figures get the ground's light while the background and the reflections keep the real sky. The environment is returned unchanged when there is no such floor, a part is baked (its light map holds the bounce), the scene is a closed room, a point, spot or area light is present (the term counts the sun and the sky only), there is no map, or `environment.groundBounce` is `false`. `automaticAlbedo` gives the colour of a floor the preview adds when no part forms one. The floor is taken as unshadowed, level and infinite. `withGroundBounce(map, { albedo, keyColor, lightDirection })` is the same with the floor given by hand. On the `brick-flat` wall the mean luminance goes from 0.556 to 0.609 (Cycles 0.615); see "Ground bounce" in `bench/reference/README.md` for every scene.## Reflection probesdiff --git a/scripts/agent-preview-browser.js b/scripts/agent-preview-browser.jsindex bf6752d8..81c44ca9 100644--- a/scripts/agent-preview-browser.js+++ b/scripts/agent-preview-browser.js@@ -9,7 +9,8 @@ import { applyProjection } from '../src/camera.js';import { mat4 } from 'gl-matrix';import { resolveAgentShadow, agentEnvironmentMap } from '../src/agent-look.js';import { agentSceneModule } from '../src/agent-scene-modules.js';-import { agentGroundPlacement, createAgentGround, placeAgentGround } from '../src/agent-ground.js';+import { agentGroundPlacement, createAgentGround, placeAgentGround, FLOOR_COLOR } from '../src/agent-ground.js';+import { groundBounceEnvironment } from '../src/ground-bounce.js';import { createAgentAssetScene } from '../src/agent-asset.js';import { parseGltf } from '../src/gltf.js';import { exportGlb } from '../src/export.js';@@ -101,6 +102,12 @@ function syncAutomaticGround(record) {}}+// The scene's environment lit by the sky map, with the light its floor bounces (src/ground-bounce.js): a floor part of the+// recipe gives its own colour, and the automatic floor gives its own.+function litEnvironment(parts, environment, hasAutomaticGround) {+ return groundBounceEnvironment(parts, { ...environment, map: agentEnvironmentMap(environment) }, { automaticAlbedo: hasAutomaticGround ? FLOOR_COLOR : null });+}+// A renderer takes its cascades at construction, so a change of the count (or of the extent that picks it) rebuilds.function syncShadowCascades(record) {const count = cascadeCountFor(record.scene);@@ -143,7 +150,7 @@ function draw(record, time = 0, camera = record.scene.camera, frameOptions = {})record.shadowKey = shadowKey;}record.renderer.world = environment.world;- record.renderer.render({ ...camera, environment: { ...environment, map: agentEnvironmentMap(environment) }, effects, exposure: effects.exposure, time, ...frameOptions });+ record.renderer.render({ ...camera, environment: litEnvironment(record.scene.parts, environment, Boolean(record.renderer.groundPart)), effects, exposure: effects.exposure, time, ...frameOptions });const error = record.renderer.context.getError();if (error !== 0) {throw new Error(`WebGL render failed with error ${error}.`);@@ -215,7 +222,7 @@ function initializeRenderer(scene, { memoryBudgetMiB, backend }) {hdr: true,depth: true,world: scene.environment.world,- environment: { ...scene.environment, map: agentEnvironmentMap(scene.environment) },+ environment: litEnvironment(scene.parts, scene.environment, Boolean(placement)),shadowBounds: resolveAgentShadow(scene.shadow, scene.environment.lightDirection),shadowCascades: cascadesFor(scene),skyOpenness,diff --git a/src/agent-ground.js b/src/agent-ground.jsindex 446e5b89..de995e40 100644--- a/src/agent-ground.js+++ b/src/agent-ground.js@@ -12,7 +12,7 @@ const FLOOR_LOWEST_TOLERANCE = 1e-3;// The disc reaches this many scene half-widths past the scene, so its edge stays out of a framed shot.const DISC_REACH = 6;const MINIMUM_RADIUS = 2;-const FLOOR_COLOR = [0.22, 0.22, 0.21];+export const FLOOR_COLOR = [0.22, 0.22, 0.21];/** World-space axis-aligned bounds of one part, from its positions and matrix. */function partBounds(part) {diff --git a/src/environment.js b/src/environment.jsindex 56693388..ab005a1d 100644--- a/src/environment.js+++ b/src/environment.js@@ -387,11 +387,12 @@ export function createEnvironmentResources(context, map, { compileProgram, fullscontext.finish();return {data: map.data,+ irradianceSource: map.irradianceSource,specularTexture,brdfTexture,levelCount: layout.levelCount,bytes: layout.bytes,- irradiance: computeIrradianceCoefficients(map),+ irradiance: computeIrradianceCoefficients(map.irradianceSource ?? map),prefilterMilliseconds: performance.now() - started,dispose() {context.deleteTexture(specularTexture);diff --git a/src/ground-bounce.js b/src/ground-bounce.jsindex 8f1ae40a..cd9b7d97 100644--- a/src/ground-bounce.js+++ b/src/ground-bounce.js@@ -1,9 +1,66 @@import { computeIrradianceCoefficients, createEnvironmentMap, evaluateIrradiance } from './environment.js'+import { CLOSED_ROOM_SHARE, closedRoomShare } from './closed-room.js'+import { worldBounds } from './probe-trace.js'++// The ground of a scene is its floor: a part that spans the scene (the same test as the automatic floor of agent scenes),+// is thin and is the lowest geometry. Its albedo comes from its material.+const GROUND_SPAN_SHARE = 0.9+const GROUND_THINNESS = 0.25+const GROUND_LOWEST_TOLERANCE = 1e-3+const GROUND_MAXIMUM_METALLIC = 0.5+const EXCLUDED_TAGS = new Set(['liquid', 'foam', 'unlit', 'fire', 'smoke', 'floor'])++function sceneBoundsOf(boundsList) {+ const minimum = [Infinity, Infinity, Infinity]+ const maximum = [-Infinity, -Infinity, -Infinity]+ for (const bounds of boundsList) {+ for (let axis = 0; axis < 3; axis++) {+ minimum[axis] = Math.min(minimum[axis], bounds.minimum[axis])+ maximum[axis] = Math.max(maximum[axis], bounds.maximum[axis])+ }+ }+ return { minimum, maximum }+}++function groundAlbedo(material) {+ const tinted = !material.map && !material.graph && material.alphaMode !== 'blend' && !(material.transmission > 0) && !EXCLUDED_TAGS.has(material.tag)+ if (!tinted || !Array.isArray(material.color) || (material.metallic ?? 0) > GROUND_MAXIMUM_METALLIC) {+ return null+ }+ return material.color.slice(0, 3).map(channel => channel * (1 - (material.metallic ?? 0)))+}/**- * Returns a copy of an environment map whose lower half is the light a flat ground sends back up: albedo times the- * sun and the sky that reach it, over pi. A wall, a figure or a roof then gets ground bounce from the same diffuse- * and reflection lookups as the sky, at no cost per frame. The ground is taken as unshadowed, level (y up) and+ * The floor of a scene as `{ albedo }`, or null: the lowest, thin part that spans the scene, when it is a plain+ * coloured, non-metal, opaque surface. A textured floor, water and a scene without a floor give null.+ */+export function findGroundSurface(parts) {+ if (parts.length < 2) {+ return null+ }+ const boundsList = parts.map(part => worldBounds(part))+ const scene = sceneBoundsOf(boundsList)+ const widthX = scene.maximum[0] - scene.minimum[0]+ const widthZ = scene.maximum[2] - scene.minimum[2]+ for (const [index, bounds] of boundsList.entries()) {+ const partX = bounds.maximum[0] - bounds.minimum[0]+ const partZ = bounds.maximum[2] - bounds.minimum[2]+ const partHeight = bounds.maximum[1] - bounds.minimum[1]+ const spansScene = partX >= GROUND_SPAN_SHARE * widthX && partZ >= GROUND_SPAN_SHARE * widthZ+ const isThin = partHeight <= GROUND_THINNESS * Math.max(partX, partZ)+ const isLowest = bounds.minimum[1] <= scene.minimum[1] + GROUND_LOWEST_TOLERANCE+ if (spansScene && isThin && isLowest) {+ const albedo = groundAlbedo(parts[index].material)+ return albedo ? { albedo } : null+ }+ }+ return null+}++/**+ * Returns the environment map with an `irradianceSource`: a copy whose lower half is the light a flat ground sends back+ * up, albedo times the sun and the sky that reach it, over pi. Only the diffuse light reads that copy, so a wall, a figure+ * or a roof gets ground bounce at no cost per frame, while the background and the reflections still show the original sky. The ground is taken as unshadowed, level (y up) and* infinite, so a scene with a small or mostly shaded floor should give a smaller albedo.** `albedo` is the ground's linear colour, `keyColor` and `lightDirection` are the environment's sun (direction@@ -25,5 +82,65 @@ export function withGroundBounce(map, { albedo, keyColor = [0, 0, 0], lightDirecfor (let index = 0; index < 3; index++) bounced[offset + index] = groundRadiance[index]}}- return createEnvironmentMap({ ...map, data: bounced })+ return Object.freeze({ ...map, irradianceSource: createEnvironmentMap({ ...map, data: bounced }) })+}++// The renderer keys its prefiltered copy of a map on the map object, so the same inputs must return the same object.+const cache = new WeakMap()++function isDrawnWithBakedLight(parts) {+ return parts.some(part => part.material?.lightMap)+}++function isClosedRoom(parts) {+ const share = closedRoomShare(parts, new Map(parts.map(part => [part.name, part.matrix])))+ return share !== null && share >= CLOSED_ROOM_SHARE+}++// What the parts say about their ground does not change from frame to frame, and a preview asks every frame, so the+// answer is kept for as long as the same parts array (of the same length) is asked about.+const groundOfParts = new WeakMap()++function groundOf(parts, automaticAlbedo) {+ const key = JSON.stringify([parts.length, automaticAlbedo])+ const remembered = groundOfParts.get(parts)+ if (remembered?.key === key) {+ return remembered.ground+ }+ const found = isDrawnWithBakedLight(parts) ? null : findGroundSurface(parts) ?? (automaticAlbedo && { albedo: automaticAlbedo })+ const ground = found && !isClosedRoom(parts) ? found : null+ groundOfParts.set(parts, { key, ground })+ return ground+}++// The term knows the sun and the sky only. A scene lit by point, spot or area lights has a floor those lights brighten, which+// it would not count, so it would take the sky's own light away from the lower half and darken the scene (measured on+// `light-linking` and `spot-area`).+function hasLocalLights(environment) {+ return [environment.pointLights, environment.spotLights, environment.areaLights].some(lights => lights?.length > 0)+}++/**+ * The environment with the ground's bounce in its map, found from the parts: the same environment when the scene has no+ * plain floor, a baked part (its light map already holds the bounce), a closed room (a bake or the room's own walls+ * give that light), a point, spot or area light, or no map. `automaticAlbedo` is the colour of a floor the preview adds when no part forms one.+ * `environment.groundBounce: false` turns it off.+ */+export function groundBounceEnvironment(parts, environment, { automaticAlbedo = null } = {}) {+ if (!environment.map || environment.groundBounce === false || hasLocalLights(environment)) {+ return environment+ }+ const ground = groundOf(parts, automaticAlbedo)+ if (!ground) {+ return environment+ }+ const { lightDirection } = environment+ const keyColor = environment.keyColor.map(channel => channel * (environment.keyIntensity ?? 1))+ const key = JSON.stringify([ground.albedo, keyColor, lightDirection])+ const byInputs = cache.get(environment.map) ?? new Map()+ cache.set(environment.map, byInputs)+ if (!byInputs.has(key)) {+ byInputs.set(key, withGroundBounce(environment.map, { albedo: ground.albedo, keyColor, lightDirection }))+ }+ return { ...environment, map: byInputs.get(key) }}diff --git a/src/renderer.js b/src/renderer.jsindex 2a5c9a2e..06e2bfc6 100644--- a/src/renderer.js+++ b/src/renderer.js@@ -1546,10 +1546,10 @@ export class Renderer67 {context.bindTexture(context.TEXTURE_2D, brdfTexture);}- // Prefilters a map the first time it is seen; maps spread from one created map share its data and reuse the GPU textures. Returns true when new textures were built.+ // Prefilters a map the first time it is seen; maps spread from one created map share its data and reuse the GPU textures (an `irradianceSource` map, which only the diffuse light reads, counts as part of the map). Returns true when new textures were built.prepareEnvironment(map) {assertEnvironmentMap(map);- if (this.environmentResources?.data === map.data) return false;+ if (this.environmentResources?.data === map.data && this.environmentResources.irradianceSource === map.irradianceSource) return false;estimateEnvironmentBytes(map, this.capabilities.maximumTextureSize);const resources = createEnvironmentResources(this.context, map, { compileProgram: (context, vertexSource, fragmentSource) => this.compileEnvironmentProgram(context, vertexSource, fragmentSource), fullscreenVertex });this.environmentResources?.dispose();diff --git a/tests/ground-bounce.test.js b/tests/ground-bounce.test.jsindex 388025e8..734d0f42 100644--- a/tests/ground-bounce.test.js+++ b/tests/ground-bounce.test.js@@ -1,7 +1,7 @@import test from 'node:test';import assert from 'node:assert/strict';import { createEnvironmentMap, computeIrradianceCoefficients, evaluateIrradiance } from '../src/environment.js';-import { withGroundBounce } from '../src/ground-bounce.js';+import { findGroundSurface, groundBounceEnvironment, withGroundBounce } from '../src/ground-bounce.js';const WIDTH = 8;const HEIGHT = 4;@@ -15,42 +15,112 @@ function pixel(map, column, row) {return Array.from(map.data.slice(offset, offset + 3));}-test('the lower half becomes albedo times the sky and sun on the ground, and the upper half is kept', () => {+test('the diffuse copy has albedo times the sky and sun on the ground in its lower half and the sky above', () => {const sky = uniformSky(0.5);const bounced = withGroundBounce(sky, { albedo: [0.4, 0.2, 0.1], keyColor: [Math.PI, Math.PI, Math.PI], lightDirection: [0, 2, 0] });+ const copy = bounced.irradianceSource;const skyOnGround = evaluateIrradiance(computeIrradianceCoefficients(sky), [0, 1, 0]);- assert.deepEqual(pixel(bounced, 3, 0), pixel(sky, 3, 0));- assert.deepEqual(pixel(bounced, 3, 1), pixel(sky, 3, 1));+ assert.deepEqual(pixel(copy, 3, 0), pixel(sky, 3, 0));+ assert.deepEqual(pixel(copy, 3, 1), pixel(sky, 3, 1));const expected = [0.4, 0.2, 0.1].map((albedo, index) => albedo * (1 + skyOnGround[index]));- pixel(bounced, 3, 3).forEach((value, index) => assert.ok(Math.abs(value - expected[index]) < 1e-5));- assert.deepEqual(pixel(bounced, 0, 2), pixel(bounced, 7, 3));+ pixel(copy, 3, 3).forEach((value, index) => assert.ok(Math.abs(value - expected[index]) < 1e-5));+ assert.deepEqual(pixel(copy, 0, 2), pixel(copy, 7, 3));});-test('a sun below the horizon, black albedo or no sun leaves only the sky term', () => {- const sky = uniformSky(0.5);- const skyOnGround = evaluateIrradiance(computeIrradianceCoefficients(sky), [0, 1, 0]);- const night = withGroundBounce(sky, { albedo: [1, 1, 1], keyColor: [5, 5, 5], lightDirection: [0, -1, 0] });- assert.ok(Math.abs(pixel(night, 0, 3)[0] - skyOnGround[0]) < 1e-5);- const black = withGroundBounce(sky, { albedo: [0, 0, 0], keyColor: [5, 5, 5], lightDirection: [0, 1, 0] });- assert.deepEqual(pixel(black, 0, 3), [0, 0, 0]);-});--test('the map keeps its intensity, rotation and size, and the input map is not changed', () => {+test('the background and the reflections keep the original sky', () => {const sky = uniformSky(0.5, { intensity: 2, rotation: 1, showBackground: true });const before = Array.from(sky.data);const bounced = withGroundBounce(sky, { albedo: [0.5, 0.5, 0.5], keyColor: [1, 1, 1], lightDirection: [0, 1, 0] });+ assert.equal(bounced.data, sky.data);assert.equal(bounced.intensity, 2);assert.equal(bounced.rotation, 1);assert.equal(bounced.showBackground, true);- assert.equal(bounced.width, WIDTH);assert.deepEqual(Array.from(sky.data), before);});-test('the bounce lights a wall: a vertical normal gets more irradiance than the sky alone gave', () => {+test('a sun below the horizon, black albedo or no sun leaves only the sky term', () => {+ const sky = uniformSky(0.5);+ const skyOnGround = evaluateIrradiance(computeIrradianceCoefficients(sky), [0, 1, 0]);+ const night = withGroundBounce(sky, { albedo: [1, 1, 1], keyColor: [5, 5, 5], lightDirection: [0, -1, 0] });+ assert.ok(Math.abs(pixel(night.irradianceSource, 0, 3)[0] - skyOnGround[0]) < 1e-5);+ const black = withGroundBounce(sky, { albedo: [0, 0, 0], keyColor: [5, 5, 5], lightDirection: [0, 1, 0] });+ assert.deepEqual(pixel(black.irradianceSource, 0, 3), [0, 0, 0]);+});++test('the bounce lights a wall: a sideways normal gets more irradiance from the diffuse copy', () => {const sky = uniformSky(0.5);const sideways = [1, 0, 0];+ const bounced = withGroundBounce(sky, { albedo: [0.9, 0.9, 0.9], keyColor: [3, 3, 3], lightDirection: [0, 1, 0] });const plain = evaluateIrradiance(computeIrradianceCoefficients(sky), sideways);- const bounced = withGroundBounce(sky, { albedo: [0.4, 0.4, 0.4], keyColor: [3, 3, 3], lightDirection: [0, 1, 0] });- const lit = evaluateIrradiance(computeIrradianceCoefficients(bounced), sideways);- assert.ok(lit[0] > plain[0] * 0.5);+ const lit = evaluateIrradiance(computeIrradianceCoefficients(bounced.irradianceSource), sideways);+ assert.ok(lit[0] > plain[0]);+});++function slab(name, center, size, material) {+ const corners = [];+ for (const x of [-0.5, 0.5]) for (const y of [-0.5, 0.5]) for (const z of [-0.5, 0.5]) corners.push(x, y, z);+ const matrix = new Float32Array([size[0], 0, 0, 0, 0, size[1], 0, 0, 0, 0, size[2], 0, ...center, 1]);+ const indices = new Uint32Array([0, 1, 3, 0, 3, 2, 4, 6, 7, 4, 7, 5, 0, 4, 5, 0, 5, 1, 2, 3, 7, 2, 7, 6, 0, 2, 6, 0, 6, 4, 1, 5, 7, 1, 7, 3]);+ return { name, geometry: { positions: new Float32Array(corners), indices }, matrix, material };+}++const GRASS = { tag: 'surface', color: [0.2, 0.4, 0.1], metallic: 0, roughness: 0.9 };+const environmentOf = map => ({ map, keyColor: [3, 3, 3], lightDirection: [-3, 6, 4] });++function openScene(floorMaterial = GRASS) {+ return [slab('floor', [0, -0.05, 0], [40, 0.1, 40], floorMaterial), slab('wall', [0, 2, 0], [6, 4, 0.2], { tag: 'surface', color: [0.5, 0.5, 0.5] })];+}++test('the floor is the lowest thin part that spans the scene, and its albedo is its colour', () => {+ assert.deepEqual(findGroundSurface(openScene()), { albedo: [0.2, 0.4, 0.1] });+ assert.deepEqual(findGroundSurface(openScene({ ...GRASS, metallic: 0.2 })).albedo.map(value => Number(value.toFixed(2))), [0.16, 0.32, 0.08]);+});++test('no floor, a textured, metal, water or lone part gives no ground', () => {+ assert.equal(findGroundSurface(openScene().slice(1)), null);+ assert.equal(findGroundSurface(openScene({ ...GRASS, map: { image: {} } })), null);+ assert.equal(findGroundSurface(openScene({ ...GRASS, metallic: 1 })), null);+ assert.equal(findGroundSurface(openScene({ ...GRASS, tag: 'liquid' })), null);+ assert.equal(findGroundSurface([openScene()[0]]), null);+});++test('an open scene with a floor gets one bounced map, the same object on every call', () => {+ const parts = openScene();+ const environment = environmentOf(uniformSky(0.5));+ const first = groundBounceEnvironment(parts, environment);+ assert.ok(first.map.irradianceSource);+ assert.equal(groundBounceEnvironment(parts, environment).map, first.map);+});++test('a baked part, a closed room, no floor, no map or groundBounce false keep the environment', () => {+ const environment = environmentOf(uniformSky(0.5));+ const baked = openScene().map(part => ({ ...part, material: { ...part.material, lightMap: {} } }));+ assert.equal(groundBounceEnvironment(baked, environment), environment);+ assert.equal(groundBounceEnvironment(openScene().slice(1), environment), environment);+ assert.equal(groundBounceEnvironment(openScene(), { ...environment, map: undefined }).map, undefined);+ assert.equal(groundBounceEnvironment(openScene(), { ...environment, groundBounce: false }).map, environment.map);+ const room = [+ slab('floor', [0, -0.05, 0], [8, 0.1, 8], GRASS), slab('ceiling', [0, 3.05, 0], [8, 0.1, 8], GRASS),+ slab('back', [0, 1.5, -4.05], [8, 3.2, 0.1], GRASS), slab('front', [0, 1.5, 4.05], [8, 3.2, 0.1], GRASS),+ slab('left', [-4.05, 1.5, 0], [0.1, 3.2, 8], GRASS), slab('right', [4.05, 1.5, 0], [0.1, 3.2, 8], GRASS),+ ];+ assert.equal(groundBounceEnvironment(room, environment), environment);+});++test('an automatic floor gives its albedo when no part forms one, and keyIntensity scales the sun', () => {+ const parts = openScene().slice(1).concat(slab('block', [0, 1, 2], [1, 1, 1], GRASS));+ const environment = environmentOf(uniformSky(0.5));+ const albedo = [0.22, 0.22, 0.21];+ const lit = groundBounceEnvironment(parts, environment, { automaticAlbedo: albedo });+ assert.ok(lit.map.irradianceSource);+ const dimmer = groundBounceEnvironment(parts, { ...environment, keyIntensity: 0 }, { automaticAlbedo: albedo });+ assert.ok(pixel(dimmer.map.irradianceSource, 0, 3)[0] < pixel(lit.map.irradianceSource, 0, 3)[0]);+});++test('a point, spot or area light keeps the environment, as the term knows only the sun and the sky', () => {+ const environment = environmentOf(uniformSky(0.5));+ for (const field of ['pointLights', 'spotLights', 'areaLights']) {+ assert.equal(groundBounceEnvironment(openScene(), { ...environment, [field]: [{}] }).map, environment.map);+ }+ assert.ok(groundBounceEnvironment(openScene(), { ...environment, pointLights: [] }).map.irradianceSource);});diff --git a/tests/support/preview-harness.mjs b/tests/support/preview-harness.mjsindex 198f4b86..0422eecd 100644--- a/tests/support/preview-harness.mjs+++ b/tests/support/preview-harness.mjs@@ -77,7 +77,7 @@ export function previewHarness() {applyProjection, mat4, resolveAgentShadow, agentEnvironmentMap, agentSceneModule, BRANCH_LIMITS, createBranchStore, printableLabel,Renderer67: FaultInjectedRenderer, skyOpenness: () => 1, fogSkyVisibility: () => null,// The fault-injected renderer has no floor part; the automatic floor is covered by agent-ground.test.js and the live smokes.- agentGroundPlacement: () => null, createAgentGround: () => null, placeAgentGround: () => {},+ agentGroundPlacement: () => null, createAgentGround: () => null, placeAgentGround: () => {}, FLOOR_COLOR: [0.22, 0.22, 0.21], groundBounceEnvironment: (parts, environment) => environment,// The optional addons only plug stages into a real renderer; the fault-injected one needs none.installCameraEffects: renderer => renderer, installRenderPasses: renderer => renderer,});