3D engine that AI agents drive
Score each recipe bake preset against Cycles
Nguyen Xuan An654dd57d1585
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e6fd45b4..c36647e2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,7 +2,8 @@## Unreleased-- No test asserts real elapsed time any more (issue #179). The relation chain test counts bounds reads, the particle seek test checks a stateless seek in fixed buffers, the material graph test checks the rejection, and the bake and path tracer limit tests run on a fake clock. `smoke-agent-review-close` no longer asserts seconds, `smoke-film-physics` starts its own server instead of assuming port 5173, and both have npm scripts (`smoke:agent-review-close`, `smoke:film-physics`).+- Score the recipe bake presets against Cycles (part of issue #170, open for the frame costs). `standard` scores 0.127 to 0.159 on the three rooms (no bake 0.51), `fine` is no better, and `standard` and `fine` refuse `temple-hall`. Table in `bench/reference/README.md`.+- No test asserts real elapsed time any more (issue #179): work counts and a fake clock replace stopwatches. `smoke:agent-review-close` and `smoke:film-physics` are wired; the second starts its own server.- Remove the AGPL-3.0 `@codepawlhq/orglet-ui` package, React and react-dom from the website (issue #176). The site now uses its own tokens and button in `src/site-tokens.css` and `src/site-controls.js`, and screenshots of the pages match before and after. The site JavaScript drops from 1,778,425 to 1,531,367 bytes. The published package was never affected.- A renderer no longer draws its shadow map a second time on the first frame when the frame has no assembly; the constructor already drew it. On `mountain-valley` that removes 9.72 million shadow triangles from the first frame, with identical pictures (issue #171). `node bench/reference/profile-scene.mjs <scene>` prints where a scene's time goes, and `frame-time.mjs --plain` measures scenes that are too large for the light bake.- Tell an agent when its scene is a closed room with no bake (issue #163). `scene_inspect` now returns a `closed-room-without-bake` diagnostic when 90 percent or more of 48 rays from the middle of the scene hit a front face, and names `bake`; measured against Cycles a closed room goes from 0.1430 and 0.1436 (`dark-shaft`, `temple-hall`) to 0.0609 and 0.0560 once baked. No frame cost and no schema change; agent scene entry grows 884 bytes gzip. `bakeSkyVisibility` in `light-bake` writes only the occlusion map (0.1021 and 0.0856 in under a second) and is not applied automatically. **A closed room without a bake now shows a warning in `scene_inspect`.**diff --git a/bench/reference/README.md b/bench/reference/README.mdindex a8324ecc..4624a51b 100644--- a/bench/reference/README.md+++ b/bench/reference/README.md@@ -318,3 +318,24 @@ Adaptive sampling is not free in quality. On `spot-area` the score is 0.0658 witDenoising a lower sample count (fixed 24 samples with the tracer's filter, threshold 0, against the 64 sample score before the change): `brick-graph` 0.1394 against 0.1370 (0.0024 worse, 17.1 s against 37.3 s) and `character` 0.1164 against 0.1116 (0.0048 worse, 17.2 s against 39.3 s). Both are within 0.005, so a 24 sample still with the filter is a good still on these two scenes at about 45 percent of the time; two scenes are not proof for all.Darker floor in `character` and `outdoor-hdri`: not found, but narrowed. In `outdoor-hdri` the mean display value of the bottom third (the floor) is 225.5 in Cycles, 225.4 in EEVEE, 224.8 in the rasterizer and 217.1 in the tracer, so the rasterizer agrees with Cycles and the tracer alone is darker, by 8.4 of 255 (the scene is bright, so the display curve compresses it; the linear gap is larger). A white furnace test (a diffuse floor of albedo 0.4 under a sky of radiance 1) gives 0.3955 straight down (1 percent low) and 0.588 at a grazing view with the sky reflection, so sampling the environment and the diffuse lobe is not what loses the light. What is left: the sun together with the HDRI, the clamp of 20 on bounced light (`fireflyClamp`), the grazing-angle specular and light from the other parts, none of which was isolated.++## Recipe bake presets (2026-11-02, part of issue #170)++An agent names a preset (`bake: { preset }`), and `standard` and `fine` shrink to the path work budget of 5 million steps (`bake.used`, `bake.reduced`). `npm run reference -- --skip-blender --bake <ids> --bake-preset <name> --probes <ids>` bakes the way a recipe does (`normalizeAgentBake` and `bakeAgentParts`, the scene's own `bakeOptions` ignored) and scores against the Cycles renders already in `artifacts/reference`. The preset rows below carry the room probe a recipe adds with a bake; the no-bake row has none. A preset the budget refuses (the error a recipe gets) draws the scene unbaked and prints `REFUSED`. Whole frame FLIP against Cycles, RTX 3060 shared with other jobs, one run per cell, bake seconds from the harness (not an idle machine):++| Scene | No bake | draft | standard | fine |+| --- | --- | --- | --- | --- |+| `lit-interior` | 0.5055 | 0.2919, 0.5 s, 8,000 texels | 0.1270, 3.4 s, 19,360 texels | 0.1293, 3.3 s, 16,800 texels |+| `brick-room` | 0.5102 | 0.3185, 1.4 s, 37,136 texels | 0.1353, 1.8 s, 42,576 texels | 0.1382, 1.8 s, 37,136 texels |+| `metal-room` | 0.5128 | 0.3187, 0.8 s, 8,816 texels | 0.1594, 3.2 s, 15,936 texels | 0.1624, 4.6 s, 18,336 texels |+| `dark-shaft` | 0.1430 | 0.0791, 0.9 s, 28,208 texels | 0.0610, 2.3 s, 40,336 texels | 0.0603, 2.2 s, 35,664 texels |+| `temple-hall` | 0.1436 | 0.0706, 5.7 s, 285,376 texels | refused (0.1504 drawn unbaked with a probe) | refused (same) |++What the table shows:++- `standard` is the preset to name for a room: it halves the error of `draft` on `lit-interior`, `brick-room` and `metal-room` (3 bounces against 1) and beats the default bake of "Baked rooms and the bounce count" (0.1341, 0.1412, 0.1656) on all three, for 2 to 3.5 s.+- `fine` is no better than `standard`. Its extra samples and density are cut back to the same budget (38 to 77 samples, 3.0 to 4.6 texels per unit), so it ends up within 0.003 of `standard`, slightly worse on three of five rooms, and costs the same or a little more. A recipe gains nothing by asking for it on these scenes.+- `temple-hall` (167 parts, 3 bounces) is out of reach of `standard` and `fine`: even 16 samples at 1 texel per unit pass 5 million steps, so a recipe gets the error and no bake. `draft` works (reduced to 16 samples and 1.29 texels per unit) and scores 0.0706, against 0.0560 for the scene's own tuned options. Reaching `standard` on a hall needs explicit settings within the 24 million explicit limit, or a lower budget floor; this is left open.+- `draft` is a rough preset: one bounce leaves the lit rooms at 0.29 to 0.32, still well under the unbaked 0.51.++Frame costs from the issue (a baked closed room, and the fog glow mip chain on `dark-shaft`) were not measured: `nvidia-smi` showed 14 to 48 percent utilization and 6 to 7 GB in use over 24 seconds while another worker held the GPU, so a number would be a loaded one. The ranges above in this file stay ranges.diff --git a/bench/reference/harness.js b/bench/reference/harness.jsindex 6d92cd41..7714adf8 100644--- a/bench/reference/harness.js+++ b/bench/reference/harness.js@@ -100,6 +100,9 @@ function describeScene(id, scene) {// Blender always gets the original parts: the bake is 67js's approximation of what Cycles computes.async function bakeScene(scene, bakeOptions) {+ if (bakeOptions.preset) {+ return bakeScenePreset(scene, bakeOptions.preset);+ }const { bakeLightmaps } = await import('/src/light-bake.js');const { pointLights, keyColor, lightDirection } = scene.environment;const started = performance.now();@@ -108,6 +111,22 @@ async function bakeScene(scene, bakeOptions) {return { parts: baked.parts, report: baked.report, seconds: (performance.now() - started) / 1000 };}+// The bake an agent gets from `bake: { preset }`: the same settings and budget fit as a recipe. Probes stay out of it and come+// from --probes, as in the other rows.+async function bakeScenePreset(scene, preset) {+ const { normalizeAgentBake, bakeAgentParts } = await import('/src/agent-bake.js');+ const settings = normalizeAgentBake({ preset, probes: false });+ const started = performance.now();+ let baked;+ try {+ baked = bakeAgentParts(scene.parts, new Map(scene.parts.map(part => [part.name, part.matrix])), scene.environment, settings);+ } catch (error) {+ // A recipe would get this error and no bake: the scene is drawn unbaked and the row says so.+ return { parts: scene.parts, report: { refused: error.message, texels: 0 }, seconds: 0 };+ }+ return { parts: baked.parts, report: baked.report, seconds: (performance.now() - started) / 1000 };+}+// The 67js renderer for a scene: light linking from the lights' affects lists, and cascaded sun shadows when asked for.function createSceneRenderer(parts, scene, cascades) {return new Renderer67(document.querySelector('canvas'), applyLightLinks(parts, scene.environment), {diff --git a/bench/reference/run.mjs b/bench/reference/run.mjsindex a3d335cd..f8bec566 100644--- a/bench/reference/run.mjs+++ b/bench/reference/run.mjs@@ -1,6 +1,6 @@// Renders the reference scenes in 67js and Blender, then scores them: npm run reference// --ambient-occlusion <strength> [--ambient-occlusion-radius <units>] turns occlusion on (off by default).-// --bake [<id>,<id>] bakes bounced light into the named scenes (every scene when no ids follow) before 67js draws them;+// --bake [<id>,<id>] [--bake-preset <name>] bakes bounced light into the named scenes (every scene when no ids follow) before 67js draws them;// Blender still gets the plain scene.// --probes [<id>,<id>] adds reflection probes (src/reflection-probes.js) to the named scenes, on top of --bake when both are given.// --ambient <scale> multiplies the light the world gives every surface (0 removes it); with --skip-blender it measures what the world adds.@@ -50,6 +50,10 @@ const bakedSceneIds = bakeFlag >= 0 && bakeValue && !bakeValue.startsWith('--')const skyOnlyFlag = argumentsGiven.indexOf('--sky-only');const [skyTexelsPerUnit, skySamples] = skyOnlyFlag >= 0 ? argumentsGiven[skyOnlyFlag + 1].split(',').map(Number) : [];const skyOnlyOptions = skyOnlyFlag >= 0 ? { skyOnly: true, texelsPerUnit: skyTexelsPerUnit, samples: skySamples } : {};+// --bake-preset <draft|standard|fine> bakes the way a recipe does (`bake: { preset }`): the preset's own samples, bounces and+// texel density, scaled down to the preset's path work budget, and the scene's own `bakeOptions` are ignored. Needs --bake.+const bakePresetFlag = argumentsGiven.indexOf('--bake-preset');+const bakePreset = bakePresetFlag >= 0 ? argumentsGiven[bakePresetFlag + 1] : null;const probesFlag =argumentsGiven.indexOf('--probes');const probesValue = probesFlag >= 0 ? argumentsGiven[probesFlag + 1] : undefined;const probedSceneIds = probesFlag >= 0 && probesValue && !probesValue.startsWith('--') ? probesValue.split(',') : null;@@ -85,7 +89,7 @@ async function renderBackend(backend, serverUrl, graphics) {const describe = backend === 'gpu';const probes = probesFlag >= 0 && (probedSceneIds === null || probedSceneIds.includes(id));const bakesThisScene = bakeFlag >= 0 && (bakedSceneIds === null || bakedSceneIds.includes(id));- const bake = bakesThisScene ? { ...skyOnlyOptions } : null;+ const bake = bakesThisScene ? { ...skyOnlyOptions, ...(bakePreset ? { preset: bakePreset } : {}) } : null;const result = await page.evaluate(([sceneId, shouldDescribe, ambientOcclusion, ambientOcclusionRadius, bakeOptions, cascadeCount, withProbes, ambientScale]) => window.renderReferenceScene(sceneId, { describe: shouldDescribe, ambientOcclusion, ambientOcclusionRadius, bake: bakeOptions, cascades: cascadeCount, probes: withProbes, ambient: ambientScale }), [id, describe, ambientOcclusion, ambientOcclusionRadius, bake, cascades, probes, ambient]);if (result.glError !== 0) throw new Error(`${id} on ${backend} gave WebGL error ${result.glError}.`);graphics[backend] = result.graphics;@@ -95,7 +99,7 @@ async function renderBackend(backend, serverUrl, graphics) {const background = await page.evaluate(sceneId => window.renderReferenceScene(sceneId, { describe: false, backgroundOnly: true }), id);await writeFile(`${WORK_DIRECTORY}/${id}-background.png`, Buffer.from(background.image, 'base64'));}- const bakeNote = result.bake ? `, bake ${result.bake.seconds.toFixed(1)} s, ${result.bake.report.texels} texels` : '';+ const bakeNote = result.bake?.report.refused ? `, bake REFUSED, drawn unbaked: ${result.bake.report.refused}` : result.bake ? `, bake ${result.bake.seconds.toFixed(1)} s, ${result.bake.report.texels} texels${result.bake.report.reduced ? ` (preset reduced to ${result.bake.report.used.samples} samples, ${result.bake.report.used.texelsPerUnit} texels per unit)` : ''}` : '';const probeNote = result.probes ? `, probes ${result.probes.report.placed.length} on ${result.probes.report.partsWithProbe} parts` : '';console.log(`${id} on ${backend}: ${Math.round(performance.now() - started)} ms${bakeNote}${probeNote}`);}