@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/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;
@@ -8386,31 +8395,18 @@ __decorate([
8386
8395
  };
8387
8396
  /**
8388
8397
  * @internal
8389
- */ _proto._getSunLightIndex = function _getSunLightIndex() {
8398
+ */ _proto._updateSunLightIndex = function _updateSunLightIndex() {
8390
8399
  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
- }
8400
+ var index = this._getSunLightIndex();
8401
+ // -1 means no sun light, 0 means the first direct light already is sun light
8402
+ if (index > 0) {
8403
+ var firstLight = directLights.get(0);
8404
+ var sunLight = directLights.get(index);
8405
+ directLights.set(0, sunLight);
8406
+ directLights.set(index, firstLight);
8407
+ sunLight._lightIndex = 0;
8408
+ firstLight._lightIndex = index;
8412
8409
  }
8413
- return sunLightIndex;
8414
8410
  };
8415
8411
  /**
8416
8412
  * @internal
@@ -8459,6 +8455,32 @@ __decorate([
8459
8455
  this._pointLights.garbageCollection();
8460
8456
  this._directLights.garbageCollection();
8461
8457
  };
8458
+ _proto._getSunLightIndex = function _getSunLightIndex() {
8459
+ var directLights = this._directLights;
8460
+ var sunLightIndex = -1;
8461
+ var maxIntensity = Number.NEGATIVE_INFINITY;
8462
+ var hasShadowLight = false;
8463
+ for(var i = 0, n = directLights.length; i < n; i++){
8464
+ var directLight = directLights.get(i);
8465
+ if (directLight.shadowType !== ShadowType.None && !hasShadowLight) {
8466
+ maxIntensity = Number.NEGATIVE_INFINITY;
8467
+ hasShadowLight = true;
8468
+ }
8469
+ var intensity = directLight.intensity * directLight.color.getBrightness();
8470
+ if (hasShadowLight) {
8471
+ if (directLight.shadowType !== ShadowType.None && maxIntensity < intensity) {
8472
+ maxIntensity = intensity;
8473
+ sunLightIndex = i;
8474
+ }
8475
+ } else {
8476
+ if (maxIntensity < intensity) {
8477
+ maxIntensity = intensity;
8478
+ sunLightIndex = i;
8479
+ }
8480
+ }
8481
+ }
8482
+ return sunLightIndex;
8483
+ };
8462
8484
  return LightManager;
8463
8485
  }();
8464
8486
 
@@ -9669,7 +9691,7 @@ var begin_mobile_frag = "#define GLSLIFY 1\nvec4 ambient=vec4(0.0);vec4 emission
9669
9691
 
9670
9692
  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
9693
 
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
9694
+ 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
9695
 
9674
9696
  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
9697
 
@@ -9709,7 +9731,7 @@ var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\nfloat computeSpecula
9709
9731
 
9710
9732
  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
9733
 
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
9734
+ 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
9735
 
9714
9736
  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
9737
 
@@ -15996,20 +16018,25 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
15996
16018
 
15997
16019
  /**
15998
16020
  * 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;
16021
+ */ var AmbientLight = /*#__PURE__*/ function(ReferResource) {
16022
+ _inherits(AmbientLight, ReferResource);
16023
+ function AmbientLight(engine) {
16024
+ var _this;
16025
+ _this = ReferResource.call(this, engine) || this;
16026
+ _this._diffuseSolidColor = new Color$1(0.212, 0.227, 0.259);
16027
+ _this._diffuseIntensity = 1.0;
16028
+ _this._specularIntensity = 1.0;
16029
+ _this._diffuseMode = DiffuseMode.SolidColor;
16030
+ _this._shArray = new Float32Array(27);
16031
+ _this._scenes = [];
16032
+ _this._specularTextureDecodeRGBM = false;
16033
+ return _this;
16008
16034
  }
16009
16035
  var _proto = AmbientLight.prototype;
16010
16036
  /**
16011
16037
  * @internal
16012
16038
  */ _proto._addToScene = function _addToScene(scene) {
16039
+ this._addReferCount(1);
16013
16040
  this._scenes.push(scene);
16014
16041
  var shaderData = scene.shaderData;
16015
16042
  shaderData.setColor(AmbientLight._diffuseColorProperty, this._diffuseSolidColor);
@@ -16023,9 +16050,13 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16023
16050
  /**
16024
16051
  * @internal
16025
16052
  */ _proto._removeFromScene = function _removeFromScene(scene) {
16053
+ this._addReferCount(-1);
16026
16054
  var scenes = this._scenes;
16027
16055
  var index = scenes.indexOf(scene);
16028
16056
  scenes.splice(index, 1);
16057
+ var shaderData = scene.shaderData;
16058
+ shaderData.setTexture(AmbientLight._specularTextureProperty, null);
16059
+ shaderData.disableMacro(AmbientLight._specularMacro);
16029
16060
  };
16030
16061
  _proto._setDiffuseMode = function _setDiffuseMode(sceneShaderData) {
16031
16062
  if (this._diffuseMode === DiffuseMode.SphericalHarmonics) {
@@ -16213,7 +16244,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16213
16244
  }
16214
16245
  ]);
16215
16246
  return AmbientLight;
16216
- }();
16247
+ }(ReferResource);
16217
16248
  (function() {
16218
16249
  AmbientLight._shMacro = ShaderMacro.getByName("SCENE_USE_SH");
16219
16250
  })();
@@ -16270,7 +16301,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16270
16301
  _this.name = name || "";
16271
16302
  var shaderData = _this.shaderData;
16272
16303
  shaderData._addReferCount(1);
16273
- _this.ambientLight = new AmbientLight();
16304
+ _this.ambientLight = new AmbientLight(engine);
16274
16305
  engine.sceneManager._allScenes.push(_assert_this_initialized(_this));
16275
16306
  shaderData.enableMacro("SCENE_FOG_MODE", _this._fogMode.toString());
16276
16307
  shaderData.enableMacro("SCENE_SHADOW_CASCADED_COUNT", _this.shadowCascades.toString());
@@ -16378,6 +16409,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16378
16409
  if (this._destroyed) {
16379
16410
  return;
16380
16411
  }
16412
+ EngineObject.prototype.destroy.call(this);
16381
16413
  this._destroy();
16382
16414
  var allScenes = this.engine.sceneManager._allScenes;
16383
16415
  allScenes.splice(allScenes.indexOf(this), 1);
@@ -16420,9 +16452,9 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16420
16452
  var lightManager = engine._lightManager;
16421
16453
  engine.time._updateSceneShaderData(shaderData);
16422
16454
  lightManager._updateShaderData(this.shaderData);
16423
- var sunLightIndex = lightManager._getSunLightIndex();
16424
- if (sunLightIndex !== -1) {
16425
- var sunlight = lightManager._directLights.get(sunLightIndex);
16455
+ lightManager._updateSunLightIndex();
16456
+ if (lightManager._directLights.length > 0) {
16457
+ var sunlight = lightManager._directLights.get(0);
16426
16458
  shaderData.setColor(Scene._sunlightColorProperty, sunlight._getLightIntensityColor());
16427
16459
  shaderData.setVector3(Scene._sunlightDirectionProperty, sunlight.direction);
16428
16460
  this._sunLight = sunlight;
@@ -16457,6 +16489,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16457
16489
  }
16458
16490
  this._activeCameras.length = 0;
16459
16491
  this.background.destroy();
16492
+ this._ambientLight && this._ambientLight._removeFromScene(this);
16460
16493
  this.shaderData._addReferCount(-1);
16461
16494
  };
16462
16495
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -16684,10 +16717,9 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16684
16717
  * @internal
16685
16718
  */ _proto._destroyAllScene = function _destroyAllScene() {
16686
16719
  var allScenes = this._allScenes;
16687
- for(var i = 0, n = allScenes.length; i < n; i++){
16688
- allScenes[i]._destroy();
16720
+ while(allScenes[0]){
16721
+ allScenes[0].destroy();
16689
16722
  }
16690
- allScenes.length = 0;
16691
16723
  };
16692
16724
  _create_class(SceneManager, [
16693
16725
  {
@@ -18460,9 +18492,8 @@ var /**
18460
18492
  var lightUp = this._lightUp;
18461
18493
  var lightSide = this._lightSide;
18462
18494
  var lightForward = shadowSliceData.virtualCamera.forward;
18463
- var sunLightIndex = engine._lightManager._getSunLightIndex();
18464
- if (sunLightIndex !== -1) {
18465
- var light = camera.scene._sunLight;
18495
+ var light = camera.scene._sunLight;
18496
+ if (light) {
18466
18497
  var shadowFar = Math.min(camera.scene.shadowDistance, camera.farClipPlane);
18467
18498
  this._getCascadesSplitDistance(shadowFar);
18468
18499
  // prepare render target
@@ -18475,7 +18506,7 @@ var /**
18475
18506
  rhi.clearRenderTarget(engine, CameraClearFlags.All, CascadedShadowCasterPass._clearColor);
18476
18507
  }
18477
18508
  this._shadowInfos.x = light.shadowStrength;
18478
- this._shadowInfos.z = sunLightIndex;
18509
+ this._shadowInfos.z = 0; // @todo: sun light index always 0
18479
18510
  // prepare light and camera direction
18480
18511
  Matrix.rotationQuaternion(light.entity.transform.worldRotationQuaternion, lightWorld);
18481
18512
  lightSide.set(lightWorldE[0], lightWorldE[1], lightWorldE[2]);
@@ -20810,6 +20841,15 @@ var TextVerticalAlignment;
20810
20841
  _this._dirtyUpdateFlag = 0x7;
20811
20842
  /** @internal */ _this._updateFlagManager = new UpdateFlagManager();
20812
20843
  _this._texture = texture;
20844
+ _this._onRegionChange = _this._onRegionChange.bind(_assert_this_initialized(_this));
20845
+ _this._onPivotChange = _this._onPivotChange.bind(_assert_this_initialized(_this));
20846
+ _this._onBorderChange = _this._onBorderChange.bind(_assert_this_initialized(_this));
20847
+ // @ts-ignore
20848
+ _this._region._onValueChanged = _this._onRegionChange;
20849
+ // @ts-ignore
20850
+ _this._pivot._onValueChanged = _this._onPivotChange;
20851
+ // @ts-ignore
20852
+ _this._border._onValueChanged = _this._onBorderChange;
20813
20853
  region && _this._region.copyFrom(region);
20814
20854
  pivot && _this._pivot.copyFrom(pivot);
20815
20855
  border && _this._border.copyFrom(border);
@@ -20949,6 +20989,34 @@ var TextVerticalAlignment;
20949
20989
  }
20950
20990
  this._updateFlagManager.dispatch(type);
20951
20991
  };
20992
+ _proto._onRegionChange = function _onRegionChange() {
20993
+ var _this = this, region = _this._region;
20994
+ // @ts-ignore
20995
+ region._onValueChanged = null;
20996
+ var x = MathUtil$1.clamp(region.x, 0, 1);
20997
+ var y = MathUtil$1.clamp(region.y, 0, 1);
20998
+ region.set(x, y, MathUtil$1.clamp(region.width, 0, 1 - x), MathUtil$1.clamp(region.height, 0, 1 - y));
20999
+ this._dispatchSpriteChange(SpriteModifyFlags.region);
21000
+ if (this._customWidth === undefined || this._customHeight === undefined) {
21001
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
21002
+ }
21003
+ // @ts-ignore
21004
+ region._onValueChanged = this._onRegionChange;
21005
+ };
21006
+ _proto._onPivotChange = function _onPivotChange() {
21007
+ this._dispatchSpriteChange(SpriteModifyFlags.pivot);
21008
+ };
21009
+ _proto._onBorderChange = function _onBorderChange() {
21010
+ var _this = this, border = _this._border;
21011
+ // @ts-ignore
21012
+ border._onValueChanged = null;
21013
+ var x = MathUtil$1.clamp(border.x, 0, 1);
21014
+ var y = MathUtil$1.clamp(border.y, 0, 1);
21015
+ border.set(x, y, MathUtil$1.clamp(border.z, 0, 1 - x), MathUtil$1.clamp(border.w, 0, 1 - y));
21016
+ this._dispatchSpriteChange(SpriteModifyFlags.border);
21017
+ // @ts-ignore
21018
+ border._onValueChanged = this._onBorderChange;
21019
+ };
20952
21020
  _create_class(Sprite, [
20953
21021
  {
20954
21022
  key: "texture",
@@ -21068,14 +21136,7 @@ var TextVerticalAlignment;
21068
21136
  return this._region;
21069
21137
  },
21070
21138
  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
- }
21139
+ this._region !== value && this._region.copyFrom(value);
21079
21140
  }
21080
21141
  },
21081
21142
  {
@@ -21087,16 +21148,7 @@ var TextVerticalAlignment;
21087
21148
  return this._pivot;
21088
21149
  },
21089
21150
  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
- }
21151
+ this._pivot !== value && this._pivot.copyFrom(value);
21100
21152
  }
21101
21153
  },
21102
21154
  {
@@ -21111,11 +21163,7 @@ var TextVerticalAlignment;
21111
21163
  return this._border;
21112
21164
  },
21113
21165
  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);
21166
+ this._border !== value && this._border.copyFrom(value);
21119
21167
  }
21120
21168
  }
21121
21169
  ]);