Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Path tracer: draw every sample by default, expose noiseThreshold on render jobs

Nguyen Xuan An32bc64c26d0d
diff --git a/docs/parity.md b/docs/parity.md
index d2f0ac05..553dc7a2 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -187,7 +187,7 @@ To move to a new Blender release, run `node scripts/parity-manual-snapshot.mjs`.
| 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 | 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 draws normal and metallic-roughness maps (issue #129) and runs about 2.8 times faster per thread, and 3.5 to 3.9 times with the shadow-ray change (inferred from 8,360 to about 30,000 paths per second on the demo room), than at that table, whose scores and seconds predate both (the second table in the reference README has the current ones); it draws them on box-projected materials too, stops converged pixels (`noiseThreshold`, which costs `spot-area` some score, see the reference README), and finishes a 1920 by 1080 still of a 181,708 triangle room at 64 samples in 246 s on 8 threads under a job limit now 600 s (it would have missed the old 240 s by 6 s); it does not trace volume fog, translucent leaves, occlusion or emissive maps or light linking, and it is not Cycles parity (its floor is darker than Cycles' in `character` and `outdoor-hdri`, cause not found). `addons/light-bake` bakes bounced light from point, spot and area 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, shrunk deterministically to a ray work budget of 10 million so a preset finishes on a 56 part room; scene_inspect reports what it used, whether it reduced, bake seconds and skipped parts, which include hair, particle and cloth nodes), patterned, textured and emissive parts bake through a second UV set and a `lightMap` slot, GLB export writes the map approximately as `TEXCOORD_1` emissive, but there are no reflection probes and 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, #128 |
+| 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 draws normal and metallic-roughness maps (issue #129) and runs about 2.8 times faster per thread, and 3.5 to 3.9 times with the shadow-ray change (inferred from 8,360 to about 30,000 paths per second on the demo room), than at that table, whose scores and seconds predate both (the second table in the reference README has the current ones); it draws them on box-projected materials too, can stop converged pixels on request (`noiseThreshold`, off by default because it costs `spot-area` score, see the reference README), and finishes a 1920 by 1080 still of a 181,708 triangle room at 64 samples in 246 s on 8 threads with `noiseThreshold` 0.03 (about 8 to 9 minutes with every sample, inferred) under a job limit now 600 s; it does not trace volume fog, translucent leaves, occlusion or emissive maps or light linking, and it is not Cycles parity (its floor is darker than Cycles' in `character` and `outdoor-hdri`, cause not found). `addons/light-bake` bakes bounced light from point, spot and area 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, shrunk deterministically to a ray work budget of 10 million so a preset finishes on a 56 part room; scene_inspect reports what it used, whether it reduced, bake seconds and skipped parts, which include hair, particle and cloth nodes), patterned, textured and emissive parts bake through a second UV set and a `lightMap` slot, GLB export writes the map approximately as `TEXCOORD_1` emissive, but there are no reflection probes and 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, #128 |
| 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, or up to four cascades through `addons/cascaded-shadows` (`shadowCascades` on the renderer and `environment.shadowCascades` in recipes, three by themselves when `shadow.extent` is above 40): scene `long-street` scores 0.1555 against Cycles with one map and 0.1398 with three cascades, for about 0.2 ms more a frame on an RTX 3060 when the camera moves. | [lighting](../tests/lighting.test.js), [cascades](../tests/cascaded-shadows.test.js), `npm run reference` scenes `spot-area` and `long-street` | #52 |
diff --git a/docs/path-tracer.md b/docs/path-tracer.md
index 5d688f9f..3464cc44 100644
--- a/docs/path-tracer.md
+++ b/docs/path-tracer.md
@@ -7,7 +7,7 @@ import { renderPathTracedImage } from '67js/addons/path-tracer';
const { rgba, linear, report } = await renderPathTracedImage(
{ parts, environment, camera }, // the same objects the rasterizer takes
- { width: 960, height: 540, samples: 64, bounces: 8, seed: 0, denoise: true, threads: 4, maxSeconds: 300, noiseThreshold: 0.03 },
+ { width: 960, height: 540, samples: 64, bounces: 8, seed: 0, denoise: true, threads: 4, maxSeconds: 300, noiseThreshold: 0 },
);
```
@@ -36,11 +36,11 @@ Unidirectional path tracing against the triangle BVH that the [light bake](light
| Option | Default | Range | Meaning |
| --- | --- | --- | --- |
| `width`, `height` | 960, 540 | 16 to 4096 | Output size, at most 2,073,600 pixels. |
-| `samples` | 64 | 1 to 1024 | Most paths per pixel. A pixel stops earlier when it has converged (`noiseThreshold`). |
+| `samples` | 64 | 1 to 1024 | Paths per pixel. Every pixel draws all of them unless `noiseThreshold` is above 0. |
| `bounces` | 8 | 1 to 16 | Reflections followed by each path. |
| `seed` | 0 | 0 to 2147483647 | Changes the noise. |
| `threads` | 4 | 1 to 8 | Module workers; the pixels are the same for any count. Without `Worker` it runs on one thread. |
-| `noiseThreshold` | 0.03 | 0 to 1 | A pixel stops once the standard error of its mean luminance, relative to that mean plus 0.05, is under this, checked from 16 samples on and after every 8 more. 0 draws every sample. It reads only the pixel's own samples, so the result is the same on any thread count and band split. `report.averageSamples` says how many paths a pixel took. |
+| `noiseThreshold` | 0 | 0 to 1 (render jobs: 0 to 0.1) | 0 draws every sample. Above 0, a pixel stops once the standard error of its mean luminance, relative to that mean plus 0.05, is under this, checked from 16 samples on and after every 8 more. It costs quality on some scenes (see the table below). It reads only the pixel's own samples, so the result is the same on any thread count and band split. `report.averageSamples` says how many paths a pixel took. |
| `maxSeconds` | 300 | 1 to 1800 | Wall-clock limit. Passing it throws; there is never a partial image. |
| `denoise` | true | boolean | Filters the light with normal, depth and noise guides. |
| `fireflyClamp` | 20 | 1 to 1000 | Largest radiance one bounce may add to a sample. |
@@ -71,12 +71,24 @@ Adaptive sampling, a shadow-ray shortcut and the demo-room still (issue #129, se
| Same, shadow rays skip the surface lookup unless the material is a cutout | 21.0 and 19.1 (1.23 to 1.36 times) | 64 | 4.38, pixels unchanged |
| 24 samples, every pixel | 9.5 | 24 | 5.53 |
| `noiseThreshold` 0.05 | 11.3 | 26.1 | 4.87 |
-| `noiseThreshold` 0.03 (the default) | 14.1 | 34.4 | 4.77 |
+| `noiseThreshold` 0.03 | 14.1 | 34.4 | 4.77 |
| One light drawn at random at the first hit too | 12.9 | 64 | 7.26 |
-Adaptive sampling beats fewer samples at the same cost (4.87 at 11.3 s against 5.53 at 9.5 s) and keeps most of the quality of 64 (4.77 against 4.38 in about half the time, measured before the shadow-ray change). Drawing one light at the first hit halves the time but makes the image noisier than 24 samples cost, so it was not kept.
+Adaptive sampling beats fewer samples at the same cost on this room (4.87 at 11.3 s against 5.53 at 9.5 s), but it is off by default because it costs score against Cycles on other scenes, and quality is why the tracer exists. Score against Cycles (FLIP, lower is better), 64 samples at most, four threads, 960 by 540:
-The 1920 by 1080 still of `tests/fixtures/demo-room.recipe.json` at `samples: 64`, through an MCP image job with 8 threads: 246.4 s in the tracer (229.4 s tracing, the rest the filter), 30.7 samples per pixel on average, 257 s for the whole job (measured, once). That is 6 seconds over the old 240 s job limit, so the limit is now 600. The hair strands were not the cost by themselves: the time was per ray, and every ray was slow.
+| Scene | `noiseThreshold` | Score | Seconds |
+| --- | --- | --- | --- |
+| `spot-area` | 0 (default) | 0.0658 | 37.1 |
+| `spot-area` | 0.008 | 0.0748 | 31.3 |
+| `spot-area` | 0.015 | 0.0847 | 25.1 |
+| `spot-area` | 0.03 | 0.0900 | 21.3 |
+| `lit-interior` | 0.03 | 0.2214 | 106.7 |
+
+`lit-interior` scored 0.1993 at 32 samples before adaptive sampling; it was not re-run with every sample at 64. A render job passes the value as `settings.renderer.noiseThreshold`, 0 to 0.1.
+
+Fewer samples with the denoiser lose little on some scenes: 24 samples scored within 0.005 of 64 on `brick-graph` (0.1394 against 0.1370) and `character` (0.1164 against 0.1116), at about 45 percent of the time. Two scenes are not proof for all. Drawing one light at the first hit halves the time but makes the image noisier than 24 samples cost, so it was not kept.
+
+The 1920 by 1080 still of `tests/fixtures/demo-room.recipe.json` at `samples: 64`, through an MCP image job with 8 threads: 246.4 s in the tracer (229.4 s tracing, the rest the filter), 30.7 samples per pixel on average, 257 s for the whole job (measured, once, with `noiseThreshold` 0.03, the setting at that time). With the default of 0 every pixel draws all 64, so the same still takes about 8 to 9 minutes on 8 free threads (inferred from 246 s at 30.7 average samples: 246 times 64 / 30.7 is about 513 s), inside the 600 s limit but with little room: lower `samples` or pass a `noiseThreshold` for a larger room. That is 6 seconds over the old 240 s job limit, so the limit is now 600. The hair strands were not the cost by themselves: the time was per ray, and every ray was slow.
## Measured
diff --git a/scripts/agent-render-jobs.mjs b/scripts/agent-render-jobs.mjs
index 854ee79c..4bf6b85e 100644
--- a/scripts/agent-render-jobs.mjs
+++ b/scripts/agent-render-jobs.mjs
@@ -139,8 +139,10 @@ function settingsFrom(input, clips, recipe) {
return result;
}
+const FRACTIONAL_RENDERER_FIELDS = new Set(['maxSeconds', 'noiseThreshold']);
+
function rendererFrom(renderer, kind, passes) {
- objectKeys(renderer, ['type', 'samples', 'bounces', 'denoise', 'seed', 'maxSeconds'], 'renderer');
+ objectKeys(renderer, ['type', 'samples', 'bounces', 'denoise', 'seed', 'maxSeconds', 'noiseThreshold'], 'renderer');
if (renderer.type !== 'pathTracer') throw new TypeError('renderer.type must be pathTracer.');
if (kind !== 'image') throw new RangeError('The path tracer renders one image: use kind image.');
if (passes !== undefined) throw new RangeError('The path tracer writes the lit image only: leave passes out.');
@@ -148,7 +150,7 @@ function rendererFrom(renderer, kind, passes) {
const result = { type: 'pathTracer', denoise: renderer.denoise ?? true };
for (const name of Object.keys(PATH_TRACER_JOB_LIMITS)) {
const { minimum, maximum, default: fallback } = PATH_TRACER_JOB_LIMITS[name];
- result[name] = boundedNumber(renderer[name] ?? fallback, minimum, maximum, `renderer ${name}`, name !== 'maxSeconds');
+ result[name] = boundedNumber(renderer[name] ?? fallback, minimum, maximum, `renderer ${name}`, !FRACTIONAL_RENDERER_FIELDS.has(name));
}
return result;
}
diff --git a/scripts/mcp-server.mjs b/scripts/mcp-server.mjs
index 15b2b7f8..a62b1c8a 100644
--- a/scripts/mcp-server.mjs
+++ b/scripts/mcp-server.mjs
@@ -607,7 +607,7 @@ const renderSettings = z.strictObject({
animation: z.strictObject({ clip: z.number().int().min(0), start: z.number().min(0).max(3600).optional() }).optional(),
motion: z.strictObject({ start: z.number().min(0).max(3600).optional() }).optional(),
rendererTime: z.strictObject({ start: z.number().min(0).max(3600).optional(), rate: z.number().min(-16).max(16).optional() }).optional(),
- renderer: z.strictObject({ type: z.literal('pathTracer'), samples: z.number().optional(), bounces: z.number().optional(), denoise: z.boolean().optional(), seed: z.number().optional(), maxSeconds: z.number().optional() }).optional().describe('image only: offline path tracer; limits and skips in scene_capabilities pathTracer.'),
+ renderer: z.strictObject({ type: z.literal('pathTracer'), samples: z.number().optional(), bounces: z.number().optional(), denoise: z.boolean().optional(), seed: z.number().optional(), maxSeconds: z.number().optional(), noiseThreshold: z.number().optional() }).optional().describe('image only: offline path tracer; limits and skips in scene_capabilities pathTracer.'),
timeline: z.strictObject({ start: z.number().min(0).max(60).optional() }).optional().describe('Play the recipe timeline from start (default 0); duration defaults to the rest of it. It owns the motion clock, so leave motion and animation out.'),
audio: z.strictObject({ file: z.string().max(68), offset: z.number().min(0).max(3600).optional() }).optional().describe('Video only: a file name in the --audio folder (.wav, .mp3, .ogg, .flac) mixed in from offset seconds.'),
encoder: z.enum(VIDEO_ENCODERS).optional().describe('Video only: cpu (default) or nvenc.'),
diff --git a/src/path-tracer-capabilities.js b/src/path-tracer-capabilities.js
index 720c6c8e..f9f85c32 100644
--- a/src/path-tracer-capabilities.js
+++ b/src/path-tracer-capabilities.js
@@ -7,10 +7,12 @@ export const PATH_TRACER_JOB_LIMITS = Object.freeze({
bounces: Object.freeze({ minimum: 1, maximum: 16, default: 8 }),
maxSeconds: Object.freeze({ minimum: 1, maximum: 600, default: 120 }),
seed: Object.freeze({ minimum: 0, maximum: 2147483647, default: 0 }),
+ noiseThreshold: Object.freeze({ minimum: 0, maximum: 0.1, default: 0 }),
});
export const PATH_TRACER_CAPABILITIES = Object.freeze({
- setting: 'settings.renderer { type: "pathTracer", samples, bounces, denoise, seed, maxSeconds }; image jobs only, no passes. Past maxSeconds the job fails.',
+ setting: 'settings.renderer { type: "pathTracer", samples, bounces, denoise, seed, maxSeconds, noiseThreshold }; image jobs only, no passes. Past maxSeconds the job fails.',
+ noiseThreshold: 'Default 0 draws every sample. Above 0 a pixel stops once its standard error relative to its mean is under the value, checked from 16 samples on: faster and noisier, and it cost quality on spot-area (score 0.0658 at 0, 0.0900 at 0.03). docs/path-tracer.md has the table.',
skips: 'volume fog, occlusion and emissive maps, translucent leaves, liquids, caustics, depth of field, bloom; the job result lists what the scene asked for.',
limits: PATH_TRACER_JOB_LIMITS,
});
diff --git a/src/path-tracer.js b/src/path-tracer.js
index d6ed178d..5bc5dd1a 100644
--- a/src/path-tracer.js
+++ b/src/path-tracer.js
@@ -18,7 +18,7 @@ export const PATH_TRACER_LIMITS = Object.freeze({
bounces: Object.freeze({ minimum: 1, maximum: 16, fallback: 8 }),
maxSeconds: Object.freeze({ minimum: 1, maximum: 1800, fallback: 300 }),
fireflyClamp: Object.freeze({ minimum: 1, maximum: 1000, fallback: 20 }),
- noiseThreshold: Object.freeze({ minimum: 0, maximum: 1, fallback: 0.03 }),
+ noiseThreshold: Object.freeze({ minimum: 0, maximum: 1, fallback: 0 }),
seed: Object.freeze({ minimum: 0, maximum: 2 ** 31 - 1, fallback: 0 }),
threads: Object.freeze({ minimum: 1, maximum: 8, fallback: 4 }),
});
diff --git a/tests/agent-render-jobs.test.js b/tests/agent-render-jobs.test.js
index cde83369..48f9beef 100644
--- a/tests/agent-render-jobs.test.js
+++ b/tests/agent-render-jobs.test.js
@@ -360,3 +360,23 @@ test('asset digests bind immutable bytes and still/video settings produce only t
}
await controller.close();
});
+
+test('a path tracer job draws every sample unless it passes a noise threshold, which stays within 0 to 0.1', async context => {
+ const root = await temporary(context);
+ const assetBytes = Buffer.from('bounded embedded GLB fixture');
+ const assetId = createHash('sha256').update(assetBytes).digest('hex');
+ const snapshot = { recipe: { format: '67js.asset', assetId }, assetBytes, clips: [{ duration: 5 }] };
+ const controller = await createAgentRenderJobs({ root, limits, async run({ directory }) {
+ await writeFile(join(directory, 'render.png.partial'), Buffer.alloc(32, 1));
+ return { artifacts: [{ temporary: 'render.png.partial', filename: 'render.png', mimeType: 'image/png' }], metrics: {} };
+ } });
+ const submitWith = renderer => controller.submit({ sourceRevision: 1, snapshot, settings: { kind: 'image', width: 64, height: 64, renderer: { type: 'pathTracer', ...renderer } } });
+ const defaulted = await submitWith({});
+ await terminal(controller, defaulted.jobId);
+ assert.equal(controller.status(defaulted.jobId).settings.renderer.noiseThreshold, 0);
+ const adaptive = await submitWith({ noiseThreshold: 0.03 });
+ await terminal(controller, adaptive.jobId);
+ assert.equal(controller.status(adaptive.jobId).settings.renderer.noiseThreshold, 0.03);
+ for (const noiseThreshold of [-0.01, 0.11, Number.NaN]) await assert.rejects(submitWith({ noiseThreshold }), /noiseThreshold/);
+ await controller.close();
+});
diff --git a/tests/path-tracer.test.js b/tests/path-tracer.test.js
index 3c8744aa..2ec860ec 100644
--- a/tests/path-tracer.test.js
+++ b/tests/path-tracer.test.js
@@ -47,6 +47,8 @@ test('the job limits listed for agents match the limits the tracer enforces', ()
assert.equal(PATH_TRACER_JOB_LIMITS[name].default, PATH_TRACER_LIMITS[name].fallback, name);
}
assert.ok(PATH_TRACER_JOB_LIMITS.maxSeconds.maximum <= PATH_TRACER_LIMITS.maxSeconds.maximum);
+ assert.ok(PATH_TRACER_JOB_LIMITS.noiseThreshold.maximum <= PATH_TRACER_LIMITS.noiseThreshold.maximum);
+ assert.equal(PATH_TRACER_JOB_LIMITS.noiseThreshold.default, PATH_TRACER_LIMITS.noiseThreshold.fallback);
});
test('options are validated with their bounds', () => {
@@ -270,7 +272,7 @@ test('a scene sent to a worker gets its ray query back from the arrays', () => {
const NOISY_AND_QUIET = { width: 24, height: 18, samples: 48, bounces: 3, threads: 1, denoise: false };
test('a threshold of zero draws every sample, and a threshold stops the pixels that have converged', async () => {
- const fixed = await renderPathTracedImage(checkerScene(), { ...NOISY_AND_QUIET, noiseThreshold: 0 });
+ const fixed = await renderPathTracedImage(checkerScene(), NOISY_AND_QUIET);
assert.equal(fixed.report.averageSamples, 48);
const adaptive = await renderPathTracedImage(checkerScene(), { ...NOISY_AND_QUIET, noiseThreshold: 0.05 });
assert.ok(adaptive.report.averageSamples < 48, `average ${adaptive.report.averageSamples}`);