@galacean/engine-core 1.2.0-alpha.2 → 1.2.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -3292,7 +3292,7 @@ var PBRShaderLib = {
3292
3292
 
3293
3293
  var ShadowCoord = "#define GLSLIFY 1\nuniform mat4 scene_ShadowMatrices[SCENE_SHADOW_CASCADED_COUNT+1];uniform vec4 scene_ShadowSplitSpheres[4];mediump int computeCascadeIndex(vec3 positionWS){vec3 fromCenter0=positionWS-scene_ShadowSplitSpheres[0].xyz;vec3 fromCenter1=positionWS-scene_ShadowSplitSpheres[1].xyz;vec3 fromCenter2=positionWS-scene_ShadowSplitSpheres[2].xyz;vec3 fromCenter3=positionWS-scene_ShadowSplitSpheres[3].xyz;mediump vec4 comparison=vec4(dot(fromCenter0,fromCenter0)<scene_ShadowSplitSpheres[0].w,dot(fromCenter1,fromCenter1)<scene_ShadowSplitSpheres[1].w,dot(fromCenter2,fromCenter2)<scene_ShadowSplitSpheres[2].w,dot(fromCenter3,fromCenter3)<scene_ShadowSplitSpheres[3].w);comparison.yzw=clamp(comparison.yzw-comparison.xyz,0.0,1.0);mediump vec4 indexCoefficient=vec4(4.0,3.0,2.0,1.0);mediump int index=4-int(dot(comparison,indexCoefficient));return index;}vec3 getShadowCoord(){\n#if SCENE_SHADOW_CASCADED_COUNT == 1\nmediump int cascadeIndex=0;\n#else\nmediump int cascadeIndex=computeCascadeIndex(v_pos);\n#endif\n#ifdef GRAPHICS_API_WEBGL2\nmat4 shadowMatrix=scene_ShadowMatrices[cascadeIndex];\n#else\nmat4 shadowMatrix;\n#if SCENE_SHADOW_CASCADED_COUNT == 4\nif(cascadeIndex==0){shadowMatrix=scene_ShadowMatrices[0];}else if(cascadeIndex==1){shadowMatrix=scene_ShadowMatrices[1];}else if(cascadeIndex==2){shadowMatrix=scene_ShadowMatrices[2];}else if(cascadeIndex==3){shadowMatrix=scene_ShadowMatrices[3];}else{shadowMatrix=scene_ShadowMatrices[4];}\n#endif\n#if SCENE_SHADOW_CASCADED_COUNT == 2\nif(cascadeIndex==0){shadowMatrix=scene_ShadowMatrices[0];}else if(cascadeIndex==1){shadowMatrix=scene_ShadowMatrices[1];}else{shadowMatrix=scene_ShadowMatrices[2];}\n#endif\n#if SCENE_SHADOW_CASCADED_COUNT == 1\nif(cascadeIndex==0){shadowMatrix=scene_ShadowMatrices[0];}else{shadowMatrix=scene_ShadowMatrices[1];}\n#endif\n#endif\nvec4 shadowCoord=shadowMatrix*vec4(v_pos,1.0);return shadowCoord.xyz;}"; // eslint-disable-line
3294
3294
 
3295
- var ShadowFragmentDeclaration = "#define GLSLIFY 1\n#if defined(SCENE_SHADOW_TYPE) && defined(RENDERER_IS_RECEIVE_SHADOWS)\n#define SCENE_IS_CALCULATE_SHADOWS\n#endif\n#ifdef SCENE_IS_CALCULATE_SHADOWS\n#if SCENE_SHADOW_CASCADED_COUNT == 1\nvarying vec3 v_shadowCoord;\n#else\n#include <ShadowCoord>\n#endif\nuniform vec3 scene_ShadowInfo;uniform vec4 scene_ShadowMapSize;\n#ifdef GRAPHICS_API_WEBGL2\nuniform mediump sampler2DShadow scene_ShadowMap;\n#define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) textureLod(textureName, coord3 , 0.0)\n#define TEXTURE2D_SHADOW_PARAM(shadowMap) mediump sampler2DShadow shadowMap\n#else\nuniform sampler2D scene_ShadowMap;\n#ifdef ENGINE_NO_DEPTH_TEXTURE\nconst vec4 bitShift=vec4(1.0,1.0/256.0,1.0/(256.0*256.0),1.0/(256.0*256.0*256.0));float unpack(const in vec4 rgbaDepth){return dot(rgbaDepth,bitShift);}\n#define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) (unpack(texture2D(textureName, coord3.xy)) < coord3.z ? 0.0 : 1.0)\n#else\n#define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) (texture2D(textureName, coord3.xy).r < coord3.z ? 0.0 : 1.0)\n#endif\n#define TEXTURE2D_SHADOW_PARAM(shadowMap) mediump sampler2D shadowMap\n#endif\n#if SCENE_SHADOW_TYPE == 2\nfloat sampleShadowMapFiltered4(TEXTURE2D_SHADOW_PARAM(shadowMap),vec3 shadowCoord,vec4 shadowMapSize){float attenuation;vec4 attenuation4;vec2 offset=shadowMapSize.xy/2.0;vec3 shadowCoord0=shadowCoord+vec3(-offset,0.0);vec3 shadowCoord1=shadowCoord+vec3(offset.x,-offset.y,0.0);vec3 shadowCoord2=shadowCoord+vec3(-offset.x,offset.y,0.0);vec3 shadowCoord3=shadowCoord+vec3(offset,0.0);attenuation4.x=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord0);attenuation4.y=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord1);attenuation4.z=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord2);attenuation4.w=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord3);attenuation=dot(attenuation4,vec4(0.25));return attenuation;}\n#endif\n#if SCENE_SHADOW_TYPE == 3\n#include <shadow_sample_tent>\nfloat sampleShadowMapFiltered9(TEXTURE2D_SHADOW_PARAM(shadowMap),vec3 shadowCoord,vec4 shadowmapSize){float attenuation;float fetchesWeights[9];vec2 fetchesUV[9];sampleShadowComputeSamplesTent5x5(shadowmapSize,shadowCoord.xy,fetchesWeights,fetchesUV);attenuation=fetchesWeights[0]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[0].xy,shadowCoord.z));attenuation+=fetchesWeights[1]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[1].xy,shadowCoord.z));attenuation+=fetchesWeights[2]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[2].xy,shadowCoord.z));attenuation+=fetchesWeights[3]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[3].xy,shadowCoord.z));attenuation+=fetchesWeights[4]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[4].xy,shadowCoord.z));attenuation+=fetchesWeights[5]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[5].xy,shadowCoord.z));attenuation+=fetchesWeights[6]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[6].xy,shadowCoord.z));attenuation+=fetchesWeights[7]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[7].xy,shadowCoord.z));attenuation+=fetchesWeights[8]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[8].xy,shadowCoord.z));return attenuation;}\n#endif\nfloat sampleShadowMap(){\n#if SCENE_SHADOW_CASCADED_COUNT == 1\nvec3 shadowCoord=v_shadowCoord;\n#else\nvec3 shadowCoord=getShadowCoord();\n#endif\nfloat attenuation=1.0;if(shadowCoord.z>0.0&&shadowCoord.z<1.0){\n#if SCENE_SHADOW_TYPE == 1\nattenuation=SAMPLE_TEXTURE2D_SHADOW(scene_ShadowMap,shadowCoord);\n#endif\n#if SCENE_SHADOW_TYPE == 2\nattenuation=sampleShadowMapFiltered4(scene_ShadowMap,shadowCoord,scene_ShadowMapSize);\n#endif\n#if SCENE_SHADOW_TYPE == 3\nattenuation=sampleShadowMapFiltered9(scene_ShadowMap,shadowCoord,scene_ShadowMapSize);\n#endif\nattenuation=mix(1.0,attenuation,scene_ShadowInfo.x);}return attenuation;}\n#endif\n"; // eslint-disable-line
3295
+ var ShadowFragmentDeclaration = "#define GLSLIFY 1\n#if defined(SCENE_SHADOW_TYPE) && defined(RENDERER_IS_RECEIVE_SHADOWS)\n#define SCENE_IS_CALCULATE_SHADOWS\n#endif\n#ifdef SCENE_IS_CALCULATE_SHADOWS\n#if SCENE_SHADOW_CASCADED_COUNT == 1\nvarying vec3 v_shadowCoord;\n#else\n#include <ShadowCoord>\n#endif\nuniform vec4 scene_ShadowInfo;uniform vec4 scene_ShadowMapSize;\n#ifdef GRAPHICS_API_WEBGL2\nuniform mediump sampler2DShadow scene_ShadowMap;\n#define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) textureLod(textureName, coord3 , 0.0)\n#define TEXTURE2D_SHADOW_PARAM(shadowMap) mediump sampler2DShadow shadowMap\n#else\nuniform sampler2D scene_ShadowMap;\n#ifdef ENGINE_NO_DEPTH_TEXTURE\nconst vec4 bitShift=vec4(1.0,1.0/256.0,1.0/(256.0*256.0),1.0/(256.0*256.0*256.0));float unpack(const in vec4 rgbaDepth){return dot(rgbaDepth,bitShift);}\n#define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) (unpack(texture2D(textureName, coord3.xy)) < coord3.z ? 0.0 : 1.0)\n#else\n#define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) (texture2D(textureName, coord3.xy).r < coord3.z ? 0.0 : 1.0)\n#endif\n#define TEXTURE2D_SHADOW_PARAM(shadowMap) mediump sampler2D shadowMap\n#endif\n#if SCENE_SHADOW_TYPE == 2\nfloat sampleShadowMapFiltered4(TEXTURE2D_SHADOW_PARAM(shadowMap),vec3 shadowCoord,vec4 shadowMapSize){float attenuation;vec4 attenuation4;vec2 offset=shadowMapSize.xy/2.0;vec3 shadowCoord0=shadowCoord+vec3(-offset,0.0);vec3 shadowCoord1=shadowCoord+vec3(offset.x,-offset.y,0.0);vec3 shadowCoord2=shadowCoord+vec3(-offset.x,offset.y,0.0);vec3 shadowCoord3=shadowCoord+vec3(offset,0.0);attenuation4.x=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord0);attenuation4.y=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord1);attenuation4.z=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord2);attenuation4.w=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord3);attenuation=dot(attenuation4,vec4(0.25));return attenuation;}\n#endif\n#if SCENE_SHADOW_TYPE == 3\n#include <shadow_sample_tent>\nfloat sampleShadowMapFiltered9(TEXTURE2D_SHADOW_PARAM(shadowMap),vec3 shadowCoord,vec4 shadowmapSize){float attenuation;float fetchesWeights[9];vec2 fetchesUV[9];sampleShadowComputeSamplesTent5x5(shadowmapSize,shadowCoord.xy,fetchesWeights,fetchesUV);attenuation=fetchesWeights[0]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[0].xy,shadowCoord.z));attenuation+=fetchesWeights[1]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[1].xy,shadowCoord.z));attenuation+=fetchesWeights[2]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[2].xy,shadowCoord.z));attenuation+=fetchesWeights[3]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[3].xy,shadowCoord.z));attenuation+=fetchesWeights[4]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[4].xy,shadowCoord.z));attenuation+=fetchesWeights[5]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[5].xy,shadowCoord.z));attenuation+=fetchesWeights[6]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[6].xy,shadowCoord.z));attenuation+=fetchesWeights[7]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[7].xy,shadowCoord.z));attenuation+=fetchesWeights[8]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[8].xy,shadowCoord.z));return attenuation;}\n#endif\nfloat getShadowFade(vec3 positionWS){vec3 camToPixel=positionWS-camera_Position;float distanceCamToPixel2=dot(camToPixel,camToPixel);return saturate(distanceCamToPixel2*scene_ShadowInfo.z+scene_ShadowInfo.w);}float sampleShadowMap(){\n#if SCENE_SHADOW_CASCADED_COUNT == 1\nvec3 shadowCoord=v_shadowCoord;\n#else\nvec3 shadowCoord=getShadowCoord();\n#endif\nfloat attenuation=1.0;if(shadowCoord.z>0.0&&shadowCoord.z<1.0){\n#if SCENE_SHADOW_TYPE == 1\nattenuation=SAMPLE_TEXTURE2D_SHADOW(scene_ShadowMap,shadowCoord);\n#endif\n#if SCENE_SHADOW_TYPE == 2\nattenuation=sampleShadowMapFiltered4(scene_ShadowMap,shadowCoord,scene_ShadowMapSize);\n#endif\n#if SCENE_SHADOW_TYPE == 3\nattenuation=sampleShadowMapFiltered9(scene_ShadowMap,shadowCoord,scene_ShadowMapSize);\n#endif\nfloat shadowFade=getShadowFade(v_pos);attenuation=mix(1.0,mix(attenuation,1.0,shadowFade),scene_ShadowInfo.x);}return attenuation;}\n#endif\n"; // eslint-disable-line
3296
3296
 
3297
3297
  var shadow_sample_tent = "#define GLSLIFY 1\nfloat sampleShadowGetIRTriangleTexelArea(float triangleHeight){return triangleHeight-0.5;}void sampleShadowGetTexelAreasTent3x3(float offset,out vec4 computedArea,out vec4 computedAreaUncut){float a=offset+0.5;float offsetSquaredHalved=a*a*0.5;computedAreaUncut.x=computedArea.x=offsetSquaredHalved-offset;computedAreaUncut.w=computedArea.w=offsetSquaredHalved;computedAreaUncut.y=sampleShadowGetIRTriangleTexelArea(1.5-offset);float clampedOffsetLeft=min(offset,0.0);float areaOfSmallLeftTriangle=clampedOffsetLeft*clampedOffsetLeft;computedArea.y=computedAreaUncut.y-areaOfSmallLeftTriangle;computedAreaUncut.z=sampleShadowGetIRTriangleTexelArea(1.5+offset);float clampedOffsetRight=max(offset,0.0);float areaOfSmallRightTriangle=clampedOffsetRight*clampedOffsetRight;computedArea.z=computedAreaUncut.z-areaOfSmallRightTriangle;}void sampleShadowGetTexelWeightsTent5x5(float offset,out vec3 texelsWeightsA,out vec3 texelsWeightsB){vec4 areaFrom3texelTriangle;vec4 areaUncutFrom3texelTriangle;sampleShadowGetTexelAreasTent3x3(offset,areaFrom3texelTriangle,areaUncutFrom3texelTriangle);texelsWeightsA.x=0.16*(areaFrom3texelTriangle.x);texelsWeightsA.y=0.16*(areaUncutFrom3texelTriangle.y);texelsWeightsA.z=0.16*(areaFrom3texelTriangle.y+1.0);texelsWeightsB.x=0.16*(areaFrom3texelTriangle.z+1.0);texelsWeightsB.y=0.16*(areaUncutFrom3texelTriangle.z);texelsWeightsB.z=0.16*(areaFrom3texelTriangle.w);}void sampleShadowComputeSamplesTent5x5(vec4 shadowMapTextureTexelSize,vec2 coord,out float fetchesWeights[9],out vec2 fetchesUV[9]){vec2 tentCenterInTexelSpace=coord.xy*shadowMapTextureTexelSize.zw;vec2 centerOfFetchesInTexelSpace=floor(tentCenterInTexelSpace+0.5);vec2 offsetFromTentCenterToCenterOfFetches=tentCenterInTexelSpace-centerOfFetchesInTexelSpace;vec3 texelsWeightsUA,texelsWeightsUB;vec3 texelsWeightsVA,texelsWeightsVB;sampleShadowGetTexelWeightsTent5x5(offsetFromTentCenterToCenterOfFetches.x,texelsWeightsUA,texelsWeightsUB);sampleShadowGetTexelWeightsTent5x5(offsetFromTentCenterToCenterOfFetches.y,texelsWeightsVA,texelsWeightsVB);vec3 fetchesWeightsU=vec3(texelsWeightsUA.xz,texelsWeightsUB.y)+vec3(texelsWeightsUA.y,texelsWeightsUB.xz);vec3 fetchesWeightsV=vec3(texelsWeightsVA.xz,texelsWeightsVB.y)+vec3(texelsWeightsVA.y,texelsWeightsVB.xz);vec3 fetchesOffsetsU=vec3(texelsWeightsUA.y,texelsWeightsUB.xz)/fetchesWeightsU.xyz+vec3(-2.5,-0.5,1.5);vec3 fetchesOffsetsV=vec3(texelsWeightsVA.y,texelsWeightsVB.xz)/fetchesWeightsV.xyz+vec3(-2.5,-0.5,1.5);fetchesOffsetsU*=shadowMapTextureTexelSize.xxx;fetchesOffsetsV*=shadowMapTextureTexelSize.yyy;vec2 bilinearFetchOrigin=centerOfFetchesInTexelSpace*shadowMapTextureTexelSize.xy;fetchesUV[0]=bilinearFetchOrigin+vec2(fetchesOffsetsU.x,fetchesOffsetsV.x);fetchesUV[1]=bilinearFetchOrigin+vec2(fetchesOffsetsU.y,fetchesOffsetsV.x);fetchesUV[2]=bilinearFetchOrigin+vec2(fetchesOffsetsU.z,fetchesOffsetsV.x);fetchesUV[3]=bilinearFetchOrigin+vec2(fetchesOffsetsU.x,fetchesOffsetsV.y);fetchesUV[4]=bilinearFetchOrigin+vec2(fetchesOffsetsU.y,fetchesOffsetsV.y);fetchesUV[5]=bilinearFetchOrigin+vec2(fetchesOffsetsU.z,fetchesOffsetsV.y);fetchesUV[6]=bilinearFetchOrigin+vec2(fetchesOffsetsU.x,fetchesOffsetsV.z);fetchesUV[7]=bilinearFetchOrigin+vec2(fetchesOffsetsU.y,fetchesOffsetsV.z);fetchesUV[8]=bilinearFetchOrigin+vec2(fetchesOffsetsU.z,fetchesOffsetsV.z);fetchesWeights[0]=fetchesWeightsU.x*fetchesWeightsV.x;fetchesWeights[1]=fetchesWeightsU.y*fetchesWeightsV.x;fetchesWeights[2]=fetchesWeightsU.z*fetchesWeightsV.x;fetchesWeights[3]=fetchesWeightsU.x*fetchesWeightsV.y;fetchesWeights[4]=fetchesWeightsU.y*fetchesWeightsV.y;fetchesWeights[5]=fetchesWeightsU.z*fetchesWeightsV.y;fetchesWeights[6]=fetchesWeightsU.x*fetchesWeightsV.z;fetchesWeights[7]=fetchesWeightsU.y*fetchesWeightsV.z;fetchesWeights[8]=fetchesWeightsU.z*fetchesWeightsV.z;}"; // eslint-disable-line
3298
3298
 
@@ -18931,8 +18931,9 @@ var unlitVs = "#define GLSLIFY 1\n#include <common>\n#include <common_vert>\n#in
18931
18931
  }
18932
18932
  return;
18933
18933
  }
18934
+ ++hierarchy;
18934
18935
  for(var k1 in cacheMap){
18935
- this._recursiveDestroy(++hierarchy, cacheMap[k1]);
18936
+ this._recursiveDestroy(hierarchy, cacheMap[k1]);
18936
18937
  }
18937
18938
  };
18938
18939
  _proto._resizeCacheMapHierarchy = function _resizeCacheMapHierarchy(cacheMap, hierarchy, currentHierarchy, increaseHierarchy) {
@@ -20961,6 +20962,10 @@ __decorate([
20961
20962
  /** The splits of two cascade distribution. */ _this.shadowTwoCascadeSplits = 1.0 / 3.0;
20962
20963
  /** The splits of four cascade distribution. */ _this.shadowFourCascadeSplits = new engineMath.Vector3(1.0 / 15, 3.0 / 15.0, 7.0 / 15.0);
20963
20964
  /** Max Shadow distance. */ _this.shadowDistance = 50;
20965
+ /**
20966
+ * Last shadow fade distance in percentage, range [0,1].
20967
+ * @remarks Value 0 is used for no shadow fade.
20968
+ */ _this.shadowFadeBorder = 0.1;
20964
20969
  /* @internal */ _this._lightManager = new LightManager();
20965
20970
  /* @internal */ _this._componentsManager = new ComponentsManager();
20966
20971
  /** @internal */ _this._isActiveInEngine = false;
@@ -21585,47 +21590,66 @@ __decorate([
21585
21590
  DepthTextureMode[DepthTextureMode[/* Generate depth texture by pre-pass rendering. */ "PrePass"] = 1] = "PrePass";
21586
21591
  })(exports.DepthTextureMode || (exports.DepthTextureMode = {}));
21587
21592
 
21588
- var passNum = 0;
21589
21593
  /**
21590
- * RenderPass.
21591
- */ var RenderPass = /*#__PURE__*/ function() {
21592
- function RenderPass(name, priority, renderTarget, replaceMaterial, mask) {
21593
- if (name === void 0) name = "RENDER_PASS" + passNum++;
21594
- if (priority === void 0) priority = 0;
21595
- if (renderTarget === void 0) renderTarget = null;
21596
- if (replaceMaterial === void 0) replaceMaterial = null;
21597
- if (mask === void 0) mask = null;
21598
- this.name = name;
21599
- this.enabled = true;
21600
- this.priority = priority;
21601
- this.renderTarget = renderTarget;
21602
- this.replaceMaterial = replaceMaterial;
21603
- this.mask = mask || exports.Layer.Everything;
21604
- this.renderOverride = false; // If renderOverride is set to true, you need to implement the render method
21605
- }
21606
- var _proto = RenderPass.prototype;
21607
- /**
21608
- * Rendering callback, will be executed if renderOverride is set to true.
21609
- * @param camera - Camera
21610
- * @param opaqueQueue - Opaque queue
21611
- * @param alphaTestQueue - Alpha test queue
21612
- * @param transparentQueue - Transparent queue
21613
- */ _proto.render = function render(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
21594
+ * PipelinePass is a base class for all pipeline passes.
21595
+ */ var PipelinePass = function PipelinePass(engine) {
21596
+ this._engine = engine;
21597
+ };
21598
+
21599
+ /**
21600
+ * @internal
21601
+ */ var PipelineUtils = /*#__PURE__*/ function() {
21602
+ function PipelineUtils() {}
21614
21603
  /**
21615
- * Post rendering callback.
21616
- * @param camera - Camera
21617
- * @param opaqueQueue - Opaque queue
21618
- * @param alphaTestQueue - Alpha test queue
21619
- * @param transparentQueue - Transparent queue
21620
- */ _proto.preRender = function preRender(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
21604
+ * Recreate texture if needed.
21605
+ * @param engine - Engine
21606
+ * @param currentTexture - Current texture
21607
+ * @param width - Need texture width
21608
+ * @param height - Need texture height
21609
+ * @param format - Need texture format
21610
+ * @param mipmap - Need texture mipmap
21611
+ * @returns Texture
21612
+ */ PipelineUtils.recreateTextureIfNeeded = function recreateTextureIfNeeded(engine, currentTexture, width, height, format, mipmap) {
21613
+ if (currentTexture) {
21614
+ if (currentTexture.width !== width || currentTexture.height !== height || currentTexture.format !== format || currentTexture.mipmapCount > 1 !== mipmap) {
21615
+ currentTexture.destroy();
21616
+ var texture = new Texture2D(engine, width, height, format, mipmap);
21617
+ texture.isGCIgnored = true;
21618
+ return texture;
21619
+ } else {
21620
+ return currentTexture;
21621
+ }
21622
+ } else {
21623
+ var texture1 = new Texture2D(engine, width, height, format, mipmap);
21624
+ texture1.isGCIgnored = true;
21625
+ return texture1;
21626
+ }
21627
+ };
21621
21628
  /**
21622
- * Post rendering callback.
21623
- * @param camera - Camera
21624
- * @param opaqueQueue - Opaque queue
21625
- * @param alphaTestQueue - Alpha test queue
21626
- * @param transparentQueue - Transparent queue
21627
- */ _proto.postRender = function postRender(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
21628
- return RenderPass;
21629
+ * Recreate render target if needed.
21630
+ * @param engine - Engine
21631
+ * @param currentRenderTarget - Current render target
21632
+ * @param width - Need render target width
21633
+ * @param height - Need render target height
21634
+ * @param colorFormat - Need render target color format
21635
+ * @param depthFormat - Need render target depth format
21636
+ * @param mipmap - Need render target mipmap
21637
+ * @returns Render target
21638
+ */ PipelineUtils.recreateRenderTargetIfNeeded = function recreateRenderTargetIfNeeded(engine, currentRenderTarget, width, height, colorFormat, depthFormat, mipmap) {
21639
+ var _currentRenderTarget, _currentRenderTarget1;
21640
+ var currentColorTexture = (_currentRenderTarget = currentRenderTarget) == null ? void 0 : _currentRenderTarget.getColorTexture(0);
21641
+ var currentDepthTexture = (_currentRenderTarget1 = currentRenderTarget) == null ? void 0 : _currentRenderTarget1.depthTexture;
21642
+ var colorTexture = colorFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentColorTexture, width, height, colorFormat, mipmap) : null;
21643
+ var depthTexture = depthFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentDepthTexture, width, height, depthFormat, mipmap) : null;
21644
+ if (currentColorTexture !== colorTexture || currentDepthTexture !== depthTexture) {
21645
+ var _currentRenderTarget2;
21646
+ (_currentRenderTarget2 = currentRenderTarget) == null ? void 0 : _currentRenderTarget2.destroy();
21647
+ currentRenderTarget = new RenderTarget(engine, width, height, colorTexture, depthTexture);
21648
+ currentRenderTarget.isGCIgnored = true;
21649
+ }
21650
+ return currentRenderTarget;
21651
+ };
21652
+ return PipelineUtils;
21629
21653
  }();
21630
21654
 
21631
21655
  /**
@@ -21932,60 +21956,47 @@ var passNum = 0;
21932
21956
  return RenderQueue;
21933
21957
  }();
21934
21958
 
21959
+ var passNum = 0;
21935
21960
  /**
21936
- * @internal
21937
- */ var PipelineUtils = /*#__PURE__*/ function() {
21938
- function PipelineUtils() {}
21961
+ * RenderPass.
21962
+ */ var RenderPass = /*#__PURE__*/ function() {
21963
+ function RenderPass(name, priority, renderTarget, replaceMaterial, mask) {
21964
+ if (name === void 0) name = "RENDER_PASS" + passNum++;
21965
+ if (priority === void 0) priority = 0;
21966
+ if (renderTarget === void 0) renderTarget = null;
21967
+ if (replaceMaterial === void 0) replaceMaterial = null;
21968
+ if (mask === void 0) mask = null;
21969
+ this.name = name;
21970
+ this.enabled = true;
21971
+ this.priority = priority;
21972
+ this.renderTarget = renderTarget;
21973
+ this.replaceMaterial = replaceMaterial;
21974
+ this.mask = mask || exports.Layer.Everything;
21975
+ this.renderOverride = false; // If renderOverride is set to true, you need to implement the render method
21976
+ }
21977
+ var _proto = RenderPass.prototype;
21939
21978
  /**
21940
- * Recreate texture if needed.
21941
- * @param engine - Engine
21942
- * @param currentTexture - Current texture
21943
- * @param width - Need texture width
21944
- * @param height - Need texture height
21945
- * @param format - Need texture format
21946
- * @param mipmap - Need texture mipmap
21947
- * @returns Texture
21948
- */ PipelineUtils.recreateTextureIfNeeded = function recreateTextureIfNeeded(engine, currentTexture, width, height, format, mipmap) {
21949
- if (currentTexture) {
21950
- if (currentTexture.width !== width || currentTexture.height !== height || currentTexture.format !== format || currentTexture.mipmapCount > 1 !== mipmap) {
21951
- currentTexture.destroy();
21952
- var texture = new Texture2D(engine, width, height, format, mipmap);
21953
- texture.isGCIgnored = true;
21954
- return texture;
21955
- } else {
21956
- return currentTexture;
21957
- }
21958
- } else {
21959
- var texture1 = new Texture2D(engine, width, height, format, mipmap);
21960
- texture1.isGCIgnored = true;
21961
- return texture1;
21962
- }
21963
- };
21979
+ * Rendering callback, will be executed if renderOverride is set to true.
21980
+ * @param camera - Camera
21981
+ * @param opaqueQueue - Opaque queue
21982
+ * @param alphaTestQueue - Alpha test queue
21983
+ * @param transparentQueue - Transparent queue
21984
+ */ _proto.render = function render(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
21964
21985
  /**
21965
- * Recreate render target if needed.
21966
- * @param engine - Engine
21967
- * @param currentRenderTarget - Current render target
21968
- * @param width - Need render target width
21969
- * @param height - Need render target height
21970
- * @param colorFormat - Need render target color format
21971
- * @param depthFormat - Need render target depth format
21972
- * @param mipmap - Need render target mipmap
21973
- * @returns Render target
21974
- */ PipelineUtils.recreateRenderTargetIfNeeded = function recreateRenderTargetIfNeeded(engine, currentRenderTarget, width, height, colorFormat, depthFormat, mipmap) {
21975
- var _currentRenderTarget, _currentRenderTarget1;
21976
- var currentColorTexture = (_currentRenderTarget = currentRenderTarget) == null ? void 0 : _currentRenderTarget.getColorTexture(0);
21977
- var currentDepthTexture = (_currentRenderTarget1 = currentRenderTarget) == null ? void 0 : _currentRenderTarget1.depthTexture;
21978
- var colorTexture = colorFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentColorTexture, width, height, colorFormat, mipmap) : null;
21979
- var depthTexture = depthFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentDepthTexture, width, height, depthFormat, mipmap) : null;
21980
- if (currentColorTexture !== colorTexture || currentDepthTexture !== depthTexture) {
21981
- var _currentRenderTarget2;
21982
- (_currentRenderTarget2 = currentRenderTarget) == null ? void 0 : _currentRenderTarget2.destroy();
21983
- currentRenderTarget = new RenderTarget(engine, width, height, colorTexture, depthTexture);
21984
- currentRenderTarget.isGCIgnored = true;
21985
- }
21986
- return currentRenderTarget;
21987
- };
21988
- return PipelineUtils;
21986
+ * Post rendering callback.
21987
+ * @param camera - Camera
21988
+ * @param opaqueQueue - Opaque queue
21989
+ * @param alphaTestQueue - Alpha test queue
21990
+ * @param transparentQueue - Transparent queue
21991
+ */ _proto.preRender = function preRender(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
21992
+ /**
21993
+ * Post rendering callback.
21994
+ * @param camera - Camera
21995
+ * @param opaqueQueue - Opaque queue
21996
+ * @param alphaTestQueue - Alpha test queue
21997
+ * @param transparentQueue - Transparent queue
21998
+ */ _proto.postRender = function postRender(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
21999
+ return RenderPass;
21989
22000
  }();
21990
22001
 
21991
22002
  /**
@@ -22253,6 +22264,26 @@ var /**
22253
22264
  var offset = cascadeIndex * 16;
22254
22265
  Utils._floatMatrixMultiply(sliceMatrix, outShadowMatrices, offset, outShadowMatrices, offset);
22255
22266
  };
22267
+ /**
22268
+ * Extract scale and bias from a fade distance to achieve a linear fading of the fade distance.
22269
+ */ ShadowUtils.getScaleAndBiasForLinearDistanceFade = function getScaleAndBiasForLinearDistanceFade(fadeDistance, border, outInfo) {
22270
+ // (P^2-N^2)/(F^2-N^2)
22271
+ // To avoid division from zero
22272
+ // This values ensure that fade within cascade will be 0 and outside 1
22273
+ if (border < 0.0001) {
22274
+ var multiplier = 1000; // To avoid blending if difference is in fractions
22275
+ outInfo.z = multiplier;
22276
+ outInfo.w = -fadeDistance * multiplier;
22277
+ return;
22278
+ }
22279
+ border = 1 - border;
22280
+ border *= border;
22281
+ // Fade with distance calculation is just a linear fade from 90% of fade distance to fade distance. 90% arbitrarily chosen but should work well enough.
22282
+ var distanceFadeNear = border * fadeDistance;
22283
+ var fadeRange = fadeDistance - distanceFadeNear;
22284
+ outInfo.z = 1.0 / fadeRange;
22285
+ outInfo.w = -distanceFadeNear / fadeRange;
22286
+ };
22256
22287
  return ShadowUtils;
22257
22288
  }();
22258
22289
  (function() {
@@ -22497,12 +22528,6 @@ var /**
22497
22528
  ShadowUtils.atlasBorderSize = 4.0;
22498
22529
  })();
22499
22530
 
22500
- /**
22501
- * PipelinePass is a base class for all pipeline passes.
22502
- */ var PipelinePass = function PipelinePass(engine) {
22503
- this._engine = engine;
22504
- };
22505
-
22506
22531
  /**
22507
22532
  * Cascade shadow caster pass.
22508
22533
  */ var CascadedShadowCasterPass = /*#__PURE__*/ function(PipelinePass1) {
@@ -22515,11 +22540,10 @@ var /**
22515
22540
  _this._shadowSliceData = new ShadowSliceData();
22516
22541
  _this._lightUp = new engineMath.Vector3();
22517
22542
  _this._lightSide = new engineMath.Vector3();
22518
- _this._existShadowMap = false;
22519
22543
  _this._splitBoundSpheres = new Float32Array(CascadedShadowCasterPass._maxCascades * 4);
22520
22544
  /** The end is project precision problem in shader. */ _this._shadowMatrices = new Float32Array((CascadedShadowCasterPass._maxCascades + 1) * 16);
22521
- // strength, null, lightIndex
22522
- _this._shadowInfos = new engineMath.Vector3();
22545
+ // intensity, null, fadeScale, fadeBias
22546
+ _this._shadowInfos = new engineMath.Vector4();
22523
22547
  _this._viewportOffsets = [
22524
22548
  new engineMath.Vector2(),
22525
22549
  new engineMath.Vector2(),
@@ -22535,14 +22559,12 @@ var /**
22535
22559
  /**
22536
22560
  * @internal
22537
22561
  */ _proto.onRender = function onRender(context) {
22562
+ var light = this._camera.scene._lightManager._sunlight;
22538
22563
  this._updateShadowSettings();
22539
- this._existShadowMap = false;
22540
- this._renderDirectShadowMap(context);
22541
- if (this._existShadowMap) {
22542
- this._updateReceiversShaderData();
22543
- }
22564
+ this._renderDirectShadowMap(context, light);
22565
+ this._updateReceiversShaderData(light);
22544
22566
  };
22545
- _proto._renderDirectShadowMap = function _renderDirectShadowMap(context) {
22567
+ _proto._renderDirectShadowMap = function _renderDirectShadowMap(context, light) {
22546
22568
  var _this = this, engine = _this._engine, camera = _this._camera, viewports = _this._viewportOffsets, shadowSliceData = _this._shadowSliceData, splitBoundSpheres = _this._splitBoundSpheres, shadowMatrices = _this._shadowMatrices;
22547
22569
  var _camera__renderPipeline__cullingResults = camera._renderPipeline._cullingResults, opaqueQueue = _camera__renderPipeline__cullingResults.opaqueQueue, alphaTestQueue = _camera__renderPipeline__cullingResults.alphaTestQueue, transparentQueue = _camera__renderPipeline__cullingResults.transparentQueue;
22548
22570
  var scene = camera.scene;
@@ -22556,91 +22578,87 @@ var /**
22556
22578
  var lightUp = this._lightUp;
22557
22579
  var lightSide = this._lightSide;
22558
22580
  var lightForward = shadowSliceData.virtualCamera.forward;
22559
- var light = scene._lightManager._sunlight;
22560
- if (light) {
22561
- var shadowFar = Math.min(camera.scene.shadowDistance, camera.farClipPlane);
22562
- this._getCascadesSplitDistance(shadowFar);
22563
- // Prepare render target
22564
- var _this__shadowMapSize = this._shadowMapSize, width = _this__shadowMapSize.z, height = _this__shadowMapSize.w;
22565
- var format = this._shadowMapFormat;
22566
- var renderTarget;
22567
- var shadowTexture;
22568
- if (this._supportDepthTexture) {
22569
- renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, null, format, false);
22570
- shadowTexture = renderTarget.depthTexture;
22571
- } else {
22572
- renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, format, null, false);
22573
- shadowTexture = renderTarget.getColorTexture(0);
22574
- }
22575
- shadowTexture.wrapModeU = shadowTexture.wrapModeV = exports.TextureWrapMode.Clamp;
22576
- if (engine._hardwareRenderer._isWebGL2) {
22577
- shadowTexture.depthCompareFunction = exports.TextureDepthCompareFunction.Less;
22578
- }
22579
- this._renderTarget = renderTarget;
22580
- this._depthTexture = shadowTexture;
22581
- // @todo: shouldn't set viewport and scissor in activeRenderTarget
22582
- rhi.activeRenderTarget(renderTarget, CascadedShadowCasterPass._viewport, 0);
22583
- if (this._supportDepthTexture) {
22584
- rhi.clearRenderTarget(engine, exports.CameraClearFlags.Depth, null);
22585
- } else {
22586
- rhi.clearRenderTarget(engine, exports.CameraClearFlags.All, CascadedShadowCasterPass._clearColor);
22587
- }
22588
- this._shadowInfos.x = light.shadowStrength;
22589
- this._shadowInfos.z = 0; // @todo: sun light index always 0
22590
- // prepare light and camera direction
22591
- engineMath.Matrix.rotationQuaternion(light.entity.transform.worldRotationQuaternion, lightWorld);
22592
- lightSide.set(lightWorldE[0], lightWorldE[1], lightWorldE[2]);
22593
- lightUp.set(lightWorldE[4], lightWorldE[5], lightWorldE[6]);
22594
- lightForward.set(-lightWorldE[8], -lightWorldE[9], -lightWorldE[10]);
22595
- var cameraForward = CascadedShadowCasterPass._tempVector;
22596
- cameraForward.copyFrom(camera.entity.transform.worldForward);
22597
- var shadowTileResolution = this._shadowTileResolution;
22598
- for(var j = 0; j < shadowCascades; j++){
22599
- ShadowUtils.getBoundSphereByFrustum(splitDistance[j], splitDistance[j + 1], camera, cameraForward, shadowSliceData);
22600
- ShadowUtils.getDirectionLightShadowCullPlanes(camera._frustum, splitDistance[j], camera.nearClipPlane, lightForward, shadowSliceData);
22601
- ShadowUtils.getDirectionalLightMatrices(lightUp, lightSide, lightForward, j, light.shadowNearPlane, shadowTileResolution, shadowSliceData, shadowMatrices);
22602
- if (shadowCascades > 1) {
22603
- ShadowUtils.applySliceTransform(shadowTileResolution, width, height, j, this._viewportOffsets[j], shadowMatrices);
22604
- }
22605
- this._updateSingleShadowCasterShaderData(light, shadowSliceData, context);
22606
- // upload pre-cascade infos.
22607
- var center = boundSphere.center;
22608
- var radius = boundSphere.radius;
22609
- var offset = j * 4;
22610
- splitBoundSpheres[offset] = center.x;
22611
- splitBoundSpheres[offset + 1] = center.y;
22612
- splitBoundSpheres[offset + 2] = center.z;
22613
- splitBoundSpheres[offset + 3] = radius * radius;
22614
- opaqueQueue.clear();
22615
- alphaTestQueue.clear();
22616
- transparentQueue.clear();
22617
- var renderers = componentsManager._renderers;
22618
- var elements = renderers._elements;
22619
- for(var k = renderers.length - 1; k >= 0; --k){
22620
- ShadowUtils.shadowCullFrustum(context, light, elements[k], shadowSliceData);
22621
- }
22622
- if (opaqueQueue.elements.length || alphaTestQueue.elements.length) {
22623
- opaqueQueue.sort(RenderQueue._compareFromNearToFar);
22624
- alphaTestQueue.sort(RenderQueue._compareFromNearToFar);
22625
- var _viewports_j = viewports[j], x = _viewports_j.x, y = _viewports_j.y;
22626
- rhi.setGlobalDepthBias(1.0, 1.0);
22627
- rhi.viewport(x, y, shadowTileResolution, shadowTileResolution);
22628
- // for no cascade is for the edge,for cascade is for the beyond maxCascade pixel can use (0,0,0) trick sample the shadowMap
22629
- rhi.scissor(x + 1, y + 1, shadowTileResolution - 2, shadowTileResolution - 2);
22630
- engine._renderCount++;
22631
- opaqueQueue.render(camera, exports.Layer.Everything, exports.PipelineStage.ShadowCaster);
22632
- alphaTestQueue.render(camera, exports.Layer.Everything, exports.PipelineStage.ShadowCaster);
22633
- rhi.setGlobalDepthBias(0, 0);
22634
- }
22635
- }
22636
- this._existShadowMap = true;
22637
- }
22638
- };
22639
- _proto._updateReceiversShaderData = function _updateReceiversShaderData() {
22640
- var scene = this._camera.scene;
22581
+ // Prepare render target
22582
+ var _this__shadowMapSize = this._shadowMapSize, width = _this__shadowMapSize.z, height = _this__shadowMapSize.w;
22583
+ var format = this._shadowMapFormat;
22584
+ var renderTarget;
22585
+ var shadowTexture;
22586
+ if (this._supportDepthTexture) {
22587
+ renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, null, format, false);
22588
+ shadowTexture = renderTarget.depthTexture;
22589
+ } else {
22590
+ renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, format, null, false);
22591
+ shadowTexture = renderTarget.getColorTexture(0);
22592
+ }
22593
+ shadowTexture.wrapModeU = shadowTexture.wrapModeV = exports.TextureWrapMode.Clamp;
22594
+ if (engine._hardwareRenderer._isWebGL2) {
22595
+ shadowTexture.depthCompareFunction = exports.TextureDepthCompareFunction.Less;
22596
+ }
22597
+ this._renderTarget = renderTarget;
22598
+ this._depthTexture = shadowTexture;
22599
+ // @todo: shouldn't set viewport and scissor in activeRenderTarget
22600
+ rhi.activeRenderTarget(renderTarget, CascadedShadowCasterPass._viewport, 0);
22601
+ if (this._supportDepthTexture) {
22602
+ rhi.clearRenderTarget(engine, exports.CameraClearFlags.Depth, null);
22603
+ } else {
22604
+ rhi.clearRenderTarget(engine, exports.CameraClearFlags.All, CascadedShadowCasterPass._clearColor);
22605
+ }
22606
+ // prepare light and camera direction
22607
+ engineMath.Matrix.rotationQuaternion(light.entity.transform.worldRotationQuaternion, lightWorld);
22608
+ lightSide.set(lightWorldE[0], lightWorldE[1], lightWorldE[2]);
22609
+ lightUp.set(lightWorldE[4], lightWorldE[5], lightWorldE[6]);
22610
+ lightForward.set(-lightWorldE[8], -lightWorldE[9], -lightWorldE[10]);
22611
+ var cameraForward = CascadedShadowCasterPass._tempVector;
22612
+ cameraForward.copyFrom(camera.entity.transform.worldForward);
22613
+ var shadowTileResolution = this._shadowTileResolution;
22614
+ for(var j = 0; j < shadowCascades; j++){
22615
+ ShadowUtils.getBoundSphereByFrustum(splitDistance[j], splitDistance[j + 1], camera, cameraForward, shadowSliceData);
22616
+ ShadowUtils.getDirectionLightShadowCullPlanes(camera._frustum, splitDistance[j], camera.nearClipPlane, lightForward, shadowSliceData);
22617
+ ShadowUtils.getDirectionalLightMatrices(lightUp, lightSide, lightForward, j, light.shadowNearPlane, shadowTileResolution, shadowSliceData, shadowMatrices);
22618
+ if (shadowCascades > 1) {
22619
+ ShadowUtils.applySliceTransform(shadowTileResolution, width, height, j, this._viewportOffsets[j], shadowMatrices);
22620
+ }
22621
+ this._updateSingleShadowCasterShaderData(light, shadowSliceData, context);
22622
+ // upload pre-cascade infos.
22623
+ var center = boundSphere.center;
22624
+ var radius = boundSphere.radius;
22625
+ var offset = j * 4;
22626
+ splitBoundSpheres[offset] = center.x;
22627
+ splitBoundSpheres[offset + 1] = center.y;
22628
+ splitBoundSpheres[offset + 2] = center.z;
22629
+ splitBoundSpheres[offset + 3] = radius * radius;
22630
+ opaqueQueue.clear();
22631
+ alphaTestQueue.clear();
22632
+ transparentQueue.clear();
22633
+ var renderers = componentsManager._renderers;
22634
+ var elements = renderers._elements;
22635
+ for(var k = renderers.length - 1; k >= 0; --k){
22636
+ ShadowUtils.shadowCullFrustum(context, light, elements[k], shadowSliceData);
22637
+ }
22638
+ if (opaqueQueue.elements.length || alphaTestQueue.elements.length) {
22639
+ opaqueQueue.sort(RenderQueue._compareFromNearToFar);
22640
+ alphaTestQueue.sort(RenderQueue._compareFromNearToFar);
22641
+ var _viewports_j = viewports[j], x = _viewports_j.x, y = _viewports_j.y;
22642
+ rhi.setGlobalDepthBias(1.0, 1.0);
22643
+ rhi.viewport(x, y, shadowTileResolution, shadowTileResolution);
22644
+ // for no cascade is for the edge,for cascade is for the beyond maxCascade pixel can use (0,0,0) trick sample the shadowMap
22645
+ rhi.scissor(x + 1, y + 1, shadowTileResolution - 2, shadowTileResolution - 2);
22646
+ engine._renderCount++;
22647
+ opaqueQueue.render(camera, exports.Layer.Everything, exports.PipelineStage.ShadowCaster);
22648
+ alphaTestQueue.render(camera, exports.Layer.Everything, exports.PipelineStage.ShadowCaster);
22649
+ rhi.setGlobalDepthBias(0, 0);
22650
+ }
22651
+ }
22652
+ };
22653
+ _proto._updateReceiversShaderData = function _updateReceiversShaderData(light) {
22654
+ var camera = this._camera;
22655
+ var scene = camera.scene;
22641
22656
  var splitBoundSpheres = this._splitBoundSpheres;
22642
22657
  var shadowMatrices = this._shadowMatrices;
22643
22658
  var shadowCascades = scene.shadowCascades;
22659
+ var shadowFar = Math.min(scene.shadowDistance, camera.farClipPlane);
22660
+ ShadowUtils.getScaleAndBiasForLinearDistanceFade(Math.pow(shadowFar, 2), scene.shadowFadeBorder, this._shadowInfos);
22661
+ this._shadowInfos.x = light.shadowStrength;
22644
22662
  // set zero matrix to project the index out of max cascade
22645
22663
  if (shadowCascades > 1) {
22646
22664
  for(var i = shadowCascades * 4, n = splitBoundSpheres.length; i < n; i++){
@@ -22653,7 +22671,7 @@ var /**
22653
22671
  }
22654
22672
  var shaderData = scene.shaderData;
22655
22673
  shaderData.setFloatArray(CascadedShadowCasterPass._shadowMatricesProperty, this._shadowMatrices);
22656
- shaderData.setVector3(CascadedShadowCasterPass._shadowInfosProperty, this._shadowInfos);
22674
+ shaderData.setVector4(CascadedShadowCasterPass._shadowInfosProperty, this._shadowInfos);
22657
22675
  shaderData.setTexture(CascadedShadowCasterPass._shadowMapsProperty, this._depthTexture);
22658
22676
  shaderData.setFloatArray(CascadedShadowCasterPass._shadowSplitSpheresProperty, this._splitBoundSpheres);
22659
22677
  shaderData.setVector4(CascadedShadowCasterPass._shadowMapSize, this._shadowMapSize);
@@ -22689,10 +22707,13 @@ var /**
22689
22707
  return Math.sqrt(radius * radius / denominator);
22690
22708
  };
22691
22709
  _proto._updateShadowSettings = function _updateShadowSettings() {
22692
- var scene = this._camera.scene;
22710
+ var camera = this._camera;
22711
+ var scene = camera.scene;
22693
22712
  var shadowFormat = ShadowUtils.shadowDepthFormat(scene.shadowResolution, this._supportDepthTexture);
22694
22713
  var shadowResolution = ShadowUtils.shadowResolution(scene.shadowResolution);
22695
22714
  var shadowCascades = scene.shadowCascades;
22715
+ var shadowFar = Math.min(scene.shadowDistance, camera.farClipPlane);
22716
+ this._getCascadesSplitDistance(shadowFar);
22696
22717
  if (shadowFormat !== this._shadowMapFormat || shadowResolution !== this._shadowMapResolution || shadowCascades !== this._shadowCascadeMode) {
22697
22718
  this._shadowMapFormat = shadowFormat;
22698
22719
  this._shadowMapResolution = shadowResolution;
@@ -23873,6 +23894,7 @@ var MultiExecutor = /*#__PURE__*/ function() {
23873
23894
  * @param obj - class object
23874
23895
  */ Loader.registerClass = function registerClass(className, classDefine) {
23875
23896
  this._engineObjects[className] = classDefine;
23897
+ this._classNameMap.set(classDefine, className);
23876
23898
  };
23877
23899
  /**
23878
23900
  * Get the class object by class name.
@@ -23881,11 +23903,21 @@ var MultiExecutor = /*#__PURE__*/ function() {
23881
23903
  */ Loader.getClass = function getClass(className) {
23882
23904
  return this._engineObjects[className];
23883
23905
  };
23906
+ /**
23907
+ * Get the class name by class object.
23908
+ * @param obj - class object
23909
+ * @returns class name
23910
+ */ Loader.getClassName = function getClassName(obj) {
23911
+ return this._classNameMap.get(obj);
23912
+ };
23884
23913
  return Loader;
23885
23914
  }();
23886
23915
  (function() {
23887
23916
  Loader._engineObjects = {};
23888
23917
  })();
23918
+ (function() {
23919
+ Loader._classNameMap = new Map();
23920
+ })();
23889
23921
 
23890
23922
  /**
23891
23923
  * Alpha blend mode.
@@ -27655,7 +27687,7 @@ __decorate([
27655
27687
  this._clip = clip;
27656
27688
  this._clipEndTime = Math.min(this._clipEndTime, 1);
27657
27689
  this._onClipChanged();
27658
- clip._updateFlagManager.addListener(this._onClipChanged);
27690
+ clip && clip._updateFlagManager.addListener(this._onClipChanged);
27659
27691
  }
27660
27692
  },
27661
27693
  {
@@ -28362,6 +28394,7 @@ __decorate([
28362
28394
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["RotationOverLifetime"] = 0x40eb95e4] = "RotationOverLifetime";
28363
28395
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["TextureSheetAnimation"] = 0xbc524e5] = "TextureSheetAnimation";
28364
28396
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["Shape"] = 0xaf502044] = "Shape";
28397
+ ParticleRandomSubSeeds[ParticleRandomSubSeeds["GravityModifier"] = 0xa47b8c4d] = "GravityModifier";
28365
28398
  })(ParticleRandomSubSeeds || (ParticleRandomSubSeeds = {}));
28366
28399
 
28367
28400
  /**
@@ -29075,6 +29108,7 @@ var MainModule = /*#__PURE__*/ function() {
29075
29108
  /** @internal */ this._startColorRand = new engineMath.Rand(0, ParticleRandomSubSeeds.StartColor);
29076
29109
  /** @internal */ this._startSizeRand = new engineMath.Rand(0, ParticleRandomSubSeeds.StartSize);
29077
29110
  /** @internal */ this._startRotationRand = new engineMath.Rand(0, ParticleRandomSubSeeds.StartRotation);
29111
+ this._gravityModifierRand = new engineMath.Rand(0, ParticleRandomSubSeeds.GravityModifier);
29078
29112
  this._gravity = new engineMath.Vector3();
29079
29113
  this._generator = generator;
29080
29114
  }
@@ -29135,7 +29169,7 @@ var MainModule = /*#__PURE__*/ function() {
29135
29169
  break;
29136
29170
  }
29137
29171
  var particleGravity = this._gravity;
29138
- var gravityModifierValue = this.gravityModifier.evaluate(undefined, undefined);
29172
+ var gravityModifierValue = this.gravityModifier.evaluate(undefined, this._gravityModifierRand.random());
29139
29173
  engineMath.Vector3.scale(renderer.scene.physics.gravity, gravityModifierValue, particleGravity);
29140
29174
  shaderData.setVector3(MainModule._gravity, particleGravity);
29141
29175
  shaderData.setInt(MainModule._simulationSpace, this.simulationSpace);
@@ -29254,6 +29288,9 @@ __decorate([
29254
29288
  __decorate([
29255
29289
  ignoreClone
29256
29290
  ], MainModule.prototype, "_startRotationRand", void 0);
29291
+ __decorate([
29292
+ ignoreClone
29293
+ ], MainModule.prototype, "_gravityModifierRand", void 0);
29257
29294
  __decorate([
29258
29295
  ignoreClone
29259
29296
  ], MainModule.prototype, "_generator", void 0);
@@ -30568,14 +30605,14 @@ __decorate([
30568
30605
 
30569
30606
  /**
30570
30607
  * The emission shape.
30571
- */ var ParticleShapeType;
30608
+ */ exports.ParticleShapeType = void 0;
30572
30609
  (function(ParticleShapeType) {
30573
30610
  ParticleShapeType[ParticleShapeType[/** Emit from the volume of a box. */ "Box"] = 0] = "Box";
30574
30611
  ParticleShapeType[ParticleShapeType[/** Emit from a circle. */ "Circle"] = 1] = "Circle";
30575
30612
  ParticleShapeType[ParticleShapeType[/** Emit from the base of a cone. */ "Cone"] = 2] = "Cone";
30576
30613
  ParticleShapeType[ParticleShapeType[/** Emit from a half-sphere. */ "Hemisphere"] = 3] = "Hemisphere";
30577
30614
  ParticleShapeType[ParticleShapeType[/** Emit from a sphere. */ "Sphere"] = 4] = "Sphere";
30578
- })(ParticleShapeType || (ParticleShapeType = {}));
30615
+ })(exports.ParticleShapeType || (exports.ParticleShapeType = {}));
30579
30616
 
30580
30617
  /**
30581
30618
  * Particle shape that emits particles from a box.
@@ -30583,9 +30620,9 @@ __decorate([
30583
30620
  _inherits(BoxShape, BaseShape1);
30584
30621
  function BoxShape() {
30585
30622
  var _this;
30586
- _this = BaseShape1.call(this) || this;
30623
+ _this = BaseShape1.apply(this, arguments) || this;
30624
+ _this.shapeType = exports.ParticleShapeType.Box;
30587
30625
  /** The size of the box. */ _this.size = new engineMath.Vector3(1, 1, 1);
30588
- _this.shapeType = ParticleShapeType.Box;
30589
30626
  return _this;
30590
30627
  }
30591
30628
  var _proto = BoxShape.prototype;
@@ -30622,12 +30659,12 @@ __decorate([
30622
30659
  _inherits(CircleShape, BaseShape1);
30623
30660
  function CircleShape() {
30624
30661
  var _this;
30625
- _this = BaseShape1.call(this) || this;
30662
+ _this = BaseShape1.apply(this, arguments) || this;
30663
+ _this.shapeType = exports.ParticleShapeType.Circle;
30626
30664
  /** Radius of the shape to emit particles from. */ _this.radius = 1.0;
30627
30665
  /** Angle of the circle arc to emit particles from. */ _this.arc = 360.0;
30628
30666
  /** The mode to generate particles around the arc. */ _this.arcMode = exports.ParticleShapeArcMode.Random;
30629
30667
  /** The speed of complete 360 degree rotation. */ _this.arcSpeed = 1.0;
30630
- _this.shapeType = ParticleShapeType.Circle;
30631
30668
  return _this;
30632
30669
  }
30633
30670
  var _proto = CircleShape.prototype;
@@ -30663,12 +30700,12 @@ __decorate([
30663
30700
  _inherits(ConeShape, BaseShape1);
30664
30701
  function ConeShape() {
30665
30702
  var _this;
30666
- _this = BaseShape1.call(this) || this;
30703
+ _this = BaseShape1.apply(this, arguments) || this;
30704
+ _this.shapeType = exports.ParticleShapeType.Cone;
30667
30705
  /** Angle of the cone to emit particles from. */ _this.angle = 25.0;
30668
30706
  /** Radius of the shape to emit particles from. */ _this.radius = 1.0;
30669
30707
  /** Length of the cone to emit particles from. */ _this.length = 5.0;
30670
30708
  /** Cone emitter type. */ _this.emitType = /** Emit particles from the base of the cone. */ 0;
30671
- _this.shapeType = ParticleShapeType.Cone;
30672
30709
  return _this;
30673
30710
  }
30674
30711
  var _proto = ConeShape.prototype;
@@ -30728,9 +30765,9 @@ exports.ConeEmitType = void 0;
30728
30765
  _inherits(HemisphereShape, BaseShape1);
30729
30766
  function HemisphereShape() {
30730
30767
  var _this;
30731
- _this = BaseShape1.call(this) || this;
30768
+ _this = BaseShape1.apply(this, arguments) || this;
30769
+ _this.shapeType = exports.ParticleShapeType.Hemisphere;
30732
30770
  /** Radius of the shape to emit particles from. */ _this.radius = 1.0;
30733
- _this.shapeType = ParticleShapeType.Hemisphere;
30734
30771
  return _this;
30735
30772
  }
30736
30773
  var _proto = HemisphereShape.prototype;
@@ -30753,9 +30790,9 @@ exports.ConeEmitType = void 0;
30753
30790
  _inherits(SphereShape, BaseShape1);
30754
30791
  function SphereShape() {
30755
30792
  var _this;
30756
- _this = BaseShape1.call(this) || this;
30793
+ _this = BaseShape1.apply(this, arguments) || this;
30794
+ _this.shapeType = exports.ParticleShapeType.Sphere;
30757
30795
  /** Radius of the shape to emit particles from. */ _this.radius = 1.0;
30758
- _this.shapeType = ParticleShapeType.Sphere;
30759
30796
  return _this;
30760
30797
  }
30761
30798
  var _proto = SphereShape.prototype;