@zephyr3d/scene 0.9.6 → 0.9.8

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.
Files changed (205) hide show
  1. package/dist/animation/animationset.js +52 -55
  2. package/dist/animation/animationset.js.map +1 -1
  3. package/dist/animation/joint_dynamics/controller.js +92 -32
  4. package/dist/animation/joint_dynamics/controller.js.map +1 -1
  5. package/dist/animation/joint_dynamics/convex_collider.js +320 -0
  6. package/dist/animation/joint_dynamics/convex_collider.js.map +1 -0
  7. package/dist/animation/joint_dynamics/joint_dynamics_system.js +57 -19
  8. package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
  9. package/dist/animation/joint_dynamics/solver.js +71 -27
  10. package/dist/animation/joint_dynamics/solver.js.map +1 -1
  11. package/dist/animation/joint_dynamics_modifier.js +4 -3
  12. package/dist/animation/joint_dynamics_modifier.js.map +1 -1
  13. package/dist/animation/skeleton.js +7 -10
  14. package/dist/animation/skeleton.js.map +1 -1
  15. package/dist/app/engine.js +3 -9
  16. package/dist/app/engine.js.map +1 -1
  17. package/dist/app/scriptregistry.js +47 -16
  18. package/dist/app/scriptregistry.js.map +1 -1
  19. package/dist/asset/assetmanager.js +3 -1
  20. package/dist/asset/assetmanager.js.map +1 -1
  21. package/dist/asset/model.js +346 -7
  22. package/dist/asset/model.js.map +1 -1
  23. package/dist/avatar/wardrobe.js +7 -3
  24. package/dist/avatar/wardrobe.js.map +1 -1
  25. package/dist/camera/camera.js +240 -34
  26. package/dist/camera/camera.js.map +1 -1
  27. package/dist/index.d.ts +1350 -622
  28. package/dist/index.js +6 -11
  29. package/dist/index.js.map +1 -1
  30. package/dist/material/blinn.js +1 -1
  31. package/dist/material/blinn.js.map +1 -1
  32. package/dist/material/lambert.js +1 -1
  33. package/dist/material/lambert.js.map +1 -1
  34. package/dist/material/material.js +23 -1
  35. package/dist/material/material.js.map +1 -1
  36. package/dist/material/meshmaterial.js +178 -23
  37. package/dist/material/meshmaterial.js.map +1 -1
  38. package/dist/material/mixins/albedocolor.js +4 -4
  39. package/dist/material/mixins/albedocolor.js.map +1 -1
  40. package/dist/material/mixins/lightmodel/blinnphong.js +2 -1
  41. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  42. package/dist/material/mixins/lightmodel/lambert.js +2 -1
  43. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  44. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +63 -16
  45. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
  46. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +100 -27
  47. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  48. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +16 -6
  49. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  50. package/dist/material/mixins/lit.js +1 -1
  51. package/dist/material/mixins/lit.js.map +1 -1
  52. package/dist/material/mixins/pbr/common.js +276 -65
  53. package/dist/material/mixins/pbr/common.js.map +1 -1
  54. package/dist/material/mixins/texture.js +3 -3
  55. package/dist/material/mixins/texture.js.map +1 -1
  56. package/dist/material/mixins/vertexcolor.js +2 -2
  57. package/dist/material/mixins/vertexcolor.js.map +1 -1
  58. package/dist/material/mtoon.js +574 -0
  59. package/dist/material/mtoon.js.map +1 -0
  60. package/dist/material/pbrblueprint.js +494 -331
  61. package/dist/material/pbrblueprint.js.map +1 -1
  62. package/dist/material/pbrmr.js +118 -100
  63. package/dist/material/pbrmr.js.map +1 -1
  64. package/dist/material/pbrsg.js +1 -1
  65. package/dist/material/pbrsg.js.map +1 -1
  66. package/dist/material/shader/helper.js +45 -15
  67. package/dist/material/shader/helper.js.map +1 -1
  68. package/dist/material/subsurfaceprofile.js +812 -0
  69. package/dist/material/subsurfaceprofile.js.map +1 -0
  70. package/dist/material/unlit.js +1 -1
  71. package/dist/material/unlit.js.map +1 -1
  72. package/dist/posteffect/compositor.js +46 -11
  73. package/dist/posteffect/compositor.js.map +1 -1
  74. package/dist/posteffect/ssr.js +413 -87
  75. package/dist/posteffect/ssr.js.map +1 -1
  76. package/dist/posteffect/sss.js +1053 -0
  77. package/dist/posteffect/sss.js.map +1 -0
  78. package/dist/posteffect/taa.js +61 -60
  79. package/dist/posteffect/taa.js.map +1 -1
  80. package/dist/render/abuffer_oit.js +63 -12
  81. package/dist/render/abuffer_oit.js.map +1 -1
  82. package/dist/render/cluster_light.js +6 -5
  83. package/dist/render/cluster_light.js.map +1 -1
  84. package/dist/render/drawable.js +1 -5
  85. package/dist/render/drawable.js.map +1 -1
  86. package/dist/render/drawable_mixin.js +2 -1
  87. package/dist/render/drawable_mixin.js.map +1 -1
  88. package/dist/render/fbm_wavegenerator.js +2 -1
  89. package/dist/render/fbm_wavegenerator.js.map +1 -1
  90. package/dist/render/gerstner_wavegenerator.js +2 -1
  91. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  92. package/dist/render/globalbindgroup_allocator.js +2 -1
  93. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  94. package/dist/render/lightpass.js +105 -18
  95. package/dist/render/lightpass.js.map +1 -1
  96. package/dist/render/render_queue.js +51 -8
  97. package/dist/render/render_queue.js.map +1 -1
  98. package/dist/render/renderer.js +73 -59
  99. package/dist/render/renderer.js.map +1 -1
  100. package/dist/render/rendergraph/device_pool_allocator.js +8 -0
  101. package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
  102. package/dist/render/rendergraph/forward_plus_builder.js +481 -95
  103. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  104. package/dist/render/rendergraph/history_resource_manager.js +55 -0
  105. package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
  106. package/dist/render/rendergraph/history_resources.js +3 -1
  107. package/dist/render/rendergraph/history_resources.js.map +1 -1
  108. package/dist/render/rendergraph/types.js.map +1 -1
  109. package/dist/render/renderpass.js +10 -4
  110. package/dist/render/renderpass.js.map +1 -1
  111. package/dist/render/sky.js +31 -1
  112. package/dist/render/sky.js.map +1 -1
  113. package/dist/render/weightedblended_oit.js +23 -5
  114. package/dist/render/weightedblended_oit.js.map +1 -1
  115. package/dist/scene/basesprite.js +4 -2
  116. package/dist/scene/basesprite.js.map +1 -1
  117. package/dist/scene/batchgroup.js +3 -1
  118. package/dist/scene/batchgroup.js.map +1 -1
  119. package/dist/scene/environment.js +11 -1
  120. package/dist/scene/environment.js.map +1 -1
  121. package/dist/scene/light.js +21 -3
  122. package/dist/scene/light.js.map +1 -1
  123. package/dist/scene/mesh.js +29 -14
  124. package/dist/scene/mesh.js.map +1 -1
  125. package/dist/scene/meshdrawable.js +6 -0
  126. package/dist/scene/meshdrawable.js.map +1 -1
  127. package/dist/scene/msdftext.js +5 -2
  128. package/dist/scene/msdftext.js.map +1 -1
  129. package/dist/scene/msdftextsprite.js +5 -3
  130. package/dist/scene/msdftextsprite.js.map +1 -1
  131. package/dist/scene/particlesys.js +3 -1
  132. package/dist/scene/particlesys.js.map +1 -1
  133. package/dist/scene/scene.js +6 -5
  134. package/dist/scene/scene.js.map +1 -1
  135. package/dist/scene/terrain-cm/grass.js +4 -2
  136. package/dist/scene/terrain-cm/grass.js.map +1 -1
  137. package/dist/scene/terrain-cm/grassmaterial.js +2 -1
  138. package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
  139. package/dist/scene/terrain-cm/terrain-cm.js +4 -2
  140. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  141. package/dist/scene/water.js +4 -2
  142. package/dist/scene/water.js.map +1 -1
  143. package/dist/shaders/shadow.js +26 -393
  144. package/dist/shaders/shadow.js.map +1 -1
  145. package/dist/shadow/esm.js +112 -12
  146. package/dist/shadow/esm.js.map +1 -1
  147. package/dist/shadow/pcf_opt.js +2 -2
  148. package/dist/shadow/pcf_opt.js.map +1 -1
  149. package/dist/shadow/pcf_pd.js +19 -10
  150. package/dist/shadow/pcf_pd.js.map +1 -1
  151. package/dist/shadow/shader.js +58 -7
  152. package/dist/shadow/shader.js.map +1 -1
  153. package/dist/shadow/shadow_impl.js +6 -0
  154. package/dist/shadow/shadow_impl.js.map +1 -1
  155. package/dist/shadow/shadow_region.js +229 -0
  156. package/dist/shadow/shadow_region.js.map +1 -0
  157. package/dist/shadow/shadowmapper.js +67 -59
  158. package/dist/shadow/shadowmapper.js.map +1 -1
  159. package/dist/shadow/vsm.js +45 -19
  160. package/dist/shadow/vsm.js.map +1 -1
  161. package/dist/utility/blueprint/common/constants.js +8 -8
  162. package/dist/utility/blueprint/common/constants.js.map +1 -1
  163. package/dist/utility/blueprint/material/pbr.js +31 -4
  164. package/dist/utility/blueprint/material/pbr.js.map +1 -1
  165. package/dist/utility/blueprint/material/texture.js +1 -17
  166. package/dist/utility/blueprint/material/texture.js.map +1 -1
  167. package/dist/utility/serialization/manager.js +66 -98
  168. package/dist/utility/serialization/manager.js.map +1 -1
  169. package/dist/utility/serialization/scene/animation.js +5 -2
  170. package/dist/utility/serialization/scene/animation.js.map +1 -1
  171. package/dist/utility/serialization/scene/batch.js +4 -1
  172. package/dist/utility/serialization/scene/batch.js.map +1 -1
  173. package/dist/utility/serialization/scene/camera.js +249 -54
  174. package/dist/utility/serialization/scene/camera.js.map +1 -1
  175. package/dist/utility/serialization/scene/common.js +37 -1
  176. package/dist/utility/serialization/scene/common.js.map +1 -1
  177. package/dist/utility/serialization/scene/light.js +42 -3
  178. package/dist/utility/serialization/scene/light.js.map +1 -1
  179. package/dist/utility/serialization/scene/material.js +1112 -646
  180. package/dist/utility/serialization/scene/material.js.map +1 -1
  181. package/dist/utility/serialization/scene/mesh.js +7 -4
  182. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  183. package/dist/utility/serialization/scene/node.js +31 -12
  184. package/dist/utility/serialization/scene/node.js.map +1 -1
  185. package/dist/utility/serialization/scene/particle.js +4 -1
  186. package/dist/utility/serialization/scene/particle.js.map +1 -1
  187. package/dist/utility/serialization/scene/primitive.js +3 -1
  188. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  189. package/dist/utility/serialization/scene/scene.js +18 -0
  190. package/dist/utility/serialization/scene/scene.js.map +1 -1
  191. package/dist/utility/serialization/scene/sprite.js +6 -3
  192. package/dist/utility/serialization/scene/sprite.js.map +1 -1
  193. package/dist/utility/serialization/scene/terrain.js +5 -2
  194. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  195. package/dist/utility/serialization/scene/text.js +3 -1
  196. package/dist/utility/serialization/scene/text.js.map +1 -1
  197. package/dist/utility/serialization/scene/water.js +4 -1
  198. package/dist/utility/serialization/scene/water.js.map +1 -1
  199. package/dist/utility/textures/ltcdata.js +6 -0
  200. package/dist/utility/textures/ltcdata.js.map +1 -0
  201. package/dist/utility/textures/ltclut.js +61 -0
  202. package/dist/utility/textures/ltclut.js.map +1 -0
  203. package/dist/values.js +9 -1
  204. package/dist/values.js.map +1 -1
  205. 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.5,
57
+ depthBias: 0.003,
55
58
  normalBias: 0.2,
56
59
  nearClip: 1
57
60
  };
58
61
  this._resourceDirty = true;
59
- this._shadowMode = 'hard';
62
+ this._shadowMode = 'pcf-pd';
60
63
  this._shadowDistance = 2000;
61
64
  this._impl = null;
62
- this._pdSampleCount = 12;
63
- this._pdSampleRadius = 4;
64
- this._pcfKernelSize = 5;
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._shadowRegion = null;
73
- this._autoShadowRegion = false;
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 && !this._autoShadowRegion) {
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
- this._shadowRegion = aabb.isValid() ? aabb : null;
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.18;
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.35;
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.parent = this._light;
484
- lightCamera.position.setXYZ(0, 0, 0);
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.parent = this._light;
492
- lightCamera.position.setXYZ(0, 0, 0);
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
- border = border || 0;
510
- const expand = (this.shadowMapSize - 2 * border) / this.shadowMapSize;
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 * expand;
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
- // Bounding sphere of the shadow camera should not be larger than bounding sphere of the scene.
527
- const sceneRadius = sceneAABB.diagonalLength * 0.5 * expand;
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 = fb.getColorAttachments()[0] ? fb.getColorAttachments()[0].isFloatFormat() ? new Vector4(1, 1, 1, 1) : new Vector4(0, 0, 0, 1) : null;
710
+ renderPass.clearColor = this._impl.getShadowMapClearColor(shadowMapParams);
705
711
  const depthScale = this._impl.getDepthScale();
706
- if (this._light.isDirectionLight() && this._autoShadowRegion) {
707
- this.updateDirectionalShadowRegion();
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(camera, this._config.shadowMapSize, this._config.depthBias, this._config.normalBias, depthScale, shadowMapParams.depthBiasValues[0]);
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(camera, this._config.shadowMapSize, this._config.depthBias, this._config.normalBias, depthScale, shadowMapParams.depthBiasValues[split]);
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(camera, this._config.shadowMapSize, this._config.depthBias, this._config.normalBias, depthScale, shadowMapParams.depthBiasValues[0]);
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') {