3D engine that AI agents drive
Merge origin/main and draw the outdoor shadow fill by giving its map the method that adds it (part of #392)
Nguyen Xuan An98cc98d9f3af
diff --cc changes/392.mdindex 8a49eb9d,00000000..e8084f7emode 100644,000000..100644--- a/changes/392.md+++ b/changes/392.md@@@ -1,1 -1,0 +1,1 @@@- - Add the light that emissive parts send to the rest of an open scene to the preview environment (`groundBounceEnvironment`, issue #392). Their emitted power, per colour channel, over the area of the scene without its ground, times the mean albedo over one minus it, is added to the map's `bounce` colour, so windows and lamps warm the facades and streets around them with no per-frame or shader cost. A closed room, a baked scene, a scene with only mapped emission or with next to no emission is unchanged, and `environment.emissiveSpill: false` turns it off. On `megacity-dusk` (SwiftShader against a fresh Cycles render) FLIP goes from 0.1580 to 0.1364 and the facade slices of the picture from 0.75-0.77 to 0.96-1.07 of Cycles; the seven other scenes checked draw the same pixels.++- Fix the outdoor shadow fill never being drawn (issue #392, part of #351): `groundBounceEnvironment` set the fill as the map's `bounce` colour but not the `irradianceWithBounce` method the renderer calls to add it, so the colour was ignored. A map with a fill now carries the method, as the room bounce does. In `megacity-dusk` (SwiftShader against a fresh Cycles render) the facade slices of the picture go from 0.75-0.77 to 0.95-1.05 of Cycles' luminance and FLIP from 0.1580 to 0.1340; `mountain-valley`, `fog-valley`, `subsurface` and `subsurface-off` get a lighter shadow too, and the other 16 reference scenes checked draw the same pixels.diff --cc src/ground-bounce.jsindex cc5925c1,7d183c04..6f39ad5e--- a/src/ground-bounce.js+++ b/src/ground-bounce.js@@@ -434,8 -371,9 +371,9 @@@ export function groundBounceEnvironmentreturn environment}const ground = groundOf(parts, automaticAlbedo)+ const fill = outdoorFillBounce(parts, environment, ground)if (!ground) {- return environment- return fill ? { ...environment, map: { ...environment.map, bounce: fill } } : environment++ return fill ? { ...environment, map: { ...environment.map, bounce: fill, irradianceWithBounce } } : environment}const { lightDirection } = environmentconst keyColor = environment.keyColor.map(channel => channel * (environment.keyIntensity ?? 1))@@@ -443,7 -381,8 +381,8 @@@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 }))+ const bounced = withGroundBounce(environment.map, { albedo: ground.albedo, keyColor, lightDirection })- byInputs.set(key, fill ? { ...bounced, bounce: fill } : bounced)++ byInputs.set(key, fill ? { ...bounced, bounce: fill, irradianceWithBounce } : bounced)}return { ...environment, map: byInputs.get(key) }}diff --cc tests/ground-bounce.test.jsindex 99758a59,dfd9e500..415a21db--- a/tests/ground-bounce.test.js+++ b/tests/ground-bounce.test.js@@@ -144,24 -144,16 +144,21 @@@ test('the mean of a texture is found onassert.ok(findGroundSurface(openScene({ ...GRASS, map })).albedo[0] > 0.1);});- const LAMP_WINDOW = { tag: 'surface', color: [1, 0.7, 0.35], emission: 4 };-- test('emissive parts of an open scene add their spill to the map bounce, tinted by their colour', () => {- const environment = environmentOf(uniformSky(0.5));- const lit = [...openScene(), slab('windows', [0, 2, 1], [4, 2, 0.2], LAMP_WINDOW)];- const spill = emissiveSpill(lit);- assert.ok(spill[0] > spill[1] && spill[1] > spill[2] && spill[2] > 0);- const bounced = groundBounceEnvironment(lit, environment);- assert.deepEqual(bounced.map.bounce, spill);- assert.ok(bounced.map.irradianceSource);- });-- test('a scene with no emission, a faint one, a mapped one or emissiveSpill false keeps its map bounce', () => {- const environment = environmentOf(uniformSky(0.5));- assert.equal(emissiveSpill(openScene()), null);- assert.equal(groundBounceEnvironment(openScene(), environment).map.bounce, undefined);- assert.equal(emissiveSpill([...openScene(), slab('faint', [0, 2, 1], [1, 1, 0.1], { ...LAMP_WINDOW, emission: 0.001 })]), null);- assert.equal(emissiveSpill([...openScene(), slab('sign', [0, 2, 1], [4, 2, 0.2], { ...LAMP_WINDOW, emissiveMap: {} })]), null);- const lit = [...openScene(), slab('windows', [0, 2, 1], [4, 2, 0.2], LAMP_WINDOW)];- assert.equal(groundBounceEnvironment(lit, { ...environment, emissiveSpill: false }).map.bounce, undefined);+ test('a low sun adds a bounce colour to the map, a high sun, no sun or outdoorFill false add none', () => {+ const parts = openScene();+ const lowSun = { map: uniformSky(0.5), keyColor: [3, 3, 3], lightDirection: [-5, 1, 4] };+ const filled = groundBounceEnvironment(parts, lowSun);+ assert.ok(filled.map.irradianceSource);+ assert.ok(filled.map.bounce.every(channel => channel > 0));++ // The renderer adds a bounce through this method; without it the colour is never drawn (issue #392).++ const coefficients = computeIrradianceCoefficients(filled.map);++ const lit = filled.map.irradianceWithBounce(coefficients);++ assert.ok(lit[0] > coefficients[0] && lit[1] > coefficients[1] && lit[2] > coefficients[2]);++ assert.ok(groundBounceEnvironment(parts.slice(1), lowSun).map.irradianceWithBounce);+ assert.equal(groundBounceEnvironment(parts, lowSun).map, filled.map);+ assert.equal(groundBounceEnvironment(parts, environmentOf(uniformSky(0.5))).map.bounce, undefined);+ assert.equal(groundBounceEnvironment(parts, { ...lowSun, keyColor: [0, 0, 0] }).map.bounce, undefined);+ assert.equal(groundBounceEnvironment(parts, { ...lowSun, outdoorFill: false }).map.bounce, undefined);+ const withoutFloor = groundBounceEnvironment(parts.slice(1), lowSun);+ assert.ok(withoutFloor.map.bounce.every(channel => channel > 0));});