@zephyr3d/editor 0.3.8 → 0.3.9

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 (137) hide show
  1. package/dist/assets/{index-BZ1L8ggE.js → index-CO6yA4Rj.js} +313 -11
  2. package/dist/assistant/zephyr-types-index.json +13834 -11679
  3. package/dist/index.html +1 -1
  4. package/dist/modules/zephyr3d_backend-webgpu.js +1 -1
  5. package/dist/modules/zephyr3d_backend-webgpu.js.map +1 -1
  6. package/dist/modules/zephyr3d_device.js +2 -2
  7. package/dist/modules/zephyr3d_device.js.map +1 -1
  8. package/dist/modules/zephyr3d_scene.js +2325 -515
  9. package/dist/modules/zephyr3d_scene.js.map +1 -1
  10. package/dist/vendor/zephyr3d/backend-webgpu/dist/renderpass_webgpu.js +1 -1
  11. package/dist/vendor/zephyr3d/backend-webgpu/dist/renderpass_webgpu.js.map +1 -1
  12. package/dist/vendor/zephyr3d/device/dist/device.js +2 -2
  13. package/dist/vendor/zephyr3d/device/dist/device.js.map +1 -1
  14. package/dist/vendor/zephyr3d/scene/dist/app/engine.js +3 -1
  15. package/dist/vendor/zephyr3d/scene/dist/app/engine.js.map +1 -1
  16. package/dist/vendor/zephyr3d/scene/dist/asset/assetmanager.js +1 -0
  17. package/dist/vendor/zephyr3d/scene/dist/asset/assetmanager.js.map +1 -1
  18. package/dist/vendor/zephyr3d/scene/dist/camera/camera.js +87 -0
  19. package/dist/vendor/zephyr3d/scene/dist/camera/camera.js.map +1 -1
  20. package/dist/vendor/zephyr3d/scene/dist/index.d.ts +158 -4
  21. package/dist/vendor/zephyr3d/scene/dist/index.js +3 -0
  22. package/dist/vendor/zephyr3d/scene/dist/index.js.map +1 -1
  23. package/dist/vendor/zephyr3d/scene/dist/material/meshmaterial.js +8 -1
  24. package/dist/vendor/zephyr3d/scene/dist/material/meshmaterial.js.map +1 -1
  25. package/dist/vendor/zephyr3d/scene/dist/material/shader/helper.js +6 -0
  26. package/dist/vendor/zephyr3d/scene/dist/material/shader/helper.js.map +1 -1
  27. package/dist/vendor/zephyr3d/scene/dist/material/skin.js +263 -0
  28. package/dist/vendor/zephyr3d/scene/dist/material/skin.js.map +1 -0
  29. package/dist/vendor/zephyr3d/scene/dist/posteffect/compositor.js +3 -0
  30. package/dist/vendor/zephyr3d/scene/dist/posteffect/compositor.js.map +1 -1
  31. package/dist/vendor/zephyr3d/scene/dist/posteffect/skinsss.js +194 -0
  32. package/dist/vendor/zephyr3d/scene/dist/posteffect/skinsss.js.map +1 -0
  33. package/dist/vendor/zephyr3d/scene/dist/posteffect/ssr.js +26 -49
  34. package/dist/vendor/zephyr3d/scene/dist/posteffect/ssr.js.map +1 -1
  35. package/dist/vendor/zephyr3d/scene/dist/posteffect/sss.js +1 -0
  36. package/dist/vendor/zephyr3d/scene/dist/posteffect/sss.js.map +1 -1
  37. package/dist/vendor/zephyr3d/scene/dist/posteffect/taa.js +2 -40
  38. package/dist/vendor/zephyr3d/scene/dist/posteffect/taa.js.map +1 -1
  39. package/dist/vendor/zephyr3d/scene/dist/render/abuffer_oit.js +1 -0
  40. package/dist/vendor/zephyr3d/scene/dist/render/abuffer_oit.js.map +1 -1
  41. package/dist/vendor/zephyr3d/scene/dist/render/drawable_mixin.js +1 -0
  42. package/dist/vendor/zephyr3d/scene/dist/render/drawable_mixin.js.map +1 -1
  43. package/dist/vendor/zephyr3d/scene/dist/render/fbm_wavegenerator.js +1 -0
  44. package/dist/vendor/zephyr3d/scene/dist/render/fbm_wavegenerator.js.map +1 -1
  45. package/dist/vendor/zephyr3d/scene/dist/render/gerstner_wavegenerator.js +1 -0
  46. package/dist/vendor/zephyr3d/scene/dist/render/gerstner_wavegenerator.js.map +1 -1
  47. package/dist/vendor/zephyr3d/scene/dist/render/globalbindgroup_allocator.js +1 -0
  48. package/dist/vendor/zephyr3d/scene/dist/render/globalbindgroup_allocator.js.map +1 -1
  49. package/dist/vendor/zephyr3d/scene/dist/render/lightpass.js +4 -1
  50. package/dist/vendor/zephyr3d/scene/dist/render/lightpass.js.map +1 -1
  51. package/dist/vendor/zephyr3d/scene/dist/render/render_queue.js +1 -0
  52. package/dist/vendor/zephyr3d/scene/dist/render/render_queue.js.map +1 -1
  53. package/dist/vendor/zephyr3d/scene/dist/render/renderer.js +1 -0
  54. package/dist/vendor/zephyr3d/scene/dist/render/renderer.js.map +1 -1
  55. package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/device_pool_allocator.js +12 -5
  56. package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
  57. package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/forward_plus_builder.js +78 -8
  58. package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  59. package/dist/vendor/zephyr3d/scene/dist/scene/basesprite.js +1 -0
  60. package/dist/vendor/zephyr3d/scene/dist/scene/basesprite.js.map +1 -1
  61. package/dist/vendor/zephyr3d/scene/dist/scene/batchgroup.js +1 -0
  62. package/dist/vendor/zephyr3d/scene/dist/scene/batchgroup.js.map +1 -1
  63. package/dist/vendor/zephyr3d/scene/dist/scene/environment.js +1 -0
  64. package/dist/vendor/zephyr3d/scene/dist/scene/environment.js.map +1 -1
  65. package/dist/vendor/zephyr3d/scene/dist/scene/light.js +158 -154
  66. package/dist/vendor/zephyr3d/scene/dist/scene/light.js.map +1 -1
  67. package/dist/vendor/zephyr3d/scene/dist/scene/mesh.js +1 -0
  68. package/dist/vendor/zephyr3d/scene/dist/scene/mesh.js.map +1 -1
  69. package/dist/vendor/zephyr3d/scene/dist/scene/msdftext.js +1 -0
  70. package/dist/vendor/zephyr3d/scene/dist/scene/msdftext.js.map +1 -1
  71. package/dist/vendor/zephyr3d/scene/dist/scene/msdftextsprite.js +1 -0
  72. package/dist/vendor/zephyr3d/scene/dist/scene/msdftextsprite.js.map +1 -1
  73. package/dist/vendor/zephyr3d/scene/dist/scene/particlesys.js +1 -0
  74. package/dist/vendor/zephyr3d/scene/dist/scene/particlesys.js.map +1 -1
  75. package/dist/vendor/zephyr3d/scene/dist/scene/scene.js +1 -0
  76. package/dist/vendor/zephyr3d/scene/dist/scene/scene.js.map +1 -1
  77. package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/grass.js +1 -0
  78. package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/grass.js.map +1 -1
  79. package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/grassmaterial.js +1 -0
  80. package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
  81. package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/terrain-cm.js +1 -0
  82. package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  83. package/dist/vendor/zephyr3d/scene/dist/scene/water.js +1 -0
  84. package/dist/vendor/zephyr3d/scene/dist/scene/water.js.map +1 -1
  85. package/dist/vendor/zephyr3d/scene/dist/shaders/shadow.js +617 -1
  86. package/dist/vendor/zephyr3d/scene/dist/shaders/shadow.js.map +1 -1
  87. package/dist/vendor/zephyr3d/scene/dist/shadow/esm.js +1 -0
  88. package/dist/vendor/zephyr3d/scene/dist/shadow/esm.js.map +1 -1
  89. package/dist/vendor/zephyr3d/scene/dist/shadow/pcf_opt.js +1 -0
  90. package/dist/vendor/zephyr3d/scene/dist/shadow/pcf_opt.js.map +1 -1
  91. package/dist/vendor/zephyr3d/scene/dist/shadow/pcf_pd.js +1 -0
  92. package/dist/vendor/zephyr3d/scene/dist/shadow/pcf_pd.js.map +1 -1
  93. package/dist/vendor/zephyr3d/scene/dist/shadow/pcss.js +182 -0
  94. package/dist/vendor/zephyr3d/scene/dist/shadow/pcss.js.map +1 -0
  95. package/dist/vendor/zephyr3d/scene/dist/shadow/shader.js +1 -0
  96. package/dist/vendor/zephyr3d/scene/dist/shadow/shader.js.map +1 -1
  97. package/dist/vendor/zephyr3d/scene/dist/shadow/shadow_impl.js.map +1 -1
  98. package/dist/vendor/zephyr3d/scene/dist/shadow/shadowmapper.js +183 -105
  99. package/dist/vendor/zephyr3d/scene/dist/shadow/shadowmapper.js.map +1 -1
  100. package/dist/vendor/zephyr3d/scene/dist/shadow/ssm.js +1 -0
  101. package/dist/vendor/zephyr3d/scene/dist/shadow/ssm.js.map +1 -1
  102. package/dist/vendor/zephyr3d/scene/dist/shadow/vsm.js +1 -0
  103. package/dist/vendor/zephyr3d/scene/dist/shadow/vsm.js.map +1 -1
  104. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/manager.js +3 -1
  105. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/manager.js.map +1 -1
  106. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/animation.js +1 -0
  107. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/animation.js.map +1 -1
  108. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/batch.js +1 -0
  109. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/batch.js.map +1 -1
  110. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/camera.js +122 -0
  111. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/camera.js.map +1 -1
  112. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/common.js +1 -0
  113. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/common.js.map +1 -1
  114. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/light.js +102 -21
  115. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/light.js.map +1 -1
  116. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/material.js +195 -3
  117. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/material.js.map +1 -1
  118. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/mesh.js +1 -0
  119. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/mesh.js.map +1 -1
  120. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/node.js +1 -0
  121. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/node.js.map +1 -1
  122. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/particle.js +1 -0
  123. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/particle.js.map +1 -1
  124. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/primitive.js +1 -0
  125. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/primitive.js.map +1 -1
  126. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/sprite.js +1 -0
  127. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/sprite.js.map +1 -1
  128. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/terrain.js +1 -0
  129. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/terrain.js.map +1 -1
  130. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/text.js +1 -0
  131. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/text.js.map +1 -1
  132. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/water.js +1 -0
  133. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/water.js.map +1 -1
  134. package/dist/vendor/zephyr3d/scene/dist/values.js +1 -0
  135. package/dist/vendor/zephyr3d/scene/dist/values.js.map +1 -1
  136. package/electron/main.cjs +30 -6
  137. package/package.json +4 -4
@@ -3,8 +3,8 @@ import { Camera } from '../camera/camera.js';
3
3
  import { SSM } from './ssm.js';
4
4
  import { ESM } from './esm.js';
5
5
  import { VSM } from './vsm.js';
6
- import { PCFPD } from './pcf_pd.js';
7
6
  import { PCFOPT } from './pcf_opt.js';
7
+ import { PCSS } from './pcss.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';
@@ -13,9 +13,9 @@ import { ShadowRegion } from './shadow_region.js';
13
13
  const tmpMatrix = new Matrix4x4();
14
14
  const tmpFrustum = new Frustum(Matrix4x4.identity());
15
15
  // const zeroPosition = Vector3.zero();
16
- /**
17
- * The shadow map generator
18
- * @public
16
+ /**
17
+ * The shadow map generator
18
+ * @public
19
19
  */ class ShadowMapper extends Disposable {
20
20
  /** @internal */ static _snapMatrix = new Matrix4x4();
21
21
  /** @internal */ static _target = new Vector3();
@@ -34,6 +34,11 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
34
34
  /** @internal */ _pdSampleCount;
35
35
  /** @internal */ _pdSampleRadius;
36
36
  /** @internal */ _pcfKernelSize;
37
+ /** @internal */ _pcssLightRadius;
38
+ /** @internal */ _pcssBlockerSampleCount;
39
+ /** @internal */ _pcssFilterSampleCount;
40
+ /** @internal */ _pcssMaxFilterRadius;
41
+ /** @internal */ _pcssTemporalJitter;
37
42
  /** @internal */ _vsmBlurKernelSize;
38
43
  /** @internal */ _vsmBlurRadius;
39
44
  /** @internal */ _vsmDarkness;
@@ -44,9 +49,9 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
44
49
  /** @internal */ _esmDepthScale;
45
50
  /** @internal */ _shadowStrength;
46
51
  /** @internal */ _shadowRegion;
47
- /**
48
- * Creates an instance of ShadowMapper
49
- * @param light - The light that is used to generate shadow map
52
+ /**
53
+ * Creates an instance of ShadowMapper
54
+ * @param light - The light that is used to generate shadow map
50
55
  */ constructor(light){
51
56
  super();
52
57
  this._light = light;
@@ -59,12 +64,17 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
59
64
  nearClip: 1
60
65
  };
61
66
  this._resourceDirty = true;
62
- this._shadowMode = 'pcf-pd';
67
+ this._shadowMode = 'pcf';
63
68
  this._shadowDistance = 2000;
64
69
  this._impl = null;
65
70
  this._pdSampleCount = 24;
66
71
  this._pdSampleRadius = 3;
67
72
  this._pcfKernelSize = 7;
73
+ this._pcssLightRadius = 8;
74
+ this._pcssBlockerSampleCount = 24;
75
+ this._pcssFilterSampleCount = 32;
76
+ this._pcssMaxFilterRadius = 32;
77
+ this._pcssTemporalJitter = true;
68
78
  this._vsmBlurKernelSize = 5;
69
79
  this._vsmBlurRadius = 4;
70
80
  this._vsmDarkness = 0.3;
@@ -194,14 +204,14 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
194
204
  this.applyMode(this._shadowMode);
195
205
  }
196
206
  }
197
- /**
198
- * Applies a practical shadow preset for common scenarios.
199
- *
200
- * `character-small`: higher contact quality and tighter distance for character-centric scenes.
201
- * `outdoor-large`: longer distance coverage for open scenes.
207
+ /**
208
+ * Applies a practical shadow preset for common scenarios.
209
+ *
210
+ * `character-small`: higher contact quality and tighter distance for character-centric scenes.
211
+ * `outdoor-large`: longer distance coverage for open scenes.
202
212
  */ applyQualityPreset(preset) {
203
213
  if (preset === 'character-small') {
204
- this.mode = 'pcf-opt';
214
+ this.mode = 'pcf';
205
215
  this.shadowMapSize = 2048;
206
216
  this.shadowDistance = 120;
207
217
  this.splitLambda = 0.75;
@@ -212,7 +222,7 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
212
222
  this.numShadowCascades = this._light.isDirectionLight() ? 3 : 1;
213
223
  return;
214
224
  }
215
- this.mode = 'pcf-opt';
225
+ this.mode = 'pcf';
216
226
  this.shadowMapSize = 2048;
217
227
  this.shadowDistance = 800;
218
228
  this.splitLambda = 0.6;
@@ -261,6 +271,71 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
261
271
  }
262
272
  }
263
273
  }
274
+ /** Light radius for PCSS shadow, measured in shadow-map texels */ get pcssLightRadius() {
275
+ return this._pcssLightRadius;
276
+ }
277
+ set pcssLightRadius(val) {
278
+ val = Math.max(0, Number(val) || 0);
279
+ if (val !== this._pcssLightRadius) {
280
+ this._pcssLightRadius = val;
281
+ const pcss = this.asPCSS();
282
+ if (pcss) {
283
+ pcss.lightRadius = this._pcssLightRadius;
284
+ }
285
+ }
286
+ }
287
+ /** Blocker search sample count for PCSS shadow */ get pcssBlockerSampleCount() {
288
+ return this._pcssBlockerSampleCount;
289
+ }
290
+ set pcssBlockerSampleCount(val) {
291
+ val = Math.min(Math.max(1, Number(val) >> 0), 64);
292
+ if (val !== this._pcssBlockerSampleCount) {
293
+ this._pcssBlockerSampleCount = val;
294
+ const pcss = this.asPCSS();
295
+ if (pcss) {
296
+ pcss.blockerSampleCount = this._pcssBlockerSampleCount;
297
+ }
298
+ }
299
+ }
300
+ /** Filter sample count for PCSS shadow */ get pcssFilterSampleCount() {
301
+ return this._pcssFilterSampleCount;
302
+ }
303
+ set pcssFilterSampleCount(val) {
304
+ val = Math.min(Math.max(1, Number(val) >> 0), 64);
305
+ if (val !== this._pcssFilterSampleCount) {
306
+ this._pcssFilterSampleCount = val;
307
+ const pcss = this.asPCSS();
308
+ if (pcss) {
309
+ pcss.filterSampleCount = this._pcssFilterSampleCount;
310
+ }
311
+ }
312
+ }
313
+ /** Maximum PCSS filter radius, measured in shadow-map texels */ get pcssMaxFilterRadius() {
314
+ return this._pcssMaxFilterRadius;
315
+ }
316
+ set pcssMaxFilterRadius(val) {
317
+ val = Math.max(1, Number(val) || 1);
318
+ if (val !== this._pcssMaxFilterRadius) {
319
+ this._pcssMaxFilterRadius = val;
320
+ const pcss = this.asPCSS();
321
+ if (pcss) {
322
+ pcss.maxFilterRadius = this._pcssMaxFilterRadius;
323
+ }
324
+ }
325
+ }
326
+ /** If true, rotates PCSS sampling pattern over frames for TAA accumulation */ get pcssTemporalJitter() {
327
+ return this._pcssTemporalJitter;
328
+ }
329
+ set pcssTemporalJitter(val) {
330
+ val = !!val;
331
+ if (val !== this._pcssTemporalJitter) {
332
+ this._pcssTemporalJitter = val;
333
+ const pcss = this.asPCSS();
334
+ if (pcss) {
335
+ pcss.temporalJitter = this._pcssTemporalJitter;
336
+ }
337
+ }
338
+ }
264
339
  /** Kernel size of VSM */ get vsmBlurKernelSize() {
265
340
  return this._vsmBlurKernelSize;
266
341
  }
@@ -448,28 +523,28 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
448
523
  const useTextureArray = numCascades > 1 && device.type !== 'webgl';
449
524
  const shadowMapWidth = numCascades > 1 && !useTextureArray ? 2 * this._config.shadowMapSize : this._config.shadowMapSize;
450
525
  const shadowMapHeight = numCascades > 2 && !useTextureArray ? 2 * this._config.shadowMapSize : this._config.shadowMapSize;
451
- /*
452
- const colorAttachments = colorFormat
453
- ? useTextureArray
454
- ? [device.pool.fetchTemporalTexture2DArray(false, colorFormat, shadowMapWidth, shadowMapHeight, numCascades, false)]
455
- : this._light.isPointLight()
456
- ? [device.pool.fetchTemporalTextureCube(false, colorFormat, shadowMapWidth, false)]
457
- : [device.pool.fetchTemporalTexture2D(false, colorFormat, shadowMapWidth, shadowMapHeight, false)]
458
- : null;
459
- const depthAttachment = depthFormat
460
- ? useTextureArray
461
- ? device.pool.fetchTemporalTexture2DArray(false, depthFormat, shadowMapWidth, shadowMapHeight, numCascades, false)
462
- : device.type !== 'webgl' && this._light.isPointLight()
463
- ? device.pool.fetchTemporalTextureCube(false, depthFormat, shadowMapWidth, false)
464
- : device.pool.fetchTemporalTexture2D(false, depthFormat, shadowMapWidth, shadowMapHeight, false)
465
- : null;
466
- shadowMapParams.shadowMapFramebuffer = device.pool.createTemporalFramebuffer(false, colorAttachments, depthAttachment);
467
- if (colorAttachments) {
468
- device.pool.releaseTexture(colorAttachments[0]);
469
- }
470
- if (depthAttachment) {
471
- device.pool.releaseTexture(depthAttachment);
472
- }
526
+ /*
527
+ const colorAttachments = colorFormat
528
+ ? useTextureArray
529
+ ? [device.pool.fetchTemporalTexture2DArray(false, colorFormat, shadowMapWidth, shadowMapHeight, numCascades, false)]
530
+ : this._light.isPointLight()
531
+ ? [device.pool.fetchTemporalTextureCube(false, colorFormat, shadowMapWidth, false)]
532
+ : [device.pool.fetchTemporalTexture2D(false, colorFormat, shadowMapWidth, shadowMapHeight, false)]
533
+ : null;
534
+ const depthAttachment = depthFormat
535
+ ? useTextureArray
536
+ ? device.pool.fetchTemporalTexture2DArray(false, depthFormat, shadowMapWidth, shadowMapHeight, numCascades, false)
537
+ : device.type !== 'webgl' && this._light.isPointLight()
538
+ ? device.pool.fetchTemporalTextureCube(false, depthFormat, shadowMapWidth, false)
539
+ : device.pool.fetchTemporalTexture2D(false, depthFormat, shadowMapWidth, shadowMapHeight, false)
540
+ : null;
541
+ shadowMapParams.shadowMapFramebuffer = device.pool.createTemporalFramebuffer(false, colorAttachments, depthAttachment);
542
+ if (colorAttachments) {
543
+ device.pool.releaseTexture(colorAttachments[0]);
544
+ }
545
+ if (depthAttachment) {
546
+ device.pool.releaseTexture(depthAttachment);
547
+ }
473
548
  */ shadowMapParams.shadowMapFramebuffer = ShadowMapper.fetchTemporalFramebuffer(true, this._light.lightType, numCascades, shadowMapWidth, shadowMapHeight, colorFormat, depthFormat);
474
549
  shadowMapParams.impl = this._impl;
475
550
  this._impl.updateResources(shadowMapParams);
@@ -480,14 +555,14 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
480
555
  lightCamera.position.setXYZ(0, 0, 0);
481
556
  lightCamera.rotation.identity();
482
557
  lightCamera.scale.setXYZ(1, 1, 1);
483
- lightCamera.setPerspective(Math.PI / 2, 1, this._config.nearClip, Math.min(this._shadowDistance, this._light.range));
558
+ lightCamera.setPerspective(Math.PI / 2, 1, this._config.nearClip, Math.min(this._shadowDistance, this._light.positionAndRange.w));
484
559
  lightCamera.position.set(this._light.positionAndRange.xyz());
485
560
  }
486
561
  /** @internal */ createLightCameraSpot(lightCamera) {
487
562
  this._light.worldMatrix.decompose(null, lightCamera.rotation, lightCamera.position);
488
563
  lightCamera.parent = this._light.scene?.rootNode ?? null;
489
564
  lightCamera.scale.setXYZ(1, 1, 1);
490
- lightCamera.setPerspective(2 * Math.acos(this._light.cutoff), 1, this._config.nearClip, Math.min(this._shadowDistance, this._light.range));
565
+ lightCamera.setPerspective(2 * Math.acos(this._light.cutoff), 1, this._config.nearClip, Math.min(this._shadowDistance, this._light.positionAndRange.w));
491
566
  }
492
567
  /** @internal */ createLightCameraRect(lightCamera) {
493
568
  const rect = this._light;
@@ -547,68 +622,68 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
547
622
  center.setXYZ((rx - tx) * 2 / this.shadowMapSize, (ry - ty) * 2 / this.shadowMapSize, 0);
548
623
  cropMatrix.translation(center);
549
624
  }
550
- /*
551
- const minx = frustumMin.x;
552
- const maxx = frustumMax.x;
553
- const miny = frustumMin.y;
554
- const maxy = frustumMax.y;
555
- const minz = frustumMin.z;
556
- const maxz = frustumMax.z;
557
- const texelSizeW = (maxx - minx) / this.shadowMapSize;
558
- const texelSizeH = (maxy - miny) / this.shadowMapSize;
559
- const cx = Math.floor((minx + maxx) / 2 / texelSizeW) * texelSizeW;
560
- const cy = Math.floor((miny + maxy) / 2 / texelSizeH) * texelSizeH;
561
- const cz = (minz + maxz) / 2;
562
- const hx = Math.floor(((maxx - minx) * (expand + 0.5)) / texelSizeW) * texelSizeW;
563
- const hy = Math.floor(((maxy - miny) * (expand + 0.5)) / texelSizeH) * texelSizeH;
564
- lightCamera.position.setXYZ(cx, cy, cz);
565
- lightCamera.setOrtho(
566
- -hx,
567
- hx,
568
- -hy,
569
- hy,
570
- sceneMax.z - maxz,
571
- sceneMax.z - minz + 1
572
- );
573
- if (cropMatrix) {
574
- // compute crop matrix
575
- let clipMaxX = 0,
576
- clipMaxY = 0;
577
- let clipMinX = Number.MAX_VALUE,
578
- clipMinY = Number.MAX_VALUE;
579
- frustum.corners.forEach((p) => {
580
- const clipPos = lightCamera.viewProjectionMatrix.transformPoint(p);
581
- clipPos.x = Math.min(1, Math.max(-1, clipPos.x / clipPos.w));
582
- clipPos.y = Math.min(1, Math.max(-1, clipPos.y / clipPos.w));
583
- if (clipPos.x > clipMaxX) {
584
- clipMaxX = clipPos.x;
585
- }
586
- if (clipPos.x < clipMinX) {
587
- clipMinX = clipPos.x;
588
- }
589
- if (clipPos.y > clipMaxY) {
590
- clipMaxY = clipPos.y;
591
- }
592
- if (clipPos.y < clipMinY) {
593
- clipMinY = clipPos.y;
594
- }
595
- });
596
- const clipW = clipMaxX - clipMinX;
597
- const clipH = clipMaxY - clipMinY;
598
- clipMinX -= expand * clipW;
599
- clipMinY -= expand * clipH;
600
- clipMaxX += expand * clipW;
601
- clipMaxY += expand * clipH;
602
- const scaleX = 2 / (clipMaxX - clipMinX);
603
- const scaleY = 2 / (clipMaxY - clipMinY);
604
- const offsetX = -0.5 * (clipMaxX + clipMinX) * scaleX;
605
- const offsetY = -0.5 * (clipMaxY + clipMinY) * scaleY;
606
- cropMatrix.identity();
607
- cropMatrix.m00 = scaleX;
608
- cropMatrix.m11 = scaleY;
609
- cropMatrix.m03 = offsetX;
610
- cropMatrix.m13 = offsetY;
611
- }
625
+ /*
626
+ const minx = frustumMin.x;
627
+ const maxx = frustumMax.x;
628
+ const miny = frustumMin.y;
629
+ const maxy = frustumMax.y;
630
+ const minz = frustumMin.z;
631
+ const maxz = frustumMax.z;
632
+ const texelSizeW = (maxx - minx) / this.shadowMapSize;
633
+ const texelSizeH = (maxy - miny) / this.shadowMapSize;
634
+ const cx = Math.floor((minx + maxx) / 2 / texelSizeW) * texelSizeW;
635
+ const cy = Math.floor((miny + maxy) / 2 / texelSizeH) * texelSizeH;
636
+ const cz = (minz + maxz) / 2;
637
+ const hx = Math.floor(((maxx - minx) * (expand + 0.5)) / texelSizeW) * texelSizeW;
638
+ const hy = Math.floor(((maxy - miny) * (expand + 0.5)) / texelSizeH) * texelSizeH;
639
+ lightCamera.position.setXYZ(cx, cy, cz);
640
+ lightCamera.setOrtho(
641
+ -hx,
642
+ hx,
643
+ -hy,
644
+ hy,
645
+ sceneMax.z - maxz,
646
+ sceneMax.z - minz + 1
647
+ );
648
+ if (cropMatrix) {
649
+ // compute crop matrix
650
+ let clipMaxX = 0,
651
+ clipMaxY = 0;
652
+ let clipMinX = Number.MAX_VALUE,
653
+ clipMinY = Number.MAX_VALUE;
654
+ frustum.corners.forEach((p) => {
655
+ const clipPos = lightCamera.viewProjectionMatrix.transformPoint(p);
656
+ clipPos.x = Math.min(1, Math.max(-1, clipPos.x / clipPos.w));
657
+ clipPos.y = Math.min(1, Math.max(-1, clipPos.y / clipPos.w));
658
+ if (clipPos.x > clipMaxX) {
659
+ clipMaxX = clipPos.x;
660
+ }
661
+ if (clipPos.x < clipMinX) {
662
+ clipMinX = clipPos.x;
663
+ }
664
+ if (clipPos.y > clipMaxY) {
665
+ clipMaxY = clipPos.y;
666
+ }
667
+ if (clipPos.y < clipMinY) {
668
+ clipMinY = clipPos.y;
669
+ }
670
+ });
671
+ const clipW = clipMaxX - clipMinX;
672
+ const clipH = clipMaxY - clipMinY;
673
+ clipMinX -= expand * clipW;
674
+ clipMinY -= expand * clipH;
675
+ clipMaxX += expand * clipW;
676
+ clipMaxY += expand * clipH;
677
+ const scaleX = 2 / (clipMaxX - clipMinX);
678
+ const scaleY = 2 / (clipMaxY - clipMinY);
679
+ const offsetX = -0.5 * (clipMaxX + clipMinX) * scaleX;
680
+ const offsetY = -0.5 * (clipMaxY + clipMinY) * scaleY;
681
+ cropMatrix.identity();
682
+ cropMatrix.m00 = scaleX;
683
+ cropMatrix.m11 = scaleY;
684
+ cropMatrix.m03 = offsetX;
685
+ cropMatrix.m13 = offsetY;
686
+ }
612
687
  */ }
613
688
  /** {@inheritDoc Disposable.onDispose} */ onDispose() {
614
689
  this._shadowRegion.dispose();
@@ -816,7 +891,7 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
816
891
  this.postRenderShadowMap(shadowMapParams);
817
892
  }
818
893
  /** @internal */ applyMode(mode) {
819
- if (mode !== 'hard' && mode !== 'vsm' && mode !== 'esm' && mode !== 'pcf-pd' && mode !== 'pcf-opt') {
894
+ if (mode !== 'hard' && mode !== 'vsm' && mode !== 'esm' && mode !== 'pcf' && mode !== 'pcf-pd' && mode !== 'pcf-opt' && mode !== 'pcss') {
820
895
  console.error(`ShadowMapper.setShadowMode() failed: invalid mode: ${mode}`);
821
896
  return;
822
897
  }
@@ -830,10 +905,10 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
830
905
  const esm = this._impl;
831
906
  esm.blur = this._esmBlur;
832
907
  esm.logSpace = this._esmLogSpace;
833
- } else if (mode === 'pcf-pd') {
834
- this._impl = new PCFPD(this._pdSampleCount, this._pdSampleRadius);
835
- } else if (mode === 'pcf-opt') {
908
+ } else if (mode === 'pcf' || mode === 'pcf-opt' || mode === 'pcf-pd') {
836
909
  this._impl = new PCFOPT(this._pcfKernelSize);
910
+ } else if (mode === 'pcss') {
911
+ this._impl = new PCSS(this._pcssLightRadius, this._pcssBlockerSampleCount, this._pcssFilterSampleCount, this._pcssMaxFilterRadius, this._pcssTemporalJitter);
837
912
  }
838
913
  }
839
914
  /** @internal */ asVSM() {
@@ -848,6 +923,9 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
848
923
  /** @internal */ asPCFOPT() {
849
924
  return this._impl?.getType() === 'pcf-opt' ? this._impl : null;
850
925
  }
926
+ /** @internal */ asPCSS() {
927
+ return this._impl?.getType() === 'pcss' ? this._impl : null;
928
+ }
851
929
  }
852
930
 
853
931
  export { ShadowMapper };