@galacean/engine-core 1.0.0-beta.15 → 1.0.0-beta.17

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.
@@ -3005,15 +3005,24 @@ exports.GLCapabilityType = void 0;
3005
3005
  }
3006
3006
  var _proto = DisorderedArray.prototype;
3007
3007
  _proto.add = function add(element) {
3008
- if (this.length === this._elements.length) this._elements.push(element);
3009
- else this._elements[this.length] = element;
3008
+ if (this.length === this._elements.length) {
3009
+ this._elements.push(element);
3010
+ } else {
3011
+ this._elements[this.length] = element;
3012
+ }
3010
3013
  this.length++;
3011
3014
  };
3012
3015
  _proto.delete = function _delete(element) {
3013
- //TODO: It can be optimized for custom binary search and other algorithms, currently this._elements>=this.length wastes performance.
3016
+ // @todo: It can be optimized for custom binary search and other algorithms, currently this._elements>=this.length wastes performance.
3014
3017
  var index = this._elements.indexOf(element);
3015
3018
  this.deleteByIndex(index);
3016
3019
  };
3020
+ _proto.set = function set(index, element) {
3021
+ if (index >= this.length) {
3022
+ throw "Index is out of range.";
3023
+ }
3024
+ this._elements[index] = element;
3025
+ };
3017
3026
  _proto.get = function get(index) {
3018
3027
  if (index >= this.length) {
3019
3028
  throw "Index is out of range.";
@@ -3021,9 +3030,9 @@ exports.GLCapabilityType = void 0;
3021
3030
  return this._elements[index];
3022
3031
  };
3023
3032
  /**
3024
- *
3025
- * @param index
3026
- * @returns The replaced item is used to reset its index.
3033
+ * Delete the element at the specified index.
3034
+ * @param index - The index of the element to be deleted
3035
+ * @returns The replaced item is used to reset its index
3027
3036
  */ _proto.deleteByIndex = function deleteByIndex(index) {
3028
3037
  var elements = this._elements;
3029
3038
  var end = null;
@@ -4759,6 +4768,7 @@ var ComponentCloner = /*#__PURE__*/ function() {
4759
4768
  cloneEntity._hookResource = hookResource;
4760
4769
  hookResource._addReferCount(1);
4761
4770
  }
4771
+ cloneEntity.layer = this.layer;
4762
4772
  cloneEntity._isActive = this._isActive;
4763
4773
  cloneEntity.transform.localMatrix = this.transform.localMatrix;
4764
4774
  var children = this._children;
@@ -8391,31 +8401,18 @@ __decorate([
8391
8401
  };
8392
8402
  /**
8393
8403
  * @internal
8394
- */ _proto._getSunLightIndex = function _getSunLightIndex() {
8404
+ */ _proto._updateSunLightIndex = function _updateSunLightIndex() {
8395
8405
  var directLights = this._directLights;
8396
- var sunLightIndex = -1;
8397
- var maxIntensity = Number.NEGATIVE_INFINITY;
8398
- var hasShadowLight = false;
8399
- for(var i = 0, n = directLights.length; i < n; i++){
8400
- var directLight = directLights.get(i);
8401
- if (directLight.shadowType !== exports.ShadowType.None && !hasShadowLight) {
8402
- maxIntensity = Number.NEGATIVE_INFINITY;
8403
- hasShadowLight = true;
8404
- }
8405
- var intensity = directLight.intensity * directLight.color.getBrightness();
8406
- if (hasShadowLight) {
8407
- if (directLight.shadowType !== exports.ShadowType.None && maxIntensity < intensity) {
8408
- maxIntensity = intensity;
8409
- sunLightIndex = i;
8410
- }
8411
- } else {
8412
- if (maxIntensity < intensity) {
8413
- maxIntensity = intensity;
8414
- sunLightIndex = i;
8415
- }
8416
- }
8406
+ var index = this._getSunLightIndex();
8407
+ // -1 means no sun light, 0 means the first direct light already is sun light
8408
+ if (index > 0) {
8409
+ var firstLight = directLights.get(0);
8410
+ var sunLight = directLights.get(index);
8411
+ directLights.set(0, sunLight);
8412
+ directLights.set(index, firstLight);
8413
+ sunLight._lightIndex = 0;
8414
+ firstLight._lightIndex = index;
8417
8415
  }
8418
- return sunLightIndex;
8419
8416
  };
8420
8417
  /**
8421
8418
  * @internal
@@ -8464,6 +8461,32 @@ __decorate([
8464
8461
  this._pointLights.garbageCollection();
8465
8462
  this._directLights.garbageCollection();
8466
8463
  };
8464
+ _proto._getSunLightIndex = function _getSunLightIndex() {
8465
+ var directLights = this._directLights;
8466
+ var sunLightIndex = -1;
8467
+ var maxIntensity = Number.NEGATIVE_INFINITY;
8468
+ var hasShadowLight = false;
8469
+ for(var i = 0, n = directLights.length; i < n; i++){
8470
+ var directLight = directLights.get(i);
8471
+ if (directLight.shadowType !== exports.ShadowType.None && !hasShadowLight) {
8472
+ maxIntensity = Number.NEGATIVE_INFINITY;
8473
+ hasShadowLight = true;
8474
+ }
8475
+ var intensity = directLight.intensity * directLight.color.getBrightness();
8476
+ if (hasShadowLight) {
8477
+ if (directLight.shadowType !== exports.ShadowType.None && maxIntensity < intensity) {
8478
+ maxIntensity = intensity;
8479
+ sunLightIndex = i;
8480
+ }
8481
+ } else {
8482
+ if (maxIntensity < intensity) {
8483
+ maxIntensity = intensity;
8484
+ sunLightIndex = i;
8485
+ }
8486
+ }
8487
+ }
8488
+ return sunLightIndex;
8489
+ };
8467
8490
  return LightManager;
8468
8491
  }();
8469
8492
 
@@ -9674,7 +9697,7 @@ var begin_mobile_frag = "#define GLSLIFY 1\nvec4 ambient=vec4(0.0);vec4 emission
9674
9697
 
9675
9698
  var begin_viewdir_frag = "#define GLSLIFY 1\n#ifdef MATERIAL_NEED_WORLD_POS\nvec3 V=normalize(camera_Position-v_pos);\n#endif\n"; // eslint-disable-line
9676
9699
 
9677
- var mobile_blinnphong_frag = "#define GLSLIFY 1\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nmat3 tbn=getTBN(gl_FrontFacing);vec3 N=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv,gl_FrontFacing);\n#else\nvec3 N=getNormal(gl_FrontFacing);\n#endif\nvec3 lightDiffuse=vec3(0.0,0.0,0.0);vec3 lightSpecular=vec3(0.0,0.0,0.0);float shadowAttenuation=1.0;\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nshadowAttenuation=1.0;\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nshadowAttenuation*=sampleShadowMap();int sunIndex=int(scene_ShadowInfo.z);\n#endif\nDirectLight directionalLight;for(int i=0;i<SCENE_DIRECT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_DirectLightCullingMask[i]))continue;directionalLight.color=scene_DirectLightColor[i];\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nif(i==sunIndex){directionalLight.color*=shadowAttenuation;}\n#endif\ndirectionalLight.direction=scene_DirectLightDirection[i];float d=max(dot(N,-directionalLight.direction),0.0);lightDiffuse+=directionalLight.color*d;vec3 halfDir=normalize(V-directionalLight.direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess);lightSpecular+=directionalLight.color*s;}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nPointLight pointLight;for(int i=0;i<SCENE_POINT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_PointLightCullingMask[i]))continue;pointLight.color=scene_PointLightColor[i];pointLight.position=scene_PointLightPosition[i];pointLight.distance=scene_PointLightDistance[i];vec3 direction=v_pos-pointLight.position;float dist=length(direction);direction/=dist;float decay=clamp(1.0-pow(dist/pointLight.distance,4.0),0.0,1.0);float d=max(dot(N,-direction),0.0)*decay;lightDiffuse+=pointLight.color*d;vec3 halfDir=normalize(V-direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decay;lightSpecular+=pointLight.color*s;}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nSpotLight spotLight;for(int i=0;i<SCENE_SPOT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_SpotLightCullingMask[i]))continue;spotLight.color=scene_SpotLightColor[i];spotLight.position=scene_SpotLightPosition[i];spotLight.direction=scene_SpotLightDirection[i];spotLight.distance=scene_SpotLightDistance[i];spotLight.angleCos=scene_SpotLightAngleCos[i];spotLight.penumbraCos=scene_SpotLightPenumbraCos[i];vec3 direction=spotLight.position-v_pos;float lightDistance=length(direction);direction/=lightDistance;float angleCos=dot(direction,-spotLight.direction);float decay=clamp(1.0-pow(lightDistance/spotLight.distance,4.0),0.0,1.0);float spotEffect=smoothstep(spotLight.penumbraCos,spotLight.angleCos,angleCos);float decayTotal=decay*spotEffect;float d=max(dot(N,direction),0.0)*decayTotal;lightDiffuse+=spotLight.color*d;vec3 halfDir=normalize(V+direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decayTotal;lightSpecular+=spotLight.color*s;}\n#endif\ndiffuse*=vec4(lightDiffuse,1.0);specular*=vec4(lightSpecular,1.0);\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(diffuse.a<material_AlphaCutoff){discard;}\n#endif\n"; // eslint-disable-line
9700
+ var mobile_blinnphong_frag = "#define GLSLIFY 1\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nmat3 tbn=getTBN(gl_FrontFacing);vec3 N=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv,gl_FrontFacing);\n#else\nvec3 N=getNormal(gl_FrontFacing);\n#endif\nvec3 lightDiffuse=vec3(0.0,0.0,0.0);vec3 lightSpecular=vec3(0.0,0.0,0.0);float shadowAttenuation=1.0;\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nshadowAttenuation=1.0;\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nshadowAttenuation*=sampleShadowMap();\n#endif\nDirectLight directionalLight;for(int i=0;i<SCENE_DIRECT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_DirectLightCullingMask[i]))continue;directionalLight.color=scene_DirectLightColor[i];\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nif(i==0){directionalLight.color*=shadowAttenuation;}\n#endif\ndirectionalLight.direction=scene_DirectLightDirection[i];float d=max(dot(N,-directionalLight.direction),0.0);lightDiffuse+=directionalLight.color*d;vec3 halfDir=normalize(V-directionalLight.direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess);lightSpecular+=directionalLight.color*s;}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nPointLight pointLight;for(int i=0;i<SCENE_POINT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_PointLightCullingMask[i]))continue;pointLight.color=scene_PointLightColor[i];pointLight.position=scene_PointLightPosition[i];pointLight.distance=scene_PointLightDistance[i];vec3 direction=v_pos-pointLight.position;float dist=length(direction);direction/=dist;float decay=clamp(1.0-pow(dist/pointLight.distance,4.0),0.0,1.0);float d=max(dot(N,-direction),0.0)*decay;lightDiffuse+=pointLight.color*d;vec3 halfDir=normalize(V-direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decay;lightSpecular+=pointLight.color*s;}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nSpotLight spotLight;for(int i=0;i<SCENE_SPOT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_SpotLightCullingMask[i]))continue;spotLight.color=scene_SpotLightColor[i];spotLight.position=scene_SpotLightPosition[i];spotLight.direction=scene_SpotLightDirection[i];spotLight.distance=scene_SpotLightDistance[i];spotLight.angleCos=scene_SpotLightAngleCos[i];spotLight.penumbraCos=scene_SpotLightPenumbraCos[i];vec3 direction=spotLight.position-v_pos;float lightDistance=length(direction);direction/=lightDistance;float angleCos=dot(direction,-spotLight.direction);float decay=clamp(1.0-pow(lightDistance/spotLight.distance,4.0),0.0,1.0);float spotEffect=smoothstep(spotLight.penumbraCos,spotLight.angleCos,angleCos);float decayTotal=decay*spotEffect;float d=max(dot(N,direction),0.0)*decayTotal;lightDiffuse+=spotLight.color*d;vec3 halfDir=normalize(V+direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decayTotal;lightSpecular+=spotLight.color*s;}\n#endif\ndiffuse*=vec4(lightDiffuse,1.0);specular*=vec4(lightSpecular,1.0);\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(diffuse.a<material_AlphaCutoff){discard;}\n#endif\n"; // eslint-disable-line
9678
9701
 
9679
9702
  var noise_cellular = "#define GLSLIFY 1\n#include <noise_cellular_2D>\n#include <noise_cellular_3D>\n#include <noise_cellular_2x2>\n#include <noise_cellular_2x2x2>\n"; // eslint-disable-line
9680
9703
 
@@ -9714,7 +9737,7 @@ var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\nfloat computeSpecula
9714
9737
 
9715
9738
  var brdf = "#define GLSLIFY 1\nfloat F_Schlick(float dotLH){return 0.04+0.96*(pow(1.0-dotLH,5.0));}vec3 F_Schlick(vec3 specularColor,float dotLH){float fresnel=exp2((-5.55473*dotLH-6.98316)*dotLH);return(1.0-specularColor)*fresnel+specularColor;}float G_GGX_SmithCorrelated(float alpha,float dotNL,float dotNV){float a2=pow2(alpha);float gv=dotNL*sqrt(a2+(1.0-a2)*pow2(dotNV));float gl=dotNV*sqrt(a2+(1.0-a2)*pow2(dotNL));return 0.5/max(gv+gl,EPSILON);}float D_GGX(float alpha,float dotNH){float a2=pow2(alpha);float denom=pow2(dotNH)*(a2-1.0)+1.0;return RECIPROCAL_PI*a2/pow2(denom);}vec3 BRDF_Specular_GGX(vec3 incidentDirection,vec3 viewDir,vec3 normal,vec3 specularColor,float roughness){float alpha=pow2(roughness);vec3 halfDir=normalize(incidentDirection+viewDir);float dotNL=saturate(dot(normal,incidentDirection));float dotNV=saturate(dot(normal,viewDir));float dotNH=saturate(dot(normal,halfDir));float dotLH=saturate(dot(incidentDirection,halfDir));vec3 F=F_Schlick(specularColor,dotLH);float G=G_GGX_SmithCorrelated(alpha,dotNL,dotNV);float D=D_GGX(alpha,dotNH);return F*(G*D);}vec3 BRDF_Diffuse_Lambert(vec3 diffuseColor){return RECIPROCAL_PI*diffuseColor;}"; // eslint-disable-line
9716
9739
 
9717
- var direct_irradiance_frag_define = "#define GLSLIFY 1\n#include <ShadowFragmentDeclaration>\nvoid addDirectRadiance(vec3 incidentDirection,vec3 color,Geometry geometry,Material material,inout ReflectedLight reflectedLight){float attenuation=1.0;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nfloat clearCoatDotNL=saturate(dot(geometry.clearCoatNormal,incidentDirection));vec3 clearCoatIrradiance=clearCoatDotNL*color;reflectedLight.directSpecular+=material.clearCoat*clearCoatIrradiance*BRDF_Specular_GGX(incidentDirection,geometry.viewDir,geometry.clearCoatNormal,vec3(0.04),material.clearCoatRoughness);attenuation-=material.clearCoat*F_Schlick(geometry.clearCoatDotNV);\n#endif\nfloat dotNL=saturate(dot(geometry.normal,incidentDirection));vec3 irradiance=dotNL*color*PI;reflectedLight.directSpecular+=attenuation*irradiance*BRDF_Specular_GGX(incidentDirection,geometry.viewDir,geometry.normal,material.specularColor,material.roughness);reflectedLight.directDiffuse+=attenuation*irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);}\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nvoid addDirectionalDirectLightRadiance(DirectLight directionalLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 color=directionalLight.color;vec3 direction=-directionalLight.direction;addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nvoid addPointDirectLightRadiance(PointLight pointLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 lVector=pointLight.position-geometry.position;vec3 direction=normalize(lVector);float lightDistance=length(lVector);vec3 color=pointLight.color;color*=clamp(1.0-pow(lightDistance/pointLight.distance,4.0),0.0,1.0);addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nvoid addSpotDirectLightRadiance(SpotLight spotLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 lVector=spotLight.position-geometry.position;vec3 direction=normalize(lVector);float lightDistance=length(lVector);float angleCos=dot(direction,-spotLight.direction);float spotEffect=smoothstep(spotLight.penumbraCos,spotLight.angleCos,angleCos);float decayEffect=clamp(1.0-pow(lightDistance/spotLight.distance,4.0),0.0,1.0);vec3 color=spotLight.color;color*=spotEffect*decayEffect;addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\nvoid addTotalDirectRadiance(Geometry geometry,Material material,inout ReflectedLight reflectedLight){float shadowAttenuation=1.0;\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nshadowAttenuation=1.0;\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nshadowAttenuation*=sampleShadowMap();int sunIndex=int(scene_ShadowInfo.z);\n#endif\nDirectLight directionalLight;for(int i=0;i<SCENE_DIRECT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_DirectLightCullingMask[i]))continue;directionalLight.color=scene_DirectLightColor[i];\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nif(i==sunIndex){directionalLight.color*=shadowAttenuation;}\n#endif\ndirectionalLight.direction=scene_DirectLightDirection[i];addDirectionalDirectLightRadiance(directionalLight,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nPointLight pointLight;for(int i=0;i<SCENE_POINT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_PointLightCullingMask[i]))continue;pointLight.color=scene_PointLightColor[i];pointLight.position=scene_PointLightPosition[i];pointLight.distance=scene_PointLightDistance[i];addPointDirectLightRadiance(pointLight,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nSpotLight spotLight;for(int i=0;i<SCENE_SPOT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_SpotLightCullingMask[i]))continue;spotLight.color=scene_SpotLightColor[i];spotLight.position=scene_SpotLightPosition[i];spotLight.direction=scene_SpotLightDirection[i];spotLight.distance=scene_SpotLightDistance[i];spotLight.angleCos=scene_SpotLightAngleCos[i];spotLight.penumbraCos=scene_SpotLightPenumbraCos[i];addSpotDirectLightRadiance(spotLight,geometry,material,reflectedLight);}\n#endif\n}"; // eslint-disable-line
9740
+ var direct_irradiance_frag_define = "#define GLSLIFY 1\n#include <ShadowFragmentDeclaration>\nvoid addDirectRadiance(vec3 incidentDirection,vec3 color,Geometry geometry,Material material,inout ReflectedLight reflectedLight){float attenuation=1.0;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nfloat clearCoatDotNL=saturate(dot(geometry.clearCoatNormal,incidentDirection));vec3 clearCoatIrradiance=clearCoatDotNL*color;reflectedLight.directSpecular+=material.clearCoat*clearCoatIrradiance*BRDF_Specular_GGX(incidentDirection,geometry.viewDir,geometry.clearCoatNormal,vec3(0.04),material.clearCoatRoughness);attenuation-=material.clearCoat*F_Schlick(geometry.clearCoatDotNV);\n#endif\nfloat dotNL=saturate(dot(geometry.normal,incidentDirection));vec3 irradiance=dotNL*color*PI;reflectedLight.directSpecular+=attenuation*irradiance*BRDF_Specular_GGX(incidentDirection,geometry.viewDir,geometry.normal,material.specularColor,material.roughness);reflectedLight.directDiffuse+=attenuation*irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);}\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nvoid addDirectionalDirectLightRadiance(DirectLight directionalLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 color=directionalLight.color;vec3 direction=-directionalLight.direction;addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nvoid addPointDirectLightRadiance(PointLight pointLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 lVector=pointLight.position-geometry.position;vec3 direction=normalize(lVector);float lightDistance=length(lVector);vec3 color=pointLight.color;color*=clamp(1.0-pow(lightDistance/pointLight.distance,4.0),0.0,1.0);addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nvoid addSpotDirectLightRadiance(SpotLight spotLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 lVector=spotLight.position-geometry.position;vec3 direction=normalize(lVector);float lightDistance=length(lVector);float angleCos=dot(direction,-spotLight.direction);float spotEffect=smoothstep(spotLight.penumbraCos,spotLight.angleCos,angleCos);float decayEffect=clamp(1.0-pow(lightDistance/spotLight.distance,4.0),0.0,1.0);vec3 color=spotLight.color;color*=spotEffect*decayEffect;addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\nvoid addTotalDirectRadiance(Geometry geometry,Material material,inout ReflectedLight reflectedLight){float shadowAttenuation=1.0;\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nshadowAttenuation=1.0;\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nshadowAttenuation*=sampleShadowMap();\n#endif\nDirectLight directionalLight;for(int i=0;i<SCENE_DIRECT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_DirectLightCullingMask[i]))continue;directionalLight.color=scene_DirectLightColor[i];\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nif(i==0){directionalLight.color*=shadowAttenuation;}\n#endif\ndirectionalLight.direction=scene_DirectLightDirection[i];addDirectionalDirectLightRadiance(directionalLight,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nPointLight pointLight;for(int i=0;i<SCENE_POINT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_PointLightCullingMask[i]))continue;pointLight.color=scene_PointLightColor[i];pointLight.position=scene_PointLightPosition[i];pointLight.distance=scene_PointLightDistance[i];addPointDirectLightRadiance(pointLight,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nSpotLight spotLight;for(int i=0;i<SCENE_SPOT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_SpotLightCullingMask[i]))continue;spotLight.color=scene_SpotLightColor[i];spotLight.position=scene_SpotLightPosition[i];spotLight.direction=scene_SpotLightDirection[i];spotLight.distance=scene_SpotLightDistance[i];spotLight.angleCos=scene_SpotLightAngleCos[i];spotLight.penumbraCos=scene_SpotLightPenumbraCos[i];addSpotDirectLightRadiance(spotLight,geometry,material,reflectedLight);}\n#endif\n}"; // eslint-disable-line
9718
9741
 
9719
9742
  var ibl_frag_define = "#define GLSLIFY 1\nvec3 getLightProbeIrradiance(vec3 sh[9],vec3 normal){normal.x=-normal.x;vec3 result=sh[0]+sh[1]*(normal.y)+sh[2]*(normal.z)+sh[3]*(normal.x)+sh[4]*(normal.y*normal.x)+sh[5]*(normal.y*normal.z)+sh[6]*(3.0*normal.z*normal.z-1.0)+sh[7]*(normal.z*normal.x)+sh[8]*(normal.x*normal.x-normal.y*normal.y);return max(result,vec3(0.0));}vec3 envBRDFApprox(vec3 specularColor,float roughness,float dotNV){const vec4 c0=vec4(-1,-0.0275,-0.572,0.022);const vec4 c1=vec4(1,0.0425,1.04,-0.04);vec4 r=roughness*c0+c1;float a004=min(r.x*r.x,exp2(-9.28*dotNV))*r.x+r.y;vec2 AB=vec2(-1.04,1.04)*a004+r.zw;return specularColor*AB.x+AB.y;}float getSpecularMIPLevel(float roughness,int maxMIPLevel){return roughness*float(maxMIPLevel);}vec3 getLightProbeRadiance(vec3 viewDir,vec3 normal,float roughness,int maxMIPLevel,float specularIntensity){\n#ifndef SCENE_USE_SPECULAR_ENV\nreturn vec3(0);\n#else\nvec3 reflectVec=reflect(-viewDir,normal);reflectVec.x=-reflectVec.x;float specularMIPLevel=getSpecularMIPLevel(roughness,maxMIPLevel);\n#ifdef HAS_TEX_LOD\nvec4 envMapColor=textureCubeLodEXT(scene_EnvSpecularSampler,reflectVec,specularMIPLevel);\n#else\nvec4 envMapColor=textureCube(scene_EnvSpecularSampler,reflectVec,specularMIPLevel);\n#endif\n#ifdef SCENE_IS_DECODE_ENV_RGBM\nenvMapColor.rgb=RGBMToLinear(envMapColor,5.0).rgb;\n#ifdef ENGINE_IS_COLORSPACE_GAMMA\nenvMapColor=linearToGamma(envMapColor);\n#endif\n#else\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nenvMapColor=gammaToLinear(envMapColor);\n#endif\n#endif\nreturn envMapColor.rgb*specularIntensity;\n#endif\n}"; // eslint-disable-line
9720
9743
 
@@ -16001,20 +16024,25 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16001
16024
 
16002
16025
  /**
16003
16026
  * Ambient light.
16004
- */ var AmbientLight = /*#__PURE__*/ function() {
16005
- function AmbientLight() {
16006
- this._diffuseSolidColor = new miniprogram.Color(0.212, 0.227, 0.259);
16007
- this._diffuseIntensity = 1.0;
16008
- this._specularIntensity = 1.0;
16009
- this._diffuseMode = exports.DiffuseMode.SolidColor;
16010
- this._shArray = new Float32Array(27);
16011
- this._scenes = [];
16012
- this._specularTextureDecodeRGBM = false;
16027
+ */ var AmbientLight = /*#__PURE__*/ function(ReferResource) {
16028
+ _inherits(AmbientLight, ReferResource);
16029
+ function AmbientLight(engine) {
16030
+ var _this;
16031
+ _this = ReferResource.call(this, engine) || this;
16032
+ _this._diffuseSolidColor = new miniprogram.Color(0.212, 0.227, 0.259);
16033
+ _this._diffuseIntensity = 1.0;
16034
+ _this._specularIntensity = 1.0;
16035
+ _this._diffuseMode = exports.DiffuseMode.SolidColor;
16036
+ _this._shArray = new Float32Array(27);
16037
+ _this._scenes = [];
16038
+ _this._specularTextureDecodeRGBM = false;
16039
+ return _this;
16013
16040
  }
16014
16041
  var _proto = AmbientLight.prototype;
16015
16042
  /**
16016
16043
  * @internal
16017
16044
  */ _proto._addToScene = function _addToScene(scene) {
16045
+ this._addReferCount(1);
16018
16046
  this._scenes.push(scene);
16019
16047
  var shaderData = scene.shaderData;
16020
16048
  shaderData.setColor(AmbientLight._diffuseColorProperty, this._diffuseSolidColor);
@@ -16028,9 +16056,13 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16028
16056
  /**
16029
16057
  * @internal
16030
16058
  */ _proto._removeFromScene = function _removeFromScene(scene) {
16059
+ this._addReferCount(-1);
16031
16060
  var scenes = this._scenes;
16032
16061
  var index = scenes.indexOf(scene);
16033
16062
  scenes.splice(index, 1);
16063
+ var shaderData = scene.shaderData;
16064
+ shaderData.setTexture(AmbientLight._specularTextureProperty, null);
16065
+ shaderData.disableMacro(AmbientLight._specularMacro);
16034
16066
  };
16035
16067
  _proto._setDiffuseMode = function _setDiffuseMode(sceneShaderData) {
16036
16068
  if (this._diffuseMode === exports.DiffuseMode.SphericalHarmonics) {
@@ -16218,7 +16250,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16218
16250
  }
16219
16251
  ]);
16220
16252
  return AmbientLight;
16221
- }();
16253
+ }(ReferResource);
16222
16254
  (function() {
16223
16255
  AmbientLight._shMacro = ShaderMacro.getByName("SCENE_USE_SH");
16224
16256
  })();
@@ -16275,7 +16307,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16275
16307
  _this.name = name || "";
16276
16308
  var shaderData = _this.shaderData;
16277
16309
  shaderData._addReferCount(1);
16278
- _this.ambientLight = new AmbientLight();
16310
+ _this.ambientLight = new AmbientLight(engine);
16279
16311
  engine.sceneManager._allScenes.push(_assert_this_initialized(_this));
16280
16312
  shaderData.enableMacro("SCENE_FOG_MODE", _this._fogMode.toString());
16281
16313
  shaderData.enableMacro("SCENE_SHADOW_CASCADED_COUNT", _this.shadowCascades.toString());
@@ -16383,6 +16415,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16383
16415
  if (this._destroyed) {
16384
16416
  return;
16385
16417
  }
16418
+ EngineObject.prototype.destroy.call(this);
16386
16419
  this._destroy();
16387
16420
  var allScenes = this.engine.sceneManager._allScenes;
16388
16421
  allScenes.splice(allScenes.indexOf(this), 1);
@@ -16425,9 +16458,9 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16425
16458
  var lightManager = engine._lightManager;
16426
16459
  engine.time._updateSceneShaderData(shaderData);
16427
16460
  lightManager._updateShaderData(this.shaderData);
16428
- var sunLightIndex = lightManager._getSunLightIndex();
16429
- if (sunLightIndex !== -1) {
16430
- var sunlight = lightManager._directLights.get(sunLightIndex);
16461
+ lightManager._updateSunLightIndex();
16462
+ if (lightManager._directLights.length > 0) {
16463
+ var sunlight = lightManager._directLights.get(0);
16431
16464
  shaderData.setColor(Scene._sunlightColorProperty, sunlight._getLightIntensityColor());
16432
16465
  shaderData.setVector3(Scene._sunlightDirectionProperty, sunlight.direction);
16433
16466
  this._sunLight = sunlight;
@@ -16462,6 +16495,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16462
16495
  }
16463
16496
  this._activeCameras.length = 0;
16464
16497
  this.background.destroy();
16498
+ this._ambientLight && this._ambientLight._removeFromScene(this);
16465
16499
  this.shaderData._addReferCount(-1);
16466
16500
  };
16467
16501
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -16689,10 +16723,9 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16689
16723
  * @internal
16690
16724
  */ _proto._destroyAllScene = function _destroyAllScene() {
16691
16725
  var allScenes = this._allScenes;
16692
- for(var i = 0, n = allScenes.length; i < n; i++){
16693
- allScenes[i]._destroy();
16726
+ while(allScenes[0]){
16727
+ allScenes[0].destroy();
16694
16728
  }
16695
- allScenes.length = 0;
16696
16729
  };
16697
16730
  _create_class(SceneManager, [
16698
16731
  {
@@ -18465,9 +18498,8 @@ var /**
18465
18498
  var lightUp = this._lightUp;
18466
18499
  var lightSide = this._lightSide;
18467
18500
  var lightForward = shadowSliceData.virtualCamera.forward;
18468
- var sunLightIndex = engine._lightManager._getSunLightIndex();
18469
- if (sunLightIndex !== -1) {
18470
- var light = camera.scene._sunLight;
18501
+ var light = camera.scene._sunLight;
18502
+ if (light) {
18471
18503
  var shadowFar = Math.min(camera.scene.shadowDistance, camera.farClipPlane);
18472
18504
  this._getCascadesSplitDistance(shadowFar);
18473
18505
  // prepare render target
@@ -18480,7 +18512,7 @@ var /**
18480
18512
  rhi.clearRenderTarget(engine, exports.CameraClearFlags.All, CascadedShadowCasterPass._clearColor);
18481
18513
  }
18482
18514
  this._shadowInfos.x = light.shadowStrength;
18483
- this._shadowInfos.z = sunLightIndex;
18515
+ this._shadowInfos.z = 0; // @todo: sun light index always 0
18484
18516
  // prepare light and camera direction
18485
18517
  miniprogram.Matrix.rotationQuaternion(light.entity.transform.worldRotationQuaternion, lightWorld);
18486
18518
  lightSide.set(lightWorldE[0], lightWorldE[1], lightWorldE[2]);
@@ -20815,6 +20847,15 @@ exports.TextVerticalAlignment = void 0;
20815
20847
  _this._dirtyUpdateFlag = 0x7;
20816
20848
  /** @internal */ _this._updateFlagManager = new UpdateFlagManager();
20817
20849
  _this._texture = texture;
20850
+ _this._onRegionChange = _this._onRegionChange.bind(_assert_this_initialized(_this));
20851
+ _this._onPivotChange = _this._onPivotChange.bind(_assert_this_initialized(_this));
20852
+ _this._onBorderChange = _this._onBorderChange.bind(_assert_this_initialized(_this));
20853
+ // @ts-ignore
20854
+ _this._region._onValueChanged = _this._onRegionChange;
20855
+ // @ts-ignore
20856
+ _this._pivot._onValueChanged = _this._onPivotChange;
20857
+ // @ts-ignore
20858
+ _this._border._onValueChanged = _this._onBorderChange;
20818
20859
  region && _this._region.copyFrom(region);
20819
20860
  pivot && _this._pivot.copyFrom(pivot);
20820
20861
  border && _this._border.copyFrom(border);
@@ -20954,6 +20995,34 @@ exports.TextVerticalAlignment = void 0;
20954
20995
  }
20955
20996
  this._updateFlagManager.dispatch(type);
20956
20997
  };
20998
+ _proto._onRegionChange = function _onRegionChange() {
20999
+ var _this = this, region = _this._region;
21000
+ // @ts-ignore
21001
+ region._onValueChanged = null;
21002
+ var x = miniprogram.MathUtil.clamp(region.x, 0, 1);
21003
+ var y = miniprogram.MathUtil.clamp(region.y, 0, 1);
21004
+ region.set(x, y, miniprogram.MathUtil.clamp(region.width, 0, 1 - x), miniprogram.MathUtil.clamp(region.height, 0, 1 - y));
21005
+ this._dispatchSpriteChange(SpriteModifyFlags.region);
21006
+ if (this._customWidth === undefined || this._customHeight === undefined) {
21007
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
21008
+ }
21009
+ // @ts-ignore
21010
+ region._onValueChanged = this._onRegionChange;
21011
+ };
21012
+ _proto._onPivotChange = function _onPivotChange() {
21013
+ this._dispatchSpriteChange(SpriteModifyFlags.pivot);
21014
+ };
21015
+ _proto._onBorderChange = function _onBorderChange() {
21016
+ var _this = this, border = _this._border;
21017
+ // @ts-ignore
21018
+ border._onValueChanged = null;
21019
+ var x = miniprogram.MathUtil.clamp(border.x, 0, 1);
21020
+ var y = miniprogram.MathUtil.clamp(border.y, 0, 1);
21021
+ border.set(x, y, miniprogram.MathUtil.clamp(border.z, 0, 1 - x), miniprogram.MathUtil.clamp(border.w, 0, 1 - y));
21022
+ this._dispatchSpriteChange(SpriteModifyFlags.border);
21023
+ // @ts-ignore
21024
+ border._onValueChanged = this._onBorderChange;
21025
+ };
20957
21026
  _create_class(Sprite, [
20958
21027
  {
20959
21028
  key: "texture",
@@ -21073,14 +21142,7 @@ exports.TextVerticalAlignment = void 0;
21073
21142
  return this._region;
21074
21143
  },
21075
21144
  set: function set(value) {
21076
- var region = this._region;
21077
- var x = miniprogram.MathUtil.clamp(value.x, 0, 1);
21078
- var y = miniprogram.MathUtil.clamp(value.y, 0, 1);
21079
- region.set(x, y, miniprogram.MathUtil.clamp(value.width, 0, 1 - x), miniprogram.MathUtil.clamp(value.height, 0, 1 - y));
21080
- this._dispatchSpriteChange(SpriteModifyFlags.region);
21081
- if (this._customWidth === undefined || this._customHeight === undefined) {
21082
- this._dispatchSpriteChange(SpriteModifyFlags.size);
21083
- }
21145
+ this._region !== value && this._region.copyFrom(value);
21084
21146
  }
21085
21147
  },
21086
21148
  {
@@ -21092,16 +21154,7 @@ exports.TextVerticalAlignment = void 0;
21092
21154
  return this._pivot;
21093
21155
  },
21094
21156
  set: function set(value) {
21095
- var pivot = this._pivot;
21096
- if (pivot === value) {
21097
- this._dispatchSpriteChange(SpriteModifyFlags.pivot);
21098
- } else {
21099
- var x = value.x, y = value.y;
21100
- if (pivot.x !== x || pivot.y !== y) {
21101
- pivot.set(x, y);
21102
- this._dispatchSpriteChange(SpriteModifyFlags.pivot);
21103
- }
21104
- }
21157
+ this._pivot !== value && this._pivot.copyFrom(value);
21105
21158
  }
21106
21159
  },
21107
21160
  {
@@ -21116,11 +21169,7 @@ exports.TextVerticalAlignment = void 0;
21116
21169
  return this._border;
21117
21170
  },
21118
21171
  set: function set(value) {
21119
- var border = this._border;
21120
- var x = miniprogram.MathUtil.clamp(value.x, 0, 1);
21121
- var y = miniprogram.MathUtil.clamp(value.y, 0, 1);
21122
- border.set(x, y, miniprogram.MathUtil.clamp(value.z, 0, 1 - x), miniprogram.MathUtil.clamp(value.w, 0, 1 - y));
21123
- this._dispatchSpriteChange(SpriteModifyFlags.border);
21172
+ this._border !== value && this._border.copyFrom(value);
21124
21173
  }
21125
21174
  }
21126
21175
  ]);