Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Merge origin/main into feat/vegetation-impostors

Nguyen Xuan An558bcef0c687
diff --cc src/renderer.js
index 9acac618,a12bcbc1..c468ea06
--- a/src/renderer.js
+++ b/src/renderer.js
@@@ -20,9 -18,10 +19,9 @@@ import { MaterialSnapshot } from './mat
import { fittedFogDensity } from './fog-fit.js';
import { InstanceSelection, extractFrustumPlanes, geometryBoundingSphere, selectInstances } from './render-culling.js';
import { resolveShadowLight, shadowBiasPerSlope } from './shadow-light.js';
- import { validateMorphGeometry, validateMorphPose, validateMorphTransform, packMorphTargets } from './morph.js';
+ import { requireDeformationSupport } from './shader-registry.js';
const SHADOW_MAP_SIZE = 2048;
-const MATERIAL_TAGS = { armor: 1, floor: 2, water: 3, foliage: 4, terrain: 5, grass: 7, fire: 8, smoke: 9, unlit: 10, liquid: 11, foam: 12 };
// Liquid and foam see the resolved opaque scene, so they draw in their own pass after it.
const TRANSLUCENT_TAGS = new Set(['liquid', 'foam']);
const DEFAULT_LIQUID = Object.freeze({ thickness: 0.5, ior: 1.33, refraction: 1, scattering: 1, foamOpacity: 0.55, foamSoftness: 1 });
diff --cc src/shader-registry.js
index 9bfa01dd,1c660c38..d5f6209a
--- a/src/shader-registry.js
+++ b/src/shader-registry.js
@@@ -51,9 -51,20 +51,26 @@@ export function requireFeatureCode(feat
}
+/** Value of `material.tag` in the instance data; the vegetation addon adds `impostor`. */
+export const materialTags = { armor: 1, floor: 2, water: 3, foliage: 4, terrain: 5, grass: 7, fire: 8, smoke: 9, unlit: 10, liquid: 11, foam: 12 };
+
+// GLSL the vegetation addon splices into the shaders: `defs` and `color` in the colour vertex shader, `defs` and `depth` in the shadow vertex shader and `alpha` in the fragment shader's surfaceAlpha.
+export const addonGlsl = { defs: '', color: '', depth: '', alpha: '' };
+
+ /** The most morph targets one geometry carries; the morph shader's weight array has this length. */
+ export const MAX_MORPH_TARGETS = 64;
+
+ // skinning.js and morph.js set the JavaScript half of skinned and morphed parts: validation, texture layout and packing.
+ // The renderer calls them only for a part with a skin or morph targets, so a renderer without those parts never carries them.
+ const deformationSupport = {};
+
+ export function registerDeformationSupport(functions) {
+ Object.assign(deformationSupport, functions);
+ }
+
+ export function requireDeformationSupport(requiredFunction, file) {
+ if (!deformationSupport[requiredFunction]) {
+ throw new Error(`Skinned and morphed parts need their code: import ${file}, or a module that makes the pose (createSkinPose, createMorphPose, the glTF loader).`);
+ }
+ return deformationSupport;
+ }
diff --cc src/shaders.js
index 4725c46c,9d384535..3b5a0d08
--- a/src/shaders.js
+++ b/src/shaders.js
@@@ -1,6 -1,4 +1,5 @@@
- import { MAX_MORPH_TARGETS } from './morph.js';
import { MAX_POINT_LIGHTS, MAX_SPOT_LIGHTS, MAX_AREA_LIGHTS } from './light-limits.js';
+import { addonGlsl } from './shader-registry.js';
import { registeredFeatureCode, requireFeatureCode, registerShaderFeatureCode, registerSplatSupport, requireSplatSupport, layerTextureSupport, viewTransformShader, SPLAT_UNITS } from './shader-registry.js';
export { registerShaderFeatureCode, registerSplatSupport, requireSplatSupport, layerTextureSupport, viewTransformShader, SPLAT_UNITS };
@@@ -116,10 -84,9 +85,10 @@@ flat out float instanceOrdinal
out vec3 boxPosition;
out vec3 boxNormal;
flat out mat3 boxNormalMatrix;
- ${skinningShader()}
- ${morphingShader}
+ ${skinningShader(features)}
+ ${morphingShader(features)}
${windShader(features)}
+${addonGlsl.defs}
void main() {
// A crowd batch reads its joints and weights from the UV and colour attributes, which then carry no texture or tint.
vec2 uv = USES_CROWD ? vec2(-1.0) : uvSets.xy;
@@@ -171,10 -138,9 +140,10 @@@ uniform float assemblyAmount
uniform float time;
uniform float wind;
out vec2 textureUV;
- ${skinningShader()}
- ${morphingShader}
+ ${skinningShader(features)}
+ ${morphingShader(features)}
${windShader(features)}
+${addonGlsl.defs}
void main() {
vec2 uv = USES_CROWD ? vec2(-1.0) : uvSets.xy;
vec4 world = instanceMatrix * (USES_CROWD ? crowdTransform() : skinTransform()) * vec4(morphedPosition(position), 1.0);