e07fe4e9cd872e0a1a4c385117389a45f5739cc83fcd692cb48b0a9d2a121402.json 120 KB

1
  1. {"ast":null,"code":"import { Matrix, Vector3 } from \"../../Maths/math.vector.js\";\nimport { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture.js\";\nimport { _WarnImport } from \"../../Misc/devTools.js\";\nimport { ShadowGenerator } from \"./shadowGenerator.js\";\nimport { BoundingInfo } from \"../../Culling/boundingInfo.js\";\nimport { DepthReducer } from \"../../Misc/depthReducer.js\";\nimport { Logger } from \"../../Misc/logger.js\";\nimport { EngineStore } from \"../../Engines/engineStore.js\";\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst UpDir = Vector3.Up();\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst ZeroVec = Vector3.Zero();\nconst tmpv1 = new Vector3(),\n tmpv2 = new Vector3(),\n tmpMatrix = new Matrix();\n/**\n * A CSM implementation allowing casting shadows on large scenes.\n * Documentation : https://doc.babylonjs.com/babylon101/cascadedShadows\n * Based on: https://github.com/TheRealMJP/Shadows and https://johanmedestrom.wordpress.com/2016/03/18/opengl-cascaded-shadow-maps/\n */\nexport class CascadedShadowGenerator extends ShadowGenerator {\n _validateFilter(filter) {\n if (filter === ShadowGenerator.FILTER_NONE || filter === ShadowGenerator.FILTER_PCF || filter === ShadowGenerator.FILTER_PCSS) {\n return filter;\n }\n Logger.Error('Unsupported filter \"' + filter + '\"!');\n return ShadowGenerator.FILTER_NONE;\n }\n /**\n * Gets or set the number of cascades used by the CSM.\n */\n get numCascades() {\n return this._numCascades;\n }\n set numCascades(value) {\n value = Math.min(Math.max(value, CascadedShadowGenerator.MIN_CASCADES_COUNT), CascadedShadowGenerator.MAX_CASCADES_COUNT);\n if (value === this._numCascades) {\n return;\n }\n this._numCascades = value;\n this.recreateShadowMap();\n this._recreateSceneUBOs();\n }\n /**\n * Enables or disables the shadow casters bounding info computation.\n * If your shadow casters don't move, you can disable this feature.\n * If it is enabled, the bounding box computation is done every frame.\n */\n get freezeShadowCastersBoundingInfo() {\n return this._freezeShadowCastersBoundingInfo;\n }\n set freezeShadowCastersBoundingInfo(freeze) {\n if (this._freezeShadowCastersBoundingInfoObservable && freeze) {\n this._scene.onBeforeRenderObservable.remove(this._freezeShadowCastersBoundingInfoObservable);\n this._freezeShadowCastersBoundingInfoObservable = null;\n }\n if (!this._freezeShadowCastersBoundingInfoObservable && !freeze) {\n this._freezeShadowCastersBoundingInfoObservable = this._scene.onBeforeRenderObservable.add(() => this._computeShadowCastersBoundingInfo());\n }\n this._freezeShadowCastersBoundingInfo = freeze;\n if (freeze) {\n this._computeShadowCastersBoundingInfo();\n }\n }\n _computeShadowCastersBoundingInfo() {\n this._scbiMin.copyFromFloats(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n this._scbiMax.copyFromFloats(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);\n if (this._shadowMap && this._shadowMap.renderList) {\n const renderList = this._shadowMap.renderList;\n for (let meshIndex = 0; meshIndex < renderList.length; meshIndex++) {\n const mesh = renderList[meshIndex];\n if (!mesh) {\n continue;\n }\n const boundingInfo = mesh.getBoundingInfo(),\n boundingBox = boundingInfo.boundingBox;\n this._scbiMin.minimizeInPlace(boundingBox.minimumWorld);\n this._scbiMax.maximizeInPlace(boundingBox.maximumWorld);\n }\n const meshes = this._scene.meshes;\n for (let meshIndex = 0; meshIndex < meshes.length; meshIndex++) {\n const mesh = meshes[meshIndex];\n if (!mesh || !mesh.isVisible || !mesh.isEnabled || !mesh.receiveShadows) {\n continue;\n }\n const boundingInfo = mesh.getBoundingInfo(),\n boundingBox = boundingInfo.boundingBox;\n this._scbiMin.minimizeInPlace(boundingBox.minimumWorld);\n this._scbiMax.maximizeInPlace(boundingBox.maximumWorld);\n }\n }\n this._shadowCastersBoundingInfo.reConstruct(this._scbiMin, this._scbiMax);\n }\n /**\n * Gets or sets the shadow casters bounding info.\n * If you provide your own shadow casters bounding info, first enable freezeShadowCastersBoundingInfo\n * so that the system won't overwrite the bounds you provide\n */\n get shadowCastersBoundingInfo() {\n return this._shadowCastersBoundingInfo;\n }\n set shadowCastersBoundingInfo(boundingInfo) {\n this._shadowCastersBoundingInfo = boundingInfo;\n }\n /**\n * Sets the minimal and maximal distances to use when computing the cascade breaks.\n *\n * The values of min / max are typically the depth zmin and zmax values of your scene, for a given frame.\n * If you don't know these values, simply leave them to their defaults and don't call this function.\n * @param min minimal distance for the breaks (default to 0.)\n * @param max maximal distance for the breaks (default to 1.)\n */\n setMinMaxDistance(min, max) {\n if (this._minDistance === min && this._maxDistance === max) {\n return;\n }\n if (min > max) {\n min = 0;\n max = 1;\n }\n if (min < 0) {\n min = 0;\n }\n if (max > 1) {\n max = 1;\n }\n this._minDistance = min;\n this._maxDistance = max;\n this._breaksAreDirty = true;\n }\n /** Gets the minimal distance used in the cascade break computation */\n get minDistance() {\n return this._minDistance;\n }\n /** Gets the maximal distance used in the cascade break computation */\n get maxDistance() {\n return this._maxDistance;\n }\n /**\n * Gets the class name of that object\n * @returns \"CascadedShadowGenerator\"\n */\n getClassName() {\n return CascadedShadowGenerator.CLASSNAME;\n }\n /**\n * Gets a cascade minimum extents\n * @param cascadeIndex index of the cascade\n * @returns the minimum cascade extents\n */\n getCascadeMinExtents(cascadeIndex) {\n return cascadeIndex >= 0 && cascadeIndex < this._numCascades ? this._cascadeMinExtents[cascadeIndex] : null;\n }\n /**\n * Gets a cascade maximum extents\n * @param cascadeIndex index of the cascade\n * @returns the maximum cascade extents\n */\n getCascadeMaxExtents(cascadeIndex) {\n return cascadeIndex >= 0 && cascadeIndex < this._numCascades ? this._cascadeMaxExtents[cascadeIndex] : null;\n }\n /**\n * Gets the shadow max z distance. It's the limit beyond which shadows are not displayed.\n * It defaults to camera.maxZ\n */\n get shadowMaxZ() {\n if (!this._getCamera()) {\n return 0;\n }\n return this._shadowMaxZ;\n }\n /**\n * Sets the shadow max z distance.\n */\n set shadowMaxZ(value) {\n const camera = this._getCamera();\n if (!camera) {\n this._shadowMaxZ = value;\n return;\n }\n if (this._shadowMaxZ === value || value < camera.minZ || value > camera.maxZ && camera.maxZ !== 0) {\n return;\n }\n this._shadowMaxZ = value;\n this._light._markMeshesAsLightDirty();\n this._breaksAreDirty = true;\n }\n /**\n * Gets or sets the debug flag.\n * When enabled, the cascades are materialized by different colors on the screen.\n */\n get debug() {\n return this._debug;\n }\n set debug(dbg) {\n this._debug = dbg;\n this._light._markMeshesAsLightDirty();\n }\n /**\n * Gets or sets the depth clamping value.\n *\n * When enabled, it improves the shadow quality because the near z plane of the light frustum don't need to be adjusted\n * to account for the shadow casters far away.\n *\n * Note that this property is incompatible with PCSS filtering, so it won't be used in that case.\n */\n get depthClamp() {\n return this._depthClamp;\n }\n set depthClamp(value) {\n this._depthClamp = value;\n }\n /**\n * Gets or sets the percentage of blending between two cascades (value between 0. and 1.).\n * It defaults to 0.1 (10% blending).\n */\n get cascadeBlendPercentage() {\n return this._cascadeBlendPercentage;\n }\n set cascadeBlendPercentage(value) {\n this._cascadeBlendPercentage = value;\n this._light._markMeshesAsLightDirty();\n }\n /**\n * Gets or set the lambda parameter.\n * This parameter is used to split the camera frustum and create the cascades.\n * It's a value between 0. and 1.: If 0, the split is a uniform split of the frustum, if 1 it is a logarithmic split.\n * For all values in-between, it's a linear combination of the uniform and logarithm split algorithm.\n */\n get lambda() {\n return this._lambda;\n }\n set lambda(value) {\n const lambda = Math.min(Math.max(value, 0), 1);\n if (this._lambda == lambda) {\n return;\n }\n this._lambda = lambda;\n this._breaksAreDirty = true;\n }\n /**\n * Gets the view matrix corresponding to a given cascade\n * @param cascadeNum cascade to retrieve the view matrix from\n * @returns the cascade view matrix\n */\n getCascadeViewMatrix(cascadeNum) {\n return cascadeNum >= 0 && cascadeNum < this._numCascades ? this._viewMatrices[cascadeNum] : null;\n }\n /**\n * Gets the projection matrix corresponding to a given cascade\n * @param cascadeNum cascade to retrieve the projection matrix from\n * @returns the cascade projection matrix\n */\n getCascadeProjectionMatrix(cascadeNum) {\n return cascadeNum >= 0 && cascadeNum < this._numCascades ? this._projectionMatrices[cascadeNum] : null;\n }\n /**\n * Gets the transformation matrix corresponding to a given cascade\n * @param cascadeNum cascade to retrieve the transformation matrix from\n * @returns the cascade transformation matrix\n */\n getCascadeTransformMatrix(cascadeNum) {\n return cascadeNum >= 0 && cascadeNum < this._numCascades ? this._transformMatrices[cascadeNum] : null;\n }\n /**\n * Sets the depth renderer to use when autoCalcDepthBounds is enabled.\n *\n * Note that if no depth renderer is set, a new one will be automatically created internally when necessary.\n *\n * You should call this function if you already have a depth renderer enabled in your scene, to avoid\n * doing multiple depth rendering each frame. If you provide your own depth renderer, make sure it stores linear depth!\n * @param depthRenderer The depth renderer to use when autoCalcDepthBounds is enabled. If you pass null or don't call this function at all, a depth renderer will be automatically created\n */\n setDepthRenderer(depthRenderer) {\n this._depthRenderer = depthRenderer;\n if (this._depthReducer) {\n this._depthReducer.setDepthRenderer(this._depthRenderer);\n }\n }\n /**\n * Gets or sets the autoCalcDepthBounds property.\n *\n * When enabled, a depth rendering pass is first performed (with an internally created depth renderer or with the one\n * you provide by calling setDepthRenderer). Then, a min/max reducing is applied on the depth map to compute the\n * minimal and maximal depth of the map and those values are used as inputs for the setMinMaxDistance() function.\n * It can greatly enhance the shadow quality, at the expense of more GPU works.\n * When using this option, you should increase the value of the lambda parameter, and even set it to 1 for best results.\n */\n get autoCalcDepthBounds() {\n return this._autoCalcDepthBounds;\n }\n set autoCalcDepthBounds(value) {\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n this._autoCalcDepthBounds = value;\n if (!value) {\n if (this._depthReducer) {\n this._depthReducer.deactivate();\n }\n this.setMinMaxDistance(0, 1);\n return;\n }\n if (!this._depthReducer) {\n this._depthReducer = new DepthReducer(camera);\n this._depthReducer.onAfterReductionPerformed.add(minmax => {\n let min = minmax.min,\n max = minmax.max;\n if (min >= max) {\n min = 0;\n max = 1;\n }\n if (min != this._minDistance || max != this._maxDistance) {\n this.setMinMaxDistance(min, max);\n }\n });\n this._depthReducer.setDepthRenderer(this._depthRenderer);\n }\n this._depthReducer.activate();\n }\n /**\n * Defines the refresh rate of the min/max computation used when autoCalcDepthBounds is set to true\n * Use 0 to compute just once, 1 to compute on every frame, 2 to compute every two frames and so on...\n * Note that if you provided your own depth renderer through a call to setDepthRenderer, you are responsible\n * for setting the refresh rate on the renderer yourself!\n */\n get autoCalcDepthBoundsRefreshRate() {\n var _this$_depthReducer$d, _this$_depthReducer;\n return (_this$_depthReducer$d = (_this$_depthReducer = this._depthReducer) === null || _this$_depthReducer === void 0 || (_this$_depthReducer = _this$_depthReducer.depthRenderer) === null || _this$_depthReducer === void 0 ? void 0 : _this$_depthReducer.getDepthMap().refreshRate) !== null && _this$_depthReducer$d !== void 0 ? _this$_depthReducer$d : -1;\n }\n set autoCalcDepthBoundsRefreshRate(value) {\n var _this$_depthReducer2;\n if ((_this$_depthReducer2 = this._depthReducer) !== null && _this$_depthReducer2 !== void 0 && _this$_depthReducer2.depthRenderer) {\n this._depthReducer.depthRenderer.getDepthMap().refreshRate = value;\n }\n }\n /**\n * Create the cascade breaks according to the lambda, shadowMaxZ and min/max distance properties, as well as the camera near and far planes.\n * This function is automatically called when updating lambda, shadowMaxZ and min/max distances, however you should call it yourself if\n * you change the camera near/far planes!\n */\n splitFrustum() {\n this._breaksAreDirty = true;\n }\n _splitFrustum() {\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n const near = camera.minZ,\n far = camera.maxZ || this._shadowMaxZ,\n // account for infinite far plane (ie. maxZ = 0)\n cameraRange = far - near,\n minDistance = this._minDistance,\n maxDistance = this._shadowMaxZ < far && this._shadowMaxZ >= near ? Math.min((this._shadowMaxZ - near) / (far - near), this._maxDistance) : this._maxDistance;\n const minZ = near + minDistance * cameraRange,\n maxZ = near + maxDistance * cameraRange;\n const range = maxZ - minZ,\n ratio = maxZ / minZ;\n for (let cascadeIndex = 0; cascadeIndex < this._cascades.length; ++cascadeIndex) {\n const p = (cascadeIndex + 1) / this._numCascades,\n log = minZ * ratio ** p,\n uniform = minZ + range * p;\n const d = this._lambda * (log - uniform) + uniform;\n this._cascades[cascadeIndex].prevBreakDistance = cascadeIndex === 0 ? minDistance : this._cascades[cascadeIndex - 1].breakDistance;\n this._cascades[cascadeIndex].breakDistance = (d - near) / cameraRange;\n this._viewSpaceFrustumsZ[cascadeIndex] = d;\n this._frustumLengths[cascadeIndex] = (this._cascades[cascadeIndex].breakDistance - this._cascades[cascadeIndex].prevBreakDistance) * cameraRange;\n }\n this._breaksAreDirty = false;\n }\n _computeMatrices() {\n const scene = this._scene;\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n Vector3.NormalizeToRef(this._light.getShadowDirection(0), this._lightDirection);\n if (Math.abs(Vector3.Dot(this._lightDirection, Vector3.Up())) === 1.0) {\n this._lightDirection.z = 0.0000000000001; // Required to avoid perfectly perpendicular light\n }\n this._cachedDirection.copyFrom(this._lightDirection);\n const useReverseDepthBuffer = scene.getEngine().useReverseDepthBuffer;\n for (let cascadeIndex = 0; cascadeIndex < this._numCascades; ++cascadeIndex) {\n this._computeFrustumInWorldSpace(cascadeIndex);\n this._computeCascadeFrustum(cascadeIndex);\n this._cascadeMaxExtents[cascadeIndex].subtractToRef(this._cascadeMinExtents[cascadeIndex], tmpv1); // tmpv1 = cascadeExtents\n // Get position of the shadow camera\n this._frustumCenter[cascadeIndex].addToRef(this._lightDirection.scale(this._cascadeMinExtents[cascadeIndex].z), this._shadowCameraPos[cascadeIndex]);\n // Come up with a new orthographic camera for the shadow caster\n Matrix.LookAtLHToRef(this._shadowCameraPos[cascadeIndex], this._frustumCenter[cascadeIndex], UpDir, this._viewMatrices[cascadeIndex]);\n let minZ = 0,\n maxZ = tmpv1.z;\n // Try to tighten minZ and maxZ based on the bounding box of the shadow casters\n const boundingInfo = this._shadowCastersBoundingInfo;\n boundingInfo.update(this._viewMatrices[cascadeIndex]);\n maxZ = Math.min(maxZ, boundingInfo.boundingBox.maximumWorld.z);\n if (!this._depthClamp || this.filter === ShadowGenerator.FILTER_PCSS) {\n // If we don't use depth clamping, we must set minZ so that all shadow casters are in the light frustum\n minZ = Math.min(minZ, boundingInfo.boundingBox.minimumWorld.z);\n } else {\n // If using depth clamping, we can adjust minZ to reduce the [minZ, maxZ] range (and get some additional precision in the shadow map)\n minZ = Math.max(minZ, boundingInfo.boundingBox.minimumWorld.z);\n }\n Matrix.OrthoOffCenterLHToRef(this._cascadeMinExtents[cascadeIndex].x, this._cascadeMaxExtents[cascadeIndex].x, this._cascadeMinExtents[cascadeIndex].y, this._cascadeMaxExtents[cascadeIndex].y, useReverseDepthBuffer ? maxZ : minZ, useReverseDepthBuffer ? minZ : maxZ, this._projectionMatrices[cascadeIndex], scene.getEngine().isNDCHalfZRange);\n this._cascadeMinExtents[cascadeIndex].z = minZ;\n this._cascadeMaxExtents[cascadeIndex].z = maxZ;\n this._viewMatrices[cascadeIndex].multiplyToRef(this._projectionMatrices[cascadeIndex], this._transformMatrices[cascadeIndex]);\n // Create the rounding matrix, by projecting the world-space origin and determining\n // the fractional offset in texel space\n Vector3.TransformCoordinatesToRef(ZeroVec, this._transformMatrices[cascadeIndex], tmpv1); // tmpv1 = shadowOrigin\n tmpv1.scaleInPlace(this._mapSize / 2);\n tmpv2.copyFromFloats(Math.round(tmpv1.x), Math.round(tmpv1.y), Math.round(tmpv1.z)); // tmpv2 = roundedOrigin\n tmpv2.subtractInPlace(tmpv1).scaleInPlace(2 / this._mapSize); // tmpv2 = roundOffset\n Matrix.TranslationToRef(tmpv2.x, tmpv2.y, 0.0, tmpMatrix);\n this._projectionMatrices[cascadeIndex].multiplyToRef(tmpMatrix, this._projectionMatrices[cascadeIndex]);\n this._viewMatrices[cascadeIndex].multiplyToRef(this._projectionMatrices[cascadeIndex], this._transformMatrices[cascadeIndex]);\n this._transformMatrices[cascadeIndex].copyToArray(this._transformMatricesAsArray, cascadeIndex * 16);\n }\n }\n // Get the 8 points of the view frustum in world space\n _computeFrustumInWorldSpace(cascadeIndex) {\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n const prevSplitDist = this._cascades[cascadeIndex].prevBreakDistance,\n splitDist = this._cascades[cascadeIndex].breakDistance;\n const isNDCHalfZRange = this._scene.getEngine().isNDCHalfZRange;\n camera.getViewMatrix(); // make sure the transformation matrix we get when calling 'getTransformationMatrix()' is calculated with an up to date view matrix\n const cameraInfiniteFarPlane = camera.maxZ === 0;\n const saveCameraMaxZ = camera.maxZ;\n if (cameraInfiniteFarPlane) {\n camera.maxZ = this._shadowMaxZ;\n camera.getProjectionMatrix(true);\n }\n const invViewProj = Matrix.Invert(camera.getTransformationMatrix());\n if (cameraInfiniteFarPlane) {\n camera.maxZ = saveCameraMaxZ;\n camera.getProjectionMatrix(true);\n }\n const cornerIndexOffset = this._scene.getEngine().useReverseDepthBuffer ? 4 : 0;\n for (let cornerIndex = 0; cornerIndex < CascadedShadowGenerator._FrustumCornersNDCSpace.length; ++cornerIndex) {\n tmpv1.copyFrom(CascadedShadowGenerator._FrustumCornersNDCSpace[(cornerIndex + cornerIndexOffset) % CascadedShadowGenerator._FrustumCornersNDCSpace.length]);\n if (isNDCHalfZRange && tmpv1.z === -1) {\n tmpv1.z = 0;\n }\n Vector3.TransformCoordinatesToRef(tmpv1, invViewProj, this._frustumCornersWorldSpace[cascadeIndex][cornerIndex]);\n }\n // Get the corners of the current cascade slice of the view frustum\n for (let cornerIndex = 0; cornerIndex < CascadedShadowGenerator._FrustumCornersNDCSpace.length / 2; ++cornerIndex) {\n tmpv1.copyFrom(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex + 4]).subtractInPlace(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex]);\n tmpv2.copyFrom(tmpv1).scaleInPlace(prevSplitDist); // near corner ray\n tmpv1.scaleInPlace(splitDist); // far corner ray\n tmpv1.addInPlace(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex]);\n this._frustumCornersWorldSpace[cascadeIndex][cornerIndex + 4].copyFrom(tmpv1);\n this._frustumCornersWorldSpace[cascadeIndex][cornerIndex].addInPlace(tmpv2);\n }\n }\n _computeCascadeFrustum(cascadeIndex) {\n this._cascadeMinExtents[cascadeIndex].copyFromFloats(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n this._cascadeMaxExtents[cascadeIndex].copyFromFloats(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);\n this._frustumCenter[cascadeIndex].copyFromFloats(0, 0, 0);\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n // Calculate the centroid of the view frustum slice\n for (let cornerIndex = 0; cornerIndex < this._frustumCornersWorldSpace[cascadeIndex].length; ++cornerIndex) {\n this._frustumCenter[cascadeIndex].addInPlace(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex]);\n }\n this._frustumCenter[cascadeIndex].scaleInPlace(1 / this._frustumCornersWorldSpace[cascadeIndex].length);\n if (this.stabilizeCascades) {\n // Calculate the radius of a bounding sphere surrounding the frustum corners\n let sphereRadius = 0;\n for (let cornerIndex = 0; cornerIndex < this._frustumCornersWorldSpace[cascadeIndex].length; ++cornerIndex) {\n const dist = this._frustumCornersWorldSpace[cascadeIndex][cornerIndex].subtractToRef(this._frustumCenter[cascadeIndex], tmpv1).length();\n sphereRadius = Math.max(sphereRadius, dist);\n }\n sphereRadius = Math.ceil(sphereRadius * 16) / 16;\n this._cascadeMaxExtents[cascadeIndex].copyFromFloats(sphereRadius, sphereRadius, sphereRadius);\n this._cascadeMinExtents[cascadeIndex].copyFromFloats(-sphereRadius, -sphereRadius, -sphereRadius);\n } else {\n // Create a temporary view matrix for the light\n const lightCameraPos = this._frustumCenter[cascadeIndex];\n this._frustumCenter[cascadeIndex].addToRef(this._lightDirection, tmpv1); // tmpv1 = look at\n Matrix.LookAtLHToRef(lightCameraPos, tmpv1, UpDir, tmpMatrix); // matrix = lightView\n // Calculate an AABB around the frustum corners\n for (let cornerIndex = 0; cornerIndex < this._frustumCornersWorldSpace[cascadeIndex].length; ++cornerIndex) {\n Vector3.TransformCoordinatesToRef(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex], tmpMatrix, tmpv1);\n this._cascadeMinExtents[cascadeIndex].minimizeInPlace(tmpv1);\n this._cascadeMaxExtents[cascadeIndex].maximizeInPlace(tmpv1);\n }\n }\n }\n _recreateSceneUBOs() {\n this._disposeSceneUBOs();\n if (this._sceneUBOs) {\n for (let i = 0; i < this._numCascades; ++i) {\n this._sceneUBOs.push(this._scene.createSceneUniformBuffer(`Scene for CSM Shadow Generator (light \"${this._light.name}\" cascade #${i})`));\n }\n }\n }\n /**\n * Support test.\n */\n static get IsSupported() {\n const engine = EngineStore.LastCreatedEngine;\n if (!engine) {\n return false;\n }\n return engine._features.supportCSM;\n }\n /**\n * Creates a Cascaded Shadow Generator object.\n * A ShadowGenerator is the required tool to use the shadows.\n * Each directional light casting shadows needs to use its own ShadowGenerator.\n * Documentation : https://doc.babylonjs.com/babylon101/cascadedShadows\n * @param mapSize The size of the texture what stores the shadows. Example : 1024.\n * @param light The directional light object generating the shadows.\n * @param usefulFloatFirst By default the generator will try to use half float textures but if you need precision (for self shadowing for instance), you can use this option to enforce full float texture.\n * @param camera Camera associated with this shadow generator (default: null). If null, takes the scene active camera at the time we need to access it\n * @param useRedTextureType Forces the generator to use a Red instead of a RGBA type for the shadow map texture format (default: true)\n */\n constructor(mapSize, light, usefulFloatFirst, camera, useRedTextureType = true) {\n if (!CascadedShadowGenerator.IsSupported) {\n Logger.Error(\"CascadedShadowMap is not supported by the current engine.\");\n return;\n }\n super(mapSize, light, usefulFloatFirst, camera, useRedTextureType);\n this.usePercentageCloserFiltering = true;\n }\n _initializeGenerator() {\n var _this$penumbraDarknes, _this$_numCascades, _this$stabilizeCascad, _this$_freezeShadowCa, _this$freezeShadowCas, _this$_scbiMin, _this$_scbiMax, _this$_shadowCastersB, _this$_breaksAreDirty, _this$_minDistance, _this$_maxDistance, _this$_currentLayer, _ref, _this$_shadowMaxZ, _this$_getCamera, _this$_debug, _this$_depthClamp, _this$_cascadeBlendPe, _this$_lambda, _this$_autoCalcDepthB;\n this.penumbraDarkness = (_this$penumbraDarknes = this.penumbraDarkness) !== null && _this$penumbraDarknes !== void 0 ? _this$penumbraDarknes : 1.0;\n this._numCascades = (_this$_numCascades = this._numCascades) !== null && _this$_numCascades !== void 0 ? _this$_numCascades : CascadedShadowGenerator.DEFAULT_CASCADES_COUNT;\n this.stabilizeCascades = (_this$stabilizeCascad = this.stabilizeCascades) !== null && _this$stabilizeCascad !== void 0 ? _this$stabilizeCascad : false;\n this._freezeShadowCastersBoundingInfoObservable = (_this$_freezeShadowCa = this._freezeShadowCastersBoundingInfoObservable) !== null && _this$_freezeShadowCa !== void 0 ? _this$_freezeShadowCa : null;\n this.freezeShadowCastersBoundingInfo = (_this$freezeShadowCas = this.freezeShadowCastersBoundingInfo) !== null && _this$freezeShadowCas !== void 0 ? _this$freezeShadowCas : false;\n this._scbiMin = (_this$_scbiMin = this._scbiMin) !== null && _this$_scbiMin !== void 0 ? _this$_scbiMin : new Vector3(0, 0, 0);\n this._scbiMax = (_this$_scbiMax = this._scbiMax) !== null && _this$_scbiMax !== void 0 ? _this$_scbiMax : new Vector3(0, 0, 0);\n this._shadowCastersBoundingInfo = (_this$_shadowCastersB = this._shadowCastersBoundingInfo) !== null && _this$_shadowCastersB !== void 0 ? _this$_shadowCastersB : new BoundingInfo(new Vector3(0, 0, 0), new Vector3(0, 0, 0));\n this._breaksAreDirty = (_this$_breaksAreDirty = this._breaksAreDirty) !== null && _this$_breaksAreDirty !== void 0 ? _this$_breaksAreDirty : true;\n this._minDistance = (_this$_minDistance = this._minDistance) !== null && _this$_minDistance !== void 0 ? _this$_minDistance : 0;\n this._maxDistance = (_this$_maxDistance = this._maxDistance) !== null && _this$_maxDistance !== void 0 ? _this$_maxDistance : 1;\n this._currentLayer = (_this$_currentLayer = this._currentLayer) !== null && _this$_currentLayer !== void 0 ? _this$_currentLayer : 0;\n this._shadowMaxZ = (_ref = (_this$_shadowMaxZ = this._shadowMaxZ) !== null && _this$_shadowMaxZ !== void 0 ? _this$_shadowMaxZ : (_this$_getCamera = this._getCamera()) === null || _this$_getCamera === void 0 ? void 0 : _this$_getCamera.maxZ) !== null && _ref !== void 0 ? _ref : 10000;\n this._debug = (_this$_debug = this._debug) !== null && _this$_debug !== void 0 ? _this$_debug : false;\n this._depthClamp = (_this$_depthClamp = this._depthClamp) !== null && _this$_depthClamp !== void 0 ? _this$_depthClamp : true;\n this._cascadeBlendPercentage = (_this$_cascadeBlendPe = this._cascadeBlendPercentage) !== null && _this$_cascadeBlendPe !== void 0 ? _this$_cascadeBlendPe : 0.1;\n this._lambda = (_this$_lambda = this._lambda) !== null && _this$_lambda !== void 0 ? _this$_lambda : 0.5;\n this._autoCalcDepthBounds = (_this$_autoCalcDepthB = this._autoCalcDepthBounds) !== null && _this$_autoCalcDepthB !== void 0 ? _this$_autoCalcDepthB : false;\n this._recreateSceneUBOs();\n super._initializeGenerator();\n }\n _createTargetRenderTexture() {\n const engine = this._scene.getEngine();\n const size = {\n width: this._mapSize,\n height: this._mapSize,\n layers: this.numCascades\n };\n this._shadowMap = new RenderTargetTexture(this._light.name + \"_CSMShadowMap\", size, this._scene, false, true, this._textureType, false, undefined, false, false, undefined, this._useRedTextureType ? 6 : 5);\n this._shadowMap.createDepthStencilTexture(engine.useReverseDepthBuffer ? 516 : 513, true, undefined, undefined, undefined, `DepthStencilForCSMShadowGenerator-${this._light.name}`);\n this._shadowMap.noPrePassRenderer = true;\n }\n _initializeShadowMap() {\n super._initializeShadowMap();\n if (this._shadowMap === null) {\n return;\n }\n this._transformMatricesAsArray = new Float32Array(this._numCascades * 16);\n this._viewSpaceFrustumsZ = new Array(this._numCascades);\n this._frustumLengths = new Array(this._numCascades);\n this._lightSizeUVCorrection = new Array(this._numCascades * 2);\n this._depthCorrection = new Array(this._numCascades);\n this._cascades = [];\n this._viewMatrices = [];\n this._projectionMatrices = [];\n this._transformMatrices = [];\n this._cascadeMinExtents = [];\n this._cascadeMaxExtents = [];\n this._frustumCenter = [];\n this._shadowCameraPos = [];\n this._frustumCornersWorldSpace = [];\n for (let cascadeIndex = 0; cascadeIndex < this._numCascades; ++cascadeIndex) {\n this._cascades[cascadeIndex] = {\n prevBreakDistance: 0,\n breakDistance: 0\n };\n this._viewMatrices[cascadeIndex] = Matrix.Zero();\n this._projectionMatrices[cascadeIndex] = Matrix.Zero();\n this._transformMatrices[cascadeIndex] = Matrix.Zero();\n this._cascadeMinExtents[cascadeIndex] = new Vector3();\n this._cascadeMaxExtents[cascadeIndex] = new Vector3();\n this._frustumCenter[cascadeIndex] = new Vector3();\n this._shadowCameraPos[cascadeIndex] = new Vector3();\n this._frustumCornersWorldSpace[cascadeIndex] = new Array(CascadedShadowGenerator._FrustumCornersNDCSpace.length);\n for (let i = 0; i < CascadedShadowGenerator._FrustumCornersNDCSpace.length; ++i) {\n this._frustumCornersWorldSpace[cascadeIndex][i] = new Vector3();\n }\n }\n const engine = this._scene.getEngine();\n this._shadowMap.onBeforeBindObservable.clear();\n this._shadowMap.onBeforeRenderObservable.clear();\n this._shadowMap.onBeforeRenderObservable.add(layer => {\n if (this._sceneUBOs) {\n this._scene.setSceneUniformBuffer(this._sceneUBOs[layer]);\n }\n this._currentLayer = layer;\n if (this._filter === ShadowGenerator.FILTER_PCF) {\n engine.setColorWrite(false);\n }\n this._scene.setTransformMatrix(this.getCascadeViewMatrix(layer), this.getCascadeProjectionMatrix(layer));\n if (this._useUBO) {\n this._scene.getSceneUniformBuffer().unbindEffect();\n this._scene.finalizeSceneUbo();\n }\n });\n this._shadowMap.onBeforeBindObservable.add(() => {\n var _engine$_debugPushGro;\n this._currentSceneUBO = this._scene.getSceneUniformBuffer();\n (_engine$_debugPushGro = engine._debugPushGroup) === null || _engine$_debugPushGro === void 0 || _engine$_debugPushGro.call(engine, `cascaded shadow map generation for pass id ${engine.currentRenderPassId}`, 1);\n if (this._breaksAreDirty) {\n this._splitFrustum();\n }\n this._computeMatrices();\n });\n this._splitFrustum();\n }\n _bindCustomEffectForRenderSubMeshForShadowMap(subMesh, effect) {\n effect.setMatrix(\"viewProjection\", this.getCascadeTransformMatrix(this._currentLayer));\n }\n _isReadyCustomDefines(defines) {\n defines.push(\"#define SM_DEPTHCLAMP \" + (this._depthClamp && this._filter !== ShadowGenerator.FILTER_PCSS ? \"1\" : \"0\"));\n }\n /**\n * Prepare all the defines in a material relying on a shadow map at the specified light index.\n * @param defines Defines of the material we want to update\n * @param lightIndex Index of the light in the enabled light list of the material\n */\n prepareDefines(defines, lightIndex) {\n super.prepareDefines(defines, lightIndex);\n const scene = this._scene;\n const light = this._light;\n if (!scene.shadowsEnabled || !light.shadowEnabled) {\n return;\n }\n defines[\"SHADOWCSM\" + lightIndex] = true;\n defines[\"SHADOWCSMDEBUG\" + lightIndex] = this.debug;\n defines[\"SHADOWCSMNUM_CASCADES\" + lightIndex] = this.numCascades;\n defines[\"SHADOWCSM_RIGHTHANDED\" + lightIndex] = scene.useRightHandedSystem;\n const camera = this._getCamera();\n if (camera && this._shadowMaxZ <= (camera.maxZ || this._shadowMaxZ)) {\n defines[\"SHADOWCSMUSESHADOWMAXZ\" + lightIndex] = true;\n }\n if (this.cascadeBlendPercentage === 0) {\n defines[\"SHADOWCSMNOBLEND\" + lightIndex] = true;\n }\n }\n /**\n * Binds the shadow related information inside of an effect (information like near, far, darkness...\n * defined in the generator but impacting the effect).\n * @param lightIndex Index of the light in the enabled light list of the material owning the effect\n * @param effect The effect we are binfing the information for\n */\n bindShadowLight(lightIndex, effect) {\n const light = this._light;\n const scene = this._scene;\n if (!scene.shadowsEnabled || !light.shadowEnabled) {\n return;\n }\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n const shadowMap = this.getShadowMap();\n if (!shadowMap) {\n return;\n }\n const width = shadowMap.getSize().width;\n effect.setMatrices(\"lightMatrix\" + lightIndex, this._transformMatricesAsArray);\n effect.setArray(\"viewFrustumZ\" + lightIndex, this._viewSpaceFrustumsZ);\n effect.setFloat(\"cascadeBlendFactor\" + lightIndex, this.cascadeBlendPercentage === 0 ? 10000 : 1 / this.cascadeBlendPercentage);\n effect.setArray(\"frustumLengths\" + lightIndex, this._frustumLengths);\n // Only PCF uses depth stencil texture.\n if (this._filter === ShadowGenerator.FILTER_PCF) {\n effect.setDepthStencilTexture(\"shadowTexture\" + lightIndex, shadowMap);\n light._uniformBuffer.updateFloat4(\"shadowsInfo\", this.getDarkness(), width, 1 / width, this.frustumEdgeFalloff, lightIndex);\n } else if (this._filter === ShadowGenerator.FILTER_PCSS) {\n for (let cascadeIndex = 0; cascadeIndex < this._numCascades; ++cascadeIndex) {\n this._lightSizeUVCorrection[cascadeIndex * 2 + 0] = cascadeIndex === 0 ? 1 : (this._cascadeMaxExtents[0].x - this._cascadeMinExtents[0].x) / (this._cascadeMaxExtents[cascadeIndex].x - this._cascadeMinExtents[cascadeIndex].x); // x correction\n this._lightSizeUVCorrection[cascadeIndex * 2 + 1] = cascadeIndex === 0 ? 1 : (this._cascadeMaxExtents[0].y - this._cascadeMinExtents[0].y) / (this._cascadeMaxExtents[cascadeIndex].y - this._cascadeMinExtents[cascadeIndex].y); // y correction\n this._depthCorrection[cascadeIndex] = cascadeIndex === 0 ? 1 : (this._cascadeMaxExtents[cascadeIndex].z - this._cascadeMinExtents[cascadeIndex].z) / (this._cascadeMaxExtents[0].z - this._cascadeMinExtents[0].z);\n }\n effect.setDepthStencilTexture(\"shadowTexture\" + lightIndex, shadowMap);\n effect.setTexture(\"depthTexture\" + lightIndex, shadowMap);\n effect.setArray2(\"lightSizeUVCorrection\" + lightIndex, this._lightSizeUVCorrection);\n effect.setArray(\"depthCorrection\" + lightIndex, this._depthCorrection);\n effect.setFloat(\"penumbraDarkness\" + lightIndex, this.penumbraDarkness);\n light._uniformBuffer.updateFloat4(\"shadowsInfo\", this.getDarkness(), 1 / width, this._contactHardeningLightSizeUVRatio * width, this.frustumEdgeFalloff, lightIndex);\n } else {\n effect.setTexture(\"shadowTexture\" + lightIndex, shadowMap);\n light._uniformBuffer.updateFloat4(\"shadowsInfo\", this.getDarkness(), width, 1 / width, this.frustumEdgeFalloff, lightIndex);\n }\n light._uniformBuffer.updateFloat2(\"depthValues\", this.getLight().getDepthMinZ(camera), this.getLight().getDepthMinZ(camera) + this.getLight().getDepthMaxZ(camera), lightIndex);\n }\n /**\n * Gets the transformation matrix of the first cascade used to project the meshes into the map from the light point of view.\n * (eq to view projection * shadow projection matrices)\n * @returns The transform matrix used to create the shadow map\n */\n getTransformMatrix() {\n return this.getCascadeTransformMatrix(0);\n }\n /**\n * Disposes the ShadowGenerator.\n * Returns nothing.\n */\n dispose() {\n super.dispose();\n if (this._freezeShadowCastersBoundingInfoObservable) {\n this._scene.onBeforeRenderObservable.remove(this._freezeShadowCastersBoundingInfoObservable);\n this._freezeShadowCastersBoundingInfoObservable = null;\n }\n if (this._depthReducer) {\n this._depthReducer.dispose();\n this._depthReducer = null;\n }\n }\n /**\n * Serializes the shadow generator setup to a json object.\n * @returns The serialized JSON object\n */\n serialize() {\n const serializationObject = super.serialize();\n const shadowMap = this.getShadowMap();\n if (!shadowMap) {\n return serializationObject;\n }\n serializationObject.numCascades = this._numCascades;\n serializationObject.debug = this._debug;\n serializationObject.stabilizeCascades = this.stabilizeCascades;\n serializationObject.lambda = this._lambda;\n serializationObject.cascadeBlendPercentage = this.cascadeBlendPercentage;\n serializationObject.depthClamp = this._depthClamp;\n serializationObject.autoCalcDepthBounds = this.autoCalcDepthBounds;\n serializationObject.shadowMaxZ = this._shadowMaxZ;\n serializationObject.penumbraDarkness = this.penumbraDarkness;\n serializationObject.freezeShadowCastersBoundingInfo = this._freezeShadowCastersBoundingInfo;\n serializationObject.minDistance = this.minDistance;\n serializationObject.maxDistance = this.maxDistance;\n serializationObject.renderList = [];\n if (shadowMap.renderList) {\n for (let meshIndex = 0; meshIndex < shadowMap.renderList.length; meshIndex++) {\n const mesh = shadowMap.renderList[meshIndex];\n serializationObject.renderList.push(mesh.id);\n }\n }\n return serializationObject;\n }\n /**\n * Parses a serialized ShadowGenerator and returns a new ShadowGenerator.\n * @param parsedShadowGenerator The JSON object to parse\n * @param scene The scene to create the shadow map for\n * @returns The parsed shadow generator\n */\n static Parse(parsedShadowGenerator, scene) {\n const shadowGenerator = ShadowGenerator.Parse(parsedShadowGenerator, scene, (mapSize, light, camera) => new CascadedShadowGenerator(mapSize, light, undefined, camera));\n if (parsedShadowGenerator.numCascades !== undefined) {\n shadowGenerator.numCascades = parsedShadowGenerator.numCascades;\n }\n if (parsedShadowGenerator.debug !== undefined) {\n shadowGenerator.debug = parsedShadowGenerator.debug;\n }\n if (parsedShadowGenerator.stabilizeCascades !== undefined) {\n shadowGenerator.stabilizeCascades = parsedShadowGenerator.stabilizeCascades;\n }\n if (parsedShadowGenerator.lambda !== undefined) {\n shadowGenerator.lambda = parsedShadowGenerator.lambda;\n }\n if (parsedShadowGenerator.cascadeBlendPercentage !== undefined) {\n shadowGenerator.cascadeBlendPercentage = parsedShadowGenerator.cascadeBlendPercentage;\n }\n if (parsedShadowGenerator.depthClamp !== undefined) {\n shadowGenerator.depthClamp = parsedShadowGenerator.depthClamp;\n }\n if (parsedShadowGenerator.autoCalcDepthBounds !== undefined) {\n shadowGenerator.autoCalcDepthBounds = parsedShadowGenerator.autoCalcDepthBounds;\n }\n if (parsedShadowGenerator.shadowMaxZ !== undefined) {\n shadowGenerator.shadowMaxZ = parsedShadowGenerator.shadowMaxZ;\n }\n if (parsedShadowGenerator.penumbraDarkness !== undefined) {\n shadowGenerator.penumbraDarkness = parsedShadowGenerator.penumbraDarkness;\n }\n if (parsedShadowGenerator.freezeShadowCastersBoundingInfo !== undefined) {\n shadowGenerator.freezeShadowCastersBoundingInfo = parsedShadowGenerator.freezeShadowCastersBoundingInfo;\n }\n if (parsedShadowGenerator.minDistance !== undefined && parsedShadowGenerator.maxDistance !== undefined) {\n shadowGenerator.setMinMaxDistance(parsedShadowGenerator.minDistance, parsedShadowGenerator.maxDistance);\n }\n return shadowGenerator;\n }\n}\nCascadedShadowGenerator._FrustumCornersNDCSpace = [new Vector3(-1.0, +1.0, -1.0), new Vector3(+1.0, +1.0, -1.0), new Vector3(+1.0, -1.0, -1.0), new Vector3(-1.0, -1.0, -1.0), new Vector3(-1.0, +1.0, +1.0), new Vector3(+1.0, +1.0, +1.0), new Vector3(+1.0, -1.0, +1.0), new Vector3(-1.0, -1.0, +1.0)];\n/**\n * Name of the CSM class\n */\nCascadedShadowGenerator.CLASSNAME = \"CascadedShadowGenerator\";\n/**\n * Defines the default number of cascades used by the CSM.\n */\nCascadedShadowGenerator.DEFAULT_CASCADES_COUNT = 4;\n/**\n * Defines the minimum number of cascades used by the CSM.\n */\nCascadedShadowGenerator.MIN_CASCADES_COUNT = 2;\n/**\n * Defines the maximum number of cascades used by the CSM.\n */\nCascadedShadowGenerator.MAX_CASCADES_COUNT = 4;\n/**\n * @internal\n */\nCascadedShadowGenerator._SceneComponentInitialization = _ => {\n throw _WarnImport(\"ShadowGeneratorSceneComponent\");\n};","map":{"version":3,"names":["Matrix","Vector3","RenderTargetTexture","_WarnImport","ShadowGenerator","BoundingInfo","DepthReducer","Logger","EngineStore","UpDir","Up","ZeroVec","Zero","tmpv1","tmpv2","tmpMatrix","CascadedShadowGenerator","_validateFilter","filter","FILTER_NONE","FILTER_PCF","FILTER_PCSS","Error","numCascades","_numCascades","value","Math","min","max","MIN_CASCADES_COUNT","MAX_CASCADES_COUNT","recreateShadowMap","_recreateSceneUBOs","freezeShadowCastersBoundingInfo","_freezeShadowCastersBoundingInfo","freeze","_freezeShadowCastersBoundingInfoObservable","_scene","onBeforeRenderObservable","remove","add","_computeShadowCastersBoundingInfo","_scbiMin","copyFromFloats","Number","MAX_VALUE","_scbiMax","_shadowMap","renderList","meshIndex","length","mesh","boundingInfo","getBoundingInfo","boundingBox","minimizeInPlace","minimumWorld","maximizeInPlace","maximumWorld","meshes","isVisible","isEnabled","receiveShadows","_shadowCastersBoundingInfo","reConstruct","shadowCastersBoundingInfo","setMinMaxDistance","_minDistance","_maxDistance","_breaksAreDirty","minDistance","maxDistance","getClassName","CLASSNAME","getCascadeMinExtents","cascadeIndex","_cascadeMinExtents","getCascadeMaxExtents","_cascadeMaxExtents","shadowMaxZ","_getCamera","_shadowMaxZ","camera","minZ","maxZ","_light","_markMeshesAsLightDirty","debug","_debug","dbg","depthClamp","_depthClamp","cascadeBlendPercentage","_cascadeBlendPercentage","lambda","_lambda","getCascadeViewMatrix","cascadeNum","_viewMatrices","getCascadeProjectionMatrix","_projectionMatrices","getCascadeTransformMatrix","_transformMatrices","setDepthRenderer","depthRenderer","_depthRenderer","_depthReducer","autoCalcDepthBounds","_autoCalcDepthBounds","deactivate","onAfterReductionPerformed","minmax","activate","autoCalcDepthBoundsRefreshRate","_this$_depthReducer$d","_this$_depthReducer","getDepthMap","refreshRate","_this$_depthReducer2","splitFrustum","_splitFrustum","near","far","cameraRange","range","ratio","_cascades","p","log","uniform","d","prevBreakDistance","breakDistance","_viewSpaceFrustumsZ","_frustumLengths","_computeMatrices","scene","NormalizeToRef","getShadowDirection","_lightDirection","abs","Dot","z","_cachedDirection","copyFrom","useReverseDepthBuffer","getEngine","_computeFrustumInWorldSpace","_computeCascadeFrustum","subtractToRef","_frustumCenter","addToRef","scale","_shadowCameraPos","LookAtLHToRef","update","OrthoOffCenterLHToRef","x","y","isNDCHalfZRange","multiplyToRef","TransformCoordinatesToRef","scaleInPlace","_mapSize","round","subtractInPlace","TranslationToRef","copyToArray","_transformMatricesAsArray","prevSplitDist","splitDist","getViewMatrix","cameraInfiniteFarPlane","saveCameraMaxZ","getProjectionMatrix","invViewProj","Invert","getTransformationMatrix","cornerIndexOffset","cornerIndex","_FrustumCornersNDCSpace","_frustumCornersWorldSpace","addInPlace","stabilizeCascades","sphereRadius","dist","ceil","lightCameraPos","_disposeSceneUBOs","_sceneUBOs","i","push","createSceneUniformBuffer","name","IsSupported","engine","LastCreatedEngine","_features","supportCSM","constructor","mapSize","light","usefulFloatFirst","useRedTextureType","usePercentageCloserFiltering","_initializeGenerator","_this$penumbraDarknes","_this$_numCascades","_this$stabilizeCascad","_this$_freezeShadowCa","_this$freezeShadowCas","_this$_scbiMin","_this$_scbiMax","_this$_shadowCastersB","_this$_breaksAreDirty","_this$_minDistance","_this$_maxDistance","_this$_currentLayer","_ref","_this$_shadowMaxZ","_this$_getCamera","_this$_debug","_this$_depthClamp","_this$_cascadeBlendPe","_this$_lambda","_this$_autoCalcDepthB","penumbraDarkness","DEFAULT_CASCADES_COUNT","_currentLayer","_createTargetRenderTexture","size","width","height","layers","_textureType","undefined","_useRedTextureType","createDepthStencilTexture","noPrePassRenderer","_initializeShadowMap","Float32Array","Array","_lightSizeUVCorrection","_depthCorrection","onBeforeBindObservable","clear","layer","setSceneUniformBuffer","_filter","setColorWrite","setTransformMatrix","_useUBO","getSceneUniformBuffer","unbindEffect","finalizeSceneUbo","_engine$_debugPushGro","_currentSceneUBO","_debugPushGroup","call","currentRenderPassId","_bindCustomEffectForRenderSubMeshForShadowMap","subMesh","effect","setMatrix","_isReadyCustomDefines","defines","prepareDefines","lightIndex","shadowsEnabled","shadowEnabled","useRightHandedSystem","bindShadowLight","shadowMap","getShadowMap","getSize","setMatrices","setArray","setFloat","setDepthStencilTexture","_uniformBuffer","updateFloat4","getDarkness","frustumEdgeFalloff","setTexture","setArray2","_contactHardeningLightSizeUVRatio","updateFloat2","getLight","getDepthMinZ","getDepthMaxZ","getTransformMatrix","dispose","serialize","serializationObject","id","Parse","parsedShadowGenerator","shadowGenerator","_SceneComponentInitialization","_"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Lights/Shadows/cascadedShadowGenerator.js"],"sourcesContent":["import { Matrix, Vector3 } from \"../../Maths/math.vector.js\";\nimport { RenderTargetTexture } from \"../../Materials/Textures/renderTargetTexture.js\";\n\nimport { _WarnImport } from \"../../Misc/devTools.js\";\nimport { ShadowGenerator } from \"./shadowGenerator.js\";\nimport { BoundingInfo } from \"../../Culling/boundingInfo.js\";\nimport { DepthReducer } from \"../../Misc/depthReducer.js\";\nimport { Logger } from \"../../Misc/logger.js\";\nimport { EngineStore } from \"../../Engines/engineStore.js\";\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst UpDir = Vector3.Up();\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst ZeroVec = Vector3.Zero();\nconst tmpv1 = new Vector3(), tmpv2 = new Vector3(), tmpMatrix = new Matrix();\n/**\n * A CSM implementation allowing casting shadows on large scenes.\n * Documentation : https://doc.babylonjs.com/babylon101/cascadedShadows\n * Based on: https://github.com/TheRealMJP/Shadows and https://johanmedestrom.wordpress.com/2016/03/18/opengl-cascaded-shadow-maps/\n */\nexport class CascadedShadowGenerator extends ShadowGenerator {\n _validateFilter(filter) {\n if (filter === ShadowGenerator.FILTER_NONE || filter === ShadowGenerator.FILTER_PCF || filter === ShadowGenerator.FILTER_PCSS) {\n return filter;\n }\n Logger.Error('Unsupported filter \"' + filter + '\"!');\n return ShadowGenerator.FILTER_NONE;\n }\n /**\n * Gets or set the number of cascades used by the CSM.\n */\n get numCascades() {\n return this._numCascades;\n }\n set numCascades(value) {\n value = Math.min(Math.max(value, CascadedShadowGenerator.MIN_CASCADES_COUNT), CascadedShadowGenerator.MAX_CASCADES_COUNT);\n if (value === this._numCascades) {\n return;\n }\n this._numCascades = value;\n this.recreateShadowMap();\n this._recreateSceneUBOs();\n }\n /**\n * Enables or disables the shadow casters bounding info computation.\n * If your shadow casters don't move, you can disable this feature.\n * If it is enabled, the bounding box computation is done every frame.\n */\n get freezeShadowCastersBoundingInfo() {\n return this._freezeShadowCastersBoundingInfo;\n }\n set freezeShadowCastersBoundingInfo(freeze) {\n if (this._freezeShadowCastersBoundingInfoObservable && freeze) {\n this._scene.onBeforeRenderObservable.remove(this._freezeShadowCastersBoundingInfoObservable);\n this._freezeShadowCastersBoundingInfoObservable = null;\n }\n if (!this._freezeShadowCastersBoundingInfoObservable && !freeze) {\n this._freezeShadowCastersBoundingInfoObservable = this._scene.onBeforeRenderObservable.add(() => this._computeShadowCastersBoundingInfo());\n }\n this._freezeShadowCastersBoundingInfo = freeze;\n if (freeze) {\n this._computeShadowCastersBoundingInfo();\n }\n }\n _computeShadowCastersBoundingInfo() {\n this._scbiMin.copyFromFloats(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n this._scbiMax.copyFromFloats(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);\n if (this._shadowMap && this._shadowMap.renderList) {\n const renderList = this._shadowMap.renderList;\n for (let meshIndex = 0; meshIndex < renderList.length; meshIndex++) {\n const mesh = renderList[meshIndex];\n if (!mesh) {\n continue;\n }\n const boundingInfo = mesh.getBoundingInfo(), boundingBox = boundingInfo.boundingBox;\n this._scbiMin.minimizeInPlace(boundingBox.minimumWorld);\n this._scbiMax.maximizeInPlace(boundingBox.maximumWorld);\n }\n const meshes = this._scene.meshes;\n for (let meshIndex = 0; meshIndex < meshes.length; meshIndex++) {\n const mesh = meshes[meshIndex];\n if (!mesh || !mesh.isVisible || !mesh.isEnabled || !mesh.receiveShadows) {\n continue;\n }\n const boundingInfo = mesh.getBoundingInfo(), boundingBox = boundingInfo.boundingBox;\n this._scbiMin.minimizeInPlace(boundingBox.minimumWorld);\n this._scbiMax.maximizeInPlace(boundingBox.maximumWorld);\n }\n }\n this._shadowCastersBoundingInfo.reConstruct(this._scbiMin, this._scbiMax);\n }\n /**\n * Gets or sets the shadow casters bounding info.\n * If you provide your own shadow casters bounding info, first enable freezeShadowCastersBoundingInfo\n * so that the system won't overwrite the bounds you provide\n */\n get shadowCastersBoundingInfo() {\n return this._shadowCastersBoundingInfo;\n }\n set shadowCastersBoundingInfo(boundingInfo) {\n this._shadowCastersBoundingInfo = boundingInfo;\n }\n /**\n * Sets the minimal and maximal distances to use when computing the cascade breaks.\n *\n * The values of min / max are typically the depth zmin and zmax values of your scene, for a given frame.\n * If you don't know these values, simply leave them to their defaults and don't call this function.\n * @param min minimal distance for the breaks (default to 0.)\n * @param max maximal distance for the breaks (default to 1.)\n */\n setMinMaxDistance(min, max) {\n if (this._minDistance === min && this._maxDistance === max) {\n return;\n }\n if (min > max) {\n min = 0;\n max = 1;\n }\n if (min < 0) {\n min = 0;\n }\n if (max > 1) {\n max = 1;\n }\n this._minDistance = min;\n this._maxDistance = max;\n this._breaksAreDirty = true;\n }\n /** Gets the minimal distance used in the cascade break computation */\n get minDistance() {\n return this._minDistance;\n }\n /** Gets the maximal distance used in the cascade break computation */\n get maxDistance() {\n return this._maxDistance;\n }\n /**\n * Gets the class name of that object\n * @returns \"CascadedShadowGenerator\"\n */\n getClassName() {\n return CascadedShadowGenerator.CLASSNAME;\n }\n /**\n * Gets a cascade minimum extents\n * @param cascadeIndex index of the cascade\n * @returns the minimum cascade extents\n */\n getCascadeMinExtents(cascadeIndex) {\n return cascadeIndex >= 0 && cascadeIndex < this._numCascades ? this._cascadeMinExtents[cascadeIndex] : null;\n }\n /**\n * Gets a cascade maximum extents\n * @param cascadeIndex index of the cascade\n * @returns the maximum cascade extents\n */\n getCascadeMaxExtents(cascadeIndex) {\n return cascadeIndex >= 0 && cascadeIndex < this._numCascades ? this._cascadeMaxExtents[cascadeIndex] : null;\n }\n /**\n * Gets the shadow max z distance. It's the limit beyond which shadows are not displayed.\n * It defaults to camera.maxZ\n */\n get shadowMaxZ() {\n if (!this._getCamera()) {\n return 0;\n }\n return this._shadowMaxZ;\n }\n /**\n * Sets the shadow max z distance.\n */\n set shadowMaxZ(value) {\n const camera = this._getCamera();\n if (!camera) {\n this._shadowMaxZ = value;\n return;\n }\n if (this._shadowMaxZ === value || value < camera.minZ || (value > camera.maxZ && camera.maxZ !== 0)) {\n return;\n }\n this._shadowMaxZ = value;\n this._light._markMeshesAsLightDirty();\n this._breaksAreDirty = true;\n }\n /**\n * Gets or sets the debug flag.\n * When enabled, the cascades are materialized by different colors on the screen.\n */\n get debug() {\n return this._debug;\n }\n set debug(dbg) {\n this._debug = dbg;\n this._light._markMeshesAsLightDirty();\n }\n /**\n * Gets or sets the depth clamping value.\n *\n * When enabled, it improves the shadow quality because the near z plane of the light frustum don't need to be adjusted\n * to account for the shadow casters far away.\n *\n * Note that this property is incompatible with PCSS filtering, so it won't be used in that case.\n */\n get depthClamp() {\n return this._depthClamp;\n }\n set depthClamp(value) {\n this._depthClamp = value;\n }\n /**\n * Gets or sets the percentage of blending between two cascades (value between 0. and 1.).\n * It defaults to 0.1 (10% blending).\n */\n get cascadeBlendPercentage() {\n return this._cascadeBlendPercentage;\n }\n set cascadeBlendPercentage(value) {\n this._cascadeBlendPercentage = value;\n this._light._markMeshesAsLightDirty();\n }\n /**\n * Gets or set the lambda parameter.\n * This parameter is used to split the camera frustum and create the cascades.\n * It's a value between 0. and 1.: If 0, the split is a uniform split of the frustum, if 1 it is a logarithmic split.\n * For all values in-between, it's a linear combination of the uniform and logarithm split algorithm.\n */\n get lambda() {\n return this._lambda;\n }\n set lambda(value) {\n const lambda = Math.min(Math.max(value, 0), 1);\n if (this._lambda == lambda) {\n return;\n }\n this._lambda = lambda;\n this._breaksAreDirty = true;\n }\n /**\n * Gets the view matrix corresponding to a given cascade\n * @param cascadeNum cascade to retrieve the view matrix from\n * @returns the cascade view matrix\n */\n getCascadeViewMatrix(cascadeNum) {\n return cascadeNum >= 0 && cascadeNum < this._numCascades ? this._viewMatrices[cascadeNum] : null;\n }\n /**\n * Gets the projection matrix corresponding to a given cascade\n * @param cascadeNum cascade to retrieve the projection matrix from\n * @returns the cascade projection matrix\n */\n getCascadeProjectionMatrix(cascadeNum) {\n return cascadeNum >= 0 && cascadeNum < this._numCascades ? this._projectionMatrices[cascadeNum] : null;\n }\n /**\n * Gets the transformation matrix corresponding to a given cascade\n * @param cascadeNum cascade to retrieve the transformation matrix from\n * @returns the cascade transformation matrix\n */\n getCascadeTransformMatrix(cascadeNum) {\n return cascadeNum >= 0 && cascadeNum < this._numCascades ? this._transformMatrices[cascadeNum] : null;\n }\n /**\n * Sets the depth renderer to use when autoCalcDepthBounds is enabled.\n *\n * Note that if no depth renderer is set, a new one will be automatically created internally when necessary.\n *\n * You should call this function if you already have a depth renderer enabled in your scene, to avoid\n * doing multiple depth rendering each frame. If you provide your own depth renderer, make sure it stores linear depth!\n * @param depthRenderer The depth renderer to use when autoCalcDepthBounds is enabled. If you pass null or don't call this function at all, a depth renderer will be automatically created\n */\n setDepthRenderer(depthRenderer) {\n this._depthRenderer = depthRenderer;\n if (this._depthReducer) {\n this._depthReducer.setDepthRenderer(this._depthRenderer);\n }\n }\n /**\n * Gets or sets the autoCalcDepthBounds property.\n *\n * When enabled, a depth rendering pass is first performed (with an internally created depth renderer or with the one\n * you provide by calling setDepthRenderer). Then, a min/max reducing is applied on the depth map to compute the\n * minimal and maximal depth of the map and those values are used as inputs for the setMinMaxDistance() function.\n * It can greatly enhance the shadow quality, at the expense of more GPU works.\n * When using this option, you should increase the value of the lambda parameter, and even set it to 1 for best results.\n */\n get autoCalcDepthBounds() {\n return this._autoCalcDepthBounds;\n }\n set autoCalcDepthBounds(value) {\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n this._autoCalcDepthBounds = value;\n if (!value) {\n if (this._depthReducer) {\n this._depthReducer.deactivate();\n }\n this.setMinMaxDistance(0, 1);\n return;\n }\n if (!this._depthReducer) {\n this._depthReducer = new DepthReducer(camera);\n this._depthReducer.onAfterReductionPerformed.add((minmax) => {\n let min = minmax.min, max = minmax.max;\n if (min >= max) {\n min = 0;\n max = 1;\n }\n if (min != this._minDistance || max != this._maxDistance) {\n this.setMinMaxDistance(min, max);\n }\n });\n this._depthReducer.setDepthRenderer(this._depthRenderer);\n }\n this._depthReducer.activate();\n }\n /**\n * Defines the refresh rate of the min/max computation used when autoCalcDepthBounds is set to true\n * Use 0 to compute just once, 1 to compute on every frame, 2 to compute every two frames and so on...\n * Note that if you provided your own depth renderer through a call to setDepthRenderer, you are responsible\n * for setting the refresh rate on the renderer yourself!\n */\n get autoCalcDepthBoundsRefreshRate() {\n return this._depthReducer?.depthRenderer?.getDepthMap().refreshRate ?? -1;\n }\n set autoCalcDepthBoundsRefreshRate(value) {\n if (this._depthReducer?.depthRenderer) {\n this._depthReducer.depthRenderer.getDepthMap().refreshRate = value;\n }\n }\n /**\n * Create the cascade breaks according to the lambda, shadowMaxZ and min/max distance properties, as well as the camera near and far planes.\n * This function is automatically called when updating lambda, shadowMaxZ and min/max distances, however you should call it yourself if\n * you change the camera near/far planes!\n */\n splitFrustum() {\n this._breaksAreDirty = true;\n }\n _splitFrustum() {\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n const near = camera.minZ, far = camera.maxZ || this._shadowMaxZ, // account for infinite far plane (ie. maxZ = 0)\n cameraRange = far - near, minDistance = this._minDistance, maxDistance = this._shadowMaxZ < far && this._shadowMaxZ >= near ? Math.min((this._shadowMaxZ - near) / (far - near), this._maxDistance) : this._maxDistance;\n const minZ = near + minDistance * cameraRange, maxZ = near + maxDistance * cameraRange;\n const range = maxZ - minZ, ratio = maxZ / minZ;\n for (let cascadeIndex = 0; cascadeIndex < this._cascades.length; ++cascadeIndex) {\n const p = (cascadeIndex + 1) / this._numCascades, log = minZ * ratio ** p, uniform = minZ + range * p;\n const d = this._lambda * (log - uniform) + uniform;\n this._cascades[cascadeIndex].prevBreakDistance = cascadeIndex === 0 ? minDistance : this._cascades[cascadeIndex - 1].breakDistance;\n this._cascades[cascadeIndex].breakDistance = (d - near) / cameraRange;\n this._viewSpaceFrustumsZ[cascadeIndex] = d;\n this._frustumLengths[cascadeIndex] = (this._cascades[cascadeIndex].breakDistance - this._cascades[cascadeIndex].prevBreakDistance) * cameraRange;\n }\n this._breaksAreDirty = false;\n }\n _computeMatrices() {\n const scene = this._scene;\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n Vector3.NormalizeToRef(this._light.getShadowDirection(0), this._lightDirection);\n if (Math.abs(Vector3.Dot(this._lightDirection, Vector3.Up())) === 1.0) {\n this._lightDirection.z = 0.0000000000001; // Required to avoid perfectly perpendicular light\n }\n this._cachedDirection.copyFrom(this._lightDirection);\n const useReverseDepthBuffer = scene.getEngine().useReverseDepthBuffer;\n for (let cascadeIndex = 0; cascadeIndex < this._numCascades; ++cascadeIndex) {\n this._computeFrustumInWorldSpace(cascadeIndex);\n this._computeCascadeFrustum(cascadeIndex);\n this._cascadeMaxExtents[cascadeIndex].subtractToRef(this._cascadeMinExtents[cascadeIndex], tmpv1); // tmpv1 = cascadeExtents\n // Get position of the shadow camera\n this._frustumCenter[cascadeIndex].addToRef(this._lightDirection.scale(this._cascadeMinExtents[cascadeIndex].z), this._shadowCameraPos[cascadeIndex]);\n // Come up with a new orthographic camera for the shadow caster\n Matrix.LookAtLHToRef(this._shadowCameraPos[cascadeIndex], this._frustumCenter[cascadeIndex], UpDir, this._viewMatrices[cascadeIndex]);\n let minZ = 0, maxZ = tmpv1.z;\n // Try to tighten minZ and maxZ based on the bounding box of the shadow casters\n const boundingInfo = this._shadowCastersBoundingInfo;\n boundingInfo.update(this._viewMatrices[cascadeIndex]);\n maxZ = Math.min(maxZ, boundingInfo.boundingBox.maximumWorld.z);\n if (!this._depthClamp || this.filter === ShadowGenerator.FILTER_PCSS) {\n // If we don't use depth clamping, we must set minZ so that all shadow casters are in the light frustum\n minZ = Math.min(minZ, boundingInfo.boundingBox.minimumWorld.z);\n }\n else {\n // If using depth clamping, we can adjust minZ to reduce the [minZ, maxZ] range (and get some additional precision in the shadow map)\n minZ = Math.max(minZ, boundingInfo.boundingBox.minimumWorld.z);\n }\n Matrix.OrthoOffCenterLHToRef(this._cascadeMinExtents[cascadeIndex].x, this._cascadeMaxExtents[cascadeIndex].x, this._cascadeMinExtents[cascadeIndex].y, this._cascadeMaxExtents[cascadeIndex].y, useReverseDepthBuffer ? maxZ : minZ, useReverseDepthBuffer ? minZ : maxZ, this._projectionMatrices[cascadeIndex], scene.getEngine().isNDCHalfZRange);\n this._cascadeMinExtents[cascadeIndex].z = minZ;\n this._cascadeMaxExtents[cascadeIndex].z = maxZ;\n this._viewMatrices[cascadeIndex].multiplyToRef(this._projectionMatrices[cascadeIndex], this._transformMatrices[cascadeIndex]);\n // Create the rounding matrix, by projecting the world-space origin and determining\n // the fractional offset in texel space\n Vector3.TransformCoordinatesToRef(ZeroVec, this._transformMatrices[cascadeIndex], tmpv1); // tmpv1 = shadowOrigin\n tmpv1.scaleInPlace(this._mapSize / 2);\n tmpv2.copyFromFloats(Math.round(tmpv1.x), Math.round(tmpv1.y), Math.round(tmpv1.z)); // tmpv2 = roundedOrigin\n tmpv2.subtractInPlace(tmpv1).scaleInPlace(2 / this._mapSize); // tmpv2 = roundOffset\n Matrix.TranslationToRef(tmpv2.x, tmpv2.y, 0.0, tmpMatrix);\n this._projectionMatrices[cascadeIndex].multiplyToRef(tmpMatrix, this._projectionMatrices[cascadeIndex]);\n this._viewMatrices[cascadeIndex].multiplyToRef(this._projectionMatrices[cascadeIndex], this._transformMatrices[cascadeIndex]);\n this._transformMatrices[cascadeIndex].copyToArray(this._transformMatricesAsArray, cascadeIndex * 16);\n }\n }\n // Get the 8 points of the view frustum in world space\n _computeFrustumInWorldSpace(cascadeIndex) {\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n const prevSplitDist = this._cascades[cascadeIndex].prevBreakDistance, splitDist = this._cascades[cascadeIndex].breakDistance;\n const isNDCHalfZRange = this._scene.getEngine().isNDCHalfZRange;\n camera.getViewMatrix(); // make sure the transformation matrix we get when calling 'getTransformationMatrix()' is calculated with an up to date view matrix\n const cameraInfiniteFarPlane = camera.maxZ === 0;\n const saveCameraMaxZ = camera.maxZ;\n if (cameraInfiniteFarPlane) {\n camera.maxZ = this._shadowMaxZ;\n camera.getProjectionMatrix(true);\n }\n const invViewProj = Matrix.Invert(camera.getTransformationMatrix());\n if (cameraInfiniteFarPlane) {\n camera.maxZ = saveCameraMaxZ;\n camera.getProjectionMatrix(true);\n }\n const cornerIndexOffset = this._scene.getEngine().useReverseDepthBuffer ? 4 : 0;\n for (let cornerIndex = 0; cornerIndex < CascadedShadowGenerator._FrustumCornersNDCSpace.length; ++cornerIndex) {\n tmpv1.copyFrom(CascadedShadowGenerator._FrustumCornersNDCSpace[(cornerIndex + cornerIndexOffset) % CascadedShadowGenerator._FrustumCornersNDCSpace.length]);\n if (isNDCHalfZRange && tmpv1.z === -1) {\n tmpv1.z = 0;\n }\n Vector3.TransformCoordinatesToRef(tmpv1, invViewProj, this._frustumCornersWorldSpace[cascadeIndex][cornerIndex]);\n }\n // Get the corners of the current cascade slice of the view frustum\n for (let cornerIndex = 0; cornerIndex < CascadedShadowGenerator._FrustumCornersNDCSpace.length / 2; ++cornerIndex) {\n tmpv1.copyFrom(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex + 4]).subtractInPlace(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex]);\n tmpv2.copyFrom(tmpv1).scaleInPlace(prevSplitDist); // near corner ray\n tmpv1.scaleInPlace(splitDist); // far corner ray\n tmpv1.addInPlace(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex]);\n this._frustumCornersWorldSpace[cascadeIndex][cornerIndex + 4].copyFrom(tmpv1);\n this._frustumCornersWorldSpace[cascadeIndex][cornerIndex].addInPlace(tmpv2);\n }\n }\n _computeCascadeFrustum(cascadeIndex) {\n this._cascadeMinExtents[cascadeIndex].copyFromFloats(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n this._cascadeMaxExtents[cascadeIndex].copyFromFloats(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);\n this._frustumCenter[cascadeIndex].copyFromFloats(0, 0, 0);\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n // Calculate the centroid of the view frustum slice\n for (let cornerIndex = 0; cornerIndex < this._frustumCornersWorldSpace[cascadeIndex].length; ++cornerIndex) {\n this._frustumCenter[cascadeIndex].addInPlace(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex]);\n }\n this._frustumCenter[cascadeIndex].scaleInPlace(1 / this._frustumCornersWorldSpace[cascadeIndex].length);\n if (this.stabilizeCascades) {\n // Calculate the radius of a bounding sphere surrounding the frustum corners\n let sphereRadius = 0;\n for (let cornerIndex = 0; cornerIndex < this._frustumCornersWorldSpace[cascadeIndex].length; ++cornerIndex) {\n const dist = this._frustumCornersWorldSpace[cascadeIndex][cornerIndex].subtractToRef(this._frustumCenter[cascadeIndex], tmpv1).length();\n sphereRadius = Math.max(sphereRadius, dist);\n }\n sphereRadius = Math.ceil(sphereRadius * 16) / 16;\n this._cascadeMaxExtents[cascadeIndex].copyFromFloats(sphereRadius, sphereRadius, sphereRadius);\n this._cascadeMinExtents[cascadeIndex].copyFromFloats(-sphereRadius, -sphereRadius, -sphereRadius);\n }\n else {\n // Create a temporary view matrix for the light\n const lightCameraPos = this._frustumCenter[cascadeIndex];\n this._frustumCenter[cascadeIndex].addToRef(this._lightDirection, tmpv1); // tmpv1 = look at\n Matrix.LookAtLHToRef(lightCameraPos, tmpv1, UpDir, tmpMatrix); // matrix = lightView\n // Calculate an AABB around the frustum corners\n for (let cornerIndex = 0; cornerIndex < this._frustumCornersWorldSpace[cascadeIndex].length; ++cornerIndex) {\n Vector3.TransformCoordinatesToRef(this._frustumCornersWorldSpace[cascadeIndex][cornerIndex], tmpMatrix, tmpv1);\n this._cascadeMinExtents[cascadeIndex].minimizeInPlace(tmpv1);\n this._cascadeMaxExtents[cascadeIndex].maximizeInPlace(tmpv1);\n }\n }\n }\n _recreateSceneUBOs() {\n this._disposeSceneUBOs();\n if (this._sceneUBOs) {\n for (let i = 0; i < this._numCascades; ++i) {\n this._sceneUBOs.push(this._scene.createSceneUniformBuffer(`Scene for CSM Shadow Generator (light \"${this._light.name}\" cascade #${i})`));\n }\n }\n }\n /**\n * Support test.\n */\n static get IsSupported() {\n const engine = EngineStore.LastCreatedEngine;\n if (!engine) {\n return false;\n }\n return engine._features.supportCSM;\n }\n /**\n * Creates a Cascaded Shadow Generator object.\n * A ShadowGenerator is the required tool to use the shadows.\n * Each directional light casting shadows needs to use its own ShadowGenerator.\n * Documentation : https://doc.babylonjs.com/babylon101/cascadedShadows\n * @param mapSize The size of the texture what stores the shadows. Example : 1024.\n * @param light The directional light object generating the shadows.\n * @param usefulFloatFirst By default the generator will try to use half float textures but if you need precision (for self shadowing for instance), you can use this option to enforce full float texture.\n * @param camera Camera associated with this shadow generator (default: null). If null, takes the scene active camera at the time we need to access it\n * @param useRedTextureType Forces the generator to use a Red instead of a RGBA type for the shadow map texture format (default: true)\n */\n constructor(mapSize, light, usefulFloatFirst, camera, useRedTextureType = true) {\n if (!CascadedShadowGenerator.IsSupported) {\n Logger.Error(\"CascadedShadowMap is not supported by the current engine.\");\n return;\n }\n super(mapSize, light, usefulFloatFirst, camera, useRedTextureType);\n this.usePercentageCloserFiltering = true;\n }\n _initializeGenerator() {\n this.penumbraDarkness = this.penumbraDarkness ?? 1.0;\n this._numCascades = this._numCascades ?? CascadedShadowGenerator.DEFAULT_CASCADES_COUNT;\n this.stabilizeCascades = this.stabilizeCascades ?? false;\n this._freezeShadowCastersBoundingInfoObservable = this._freezeShadowCastersBoundingInfoObservable ?? null;\n this.freezeShadowCastersBoundingInfo = this.freezeShadowCastersBoundingInfo ?? false;\n this._scbiMin = this._scbiMin ?? new Vector3(0, 0, 0);\n this._scbiMax = this._scbiMax ?? new Vector3(0, 0, 0);\n this._shadowCastersBoundingInfo = this._shadowCastersBoundingInfo ?? new BoundingInfo(new Vector3(0, 0, 0), new Vector3(0, 0, 0));\n this._breaksAreDirty = this._breaksAreDirty ?? true;\n this._minDistance = this._minDistance ?? 0;\n this._maxDistance = this._maxDistance ?? 1;\n this._currentLayer = this._currentLayer ?? 0;\n this._shadowMaxZ = this._shadowMaxZ ?? this._getCamera()?.maxZ ?? 10000;\n this._debug = this._debug ?? false;\n this._depthClamp = this._depthClamp ?? true;\n this._cascadeBlendPercentage = this._cascadeBlendPercentage ?? 0.1;\n this._lambda = this._lambda ?? 0.5;\n this._autoCalcDepthBounds = this._autoCalcDepthBounds ?? false;\n this._recreateSceneUBOs();\n super._initializeGenerator();\n }\n _createTargetRenderTexture() {\n const engine = this._scene.getEngine();\n const size = { width: this._mapSize, height: this._mapSize, layers: this.numCascades };\n this._shadowMap = new RenderTargetTexture(this._light.name + \"_CSMShadowMap\", size, this._scene, false, true, this._textureType, false, undefined, false, false, undefined, this._useRedTextureType ? 6 : 5);\n this._shadowMap.createDepthStencilTexture(engine.useReverseDepthBuffer ? 516 : 513, true, undefined, undefined, undefined, `DepthStencilForCSMShadowGenerator-${this._light.name}`);\n this._shadowMap.noPrePassRenderer = true;\n }\n _initializeShadowMap() {\n super._initializeShadowMap();\n if (this._shadowMap === null) {\n return;\n }\n this._transformMatricesAsArray = new Float32Array(this._numCascades * 16);\n this._viewSpaceFrustumsZ = new Array(this._numCascades);\n this._frustumLengths = new Array(this._numCascades);\n this._lightSizeUVCorrection = new Array(this._numCascades * 2);\n this._depthCorrection = new Array(this._numCascades);\n this._cascades = [];\n this._viewMatrices = [];\n this._projectionMatrices = [];\n this._transformMatrices = [];\n this._cascadeMinExtents = [];\n this._cascadeMaxExtents = [];\n this._frustumCenter = [];\n this._shadowCameraPos = [];\n this._frustumCornersWorldSpace = [];\n for (let cascadeIndex = 0; cascadeIndex < this._numCascades; ++cascadeIndex) {\n this._cascades[cascadeIndex] = {\n prevBreakDistance: 0,\n breakDistance: 0,\n };\n this._viewMatrices[cascadeIndex] = Matrix.Zero();\n this._projectionMatrices[cascadeIndex] = Matrix.Zero();\n this._transformMatrices[cascadeIndex] = Matrix.Zero();\n this._cascadeMinExtents[cascadeIndex] = new Vector3();\n this._cascadeMaxExtents[cascadeIndex] = new Vector3();\n this._frustumCenter[cascadeIndex] = new Vector3();\n this._shadowCameraPos[cascadeIndex] = new Vector3();\n this._frustumCornersWorldSpace[cascadeIndex] = new Array(CascadedShadowGenerator._FrustumCornersNDCSpace.length);\n for (let i = 0; i < CascadedShadowGenerator._FrustumCornersNDCSpace.length; ++i) {\n this._frustumCornersWorldSpace[cascadeIndex][i] = new Vector3();\n }\n }\n const engine = this._scene.getEngine();\n this._shadowMap.onBeforeBindObservable.clear();\n this._shadowMap.onBeforeRenderObservable.clear();\n this._shadowMap.onBeforeRenderObservable.add((layer) => {\n if (this._sceneUBOs) {\n this._scene.setSceneUniformBuffer(this._sceneUBOs[layer]);\n }\n this._currentLayer = layer;\n if (this._filter === ShadowGenerator.FILTER_PCF) {\n engine.setColorWrite(false);\n }\n this._scene.setTransformMatrix(this.getCascadeViewMatrix(layer), this.getCascadeProjectionMatrix(layer));\n if (this._useUBO) {\n this._scene.getSceneUniformBuffer().unbindEffect();\n this._scene.finalizeSceneUbo();\n }\n });\n this._shadowMap.onBeforeBindObservable.add(() => {\n this._currentSceneUBO = this._scene.getSceneUniformBuffer();\n engine._debugPushGroup?.(`cascaded shadow map generation for pass id ${engine.currentRenderPassId}`, 1);\n if (this._breaksAreDirty) {\n this._splitFrustum();\n }\n this._computeMatrices();\n });\n this._splitFrustum();\n }\n _bindCustomEffectForRenderSubMeshForShadowMap(subMesh, effect) {\n effect.setMatrix(\"viewProjection\", this.getCascadeTransformMatrix(this._currentLayer));\n }\n _isReadyCustomDefines(defines) {\n defines.push(\"#define SM_DEPTHCLAMP \" + (this._depthClamp && this._filter !== ShadowGenerator.FILTER_PCSS ? \"1\" : \"0\"));\n }\n /**\n * Prepare all the defines in a material relying on a shadow map at the specified light index.\n * @param defines Defines of the material we want to update\n * @param lightIndex Index of the light in the enabled light list of the material\n */\n prepareDefines(defines, lightIndex) {\n super.prepareDefines(defines, lightIndex);\n const scene = this._scene;\n const light = this._light;\n if (!scene.shadowsEnabled || !light.shadowEnabled) {\n return;\n }\n defines[\"SHADOWCSM\" + lightIndex] = true;\n defines[\"SHADOWCSMDEBUG\" + lightIndex] = this.debug;\n defines[\"SHADOWCSMNUM_CASCADES\" + lightIndex] = this.numCascades;\n defines[\"SHADOWCSM_RIGHTHANDED\" + lightIndex] = scene.useRightHandedSystem;\n const camera = this._getCamera();\n if (camera && this._shadowMaxZ <= (camera.maxZ || this._shadowMaxZ)) {\n defines[\"SHADOWCSMUSESHADOWMAXZ\" + lightIndex] = true;\n }\n if (this.cascadeBlendPercentage === 0) {\n defines[\"SHADOWCSMNOBLEND\" + lightIndex] = true;\n }\n }\n /**\n * Binds the shadow related information inside of an effect (information like near, far, darkness...\n * defined in the generator but impacting the effect).\n * @param lightIndex Index of the light in the enabled light list of the material owning the effect\n * @param effect The effect we are binfing the information for\n */\n bindShadowLight(lightIndex, effect) {\n const light = this._light;\n const scene = this._scene;\n if (!scene.shadowsEnabled || !light.shadowEnabled) {\n return;\n }\n const camera = this._getCamera();\n if (!camera) {\n return;\n }\n const shadowMap = this.getShadowMap();\n if (!shadowMap) {\n return;\n }\n const width = shadowMap.getSize().width;\n effect.setMatrices(\"lightMatrix\" + lightIndex, this._transformMatricesAsArray);\n effect.setArray(\"viewFrustumZ\" + lightIndex, this._viewSpaceFrustumsZ);\n effect.setFloat(\"cascadeBlendFactor\" + lightIndex, this.cascadeBlendPercentage === 0 ? 10000 : 1 / this.cascadeBlendPercentage);\n effect.setArray(\"frustumLengths\" + lightIndex, this._frustumLengths);\n // Only PCF uses depth stencil texture.\n if (this._filter === ShadowGenerator.FILTER_PCF) {\n effect.setDepthStencilTexture(\"shadowTexture\" + lightIndex, shadowMap);\n light._uniformBuffer.updateFloat4(\"shadowsInfo\", this.getDarkness(), width, 1 / width, this.frustumEdgeFalloff, lightIndex);\n }\n else if (this._filter === ShadowGenerator.FILTER_PCSS) {\n for (let cascadeIndex = 0; cascadeIndex < this._numCascades; ++cascadeIndex) {\n this._lightSizeUVCorrection[cascadeIndex * 2 + 0] =\n cascadeIndex === 0\n ? 1\n : (this._cascadeMaxExtents[0].x - this._cascadeMinExtents[0].x) / (this._cascadeMaxExtents[cascadeIndex].x - this._cascadeMinExtents[cascadeIndex].x); // x correction\n this._lightSizeUVCorrection[cascadeIndex * 2 + 1] =\n cascadeIndex === 0\n ? 1\n : (this._cascadeMaxExtents[0].y - this._cascadeMinExtents[0].y) / (this._cascadeMaxExtents[cascadeIndex].y - this._cascadeMinExtents[cascadeIndex].y); // y correction\n this._depthCorrection[cascadeIndex] =\n cascadeIndex === 0\n ? 1\n : (this._cascadeMaxExtents[cascadeIndex].z - this._cascadeMinExtents[cascadeIndex].z) / (this._cascadeMaxExtents[0].z - this._cascadeMinExtents[0].z);\n }\n effect.setDepthStencilTexture(\"shadowTexture\" + lightIndex, shadowMap);\n effect.setTexture(\"depthTexture\" + lightIndex, shadowMap);\n effect.setArray2(\"lightSizeUVCorrection\" + lightIndex, this._lightSizeUVCorrection);\n effect.setArray(\"depthCorrection\" + lightIndex, this._depthCorrection);\n effect.setFloat(\"penumbraDarkness\" + lightIndex, this.penumbraDarkness);\n light._uniformBuffer.updateFloat4(\"shadowsInfo\", this.getDarkness(), 1 / width, this._contactHardeningLightSizeUVRatio * width, this.frustumEdgeFalloff, lightIndex);\n }\n else {\n effect.setTexture(\"shadowTexture\" + lightIndex, shadowMap);\n light._uniformBuffer.updateFloat4(\"shadowsInfo\", this.getDarkness(), width, 1 / width, this.frustumEdgeFalloff, lightIndex);\n }\n light._uniformBuffer.updateFloat2(\"depthValues\", this.getLight().getDepthMinZ(camera), this.getLight().getDepthMinZ(camera) + this.getLight().getDepthMaxZ(camera), lightIndex);\n }\n /**\n * Gets the transformation matrix of the first cascade used to project the meshes into the map from the light point of view.\n * (eq to view projection * shadow projection matrices)\n * @returns The transform matrix used to create the shadow map\n */\n getTransformMatrix() {\n return this.getCascadeTransformMatrix(0);\n }\n /**\n * Disposes the ShadowGenerator.\n * Returns nothing.\n */\n dispose() {\n super.dispose();\n if (this._freezeShadowCastersBoundingInfoObservable) {\n this._scene.onBeforeRenderObservable.remove(this._freezeShadowCastersBoundingInfoObservable);\n this._freezeShadowCastersBoundingInfoObservable = null;\n }\n if (this._depthReducer) {\n this._depthReducer.dispose();\n this._depthReducer = null;\n }\n }\n /**\n * Serializes the shadow generator setup to a json object.\n * @returns The serialized JSON object\n */\n serialize() {\n const serializationObject = super.serialize();\n const shadowMap = this.getShadowMap();\n if (!shadowMap) {\n return serializationObject;\n }\n serializationObject.numCascades = this._numCascades;\n serializationObject.debug = this._debug;\n serializationObject.stabilizeCascades = this.stabilizeCascades;\n serializationObject.lambda = this._lambda;\n serializationObject.cascadeBlendPercentage = this.cascadeBlendPercentage;\n serializationObject.depthClamp = this._depthClamp;\n serializationObject.autoCalcDepthBounds = this.autoCalcDepthBounds;\n serializationObject.shadowMaxZ = this._shadowMaxZ;\n serializationObject.penumbraDarkness = this.penumbraDarkness;\n serializationObject.freezeShadowCastersBoundingInfo = this._freezeShadowCastersBoundingInfo;\n serializationObject.minDistance = this.minDistance;\n serializationObject.maxDistance = this.maxDistance;\n serializationObject.renderList = [];\n if (shadowMap.renderList) {\n for (let meshIndex = 0; meshIndex < shadowMap.renderList.length; meshIndex++) {\n const mesh = shadowMap.renderList[meshIndex];\n serializationObject.renderList.push(mesh.id);\n }\n }\n return serializationObject;\n }\n /**\n * Parses a serialized ShadowGenerator and returns a new ShadowGenerator.\n * @param parsedShadowGenerator The JSON object to parse\n * @param scene The scene to create the shadow map for\n * @returns The parsed shadow generator\n */\n static Parse(parsedShadowGenerator, scene) {\n const shadowGenerator = ShadowGenerator.Parse(parsedShadowGenerator, scene, (mapSize, light, camera) => new CascadedShadowGenerator(mapSize, light, undefined, camera));\n if (parsedShadowGenerator.numCascades !== undefined) {\n shadowGenerator.numCascades = parsedShadowGenerator.numCascades;\n }\n if (parsedShadowGenerator.debug !== undefined) {\n shadowGenerator.debug = parsedShadowGenerator.debug;\n }\n if (parsedShadowGenerator.stabilizeCascades !== undefined) {\n shadowGenerator.stabilizeCascades = parsedShadowGenerator.stabilizeCascades;\n }\n if (parsedShadowGenerator.lambda !== undefined) {\n shadowGenerator.lambda = parsedShadowGenerator.lambda;\n }\n if (parsedShadowGenerator.cascadeBlendPercentage !== undefined) {\n shadowGenerator.cascadeBlendPercentage = parsedShadowGenerator.cascadeBlendPercentage;\n }\n if (parsedShadowGenerator.depthClamp !== undefined) {\n shadowGenerator.depthClamp = parsedShadowGenerator.depthClamp;\n }\n if (parsedShadowGenerator.autoCalcDepthBounds !== undefined) {\n shadowGenerator.autoCalcDepthBounds = parsedShadowGenerator.autoCalcDepthBounds;\n }\n if (parsedShadowGenerator.shadowMaxZ !== undefined) {\n shadowGenerator.shadowMaxZ = parsedShadowGenerator.shadowMaxZ;\n }\n if (parsedShadowGenerator.penumbraDarkness !== undefined) {\n shadowGenerator.penumbraDarkness = parsedShadowGenerator.penumbraDarkness;\n }\n if (parsedShadowGenerator.freezeShadowCastersBoundingInfo !== undefined) {\n shadowGenerator.freezeShadowCastersBoundingInfo = parsedShadowGenerator.freezeShadowCastersBoundingInfo;\n }\n if (parsedShadowGenerator.minDistance !== undefined && parsedShadowGenerator.maxDistance !== undefined) {\n shadowGenerator.setMinMaxDistance(parsedShadowGenerator.minDistance, parsedShadowGenerator.maxDistance);\n }\n return shadowGenerator;\n }\n}\nCascadedShadowGenerator._FrustumCornersNDCSpace = [\n new Vector3(-1.0, +1.0, -1.0),\n new Vector3(+1.0, +1.0, -1.0),\n new Vector3(+1.0, -1.0, -1.0),\n new Vector3(-1.0, -1.0, -1.0),\n new Vector3(-1.0, +1.0, +1.0),\n new Vector3(+1.0, +1.0, +1.0),\n new Vector3(+1.0, -1.0, +1.0),\n new Vector3(-1.0, -1.0, +1.0),\n];\n/**\n * Name of the CSM class\n */\nCascadedShadowGenerator.CLASSNAME = \"CascadedShadowGenerator\";\n/**\n * Defines the default number of cascades used by the CSM.\n */\nCascadedShadowGenerator.DEFAULT_CASCADES_COUNT = 4;\n/**\n * Defines the minimum number of cascades used by the CSM.\n */\nCascadedShadowGenerator.MIN_CASCADES_COUNT = 2;\n/**\n * Defines the maximum number of cascades used by the CSM.\n */\nCascadedShadowGenerator.MAX_CASCADES_COUNT = 4;\n/**\n * @internal\n */\nCascadedShadowGenerator._SceneComponentInitialization = (_) => {\n throw _WarnImport(\"ShadowGeneratorSceneComponent\");\n};\n"],"mappings":"AAAA,SAASA,MAAM,EAAEC,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