Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Budget recipe light bakes by path steps, not by a ray count

Nguyen Xuan Ana290e5da42c2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b8a23b8e..da183ca8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
## Unreleased
+- Fix the recipe light bake budget, which rejected the demo room at samples 96, bounces 2, texelsPerUnit 3 (11.5 s before the budget) and scaled `standard` there to 16 samples (part of issue #55). The ray work estimate multiplied by every light and so overcounted open scenes by about 4 times. The budget now counts path steps (texels x samples x bounces), which cost about the same per path in a closed 56 part room and in the demo room. A preset scales down to 5 million path steps (the demo room at `standard` keeps about 52 samples, not 16); explicit settings are limited only by a hard bound of 24 million path steps and by the real 20 s limit, which fails the edit with the scene unchanged and names a lower samples and texelsPerUnit to try. `bake.used` and `bake.reduced` are unchanged; the capability limit `maxRayWork` is now `maxPathWork`.
- Run the heavy scene kernels on a worker in the MCP preview (part of issue #38; edits after creation still run on the main thread). The light bake, the cloth solver, `uv_unwrap` and pattern textures are pure functions of their input, so `runKernel` in the new `src/kernel-offload.js` computes them inline as before, or, inside `buildWithKernels`, throws `KernelDeferred`, lets a module worker (`kernel-worker.js`, a package entry like the path tracer's) compute the result, caches it by a hash of the input bytes and runs the synchronous build again. The preview builds `scene_create` that way when the page has `Worker`; Node and every other caller keep the synchronous path and the same bytes (a test builds one scene cold in a separate process both ways and compares a digest of geometry, textures and the bake report). A worker error comes back with its class and message, a worker that cannot start or dies leaves the job to the inline path, and an `AbortSignal` ends the build and the worker. Measured in Node on the demo recipe: the `uv_unwrap` stack takes 3.6 s, the draft light bake 7.5 s and the standard bake passes the 20 s limit on this machine, cloth at the 10 s limit takes 3.4 s, a 1024 pattern takes 1 to 7 s, a boolean 0.12 s. Measured in headless Chrome on the GPU backend with the demo room recipe (`tests/fixtures/demo-room.recipe.json`, 9 kernels): the longest stretch the page was unresponsive during `scene_create` fell from 11.8 and 11.9 s to 1.6 s with workers (two runs each), while the build took 12.3 and 12.5 s instead of 10.9 and 11.0 s, because the kernels run one after another and the build reruns after each. `scene_inspect` now reports `kernels`: how many kernels a worker served and how many ran inline, each fallback with its reason (also a `67js kernel fallback` line on stderr when a page that has `Worker` falls back), the build time and the longest block; `npm run smoke:kernel-workers` installs the package, runs the demo room and fails unless kernels ran on the worker with no fallback. The `longtask` observer saw nothing in either mode because the browser does not count work run by a remote-debugging call, so the block is measured with a 20 ms timer. `scene_apply` edits still run on the main thread. Core did not grow (`entry:core`, `lit-box` unchanged); the lazy entries rose by about 900 bytes gzip.
- Fix three gaps a demo film found in the recipe light bake (part of issue #55). A baked scene with `cloth` failed at render time for every frame after t=0 with "A light map needs lightUvs on rigid geometry, with no skin or morph", because the cloth simulation replaces the sheet's geometry each frame; cloth sheet nodes are now skipped and listed in `report.skipped`. The bake now lights with spot lights (the renderer's cone and soft edge) and area lights (front side only, one deterministic shadow ray to a point of the rectangle per hit), where it ignored both; a scene without them bakes the same bytes. The presets could not finish a normal scene (`standard` passed its 20 s limit on a 56 part room, `fine` hit the 30 s preview limit): a recipe bake now has a ray work budget of 10 million units (texels x samples x bounces x rays per hit), estimated from the unwrap before any ray is traced with no clock involved. A preset is scaled down to fit and `scene_inspect` `bake` reports `used` and `reduced`; explicit `samples`, `bounces` or `texelsPerUnit` are never reduced and fail with a message naming the number that fits. `bakeLightmaps` is now `planLightmaps`, `estimateBake` and `traceLightmaps` (still exported as one call). `entry:core` did not change; `entry:light-bake` grew by 1,033 bytes gzip (budget 25,900 to 26,900) and the lazy agent entries by about 1,580; the schema stayed within its total budget (the capability notes were shortened to fit).
- Add `sculpt` and `shrinkwrap` mesh edits (part of issue #47; surface patches and a stack form are not built). `sculpt` applies up to 32 inflate, displace and smooth strokes to the vertices of the selected faces; `shrinkwrap` moves them onto a primitive, to the nearest point or projected along a direction, with an offset. Both are in `scene_capabilities` (`meshSculpt`) and in the `mesh_edit` schema, with the tool schema total unchanged (the face rule and tag prefix descriptions were shortened to pay for them). The stroke maths moved to `src/sculpt-strokes.js` and serves `sculptGeometry` too. Four Blender golden cases (two Shrinkwrap modifier comparisons; the sculpt reference runs the same brush formula on Blender's mesh), hostile input tests, and the suite task `ball-badge`, which needs a plate bent onto a ball.
diff --git a/docs/light-bake.md b/docs/light-bake.md
index c942142b..b49eacdf 100644
--- a/docs/light-bake.md
+++ b/docs/light-bake.md
@@ -30,13 +30,12 @@ const renderer = new Renderer67(canvas, bakedParts, rendererOptions);
Ranges are 1 to 256 samples, 1 to 3 bounces and 1 to 12 texels per unit. The bake lights the rest pose with the recipe's point lights and key light (key colour times `keyIntensity`). It runs when the scene builds and again only when a part, its matrix, a light, a material or the bake fields change: camera edits, effects edits, motion seeks and renders reuse the result. A bake over 20 s fails the edit and leaves the scene as it was. The same recipe gives the same lightmap bytes. `scene_inspect` returns `bake`: the resolved fields, `used` (the samples, bounces and texelsPerUnit that were traced), `reduced`, `texels`, `rayWork`, `seconds` (of the run that made the lightmaps), `bakedParts`, `skipped` (name and reason) and `reused`.
-### Ray work budget
+### Work budget
-A recipe bake may trace 10 million units of ray work (texels x samples x bounces x rays per hit, one bounce ray plus a shadow ray for each light). The unwrap gives the texel count before any ray is traced, so the estimate is plain arithmetic: it reads no clock and does not depend on machine speed, and the same recipe always resolves to the same numbers. The budget was measured on a closed 56 part room, where every path bounces to the end, at about 1.3 million units per second (about 8 s of tracing, under the 20 s limit and the 30 s preview deadline). Open scenes run faster.
+The unwrap gives the texel count before any ray is traced, so the work of a bake is plain arithmetic: path steps, texels x samples x bounces. It reads no clock and does not depend on machine speed, and the same recipe always resolves to the same numbers. Measured on this machine, a path step costs about 1.8 to 3.1 microseconds, in a closed 56 part room and in the 57 node demo room alike (the number of lights did not change it, so it is not counted).
-- A preset (all three fields equal to `draft`, `standard` or `fine`) that is over the budget is scaled down: samples by a fifth and texelsPerUnit by a tenth, repeatedly, until it fits (samples not below 16, texelsPerUnit not below 1). `bake.used` shows the result and `bake.reduced` is `true`. The 57 node demo room at `standard` runs at 16 samples and texelsPerUnit 2.32 instead of 128 and 6 (8.9 million units, 1.8 s of tracing, 52 parts baked; it is an open room, so it traces faster per unit than the closed-room measurement the budget is set on).
-- Explicit `samples`, `bounces` or `texelsPerUnit` (any combination that is not exactly a preset) are never reduced. Over the budget they fail, and the message names what fits, for example "samples 32 or fewer with texelsPerUnit 12, or texelsPerUnit 4.1 or less with samples 256".
-- A scene that cannot fit even 16 samples at texelsPerUnit 1 fails with a message to remove parts or lights.
+- A preset (all three fields equal to `draft`, `standard` or `fine`) is scaled down until it fits 5 million path steps: samples by a fifth and texelsPerUnit by a tenth, repeatedly (samples not below 16, texelsPerUnit not below 1). That is 9 to 16 s of tracing, under the 20 s limit. `bake.used` shows the result and `bake.reduced` is `true`. The demo room at `standard` runs at about 52 samples and texelsPerUnit 3.94 instead of 16 and 2.32 before. A scene that cannot fit even 16 samples at texelsPerUnit 1 fails with a message to remove parts or lights.
+- Explicit `samples`, `bounces` or `texelsPerUnit` (any combination that is not exactly a preset) are never reduced. They are limited by a hard bound of 24 million path steps (about 5 times the demo room at samples 96, bounces 2, texelsPerUnit 3, which bakes in 11 to 17 s), and by the real 20 s limit. Over the bound they fail before any ray is traced and the message names what fits, for example "samples 120 or fewer with texelsPerUnit 12, or texelsPerUnit 8.61 or less with samples 256". Under the bound they run, and one that passes 20 s fails with "The scene is unchanged. Try samples 128, or texelsPerUnit 3.5." (half of what was asked); the clock decides only that failure, never what is traced.
A node that hosts cloth is skipped like a hair host: the cloth simulation replaces its geometry every frame, so a lightmap built on the rest geometry would not follow it (and the renderer refuses a light map on geometry without `lightUvs`, which failed every frame after t=0). Baked parts read every other material field live, so motion tracks on colour still work; the lightmap itself is fixed at the rest pose.
diff --git a/src/agent-bake.js b/src/agent-bake.js
index 5143f3f7..cf1ad29a 100644
--- a/src/agent-bake.js
+++ b/src/agent-bake.js
@@ -1,7 +1,7 @@
import { planLightmaps, estimateBake, traceLightmaps } from './light-bake.js';
import { runKernel } from './kernel-offload.js';
import { knownKeys, finiteNumber } from './agent-recipe-checks.js';
-import { BAKE_PRESETS, BAKE_RANGES, BAKE_MAXIMUM_SECONDS, BAKE_RAY_WORK_BUDGET } from './agent-scene-capabilities.js';
+import { BAKE_PRESETS, BAKE_RANGES, BAKE_MAXIMUM_SECONDS, BAKE_PRESET_PATH_WORK, BAKE_EXPLICIT_PATH_WORK_LIMIT } from './agent-scene-capabilities.js';
const PRESET_SAMPLES_FLOOR = 16;
@@ -39,11 +39,13 @@ function isPreset(settings) {
return Object.values(BAKE_PRESETS).some(preset => Object.keys(preset).every(field => preset[field] === settings[field]));
}
-function fits(plan, settings) {
- return estimateBake(plan, settings).rayWork <= BAKE_RAY_WORK_BUDGET;
+// Path steps in total: texels x samples x bounces. Measured, a path costs about the same in a closed room and in an
+// open one whatever the number of lights, so this tracks the time of a bake better than a count of rays does.
+function pathWorkOf(plan, settings) {
+ return estimateBake(plan, settings).texels * settings.samples * settings.bounces;
}
-// The densest texelsPerUnit, to two decimals, that still fits the budget at the given samples and bounces (0 when none does).
+// The densest texelsPerUnit, to two decimals, that still fits the explicit limit at the given samples and bounces (0 when none does).
function largestFittingTexelsPerUnit(plan, settings) {
let fitting = 0;
let tooMuch = settings.texelsPerUnit;
@@ -52,7 +54,7 @@ function largestFittingTexelsPerUnit(plan, settings) {
if (middle <= fitting) {
break;
}
- if (fits(plan, { ...settings, texelsPerUnit: middle })) {
+ if (pathWorkOf(plan, { ...settings, texelsPerUnit: middle }) <= BAKE_EXPLICIT_PATH_WORK_LIMIT) {
fitting = middle;
} else {
tooMuch = middle;
@@ -61,8 +63,8 @@ function largestFittingTexelsPerUnit(plan, settings) {
return fitting >= BAKE_RANGES.texelsPerUnit[0] ? fitting : 0;
}
-function overBudgetMessage(plan, settings, rayWork) {
- const fittingSamples = Math.floor(BAKE_RAY_WORK_BUDGET * settings.samples / rayWork);
+function overLimitMessage(plan, settings, pathWork) {
+ const fittingSamples = Math.floor(BAKE_EXPLICIT_PATH_WORK_LIMIT * settings.samples / pathWork);
const fittingTexelsPerUnit = largestFittingTexelsPerUnit(plan, settings);
const choices = [];
if (fittingSamples >= BAKE_RANGES.samples[0]) {
@@ -72,34 +74,44 @@ function overBudgetMessage(plan, settings, rayWork) {
choices.push(`texelsPerUnit ${fittingTexelsPerUnit} or less with samples ${settings.samples}`);
}
const advice = choices.length > 0 ? `At bounces ${settings.bounces} this scene fits ${choices.join(', or ')}.` : 'Remove parts or lights, or lower bounces.';
- return `The bake would need ${rayWork} units of ray work (texels x samples x bounces x rays per hit); the limit is ${BAKE_RAY_WORK_BUDGET}. ${advice}`;
+ return `The bake would follow ${pathWork} path steps (texels x samples x bounces); the limit for explicit settings is ${BAKE_EXPLICIT_PATH_WORK_LIMIT}. ${advice}`;
+}
+
+function scalePresetDown(settings) {
+ return {
+ ...settings,
+ samples: Math.max(PRESET_SAMPLES_FLOOR, Math.floor(settings.samples * 0.8)),
+ texelsPerUnit: Math.max(BAKE_RANGES.texelsPerUnit[0], Math.round(settings.texelsPerUnit * 0.9 * 100) / 100),
+ };
}
/**
- * Keeps a bake inside the ray work budget before any ray is traced. The estimate counts texels, samples, bounces and lights,
- * and reads no clock, so the same recipe always resolves to the same settings. A preset is scaled down (samples first by a
- * fifth, texel density by a tenth, repeatedly); explicit samples or texelsPerUnit are never changed and fail instead.
+ * Keeps a bake inside its work limits before any ray is traced. The estimate counts texels, samples and bounces and reads
+ * no clock, so the same recipe always resolves to the same settings. Explicit samples or texelsPerUnit are never changed:
+ * they fail up front only over the hard limit, and otherwise run until the real maxSeconds limit. A preset is scaled down
+ * (samples by a fifth, texel density by a tenth, repeatedly) until it fits BAKE_PRESET_PATH_WORK.
*/
function fitSettingsToBudget(plan, settings) {
- const { rayWork } = estimateBake(plan, settings);
- if (rayWork <= BAKE_RAY_WORK_BUDGET) {
- return { used: settings, reduced: false };
- }
if (!isPreset(settings)) {
- throw new RangeError(overBudgetMessage(plan, settings, rayWork));
+ const pathWork = pathWorkOf(plan, settings);
+ if (pathWork > BAKE_EXPLICIT_PATH_WORK_LIMIT) {
+ throw new RangeError(overLimitMessage(plan, settings, pathWork));
+ }
+ return { used: settings, reduced: false };
}
let used = settings;
- while (!fits(plan, used)) {
+ while (pathWorkOf(plan, used) > BAKE_PRESET_PATH_WORK) {
if (used.samples <= PRESET_SAMPLES_FLOOR && used.texelsPerUnit <= BAKE_RANGES.texelsPerUnit[0]) {
- throw new RangeError(`Even ${PRESET_SAMPLES_FLOOR} samples at texelsPerUnit ${BAKE_RANGES.texelsPerUnit[0]} is over the ray work limit of ${BAKE_RAY_WORK_BUDGET} for this scene. Remove parts or lights, or lower bounces.`);
+ throw new RangeError(`Even ${PRESET_SAMPLES_FLOOR} samples at texelsPerUnit ${BAKE_RANGES.texelsPerUnit[0]} is over the preset budget of ${BAKE_PRESET_PATH_WORK} path steps for this scene. Remove parts or lights, or lower bounces.`);
}
- used = {
- ...used,
- samples: Math.max(PRESET_SAMPLES_FLOOR, Math.floor(used.samples * 0.8)),
- texelsPerUnit: Math.max(BAKE_RANGES.texelsPerUnit[0], Math.round(used.texelsPerUnit * 0.9 * 100) / 100),
- };
+ used = scalePresetDown(used);
}
- return { used, reduced: true };
+ return { used, reduced: used !== settings };
+}
+
+function timeLimitMessage(error, settings) {
+ const lowerSamples = Math.max(BAKE_RANGES.samples[0], Math.floor(settings.samples / 2));
+ return `${error.message} The scene is unchanged. Try samples ${lowerSamples}, or texelsPerUnit ${Math.max(BAKE_RANGES.texelsPerUnit[0], Math.round(settings.texelsPerUnit / 2 * 100) / 100)}.`;
}
// The baked part keeps reading every other material field from the live material, so motion tracks still drive it.
@@ -112,6 +124,17 @@ function liveBakedMaterial(liveMaterial, bakedMaterial) {
return Object.freeze(output);
}
+function traceWithAdvice(plan, used) {
+ try {
+ return traceLightmaps(plan, used);
+ } catch (error) {
+ if (/passed maxSeconds/.test(error.message)) {
+ throw new Error(timeLimitMessage(error, used));
+ }
+ throw error;
+ }
+}
+
/**
* The light bake as a worker kernel: unwrap, budget fit and trace all run in the same place, because unwrapping and
* tracing are both the heavy parts. Only the parts the bake changed travel back, as [index, part] pairs, because a part
@@ -121,7 +144,7 @@ function liveBakedMaterial(liveMaterial, bakedMaterial) {
export function bakeChangedParts(snapshots, lighting, settings) {
const plan = planLightmaps(snapshots, lighting, { ...settings, maxSeconds: BAKE_MAXIMUM_SECONDS });
const { used, reduced } = fitSettingsToBudget(plan, settings);
- const { parts, report } = traceLightmaps(plan, used);
+ const { parts, report } = traceWithAdvice(plan, used);
const changed = [];
parts.forEach((part, index) => {
if (part !== snapshots[index]) {
diff --git a/src/agent-scene-capabilities.js b/src/agent-scene-capabilities.js
index 7c30037c..8817a7eb 100644
--- a/src/agent-scene-capabilities.js
+++ b/src/agent-scene-capabilities.js
@@ -97,10 +97,17 @@ export const BAKE_PRESETS = Object.freeze({
export const BAKE_RANGES = Object.freeze({ samples: [1, 256], bounces: [1, 3], texelsPerUnit: [1, 12] });
export const BAKE_MAXIMUM_SECONDS = 20;
/**
- * Ray work (texels x samples x bounces x rays per hit) a recipe bake may trace. Measured on a closed, 56 part room (every
- * path bounces to the end) at about 1.3 million units per second, so this is about 8 s there, with room under the 20 s limit
- * for a slower machine. A preset is scaled down to fit; explicit samples or texelsPerUnit that do not fit fail. */
-export const BAKE_RAY_WORK_BUDGET = 10_000_000;
+ * Path steps (texels x samples x bounces) a preset is scaled down to. Measured at 1.8 to 3.1
+ * microseconds per path step on a closed 56 part room and the 57 node demo room, so this is 9 to 16 s, under the 20 s limit. The two rooms cost
+ * the same per path step, so the budget does not depend on the number of lights.
+ */
+export const BAKE_PRESET_PATH_WORK = 5_000_000;
+/**
+ * The hard upper bound on path steps for explicit samples, bounces and texelsPerUnit: about 5 times the demo room at 96
+ * samples, 2 bounces, texelsPerUnit 3. Below it the bake runs until BAKE_MAXIMUM_SECONDS, which fails cleanly and leaves
+ * the scene unchanged.
+ */
+export const BAKE_EXPLICIT_PATH_WORK_LIMIT = 24_000_000;
/** Render job output: each side up to 1920 and never more pixels than 1920x1080 (portrait 1080x1920 fits). */
export const MAXIMUM_JOB_SIDE = 1920;
export const MAXIMUM_JOB_PIXELS = 1920 * 1080;
@@ -231,8 +238,8 @@ export const AGENT_SCENE_CAPABILITIES = Object.freeze({
bake: Object.freeze({
fields: 'preset, or samples (1-256), bounces (1-3), texelsPerUnit (1-12) over it. Same recipe, same bytes.',
presets: BAKE_PRESETS,
- notes: 'Bounced light from point, spot, area and key lights. Reruns when parts, lights, materials or bake change. Skips alpha, skin, morph, hair, cloth (bake.skipped). A preset shrinks to fit maxRayWork (bake.used, bake.reduced); explicit samples or texelsPerUnit over it fail. No environment map or specular.',
- limits: Object.freeze({ maxSeconds: BAKE_MAXIMUM_SECONDS, maxRayWork: BAKE_RAY_WORK_BUDGET, maxPointLights: 8 }),
+ notes: 'Bounced light from point, spot, area and key lights. Reruns when parts, lights, materials or bake change. Skips alpha, skin, morph, hair, cloth (bake.skipped). A preset shrinks to fit (bake.used, bake.reduced); explicit settings fail over maxPathWork or past maxSeconds. No environment map or specular.',
+ limits: Object.freeze({ maxSeconds: BAKE_MAXIMUM_SECONDS, maxPathWork: BAKE_EXPLICIT_PATH_WORK_LIMIT, maxPointLights: 8 }),
}),
motionLimits: Object.freeze({ maxTracks: 128, maxKeyframesPerTrack: 64, maxKeyframes: 2048, maxDuration: 30 }),
});
diff --git a/tests/agent-bake.test.js b/tests/agent-bake.test.js
index 28ef9f0c..52dedf79 100644
--- a/tests/agent-bake.test.js
+++ b/tests/agent-bake.test.js
@@ -2,7 +2,7 @@ import assert from 'node:assert/strict';
import test from 'node:test';
import { createAgentScene } from '../src/agent-scene.js';
import { normalizeAgentBake } from '../src/agent-bake.js';
-import { BAKE_PRESETS, BAKE_RAY_WORK_BUDGET, BAKE_MAXIMUM_SECONDS } from '../src/agent-scene-capabilities.js';
+import { BAKE_PRESETS, BAKE_PRESET_PATH_WORK, BAKE_EXPLICIT_PATH_WORK_LIMIT, BAKE_MAXIMUM_SECONDS } from '../src/agent-scene-capabilities.js';
function closedRoom(extra = {}) {
const box = (id, translation, scale, material) => ({ id, geometry: 'box', material, translation, scale });
@@ -189,7 +189,7 @@ function largeRoom(bake) {
return recipe;
}
-test('a preset on a 56 part room shrinks to the ray work budget, finishes, and reports what it used', () => {
+test('a preset on a 56 part room shrinks to the path work budget, finishes, and reports what it used', () => {
const scene = createAgentScene(largeRoom({ preset: 'standard' }));
const bake = scene.inspect().bake;
assert.equal(scene.parts.length, 56);
@@ -197,7 +197,7 @@ test('a preset on a 56 part room shrinks to the ray work budget, finishes, and r
assert.ok(bake.used.samples < BAKE_PRESETS.standard.samples);
assert.ok(bake.used.texelsPerUnit < BAKE_PRESETS.standard.texelsPerUnit);
assert.equal(bake.used.bounces, BAKE_PRESETS.standard.bounces);
- assert.ok(bake.rayWork <= BAKE_RAY_WORK_BUDGET);
+ assert.ok(bake.texels * bake.used.samples * bake.used.bounces <= BAKE_PRESET_PATH_WORK);
assert.ok(bake.seconds < BAKE_MAXIMUM_SECONDS);
const again = createAgentScene(largeRoom({ preset: 'standard' }));
assert.deepEqual(again.inspect().bake.used, bake.used);
@@ -210,21 +210,31 @@ test('a preset that already fits is not reduced', () => {
assert.deepEqual(bake.used, BAKE_PRESETS.draft);
});
-test('explicit samples or texelsPerUnit over the budget fail with the number that fits, and that number works', () => {
+test('explicit settings over the hard limit fail up front with a lower setting to try', () => {
const heavy = { preset: 'draft', samples: 256, bounces: 3, texelsPerUnit: 12 };
let message = '';
- assert.throws(() => createAgentScene(closedRoom({ bake: heavy })), error => {
+ assert.throws(() => createAgentScene(largeRoom(heavy)), error => {
message = error.message;
- return /ray work/.test(error.message);
+ return /path steps/.test(error.message) && message.includes(String(BAKE_EXPLICIT_PATH_WORK_LIMIT));
});
const fittingSamples = Number(/samples (\d+) or fewer/.exec(message)?.[1]);
const fittingDensity = Number(/texelsPerUnit ([\d.]+) or less/.exec(message)?.[1]);
assert.ok(fittingSamples >= 1 && fittingSamples < 256, message);
assert.ok(fittingDensity >= 1 && fittingDensity < 12, message);
- const withSamples = createAgentScene(closedRoom({ bake: { ...heavy, samples: fittingSamples } })).inspect().bake;
- assert.equal(withSamples.reduced, false);
- assert.equal(withSamples.used.samples, fittingSamples);
- assert.ok(withSamples.rayWork <= BAKE_RAY_WORK_BUDGET);
+});
+
+test('explicit settings far above the preset budget run when they fit the hard limit, and are never reduced', () => {
+ const explicit = { samples: 160, bounces: 2, texelsPerUnit: 6 };
+ const bake = createAgentScene(largeRoom(explicit)).inspect().bake;
+ assert.equal(bake.reduced, false);
+ assert.deepEqual(bake.used, explicit);
+ assert.ok(bake.texels * explicit.samples * explicit.bounces > BAKE_PRESET_PATH_WORK);
+ assert.ok(bake.seconds < BAKE_MAXIMUM_SECONDS);
+});
+
+test('an explicit bake that passes maxSeconds fails cleanly with a lower setting to try', () => {
+ const slow = { samples: 256, bounces: 3, texelsPerUnit: 7 };
+ assert.throws(() => createAgentScene(largeRoom(slow)), error => /maxSeconds/.test(error.message) && /Try samples 128/.test(error.message));
});
function clothRoom() {
diff --git a/tests/kernel-offload.test.js b/tests/kernel-offload.test.js
index 99250c27..491e2b14 100644
--- a/tests/kernel-offload.test.js
+++ b/tests/kernel-offload.test.js
@@ -73,7 +73,12 @@ test('an error a kernel raises on the worker comes back as the same class and me
});
test('an explicit bake setting over the budget fails on the worker with the message that names numbers that fit', async () => {
- const heavyRoom = () => ({ ...kernelRoom(), bake: { preset: 'draft', samples: 256, bounces: 3, texelsPerUnit: 12 } });
+ // Surfaces four times as wide, so the explicit settings are over the hard path work limit in this small room too.
+ const heavyRoom = () => {
+ const room = kernelRoom();
+ const nodes = room.nodes.map(node => (node.scale ? { ...node, scale: node.scale.map(side => side * 4) } : node));
+ return { ...room, nodes, bake: { preset: 'draft', samples: 256, bounces: 3, texelsPerUnit: 12 } };
+ };
let inlineMessage = '';
assert.throws(() => createAgentScene(heavyRoom()), error => {
inlineMessage = error.message;