Skip to content

3D engine that AI agents drive

Close the corner light leak in the window room probe (#2000)

Nguyen Xuan An6b7a502f395f
diff --git a/bench/reference/interior-exposure.mjs b/bench/reference/interior-exposure.mjs
index a36872e5..5f887adb 100644
--- a/bench/reference/interior-exposure.mjs
+++ b/bench/reference/interior-exposure.mjs
@@ -10,6 +10,7 @@ import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { Client } from '@modelcontextprotocol/client';
import { StdioClientTransport } from '@modelcontextprotocol/client/stdio';
+import { ROOM_CAMERA, ROOM_GEOMETRIES, ROOM_MATERIALS, roomNodes } from './interior-room.mjs';
const argumentsGiven = process.argv.slice(2);
const outputDirectory = resolve(argumentsGiven[0] ?? 'artifacts/1334');
@@ -40,44 +41,12 @@ 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).
const denoise = argumentsGiven.includes('--denoise') ? 'oidn' : false;
-const ROOM = { halfWidth: 4, front: -3, back: 3.5, height: 3, wall: 0.2 };
-const WINDOW = { halfWidth: 1.4, bottom: 0.9, top: 2.4 };
-
-function box(id, translation, scale, material = 'plaster') {
- return { id, geometry: 'block', material, translation, scale };
-}
-
-function roomNodes() {
- const { halfWidth, front, back, height, wall } = ROOM;
- const depth = back - front;
- const middleZ = (front + back) / 2;
- const frontZ = front - wall / 2;
- const sideWidth = halfWidth - WINDOW.halfWidth;
- return [
- box('floor', [0, -wall / 2, middleZ], [halfWidth * 2 + wall * 2, wall, depth + wall * 2], 'wood'),
- box('ceiling', [0, height + wall / 2, middleZ], [halfWidth * 2 + wall * 2, wall, depth + wall * 2]),
- box('wall-left', [-halfWidth - wall / 2, height / 2, middleZ], [wall, height, depth + wall * 2]),
- box('wall-right', [halfWidth + wall / 2, height / 2, middleZ], [wall, height, depth + wall * 2]),
- box('wall-back', [0, height / 2, back + wall / 2], [halfWidth * 2, height, wall]),
- box('front-left', [-(WINDOW.halfWidth + sideWidth / 2), height / 2, frontZ], [sideWidth, height, wall]),
- box('front-right', [WINDOW.halfWidth + sideWidth / 2, height / 2, frontZ], [sideWidth, height, wall]),
- box('front-sill', [0, WINDOW.bottom / 2, frontZ], [WINDOW.halfWidth * 2, WINDOW.bottom, wall]),
- box('front-head', [0, (WINDOW.top + height) / 2, frontZ], [WINDOW.halfWidth * 2, height - WINDOW.top, wall]),
- ...(sealed ? [box('window-pane', [0, (WINDOW.bottom + WINDOW.top) / 2, frontZ], [WINDOW.halfWidth * 2, WINDOW.top - WINDOW.bottom, wall])] : []),
- ...(withoutLawn ? [] : [box('lawn', [0, -wall / 2 - 0.05, front - 20], [80, wall, 40], 'grass')]),
- ];
-}
-
const recipe = {
format: 'crucible.scene', schemaVersion: 1,
- geometries: [{ id: 'block', type: 'box' }],
- materials: [
- { id: 'plaster', color: [0.75, 0.72, 0.66], roughness: 0.9 },
- { id: 'wood', color: [0.45, 0.32, 0.2], roughness: 0.6 },
- { id: 'grass', color: [0.2, 0.3, 0.12], roughness: 1 },
- ],
- nodes: roomNodes(),
- camera: { eye: [0, 1.5, -2.4], target: [0, 1.2, 3], up: [0, 1, 0], fov: 70, near: 0.05, far: 100 },
+ geometries: ROOM_GEOMETRIES,
+ materials: ROOM_MATERIALS,
+ nodes: roomNodes({ sealed, withoutLawn }),
+ camera: ROOM_CAMERA,
environment: {
lightDirection: [0.3, 0.55, -0.8], keyIntensity, environmentIntensity, sunBounce,
sky: { type: 'physical', sunElevation: 33, sunRotation: 20 },
diff --git a/bench/reference/interior-room.mjs b/bench/reference/interior-room.mjs
new file mode 100644
index 00000000..251481ba
--- /dev/null
+++ b/bench/reference/interior-room.mjs
@@ -0,0 +1,42 @@
+// The window room of the interior exposure probe (#1334), shared with the test that pins its sealed walls (#2000).
+// Every wall is a box. The box geometry has bevel 0: the default bevel of 0.08 rounds each edge, and where two rounded
+// boxes meet the rounding leaves a groove that opens to the outside, so sky light came in at the corners of the room.
+
+export const ROOM = { halfWidth: 4, front: -3, back: 3.5, height: 3, wall: 0.2 };
+export const WINDOW = { halfWidth: 1.4, bottom: 0.9, top: 2.4 };
+
+export const ROOM_GEOMETRIES = [{ id: 'block', type: 'box', bevel: 0 }];
+
+export const ROOM_MATERIALS = [
+ { id: 'plaster', color: [0.75, 0.72, 0.66], roughness: 0.9 },
+ { id: 'wood', color: [0.45, 0.32, 0.2], roughness: 0.6 },
+ { id: 'grass', color: [0.2, 0.3, 0.12], roughness: 1 },
+];
+
+export const ROOM_CAMERA = { eye: [0, 1.5, -2.4], target: [0, 1.2, 3], up: [0, 1, 0], fov: 70, near: 0.05, far: 100 };
+
+function box(id, translation, scale, material = 'plaster') {
+ return { id, geometry: 'block', material, translation, scale };
+}
+
+/** `sealed` fills the window with a wall so no light can enter; `withoutLawn` drops the large ground slab. */
+export function roomNodes({ sealed = false, withoutLawn = false } = {}) {
+ const { halfWidth, front, back, height, wall } = ROOM;
+ const depth = back - front;
+ const middleZ = (front + back) / 2;
+ const frontZ = front - wall / 2;
+ const sideWidth = halfWidth - WINDOW.halfWidth;
+ return [
+ box('floor', [0, -wall / 2, middleZ], [halfWidth * 2 + wall * 2, wall, depth + wall * 2], 'wood'),
+ box('ceiling', [0, height + wall / 2, middleZ], [halfWidth * 2 + wall * 2, wall, depth + wall * 2]),
+ box('wall-left', [-halfWidth - wall / 2, height / 2, middleZ], [wall, height, depth + wall * 2]),
+ box('wall-right', [halfWidth + wall / 2, height / 2, middleZ], [wall, height, depth + wall * 2]),
+ box('wall-back', [0, height / 2, back + wall / 2], [halfWidth * 2, height, wall]),
+ box('front-left', [-(WINDOW.halfWidth + sideWidth / 2), height / 2, frontZ], [sideWidth, height, wall]),
+ box('front-right', [WINDOW.halfWidth + sideWidth / 2, height / 2, frontZ], [sideWidth, height, wall]),
+ box('front-sill', [0, WINDOW.bottom / 2, frontZ], [WINDOW.halfWidth * 2, WINDOW.bottom, wall]),
+ box('front-head', [0, (WINDOW.top + height) / 2, frontZ], [WINDOW.halfWidth * 2, height - WINDOW.top, wall]),
+ ...(sealed ? [box('window-pane', [0, (WINDOW.bottom + WINDOW.top) / 2, frontZ], [WINDOW.halfWidth * 2, WINDOW.top - WINDOW.bottom, wall])] : []),
+ ...(withoutLawn ? [] : [box('lawn', [0, -wall / 2 - 0.05, front - 20], [80, wall, 40], 'grass')]),
+ ];
+}
diff --git a/docs/agent-scene.md b/docs/agent-scene.md
index 9be32ecc..1c8765ec 100644
--- a/docs/agent-scene.md
+++ b/docs/agent-scene.md
@@ -83,7 +83,7 @@ The generators also enforce their existing numeric and modeling constraints.
| Type | Fields | Defaults |
| --- | --- | --- |
-| `box` | `bevel`, `subdivisions` | `0.08`, `6` |
+| `box` | `bevel`, `subdivisions` | `0.08`, `6` (walls, floors and ceilings that touch take `bevel: 0`: the rounded edges of two touching boxes leave a groove at the corner that lets sky light into a closed room, #2000) |
| `cylinder` | `segments`, `bevel`, `bevelSegments` | `80`, `0.025`, `6` |
| `sphere` | `segments`, `rings` | `64`, `40` |
| `torus` | `tubeRadius`, `segments`, `sides`, `arc`, `start` | `0.08`, `96`, `24`, `2π`, `0` |
diff --git a/tests/interior-room-corners.test.js b/tests/interior-room-corners.test.js
new file mode 100644
index 00000000..73a8aa9d
--- /dev/null
+++ b/tests/interior-room-corners.test.js
@@ -0,0 +1,43 @@
+// Issue 2000: sky light leaked through the corners of the window room's box walls in the path tracer. The default box
+// bevel rounds every edge, and two rounded boxes that touch leave a groove open to the outside at each corner.
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { createAgentScene } from '../src/agent-scene.js';
+import { createEnvironmentMap } from '../src/environment.js';
+import { renderPathTracedImage } from '../src/path-tracer.js';
+import { ROOM_CAMERA, ROOM_GEOMETRIES, ROOM_MATERIALS, roomNodes } from '../bench/reference/interior-room.mjs';
+
+const SKY_RADIANCE = 1;
+const SUN_STRENGTH = 3;
+const OPTIONS = { width: 160, height: 90, samples: 8, bounces: 3, denoise: false, threads: 1 };
+
+function sealedRoomRecipe(geometries) {
+ return {
+ format: 'crucible.scene', schemaVersion: 1,
+ geometries,
+ materials: ROOM_MATERIALS,
+ nodes: roomNodes({ sealed: true, withoutLawn: true }),
+ camera: ROOM_CAMERA,
+ };
+}
+
+async function brightestSealedPixel(geometries) {
+ const { parts } = createAgentScene(sealedRoomRecipe(geometries));
+ const environment = {
+ keyColor: [SUN_STRENGTH, SUN_STRENGTH, SUN_STRENGTH],
+ lightDirection: [0.3, 0.55, -0.8],
+ map: createEnvironmentMap({ width: 8, height: 4, data: new Float32Array(8 * 4 * 3).fill(SKY_RADIANCE) }),
+ };
+ const image = await renderPathTracedImage({ parts, environment, camera: ROOM_CAMERA }, OPTIONS);
+ return image.linear.reduce((brightest, value) => Math.max(brightest, value), 0);
+}
+
+test('a sealed room built from boxes traces black: no sky light comes in through the wall corners', async () => {
+ assert.equal(ROOM_GEOMETRIES[0].bevel, 0, 'the room boxes must have sharp edges');
+ assert.equal(await brightestSealedPixel(ROOM_GEOMETRIES), 0);
+});
+
+test('the same room with the default rounded boxes does leak, so the check above can fail', async () => {
+ const leaked = await brightestSealedPixel([{ id: 'block', type: 'box' }]);
+ assert.ok(leaked > 0.1, `a sealed room of rounded boxes should leak sky light at its corners, brightest pixel ${leaked}`);
+});