Skip to content

3D engine that AI agents drive

Give a closed room the sky light its surfaces bounce on to each other (#1334)

Nguyen Xuan An5c808b380f63
diff --git a/bench/reference/browser-root-loader.mjs b/bench/reference/browser-root-loader.mjs
new file mode 100644
index 00000000..5ce87371
--- /dev/null
+++ b/bench/reference/browser-root-loader.mjs
@@ -0,0 +1,12 @@
+// A Node module loader that reads the reference scenes' browser paths ("/src/geometry.js") from the repository root.
+import { pathToFileURL } from 'node:url';
+import { resolve as resolvePath } from 'node:path';
+
+const REPOSITORY_ROOT = resolvePath(import.meta.dirname, '../..');
+
+export async function resolve(specifier, context, nextResolve) {
+ if (specifier.startsWith('/src/') || specifier.startsWith('/bench/')) {
+ return nextResolve(pathToFileURL(resolvePath(REPOSITORY_ROOT, `.${specifier}`)).href, context);
+ }
+ return nextResolve(specifier, context);
+}
diff --git a/bench/reference/interior-compare.mjs b/bench/reference/interior-compare.mjs
new file mode 100644
index 00000000..60e0602c
--- /dev/null
+++ b/bench/reference/interior-compare.mjs
@@ -0,0 +1,48 @@
+// Prints the mean luminance of PNG files (display 0 to 255 and linear 0 to 1, Rec. 709 weights) and the RMSE (0 to 255) of
+// each file against the first one (issue #1334).
+// node bench/reference/interior-compare.mjs <reference.png> [other.png ...]
+import sharp from 'sharp';
+
+const WEIGHTS = [0.2126, 0.7152, 0.0722];
+
+function toLinear(display) {
+ const unit = display / 255;
+ return unit <= 0.04045 ? unit / 12.92 : ((unit + 0.055) / 1.055) ** 2.4;
+}
+
+async function readPixels(path) {
+ const { data, info } = await sharp(path).removeAlpha().raw().toBuffer({ resolveWithObject: true });
+ return { data, pixelCount: info.width * info.height };
+}
+
+function means({ data, pixelCount }) {
+ let display = 0;
+ let linear = 0;
+ for (let pixel = 0; pixel < pixelCount; pixel++) {
+ let displayLuma = 0;
+ let linearLuma = 0;
+ for (let channel = 0; channel < 3; channel++) {
+ displayLuma += WEIGHTS[channel] * data[pixel * 3 + channel];
+ linearLuma += WEIGHTS[channel] * toLinear(data[pixel * 3 + channel]);
+ }
+ display += displayLuma;
+ linear += linearLuma;
+ }
+ return { display: display / pixelCount, linear: linear / pixelCount };
+}
+
+function rmse(first, second) {
+ if (first.pixelCount !== second.pixelCount) return NaN;
+ let total = 0;
+ for (let index = 0; index < first.data.length; index++) total += (first.data[index] - second.data[index]) ** 2;
+ return Math.sqrt(total / first.data.length);
+}
+
+const paths = process.argv.slice(2);
+if (paths.length === 0) throw new Error('Pass at least one PNG path: node bench/reference/interior-compare.mjs <reference.png> [other.png ...]');
+const reference = await readPixels(paths[0]);
+for (const path of paths) {
+ const image = path === paths[0] ? reference : await readPixels(path);
+ const { display, linear } = means(image);
+ console.log(`${path} display ${display.toFixed(2)} linear ${linear.toFixed(4)} rmse-vs-first ${rmse(reference, image).toFixed(2)}`);
+}
diff --git a/bench/reference/interior-exposure.mjs b/bench/reference/interior-exposure.mjs
index 5f887adb..b33ac0b7 100644
--- a/bench/reference/interior-exposure.mjs
+++ b/bench/reference/interior-exposure.mjs
@@ -36,6 +36,8 @@ const tightShadow = argumentsGiven.includes('--tight-shadow');
// --raster-only skips the path tracer, for sweeps of the raster alone; --shadow-extent <metres> fits the sun's shadow view to that half width around the room.
const rasterOnly = argumentsGiven.includes('--raster-only');
const shadowExtent = numberAfter('--shadow-extent', 0);
+// --no-floor-sky turns the closed-room sky trace off (environment.floorSkyTrace: false).
+const noFloorSky = argumentsGiven.includes('--no-floor-sky');
const WIDTH = numberAfter('--width', 960);
const HEIGHT = numberAfter('--height', 540);
// --denoise runs the OIDN denoiser on the path traced frame (the default leaves it off so the mean is the raw estimate).
@@ -48,7 +50,7 @@ const recipe = {
nodes: roomNodes({ sealed, withoutLawn }),
camera: ROOM_CAMERA,
environment: {
- lightDirection: [0.3, 0.55, -0.8], keyIntensity, environmentIntensity, sunBounce,
+ lightDirection: [0.3, 0.55, -0.8], keyIntensity, environmentIntensity, sunBounce, ...(noFloorSky ? { floorSkyTrace: false } : {}),
sky: { type: 'physical', sunElevation: 33, sunRotation: 20 },
viewTransform: 'agx',
},
diff --git a/bench/reference/interior-fill-scenes.mjs b/bench/reference/interior-fill-scenes.mjs
new file mode 100644
index 00000000..931a6cc1
--- /dev/null
+++ b/bench/reference/interior-fill-scenes.mjs
@@ -0,0 +1,16 @@
+// Prints the interior sky fill (#1334) that each reference scene gets from the default closed-room sky trace, to see which scenes the fill touches.
+// node --import ./bench/reference/register-browser-root.mjs bench/reference/interior-fill-scenes.mjs [scene names...]
+import { REFERENCE_SCENES } from './scenes.js';
+import { applyDefaultFloorSky } from '../../src/floor-sky-visibility.js';
+
+const requestedNames = process.argv.slice(2);
+const names = requestedNames.length > 0 ? requestedNames : Object.keys(REFERENCE_SCENES);
+for (const name of names) {
+ try {
+ const scene = await REFERENCE_SCENES[name]();
+ const { report } = applyDefaultFloorSky(scene.parts, scene.environment);
+ console.log(`${name}: ${report ? `fill ${(report.interiorFill ?? 0).toFixed(3)} (${report.reason ?? 'traced'})` : 'no sky trace (no sun)'}`);
+ } catch (error) {
+ console.log(`${name}: could not build in node (${String(error.message).slice(0, 60)})`);
+ }
+}
diff --git a/bench/reference/register-browser-root.mjs b/bench/reference/register-browser-root.mjs
new file mode 100644
index 00000000..43a542bb
--- /dev/null
+++ b/bench/reference/register-browser-root.mjs
@@ -0,0 +1,3 @@
+import { register } from 'node:module';
+
+register('./browser-root-loader.mjs', import.meta.url);
diff --git a/changes/1334-interior-fill.md b/changes/1334-interior-fill.md
new file mode 100644
index 00000000..90d9fc15
--- /dev/null
+++ b/changes/1334-interior-fill.md
@@ -0,0 +1 @@
+- A closed room with a window renders closer to the path tracer: its surfaces now get the sky light they bounce on to each other, so the window probe is 1.3 times darker than the tracer instead of 2.6 times (#1334)
diff --git a/changes/1334.size.md b/changes/1334.size.md
new file mode 100644
index 00000000..c1b4e370
--- /dev/null
+++ b/changes/1334.size.md
@@ -0,0 +1 @@
+- scene:agent-scene+lazy: the closed-room sky fill (interiorSkyFill and its helper, 322 bytes gzip) brings a windowed room to 1.34 times under the path tracer instead of 2.6 times, a visible fix of the largest raster-versus-tracer gap measured on interiors
diff --git a/docs/lighting.md b/docs/lighting.md
index 2783beb3..90139b92 100644
--- a/docs/lighting.md
+++ b/docs/lighting.md
@@ -273,4 +273,4 @@ Two shapes were considered: mutable light nodes with independent scene ownership
Run `node --test tests/lighting.test.js` for retained-state checks and `node scripts/smoke-lighting.mjs` with the development server running for linear HDR pixel checks, native GPU timing and before/after laboratory images.
-The recipe path's trace covers every surface of a closed room, not only the floor: the ceiling, walls and props get the sky they can see, so a sealed room renders near black like the path tracer and a room with a window keeps the light that comes through it (#1334, `bench/reference/interior-exposure.mjs`). A recipe that leaves `shadow` out gets a sun shadow view fitted to its bounds when they are wider than the default 7 m view and narrower than 130 m (three automatic cascades past 40 m), so the sun no longer reaches past thin walls: the sealed probe room reads 0.0007 linear against 0.0006 from the path tracer (#1359). A recipe that sets `shadow` to anything but the defaults keeps exactly what it set; one that writes the default values out is read as having left it out. A flat horizontal slab wider than 10 m and under 15 percent as thick as it is wide, counted with the bounds padding (a ground plane) is left out of the fit when other parts exist, so a 1 m object on a 50 m plane keeps the default view and its sharp shadow instead of getting a 40 m one.
+The recipe path's trace covers every surface of a closed room, not only the floor: the ceiling, walls and props get the sky they can see, so a sealed room renders near black like the path tracer and a room with a window keeps the light that comes through it (#1334, `bench/reference/interior-exposure.mjs`). A closed room also gets the sky light its surfaces bounce on to each other (`interiorSkyFill` in `src/floor-sky-visibility.js`, `report.interiorFill`): the traced visibility of every point that sees the room from inside (at most a quarter of its rays escape) is raised by `4 * albedo * open / (1 - albedo * (1 - open))`, at most 0.5, where `open` is one minus the closed-room ray share and `albedo` the mean diffuse albedo of the traced points. A sealed room has `open` 0 and gets nothing; open scenes are not traced this way. On the window probe at exposure 3.6 the raster mean goes from 0.0388 to 0.0758 linear against 0.1014 from the path tracer (2.6 times darker before, 1.34 times after); the gain 4 is fitted on that one room, so it is a calibration, not a measurement of every room (the halls `temple-hall` and `dark-shaft` get fills of 0.13 and 0.09 and their mean moves by 2 percent). A recipe that leaves `shadow` out gets a sun shadow view fitted to its bounds when they are wider than the default 7 m view and narrower than 130 m (three automatic cascades past 40 m), so the sun no longer reaches past thin walls: the sealed probe room reads 0.0007 linear against 0.0006 from the path tracer (#1359). A recipe that sets `shadow` to anything but the defaults keeps exactly what it set; one that writes the default values out is read as having left it out. A flat horizontal slab wider than 10 m and under 15 percent as thick as it is wide, counted with the bounds padding (a ground plane) is left out of the fit when other parts exist, so a 1 m object on a 50 m plane keeps the default view and its sharp shadow instead of getting a 40 m one.
diff --git a/docs/path-tracer.md b/docs/path-tracer.md
index 837f34a4..0e8c11b4 100644
--- a/docs/path-tracer.md
+++ b/docs/path-tracer.md
@@ -39,7 +39,7 @@ Raster against tracer on a daylit interior (#1334, `bench/reference/interior-exp
| 1 | 16.7, 0.0143 | 33.5, 0.0278 | 1.9 |
| 3.6 | 31.9, 0.0385 | 73.1, 0.1042 | 2.7 |
-The sunlit floor patch agrees to within a stop (158.8, 127.2, 82.1 against 134.2, 106.0, 74.2 at exposure 1); the gap sits on the walls and ceiling in shade (display 37 against 17 on the back wall at exposure 1). A sealed room still traces black (0.0006 linear), so the extra light is not leaking sky. To match a raster look with the tracer, lower `effects.exposure` (about 1 where the raster used 3.6 in this room) rather than raising it past its cap of 16.
+The sunlit floor patch agrees to within a stop (158.8, 127.2, 82.1 against 134.2, 106.0, 74.2 at exposure 1); the gap sits on the walls and ceiling in shade (display 37 against 17 on the back wall at exposure 1). A sealed room still traces black (0.0006 linear), so the extra light is not leaking sky. Since #1334 the raster adds the bounced sky light of a closed room (`docs/lighting.md`), which brings this probe from 2.6 times darker than the tracer to 1.34 times; the tracer is still the brighter one. To match a raster look with the tracer, lower `effects.exposure` (about 1 where the raster used 3.6 in this room) rather than raising it past its cap of 16.
- Volume fog: `environment.volumeFog` is traced as a homogeneous medium inside its box, with its `density`, `color` (the scattering albedo), `anisotropy` (Henyey-Greenstein) and `maxDistance`. The distance to each scattering event is drawn from the exact free-flight distribution, so there is no step count and no banding. Every event is lit by next-event estimation (sun, point, spot, area lights and the sky, with shadow rays) and light reaching a surface through the fog is dimmed by it. Fog events count as bounces. `noiseAmount`, `noiseScale`, `drift`, `steps` and the `ambient` glow are rasterizer tricks and are not used.
- Sky strength seen by the camera (native `cycles` kernel only, #1121): `environment.cameraIntensity` (a number of 0 or more, in the units of `map.intensity`; left out, the camera sees the sky at the lighting intensity and nothing changes) is the strength of the sky for a camera ray and for a ray that reaches it from the camera through a cutout, a transparent surface or smooth glass, while the sky keeps lighting the scene at `map.intensity`. It is what Cycles does with a Light Path 'Is Camera Ray' mix in the world, and it replaces a second trace with the opaque surfaces black. The strength applies until the path first bounces off a diffuse or glossy surface, reflects (also off glass), crosses rough glass or a translucent surface, or scatters in fog; sun disks and emissive surfaces are not scaled. The CPU, WebGL and WebGPU tracers ignore it and `report.ignored` says so.
diff --git a/src/floor-sky-visibility.js b/src/floor-sky-visibility.js
index f7864dfe..c5db6eea 100644
--- a/src/floor-sky-visibility.js
+++ b/src/floor-sky-visibility.js
@@ -3,6 +3,7 @@ import { fittedClosedRoomShare, fittedRoomHasWalls } from './fitted-closed-room.
import { buildWorld, cosineDirection, radicalInverse, sceneScale } from './light-bake.js';
import { worldBounds } from './probe-trace.js';
import { createTracer } from './ray-query.js';
+import { partDiffuseAlbedo } from './ground-bounce.js';
// The sunlit patches' lights (src/sun-bounce.js) load with the floor sky trace: both are for a closed room a sun lights.
export { withSunBounce } from './sun-bounce.js';
@@ -25,6 +26,54 @@ export const FLOOR_SKY_STRENGTH = 1;
export const FLOOR_SKY_ROOM_STRENGTH = 0.2;
// A closed room's walls, ceiling and props are traced too (#1334): the raster gave every one of them the whole sky, so a sealed room came out bright.
export const ROOM_SURFACE_SKY_STRENGTH = 1;
+// Upper bound on the interior fill: a room cannot bounce back more of the sky than it lets in.
+export const INTERIOR_FILL_MAXIMUM = 0.5;
+// Fitted against the path tracer on the window room (bench/reference/interior-exposure.mjs): the bounce series alone leaves the raster below the tracer.
+export const INTERIOR_FILL_GAIN = 4;
+
+/**
+ * The share of the open sky's light that a closed room's surfaces get back from each other (#1334). `openShare` is the mean share of
+ * cosine rays from the room's surfaces that escape (a window is a small share), `meanAlbedo` the area-weighted diffuse albedo of the
+ * room. Light that enters bounces: the first bounce keeps albedo x openShare of it and each later bounce keeps albedo x
+ * (1 - openShare), a geometric series. A sealed room (nothing escapes) gets 0.
+ */
+export function interiorSkyFill(openShare, meanAlbedo) {
+ if (!(openShare > 0) || !(meanAlbedo > 0)) return 0;
+ const albedo = Math.min(meanAlbedo, 0.95);
+ const open = Math.min(openShare, 1);
+ return Math.min(INTERIOR_FILL_MAXIMUM, (INTERIOR_FILL_GAIN * albedo * open) / (1 - albedo * (1 - open)));
+}
+
+// A traced point sees the room from inside when at most this share of its rays escape; the outer face of a wall (about half, the ground hides the rest) and the lawn see the sky and are not part of the room.
+const INTERIOR_MAXIMUM_ESCAPE = 0.25;
+
+function isInteriorVertex(escapedShare) {
+ return escapedShare <= INTERIOR_MAXIMUM_ESCAPE;
+}
+
+/**
+ * The fill for the traced parts of a closed room: `openShare` is what the room opens to the sky (1 minus the closed-room ray share); the mean albedo is taken over the points that see
+ * the room from inside (the cut gives every part about the same area per point), and only those points get the fill.
+ * Each traced part is `{ skyVisibility, escapedShares, tracedVertices, albedo }`; their `skyVisibility` is raised in place.
+ */
+function applyInteriorFill(tracedParts, openShare) {
+ let count = 0;
+ let albedoTotal = 0;
+ for (const { escapedShares, tracedVertices, albedo } of tracedParts) {
+ for (const vertex of tracedVertices) {
+ if (!isInteriorVertex(escapedShares[vertex])) continue;
+ count++;
+ albedoTotal += albedo;
+ }
+ }
+ const fill = count > 0 ? interiorSkyFill(openShare, albedoTotal / count) : 0;
+ for (const { skyVisibility, escapedShares, tracedVertices } of tracedParts) {
+ for (const vertex of tracedVertices) {
+ if (isInteriorVertex(escapedShares[vertex])) skyVisibility[vertex] = Math.min(1, skyVisibility[vertex] + fill);
+ }
+ }
+ return fill;
+}
const FLOOR_THINNESS = 0.1;
const FLOOR_MINIMUM_FOOTPRINT_SHARE = 0.02;
@@ -264,6 +313,7 @@ export function applyFloorSkyVisibility(parts, { raysPerTexel = FLOOR_SKY_RAYS,
const worldNormal = [0, 0, 0];
const floors = [];
let totalRays = 0;
+ const tracedParts = [];
const nextParts = parts.slice();
for (const index of cutPartIndices) {
const part = parts[index];
@@ -272,6 +322,7 @@ export function applyFloorSkyVisibility(parts, { raysPerTexel = FLOOR_SKY_RAYS,
if (totalRays + tracedVertices.size * raysPerTexel > maximumRays) return unchanged('too many rays');
const vertexCount = builder.positions.length / 3;
const skyVisibility = new Float32Array(vertexCount).fill(1);
+ const escapedShares = new Float32Array(vertexCount);
for (const vertex of tracedVertices) {
if (performance.now() - started > maxSeconds * 1000) return unchanged('passed maxSeconds');
const local = builder.positions.slice(vertex * 3, vertex * 3 + 3);
@@ -289,6 +340,7 @@ export function applyFloorSkyVisibility(parts, { raysPerTexel = FLOOR_SKY_RAYS,
if (hit.nearestTriangle < 0) escaped++;
}
skyVisibility[vertex] = 1 - strength * (1 - escaped / raysPerTexel);
+ escapedShares[vertex] = escaped / raysPerTexel;
totalRays += raysPerTexel;
}
const cutGeometryResult = {
@@ -301,13 +353,21 @@ export function applyFloorSkyVisibility(parts, { raysPerTexel = FLOOR_SKY_RAYS,
if (builder.hasUvs) cutGeometryResult.uvs = new Float32Array(builder.uvs);
if (builder.hasColors) cutGeometryResult.colors = new Float32Array(builder.colors);
nextParts[index] = Object.freeze({ ...part, geometry: Object.freeze(cutGeometryResult) });
+ const floor = { name: part.name, texels: tracedVertices.size, triangles: indices.length / 3, meanVisibility: 1 };
+ floors.push(floor);
+ const albedo = partDiffuseAlbedo(part.material ?? {});
+ tracedParts.push({ floor, skyVisibility, escapedShares, tracedVertices, albedo: (albedo[0] + albedo[1] + albedo[2]) / 3 });
+ }
+ // A closed room also gets the sky light its surfaces bounce on to each other (#1334): without it every point the window cannot see is as dark as a sealed room.
+ const interiorFill = everySurface ? applyInteriorFill(tracedParts, 1 - roomShare) : 0;
+ for (const { floor, skyVisibility, tracedVertices } of tracedParts) {
let sharedSum = 0;
for (const vertex of tracedVertices) sharedSum += skyVisibility[vertex];
- floors.push({ name: part.name, texels: tracedVertices.size, triangles: indices.length / 3, meanVisibility: tracedVertices.size ? sharedSum / tracedVertices.size : 1 });
+ floor.meanVisibility = tracedVertices.size ? sharedSum / tracedVertices.size : 1;
}
const texels = floors.reduce((total, floor) => total + floor.texels, 0);
const meanVisibility = texels ? floors.reduce((total, floor) => total + floor.meanVisibility * floor.texels, 0) / texels : 1;
- return { parts: Object.freeze(nextParts), report: { floors, texels, meanVisibility, rays: totalRays, seconds: (performance.now() - started) / 1000, reason: null } };
+ return { parts: Object.freeze(nextParts), report: { floors, texels, meanVisibility, interiorFill, rays: totalRays, seconds: (performance.now() - started) / 1000, reason: null } };
}
/** True when the environment has a sun: a key light with a colour and intensity above zero. A recipe that sets neither has the default sun. */
diff --git a/tests/interior-fill.test.js b/tests/interior-fill.test.js
new file mode 100644
index 00000000..806451f3
--- /dev/null
+++ b/tests/interior-fill.test.js
@@ -0,0 +1,92 @@
+// The sky light that a closed room's surfaces bounce on to each other (#1334): the raster darkened every point the window cannot
+// see to the level of a sealed room, while a path tracer lights them with the light that came in.
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { box } from '../src/geometry.js';
+import { applyDefaultFloorSky, interiorSkyFill, INTERIOR_FILL_MAXIMUM } from '../src/floor-sky-visibility.js';
+
+const HALF_WIDTH = 4;
+const FRONT = -3;
+const BACK = 3.5;
+const HEIGHT = 3;
+const WALL = 0.2;
+const SUN = { keyIntensity: 1 };
+
+function slab(name, center, size) {
+ const matrix = new Float32Array([size[0], 0, 0, 0, 0, size[1], 0, 0, 0, 0, size[2], 0, center[0], center[1], center[2], 1]);
+ return { name, geometry: box(0, 1), matrix, material: { color: [0.7, 0.7, 0.7], metallic: 0, roughness: 0.9 } };
+}
+
+// The probe room of bench/reference/interior-exposure.mjs: a window in the front wall, or none when sealed.
+function room({ window }) {
+ const depth = BACK - FRONT;
+ const middleZ = (FRONT + BACK) / 2;
+ const frontZ = FRONT - WALL / 2;
+ const parts = [
+ slab('floor', [0, -WALL / 2, middleZ], [HALF_WIDTH * 2 + WALL * 2, WALL, depth + WALL * 2]),
+ slab('ceiling', [0, HEIGHT + WALL / 2, middleZ], [HALF_WIDTH * 2 + WALL * 2, WALL, depth + WALL * 2]),
+ slab('wall-left', [-HALF_WIDTH - WALL / 2, HEIGHT / 2, middleZ], [WALL, HEIGHT, depth + WALL * 2]),
+ slab('wall-right', [HALF_WIDTH + WALL / 2, HEIGHT / 2, middleZ], [WALL, HEIGHT, depth + WALL * 2]),
+ slab('wall-back', [0, HEIGHT / 2, BACK + WALL / 2], [HALF_WIDTH * 2, HEIGHT, WALL]),
+ ];
+ if (!window) {
+ parts.push(slab('wall-front', [0, HEIGHT / 2, frontZ], [HALF_WIDTH * 2, HEIGHT, WALL]));
+ return parts;
+ }
+ const opening = { halfWidth: 1.4, bottom: 0.9, top: 2.4 };
+ const side = HALF_WIDTH - opening.halfWidth;
+ parts.push(
+ slab('front-left', [-(opening.halfWidth + side / 2), HEIGHT / 2, frontZ], [side, HEIGHT, WALL]),
+ slab('front-right', [opening.halfWidth + side / 2, HEIGHT / 2, frontZ], [side, HEIGHT, WALL]),
+ slab('front-sill', [0, opening.bottom / 2, frontZ], [opening.halfWidth * 2, opening.bottom, WALL]),
+ slab('front-head', [0, (opening.top + HEIGHT) / 2, frontZ], [opening.halfWidth * 2, HEIGHT - opening.top, WALL]),
+ );
+ return parts;
+}
+
+// The mean sky visibility of the vertices whose normal points along `normalAxis` in the direction `normalSign`.
+function faceMean(part, normalAxis, normalSign) {
+ const { skyVisibility, normals } = part.geometry;
+ let sum = 0;
+ let count = 0;
+ for (let vertex = 0; vertex < skyVisibility.length; vertex++) {
+ if (Math.round(normals[vertex * 3 + normalAxis]) !== normalSign) continue;
+ sum += skyVisibility[vertex];
+ count += 1;
+ }
+ return sum / count;
+}
+
+test('the fill follows the bounce series: nothing for a sealed room, more for a brighter and more open room', () => {
+ assert.equal(interiorSkyFill(0, 0.6), 0);
+ assert.equal(interiorSkyFill(0.03, 0), 0);
+ // 4 (fitted gain) x 0.6 x 0.03 / (1 - 0.6 x 0.97)
+ assert.ok(Math.abs(interiorSkyFill(0.03, 0.6) - 0.1722) < 0.001, `got ${interiorSkyFill(0.03, 0.6)}`);
+ assert.ok(interiorSkyFill(0.03, 0.8) > interiorSkyFill(0.03, 0.4));
+ assert.ok(interiorSkyFill(0.06, 0.6) > interiorSkyFill(0.03, 0.6));
+ assert.equal(interiorSkyFill(0.9, 0.9), INTERIOR_FILL_MAXIMUM);
+});
+
+test('a room with a window reports its fill, and a sealed room reports none', () => {
+ const windowed = applyDefaultFloorSky(room({ window: true }), SUN, { maximumTexels: 4000 }).report;
+ const sealed = applyDefaultFloorSky(room({ window: false }), SUN, { maximumTexels: 4000 }).report;
+ assert.ok(windowed.interiorFill > 0.1 && windowed.interiorFill < 0.3, `window room fill ${windowed.interiorFill}`);
+ assert.equal(sealed.interiorFill, 0);
+});
+
+test('the fill lifts the inside faces of a windowed room and leaves its outside faces and a sealed room alone', () => {
+ const windowed = applyDefaultFloorSky(room({ window: true }), SUN, { maximumTexels: 4000 }).parts;
+ const sealed = applyDefaultFloorSky(room({ window: false }), SUN, { maximumTexels: 4000 }).parts;
+ const insideBackWallWindowed = faceMean(windowed.find(part => part.name === 'wall-back'), 2, -1);
+ const insideBackWallSealed = faceMean(sealed.find(part => part.name === 'wall-back'), 2, -1);
+ assert.ok(insideBackWallWindowed > insideBackWallSealed + 0.15, `inside back wall ${insideBackWallWindowed.toFixed(3)} against sealed ${insideBackWallSealed.toFixed(3)}`);
+ assert.ok(insideBackWallSealed < 0.1, `a sealed room stays dark inside: ${insideBackWallSealed.toFixed(3)}`);
+ const outsideRoof = faceMean(windowed.find(part => part.name === 'ceiling'), 1, 1);
+ assert.ok(outsideRoof > 0.9, `the roof stays open to the sky: ${outsideRoof.toFixed(3)}`);
+});
+
+test('an open scene gets no fill', () => {
+ const open = [room({ window: false })[0], room({ window: false })[2]];
+ const { report } = applyDefaultFloorSky(open, SUN, { maximumTexels: 4000 });
+ assert.equal(report.interiorFill ?? 0, 0);
+});