Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Merge main into the home hero loop

Nguyen Xuan Anc9c2c5e2f85b
diff --cc changes/779.md
index ff8c0905,00000000..711b5359
mode 100644,000000..100644
--- a/changes/779.md
+++ b/changes/779.md
@@@ -1,2 -1,0 +1,2 @@@
- - A renderer built with `deferProgramLink: true` links its shaders without freezing the page: await `renderer.programsReady()`; `shaderFeatureRepresentatives(parts)` picks the few parts that compile the program a whole scene needs, and `groupParts` builds each material key once; `await renderer.prepareFrame(frame)` then draws the first frame while the canvas is hidden without blocking on the post, liquid, occlusion and reversed-depth programs a first draw links (#ISSUE)
- - `loadGltf` copies accessors and converts geometry in slices of about 8 ms, and `loadHdri` decodes a Radiance map a row at a time with a yield between slices, so a large model or sky no longer blocks the page in one piece; the sync `readAccessor` and `parseRadianceHdr` stay, and the output is byte for byte the same (#ISSUE)
++- A renderer built with `deferProgramLink: true` links its shaders without freezing the page: await `renderer.programsReady()`; `shaderFeatureRepresentatives(parts)` picks the few parts that compile the program a whole scene needs, and `groupParts` builds each material key once; `await renderer.prepareFrame(frame)` then draws the first frame while the canvas is hidden without blocking on the post, liquid, occlusion and reversed-depth programs a first draw links (#779)
++- `loadGltf` copies accessors and converts geometry in slices of about 8 ms, and `loadHdri` decodes a Radiance map a row at a time with a yield between slices, so a large model or sky no longer blocks the page in one piece; the sync `readAccessor` and `parseRadianceHdr` stay, and the output is byte for byte the same (#779)
diff --cc src/renderer.js
index 83015187,274a059a..21892498
--- a/src/renderer.js
+++ b/src/renderer.js
@@@ -444,18 -431,7 +455,18 @@@ export function groupParts(parts, batch
const key = batching ? part.geometry : part;
if (!groups.has(key)) groups.set(key, new Map());
let maps = groups.get(key);
- for (const value of [...materialMapState(part.material), ...materialLayerState(part.material), part.skin ?? null, part.material.snippet, part.crowd ?? null, part.morph ?? null, castsShadow(part), receivesShadow(part), compositeModeOf(part), depthLayerOf(part), flushOrderOf(part), renderPass(part.material), part.lods ?? null, part.shadowLods ?? null, isMirroredMatrix(part.matrix), ...materialAlphaState(part.material), part.material.aovMap ?? null, part.material.transmissionMap ?? null, ...(part.material.aov ?? ZERO_VECTOR)]) {
+ // Thousands of parts share a few materials, so the material half of the key is built once per material.
+ let materialValues = materialKeyValues.get(part.material);
+ if (!materialValues) {
+ materialValues = [...materialMapState(part.material), ...materialLayerState(part.material)];
+ materialKeyValues.set(part.material, materialValues);
+ }
+ let materialTail = materialKeyTails.get(part.material);
+ if (!materialTail) {
+ materialTail = [renderPass(part.material), ...materialAlphaState(part.material), part.material.aovMap ?? null, part.material.transmissionMap ?? null, ...(part.material.aov ?? ZERO_VECTOR)];
+ materialKeyTails.set(part.material, materialTail);
+ }
- for (const value of [...materialValues, part.skin ?? null, part.material.snippet, part.crowd ?? null, part.morph ?? null, castsShadow(part), receivesShadow(part), compositeModeOf(part), depthLayerOf(part), part.lods ?? null, part.shadowLods ?? null, isMirroredMatrix(part.matrix), ...materialTail]) {
++ for (const value of [...materialValues, part.skin ?? null, part.material.snippet, part.crowd ?? null, part.morph ?? null, castsShadow(part), receivesShadow(part), compositeModeOf(part), depthLayerOf(part), flushOrderOf(part), part.lods ?? null, part.shadowLods ?? null, isMirroredMatrix(part.matrix), ...materialTail]) {
if (!maps.has(value)) maps.set(value, new Map());
maps = maps.get(value);
}