Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Merge origin/main into feat/gpu-crowds

Nguyen Xuan Ane1652a8a3c8e
diff --cc bench/size/budgets.json
index a420ee69,ebe1decc..de18c020
--- a/bench/size/budgets.json
+++ b/bench/size/budgets.json
@@@ -1,18 -1,18 +1,18 @@@
{
- "archiveBytes": 740000,
- "archiveBytes": 749600,
++ "archiveBytes": 752564,
"goals": {
"lit-box": 50000,
"gltf-box": 80000,
"agent-scene": 100000
},
"budgets": {
- "entry:core": 89432,
- "entry:core": 90530,
++ "entry:core": 90949,
"entry:model": 14400,
"entry:nature": 13200,
"entry:motion": 15260,
"entry:canvas2d": 9400,
- "entry:gltf": 58022,
- "entry:gltf+lazy": 61351,
- "entry:gltf": 57790,
- "entry:gltf+lazy": 61120,
++ "entry:gltf": 58016,
++ "entry:gltf+lazy": 61343,
"entry:modeling": 8700,
"entry:sculpt": 2500,
"entry:surface": 10100,
@@@ -23,6 -23,6 +23,7 @@@
"entry:physics": 18000,
"entry:spume": 9000,
"entry:retarget": 17210,
++ "entry:crowd-skinning": 27017,
"entry:skeleton-pose": 20640,
"entry:vehicle": 15764,
"entry:vegetation": 18600,
@@@ -32,25 -32,27 +33,27 @@@
"entry:clutter": 5300,
"entry:light-bake": 28500,
"entry:ground-bounce": 9460,
- "entry:path-tracer": 15960,
+ "entry:path-tracer": 17110,
"entry:texture-set": 900,
- "entry:agent-scene": 81003,
- "entry:agent-scene+lazy": 263580,
- "entry:agent-asset": 112411,
- "entry:agent-asset+lazy": 274964,
- "entry:agent-scene": 81730,
- "entry:agent-scene+lazy": 269730,
- "entry:agent-asset": 113050,
- "entry:agent-asset+lazy": 281030,
++ "entry:agent-scene": 81967,
++ "entry:agent-scene+lazy": 269970,
++ "entry:agent-asset": 113297,
++ "entry:agent-asset+lazy": 281270,
"entry:hdri": 3300,
"entry:camera-effects": 8600,
- "entry:water-reflection": 27030,
+ "entry:water-reflection": 27265,
"entry:render-passes": 1700,
"entry:gaussian-splats": 11023,
- "entry:material-layer-shaders": 21400,
- "entry:light-linking": 19720,
- "entry:cascaded-shadows": 28595,
- "scene:lit-box": 67520,
- "scene:gltf-box": 91830,
- "scene:gltf-box+lazy": 95160,
- "scene:agent-scene": 112150,
- "scene:agent-scene+lazy": 300160,
+ "entry:material-layer-shaders": 21627,
+ "entry:light-linking": 19948,
- "entry:cascaded-shadows": 28797,
- "scene:lit-box": 66438,
- "scene:gltf-box": 90716,
- "scene:gltf-box+lazy": 94044,
- "scene:agent-scene": 110234,
- "scene:agent-scene+lazy": 292814,
- "entry:crowd-skinning": 27017
++ "entry:cascaded-shadows": 28861,
++ "scene:lit-box": 67963,
++ "scene:gltf-box": 92246,
++ "scene:gltf-box+lazy": 95575,
++ "scene:agent-scene": 112573,
++ "scene:agent-scene+lazy": 300582,
+ "entry:coplanar-overlap": 2960,
+ "entry:view-transform": 2120,
- "entry:view-transform-shader": 20980
++ "entry:view-transform-shader": 21213
}
}
diff --cc src/renderer.js
index c13b408b,c06bbaa2..ab6c31f5
--- a/src/renderer.js
+++ b/src/renderer.js
@@@ -1,5 -1,5 +1,5 @@@
import { mat4, mat3 } from 'gl-matrix';
- import { layerTextureSupport, LIGHT_SHADING_FEATURE, SHADING_MODES, LIGHT_SHADING_MAXIMUM_SAMPLES, vertexShader, createVertexShader, createFragmentShader, liquidFragmentShader, createDepthVertexShader, depthFragmentShader, benchmarkVertexShader, benchmarkFragmentShader } from './shaders.js';
-import { layerTextureSupport, viewTransformShader, LIGHT_SHADING_FEATURE, SHADING_MODES, LIGHT_SHADING_MAXIMUM_SAMPLES, vertexShader, createVertexShader, createFragmentShader, liquidFragmentShader, depthVertexShader, depthFragmentShader, benchmarkVertexShader, benchmarkFragmentShader } from './shaders.js';
++import { layerTextureSupport, viewTransformShader, LIGHT_SHADING_FEATURE, SHADING_MODES, LIGHT_SHADING_MAXIMUM_SAMPLES, vertexShader, createVertexShader, createFragmentShader, liquidFragmentShader, createDepthVertexShader, depthFragmentShader, benchmarkVertexShader, benchmarkFragmentShader } from './shaders.js';
import { postFragment, createPostFragment, POST_STEPS, skyFragment, bloomFragment } from './post.js';
import { fullscreenVertex, startProgram, finishProgram, compileProgram } from './gl-program.js';
import { ambientOcclusionFragment } from './ambient-occlusion.js';
@@@ -332,7 -336,7 +337,7 @@@ 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.crowd ?? null, part.morph ?? null, castsShadow(part), renderPass(part.material), part.lods ?? null, part.shadowLods ?? null, ...materialAlphaState(part.material)]) {
- for (const value of [...materialMapState(part.material), ...materialLayerState(part.material), part.skin ?? null, part.morph ?? null, castsShadow(part), depthLayerOf(part), renderPass(part.material), part.lods ?? null, part.shadowLods ?? null, ...materialAlphaState(part.material)]) {
++ for (const value of [...materialMapState(part.material), ...materialLayerState(part.material), part.skin ?? null, part.crowd ?? null, part.morph ?? null, castsShadow(part), depthLayerOf(part), renderPass(part.material), part.lods ?? null, part.shadowLods ?? null, ...materialAlphaState(part.material)]) {
if (!maps.has(value)) maps.set(value, new Map());
maps = maps.get(value);
}
@@@ -585,13 -595,13 +600,13 @@@ export class Renderer67
if (shadowCascades) this.shaderFeatures.add(shadowCascades.shaderFeature);
const pending = {
main: this.startMainProgram(),
- depth: startProgram(this.context, depthVertexShader, depthFragmentShader),
+ depth: startProgram(this.context, createDepthVertexShader(this.shaderFeatures), depthFragmentShader),
};
if (!benchmark) {
- pending.post = startProgram(this.context, fullscreenVertex, postFragment);
+ pending.post = startProgram(this.context, fullscreenVertex, this.withViewTransform(postFragment, 'post'));
pending.sky = startProgram(this.context, fullscreenVertex, skyFragment);
pending.bloom = startProgram(this.context, fullscreenVertex, bloomFragment);
- pending.liquid = startProgram(this.context, vertexShader, liquidFragmentShader);
+ pending.liquid = startProgram(this.context, vertexShader, this.withViewTransform(liquidFragmentShader, 'liquid'));
if (environment.map) this.startEnvironmentPrograms();
}
this.finishMainProgram(pending.main);
@@@ -1039,7 -1080,7 +1095,7 @@@
const [alphaMode, alphaCutoff, opacity, doubleSided] = materialAlphaState(parts[0].material);
const layerState = materialLayerState(parts[0].material);
const culling = this.createCullingState(parts);
- const batch = { ...culling, alphaMode, alphaCutoff, opacity, doubleSided, layerState, parts: [...parts], vertexArray, instanceBuffer, instanceData, textures, mapState, splat, lightMapTexture, texture: textures[0], map, skin, skinTexture, influenceTexture, crowd, crowdTexture, morph, morphTexture, morphWeights, indexCount: geometry.indices.length, instanceCount: parts.length, floor: parts[0].material.tag === 'floor', castShadow: castsShadow(parts[0]), pass: renderPass(parts[0].material) };
- const batch = { ...culling, alphaMode, alphaCutoff, opacity, doubleSided, layerState, parts: [...parts], vertexArray, instanceBuffer, instanceData, textures, mapState, splat, lightMapTexture, texture: textures[0], map, skin, skinTexture, influenceTexture, morph, morphTexture, morphWeights, indexCount: geometry.indices.length, instanceCount: parts.length, floor: parts[0].material.tag === 'floor', castShadow: castsShadow(parts[0]), depthLayer: depthLayerOf(parts[0]), pass: renderPass(parts[0].material) };
++ const batch = { ...culling, alphaMode, alphaCutoff, opacity, doubleSided, layerState, parts: [...parts], vertexArray, instanceBuffer, instanceData, textures, mapState, splat, lightMapTexture, texture: textures[0], map, skin, skinTexture, influenceTexture, crowd, crowdTexture, morph, morphTexture, morphWeights, indexCount: geometry.indices.length, instanceCount: parts.length, floor: parts[0].material.tag === 'floor', castShadow: castsShadow(parts[0]), depthLayer: depthLayerOf(parts[0]), pass: renderPass(parts[0].material) };
if (parts[0].lods) culling.levelGeometries.forEach((geometryOfLevel, level) => this.levelDraw(batch, level));
culling.shadowLevels?.levelGeometries.forEach((geometryOfLevel, level) => this.levelDraw(batch, level, batch.shadowLevels));
parts.forEach((part, index) => this.partLocations.set(part, { batch, index, geometry: part.geometry, map, mapState, layerState, skin, jointMatrices: skin?.jointMatrices, skinIndices: geometry.skinIndices, skinWeights: geometry.skinWeights, morph, morphWeights: morph?.weights, morphTargets: geometry.morphTargets, normalMatrix: mat3.create(), committedMatrix: batch.instanceData.subarray(index * INSTANCE_STRIDE, index * INSTANCE_STRIDE + 16) }));