@babylonjs/core 7.39.1 → 7.39.2

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 (159) hide show
  1. package/Cameras/arcRotateCamera.d.ts +1 -1
  2. package/Cameras/arcRotateCamera.js.map +1 -1
  3. package/Debug/directionalLightFrustumViewer.d.ts +2 -1
  4. package/Debug/directionalLightFrustumViewer.js +4 -3
  5. package/Debug/directionalLightFrustumViewer.js.map +1 -1
  6. package/Engines/Extensions/engine.multiRender.js +1 -0
  7. package/Engines/Extensions/engine.multiRender.js.map +1 -1
  8. package/Engines/abstractEngine.js +2 -2
  9. package/Engines/abstractEngine.js.map +1 -1
  10. package/Engines/constants.d.ts +8 -0
  11. package/Engines/constants.js +8 -0
  12. package/Engines/constants.js.map +1 -1
  13. package/FrameGraph/Node/Blocks/PostProcesses/blackAndWhitePostProcessBlock.js +3 -9
  14. package/FrameGraph/Node/Blocks/PostProcesses/blackAndWhitePostProcessBlock.js.map +1 -1
  15. package/FrameGraph/Node/Blocks/PostProcesses/bloomPostProcessBlock.js +3 -9
  16. package/FrameGraph/Node/Blocks/PostProcesses/bloomPostProcessBlock.js.map +1 -1
  17. package/FrameGraph/Node/Blocks/PostProcesses/blurPostProcessBlock.js +3 -9
  18. package/FrameGraph/Node/Blocks/PostProcesses/blurPostProcessBlock.js.map +1 -1
  19. package/FrameGraph/Node/Blocks/PostProcesses/circleOfConfusionPostProcessBlock.js +5 -17
  20. package/FrameGraph/Node/Blocks/PostProcesses/circleOfConfusionPostProcessBlock.js.map +1 -1
  21. package/FrameGraph/Node/Blocks/PostProcesses/depthOfFieldPostProcessBlock.js +5 -17
  22. package/FrameGraph/Node/Blocks/PostProcesses/depthOfFieldPostProcessBlock.js.map +1 -1
  23. package/FrameGraph/Node/Blocks/PostProcesses/extractHighlightsPostProcessBlock.js +3 -9
  24. package/FrameGraph/Node/Blocks/PostProcesses/extractHighlightsPostProcessBlock.js.map +1 -1
  25. package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.d.ts +6 -1
  26. package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js +40 -20
  27. package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js.map +1 -1
  28. package/FrameGraph/Node/Blocks/Rendering/baseShadowGeneratorBlock.d.ts +77 -0
  29. package/FrameGraph/Node/Blocks/Rendering/baseShadowGeneratorBlock.js +250 -0
  30. package/FrameGraph/Node/Blocks/Rendering/baseShadowGeneratorBlock.js.map +1 -0
  31. package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.d.ts +57 -0
  32. package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.js +169 -0
  33. package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.js.map +1 -0
  34. package/FrameGraph/Node/Blocks/Rendering/cullObjectsBlock.js +3 -9
  35. package/FrameGraph/Node/Blocks/Rendering/cullObjectsBlock.js.map +1 -1
  36. package/FrameGraph/Node/Blocks/Rendering/geometryRendererBlock.js +4 -13
  37. package/FrameGraph/Node/Blocks/Rendering/geometryRendererBlock.js.map +1 -1
  38. package/FrameGraph/Node/Blocks/Rendering/objectRendererBlock.d.ts +6 -0
  39. package/FrameGraph/Node/Blocks/Rendering/objectRendererBlock.js +27 -0
  40. package/FrameGraph/Node/Blocks/Rendering/objectRendererBlock.js.map +1 -1
  41. package/FrameGraph/Node/Blocks/Rendering/shadowGeneratorBlock.d.ts +19 -0
  42. package/FrameGraph/Node/Blocks/Rendering/shadowGeneratorBlock.js +28 -0
  43. package/FrameGraph/Node/Blocks/Rendering/shadowGeneratorBlock.js.map +1 -0
  44. package/FrameGraph/Node/Blocks/Textures/clearBlock.js +3 -9
  45. package/FrameGraph/Node/Blocks/Textures/clearBlock.js.map +1 -1
  46. package/FrameGraph/Node/Blocks/Textures/copyTextureBlock.js +3 -9
  47. package/FrameGraph/Node/Blocks/Textures/copyTextureBlock.js.map +1 -1
  48. package/FrameGraph/Node/Blocks/Textures/generateMipmapsBlock.js +2 -5
  49. package/FrameGraph/Node/Blocks/Textures/generateMipmapsBlock.js.map +1 -1
  50. package/FrameGraph/Node/Blocks/executeBlock.d.ts +29 -0
  51. package/FrameGraph/Node/Blocks/executeBlock.js +43 -0
  52. package/FrameGraph/Node/Blocks/executeBlock.js.map +1 -0
  53. package/FrameGraph/Node/Blocks/index.d.ts +4 -0
  54. package/FrameGraph/Node/Blocks/index.js +4 -0
  55. package/FrameGraph/Node/Blocks/index.js.map +1 -1
  56. package/FrameGraph/Node/Blocks/inputBlock.d.ts +7 -2
  57. package/FrameGraph/Node/Blocks/inputBlock.js +13 -0
  58. package/FrameGraph/Node/Blocks/inputBlock.js.map +1 -1
  59. package/FrameGraph/Node/Blocks/resourceContainerBlock.d.ts +55 -0
  60. package/FrameGraph/Node/Blocks/resourceContainerBlock.js +97 -0
  61. package/FrameGraph/Node/Blocks/resourceContainerBlock.js.map +1 -0
  62. package/FrameGraph/Node/Types/nodeRenderGraphTypes.d.ts +13 -10
  63. package/FrameGraph/Node/Types/nodeRenderGraphTypes.js +11 -4
  64. package/FrameGraph/Node/Types/nodeRenderGraphTypes.js.map +1 -1
  65. package/FrameGraph/Node/nodeRenderGraph.js +32 -4
  66. package/FrameGraph/Node/nodeRenderGraph.js.map +1 -1
  67. package/FrameGraph/Node/nodeRenderGraphBlock.d.ts +1 -0
  68. package/FrameGraph/Node/nodeRenderGraphBlock.js +11 -0
  69. package/FrameGraph/Node/nodeRenderGraphBlock.js.map +1 -1
  70. package/FrameGraph/Node/nodeRenderGraphBlockConnectionPoint.d.ts +18 -0
  71. package/FrameGraph/Node/nodeRenderGraphBlockConnectionPoint.js +24 -0
  72. package/FrameGraph/Node/nodeRenderGraphBlockConnectionPoint.js.map +1 -1
  73. package/FrameGraph/Passes/cullPass.d.ts +1 -1
  74. package/FrameGraph/Passes/cullPass.js.map +1 -1
  75. package/FrameGraph/Tasks/Misc/executeTask.d.ts +22 -0
  76. package/FrameGraph/Tasks/Misc/executeTask.js +28 -0
  77. package/FrameGraph/Tasks/Misc/executeTask.js.map +1 -0
  78. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.d.ts +72 -0
  79. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.js +183 -0
  80. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.js.map +1 -0
  81. package/FrameGraph/Tasks/Rendering/objectRendererTask.d.ts +16 -5
  82. package/FrameGraph/Tasks/Rendering/objectRendererTask.js +46 -0
  83. package/FrameGraph/Tasks/Rendering/objectRendererTask.js.map +1 -1
  84. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.d.ts +107 -0
  85. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.js +264 -0
  86. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.js.map +1 -0
  87. package/FrameGraph/Tasks/Texture/clearTextureTask.js +7 -0
  88. package/FrameGraph/Tasks/Texture/clearTextureTask.js.map +1 -1
  89. package/FrameGraph/frameGraph.d.ts +9 -0
  90. package/FrameGraph/frameGraph.js +12 -3
  91. package/FrameGraph/frameGraph.js.map +1 -1
  92. package/FrameGraph/frameGraphTextureManager.js +4 -1
  93. package/FrameGraph/frameGraphTextureManager.js.map +1 -1
  94. package/FrameGraph/index.d.ts +5 -0
  95. package/FrameGraph/index.js +5 -0
  96. package/FrameGraph/index.js.map +1 -1
  97. package/Inputs/scene.inputManager.d.ts +1 -1
  98. package/Inputs/scene.inputManager.js +8 -1
  99. package/Inputs/scene.inputManager.js.map +1 -1
  100. package/Lights/Shadows/shadowGenerator.d.ts +1 -1
  101. package/Lights/Shadows/shadowGenerator.js +2 -7
  102. package/Lights/Shadows/shadowGenerator.js.map +1 -1
  103. package/Lights/directionalLight.d.ts +5 -4
  104. package/Lights/directionalLight.js +7 -9
  105. package/Lights/directionalLight.js.map +1 -1
  106. package/Lights/shadowLight.d.ts +4 -4
  107. package/Lights/shadowLight.js +3 -2
  108. package/Lights/shadowLight.js.map +1 -1
  109. package/Lights/spotLight.d.ts +2 -2
  110. package/Lights/spotLight.js +3 -2
  111. package/Lights/spotLight.js.map +1 -1
  112. package/Loading/sceneLoader.d.ts +1 -1
  113. package/Loading/sceneLoader.js.map +1 -1
  114. package/Materials/GreasedLine/greasedLinePluginMaterial.js +1 -1
  115. package/Materials/GreasedLine/greasedLinePluginMaterial.js.map +1 -1
  116. package/Materials/PBR/pbrMetallicRoughnessMaterial.js +18 -6
  117. package/Materials/PBR/pbrMetallicRoughnessMaterial.js.map +1 -1
  118. package/Materials/PBR/pbrSpecularGlossinessMaterial.js +18 -6
  119. package/Materials/PBR/pbrSpecularGlossinessMaterial.js.map +1 -1
  120. package/Materials/Textures/renderTargetTexture.d.ts +2 -0
  121. package/Materials/Textures/renderTargetTexture.js +18 -8
  122. package/Materials/Textures/renderTargetTexture.js.map +1 -1
  123. package/Materials/material.js +3 -1
  124. package/Materials/material.js.map +1 -1
  125. package/Materials/materialPluginBase.d.ts +4 -0
  126. package/Materials/materialPluginBase.js +4 -0
  127. package/Materials/materialPluginBase.js.map +1 -1
  128. package/Maths/math.color.js.map +1 -1
  129. package/Maths/math.vector.js.map +1 -1
  130. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +1 -1
  131. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
  132. package/Meshes/lattice.material.d.ts +3 -8
  133. package/Meshes/lattice.material.js.map +1 -1
  134. package/Misc/copyTextureToTexture.js +1 -1
  135. package/Misc/copyTextureToTexture.js.map +1 -1
  136. package/Misc/filesInput.d.ts +3 -1
  137. package/Misc/filesInput.js +8 -4
  138. package/Misc/filesInput.js.map +1 -1
  139. package/PostProcesses/postProcess.d.ts +2 -2
  140. package/PostProcesses/postProcess.js +4 -4
  141. package/PostProcesses/postProcess.js.map +1 -1
  142. package/PostProcesses/postProcessManager.js +1 -1
  143. package/PostProcesses/postProcessManager.js.map +1 -1
  144. package/Shaders/ShadersInclude/lightsFragmentFunctions.js +1 -1
  145. package/Shaders/ShadersInclude/lightsFragmentFunctions.js.map +1 -1
  146. package/Shaders/default.fragment.js +2 -1
  147. package/Shaders/default.fragment.js.map +1 -1
  148. package/Shaders/default.vertex.js +2 -1
  149. package/Shaders/default.vertex.js.map +1 -1
  150. package/Shaders/pbr.fragment.js +2 -1
  151. package/Shaders/pbr.fragment.js.map +1 -1
  152. package/Shaders/pbr.vertex.js +2 -1
  153. package/Shaders/pbr.vertex.js.map +1 -1
  154. package/XR/webXRCamera.js +3 -0
  155. package/XR/webXRCamera.js.map +1 -1
  156. package/package.json +1 -1
  157. package/scene.d.ts +7 -0
  158. package/scene.js +10 -1
  159. package/scene.js.map +1 -1
@@ -5,6 +5,7 @@ import type { AbstractMesh } from "../Meshes/abstractMesh";
5
5
  import { Light } from "./light";
6
6
  import { ShadowLight } from "./shadowLight";
7
7
  import type { Effect } from "../Materials/effect";
8
+ import type { Nullable } from "../types";
8
9
  /**
9
10
  * A directional light is defined by a direction (what a surprise!).
10
11
  * The light is emitted from everywhere in the specified direction, and has an infinite range.
@@ -125,20 +126,20 @@ export declare class DirectionalLight extends ShadowLight {
125
126
  * Values are fixed on directional lights as it relies on an ortho projection hence the need to convert being
126
127
  * -1 and 1 to 0 and 1 doing (depth + min) / (min + max) -> (depth + 1) / (1 + 1) -> (depth * 0.5) + 0.5.
127
128
  * (when not using reverse depth buffer / NDC half Z range)
128
- * @param activeCamera The camera we are returning the min for
129
+ * @param _activeCamera The camera we are returning the min for (not used)
129
130
  * @returns the depth min z
130
131
  */
131
- getDepthMinZ(activeCamera: Camera): number;
132
+ getDepthMinZ(_activeCamera: Nullable<Camera>): number;
132
133
  /**
133
134
  * Gets the maxZ used for shadow according to both the scene and the light.
134
135
  *
135
136
  * Values are fixed on directional lights as it relies on an ortho projection hence the need to convert being
136
137
  * -1 and 1 to 0 and 1 doing (depth + min) / (min + max) -> (depth + 1) / (1 + 1) -> (depth * 0.5) + 0.5.
137
138
  * (when not using reverse depth buffer / NDC half Z range)
138
- * @param activeCamera The camera we are returning the max for
139
+ * @param _activeCamera The camera we are returning the max for
139
140
  * @returns the depth max z
140
141
  */
141
- getDepthMaxZ(activeCamera: Camera): number;
142
+ getDepthMaxZ(_activeCamera: Nullable<Camera>): number;
142
143
  /**
143
144
  * Prepares the list of defines specific to the light type.
144
145
  * @param defines the list of defines
@@ -5,6 +5,7 @@ import { Node } from "../node.js";
5
5
  import { Light } from "./light.js";
6
6
  import { ShadowLight } from "./shadowLight.js";
7
7
  import { RegisterClass } from "../Misc/typeStore.js";
8
+
8
9
  Node.AddNodeConstructor("Light_Type_1", (name, scene) => {
9
10
  return () => new DirectionalLight(name, Vector3.Zero(), scene);
10
11
  });
@@ -162,9 +163,6 @@ export class DirectionalLight extends ShadowLight {
162
163
  */
163
164
  _setDefaultAutoExtendShadowProjectionMatrix(matrix, viewMatrix, renderList) {
164
165
  const activeCamera = this.getScene().activeCamera;
165
- if (!activeCamera) {
166
- return;
167
- }
168
166
  // Check extends
169
167
  if (this.autoUpdateExtends || this._orthoLeft === Number.MAX_VALUE) {
170
168
  const tempVector3 = Vector3.Zero();
@@ -212,8 +210,8 @@ export class DirectionalLight extends ShadowLight {
212
210
  }
213
211
  const xOffset = this._orthoRight - this._orthoLeft;
214
212
  const yOffset = this._orthoTop - this._orthoBottom;
215
- const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;
216
- const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;
213
+ const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera?.minZ || 0;
214
+ const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera?.maxZ || 10000;
217
215
  const useReverseDepthBuffer = this.getScene().getEngine().useReverseDepthBuffer;
218
216
  Matrix.OrthoOffCenterLHToRef(this._orthoLeft - xOffset * this.shadowOrthoScale, this._orthoRight + xOffset * this.shadowOrthoScale, this._orthoBottom - yOffset * this.shadowOrthoScale, this._orthoTop + yOffset * this.shadowOrthoScale, useReverseDepthBuffer ? maxZ : minZ, useReverseDepthBuffer ? minZ : maxZ, matrix, this.getScene().getEngine().isNDCHalfZRange);
219
217
  }
@@ -253,11 +251,11 @@ export class DirectionalLight extends ShadowLight {
253
251
  * Values are fixed on directional lights as it relies on an ortho projection hence the need to convert being
254
252
  * -1 and 1 to 0 and 1 doing (depth + min) / (min + max) -> (depth + 1) / (1 + 1) -> (depth * 0.5) + 0.5.
255
253
  * (when not using reverse depth buffer / NDC half Z range)
256
- * @param activeCamera The camera we are returning the min for
254
+ * @param _activeCamera The camera we are returning the min for (not used)
257
255
  * @returns the depth min z
258
256
  */
259
257
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
260
- getDepthMinZ(activeCamera) {
258
+ getDepthMinZ(_activeCamera) {
261
259
  const engine = this._scene.getEngine();
262
260
  return !engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : 1;
263
261
  }
@@ -267,11 +265,11 @@ export class DirectionalLight extends ShadowLight {
267
265
  * Values are fixed on directional lights as it relies on an ortho projection hence the need to convert being
268
266
  * -1 and 1 to 0 and 1 doing (depth + min) / (min + max) -> (depth + 1) / (1 + 1) -> (depth * 0.5) + 0.5.
269
267
  * (when not using reverse depth buffer / NDC half Z range)
270
- * @param activeCamera The camera we are returning the max for
268
+ * @param _activeCamera The camera we are returning the max for
271
269
  * @returns the depth max z
272
270
  */
273
271
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
274
- getDepthMaxZ(activeCamera) {
272
+ getDepthMaxZ(_activeCamera) {
275
273
  const engine = this._scene.getEngine();
276
274
  return engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : 1;
277
275
  }
@@ -1 +1 @@
1
- {"version":3,"file":"directionalLight.js","sourceRoot":"","sources":["../../../../dev/core/src/Lights/directionalLight.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM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;AAgBM;IADN,SAAS,EAAE;2DACoB;AAOzB;IADN,SAAS,EAAE;+DACyB;AAI7B;IADP,SAAS,CAAC,WAAW,CAAC;oDACe;AAE9B;IADP,SAAS,CAAC,YAAY,CAAC;qDACe;AAE/B;IADP,SAAS,CAAC,UAAU,CAAC;mDACe;AAE7B;IADP,SAAS,CAAC,aAAa,CAAC;sDACe;AAqR5C,sBAAsB;AACtB,aAAa,CAAC,0BAA0B,EAAE,gBAAgB,CAAC,CAAC","sourcesContent":["import { serialize } from \"../Misc/decorators\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Matrix, Vector3 } from \"../Maths/math.vector\";\r\nimport { Node } from \"../node\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Light } from \"./light\";\r\nimport { ShadowLight } from \"./shadowLight\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\n\r\nNode.AddNodeConstructor(\"Light_Type_1\", (name, scene) => {\r\n return () => new DirectionalLight(name, Vector3.Zero(), scene);\r\n});\r\n\r\n/**\r\n * A directional light is defined by a direction (what a surprise!).\r\n * The light is emitted from everywhere in the specified direction, and has an infinite range.\r\n * An example of a directional light is when a distance planet is lit by the apparently parallel lines of light from its sun. Light in a downward direction will light the top of an object.\r\n * Documentation: https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\r\n */\r\nexport class DirectionalLight extends ShadowLight {\r\n private _shadowFrustumSize = 0;\r\n /**\r\n * Fix frustum size for the shadow generation. This is disabled if the value is 0.\r\n */\r\n @serialize()\r\n public get shadowFrustumSize(): number {\r\n return this._shadowFrustumSize;\r\n }\r\n /**\r\n * Specifies a fix frustum size for the shadow generation.\r\n */\r\n public set shadowFrustumSize(value: number) {\r\n this._shadowFrustumSize = value;\r\n this.forceProjectionMatrixCompute();\r\n }\r\n\r\n private _shadowOrthoScale = 0.1;\r\n /**\r\n * Gets the shadow projection scale against the optimal computed one.\r\n * 0.1 by default which means that the projection window is increase by 10% from the optimal size.\r\n * This does not impact in fixed frustum size (shadowFrustumSize being set)\r\n */\r\n @serialize()\r\n public get shadowOrthoScale(): number {\r\n return this._shadowOrthoScale;\r\n }\r\n /**\r\n * Sets the shadow projection scale against the optimal computed one.\r\n * 0.1 by default which means that the projection window is increase by 10% from the optimal size.\r\n * This does not impact in fixed frustum size (shadowFrustumSize being set)\r\n */\r\n public set shadowOrthoScale(value: number) {\r\n this._shadowOrthoScale = value;\r\n this.forceProjectionMatrixCompute();\r\n }\r\n\r\n /**\r\n * Automatically compute the projection matrix to best fit (including all the casters)\r\n * on each frame.\r\n */\r\n @serialize()\r\n public autoUpdateExtends = true;\r\n\r\n /**\r\n * Automatically compute the shadowMinZ and shadowMaxZ for the projection matrix to best fit (including all the casters)\r\n * on each frame. autoUpdateExtends must be set to true for this to work\r\n */\r\n @serialize()\r\n public autoCalcShadowZBounds = false;\r\n\r\n // Cache\r\n @serialize(\"orthoLeft\")\r\n private _orthoLeft = Number.MAX_VALUE;\r\n @serialize(\"orthoRight\")\r\n private _orthoRight = Number.MIN_VALUE;\r\n @serialize(\"orthoTop\")\r\n private _orthoTop = Number.MIN_VALUE;\r\n @serialize(\"orthoBottom\")\r\n private _orthoBottom = Number.MAX_VALUE;\r\n\r\n /**\r\n * Gets or sets the orthoLeft property used to build the light frustum\r\n */\r\n public get orthoLeft(): number {\r\n return this._orthoLeft;\r\n }\r\n\r\n public set orthoLeft(left: number) {\r\n this._orthoLeft = left;\r\n }\r\n\r\n /**\r\n * Gets or sets the orthoRight property used to build the light frustum\r\n */\r\n public get orthoRight(): number {\r\n return this._orthoRight;\r\n }\r\n\r\n public set orthoRight(right: number) {\r\n this._orthoRight = right;\r\n }\r\n\r\n /**\r\n * Gets or sets the orthoTop property used to build the light frustum\r\n */\r\n public get orthoTop(): number {\r\n return this._orthoTop;\r\n }\r\n\r\n public set orthoTop(top: number) {\r\n this._orthoTop = top;\r\n }\r\n\r\n /**\r\n * Gets or sets the orthoBottom property used to build the light frustum\r\n */\r\n public get orthoBottom(): number {\r\n return this._orthoBottom;\r\n }\r\n\r\n public set orthoBottom(bottom: number) {\r\n this._orthoBottom = bottom;\r\n }\r\n\r\n /**\r\n * Creates a DirectionalLight object in the scene, oriented towards the passed direction (Vector3).\r\n * The directional light is emitted from everywhere in the given direction.\r\n * It can cast shadows.\r\n * Documentation : https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\r\n * @param name The friendly name of the light\r\n * @param direction The direction of the light\r\n * @param scene The scene the light belongs to\r\n */\r\n constructor(name: string, direction: Vector3, scene?: Scene) {\r\n super(name, scene);\r\n this.position = direction.scale(-1.0);\r\n this.direction = direction;\r\n }\r\n\r\n /**\r\n * Returns the string \"DirectionalLight\".\r\n * @returns The class name\r\n */\r\n public override getClassName(): string {\r\n return \"DirectionalLight\";\r\n }\r\n\r\n /**\r\n * Returns the integer 1.\r\n * @returns The light Type id as a constant defines in Light.LIGHTTYPEID_x\r\n */\r\n public override getTypeID(): number {\r\n return Light.LIGHTTYPEID_DIRECTIONALLIGHT;\r\n }\r\n\r\n /**\r\n * Sets the passed matrix \"matrix\" as projection matrix for the shadows cast by the light according to the passed view matrix.\r\n * Returns the DirectionalLight Shadow projection matrix.\r\n * @param matrix\r\n * @param viewMatrix\r\n * @param renderList\r\n */\r\n protected _setDefaultShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array<AbstractMesh>): void {\r\n if (this.shadowFrustumSize > 0) {\r\n this._setDefaultFixedFrustumShadowProjectionMatrix(matrix);\r\n } else {\r\n this._setDefaultAutoExtendShadowProjectionMatrix(matrix, viewMatrix, renderList);\r\n }\r\n }\r\n\r\n /**\r\n * Sets the passed matrix \"matrix\" as fixed frustum projection matrix for the shadows cast by the light according to the passed view matrix.\r\n * Returns the DirectionalLight Shadow projection matrix.\r\n * @param matrix\r\n */\r\n protected _setDefaultFixedFrustumShadowProjectionMatrix(matrix: Matrix): void {\r\n const activeCamera = this.getScene().activeCamera;\r\n\r\n if (!activeCamera) {\r\n return;\r\n }\r\n\r\n Matrix.OrthoLHToRef(\r\n this.shadowFrustumSize,\r\n this.shadowFrustumSize,\r\n this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ,\r\n this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ,\r\n matrix,\r\n this.getScene().getEngine().isNDCHalfZRange\r\n );\r\n }\r\n\r\n /**\r\n * Sets the passed matrix \"matrix\" as auto extend projection matrix for the shadows cast by the light according to the passed view matrix.\r\n * Returns the DirectionalLight Shadow projection matrix.\r\n * @param matrix\r\n * @param viewMatrix\r\n * @param renderList\r\n */\r\n protected _setDefaultAutoExtendShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array<AbstractMesh>): void {\r\n const activeCamera = this.getScene().activeCamera;\r\n\r\n if (!activeCamera) {\r\n return;\r\n }\r\n\r\n // Check extends\r\n if (this.autoUpdateExtends || this._orthoLeft === Number.MAX_VALUE) {\r\n const tempVector3 = Vector3.Zero();\r\n\r\n this._orthoLeft = Number.MAX_VALUE;\r\n this._orthoRight = -Number.MAX_VALUE;\r\n this._orthoTop = -Number.MAX_VALUE;\r\n this._orthoBottom = Number.MAX_VALUE;\r\n\r\n let shadowMinZ = Number.MAX_VALUE;\r\n let shadowMaxZ = -Number.MAX_VALUE;\r\n\r\n for (let meshIndex = 0; meshIndex < renderList.length; meshIndex++) {\r\n const mesh = renderList[meshIndex];\r\n\r\n if (!mesh) {\r\n continue;\r\n }\r\n\r\n const boundingInfo = mesh.getBoundingInfo();\r\n const boundingBox = boundingInfo.boundingBox;\r\n\r\n for (let index = 0; index < boundingBox.vectorsWorld.length; index++) {\r\n Vector3.TransformCoordinatesToRef(boundingBox.vectorsWorld[index], viewMatrix, tempVector3);\r\n\r\n if (tempVector3.x < this._orthoLeft) {\r\n this._orthoLeft = tempVector3.x;\r\n }\r\n if (tempVector3.y < this._orthoBottom) {\r\n this._orthoBottom = tempVector3.y;\r\n }\r\n\r\n if (tempVector3.x > this._orthoRight) {\r\n this._orthoRight = tempVector3.x;\r\n }\r\n if (tempVector3.y > this._orthoTop) {\r\n this._orthoTop = tempVector3.y;\r\n }\r\n if (this.autoCalcShadowZBounds) {\r\n if (tempVector3.z < shadowMinZ) {\r\n shadowMinZ = tempVector3.z;\r\n }\r\n if (tempVector3.z > shadowMaxZ) {\r\n shadowMaxZ = tempVector3.z;\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (this.autoCalcShadowZBounds) {\r\n this._shadowMinZ = shadowMinZ;\r\n this._shadowMaxZ = shadowMaxZ;\r\n }\r\n }\r\n\r\n const xOffset = this._orthoRight - this._orthoLeft;\r\n const yOffset = this._orthoTop - this._orthoBottom;\r\n\r\n const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;\r\n const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;\r\n\r\n const useReverseDepthBuffer = this.getScene().getEngine().useReverseDepthBuffer;\r\n\r\n Matrix.OrthoOffCenterLHToRef(\r\n this._orthoLeft - xOffset * this.shadowOrthoScale,\r\n this._orthoRight + xOffset * this.shadowOrthoScale,\r\n this._orthoBottom - yOffset * this.shadowOrthoScale,\r\n this._orthoTop + yOffset * this.shadowOrthoScale,\r\n useReverseDepthBuffer ? maxZ : minZ,\r\n useReverseDepthBuffer ? minZ : maxZ,\r\n matrix,\r\n this.getScene().getEngine().isNDCHalfZRange\r\n );\r\n }\r\n\r\n protected _buildUniformLayout(): void {\r\n this._uniformBuffer.addUniform(\"vLightData\", 4);\r\n this._uniformBuffer.addUniform(\"vLightDiffuse\", 4);\r\n this._uniformBuffer.addUniform(\"vLightSpecular\", 4);\r\n this._uniformBuffer.addUniform(\"shadowsInfo\", 3);\r\n this._uniformBuffer.addUniform(\"depthValues\", 2);\r\n this._uniformBuffer.create();\r\n }\r\n\r\n /**\r\n * Sets the passed Effect object with the DirectionalLight transformed position (or position if not parented) and the passed name.\r\n * @param effect The effect to update\r\n * @param lightIndex The index of the light in the effect to update\r\n * @returns The directional light\r\n */\r\n public transferToEffect(effect: Effect, lightIndex: string): DirectionalLight {\r\n if (this.computeTransformedInformation()) {\r\n this._uniformBuffer.updateFloat4(\"vLightData\", this.transformedDirection.x, this.transformedDirection.y, this.transformedDirection.z, 1, lightIndex);\r\n return this;\r\n }\r\n this._uniformBuffer.updateFloat4(\"vLightData\", this.direction.x, this.direction.y, this.direction.z, 1, lightIndex);\r\n return this;\r\n }\r\n\r\n public transferToNodeMaterialEffect(effect: Effect, lightDataUniformName: string): Light {\r\n if (this.computeTransformedInformation()) {\r\n effect.setFloat3(lightDataUniformName, this.transformedDirection.x, this.transformedDirection.y, this.transformedDirection.z);\r\n return this;\r\n }\r\n\r\n effect.setFloat3(lightDataUniformName, this.direction.x, this.direction.y, this.direction.z);\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets the minZ used for shadow according to both the scene and the light.\r\n *\r\n * Values are fixed on directional lights as it relies on an ortho projection hence the need to convert being\r\n * -1 and 1 to 0 and 1 doing (depth + min) / (min + max) -> (depth + 1) / (1 + 1) -> (depth * 0.5) + 0.5.\r\n * (when not using reverse depth buffer / NDC half Z range)\r\n * @param activeCamera The camera we are returning the min for\r\n * @returns the depth min z\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public override getDepthMinZ(activeCamera: Camera): number {\r\n const engine = this._scene.getEngine();\r\n return !engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : 1;\r\n }\r\n\r\n /**\r\n * Gets the maxZ used for shadow according to both the scene and the light.\r\n *\r\n * Values are fixed on directional lights as it relies on an ortho projection hence the need to convert being\r\n * -1 and 1 to 0 and 1 doing (depth + min) / (min + max) -> (depth + 1) / (1 + 1) -> (depth * 0.5) + 0.5.\r\n * (when not using reverse depth buffer / NDC half Z range)\r\n * @param activeCamera The camera we are returning the max for\r\n * @returns the depth max z\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public override getDepthMaxZ(activeCamera: Camera): number {\r\n const engine = this._scene.getEngine();\r\n return engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : 1;\r\n }\r\n\r\n /**\r\n * Prepares the list of defines specific to the light type.\r\n * @param defines the list of defines\r\n * @param lightIndex defines the index of the light for the effect\r\n */\r\n public prepareLightSpecificDefines(defines: any, lightIndex: number): void {\r\n defines[\"DIRLIGHT\" + lightIndex] = true;\r\n }\r\n}\r\n\r\n// Register Class Name\r\nRegisterClass(\"BABYLON.DirectionalLight\", DirectionalLight);\r\n"]}
1
+ {"version":3,"file":"directionalLight.js","sourceRoot":"","sources":["../../../../dev/core/src/Lights/directionalLight.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,gCAA+B;AAEnD,IAAI,CAAC,kBAAkB,CAAC,cAAc,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;IACpD,OAAO,GAAG,EAAE,CAAC,IAAI,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC;AACnE,CAAC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,OAAO,gBAAiB,SAAQ,WAAW;IAE7C;;OAEG;IAEH,IAAW,iBAAiB;QACxB,OAAO,IAAI,CAAC,kBAAkB,CAAC;IACnC,CAAC;IACD;;OAEG;IACH,IAAW,iBAAiB,CAAC,KAAa;QACtC,IAAI,CAAC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SAAS,EAAE,CAAC;QACvC,OAAO,CAAC,MAAM,CAAC,qBAAqB,IAAI,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED;;;;;;;;OAQG;IACH,6DAA6D;IAC7C,YAAY,CAAC,aAA+B;QACxD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACvC,OAAO,MAAM,CAAC,qBAAqB,IAAI,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED;;;;OAIG;IACI,2BAA2B,CAAC,OAAY,EAAE,UAAkB;QAC/D,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC,GAAG,IAAI,CAAC;IAC5C,CAAC;CACJ;AApUG;IADC,SAAS,EAAE;yDAGX;AAgBD;IADC,SAAS,EAAE;wDAGX;AAgBM;IADN,SAAS,EAAE;2DACoB;AAOzB;IADN,SAAS,EAAE;+DACyB;AAI7B;IADP,SAAS,CAAC,WAAW,CAAC;oDACe;AAE9B;IADP,SAAS,CAAC,YAAY,CAAC;qDACe;AAE/B;IADP,SAAS,CAAC,UAAU,CAAC;mDACe;AAE7B;IADP,SAAS,CAAC,aAAa,CAAC;sDACe;AAiR5C,sBAAsB;AACtB,aAAa,CAAC,0BAA0B,EAAE,gBAAgB,CAAC,CAAC","sourcesContent":["import { serialize } from \"../Misc/decorators\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Matrix, Vector3 } from \"../Maths/math.vector\";\r\nimport { Node } from \"../node\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Light } from \"./light\";\r\nimport { ShadowLight } from \"./shadowLight\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Constants } from \"core/Engines/constants\";\r\n\r\nNode.AddNodeConstructor(\"Light_Type_1\", (name, scene) => {\r\n return () => new DirectionalLight(name, Vector3.Zero(), scene);\r\n});\r\n\r\n/**\r\n * A directional light is defined by a direction (what a surprise!).\r\n * The light is emitted from everywhere in the specified direction, and has an infinite range.\r\n * An example of a directional light is when a distance planet is lit by the apparently parallel lines of light from its sun. Light in a downward direction will light the top of an object.\r\n * Documentation: https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\r\n */\r\nexport class DirectionalLight extends ShadowLight {\r\n private _shadowFrustumSize = 0;\r\n /**\r\n * Fix frustum size for the shadow generation. This is disabled if the value is 0.\r\n */\r\n @serialize()\r\n public get shadowFrustumSize(): number {\r\n return this._shadowFrustumSize;\r\n }\r\n /**\r\n * Specifies a fix frustum size for the shadow generation.\r\n */\r\n public set shadowFrustumSize(value: number) {\r\n this._shadowFrustumSize = value;\r\n this.forceProjectionMatrixCompute();\r\n }\r\n\r\n private _shadowOrthoScale = 0.1;\r\n /**\r\n * Gets the shadow projection scale against the optimal computed one.\r\n * 0.1 by default which means that the projection window is increase by 10% from the optimal size.\r\n * This does not impact in fixed frustum size (shadowFrustumSize being set)\r\n */\r\n @serialize()\r\n public get shadowOrthoScale(): number {\r\n return this._shadowOrthoScale;\r\n }\r\n /**\r\n * Sets the shadow projection scale against the optimal computed one.\r\n * 0.1 by default which means that the projection window is increase by 10% from the optimal size.\r\n * This does not impact in fixed frustum size (shadowFrustumSize being set)\r\n */\r\n public set shadowOrthoScale(value: number) {\r\n this._shadowOrthoScale = value;\r\n this.forceProjectionMatrixCompute();\r\n }\r\n\r\n /**\r\n * Automatically compute the projection matrix to best fit (including all the casters)\r\n * on each frame.\r\n */\r\n @serialize()\r\n public autoUpdateExtends = true;\r\n\r\n /**\r\n * Automatically compute the shadowMinZ and shadowMaxZ for the projection matrix to best fit (including all the casters)\r\n * on each frame. autoUpdateExtends must be set to true for this to work\r\n */\r\n @serialize()\r\n public autoCalcShadowZBounds = false;\r\n\r\n // Cache\r\n @serialize(\"orthoLeft\")\r\n private _orthoLeft = Number.MAX_VALUE;\r\n @serialize(\"orthoRight\")\r\n private _orthoRight = Number.MIN_VALUE;\r\n @serialize(\"orthoTop\")\r\n private _orthoTop = Number.MIN_VALUE;\r\n @serialize(\"orthoBottom\")\r\n private _orthoBottom = Number.MAX_VALUE;\r\n\r\n /**\r\n * Gets or sets the orthoLeft property used to build the light frustum\r\n */\r\n public get orthoLeft(): number {\r\n return this._orthoLeft;\r\n }\r\n\r\n public set orthoLeft(left: number) {\r\n this._orthoLeft = left;\r\n }\r\n\r\n /**\r\n * Gets or sets the orthoRight property used to build the light frustum\r\n */\r\n public get orthoRight(): number {\r\n return this._orthoRight;\r\n }\r\n\r\n public set orthoRight(right: number) {\r\n this._orthoRight = right;\r\n }\r\n\r\n /**\r\n * Gets or sets the orthoTop property used to build the light frustum\r\n */\r\n public get orthoTop(): number {\r\n return this._orthoTop;\r\n }\r\n\r\n public set orthoTop(top: number) {\r\n this._orthoTop = top;\r\n }\r\n\r\n /**\r\n * Gets or sets the orthoBottom property used to build the light frustum\r\n */\r\n public get orthoBottom(): number {\r\n return this._orthoBottom;\r\n }\r\n\r\n public set orthoBottom(bottom: number) {\r\n this._orthoBottom = bottom;\r\n }\r\n\r\n /**\r\n * Creates a DirectionalLight object in the scene, oriented towards the passed direction (Vector3).\r\n * The directional light is emitted from everywhere in the given direction.\r\n * It can cast shadows.\r\n * Documentation : https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\r\n * @param name The friendly name of the light\r\n * @param direction The direction of the light\r\n * @param scene The scene the light belongs to\r\n */\r\n constructor(name: string, direction: Vector3, scene?: Scene) {\r\n super(name, scene);\r\n this.position = direction.scale(-1.0);\r\n this.direction = direction;\r\n }\r\n\r\n /**\r\n * Returns the string \"DirectionalLight\".\r\n * @returns The class name\r\n */\r\n public override getClassName(): string {\r\n return \"DirectionalLight\";\r\n }\r\n\r\n /**\r\n * Returns the integer 1.\r\n * @returns The light Type id as a constant defines in Light.LIGHTTYPEID_x\r\n */\r\n public override getTypeID(): number {\r\n return Light.LIGHTTYPEID_DIRECTIONALLIGHT;\r\n }\r\n\r\n /**\r\n * Sets the passed matrix \"matrix\" as projection matrix for the shadows cast by the light according to the passed view matrix.\r\n * Returns the DirectionalLight Shadow projection matrix.\r\n * @param matrix\r\n * @param viewMatrix\r\n * @param renderList\r\n */\r\n protected _setDefaultShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array<AbstractMesh>): void {\r\n if (this.shadowFrustumSize > 0) {\r\n this._setDefaultFixedFrustumShadowProjectionMatrix(matrix);\r\n } else {\r\n this._setDefaultAutoExtendShadowProjectionMatrix(matrix, viewMatrix, renderList);\r\n }\r\n }\r\n\r\n /**\r\n * Sets the passed matrix \"matrix\" as fixed frustum projection matrix for the shadows cast by the light according to the passed view matrix.\r\n * Returns the DirectionalLight Shadow projection matrix.\r\n * @param matrix\r\n */\r\n protected _setDefaultFixedFrustumShadowProjectionMatrix(matrix: Matrix): void {\r\n const activeCamera = this.getScene().activeCamera;\r\n\r\n if (!activeCamera) {\r\n return;\r\n }\r\n\r\n Matrix.OrthoLHToRef(\r\n this.shadowFrustumSize,\r\n this.shadowFrustumSize,\r\n this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ,\r\n this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ,\r\n matrix,\r\n this.getScene().getEngine().isNDCHalfZRange\r\n );\r\n }\r\n\r\n /**\r\n * Sets the passed matrix \"matrix\" as auto extend projection matrix for the shadows cast by the light according to the passed view matrix.\r\n * Returns the DirectionalLight Shadow projection matrix.\r\n * @param matrix\r\n * @param viewMatrix\r\n * @param renderList\r\n */\r\n protected _setDefaultAutoExtendShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array<AbstractMesh>): void {\r\n const activeCamera = this.getScene().activeCamera;\r\n\r\n // Check extends\r\n if (this.autoUpdateExtends || this._orthoLeft === Number.MAX_VALUE) {\r\n const tempVector3 = Vector3.Zero();\r\n\r\n this._orthoLeft = Number.MAX_VALUE;\r\n this._orthoRight = -Number.MAX_VALUE;\r\n this._orthoTop = -Number.MAX_VALUE;\r\n this._orthoBottom = Number.MAX_VALUE;\r\n\r\n let shadowMinZ = Number.MAX_VALUE;\r\n let shadowMaxZ = -Number.MAX_VALUE;\r\n\r\n for (let meshIndex = 0; meshIndex < renderList.length; meshIndex++) {\r\n const mesh = renderList[meshIndex];\r\n\r\n if (!mesh) {\r\n continue;\r\n }\r\n\r\n const boundingInfo = mesh.getBoundingInfo();\r\n const boundingBox = boundingInfo.boundingBox;\r\n\r\n for (let index = 0; index < boundingBox.vectorsWorld.length; index++) {\r\n Vector3.TransformCoordinatesToRef(boundingBox.vectorsWorld[index], viewMatrix, tempVector3);\r\n\r\n if (tempVector3.x < this._orthoLeft) {\r\n this._orthoLeft = tempVector3.x;\r\n }\r\n if (tempVector3.y < this._orthoBottom) {\r\n this._orthoBottom = tempVector3.y;\r\n }\r\n\r\n if (tempVector3.x > this._orthoRight) {\r\n this._orthoRight = tempVector3.x;\r\n }\r\n if (tempVector3.y > this._orthoTop) {\r\n this._orthoTop = tempVector3.y;\r\n }\r\n if (this.autoCalcShadowZBounds) {\r\n if (tempVector3.z < shadowMinZ) {\r\n shadowMinZ = tempVector3.z;\r\n }\r\n if (tempVector3.z > shadowMaxZ) {\r\n shadowMaxZ = tempVector3.z;\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (this.autoCalcShadowZBounds) {\r\n this._shadowMinZ = shadowMinZ;\r\n this._shadowMaxZ = shadowMaxZ;\r\n }\r\n }\r\n\r\n const xOffset = this._orthoRight - this._orthoLeft;\r\n const yOffset = this._orthoTop - this._orthoBottom;\r\n\r\n const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera?.minZ || Constants.ShadowMinZ;\r\n const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera?.maxZ || Constants.ShadowMaxZ;\r\n\r\n const useReverseDepthBuffer = this.getScene().getEngine().useReverseDepthBuffer;\r\n\r\n Matrix.OrthoOffCenterLHToRef(\r\n this._orthoLeft - xOffset * this.shadowOrthoScale,\r\n this._orthoRight + xOffset * this.shadowOrthoScale,\r\n this._orthoBottom - yOffset * this.shadowOrthoScale,\r\n this._orthoTop + yOffset * this.shadowOrthoScale,\r\n useReverseDepthBuffer ? maxZ : minZ,\r\n useReverseDepthBuffer ? minZ : maxZ,\r\n matrix,\r\n this.getScene().getEngine().isNDCHalfZRange\r\n );\r\n }\r\n\r\n protected _buildUniformLayout(): void {\r\n this._uniformBuffer.addUniform(\"vLightData\", 4);\r\n this._uniformBuffer.addUniform(\"vLightDiffuse\", 4);\r\n this._uniformBuffer.addUniform(\"vLightSpecular\", 4);\r\n this._uniformBuffer.addUniform(\"shadowsInfo\", 3);\r\n this._uniformBuffer.addUniform(\"depthValues\", 2);\r\n this._uniformBuffer.create();\r\n }\r\n\r\n /**\r\n * Sets the passed Effect object with the DirectionalLight transformed position (or position if not parented) and the passed name.\r\n * @param effect The effect to update\r\n * @param lightIndex The index of the light in the effect to update\r\n * @returns The directional light\r\n */\r\n public transferToEffect(effect: Effect, lightIndex: string): DirectionalLight {\r\n if (this.computeTransformedInformation()) {\r\n this._uniformBuffer.updateFloat4(\"vLightData\", this.transformedDirection.x, this.transformedDirection.y, this.transformedDirection.z, 1, lightIndex);\r\n return this;\r\n }\r\n this._uniformBuffer.updateFloat4(\"vLightData\", this.direction.x, this.direction.y, this.direction.z, 1, lightIndex);\r\n return this;\r\n }\r\n\r\n public transferToNodeMaterialEffect(effect: Effect, lightDataUniformName: string): Light {\r\n if (this.computeTransformedInformation()) {\r\n effect.setFloat3(lightDataUniformName, this.transformedDirection.x, this.transformedDirection.y, this.transformedDirection.z);\r\n return this;\r\n }\r\n\r\n effect.setFloat3(lightDataUniformName, this.direction.x, this.direction.y, this.direction.z);\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets the minZ used for shadow according to both the scene and the light.\r\n *\r\n * Values are fixed on directional lights as it relies on an ortho projection hence the need to convert being\r\n * -1 and 1 to 0 and 1 doing (depth + min) / (min + max) -> (depth + 1) / (1 + 1) -> (depth * 0.5) + 0.5.\r\n * (when not using reverse depth buffer / NDC half Z range)\r\n * @param _activeCamera The camera we are returning the min for (not used)\r\n * @returns the depth min z\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public override getDepthMinZ(_activeCamera: Nullable<Camera>): number {\r\n const engine = this._scene.getEngine();\r\n return !engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : 1;\r\n }\r\n\r\n /**\r\n * Gets the maxZ used for shadow according to both the scene and the light.\r\n *\r\n * Values are fixed on directional lights as it relies on an ortho projection hence the need to convert being\r\n * -1 and 1 to 0 and 1 doing (depth + min) / (min + max) -> (depth + 1) / (1 + 1) -> (depth * 0.5) + 0.5.\r\n * (when not using reverse depth buffer / NDC half Z range)\r\n * @param _activeCamera The camera we are returning the max for\r\n * @returns the depth max z\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public override getDepthMaxZ(_activeCamera: Nullable<Camera>): number {\r\n const engine = this._scene.getEngine();\r\n return engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : 1;\r\n }\r\n\r\n /**\r\n * Prepares the list of defines specific to the light type.\r\n * @param defines the list of defines\r\n * @param lightIndex defines the index of the light for the effect\r\n */\r\n public prepareLightSpecificDefines(defines: any, lightIndex: number): void {\r\n defines[\"DIRLIGHT\" + lightIndex] = true;\r\n }\r\n}\r\n\r\n// Register Class Name\r\nRegisterClass(\"BABYLON.DirectionalLight\", DirectionalLight);\r\n"]}
@@ -95,13 +95,13 @@ export interface IShadowLight extends Light {
95
95
  * @param activeCamera The camera we are returning the min for
96
96
  * @returns the depth min z
97
97
  */
98
- getDepthMinZ(activeCamera: Camera): number;
98
+ getDepthMinZ(activeCamera: Nullable<Camera>): number;
99
99
  /**
100
100
  * Gets the maxZ used for shadow according to both the scene and the light.
101
101
  * @param activeCamera The camera we are returning the max for
102
102
  * @returns the depth max z
103
103
  */
104
- getDepthMaxZ(activeCamera: Camera): number;
104
+ getDepthMaxZ(activeCamera: Nullable<Camera>): number;
105
105
  }
106
106
  /**
107
107
  * Base implementation IShadowLight
@@ -226,13 +226,13 @@ export declare abstract class ShadowLight extends Light implements IShadowLight
226
226
  * @param activeCamera The camera we are returning the min for
227
227
  * @returns the depth min z
228
228
  */
229
- getDepthMinZ(activeCamera: Camera): number;
229
+ getDepthMinZ(activeCamera: Nullable<Camera>): number;
230
230
  /**
231
231
  * Gets the maxZ used for shadow according to both the scene and the light.
232
232
  * @param activeCamera The camera we are returning the max for
233
233
  * @returns the depth max z
234
234
  */
235
- getDepthMaxZ(activeCamera: Camera): number;
235
+ getDepthMaxZ(activeCamera: Nullable<Camera>): number;
236
236
  /**
237
237
  * Sets the shadow projection matrix in parameter to the generated projection matrix.
238
238
  * @param matrix The matrix to updated with the projection information
@@ -3,6 +3,7 @@ import { serialize, serializeAsVector3 } from "../Misc/decorators.js";
3
3
  import { Matrix, TmpVectors, Vector3 } from "../Maths/math.vector.js";
4
4
  import { Light } from "./light.js";
5
5
  import { Axis } from "../Maths/math.axis.js";
6
+
6
7
  /**
7
8
  * Base implementation IShadowLight
8
9
  * It groups all the common behaviour in order to reduce duplication and better follow the DRY pattern.
@@ -199,7 +200,7 @@ export class ShadowLight extends Light {
199
200
  * @returns the depth min z
200
201
  */
201
202
  getDepthMinZ(activeCamera) {
202
- return this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;
203
+ return this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera?.minZ || 0;
203
204
  }
204
205
  /**
205
206
  * Gets the maxZ used for shadow according to both the scene and the light.
@@ -207,7 +208,7 @@ export class ShadowLight extends Light {
207
208
  * @returns the depth max z
208
209
  */
209
210
  getDepthMaxZ(activeCamera) {
210
- return this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;
211
+ return this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera?.maxZ || 10000;
211
212
  }
212
213
  /**
213
214
  * Sets the shadow projection matrix in parameter to the generated projection matrix.
@@ -1 +1 @@
1
- {"version":3,"file":"shadowLight.js","sourceRoot":"","sources":["../../../../dev/core/src/Lights/shadowLight.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGnE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEnE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAiH1C;;;GAGG;AACH,MAAM,OAAgB,WAAY,SAAQ,KAAK;IAA/C;;QA2FY,iCAA4B,GAAY,IAAI,CAAC;QA0L3C,gBAAW,GAAW,MAAM,CAAC,QAAQ,EAAE,CAAC;QACxC,sBAAiB,GAAW,MAAM,CAAC,QAAQ,EAAE,CAAC;IAwC5D,CAAC;IA1Ta,YAAY,CAAC,KAAc;QACjC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IAC3B,CAAC;IACD;;;OAGG;IAEH,IAAW,QAAQ;QACf,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IACD;;;OAGG;IACH,IAAW,QAAQ,CAAC,KAAc;QAC9B,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAGS,aAAa,CAAC,KAAc;QAClC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IAC5B,CAAC;IACD;;;OAGG;IAEH,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IACD;;;OAGG;IACH,IAAW,SAAS,CAAC,KAAc;QAC/B,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAGD;;OAEG;IAE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,mBAAmB,CAAC;QAC7C,CAAC;QAED,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAAE,cAAc,CAAC,CAAC;QAC3E,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YAC9D,cAAc,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,kDAAkD;QAC1F,CAAC;QAED,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC1C,aAAa,CAAC,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;QAEpD,MAAM,CAAC,aAAa,CAAC,aAAa,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAEjF,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED;;;;;;OAMG;IACa,mBAAmB,CAAC,UAAmB,EAAE,UAAgC;QACrF,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,iBAAiB,EAAE,UAAU,IAAI,IAAI,CAAC,WAAW,EAAE,UAAU,IAAI,EAAE,CAAC,CAAC;QAEzG,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAClC,CAAC;CACJ;AAlTG;IADC,kBAAkB,EAAE;2CAGpB;AAkBD;IADC,kBAAkB,EAAE;4CAGpB;AAcD;IADC,SAAS,EAAE;6CAGX;AAcD;IADC,SAAS,EAAE;6CAGX","sourcesContent":["import { serialize, serializeAsVector3 } from \"../Misc/decorators\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Matrix, TmpVectors, Vector3 } from \"../Maths/math.vector\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Light } from \"./light\";\r\nimport { Axis } from \"../Maths/math.axis\";\r\nimport type { Nullable } from \"core/types\";\r\n/**\r\n * Interface describing all the common properties and methods a shadow light needs to implement.\r\n * This helps both the shadow generator and materials to generate the corresponding shadow maps\r\n * as well as binding the different shadow properties to the effects.\r\n */\r\nexport interface IShadowLight extends Light {\r\n /**\r\n * The light id in the scene (used in scene.getLightById for instance)\r\n */\r\n id: string;\r\n /**\r\n * The position the shadow will be casted from.\r\n */\r\n position: Vector3;\r\n /**\r\n * In 2d mode (needCube being false), the direction used to cast the shadow.\r\n */\r\n direction: Vector3;\r\n /**\r\n * The transformed position. Position of the light in world space taking parenting in account.\r\n */\r\n transformedPosition: Vector3;\r\n /**\r\n * The transformed direction. Direction of the light in world space taking parenting in account.\r\n */\r\n transformedDirection: Vector3;\r\n /**\r\n * The friendly name of the light in the scene.\r\n */\r\n name: string;\r\n /**\r\n * Defines the shadow projection clipping minimum z value.\r\n */\r\n shadowMinZ: number;\r\n /**\r\n * Defines the shadow projection clipping maximum z value.\r\n */\r\n shadowMaxZ: number;\r\n\r\n /**\r\n * Computes the transformed information (transformedPosition and transformedDirection in World space) of the current light\r\n * @returns true if the information has been computed, false if it does not need to (no parenting)\r\n */\r\n computeTransformedInformation(): boolean;\r\n\r\n /**\r\n * Gets the scene the light belongs to.\r\n * @returns The scene\r\n */\r\n getScene(): Scene;\r\n\r\n /**\r\n * Callback defining a custom Projection Matrix Builder.\r\n * This can be used to override the default projection matrix computation.\r\n */\r\n customProjectionMatrixBuilder: (viewMatrix: Matrix, renderList: Array<AbstractMesh>, result: Matrix) => void;\r\n\r\n /**\r\n * Sets the shadow projection matrix in parameter to the generated projection matrix.\r\n * @param matrix The matrix to update with the projection information\r\n * @param viewMatrix The transform matrix of the light\r\n * @param renderList The list of mesh to render in the map\r\n * @returns The current light\r\n */\r\n setShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array<AbstractMesh>): IShadowLight;\r\n\r\n /**\r\n * Gets the current depth scale used in ESM.\r\n * @returns The scale\r\n */\r\n getDepthScale(): number;\r\n\r\n /**\r\n * Returns whether or not the shadow generation require a cube texture or a 2d texture.\r\n * @returns true if a cube texture needs to be use\r\n */\r\n needCube(): boolean;\r\n\r\n /**\r\n * Detects if the projection matrix requires to be recomputed this frame.\r\n * @returns true if it requires to be recomputed otherwise, false.\r\n */\r\n needProjectionMatrixCompute(): boolean;\r\n\r\n /**\r\n * Forces the shadow generator to recompute the projection matrix even if position and direction did not changed.\r\n */\r\n forceProjectionMatrixCompute(): void;\r\n\r\n /**\r\n * Get the direction to use to render the shadow map. In case of cube texture, the face index can be passed.\r\n * @param faceIndex The index of the face we are computed the direction to generate shadow\r\n * @returns The set direction in 2d mode otherwise the direction to the cubemap face if needCube() is true\r\n */\r\n getShadowDirection(faceIndex?: number): Vector3;\r\n\r\n /**\r\n * Gets the minZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the min for\r\n * @returns the depth min z\r\n */\r\n getDepthMinZ(activeCamera: Camera): number;\r\n\r\n /**\r\n * Gets the maxZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the max for\r\n * @returns the depth max z\r\n */\r\n getDepthMaxZ(activeCamera: Camera): number;\r\n}\r\n\r\n/**\r\n * Base implementation IShadowLight\r\n * It groups all the common behaviour in order to reduce duplication and better follow the DRY pattern.\r\n */\r\nexport abstract class ShadowLight extends Light implements IShadowLight {\r\n protected abstract _setDefaultShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array<AbstractMesh>): void;\r\n\r\n protected _position: Vector3;\r\n protected _setPosition(value: Vector3) {\r\n this._position = value;\r\n }\r\n /**\r\n * Sets the position the shadow will be casted from. Also use as the light position for both\r\n * point and spot lights.\r\n */\r\n @serializeAsVector3()\r\n public get position(): Vector3 {\r\n return this._position;\r\n }\r\n /**\r\n * Sets the position the shadow will be casted from. Also use as the light position for both\r\n * point and spot lights.\r\n */\r\n public set position(value: Vector3) {\r\n this._setPosition(value);\r\n }\r\n\r\n protected _direction: Vector3;\r\n protected _setDirection(value: Vector3) {\r\n this._direction = value;\r\n }\r\n /**\r\n * In 2d mode (needCube being false), gets the direction used to cast the shadow.\r\n * Also use as the light direction on spot and directional lights.\r\n */\r\n @serializeAsVector3()\r\n public get direction(): Vector3 {\r\n return this._direction;\r\n }\r\n /**\r\n * In 2d mode (needCube being false), sets the direction used to cast the shadow.\r\n * Also use as the light direction on spot and directional lights.\r\n */\r\n public set direction(value: Vector3) {\r\n this._setDirection(value);\r\n }\r\n\r\n protected _shadowMinZ: number;\r\n /**\r\n * Gets the shadow projection clipping minimum z value.\r\n */\r\n @serialize()\r\n public get shadowMinZ(): number {\r\n return this._shadowMinZ;\r\n }\r\n /**\r\n * Sets the shadow projection clipping minimum z value.\r\n */\r\n public set shadowMinZ(value: number) {\r\n this._shadowMinZ = value;\r\n this.forceProjectionMatrixCompute();\r\n }\r\n\r\n protected _shadowMaxZ: number;\r\n /**\r\n * Sets the shadow projection clipping maximum z value.\r\n */\r\n @serialize()\r\n public get shadowMaxZ(): number {\r\n return this._shadowMaxZ;\r\n }\r\n /**\r\n * Gets the shadow projection clipping maximum z value.\r\n */\r\n public set shadowMaxZ(value: number) {\r\n this._shadowMaxZ = value;\r\n this.forceProjectionMatrixCompute();\r\n }\r\n\r\n /**\r\n * Callback defining a custom Projection Matrix Builder.\r\n * This can be used to override the default projection matrix computation.\r\n */\r\n public customProjectionMatrixBuilder: (viewMatrix: Matrix, renderList: Array<AbstractMesh>, result: Matrix) => void;\r\n\r\n /**\r\n * The transformed position. Position of the light in world space taking parenting in account. Needs to be computed by calling computeTransformedInformation.\r\n */\r\n public transformedPosition: Vector3;\r\n\r\n /**\r\n * The transformed direction. Direction of the light in world space taking parenting in account.\r\n */\r\n public transformedDirection: Vector3;\r\n\r\n private _needProjectionMatrixCompute: boolean = true;\r\n\r\n /**\r\n * Computes the transformed information (transformedPosition and transformedDirection in World space) of the current light\r\n * @returns true if the information has been computed, false if it does not need to (no parenting)\r\n */\r\n public computeTransformedInformation(): boolean {\r\n if (this.parent && this.parent.getWorldMatrix) {\r\n if (!this.transformedPosition) {\r\n this.transformedPosition = Vector3.Zero();\r\n }\r\n Vector3.TransformCoordinatesToRef(this.position, this.parent.getWorldMatrix(), this.transformedPosition);\r\n\r\n // In case the direction is present.\r\n if (this.direction) {\r\n if (!this.transformedDirection) {\r\n this.transformedDirection = Vector3.Zero();\r\n }\r\n Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this.transformedDirection);\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Return the depth scale used for the shadow map.\r\n * @returns the depth scale.\r\n */\r\n public getDepthScale(): number {\r\n return 50.0;\r\n }\r\n\r\n /**\r\n * Get the direction to use to render the shadow map. In case of cube texture, the face index can be passed.\r\n * @param faceIndex The index of the face we are computed the direction to generate shadow\r\n * @returns The set direction in 2d mode otherwise the direction to the cubemap face if needCube() is true\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getShadowDirection(faceIndex?: number): Vector3 {\r\n return this.transformedDirection ? this.transformedDirection : this.direction;\r\n }\r\n\r\n /**\r\n * If computeTransformedInformation has been called, returns the ShadowLight absolute position in the world. Otherwise, returns the local position.\r\n * @returns the position vector in world space\r\n */\r\n public override getAbsolutePosition(): Vector3 {\r\n return this.transformedPosition ? this.transformedPosition : this.position;\r\n }\r\n\r\n /**\r\n * Sets the ShadowLight direction toward the passed target.\r\n * @param target The point to target in local space\r\n * @returns the updated ShadowLight direction\r\n */\r\n public setDirectionToTarget(target: Vector3): Vector3 {\r\n this.direction = Vector3.Normalize(target.subtract(this.position));\r\n return this.direction;\r\n }\r\n\r\n /**\r\n * Returns the light rotation in euler definition.\r\n * @returns the x y z rotation in local space.\r\n */\r\n public getRotation(): Vector3 {\r\n this.direction.normalize();\r\n const xaxis = Vector3.Cross(this.direction, Axis.Y);\r\n const yaxis = Vector3.Cross(xaxis, this.direction);\r\n return Vector3.RotationFromAxis(xaxis, yaxis, this.direction);\r\n }\r\n\r\n /**\r\n * Returns whether or not the shadow generation require a cube texture or a 2d texture.\r\n * @returns true if a cube texture needs to be use\r\n */\r\n public needCube(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Detects if the projection matrix requires to be recomputed this frame.\r\n * @returns true if it requires to be recomputed otherwise, false.\r\n */\r\n public needProjectionMatrixCompute(): boolean {\r\n return this._needProjectionMatrixCompute;\r\n }\r\n\r\n /**\r\n * Forces the shadow generator to recompute the projection matrix even if position and direction did not changed.\r\n */\r\n public forceProjectionMatrixCompute(): void {\r\n this._needProjectionMatrixCompute = true;\r\n }\r\n\r\n /** @internal */\r\n public override _initCache() {\r\n super._initCache();\r\n\r\n this._cache.position = Vector3.Zero();\r\n }\r\n\r\n /** @internal */\r\n public override _isSynchronized(): boolean {\r\n if (!this._cache.position.equals(this.position)) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Computes the world matrix of the node\r\n * @param force defines if the cache version should be invalidated forcing the world matrix to be created from scratch\r\n * @returns the world matrix\r\n */\r\n public override computeWorldMatrix(force?: boolean): Matrix {\r\n if (!force && this.isSynchronized()) {\r\n this._currentRenderId = this.getScene().getRenderId();\r\n return this._worldMatrix;\r\n }\r\n\r\n this._updateCache();\r\n this._cache.position.copyFrom(this.position);\r\n\r\n if (!this._worldMatrix) {\r\n this._worldMatrix = Matrix.Identity();\r\n }\r\n\r\n Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._worldMatrix);\r\n\r\n if (this.parent && this.parent.getWorldMatrix) {\r\n this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);\r\n\r\n this._markSyncedWithParent();\r\n }\r\n\r\n // Cache the determinant\r\n this._worldMatrixDeterminantIsDirty = true;\r\n\r\n return this._worldMatrix;\r\n }\r\n\r\n /**\r\n * Gets the minZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the min for\r\n * @returns the depth min z\r\n */\r\n public getDepthMinZ(activeCamera: Camera): number {\r\n return this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;\r\n }\r\n\r\n /**\r\n * Gets the maxZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the max for\r\n * @returns the depth max z\r\n */\r\n public getDepthMaxZ(activeCamera: Camera): number {\r\n return this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;\r\n }\r\n\r\n /**\r\n * Sets the shadow projection matrix in parameter to the generated projection matrix.\r\n * @param matrix The matrix to updated with the projection information\r\n * @param viewMatrix The transform matrix of the light\r\n * @param renderList The list of mesh to render in the map\r\n * @returns The current light\r\n */\r\n public setShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array<AbstractMesh>): IShadowLight {\r\n if (this.customProjectionMatrixBuilder) {\r\n this.customProjectionMatrixBuilder(viewMatrix, renderList, matrix);\r\n } else {\r\n this._setDefaultShadowProjectionMatrix(matrix, viewMatrix, renderList);\r\n }\r\n return this;\r\n }\r\n\r\n /** @internal */\r\n protected override _syncParentEnabledState() {\r\n super._syncParentEnabledState();\r\n if (!this.parent || !this.parent.getWorldMatrix) {\r\n (this.transformedPosition as any) = null;\r\n (this.transformedDirection as any) = null;\r\n }\r\n }\r\n\r\n protected _viewMatrix: Matrix = Matrix.Identity();\r\n protected _projectionMatrix: Matrix = Matrix.Identity();\r\n\r\n /**\r\n * Returns the view matrix.\r\n * @param faceIndex The index of the face for which we want to extract the view matrix. Only used for point light types.\r\n * @returns The view matrix. Can be null, if a view matrix cannot be defined for the type of light considered (as for a hemispherical light, for example).\r\n */\r\n public override getViewMatrix(faceIndex?: number): Nullable<Matrix> {\r\n const lightDirection = TmpVectors.Vector3[0];\r\n\r\n let lightPosition = this.position;\r\n if (this.computeTransformedInformation()) {\r\n lightPosition = this.transformedPosition;\r\n }\r\n\r\n Vector3.NormalizeToRef(this.getShadowDirection(faceIndex), lightDirection);\r\n if (Math.abs(Vector3.Dot(lightDirection, Vector3.Up())) === 1.0) {\r\n lightDirection.z = 0.0000000000001; // Required to avoid perfectly perpendicular light\r\n }\r\n\r\n const lightTarget = TmpVectors.Vector3[1];\r\n lightPosition.addToRef(lightDirection, lightTarget);\r\n\r\n Matrix.LookAtLHToRef(lightPosition, lightTarget, Vector3.Up(), this._viewMatrix);\r\n\r\n return this._viewMatrix;\r\n }\r\n\r\n /**\r\n * Returns the projection matrix.\r\n * Note that viewMatrix and renderList are optional and are only used by lights that calculate the projection matrix from a list of meshes (e.g. directional lights with automatic extents calculation).\r\n * @param viewMatrix The view transform matrix of the light (optional).\r\n * @param renderList The list of meshes to take into account when calculating the projection matrix (optional).\r\n * @returns The projection matrix. Can be null, if a projection matrix cannot be defined for the type of light considered (as for a hemispherical light, for example).\r\n */\r\n public override getProjectionMatrix(viewMatrix?: Matrix, renderList?: Array<AbstractMesh>): Nullable<Matrix> {\r\n this.setShadowProjectionMatrix(this._projectionMatrix, viewMatrix ?? this._viewMatrix, renderList ?? []);\r\n\r\n return this._projectionMatrix;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"shadowLight.js","sourceRoot":"","sources":["../../../../dev/core/src/Lights/shadowLight.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGnE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEnE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,gCAA+B;AAgHnD;;;GAGG;AACH,MAAM,OAAgB,WAAY,SAAQ,KAAK;IAA/C;;QA2FY,iCAA4B,GAAY,IAAI,CAAC;QA0L3C,gBAAW,GAAW,MAAM,CAAC,QAAQ,EAAE,CAAC;QACxC,sBAAiB,GAAW,MAAM,CAAC,QAAQ,EAAE,CAAC;IAwC5D,CAAC;IA1Ta,YAAY,CAAC,KAAc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B,EAAE,UAAgC;QACrF,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,iBAAiB,EAAE,UAAU,IAAI,IAAI,CAAC,WAAW,EAAE,UAAU,IAAI,EAAE,CAAC,CAAC;QAEzG,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAClC,CAAC;CACJ;AAlTG;IADC,kBAAkB,EAAE;2CAGpB;AAkBD;IADC,kBAAkB,EAAE;4CAGpB;AAcD;IADC,SAAS,EAAE;6CAGX;AAcD;IADC,SAAS,EAAE;6CAGX","sourcesContent":["import { serialize, serializeAsVector3 } from \"../Misc/decorators\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Matrix, TmpVectors, Vector3 } from \"../Maths/math.vector\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Light } from \"./light\";\r\nimport { Axis } from \"../Maths/math.axis\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { Constants } from \"core/Engines/constants\";\r\n/**\r\n * Interface describing all the common properties and methods a shadow light needs to implement.\r\n * This helps both the shadow generator and materials to generate the corresponding shadow maps\r\n * as well as binding the different shadow properties to the effects.\r\n */\r\nexport interface IShadowLight extends Light {\r\n /**\r\n * The light id in the scene (used in scene.getLightById for instance)\r\n */\r\n id: string;\r\n /**\r\n * The position the shadow will be casted from.\r\n */\r\n position: Vector3;\r\n /**\r\n * In 2d mode (needCube being false), the direction used to cast the shadow.\r\n */\r\n direction: Vector3;\r\n /**\r\n * The transformed position. Position of the light in world space taking parenting in account.\r\n */\r\n transformedPosition: Vector3;\r\n /**\r\n * The transformed direction. Direction of the light in world space taking parenting in account.\r\n */\r\n transformedDirection: Vector3;\r\n /**\r\n * The friendly name of the light in the scene.\r\n */\r\n name: string;\r\n /**\r\n * Defines the shadow projection clipping minimum z value.\r\n */\r\n shadowMinZ: number;\r\n /**\r\n * Defines the shadow projection clipping maximum z value.\r\n */\r\n shadowMaxZ: number;\r\n\r\n /**\r\n * Computes the transformed information (transformedPosition and transformedDirection in World space) of the current light\r\n * @returns true if the information has been computed, false if it does not need to (no parenting)\r\n */\r\n computeTransformedInformation(): boolean;\r\n\r\n /**\r\n * Gets the scene the light belongs to.\r\n * @returns The scene\r\n */\r\n getScene(): Scene;\r\n\r\n /**\r\n * Callback defining a custom Projection Matrix Builder.\r\n * This can be used to override the default projection matrix computation.\r\n */\r\n customProjectionMatrixBuilder: (viewMatrix: Matrix, renderList: Array<AbstractMesh>, result: Matrix) => void;\r\n\r\n /**\r\n * Sets the shadow projection matrix in parameter to the generated projection matrix.\r\n * @param matrix The matrix to update with the projection information\r\n * @param viewMatrix The transform matrix of the light\r\n * @param renderList The list of mesh to render in the map\r\n * @returns The current light\r\n */\r\n setShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array<AbstractMesh>): IShadowLight;\r\n\r\n /**\r\n * Gets the current depth scale used in ESM.\r\n * @returns The scale\r\n */\r\n getDepthScale(): number;\r\n\r\n /**\r\n * Returns whether or not the shadow generation require a cube texture or a 2d texture.\r\n * @returns true if a cube texture needs to be use\r\n */\r\n needCube(): boolean;\r\n\r\n /**\r\n * Detects if the projection matrix requires to be recomputed this frame.\r\n * @returns true if it requires to be recomputed otherwise, false.\r\n */\r\n needProjectionMatrixCompute(): boolean;\r\n\r\n /**\r\n * Forces the shadow generator to recompute the projection matrix even if position and direction did not changed.\r\n */\r\n forceProjectionMatrixCompute(): void;\r\n\r\n /**\r\n * Get the direction to use to render the shadow map. In case of cube texture, the face index can be passed.\r\n * @param faceIndex The index of the face we are computed the direction to generate shadow\r\n * @returns The set direction in 2d mode otherwise the direction to the cubemap face if needCube() is true\r\n */\r\n getShadowDirection(faceIndex?: number): Vector3;\r\n\r\n /**\r\n * Gets the minZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the min for\r\n * @returns the depth min z\r\n */\r\n getDepthMinZ(activeCamera: Nullable<Camera>): number;\r\n\r\n /**\r\n * Gets the maxZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the max for\r\n * @returns the depth max z\r\n */\r\n getDepthMaxZ(activeCamera: Nullable<Camera>): number;\r\n}\r\n\r\n/**\r\n * Base implementation IShadowLight\r\n * It groups all the common behaviour in order to reduce duplication and better follow the DRY pattern.\r\n */\r\nexport abstract class ShadowLight extends Light implements IShadowLight {\r\n protected abstract _setDefaultShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array<AbstractMesh>): void;\r\n\r\n protected _position: Vector3;\r\n protected _setPosition(value: Vector3) {\r\n this._position = value;\r\n }\r\n /**\r\n * Sets the position the shadow will be casted from. Also use as the light position for both\r\n * point and spot lights.\r\n */\r\n @serializeAsVector3()\r\n public get position(): Vector3 {\r\n return this._position;\r\n }\r\n /**\r\n * Sets the position the shadow will be casted from. Also use as the light position for both\r\n * point and spot lights.\r\n */\r\n public set position(value: Vector3) {\r\n this._setPosition(value);\r\n }\r\n\r\n protected _direction: Vector3;\r\n protected _setDirection(value: Vector3) {\r\n this._direction = value;\r\n }\r\n /**\r\n * In 2d mode (needCube being false), gets the direction used to cast the shadow.\r\n * Also use as the light direction on spot and directional lights.\r\n */\r\n @serializeAsVector3()\r\n public get direction(): Vector3 {\r\n return this._direction;\r\n }\r\n /**\r\n * In 2d mode (needCube being false), sets the direction used to cast the shadow.\r\n * Also use as the light direction on spot and directional lights.\r\n */\r\n public set direction(value: Vector3) {\r\n this._setDirection(value);\r\n }\r\n\r\n protected _shadowMinZ: number;\r\n /**\r\n * Gets the shadow projection clipping minimum z value.\r\n */\r\n @serialize()\r\n public get shadowMinZ(): number {\r\n return this._shadowMinZ;\r\n }\r\n /**\r\n * Sets the shadow projection clipping minimum z value.\r\n */\r\n public set shadowMinZ(value: number) {\r\n this._shadowMinZ = value;\r\n this.forceProjectionMatrixCompute();\r\n }\r\n\r\n protected _shadowMaxZ: number;\r\n /**\r\n * Sets the shadow projection clipping maximum z value.\r\n */\r\n @serialize()\r\n public get shadowMaxZ(): number {\r\n return this._shadowMaxZ;\r\n }\r\n /**\r\n * Gets the shadow projection clipping maximum z value.\r\n */\r\n public set shadowMaxZ(value: number) {\r\n this._shadowMaxZ = value;\r\n this.forceProjectionMatrixCompute();\r\n }\r\n\r\n /**\r\n * Callback defining a custom Projection Matrix Builder.\r\n * This can be used to override the default projection matrix computation.\r\n */\r\n public customProjectionMatrixBuilder: (viewMatrix: Matrix, renderList: Array<AbstractMesh>, result: Matrix) => void;\r\n\r\n /**\r\n * The transformed position. Position of the light in world space taking parenting in account. Needs to be computed by calling computeTransformedInformation.\r\n */\r\n public transformedPosition: Vector3;\r\n\r\n /**\r\n * The transformed direction. Direction of the light in world space taking parenting in account.\r\n */\r\n public transformedDirection: Vector3;\r\n\r\n private _needProjectionMatrixCompute: boolean = true;\r\n\r\n /**\r\n * Computes the transformed information (transformedPosition and transformedDirection in World space) of the current light\r\n * @returns true if the information has been computed, false if it does not need to (no parenting)\r\n */\r\n public computeTransformedInformation(): boolean {\r\n if (this.parent && this.parent.getWorldMatrix) {\r\n if (!this.transformedPosition) {\r\n this.transformedPosition = Vector3.Zero();\r\n }\r\n Vector3.TransformCoordinatesToRef(this.position, this.parent.getWorldMatrix(), this.transformedPosition);\r\n\r\n // In case the direction is present.\r\n if (this.direction) {\r\n if (!this.transformedDirection) {\r\n this.transformedDirection = Vector3.Zero();\r\n }\r\n Vector3.TransformNormalToRef(this.direction, this.parent.getWorldMatrix(), this.transformedDirection);\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Return the depth scale used for the shadow map.\r\n * @returns the depth scale.\r\n */\r\n public getDepthScale(): number {\r\n return 50.0;\r\n }\r\n\r\n /**\r\n * Get the direction to use to render the shadow map. In case of cube texture, the face index can be passed.\r\n * @param faceIndex The index of the face we are computed the direction to generate shadow\r\n * @returns The set direction in 2d mode otherwise the direction to the cubemap face if needCube() is true\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n public getShadowDirection(faceIndex?: number): Vector3 {\r\n return this.transformedDirection ? this.transformedDirection : this.direction;\r\n }\r\n\r\n /**\r\n * If computeTransformedInformation has been called, returns the ShadowLight absolute position in the world. Otherwise, returns the local position.\r\n * @returns the position vector in world space\r\n */\r\n public override getAbsolutePosition(): Vector3 {\r\n return this.transformedPosition ? this.transformedPosition : this.position;\r\n }\r\n\r\n /**\r\n * Sets the ShadowLight direction toward the passed target.\r\n * @param target The point to target in local space\r\n * @returns the updated ShadowLight direction\r\n */\r\n public setDirectionToTarget(target: Vector3): Vector3 {\r\n this.direction = Vector3.Normalize(target.subtract(this.position));\r\n return this.direction;\r\n }\r\n\r\n /**\r\n * Returns the light rotation in euler definition.\r\n * @returns the x y z rotation in local space.\r\n */\r\n public getRotation(): Vector3 {\r\n this.direction.normalize();\r\n const xaxis = Vector3.Cross(this.direction, Axis.Y);\r\n const yaxis = Vector3.Cross(xaxis, this.direction);\r\n return Vector3.RotationFromAxis(xaxis, yaxis, this.direction);\r\n }\r\n\r\n /**\r\n * Returns whether or not the shadow generation require a cube texture or a 2d texture.\r\n * @returns true if a cube texture needs to be use\r\n */\r\n public needCube(): boolean {\r\n return false;\r\n }\r\n\r\n /**\r\n * Detects if the projection matrix requires to be recomputed this frame.\r\n * @returns true if it requires to be recomputed otherwise, false.\r\n */\r\n public needProjectionMatrixCompute(): boolean {\r\n return this._needProjectionMatrixCompute;\r\n }\r\n\r\n /**\r\n * Forces the shadow generator to recompute the projection matrix even if position and direction did not changed.\r\n */\r\n public forceProjectionMatrixCompute(): void {\r\n this._needProjectionMatrixCompute = true;\r\n }\r\n\r\n /** @internal */\r\n public override _initCache() {\r\n super._initCache();\r\n\r\n this._cache.position = Vector3.Zero();\r\n }\r\n\r\n /** @internal */\r\n public override _isSynchronized(): boolean {\r\n if (!this._cache.position.equals(this.position)) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Computes the world matrix of the node\r\n * @param force defines if the cache version should be invalidated forcing the world matrix to be created from scratch\r\n * @returns the world matrix\r\n */\r\n public override computeWorldMatrix(force?: boolean): Matrix {\r\n if (!force && this.isSynchronized()) {\r\n this._currentRenderId = this.getScene().getRenderId();\r\n return this._worldMatrix;\r\n }\r\n\r\n this._updateCache();\r\n this._cache.position.copyFrom(this.position);\r\n\r\n if (!this._worldMatrix) {\r\n this._worldMatrix = Matrix.Identity();\r\n }\r\n\r\n Matrix.TranslationToRef(this.position.x, this.position.y, this.position.z, this._worldMatrix);\r\n\r\n if (this.parent && this.parent.getWorldMatrix) {\r\n this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._worldMatrix);\r\n\r\n this._markSyncedWithParent();\r\n }\r\n\r\n // Cache the determinant\r\n this._worldMatrixDeterminantIsDirty = true;\r\n\r\n return this._worldMatrix;\r\n }\r\n\r\n /**\r\n * Gets the minZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the min for\r\n * @returns the depth min z\r\n */\r\n public getDepthMinZ(activeCamera: Nullable<Camera>): number {\r\n return this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera?.minZ || Constants.ShadowMinZ;\r\n }\r\n\r\n /**\r\n * Gets the maxZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the max for\r\n * @returns the depth max z\r\n */\r\n public getDepthMaxZ(activeCamera: Nullable<Camera>): number {\r\n return this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera?.maxZ || Constants.ShadowMaxZ;\r\n }\r\n\r\n /**\r\n * Sets the shadow projection matrix in parameter to the generated projection matrix.\r\n * @param matrix The matrix to updated with the projection information\r\n * @param viewMatrix The transform matrix of the light\r\n * @param renderList The list of mesh to render in the map\r\n * @returns The current light\r\n */\r\n public setShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array<AbstractMesh>): IShadowLight {\r\n if (this.customProjectionMatrixBuilder) {\r\n this.customProjectionMatrixBuilder(viewMatrix, renderList, matrix);\r\n } else {\r\n this._setDefaultShadowProjectionMatrix(matrix, viewMatrix, renderList);\r\n }\r\n return this;\r\n }\r\n\r\n /** @internal */\r\n protected override _syncParentEnabledState() {\r\n super._syncParentEnabledState();\r\n if (!this.parent || !this.parent.getWorldMatrix) {\r\n (this.transformedPosition as any) = null;\r\n (this.transformedDirection as any) = null;\r\n }\r\n }\r\n\r\n protected _viewMatrix: Matrix = Matrix.Identity();\r\n protected _projectionMatrix: Matrix = Matrix.Identity();\r\n\r\n /**\r\n * Returns the view matrix.\r\n * @param faceIndex The index of the face for which we want to extract the view matrix. Only used for point light types.\r\n * @returns The view matrix. Can be null, if a view matrix cannot be defined for the type of light considered (as for a hemispherical light, for example).\r\n */\r\n public override getViewMatrix(faceIndex?: number): Nullable<Matrix> {\r\n const lightDirection = TmpVectors.Vector3[0];\r\n\r\n let lightPosition = this.position;\r\n if (this.computeTransformedInformation()) {\r\n lightPosition = this.transformedPosition;\r\n }\r\n\r\n Vector3.NormalizeToRef(this.getShadowDirection(faceIndex), lightDirection);\r\n if (Math.abs(Vector3.Dot(lightDirection, Vector3.Up())) === 1.0) {\r\n lightDirection.z = 0.0000000000001; // Required to avoid perfectly perpendicular light\r\n }\r\n\r\n const lightTarget = TmpVectors.Vector3[1];\r\n lightPosition.addToRef(lightDirection, lightTarget);\r\n\r\n Matrix.LookAtLHToRef(lightPosition, lightTarget, Vector3.Up(), this._viewMatrix);\r\n\r\n return this._viewMatrix;\r\n }\r\n\r\n /**\r\n * Returns the projection matrix.\r\n * Note that viewMatrix and renderList are optional and are only used by lights that calculate the projection matrix from a list of meshes (e.g. directional lights with automatic extents calculation).\r\n * @param viewMatrix The view transform matrix of the light (optional).\r\n * @param renderList The list of meshes to take into account when calculating the projection matrix (optional).\r\n * @returns The projection matrix. Can be null, if a projection matrix cannot be defined for the type of light considered (as for a hemispherical light, for example).\r\n */\r\n public override getProjectionMatrix(viewMatrix?: Matrix, renderList?: Array<AbstractMesh>): Nullable<Matrix> {\r\n this.setShadowProjectionMatrix(this._projectionMatrix, viewMatrix ?? this._viewMatrix, renderList ?? []);\r\n\r\n return this._projectionMatrix;\r\n }\r\n}\r\n"]}
@@ -187,13 +187,13 @@ export declare class SpotLight extends ShadowLight {
187
187
  * @param activeCamera The camera we are returning the min for
188
188
  * @returns the depth min z
189
189
  */
190
- getDepthMinZ(activeCamera: Camera): number;
190
+ getDepthMinZ(activeCamera: Nullable<Camera>): number;
191
191
  /**
192
192
  * Gets the maxZ used for shadow according to both the scene and the light.
193
193
  * @param activeCamera The camera we are returning the max for
194
194
  * @returns the depth max z
195
195
  */
196
- getDepthMaxZ(activeCamera: Camera): number;
196
+ getDepthMaxZ(activeCamera: Nullable<Camera>): number;
197
197
  /**
198
198
  * Prepares the list of defines specific to the light type.
199
199
  * @param defines the list of defines
@@ -6,6 +6,7 @@ import { Light } from "./light.js";
6
6
  import { ShadowLight } from "./shadowLight.js";
7
7
  import { Texture } from "../Materials/Textures/texture.js";
8
8
  import { RegisterClass } from "../Misc/typeStore.js";
9
+
9
10
  Node.AddNodeConstructor("Light_Type_2", (name, scene) => {
10
11
  return () => new SpotLight(name, Vector3.Zero(), Vector3.Zero(), 0, 0, scene);
11
12
  });
@@ -377,7 +378,7 @@ export class SpotLight extends ShadowLight {
377
378
  */
378
379
  getDepthMinZ(activeCamera) {
379
380
  const engine = this._scene.getEngine();
380
- const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;
381
+ const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : (activeCamera?.minZ ?? 0);
381
382
  return engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? minZ : this._scene.getEngine().isNDCHalfZRange ? 0 : minZ;
382
383
  }
383
384
  /**
@@ -387,7 +388,7 @@ export class SpotLight extends ShadowLight {
387
388
  */
388
389
  getDepthMaxZ(activeCamera) {
389
390
  const engine = this._scene.getEngine();
390
- const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;
391
+ const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : (activeCamera?.maxZ ?? 10000);
391
392
  return engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : maxZ;
392
393
  }
393
394
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"spotLight.js","sourceRoot":"","sources":["../../../../dev/core/src/Lights/spotLight.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGnE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAI/B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAGxD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,IAAI,CAAC,kBAAkB,CAAC,cAAc,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;IACpD,OAAO,GAAG,EAAE,CAAC,IAAI,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;AAClF,CAAC,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,OAAO,SAAU,SAAQ,WAAW;IAuBtC;;;OAGG;IACH,IAAW,iBAAiB;QACxB,OAAO,IAAI,CAAC,kBAAkB,CAAC;IACnC,CAAC;IAED,IAAW,iBAAiB,CAAC,KAA4B;QACrD,IAAI,IAAI,CAAC,kBAAkB,KAAK,KAAK,EAAE,CAAC;YACpC,OAAO;QACX,CAAC;QAED,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAC;QAEhC,IAAI,IAAI,CAAC,kBAAkB,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;YA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CAAC,WAAW,GAAG,UAAU,CAAC,GAAG,IAAI,CAAC;QACzC,OAAO,CAAC,uBAAuB,GAAG,UAAU,CAAC,GAAG,IAAI,CAAC,iBAAiB,IAAI,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;QAC1H,OAAO,CAAC,iBAAiB,GAAG,UAAU,CAAC,GAAG,IAAI,CAAC,kBAAkB,IAAI,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1H,CAAC;CACJ;AAlbG;IADC,SAAS,EAAE;sCAGX;AAkBD;IADC,SAAS,EAAE;2CAGX;AAgBD;IADC,SAAS,EAAE;iDAGX;AAaM;IADN,SAAS,EAAE;2CACY;AAexB;IADC,SAAS,EAAE;2DAGX;AAcD;IADC,SAAS,EAAE;0DAGX;AAcD;IADC,SAAS,EAAE;6DAGX;AAUO;IADP,kBAAkB,CAAC,uBAAuB,CAAC;qDACM;AAoUtD,sBAAsB;AACtB,aAAa,CAAC,mBAAmB,EAAE,SAAS,CAAC,CAAC","sourcesContent":["import { serialize, serializeAsTexture } from \"../Misc/decorators\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Matrix, Vector3 } from \"../Maths/math.vector\";\r\nimport { Node } from \"../node\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Light } from \"./light\";\r\nimport { ShadowLight } from \"./shadowLight\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport type { ProceduralTexture } from \"../Materials/Textures/Procedurals/proceduralTexture\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\n\r\nNode.AddNodeConstructor(\"Light_Type_2\", (name, scene) => {\r\n return () => new SpotLight(name, Vector3.Zero(), Vector3.Zero(), 0, 0, scene);\r\n});\r\n\r\n/**\r\n * A spot light is defined by a position, a direction, an angle, and an exponent.\r\n * These values define a cone of light starting from the position, emitting toward the direction.\r\n * The angle, in radians, defines the size (field of illumination) of the spotlight's conical beam,\r\n * and the exponent defines the speed of the decay of the light with distance (reach).\r\n * Documentation: https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\r\n */\r\nexport class SpotLight extends ShadowLight {\r\n /*\r\n upVector , rightVector and direction will form the coordinate system for this spot light.\r\n These three vectors will be used as projection matrix when doing texture projection.\r\n\r\n Also we have the following rules always holds:\r\n direction cross up = right\r\n right cross direction = up\r\n up cross right = forward\r\n\r\n light_near and light_far will control the range of the texture projection. If a plane is\r\n out of the range in spot light space, there is no texture projection.\r\n */\r\n\r\n private _angle: number;\r\n private _innerAngle: number = 0;\r\n private _cosHalfAngle: number;\r\n\r\n private _lightAngleScale: number;\r\n private _lightAngleOffset: number;\r\n\r\n private _iesProfileTexture: Nullable<BaseTexture> = null;\r\n\r\n /**\r\n * Gets or sets the IES profile texture used to create the spotlight\r\n * #UIAXAU#1\r\n */\r\n public get iesProfileTexture(): Nullable<BaseTexture> {\r\n return this._iesProfileTexture;\r\n }\r\n\r\n public set iesProfileTexture(value: Nullable<BaseTexture>) {\r\n if (this._iesProfileTexture === value) {\r\n return;\r\n }\r\n\r\n this._iesProfileTexture = value;\r\n\r\n if (this._iesProfileTexture && SpotLight._IsTexture(this._iesProfileTexture)) {\r\n this._iesProfileTexture.onLoadObservable.addOnce(() => {\r\n this._markMeshesAsLightDirty();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Gets the cone angle of the spot light in Radians.\r\n */\r\n @serialize()\r\n public get angle(): number {\r\n return this._angle;\r\n }\r\n /**\r\n * Sets the cone angle of the spot light in Radians.\r\n */\r\n public set angle(value: number) {\r\n this._angle = value;\r\n this._cosHalfAngle = Math.cos(value * 0.5);\r\n this._projectionTextureProjectionLightDirty = true;\r\n this.forceProjectionMatrixCompute();\r\n this._computeAngleValues();\r\n }\r\n\r\n /**\r\n * Only used in gltf falloff mode, this defines the angle where\r\n * the directional falloff will start before cutting at angle which could be seen\r\n * as outer angle.\r\n */\r\n @serialize()\r\n public get innerAngle(): number {\r\n return this._innerAngle;\r\n }\r\n /**\r\n * Only used in gltf falloff mode, this defines the angle where\r\n * the directional falloff will start before cutting at angle which could be seen\r\n * as outer angle.\r\n */\r\n public set innerAngle(value: number) {\r\n this._innerAngle = value;\r\n this._computeAngleValues();\r\n }\r\n\r\n private _shadowAngleScale: number;\r\n /**\r\n * Allows scaling the angle of the light for shadow generation only.\r\n */\r\n @serialize()\r\n public get shadowAngleScale(): number {\r\n return this._shadowAngleScale;\r\n }\r\n /**\r\n * Allows scaling the angle of the light for shadow generation only.\r\n */\r\n public set shadowAngleScale(value: number) {\r\n this._shadowAngleScale = value;\r\n this.forceProjectionMatrixCompute();\r\n }\r\n\r\n /**\r\n * The light decay speed with the distance from the emission spot.\r\n */\r\n @serialize()\r\n public exponent: number;\r\n\r\n private _projectionTextureMatrix = Matrix.Zero();\r\n /**\r\n * Allows reading the projection texture\r\n */\r\n public get projectionTextureMatrix(): Matrix {\r\n return this._projectionTextureMatrix;\r\n }\r\n\r\n protected _projectionTextureLightNear: number = 1e-6;\r\n /**\r\n * Gets the near clip of the Spotlight for texture projection.\r\n */\r\n @serialize()\r\n public get projectionTextureLightNear(): number {\r\n return this._projectionTextureLightNear;\r\n }\r\n /**\r\n * Sets the near clip of the Spotlight for texture projection.\r\n */\r\n public set projectionTextureLightNear(value: number) {\r\n this._projectionTextureLightNear = value;\r\n this._projectionTextureProjectionLightDirty = true;\r\n }\r\n\r\n protected _projectionTextureLightFar: number = 1000.0;\r\n /**\r\n * Gets the far clip of the Spotlight for texture projection.\r\n */\r\n @serialize()\r\n public get projectionTextureLightFar(): number {\r\n return this._projectionTextureLightFar;\r\n }\r\n /**\r\n * Sets the far clip of the Spotlight for texture projection.\r\n */\r\n public set projectionTextureLightFar(value: number) {\r\n this._projectionTextureLightFar = value;\r\n this._projectionTextureProjectionLightDirty = true;\r\n }\r\n\r\n protected _projectionTextureUpDirection: Vector3 = Vector3.Up();\r\n /**\r\n * Gets the Up vector of the Spotlight for texture projection.\r\n */\r\n @serialize()\r\n public get projectionTextureUpDirection(): Vector3 {\r\n return this._projectionTextureUpDirection;\r\n }\r\n /**\r\n * Sets the Up vector of the Spotlight for texture projection.\r\n */\r\n public set projectionTextureUpDirection(value: Vector3) {\r\n this._projectionTextureUpDirection = value;\r\n this._projectionTextureProjectionLightDirty = true;\r\n }\r\n\r\n @serializeAsTexture(\"projectedLightTexture\")\r\n private _projectionTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Gets the projection texture of the light.\r\n */\r\n public get projectionTexture(): Nullable<BaseTexture> {\r\n return this._projectionTexture;\r\n }\r\n /**\r\n * Sets the projection texture of the light.\r\n */\r\n public set projectionTexture(value: Nullable<BaseTexture>) {\r\n if (this._projectionTexture === value) {\r\n return;\r\n }\r\n this._projectionTexture = value;\r\n this._projectionTextureDirty = true;\r\n if (this._projectionTexture && !this._projectionTexture.isReady()) {\r\n if (SpotLight._IsProceduralTexture(this._projectionTexture)) {\r\n this._projectionTexture.getEffect().executeWhenCompiled(() => {\r\n this._markMeshesAsLightDirty();\r\n });\r\n } else if (SpotLight._IsTexture(this._projectionTexture)) {\r\n this._projectionTexture.onLoadObservable.addOnce(() => {\r\n this._markMeshesAsLightDirty();\r\n });\r\n }\r\n }\r\n }\r\n\r\n private static _IsProceduralTexture(texture: BaseTexture): texture is ProceduralTexture {\r\n return (texture as ProceduralTexture).onGeneratedObservable !== undefined;\r\n }\r\n\r\n private static _IsTexture(texture: BaseTexture): texture is Texture {\r\n return (texture as Texture).onLoadObservable !== undefined;\r\n }\r\n\r\n private _projectionTextureViewLightDirty = true;\r\n private _projectionTextureProjectionLightDirty = true;\r\n private _projectionTextureDirty = true;\r\n private _projectionTextureViewTargetVector = Vector3.Zero();\r\n private _projectionTextureViewLightMatrix = Matrix.Zero();\r\n\r\n private _projectionTextureProjectionLightMatrix = Matrix.Zero();\r\n /**\r\n * Gets or sets the light projection matrix as used by the projection texture\r\n */\r\n public get projectionTextureProjectionLightMatrix(): Matrix {\r\n return this._projectionTextureProjectionLightMatrix;\r\n }\r\n\r\n public set projectionTextureProjectionLightMatrix(projection: Matrix) {\r\n this._projectionTextureProjectionLightMatrix = projection;\r\n this._projectionTextureProjectionLightDirty = false;\r\n this._projectionTextureDirty = true;\r\n }\r\n\r\n private _projectionTextureScalingMatrix = Matrix.FromValues(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);\r\n\r\n /**\r\n * Creates a SpotLight object in the scene. A spot light is a simply light oriented cone.\r\n * It can cast shadows.\r\n * Documentation : https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\r\n * @param name The light friendly name\r\n * @param position The position of the spot light in the scene\r\n * @param direction The direction of the light in the scene\r\n * @param angle The cone angle of the light in Radians\r\n * @param exponent The light decay speed with the distance from the emission spot\r\n * @param scene The scene the lights belongs to\r\n */\r\n constructor(name: string, position: Vector3, direction: Vector3, angle: number, exponent: number, scene?: Scene) {\r\n super(name, scene);\r\n\r\n this.position = position;\r\n this.direction = direction;\r\n this.angle = angle;\r\n this.exponent = exponent;\r\n }\r\n\r\n /**\r\n * Returns the string \"SpotLight\".\r\n * @returns the class name\r\n */\r\n public override getClassName(): string {\r\n return \"SpotLight\";\r\n }\r\n\r\n /**\r\n * Returns the integer 2.\r\n * @returns The light Type id as a constant defines in Light.LIGHTTYPEID_x\r\n */\r\n public override getTypeID(): number {\r\n return Light.LIGHTTYPEID_SPOTLIGHT;\r\n }\r\n\r\n /**\r\n * Overrides the direction setter to recompute the projection texture view light Matrix.\r\n * @param value\r\n */\r\n protected override _setDirection(value: Vector3) {\r\n super._setDirection(value);\r\n this._projectionTextureViewLightDirty = true;\r\n }\r\n\r\n /**\r\n * Overrides the position setter to recompute the projection texture view light Matrix.\r\n * @param value\r\n */\r\n protected override _setPosition(value: Vector3) {\r\n super._setPosition(value);\r\n this._projectionTextureViewLightDirty = true;\r\n }\r\n\r\n /**\r\n * Sets the passed matrix \"matrix\" as perspective projection matrix for the shadows and the passed view matrix with the fov equal to the SpotLight angle and and aspect ratio of 1.0.\r\n * Returns the SpotLight.\r\n * @param matrix\r\n * @param viewMatrix\r\n * @param renderList\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n protected _setDefaultShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array<AbstractMesh>): void {\r\n const activeCamera = this.getScene().activeCamera;\r\n\r\n if (!activeCamera) {\r\n return;\r\n }\r\n\r\n this._shadowAngleScale = this._shadowAngleScale || 1;\r\n const angle = this._shadowAngleScale * this._angle;\r\n\r\n const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;\r\n const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;\r\n\r\n const useReverseDepthBuffer = this.getScene().getEngine().useReverseDepthBuffer;\r\n\r\n Matrix.PerspectiveFovLHToRef(\r\n angle,\r\n 1.0,\r\n useReverseDepthBuffer ? maxZ : minZ,\r\n useReverseDepthBuffer ? minZ : maxZ,\r\n matrix,\r\n true,\r\n this._scene.getEngine().isNDCHalfZRange,\r\n undefined,\r\n useReverseDepthBuffer\r\n );\r\n }\r\n\r\n protected _computeProjectionTextureViewLightMatrix(): void {\r\n this._projectionTextureViewLightDirty = false;\r\n this._projectionTextureDirty = true;\r\n\r\n this.getAbsolutePosition().addToRef(this.getShadowDirection(), this._projectionTextureViewTargetVector);\r\n Matrix.LookAtLHToRef(this.getAbsolutePosition(), this._projectionTextureViewTargetVector, this._projectionTextureUpDirection, this._projectionTextureViewLightMatrix);\r\n }\r\n\r\n protected _computeProjectionTextureProjectionLightMatrix(): void {\r\n this._projectionTextureProjectionLightDirty = false;\r\n this._projectionTextureDirty = true;\r\n\r\n const lightFar = this.projectionTextureLightFar;\r\n const lightNear = this.projectionTextureLightNear;\r\n\r\n const P = lightFar / (lightFar - lightNear);\r\n const Q = -P * lightNear;\r\n const S = 1.0 / Math.tan(this._angle / 2.0);\r\n const A = 1.0;\r\n\r\n Matrix.FromValuesToRef(S / A, 0.0, 0.0, 0.0, 0.0, S, 0.0, 0.0, 0.0, 0.0, P, 1.0, 0.0, 0.0, Q, 0.0, this._projectionTextureProjectionLightMatrix);\r\n }\r\n\r\n /**\r\n * Main function for light texture projection matrix computing.\r\n */\r\n protected _computeProjectionTextureMatrix(): void {\r\n this._projectionTextureDirty = false;\r\n\r\n this._projectionTextureViewLightMatrix.multiplyToRef(this._projectionTextureProjectionLightMatrix, this._projectionTextureMatrix);\r\n if (this._projectionTexture instanceof Texture) {\r\n const u = this._projectionTexture.uScale / 2.0;\r\n const v = this._projectionTexture.vScale / 2.0;\r\n Matrix.FromValuesToRef(u, 0.0, 0.0, 0.0, 0.0, v, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0, this._projectionTextureScalingMatrix);\r\n }\r\n this._projectionTextureMatrix.multiplyToRef(this._projectionTextureScalingMatrix, this._projectionTextureMatrix);\r\n }\r\n\r\n protected _buildUniformLayout(): void {\r\n this._uniformBuffer.addUniform(\"vLightData\", 4);\r\n this._uniformBuffer.addUniform(\"vLightDiffuse\", 4);\r\n this._uniformBuffer.addUniform(\"vLightSpecular\", 4);\r\n this._uniformBuffer.addUniform(\"vLightDirection\", 3);\r\n this._uniformBuffer.addUniform(\"vLightFalloff\", 4);\r\n this._uniformBuffer.addUniform(\"shadowsInfo\", 3);\r\n this._uniformBuffer.addUniform(\"depthValues\", 2);\r\n this._uniformBuffer.create();\r\n }\r\n\r\n private _computeAngleValues(): void {\r\n this._lightAngleScale = 1.0 / Math.max(0.001, Math.cos(this._innerAngle * 0.5) - this._cosHalfAngle);\r\n this._lightAngleOffset = -this._cosHalfAngle * this._lightAngleScale;\r\n }\r\n\r\n /**\r\n * Sets the passed Effect \"effect\" with the Light textures.\r\n * @param effect The effect to update\r\n * @param lightIndex The index of the light in the effect to update\r\n * @returns The light\r\n */\r\n public override transferTexturesToEffect(effect: Effect, lightIndex: string): Light {\r\n if (this.projectionTexture && this.projectionTexture.isReady()) {\r\n if (this._projectionTextureViewLightDirty) {\r\n this._computeProjectionTextureViewLightMatrix();\r\n }\r\n if (this._projectionTextureProjectionLightDirty) {\r\n this._computeProjectionTextureProjectionLightMatrix();\r\n }\r\n if (this._projectionTextureDirty) {\r\n this._computeProjectionTextureMatrix();\r\n }\r\n effect.setMatrix(\"textureProjectionMatrix\" + lightIndex, this._projectionTextureMatrix);\r\n effect.setTexture(\"projectionLightTexture\" + lightIndex, this.projectionTexture);\r\n }\r\n\r\n if (this._iesProfileTexture && this._iesProfileTexture.isReady()) {\r\n effect.setTexture(\"iesLightTexture\" + lightIndex, this._iesProfileTexture);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the passed Effect object with the SpotLight transformed position (or position if not parented) and normalized direction.\r\n * @param effect The effect to update\r\n * @param lightIndex The index of the light in the effect to update\r\n * @returns The spot light\r\n */\r\n public transferToEffect(effect: Effect, lightIndex: string): SpotLight {\r\n let normalizeDirection;\r\n\r\n if (this.computeTransformedInformation()) {\r\n this._uniformBuffer.updateFloat4(\"vLightData\", this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, this.exponent, lightIndex);\r\n\r\n normalizeDirection = Vector3.Normalize(this.transformedDirection);\r\n } else {\r\n this._uniformBuffer.updateFloat4(\"vLightData\", this.position.x, this.position.y, this.position.z, this.exponent, lightIndex);\r\n\r\n normalizeDirection = Vector3.Normalize(this.direction);\r\n }\r\n\r\n this._uniformBuffer.updateFloat4(\"vLightDirection\", normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, this._cosHalfAngle, lightIndex);\r\n\r\n this._uniformBuffer.updateFloat4(\"vLightFalloff\", this.range, this._inverseSquaredRange, this._lightAngleScale, this._lightAngleOffset, lightIndex);\r\n return this;\r\n }\r\n\r\n public transferToNodeMaterialEffect(effect: Effect, lightDataUniformName: string) {\r\n let normalizeDirection;\r\n\r\n if (this.computeTransformedInformation()) {\r\n normalizeDirection = Vector3.Normalize(this.transformedDirection);\r\n } else {\r\n normalizeDirection = Vector3.Normalize(this.direction);\r\n }\r\n\r\n if (this.getScene().useRightHandedSystem) {\r\n effect.setFloat3(lightDataUniformName, -normalizeDirection.x, -normalizeDirection.y, -normalizeDirection.z);\r\n } else {\r\n effect.setFloat3(lightDataUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z);\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Disposes the light and the associated resources.\r\n */\r\n public override dispose(): void {\r\n super.dispose();\r\n if (this._projectionTexture) {\r\n this._projectionTexture.dispose();\r\n }\r\n if (this._iesProfileTexture) {\r\n this._iesProfileTexture.dispose();\r\n this._iesProfileTexture = null;\r\n }\r\n }\r\n\r\n /**\r\n * Gets the minZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the min for\r\n * @returns the depth min z\r\n */\r\n public override getDepthMinZ(activeCamera: Camera): number {\r\n const engine = this._scene.getEngine();\r\n const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;\r\n\r\n return engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? minZ : this._scene.getEngine().isNDCHalfZRange ? 0 : minZ;\r\n }\r\n\r\n /**\r\n * Gets the maxZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the max for\r\n * @returns the depth max z\r\n */\r\n public override getDepthMaxZ(activeCamera: Camera): number {\r\n const engine = this._scene.getEngine();\r\n const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;\r\n\r\n return engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : maxZ;\r\n }\r\n\r\n /**\r\n * Prepares the list of defines specific to the light type.\r\n * @param defines the list of defines\r\n * @param lightIndex defines the index of the light for the effect\r\n */\r\n public prepareLightSpecificDefines(defines: any, lightIndex: number): void {\r\n defines[\"SPOTLIGHT\" + lightIndex] = true;\r\n defines[\"PROJECTEDLIGHTTEXTURE\" + lightIndex] = this.projectionTexture && this.projectionTexture.isReady() ? true : false;\r\n defines[\"IESLIGHTTEXTURE\" + lightIndex] = this._iesProfileTexture && this._iesProfileTexture.isReady() ? true : false;\r\n }\r\n}\r\n\r\n// Register Class Name\r\nRegisterClass(\"BABYLON.SpotLight\", SpotLight);\r\n"]}
1
+ {"version":3,"file":"spotLight.js","sourceRoot":"","sources":["../../../../dev/core/src/Lights/spotLight.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGnE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAI/B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAGxD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,gCAA+B;AAEnD,IAAI,CAAC,kBAAkB,CAAC,cAAc,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;IACpD,OAAO,GAAG,EAAE,CAAC,IAAI,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;AAClF,CAAC,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,OAAO,SAAU,SAAQ,WAAW;IAuBtC;;;OAGG;IACH,IAAW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MAAM,CAAC,SAAS,EAAE,CAAC;QACvC,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,IAAI,IAAI,SAAS,CAAC,UAAU,CAAC,CAAC;QAE5G,OAAO,MAAM,CAAC,qBAAqB,IAAI,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7E,CAAC;IAED;;;;OAIG;IACI,2BAA2B,CAAC,OAAY,EAAE,UAAkB;QAC/D,OAAO,CAAC,WAAW,GAAG,UAAU,CAAC,GAAG,IAAI,CAAC;QACzC,OAAO,CAAC,uBAAuB,GAAG,UAAU,CAAC,GAAG,IAAI,CAAC,iBAAiB,IAAI,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;QAC1H,OAAO,CAAC,iBAAiB,GAAG,UAAU,CAAC,GAAG,IAAI,CAAC,kBAAkB,IAAI,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1H,CAAC;CACJ;AAlbG;IADC,SAAS,EAAE;sCAGX;AAkBD;IADC,SAAS,EAAE;2CAGX;AAgBD;IADC,SAAS,EAAE;iDAGX;AAaM;IADN,SAAS,EAAE;2CACY;AAexB;IADC,SAAS,EAAE;2DAGX;AAcD;IADC,SAAS,EAAE;0DAGX;AAcD;IADC,SAAS,EAAE;6DAGX;AAUO;IADP,kBAAkB,CAAC,uBAAuB,CAAC;qDACM;AAoUtD,sBAAsB;AACtB,aAAa,CAAC,mBAAmB,EAAE,SAAS,CAAC,CAAC","sourcesContent":["import { serialize, serializeAsTexture } from \"../Misc/decorators\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Matrix, Vector3 } from \"../Maths/math.vector\";\r\nimport { Node } from \"../node\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { Effect } from \"../Materials/effect\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Light } from \"./light\";\r\nimport { ShadowLight } from \"./shadowLight\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport type { ProceduralTexture } from \"../Materials/Textures/Procedurals/proceduralTexture\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\nimport { Constants } from \"core/Engines/constants\";\r\n\r\nNode.AddNodeConstructor(\"Light_Type_2\", (name, scene) => {\r\n return () => new SpotLight(name, Vector3.Zero(), Vector3.Zero(), 0, 0, scene);\r\n});\r\n\r\n/**\r\n * A spot light is defined by a position, a direction, an angle, and an exponent.\r\n * These values define a cone of light starting from the position, emitting toward the direction.\r\n * The angle, in radians, defines the size (field of illumination) of the spotlight's conical beam,\r\n * and the exponent defines the speed of the decay of the light with distance (reach).\r\n * Documentation: https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\r\n */\r\nexport class SpotLight extends ShadowLight {\r\n /*\r\n upVector , rightVector and direction will form the coordinate system for this spot light.\r\n These three vectors will be used as projection matrix when doing texture projection.\r\n\r\n Also we have the following rules always holds:\r\n direction cross up = right\r\n right cross direction = up\r\n up cross right = forward\r\n\r\n light_near and light_far will control the range of the texture projection. If a plane is\r\n out of the range in spot light space, there is no texture projection.\r\n */\r\n\r\n private _angle: number;\r\n private _innerAngle: number = 0;\r\n private _cosHalfAngle: number;\r\n\r\n private _lightAngleScale: number;\r\n private _lightAngleOffset: number;\r\n\r\n private _iesProfileTexture: Nullable<BaseTexture> = null;\r\n\r\n /**\r\n * Gets or sets the IES profile texture used to create the spotlight\r\n * #UIAXAU#1\r\n */\r\n public get iesProfileTexture(): Nullable<BaseTexture> {\r\n return this._iesProfileTexture;\r\n }\r\n\r\n public set iesProfileTexture(value: Nullable<BaseTexture>) {\r\n if (this._iesProfileTexture === value) {\r\n return;\r\n }\r\n\r\n this._iesProfileTexture = value;\r\n\r\n if (this._iesProfileTexture && SpotLight._IsTexture(this._iesProfileTexture)) {\r\n this._iesProfileTexture.onLoadObservable.addOnce(() => {\r\n this._markMeshesAsLightDirty();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Gets the cone angle of the spot light in Radians.\r\n */\r\n @serialize()\r\n public get angle(): number {\r\n return this._angle;\r\n }\r\n /**\r\n * Sets the cone angle of the spot light in Radians.\r\n */\r\n public set angle(value: number) {\r\n this._angle = value;\r\n this._cosHalfAngle = Math.cos(value * 0.5);\r\n this._projectionTextureProjectionLightDirty = true;\r\n this.forceProjectionMatrixCompute();\r\n this._computeAngleValues();\r\n }\r\n\r\n /**\r\n * Only used in gltf falloff mode, this defines the angle where\r\n * the directional falloff will start before cutting at angle which could be seen\r\n * as outer angle.\r\n */\r\n @serialize()\r\n public get innerAngle(): number {\r\n return this._innerAngle;\r\n }\r\n /**\r\n * Only used in gltf falloff mode, this defines the angle where\r\n * the directional falloff will start before cutting at angle which could be seen\r\n * as outer angle.\r\n */\r\n public set innerAngle(value: number) {\r\n this._innerAngle = value;\r\n this._computeAngleValues();\r\n }\r\n\r\n private _shadowAngleScale: number;\r\n /**\r\n * Allows scaling the angle of the light for shadow generation only.\r\n */\r\n @serialize()\r\n public get shadowAngleScale(): number {\r\n return this._shadowAngleScale;\r\n }\r\n /**\r\n * Allows scaling the angle of the light for shadow generation only.\r\n */\r\n public set shadowAngleScale(value: number) {\r\n this._shadowAngleScale = value;\r\n this.forceProjectionMatrixCompute();\r\n }\r\n\r\n /**\r\n * The light decay speed with the distance from the emission spot.\r\n */\r\n @serialize()\r\n public exponent: number;\r\n\r\n private _projectionTextureMatrix = Matrix.Zero();\r\n /**\r\n * Allows reading the projection texture\r\n */\r\n public get projectionTextureMatrix(): Matrix {\r\n return this._projectionTextureMatrix;\r\n }\r\n\r\n protected _projectionTextureLightNear: number = 1e-6;\r\n /**\r\n * Gets the near clip of the Spotlight for texture projection.\r\n */\r\n @serialize()\r\n public get projectionTextureLightNear(): number {\r\n return this._projectionTextureLightNear;\r\n }\r\n /**\r\n * Sets the near clip of the Spotlight for texture projection.\r\n */\r\n public set projectionTextureLightNear(value: number) {\r\n this._projectionTextureLightNear = value;\r\n this._projectionTextureProjectionLightDirty = true;\r\n }\r\n\r\n protected _projectionTextureLightFar: number = 1000.0;\r\n /**\r\n * Gets the far clip of the Spotlight for texture projection.\r\n */\r\n @serialize()\r\n public get projectionTextureLightFar(): number {\r\n return this._projectionTextureLightFar;\r\n }\r\n /**\r\n * Sets the far clip of the Spotlight for texture projection.\r\n */\r\n public set projectionTextureLightFar(value: number) {\r\n this._projectionTextureLightFar = value;\r\n this._projectionTextureProjectionLightDirty = true;\r\n }\r\n\r\n protected _projectionTextureUpDirection: Vector3 = Vector3.Up();\r\n /**\r\n * Gets the Up vector of the Spotlight for texture projection.\r\n */\r\n @serialize()\r\n public get projectionTextureUpDirection(): Vector3 {\r\n return this._projectionTextureUpDirection;\r\n }\r\n /**\r\n * Sets the Up vector of the Spotlight for texture projection.\r\n */\r\n public set projectionTextureUpDirection(value: Vector3) {\r\n this._projectionTextureUpDirection = value;\r\n this._projectionTextureProjectionLightDirty = true;\r\n }\r\n\r\n @serializeAsTexture(\"projectedLightTexture\")\r\n private _projectionTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Gets the projection texture of the light.\r\n */\r\n public get projectionTexture(): Nullable<BaseTexture> {\r\n return this._projectionTexture;\r\n }\r\n /**\r\n * Sets the projection texture of the light.\r\n */\r\n public set projectionTexture(value: Nullable<BaseTexture>) {\r\n if (this._projectionTexture === value) {\r\n return;\r\n }\r\n this._projectionTexture = value;\r\n this._projectionTextureDirty = true;\r\n if (this._projectionTexture && !this._projectionTexture.isReady()) {\r\n if (SpotLight._IsProceduralTexture(this._projectionTexture)) {\r\n this._projectionTexture.getEffect().executeWhenCompiled(() => {\r\n this._markMeshesAsLightDirty();\r\n });\r\n } else if (SpotLight._IsTexture(this._projectionTexture)) {\r\n this._projectionTexture.onLoadObservable.addOnce(() => {\r\n this._markMeshesAsLightDirty();\r\n });\r\n }\r\n }\r\n }\r\n\r\n private static _IsProceduralTexture(texture: BaseTexture): texture is ProceduralTexture {\r\n return (texture as ProceduralTexture).onGeneratedObservable !== undefined;\r\n }\r\n\r\n private static _IsTexture(texture: BaseTexture): texture is Texture {\r\n return (texture as Texture).onLoadObservable !== undefined;\r\n }\r\n\r\n private _projectionTextureViewLightDirty = true;\r\n private _projectionTextureProjectionLightDirty = true;\r\n private _projectionTextureDirty = true;\r\n private _projectionTextureViewTargetVector = Vector3.Zero();\r\n private _projectionTextureViewLightMatrix = Matrix.Zero();\r\n\r\n private _projectionTextureProjectionLightMatrix = Matrix.Zero();\r\n /**\r\n * Gets or sets the light projection matrix as used by the projection texture\r\n */\r\n public get projectionTextureProjectionLightMatrix(): Matrix {\r\n return this._projectionTextureProjectionLightMatrix;\r\n }\r\n\r\n public set projectionTextureProjectionLightMatrix(projection: Matrix) {\r\n this._projectionTextureProjectionLightMatrix = projection;\r\n this._projectionTextureProjectionLightDirty = false;\r\n this._projectionTextureDirty = true;\r\n }\r\n\r\n private _projectionTextureScalingMatrix = Matrix.FromValues(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);\r\n\r\n /**\r\n * Creates a SpotLight object in the scene. A spot light is a simply light oriented cone.\r\n * It can cast shadows.\r\n * Documentation : https://doc.babylonjs.com/features/featuresDeepDive/lights/lights_introduction\r\n * @param name The light friendly name\r\n * @param position The position of the spot light in the scene\r\n * @param direction The direction of the light in the scene\r\n * @param angle The cone angle of the light in Radians\r\n * @param exponent The light decay speed with the distance from the emission spot\r\n * @param scene The scene the lights belongs to\r\n */\r\n constructor(name: string, position: Vector3, direction: Vector3, angle: number, exponent: number, scene?: Scene) {\r\n super(name, scene);\r\n\r\n this.position = position;\r\n this.direction = direction;\r\n this.angle = angle;\r\n this.exponent = exponent;\r\n }\r\n\r\n /**\r\n * Returns the string \"SpotLight\".\r\n * @returns the class name\r\n */\r\n public override getClassName(): string {\r\n return \"SpotLight\";\r\n }\r\n\r\n /**\r\n * Returns the integer 2.\r\n * @returns The light Type id as a constant defines in Light.LIGHTTYPEID_x\r\n */\r\n public override getTypeID(): number {\r\n return Light.LIGHTTYPEID_SPOTLIGHT;\r\n }\r\n\r\n /**\r\n * Overrides the direction setter to recompute the projection texture view light Matrix.\r\n * @param value\r\n */\r\n protected override _setDirection(value: Vector3) {\r\n super._setDirection(value);\r\n this._projectionTextureViewLightDirty = true;\r\n }\r\n\r\n /**\r\n * Overrides the position setter to recompute the projection texture view light Matrix.\r\n * @param value\r\n */\r\n protected override _setPosition(value: Vector3) {\r\n super._setPosition(value);\r\n this._projectionTextureViewLightDirty = true;\r\n }\r\n\r\n /**\r\n * Sets the passed matrix \"matrix\" as perspective projection matrix for the shadows and the passed view matrix with the fov equal to the SpotLight angle and and aspect ratio of 1.0.\r\n * Returns the SpotLight.\r\n * @param matrix\r\n * @param viewMatrix\r\n * @param renderList\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n protected _setDefaultShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array<AbstractMesh>): void {\r\n const activeCamera = this.getScene().activeCamera;\r\n\r\n if (!activeCamera) {\r\n return;\r\n }\r\n\r\n this._shadowAngleScale = this._shadowAngleScale || 1;\r\n const angle = this._shadowAngleScale * this._angle;\r\n\r\n const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : activeCamera.minZ;\r\n const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : activeCamera.maxZ;\r\n\r\n const useReverseDepthBuffer = this.getScene().getEngine().useReverseDepthBuffer;\r\n\r\n Matrix.PerspectiveFovLHToRef(\r\n angle,\r\n 1.0,\r\n useReverseDepthBuffer ? maxZ : minZ,\r\n useReverseDepthBuffer ? minZ : maxZ,\r\n matrix,\r\n true,\r\n this._scene.getEngine().isNDCHalfZRange,\r\n undefined,\r\n useReverseDepthBuffer\r\n );\r\n }\r\n\r\n protected _computeProjectionTextureViewLightMatrix(): void {\r\n this._projectionTextureViewLightDirty = false;\r\n this._projectionTextureDirty = true;\r\n\r\n this.getAbsolutePosition().addToRef(this.getShadowDirection(), this._projectionTextureViewTargetVector);\r\n Matrix.LookAtLHToRef(this.getAbsolutePosition(), this._projectionTextureViewTargetVector, this._projectionTextureUpDirection, this._projectionTextureViewLightMatrix);\r\n }\r\n\r\n protected _computeProjectionTextureProjectionLightMatrix(): void {\r\n this._projectionTextureProjectionLightDirty = false;\r\n this._projectionTextureDirty = true;\r\n\r\n const lightFar = this.projectionTextureLightFar;\r\n const lightNear = this.projectionTextureLightNear;\r\n\r\n const P = lightFar / (lightFar - lightNear);\r\n const Q = -P * lightNear;\r\n const S = 1.0 / Math.tan(this._angle / 2.0);\r\n const A = 1.0;\r\n\r\n Matrix.FromValuesToRef(S / A, 0.0, 0.0, 0.0, 0.0, S, 0.0, 0.0, 0.0, 0.0, P, 1.0, 0.0, 0.0, Q, 0.0, this._projectionTextureProjectionLightMatrix);\r\n }\r\n\r\n /**\r\n * Main function for light texture projection matrix computing.\r\n */\r\n protected _computeProjectionTextureMatrix(): void {\r\n this._projectionTextureDirty = false;\r\n\r\n this._projectionTextureViewLightMatrix.multiplyToRef(this._projectionTextureProjectionLightMatrix, this._projectionTextureMatrix);\r\n if (this._projectionTexture instanceof Texture) {\r\n const u = this._projectionTexture.uScale / 2.0;\r\n const v = this._projectionTexture.vScale / 2.0;\r\n Matrix.FromValuesToRef(u, 0.0, 0.0, 0.0, 0.0, v, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0, this._projectionTextureScalingMatrix);\r\n }\r\n this._projectionTextureMatrix.multiplyToRef(this._projectionTextureScalingMatrix, this._projectionTextureMatrix);\r\n }\r\n\r\n protected _buildUniformLayout(): void {\r\n this._uniformBuffer.addUniform(\"vLightData\", 4);\r\n this._uniformBuffer.addUniform(\"vLightDiffuse\", 4);\r\n this._uniformBuffer.addUniform(\"vLightSpecular\", 4);\r\n this._uniformBuffer.addUniform(\"vLightDirection\", 3);\r\n this._uniformBuffer.addUniform(\"vLightFalloff\", 4);\r\n this._uniformBuffer.addUniform(\"shadowsInfo\", 3);\r\n this._uniformBuffer.addUniform(\"depthValues\", 2);\r\n this._uniformBuffer.create();\r\n }\r\n\r\n private _computeAngleValues(): void {\r\n this._lightAngleScale = 1.0 / Math.max(0.001, Math.cos(this._innerAngle * 0.5) - this._cosHalfAngle);\r\n this._lightAngleOffset = -this._cosHalfAngle * this._lightAngleScale;\r\n }\r\n\r\n /**\r\n * Sets the passed Effect \"effect\" with the Light textures.\r\n * @param effect The effect to update\r\n * @param lightIndex The index of the light in the effect to update\r\n * @returns The light\r\n */\r\n public override transferTexturesToEffect(effect: Effect, lightIndex: string): Light {\r\n if (this.projectionTexture && this.projectionTexture.isReady()) {\r\n if (this._projectionTextureViewLightDirty) {\r\n this._computeProjectionTextureViewLightMatrix();\r\n }\r\n if (this._projectionTextureProjectionLightDirty) {\r\n this._computeProjectionTextureProjectionLightMatrix();\r\n }\r\n if (this._projectionTextureDirty) {\r\n this._computeProjectionTextureMatrix();\r\n }\r\n effect.setMatrix(\"textureProjectionMatrix\" + lightIndex, this._projectionTextureMatrix);\r\n effect.setTexture(\"projectionLightTexture\" + lightIndex, this.projectionTexture);\r\n }\r\n\r\n if (this._iesProfileTexture && this._iesProfileTexture.isReady()) {\r\n effect.setTexture(\"iesLightTexture\" + lightIndex, this._iesProfileTexture);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the passed Effect object with the SpotLight transformed position (or position if not parented) and normalized direction.\r\n * @param effect The effect to update\r\n * @param lightIndex The index of the light in the effect to update\r\n * @returns The spot light\r\n */\r\n public transferToEffect(effect: Effect, lightIndex: string): SpotLight {\r\n let normalizeDirection;\r\n\r\n if (this.computeTransformedInformation()) {\r\n this._uniformBuffer.updateFloat4(\"vLightData\", this.transformedPosition.x, this.transformedPosition.y, this.transformedPosition.z, this.exponent, lightIndex);\r\n\r\n normalizeDirection = Vector3.Normalize(this.transformedDirection);\r\n } else {\r\n this._uniformBuffer.updateFloat4(\"vLightData\", this.position.x, this.position.y, this.position.z, this.exponent, lightIndex);\r\n\r\n normalizeDirection = Vector3.Normalize(this.direction);\r\n }\r\n\r\n this._uniformBuffer.updateFloat4(\"vLightDirection\", normalizeDirection.x, normalizeDirection.y, normalizeDirection.z, this._cosHalfAngle, lightIndex);\r\n\r\n this._uniformBuffer.updateFloat4(\"vLightFalloff\", this.range, this._inverseSquaredRange, this._lightAngleScale, this._lightAngleOffset, lightIndex);\r\n return this;\r\n }\r\n\r\n public transferToNodeMaterialEffect(effect: Effect, lightDataUniformName: string) {\r\n let normalizeDirection;\r\n\r\n if (this.computeTransformedInformation()) {\r\n normalizeDirection = Vector3.Normalize(this.transformedDirection);\r\n } else {\r\n normalizeDirection = Vector3.Normalize(this.direction);\r\n }\r\n\r\n if (this.getScene().useRightHandedSystem) {\r\n effect.setFloat3(lightDataUniformName, -normalizeDirection.x, -normalizeDirection.y, -normalizeDirection.z);\r\n } else {\r\n effect.setFloat3(lightDataUniformName, normalizeDirection.x, normalizeDirection.y, normalizeDirection.z);\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Disposes the light and the associated resources.\r\n */\r\n public override dispose(): void {\r\n super.dispose();\r\n if (this._projectionTexture) {\r\n this._projectionTexture.dispose();\r\n }\r\n if (this._iesProfileTexture) {\r\n this._iesProfileTexture.dispose();\r\n this._iesProfileTexture = null;\r\n }\r\n }\r\n\r\n /**\r\n * Gets the minZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the min for\r\n * @returns the depth min z\r\n */\r\n public override getDepthMinZ(activeCamera: Nullable<Camera>): number {\r\n const engine = this._scene.getEngine();\r\n const minZ = this.shadowMinZ !== undefined ? this.shadowMinZ : (activeCamera?.minZ ?? Constants.ShadowMinZ);\r\n\r\n return engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? minZ : this._scene.getEngine().isNDCHalfZRange ? 0 : minZ;\r\n }\r\n\r\n /**\r\n * Gets the maxZ used for shadow according to both the scene and the light.\r\n * @param activeCamera The camera we are returning the max for\r\n * @returns the depth max z\r\n */\r\n public override getDepthMaxZ(activeCamera: Nullable<Camera>): number {\r\n const engine = this._scene.getEngine();\r\n const maxZ = this.shadowMaxZ !== undefined ? this.shadowMaxZ : (activeCamera?.maxZ ?? Constants.ShadowMaxZ);\r\n\r\n return engine.useReverseDepthBuffer && engine.isNDCHalfZRange ? 0 : maxZ;\r\n }\r\n\r\n /**\r\n * Prepares the list of defines specific to the light type.\r\n * @param defines the list of defines\r\n * @param lightIndex defines the index of the light for the effect\r\n */\r\n public prepareLightSpecificDefines(defines: any, lightIndex: number): void {\r\n defines[\"SPOTLIGHT\" + lightIndex] = true;\r\n defines[\"PROJECTEDLIGHTTEXTURE\" + lightIndex] = this.projectionTexture && this.projectionTexture.isReady() ? true : false;\r\n defines[\"IESLIGHTTEXTURE\" + lightIndex] = this._iesProfileTexture && this._iesProfileTexture.isReady() ? true : false;\r\n }\r\n}\r\n\r\n// Register Class Name\r\nRegisterClass(\"BABYLON.SpotLight\", SpotLight);\r\n"]}
@@ -368,7 +368,7 @@ export declare function loadSceneAsync(source: SceneSource, engine: AbstractEngi
368
368
  * @param scene is the instance of BABYLON.Scene to append to
369
369
  * @param options an object that configures aspects of how the scene is loaded
370
370
  */
371
- export declare function appendSceneAsync(source: SceneSource, scene: Scene, options?: LoadAssetContainerOptions): Promise<void>;
371
+ export declare function appendSceneAsync(source: SceneSource, scene: Scene, options?: AppendOptions): Promise<void>;
372
372
  /**
373
373
  * Load a scene into an asset container
374
374
  * @experimental