Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Merge origin/main into 1054-part-ray-visibility

Nguyen Xuan An40ba3b27f0bd
diff --cc bench/cycles-parity/instanced-scene.mjs
index 00000000,5aac3882..e993284c
mode 000000,100644..100644
--- a/bench/cycles-parity/instanced-scene.mjs
+++ b/bench/cycles-parity/instanced-scene.mjs
@@@ -1,0 -1,37 +1,13 @@@
+ // The instanced trace scene of a bench scene for the native cycles kernel: copies of one geometry stay instances, and a part that hides
-// from some ray kinds gets those visibility bits cleared (buildTraceScene does not read `rayVisibility`). The scene is built with the
++// from some ray kinds gets those visibility bits cleared (buildTraceScene reads `rayVisibility`, #1054). The scene is built with the
+ // native triangle bound (#1041), so a scene above the 400,000 unique triangles of the CPU and WebGL paths, such as the Classroom, packs directly.
+ import { MAX_NATIVE_TRACE_TRIANGLES } from '../../src/path-tracer-scene.js';
+ import { buildTraceSceneWithManyLights } from './trace-scene-many-lights.mjs';
+
-// FORMAT-v2 instance visibility bits: 1 camera, 2 diffuse, 4 glossy, 8 transmission, 16 shadow, 32 volume scatter.
-const RAY_VISIBILITY_BITS = { camera: 1, diffuse: 2, glossy: 4, transmission: 8, shadow: 16, volumeScatter: 32 };
-const ALL_RAY_KINDS = 63;
-
-function visibilityFlagsFor(part) {
- let flags = ALL_RAY_KINDS;
- for (const [kind, isVisible] of Object.entries(part.rayVisibility ?? {})) {
- if (isVisible === false) {
- flags &= ~RAY_VISIBILITY_BITS[kind];
- }
- }
- return flags;
-}
-
-// Each instance of the scene is its part, in order.
-function applyRayVisibility(scene, parts) {
- scene.instances.forEach((instance, index) => {
- if (parts[index].rayVisibility) {
- instance.visibilityFlags = visibilityFlagsFor(parts[index]);
- }
- });
-}
-
+ export function buildInstancedTraceScene(parts, environment) {
+ const scene = buildTraceSceneWithManyLights(parts, environment, { instancing: true, maximumTriangles: MAX_NATIVE_TRACE_TRIANGLES });
+ if (!scene.instances) {
+ throw new RangeError('The scene has no shared geometry and was flattened.');
+ }
- applyRayVisibility(scene, parts);
+ return scene;
+ }
diff --cc docs/cycles-parity.md
index 7cd8cb4b,18d53e30..0a0311ae
--- a/docs/cycles-parity.md
+++ b/docs/cycles-parity.md
@@@ -1011,9 -1011,9 +1011,9 @@@ Picture (Cook left, Cycles right, 1024
[`classroom_bridge.py`](../bench/cycles-parity/classroom_bridge.py) runs inside Blender 5.3 on the opened scene, with auto-run scripts disabled (`blender -b --disable-autoexec classroom.blend --python ... -- export <dir>`). `export` writes the evaluated scene in the JSON format the other parity benches read: one geometry per mesh datablock and modifier stack (so linked copies share it), one part per instance with its world matrix, the camera, the lights, the world and one grey material (base 0.8, roughness 1, as the harness defines). `render-cycles.py` builds the Cycles side from that same JSON, so both renderers see exactly the same scene. `reference` renders the original `.blend` in Cycles with the same drops and the same override, to measure the bridge itself.
- [`run-classroom-parity.py`](../bench/cycles-parity/run-classroom-parity.py) (started by `run-classroom-parity.sh`) does everything in one call: download once, export, Cook and Cycles renders, comparisons, depth, a figure and the diagnostic experiments. Small changes elsewhere in `bench/`: `trace-native.mjs --instancing` keeps shared geometry as instances (through `instanced-scene-in-batches.mjs`, below), parts may carry `rayVisibility` (read by `render-cycles.py` and by Cook's instance visibility bits), and `render-cycles.py` reads `environment.sunAngularRadius` as Cook does.
+ [`run-classroom-parity.py`](../bench/cycles-parity/run-classroom-parity.py) (started by `run-classroom-parity.sh`) does everything in one call: download once, export, Cook and Cycles renders, comparisons, depth, a figure and the diagnostic experiments. Small changes elsewhere in `bench/`: `trace-native.mjs --instancing` keeps shared geometry as instances (through `instanced-scene.mjs`, below), parts may carry `rayVisibility` (read by `render-cycles.py` and by Cook's instance visibility bits), and `render-cycles.py` reads `environment.sunAngularRadius` as Cook does.
- `buildTraceScene` refuses an instanced scene with more than 400,000 unique triangles, counted once per shared geometry, and the Classroom holds 427,769. The kernel has no such limit. `instanced-scene-in-batches.mjs` builds the scene in two batches that each fit and joins their instance lists, so `src/` is untouched (tests: `tests/cycles-parity-instanced-batches.test.js`, `tests/cycles-parity-instancing-option.test.js`).
-The Classroom holds 427,769 unique triangles, above the 400,000 of the CPU and WebGL tracers. `instanced-scene.mjs` builds it directly with the native bound (`maximumTriangles`, see "Triangle bound of a native scene" below) and applies the parts' `rayVisibility`; the two-batch workaround of the first slice is gone (tests: `tests/cycles-parity-instanced-scene.test.js`, `tests/cycles-parity-instancing-option.test.js`). The instance order is now the part order, as in a flattened scene, where the batches listed one batch after the other. This has not been re-run against Cycles `[not measured]`: the Classroom needs Blender and its download.
++The Classroom holds 427,769 unique triangles, above the 400,000 of the CPU and WebGL tracers. `instanced-scene.mjs` builds it directly with the native bound (`maximumTriangles`, see "Triangle bound of a native scene" below); `buildTraceScene` reads the parts' `rayVisibility` itself (#1054); the two-batch workaround of the first slice is gone (tests: `tests/cycles-parity-instanced-scene.test.js`, `tests/cycles-parity-instancing-option.test.js`). The instance order is now the part order, as in a flattened scene, where the batches listed one batch after the other. This has not been re-run against Cycles `[not measured]`: the Classroom needs Blender and its download.
### Counts `[measured]`
diff --cc scripts/native-bake-page.js
index ba884a62,476ff861..1cd8c26e
--- a/scripts/native-bake-page.js
+++ b/scripts/native-bake-page.js
@@@ -79,16 -84,22 +84,27 @@@ export function exportNativeSceneTables
materialsReason = error.message;
}
}
- const input = buildNativeInput(traceScene, camera, options, pack);
+ if (traceScene.partRayVisibility && !wholeMaterials) {
+ throw new TypeError('A part sets rayVisibility to hide from a ray kind, which only the "cycles" kernel can carry. Use kernel "cycles", or drop the rayVisibility of the part.');
+ }
+ // The v1 tables of the "cycles" job fallback cannot carry visibility: the scene is drawn without it, and the report says so.
+ const visibilityNote = traceScene.partRayVisibility ? { rayVisibility: 'ignored', rayVisibilityReason: materialsReason } : {};
+ const input = buildNativeInput({ ...traceScene, partRayVisibility: null }, camera, options, pack);
return { tables: encodeNativeTables(input), triangleCount: input.triangleCount, triangles: traceScene.indices.length / 3, wholeMaterials: false,
- ...(materialsReason === undefined ? {} : { materialsReason }), ...instancingNote };
+ ...(materialsReason === undefined ? {} : { materialsReason }), ...visibilityNote, ...instancingNote };
}
+ // The flattened scene of parts the packer refused as instances. Every copy counts against the bound once flattened, so a scene
+ // that fitted as instances can be over it; the error then names the packer's refusal, since the geometry was already shared.
+ function flattenRefusedScene(buildTraceScene, parts, environment, triangleLimit, refusal) {
+ try {
+ return buildTraceScene(parts, environment, triangleLimit);
+ } catch (error) {
+ if (!(error instanceof RangeError)) throw error;
+ throw new RangeError(`The scene could not stay instanced (${refusal}) and is too large once every copy is flattened: ${error.message}`);
+ }
+ }
+
function floatsFromBase64(data) {
const bytes = bytesFromBase64(data);
return new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / Float32Array.BYTES_PER_ELEMENT);