Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Fix large-scene automatic object reflections and liquidProgram disposal (#733, #734) (#742)

Nguyen Xuan Anda3aea3d5cd9
diff --git a/bench/agent-modeling/look.mjs b/bench/agent-modeling/look.mjs
index 86a2370b..7d6f5ef3 100644
--- a/bench/agent-modeling/look.mjs
+++ b/bench/agent-modeling/look.mjs
@@ -74,7 +74,7 @@ export async function withLookPage(callback, viewport = { width: IMAGE_SIZE, hei
const page = await browser.newPage({ viewport });
const errors = [];
page.on('pageerror', error => errors.push(error.message));
- await page.goto(`http://127.0.0.1:${server.httpServer.address().port}/bench/agent-modeling/look-harness.html`);
+ await page.goto(`http://127.0.0.1:${server.httpServer.address().port}/bench/agent-modeling/look-harness.html`, { timeout: 60000 });
await page.waitForFunction(() => window.renderLookViews);
const result = await callback(page);
if (errors.length) throw new Error(errors.join('\n'));
diff --git a/changes/733-734.md b/changes/733-734.md
new file mode 100644
index 00000000..a7bc37fa
--- /dev/null
+++ b/changes/733-734.md
@@ -0,0 +1 @@
+- Fixed: automatic `objectReflections` skip with a reported reason when a scene has more than 256 other parts instead of failing `createAgentScene`, and `Renderer67.dispose()` deletes `liquidProgram` so transmissive scenes release every WebGL program (#733, #734).
diff --git a/docs/agent-look.md b/docs/agent-look.md
index d8fbca15..0dda961f 100644
--- a/docs/agent-look.md
+++ b/docs/agent-look.md
@@ -122,7 +122,7 @@ Sky colors use display RGB, matching the renderer's existing environment contrac
| `hdri` | absent | A shipped HDRI (`sky-clouds`, `studio-softbox`) or the 64-character ID of a `.hdr` file in `scene_asset_catalog`. It lights, reflects and (with `world: true`) forms the background instead of the setup sky; `environmentIntensity` is its strength and `environmentRotation` turns it about the vertical axis. The setup still gives the key light, so set `keyIntensity: 0` when the HDRI has its own sun. `null` clears. See [Catalog HDRIs and looks](#catalog-hdris-and-looks) |
| `ground` | on | Absent unless set. `false` removes the preview's automatic floor and contact shadow |
| `resolveCoplanar` | off | `'offset'` puts the smaller part of each coplanar pair (see the `coplanar-overlap` warning) on the next depth layer, drawn with a polygon offset; `false` or absent leaves parts as authored. Geometry never moves. Parts that set `decal` or `depthLayer` keep their own |
-| `objectReflections` | on | Absent unless set. Each smooth metal part (`metallic` 0.5 or more, `roughness` 0.6 or less; at most 8 such parts) gets a reflection probe of the scene around it, so a chrome sphere shows the floor and its neighbours. `false` turns it off. Probes are traced at rest, so a part that moves reflects the scene as it started. `scene_inspect` names them in `reflections` |
+| `objectReflections` | on | Absent unless set. Each smooth metal part (`metallic` 0.5 or more, `roughness` 0.6 or less; at most 8 such parts, in a scene with at most 256 other parts) gets a reflection probe of the scene around it, so a chrome sphere shows the floor and its neighbours. `false` turns it off. Probes are traced at rest, so a part that moves reflects the scene as it started. `scene_inspect` names them in `reflections` |
| `sky` | absent | Absent unless set. `{ type: 'physical', sunElevation, sunRotation, turbidity, groundAlbedo, aerialPerspective, ozone, sunDisc }`: one time-of-day control. `sunElevation` -90 to 90 degrees (default 45), `sunRotation` degrees clockwise from -Z seen from above (0), `turbidity` 1 to 10 haze (3), `groundAlbedo` 0 to 1 (0.3), `aerialPerspective` 0 to 4 scales the distance haze (1; 0 for none), `ozone` 0 to 10 Chappuis-band absorption (1), `sunDisc` boolean (true). The sky sets `lightDirection`, `keyColor` (the sun reddens and dims with air mass and sets below the horizon), `skyTop`, `skyBottom`, `fogColor` and `fogDensity`, and replaces the setup's environment map with the sky, so those fields no longer take your values while a sky is set. `environment` motion tracks can animate `sunElevation`, `sunRotation`, `turbidity`, `groundAlbedo`, `aerialPerspective` and `ozone` for time-of-day arcs. A `set-environment` patch changes the fields it names and keeps the rest; `sky: null` in a patch keeps the last derived values as plain fields. It is an analytic single-scattering approximation (Rayleigh, aerosol and ozone, Kasten-Young air mass), not Blender's Nishita integration: no clouds. Raster first: the path tracer backends read the same environment map and key light, but are not yet checked against it. |
| `floorSkyTrace` | on | Absent unless set. A closed room a sun lights gets the sky each floor texel sees traced into its floor (`applyFloorSkyVisibility`, strength 0.2), so shadowed floors under a roof or between walls get less world and sky light; it makes the dark end of halls closer to Cycles. Open scenes and rooms lit by lamps alone are left as they are. `false` turns it off; a value that is not a boolean is refused. It loads lazily with a recipe that names its sun (`keyColor` or `keyIntensity`), costs about 1 s of trace when the scene is built and adds triangles to the floor (0.1 to 0.4 ms per frame in the reference halls). |
| `specularAntiAliasing` | `1` | Absent unless set. `0` to `4`. Widens highlights where the shading normal or normal map detail changes within a pixel (geometric specular anti-aliasing plus a Toksvig term read from the filtered normal map length), so grainy or scanned metal stops sparkling from frame to frame at grazing angles. `0` gives a highlight that follows every texel; above `1` is softer. |
diff --git a/src/probe-trace.js b/src/probe-trace.js
index a59afcc0..675c0002 100644
--- a/src/probe-trace.js
+++ b/src/probe-trace.js
@@ -274,8 +274,9 @@ export function traceObjectProbes(parts, lighting, options = {}) {
if (isReflectivePart(part.material)) reflective.push(index);
});
// Many small metal parts (lamp posts, spires) read as shapes and not as mirrors, and each probe costs a trace and a draw batch.
- const wanted = reflective.length > MAXIMUM_OBJECT_PROBES ? [] : reflective;
- const skipped = wanted.length > 0 ? null : reflective.length > 0 ? `more than ${MAXIMUM_OBJECT_PROBES} reflective parts` : 'no reflective part';
+ const tooManyOthers = parts.length - 1 > MAX_BAKE_PARTS;
+ const wanted = reflective.length > MAXIMUM_OBJECT_PROBES || tooManyOthers ? [] : reflective;
+ const skipped = wanted.length > 0 ? null : reflective.length > MAXIMUM_OBJECT_PROBES ? `more than ${MAXIMUM_OBJECT_PROBES} reflective parts` : tooManyOthers ? `more than ${MAX_BAKE_PARTS} other parts` : 'no reflective part';
if (wanted.length === 0 || parts.length < 2) {
return { traced: [], automatic: true, requested: reflective.length, skipped, seconds: 0 };
}
diff --git a/src/renderer.js b/src/renderer.js
index 9f8558dd..2e0fb5e7 100644
--- a/src/renderer.js
+++ b/src/renderer.js
@@ -2397,6 +2397,7 @@ export class Renderer67 {
this.context.deleteTexture(this.shadowTexture);
this.context.deleteFramebuffer(this.shadowFramebuffer);
this.context.deleteProgram(this.program);
+ if (this.liquidProgram) this.context.deleteProgram(this.liquidProgram);
this.context.deleteProgram(this.depthProgram);
if (this.postProgram) this.context.deleteProgram(this.postProgram);
// A program still linking must finish first: deleting it mid-link leaves a GL error that the next renderer on this context sees.
diff --git a/tests/lighting-passes.test.js b/tests/lighting-passes.test.js
index 7cd04014..4b30902a 100644
--- a/tests/lighting-passes.test.js
+++ b/tests/lighting-passes.test.js
@@ -109,7 +109,7 @@ test('diffuse + glossy + emission match the beauty frame, and auxiliary passes r
return;
}
const page = await browser.newPage({ viewport: { width: 64, height: 64 } });
- await page.goto(`http://127.0.0.1:${port}/`);
+ await page.goto(`http://127.0.0.1:${port}/`, { timeout: 60000 });
const { beauty, passes, movedVelocity, manifest, transmission, size: SIZE } = await drawFrames(page);
let compared = 0;
let totalError = 0;
diff --git a/tests/reflection-probes.test.js b/tests/reflection-probes.test.js
index 80188074..3b5980a6 100644
--- a/tests/reflection-probes.test.js
+++ b/tests/reflection-probes.test.js
@@ -160,6 +160,13 @@ test('a scene with no reflective part, or too many, traces nothing', () => {
const trace = traceObjectProbes(crowd, openAir);
assert.equal(trace.traced.length, 0);
assert.match(trace.skipped, /more than 8/);
+ const largeScene = [
+ placed('mirror', ball, [0, 0.5, 0], [0.5, 0.5, 0.5], { metallic: 1, roughness: 0.3 }),
+ ...Array.from({ length: 257 }, (item, index) => placed(`box-${index}`, cube, [index, 0.5, 0], [1, 1, 1])),
+ ];
+ const largeTrace = traceObjectProbes(largeScene, openAir);
+ assert.equal(largeTrace.traced.length, 0);
+ assert.match(largeTrace.skipped, /more than 256 other parts/);
});
test('rough metal and plain surfaces are not reflective', () => {
diff --git a/tests/renderer.test.js b/tests/renderer.test.js
index 453ff86c..519615d9 100644
--- a/tests/renderer.test.js
+++ b/tests/renderer.test.js
@@ -496,8 +496,12 @@ test('skin palette and influence textures cache by pose and geometry identity an
renderer.buffers = [];
renderer.textures = new Map();
renderer.partLocations = new Map();
+ renderer.liquidProgram = 'liquidProgram';
+ const deletedPrograms = [];
+ renderer.context.deleteProgram = (program) => { if (program) deletedPrograms.push(program); };
renderer.dispose();
assert.deepEqual(deleted, [palette.texture, influences.texture]);
+ assert.deepEqual(deletedPrograms, ['liquidProgram']);
assert.equal(renderer.skinTextures.size, 0);
assert.equal(renderer.influenceTextures.size, 0);
});