@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/module.js CHANGED
@@ -3000,15 +3000,24 @@ var GLCapabilityType;
3000
3000
  }
3001
3001
  var _proto = DisorderedArray.prototype;
3002
3002
  _proto.add = function add(element) {
3003
- if (this.length === this._elements.length) this._elements.push(element);
3004
- else this._elements[this.length] = element;
3003
+ if (this.length === this._elements.length) {
3004
+ this._elements.push(element);
3005
+ } else {
3006
+ this._elements[this.length] = element;
3007
+ }
3005
3008
  this.length++;
3006
3009
  };
3007
3010
  _proto.delete = function _delete(element) {
3008
- //TODO: It can be optimized for custom binary search and other algorithms, currently this._elements>=this.length wastes performance.
3011
+ // @todo: It can be optimized for custom binary search and other algorithms, currently this._elements>=this.length wastes performance.
3009
3012
  var index = this._elements.indexOf(element);
3010
3013
  this.deleteByIndex(index);
3011
3014
  };
3015
+ _proto.set = function set(index, element) {
3016
+ if (index >= this.length) {
3017
+ throw "Index is out of range.";
3018
+ }
3019
+ this._elements[index] = element;
3020
+ };
3012
3021
  _proto.get = function get(index) {
3013
3022
  if (index >= this.length) {
3014
3023
  throw "Index is out of range.";
@@ -3016,9 +3025,9 @@ var GLCapabilityType;
3016
3025
  return this._elements[index];
3017
3026
  };
3018
3027
  /**
3019
- *
3020
- * @param index
3021
- * @returns The replaced item is used to reset its index.
3028
+ * Delete the element at the specified index.
3029
+ * @param index - The index of the element to be deleted
3030
+ * @returns The replaced item is used to reset its index
3022
3031
  */ _proto.deleteByIndex = function deleteByIndex(index) {
3023
3032
  var elements = this._elements;
3024
3033
  var end = null;
@@ -4754,6 +4763,7 @@ var ComponentCloner = /*#__PURE__*/ function() {
4754
4763
  cloneEntity._hookResource = hookResource;
4755
4764
  hookResource._addReferCount(1);
4756
4765
  }
4766
+ cloneEntity.layer = this.layer;
4757
4767
  cloneEntity._isActive = this._isActive;
4758
4768
  cloneEntity.transform.localMatrix = this.transform.localMatrix;
4759
4769
  var children = this._children;
@@ -8386,31 +8396,18 @@ __decorate([
8386
8396
  };
8387
8397
  /**
8388
8398
  * @internal
8389
- */ _proto._getSunLightIndex = function _getSunLightIndex() {
8399
+ */ _proto._updateSunLightIndex = function _updateSunLightIndex() {
8390
8400
  var directLights = this._directLights;
8391
- var sunLightIndex = -1;
8392
- var maxIntensity = Number.NEGATIVE_INFINITY;
8393
- var hasShadowLight = false;
8394
- for(var i = 0, n = directLights.length; i < n; i++){
8395
- var directLight = directLights.get(i);
8396
- if (directLight.shadowType !== ShadowType.None && !hasShadowLight) {
8397
- maxIntensity = Number.NEGATIVE_INFINITY;
8398
- hasShadowLight = true;
8399
- }
8400
- var intensity = directLight.intensity * directLight.color.getBrightness();
8401
- if (hasShadowLight) {
8402
- if (directLight.shadowType !== ShadowType.None && maxIntensity < intensity) {
8403
- maxIntensity = intensity;
8404
- sunLightIndex = i;
8405
- }
8406
- } else {
8407
- if (maxIntensity < intensity) {
8408
- maxIntensity = intensity;
8409
- sunLightIndex = i;
8410
- }
8411
- }
8401
+ var index = this._getSunLightIndex();
8402
+ // -1 means no sun light, 0 means the first direct light already is sun light
8403
+ if (index > 0) {
8404
+ var firstLight = directLights.get(0);
8405
+ var sunLight = directLights.get(index);
8406
+ directLights.set(0, sunLight);
8407
+ directLights.set(index, firstLight);
8408
+ sunLight._lightIndex = 0;
8409
+ firstLight._lightIndex = index;
8412
8410
  }
8413
- return sunLightIndex;
8414
8411
  };
8415
8412
  /**
8416
8413
  * @internal
@@ -8459,6 +8456,32 @@ __decorate([
8459
8456
  this._pointLights.garbageCollection();
8460
8457
  this._directLights.garbageCollection();
8461
8458
  };
8459
+ _proto._getSunLightIndex = function _getSunLightIndex() {
8460
+ var directLights = this._directLights;
8461
+ var sunLightIndex = -1;
8462
+ var maxIntensity = Number.NEGATIVE_INFINITY;
8463
+ var hasShadowLight = false;
8464
+ for(var i = 0, n = directLights.length; i < n; i++){
8465
+ var directLight = directLights.get(i);
8466
+ if (directLight.shadowType !== ShadowType.None && !hasShadowLight) {
8467
+ maxIntensity = Number.NEGATIVE_INFINITY;
8468
+ hasShadowLight = true;
8469
+ }
8470
+ var intensity = directLight.intensity * directLight.color.getBrightness();
8471
+ if (hasShadowLight) {
8472
+ if (directLight.shadowType !== ShadowType.None && maxIntensity < intensity) {
8473
+ maxIntensity = intensity;
8474
+ sunLightIndex = i;
8475
+ }
8476
+ } else {
8477
+ if (maxIntensity < intensity) {
8478
+ maxIntensity = intensity;
8479
+ sunLightIndex = i;
8480
+ }
8481
+ }
8482
+ }
8483
+ return sunLightIndex;
8484
+ };
8462
8485
  return LightManager;
8463
8486
  }();
8464
8487
 
@@ -9669,7 +9692,7 @@ var begin_mobile_frag = "#define GLSLIFY 1\nvec4 ambient=vec4(0.0);vec4 emission
9669
9692
 
9670
9693
  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
9671
9694
 
9672
- 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
9695
+ 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
9673
9696
 
9674
9697
  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
9675
9698
 
@@ -9709,7 +9732,7 @@ var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\nfloat computeSpecula
9709
9732
 
9710
9733
  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
9711
9734
 
9712
- 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
9735
+ 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
9713
9736
 
9714
9737
  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
9715
9738
 
@@ -15996,20 +16019,25 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
15996
16019
 
15997
16020
  /**
15998
16021
  * Ambient light.
15999
- */ var AmbientLight = /*#__PURE__*/ function() {
16000
- function AmbientLight() {
16001
- this._diffuseSolidColor = new Color$1(0.212, 0.227, 0.259);
16002
- this._diffuseIntensity = 1.0;
16003
- this._specularIntensity = 1.0;
16004
- this._diffuseMode = DiffuseMode.SolidColor;
16005
- this._shArray = new Float32Array(27);
16006
- this._scenes = [];
16007
- this._specularTextureDecodeRGBM = false;
16022
+ */ var AmbientLight = /*#__PURE__*/ function(ReferResource) {
16023
+ _inherits(AmbientLight, ReferResource);
16024
+ function AmbientLight(engine) {
16025
+ var _this;
16026
+ _this = ReferResource.call(this, engine) || this;
16027
+ _this._diffuseSolidColor = new Color$1(0.212, 0.227, 0.259);
16028
+ _this._diffuseIntensity = 1.0;
16029
+ _this._specularIntensity = 1.0;
16030
+ _this._diffuseMode = DiffuseMode.SolidColor;
16031
+ _this._shArray = new Float32Array(27);
16032
+ _this._scenes = [];
16033
+ _this._specularTextureDecodeRGBM = false;
16034
+ return _this;
16008
16035
  }
16009
16036
  var _proto = AmbientLight.prototype;
16010
16037
  /**
16011
16038
  * @internal
16012
16039
  */ _proto._addToScene = function _addToScene(scene) {
16040
+ this._addReferCount(1);
16013
16041
  this._scenes.push(scene);
16014
16042
  var shaderData = scene.shaderData;
16015
16043
  shaderData.setColor(AmbientLight._diffuseColorProperty, this._diffuseSolidColor);
@@ -16023,9 +16051,13 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16023
16051
  /**
16024
16052
  * @internal
16025
16053
  */ _proto._removeFromScene = function _removeFromScene(scene) {
16054
+ this._addReferCount(-1);
16026
16055
  var scenes = this._scenes;
16027
16056
  var index = scenes.indexOf(scene);
16028
16057
  scenes.splice(index, 1);
16058
+ var shaderData = scene.shaderData;
16059
+ shaderData.setTexture(AmbientLight._specularTextureProperty, null);
16060
+ shaderData.disableMacro(AmbientLight._specularMacro);
16029
16061
  };
16030
16062
  _proto._setDiffuseMode = function _setDiffuseMode(sceneShaderData) {
16031
16063
  if (this._diffuseMode === DiffuseMode.SphericalHarmonics) {
@@ -16213,7 +16245,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16213
16245
  }
16214
16246
  ]);
16215
16247
  return AmbientLight;
16216
- }();
16248
+ }(ReferResource);
16217
16249
  (function() {
16218
16250
  AmbientLight._shMacro = ShaderMacro.getByName("SCENE_USE_SH");
16219
16251
  })();
@@ -16270,7 +16302,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16270
16302
  _this.name = name || "";
16271
16303
  var shaderData = _this.shaderData;
16272
16304
  shaderData._addReferCount(1);
16273
- _this.ambientLight = new AmbientLight();
16305
+ _this.ambientLight = new AmbientLight(engine);
16274
16306
  engine.sceneManager._allScenes.push(_assert_this_initialized(_this));
16275
16307
  shaderData.enableMacro("SCENE_FOG_MODE", _this._fogMode.toString());
16276
16308
  shaderData.enableMacro("SCENE_SHADOW_CASCADED_COUNT", _this.shadowCascades.toString());
@@ -16378,6 +16410,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16378
16410
  if (this._destroyed) {
16379
16411
  return;
16380
16412
  }
16413
+ EngineObject.prototype.destroy.call(this);
16381
16414
  this._destroy();
16382
16415
  var allScenes = this.engine.sceneManager._allScenes;
16383
16416
  allScenes.splice(allScenes.indexOf(this), 1);
@@ -16420,9 +16453,9 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16420
16453
  var lightManager = engine._lightManager;
16421
16454
  engine.time._updateSceneShaderData(shaderData);
16422
16455
  lightManager._updateShaderData(this.shaderData);
16423
- var sunLightIndex = lightManager._getSunLightIndex();
16424
- if (sunLightIndex !== -1) {
16425
- var sunlight = lightManager._directLights.get(sunLightIndex);
16456
+ lightManager._updateSunLightIndex();
16457
+ if (lightManager._directLights.length > 0) {
16458
+ var sunlight = lightManager._directLights.get(0);
16426
16459
  shaderData.setColor(Scene._sunlightColorProperty, sunlight._getLightIntensityColor());
16427
16460
  shaderData.setVector3(Scene._sunlightDirectionProperty, sunlight.direction);
16428
16461
  this._sunLight = sunlight;
@@ -16457,6 +16490,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16457
16490
  }
16458
16491
  this._activeCameras.length = 0;
16459
16492
  this.background.destroy();
16493
+ this._ambientLight && this._ambientLight._removeFromScene(this);
16460
16494
  this.shaderData._addReferCount(-1);
16461
16495
  };
16462
16496
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -16684,10 +16718,9 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16684
16718
  * @internal
16685
16719
  */ _proto._destroyAllScene = function _destroyAllScene() {
16686
16720
  var allScenes = this._allScenes;
16687
- for(var i = 0, n = allScenes.length; i < n; i++){
16688
- allScenes[i]._destroy();
16721
+ while(allScenes[0]){
16722
+ allScenes[0].destroy();
16689
16723
  }
16690
- allScenes.length = 0;
16691
16724
  };
16692
16725
  _create_class(SceneManager, [
16693
16726
  {
@@ -18460,9 +18493,8 @@ var /**
18460
18493
  var lightUp = this._lightUp;
18461
18494
  var lightSide = this._lightSide;
18462
18495
  var lightForward = shadowSliceData.virtualCamera.forward;
18463
- var sunLightIndex = engine._lightManager._getSunLightIndex();
18464
- if (sunLightIndex !== -1) {
18465
- var light = camera.scene._sunLight;
18496
+ var light = camera.scene._sunLight;
18497
+ if (light) {
18466
18498
  var shadowFar = Math.min(camera.scene.shadowDistance, camera.farClipPlane);
18467
18499
  this._getCascadesSplitDistance(shadowFar);
18468
18500
  // prepare render target
@@ -18475,7 +18507,7 @@ var /**
18475
18507
  rhi.clearRenderTarget(engine, CameraClearFlags.All, CascadedShadowCasterPass._clearColor);
18476
18508
  }
18477
18509
  this._shadowInfos.x = light.shadowStrength;
18478
- this._shadowInfos.z = sunLightIndex;
18510
+ this._shadowInfos.z = 0; // @todo: sun light index always 0
18479
18511
  // prepare light and camera direction
18480
18512
  Matrix.rotationQuaternion(light.entity.transform.worldRotationQuaternion, lightWorld);
18481
18513
  lightSide.set(lightWorldE[0], lightWorldE[1], lightWorldE[2]);
@@ -20810,6 +20842,15 @@ var TextVerticalAlignment;
20810
20842
  _this._dirtyUpdateFlag = 0x7;
20811
20843
  /** @internal */ _this._updateFlagManager = new UpdateFlagManager();
20812
20844
  _this._texture = texture;
20845
+ _this._onRegionChange = _this._onRegionChange.bind(_assert_this_initialized(_this));
20846
+ _this._onPivotChange = _this._onPivotChange.bind(_assert_this_initialized(_this));
20847
+ _this._onBorderChange = _this._onBorderChange.bind(_assert_this_initialized(_this));
20848
+ // @ts-ignore
20849
+ _this._region._onValueChanged = _this._onRegionChange;
20850
+ // @ts-ignore
20851
+ _this._pivot._onValueChanged = _this._onPivotChange;
20852
+ // @ts-ignore
20853
+ _this._border._onValueChanged = _this._onBorderChange;
20813
20854
  region && _this._region.copyFrom(region);
20814
20855
  pivot && _this._pivot.copyFrom(pivot);
20815
20856
  border && _this._border.copyFrom(border);
@@ -20949,6 +20990,34 @@ var TextVerticalAlignment;
20949
20990
  }
20950
20991
  this._updateFlagManager.dispatch(type);
20951
20992
  };
20993
+ _proto._onRegionChange = function _onRegionChange() {
20994
+ var _this = this, region = _this._region;
20995
+ // @ts-ignore
20996
+ region._onValueChanged = null;
20997
+ var x = MathUtil$1.clamp(region.x, 0, 1);
20998
+ var y = MathUtil$1.clamp(region.y, 0, 1);
20999
+ region.set(x, y, MathUtil$1.clamp(region.width, 0, 1 - x), MathUtil$1.clamp(region.height, 0, 1 - y));
21000
+ this._dispatchSpriteChange(SpriteModifyFlags.region);
21001
+ if (this._customWidth === undefined || this._customHeight === undefined) {
21002
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
21003
+ }
21004
+ // @ts-ignore
21005
+ region._onValueChanged = this._onRegionChange;
21006
+ };
21007
+ _proto._onPivotChange = function _onPivotChange() {
21008
+ this._dispatchSpriteChange(SpriteModifyFlags.pivot);
21009
+ };
21010
+ _proto._onBorderChange = function _onBorderChange() {
21011
+ var _this = this, border = _this._border;
21012
+ // @ts-ignore
21013
+ border._onValueChanged = null;
21014
+ var x = MathUtil$1.clamp(border.x, 0, 1);
21015
+ var y = MathUtil$1.clamp(border.y, 0, 1);
21016
+ border.set(x, y, MathUtil$1.clamp(border.z, 0, 1 - x), MathUtil$1.clamp(border.w, 0, 1 - y));
21017
+ this._dispatchSpriteChange(SpriteModifyFlags.border);
21018
+ // @ts-ignore
21019
+ border._onValueChanged = this._onBorderChange;
21020
+ };
20952
21021
  _create_class(Sprite, [
20953
21022
  {
20954
21023
  key: "texture",
@@ -21068,14 +21137,7 @@ var TextVerticalAlignment;
21068
21137
  return this._region;
21069
21138
  },
21070
21139
  set: function set(value) {
21071
- var region = this._region;
21072
- var x = MathUtil$1.clamp(value.x, 0, 1);
21073
- var y = MathUtil$1.clamp(value.y, 0, 1);
21074
- region.set(x, y, MathUtil$1.clamp(value.width, 0, 1 - x), MathUtil$1.clamp(value.height, 0, 1 - y));
21075
- this._dispatchSpriteChange(SpriteModifyFlags.region);
21076
- if (this._customWidth === undefined || this._customHeight === undefined) {
21077
- this._dispatchSpriteChange(SpriteModifyFlags.size);
21078
- }
21140
+ this._region !== value && this._region.copyFrom(value);
21079
21141
  }
21080
21142
  },
21081
21143
  {
@@ -21087,16 +21149,7 @@ var TextVerticalAlignment;
21087
21149
  return this._pivot;
21088
21150
  },
21089
21151
  set: function set(value) {
21090
- var pivot = this._pivot;
21091
- if (pivot === value) {
21092
- this._dispatchSpriteChange(SpriteModifyFlags.pivot);
21093
- } else {
21094
- var x = value.x, y = value.y;
21095
- if (pivot.x !== x || pivot.y !== y) {
21096
- pivot.set(x, y);
21097
- this._dispatchSpriteChange(SpriteModifyFlags.pivot);
21098
- }
21099
- }
21152
+ this._pivot !== value && this._pivot.copyFrom(value);
21100
21153
  }
21101
21154
  },
21102
21155
  {
@@ -21111,11 +21164,7 @@ var TextVerticalAlignment;
21111
21164
  return this._border;
21112
21165
  },
21113
21166
  set: function set(value) {
21114
- var border = this._border;
21115
- var x = MathUtil$1.clamp(value.x, 0, 1);
21116
- var y = MathUtil$1.clamp(value.y, 0, 1);
21117
- border.set(x, y, MathUtil$1.clamp(value.z, 0, 1 - x), MathUtil$1.clamp(value.w, 0, 1 - y));
21118
- this._dispatchSpriteChange(SpriteModifyFlags.border);
21167
+ this._border !== value && this._border.copyFrom(value);
21119
21168
  }
21120
21169
  }
21121
21170
  ]);