@galacean/engine 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/browser.js CHANGED
@@ -12650,8 +12650,9 @@
12650
12650
  _inherits$2(Light, Component);
12651
12651
  var _proto = Light.prototype;
12652
12652
  /**
12653
+ * Light Color, include intensity.
12653
12654
  * @internal
12654
- */ _proto._getLightColor = function _getLightColor() {
12655
+ */ _proto._getLightIntensityColor = function _getLightIntensityColor() {
12655
12656
  this._lightColor.r = this.color.r * this.intensity;
12656
12657
  this._lightColor.g = this.color.g * this.intensity;
12657
12658
  this._lightColor.b = this.color.b * this.intensity;
@@ -12720,15 +12721,21 @@
12720
12721
  var cullingMaskStart = lightIndex * 2;
12721
12722
  var colorStart = lightIndex * 3;
12722
12723
  var directionStart = lightIndex * 3;
12723
- var lightColor = this._getLightColor();
12724
+ var lightColor = this._getLightIntensityColor();
12724
12725
  var direction = this.direction;
12725
12726
  var data = DirectLight._combinedData;
12726
12727
  var cullingMask = this.cullingMask;
12727
12728
  data.cullingMask[cullingMaskStart] = cullingMask & 65535;
12728
12729
  data.cullingMask[cullingMaskStart + 1] = cullingMask >>> 16 & 65535;
12729
- data.color[colorStart] = lightColor.r;
12730
- data.color[colorStart + 1] = lightColor.g;
12731
- data.color[colorStart + 2] = lightColor.b;
12730
+ if (this.engine.settings.colorSpace === exports.ColorSpace.Linear) {
12731
+ data.color[colorStart] = Color$1.gammaToLinearSpace(lightColor.r);
12732
+ data.color[colorStart + 1] = Color$1.gammaToLinearSpace(lightColor.g);
12733
+ data.color[colorStart + 2] = Color$1.gammaToLinearSpace(lightColor.b);
12734
+ } else {
12735
+ data.color[colorStart] = lightColor.r;
12736
+ data.color[colorStart + 1] = lightColor.g;
12737
+ data.color[colorStart + 2] = lightColor.b;
12738
+ }
12732
12739
  data.direction[directionStart] = direction.x;
12733
12740
  data.direction[directionStart + 1] = direction.y;
12734
12741
  data.direction[directionStart + 2] = direction.z;
@@ -12816,15 +12823,21 @@
12816
12823
  var colorStart = lightIndex * 3;
12817
12824
  var positionStart = lightIndex * 3;
12818
12825
  var distanceStart = lightIndex;
12819
- var lightColor = this._getLightColor();
12826
+ var lightColor = this._getLightIntensityColor();
12820
12827
  var lightPosition = this.position;
12821
12828
  var data = PointLight._combinedData;
12822
12829
  var cullingMask = this.cullingMask;
12823
12830
  data.cullingMask[cullingMaskStart] = cullingMask & 65535;
12824
12831
  data.cullingMask[cullingMaskStart + 1] = cullingMask >>> 16 & 65535;
12825
- data.color[colorStart] = lightColor.r;
12826
- data.color[colorStart + 1] = lightColor.g;
12827
- data.color[colorStart + 2] = lightColor.b;
12832
+ if (this.engine.settings.colorSpace === exports.ColorSpace.Linear) {
12833
+ data.color[colorStart] = Color$1.gammaToLinearSpace(lightColor.r);
12834
+ data.color[colorStart + 1] = Color$1.gammaToLinearSpace(lightColor.g);
12835
+ data.color[colorStart + 2] = Color$1.gammaToLinearSpace(lightColor.b);
12836
+ } else {
12837
+ data.color[colorStart] = lightColor.r;
12838
+ data.color[colorStart + 1] = lightColor.g;
12839
+ data.color[colorStart + 2] = lightColor.b;
12840
+ }
12828
12841
  data.position[positionStart] = lightPosition.x;
12829
12842
  data.position[positionStart + 1] = lightPosition.y;
12830
12843
  data.position[positionStart + 2] = lightPosition.z;
@@ -12916,16 +12929,22 @@
12916
12929
  var distanceStart = lightIndex;
12917
12930
  var penumbraCosStart = lightIndex;
12918
12931
  var angleCosStart = lightIndex;
12919
- var color = this._getLightColor();
12932
+ var lightColor = this._getLightIntensityColor();
12920
12933
  var position = this.position;
12921
12934
  var direction = this.direction;
12922
12935
  var data = SpotLight._combinedData;
12923
12936
  var cullingMask = this.cullingMask;
12924
12937
  data.cullingMask[cullingMaskStart] = cullingMask & 65535;
12925
12938
  data.cullingMask[cullingMaskStart + 1] = cullingMask >>> 16 & 65535;
12926
- data.color[colorStart] = color.r;
12927
- data.color[colorStart + 1] = color.g;
12928
- data.color[colorStart + 2] = color.b;
12939
+ if (this.engine.settings.colorSpace === exports.ColorSpace.Linear) {
12940
+ data.color[colorStart] = Color$1.gammaToLinearSpace(lightColor.r);
12941
+ data.color[colorStart + 1] = Color$1.gammaToLinearSpace(lightColor.g);
12942
+ data.color[colorStart + 2] = Color$1.gammaToLinearSpace(lightColor.b);
12943
+ } else {
12944
+ data.color[colorStart] = lightColor.r;
12945
+ data.color[colorStart + 1] = lightColor.g;
12946
+ data.color[colorStart + 2] = lightColor.b;
12947
+ }
12929
12948
  data.position[positionStart] = position.x;
12930
12949
  data.position[positionStart + 1] = position.y;
12931
12950
  data.position[positionStart + 2] = position.z;
@@ -14252,9 +14271,9 @@
14252
14271
  }
14253
14272
  var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;"; // eslint-disable-line
14254
14273
  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
14255
- 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
14274
+ 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
14256
14275
  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
14257
- var color_share = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_VERTEXCOLOR\nvarying vec4 v_color;\n#endif\n"; // eslint-disable-line
14276
+ var color_share = "#define GLSLIFY 1\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nvarying vec4 v_color;\n#endif\n"; // eslint-disable-line
14258
14277
  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
14259
14278
  var FogVertexDeclaration = "#define GLSLIFY 1\n#if SCENE_FOG_MODE != 0\nvarying vec3 v_positionVS;\n#endif\n"; // eslint-disable-line
14260
14279
  var normal_share = "#define GLSLIFY 1\n#ifndef MATERIAL_OMIT_NORMAL\n#ifdef RENDERER_HAS_NORMAL\nvarying vec3 v_normal;\n#if defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\nvarying mat3 v_TBN;\n#endif\n#endif\n#endif\n"; // eslint-disable-line
@@ -14264,7 +14283,7 @@
14264
14283
  var begin_position_vert = "#define GLSLIFY 1\nvec4 position=vec4(POSITION,1.0);"; // eslint-disable-line
14265
14284
  var blendShape_input = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_BLENDSHAPE\n#ifdef RENDERER_BLENDSHAPE_USE_TEXTURE\nuniform mediump sampler2DArray renderer_BlendShapeTexture;uniform ivec3 renderer_BlendShapeTextureInfo;uniform float renderer_BlendShapeWeights[RENDERER_BLENDSHAPE_COUNT];\n#else\nattribute vec3 POSITION_BS0;attribute vec3 POSITION_BS1;\n#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\nattribute vec3 NORMAL_BS0;attribute vec3 NORMAL_BS1;attribute vec3 TANGENT_BS0;attribute vec3 TANGENT_BS1;uniform float renderer_BlendShapeWeights[2];\n#else\n#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) || defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\nattribute vec3 POSITION_BS2;attribute vec3 POSITION_BS3;\n#ifdef RENDERER_BLENDSHAPE_HAS_NORMAL\nattribute vec3 NORMAL_BS0;attribute vec3 NORMAL_BS1;attribute vec3 NORMAL_BS2;attribute vec3 NORMAL_BS3;\n#endif\n#ifdef RENDERER_BLENDSHAPE_HAS_TANGENT\nattribute vec3 TANGENT_BS0;attribute vec3 TANGENT_BS1;attribute vec3 TANGENT_BS2;attribute vec3 TANGENT_BS3;\n#endif\nuniform float renderer_BlendShapeWeights[4];\n#else\nattribute vec3 POSITION_BS2;attribute vec3 POSITION_BS3;attribute vec3 POSITION_BS4;attribute vec3 POSITION_BS5;attribute vec3 POSITION_BS6;attribute vec3 POSITION_BS7;uniform float renderer_BlendShapeWeights[8];\n#endif\n#endif\n#endif\n#ifdef RENDERER_BLENDSHAPE_USE_TEXTURE\nvec3 getBlendShapeVertexElement(int blendShapeIndex,int vertexElementIndex){int y=vertexElementIndex/renderer_BlendShapeTextureInfo.y;int x=vertexElementIndex-y*renderer_BlendShapeTextureInfo.y;ivec3 uv=ivec3(x,y,blendShapeIndex);return texelFetch(renderer_BlendShapeTexture,uv,0).xyz;}\n#endif\n#endif\n"; // eslint-disable-line
14266
14285
  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
14267
- var color_vert = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_VERTEXCOLOR\nv_color=COLOR_0;\n#endif\n"; // eslint-disable-line
14286
+ var color_vert = "#define GLSLIFY 1\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nv_color=COLOR_0;\n#endif\n"; // eslint-disable-line
14268
14287
  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
14269
14288
  var normal_vert = "#define GLSLIFY 1\n#ifndef MATERIAL_OMIT_NORMAL\n#ifdef RENDERER_HAS_NORMAL\nv_normal=normalize(mat3(renderer_NormalMat)*normal);\n#if defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\nvec3 normalW=normalize(mat3(renderer_NormalMat)*normal.xyz);vec3 tangentW=normalize(mat3(renderer_NormalMat)*tangent.xyz);vec3 bitangentW=cross(normalW,tangentW)*tangent.w;v_TBN=mat3(tangentW,bitangentW,normalW);\n#endif\n#endif\n#endif\n"; // eslint-disable-line
14270
14289
  var position_vert = "#define GLSLIFY 1\ngl_Position=renderer_MVPMat*position;"; // eslint-disable-line
@@ -14274,9 +14293,9 @@
14274
14293
  var FogFragment = "#define GLSLIFY 1\n#if SCENE_FOG_MODE != 0\nfloat fogIntensity=ComputeFogIntensity(length(v_positionVS));gl_FragColor.rgb=mix(scene_FogColor.rgb,gl_FragColor.rgb,fogIntensity);\n#endif\n"; // eslint-disable-line
14275
14294
  var light_frag_define = "#define GLSLIFY 1\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nstruct DirectLight{vec3 color;vec3 direction;};uniform ivec2 scene_DirectLightCullingMask[SCENE_DIRECT_LIGHT_COUNT];uniform vec3 scene_DirectLightColor[SCENE_DIRECT_LIGHT_COUNT];uniform vec3 scene_DirectLightDirection[SCENE_DIRECT_LIGHT_COUNT];\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nstruct PointLight{vec3 color;vec3 position;float distance;};uniform ivec2 scene_PointLightCullingMask[SCENE_POINT_LIGHT_COUNT];uniform vec3 scene_PointLightColor[SCENE_POINT_LIGHT_COUNT];uniform vec3 scene_PointLightPosition[SCENE_POINT_LIGHT_COUNT];uniform float scene_PointLightDistance[SCENE_POINT_LIGHT_COUNT];\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nstruct SpotLight{vec3 color;vec3 position;vec3 direction;float distance;float angleCos;float penumbraCos;};uniform ivec2 scene_SpotLightCullingMask[SCENE_SPOT_LIGHT_COUNT];uniform vec3 scene_SpotLightColor[SCENE_SPOT_LIGHT_COUNT];uniform vec3 scene_SpotLightPosition[SCENE_SPOT_LIGHT_COUNT];uniform vec3 scene_SpotLightDirection[SCENE_SPOT_LIGHT_COUNT];uniform float scene_SpotLightDistance[SCENE_SPOT_LIGHT_COUNT];uniform float scene_SpotLightAngleCos[SCENE_SPOT_LIGHT_COUNT];uniform float scene_SpotLightPenumbraCos[SCENE_SPOT_LIGHT_COUNT];\n#endif\nstruct EnvMapLight{vec3 diffuse;float mipMapLevel;float diffuseIntensity;float specularIntensity;};uniform EnvMapLight scene_EnvMapLight;uniform ivec4 renderer_Layer;\n#ifdef SCENE_USE_SH\nuniform vec3 scene_EnvSH[9];\n#endif\n#ifdef SCENE_USE_SPECULAR_ENV\nuniform samplerCube scene_EnvSpecularSampler;\n#endif\n#ifndef GRAPHICS_API_WEBGL2\nbool isBitSet(float value,float mask,float bitIndex){return mod(floor(value/pow(2.0,bitIndex)),2.0)==1.0&&mod(floor(mask/pow(2.0,bitIndex)),2.0)==1.0;}\n#endif\nbool isRendererCulledByLight(ivec2 rendererLayer,ivec2 lightCullingMask){\n#ifdef GRAPHICS_API_WEBGL2\nreturn!((rendererLayer.x&lightCullingMask.x)!=0||(rendererLayer.y&lightCullingMask.y)!=0);\n#else\nfor(int i=0;i<16;i++){if(isBitSet(float(rendererLayer.x),float(lightCullingMask.x),float(i))||isBitSet(float(rendererLayer.y),float(lightCullingMask.y),float(i))){return false;}}return true;\n#endif\n}"; // eslint-disable-line
14276
14295
  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
14277
- 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
14296
+ 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
14278
14297
  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
14279
- 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
14298
+ 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
14280
14299
  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
14281
14300
  var noise_cellular_2D = "#define GLSLIFY 1\nvec2 cellular(vec2 P){vec2 Pi=mod289(floor(P));vec2 Pf=fract(P);vec3 oi=vec3(-1.0,0.0,1.0);vec3 of=vec3(-0.5,0.5,1.5);vec3 px=permute(Pi.x+oi);vec3 p=permute(px.x+Pi.y+oi);vec3 ox=fract(p*K)-Ko;vec3 oy=mod7(floor(p*K))*K-Ko;vec3 dx=Pf.x+0.5+jitter*ox;vec3 dy=Pf.y-of+jitter*oy;vec3 d1=dx*dx+dy*dy;p=permute(px.y+Pi.y+oi);ox=fract(p*K)-Ko;oy=mod7(floor(p*K))*K-Ko;dx=Pf.x-0.5+jitter*ox;dy=Pf.y-of+jitter*oy;vec3 d2=dx*dx+dy*dy;p=permute(px.z+Pi.y+oi);ox=fract(p*K)-Ko;oy=mod7(floor(p*K))*K-Ko;dx=Pf.x-1.5+jitter*ox;dy=Pf.y-of+jitter*oy;vec3 d3=dx*dx+dy*dy;vec3 d1a=min(d1,d2);d2=max(d1,d2);d2=min(d2,d3);d1=min(d1a,d2);d2=max(d1a,d2);d1.xy=(d1.x<d1.y)? d1.xy : d1.yx;d1.xz=(d1.x<d1.z)? d1.xz : d1.zx;d1.yz=min(d1.yz,d2.yz);d1.y=min(d1.y,d1.z);d1.y=min(d1.y,d2.x);return sqrt(d1.xy);}"; // eslint-disable-line
14282
14301
  var noise_cellular_2x2 = "#define GLSLIFY 1\nvec2 cellular2x2(vec2 P){vec2 Pi=mod289(floor(P));vec2 Pf=fract(P);vec4 Pfx=Pf.x+vec4(-0.5,-1.5,-0.5,-1.5);vec4 Pfy=Pf.y+vec4(-0.5,-0.5,-1.5,-1.5);vec4 p=permute(Pi.x+vec4(0.0,1.0,0.0,1.0));p=permute(p+Pi.y+vec4(0.0,0.0,1.0,1.0));vec4 ox=mod7(p)*K+Kd2;vec4 oy=mod7(floor(p*K))*K+Kd2;vec4 dx=Pfx+jitter1*ox;vec4 dy=Pfy+jitter1*oy;vec4 d=dx*dx+dy*dy;d.xy=(d.x<d.y)? d.xy : d.yx;d.xz=(d.x<d.z)? d.xz : d.zx;d.xw=(d.x<d.w)? d.xw : d.wx;d.y=min(d.y,d.z);d.y=min(d.y,d.w);return sqrt(d.xy);}"; // eslint-disable-line
@@ -14294,11 +14313,11 @@
14294
14313
  var noise_simplex_3D_grad = "#define GLSLIFY 1\nfloat simplex(vec3 v,out vec3 gradient){const vec2 C=vec2(1.0/6.0,1.0/3.0);const vec4 D=vec4(0.0,0.5,1.0,2.0);vec3 i=floor(v+dot(v,C.yyy));vec3 x0=v-i+dot(i,C.xxx);vec3 g=step(x0.yzx,x0.xyz);vec3 l=1.0-g;vec3 i1=min(g.xyz,l.zxy);vec3 i2=max(g.xyz,l.zxy);vec3 x1=x0-i1+C.xxx;vec3 x2=x0-i2+C.yyy;vec3 x3=x0-D.yyy;i=mod289(i);vec4 p=permute(permute(permute(i.z+vec4(0.0,i1.z,i2.z,1.0))+i.y+vec4(0.0,i1.y,i2.y,1.0))+i.x+vec4(0.0,i1.x,i2.x,1.0));float n_=0.142857142857;vec3 ns=n_*D.wyz-D.xzx;vec4 j=p-49.0*floor(p*ns.z*ns.z);vec4 x_=floor(j*ns.z);vec4 y_=floor(j-7.0*x_);vec4 x=x_*ns.x+ns.yyyy;vec4 y=y_*ns.x+ns.yyyy;vec4 h=1.0-abs(x)-abs(y);vec4 b0=vec4(x.xy,y.xy);vec4 b1=vec4(x.zw,y.zw);vec4 s0=floor(b0)*2.0+1.0;vec4 s1=floor(b1)*2.0+1.0;vec4 sh=-step(h,vec4(0.0));vec4 a0=b0.xzyw+s0.xzyw*sh.xxyy;vec4 a1=b1.xzyw+s1.xzyw*sh.zzww;vec3 p0=vec3(a0.xy,h.x);vec3 p1=vec3(a0.zw,h.y);vec3 p2=vec3(a1.xy,h.z);vec3 p3=vec3(a1.zw,h.w);vec4 norm=taylorInvSqrt(vec4(dot(p0,p0),dot(p1,p1),dot(p2,p2),dot(p3,p3)));p0*=norm.x;p1*=norm.y;p2*=norm.z;p3*=norm.w;vec4 m=max(0.6-vec4(dot(x0,x0),dot(x1,x1),dot(x2,x2),dot(x3,x3)),0.0);vec4 m2=m*m;vec4 m4=m2*m2;vec4 pdotx=vec4(dot(p0,x0),dot(p1,x1),dot(p2,x2),dot(p3,x3));vec4 temp=m2*m*pdotx;gradient=-8.0*(temp.x*x0+temp.y*x1+temp.z*x2+temp.w*x3);gradient+=m4.x*p0+m4.y*p1+m4.z*p2+m4.w*p3;gradient*=42.0;return 42.0*dot(m4,pdotx);}"; // eslint-disable-line
14295
14314
  var noise_simplex_4D = "#define GLSLIFY 1\nvec4 grad4(float j,vec4 ip){const vec4 ones=vec4(1.0,1.0,1.0,-1.0);vec4 p,s;p.xyz=floor(fract(vec3(j)*ip.xyz)*7.0)*ip.z-1.0;p.w=1.5-dot(abs(p.xyz),ones.xyz);s=vec4(lessThan(p,vec4(0.0)));p.xyz=p.xyz+(s.xyz*2.0-1.0)*s.www;return p;}\n#define F4 0.309016994374947451\nfloat simplex(vec4 v){const vec4 C=vec4(0.138196601125011,0.276393202250021,0.414589803375032,-0.447213595499958);vec4 i=floor(v+dot(v,vec4(F4)));vec4 x0=v-i+dot(i,C.xxxx);vec4 i0;vec3 isX=step(x0.yzw,x0.xxx);vec3 isYZ=step(x0.zww,x0.yyz);i0.x=isX.x+isX.y+isX.z;i0.yzw=1.0-isX;i0.y+=isYZ.x+isYZ.y;i0.zw+=1.0-isYZ.xy;i0.z+=isYZ.z;i0.w+=1.0-isYZ.z;vec4 i3=clamp(i0,0.0,1.0);vec4 i2=clamp(i0-1.0,0.0,1.0);vec4 i1=clamp(i0-2.0,0.0,1.0);vec4 x1=x0-i1+C.xxxx;vec4 x2=x0-i2+C.yyyy;vec4 x3=x0-i3+C.zzzz;vec4 x4=x0+C.wwww;i=mod289(i);float j0=permute(permute(permute(permute(i.w)+i.z)+i.y)+i.x);vec4 j1=permute(permute(permute(permute(i.w+vec4(i1.w,i2.w,i3.w,1.0))+i.z+vec4(i1.z,i2.z,i3.z,1.0))+i.y+vec4(i1.y,i2.y,i3.y,1.0))+i.x+vec4(i1.x,i2.x,i3.x,1.0));vec4 ip=vec4(1.0/294.0,1.0/49.0,1.0/7.0,0.0);vec4 p0=grad4(j0,ip);vec4 p1=grad4(j1.x,ip);vec4 p2=grad4(j1.y,ip);vec4 p3=grad4(j1.z,ip);vec4 p4=grad4(j1.w,ip);vec4 norm=taylorInvSqrt(vec4(dot(p0,p0),dot(p1,p1),dot(p2,p2),dot(p3,p3)));p0*=norm.x;p1*=norm.y;p2*=norm.z;p3*=norm.w;p4*=taylorInvSqrt(dot(p4,p4));vec3 m0=max(0.6-vec3(dot(x0,x0),dot(x1,x1),dot(x2,x2)),0.0);vec2 m1=max(0.6-vec2(dot(x3,x3),dot(x4,x4)),0.0);m0=m0*m0;m1=m1*m1;return 49.0*(dot(m0*m0,vec3(dot(p0,x0),dot(p1,x1),dot(p2,x2)))+dot(m1*m1,vec2(dot(p3,x3),dot(p4,x4))));}"; // eslint-disable-line
14296
14315
  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
14297
- 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
14316
+ 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
14298
14317
  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
14299
14318
  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
14300
14319
  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
14301
- 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
14320
+ 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
14302
14321
  var PBRShaderLib = {
14303
14322
  pbr_frag_define: pbr_frag_define,
14304
14323
  pbr_helper: pbr_helper,
@@ -14319,7 +14338,7 @@
14319
14338
  ShadowVertexDeclaration: ShadowVertexDeclaration,
14320
14339
  ShadowVertex: ShadowVertex
14321
14340
  };
14322
- 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
14341
+ 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
14323
14342
  var ShaderLib = _extends$2({
14324
14343
  common: common,
14325
14344
  common_vert: common_vert,
@@ -15836,8 +15855,10 @@
15836
15855
  _this = Renderer.call(this, entity) || this;
15837
15856
  /** The mask layers the sprite mask influence to. */ _this.influenceLayers = exports.SpriteMaskLayer.Everything;
15838
15857
  _this._sprite = null;
15839
- _this._width = undefined;
15840
- _this._height = undefined;
15858
+ _this._automaticWidth = 0;
15859
+ _this._automaticHeight = 0;
15860
+ _this._customWidth = undefined;
15861
+ _this._customHeight = undefined;
15841
15862
  _this._flipX = false;
15842
15863
  _this._flipY = false;
15843
15864
  _this._alphaCutoff = 0.5;
@@ -15857,12 +15878,11 @@
15857
15878
  /**
15858
15879
  * @internal
15859
15880
  */ _proto._updateBounds = function _updateBounds(worldBounds) {
15860
- var _this_sprite;
15861
- if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
15881
+ if (this.sprite) {
15882
+ SimpleSpriteAssembler.updatePositions(this);
15883
+ } else {
15862
15884
  worldBounds.min.set(0, 0, 0);
15863
15885
  worldBounds.max.set(0, 0, 0);
15864
- } else {
15865
- SimpleSpriteAssembler.updatePositions(this);
15866
15886
  }
15867
15887
  };
15868
15888
  /**
@@ -15873,12 +15893,12 @@
15873
15893
  if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
15874
15894
  return;
15875
15895
  }
15876
- // Update position.
15896
+ // Update position
15877
15897
  if (this._dirtyUpdateFlag & RendererUpdateFlags.WorldVolume) {
15878
15898
  SimpleSpriteAssembler.updatePositions(this);
15879
15899
  this._dirtyUpdateFlag &= ~RendererUpdateFlags.WorldVolume;
15880
15900
  }
15881
- // Update uv.
15901
+ // Update uv
15882
15902
  if (this._dirtyUpdateFlag & 0x2) {
15883
15903
  SimpleSpriteAssembler.updateUVs(this);
15884
15904
  this._dirtyUpdateFlag &= ~0x2;
@@ -15901,11 +15921,27 @@
15901
15921
  this._sprite = null;
15902
15922
  this._verticesData = null;
15903
15923
  };
15924
+ _proto._calDefaultSize = function _calDefaultSize() {
15925
+ var sprite = this._sprite;
15926
+ if (sprite) {
15927
+ this._automaticWidth = sprite.width;
15928
+ this._automaticHeight = sprite.height;
15929
+ } else {
15930
+ this._automaticWidth = this._automaticHeight = 0;
15931
+ }
15932
+ this._dirtyUpdateFlag &= ~0x4;
15933
+ };
15904
15934
  _proto._onSpriteChange = function _onSpriteChange(type) {
15905
15935
  switch(type){
15906
15936
  case SpriteModifyFlags.texture:
15907
15937
  this.shaderData.setTexture(SpriteMask._textureProperty, this.sprite.texture);
15908
15938
  break;
15939
+ case SpriteModifyFlags.size:
15940
+ this._dirtyUpdateFlag |= 0x4;
15941
+ if (this._customWidth === undefined || this._customHeight === undefined) {
15942
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
15943
+ }
15944
+ break;
15909
15945
  case SpriteModifyFlags.region:
15910
15946
  case SpriteModifyFlags.atlasRegionOffset:
15911
15947
  this._dirtyUpdateFlag |= 0x3;
@@ -15913,22 +15949,31 @@
15913
15949
  case SpriteModifyFlags.atlasRegion:
15914
15950
  this._dirtyUpdateFlag |= 0x2;
15915
15951
  break;
15952
+ case SpriteModifyFlags.pivot:
15953
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
15954
+ break;
15916
15955
  }
15917
15956
  };
15918
15957
  _create_class$3(SpriteMask, [
15919
15958
  {
15920
15959
  key: "width",
15921
15960
  get: /**
15922
- * Render width.
15961
+ * Render width (in world coordinates).
15962
+ *
15963
+ * @remarks
15964
+ * If width is set, return the set value,
15965
+ * otherwise return `SpriteMask.sprite.width`.
15923
15966
  */ function get() {
15924
- if (this._width === undefined && this._sprite) {
15925
- this.width = this._sprite.width;
15967
+ if (this._customWidth !== undefined) {
15968
+ return this._customWidth;
15969
+ } else {
15970
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
15971
+ return this._automaticWidth;
15926
15972
  }
15927
- return this._width;
15928
15973
  },
15929
15974
  set: function set(value) {
15930
- if (this._width !== value) {
15931
- this._width = value;
15975
+ if (this._customWidth !== value) {
15976
+ this._customWidth = value;
15932
15977
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
15933
15978
  }
15934
15979
  }
@@ -15936,16 +15981,22 @@
15936
15981
  {
15937
15982
  key: "height",
15938
15983
  get: /**
15939
- * Render height.
15984
+ * Render height (in world coordinates).
15985
+ *
15986
+ * @remarks
15987
+ * If height is set, return the set value,
15988
+ * otherwise return `SpriteMask.sprite.height`.
15940
15989
  */ function get() {
15941
- if (this._height === undefined && this._sprite) {
15942
- this.height = this._sprite.height;
15990
+ if (this._customHeight !== undefined) {
15991
+ return this._customHeight;
15992
+ } else {
15993
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
15994
+ return this._automaticHeight;
15943
15995
  }
15944
- return this._height;
15945
15996
  },
15946
15997
  set: function set(value) {
15947
- if (this._height !== value) {
15948
- this._height = value;
15998
+ if (this._customHeight !== value) {
15999
+ this._customHeight = value;
15949
16000
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
15950
16001
  }
15951
16002
  }
@@ -15989,9 +16040,9 @@
15989
16040
  var lastSprite = this._sprite;
15990
16041
  if (lastSprite !== value) {
15991
16042
  lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
16043
+ this._dirtyUpdateFlag |= 0x7;
15992
16044
  if (value) {
15993
16045
  value._updateFlagManager.addListener(this._onSpriteChange);
15994
- this._dirtyUpdateFlag |= 0x3;
15995
16046
  this.shaderData.setTexture(SpriteMask._textureProperty, value.texture);
15996
16047
  } else {
15997
16048
  this.shaderData.setTexture(SpriteMask._textureProperty, null);
@@ -16031,10 +16082,16 @@
16031
16082
  ], SpriteMask.prototype, "_sprite", void 0);
16032
16083
  __decorate$1([
16033
16084
  ignoreClone
16034
- ], SpriteMask.prototype, "_width", void 0);
16085
+ ], SpriteMask.prototype, "_automaticWidth", void 0);
16035
16086
  __decorate$1([
16036
16087
  ignoreClone
16037
- ], SpriteMask.prototype, "_height", void 0);
16088
+ ], SpriteMask.prototype, "_automaticHeight", void 0);
16089
+ __decorate$1([
16090
+ assignmentClone
16091
+ ], SpriteMask.prototype, "_customWidth", void 0);
16092
+ __decorate$1([
16093
+ assignmentClone
16094
+ ], SpriteMask.prototype, "_customHeight", void 0);
16038
16095
  __decorate$1([
16039
16096
  assignmentClone
16040
16097
  ], SpriteMask.prototype, "_flipX", void 0);
@@ -16052,7 +16109,9 @@
16052
16109
  */ SpriteMaskUpdateFlags;
16053
16110
  (function(SpriteMaskUpdateFlags) {
16054
16111
  SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** UV. */ "UV"] = 0x2] = "UV";
16055
- SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** All. */ "All"] = 0x3] = "All";
16112
+ SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** WorldVolume and UV . */ "RenderData"] = 0x3] = "RenderData";
16113
+ SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** Automatic Size. */ "AutomaticSize"] = 0x4] = "AutomaticSize";
16114
+ SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** All. */ "All"] = 0x7] = "All";
16056
16115
  })(SpriteMaskUpdateFlags || (SpriteMaskUpdateFlags = {}));
16057
16116
  /**
16058
16117
  * Vertex element format.
@@ -16845,6 +16904,7 @@
16845
16904
  var subDataDirtyFlags = this._subDataDirtyFlags;
16846
16905
  var blendShapeFloatStride = this._vertexElementCount * 3;
16847
16906
  var blendShapeByteStride = blendShapeFloatStride * 4;
16907
+ var bufferOffset = this._bufferBindingOffset;
16848
16908
  // @todo: should fix bug when dataChangedFlag is true
16849
16909
  for(var i = 0, n = blendShapes.length; i < n; i++){
16850
16910
  var dataChangedFlag = subDataDirtyFlags[i];
@@ -16862,7 +16922,7 @@
16862
16922
  var offset = indexInBuffer * blendShapeFloatStride;
16863
16923
  var storeInfo = storeInfos[i];
16864
16924
  storeInfo || (storeInfos[i] = storeInfo = new Vector2());
16865
- storeInfo.set(bufferIndex + 1, indexInBuffer * blendShapeByteStride); // BlendShape buffer is start from 1
16925
+ storeInfo.set(bufferOffset + bufferIndex, indexInBuffer * blendShapeByteStride); // BufferOffset is mesh vertexBuffer offset
16866
16926
  var deltaPositions = endFrame.deltaPositions;
16867
16927
  for(var j = 0; j < vertexCount; j++){
16868
16928
  var start = offset + bufferFloatStride * j;
@@ -18134,6 +18194,7 @@
18134
18194
  var MeshRenderer = function MeshRenderer(entity) {
18135
18195
  var _this;
18136
18196
  _this = Renderer.call(this, entity) || this;
18197
+ _this._enableVertexColor = false;
18137
18198
  _this._onMeshChanged = _this._onMeshChanged.bind(_assert_this_initialized(_this));
18138
18199
  return _this;
18139
18200
  };
@@ -18179,7 +18240,7 @@
18179
18240
  shaderData.disableMacro(MeshRenderer._uv1Macro);
18180
18241
  shaderData.disableMacro(MeshRenderer._normalMacro);
18181
18242
  shaderData.disableMacro(MeshRenderer._tangentMacro);
18182
- shaderData.disableMacro(MeshRenderer._vertexColorMacro);
18243
+ shaderData.disableMacro(MeshRenderer._enableVertexColorMacro);
18183
18244
  for(var i = 0, n = vertexElements.length; i < n; i++){
18184
18245
  switch(vertexElements[i].semantic){
18185
18246
  case "TEXCOORD_0":
@@ -18195,7 +18256,7 @@
18195
18256
  shaderData.enableMacro(MeshRenderer._tangentMacro);
18196
18257
  break;
18197
18258
  case "COLOR_0":
18198
- shaderData.enableMacro(MeshRenderer._vertexColorMacro);
18259
+ this._enableVertexColor && shaderData.enableMacro(MeshRenderer._enableVertexColorMacro);
18199
18260
  break;
18200
18261
  }
18201
18262
  }
@@ -18246,6 +18307,20 @@
18246
18307
  this._setMesh(value);
18247
18308
  }
18248
18309
  }
18310
+ },
18311
+ {
18312
+ key: "enableVertexColor",
18313
+ get: /**
18314
+ * Whether enable vertex color.
18315
+ */ function get() {
18316
+ return this._enableVertexColor;
18317
+ },
18318
+ set: function set(value) {
18319
+ if (value !== this._enableVertexColor) {
18320
+ this._dirtyUpdateFlag |= 0x2;
18321
+ this._enableVertexColor = value;
18322
+ }
18323
+ }
18249
18324
  }
18250
18325
  ]);
18251
18326
  return MeshRenderer;
@@ -18263,7 +18338,7 @@
18263
18338
  MeshRenderer._tangentMacro = ShaderMacro.getByName("RENDERER_HAS_TANGENT");
18264
18339
  })();
18265
18340
  (function() {
18266
- MeshRenderer._vertexColorMacro = ShaderMacro.getByName("RENDERER_HAS_VERTEXCOLOR");
18341
+ MeshRenderer._enableVertexColorMacro = ShaderMacro.getByName("RENDERER_ENABLE_VERTEXCOLOR");
18267
18342
  })();
18268
18343
  __decorate$1([
18269
18344
  ignoreClone
@@ -20739,7 +20814,7 @@
20739
20814
  var sunLightIndex = lightManager._getSunLightIndex();
20740
20815
  if (sunLightIndex !== -1) {
20741
20816
  var sunlight = lightManager._directLights.get(sunLightIndex);
20742
- shaderData.setColor(Scene._sunlightColorProperty, sunlight.color);
20817
+ shaderData.setColor(Scene._sunlightColorProperty, sunlight._getLightIntensityColor());
20743
20818
  shaderData.setVector3(Scene._sunlightDirectionProperty, sunlight.direction);
20744
20819
  this._sunLight = sunlight;
20745
20820
  }
@@ -24960,8 +25035,10 @@
24960
25035
  if (name === void 0) name = null;
24961
25036
  var _this;
24962
25037
  _this = ReferResource.call(this, engine) || this;
24963
- _this._width = undefined;
24964
- _this._height = undefined;
25038
+ _this._automaticWidth = 0;
25039
+ _this._automaticHeight = 0;
25040
+ _this._customWidth = undefined;
25041
+ _this._customHeight = undefined;
24965
25042
  _this._positions = [
24966
25043
  new Vector2(),
24967
25044
  new Vector2(),
@@ -24982,7 +25059,7 @@
24982
25059
  _this._region = new Rect(0, 0, 1, 1);
24983
25060
  _this._pivot = new Vector2(0.5, 0.5);
24984
25061
  _this._border = new Vector4(0, 0, 0, 0);
24985
- _this._dirtyUpdateFlag = 0x3;
25062
+ _this._dirtyUpdateFlag = 0x7;
24986
25063
  /** @internal */ _this._updateFlagManager = new UpdateFlagManager();
24987
25064
  _this._texture = texture;
24988
25065
  region && _this._region.copyFrom(region);
@@ -25031,9 +25108,12 @@
25031
25108
  if (this._texture) {
25032
25109
  var _this = this, _texture = _this._texture, _atlasRegion = _this._atlasRegion, _atlasRegionOffset = _this._atlasRegionOffset, _region = _this._region;
25033
25110
  var pixelsPerUnitReciprocal = 1.0 / Engine._pixelsPerUnit;
25034
- this._width = _texture.width * _atlasRegion.width / (1 - _atlasRegionOffset.x - _atlasRegionOffset.z) * _region.width * pixelsPerUnitReciprocal;
25035
- this._height = _texture.height * _atlasRegion.height / (1 - _atlasRegionOffset.y - _atlasRegionOffset.w) * _region.height * pixelsPerUnitReciprocal;
25111
+ this._automaticWidth = _texture.width * _atlasRegion.width / (1 - _atlasRegionOffset.x - _atlasRegionOffset.z) * _region.width * pixelsPerUnitReciprocal;
25112
+ this._automaticHeight = _texture.height * _atlasRegion.height / (1 - _atlasRegionOffset.y - _atlasRegionOffset.w) * _region.height * pixelsPerUnitReciprocal;
25113
+ } else {
25114
+ this._automaticWidth = this._automaticHeight = 0;
25036
25115
  }
25116
+ this._dirtyUpdateFlag &= ~0x4;
25037
25117
  };
25038
25118
  _proto._updatePositions = function _updatePositions() {
25039
25119
  var blank = this._atlasRegionOffset;
@@ -25087,11 +25167,16 @@
25087
25167
  };
25088
25168
  _proto._dispatchSpriteChange = function _dispatchSpriteChange(type) {
25089
25169
  switch(type){
25170
+ case SpriteModifyFlags.texture:
25171
+ this._dirtyUpdateFlag |= 0x4;
25172
+ break;
25090
25173
  case SpriteModifyFlags.atlasRegionOffset:
25091
25174
  case SpriteModifyFlags.region:
25092
- this._dirtyUpdateFlag |= 0x3;
25175
+ this._dirtyUpdateFlag |= 0x7;
25093
25176
  break;
25094
25177
  case SpriteModifyFlags.atlasRegion:
25178
+ this._dirtyUpdateFlag |= 0x4 | 0x2;
25179
+ break;
25095
25180
  case SpriteModifyFlags.border:
25096
25181
  this._dirtyUpdateFlag |= 0x2;
25097
25182
  break;
@@ -25110,7 +25195,9 @@
25110
25195
  if (this._texture !== value) {
25111
25196
  this._texture = value;
25112
25197
  this._dispatchSpriteChange(SpriteModifyFlags.texture);
25113
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
25198
+ if (this._customWidth === undefined || this._customHeight === undefined) {
25199
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
25200
+ }
25114
25201
  }
25115
25202
  }
25116
25203
  },
@@ -25118,13 +25205,21 @@
25118
25205
  key: "width",
25119
25206
  get: /**
25120
25207
  * The width of the sprite (in world coordinates).
25208
+ *
25209
+ * @remarks
25210
+ * If width is set, return the set value,
25211
+ * otherwise return the width calculated according to `Texture.width`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
25121
25212
  */ function get() {
25122
- this._width === undefined && this._calDefaultSize();
25123
- return this._width;
25213
+ if (this._customWidth !== undefined) {
25214
+ return this._customWidth;
25215
+ } else {
25216
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
25217
+ return this._automaticWidth;
25218
+ }
25124
25219
  },
25125
25220
  set: function set(value) {
25126
- if (this._width !== value) {
25127
- this._width = value;
25221
+ if (this._customWidth !== value) {
25222
+ this._customWidth = value;
25128
25223
  this._dispatchSpriteChange(SpriteModifyFlags.size);
25129
25224
  }
25130
25225
  }
@@ -25133,13 +25228,21 @@
25133
25228
  key: "height",
25134
25229
  get: /**
25135
25230
  * The height of the sprite (in world coordinates).
25231
+ *
25232
+ * @remarks
25233
+ * If height is set, return the set value,
25234
+ * otherwise return the height calculated according to `Texture.height`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
25136
25235
  */ function get() {
25137
- this._height === undefined && this._calDefaultSize();
25138
- return this._height;
25236
+ if (this._customHeight !== undefined) {
25237
+ return this._customHeight;
25238
+ } else {
25239
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
25240
+ return this._automaticHeight;
25241
+ }
25139
25242
  },
25140
25243
  set: function set(value) {
25141
- if (this._height !== value) {
25142
- this._height = value;
25244
+ if (this._customHeight !== value) {
25245
+ this._customHeight = value;
25143
25246
  this._dispatchSpriteChange(SpriteModifyFlags.size);
25144
25247
  }
25145
25248
  }
@@ -25169,7 +25272,9 @@
25169
25272
  var y = MathUtil$1.clamp(value.y, 0, 1);
25170
25273
  this._atlasRegion.set(x, y, MathUtil$1.clamp(value.width, 0, 1 - x), MathUtil$1.clamp(value.height, 0, 1 - y));
25171
25274
  this._dispatchSpriteChange(SpriteModifyFlags.atlasRegion);
25172
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
25275
+ if (this._customWidth === undefined || this._customHeight === undefined) {
25276
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
25277
+ }
25173
25278
  }
25174
25279
  },
25175
25280
  {
@@ -25184,7 +25289,9 @@
25184
25289
  var y = MathUtil$1.clamp(value.y, 0, 1);
25185
25290
  this._atlasRegionOffset.set(x, y, MathUtil$1.clamp(value.z, 0, 1 - x), MathUtil$1.clamp(value.w, 0, 1 - y));
25186
25291
  this._dispatchSpriteChange(SpriteModifyFlags.atlasRegionOffset);
25187
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
25292
+ if (this._customWidth === undefined || this._customHeight === undefined) {
25293
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
25294
+ }
25188
25295
  }
25189
25296
  },
25190
25297
  {
@@ -25200,7 +25307,9 @@
25200
25307
  var y = MathUtil$1.clamp(value.y, 0, 1);
25201
25308
  region.set(x, y, MathUtil$1.clamp(value.width, 0, 1 - x), MathUtil$1.clamp(value.height, 0, 1 - y));
25202
25309
  this._dispatchSpriteChange(SpriteModifyFlags.region);
25203
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
25310
+ if (this._customWidth === undefined || this._customHeight === undefined) {
25311
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
25312
+ }
25204
25313
  }
25205
25314
  },
25206
25315
  {
@@ -25250,7 +25359,8 @@
25250
25359
  (function(SpriteUpdateFlags) {
25251
25360
  SpriteUpdateFlags[SpriteUpdateFlags["positions"] = 0x1] = "positions";
25252
25361
  SpriteUpdateFlags[SpriteUpdateFlags["uvs"] = 0x2] = "uvs";
25253
- SpriteUpdateFlags[SpriteUpdateFlags["all"] = 0x3] = "all";
25362
+ SpriteUpdateFlags[SpriteUpdateFlags["automaticSize"] = 0x4] = "automaticSize";
25363
+ SpriteUpdateFlags[SpriteUpdateFlags["all"] = 0x7] = "all";
25254
25364
  })(SpriteUpdateFlags || (SpriteUpdateFlags = {}));
25255
25365
  var _SlicedSpriteAssembler;
25256
25366
  var SlicedSpriteAssembler = (_SlicedSpriteAssembler = /*#__PURE__*/ function() {
@@ -25738,8 +25848,10 @@
25738
25848
  _this._tiledAdaptiveThreshold = 0.5;
25739
25849
  _this._color = new Color$1(1, 1, 1, 1);
25740
25850
  _this._sprite = null;
25741
- _this._width = undefined;
25742
- _this._height = undefined;
25851
+ _this._automaticWidth = 0;
25852
+ _this._automaticHeight = 0;
25853
+ _this._customWidth = undefined;
25854
+ _this._customHeight = undefined;
25743
25855
  _this._flipX = false;
25744
25856
  _this._flipY = false;
25745
25857
  _this._maskLayer = exports.SpriteMaskLayer.Layer0;
@@ -25757,6 +25869,7 @@
25757
25869
  */ _proto._cloneTo = function _cloneTo(target) {
25758
25870
  target._assembler.resetData(target);
25759
25871
  target.sprite = this._sprite;
25872
+ target.drawMode = this._drawMode;
25760
25873
  };
25761
25874
  /**
25762
25875
  * @internal
@@ -25767,12 +25880,11 @@
25767
25880
  /**
25768
25881
  * @internal
25769
25882
  */ _proto._updateBounds = function _updateBounds(worldBounds) {
25770
- var _this_sprite;
25771
- if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
25883
+ if (this.sprite) {
25884
+ this._assembler.updatePositions(this);
25885
+ } else {
25772
25886
  worldBounds.min.set(0, 0, 0);
25773
25887
  worldBounds.max.set(0, 0, 0);
25774
- } else {
25775
- this._assembler.updatePositions(this);
25776
25888
  }
25777
25889
  };
25778
25890
  /**
@@ -25782,17 +25894,17 @@
25782
25894
  if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
25783
25895
  return;
25784
25896
  }
25785
- // Update position.
25897
+ // Update position
25786
25898
  if (this._dirtyUpdateFlag & RendererUpdateFlags.WorldVolume) {
25787
25899
  this._assembler.updatePositions(this);
25788
25900
  this._dirtyUpdateFlag &= ~RendererUpdateFlags.WorldVolume;
25789
25901
  }
25790
- // Update uv.
25902
+ // Update uv
25791
25903
  if (this._dirtyUpdateFlag & 0x2) {
25792
25904
  this._assembler.updateUVs(this);
25793
25905
  this._dirtyUpdateFlag &= ~0x2;
25794
25906
  }
25795
- // Push render data
25907
+ // Push primitive
25796
25908
  var material = this.getMaterial();
25797
25909
  var texture = this.sprite.texture;
25798
25910
  var renderData = this._engine._spriteRenderDataPool.getFromPool();
@@ -25810,6 +25922,16 @@
25810
25922
  this._assembler = null;
25811
25923
  this._verticesData = null;
25812
25924
  };
25925
+ _proto._calDefaultSize = function _calDefaultSize() {
25926
+ var sprite = this._sprite;
25927
+ if (sprite) {
25928
+ this._automaticWidth = sprite.width;
25929
+ this._automaticHeight = sprite.height;
25930
+ } else {
25931
+ this._automaticWidth = this._automaticHeight = 0;
25932
+ }
25933
+ this._dirtyUpdateFlag &= ~0x4;
25934
+ };
25813
25935
  _proto._updateStencilState = function _updateStencilState() {
25814
25936
  // Update stencil.
25815
25937
  var material = this.getInstanceMaterial();
@@ -25836,22 +25958,21 @@
25836
25958
  break;
25837
25959
  case SpriteModifyFlags.size:
25838
25960
  var _this = this, drawMode = _this._drawMode;
25839
- if (drawMode === exports.SpriteDrawMode.Sliced) {
25961
+ this._dirtyUpdateFlag |= 0x4;
25962
+ if (this._drawMode === exports.SpriteDrawMode.Sliced) {
25840
25963
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
25841
25964
  } else if (drawMode === exports.SpriteDrawMode.Tiled) {
25842
25965
  this._dirtyUpdateFlag |= 0x3;
25843
25966
  } else {
25844
25967
  // When the width and height of `SpriteRenderer` are `undefined`,
25845
25968
  // the `size` of `Sprite` will affect the position of `SpriteRenderer`.
25846
- if (this._width === undefined || this._height === undefined) {
25969
+ if (this._customWidth === undefined || this._customHeight === undefined) {
25847
25970
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
25848
25971
  }
25849
25972
  }
25850
25973
  break;
25851
25974
  case SpriteModifyFlags.border:
25852
- if (this._drawMode === exports.SpriteDrawMode.Sliced || this._drawMode === exports.SpriteDrawMode.Tiled) {
25853
- this._dirtyUpdateFlag |= 0x3;
25854
- }
25975
+ this._drawMode === exports.SpriteDrawMode.Sliced && (this._dirtyUpdateFlag |= 0x3);
25855
25976
  break;
25856
25977
  case SpriteModifyFlags.region:
25857
25978
  case SpriteModifyFlags.atlasRegionOffset:
@@ -25936,9 +26057,9 @@
25936
26057
  var lastSprite = this._sprite;
25937
26058
  if (lastSprite !== value) {
25938
26059
  lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
26060
+ this._dirtyUpdateFlag |= 0x7;
25939
26061
  if (value) {
25940
26062
  value._updateFlagManager.addListener(this._onSpriteChange);
25941
- this._dirtyUpdateFlag |= 0x3;
25942
26063
  this.shaderData.setTexture(SpriteRenderer._textureProperty, value.texture);
25943
26064
  } else {
25944
26065
  this.shaderData.setTexture(SpriteRenderer._textureProperty, null);
@@ -25963,16 +26084,22 @@
25963
26084
  {
25964
26085
  key: "width",
25965
26086
  get: /**
25966
- * Render width.
26087
+ * Render width (in world coordinates).
26088
+ *
26089
+ * @remarks
26090
+ * If width is set, return the set value,
26091
+ * otherwise return `SpriteRenderer.sprite.width`.
25967
26092
  */ function get() {
25968
- this._width === undefined && this._sprite && (this.width = this._sprite.width);
25969
- return this._width;
26093
+ if (this._customWidth !== undefined) {
26094
+ return this._customWidth;
26095
+ } else {
26096
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
26097
+ return this._automaticWidth;
26098
+ }
25970
26099
  },
25971
26100
  set: function set(value) {
25972
- // Update width if undefined
25973
- this._width === undefined && this._sprite && (this._width = this._sprite.width);
25974
- if (this._width !== value) {
25975
- this._width = value;
26101
+ if (this._customWidth !== value) {
26102
+ this._customWidth = value;
25976
26103
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
25977
26104
  }
25978
26105
  }
@@ -25980,16 +26107,22 @@
25980
26107
  {
25981
26108
  key: "height",
25982
26109
  get: /**
25983
- * Render height.
26110
+ * Render height (in world coordinates).
26111
+ *
26112
+ * @remarks
26113
+ * If height is set, return the set value,
26114
+ * otherwise return `SpriteRenderer.sprite.height`.
25984
26115
  */ function get() {
25985
- this._height === undefined && this._sprite && (this.height = this._sprite.height);
25986
- return this._height;
26116
+ if (this._customHeight !== undefined) {
26117
+ return this._customHeight;
26118
+ } else {
26119
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
26120
+ return this._automaticHeight;
26121
+ }
25987
26122
  },
25988
26123
  set: function set(value) {
25989
- // Update height if undefined
25990
- this._height === undefined && this._sprite && (this._height = this._sprite.height);
25991
- if (this._height !== value) {
25992
- this._height = value;
26124
+ if (this._customHeight !== value) {
26125
+ this._customHeight = value;
25993
26126
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
25994
26127
  }
25995
26128
  }
@@ -26076,10 +26209,16 @@
26076
26209
  ], SpriteRenderer.prototype, "_sprite", void 0);
26077
26210
  __decorate$1([
26078
26211
  ignoreClone
26079
- ], SpriteRenderer.prototype, "_width", void 0);
26212
+ ], SpriteRenderer.prototype, "_automaticWidth", void 0);
26080
26213
  __decorate$1([
26081
26214
  ignoreClone
26082
- ], SpriteRenderer.prototype, "_height", void 0);
26215
+ ], SpriteRenderer.prototype, "_automaticHeight", void 0);
26216
+ __decorate$1([
26217
+ assignmentClone
26218
+ ], SpriteRenderer.prototype, "_customWidth", void 0);
26219
+ __decorate$1([
26220
+ assignmentClone
26221
+ ], SpriteRenderer.prototype, "_customHeight", void 0);
26083
26222
  __decorate$1([
26084
26223
  assignmentClone
26085
26224
  ], SpriteRenderer.prototype, "_flipX", void 0);
@@ -26100,7 +26239,9 @@
26100
26239
  */ SpriteRendererUpdateFlags;
26101
26240
  (function(SpriteRendererUpdateFlags) {
26102
26241
  SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** UV. */ "UV"] = 0x2] = "UV";
26103
- SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** All. */ "All"] = 0x3] = "All";
26242
+ SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** WorldVolume and UV . */ "RenderData"] = 0x3] = "RenderData";
26243
+ SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** Automatic Size. */ "AutomaticSize"] = 0x4] = "AutomaticSize";
26244
+ SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** All. */ "All"] = 0x7] = "All";
26104
26245
  })(SpriteRendererUpdateFlags || (SpriteRendererUpdateFlags = {}));
26105
26246
  /**
26106
26247
  * @internal
@@ -33378,6 +33519,12 @@
33378
33519
  this.vertexBuffers = [];
33379
33520
  this.blendShapes = [];
33380
33521
  };
33522
+ /**
33523
+ * @internal
33524
+ */ var BufferRestoreInfo = function BufferRestoreInfo(buffer, data) {
33525
+ this.buffer = buffer;
33526
+ this.data = data;
33527
+ };
33381
33528
  /**
33382
33529
  * @internal
33383
33530
  */ var BufferDataRestoreInfo = function BufferDataRestoreInfo(main, typeSize, sparseCount, sparseIndices, sparseValues) {
@@ -34713,6 +34860,7 @@
34713
34860
  vertexBuffer = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices.byteLength, exports.BufferUsage.Static);
34714
34861
  vertexBuffer.setData(vertices);
34715
34862
  accessorBuffer.vertexBuffer = vertexBuffer;
34863
+ meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
34716
34864
  }
34717
34865
  mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
34718
34866
  vertexBindingInfos[meshId] = bufferBindIndex++;
@@ -34724,6 +34872,7 @@
34724
34872
  vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
34725
34873
  var vertexBuffer1 = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices.byteLength, exports.BufferUsage.Static);
34726
34874
  vertexBuffer1.setData(vertices);
34875
+ meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
34727
34876
  mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
34728
34877
  vertexBindingInfos[meshId] = bufferBindIndex++;
34729
34878
  }
@@ -34895,14 +35044,7 @@
34895
35044
  camera.enabled = false;
34896
35045
  };
34897
35046
  _proto._createRenderer = function _createRenderer(context, glTFNode, entity) {
34898
- var glTFResource = context.glTFResource, glTF = context.glTF;
34899
- var glTFMeshes = glTF.meshes;
34900
- var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
34901
- var meshID = glTFNode.mesh, skinID = glTFNode.skin;
34902
- var glTFMesh = glTFMeshes[meshID];
34903
- var glTFMeshPrimitives = glTFMesh.primitives;
34904
- var blendShapeWeights = glTFNode.weights || glTFMesh.weights;
34905
- for(var i = 0; i < glTFMeshPrimitives.length; i++){
35047
+ var _loop = function _loop(i) {
34906
35048
  var gltfPrimitive = glTFMeshPrimitives[i];
34907
35049
  var mesh = meshes[meshID][i];
34908
35050
  var renderer = void 0;
@@ -34924,8 +35066,22 @@
34924
35066
  var materialIndex = gltfPrimitive.material;
34925
35067
  var material = (materials == null ? void 0 : materials[materialIndex]) || GLTFSceneParser._getDefaultMaterial(engine);
34926
35068
  renderer.setMaterial(material);
35069
+ // Enable vertex color if mesh has COLOR_0 vertex element
35070
+ mesh.vertexElements.forEach(function(element) {
35071
+ if (element.semantic === "COLOR_0") {
35072
+ renderer.enableVertexColor = true;
35073
+ }
35074
+ });
34927
35075
  GLTFParser.executeExtensionsAdditiveAndParse(gltfPrimitive.extensions, context, renderer, gltfPrimitive);
34928
- }
35076
+ };
35077
+ var glTFResource = context.glTFResource, glTF = context.glTF;
35078
+ var glTFMeshes = glTF.meshes;
35079
+ var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
35080
+ var meshID = glTFNode.mesh, skinID = glTFNode.skin;
35081
+ var glTFMesh = glTFMeshes[meshID];
35082
+ var glTFMeshPrimitives = glTFMesh.primitives;
35083
+ var blendShapeWeights = glTFNode.weights || glTFMesh.weights;
35084
+ for(var i = 0; i < glTFMeshPrimitives.length; i++)_loop(i);
34929
35085
  };
34930
35086
  _proto._createAnimator = function _createAnimator(context) {
34931
35087
  if (!context.hasSkinned && !context.glTFResource.animations) {
@@ -36945,7 +37101,7 @@
36945
37101
  var atlasItem = atlasItems[i];
36946
37102
  if (atlasItem.img) {
36947
37103
  chainPromises.push(resourceManager.load({
36948
- url: atlasItem.img,
37104
+ url: Utils.resolveAbsoluteUrl(item.url, atlasItem.img),
36949
37105
  type: exports.AssetType.Texture2D,
36950
37106
  params: {
36951
37107
  format: format,
@@ -37672,7 +37828,7 @@
37672
37828
  ], GALACEAN_animation_event);
37673
37829
 
37674
37830
  //@ts-ignore
37675
- var version = "1.0.0-beta.7";
37831
+ var version = "1.0.0-beta.9";
37676
37832
  console.log("Galacean engine version: " + version);
37677
37833
  for(var key in CoreObjects){
37678
37834
  Loader.registerClass(key, CoreObjects[key]);