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