@galacean/engine-core 1.0.0-beta.7 → 1.0.0-beta.9

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
@@ -7881,8 +7881,9 @@ exports.DynamicColliderConstraints = void 0;
7881
7881
  }
7882
7882
  var _proto = Light.prototype;
7883
7883
  /**
7884
+ * Light Color, include intensity.
7884
7885
  * @internal
7885
- */ _proto._getLightColor = function _getLightColor() {
7886
+ */ _proto._getLightIntensityColor = function _getLightIntensityColor() {
7886
7887
  this._lightColor.r = this.color.r * this.intensity;
7887
7888
  this._lightColor.g = this.color.g * this.intensity;
7888
7889
  this._lightColor.b = this.color.b * this.intensity;
@@ -7952,15 +7953,21 @@ __decorate([
7952
7953
  var cullingMaskStart = lightIndex * 2;
7953
7954
  var colorStart = lightIndex * 3;
7954
7955
  var directionStart = lightIndex * 3;
7955
- var lightColor = this._getLightColor();
7956
+ var lightColor = this._getLightIntensityColor();
7956
7957
  var direction = this.direction;
7957
7958
  var data = DirectLight._combinedData;
7958
7959
  var cullingMask = this.cullingMask;
7959
7960
  data.cullingMask[cullingMaskStart] = cullingMask & 65535;
7960
7961
  data.cullingMask[cullingMaskStart + 1] = cullingMask >>> 16 & 65535;
7961
- data.color[colorStart] = lightColor.r;
7962
- data.color[colorStart + 1] = lightColor.g;
7963
- data.color[colorStart + 2] = lightColor.b;
7962
+ if (this.engine.settings.colorSpace === exports.ColorSpace.Linear) {
7963
+ data.color[colorStart] = engineMath.Color.gammaToLinearSpace(lightColor.r);
7964
+ data.color[colorStart + 1] = engineMath.Color.gammaToLinearSpace(lightColor.g);
7965
+ data.color[colorStart + 2] = engineMath.Color.gammaToLinearSpace(lightColor.b);
7966
+ } else {
7967
+ data.color[colorStart] = lightColor.r;
7968
+ data.color[colorStart + 1] = lightColor.g;
7969
+ data.color[colorStart + 2] = lightColor.b;
7970
+ }
7964
7971
  data.direction[directionStart] = direction.x;
7965
7972
  data.direction[directionStart + 1] = direction.y;
7966
7973
  data.direction[directionStart + 2] = direction.z;
@@ -8049,15 +8056,21 @@ __decorate([
8049
8056
  var colorStart = lightIndex * 3;
8050
8057
  var positionStart = lightIndex * 3;
8051
8058
  var distanceStart = lightIndex;
8052
- var lightColor = this._getLightColor();
8059
+ var lightColor = this._getLightIntensityColor();
8053
8060
  var lightPosition = this.position;
8054
8061
  var data = PointLight._combinedData;
8055
8062
  var cullingMask = this.cullingMask;
8056
8063
  data.cullingMask[cullingMaskStart] = cullingMask & 65535;
8057
8064
  data.cullingMask[cullingMaskStart + 1] = cullingMask >>> 16 & 65535;
8058
- data.color[colorStart] = lightColor.r;
8059
- data.color[colorStart + 1] = lightColor.g;
8060
- data.color[colorStart + 2] = lightColor.b;
8065
+ if (this.engine.settings.colorSpace === exports.ColorSpace.Linear) {
8066
+ data.color[colorStart] = engineMath.Color.gammaToLinearSpace(lightColor.r);
8067
+ data.color[colorStart + 1] = engineMath.Color.gammaToLinearSpace(lightColor.g);
8068
+ data.color[colorStart + 2] = engineMath.Color.gammaToLinearSpace(lightColor.b);
8069
+ } else {
8070
+ data.color[colorStart] = lightColor.r;
8071
+ data.color[colorStart + 1] = lightColor.g;
8072
+ data.color[colorStart + 2] = lightColor.b;
8073
+ }
8061
8074
  data.position[positionStart] = lightPosition.x;
8062
8075
  data.position[positionStart + 1] = lightPosition.y;
8063
8076
  data.position[positionStart + 2] = lightPosition.z;
@@ -8150,16 +8163,22 @@ __decorate([
8150
8163
  var distanceStart = lightIndex;
8151
8164
  var penumbraCosStart = lightIndex;
8152
8165
  var angleCosStart = lightIndex;
8153
- var color = this._getLightColor();
8166
+ var lightColor = this._getLightIntensityColor();
8154
8167
  var position = this.position;
8155
8168
  var direction = this.direction;
8156
8169
  var data = SpotLight._combinedData;
8157
8170
  var cullingMask = this.cullingMask;
8158
8171
  data.cullingMask[cullingMaskStart] = cullingMask & 65535;
8159
8172
  data.cullingMask[cullingMaskStart + 1] = cullingMask >>> 16 & 65535;
8160
- data.color[colorStart] = color.r;
8161
- data.color[colorStart + 1] = color.g;
8162
- data.color[colorStart + 2] = color.b;
8173
+ if (this.engine.settings.colorSpace === exports.ColorSpace.Linear) {
8174
+ data.color[colorStart] = engineMath.Color.gammaToLinearSpace(lightColor.r);
8175
+ data.color[colorStart + 1] = engineMath.Color.gammaToLinearSpace(lightColor.g);
8176
+ data.color[colorStart + 2] = engineMath.Color.gammaToLinearSpace(lightColor.b);
8177
+ } else {
8178
+ data.color[colorStart] = lightColor.r;
8179
+ data.color[colorStart + 1] = lightColor.g;
8180
+ data.color[colorStart + 2] = lightColor.b;
8181
+ }
8163
8182
  data.position[positionStart] = position.x;
8164
8183
  data.position[positionStart + 1] = position.y;
8165
8184
  data.position[positionStart + 2] = position.z;
@@ -9517,11 +9536,11 @@ var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;"; // esli
9517
9536
 
9518
9537
  var common = "#define GLSLIFY 1\n#define PI 3.14159265359\n#define RECIPROCAL_PI 0.31830988618\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate( a ) clamp( a, 0.0, 1.0 )\nfloat pow2(float x){return x*x;}vec4 RGBMToLinear(vec4 value,float maxRange){return vec4(value.rgb*value.a*maxRange,1.0);}vec4 gammaToLinear(vec4 srgbIn){return vec4(pow(srgbIn.rgb,vec3(2.2)),srgbIn.a);}vec4 linearToGamma(vec4 linearIn){return vec4(pow(linearIn.rgb,vec3(1.0/2.2)),linearIn.a);}\n#ifdef GRAPHICS_API_WEBGL2\n#define INVERSE_MAT(mat) inverse(mat)\n#else\nmat2 inverseMat(mat2 m){return mat2(m[1][1],-m[0][1],-m[1][0],m[0][0])/(m[0][0]*m[1][1]-m[0][1]*m[1][0]);}mat3 inverseMat(mat3 m){float a00=m[0][0],a01=m[0][1],a02=m[0][2];float a10=m[1][0],a11=m[1][1],a12=m[1][2];float a20=m[2][0],a21=m[2][1],a22=m[2][2];float b01=a22*a11-a12*a21;float b11=-a22*a10+a12*a20;float b21=a21*a10-a11*a20;float det=a00*b01+a01*b11+a02*b21;return mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),b11,(a22*a00-a02*a20),(-a12*a00+a02*a10),b21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;}mat4 inverseMat(mat4 m){float a00=m[0][0],a01=m[0][1],a02=m[0][2],a03=m[0][3],a10=m[1][0],a11=m[1][1],a12=m[1][2],a13=m[1][3],a20=m[2][0],a21=m[2][1],a22=m[2][2],a23=m[2][3],a30=m[3][0],a31=m[3][1],a32=m[3][2],a33=m[3][3],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return mat4(a11*b11-a12*b10+a13*b09,a02*b10-a01*b11-a03*b09,a31*b05-a32*b04+a33*b03,a22*b04-a21*b05-a23*b03,a12*b08-a10*b11-a13*b07,a00*b11-a02*b08+a03*b07,a32*b02-a30*b05-a33*b01,a20*b05-a22*b02+a23*b01,a10*b10-a11*b08+a13*b06,a01*b08-a00*b10-a03*b06,a30*b04-a31*b02+a33*b00,a21*b02-a20*b04-a23*b00,a11*b07-a10*b09-a12*b06,a00*b09-a01*b07+a02*b06,a31*b01-a30*b03-a32*b00,a20*b03-a21*b01+a22*b00)/det;}\n#define INVERSE_MAT(mat) inverseMat(mat)\n#endif\n"; // eslint-disable-line
9519
9538
 
9520
- var common_vert = "#define GLSLIFY 1\nattribute vec3 POSITION;\n#ifdef RENDERER_HAS_UV\nattribute vec2 TEXCOORD_0;\n#endif\n#ifdef RENDERER_HAS_UV1\nattribute vec2 TEXCOORD_1;\n#endif\n#ifdef RENDERER_HAS_SKIN\nattribute vec4 JOINTS_0;attribute vec4 WEIGHTS_0;\n#ifdef RENDERER_USE_JOINT_TEXTURE\nuniform sampler2D renderer_JointSampler;uniform float renderer_JointCount;mat4 getJointMatrix(sampler2D smp,float index){float base=index/renderer_JointCount;float hf=0.5/renderer_JointCount;float v=base+hf;vec4 m0=texture2D(smp,vec2(0.125,v));vec4 m1=texture2D(smp,vec2(0.375,v));vec4 m2=texture2D(smp,vec2(0.625,v));vec4 m3=texture2D(smp,vec2(0.875,v));return mat4(m0,m1,m2,m3);}\n#else\nuniform mat4 renderer_JointMatrix[RENDERER_JOINTS_NUM];\n#endif\n#endif\n#ifdef RENDERER_HAS_VERTEXCOLOR\nattribute vec4 COLOR_0;\n#endif\n#include <transform_declare>\n#include <camera_declare>\nuniform vec4 material_TilingOffset;\n#ifndef MATERIAL_OMIT_NORMAL\n#ifdef RENDERER_HAS_NORMAL\nattribute vec3 NORMAL;\n#endif\n#ifdef RENDERER_HAS_TANGENT\nattribute vec4 TANGENT;\n#endif\n#endif\n"; // eslint-disable-line
9539
+ var common_vert = "#define GLSLIFY 1\nattribute vec3 POSITION;\n#ifdef RENDERER_HAS_UV\nattribute vec2 TEXCOORD_0;\n#endif\n#ifdef RENDERER_HAS_UV1\nattribute vec2 TEXCOORD_1;\n#endif\n#ifdef RENDERER_HAS_SKIN\nattribute vec4 JOINTS_0;attribute vec4 WEIGHTS_0;\n#ifdef RENDERER_USE_JOINT_TEXTURE\nuniform sampler2D renderer_JointSampler;uniform float renderer_JointCount;mat4 getJointMatrix(sampler2D smp,float index){float base=index/renderer_JointCount;float hf=0.5/renderer_JointCount;float v=base+hf;vec4 m0=texture2D(smp,vec2(0.125,v));vec4 m1=texture2D(smp,vec2(0.375,v));vec4 m2=texture2D(smp,vec2(0.625,v));vec4 m3=texture2D(smp,vec2(0.875,v));return mat4(m0,m1,m2,m3);}\n#else\nuniform mat4 renderer_JointMatrix[RENDERER_JOINTS_NUM];\n#endif\n#endif\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nattribute vec4 COLOR_0;\n#endif\n#include <transform_declare>\n#include <camera_declare>\nuniform vec4 material_TilingOffset;\n#ifndef MATERIAL_OMIT_NORMAL\n#ifdef RENDERER_HAS_NORMAL\nattribute vec3 NORMAL;\n#endif\n#ifdef RENDERER_HAS_TANGENT\nattribute vec4 TANGENT;\n#endif\n#endif\n"; // eslint-disable-line
9521
9540
 
9522
9541
  var transform_declare = "#define GLSLIFY 1\nuniform mat4 renderer_LocalMat;uniform mat4 renderer_ModelMat;uniform mat4 camera_ViewMat;uniform mat4 camera_ProjMat;uniform mat4 renderer_MVMat;uniform mat4 renderer_MVPMat;uniform mat4 renderer_NormalMat;"; // eslint-disable-line
9523
9542
 
9524
- var color_share = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_VERTEXCOLOR\nvarying vec4 v_color;\n#endif\n"; // eslint-disable-line
9543
+ var color_share = "#define GLSLIFY 1\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nvarying vec4 v_color;\n#endif\n"; // eslint-disable-line
9525
9544
 
9526
9545
  var FogFragmentDeclaration = "#define GLSLIFY 1\n#if SCENE_FOG_MODE != 0\nvarying vec3 v_positionVS;uniform vec4 scene_FogColor;uniform vec4 scene_FogParams;float ComputeFogIntensity(float fogDepth){\n#if SCENE_FOG_MODE == 1\nreturn clamp(fogDepth*scene_FogParams.x+scene_FogParams.y,0.0,1.0);\n#elif SCENE_FOG_MODE == 2\nreturn clamp(exp2(-fogDepth*scene_FogParams.z),0.0,1.0);\n#elif SCENE_FOG_MODE == 3\nfloat factor=fogDepth*scene_FogParams.w;return clamp(exp2(-factor*factor),0.0,1.0);\n#endif\n}\n#endif\n"; // eslint-disable-line
9527
9546
 
@@ -9541,7 +9560,7 @@ var blendShape_input = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_BLENDSHAPE\n#ifde
9541
9560
 
9542
9561
  var blendShape_vert = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_BLENDSHAPE\n#ifdef RENDERER_BLENDSHAPE_USE_TEXTURE\nint vertexOffset=gl_VertexID*renderer_BlendShapeTextureInfo.x;for(int i=0;i<RENDERER_BLENDSHAPE_COUNT;i++){int vertexElementOffset=vertexOffset;float weight=renderer_BlendShapeWeights[i];position.xyz+=getBlendShapeVertexElement(i,vertexElementOffset)*weight;\n#ifndef MATERIAL_OMIT_NORMAL\n#if defined( RENDERER_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_NORMAL )\nvertexElementOffset+=1;normal+=getBlendShapeVertexElement(i,vertexElementOffset)*weight;\n#endif\n#if defined( RENDERER_HAS_TANGENT ) && defined(RENDERER_BLENDSHAPE_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\nvertexElementOffset+=1;tangent.xyz+=getBlendShapeVertexElement(i,vertexElementOffset)*weight;\n#endif\n#endif\n}\n#else\nposition.xyz+=POSITION_BS0*renderer_BlendShapeWeights[0];position.xyz+=POSITION_BS1*renderer_BlendShapeWeights[1];\n#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\n#ifndef MATERIAL_OMIT_NORMAL\n#ifdef RENDERER_HAS_NORMAL\nnormal+=NORMAL_BS0*renderer_BlendShapeWeights[0];normal+=NORMAL_BS1*renderer_BlendShapeWeights[1];\n#endif\n#if defined( RENDERER_HAS_TANGENT ) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\ntangent.xyz+=TANGENT_BS0*renderer_BlendShapeWeights[0];tangent.xyz+=TANGENT_BS1*renderer_BlendShapeWeights[1];\n#endif\n#endif\n#else\n#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) || defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\n#ifndef MATERIAL_OMIT_NORMAL\nposition.xyz+=POSITION_BS2*renderer_BlendShapeWeights[2];position.xyz+=POSITION_BS3*renderer_BlendShapeWeights[3];\n#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_HAS_NORMAL )\nnormal+=NORMAL_BS0*renderer_BlendShapeWeights[0];normal+=NORMAL_BS1*renderer_BlendShapeWeights[1];normal+=NORMAL_BS2*renderer_BlendShapeWeights[2];normal+=NORMAL_BS3*renderer_BlendShapeWeights[3];\n#endif\n#if defined(RENDERER_BLENDSHAPE_HAS_TANGENT) && defined( RENDERER_HAS_TANGENT ) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\ntangent.xyz+=TANGENT_BS0*renderer_BlendShapeWeights[0];tangent.xyz+=TANGENT_BS1*renderer_BlendShapeWeights[1];tangent.xyz+=TANGENT_BS2*renderer_BlendShapeWeights[2];tangent.xyz+=TANGENT_BS3*renderer_BlendShapeWeights[3];\n#endif\n#endif\n#else\nposition.xyz+=POSITION_BS2*renderer_BlendShapeWeights[2];position.xyz+=POSITION_BS3*renderer_BlendShapeWeights[3];position.xyz+=POSITION_BS4*renderer_BlendShapeWeights[4];position.xyz+=POSITION_BS5*renderer_BlendShapeWeights[5];position.xyz+=POSITION_BS6*renderer_BlendShapeWeights[6];position.xyz+=POSITION_BS7*renderer_BlendShapeWeights[7];\n#endif\n#endif\n#endif\n#endif\n"; // eslint-disable-line
9543
9562
 
9544
- var color_vert = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_VERTEXCOLOR\nv_color=COLOR_0;\n#endif\n"; // eslint-disable-line
9563
+ var color_vert = "#define GLSLIFY 1\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nv_color=COLOR_0;\n#endif\n"; // eslint-disable-line
9545
9564
 
9546
9565
  var FogVertex = "#define GLSLIFY 1\n#if SCENE_FOG_MODE != 0\nvec4 positionVS=renderer_MVMat*position;v_positionVS=positionVS.xyz/positionVS.w;\n#endif\n"; // eslint-disable-line
9547
9566
 
@@ -9561,11 +9580,11 @@ var light_frag_define = "#define GLSLIFY 1\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nstr
9561
9580
 
9562
9581
  var mobile_material_frag = "#define GLSLIFY 1\nuniform vec4 material_EmissiveColor;uniform vec4 material_BaseColor;uniform vec4 material_SpecularColor;uniform float material_Shininess;uniform float material_NormalIntensity;uniform float material_AlphaCutoff;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nuniform sampler2D material_EmissiveTexture;\n#endif\n#ifdef MATERIAL_HAS_BASETEXTURE\nuniform sampler2D material_BaseTexture;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_TEXTURE\nuniform sampler2D material_SpecularTexture;\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nuniform sampler2D material_NormalTexture;\n#endif\n"; // eslint-disable-line
9563
9582
 
9564
- var begin_mobile_frag = "#define GLSLIFY 1\nvec4 ambient=vec4(0.0);vec4 emission=material_EmissiveColor;vec4 diffuse=material_BaseColor;vec4 specular=material_SpecularColor;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nvec4 emissiveTextureColor=texture2D(material_EmissiveTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nemissiveTextureColor=gammaToLinear(emissiveTextureColor);\n#endif\nemission*=emissiveTextureColor;\n#endif\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 diffuseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ndiffuseTextureColor=gammaToLinear(diffuseTextureColor);\n#endif\ndiffuse*=diffuseTextureColor;\n#endif\n#ifdef RENDERER_HAS_VERTEXCOLOR\ndiffuse*=v_color;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_TEXTURE\nvec4 specularTextureColor=texture2D(material_SpecularTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularTextureColor=gammaToLinear(specularTextureColor);\n#endif\nspecular*=specularTextureColor;\n#endif\nambient=vec4(scene_EnvMapLight.diffuse*scene_EnvMapLight.diffuseIntensity,1.0)*diffuse;"; // eslint-disable-line
9583
+ var begin_mobile_frag = "#define GLSLIFY 1\nvec4 ambient=vec4(0.0);vec4 emission=material_EmissiveColor;vec4 diffuse=material_BaseColor;vec4 specular=material_SpecularColor;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nvec4 emissiveTextureColor=texture2D(material_EmissiveTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nemissiveTextureColor=gammaToLinear(emissiveTextureColor);\n#endif\nemission*=emissiveTextureColor;\n#endif\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 diffuseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ndiffuseTextureColor=gammaToLinear(diffuseTextureColor);\n#endif\ndiffuse*=diffuseTextureColor;\n#endif\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\ndiffuse*=v_color;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_TEXTURE\nvec4 specularTextureColor=texture2D(material_SpecularTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularTextureColor=gammaToLinear(specularTextureColor);\n#endif\nspecular*=specularTextureColor;\n#endif\nambient=vec4(scene_EnvMapLight.diffuse*scene_EnvMapLight.diffuseIntensity,1.0)*diffuse;"; // eslint-disable-line
9565
9584
 
9566
9585
  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
9567
9586
 
9568
- var mobile_blinnphong_frag = "#define GLSLIFY 1\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nmat3 tbn=getTBN();vec3 N=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv);\n#else\nvec3 N=getNormal();\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
9587
+ 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
9569
9588
 
9570
9589
  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
9571
9590
 
@@ -9601,7 +9620,7 @@ var noise_simplex_4D = "#define GLSLIFY 1\nvec4 grad4(float j,vec4 ip){const vec
9601
9620
 
9602
9621
  var pbr_frag_define = "#define GLSLIFY 1\nuniform float material_AlphaCutoff;uniform vec4 material_BaseColor;uniform float material_Metal;uniform float material_Roughness;uniform float material_IOR;uniform vec3 material_PBRSpecularColor;uniform float material_Glossiness;uniform vec3 material_EmissiveColor;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nuniform float material_ClearCoat;uniform float material_ClearCoatRoughness;\n#endif\nuniform float material_NormalIntensity;uniform float material_OcclusionIntensity;uniform float material_OcclusionTextureCoord;\n#ifdef MATERIAL_HAS_BASETEXTURE\nuniform sampler2D material_BaseTexture;\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nuniform sampler2D material_NormalTexture;\n#endif\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nuniform sampler2D material_EmissiveTexture;\n#endif\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\nuniform sampler2D material_RoughnessMetallicTexture;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\nuniform sampler2D material_SpecularGlossinessTexture;\n#endif\n#ifdef MATERIAL_HAS_OCCLUSION_TEXTURE\nuniform sampler2D material_OcclusionTexture;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\nuniform sampler2D material_ClearCoatTexture;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\nuniform sampler2D material_ClearCoatRoughnessTexture;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\nuniform sampler2D material_ClearCoatNormalTexture;\n#endif\nstruct ReflectedLight{vec3 directDiffuse;vec3 directSpecular;vec3 indirectDiffuse;vec3 indirectSpecular;};struct Geometry{vec3 position;vec3 normal;vec3 viewDir;float dotNV;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nvec3 clearCoatNormal;float clearCoatDotNV;\n#endif\n};struct Material{vec3 diffuseColor;float roughness;vec3 specularColor;float opacity;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nfloat clearCoat;float clearCoatRoughness;\n#endif\n};"; // eslint-disable-line
9603
9622
 
9604
- var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\nfloat computeSpecularOcclusion(float ambientOcclusion,float roughness,float dotNV){return saturate(pow(dotNV+ambientOcclusion,exp2(-16.0*roughness-1.0))-1.0+ambientOcclusion);}float getAARoughnessFactor(vec3 normal){\n#ifdef HAS_DERIVATIVES\nvec3 dxy=max(abs(dFdx(normal)),abs(dFdy(normal)));return 0.04+max(max(dxy.x,dxy.y),dxy.z);\n#else\nreturn 0.04;\n#endif\n}void initGeometry(out Geometry geometry){geometry.position=v_pos;geometry.viewDir=normalize(camera_Position-v_pos);\n#if defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE)\nmat3 tbn=getTBN();\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\ngeometry.normal=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv);\n#else\ngeometry.normal=getNormal();\n#endif\ngeometry.dotNV=saturate(dot(geometry.normal,geometry.viewDir));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\n#ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\ngeometry.clearCoatNormal=getNormalByNormalTexture(tbn,material_ClearCoatNormalTexture,material_NormalIntensity,v_uv);\n#else\ngeometry.clearCoatNormal=getNormal();\n#endif\ngeometry.clearCoatDotNV=saturate(dot(geometry.clearCoatNormal,geometry.viewDir));\n#endif\n}void initMaterial(out Material material,const in Geometry geometry){vec4 baseColor=material_BaseColor;float metal=material_Metal;float roughness=material_Roughness;vec3 specularColor=material_PBRSpecularColor;float glossiness=material_Glossiness;float alphaCutoff=material_AlphaCutoff;float F0=pow2((material_IOR-1.0)/(material_IOR+1.0));\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 baseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nbaseTextureColor=gammaToLinear(baseTextureColor);\n#endif\nbaseColor*=baseTextureColor;\n#endif\n#ifdef RENDERER_HAS_VERTEXCOLOR\nbaseColor*=v_color;\n#endif\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(baseColor.a<alphaCutoff){discard;}\n#endif\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\nvec4 metalRoughMapColor=texture2D(material_RoughnessMetallicTexture,v_uv);roughness*=metalRoughMapColor.g;metal*=metalRoughMapColor.b;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\nvec4 specularGlossinessColor=texture2D(material_SpecularGlossinessTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularGlossinessColor=gammaToLinear(specularGlossinessColor);\n#endif\nspecularColor*=specularGlossinessColor.rgb;glossiness*=specularGlossinessColor.a;\n#endif\n#ifdef IS_METALLIC_WORKFLOW\nmaterial.diffuseColor=baseColor.rgb*(1.0-metal);material.specularColor=mix(vec3(F0),baseColor.rgb,metal);material.roughness=roughness;\n#else\nfloat specularStrength=max(max(specularColor.r,specularColor.g),specularColor.b);material.diffuseColor=baseColor.rgb*(1.0-specularStrength);material.specularColor=specularColor;material.roughness=1.0-glossiness;\n#endif\nmaterial.roughness=max(material.roughness,getAARoughnessFactor(geometry.normal));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nmaterial.clearCoat=material_ClearCoat;material.clearCoatRoughness=material_ClearCoatRoughness;\n#ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\nmaterial.clearCoat*=texture2D(material_ClearCoatTexture,v_uv).r;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\nmaterial.clearCoatRoughness*=texture2D(material_ClearCoatRoughnessTexture,v_uv).g;\n#endif\nmaterial.clearCoat=saturate(material.clearCoat);material.clearCoatRoughness=max(material.clearCoatRoughness,getAARoughnessFactor(geometry.clearCoatNormal));\n#endif\n#ifdef MATERIAL_IS_TRANSPARENT\nmaterial.opacity=baseColor.a;\n#else\nmaterial.opacity=1.0;\n#endif\n}\n#include <brdf>\n#include <direct_irradiance_frag_define>\n#include <ibl_frag_define>\n"; // eslint-disable-line
9623
+ var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\nfloat computeSpecularOcclusion(float ambientOcclusion,float roughness,float dotNV){return saturate(pow(dotNV+ambientOcclusion,exp2(-16.0*roughness-1.0))-1.0+ambientOcclusion);}float getAARoughnessFactor(vec3 normal){\n#ifdef HAS_DERIVATIVES\nvec3 dxy=max(abs(dFdx(normal)),abs(dFdy(normal)));return 0.04+max(max(dxy.x,dxy.y),dxy.z);\n#else\nreturn 0.04;\n#endif\n}void initGeometry(out Geometry geometry,bool isFrontFacing){geometry.position=v_pos;geometry.viewDir=normalize(camera_Position-v_pos);\n#if defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE)\nmat3 tbn=getTBN(isFrontFacing);\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\ngeometry.normal=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv,isFrontFacing);\n#else\ngeometry.normal=getNormal(isFrontFacing);\n#endif\ngeometry.dotNV=saturate(dot(geometry.normal,geometry.viewDir));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\n#ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\ngeometry.clearCoatNormal=getNormalByNormalTexture(tbn,material_ClearCoatNormalTexture,material_NormalIntensity,v_uv,isFrontFacing);\n#else\ngeometry.clearCoatNormal=getNormal(isFrontFacing);\n#endif\ngeometry.clearCoatDotNV=saturate(dot(geometry.clearCoatNormal,geometry.viewDir));\n#endif\n}void initMaterial(out Material material,const in Geometry geometry){vec4 baseColor=material_BaseColor;float metal=material_Metal;float roughness=material_Roughness;vec3 specularColor=material_PBRSpecularColor;float glossiness=material_Glossiness;float alphaCutoff=material_AlphaCutoff;float F0=pow2((material_IOR-1.0)/(material_IOR+1.0));\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 baseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nbaseTextureColor=gammaToLinear(baseTextureColor);\n#endif\nbaseColor*=baseTextureColor;\n#endif\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nbaseColor*=v_color;\n#endif\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(baseColor.a<alphaCutoff){discard;}\n#endif\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\nvec4 metalRoughMapColor=texture2D(material_RoughnessMetallicTexture,v_uv);roughness*=metalRoughMapColor.g;metal*=metalRoughMapColor.b;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\nvec4 specularGlossinessColor=texture2D(material_SpecularGlossinessTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularGlossinessColor=gammaToLinear(specularGlossinessColor);\n#endif\nspecularColor*=specularGlossinessColor.rgb;glossiness*=specularGlossinessColor.a;\n#endif\n#ifdef IS_METALLIC_WORKFLOW\nmaterial.diffuseColor=baseColor.rgb*(1.0-metal);material.specularColor=mix(vec3(F0),baseColor.rgb,metal);material.roughness=roughness;\n#else\nfloat specularStrength=max(max(specularColor.r,specularColor.g),specularColor.b);material.diffuseColor=baseColor.rgb*(1.0-specularStrength);material.specularColor=specularColor;material.roughness=1.0-glossiness;\n#endif\nmaterial.roughness=max(material.roughness,getAARoughnessFactor(geometry.normal));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nmaterial.clearCoat=material_ClearCoat;material.clearCoatRoughness=material_ClearCoatRoughness;\n#ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\nmaterial.clearCoat*=texture2D(material_ClearCoatTexture,v_uv).r;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\nmaterial.clearCoatRoughness*=texture2D(material_ClearCoatRoughnessTexture,v_uv).g;\n#endif\nmaterial.clearCoat=saturate(material.clearCoat);material.clearCoatRoughness=max(material.clearCoatRoughness,getAARoughnessFactor(geometry.clearCoatNormal));\n#endif\n#ifdef MATERIAL_IS_TRANSPARENT\nmaterial.opacity=baseColor.a;\n#else\nmaterial.opacity=1.0;\n#endif\n}\n#include <brdf>\n#include <direct_irradiance_frag_define>\n#include <ibl_frag_define>\n"; // eslint-disable-line
9605
9624
 
9606
9625
  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
9607
9626
 
@@ -9609,7 +9628,7 @@ var direct_irradiance_frag_define = "#define GLSLIFY 1\n#include <ShadowFragment
9609
9628
 
9610
9629
  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
9611
9630
 
9612
- var pbr_frag = "#define GLSLIFY 1\nGeometry geometry;Material material;ReflectedLight reflectedLight=ReflectedLight(vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0));initGeometry(geometry);initMaterial(material,geometry);addTotalDirectRadiance(geometry,material,reflectedLight);\n#ifdef SCENE_USE_SH\nvec3 irradiance=getLightProbeIrradiance(scene_EnvSH,geometry.normal);\n#ifdef ENGINE_IS_COLORSPACE_GAMMA\nirradiance=linearToGamma(vec4(irradiance,1.0)).rgb;\n#endif\nirradiance*=scene_EnvMapLight.diffuseIntensity;\n#else\nvec3 irradiance=scene_EnvMapLight.diffuse*scene_EnvMapLight.diffuseIntensity;irradiance*=PI;\n#endif\nreflectedLight.indirectDiffuse+=irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);vec3 radiance=getLightProbeRadiance(geometry.viewDir,geometry.normal,material.roughness,int(scene_EnvMapLight.mipMapLevel),scene_EnvMapLight.specularIntensity);float radianceAttenuation=1.0;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nvec3 clearCoatRadiance=getLightProbeRadiance(geometry.viewDir,geometry.clearCoatNormal,material.clearCoatRoughness,int(scene_EnvMapLight.mipMapLevel),scene_EnvMapLight.specularIntensity);reflectedLight.indirectSpecular+=clearCoatRadiance*material.clearCoat*envBRDFApprox(vec3(0.04),material.clearCoatRoughness,geometry.clearCoatDotNV);radianceAttenuation-=material.clearCoat*F_Schlick(geometry.clearCoatDotNV);\n#endif\nreflectedLight.indirectSpecular+=radianceAttenuation*radiance*envBRDFApprox(material.specularColor,material.roughness,geometry.dotNV);\n#ifdef MATERIAL_HAS_OCCLUSION_TEXTURE\nvec2 aoUV=v_uv;\n#ifdef RENDERER_HAS_UV1\nif(material_OcclusionTextureCoord==1.0){aoUV=v_uv1;}\n#endif\nfloat ambientOcclusion=(texture2D(material_OcclusionTexture,aoUV).r-1.0)*material_OcclusionIntensity+1.0;reflectedLight.indirectDiffuse*=ambientOcclusion;\n#ifdef SCENE_USE_SPECULAR_ENV\nreflectedLight.indirectSpecular*=computeSpecularOcclusion(ambientOcclusion,material.roughness,geometry.dotNV);\n#endif\n#endif\nvec3 emissiveRadiance=material_EmissiveColor;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nvec4 emissiveColor=texture2D(material_EmissiveTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nemissiveColor=gammaToLinear(emissiveColor);\n#endif\nemissiveRadiance*=emissiveColor.rgb;\n#endif\nvec3 totalRadiance=reflectedLight.directDiffuse+reflectedLight.indirectDiffuse+reflectedLight.directSpecular+reflectedLight.indirectSpecular+emissiveRadiance;vec4 targetColor=vec4(totalRadiance,material.opacity);gl_FragColor=targetColor;"; // eslint-disable-line
9631
+ var pbr_frag = "#define GLSLIFY 1\nGeometry geometry;Material material;ReflectedLight reflectedLight=ReflectedLight(vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0));initGeometry(geometry,gl_FrontFacing);initMaterial(material,geometry);addTotalDirectRadiance(geometry,material,reflectedLight);\n#ifdef SCENE_USE_SH\nvec3 irradiance=getLightProbeIrradiance(scene_EnvSH,geometry.normal);\n#ifdef ENGINE_IS_COLORSPACE_GAMMA\nirradiance=linearToGamma(vec4(irradiance,1.0)).rgb;\n#endif\nirradiance*=scene_EnvMapLight.diffuseIntensity;\n#else\nvec3 irradiance=scene_EnvMapLight.diffuse*scene_EnvMapLight.diffuseIntensity;irradiance*=PI;\n#endif\nreflectedLight.indirectDiffuse+=irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);vec3 radiance=getLightProbeRadiance(geometry.viewDir,geometry.normal,material.roughness,int(scene_EnvMapLight.mipMapLevel),scene_EnvMapLight.specularIntensity);float radianceAttenuation=1.0;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nvec3 clearCoatRadiance=getLightProbeRadiance(geometry.viewDir,geometry.clearCoatNormal,material.clearCoatRoughness,int(scene_EnvMapLight.mipMapLevel),scene_EnvMapLight.specularIntensity);reflectedLight.indirectSpecular+=clearCoatRadiance*material.clearCoat*envBRDFApprox(vec3(0.04),material.clearCoatRoughness,geometry.clearCoatDotNV);radianceAttenuation-=material.clearCoat*F_Schlick(geometry.clearCoatDotNV);\n#endif\nreflectedLight.indirectSpecular+=radianceAttenuation*radiance*envBRDFApprox(material.specularColor,material.roughness,geometry.dotNV);\n#ifdef MATERIAL_HAS_OCCLUSION_TEXTURE\nvec2 aoUV=v_uv;\n#ifdef RENDERER_HAS_UV1\nif(material_OcclusionTextureCoord==1.0){aoUV=v_uv1;}\n#endif\nfloat ambientOcclusion=(texture2D(material_OcclusionTexture,aoUV).r-1.0)*material_OcclusionIntensity+1.0;reflectedLight.indirectDiffuse*=ambientOcclusion;\n#ifdef SCENE_USE_SPECULAR_ENV\nreflectedLight.indirectSpecular*=computeSpecularOcclusion(ambientOcclusion,material.roughness,geometry.dotNV);\n#endif\n#endif\nvec3 emissiveRadiance=material_EmissiveColor;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nvec4 emissiveColor=texture2D(material_EmissiveTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nemissiveColor=gammaToLinear(emissiveColor);\n#endif\nemissiveRadiance*=emissiveColor.rgb;\n#endif\nvec3 totalRadiance=reflectedLight.directDiffuse+reflectedLight.indirectDiffuse+reflectedLight.directSpecular+reflectedLight.indirectSpecular+emissiveRadiance;vec4 targetColor=vec4(totalRadiance,material.opacity);gl_FragColor=targetColor;"; // eslint-disable-line
9613
9632
 
9614
9633
  var PBRShaderLib = {
9615
9634
  pbr_frag_define: pbr_frag_define,
@@ -9638,7 +9657,7 @@ var ShadowLib = {
9638
9657
  ShadowVertex: ShadowVertex
9639
9658
  };
9640
9659
 
9641
- var normal_get = "#define GLSLIFY 1\nvec3 getNormal(){\n#ifdef RENDERER_HAS_NORMAL\nvec3 normal=normalize(v_normal);\n#elif defined(HAS_DERIVATIVES)\nvec3 pos_dx=dFdx(v_pos);vec3 pos_dy=dFdy(v_pos);vec3 normal=normalize(cross(pos_dx,pos_dy));\n#else\nvec3 normal=vec3(0,0,1);\n#endif\nnormal*=float(gl_FrontFacing)*2.0-1.0;return normal;}vec3 getNormalByNormalTexture(mat3 tbn,sampler2D normalTexture,float normalIntensity,vec2 uv){vec3 normal=texture2D(normalTexture,uv).rgb;normal=normalize(tbn*((2.0*normal-1.0)*vec3(normalIntensity,normalIntensity,1.0)));normal*=float(gl_FrontFacing)*2.0-1.0;return normal;}mat3 getTBN(){\n#if defined(RENDERER_HAS_NORMAL) && defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\nmat3 tbn=v_TBN;\n#else\nvec3 normal=getNormal();vec3 position=v_pos;vec2 uv=gl_FrontFacing? v_uv:-v_uv;\n#ifdef HAS_DERIVATIVES\nvec3 dp1=dFdx(position);vec3 dp2=dFdy(position);vec2 duv1=dFdx(uv);vec2 duv2=dFdy(uv);vec3 dp2perp=cross(dp2,normal);vec3 dp1perp=cross(normal,dp1);vec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;vec3 binormal=dp2perp*duv1.y+dp1perp*duv2.y;float invmax=inversesqrt(max(dot(tangent,tangent),dot(binormal,binormal)));mat3 tbn=mat3(tangent*invmax,binormal*invmax,normal);\n#else\nmat3 tbn=mat3(vec3(0.0),vec3(0.0),normal);\n#endif\n#endif\nreturn tbn;}"; // eslint-disable-line
9660
+ var normal_get = "#define GLSLIFY 1\nvec3 getNormal(bool isFrontFacing){\n#ifdef RENDERER_HAS_NORMAL\nvec3 normal=normalize(v_normal);\n#elif defined(HAS_DERIVATIVES)\nvec3 pos_dx=dFdx(v_pos);vec3 pos_dy=dFdy(v_pos);vec3 normal=normalize(cross(pos_dx,pos_dy));\n#else\nvec3 normal=vec3(0,0,1);\n#endif\nnormal*=float(isFrontFacing)*2.0-1.0;return normal;}vec3 getNormalByNormalTexture(mat3 tbn,sampler2D normalTexture,float normalIntensity,vec2 uv,bool isFrontFacing){vec3 normal=texture2D(normalTexture,uv).rgb;normal=normalize(tbn*((2.0*normal-1.0)*vec3(normalIntensity,normalIntensity,1.0)));normal*=float(isFrontFacing)*2.0-1.0;return normal;}mat3 getTBN(bool isFrontFacing){\n#if defined(RENDERER_HAS_NORMAL) && defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\nmat3 tbn=v_TBN;\n#else\nvec3 normal=getNormal(isFrontFacing);vec3 position=v_pos;vec2 uv=isFrontFacing? v_uv:-v_uv;\n#ifdef HAS_DERIVATIVES\nvec3 dp1=dFdx(position);vec3 dp2=dFdy(position);vec2 duv1=dFdx(uv);vec2 duv2=dFdy(uv);vec3 dp2perp=cross(dp2,normal);vec3 dp1perp=cross(normal,dp1);vec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;vec3 binormal=dp2perp*duv1.y+dp1perp*duv2.y;float invmax=inversesqrt(max(dot(tangent,tangent),dot(binormal,binormal)));mat3 tbn=mat3(tangent*invmax,binormal*invmax,normal);\n#else\nmat3 tbn=mat3(vec3(0.0),vec3(0.0),normal);\n#endif\n#endif\nreturn tbn;}"; // eslint-disable-line
9642
9661
 
9643
9662
  var ShaderLib = _extends({
9644
9663
  common: common,
@@ -11176,8 +11195,10 @@ SimpleSpriteAssembler = __decorate([
11176
11195
  _this = Renderer.call(this, entity) || this;
11177
11196
  /** The mask layers the sprite mask influence to. */ _this.influenceLayers = exports.SpriteMaskLayer.Everything;
11178
11197
  _this._sprite = null;
11179
- _this._width = undefined;
11180
- _this._height = undefined;
11198
+ _this._automaticWidth = 0;
11199
+ _this._automaticHeight = 0;
11200
+ _this._customWidth = undefined;
11201
+ _this._customHeight = undefined;
11181
11202
  _this._flipX = false;
11182
11203
  _this._flipY = false;
11183
11204
  _this._alphaCutoff = 0.5;
@@ -11197,12 +11218,11 @@ SimpleSpriteAssembler = __decorate([
11197
11218
  /**
11198
11219
  * @internal
11199
11220
  */ _proto._updateBounds = function _updateBounds(worldBounds) {
11200
- var _this_sprite;
11201
- if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
11221
+ if (this.sprite) {
11222
+ SimpleSpriteAssembler.updatePositions(this);
11223
+ } else {
11202
11224
  worldBounds.min.set(0, 0, 0);
11203
11225
  worldBounds.max.set(0, 0, 0);
11204
- } else {
11205
- SimpleSpriteAssembler.updatePositions(this);
11206
11226
  }
11207
11227
  };
11208
11228
  /**
@@ -11213,12 +11233,12 @@ SimpleSpriteAssembler = __decorate([
11213
11233
  if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
11214
11234
  return;
11215
11235
  }
11216
- // Update position.
11236
+ // Update position
11217
11237
  if (this._dirtyUpdateFlag & RendererUpdateFlags.WorldVolume) {
11218
11238
  SimpleSpriteAssembler.updatePositions(this);
11219
11239
  this._dirtyUpdateFlag &= ~RendererUpdateFlags.WorldVolume;
11220
11240
  }
11221
- // Update uv.
11241
+ // Update uv
11222
11242
  if (this._dirtyUpdateFlag & 0x2) {
11223
11243
  SimpleSpriteAssembler.updateUVs(this);
11224
11244
  this._dirtyUpdateFlag &= ~0x2;
@@ -11241,11 +11261,27 @@ SimpleSpriteAssembler = __decorate([
11241
11261
  this._sprite = null;
11242
11262
  this._verticesData = null;
11243
11263
  };
11264
+ _proto._calDefaultSize = function _calDefaultSize() {
11265
+ var sprite = this._sprite;
11266
+ if (sprite) {
11267
+ this._automaticWidth = sprite.width;
11268
+ this._automaticHeight = sprite.height;
11269
+ } else {
11270
+ this._automaticWidth = this._automaticHeight = 0;
11271
+ }
11272
+ this._dirtyUpdateFlag &= ~0x4;
11273
+ };
11244
11274
  _proto._onSpriteChange = function _onSpriteChange(type) {
11245
11275
  switch(type){
11246
11276
  case SpriteModifyFlags.texture:
11247
11277
  this.shaderData.setTexture(SpriteMask._textureProperty, this.sprite.texture);
11248
11278
  break;
11279
+ case SpriteModifyFlags.size:
11280
+ this._dirtyUpdateFlag |= 0x4;
11281
+ if (this._customWidth === undefined || this._customHeight === undefined) {
11282
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
11283
+ }
11284
+ break;
11249
11285
  case SpriteModifyFlags.region:
11250
11286
  case SpriteModifyFlags.atlasRegionOffset:
11251
11287
  this._dirtyUpdateFlag |= 0x3;
@@ -11253,22 +11289,31 @@ SimpleSpriteAssembler = __decorate([
11253
11289
  case SpriteModifyFlags.atlasRegion:
11254
11290
  this._dirtyUpdateFlag |= 0x2;
11255
11291
  break;
11292
+ case SpriteModifyFlags.pivot:
11293
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
11294
+ break;
11256
11295
  }
11257
11296
  };
11258
11297
  _create_class(SpriteMask, [
11259
11298
  {
11260
11299
  key: "width",
11261
11300
  get: /**
11262
- * Render width.
11301
+ * Render width (in world coordinates).
11302
+ *
11303
+ * @remarks
11304
+ * If width is set, return the set value,
11305
+ * otherwise return `SpriteMask.sprite.width`.
11263
11306
  */ function get() {
11264
- if (this._width === undefined && this._sprite) {
11265
- this.width = this._sprite.width;
11307
+ if (this._customWidth !== undefined) {
11308
+ return this._customWidth;
11309
+ } else {
11310
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
11311
+ return this._automaticWidth;
11266
11312
  }
11267
- return this._width;
11268
11313
  },
11269
11314
  set: function set(value) {
11270
- if (this._width !== value) {
11271
- this._width = value;
11315
+ if (this._customWidth !== value) {
11316
+ this._customWidth = value;
11272
11317
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
11273
11318
  }
11274
11319
  }
@@ -11276,16 +11321,22 @@ SimpleSpriteAssembler = __decorate([
11276
11321
  {
11277
11322
  key: "height",
11278
11323
  get: /**
11279
- * Render height.
11324
+ * Render height (in world coordinates).
11325
+ *
11326
+ * @remarks
11327
+ * If height is set, return the set value,
11328
+ * otherwise return `SpriteMask.sprite.height`.
11280
11329
  */ function get() {
11281
- if (this._height === undefined && this._sprite) {
11282
- this.height = this._sprite.height;
11330
+ if (this._customHeight !== undefined) {
11331
+ return this._customHeight;
11332
+ } else {
11333
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
11334
+ return this._automaticHeight;
11283
11335
  }
11284
- return this._height;
11285
11336
  },
11286
11337
  set: function set(value) {
11287
- if (this._height !== value) {
11288
- this._height = value;
11338
+ if (this._customHeight !== value) {
11339
+ this._customHeight = value;
11289
11340
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
11290
11341
  }
11291
11342
  }
@@ -11329,9 +11380,9 @@ SimpleSpriteAssembler = __decorate([
11329
11380
  var lastSprite = this._sprite;
11330
11381
  if (lastSprite !== value) {
11331
11382
  lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
11383
+ this._dirtyUpdateFlag |= 0x7;
11332
11384
  if (value) {
11333
11385
  value._updateFlagManager.addListener(this._onSpriteChange);
11334
- this._dirtyUpdateFlag |= 0x3;
11335
11386
  this.shaderData.setTexture(SpriteMask._textureProperty, value.texture);
11336
11387
  } else {
11337
11388
  this.shaderData.setTexture(SpriteMask._textureProperty, null);
@@ -11371,10 +11422,16 @@ __decorate([
11371
11422
  ], SpriteMask.prototype, "_sprite", void 0);
11372
11423
  __decorate([
11373
11424
  ignoreClone
11374
- ], SpriteMask.prototype, "_width", void 0);
11425
+ ], SpriteMask.prototype, "_automaticWidth", void 0);
11375
11426
  __decorate([
11376
11427
  ignoreClone
11377
- ], SpriteMask.prototype, "_height", void 0);
11428
+ ], SpriteMask.prototype, "_automaticHeight", void 0);
11429
+ __decorate([
11430
+ assignmentClone
11431
+ ], SpriteMask.prototype, "_customWidth", void 0);
11432
+ __decorate([
11433
+ assignmentClone
11434
+ ], SpriteMask.prototype, "_customHeight", void 0);
11378
11435
  __decorate([
11379
11436
  assignmentClone
11380
11437
  ], SpriteMask.prototype, "_flipX", void 0);
@@ -11392,7 +11449,9 @@ var /**
11392
11449
  */ SpriteMaskUpdateFlags;
11393
11450
  (function(SpriteMaskUpdateFlags) {
11394
11451
  SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** UV. */ "UV"] = 0x2] = "UV";
11395
- SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** All. */ "All"] = 0x3] = "All";
11452
+ SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** WorldVolume and UV . */ "RenderData"] = 0x3] = "RenderData";
11453
+ SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** Automatic Size. */ "AutomaticSize"] = 0x4] = "AutomaticSize";
11454
+ SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** All. */ "All"] = 0x7] = "All";
11396
11455
  })(SpriteMaskUpdateFlags || (SpriteMaskUpdateFlags = {}));
11397
11456
 
11398
11457
  /**
@@ -12199,6 +12258,7 @@ var MeshModifyFlags;
12199
12258
  var subDataDirtyFlags = this._subDataDirtyFlags;
12200
12259
  var blendShapeFloatStride = this._vertexElementCount * 3;
12201
12260
  var blendShapeByteStride = blendShapeFloatStride * 4;
12261
+ var bufferOffset = this._bufferBindingOffset;
12202
12262
  // @todo: should fix bug when dataChangedFlag is true
12203
12263
  for(var i = 0, n = blendShapes.length; i < n; i++){
12204
12264
  var dataChangedFlag = subDataDirtyFlags[i];
@@ -12216,7 +12276,7 @@ var MeshModifyFlags;
12216
12276
  var offset = indexInBuffer * blendShapeFloatStride;
12217
12277
  var storeInfo = storeInfos[i];
12218
12278
  storeInfo || (storeInfos[i] = storeInfo = new engineMath.Vector2());
12219
- storeInfo.set(bufferIndex + 1, indexInBuffer * blendShapeByteStride); // BlendShape buffer is start from 1
12279
+ storeInfo.set(bufferOffset + bufferIndex, indexInBuffer * blendShapeByteStride); // BufferOffset is mesh vertexBuffer offset
12220
12280
  var deltaPositions = endFrame.deltaPositions;
12221
12281
  for(var j = 0; j < vertexCount; j++){
12222
12282
  var start = offset + bufferFloatStride * j;
@@ -13493,6 +13553,7 @@ var VertexChangedFlags;
13493
13553
  function MeshRenderer(entity) {
13494
13554
  var _this;
13495
13555
  _this = Renderer.call(this, entity) || this;
13556
+ _this._enableVertexColor = false;
13496
13557
  _this._onMeshChanged = _this._onMeshChanged.bind(_assert_this_initialized(_this));
13497
13558
  return _this;
13498
13559
  }
@@ -13537,7 +13598,7 @@ var VertexChangedFlags;
13537
13598
  shaderData.disableMacro(MeshRenderer._uv1Macro);
13538
13599
  shaderData.disableMacro(MeshRenderer._normalMacro);
13539
13600
  shaderData.disableMacro(MeshRenderer._tangentMacro);
13540
- shaderData.disableMacro(MeshRenderer._vertexColorMacro);
13601
+ shaderData.disableMacro(MeshRenderer._enableVertexColorMacro);
13541
13602
  for(var i = 0, n = vertexElements.length; i < n; i++){
13542
13603
  switch(vertexElements[i].semantic){
13543
13604
  case "TEXCOORD_0":
@@ -13553,7 +13614,7 @@ var VertexChangedFlags;
13553
13614
  shaderData.enableMacro(MeshRenderer._tangentMacro);
13554
13615
  break;
13555
13616
  case "COLOR_0":
13556
- shaderData.enableMacro(MeshRenderer._vertexColorMacro);
13617
+ this._enableVertexColor && shaderData.enableMacro(MeshRenderer._enableVertexColorMacro);
13557
13618
  break;
13558
13619
  }
13559
13620
  }
@@ -13604,6 +13665,20 @@ var VertexChangedFlags;
13604
13665
  this._setMesh(value);
13605
13666
  }
13606
13667
  }
13668
+ },
13669
+ {
13670
+ key: "enableVertexColor",
13671
+ get: /**
13672
+ * Whether enable vertex color.
13673
+ */ function get() {
13674
+ return this._enableVertexColor;
13675
+ },
13676
+ set: function set(value) {
13677
+ if (value !== this._enableVertexColor) {
13678
+ this._dirtyUpdateFlag |= 0x2;
13679
+ this._enableVertexColor = value;
13680
+ }
13681
+ }
13607
13682
  }
13608
13683
  ]);
13609
13684
  return MeshRenderer;
@@ -13621,7 +13696,7 @@ var VertexChangedFlags;
13621
13696
  MeshRenderer._tangentMacro = ShaderMacro.getByName("RENDERER_HAS_TANGENT");
13622
13697
  })();
13623
13698
  (function() {
13624
- MeshRenderer._vertexColorMacro = ShaderMacro.getByName("RENDERER_HAS_VERTEXCOLOR");
13699
+ MeshRenderer._enableVertexColorMacro = ShaderMacro.getByName("RENDERER_ENABLE_VERTEXCOLOR");
13625
13700
  })();
13626
13701
  __decorate([
13627
13702
  ignoreClone
@@ -16122,7 +16197,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16122
16197
  var sunLightIndex = lightManager._getSunLightIndex();
16123
16198
  if (sunLightIndex !== -1) {
16124
16199
  var sunlight = lightManager._directLights.get(sunLightIndex);
16125
- shaderData.setColor(Scene._sunlightColorProperty, sunlight.color);
16200
+ shaderData.setColor(Scene._sunlightColorProperty, sunlight._getLightIntensityColor());
16126
16201
  shaderData.setVector3(Scene._sunlightDirectionProperty, sunlight.direction);
16127
16202
  this._sunLight = sunlight;
16128
16203
  }
@@ -20397,8 +20472,10 @@ exports.TextVerticalAlignment = void 0;
20397
20472
  if (name === void 0) name = null;
20398
20473
  var _this;
20399
20474
  _this = ReferResource.call(this, engine) || this;
20400
- _this._width = undefined;
20401
- _this._height = undefined;
20475
+ _this._automaticWidth = 0;
20476
+ _this._automaticHeight = 0;
20477
+ _this._customWidth = undefined;
20478
+ _this._customHeight = undefined;
20402
20479
  _this._positions = [
20403
20480
  new engineMath.Vector2(),
20404
20481
  new engineMath.Vector2(),
@@ -20419,7 +20496,7 @@ exports.TextVerticalAlignment = void 0;
20419
20496
  _this._region = new engineMath.Rect(0, 0, 1, 1);
20420
20497
  _this._pivot = new engineMath.Vector2(0.5, 0.5);
20421
20498
  _this._border = new engineMath.Vector4(0, 0, 0, 0);
20422
- _this._dirtyUpdateFlag = 0x3;
20499
+ _this._dirtyUpdateFlag = 0x7;
20423
20500
  /** @internal */ _this._updateFlagManager = new UpdateFlagManager();
20424
20501
  _this._texture = texture;
20425
20502
  region && _this._region.copyFrom(region);
@@ -20467,9 +20544,12 @@ exports.TextVerticalAlignment = void 0;
20467
20544
  if (this._texture) {
20468
20545
  var _this = this, _texture = _this._texture, _atlasRegion = _this._atlasRegion, _atlasRegionOffset = _this._atlasRegionOffset, _region = _this._region;
20469
20546
  var pixelsPerUnitReciprocal = 1.0 / Engine._pixelsPerUnit;
20470
- this._width = _texture.width * _atlasRegion.width / (1 - _atlasRegionOffset.x - _atlasRegionOffset.z) * _region.width * pixelsPerUnitReciprocal;
20471
- this._height = _texture.height * _atlasRegion.height / (1 - _atlasRegionOffset.y - _atlasRegionOffset.w) * _region.height * pixelsPerUnitReciprocal;
20547
+ this._automaticWidth = _texture.width * _atlasRegion.width / (1 - _atlasRegionOffset.x - _atlasRegionOffset.z) * _region.width * pixelsPerUnitReciprocal;
20548
+ this._automaticHeight = _texture.height * _atlasRegion.height / (1 - _atlasRegionOffset.y - _atlasRegionOffset.w) * _region.height * pixelsPerUnitReciprocal;
20549
+ } else {
20550
+ this._automaticWidth = this._automaticHeight = 0;
20472
20551
  }
20552
+ this._dirtyUpdateFlag &= ~0x4;
20473
20553
  };
20474
20554
  _proto._updatePositions = function _updatePositions() {
20475
20555
  var blank = this._atlasRegionOffset;
@@ -20523,11 +20603,16 @@ exports.TextVerticalAlignment = void 0;
20523
20603
  };
20524
20604
  _proto._dispatchSpriteChange = function _dispatchSpriteChange(type) {
20525
20605
  switch(type){
20606
+ case SpriteModifyFlags.texture:
20607
+ this._dirtyUpdateFlag |= 0x4;
20608
+ break;
20526
20609
  case SpriteModifyFlags.atlasRegionOffset:
20527
20610
  case SpriteModifyFlags.region:
20528
- this._dirtyUpdateFlag |= 0x3;
20611
+ this._dirtyUpdateFlag |= 0x7;
20529
20612
  break;
20530
20613
  case SpriteModifyFlags.atlasRegion:
20614
+ this._dirtyUpdateFlag |= 0x4 | 0x2;
20615
+ break;
20531
20616
  case SpriteModifyFlags.border:
20532
20617
  this._dirtyUpdateFlag |= 0x2;
20533
20618
  break;
@@ -20546,7 +20631,9 @@ exports.TextVerticalAlignment = void 0;
20546
20631
  if (this._texture !== value) {
20547
20632
  this._texture = value;
20548
20633
  this._dispatchSpriteChange(SpriteModifyFlags.texture);
20549
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
20634
+ if (this._customWidth === undefined || this._customHeight === undefined) {
20635
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
20636
+ }
20550
20637
  }
20551
20638
  }
20552
20639
  },
@@ -20554,13 +20641,21 @@ exports.TextVerticalAlignment = void 0;
20554
20641
  key: "width",
20555
20642
  get: /**
20556
20643
  * The width of the sprite (in world coordinates).
20644
+ *
20645
+ * @remarks
20646
+ * If width is set, return the set value,
20647
+ * otherwise return the width calculated according to `Texture.width`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
20557
20648
  */ function get() {
20558
- this._width === undefined && this._calDefaultSize();
20559
- return this._width;
20649
+ if (this._customWidth !== undefined) {
20650
+ return this._customWidth;
20651
+ } else {
20652
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
20653
+ return this._automaticWidth;
20654
+ }
20560
20655
  },
20561
20656
  set: function set(value) {
20562
- if (this._width !== value) {
20563
- this._width = value;
20657
+ if (this._customWidth !== value) {
20658
+ this._customWidth = value;
20564
20659
  this._dispatchSpriteChange(SpriteModifyFlags.size);
20565
20660
  }
20566
20661
  }
@@ -20569,13 +20664,21 @@ exports.TextVerticalAlignment = void 0;
20569
20664
  key: "height",
20570
20665
  get: /**
20571
20666
  * The height of the sprite (in world coordinates).
20667
+ *
20668
+ * @remarks
20669
+ * If height is set, return the set value,
20670
+ * otherwise return the height calculated according to `Texture.height`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
20572
20671
  */ function get() {
20573
- this._height === undefined && this._calDefaultSize();
20574
- return this._height;
20672
+ if (this._customHeight !== undefined) {
20673
+ return this._customHeight;
20674
+ } else {
20675
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
20676
+ return this._automaticHeight;
20677
+ }
20575
20678
  },
20576
20679
  set: function set(value) {
20577
- if (this._height !== value) {
20578
- this._height = value;
20680
+ if (this._customHeight !== value) {
20681
+ this._customHeight = value;
20579
20682
  this._dispatchSpriteChange(SpriteModifyFlags.size);
20580
20683
  }
20581
20684
  }
@@ -20605,7 +20708,9 @@ exports.TextVerticalAlignment = void 0;
20605
20708
  var y = engineMath.MathUtil.clamp(value.y, 0, 1);
20606
20709
  this._atlasRegion.set(x, y, engineMath.MathUtil.clamp(value.width, 0, 1 - x), engineMath.MathUtil.clamp(value.height, 0, 1 - y));
20607
20710
  this._dispatchSpriteChange(SpriteModifyFlags.atlasRegion);
20608
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
20711
+ if (this._customWidth === undefined || this._customHeight === undefined) {
20712
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
20713
+ }
20609
20714
  }
20610
20715
  },
20611
20716
  {
@@ -20620,7 +20725,9 @@ exports.TextVerticalAlignment = void 0;
20620
20725
  var y = engineMath.MathUtil.clamp(value.y, 0, 1);
20621
20726
  this._atlasRegionOffset.set(x, y, engineMath.MathUtil.clamp(value.z, 0, 1 - x), engineMath.MathUtil.clamp(value.w, 0, 1 - y));
20622
20727
  this._dispatchSpriteChange(SpriteModifyFlags.atlasRegionOffset);
20623
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
20728
+ if (this._customWidth === undefined || this._customHeight === undefined) {
20729
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
20730
+ }
20624
20731
  }
20625
20732
  },
20626
20733
  {
@@ -20636,7 +20743,9 @@ exports.TextVerticalAlignment = void 0;
20636
20743
  var y = engineMath.MathUtil.clamp(value.y, 0, 1);
20637
20744
  region.set(x, y, engineMath.MathUtil.clamp(value.width, 0, 1 - x), engineMath.MathUtil.clamp(value.height, 0, 1 - y));
20638
20745
  this._dispatchSpriteChange(SpriteModifyFlags.region);
20639
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
20746
+ if (this._customWidth === undefined || this._customHeight === undefined) {
20747
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
20748
+ }
20640
20749
  }
20641
20750
  },
20642
20751
  {
@@ -20686,7 +20795,8 @@ var SpriteUpdateFlags;
20686
20795
  (function(SpriteUpdateFlags) {
20687
20796
  SpriteUpdateFlags[SpriteUpdateFlags["positions"] = 0x1] = "positions";
20688
20797
  SpriteUpdateFlags[SpriteUpdateFlags["uvs"] = 0x2] = "uvs";
20689
- SpriteUpdateFlags[SpriteUpdateFlags["all"] = 0x3] = "all";
20798
+ SpriteUpdateFlags[SpriteUpdateFlags["automaticSize"] = 0x4] = "automaticSize";
20799
+ SpriteUpdateFlags[SpriteUpdateFlags["all"] = 0x7] = "all";
20690
20800
  })(SpriteUpdateFlags || (SpriteUpdateFlags = {}));
20691
20801
 
20692
20802
  var _SlicedSpriteAssembler;
@@ -21178,8 +21288,10 @@ var TiledType;
21178
21288
  _this._tiledAdaptiveThreshold = 0.5;
21179
21289
  _this._color = new engineMath.Color(1, 1, 1, 1);
21180
21290
  _this._sprite = null;
21181
- _this._width = undefined;
21182
- _this._height = undefined;
21291
+ _this._automaticWidth = 0;
21292
+ _this._automaticHeight = 0;
21293
+ _this._customWidth = undefined;
21294
+ _this._customHeight = undefined;
21183
21295
  _this._flipX = false;
21184
21296
  _this._flipY = false;
21185
21297
  _this._maskLayer = exports.SpriteMaskLayer.Layer0;
@@ -21196,6 +21308,7 @@ var TiledType;
21196
21308
  */ _proto._cloneTo = function _cloneTo(target) {
21197
21309
  target._assembler.resetData(target);
21198
21310
  target.sprite = this._sprite;
21311
+ target.drawMode = this._drawMode;
21199
21312
  };
21200
21313
  /**
21201
21314
  * @internal
@@ -21206,12 +21319,11 @@ var TiledType;
21206
21319
  /**
21207
21320
  * @internal
21208
21321
  */ _proto._updateBounds = function _updateBounds(worldBounds) {
21209
- var _this_sprite;
21210
- if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
21322
+ if (this.sprite) {
21323
+ this._assembler.updatePositions(this);
21324
+ } else {
21211
21325
  worldBounds.min.set(0, 0, 0);
21212
21326
  worldBounds.max.set(0, 0, 0);
21213
- } else {
21214
- this._assembler.updatePositions(this);
21215
21327
  }
21216
21328
  };
21217
21329
  /**
@@ -21221,17 +21333,17 @@ var TiledType;
21221
21333
  if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
21222
21334
  return;
21223
21335
  }
21224
- // Update position.
21336
+ // Update position
21225
21337
  if (this._dirtyUpdateFlag & RendererUpdateFlags.WorldVolume) {
21226
21338
  this._assembler.updatePositions(this);
21227
21339
  this._dirtyUpdateFlag &= ~RendererUpdateFlags.WorldVolume;
21228
21340
  }
21229
- // Update uv.
21341
+ // Update uv
21230
21342
  if (this._dirtyUpdateFlag & 0x2) {
21231
21343
  this._assembler.updateUVs(this);
21232
21344
  this._dirtyUpdateFlag &= ~0x2;
21233
21345
  }
21234
- // Push render data
21346
+ // Push primitive
21235
21347
  var material = this.getMaterial();
21236
21348
  var texture = this.sprite.texture;
21237
21349
  var renderData = this._engine._spriteRenderDataPool.getFromPool();
@@ -21249,6 +21361,16 @@ var TiledType;
21249
21361
  this._assembler = null;
21250
21362
  this._verticesData = null;
21251
21363
  };
21364
+ _proto._calDefaultSize = function _calDefaultSize() {
21365
+ var sprite = this._sprite;
21366
+ if (sprite) {
21367
+ this._automaticWidth = sprite.width;
21368
+ this._automaticHeight = sprite.height;
21369
+ } else {
21370
+ this._automaticWidth = this._automaticHeight = 0;
21371
+ }
21372
+ this._dirtyUpdateFlag &= ~0x4;
21373
+ };
21252
21374
  _proto._updateStencilState = function _updateStencilState() {
21253
21375
  // Update stencil.
21254
21376
  var material = this.getInstanceMaterial();
@@ -21275,22 +21397,21 @@ var TiledType;
21275
21397
  break;
21276
21398
  case SpriteModifyFlags.size:
21277
21399
  var _this = this, drawMode = _this._drawMode;
21278
- if (drawMode === exports.SpriteDrawMode.Sliced) {
21400
+ this._dirtyUpdateFlag |= 0x4;
21401
+ if (this._drawMode === exports.SpriteDrawMode.Sliced) {
21279
21402
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
21280
21403
  } else if (drawMode === exports.SpriteDrawMode.Tiled) {
21281
21404
  this._dirtyUpdateFlag |= 0x3;
21282
21405
  } else {
21283
21406
  // When the width and height of `SpriteRenderer` are `undefined`,
21284
21407
  // the `size` of `Sprite` will affect the position of `SpriteRenderer`.
21285
- if (this._width === undefined || this._height === undefined) {
21408
+ if (this._customWidth === undefined || this._customHeight === undefined) {
21286
21409
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
21287
21410
  }
21288
21411
  }
21289
21412
  break;
21290
21413
  case SpriteModifyFlags.border:
21291
- if (this._drawMode === exports.SpriteDrawMode.Sliced || this._drawMode === exports.SpriteDrawMode.Tiled) {
21292
- this._dirtyUpdateFlag |= 0x3;
21293
- }
21414
+ this._drawMode === exports.SpriteDrawMode.Sliced && (this._dirtyUpdateFlag |= 0x3);
21294
21415
  break;
21295
21416
  case SpriteModifyFlags.region:
21296
21417
  case SpriteModifyFlags.atlasRegionOffset:
@@ -21375,9 +21496,9 @@ var TiledType;
21375
21496
  var lastSprite = this._sprite;
21376
21497
  if (lastSprite !== value) {
21377
21498
  lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
21499
+ this._dirtyUpdateFlag |= 0x7;
21378
21500
  if (value) {
21379
21501
  value._updateFlagManager.addListener(this._onSpriteChange);
21380
- this._dirtyUpdateFlag |= 0x3;
21381
21502
  this.shaderData.setTexture(SpriteRenderer._textureProperty, value.texture);
21382
21503
  } else {
21383
21504
  this.shaderData.setTexture(SpriteRenderer._textureProperty, null);
@@ -21402,16 +21523,22 @@ var TiledType;
21402
21523
  {
21403
21524
  key: "width",
21404
21525
  get: /**
21405
- * Render width.
21526
+ * Render width (in world coordinates).
21527
+ *
21528
+ * @remarks
21529
+ * If width is set, return the set value,
21530
+ * otherwise return `SpriteRenderer.sprite.width`.
21406
21531
  */ function get() {
21407
- this._width === undefined && this._sprite && (this.width = this._sprite.width);
21408
- return this._width;
21532
+ if (this._customWidth !== undefined) {
21533
+ return this._customWidth;
21534
+ } else {
21535
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
21536
+ return this._automaticWidth;
21537
+ }
21409
21538
  },
21410
21539
  set: function set(value) {
21411
- // Update width if undefined
21412
- this._width === undefined && this._sprite && (this._width = this._sprite.width);
21413
- if (this._width !== value) {
21414
- this._width = value;
21540
+ if (this._customWidth !== value) {
21541
+ this._customWidth = value;
21415
21542
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
21416
21543
  }
21417
21544
  }
@@ -21419,16 +21546,22 @@ var TiledType;
21419
21546
  {
21420
21547
  key: "height",
21421
21548
  get: /**
21422
- * Render height.
21549
+ * Render height (in world coordinates).
21550
+ *
21551
+ * @remarks
21552
+ * If height is set, return the set value,
21553
+ * otherwise return `SpriteRenderer.sprite.height`.
21423
21554
  */ function get() {
21424
- this._height === undefined && this._sprite && (this.height = this._sprite.height);
21425
- return this._height;
21555
+ if (this._customHeight !== undefined) {
21556
+ return this._customHeight;
21557
+ } else {
21558
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
21559
+ return this._automaticHeight;
21560
+ }
21426
21561
  },
21427
21562
  set: function set(value) {
21428
- // Update height if undefined
21429
- this._height === undefined && this._sprite && (this._height = this._sprite.height);
21430
- if (this._height !== value) {
21431
- this._height = value;
21563
+ if (this._customHeight !== value) {
21564
+ this._customHeight = value;
21432
21565
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
21433
21566
  }
21434
21567
  }
@@ -21515,10 +21648,16 @@ __decorate([
21515
21648
  ], SpriteRenderer.prototype, "_sprite", void 0);
21516
21649
  __decorate([
21517
21650
  ignoreClone
21518
- ], SpriteRenderer.prototype, "_width", void 0);
21651
+ ], SpriteRenderer.prototype, "_automaticWidth", void 0);
21519
21652
  __decorate([
21520
21653
  ignoreClone
21521
- ], SpriteRenderer.prototype, "_height", void 0);
21654
+ ], SpriteRenderer.prototype, "_automaticHeight", void 0);
21655
+ __decorate([
21656
+ assignmentClone
21657
+ ], SpriteRenderer.prototype, "_customWidth", void 0);
21658
+ __decorate([
21659
+ assignmentClone
21660
+ ], SpriteRenderer.prototype, "_customHeight", void 0);
21522
21661
  __decorate([
21523
21662
  assignmentClone
21524
21663
  ], SpriteRenderer.prototype, "_flipX", void 0);
@@ -21539,7 +21678,9 @@ var /**
21539
21678
  */ SpriteRendererUpdateFlags;
21540
21679
  (function(SpriteRendererUpdateFlags) {
21541
21680
  SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** UV. */ "UV"] = 0x2] = "UV";
21542
- SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** All. */ "All"] = 0x3] = "All";
21681
+ SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** WorldVolume and UV . */ "RenderData"] = 0x3] = "RenderData";
21682
+ SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** Automatic Size. */ "AutomaticSize"] = 0x4] = "AutomaticSize";
21683
+ SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** All. */ "All"] = 0x7] = "All";
21543
21684
  })(SpriteRendererUpdateFlags || (SpriteRendererUpdateFlags = {}));
21544
21685
 
21545
21686
  /**