@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.
package/dist/main.js CHANGED
@@ -3004,15 +3004,24 @@ exports.GLCapabilityType = void 0;
3004
3004
  }
3005
3005
  var _proto = DisorderedArray.prototype;
3006
3006
  _proto.add = function add(element) {
3007
- if (this.length === this._elements.length) this._elements.push(element);
3008
- else this._elements[this.length] = element;
3007
+ if (this.length === this._elements.length) {
3008
+ this._elements.push(element);
3009
+ } else {
3010
+ this._elements[this.length] = element;
3011
+ }
3009
3012
  this.length++;
3010
3013
  };
3011
3014
  _proto.delete = function _delete(element) {
3012
- //TODO: It can be optimized for custom binary search and other algorithms, currently this._elements>=this.length wastes performance.
3015
+ // @todo: It can be optimized for custom binary search and other algorithms, currently this._elements>=this.length wastes performance.
3013
3016
  var index = this._elements.indexOf(element);
3014
3017
  this.deleteByIndex(index);
3015
3018
  };
3019
+ _proto.set = function set(index, element) {
3020
+ if (index >= this.length) {
3021
+ throw "Index is out of range.";
3022
+ }
3023
+ this._elements[index] = element;
3024
+ };
3016
3025
  _proto.get = function get(index) {
3017
3026
  if (index >= this.length) {
3018
3027
  throw "Index is out of range.";
@@ -3020,9 +3029,9 @@ exports.GLCapabilityType = void 0;
3020
3029
  return this._elements[index];
3021
3030
  };
3022
3031
  /**
3023
- *
3024
- * @param index
3025
- * @returns The replaced item is used to reset its index.
3032
+ * Delete the element at the specified index.
3033
+ * @param index - The index of the element to be deleted
3034
+ * @returns The replaced item is used to reset its index
3026
3035
  */ _proto.deleteByIndex = function deleteByIndex(index) {
3027
3036
  var elements = this._elements;
3028
3037
  var end = null;
@@ -4758,6 +4767,7 @@ var ComponentCloner = /*#__PURE__*/ function() {
4758
4767
  cloneEntity._hookResource = hookResource;
4759
4768
  hookResource._addReferCount(1);
4760
4769
  }
4770
+ cloneEntity.layer = this.layer;
4761
4771
  cloneEntity._isActive = this._isActive;
4762
4772
  cloneEntity.transform.localMatrix = this.transform.localMatrix;
4763
4773
  var children = this._children;
@@ -8390,31 +8400,18 @@ __decorate([
8390
8400
  };
8391
8401
  /**
8392
8402
  * @internal
8393
- */ _proto._getSunLightIndex = function _getSunLightIndex() {
8403
+ */ _proto._updateSunLightIndex = function _updateSunLightIndex() {
8394
8404
  var directLights = this._directLights;
8395
- var sunLightIndex = -1;
8396
- var maxIntensity = Number.NEGATIVE_INFINITY;
8397
- var hasShadowLight = false;
8398
- for(var i = 0, n = directLights.length; i < n; i++){
8399
- var directLight = directLights.get(i);
8400
- if (directLight.shadowType !== exports.ShadowType.None && !hasShadowLight) {
8401
- maxIntensity = Number.NEGATIVE_INFINITY;
8402
- hasShadowLight = true;
8403
- }
8404
- var intensity = directLight.intensity * directLight.color.getBrightness();
8405
- if (hasShadowLight) {
8406
- if (directLight.shadowType !== exports.ShadowType.None && maxIntensity < intensity) {
8407
- maxIntensity = intensity;
8408
- sunLightIndex = i;
8409
- }
8410
- } else {
8411
- if (maxIntensity < intensity) {
8412
- maxIntensity = intensity;
8413
- sunLightIndex = i;
8414
- }
8415
- }
8405
+ var index = this._getSunLightIndex();
8406
+ // -1 means no sun light, 0 means the first direct light already is sun light
8407
+ if (index > 0) {
8408
+ var firstLight = directLights.get(0);
8409
+ var sunLight = directLights.get(index);
8410
+ directLights.set(0, sunLight);
8411
+ directLights.set(index, firstLight);
8412
+ sunLight._lightIndex = 0;
8413
+ firstLight._lightIndex = index;
8416
8414
  }
8417
- return sunLightIndex;
8418
8415
  };
8419
8416
  /**
8420
8417
  * @internal
@@ -8463,6 +8460,32 @@ __decorate([
8463
8460
  this._pointLights.garbageCollection();
8464
8461
  this._directLights.garbageCollection();
8465
8462
  };
8463
+ _proto._getSunLightIndex = function _getSunLightIndex() {
8464
+ var directLights = this._directLights;
8465
+ var sunLightIndex = -1;
8466
+ var maxIntensity = Number.NEGATIVE_INFINITY;
8467
+ var hasShadowLight = false;
8468
+ for(var i = 0, n = directLights.length; i < n; i++){
8469
+ var directLight = directLights.get(i);
8470
+ if (directLight.shadowType !== exports.ShadowType.None && !hasShadowLight) {
8471
+ maxIntensity = Number.NEGATIVE_INFINITY;
8472
+ hasShadowLight = true;
8473
+ }
8474
+ var intensity = directLight.intensity * directLight.color.getBrightness();
8475
+ if (hasShadowLight) {
8476
+ if (directLight.shadowType !== exports.ShadowType.None && maxIntensity < intensity) {
8477
+ maxIntensity = intensity;
8478
+ sunLightIndex = i;
8479
+ }
8480
+ } else {
8481
+ if (maxIntensity < intensity) {
8482
+ maxIntensity = intensity;
8483
+ sunLightIndex = i;
8484
+ }
8485
+ }
8486
+ }
8487
+ return sunLightIndex;
8488
+ };
8466
8489
  return LightManager;
8467
8490
  }();
8468
8491
 
@@ -9673,7 +9696,7 @@ var begin_mobile_frag = "#define GLSLIFY 1\nvec4 ambient=vec4(0.0);vec4 emission
9673
9696
 
9674
9697
  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
9675
9698
 
9676
- 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
9699
+ 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
9677
9700
 
9678
9701
  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
9679
9702
 
@@ -9713,7 +9736,7 @@ var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\nfloat computeSpecula
9713
9736
 
9714
9737
  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
9715
9738
 
9716
- 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
9739
+ 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
9717
9740
 
9718
9741
  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
9719
9742
 
@@ -16000,20 +16023,25 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16000
16023
 
16001
16024
  /**
16002
16025
  * Ambient light.
16003
- */ var AmbientLight = /*#__PURE__*/ function() {
16004
- function AmbientLight() {
16005
- this._diffuseSolidColor = new engineMath.Color(0.212, 0.227, 0.259);
16006
- this._diffuseIntensity = 1.0;
16007
- this._specularIntensity = 1.0;
16008
- this._diffuseMode = exports.DiffuseMode.SolidColor;
16009
- this._shArray = new Float32Array(27);
16010
- this._scenes = [];
16011
- this._specularTextureDecodeRGBM = false;
16026
+ */ var AmbientLight = /*#__PURE__*/ function(ReferResource) {
16027
+ _inherits(AmbientLight, ReferResource);
16028
+ function AmbientLight(engine) {
16029
+ var _this;
16030
+ _this = ReferResource.call(this, engine) || this;
16031
+ _this._diffuseSolidColor = new engineMath.Color(0.212, 0.227, 0.259);
16032
+ _this._diffuseIntensity = 1.0;
16033
+ _this._specularIntensity = 1.0;
16034
+ _this._diffuseMode = exports.DiffuseMode.SolidColor;
16035
+ _this._shArray = new Float32Array(27);
16036
+ _this._scenes = [];
16037
+ _this._specularTextureDecodeRGBM = false;
16038
+ return _this;
16012
16039
  }
16013
16040
  var _proto = AmbientLight.prototype;
16014
16041
  /**
16015
16042
  * @internal
16016
16043
  */ _proto._addToScene = function _addToScene(scene) {
16044
+ this._addReferCount(1);
16017
16045
  this._scenes.push(scene);
16018
16046
  var shaderData = scene.shaderData;
16019
16047
  shaderData.setColor(AmbientLight._diffuseColorProperty, this._diffuseSolidColor);
@@ -16027,9 +16055,13 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16027
16055
  /**
16028
16056
  * @internal
16029
16057
  */ _proto._removeFromScene = function _removeFromScene(scene) {
16058
+ this._addReferCount(-1);
16030
16059
  var scenes = this._scenes;
16031
16060
  var index = scenes.indexOf(scene);
16032
16061
  scenes.splice(index, 1);
16062
+ var shaderData = scene.shaderData;
16063
+ shaderData.setTexture(AmbientLight._specularTextureProperty, null);
16064
+ shaderData.disableMacro(AmbientLight._specularMacro);
16033
16065
  };
16034
16066
  _proto._setDiffuseMode = function _setDiffuseMode(sceneShaderData) {
16035
16067
  if (this._diffuseMode === exports.DiffuseMode.SphericalHarmonics) {
@@ -16217,7 +16249,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16217
16249
  }
16218
16250
  ]);
16219
16251
  return AmbientLight;
16220
- }();
16252
+ }(ReferResource);
16221
16253
  (function() {
16222
16254
  AmbientLight._shMacro = ShaderMacro.getByName("SCENE_USE_SH");
16223
16255
  })();
@@ -16274,7 +16306,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16274
16306
  _this.name = name || "";
16275
16307
  var shaderData = _this.shaderData;
16276
16308
  shaderData._addReferCount(1);
16277
- _this.ambientLight = new AmbientLight();
16309
+ _this.ambientLight = new AmbientLight(engine);
16278
16310
  engine.sceneManager._allScenes.push(_assert_this_initialized(_this));
16279
16311
  shaderData.enableMacro("SCENE_FOG_MODE", _this._fogMode.toString());
16280
16312
  shaderData.enableMacro("SCENE_SHADOW_CASCADED_COUNT", _this.shadowCascades.toString());
@@ -16382,6 +16414,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16382
16414
  if (this._destroyed) {
16383
16415
  return;
16384
16416
  }
16417
+ EngineObject.prototype.destroy.call(this);
16385
16418
  this._destroy();
16386
16419
  var allScenes = this.engine.sceneManager._allScenes;
16387
16420
  allScenes.splice(allScenes.indexOf(this), 1);
@@ -16424,9 +16457,9 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16424
16457
  var lightManager = engine._lightManager;
16425
16458
  engine.time._updateSceneShaderData(shaderData);
16426
16459
  lightManager._updateShaderData(this.shaderData);
16427
- var sunLightIndex = lightManager._getSunLightIndex();
16428
- if (sunLightIndex !== -1) {
16429
- var sunlight = lightManager._directLights.get(sunLightIndex);
16460
+ lightManager._updateSunLightIndex();
16461
+ if (lightManager._directLights.length > 0) {
16462
+ var sunlight = lightManager._directLights.get(0);
16430
16463
  shaderData.setColor(Scene._sunlightColorProperty, sunlight._getLightIntensityColor());
16431
16464
  shaderData.setVector3(Scene._sunlightDirectionProperty, sunlight.direction);
16432
16465
  this._sunLight = sunlight;
@@ -16461,6 +16494,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16461
16494
  }
16462
16495
  this._activeCameras.length = 0;
16463
16496
  this.background.destroy();
16497
+ this._ambientLight && this._ambientLight._removeFromScene(this);
16464
16498
  this.shaderData._addReferCount(-1);
16465
16499
  };
16466
16500
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -16688,10 +16722,9 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16688
16722
  * @internal
16689
16723
  */ _proto._destroyAllScene = function _destroyAllScene() {
16690
16724
  var allScenes = this._allScenes;
16691
- for(var i = 0, n = allScenes.length; i < n; i++){
16692
- allScenes[i]._destroy();
16725
+ while(allScenes[0]){
16726
+ allScenes[0].destroy();
16693
16727
  }
16694
- allScenes.length = 0;
16695
16728
  };
16696
16729
  _create_class(SceneManager, [
16697
16730
  {
@@ -18464,9 +18497,8 @@ var /**
18464
18497
  var lightUp = this._lightUp;
18465
18498
  var lightSide = this._lightSide;
18466
18499
  var lightForward = shadowSliceData.virtualCamera.forward;
18467
- var sunLightIndex = engine._lightManager._getSunLightIndex();
18468
- if (sunLightIndex !== -1) {
18469
- var light = camera.scene._sunLight;
18500
+ var light = camera.scene._sunLight;
18501
+ if (light) {
18470
18502
  var shadowFar = Math.min(camera.scene.shadowDistance, camera.farClipPlane);
18471
18503
  this._getCascadesSplitDistance(shadowFar);
18472
18504
  // prepare render target
@@ -18479,7 +18511,7 @@ var /**
18479
18511
  rhi.clearRenderTarget(engine, exports.CameraClearFlags.All, CascadedShadowCasterPass._clearColor);
18480
18512
  }
18481
18513
  this._shadowInfos.x = light.shadowStrength;
18482
- this._shadowInfos.z = sunLightIndex;
18514
+ this._shadowInfos.z = 0; // @todo: sun light index always 0
18483
18515
  // prepare light and camera direction
18484
18516
  engineMath.Matrix.rotationQuaternion(light.entity.transform.worldRotationQuaternion, lightWorld);
18485
18517
  lightSide.set(lightWorldE[0], lightWorldE[1], lightWorldE[2]);
@@ -20814,6 +20846,15 @@ exports.TextVerticalAlignment = void 0;
20814
20846
  _this._dirtyUpdateFlag = 0x7;
20815
20847
  /** @internal */ _this._updateFlagManager = new UpdateFlagManager();
20816
20848
  _this._texture = texture;
20849
+ _this._onRegionChange = _this._onRegionChange.bind(_assert_this_initialized(_this));
20850
+ _this._onPivotChange = _this._onPivotChange.bind(_assert_this_initialized(_this));
20851
+ _this._onBorderChange = _this._onBorderChange.bind(_assert_this_initialized(_this));
20852
+ // @ts-ignore
20853
+ _this._region._onValueChanged = _this._onRegionChange;
20854
+ // @ts-ignore
20855
+ _this._pivot._onValueChanged = _this._onPivotChange;
20856
+ // @ts-ignore
20857
+ _this._border._onValueChanged = _this._onBorderChange;
20817
20858
  region && _this._region.copyFrom(region);
20818
20859
  pivot && _this._pivot.copyFrom(pivot);
20819
20860
  border && _this._border.copyFrom(border);
@@ -20953,6 +20994,34 @@ exports.TextVerticalAlignment = void 0;
20953
20994
  }
20954
20995
  this._updateFlagManager.dispatch(type);
20955
20996
  };
20997
+ _proto._onRegionChange = function _onRegionChange() {
20998
+ var _this = this, region = _this._region;
20999
+ // @ts-ignore
21000
+ region._onValueChanged = null;
21001
+ var x = engineMath.MathUtil.clamp(region.x, 0, 1);
21002
+ var y = engineMath.MathUtil.clamp(region.y, 0, 1);
21003
+ region.set(x, y, engineMath.MathUtil.clamp(region.width, 0, 1 - x), engineMath.MathUtil.clamp(region.height, 0, 1 - y));
21004
+ this._dispatchSpriteChange(SpriteModifyFlags.region);
21005
+ if (this._customWidth === undefined || this._customHeight === undefined) {
21006
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
21007
+ }
21008
+ // @ts-ignore
21009
+ region._onValueChanged = this._onRegionChange;
21010
+ };
21011
+ _proto._onPivotChange = function _onPivotChange() {
21012
+ this._dispatchSpriteChange(SpriteModifyFlags.pivot);
21013
+ };
21014
+ _proto._onBorderChange = function _onBorderChange() {
21015
+ var _this = this, border = _this._border;
21016
+ // @ts-ignore
21017
+ border._onValueChanged = null;
21018
+ var x = engineMath.MathUtil.clamp(border.x, 0, 1);
21019
+ var y = engineMath.MathUtil.clamp(border.y, 0, 1);
21020
+ border.set(x, y, engineMath.MathUtil.clamp(border.z, 0, 1 - x), engineMath.MathUtil.clamp(border.w, 0, 1 - y));
21021
+ this._dispatchSpriteChange(SpriteModifyFlags.border);
21022
+ // @ts-ignore
21023
+ border._onValueChanged = this._onBorderChange;
21024
+ };
20956
21025
  _create_class(Sprite, [
20957
21026
  {
20958
21027
  key: "texture",
@@ -21072,14 +21141,7 @@ exports.TextVerticalAlignment = void 0;
21072
21141
  return this._region;
21073
21142
  },
21074
21143
  set: function set(value) {
21075
- var region = this._region;
21076
- var x = engineMath.MathUtil.clamp(value.x, 0, 1);
21077
- var y = engineMath.MathUtil.clamp(value.y, 0, 1);
21078
- region.set(x, y, engineMath.MathUtil.clamp(value.width, 0, 1 - x), engineMath.MathUtil.clamp(value.height, 0, 1 - y));
21079
- this._dispatchSpriteChange(SpriteModifyFlags.region);
21080
- if (this._customWidth === undefined || this._customHeight === undefined) {
21081
- this._dispatchSpriteChange(SpriteModifyFlags.size);
21082
- }
21144
+ this._region !== value && this._region.copyFrom(value);
21083
21145
  }
21084
21146
  },
21085
21147
  {
@@ -21091,16 +21153,7 @@ exports.TextVerticalAlignment = void 0;
21091
21153
  return this._pivot;
21092
21154
  },
21093
21155
  set: function set(value) {
21094
- var pivot = this._pivot;
21095
- if (pivot === value) {
21096
- this._dispatchSpriteChange(SpriteModifyFlags.pivot);
21097
- } else {
21098
- var x = value.x, y = value.y;
21099
- if (pivot.x !== x || pivot.y !== y) {
21100
- pivot.set(x, y);
21101
- this._dispatchSpriteChange(SpriteModifyFlags.pivot);
21102
- }
21103
- }
21156
+ this._pivot !== value && this._pivot.copyFrom(value);
21104
21157
  }
21105
21158
  },
21106
21159
  {
@@ -21115,11 +21168,7 @@ exports.TextVerticalAlignment = void 0;
21115
21168
  return this._border;
21116
21169
  },
21117
21170
  set: function set(value) {
21118
- var border = this._border;
21119
- var x = engineMath.MathUtil.clamp(value.x, 0, 1);
21120
- var y = engineMath.MathUtil.clamp(value.y, 0, 1);
21121
- border.set(x, y, engineMath.MathUtil.clamp(value.z, 0, 1 - x), engineMath.MathUtil.clamp(value.w, 0, 1 - y));
21122
- this._dispatchSpriteChange(SpriteModifyFlags.border);
21171
+ this._border !== value && this._border.copyFrom(value);
21123
21172
  }
21124
21173
  }
21125
21174
  ]);