@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/module.js CHANGED
@@ -3288,7 +3288,7 @@ var PBRShaderLib = {
3288
3288
 
3289
3289
  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
3290
3290
 
3291
- 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
3291
+ 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
3292
3292
 
3293
3293
  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
3294
3294
 
@@ -18927,8 +18927,9 @@ var unlitVs = "#define GLSLIFY 1\n#include <common>\n#include <common_vert>\n#in
18927
18927
  }
18928
18928
  return;
18929
18929
  }
18930
+ ++hierarchy;
18930
18931
  for(var k1 in cacheMap){
18931
- this._recursiveDestroy(++hierarchy, cacheMap[k1]);
18932
+ this._recursiveDestroy(hierarchy, cacheMap[k1]);
18932
18933
  }
18933
18934
  };
18934
18935
  _proto._resizeCacheMapHierarchy = function _resizeCacheMapHierarchy(cacheMap, hierarchy, currentHierarchy, increaseHierarchy) {
@@ -20957,6 +20958,10 @@ __decorate([
20957
20958
  /** The splits of two cascade distribution. */ _this.shadowTwoCascadeSplits = 1.0 / 3.0;
20958
20959
  /** The splits of four cascade distribution. */ _this.shadowFourCascadeSplits = new Vector3(1.0 / 15, 3.0 / 15.0, 7.0 / 15.0);
20959
20960
  /** Max Shadow distance. */ _this.shadowDistance = 50;
20961
+ /**
20962
+ * Last shadow fade distance in percentage, range [0,1].
20963
+ * @remarks Value 0 is used for no shadow fade.
20964
+ */ _this.shadowFadeBorder = 0.1;
20960
20965
  /* @internal */ _this._lightManager = new LightManager();
20961
20966
  /* @internal */ _this._componentsManager = new ComponentsManager();
20962
20967
  /** @internal */ _this._isActiveInEngine = false;
@@ -21581,47 +21586,66 @@ __decorate([
21581
21586
  DepthTextureMode[DepthTextureMode[/* Generate depth texture by pre-pass rendering. */ "PrePass"] = 1] = "PrePass";
21582
21587
  })(DepthTextureMode || (DepthTextureMode = {}));
21583
21588
 
21584
- var passNum = 0;
21585
21589
  /**
21586
- * RenderPass.
21587
- */ var RenderPass = /*#__PURE__*/ function() {
21588
- function RenderPass(name, priority, renderTarget, replaceMaterial, mask) {
21589
- if (name === void 0) name = "RENDER_PASS" + passNum++;
21590
- if (priority === void 0) priority = 0;
21591
- if (renderTarget === void 0) renderTarget = null;
21592
- if (replaceMaterial === void 0) replaceMaterial = null;
21593
- if (mask === void 0) mask = null;
21594
- this.name = name;
21595
- this.enabled = true;
21596
- this.priority = priority;
21597
- this.renderTarget = renderTarget;
21598
- this.replaceMaterial = replaceMaterial;
21599
- this.mask = mask || Layer.Everything;
21600
- this.renderOverride = false; // If renderOverride is set to true, you need to implement the render method
21601
- }
21602
- var _proto = RenderPass.prototype;
21603
- /**
21604
- * Rendering callback, will be executed if renderOverride is set to true.
21605
- * @param camera - Camera
21606
- * @param opaqueQueue - Opaque queue
21607
- * @param alphaTestQueue - Alpha test queue
21608
- * @param transparentQueue - Transparent queue
21609
- */ _proto.render = function render(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
21590
+ * PipelinePass is a base class for all pipeline passes.
21591
+ */ var PipelinePass = function PipelinePass(engine) {
21592
+ this._engine = engine;
21593
+ };
21594
+
21595
+ /**
21596
+ * @internal
21597
+ */ var PipelineUtils = /*#__PURE__*/ function() {
21598
+ function PipelineUtils() {}
21610
21599
  /**
21611
- * Post rendering callback.
21612
- * @param camera - Camera
21613
- * @param opaqueQueue - Opaque queue
21614
- * @param alphaTestQueue - Alpha test queue
21615
- * @param transparentQueue - Transparent queue
21616
- */ _proto.preRender = function preRender(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
21600
+ * Recreate texture if needed.
21601
+ * @param engine - Engine
21602
+ * @param currentTexture - Current texture
21603
+ * @param width - Need texture width
21604
+ * @param height - Need texture height
21605
+ * @param format - Need texture format
21606
+ * @param mipmap - Need texture mipmap
21607
+ * @returns Texture
21608
+ */ PipelineUtils.recreateTextureIfNeeded = function recreateTextureIfNeeded(engine, currentTexture, width, height, format, mipmap) {
21609
+ if (currentTexture) {
21610
+ if (currentTexture.width !== width || currentTexture.height !== height || currentTexture.format !== format || currentTexture.mipmapCount > 1 !== mipmap) {
21611
+ currentTexture.destroy();
21612
+ var texture = new Texture2D(engine, width, height, format, mipmap);
21613
+ texture.isGCIgnored = true;
21614
+ return texture;
21615
+ } else {
21616
+ return currentTexture;
21617
+ }
21618
+ } else {
21619
+ var texture1 = new Texture2D(engine, width, height, format, mipmap);
21620
+ texture1.isGCIgnored = true;
21621
+ return texture1;
21622
+ }
21623
+ };
21617
21624
  /**
21618
- * Post rendering callback.
21619
- * @param camera - Camera
21620
- * @param opaqueQueue - Opaque queue
21621
- * @param alphaTestQueue - Alpha test queue
21622
- * @param transparentQueue - Transparent queue
21623
- */ _proto.postRender = function postRender(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
21624
- return RenderPass;
21625
+ * Recreate render target if needed.
21626
+ * @param engine - Engine
21627
+ * @param currentRenderTarget - Current render target
21628
+ * @param width - Need render target width
21629
+ * @param height - Need render target height
21630
+ * @param colorFormat - Need render target color format
21631
+ * @param depthFormat - Need render target depth format
21632
+ * @param mipmap - Need render target mipmap
21633
+ * @returns Render target
21634
+ */ PipelineUtils.recreateRenderTargetIfNeeded = function recreateRenderTargetIfNeeded(engine, currentRenderTarget, width, height, colorFormat, depthFormat, mipmap) {
21635
+ var _currentRenderTarget, _currentRenderTarget1;
21636
+ var currentColorTexture = (_currentRenderTarget = currentRenderTarget) == null ? void 0 : _currentRenderTarget.getColorTexture(0);
21637
+ var currentDepthTexture = (_currentRenderTarget1 = currentRenderTarget) == null ? void 0 : _currentRenderTarget1.depthTexture;
21638
+ var colorTexture = colorFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentColorTexture, width, height, colorFormat, mipmap) : null;
21639
+ var depthTexture = depthFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentDepthTexture, width, height, depthFormat, mipmap) : null;
21640
+ if (currentColorTexture !== colorTexture || currentDepthTexture !== depthTexture) {
21641
+ var _currentRenderTarget2;
21642
+ (_currentRenderTarget2 = currentRenderTarget) == null ? void 0 : _currentRenderTarget2.destroy();
21643
+ currentRenderTarget = new RenderTarget(engine, width, height, colorTexture, depthTexture);
21644
+ currentRenderTarget.isGCIgnored = true;
21645
+ }
21646
+ return currentRenderTarget;
21647
+ };
21648
+ return PipelineUtils;
21625
21649
  }();
21626
21650
 
21627
21651
  /**
@@ -21928,60 +21952,47 @@ var passNum = 0;
21928
21952
  return RenderQueue;
21929
21953
  }();
21930
21954
 
21955
+ var passNum = 0;
21931
21956
  /**
21932
- * @internal
21933
- */ var PipelineUtils = /*#__PURE__*/ function() {
21934
- function PipelineUtils() {}
21957
+ * RenderPass.
21958
+ */ var RenderPass = /*#__PURE__*/ function() {
21959
+ function RenderPass(name, priority, renderTarget, replaceMaterial, mask) {
21960
+ if (name === void 0) name = "RENDER_PASS" + passNum++;
21961
+ if (priority === void 0) priority = 0;
21962
+ if (renderTarget === void 0) renderTarget = null;
21963
+ if (replaceMaterial === void 0) replaceMaterial = null;
21964
+ if (mask === void 0) mask = null;
21965
+ this.name = name;
21966
+ this.enabled = true;
21967
+ this.priority = priority;
21968
+ this.renderTarget = renderTarget;
21969
+ this.replaceMaterial = replaceMaterial;
21970
+ this.mask = mask || Layer.Everything;
21971
+ this.renderOverride = false; // If renderOverride is set to true, you need to implement the render method
21972
+ }
21973
+ var _proto = RenderPass.prototype;
21935
21974
  /**
21936
- * Recreate texture if needed.
21937
- * @param engine - Engine
21938
- * @param currentTexture - Current texture
21939
- * @param width - Need texture width
21940
- * @param height - Need texture height
21941
- * @param format - Need texture format
21942
- * @param mipmap - Need texture mipmap
21943
- * @returns Texture
21944
- */ PipelineUtils.recreateTextureIfNeeded = function recreateTextureIfNeeded(engine, currentTexture, width, height, format, mipmap) {
21945
- if (currentTexture) {
21946
- if (currentTexture.width !== width || currentTexture.height !== height || currentTexture.format !== format || currentTexture.mipmapCount > 1 !== mipmap) {
21947
- currentTexture.destroy();
21948
- var texture = new Texture2D(engine, width, height, format, mipmap);
21949
- texture.isGCIgnored = true;
21950
- return texture;
21951
- } else {
21952
- return currentTexture;
21953
- }
21954
- } else {
21955
- var texture1 = new Texture2D(engine, width, height, format, mipmap);
21956
- texture1.isGCIgnored = true;
21957
- return texture1;
21958
- }
21959
- };
21975
+ * Rendering callback, will be executed if renderOverride is set to true.
21976
+ * @param camera - Camera
21977
+ * @param opaqueQueue - Opaque queue
21978
+ * @param alphaTestQueue - Alpha test queue
21979
+ * @param transparentQueue - Transparent queue
21980
+ */ _proto.render = function render(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
21960
21981
  /**
21961
- * Recreate render target if needed.
21962
- * @param engine - Engine
21963
- * @param currentRenderTarget - Current render target
21964
- * @param width - Need render target width
21965
- * @param height - Need render target height
21966
- * @param colorFormat - Need render target color format
21967
- * @param depthFormat - Need render target depth format
21968
- * @param mipmap - Need render target mipmap
21969
- * @returns Render target
21970
- */ PipelineUtils.recreateRenderTargetIfNeeded = function recreateRenderTargetIfNeeded(engine, currentRenderTarget, width, height, colorFormat, depthFormat, mipmap) {
21971
- var _currentRenderTarget, _currentRenderTarget1;
21972
- var currentColorTexture = (_currentRenderTarget = currentRenderTarget) == null ? void 0 : _currentRenderTarget.getColorTexture(0);
21973
- var currentDepthTexture = (_currentRenderTarget1 = currentRenderTarget) == null ? void 0 : _currentRenderTarget1.depthTexture;
21974
- var colorTexture = colorFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentColorTexture, width, height, colorFormat, mipmap) : null;
21975
- var depthTexture = depthFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentDepthTexture, width, height, depthFormat, mipmap) : null;
21976
- if (currentColorTexture !== colorTexture || currentDepthTexture !== depthTexture) {
21977
- var _currentRenderTarget2;
21978
- (_currentRenderTarget2 = currentRenderTarget) == null ? void 0 : _currentRenderTarget2.destroy();
21979
- currentRenderTarget = new RenderTarget(engine, width, height, colorTexture, depthTexture);
21980
- currentRenderTarget.isGCIgnored = true;
21981
- }
21982
- return currentRenderTarget;
21983
- };
21984
- return PipelineUtils;
21982
+ * Post rendering callback.
21983
+ * @param camera - Camera
21984
+ * @param opaqueQueue - Opaque queue
21985
+ * @param alphaTestQueue - Alpha test queue
21986
+ * @param transparentQueue - Transparent queue
21987
+ */ _proto.preRender = function preRender(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
21988
+ /**
21989
+ * Post rendering callback.
21990
+ * @param camera - Camera
21991
+ * @param opaqueQueue - Opaque queue
21992
+ * @param alphaTestQueue - Alpha test queue
21993
+ * @param transparentQueue - Transparent queue
21994
+ */ _proto.postRender = function postRender(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
21995
+ return RenderPass;
21985
21996
  }();
21986
21997
 
21987
21998
  /**
@@ -22249,6 +22260,26 @@ var /**
22249
22260
  var offset = cascadeIndex * 16;
22250
22261
  Utils._floatMatrixMultiply(sliceMatrix, outShadowMatrices, offset, outShadowMatrices, offset);
22251
22262
  };
22263
+ /**
22264
+ * Extract scale and bias from a fade distance to achieve a linear fading of the fade distance.
22265
+ */ ShadowUtils.getScaleAndBiasForLinearDistanceFade = function getScaleAndBiasForLinearDistanceFade(fadeDistance, border, outInfo) {
22266
+ // (P^2-N^2)/(F^2-N^2)
22267
+ // To avoid division from zero
22268
+ // This values ensure that fade within cascade will be 0 and outside 1
22269
+ if (border < 0.0001) {
22270
+ var multiplier = 1000; // To avoid blending if difference is in fractions
22271
+ outInfo.z = multiplier;
22272
+ outInfo.w = -fadeDistance * multiplier;
22273
+ return;
22274
+ }
22275
+ border = 1 - border;
22276
+ border *= border;
22277
+ // 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.
22278
+ var distanceFadeNear = border * fadeDistance;
22279
+ var fadeRange = fadeDistance - distanceFadeNear;
22280
+ outInfo.z = 1.0 / fadeRange;
22281
+ outInfo.w = -distanceFadeNear / fadeRange;
22282
+ };
22252
22283
  return ShadowUtils;
22253
22284
  }();
22254
22285
  (function() {
@@ -22493,12 +22524,6 @@ var /**
22493
22524
  ShadowUtils.atlasBorderSize = 4.0;
22494
22525
  })();
22495
22526
 
22496
- /**
22497
- * PipelinePass is a base class for all pipeline passes.
22498
- */ var PipelinePass = function PipelinePass(engine) {
22499
- this._engine = engine;
22500
- };
22501
-
22502
22527
  /**
22503
22528
  * Cascade shadow caster pass.
22504
22529
  */ var CascadedShadowCasterPass = /*#__PURE__*/ function(PipelinePass1) {
@@ -22511,11 +22536,10 @@ var /**
22511
22536
  _this._shadowSliceData = new ShadowSliceData();
22512
22537
  _this._lightUp = new Vector3();
22513
22538
  _this._lightSide = new Vector3();
22514
- _this._existShadowMap = false;
22515
22539
  _this._splitBoundSpheres = new Float32Array(CascadedShadowCasterPass._maxCascades * 4);
22516
22540
  /** The end is project precision problem in shader. */ _this._shadowMatrices = new Float32Array((CascadedShadowCasterPass._maxCascades + 1) * 16);
22517
- // strength, null, lightIndex
22518
- _this._shadowInfos = new Vector3();
22541
+ // intensity, null, fadeScale, fadeBias
22542
+ _this._shadowInfos = new Vector4();
22519
22543
  _this._viewportOffsets = [
22520
22544
  new Vector2(),
22521
22545
  new Vector2(),
@@ -22531,14 +22555,12 @@ var /**
22531
22555
  /**
22532
22556
  * @internal
22533
22557
  */ _proto.onRender = function onRender(context) {
22558
+ var light = this._camera.scene._lightManager._sunlight;
22534
22559
  this._updateShadowSettings();
22535
- this._existShadowMap = false;
22536
- this._renderDirectShadowMap(context);
22537
- if (this._existShadowMap) {
22538
- this._updateReceiversShaderData();
22539
- }
22560
+ this._renderDirectShadowMap(context, light);
22561
+ this._updateReceiversShaderData(light);
22540
22562
  };
22541
- _proto._renderDirectShadowMap = function _renderDirectShadowMap(context) {
22563
+ _proto._renderDirectShadowMap = function _renderDirectShadowMap(context, light) {
22542
22564
  var _this = this, engine = _this._engine, camera = _this._camera, viewports = _this._viewportOffsets, shadowSliceData = _this._shadowSliceData, splitBoundSpheres = _this._splitBoundSpheres, shadowMatrices = _this._shadowMatrices;
22543
22565
  var _camera__renderPipeline__cullingResults = camera._renderPipeline._cullingResults, opaqueQueue = _camera__renderPipeline__cullingResults.opaqueQueue, alphaTestQueue = _camera__renderPipeline__cullingResults.alphaTestQueue, transparentQueue = _camera__renderPipeline__cullingResults.transparentQueue;
22544
22566
  var scene = camera.scene;
@@ -22552,91 +22574,87 @@ var /**
22552
22574
  var lightUp = this._lightUp;
22553
22575
  var lightSide = this._lightSide;
22554
22576
  var lightForward = shadowSliceData.virtualCamera.forward;
22555
- var light = scene._lightManager._sunlight;
22556
- if (light) {
22557
- var shadowFar = Math.min(camera.scene.shadowDistance, camera.farClipPlane);
22558
- this._getCascadesSplitDistance(shadowFar);
22559
- // Prepare render target
22560
- var _this__shadowMapSize = this._shadowMapSize, width = _this__shadowMapSize.z, height = _this__shadowMapSize.w;
22561
- var format = this._shadowMapFormat;
22562
- var renderTarget;
22563
- var shadowTexture;
22564
- if (this._supportDepthTexture) {
22565
- renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, null, format, false);
22566
- shadowTexture = renderTarget.depthTexture;
22567
- } else {
22568
- renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, format, null, false);
22569
- shadowTexture = renderTarget.getColorTexture(0);
22570
- }
22571
- shadowTexture.wrapModeU = shadowTexture.wrapModeV = TextureWrapMode.Clamp;
22572
- if (engine._hardwareRenderer._isWebGL2) {
22573
- shadowTexture.depthCompareFunction = TextureDepthCompareFunction.Less;
22574
- }
22575
- this._renderTarget = renderTarget;
22576
- this._depthTexture = shadowTexture;
22577
- // @todo: shouldn't set viewport and scissor in activeRenderTarget
22578
- rhi.activeRenderTarget(renderTarget, CascadedShadowCasterPass._viewport, 0);
22579
- if (this._supportDepthTexture) {
22580
- rhi.clearRenderTarget(engine, CameraClearFlags.Depth, null);
22581
- } else {
22582
- rhi.clearRenderTarget(engine, CameraClearFlags.All, CascadedShadowCasterPass._clearColor);
22583
- }
22584
- this._shadowInfos.x = light.shadowStrength;
22585
- this._shadowInfos.z = 0; // @todo: sun light index always 0
22586
- // prepare light and camera direction
22587
- Matrix.rotationQuaternion(light.entity.transform.worldRotationQuaternion, lightWorld);
22588
- lightSide.set(lightWorldE[0], lightWorldE[1], lightWorldE[2]);
22589
- lightUp.set(lightWorldE[4], lightWorldE[5], lightWorldE[6]);
22590
- lightForward.set(-lightWorldE[8], -lightWorldE[9], -lightWorldE[10]);
22591
- var cameraForward = CascadedShadowCasterPass._tempVector;
22592
- cameraForward.copyFrom(camera.entity.transform.worldForward);
22593
- var shadowTileResolution = this._shadowTileResolution;
22594
- for(var j = 0; j < shadowCascades; j++){
22595
- ShadowUtils.getBoundSphereByFrustum(splitDistance[j], splitDistance[j + 1], camera, cameraForward, shadowSliceData);
22596
- ShadowUtils.getDirectionLightShadowCullPlanes(camera._frustum, splitDistance[j], camera.nearClipPlane, lightForward, shadowSliceData);
22597
- ShadowUtils.getDirectionalLightMatrices(lightUp, lightSide, lightForward, j, light.shadowNearPlane, shadowTileResolution, shadowSliceData, shadowMatrices);
22598
- if (shadowCascades > 1) {
22599
- ShadowUtils.applySliceTransform(shadowTileResolution, width, height, j, this._viewportOffsets[j], shadowMatrices);
22600
- }
22601
- this._updateSingleShadowCasterShaderData(light, shadowSliceData, context);
22602
- // upload pre-cascade infos.
22603
- var center = boundSphere.center;
22604
- var radius = boundSphere.radius;
22605
- var offset = j * 4;
22606
- splitBoundSpheres[offset] = center.x;
22607
- splitBoundSpheres[offset + 1] = center.y;
22608
- splitBoundSpheres[offset + 2] = center.z;
22609
- splitBoundSpheres[offset + 3] = radius * radius;
22610
- opaqueQueue.clear();
22611
- alphaTestQueue.clear();
22612
- transparentQueue.clear();
22613
- var renderers = componentsManager._renderers;
22614
- var elements = renderers._elements;
22615
- for(var k = renderers.length - 1; k >= 0; --k){
22616
- ShadowUtils.shadowCullFrustum(context, light, elements[k], shadowSliceData);
22617
- }
22618
- if (opaqueQueue.elements.length || alphaTestQueue.elements.length) {
22619
- opaqueQueue.sort(RenderQueue._compareFromNearToFar);
22620
- alphaTestQueue.sort(RenderQueue._compareFromNearToFar);
22621
- var _viewports_j = viewports[j], x = _viewports_j.x, y = _viewports_j.y;
22622
- rhi.setGlobalDepthBias(1.0, 1.0);
22623
- rhi.viewport(x, y, shadowTileResolution, shadowTileResolution);
22624
- // for no cascade is for the edge,for cascade is for the beyond maxCascade pixel can use (0,0,0) trick sample the shadowMap
22625
- rhi.scissor(x + 1, y + 1, shadowTileResolution - 2, shadowTileResolution - 2);
22626
- engine._renderCount++;
22627
- opaqueQueue.render(camera, Layer.Everything, PipelineStage.ShadowCaster);
22628
- alphaTestQueue.render(camera, Layer.Everything, PipelineStage.ShadowCaster);
22629
- rhi.setGlobalDepthBias(0, 0);
22630
- }
22631
- }
22632
- this._existShadowMap = true;
22633
- }
22634
- };
22635
- _proto._updateReceiversShaderData = function _updateReceiversShaderData() {
22636
- var scene = this._camera.scene;
22577
+ // Prepare render target
22578
+ var _this__shadowMapSize = this._shadowMapSize, width = _this__shadowMapSize.z, height = _this__shadowMapSize.w;
22579
+ var format = this._shadowMapFormat;
22580
+ var renderTarget;
22581
+ var shadowTexture;
22582
+ if (this._supportDepthTexture) {
22583
+ renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, null, format, false);
22584
+ shadowTexture = renderTarget.depthTexture;
22585
+ } else {
22586
+ renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, format, null, false);
22587
+ shadowTexture = renderTarget.getColorTexture(0);
22588
+ }
22589
+ shadowTexture.wrapModeU = shadowTexture.wrapModeV = TextureWrapMode.Clamp;
22590
+ if (engine._hardwareRenderer._isWebGL2) {
22591
+ shadowTexture.depthCompareFunction = TextureDepthCompareFunction.Less;
22592
+ }
22593
+ this._renderTarget = renderTarget;
22594
+ this._depthTexture = shadowTexture;
22595
+ // @todo: shouldn't set viewport and scissor in activeRenderTarget
22596
+ rhi.activeRenderTarget(renderTarget, CascadedShadowCasterPass._viewport, 0);
22597
+ if (this._supportDepthTexture) {
22598
+ rhi.clearRenderTarget(engine, CameraClearFlags.Depth, null);
22599
+ } else {
22600
+ rhi.clearRenderTarget(engine, CameraClearFlags.All, CascadedShadowCasterPass._clearColor);
22601
+ }
22602
+ // prepare light and camera direction
22603
+ Matrix.rotationQuaternion(light.entity.transform.worldRotationQuaternion, lightWorld);
22604
+ lightSide.set(lightWorldE[0], lightWorldE[1], lightWorldE[2]);
22605
+ lightUp.set(lightWorldE[4], lightWorldE[5], lightWorldE[6]);
22606
+ lightForward.set(-lightWorldE[8], -lightWorldE[9], -lightWorldE[10]);
22607
+ var cameraForward = CascadedShadowCasterPass._tempVector;
22608
+ cameraForward.copyFrom(camera.entity.transform.worldForward);
22609
+ var shadowTileResolution = this._shadowTileResolution;
22610
+ for(var j = 0; j < shadowCascades; j++){
22611
+ ShadowUtils.getBoundSphereByFrustum(splitDistance[j], splitDistance[j + 1], camera, cameraForward, shadowSliceData);
22612
+ ShadowUtils.getDirectionLightShadowCullPlanes(camera._frustum, splitDistance[j], camera.nearClipPlane, lightForward, shadowSliceData);
22613
+ ShadowUtils.getDirectionalLightMatrices(lightUp, lightSide, lightForward, j, light.shadowNearPlane, shadowTileResolution, shadowSliceData, shadowMatrices);
22614
+ if (shadowCascades > 1) {
22615
+ ShadowUtils.applySliceTransform(shadowTileResolution, width, height, j, this._viewportOffsets[j], shadowMatrices);
22616
+ }
22617
+ this._updateSingleShadowCasterShaderData(light, shadowSliceData, context);
22618
+ // upload pre-cascade infos.
22619
+ var center = boundSphere.center;
22620
+ var radius = boundSphere.radius;
22621
+ var offset = j * 4;
22622
+ splitBoundSpheres[offset] = center.x;
22623
+ splitBoundSpheres[offset + 1] = center.y;
22624
+ splitBoundSpheres[offset + 2] = center.z;
22625
+ splitBoundSpheres[offset + 3] = radius * radius;
22626
+ opaqueQueue.clear();
22627
+ alphaTestQueue.clear();
22628
+ transparentQueue.clear();
22629
+ var renderers = componentsManager._renderers;
22630
+ var elements = renderers._elements;
22631
+ for(var k = renderers.length - 1; k >= 0; --k){
22632
+ ShadowUtils.shadowCullFrustum(context, light, elements[k], shadowSliceData);
22633
+ }
22634
+ if (opaqueQueue.elements.length || alphaTestQueue.elements.length) {
22635
+ opaqueQueue.sort(RenderQueue._compareFromNearToFar);
22636
+ alphaTestQueue.sort(RenderQueue._compareFromNearToFar);
22637
+ var _viewports_j = viewports[j], x = _viewports_j.x, y = _viewports_j.y;
22638
+ rhi.setGlobalDepthBias(1.0, 1.0);
22639
+ rhi.viewport(x, y, shadowTileResolution, shadowTileResolution);
22640
+ // for no cascade is for the edge,for cascade is for the beyond maxCascade pixel can use (0,0,0) trick sample the shadowMap
22641
+ rhi.scissor(x + 1, y + 1, shadowTileResolution - 2, shadowTileResolution - 2);
22642
+ engine._renderCount++;
22643
+ opaqueQueue.render(camera, Layer.Everything, PipelineStage.ShadowCaster);
22644
+ alphaTestQueue.render(camera, Layer.Everything, PipelineStage.ShadowCaster);
22645
+ rhi.setGlobalDepthBias(0, 0);
22646
+ }
22647
+ }
22648
+ };
22649
+ _proto._updateReceiversShaderData = function _updateReceiversShaderData(light) {
22650
+ var camera = this._camera;
22651
+ var scene = camera.scene;
22637
22652
  var splitBoundSpheres = this._splitBoundSpheres;
22638
22653
  var shadowMatrices = this._shadowMatrices;
22639
22654
  var shadowCascades = scene.shadowCascades;
22655
+ var shadowFar = Math.min(scene.shadowDistance, camera.farClipPlane);
22656
+ ShadowUtils.getScaleAndBiasForLinearDistanceFade(Math.pow(shadowFar, 2), scene.shadowFadeBorder, this._shadowInfos);
22657
+ this._shadowInfos.x = light.shadowStrength;
22640
22658
  // set zero matrix to project the index out of max cascade
22641
22659
  if (shadowCascades > 1) {
22642
22660
  for(var i = shadowCascades * 4, n = splitBoundSpheres.length; i < n; i++){
@@ -22649,7 +22667,7 @@ var /**
22649
22667
  }
22650
22668
  var shaderData = scene.shaderData;
22651
22669
  shaderData.setFloatArray(CascadedShadowCasterPass._shadowMatricesProperty, this._shadowMatrices);
22652
- shaderData.setVector3(CascadedShadowCasterPass._shadowInfosProperty, this._shadowInfos);
22670
+ shaderData.setVector4(CascadedShadowCasterPass._shadowInfosProperty, this._shadowInfos);
22653
22671
  shaderData.setTexture(CascadedShadowCasterPass._shadowMapsProperty, this._depthTexture);
22654
22672
  shaderData.setFloatArray(CascadedShadowCasterPass._shadowSplitSpheresProperty, this._splitBoundSpheres);
22655
22673
  shaderData.setVector4(CascadedShadowCasterPass._shadowMapSize, this._shadowMapSize);
@@ -22685,10 +22703,13 @@ var /**
22685
22703
  return Math.sqrt(radius * radius / denominator);
22686
22704
  };
22687
22705
  _proto._updateShadowSettings = function _updateShadowSettings() {
22688
- var scene = this._camera.scene;
22706
+ var camera = this._camera;
22707
+ var scene = camera.scene;
22689
22708
  var shadowFormat = ShadowUtils.shadowDepthFormat(scene.shadowResolution, this._supportDepthTexture);
22690
22709
  var shadowResolution = ShadowUtils.shadowResolution(scene.shadowResolution);
22691
22710
  var shadowCascades = scene.shadowCascades;
22711
+ var shadowFar = Math.min(scene.shadowDistance, camera.farClipPlane);
22712
+ this._getCascadesSplitDistance(shadowFar);
22692
22713
  if (shadowFormat !== this._shadowMapFormat || shadowResolution !== this._shadowMapResolution || shadowCascades !== this._shadowCascadeMode) {
22693
22714
  this._shadowMapFormat = shadowFormat;
22694
22715
  this._shadowMapResolution = shadowResolution;
@@ -23869,6 +23890,7 @@ var MultiExecutor = /*#__PURE__*/ function() {
23869
23890
  * @param obj - class object
23870
23891
  */ Loader.registerClass = function registerClass(className, classDefine) {
23871
23892
  this._engineObjects[className] = classDefine;
23893
+ this._classNameMap.set(classDefine, className);
23872
23894
  };
23873
23895
  /**
23874
23896
  * Get the class object by class name.
@@ -23877,11 +23899,21 @@ var MultiExecutor = /*#__PURE__*/ function() {
23877
23899
  */ Loader.getClass = function getClass(className) {
23878
23900
  return this._engineObjects[className];
23879
23901
  };
23902
+ /**
23903
+ * Get the class name by class object.
23904
+ * @param obj - class object
23905
+ * @returns class name
23906
+ */ Loader.getClassName = function getClassName(obj) {
23907
+ return this._classNameMap.get(obj);
23908
+ };
23880
23909
  return Loader;
23881
23910
  }();
23882
23911
  (function() {
23883
23912
  Loader._engineObjects = {};
23884
23913
  })();
23914
+ (function() {
23915
+ Loader._classNameMap = new Map();
23916
+ })();
23885
23917
 
23886
23918
  /**
23887
23919
  * Alpha blend mode.
@@ -27651,7 +27683,7 @@ __decorate([
27651
27683
  this._clip = clip;
27652
27684
  this._clipEndTime = Math.min(this._clipEndTime, 1);
27653
27685
  this._onClipChanged();
27654
- clip._updateFlagManager.addListener(this._onClipChanged);
27686
+ clip && clip._updateFlagManager.addListener(this._onClipChanged);
27655
27687
  }
27656
27688
  },
27657
27689
  {
@@ -28358,6 +28390,7 @@ __decorate([
28358
28390
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["RotationOverLifetime"] = 0x40eb95e4] = "RotationOverLifetime";
28359
28391
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["TextureSheetAnimation"] = 0xbc524e5] = "TextureSheetAnimation";
28360
28392
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["Shape"] = 0xaf502044] = "Shape";
28393
+ ParticleRandomSubSeeds[ParticleRandomSubSeeds["GravityModifier"] = 0xa47b8c4d] = "GravityModifier";
28361
28394
  })(ParticleRandomSubSeeds || (ParticleRandomSubSeeds = {}));
28362
28395
 
28363
28396
  /**
@@ -29071,6 +29104,7 @@ var MainModule = /*#__PURE__*/ function() {
29071
29104
  /** @internal */ this._startColorRand = new Rand(0, ParticleRandomSubSeeds.StartColor);
29072
29105
  /** @internal */ this._startSizeRand = new Rand(0, ParticleRandomSubSeeds.StartSize);
29073
29106
  /** @internal */ this._startRotationRand = new Rand(0, ParticleRandomSubSeeds.StartRotation);
29107
+ this._gravityModifierRand = new Rand(0, ParticleRandomSubSeeds.GravityModifier);
29074
29108
  this._gravity = new Vector3();
29075
29109
  this._generator = generator;
29076
29110
  }
@@ -29131,7 +29165,7 @@ var MainModule = /*#__PURE__*/ function() {
29131
29165
  break;
29132
29166
  }
29133
29167
  var particleGravity = this._gravity;
29134
- var gravityModifierValue = this.gravityModifier.evaluate(undefined, undefined);
29168
+ var gravityModifierValue = this.gravityModifier.evaluate(undefined, this._gravityModifierRand.random());
29135
29169
  Vector3.scale(renderer.scene.physics.gravity, gravityModifierValue, particleGravity);
29136
29170
  shaderData.setVector3(MainModule._gravity, particleGravity);
29137
29171
  shaderData.setInt(MainModule._simulationSpace, this.simulationSpace);
@@ -29250,6 +29284,9 @@ __decorate([
29250
29284
  __decorate([
29251
29285
  ignoreClone
29252
29286
  ], MainModule.prototype, "_startRotationRand", void 0);
29287
+ __decorate([
29288
+ ignoreClone
29289
+ ], MainModule.prototype, "_gravityModifierRand", void 0);
29253
29290
  __decorate([
29254
29291
  ignoreClone
29255
29292
  ], MainModule.prototype, "_generator", void 0);
@@ -30579,9 +30616,9 @@ __decorate([
30579
30616
  _inherits(BoxShape, BaseShape1);
30580
30617
  function BoxShape() {
30581
30618
  var _this;
30582
- _this = BaseShape1.call(this) || this;
30583
- /** The size of the box. */ _this.size = new Vector3(1, 1, 1);
30619
+ _this = BaseShape1.apply(this, arguments) || this;
30584
30620
  _this.shapeType = ParticleShapeType.Box;
30621
+ /** The size of the box. */ _this.size = new Vector3(1, 1, 1);
30585
30622
  return _this;
30586
30623
  }
30587
30624
  var _proto = BoxShape.prototype;
@@ -30618,12 +30655,12 @@ __decorate([
30618
30655
  _inherits(CircleShape, BaseShape1);
30619
30656
  function CircleShape() {
30620
30657
  var _this;
30621
- _this = BaseShape1.call(this) || this;
30658
+ _this = BaseShape1.apply(this, arguments) || this;
30659
+ _this.shapeType = ParticleShapeType.Circle;
30622
30660
  /** Radius of the shape to emit particles from. */ _this.radius = 1.0;
30623
30661
  /** Angle of the circle arc to emit particles from. */ _this.arc = 360.0;
30624
30662
  /** The mode to generate particles around the arc. */ _this.arcMode = ParticleShapeArcMode.Random;
30625
30663
  /** The speed of complete 360 degree rotation. */ _this.arcSpeed = 1.0;
30626
- _this.shapeType = ParticleShapeType.Circle;
30627
30664
  return _this;
30628
30665
  }
30629
30666
  var _proto = CircleShape.prototype;
@@ -30659,12 +30696,12 @@ __decorate([
30659
30696
  _inherits(ConeShape, BaseShape1);
30660
30697
  function ConeShape() {
30661
30698
  var _this;
30662
- _this = BaseShape1.call(this) || this;
30699
+ _this = BaseShape1.apply(this, arguments) || this;
30700
+ _this.shapeType = ParticleShapeType.Cone;
30663
30701
  /** Angle of the cone to emit particles from. */ _this.angle = 25.0;
30664
30702
  /** Radius of the shape to emit particles from. */ _this.radius = 1.0;
30665
30703
  /** Length of the cone to emit particles from. */ _this.length = 5.0;
30666
30704
  /** Cone emitter type. */ _this.emitType = /** Emit particles from the base of the cone. */ 0;
30667
- _this.shapeType = ParticleShapeType.Cone;
30668
30705
  return _this;
30669
30706
  }
30670
30707
  var _proto = ConeShape.prototype;
@@ -30724,9 +30761,9 @@ var ConeEmitType;
30724
30761
  _inherits(HemisphereShape, BaseShape1);
30725
30762
  function HemisphereShape() {
30726
30763
  var _this;
30727
- _this = BaseShape1.call(this) || this;
30728
- /** Radius of the shape to emit particles from. */ _this.radius = 1.0;
30764
+ _this = BaseShape1.apply(this, arguments) || this;
30729
30765
  _this.shapeType = ParticleShapeType.Hemisphere;
30766
+ /** Radius of the shape to emit particles from. */ _this.radius = 1.0;
30730
30767
  return _this;
30731
30768
  }
30732
30769
  var _proto = HemisphereShape.prototype;
@@ -30749,9 +30786,9 @@ var ConeEmitType;
30749
30786
  _inherits(SphereShape, BaseShape1);
30750
30787
  function SphereShape() {
30751
30788
  var _this;
30752
- _this = BaseShape1.call(this) || this;
30753
- /** Radius of the shape to emit particles from. */ _this.radius = 1.0;
30789
+ _this = BaseShape1.apply(this, arguments) || this;
30754
30790
  _this.shapeType = ParticleShapeType.Sphere;
30791
+ /** Radius of the shape to emit particles from. */ _this.radius = 1.0;
30755
30792
  return _this;
30756
30793
  }
30757
30794
  var _proto = SphereShape.prototype;
@@ -31124,5 +31161,5 @@ var cacheDir = new Vector3();
31124
31161
  return CubeProbe;
31125
31162
  }(Probe);
31126
31163
 
31127
- export { AmbientLight, AnimationArrayCurve, AnimationBoolCurve, AnimationClip, AnimationClipCurveBinding, AnimationColorCurve, AnimationCurve, AnimationEvent, AnimationFloatArrayCurve, AnimationFloatCurve, AnimationQuaternionCurve, AnimationRectCurve, AnimationRefCurve, AnimationStringCurve, AnimationVector2Curve, AnimationVector3Curve, AnimationVector4Curve, Animator, AnimatorConditionMode, AnimatorController, AnimatorControllerLayer, AnimatorCullingMode, AnimatorLayerBlendingMode, AnimatorLayerMask, AnimatorState, AnimatorStateMachine, AnimatorStateTransition, AssetPromise, AssetType, Background, BackgroundMode, BackgroundTextureFillMode, BaseMaterial, Basic2DBatcher, BasicRenderPipeline, BlendFactor, BlendMode, BlendOperation, BlendShape, BlendShapeFrame, BlendState, BlinnPhongMaterial, BoolUpdateFlag, BoxColliderShape, BoxShape, Buffer, BufferBindFlag, BufferMesh, BufferUsage, BufferUtil, Burst, Camera, CameraClearFlags, CameraType, Canvas, CapsuleColliderShape, CharacterController, CircleShape, CloneManager, Collider, ColliderShape, ColliderShapeUpAxis, CollisionDetectionMode, ColorOverLifetimeModule, ColorSpace, ColorWriteMask, CompareFunction, Component, ConeEmitType, ConeShape, ContentRestorer, ControllerCollisionFlag, ControllerNonWalkableMode, CubeProbe, CullMode, CurveKey, DataType, DependentMode, DepthState, DepthTextureMode, DiffuseMode, DirectLight, DynamicCollider, DynamicColliderConstraints, EmissionModule, Engine, EngineObject, Entity, EventDispatcher, FixedJoint, FogMode, Font, FontStyle, GLCapabilityType, GradientAlphaKey, GradientColorKey, HemisphereShape, HingeJoint, HitResult, IndexBufferBinding, IndexFormat, InputManager, InterpolationType, Joint, JointLimits, JointMotor, Keyframe, Keys, Layer, Light, Loader, Logger, MainModule, Material, Mesh, MeshRenderer, MeshTopology, ModelMesh, OverflowMode, PBRBaseMaterial, PBRMaterial, PBRSpecularMaterial, ParticleCompositeCurve, ParticleCompositeGradient, ParticleCurve, ParticleCurveMode, ParticleGenerator, ParticleGradient, ParticleGradientMode, ParticleMaterial, ParticleRenderMode, ParticleRenderer, ParticleScaleMode, ParticleShapeArcMode, ParticleSimulationSpace, ParticleStopMode, PhysicsMaterial, PhysicsMaterialCombineMode, PhysicsScene, PipelineStage, PlaneColliderShape, Platform, PointLight, Pointer, PointerButton, PointerPhase, Primitive, PrimitiveMesh, Probe, RasterState, ReferResource, RenderBufferDepthFormat, RenderFace, RenderPass, RenderQueue, RenderQueueType, RenderState, RenderStateElementKey as RenderStateDataKey, RenderTarget, RenderTargetBlendState, Renderer, ResourceManager, RotationOverLifetimeModule, Scene, SceneManager, Script, SetDataOptions, Shader, ShaderData, ShaderFactory, ShaderMacro, ShaderMacroCollection, ShaderPass, ShaderProperty, ShaderPropertyType, ShaderTagKey, ShadowCascadesMode, ShadowResolution, ShadowType, SizeOverLifetimeModule, Skin, SkinnedMeshRenderer, Sky, SkyBoxMaterial, SkyProceduralMaterial, SphereColliderShape, SphereShape, SpotLight, SpringJoint, Sprite, SpriteAtlas, SpriteDrawMode, SpriteMask, SpriteMaskInteraction, SpriteMaskLayer, SpriteRenderer, SpriteTileMode, StateMachineScript, StaticCollider, StencilOperation, StencilState, SubMesh, SubShader, SunMode, SystemInfo, TextHorizontalAlignment, TextRenderer, TextUtils, TextVerticalAlignment, Texture, Texture2D, Texture2DArray, TextureCoordinate, TextureCube, TextureCubeFace, TextureDepthCompareFunction, TextureFilterMode, TextureFormat, TextureSheetAnimationModule, TextureUsage, TextureWrapMode, Time, TrailMaterial, TrailRenderer, Transform, UnlitMaterial, Utils, VelocityOverLifetimeModule, VertexAttribute, VertexBufferBinding, VertexElement, VertexElementFormat, WrapMode, XRManager, assignmentClone, deepClone, dependentComponents, ignoreClone, request, resourceLoader, shallowClone };
31164
+ export { AmbientLight, AnimationArrayCurve, AnimationBoolCurve, AnimationClip, AnimationClipCurveBinding, AnimationColorCurve, AnimationCurve, AnimationEvent, AnimationFloatArrayCurve, AnimationFloatCurve, AnimationQuaternionCurve, AnimationRectCurve, AnimationRefCurve, AnimationStringCurve, AnimationVector2Curve, AnimationVector3Curve, AnimationVector4Curve, Animator, AnimatorConditionMode, AnimatorController, AnimatorControllerLayer, AnimatorCullingMode, AnimatorLayerBlendingMode, AnimatorLayerMask, AnimatorState, AnimatorStateMachine, AnimatorStateTransition, AssetPromise, AssetType, Background, BackgroundMode, BackgroundTextureFillMode, BaseMaterial, Basic2DBatcher, BasicRenderPipeline, BlendFactor, BlendMode, BlendOperation, BlendShape, BlendShapeFrame, BlendState, BlinnPhongMaterial, BoolUpdateFlag, BoxColliderShape, BoxShape, Buffer, BufferBindFlag, BufferMesh, BufferUsage, BufferUtil, Burst, Camera, CameraClearFlags, CameraType, Canvas, CapsuleColliderShape, CharacterController, CircleShape, CloneManager, Collider, ColliderShape, ColliderShapeUpAxis, CollisionDetectionMode, ColorOverLifetimeModule, ColorSpace, ColorWriteMask, CompareFunction, Component, ConeEmitType, ConeShape, ContentRestorer, ControllerCollisionFlag, ControllerNonWalkableMode, CubeProbe, CullMode, CurveKey, DataType, DependentMode, DepthState, DepthTextureMode, DiffuseMode, DirectLight, DynamicCollider, DynamicColliderConstraints, EmissionModule, Engine, EngineObject, Entity, EventDispatcher, FixedJoint, FogMode, Font, FontStyle, GLCapabilityType, GradientAlphaKey, GradientColorKey, HemisphereShape, HingeJoint, HitResult, IndexBufferBinding, IndexFormat, InputManager, InterpolationType, Joint, JointLimits, JointMotor, Keyframe, Keys, Layer, Light, Loader, Logger, MainModule, Material, Mesh, MeshRenderer, MeshTopology, ModelMesh, OverflowMode, PBRBaseMaterial, PBRMaterial, PBRSpecularMaterial, ParticleCompositeCurve, ParticleCompositeGradient, ParticleCurve, ParticleCurveMode, ParticleGenerator, ParticleGradient, ParticleGradientMode, ParticleMaterial, ParticleRenderMode, ParticleRenderer, ParticleScaleMode, ParticleShapeArcMode, ParticleShapeType, ParticleSimulationSpace, ParticleStopMode, PhysicsMaterial, PhysicsMaterialCombineMode, PhysicsScene, PipelineStage, PlaneColliderShape, Platform, PointLight, Pointer, PointerButton, PointerPhase, Primitive, PrimitiveMesh, Probe, RasterState, ReferResource, RenderBufferDepthFormat, RenderFace, RenderPass, RenderQueue, RenderQueueType, RenderState, RenderStateElementKey as RenderStateDataKey, RenderTarget, RenderTargetBlendState, Renderer, ResourceManager, RotationOverLifetimeModule, Scene, SceneManager, Script, SetDataOptions, Shader, ShaderData, ShaderFactory, ShaderMacro, ShaderMacroCollection, ShaderPass, ShaderProperty, ShaderPropertyType, ShaderTagKey, ShadowCascadesMode, ShadowResolution, ShadowType, SizeOverLifetimeModule, Skin, SkinnedMeshRenderer, Sky, SkyBoxMaterial, SkyProceduralMaterial, SphereColliderShape, SphereShape, SpotLight, SpringJoint, Sprite, SpriteAtlas, SpriteDrawMode, SpriteMask, SpriteMaskInteraction, SpriteMaskLayer, SpriteRenderer, SpriteTileMode, StateMachineScript, StaticCollider, StencilOperation, StencilState, SubMesh, SubShader, SunMode, SystemInfo, TextHorizontalAlignment, TextRenderer, TextUtils, TextVerticalAlignment, Texture, Texture2D, Texture2DArray, TextureCoordinate, TextureCube, TextureCubeFace, TextureDepthCompareFunction, TextureFilterMode, TextureFormat, TextureSheetAnimationModule, TextureUsage, TextureWrapMode, Time, TrailMaterial, TrailRenderer, Transform, UnlitMaterial, Utils, VelocityOverLifetimeModule, VertexAttribute, VertexBufferBinding, VertexElement, VertexElementFormat, WrapMode, XRManager, assignmentClone, deepClone, dependentComponents, ignoreClone, request, resourceLoader, shallowClone };
31128
31165
  //# sourceMappingURL=module.js.map