@zephyr3d/scene 0.9.6 → 0.9.7
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/joint_dynamics/controller.js +92 -32
- package/dist/animation/joint_dynamics/controller.js.map +1 -1
- package/dist/animation/joint_dynamics/convex_collider.js +320 -0
- package/dist/animation/joint_dynamics/convex_collider.js.map +1 -0
- package/dist/animation/joint_dynamics/joint_dynamics_system.js +57 -19
- package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
- package/dist/animation/joint_dynamics/solver.js +71 -27
- package/dist/animation/joint_dynamics/solver.js.map +1 -1
- package/dist/animation/joint_dynamics_modifier.js +21 -20
- package/dist/animation/joint_dynamics_modifier.js.map +1 -1
- package/dist/animation/skeleton.js +7 -10
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/app/engine.js +134 -140
- package/dist/app/engine.js.map +1 -1
- package/dist/app/scriptregistry.js +47 -16
- package/dist/app/scriptregistry.js.map +1 -1
- package/dist/asset/assetmanager.js +3 -1
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/model.js +346 -7
- package/dist/asset/model.js.map +1 -1
- package/dist/avatar/wardrobe.js +20 -16
- package/dist/avatar/wardrobe.js.map +1 -1
- package/dist/camera/camera.js +416 -210
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +1349 -621
- package/dist/index.js +6 -11
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +1 -1
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/lambert.js +1 -1
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +23 -1
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +178 -23
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +4 -4
- package/dist/material/mixins/albedocolor.js.map +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js +2 -1
- package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
- package/dist/material/mixins/lightmodel/lambert.js +2 -1
- package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +63 -16
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +105 -32
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +16 -6
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/lit.js +1 -1
- package/dist/material/mixins/lit.js.map +1 -1
- package/dist/material/mixins/pbr/common.js +276 -65
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/mixins/texture.js +3 -3
- package/dist/material/mixins/texture.js.map +1 -1
- package/dist/material/mixins/vertexcolor.js +2 -2
- package/dist/material/mixins/vertexcolor.js.map +1 -1
- package/dist/material/mtoon.js +574 -0
- package/dist/material/mtoon.js.map +1 -0
- package/dist/material/pbrblueprint.js +499 -336
- package/dist/material/pbrblueprint.js.map +1 -1
- package/dist/material/pbrmr.js +118 -100
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +1 -1
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +324 -294
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/subsurfaceprofile.js +812 -0
- package/dist/material/subsurfaceprofile.js.map +1 -0
- package/dist/material/unlit.js +1 -1
- package/dist/material/unlit.js.map +1 -1
- package/dist/posteffect/compositor.js +46 -11
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/ssr.js +422 -96
- package/dist/posteffect/ssr.js.map +1 -1
- package/dist/posteffect/sss.js +1053 -0
- package/dist/posteffect/sss.js.map +1 -0
- package/dist/posteffect/taa.js +61 -60
- package/dist/posteffect/taa.js.map +1 -1
- package/dist/render/abuffer_oit.js +63 -12
- package/dist/render/abuffer_oit.js.map +1 -1
- package/dist/render/cluster_light.js +6 -5
- package/dist/render/cluster_light.js.map +1 -1
- package/dist/render/drawable.js +1 -5
- package/dist/render/drawable.js.map +1 -1
- package/dist/render/drawable_mixin.js +2 -1
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/fbm_wavegenerator.js +2 -1
- package/dist/render/fbm_wavegenerator.js.map +1 -1
- package/dist/render/gerstner_wavegenerator.js +2 -1
- package/dist/render/gerstner_wavegenerator.js.map +1 -1
- package/dist/render/globalbindgroup_allocator.js +2 -1
- package/dist/render/globalbindgroup_allocator.js.map +1 -1
- package/dist/render/lightpass.js +110 -23
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/render_queue.js +51 -8
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +80 -66
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/rendergraph/device_pool_allocator.js +8 -0
- package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +481 -95
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/history_resource_manager.js +55 -0
- package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
- package/dist/render/rendergraph/history_resources.js +3 -1
- package/dist/render/rendergraph/history_resources.js.map +1 -1
- package/dist/render/rendergraph/types.js.map +1 -1
- package/dist/render/renderpass.js +10 -4
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/sky.js +31 -1
- package/dist/render/sky.js.map +1 -1
- package/dist/render/weightedblended_oit.js +23 -5
- package/dist/render/weightedblended_oit.js.map +1 -1
- package/dist/scene/basesprite.js +4 -2
- package/dist/scene/basesprite.js.map +1 -1
- package/dist/scene/batchgroup.js +3 -1
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +11 -1
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/light.js +21 -3
- package/dist/scene/light.js.map +1 -1
- package/dist/scene/mesh.js +29 -14
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/meshdrawable.js +6 -0
- package/dist/scene/meshdrawable.js.map +1 -1
- package/dist/scene/msdftext.js +5 -2
- package/dist/scene/msdftext.js.map +1 -1
- package/dist/scene/msdftextsprite.js +5 -3
- package/dist/scene/msdftextsprite.js.map +1 -1
- package/dist/scene/particlesys.js +3 -1
- package/dist/scene/particlesys.js.map +1 -1
- package/dist/scene/scene.js +6 -5
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/terrain-cm/grass.js +4 -2
- package/dist/scene/terrain-cm/grass.js.map +1 -1
- package/dist/scene/terrain-cm/grassmaterial.js +2 -1
- package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
- package/dist/scene/terrain-cm/terrain-cm.js +4 -2
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
- package/dist/scene/water.js +4 -2
- package/dist/scene/water.js.map +1 -1
- package/dist/shaders/shadow.js +26 -393
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shadow/esm.js +112 -12
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/pcf_opt.js +2 -2
- package/dist/shadow/pcf_opt.js.map +1 -1
- package/dist/shadow/pcf_pd.js +19 -10
- package/dist/shadow/pcf_pd.js.map +1 -1
- package/dist/shadow/shader.js +58 -7
- package/dist/shadow/shader.js.map +1 -1
- package/dist/shadow/shadow_impl.js +6 -0
- package/dist/shadow/shadow_impl.js.map +1 -1
- package/dist/shadow/shadow_region.js +229 -0
- package/dist/shadow/shadow_region.js.map +1 -0
- package/dist/shadow/shadowmapper.js +67 -59
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/vsm.js +45 -19
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/utility/blueprint/common/constants.js +8 -8
- package/dist/utility/blueprint/common/constants.js.map +1 -1
- package/dist/utility/blueprint/material/pbr.js +31 -4
- package/dist/utility/blueprint/material/pbr.js.map +1 -1
- package/dist/utility/blueprint/material/texture.js +1 -17
- package/dist/utility/blueprint/material/texture.js.map +1 -1
- package/dist/utility/serialization/manager.js +327 -359
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +5 -2
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/batch.js +4 -1
- package/dist/utility/serialization/scene/batch.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +249 -54
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/common.js +37 -1
- package/dist/utility/serialization/scene/common.js.map +1 -1
- package/dist/utility/serialization/scene/light.js +42 -3
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/material.js +1112 -646
- package/dist/utility/serialization/scene/material.js.map +1 -1
- package/dist/utility/serialization/scene/mesh.js +7 -4
- package/dist/utility/serialization/scene/mesh.js.map +1 -1
- package/dist/utility/serialization/scene/node.js +31 -12
- package/dist/utility/serialization/scene/node.js.map +1 -1
- package/dist/utility/serialization/scene/particle.js +4 -1
- package/dist/utility/serialization/scene/particle.js.map +1 -1
- package/dist/utility/serialization/scene/primitive.js +3 -1
- package/dist/utility/serialization/scene/primitive.js.map +1 -1
- package/dist/utility/serialization/scene/scene.js +18 -0
- package/dist/utility/serialization/scene/scene.js.map +1 -1
- package/dist/utility/serialization/scene/sprite.js +6 -3
- package/dist/utility/serialization/scene/sprite.js.map +1 -1
- package/dist/utility/serialization/scene/terrain.js +5 -2
- package/dist/utility/serialization/scene/terrain.js.map +1 -1
- package/dist/utility/serialization/scene/text.js +3 -1
- package/dist/utility/serialization/scene/text.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +4 -1
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/utility/textures/ltcdata.js +6 -0
- package/dist/utility/textures/ltcdata.js.map +1 -0
- package/dist/utility/textures/ltclut.js +61 -0
- package/dist/utility/textures/ltclut.js.map +1 -0
- package/dist/values.js +9 -1
- package/dist/values.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Matrix4x4, Frustum, Vector3, AABB, Vector4, retainObject, CubeFace } from '@zephyr3d/base';
|
|
1
|
+
import { Matrix4x4, Frustum, Disposable, Vector3, AABB, Vector4, retainObject, CubeFace } from '@zephyr3d/base';
|
|
2
2
|
import { Camera } from '../camera/camera.js';
|
|
3
3
|
import { SSM } from './ssm.js';
|
|
4
4
|
import { ESM } from './esm.js';
|
|
@@ -8,6 +8,7 @@ import { PCFOPT } from './pcf_opt.js';
|
|
|
8
8
|
import { LIGHT_TYPE_NONE, LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_POINT } from '../values.js';
|
|
9
9
|
import { ShaderHelper } from '../material/shader/helper.js';
|
|
10
10
|
import { getDevice } from '../app/api.js';
|
|
11
|
+
import { ShadowRegion } from './shadow_region.js';
|
|
11
12
|
|
|
12
13
|
const tmpMatrix = new Matrix4x4();
|
|
13
14
|
const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
@@ -15,7 +16,7 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
15
16
|
/**
|
|
16
17
|
* The shadow map generator
|
|
17
18
|
* @public
|
|
18
|
-
*/ class ShadowMapper {
|
|
19
|
+
*/ class ShadowMapper extends Disposable {
|
|
19
20
|
/** @internal */ static _snapMatrix = new Matrix4x4();
|
|
20
21
|
/** @internal */ static _target = new Vector3();
|
|
21
22
|
/** @internal */ static _up = new Vector3();
|
|
@@ -37,63 +38,45 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
37
38
|
/** @internal */ _vsmBlurRadius;
|
|
38
39
|
/** @internal */ _vsmDarkness;
|
|
39
40
|
/** @internal */ _esmBlur;
|
|
41
|
+
/** @internal */ _esmLogSpace;
|
|
40
42
|
/** @internal */ _esmBlurKernelSize;
|
|
41
43
|
/** @internal */ _esmBlurRadius;
|
|
42
44
|
/** @internal */ _esmDepthScale;
|
|
45
|
+
/** @internal */ _shadowStrength;
|
|
43
46
|
/** @internal */ _shadowRegion;
|
|
44
|
-
/** @internal */ _autoShadowRegion;
|
|
45
47
|
/**
|
|
46
48
|
* Creates an instance of ShadowMapper
|
|
47
49
|
* @param light - The light that is used to generate shadow map
|
|
48
50
|
*/ constructor(light){
|
|
51
|
+
super();
|
|
49
52
|
this._light = light;
|
|
50
53
|
this._config = {
|
|
51
54
|
shadowMapSize: 1024,
|
|
52
55
|
numCascades: 1,
|
|
53
56
|
splitLambda: 0.5,
|
|
54
|
-
depthBias: 0.
|
|
57
|
+
depthBias: 0.003,
|
|
55
58
|
normalBias: 0.2,
|
|
56
59
|
nearClip: 1
|
|
57
60
|
};
|
|
58
61
|
this._resourceDirty = true;
|
|
59
|
-
this._shadowMode = '
|
|
62
|
+
this._shadowMode = 'pcf-pd';
|
|
60
63
|
this._shadowDistance = 2000;
|
|
61
64
|
this._impl = null;
|
|
62
|
-
this._pdSampleCount =
|
|
63
|
-
this._pdSampleRadius =
|
|
64
|
-
this._pcfKernelSize =
|
|
65
|
+
this._pdSampleCount = 24;
|
|
66
|
+
this._pdSampleRadius = 3;
|
|
67
|
+
this._pcfKernelSize = 7;
|
|
65
68
|
this._vsmBlurKernelSize = 5;
|
|
66
69
|
this._vsmBlurRadius = 4;
|
|
67
70
|
this._vsmDarkness = 0.3;
|
|
68
71
|
this._esmBlur = true;
|
|
72
|
+
this._esmLogSpace = true;
|
|
69
73
|
this._esmBlurKernelSize = 5;
|
|
70
74
|
this._esmBlurRadius = 4;
|
|
71
75
|
this._esmDepthScale = 200;
|
|
72
|
-
this.
|
|
73
|
-
this.
|
|
76
|
+
this._shadowStrength = 1;
|
|
77
|
+
this._shadowRegion = new ShadowRegion();
|
|
74
78
|
this.applyMode(this._shadowMode);
|
|
75
79
|
}
|
|
76
|
-
copyFrom(other) {
|
|
77
|
-
this.shadowMapSize = other.shadowMapSize;
|
|
78
|
-
this.shadowRegion = other.shadowRegion ? new AABB(other.shadowRegion) : null;
|
|
79
|
-
this.shadowDistance = other.shadowDistance;
|
|
80
|
-
this.numShadowCascades = other.numShadowCascades;
|
|
81
|
-
this.splitLambda = other.splitLambda;
|
|
82
|
-
this.depthBias = other.depthBias;
|
|
83
|
-
this.normalBias = other.normalBias;
|
|
84
|
-
this.nearClip = other.nearClip;
|
|
85
|
-
this.mode = other.mode;
|
|
86
|
-
this.pdSampleCount = other.pdSampleCount;
|
|
87
|
-
this.pdSampleRadius = other.pdSampleRadius;
|
|
88
|
-
this.pcfKernelSize = other.pcfKernelSize;
|
|
89
|
-
this.vsmBlurKernelSize = other.vsmBlurKernelSize;
|
|
90
|
-
this.vsmBlurRadius = other.vsmBlurRadius;
|
|
91
|
-
this.vsmDarkness = other.vsmDarkness;
|
|
92
|
-
this.esmBlur = other.esmBlur;
|
|
93
|
-
this.esmBlurKernelSize = other.esmBlurKernelSize;
|
|
94
|
-
this.esmBlurRadius = other.esmBlurRadius;
|
|
95
|
-
this.esmDepthScale = other.esmDepthScale;
|
|
96
|
-
}
|
|
97
80
|
/** The light that is used to generate shadow map */ get light() {
|
|
98
81
|
return this._light;
|
|
99
82
|
}
|
|
@@ -113,21 +96,25 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
113
96
|
/** Shadow region for directional light */ get shadowRegion() {
|
|
114
97
|
return this._shadowRegion;
|
|
115
98
|
}
|
|
116
|
-
set shadowRegion(region) {
|
|
117
|
-
this._shadowRegion = region;
|
|
118
|
-
this._autoShadowRegion = false;
|
|
119
|
-
}
|
|
120
99
|
/** @internal */ updateDirectionalShadowRegion(force = false) {
|
|
121
100
|
if (!this._light.isDirectionLight()) {
|
|
122
101
|
return;
|
|
123
102
|
}
|
|
124
|
-
if (!force
|
|
103
|
+
if (!force) {
|
|
125
104
|
return;
|
|
126
105
|
}
|
|
127
106
|
const scene = this._light.scene;
|
|
128
107
|
if (!scene) {
|
|
129
108
|
return;
|
|
130
109
|
}
|
|
110
|
+
this._shadowRegion.clear();
|
|
111
|
+
scene.rootNode.iterate((child)=>{
|
|
112
|
+
if ((child.isMesh() || child.isClipmapTerrain()) && child.castShadow) {
|
|
113
|
+
this._shadowRegion.addDynamicCaster(child);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/** @internal */ computeDirectionalShadowRegion(scene) {
|
|
131
118
|
const aabb = new AABB();
|
|
132
119
|
aabb.beginExtend();
|
|
133
120
|
scene.rootNode.iterate((child)=>{
|
|
@@ -139,8 +126,7 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
139
126
|
}
|
|
140
127
|
}
|
|
141
128
|
});
|
|
142
|
-
|
|
143
|
-
this._autoShadowRegion = true;
|
|
129
|
+
return aabb.isValid() ? aabb : null;
|
|
144
130
|
}
|
|
145
131
|
/** Maximum distance from the camera, shadow will not be rendered beyond this range */ get shadowDistance() {
|
|
146
132
|
return this._shadowDistance;
|
|
@@ -193,6 +179,12 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
193
179
|
this._config.nearClip = val;
|
|
194
180
|
}
|
|
195
181
|
}
|
|
182
|
+
/** Shadow strength, 0 means no shadowing and 1 means full shadowing */ get shadowStrength() {
|
|
183
|
+
return this._shadowStrength;
|
|
184
|
+
}
|
|
185
|
+
set shadowStrength(val) {
|
|
186
|
+
this._shadowStrength = Math.min(1, Math.max(0, Number(val) || 0));
|
|
187
|
+
}
|
|
196
188
|
/** Shadow map mode */ get mode() {
|
|
197
189
|
return this._shadowMode;
|
|
198
190
|
}
|
|
@@ -213,7 +205,7 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
213
205
|
this.shadowMapSize = 2048;
|
|
214
206
|
this.shadowDistance = 120;
|
|
215
207
|
this.splitLambda = 0.75;
|
|
216
|
-
this.depthBias = 0.
|
|
208
|
+
this.depthBias = 0.005;
|
|
217
209
|
this.normalBias = 0.3;
|
|
218
210
|
this.nearClip = 0.2;
|
|
219
211
|
this.pcfKernelSize = 5;
|
|
@@ -224,7 +216,7 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
224
216
|
this.shadowMapSize = 2048;
|
|
225
217
|
this.shadowDistance = 800;
|
|
226
218
|
this.splitLambda = 0.6;
|
|
227
|
-
this.depthBias = 0.
|
|
219
|
+
this.depthBias = 0.0035;
|
|
228
220
|
this.normalBias = 0.22;
|
|
229
221
|
this.nearClip = 1;
|
|
230
222
|
this.pcfKernelSize = 3;
|
|
@@ -317,6 +309,18 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
317
309
|
}
|
|
318
310
|
}
|
|
319
311
|
}
|
|
312
|
+
/** Whether to enable log space ESM blur */ get esmLogSpace() {
|
|
313
|
+
return this._esmLogSpace;
|
|
314
|
+
}
|
|
315
|
+
set esmLogSpace(val) {
|
|
316
|
+
if (!!val !== this.esmLogSpace) {
|
|
317
|
+
this._esmLogSpace = !!val;
|
|
318
|
+
const esm = this.asESM();
|
|
319
|
+
if (esm) {
|
|
320
|
+
esm.logSpace = this._esmLogSpace;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
320
324
|
/** Kernel size for ESM */ get esmBlurKernelSize() {
|
|
321
325
|
return this._esmBlurKernelSize;
|
|
322
326
|
}
|
|
@@ -480,17 +484,15 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
480
484
|
lightCamera.position.set(this._light.positionAndRange.xyz());
|
|
481
485
|
}
|
|
482
486
|
/** @internal */ createLightCameraSpot(lightCamera) {
|
|
483
|
-
lightCamera.
|
|
484
|
-
lightCamera.
|
|
485
|
-
lightCamera.rotation.identity();
|
|
487
|
+
this._light.worldMatrix.decompose(null, lightCamera.rotation, lightCamera.position);
|
|
488
|
+
lightCamera.parent = this._light.scene?.rootNode ?? null;
|
|
486
489
|
lightCamera.scale.setXYZ(1, 1, 1);
|
|
487
490
|
lightCamera.setPerspective(2 * Math.acos(this._light.cutoff), 1, this._config.nearClip, Math.min(this._shadowDistance, this._light.range));
|
|
488
491
|
}
|
|
489
492
|
/** @internal */ createLightCameraRect(lightCamera) {
|
|
490
493
|
const rect = this._light;
|
|
491
|
-
lightCamera.
|
|
492
|
-
lightCamera.
|
|
493
|
-
lightCamera.rotation.identity();
|
|
494
|
+
this._light.worldMatrix.decompose(null, lightCamera.rotation, lightCamera.position);
|
|
495
|
+
lightCamera.parent = this._light.scene?.rootNode ?? null;
|
|
494
496
|
lightCamera.scale.setXYZ(1, 1, 1);
|
|
495
497
|
const halfW = rect.width * 0.5;
|
|
496
498
|
const halfH = rect.height * 0.5;
|
|
@@ -506,8 +508,9 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
506
508
|
tmpFrustum.initWithMatrix(tmpMatrix);
|
|
507
509
|
frustum = tmpFrustum;
|
|
508
510
|
}
|
|
509
|
-
|
|
510
|
-
const
|
|
511
|
+
const borderSize = Number.isFinite(border ?? 0) ? Math.max(0, border ?? 0) : 0;
|
|
512
|
+
const clampedBorderSize = Math.min(borderSize, (this.shadowMapSize - 1) * 0.5);
|
|
513
|
+
const paddingScale = this.shadowMapSize / (this.shadowMapSize - 2 * clampedBorderSize);
|
|
511
514
|
//const frustum = sceneCamera.frustum;
|
|
512
515
|
const frustumMin = ShadowMapper._frustumMin;
|
|
513
516
|
const frustumMax = ShadowMapper._frustumMax;
|
|
@@ -521,10 +524,10 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
521
524
|
frustumMin.inplaceMin(p);
|
|
522
525
|
frustumMax.inplaceMax(p);
|
|
523
526
|
});
|
|
524
|
-
let radius = Vector3.distance(frustumMin, frustumMax) * 0.5 *
|
|
527
|
+
let radius = Vector3.distance(frustumMin, frustumMax) * 0.5 * paddingScale;
|
|
525
528
|
const center = sceneCamera.thisToWorld(Vector3.add(frustumMin, frustumMax, frustumCenter).scaleBy(0.5), frustumCenter);
|
|
526
|
-
//
|
|
527
|
-
const sceneRadius = sceneAABB.diagonalLength * 0.5 *
|
|
529
|
+
// Clamp to the scene bounds first, then apply the filter border.
|
|
530
|
+
const sceneRadius = sceneAABB.diagonalLength * 0.5 * paddingScale;
|
|
528
531
|
if (sceneRadius < radius) {
|
|
529
532
|
radius = sceneRadius;
|
|
530
533
|
Vector3.add(sceneAABB.minPoint, sceneAABB.maxPoint, center).scaleBy(0.5);
|
|
@@ -607,6 +610,9 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
607
610
|
cropMatrix.m13 = offsetY;
|
|
608
611
|
}
|
|
609
612
|
*/ }
|
|
613
|
+
/** {@inheritDoc Disposable.onDispose} */ onDispose() {
|
|
614
|
+
this._shadowRegion.dispose();
|
|
615
|
+
}
|
|
610
616
|
/** @internal */ static fetchShadowMapParams() {
|
|
611
617
|
if (this._shadowMapParams.length > 0) {
|
|
612
618
|
return this._shadowMapParams.pop();
|
|
@@ -701,16 +707,14 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
701
707
|
const device = getDevice();
|
|
702
708
|
const fb = shadowMapParams.shadowMapFramebuffer;
|
|
703
709
|
shadowMapParams.depthClampEnabled = false;
|
|
704
|
-
renderPass.clearColor =
|
|
710
|
+
renderPass.clearColor = this._impl.getShadowMapClearColor(shadowMapParams);
|
|
705
711
|
const depthScale = this._impl.getDepthScale();
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
}
|
|
709
|
-
const shadowRegion = this._light.isDirectionLight() && this._shadowRegion && this._shadowRegion.isValid() ? this._shadowRegion : scene.boundingBox;
|
|
712
|
+
const directionalShadowRegion = this._shadowRegion.region;
|
|
713
|
+
const shadowRegion = this._light.isDirectionLight() && directionalShadowRegion?.isValid() ? directionalShadowRegion : scene.boundingBox;
|
|
710
714
|
if (this._light.isPointLight()) {
|
|
711
715
|
const shadowMapRenderCamera = ShadowMapper.fetchCameraForScene(scene);
|
|
712
716
|
this.createLightCameraPoint(shadowMapRenderCamera);
|
|
713
|
-
this.calcDepthBiasParams(
|
|
717
|
+
this.calcDepthBiasParams(shadowMapRenderCamera, this._config.shadowMapSize, this._config.depthBias, this._config.normalBias, depthScale, shadowMapParams.depthBiasValues[0]);
|
|
714
718
|
shadowMapParams.cameraParams.setXYZW(shadowMapRenderCamera.getNearPlane(), shadowMapRenderCamera.getFarPlane(), this._config.shadowMapSize, this._shadowDistance);
|
|
715
719
|
device.setFramebuffer(fb);
|
|
716
720
|
shadowMapParams.shadowMatrices.set(Matrix4x4.transpose(shadowMapRenderCamera.viewMatrix));
|
|
@@ -744,7 +748,7 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
744
748
|
const border = shadowMapParams.impl.getShadowMapBorder(shadowMapParams); //20 / this._config.shadowMapSize;
|
|
745
749
|
this.createLightCameraDirectional(shadowRegion, cascadeCamera, shadowMapRenderCamera, snapMatrix, border);
|
|
746
750
|
this.createLightCameraDirectional(shadowRegion, cascadeCamera, shadowMapCullCamera, null, border);
|
|
747
|
-
this.calcDepthBiasParams(
|
|
751
|
+
this.calcDepthBiasParams(shadowMapRenderCamera, this._config.shadowMapSize, this._config.depthBias, this._config.normalBias, depthScale, shadowMapParams.depthBiasValues[split]);
|
|
748
752
|
shadowMapParams.depthBiasScales[split] = shadowMapParams.depthBiasValues[0].x !== 0 ? shadowMapParams.depthBiasValues[split].x / shadowMapParams.depthBiasValues[0].x : 1;
|
|
749
753
|
shadowMapParams.cameraParams.setXYZW(shadowMapRenderCamera.getNearPlane(), shadowMapRenderCamera.getFarPlane(), this._config.shadowMapSize, this._shadowDistance);
|
|
750
754
|
let scissor = null;
|
|
@@ -791,6 +795,7 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
791
795
|
} else {
|
|
792
796
|
const shadowMapRenderCamera = ShadowMapper.fetchCameraForScene(scene);
|
|
793
797
|
const snapMatrix = ShadowMapper._snapMatrix;
|
|
798
|
+
snapMatrix.identity();
|
|
794
799
|
shadowMapRenderCamera.clipMask = AABB.ClipLeft | AABB.ClipRight | AABB.ClipBottom | AABB.ClipTop;
|
|
795
800
|
if (this._light.isDirectionLight()) {
|
|
796
801
|
this.createLightCameraDirectional(shadowRegion, camera, shadowMapRenderCamera, snapMatrix, shadowMapParams.impl.getShadowMapBorder(shadowMapParams));
|
|
@@ -799,7 +804,7 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
799
804
|
} else {
|
|
800
805
|
this.createLightCameraSpot(shadowMapRenderCamera);
|
|
801
806
|
}
|
|
802
|
-
this.calcDepthBiasParams(
|
|
807
|
+
this.calcDepthBiasParams(shadowMapRenderCamera, this._config.shadowMapSize, this._config.depthBias, this._config.normalBias, depthScale, shadowMapParams.depthBiasValues[0]);
|
|
803
808
|
shadowMapParams.cameraParams.setXYZW(shadowMapRenderCamera.getNearPlane(), shadowMapRenderCamera.getFarPlane(), this._config.shadowMapSize, this._shadowDistance);
|
|
804
809
|
device.setFramebuffer(fb);
|
|
805
810
|
shadowMapRenderCamera.setProjectionMatrix(Matrix4x4.multiply(snapMatrix, shadowMapRenderCamera.getProjectionMatrix()));
|
|
@@ -822,6 +827,9 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
822
827
|
this._impl = new VSM(this._vsmBlurKernelSize, this._vsmBlurRadius, this._vsmDarkness);
|
|
823
828
|
} else if (mode === 'esm') {
|
|
824
829
|
this._impl = new ESM(this._esmBlurKernelSize, this._esmBlurRadius, this._esmDepthScale);
|
|
830
|
+
const esm = this._impl;
|
|
831
|
+
esm.blur = this._esmBlur;
|
|
832
|
+
esm.logSpace = this._esmLogSpace;
|
|
825
833
|
} else if (mode === 'pcf-pd') {
|
|
826
834
|
this._impl = new PCFPD(this._pdSampleCount, this._pdSampleRadius);
|
|
827
835
|
} else if (mode === 'pcf-opt') {
|