Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Merge origin/main (path tracer) into feat/render-limits-bake

Nguyen Xuan An55c358845336
diff --cc CHANGELOG.md
index 4e9f1dc4,6dd805da..8e8a0b06
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -2,6 -2,7 +2,9 @@@
## Unreleased
++- A path trace job keeps its own `maxSeconds` below the job deadline: the deadline of an image job with `settings.renderer` now reaches `maxSeconds` plus 60 s (it was 60 s plus 2 s per frame, so a 1920x1080 trace of 120 s was cancelled at about 67 s), and the traced PNG may be as large as any job frame (12 MiB, not 1 MiB).
++
+ - Add `67js/addons/path-tracer` (part of issue #57; the Cycles comparison is partial). `renderPathTracedImage({ parts, environment, camera }, options)` draws a still by CPU path tracing against the triangle BVH of the light bake, with next-event estimation for the sun, point, spot and area lights, an importance-sampled environment map, GGX metal, clear coat, glass, maps and cutouts, and a wavelet denoiser, on up to eight module workers. An `image` render job selects it with `settings.renderer: { type: "pathTracer", samples, bounces, denoise, seed, maxSeconds }`; the same recipe and seed give the same PNG, a job past `maxSeconds` fails with no image, and samples, size and ray work are bounded. It loads on demand: the core bundle and the agent scene do not carry it (the limits live in `src/path-tracer-capabilities.js`, listed under `jobs.pathTracer` in `scene_capabilities`; the tool schemas gain one `renderer` field inside the total budget). `npm run reference -- --path-tracer` scores it against Cycles: better than the rasterizer on 7 of the 11 reference scenes (`lit-interior` 0.5055 to 0.1993, `spot-area` 0.1242 to 0.0639), worse on `outdoor-hdri`, `character` and `fog`, mean 0.171 against 0.189. Not drawn: volume fog, normal maps, translucent leaves, caustics, lights seen in mirrors. `src/ray-query.js` now holds the ray query and light falloff that `light-bake` used to carry. `npm run smoke:path-tracer` checks it through MCP.
- Test the docs and the MCP server on clients other than Claude Code (part of issue #69). New `npm run check:tool-schemas` and `tests/other-clients.test.js` check all 22 tool definitions against rules other clients apply: name characters and length, a description under 1024 characters, an object root, a type on every constrained schema, resolvable `$ref`, declared `required` fields, a strict JSON Schema 2020-12 compile (Ajv 8, now a dev dependency) and an empty-argument call. Reports for OpenAI `strict: true` and for Gemini's documented keyword subset list each gap with its schema path; the test fails when a new kind of gap appears. Measured: the MCP SDK client and the MCP Inspector CLI list the 22 tools and call `scene_create`; a draft-07 Ajv compile rejects every tool (`$schema`, then `prefixItems`), strict OpenAI tools would reject the optional-heavy schemas, and nothing was run on Codex, Cursor, Gemini or any non-Anthropic model. A cold Haiku read of only the README and `llms.txt` installed the package and rendered a box but found no route to a PNG without MCP, so `docs/guide.md` gains a tested "Render a PNG from a script without MCP" recipe that the README and `llms.txt` point to; `docs/mcp.md` gains an "Other clients and models" table and no longer pins the standalone launch to 0.9.1. A test checks that every page `llms.txt` and the README link to exists. Schema bytes are unchanged.
- Fix the next agent tool errors (part of issue #66). `scene_review` and `scene_look` with `labels` on an imported asset failed with "needs the mesh code" because asset creation loaded the on-demand scene modules only for mesh edits; it now always does, and a test walks every preview path in a fresh process. `geometries` and `materials` are optional in a recipe. A failed `scene_create` says no scene was created and to call it again. `scene_inspect` on an asset accepts a source-node ID that holds one part and names the parts of one that holds several.
diff --cc bench/reference/harness.js
index 159d581c,5c1f8672..a74a7dd1
--- a/bench/reference/harness.js
+++ b/bench/reference/harness.js
@@@ -103,37 -77,17 +77,50 @@@ async function renderReferenceScene(id
return result;
}
+// Frame time of one scene with and without the light bake: a bake only adds an emissive map to each part, so this shows what it costs to draw.
+async function measureReferenceFrameTime(id, { bake, warmupFrames = 20, measuredFrames = 200 }) {
+ const scene = await REFERENCE_SCENES[id]();
+ const baked = bake ? await bakeScene(scene, {}) : null;
+ const renderer = new Renderer67(document.querySelector('canvas'), baked ? baked.parts : scene.parts, {
+ ground: false, hdr: true, depth: true, samples: 4, pixelRatio: 1, memoryBudgetMiB: 1024, world: true,
+ environment: scene.environment, shadowBounds: scene.shadow,
+ });
+ renderer.resize();
+ const frame = { ...scene.camera, environment: scene.environment, time: 0, exposure: 1, effects: { ambientOcclusion: 0, ambientOcclusionRadius: 0.5 } };
+ // finish() returns before a hardware GPU is done, so reading one pixel back is what waits for the frame.
+ const pixel = new Uint8Array(4);
+ const finishDrawing = () => renderer.context.readPixels(0, 0, 1, 1, renderer.context.RGBA, renderer.context.UNSIGNED_BYTE, pixel);
+ for (let index = 0; index < warmupFrames; index++) {
+ renderer.render(frame);
+ finishDrawing();
+ }
+ const frameMilliseconds = [];
+ for (let index = 0; index < measuredFrames; index++) {
+ const started = performance.now();
+ renderer.render(frame);
+ finishDrawing();
+ frameMilliseconds.push(performance.now() - started);
+ }
+ renderer.dispose();
+ frameMilliseconds.sort((first, second) => first - second);
+ const total = frameMilliseconds.reduce((sum, value) => sum + value, 0);
+ return { baked: Boolean(bake), frames: measuredFrames, meanMilliseconds: total / measuredFrames,
+ medianMilliseconds: frameMilliseconds[Math.floor(measuredFrames / 2)], p95Milliseconds: frameMilliseconds[Math.floor(measuredFrames * 0.95)] };
+}
+
+window.measureReferenceFrameTime = measureReferenceFrameTime;
++
+ async function renderReferencePathTraced(id, options) {
+ const scene = await REFERENCE_SCENES[id]();
+ const { renderPathTracedImage } = await import('/src/path-tracer.js');
+ const result = await renderPathTracedImage({ parts: scene.parts, environment: scene.environment, camera: scene.camera }, options);
+ const canvas = document.createElement('canvas');
+ canvas.width = result.width;
+ canvas.height = result.height;
+ canvas.getContext('2d').putImageData(new ImageData(result.rgba, result.width, result.height), 0, 0);
+ return { image: canvas.toDataURL('image/png').split(',')[1], report: result.report };
+ }
+
window.renderReferenceScene = renderReferenceScene;
+ window.renderReferencePathTraced = renderReferencePathTraced;
window.referenceSceneIds = Object.keys(REFERENCE_SCENES);
diff --cc bench/size/baseline.json
index dfc42b9e,36e2bac9..c257bdd7
--- a/bench/size/baseline.json
+++ b/bench/size/baseline.json
@@@ -14,9 -14,9 +14,9 @@@
},
"bundles": {
"entry:core": {
- "min": 283396,
- "gzip": 80960,
- "brotli": 69030
- "min": 283499,
- "gzip": 80972,
- "brotli": 69112
++ "min": 283595,
++ "gzip": 81018,
++ "brotli": 69071
},
"entry:model": {
"min": 40093,
@@@ -134,24 -139,24 +139,24 @@@
"brotli": 762
},
"entry:agent-scene": {
- "min": 204341,
- "gzip": 62404,
- "brotli": 54057
- "min": 204745,
- "gzip": 62551,
- "brotli": 54219
++ "min": 206699,
++ "gzip": 63263,
++ "brotli": 54923
},
"entry:agent-scene+lazy": {
- "min": 597350,
- "gzip": 202187,
- "brotli": 176409
- "min": 597754,
- "gzip": 202334,
- "brotli": 176571
++ "min": 614147,
++ "gzip": 210233,
++ "brotli": 185269
},
"entry:agent-asset": {
- "min": 298200,
- "gzip": 92709,
- "brotli": 80775
- "min": 299072,
- "gzip": 93045,
- "brotli": 81048
++ "min": 300910,
++ "gzip": 93744,
++ "brotli": 81565
},
"entry:agent-asset+lazy": {
- "min": 632948,
- "gzip": 212517,
- "brotli": 185086
- "min": 633820,
- "gzip": 212853,
- "brotli": 185359
++ "min": 650097,
++ "gzip": 220739,
++ "brotli": 193778
},
"entry:hdri": {
"min": 8075,
@@@ -179,14 -184,14 +184,14 @@@
"brotli": 67034
},
"scene:agent-scene": {
- "min": 313662,
- "gzip": 91569,
- "brotli": 78717
- "min": 314066,
- "gzip": 91720,
- "brotli": 78757
++ "min": 315953,
++ "gzip": 92416,
++ "brotli": 79459
},
"scene:agent-scene+lazy": {
- "min": 706671,
- "gzip": 231355,
- "brotli": 201052
- "min": 707075,
- "gzip": 231506,
- "brotli": 201092
++ "min": 723401,
++ "gzip": 239390,
++ "brotli": 209757
}
}
}
diff --cc bench/size/budgets.json
index be2ff062,f11fd99b..facb2f43
--- a/bench/size/budgets.json
+++ b/bench/size/budgets.json
@@@ -1,12 -1,12 +1,12 @@@
{
- "archiveBytes": 758400,
- "archiveBytes": 781200,
++ "archiveBytes": 786350,
"goals": {
"lit-box": 50000,
"gltf-box": 80000,
"agent-scene": 100000
},
"budgets": {
-- "entry:core": 82600,
++ "entry:core": 82700,
"entry:model": 14400,
"entry:nature": 13200,
"entry:motion": 13600,
@@@ -29,17 -29,18 +29,18 @@@
"entry:grass": 4400,
"entry:clutter": 5300,
"entry:light-bake": 25400,
+ "entry:path-tracer": 12900,
"entry:texture-set": 900,
- "entry:agent-scene": 63700,
- "entry:agent-scene+lazy": 211300,
- "entry:agent-asset": 94600,
- "entry:agent-asset+lazy": 221800,
- "entry:agent-scene": 63900,
- "entry:agent-scene+lazy": 206400,
- "entry:agent-asset": 95000,
- "entry:agent-asset+lazy": 217200,
++ "entry:agent-scene": 64600,
++ "entry:agent-scene+lazy": 214500,
++ "entry:agent-asset": 95700,
++ "entry:agent-asset+lazy": 225200,
"entry:hdri": 3300,
"entry:camera-effects": 8600,
"entry:render-passes": 1700,
"scene:lit-box": 60200,
"scene:gltf-box": 79700,
- "scene:agent-scene": 93500,
- "scene:agent-scene+lazy": 240600
- "scene:agent-scene": 93600,
- "scene:agent-scene+lazy": 236200
++ "scene:agent-scene": 94300,
++ "scene:agent-scene+lazy": 244200
}
}
diff --cc bench/tool-cost-budgets.json
index 7ac742b2,6fc77d65..864fd28e
--- a/bench/tool-cost-budgets.json
+++ b/bench/tool-cost-budgets.json
@@@ -1,16 -1,16 +1,16 @@@
{
- "measured": "2026-11-01: recipe bake and set-bake added as record references with details in scene_capabilities bake (result 10613, budget 10670); total unchanged at 190730 (measured 189633) by shortening the face selection rule description, so scene_create and scene_apply were raised and mesh_edit and mesh_stack lowered. Earlier: 2026-10-31, from scripts/measure-tool-cost.mjs; raised by 800 total and 150 for scene_apply for branch and labels fields (no new tool); raised by 650 total and 80 for scene_apply for clip layers, bone masks and retargeting through MCP; raised by 20 for scene_create and 20 for the scene_capabilities result after merging the expression language with the material graph; was 373388 schema bytes before shared IDs and recipe references; trimmed after the render-passes merge: material graph, depth of field, motion blur and passes details moved to scene_capabilities, budgets set to the measured value plus 0.5% (total 188267, scene_capabilities result 5167); raised by 95 for scene_apply and 690 for the scene_capabilities result for node relations; curve and text geometry entries shortened to a pointer at scene_capabilities curveText, budgets set to the measured value plus 0.5% (total 189468, scene_capabilities result 6399); then six modifier ops (weld, triangulate, edge_split, smooth, simple_deform, cast) added as one compact schema entry with details in scene_capabilities meshModifiers, entry and mesh_stack description shortened: total 190382 (budget unchanged at 190420), mesh_edit 34216 (budget 34220), scene_capabilities result 7042 (budget 7050); mesh_stack 11682 (budget 11690); after merging imported mesh topology with the modifier ops: raised the total to 190480 (measured 190471), mesh_edit to 34300 (measured 34293) and the scene_capabilities result to 7520 (measured 7512) for imported mesh edits; then cloth (recipe cloth, set-cloth, grid geometry) added with the total unchanged at 190480 (measured 189159): physics descriptions shortened and set-physics now takes the same record reference as set-motion, scene_create raised to 62150 and scene_apply lowered to 44130, scene_capabilities result raised to 8190 (measured 8176) for the cloth details; then particles and hair (recipe `particles`, set-particles) added with the total unchanged at 190480 (measured 189642, scene_create raised to 62350 and scene_apply to 44370 for the recipe particles reference and set-particles): the section is one record reference described in scene_capabilities, so the scene_capabilities result rose to 9570 (measured 9523) for the particle and hair fields; after merging the film timeline (recipe timeline, set-timeline) with particles: total 190719 (budget 190730), scene_create 62464, scene_apply 44620, scene_capabilities result 9902",
- "schemaTotalBytes": 190730,
- "measured": "2026-10-31, from scripts/measure-tool-cost.mjs; raised by 800 total and 150 for scene_apply for branch and labels fields (no new tool); raised by 650 total and 80 for scene_apply for clip layers, bone masks and retargeting through MCP; raised by 20 for scene_create and 20 for the scene_capabilities result after merging the expression language with the material graph; was 373388 schema bytes before shared IDs and recipe references; trimmed after the render-passes merge: material graph, depth of field, motion blur and passes details moved to scene_capabilities, budgets set to the measured value plus 0.5% (total 188267, scene_capabilities result 5167); raised by 95 for scene_apply and 690 for the scene_capabilities result for node relations; curve and text geometry entries shortened to a pointer at scene_capabilities curveText, budgets set to the measured value plus 0.5% (total 189468, scene_capabilities result 6399); then six modifier ops (weld, triangulate, edge_split, smooth, simple_deform, cast) added as one compact schema entry with details in scene_capabilities meshModifiers, entry and mesh_stack description shortened: total 190382 (budget unchanged at 190420), mesh_edit 34216 (budget 34220), scene_capabilities result 7042 (budget 7050); mesh_stack 11682 (budget 11690); after merging imported mesh topology with the modifier ops: raised the total to 190480 (measured 190471), mesh_edit to 34300 (measured 34293) and the scene_capabilities result to 7520 (measured 7512) for imported mesh edits; then cloth (recipe cloth, set-cloth, grid geometry) added with the total unchanged at 190480 (measured 189159): physics descriptions shortened and set-physics now takes the same record reference as set-motion, scene_create raised to 62150 and scene_apply lowered to 44130, scene_capabilities result raised to 8190 (measured 8176) for the cloth details; then particles and hair (recipe `particles`, set-particles) added with the total unchanged at 190480 (measured 189642, scene_create raised to 62350 and scene_apply to 44370 for the recipe particles reference and set-particles): the section is one record reference described in scene_capabilities, so the scene_capabilities result rose to 9570 (measured 9523) for the particle and hair fields; after merging the film timeline (recipe timeline, set-timeline) with particles: total 190719 (budget 190730), scene_create 62464, scene_apply 44620, scene_capabilities result 9902; then the path tracer renderer setting (drop z.int bounds, integers still checked by the job validator): total raised to 190830 (measured 190818)",
++ "measured": "2026-10-31, from scripts/measure-tool-cost.mjs; raised by 800 total and 150 for scene_apply for branch and labels fields (no new tool); raised by 650 total and 80 for scene_apply for clip layers, bone masks and retargeting through MCP; raised by 20 for scene_create and 20 for the scene_capabilities result after merging the expression language with the material graph; was 373388 schema bytes before shared IDs and recipe references; trimmed after the render-passes merge: material graph, depth of field, motion blur and passes details moved to scene_capabilities, budgets set to the measured value plus 0.5% (total 188267, scene_capabilities result 5167); raised by 95 for scene_apply and 690 for the scene_capabilities result for node relations; curve and text geometry entries shortened to a pointer at scene_capabilities curveText, budgets set to the measured value plus 0.5% (total 189468, scene_capabilities result 6399); then six modifier ops (weld, triangulate, edge_split, smooth, simple_deform, cast) added as one compact schema entry with details in scene_capabilities meshModifiers, entry and mesh_stack description shortened: total 190382 (budget unchanged at 190420), mesh_edit 34216 (budget 34220), scene_capabilities result 7042 (budget 7050); mesh_stack 11682 (budget 11690); after merging imported mesh topology with the modifier ops: raised the total to 190480 (measured 190471), mesh_edit to 34300 (measured 34293) and the scene_capabilities result to 7520 (measured 7512) for imported mesh edits; then cloth (recipe cloth, set-cloth, grid geometry) added with the total unchanged at 190480 (measured 189159): physics descriptions shortened and set-physics now takes the same record reference as set-motion, scene_create raised to 62150 and scene_apply lowered to 44130, scene_capabilities result raised to 8190 (measured 8176) for the cloth details; then particles and hair (recipe `particles`, set-particles) added with the total unchanged at 190480 (measured 189642, scene_create raised to 62350 and scene_apply to 44370 for the recipe particles reference and set-particles): the section is one record reference described in scene_capabilities, so the scene_capabilities result rose to 9570 (measured 9523) for the particle and hair fields; after merging the film timeline (recipe timeline, set-timeline) with particles: total 190719 (budget 190730), scene_create 62464, scene_apply 44620, scene_capabilities result 9902; then the path tracer renderer setting (drop z.int bounds, integers still checked by the job validator): total raised to 190830 (measured 190818); after merging the render limits and light bake with the path tracer: measured total 190013, scene_create raised to 62680 (measured 62667), scene_apply to 44860 (measured 44852) and the scene_capabilities result to 10620 (measured 10613) for the bake section and job size limits",
+ "schemaTotalBytes": 190830,
"schemaToolBytes": {
- "scene_create": 62700,
- "scene_apply": 44880,
- "mesh_edit": 33400,
- "scene_create": 62480,
- "scene_apply": 44640,
++ "scene_create": 62680,
++ "scene_apply": 44860,
+ "mesh_edit": 34300,
"scene_create_asset": 19310,
- "mesh_stack": 11540
+ "mesh_stack": 11690
},
"schemaOtherToolBytes": 4000,
"resultBytes": {
- "scene_capabilities": 10670,
- "scene_capabilities": 9910,
++ "scene_capabilities": 10620,
"scene_create": 1400,
"scene_inspect": 1400,
"mesh_inspect": 1200,
diff --cc docs/parity.md
index 871d6f7c,7be09cc5..c0327aed
--- a/docs/parity.md
+++ b/docs/parity.md
@@@ -187,7 -187,7 +187,7 @@@ To move to a new Blender release, run `
| Physics > Baking Physics Simulations | partial | Physics records to a timeline in code or when a recipe scene is created, on the main thread. | [film-physics](../tests/film-physics.test.js) | #61 |
| Physics > Simulation Nodes | missing | No node graph. | | #43 |
| Rendering > Render Engines > EEVEE | partial | A WebGL2 rasterizer with PBR, one directional shadow, 8 point lights, fog and bloom. There are no light probes. | [renderer](../tests/renderer.test.js), [scores against EEVEE](../bench/reference/baseline.json) | #52, #53, #55, #56 |
- | Rendering > Render Engines > Cycles | partial | No path tracer. `addons/light-bake` bakes bounced light from point lights and the sun into a lightmap for each part, on the CPU with ray tracing; recipes reach it through the `bake` section and `set-bake` (draft, standard or fine presets; scene_inspect reports bake seconds and skipped parts), but there is no GLB export, no reflection probes, no spot or area lights, no baked AO. On `lit-interior` it brings the score against Cycles from 0.5055 to 0.1444 (`npm run reference -- --bake lit-interior`). | [light-bake](../tests/light-bake.test.js), [recipe bake](../tests/agent-bake.test.js), [frame time](../bench/reference/frame-time.mjs), [lit-interior scene](../bench/reference/scenes.js) | #55, #57 |
-| Rendering > Render Engines > Cycles | partial | A CPU path tracer (`addons/path-tracer`, or `settings.renderer` on an image render job; [path-tracer](path-tracer.md)) draws diffuse, GGX metal, clear coat, glass, maps, cutouts, the sun, point, spot and area lights with soft shadows and the environment map, with a denoiser. At 32 samples its FLIP score against Cycles is better than the rasterizer's on 7 of the 11 reference scenes and worse on `outdoor-hdri`, `character`, `fog` (no volume fog) and `foliage` (equal to 0.0003); the mean is 0.171 against 0.189 (`npm run reference -- --path-tracer`, [bench/reference/path-tracer.json](../bench/reference/path-tracer.json)). It does not trace volume fog, normal maps or translucent leaves, and it is not Cycles parity. `addons/light-bake` bakes bounced light from point lights and the sun into a lightmap for each part, on the CPU with ray tracing; it is code only (no recipe field, no GLB export, no reflection probes, no spot or area lights, no baked AO). On `lit-interior` it brings the score against Cycles from 0.5055 to 0.1444 (`npm run reference -- --bake lit-interior`). | [light-bake](../tests/light-bake.test.js), [path-tracer](../tests/path-tracer.test.js), [lit-interior scene](../bench/reference/scenes.js) | #55, #57 |
++| Rendering > Render Engines > Cycles | partial | A CPU path tracer (`addons/path-tracer`, or `settings.renderer` on an image render job; [path-tracer](path-tracer.md)) draws diffuse, GGX metal, clear coat, glass, maps, cutouts, the sun, point, spot and area lights with soft shadows and the environment map, with a denoiser. At 32 samples its FLIP score against Cycles is better than the rasterizer's on 7 of the 11 reference scenes and worse on `outdoor-hdri`, `character`, `fog` (no volume fog) and `foliage` (equal to 0.0003); the mean is 0.171 against 0.189 (`npm run reference -- --path-tracer`, [bench/reference/path-tracer.json](../bench/reference/path-tracer.json)). It does not trace volume fog, normal maps or translucent leaves, and it is not Cycles parity. `addons/light-bake` bakes bounced light from point lights and the sun into a lightmap for each part, on the CPU with ray tracing; recipes reach it through the `bake` section and `set-bake` (draft, standard or fine presets; scene_inspect reports bake seconds and skipped parts), but there is no GLB export, no reflection probes, no spot or area lights, no baked AO. On `lit-interior` it brings the score against Cycles from 0.5055 to 0.1444 (`npm run reference -- --bake lit-interior`). | [light-bake](../tests/light-bake.test.js), [path-tracer](../tests/path-tracer.test.js), [recipe bake](../tests/agent-bake.test.js), [frame time](../bench/reference/frame-time.mjs), [lit-interior scene](../bench/reference/scenes.js) | #55, #57 |
| Rendering > Render Engines > Workbench | out of scope | A viewport engine for working by hand. | | |
| Rendering > Cameras | partial | Perspective, orthographic views, focal length, animated paths, depth of field from depth and camera motion blur, both repeatable per frame. Object motion blur and bokeh shapes are missing. | [camera-path](../tests/camera-path.test.js), [camera](../tests/camera.test.js), [render-passes](../tests/render-passes.test.js) | #54 |
| Rendering > Lights > Light Objects | partial | One directional light with a shadow, 8 point lights, 8 spot lights and 4 rectangular area lights. Point and spot lights can cast shadows from one 24-tile atlas (a point light takes 6 tiles, a spot light 1). Area lights use a representative point and cast no shadow. The directional shadow is a single map, not cascaded. | [lighting](../tests/lighting.test.js), `npm run reference` scene `spot-area` | #52 |
diff --cc scripts/agent-render-jobs.mjs
index 1bd09793,afc441d6..854ee79c
--- a/scripts/agent-render-jobs.mjs
+++ b/scripts/agent-render-jobs.mjs
@@@ -2,25 -2,14 +2,34 @@@ import { mkdir, open, readFile, writeFi
import { randomUUID, createHash } from 'node:crypto';
import { isAbsolute, join, resolve } from 'node:path';
-import { RENDER_PASS_NAMES, VIDEO_ENCODERS, AUDIO_FILE_PATTERN, MAXIMUM_VIDEO_SECONDS } from '../src/agent-scene-capabilities.js';
+import { RENDER_PASS_NAMES, VIDEO_ENCODERS, AUDIO_FILE_PATTERN, MAXIMUM_VIDEO_SECONDS, MAXIMUM_JOB_SIDE, MAXIMUM_JOB_PIXELS } from '../src/agent-scene-capabilities.js';
import { normalizeFilmTimeline, filmTimelineDuration } from '../src/film-timeline.js';
+ import { PATH_TRACER_JOB_LIMITS } from '../src/path-tracer-capabilities.js';
const UUID =/^[a-f0-9]{8}-[a-f0-9]{4}-[1-8][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/;
const STATES = ['queued', 'running', 'finalizing', 'completed', 'cancelling', 'cancelled', 'failed', 'interrupted'];
const TERMINAL = new Set(['completed', 'cancelled', 'failed', 'interrupted']);
-const DEFAULT_LIMITS = Object.freeze({ maxRecords: 32, maxStoreBytes: 512 * 1024 ** 2, maxOutputBytes: 128 * 1024 ** 2, maxFrameBytes: 1024 ** 2, deadlineMs: 300000, cleanupMs: 5000 });
+/** Hard ceiling on one job's elapsed time. The deadline below it grows with the job's frames and pixels. */
+export const MAXIMUM_JOB_DEADLINE_MS = 30 * 60 * 1000;
+const BASE_DEADLINE_MS = 60 * 1000;
+const FRAME_ALLOWANCE_MS = 2000;
+const REFERENCE_FRAME_PIXELS = 1024 * 576;
+/** A 1920x1080 PNG of a busy scene runs to several MiB, so a frame may be up to 12 MiB. */
+const DEFAULT_LIMITS = Object.freeze({ maxRecords: 32, maxStoreBytes: 512 * 1024 ** 2, maxOutputBytes: 128 * 1024 ** 2, maxFrameBytes: 12 * 1024 ** 2, deadlineMs: MAXIMUM_JOB_DEADLINE_MS, cleanupMs: 5000 });
+
- /** 60 s plus 2 s per frame, scaled up for frames larger than 1024x576, never above the ceiling. */
- export function jobDeadlineMs({ frameCount, width, height }, maximumMs = MAXIMUM_JOB_DEADLINE_MS) {
++/** Time the page needs to start, draw the scene and encode the PNG around a path trace that runs for its whole maxSeconds. */
++const PATH_TRACE_OVERHEAD_MS = 60 * 1000;
++
++/**
++ * 60 s plus 2 s per frame, scaled up for frames larger than 1024x576, never above the ceiling. A path trace may run for
++ * its own maxSeconds, so its deadline also reaches that plus the overhead and the trace stops itself first.
++ */
++export function jobDeadlineMs({ frameCount, width, height, renderer }, maximumMs = MAXIMUM_JOB_DEADLINE_MS) {
+ const sizeScale = Math.max(1, (width * height) / REFERENCE_FRAME_PIXELS);
- return Math.min(maximumMs, Math.ceil(BASE_DEADLINE_MS + frameCount * FRAME_ALLOWANCE_MS * sizeScale));
++ const frameDeadline = Math.ceil(BASE_DEADLINE_MS + frameCount * FRAME_ALLOWANCE_MS * sizeScale);
++ const traceDeadline = renderer?.type === 'pathTracer' ? Math.ceil(renderer.maxSeconds * 1000) + PATH_TRACE_OVERHEAD_MS : 0;
++ return Math.min(maximumMs, Math.max(frameDeadline, traceDeadline));
+}
const MAXIMUM_JSON_BYTES = 1024 ** 2;
const MAXIMUM_ASSET_BYTES = 16 * 1024 ** 2;
/** Sibling folder of the job directories where the runtime keeps GLB exports; the store never reads or counts it. */
@@@ -70,11 -59,10 +79,11 @@@ function jsonCopy(value, maximum = MAXI
}
function settingsFrom(input, clips, recipe) {
- objectKeys(input, ['kind', 'width', 'height', 'fps', 'duration', 'animation', 'motion', 'rendererTime', 'passes', 'timeline', 'audio', 'encoder'], 'settings');
+ objectKeys(input, ['kind', 'width', 'height', 'fps', 'duration', 'animation', 'motion', 'rendererTime', 'passes', 'renderer', 'timeline', 'audio', 'encoder'], 'settings');
if (!['image', 'stills', 'video'].includes(input.kind)) throw new TypeError('kind must be image, stills or video.');
- const width = boundedNumber(input.width, 64, 1024, 'width', true);
- const height = boundedNumber(input.height, 64, 1024, 'height', true);
+ const width = boundedNumber(input.width, 64, MAXIMUM_JOB_SIDE, 'width', true);
+ const height = boundedNumber(input.height, 64, MAXIMUM_JOB_SIDE, 'height', true);
+ if (width * height > MAXIMUM_JOB_PIXELS) throw new RangeError('width x height must not exceed 1920x1080 pixels.');
if (input.kind === 'video' && (width % 2 || height % 2)) throw new RangeError('Video dimensions must be even.');
const fps = boundedNumber(input.fps ?? 24, 1, 30, 'fps', true);
const timelineStart = timelineStartFrom(input, recipe);
diff --cc scripts/agent-runtime.mjs
index e17eeb49,6390ba08..95eee43e
--- a/scripts/agent-runtime.mjs
+++ b/scripts/agent-runtime.mjs
@@@ -6,7 -6,8 +6,8 @@@ import { dirname, isAbsolute, join } fr
import { createRequire } from 'node:module';
import { fileURLToPath } from 'node:url';
import packageMetadata from '../package.json' with { type: 'json' };
-import { AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS, RENDER_PASS_NAMES, RENDER_PASS_DEPTH_RANGE, VIDEO_ENCODERS, MAXIMUM_VIDEO_SECONDS } from '../src/agent-scene-capabilities.js';
+import { AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS, RENDER_PASS_NAMES, RENDER_PASS_DEPTH_RANGE, VIDEO_ENCODERS, MAXIMUM_VIDEO_SECONDS, MAXIMUM_JOB_SIDE, MAXIMUM_JOB_PIXELS, MAXIMUM_MEMORY_MIB } from '../src/agent-scene-capabilities.js';
+ import { PATH_TRACER_CAPABILITIES } from '../src/path-tracer-capabilities.js';
import { createAgentAssetCatalog } from './agent-asset-catalog.mjs';
import { createAgentRenderJobs, EXPORT_DIRECTORY_NAME } from './agent-render-jobs.mjs';
import { createFrameEncoder } from './frame-encoder.mjs';
@@@ -19,10 -20,10 +20,12 @@@ import { sessionProblem } from '../src/
const SCENE_LIMITS = AGENT_SCENE_DEFAULT_LIMITS;
const MAXIMUM_IMAGE_BYTES = 1024 * 1024;
+// A job writes files, not MCP image responses, so a 1920x1080 PNG may be larger than an inline image.
+const MAXIMUM_JOB_FRAME_BYTES = 12 * 1024 * 1024;
// The object ID pass lists the part behind each ID in the job metrics; longer lists are cut and flagged.
const MAXIMUM_OBJECT_NAMES = 1000;
+ // A path trace shares the machine with the person using it, so it takes half of the eight-thread ceiling.
+ const PATH_TRACER_THREADS = 4;
const MAXIMUM_QUEUED_CALLS = 16;
const MAXIMUM_GLB_BYTES = 32 * 1024 * 1024;
const MAXIMUM_KEPT_GLBS = 8;
@@@ -344,6 -345,19 +347,19 @@@ export function createAgentRuntime({ ba
...(shotSample && shotSample.brightness < 1 ? { brightness: shotSample.brightness } : {}),
...(settings.animation ? { animation: { clip: settings.animation.clip, time: settings.animation.start + elapsed } } : {}) };
const renderStarted = performance.now();
+ if (settings.renderer) {
+ const traced = await jobPage.evaluate(input => window.__agentPreview.pathTrace(input), { ...frameInput, options: { width, height, ...settings.renderer, threads: PATH_TRACER_THREADS } });
+ metrics.renderSeconds += (performance.now() - renderStarted) / 1000;
+ metrics.width = width;
+ metrics.height = height;
+ metrics.pathTracer = traced.report;
+ const tracedBytes = Buffer.from(traced.data, 'base64');
- if (tracedBytes.length > MAXIMUM_IMAGE_BYTES) throw new Error('Path traced image exceeded 1 MiB.');
++ if (tracedBytes.length > MAXIMUM_JOB_FRAME_BYTES) throw new Error('Path traced image exceeded 12 MiB.');
+ await writeFile(join(directory, 'render.png.partial'), tracedBytes, { flag: 'wx' });
+ artifacts.push({ temporary: 'render.png.partial', filename: 'render.png', mimeType: 'image/png' });
+ await progress({ frames: 1, maximumPendingFrames: 1 });
+ continue;
+ }
const rendered = await jobPage.evaluate(input => window.__agentPreview.frame(input), frameInput);
metrics.renderSeconds += (performance.now() - renderStarted) / 1000;
if (backend === 'cpu' && !/swiftshader/i.test(rendered.graphics)) throw new Error('CPU job did not select SwiftShader.');
@@@ -464,8 -478,7 +480,8 @@@
maximumVertices: 250000, maximumParts: 4096, maximumTexturePixels: 4194304, maximumJoints: 1024, maximumClips: 256,
commands: ['set-root', 'set-asset-node', 'set-motion', 'set-animation', 'set-material', 'set-camera', 'set-environment', 'set-effects', 'set-shadow'],
},
- jobs: { configured: Boolean(jobRoot), kinds: ['image', 'stills', 'video'], passes: RENDER_PASS_NAMES, maximumActiveJobs: 1,
+ jobs: { configured: Boolean(jobRoot), kinds: ['image', 'stills', 'video'], passes: RENDER_PASS_NAMES, pathTracer: PATH_TRACER_CAPABILITIES, maximumActiveJobs: 1,
+ maximumWidth: MAXIMUM_JOB_SIDE, maximumHeight: MAXIMUM_JOB_SIDE, maximumPixels: MAXIMUM_JOB_PIXELS,
maximumDuration: MAXIMUM_VIDEO_SECONDS, maximumFps: 30, maximumFrames: 900, maximumStills: 8,
encoder: 'H.264', encoders: VIDEO_ENCODERS, audio: Boolean(audioRoot), timeline: true, previewSuspendedDuringJob: true,
glbExport: { maximumBytes: MAXIMUM_GLB_BYTES, maximumKept: MAXIMUM_KEPT_GLBS, maximumTextureSize: 4096 },
diff --cc tests/agent-runtime.test.js
index 5acfdfb7,17a3730e..bac7cbfb
--- a/tests/agent-runtime.test.js
+++ b/tests/agent-runtime.test.js
@@@ -6,7 -6,8 +6,8 @@@ import { readFile } from 'node:fs/promi
import { createServer } from 'node:http';
import { randomUUID } from 'node:crypto';
import { createContext, Script } from 'node:vm';
-import { AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS, RENDER_PASS_NAMES, RENDER_PASS_DEPTH_RANGE, VIDEO_ENCODERS, MAXIMUM_VIDEO_SECONDS } from '../src/agent-scene-capabilities.js';
+import { AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS, RENDER_PASS_NAMES, RENDER_PASS_DEPTH_RANGE, VIDEO_ENCODERS, MAXIMUM_VIDEO_SECONDS, MAXIMUM_JOB_SIDE, MAXIMUM_JOB_PIXELS, MAXIMUM_MEMORY_MIB } from '../src/agent-scene-capabilities.js';
+ import { PATH_TRACER_CAPABILITIES } from '../src/path-tracer-capabilities.js';
import { audioInputArguments, createAudioLibrary, measureStreamSeconds } from '../scripts/job-audio.mjs';
import { filmTimelineDuration, filmTimelineShotStarts, sampleFilmTimeline } from '../src/film-timeline.js';
import { normalizeReview, REVIEW_LIMITS } from '../scripts/agent-review.mjs';
@@@ -99,7 -100,7 +100,7 @@@ async function reviewRuntimeHarness({ f
const context = createContext({ createServer, randomUUID, existsSync: () => true,
readFile: async () => '', packageMetadata: { version: 'test' },
createRequire: () => ({ resolve: () => { throw new Error('no peer in tests'); } }),
- AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS, RENDER_PASS_NAMES, RENDER_PASS_DEPTH_RANGE, VIDEO_ENCODERS, MAXIMUM_VIDEO_SECONDS, MAXIMUM_JOB_SIDE, MAXIMUM_JOB_PIXELS, MAXIMUM_MEMORY_MIB,
- AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS, RENDER_PASS_NAMES, RENDER_PASS_DEPTH_RANGE, VIDEO_ENCODERS, MAXIMUM_VIDEO_SECONDS, PATH_TRACER_CAPABILITIES,
++ AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS, RENDER_PASS_NAMES, RENDER_PASS_DEPTH_RANGE, VIDEO_ENCODERS, MAXIMUM_VIDEO_SECONDS, MAXIMUM_JOB_SIDE, MAXIMUM_JOB_PIXELS, MAXIMUM_MEMORY_MIB, PATH_TRACER_CAPABILITIES,
audioInputArguments, createAudioLibrary, measureStreamSeconds, filmTimelineDuration, filmTimelineShotStarts, sampleFilmTimeline, normalizeReview, REVIEW_LIMITS, isPreviewHost, BRANCH_LIMITS, validateBranchName,
chromium: { launch: async () => browser }, URL, Buffer, process, performance, setTimeout, clearTimeout,
});