@luma.gl/engine 10.0.0-alpha.10 → 10.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation/node-animation-binding.cjs +10 -0
- package/dist/animation/node-animation-binding.d.ts +1 -1
- package/dist/animation/node-animation-binding.d.ts.map +1 -1
- package/dist/animation/node-animation-binding.js +10 -0
- package/dist/animation/node-animation-binding.js.map +1 -1
- package/dist/dist.dev.js +325 -80
- package/dist/dist.min.js +58 -58
- package/dist/gltf/gltf/animations/animations.d.ts +1 -1
- package/dist/gltf/gltf/animations/animations.d.ts.map +1 -1
- package/dist/gltf/gltf/create-scenegraph-from-gltf.cjs +80 -12
- package/dist/gltf/gltf/create-scenegraph-from-gltf.d.ts +8 -1
- package/dist/gltf/gltf/create-scenegraph-from-gltf.d.ts.map +1 -1
- package/dist/gltf/gltf/create-scenegraph-from-gltf.js +82 -14
- package/dist/gltf/gltf/create-scenegraph-from-gltf.js.map +1 -1
- package/dist/gltf/gltf/gltf-billboard.cjs +6 -1
- package/dist/gltf/gltf/gltf-billboard.d.ts.map +1 -1
- package/dist/gltf/gltf/gltf-billboard.js +6 -1
- package/dist/gltf/gltf/gltf-billboard.js.map +1 -1
- package/dist/gltf/gltf/gltf-extension-support.cjs +2 -2
- package/dist/gltf/gltf/gltf-extension-support.js +2 -2
- package/dist/gltf/gltf/gltf-extension-support.js.map +1 -1
- package/dist/gltf/index.cjs +2 -0
- package/dist/gltf/index.cjs.map +3 -3
- package/dist/gltf/index.d.ts +1 -1
- package/dist/gltf/index.d.ts.map +1 -1
- package/dist/gltf/index.js +1 -1
- package/dist/gltf/index.js.map +1 -1
- package/dist/gltf/parsers/parse-gltf-animations.cjs +8 -5
- package/dist/gltf/parsers/parse-gltf-animations.js +20 -5
- package/dist/gltf/parsers/parse-gltf-animations.js.map +1 -1
- package/dist/gltf/parsers/parse-gltf-lights.cjs +36 -72
- package/dist/gltf/parsers/parse-gltf-lights.d.ts +6 -2
- package/dist/gltf/parsers/parse-gltf-lights.d.ts.map +1 -1
- package/dist/gltf/parsers/parse-gltf-lights.js +34 -91
- package/dist/gltf/parsers/parse-gltf-lights.js.map +1 -1
- package/dist/gltf/parsers/parse-gltf-metadata.cjs +60 -0
- package/dist/gltf/parsers/parse-gltf-metadata.d.ts +5 -0
- package/dist/gltf/parsers/parse-gltf-metadata.d.ts.map +1 -0
- package/dist/gltf/parsers/parse-gltf-metadata.js +39 -0
- package/dist/gltf/parsers/parse-gltf-metadata.js.map +1 -0
- package/dist/gltf/parsers/parse-gltf.cjs +4 -1
- package/dist/gltf/parsers/parse-gltf.d.ts +4 -0
- package/dist/gltf/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/gltf/parsers/parse-gltf.js +3 -0
- package/dist/gltf/parsers/parse-gltf.js.map +1 -1
- package/dist/gltf/pbr/pbr-environment.cjs +21 -3
- package/dist/gltf/pbr/pbr-environment.d.ts +3 -0
- package/dist/gltf/pbr/pbr-environment.d.ts.map +1 -1
- package/dist/gltf/pbr/pbr-environment.js +19 -1
- package/dist/gltf/pbr/pbr-environment.js.map +1 -1
- package/dist/graph/models/index.cjs.map +1 -1
- package/dist/graph/models/path/path-attribute-model.cjs +1 -1
- package/dist/graph/models/path/path-attribute-model.js +1 -1
- package/dist/graph/models/path/path-attribute-model.js.map +1 -1
- package/dist/graph/models/path/path-storage-model.cjs +1 -1
- package/dist/graph/models/path/path-storage-model.js +1 -1
- package/dist/graph/models/path/path-storage-model.js.map +1 -1
- package/dist/graph/physics/index.cjs.map +1 -1
- package/dist/graph/tables/index.cjs.map +1 -1
- package/dist/index.cjs +13 -0
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/lighting/ambient-occlusion-pass.cjs +126 -0
- package/dist/lighting/ambient-occlusion-pass.d.ts +31 -0
- package/dist/lighting/ambient-occlusion-pass.d.ts.map +1 -0
- package/dist/lighting/ambient-occlusion-pass.js +108 -0
- package/dist/lighting/ambient-occlusion-pass.js.map +1 -0
- package/dist/lighting/clustered-light-grid.cjs +378 -0
- package/dist/lighting/clustered-light-grid.d.ts +94 -0
- package/dist/lighting/clustered-light-grid.d.ts.map +1 -0
- package/dist/lighting/clustered-light-grid.js +370 -0
- package/dist/lighting/clustered-light-grid.js.map +1 -0
- package/dist/lighting/contact-shadow-composite.cjs +80 -0
- package/dist/lighting/contact-shadow-composite.d.ts +6 -0
- package/dist/lighting/contact-shadow-composite.d.ts.map +1 -0
- package/dist/lighting/contact-shadow-composite.js +59 -0
- package/dist/lighting/contact-shadow-composite.js.map +1 -0
- package/dist/lighting/contact-shadow-pass.cjs +102 -0
- package/dist/lighting/contact-shadow-pass.d.ts +23 -0
- package/dist/lighting/contact-shadow-pass.d.ts.map +1 -0
- package/dist/lighting/contact-shadow-pass.js +85 -0
- package/dist/lighting/contact-shadow-pass.js.map +1 -0
- package/dist/lighting/index.cjs +98 -0
- package/dist/lighting/index.cjs.map +6 -0
- package/dist/lighting/index.d.ts +23 -0
- package/dist/lighting/index.d.ts.map +1 -0
- package/dist/lighting/index.js +16 -0
- package/dist/lighting/index.js.map +1 -0
- package/dist/lighting/pbr-environment.cjs +45 -0
- package/dist/lighting/pbr-environment.d.ts +25 -0
- package/dist/lighting/pbr-environment.d.ts.map +1 -0
- package/dist/lighting/pbr-environment.js +30 -0
- package/dist/lighting/pbr-environment.js.map +1 -0
- package/dist/lighting/pbr-material.cjs +75 -0
- package/dist/lighting/pbr-material.d.ts +33 -0
- package/dist/lighting/pbr-material.d.ts.map +1 -0
- package/dist/lighting/pbr-material.js +52 -0
- package/dist/lighting/pbr-material.js.map +1 -0
- package/dist/lighting/pbr-model.cjs +509 -0
- package/dist/lighting/pbr-model.d.ts +41 -0
- package/dist/lighting/pbr-model.d.ts.map +1 -0
- package/dist/lighting/pbr-model.js +475 -0
- package/dist/lighting/pbr-model.js.map +1 -0
- package/dist/lighting/pbr-surface-pass.cjs +116 -0
- package/dist/lighting/pbr-surface-pass.d.ts +35 -0
- package/dist/lighting/pbr-surface-pass.d.ts.map +1 -0
- package/dist/lighting/pbr-surface-pass.js +98 -0
- package/dist/lighting/pbr-surface-pass.js.map +1 -0
- package/dist/lighting/prefiltered-environment.cjs +275 -0
- package/dist/lighting/prefiltered-environment.d.ts +56 -0
- package/dist/lighting/prefiltered-environment.d.ts.map +1 -0
- package/dist/lighting/prefiltered-environment.js +264 -0
- package/dist/lighting/prefiltered-environment.js.map +1 -0
- package/dist/lighting/shadow-map-renderer.cjs +627 -0
- package/dist/lighting/shadow-map-renderer.d.ts +92 -0
- package/dist/lighting/shadow-map-renderer.d.ts.map +1 -0
- package/dist/lighting/shadow-map-renderer.js +617 -0
- package/dist/lighting/shadow-map-renderer.js.map +1 -0
- package/dist/lighting/shadow-quality.cjs +58 -0
- package/dist/lighting/shadow-quality.d.ts +13 -0
- package/dist/lighting/shadow-quality.d.ts.map +1 -0
- package/dist/lighting/shadow-quality.js +37 -0
- package/dist/lighting/shadow-quality.js.map +1 -0
- package/dist/material/material.cjs +3 -0
- package/dist/material/material.d.ts +2 -0
- package/dist/material/material.d.ts.map +1 -1
- package/dist/material/material.js +3 -0
- package/dist/material/material.js.map +1 -1
- package/dist/model/gpu-vector-model.cjs +11 -1
- package/dist/model/gpu-vector-model.d.ts +4 -2
- package/dist/model/gpu-vector-model.d.ts.map +1 -1
- package/dist/model/gpu-vector-model.js +12 -1
- package/dist/model/gpu-vector-model.js.map +1 -1
- package/dist/scenegraph/controllers/punctual-light-controller.cjs +121 -0
- package/dist/scenegraph/controllers/punctual-light-controller.d.ts +31 -0
- package/dist/scenegraph/controllers/punctual-light-controller.d.ts.map +1 -0
- package/dist/scenegraph/controllers/punctual-light-controller.js +117 -0
- package/dist/scenegraph/controllers/punctual-light-controller.js.map +1 -0
- package/dist/scenegraph/scene-metadata.cjs +43 -0
- package/dist/scenegraph/scene-metadata.d.ts +9 -0
- package/dist/scenegraph/scene-metadata.d.ts.map +1 -0
- package/dist/scenegraph/scene-metadata.js +21 -0
- package/dist/scenegraph/scene-metadata.js.map +1 -0
- package/dist/scenegraph/scenegraph-interaction.cjs +99 -0
- package/dist/scenegraph/scenegraph-interaction.d.ts +47 -0
- package/dist/scenegraph/scenegraph-interaction.d.ts.map +1 -0
- package/dist/scenegraph/scenegraph-interaction.js +79 -0
- package/dist/scenegraph/scenegraph-interaction.js.map +1 -0
- package/dist/scenegraph/scenegraph-node.cjs +10 -0
- package/dist/scenegraph/scenegraph-node.d.ts +10 -0
- package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
- package/dist/scenegraph/scenegraph-node.js +10 -0
- package/dist/scenegraph/scenegraph-node.js.map +1 -1
- package/dist/text/experimental.cjs.map +1 -1
- package/dist/text/fonts/atlas/text-utils.cjs +1 -1
- package/dist/text/fonts/atlas/text-utils.js +1 -1
- package/dist/text/fonts/atlas/text-utils.js.map +1 -1
- package/dist/text/fonts/index.cjs.map +1 -1
- package/dist/text/index.cjs.map +1 -1
- package/dist/text/text-2d/models/text-attribute-model.cjs +1 -1
- package/dist/text/text-2d/models/text-attribute-model.js +1 -1
- package/dist/text/text-2d/models/text-attribute-model.js.map +1 -1
- package/dist/text/text-2d/models/text-dictionary-model.cjs +1 -1
- package/dist/text/text-2d/models/text-dictionary-model.js +1 -1
- package/dist/text/text-2d/models/text-dictionary-model.js.map +1 -1
- package/dist/text/text-2d/models/text-storage-model.cjs +1 -1
- package/dist/text/text-2d/models/text-storage-model.js +1 -1
- package/dist/text/text-2d/models/text-storage-model.js.map +1 -1
- package/package.json +13 -8
- package/src/animation/node-animation-binding.ts +18 -1
- package/src/gltf/gltf/animations/animations.ts +8 -1
- package/src/gltf/gltf/create-scenegraph-from-gltf.ts +98 -17
- package/src/gltf/gltf/gltf-billboard.ts +6 -1
- package/src/gltf/gltf/gltf-extension-support.ts +2 -2
- package/src/gltf/index.ts +1 -0
- package/src/gltf/parsers/parse-gltf-animations.ts +22 -8
- package/src/gltf/parsers/parse-gltf-lights.ts +42 -130
- package/src/gltf/parsers/parse-gltf-metadata.ts +40 -0
- package/src/gltf/parsers/parse-gltf.ts +5 -0
- package/src/gltf/pbr/pbr-environment.ts +27 -1
- package/src/graph/models/path/path-attribute-model.ts +1 -1
- package/src/graph/models/path/path-storage-model.ts +1 -1
- package/src/index.ts +16 -0
- package/src/lighting/ambient-occlusion-pass.ts +130 -0
- package/src/lighting/clustered-light-grid.ts +481 -0
- package/src/lighting/contact-shadow-composite.ts +67 -0
- package/src/lighting/contact-shadow-pass.ts +107 -0
- package/src/lighting/index.ts +88 -0
- package/src/lighting/pbr-environment.ts +55 -0
- package/src/lighting/pbr-material.ts +85 -0
- package/src/lighting/pbr-model.ts +531 -0
- package/src/lighting/pbr-surface-pass.ts +122 -0
- package/src/lighting/prefiltered-environment.ts +354 -0
- package/src/lighting/shadow-map-renderer.ts +909 -0
- package/src/lighting/shadow-quality.ts +50 -0
- package/src/material/material.ts +3 -0
- package/src/model/gpu-vector-model.ts +18 -3
- package/src/scenegraph/controllers/punctual-light-controller.ts +172 -0
- package/src/scenegraph/scene-metadata.ts +23 -0
- package/src/scenegraph/scenegraph-interaction.ts +131 -0
- package/src/scenegraph/scenegraph-node.ts +12 -0
- package/src/text/fonts/atlas/text-utils.ts +1 -1
- package/src/text/text-2d/models/text-attribute-model.ts +1 -1
- package/src/text/text-2d/models/text-dictionary-model.ts +1 -1
- package/src/text/text-2d/models/text-storage-model.ts +1 -1
|
@@ -0,0 +1,627 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var shadow_map_renderer_exports = {};
|
|
19
|
+
__export(shadow_map_renderer_exports, {
|
|
20
|
+
ShadowMapRenderer: () => ShadowMapRenderer,
|
|
21
|
+
getDirectionalCascadeViews: () => getDirectionalCascadeViews,
|
|
22
|
+
getPointShadowViews: () => getPointShadowViews,
|
|
23
|
+
getPracticalCascadeSplits: () => getPracticalCascadeSplits,
|
|
24
|
+
getSpotShadowView: () => getSpotShadowView
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(shadow_map_renderer_exports);
|
|
27
|
+
var import_core = require("@luma.gl/core");
|
|
28
|
+
var import_core2 = require("@math.gl/core");
|
|
29
|
+
var import_shadow_quality = require("./shadow-quality.cjs");
|
|
30
|
+
const MAX_DIRECTIONAL_LIGHTS = 1;
|
|
31
|
+
const MAX_SPOT_LIGHTS = 4;
|
|
32
|
+
const MAX_POINT_LIGHTS = 4;
|
|
33
|
+
const MAX_CASCADES = 4;
|
|
34
|
+
const POINT_FACE_COUNT = 6;
|
|
35
|
+
const DEFAULT_NEAR_PLANE = 0.1;
|
|
36
|
+
const OPENGL_TO_WEBGPU_MATRIX = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 1];
|
|
37
|
+
const IDENTITY_MATRIX = [1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1];
|
|
38
|
+
const POINT_FACE_ORIENTATIONS = [
|
|
39
|
+
{ face: "+X", direction: [1, 0, 0], up: [0, -1, 0] },
|
|
40
|
+
{ face: "-X", direction: [-1, 0, 0], up: [0, -1, 0] },
|
|
41
|
+
{ face: "+Y", direction: [0, 1, 0], up: [0, 0, 1] },
|
|
42
|
+
{ face: "-Y", direction: [0, -1, 0], up: [0, 0, -1] },
|
|
43
|
+
{ face: "+Z", direction: [0, 0, 1], up: [0, -1, 0] },
|
|
44
|
+
{ face: "-Z", direction: [0, 0, -1], up: [0, -1, 0] }
|
|
45
|
+
];
|
|
46
|
+
let nextShadowResourceId = 0;
|
|
47
|
+
class ShadowMapRenderer {
|
|
48
|
+
device;
|
|
49
|
+
props;
|
|
50
|
+
inputProps;
|
|
51
|
+
resources;
|
|
52
|
+
destroyed = false;
|
|
53
|
+
constructor(device, props = {}) {
|
|
54
|
+
if (device.type !== "webgpu" && device.type !== "webgl") {
|
|
55
|
+
throw new Error("ShadowMapRenderer requires a WebGPU or WebGL2 device.");
|
|
56
|
+
}
|
|
57
|
+
this.device = device;
|
|
58
|
+
this.inputProps = { ...props };
|
|
59
|
+
this.props = resolveShadowMapRendererProps(device, this.inputProps);
|
|
60
|
+
this.resources = createShadowMapResources(device, this.props);
|
|
61
|
+
}
|
|
62
|
+
/** Reconfigures capacities or quality, rebuilding GPU resources only when their shape changes. */
|
|
63
|
+
setProps(props) {
|
|
64
|
+
this.assertNotDestroyed();
|
|
65
|
+
const nextInputProps = { ...this.inputProps, ...props };
|
|
66
|
+
const nextProps = resolveShadowMapRendererProps(this.device, nextInputProps);
|
|
67
|
+
const needsResourceRebuild = !resourcePropsEqual(this.props, nextProps);
|
|
68
|
+
this.inputProps = nextInputProps;
|
|
69
|
+
this.props = nextProps;
|
|
70
|
+
if (!needsResourceRebuild) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const previousResources = this.resources;
|
|
74
|
+
this.resources = createShadowMapResources(this.device, nextProps);
|
|
75
|
+
destroyShadowMapResources(previousResources);
|
|
76
|
+
}
|
|
77
|
+
/** Records all active shadow-map views and returns props ready for `ShaderInputs.setProps`. */
|
|
78
|
+
render(options) {
|
|
79
|
+
this.assertNotDestroyed();
|
|
80
|
+
validateShadowCamera(options.camera);
|
|
81
|
+
const directionalLights = options.directionalLights || [];
|
|
82
|
+
const spotLights = options.spotLights || [];
|
|
83
|
+
const pointLights = options.pointLights || [];
|
|
84
|
+
validateLightCount("directional", directionalLights.length, this.props.directionalLightCapacity);
|
|
85
|
+
validateLightCount("spot", spotLights.length, this.props.spotLightCapacity);
|
|
86
|
+
validateLightCount("point", pointLights.length, this.props.pointLightCapacity);
|
|
87
|
+
const directionalViews = [];
|
|
88
|
+
let cascadeSplits = padCascadeSplits([], options.camera.far);
|
|
89
|
+
if (directionalLights[0]) {
|
|
90
|
+
const light = resolveDirectionalLight(directionalLights[0], options.camera);
|
|
91
|
+
cascadeSplits = padCascadeSplits(getPracticalCascadeSplits(options.camera.near, light.shadowDistance, this.props.cascadeCount, light.cascadeSplitLambda), light.shadowDistance);
|
|
92
|
+
directionalViews.push(...getDirectionalCascadeViews(options.camera, light, cascadeSplits, this.props.cascadeCount, this.props.directionalMapSize));
|
|
93
|
+
directionalViews.forEach((view, cascadeIndex) => {
|
|
94
|
+
this.renderView({
|
|
95
|
+
framebuffer: this.resources.directionalFramebuffers[cascadeIndex],
|
|
96
|
+
view,
|
|
97
|
+
type: "directional",
|
|
98
|
+
lightIndex: 0,
|
|
99
|
+
cascadeIndex,
|
|
100
|
+
mapSize: this.props.directionalMapSize,
|
|
101
|
+
light,
|
|
102
|
+
drawShadowCasters: options.drawShadowCasters,
|
|
103
|
+
prepareShadowCasters: options.prepareShadowCasters
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const spotViews = spotLights.map((light) => getSpotShadowView(resolveSpotLight(light)));
|
|
108
|
+
spotViews.forEach((view, lightIndex) => {
|
|
109
|
+
this.renderView({
|
|
110
|
+
framebuffer: this.resources.spotFramebuffers[lightIndex],
|
|
111
|
+
view,
|
|
112
|
+
type: "spot",
|
|
113
|
+
lightIndex,
|
|
114
|
+
mapSize: this.props.spotMapSize,
|
|
115
|
+
light: resolveSpotLight(spotLights[lightIndex]),
|
|
116
|
+
drawShadowCasters: options.drawShadowCasters,
|
|
117
|
+
prepareShadowCasters: options.prepareShadowCasters
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
const pointViews = pointLights.flatMap((light) => getPointShadowViews(resolvePointLight(light)));
|
|
121
|
+
pointLights.forEach((inputLight, lightIndex) => {
|
|
122
|
+
const light = resolvePointLight(inputLight);
|
|
123
|
+
for (let faceIndex = 0; faceIndex < POINT_FACE_COUNT; faceIndex++) {
|
|
124
|
+
const viewIndex = lightIndex * POINT_FACE_COUNT + faceIndex;
|
|
125
|
+
this.renderView({
|
|
126
|
+
framebuffer: this.resources.pointFramebuffers[viewIndex],
|
|
127
|
+
view: pointViews[viewIndex],
|
|
128
|
+
type: "point",
|
|
129
|
+
lightIndex,
|
|
130
|
+
pointFace: POINT_FACE_ORIENTATIONS[faceIndex].face,
|
|
131
|
+
mapSize: this.props.pointMapSize,
|
|
132
|
+
light,
|
|
133
|
+
drawShadowCasters: options.drawShadowCasters,
|
|
134
|
+
prepareShadowCasters: options.prepareShadowCasters
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
return {
|
|
139
|
+
quality: this.props.quality,
|
|
140
|
+
cascadeCount: this.props.cascadeCount,
|
|
141
|
+
cascadeSplits,
|
|
142
|
+
blockerSampleCount: this.props.blockerSampleCount,
|
|
143
|
+
filterSampleCount: this.props.filterSampleCount,
|
|
144
|
+
directionalLights: directionalLights.map((light) => resolveDirectionalLight(light, options.camera)),
|
|
145
|
+
spotLights: spotLights.map(resolveSpotLight),
|
|
146
|
+
pointLights: pointLights.map(resolvePointLight),
|
|
147
|
+
directionalViewProjectionMatrices: padMatrices(directionalViews.map((view) => view.viewProjectionMatrix), MAX_CASCADES),
|
|
148
|
+
spotViewProjectionMatrices: padMatrices(spotViews.map((view) => view.viewProjectionMatrix), MAX_SPOT_LIGHTS),
|
|
149
|
+
pointViewProjectionMatrices: padMatrices(pointViews.map((view) => view.viewProjectionMatrix), MAX_POINT_LIGHTS * POINT_FACE_COUNT),
|
|
150
|
+
directionalShadowTexture: this.resources.directionalTexture,
|
|
151
|
+
spotShadowTexture: this.resources.spotTexture,
|
|
152
|
+
pointShadowTexture: this.resources.pointTexture,
|
|
153
|
+
comparisonSampler: this.resources.comparisonSampler,
|
|
154
|
+
nonFilteringSampler: this.resources.nonFilteringSampler
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/** Destroys all owned depth textures, views, framebuffers and samplers. */
|
|
158
|
+
destroy() {
|
|
159
|
+
if (this.destroyed) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
this.destroyed = true;
|
|
163
|
+
destroyShadowMapResources(this.resources);
|
|
164
|
+
}
|
|
165
|
+
renderView(options) {
|
|
166
|
+
var _a;
|
|
167
|
+
const rasterParameters = Object.freeze({
|
|
168
|
+
depthWriteEnabled: true,
|
|
169
|
+
depthCompare: "less-equal",
|
|
170
|
+
depthBias: options.light.depthBias,
|
|
171
|
+
depthBiasSlopeScale: options.light.depthBiasSlopeScale,
|
|
172
|
+
cullMode: "back"
|
|
173
|
+
});
|
|
174
|
+
const context = {
|
|
175
|
+
framebuffer: options.framebuffer,
|
|
176
|
+
type: options.type,
|
|
177
|
+
lightIndex: options.lightIndex,
|
|
178
|
+
cascadeIndex: options.cascadeIndex,
|
|
179
|
+
pointFace: options.pointFace,
|
|
180
|
+
camera: options.view.camera,
|
|
181
|
+
viewProjectionMatrix: options.view.viewProjectionMatrix,
|
|
182
|
+
mapSize: options.mapSize,
|
|
183
|
+
rasterParameters
|
|
184
|
+
};
|
|
185
|
+
(_a = options.prepareShadowCasters) == null ? void 0 : _a.call(options, context);
|
|
186
|
+
const renderPass = this.device.beginRenderPass({
|
|
187
|
+
id: makeShadowResourceId(`${options.type}-shadow-pass`),
|
|
188
|
+
framebuffer: options.framebuffer,
|
|
189
|
+
clearDepth: 1
|
|
190
|
+
});
|
|
191
|
+
try {
|
|
192
|
+
options.drawShadowCasters({
|
|
193
|
+
renderPass,
|
|
194
|
+
framebuffer: options.framebuffer,
|
|
195
|
+
type: options.type,
|
|
196
|
+
lightIndex: options.lightIndex,
|
|
197
|
+
cascadeIndex: options.cascadeIndex,
|
|
198
|
+
pointFace: options.pointFace,
|
|
199
|
+
camera: options.view.camera,
|
|
200
|
+
viewProjectionMatrix: options.view.viewProjectionMatrix,
|
|
201
|
+
mapSize: options.mapSize,
|
|
202
|
+
rasterParameters
|
|
203
|
+
});
|
|
204
|
+
} finally {
|
|
205
|
+
renderPass.end();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
assertNotDestroyed() {
|
|
209
|
+
if (this.destroyed) {
|
|
210
|
+
throw new Error("ShadowMapRenderer has been destroyed.");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function getPracticalCascadeSplits(near, far, cascadeCount, lambda = 0.5) {
|
|
215
|
+
if (!(near > 0 && far > near)) {
|
|
216
|
+
throw new Error("Cascade split range requires 0 < near < far.");
|
|
217
|
+
}
|
|
218
|
+
if (!Number.isInteger(cascadeCount) || cascadeCount < 1 || cascadeCount > MAX_CASCADES) {
|
|
219
|
+
throw new Error(`Cascade count must be an integer from 1 to ${MAX_CASCADES}.`);
|
|
220
|
+
}
|
|
221
|
+
const clampedLambda = clamp(lambda, 0, 1);
|
|
222
|
+
const splits = [];
|
|
223
|
+
for (let splitIndex = 1; splitIndex <= cascadeCount; splitIndex++) {
|
|
224
|
+
const fraction = splitIndex / cascadeCount;
|
|
225
|
+
const logarithmic = near * Math.pow(far / near, fraction);
|
|
226
|
+
const uniform = near + (far - near) * fraction;
|
|
227
|
+
splits.push(uniform * (1 - clampedLambda) + logarithmic * clampedLambda);
|
|
228
|
+
}
|
|
229
|
+
return splits;
|
|
230
|
+
}
|
|
231
|
+
function getDirectionalCascadeViews(camera, light, cascadeSplits, cascadeCount, mapSize) {
|
|
232
|
+
const inverseViewProjection = new import_core2.Matrix4(camera.projectionMatrix).multiplyRight(camera.viewMatrix).invert();
|
|
233
|
+
const nearCorners = getNdcPlaneCorners(inverseViewProjection, camera.clipDepth === "zero-to-one" ? 0 : -1);
|
|
234
|
+
const farCorners = getNdcPlaneCorners(inverseViewProjection, 1);
|
|
235
|
+
const lightDirection = normalize3(light.direction);
|
|
236
|
+
const views = [];
|
|
237
|
+
let cascadeNear = camera.near;
|
|
238
|
+
for (let cascadeIndex = 0; cascadeIndex < cascadeCount; cascadeIndex++) {
|
|
239
|
+
const cascadeFar = cascadeSplits[cascadeIndex];
|
|
240
|
+
const nearFraction = (cascadeNear - camera.near) / (camera.far - camera.near);
|
|
241
|
+
const farFraction = (cascadeFar - camera.near) / (camera.far - camera.near);
|
|
242
|
+
const corners = [];
|
|
243
|
+
for (let cornerIndex = 0; cornerIndex < 4; cornerIndex++) {
|
|
244
|
+
corners.push(lerp3(nearCorners[cornerIndex], farCorners[cornerIndex], nearFraction));
|
|
245
|
+
corners.push(lerp3(nearCorners[cornerIndex], farCorners[cornerIndex], farFraction));
|
|
246
|
+
}
|
|
247
|
+
const center = average3(corners);
|
|
248
|
+
let radius = 0;
|
|
249
|
+
for (const corner of corners) {
|
|
250
|
+
radius = Math.max(radius, distance3(center, corner));
|
|
251
|
+
}
|
|
252
|
+
radius = Math.ceil(radius * 16) / 16;
|
|
253
|
+
const texelWorldSize = radius * 2 / mapSize;
|
|
254
|
+
const lightForward = scale3(lightDirection, -1);
|
|
255
|
+
const referenceUp = Math.abs(lightForward[1]) > 0.99 ? [0, 0, 1] : [0, 1, 0];
|
|
256
|
+
const lightRight = normalize3(cross3(lightForward, referenceUp));
|
|
257
|
+
const lightUp = normalize3(cross3(lightRight, lightForward));
|
|
258
|
+
const centerRight = dot3(center, lightRight);
|
|
259
|
+
const centerUp = dot3(center, lightUp);
|
|
260
|
+
const snappedCenter = add3(center, add3(scale3(lightRight, Math.round(centerRight / texelWorldSize) * texelWorldSize - centerRight), scale3(lightUp, Math.round(centerUp / texelWorldSize) * texelWorldSize - centerUp)));
|
|
261
|
+
const eye = add3(snappedCenter, scale3(lightDirection, radius + light.casterDistance));
|
|
262
|
+
const viewMatrix = new import_core2.Matrix4().lookAt({ eye, center: snappedCenter, up: lightUp });
|
|
263
|
+
const projectionMatrix = new import_core2.Matrix4(OPENGL_TO_WEBGPU_MATRIX).multiplyRight(new import_core2.Matrix4().ortho({
|
|
264
|
+
left: -radius,
|
|
265
|
+
right: radius,
|
|
266
|
+
bottom: -radius,
|
|
267
|
+
top: radius,
|
|
268
|
+
near: 0.01,
|
|
269
|
+
far: radius * 2 + light.casterDistance
|
|
270
|
+
}));
|
|
271
|
+
views.push({
|
|
272
|
+
camera: {
|
|
273
|
+
viewMatrix,
|
|
274
|
+
projectionMatrix,
|
|
275
|
+
near: 0.01,
|
|
276
|
+
far: radius * 2 + light.casterDistance,
|
|
277
|
+
clipDepth: "zero-to-one"
|
|
278
|
+
},
|
|
279
|
+
viewProjectionMatrix: new import_core2.Matrix4(projectionMatrix).multiplyRight(viewMatrix)
|
|
280
|
+
});
|
|
281
|
+
cascadeNear = cascadeFar;
|
|
282
|
+
}
|
|
283
|
+
return views;
|
|
284
|
+
}
|
|
285
|
+
function getSpotShadowView(light) {
|
|
286
|
+
const direction = normalize3(light.direction);
|
|
287
|
+
const up = Math.abs(direction[1]) > 0.99 ? [0, 0, 1] : [0, 1, 0];
|
|
288
|
+
const viewMatrix = new import_core2.Matrix4().lookAt({
|
|
289
|
+
eye: light.position,
|
|
290
|
+
center: add3(light.position, direction),
|
|
291
|
+
up
|
|
292
|
+
});
|
|
293
|
+
const projectionMatrix = new import_core2.Matrix4(OPENGL_TO_WEBGPU_MATRIX).multiplyRight(new import_core2.Matrix4().perspective({
|
|
294
|
+
fovy: light.outerConeAngle * 2,
|
|
295
|
+
aspect: 1,
|
|
296
|
+
near: light.nearPlane,
|
|
297
|
+
far: light.range
|
|
298
|
+
}));
|
|
299
|
+
return {
|
|
300
|
+
camera: {
|
|
301
|
+
viewMatrix,
|
|
302
|
+
projectionMatrix,
|
|
303
|
+
near: light.nearPlane,
|
|
304
|
+
far: light.range,
|
|
305
|
+
clipDepth: "zero-to-one"
|
|
306
|
+
},
|
|
307
|
+
viewProjectionMatrix: new import_core2.Matrix4(projectionMatrix).multiplyRight(viewMatrix)
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
function getPointShadowViews(light) {
|
|
311
|
+
const projectionMatrix = new import_core2.Matrix4(OPENGL_TO_WEBGPU_MATRIX).multiplyRight(new import_core2.Matrix4().perspective({
|
|
312
|
+
fovy: (0, import_core2.radians)(90),
|
|
313
|
+
aspect: 1,
|
|
314
|
+
near: light.nearPlane,
|
|
315
|
+
far: light.range
|
|
316
|
+
}));
|
|
317
|
+
return POINT_FACE_ORIENTATIONS.map((orientation) => {
|
|
318
|
+
const viewMatrix = new import_core2.Matrix4().lookAt({
|
|
319
|
+
eye: light.position,
|
|
320
|
+
center: add3(light.position, orientation.direction),
|
|
321
|
+
up: orientation.up
|
|
322
|
+
});
|
|
323
|
+
return {
|
|
324
|
+
camera: {
|
|
325
|
+
viewMatrix,
|
|
326
|
+
projectionMatrix,
|
|
327
|
+
near: light.nearPlane,
|
|
328
|
+
far: light.range,
|
|
329
|
+
clipDepth: "zero-to-one"
|
|
330
|
+
},
|
|
331
|
+
viewProjectionMatrix: new import_core2.Matrix4(projectionMatrix).multiplyRight(viewMatrix)
|
|
332
|
+
};
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
function resolveShadowMapRendererProps(device, props) {
|
|
336
|
+
const quality = props.quality || "balanced";
|
|
337
|
+
const qualitySettings = import_shadow_quality.SHADOW_QUALITY_SETTINGS[quality];
|
|
338
|
+
if (!qualitySettings) {
|
|
339
|
+
throw new Error(`Unknown shadow quality: ${String(quality)}.`);
|
|
340
|
+
}
|
|
341
|
+
const resolved = {
|
|
342
|
+
quality,
|
|
343
|
+
directionalLightCapacity: props.directionalLightCapacity ?? 1,
|
|
344
|
+
spotLightCapacity: props.spotLightCapacity ?? 1,
|
|
345
|
+
pointLightCapacity: props.pointLightCapacity ?? 1,
|
|
346
|
+
directionalMapSize: props.directionalMapSize ?? qualitySettings.directionalMapSize,
|
|
347
|
+
spotMapSize: props.spotMapSize ?? qualitySettings.spotMapSize,
|
|
348
|
+
pointMapSize: props.pointMapSize ?? qualitySettings.pointMapSize,
|
|
349
|
+
cascadeCount: qualitySettings.cascadeCount,
|
|
350
|
+
blockerSampleCount: qualitySettings.blockerSampleCount,
|
|
351
|
+
filterSampleCount: qualitySettings.filterSampleCount
|
|
352
|
+
};
|
|
353
|
+
validateCapacity("directionalLightCapacity", resolved.directionalLightCapacity, MAX_DIRECTIONAL_LIGHTS);
|
|
354
|
+
validateCapacity("spotLightCapacity", resolved.spotLightCapacity, MAX_SPOT_LIGHTS);
|
|
355
|
+
validateCapacity("pointLightCapacity", resolved.pointLightCapacity, MAX_POINT_LIGHTS);
|
|
356
|
+
validateMapSize(device, "directionalMapSize", resolved.directionalMapSize);
|
|
357
|
+
validateMapSize(device, "spotMapSize", resolved.spotMapSize);
|
|
358
|
+
validateMapSize(device, "pointMapSize", resolved.pointMapSize);
|
|
359
|
+
const pointLayers = Math.max(POINT_FACE_COUNT, resolved.pointLightCapacity * POINT_FACE_COUNT);
|
|
360
|
+
if (pointLayers > device.limits.maxTextureArrayLayers) {
|
|
361
|
+
throw new Error(`pointLightCapacity requires ${pointLayers} array layers, exceeding the device limit ${device.limits.maxTextureArrayLayers}.`);
|
|
362
|
+
}
|
|
363
|
+
return resolved;
|
|
364
|
+
}
|
|
365
|
+
function createShadowMapResources(device, props) {
|
|
366
|
+
const directionalLayers = Math.max(1, props.directionalLightCapacity * props.cascadeCount);
|
|
367
|
+
const spotLayers = Math.max(1, props.spotLightCapacity);
|
|
368
|
+
const pointLayers = Math.max(POINT_FACE_COUNT, props.pointLightCapacity * POINT_FACE_COUNT);
|
|
369
|
+
const comparisonSampler = device.createSampler({
|
|
370
|
+
id: makeShadowResourceId("shadow-comparison-sampler"),
|
|
371
|
+
type: "comparison-sampler",
|
|
372
|
+
compare: "less-equal",
|
|
373
|
+
minFilter: "linear",
|
|
374
|
+
magFilter: "linear",
|
|
375
|
+
addressModeU: "clamp-to-edge",
|
|
376
|
+
addressModeV: "clamp-to-edge",
|
|
377
|
+
addressModeW: "clamp-to-edge"
|
|
378
|
+
});
|
|
379
|
+
const nonFilteringSampler = device.createSampler({
|
|
380
|
+
id: makeShadowResourceId("shadow-depth-sampler"),
|
|
381
|
+
minFilter: "nearest",
|
|
382
|
+
magFilter: "nearest",
|
|
383
|
+
addressModeU: "clamp-to-edge",
|
|
384
|
+
addressModeV: "clamp-to-edge",
|
|
385
|
+
addressModeW: "clamp-to-edge"
|
|
386
|
+
});
|
|
387
|
+
const directionalTexture = createDepthArrayTexture(device, "directional-shadow-map", "2d-array", props.directionalMapSize, directionalLayers, nonFilteringSampler);
|
|
388
|
+
const spotTexture = createDepthArrayTexture(device, "spot-shadow-map", "2d-array", props.spotMapSize, spotLayers, nonFilteringSampler);
|
|
389
|
+
const pointTexture = createDepthArrayTexture(device, "point-shadow-map", device.type === "webgpu" ? "cube-array" : "2d-array", props.pointMapSize, pointLayers, nonFilteringSampler);
|
|
390
|
+
const attachmentViews = [];
|
|
391
|
+
const directionalFramebuffers = createLayerFramebuffers(device, directionalTexture, props.directionalMapSize, directionalLayers, attachmentViews);
|
|
392
|
+
const spotFramebuffers = createLayerFramebuffers(device, spotTexture, props.spotMapSize, spotLayers, attachmentViews);
|
|
393
|
+
const pointFramebuffers = createLayerFramebuffers(device, pointTexture, props.pointMapSize, pointLayers, attachmentViews);
|
|
394
|
+
return {
|
|
395
|
+
directionalTexture,
|
|
396
|
+
spotTexture,
|
|
397
|
+
pointTexture,
|
|
398
|
+
comparisonSampler,
|
|
399
|
+
nonFilteringSampler,
|
|
400
|
+
directionalFramebuffers,
|
|
401
|
+
spotFramebuffers,
|
|
402
|
+
pointFramebuffers,
|
|
403
|
+
attachmentViews
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
function createDepthArrayTexture(device, id, dimension, size, depth, sampler) {
|
|
407
|
+
return device.createTexture({
|
|
408
|
+
id: makeShadowResourceId(id),
|
|
409
|
+
dimension,
|
|
410
|
+
format: "depth32float",
|
|
411
|
+
width: size,
|
|
412
|
+
height: size,
|
|
413
|
+
depth,
|
|
414
|
+
sampler,
|
|
415
|
+
usage: import_core.Texture.SAMPLE | import_core.Texture.RENDER
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
function createLayerFramebuffers(device, texture, size, layerCount, views) {
|
|
419
|
+
return Array.from({ length: layerCount }, (_, layerIndex) => {
|
|
420
|
+
const view = texture.createView({
|
|
421
|
+
id: makeShadowResourceId("shadow-layer-view"),
|
|
422
|
+
format: texture.format,
|
|
423
|
+
dimension: "2d",
|
|
424
|
+
baseMipLevel: 0,
|
|
425
|
+
mipLevelCount: 1,
|
|
426
|
+
baseArrayLayer: layerIndex,
|
|
427
|
+
arrayLayerCount: 1
|
|
428
|
+
});
|
|
429
|
+
views.push(view);
|
|
430
|
+
return device.createFramebuffer({
|
|
431
|
+
id: makeShadowResourceId("shadow-layer-framebuffer"),
|
|
432
|
+
width: size,
|
|
433
|
+
height: size,
|
|
434
|
+
colorAttachments: [],
|
|
435
|
+
depthStencilAttachment: view
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
function destroyShadowMapResources(resources) {
|
|
440
|
+
for (const framebuffer of [
|
|
441
|
+
...resources.directionalFramebuffers,
|
|
442
|
+
...resources.spotFramebuffers,
|
|
443
|
+
...resources.pointFramebuffers
|
|
444
|
+
]) {
|
|
445
|
+
framebuffer.destroy();
|
|
446
|
+
}
|
|
447
|
+
for (const view of resources.attachmentViews) {
|
|
448
|
+
view.destroy();
|
|
449
|
+
}
|
|
450
|
+
resources.directionalTexture.destroy();
|
|
451
|
+
resources.spotTexture.destroy();
|
|
452
|
+
resources.pointTexture.destroy();
|
|
453
|
+
resources.comparisonSampler.destroy();
|
|
454
|
+
resources.nonFilteringSampler.destroy();
|
|
455
|
+
}
|
|
456
|
+
function resourcePropsEqual(first, second) {
|
|
457
|
+
return first.cascadeCount === second.cascadeCount && first.directionalLightCapacity === second.directionalLightCapacity && first.spotLightCapacity === second.spotLightCapacity && first.pointLightCapacity === second.pointLightCapacity && first.directionalMapSize === second.directionalMapSize && first.spotMapSize === second.spotMapSize && first.pointMapSize === second.pointMapSize;
|
|
458
|
+
}
|
|
459
|
+
function resolveDirectionalLight(light, camera) {
|
|
460
|
+
const shadowDistance = clamp(light.shadowDistance ?? camera.far, camera.near, camera.far);
|
|
461
|
+
return {
|
|
462
|
+
direction: normalize3(light.direction),
|
|
463
|
+
shadowDistance,
|
|
464
|
+
casterDistance: light.casterDistance ?? shadowDistance,
|
|
465
|
+
sourceAngularRadius: light.sourceAngularRadius ?? 465e-5,
|
|
466
|
+
cascadeSplitLambda: light.cascadeSplitLambda ?? 0.5,
|
|
467
|
+
cascadeBlendFraction: light.cascadeBlendFraction ?? 0.1,
|
|
468
|
+
farFadeFraction: light.farFadeFraction ?? 0.1,
|
|
469
|
+
normalBias: light.normalBias ?? 0.04,
|
|
470
|
+
depthBias: light.depthBias ?? 2,
|
|
471
|
+
depthBiasSlopeScale: light.depthBiasSlopeScale ?? 2,
|
|
472
|
+
strength: clamp(light.strength ?? 1, 0, 1)
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
function resolveSpotLight(light) {
|
|
476
|
+
validateRange("Spot shadow", light.range);
|
|
477
|
+
if (!(light.outerConeAngle > 0 && light.outerConeAngle < Math.PI / 2)) {
|
|
478
|
+
throw new Error("Spot shadow outerConeAngle must be between 0 and PI / 2 radians.");
|
|
479
|
+
}
|
|
480
|
+
return {
|
|
481
|
+
position: [...light.position],
|
|
482
|
+
direction: normalize3(light.direction),
|
|
483
|
+
range: light.range,
|
|
484
|
+
outerConeAngle: light.outerConeAngle,
|
|
485
|
+
nearPlane: resolveNearPlane(light.nearPlane, light.range),
|
|
486
|
+
sourceRadius: light.sourceRadius ?? 0.2,
|
|
487
|
+
normalBias: light.normalBias ?? 0.025,
|
|
488
|
+
depthBias: light.depthBias ?? 2,
|
|
489
|
+
depthBiasSlopeScale: light.depthBiasSlopeScale ?? 2,
|
|
490
|
+
strength: clamp(light.strength ?? 1, 0, 1)
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
function resolvePointLight(light) {
|
|
494
|
+
validateRange("Point shadow", light.range);
|
|
495
|
+
return {
|
|
496
|
+
position: [...light.position],
|
|
497
|
+
range: light.range,
|
|
498
|
+
nearPlane: resolveNearPlane(light.nearPlane, light.range),
|
|
499
|
+
sourceRadius: light.sourceRadius ?? 0.2,
|
|
500
|
+
normalBias: light.normalBias ?? 0.025,
|
|
501
|
+
depthBias: light.depthBias ?? 2,
|
|
502
|
+
depthBiasSlopeScale: light.depthBiasSlopeScale ?? 2,
|
|
503
|
+
strength: clamp(light.strength ?? 1, 0, 1)
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
function resolveNearPlane(nearPlane, range) {
|
|
507
|
+
const resolvedNearPlane = nearPlane ?? Math.max(DEFAULT_NEAR_PLANE, range / 1e3);
|
|
508
|
+
if (!(resolvedNearPlane > 0 && resolvedNearPlane < range)) {
|
|
509
|
+
throw new Error("Shadow nearPlane must be greater than zero and less than range.");
|
|
510
|
+
}
|
|
511
|
+
return resolvedNearPlane;
|
|
512
|
+
}
|
|
513
|
+
function validateShadowCamera(camera) {
|
|
514
|
+
if (!(camera.near > 0 && camera.far > camera.near)) {
|
|
515
|
+
throw new Error("ShadowCamera requires 0 < near < far.");
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
function validateCapacity(name, value, maximum) {
|
|
519
|
+
if (!Number.isInteger(value) || value < 0 || value > maximum) {
|
|
520
|
+
throw new Error(`${name} must be an integer from 0 to ${maximum}.`);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
function validateMapSize(device, name, value) {
|
|
524
|
+
if (!Number.isInteger(value) || value < 1 || value > device.limits.maxTextureDimension2D) {
|
|
525
|
+
throw new Error(`${name} must be a positive integer no greater than ${device.limits.maxTextureDimension2D}.`);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
function validateLightCount(type, count, capacity) {
|
|
529
|
+
if (count > capacity) {
|
|
530
|
+
throw new Error(`${type} shadow light count ${count} exceeds configured capacity ${capacity}.`);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
function validateRange(label, range) {
|
|
534
|
+
if (!(range > 0 && Number.isFinite(range))) {
|
|
535
|
+
throw new Error(`${label} range must be a finite positive number.`);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
function padCascadeSplits(splits, fallback) {
|
|
539
|
+
const result = splits.slice(0, MAX_CASCADES);
|
|
540
|
+
while (result.length < MAX_CASCADES) {
|
|
541
|
+
result.push(result[result.length - 1] ?? fallback);
|
|
542
|
+
}
|
|
543
|
+
return result;
|
|
544
|
+
}
|
|
545
|
+
function padMatrices(matrices, count) {
|
|
546
|
+
const result = matrices.slice(0, count);
|
|
547
|
+
while (result.length < count) {
|
|
548
|
+
result.push(IDENTITY_MATRIX);
|
|
549
|
+
}
|
|
550
|
+
return result;
|
|
551
|
+
}
|
|
552
|
+
function getNdcPlaneCorners(matrix, z) {
|
|
553
|
+
return [
|
|
554
|
+
transformHomogeneous(matrix, [-1, -1, z]),
|
|
555
|
+
transformHomogeneous(matrix, [1, -1, z]),
|
|
556
|
+
transformHomogeneous(matrix, [1, 1, z]),
|
|
557
|
+
transformHomogeneous(matrix, [-1, 1, z])
|
|
558
|
+
];
|
|
559
|
+
}
|
|
560
|
+
function transformHomogeneous(matrix, point) {
|
|
561
|
+
const x = point[0];
|
|
562
|
+
const y = point[1];
|
|
563
|
+
const z = point[2];
|
|
564
|
+
const w = matrix[3] * x + matrix[7] * y + matrix[11] * z + matrix[15];
|
|
565
|
+
return [
|
|
566
|
+
(matrix[0] * x + matrix[4] * y + matrix[8] * z + matrix[12]) / w,
|
|
567
|
+
(matrix[1] * x + matrix[5] * y + matrix[9] * z + matrix[13]) / w,
|
|
568
|
+
(matrix[2] * x + matrix[6] * y + matrix[10] * z + matrix[14]) / w
|
|
569
|
+
];
|
|
570
|
+
}
|
|
571
|
+
function normalize3(vector) {
|
|
572
|
+
const length = Math.hypot(vector[0], vector[1], vector[2]);
|
|
573
|
+
if (!(length > 0)) {
|
|
574
|
+
throw new Error("Shadow light direction must be non-zero.");
|
|
575
|
+
}
|
|
576
|
+
return [vector[0] / length, vector[1] / length, vector[2] / length];
|
|
577
|
+
}
|
|
578
|
+
function add3(first, second) {
|
|
579
|
+
return [first[0] + second[0], first[1] + second[1], first[2] + second[2]];
|
|
580
|
+
}
|
|
581
|
+
function scale3(vector, scale) {
|
|
582
|
+
return [vector[0] * scale, vector[1] * scale, vector[2] * scale];
|
|
583
|
+
}
|
|
584
|
+
function dot3(first, second) {
|
|
585
|
+
return first[0] * second[0] + first[1] * second[1] + first[2] * second[2];
|
|
586
|
+
}
|
|
587
|
+
function cross3(first, second) {
|
|
588
|
+
return [
|
|
589
|
+
first[1] * second[2] - first[2] * second[1],
|
|
590
|
+
first[2] * second[0] - first[0] * second[2],
|
|
591
|
+
first[0] * second[1] - first[1] * second[0]
|
|
592
|
+
];
|
|
593
|
+
}
|
|
594
|
+
function lerp3(first, second, t) {
|
|
595
|
+
return [
|
|
596
|
+
first[0] + (second[0] - first[0]) * t,
|
|
597
|
+
first[1] + (second[1] - first[1]) * t,
|
|
598
|
+
first[2] + (second[2] - first[2]) * t
|
|
599
|
+
];
|
|
600
|
+
}
|
|
601
|
+
function average3(vectors) {
|
|
602
|
+
const sum = [0, 0, 0];
|
|
603
|
+
for (const vector of vectors) {
|
|
604
|
+
sum[0] += vector[0];
|
|
605
|
+
sum[1] += vector[1];
|
|
606
|
+
sum[2] += vector[2];
|
|
607
|
+
}
|
|
608
|
+
return scale3(sum, 1 / vectors.length);
|
|
609
|
+
}
|
|
610
|
+
function distance3(first, second) {
|
|
611
|
+
return Math.hypot(first[0] - second[0], first[1] - second[1], first[2] - second[2]);
|
|
612
|
+
}
|
|
613
|
+
function clamp(value, minimum, maximum) {
|
|
614
|
+
return Math.max(minimum, Math.min(maximum, value));
|
|
615
|
+
}
|
|
616
|
+
function makeShadowResourceId(prefix) {
|
|
617
|
+
nextShadowResourceId += 1;
|
|
618
|
+
return `${prefix}-${nextShadowResourceId}`;
|
|
619
|
+
}
|
|
620
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
621
|
+
0 && (module.exports = {
|
|
622
|
+
ShadowMapRenderer,
|
|
623
|
+
getDirectionalCascadeViews,
|
|
624
|
+
getPointShadowViews,
|
|
625
|
+
getPracticalCascadeSplits,
|
|
626
|
+
getSpotShadowView
|
|
627
|
+
});
|