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

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;
@@ -8390,31 +8399,18 @@ __decorate([
8390
8399
  };
8391
8400
  /**
8392
8401
  * @internal
8393
- */ _proto._getSunLightIndex = function _getSunLightIndex() {
8402
+ */ _proto._updateSunLightIndex = function _updateSunLightIndex() {
8394
8403
  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
- }
8404
+ var index = this._getSunLightIndex();
8405
+ // -1 means no sun light, 0 means the first direct light already is sun light
8406
+ if (index > 0) {
8407
+ var firstLight = directLights.get(0);
8408
+ var sunLight = directLights.get(index);
8409
+ directLights.set(0, sunLight);
8410
+ directLights.set(index, firstLight);
8411
+ sunLight._lightIndex = 0;
8412
+ firstLight._lightIndex = index;
8416
8413
  }
8417
- return sunLightIndex;
8418
8414
  };
8419
8415
  /**
8420
8416
  * @internal
@@ -8463,6 +8459,32 @@ __decorate([
8463
8459
  this._pointLights.garbageCollection();
8464
8460
  this._directLights.garbageCollection();
8465
8461
  };
8462
+ _proto._getSunLightIndex = function _getSunLightIndex() {
8463
+ var directLights = this._directLights;
8464
+ var sunLightIndex = -1;
8465
+ var maxIntensity = Number.NEGATIVE_INFINITY;
8466
+ var hasShadowLight = false;
8467
+ for(var i = 0, n = directLights.length; i < n; i++){
8468
+ var directLight = directLights.get(i);
8469
+ if (directLight.shadowType !== exports.ShadowType.None && !hasShadowLight) {
8470
+ maxIntensity = Number.NEGATIVE_INFINITY;
8471
+ hasShadowLight = true;
8472
+ }
8473
+ var intensity = directLight.intensity * directLight.color.getBrightness();
8474
+ if (hasShadowLight) {
8475
+ if (directLight.shadowType !== exports.ShadowType.None && maxIntensity < intensity) {
8476
+ maxIntensity = intensity;
8477
+ sunLightIndex = i;
8478
+ }
8479
+ } else {
8480
+ if (maxIntensity < intensity) {
8481
+ maxIntensity = intensity;
8482
+ sunLightIndex = i;
8483
+ }
8484
+ }
8485
+ }
8486
+ return sunLightIndex;
8487
+ };
8466
8488
  return LightManager;
8467
8489
  }();
8468
8490
 
@@ -9673,7 +9695,7 @@ var begin_mobile_frag = "#define GLSLIFY 1\nvec4 ambient=vec4(0.0);vec4 emission
9673
9695
 
9674
9696
  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
9697
 
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
9698
+ 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
9699
 
9678
9700
  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
9701
 
@@ -9713,7 +9735,7 @@ var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\nfloat computeSpecula
9713
9735
 
9714
9736
  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
9737
 
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
9738
+ 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
9739
 
9718
9740
  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
9741
 
@@ -16000,20 +16022,25 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16000
16022
 
16001
16023
  /**
16002
16024
  * 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;
16025
+ */ var AmbientLight = /*#__PURE__*/ function(ReferResource) {
16026
+ _inherits(AmbientLight, ReferResource);
16027
+ function AmbientLight(engine) {
16028
+ var _this;
16029
+ _this = ReferResource.call(this, engine) || this;
16030
+ _this._diffuseSolidColor = new engineMath.Color(0.212, 0.227, 0.259);
16031
+ _this._diffuseIntensity = 1.0;
16032
+ _this._specularIntensity = 1.0;
16033
+ _this._diffuseMode = exports.DiffuseMode.SolidColor;
16034
+ _this._shArray = new Float32Array(27);
16035
+ _this._scenes = [];
16036
+ _this._specularTextureDecodeRGBM = false;
16037
+ return _this;
16012
16038
  }
16013
16039
  var _proto = AmbientLight.prototype;
16014
16040
  /**
16015
16041
  * @internal
16016
16042
  */ _proto._addToScene = function _addToScene(scene) {
16043
+ this._addReferCount(1);
16017
16044
  this._scenes.push(scene);
16018
16045
  var shaderData = scene.shaderData;
16019
16046
  shaderData.setColor(AmbientLight._diffuseColorProperty, this._diffuseSolidColor);
@@ -16027,9 +16054,13 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16027
16054
  /**
16028
16055
  * @internal
16029
16056
  */ _proto._removeFromScene = function _removeFromScene(scene) {
16057
+ this._addReferCount(-1);
16030
16058
  var scenes = this._scenes;
16031
16059
  var index = scenes.indexOf(scene);
16032
16060
  scenes.splice(index, 1);
16061
+ var shaderData = scene.shaderData;
16062
+ shaderData.setTexture(AmbientLight._specularTextureProperty, null);
16063
+ shaderData.disableMacro(AmbientLight._specularMacro);
16033
16064
  };
16034
16065
  _proto._setDiffuseMode = function _setDiffuseMode(sceneShaderData) {
16035
16066
  if (this._diffuseMode === exports.DiffuseMode.SphericalHarmonics) {
@@ -16217,7 +16248,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16217
16248
  }
16218
16249
  ]);
16219
16250
  return AmbientLight;
16220
- }();
16251
+ }(ReferResource);
16221
16252
  (function() {
16222
16253
  AmbientLight._shMacro = ShaderMacro.getByName("SCENE_USE_SH");
16223
16254
  })();
@@ -16274,7 +16305,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16274
16305
  _this.name = name || "";
16275
16306
  var shaderData = _this.shaderData;
16276
16307
  shaderData._addReferCount(1);
16277
- _this.ambientLight = new AmbientLight();
16308
+ _this.ambientLight = new AmbientLight(engine);
16278
16309
  engine.sceneManager._allScenes.push(_assert_this_initialized(_this));
16279
16310
  shaderData.enableMacro("SCENE_FOG_MODE", _this._fogMode.toString());
16280
16311
  shaderData.enableMacro("SCENE_SHADOW_CASCADED_COUNT", _this.shadowCascades.toString());
@@ -16382,6 +16413,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16382
16413
  if (this._destroyed) {
16383
16414
  return;
16384
16415
  }
16416
+ EngineObject.prototype.destroy.call(this);
16385
16417
  this._destroy();
16386
16418
  var allScenes = this.engine.sceneManager._allScenes;
16387
16419
  allScenes.splice(allScenes.indexOf(this), 1);
@@ -16424,9 +16456,9 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16424
16456
  var lightManager = engine._lightManager;
16425
16457
  engine.time._updateSceneShaderData(shaderData);
16426
16458
  lightManager._updateShaderData(this.shaderData);
16427
- var sunLightIndex = lightManager._getSunLightIndex();
16428
- if (sunLightIndex !== -1) {
16429
- var sunlight = lightManager._directLights.get(sunLightIndex);
16459
+ lightManager._updateSunLightIndex();
16460
+ if (lightManager._directLights.length > 0) {
16461
+ var sunlight = lightManager._directLights.get(0);
16430
16462
  shaderData.setColor(Scene._sunlightColorProperty, sunlight._getLightIntensityColor());
16431
16463
  shaderData.setVector3(Scene._sunlightDirectionProperty, sunlight.direction);
16432
16464
  this._sunLight = sunlight;
@@ -16461,6 +16493,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16461
16493
  }
16462
16494
  this._activeCameras.length = 0;
16463
16495
  this.background.destroy();
16496
+ this._ambientLight && this._ambientLight._removeFromScene(this);
16464
16497
  this.shaderData._addReferCount(-1);
16465
16498
  };
16466
16499
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -16688,10 +16721,9 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16688
16721
  * @internal
16689
16722
  */ _proto._destroyAllScene = function _destroyAllScene() {
16690
16723
  var allScenes = this._allScenes;
16691
- for(var i = 0, n = allScenes.length; i < n; i++){
16692
- allScenes[i]._destroy();
16724
+ while(allScenes[0]){
16725
+ allScenes[0].destroy();
16693
16726
  }
16694
- allScenes.length = 0;
16695
16727
  };
16696
16728
  _create_class(SceneManager, [
16697
16729
  {
@@ -18464,9 +18496,8 @@ var /**
18464
18496
  var lightUp = this._lightUp;
18465
18497
  var lightSide = this._lightSide;
18466
18498
  var lightForward = shadowSliceData.virtualCamera.forward;
18467
- var sunLightIndex = engine._lightManager._getSunLightIndex();
18468
- if (sunLightIndex !== -1) {
18469
- var light = camera.scene._sunLight;
18499
+ var light = camera.scene._sunLight;
18500
+ if (light) {
18470
18501
  var shadowFar = Math.min(camera.scene.shadowDistance, camera.farClipPlane);
18471
18502
  this._getCascadesSplitDistance(shadowFar);
18472
18503
  // prepare render target
@@ -18479,7 +18510,7 @@ var /**
18479
18510
  rhi.clearRenderTarget(engine, exports.CameraClearFlags.All, CascadedShadowCasterPass._clearColor);
18480
18511
  }
18481
18512
  this._shadowInfos.x = light.shadowStrength;
18482
- this._shadowInfos.z = sunLightIndex;
18513
+ this._shadowInfos.z = 0; // @todo: sun light index always 0
18483
18514
  // prepare light and camera direction
18484
18515
  engineMath.Matrix.rotationQuaternion(light.entity.transform.worldRotationQuaternion, lightWorld);
18485
18516
  lightSide.set(lightWorldE[0], lightWorldE[1], lightWorldE[2]);
@@ -20814,6 +20845,15 @@ exports.TextVerticalAlignment = void 0;
20814
20845
  _this._dirtyUpdateFlag = 0x7;
20815
20846
  /** @internal */ _this._updateFlagManager = new UpdateFlagManager();
20816
20847
  _this._texture = texture;
20848
+ _this._onRegionChange = _this._onRegionChange.bind(_assert_this_initialized(_this));
20849
+ _this._onPivotChange = _this._onPivotChange.bind(_assert_this_initialized(_this));
20850
+ _this._onBorderChange = _this._onBorderChange.bind(_assert_this_initialized(_this));
20851
+ // @ts-ignore
20852
+ _this._region._onValueChanged = _this._onRegionChange;
20853
+ // @ts-ignore
20854
+ _this._pivot._onValueChanged = _this._onPivotChange;
20855
+ // @ts-ignore
20856
+ _this._border._onValueChanged = _this._onBorderChange;
20817
20857
  region && _this._region.copyFrom(region);
20818
20858
  pivot && _this._pivot.copyFrom(pivot);
20819
20859
  border && _this._border.copyFrom(border);
@@ -20953,6 +20993,34 @@ exports.TextVerticalAlignment = void 0;
20953
20993
  }
20954
20994
  this._updateFlagManager.dispatch(type);
20955
20995
  };
20996
+ _proto._onRegionChange = function _onRegionChange() {
20997
+ var _this = this, region = _this._region;
20998
+ // @ts-ignore
20999
+ region._onValueChanged = null;
21000
+ var x = engineMath.MathUtil.clamp(region.x, 0, 1);
21001
+ var y = engineMath.MathUtil.clamp(region.y, 0, 1);
21002
+ region.set(x, y, engineMath.MathUtil.clamp(region.width, 0, 1 - x), engineMath.MathUtil.clamp(region.height, 0, 1 - y));
21003
+ this._dispatchSpriteChange(SpriteModifyFlags.region);
21004
+ if (this._customWidth === undefined || this._customHeight === undefined) {
21005
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
21006
+ }
21007
+ // @ts-ignore
21008
+ region._onValueChanged = this._onRegionChange;
21009
+ };
21010
+ _proto._onPivotChange = function _onPivotChange() {
21011
+ this._dispatchSpriteChange(SpriteModifyFlags.pivot);
21012
+ };
21013
+ _proto._onBorderChange = function _onBorderChange() {
21014
+ var _this = this, border = _this._border;
21015
+ // @ts-ignore
21016
+ border._onValueChanged = null;
21017
+ var x = engineMath.MathUtil.clamp(border.x, 0, 1);
21018
+ var y = engineMath.MathUtil.clamp(border.y, 0, 1);
21019
+ border.set(x, y, engineMath.MathUtil.clamp(border.z, 0, 1 - x), engineMath.MathUtil.clamp(border.w, 0, 1 - y));
21020
+ this._dispatchSpriteChange(SpriteModifyFlags.border);
21021
+ // @ts-ignore
21022
+ border._onValueChanged = this._onBorderChange;
21023
+ };
20956
21024
  _create_class(Sprite, [
20957
21025
  {
20958
21026
  key: "texture",
@@ -21072,14 +21140,7 @@ exports.TextVerticalAlignment = void 0;
21072
21140
  return this._region;
21073
21141
  },
21074
21142
  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
- }
21143
+ this._region !== value && this._region.copyFrom(value);
21083
21144
  }
21084
21145
  },
21085
21146
  {
@@ -21091,16 +21152,7 @@ exports.TextVerticalAlignment = void 0;
21091
21152
  return this._pivot;
21092
21153
  },
21093
21154
  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
- }
21155
+ this._pivot !== value && this._pivot.copyFrom(value);
21104
21156
  }
21105
21157
  },
21106
21158
  {
@@ -21115,11 +21167,7 @@ exports.TextVerticalAlignment = void 0;
21115
21167
  return this._border;
21116
21168
  },
21117
21169
  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);
21170
+ this._border !== value && this._border.copyFrom(value);
21123
21171
  }
21124
21172
  }
21125
21173
  ]);