@galacean/engine-core 1.3.0-alpha.1 → 1.3.0-alpha.2

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.
Files changed (42) hide show
  1. package/dist/main.js +131 -57
  2. package/dist/main.js.map +1 -1
  3. package/dist/miniprogram.js +131 -57
  4. package/dist/module.js +132 -58
  5. package/dist/module.js.map +1 -1
  6. package/package.json +3 -3
  7. package/types/Camera.d.ts +7 -4
  8. package/types/enums/ReplacementFailureStrategy.d.ts +9 -0
  9. package/types/index.d.ts +1 -0
  10. package/types/shader/ShaderPass.d.ts +10 -0
  11. package/types/shader/index.d.ts +1 -0
  12. package/types/shaderlib/ShaderFactory.d.ts +2 -1
  13. package/types/2d/assembler/IAssembler.d.ts +0 -1
  14. package/types/2d/data/VertexData2D.d.ts +0 -1
  15. package/types/2d/text/CharRenderData.d.ts +0 -1
  16. package/types/2d/text/CharRenderDataPool.d.ts +0 -1
  17. package/types/Deprecated.d.ts +0 -101
  18. package/types/RenderPipeline/Basic2DBatcher.d.ts +0 -19
  19. package/types/RenderPipeline/Chunk.d.ts +0 -1
  20. package/types/RenderPipeline/ClassPool.d.ts +0 -19
  21. package/types/RenderPipeline/DynamicGeometryData.d.ts +0 -1
  22. package/types/RenderPipeline/DynamicGeometryDataManager.d.ts +0 -1
  23. package/types/RenderPipeline/IPoolElement.d.ts +0 -3
  24. package/types/RenderPipeline/RenderData.d.ts +0 -14
  25. package/types/RenderPipeline/RenderData2D.d.ts +0 -14
  26. package/types/RenderPipeline/RenderPass.d.ts +0 -55
  27. package/types/RenderPipeline/SpriteBatcher.d.ts +0 -1
  28. package/types/RenderPipeline/SpriteMaskBatcher.d.ts +0 -11
  29. package/types/RenderPipeline/SpriteMaskManager.d.ts +0 -1
  30. package/types/RenderPipeline/SpriteMaskRenderData.d.ts +0 -12
  31. package/types/RenderPipeline/SpriteRenderData.d.ts +0 -14
  32. package/types/RenderPipeline/TextRenderData.d.ts +0 -8
  33. package/types/RenderPipeline/batcher/MeshBuffer.d.ts +0 -1
  34. package/types/RenderPipeline/enums/ForceUploadShaderDataFlag.d.ts +0 -15
  35. package/types/RenderPipeline/enums/RenderBufferStoreAction.d.ts +0 -13
  36. package/types/RenderPipeline/enums/RenderDataUsage.d.ts +0 -13
  37. package/types/animation/AnimatorTransition.d.ts +0 -14
  38. package/types/postProcess/PostProcessEffect.d.ts +0 -13
  39. package/types/postProcess/PostProcessPass.d.ts +0 -55
  40. package/types/renderingHardwareInterface/IHardwareRenderer.d.ts +0 -6
  41. package/types/texture/enums/PixelFormat.d.ts +0 -73
  42. package/types/utils/Pool.d.ts +0 -12
package/dist/main.js CHANGED
@@ -2994,6 +2994,12 @@ exports.RenderStateDataKey = void 0;
2994
2994
  StencilOperation[StencilOperation[/** Decrements the current stencil buffer value. Wraps stencil buffer value to the maximum representable unsigned value when decrementing a stencil buffer value of 0. */ "DecrementWrap"] = 7] = "DecrementWrap";
2995
2995
  })(exports.StencilOperation || (exports.StencilOperation = {}));
2996
2996
 
2997
+ exports.ShaderPlatformTarget = void 0;
2998
+ (function(ShaderPlatformTarget) {
2999
+ ShaderPlatformTarget[ShaderPlatformTarget["GLES100"] = 0] = "GLES100";
3000
+ ShaderPlatformTarget[ShaderPlatformTarget["GLES300"] = 1] = "GLES300";
3001
+ })(exports.ShaderPlatformTarget || (exports.ShaderPlatformTarget = {}));
3002
+
2997
3003
  /**
2998
3004
  * Shader macro。
2999
3005
  */ var ShaderMacro = /*#__PURE__*/ function() {
@@ -3023,14 +3029,14 @@ exports.RenderStateDataKey = void 0;
3023
3029
  maskMap.length++;
3024
3030
  maskMap[index] = new Array(32);
3025
3031
  }
3026
- maskMap[index][bit] = key;
3032
+ maskMap[index][bit] = macro;
3027
3033
  ShaderMacro._macroCounter++;
3028
3034
  }
3029
3035
  return macro;
3030
3036
  };
3031
3037
  /**
3032
3038
  * @internal
3033
- */ ShaderMacro._getNamesByMacros = function _getNamesByMacros(macros, out) {
3039
+ */ ShaderMacro._getMacrosElements = function _getMacrosElements(macros, out) {
3034
3040
  var maskMap = ShaderMacro._macroMaskMap;
3035
3041
  var mask = macros._mask;
3036
3042
  out.length = 0;
@@ -3213,15 +3219,6 @@ exports.RenderStateDataKey = void 0;
3213
3219
  return ShaderMacroCollection;
3214
3220
  }();
3215
3221
 
3216
- /**
3217
- * Pipeline stage.
3218
- */ exports.PipelineStage = void 0;
3219
- (function(PipelineStage) {
3220
- PipelineStage[/** DepthOnly stage. */ "DepthOnly"] = "DepthOnly";
3221
- PipelineStage[/** Shadow caster stage. */ "ShadowCaster"] = "ShadowCaster";
3222
- PipelineStage[/** Forward shading stage. */ "Forward"] = "Forward";
3223
- })(exports.PipelineStage || (exports.PipelineStage = {}));
3224
-
3225
3222
  function _extends() {
3226
3223
  _extends = Object.assign || function assign(target) {
3227
3224
  for (var i = 1; i < arguments.length; i++) {
@@ -3235,6 +3232,15 @@ function _extends() {
3235
3232
  return _extends.apply(this, arguments);
3236
3233
  }
3237
3234
 
3235
+ /**
3236
+ * Pipeline stage.
3237
+ */ exports.PipelineStage = void 0;
3238
+ (function(PipelineStage) {
3239
+ PipelineStage[/** DepthOnly stage. */ "DepthOnly"] = "DepthOnly";
3240
+ PipelineStage[/** Shadow caster stage. */ "ShadowCaster"] = "ShadowCaster";
3241
+ PipelineStage[/** Forward shading stage. */ "Forward"] = "Forward";
3242
+ })(exports.PipelineStage || (exports.PipelineStage = {}));
3243
+
3238
3244
  var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;uniform vec3 camera_Forward;uniform vec4 camera_ProjectionParams;"; // eslint-disable-line
3239
3245
 
3240
3246
  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);}uniform vec4 camera_DepthBufferParams;float remapDepthBufferLinear01(float z){return 1.0/(camera_DepthBufferParams.x*z+camera_DepthBufferParams.y);}\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
@@ -3329,7 +3335,7 @@ var brdf = "#define GLSLIFY 1\nfloat F_Schlick(float f0,float dotLH){return f0+0
3329
3335
 
3330
3336
  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,geometry.clearCoatNormal,vec3(0.04),material.clearCoatRoughness);attenuation-=material.clearCoat*F_Schlick(material.f0,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,geometry.normal,material.specularColor,material.roughness);reflectedLight.directDiffuse+=attenuation*irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);}\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nvoid addDirectionalDirectLightRadiance(DirectLight directionalLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 color=directionalLight.color;vec3 direction=-directionalLight.direction;addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nvoid addPointDirectLightRadiance(PointLight pointLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 lVector=pointLight.position-geometry.position;vec3 direction=normalize(lVector);float lightDistance=length(lVector);vec3 color=pointLight.color;color*=clamp(1.0-pow(lightDistance/pointLight.distance,4.0),0.0,1.0);addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nvoid addSpotDirectLightRadiance(SpotLight spotLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 lVector=spotLight.position-geometry.position;vec3 direction=normalize(lVector);float lightDistance=length(lVector);float angleCos=dot(direction,-spotLight.direction);float spotEffect=smoothstep(spotLight.penumbraCos,spotLight.angleCos,angleCos);float decayEffect=clamp(1.0-pow(lightDistance/spotLight.distance,4.0),0.0,1.0);vec3 color=spotLight.color;color*=spotEffect*decayEffect;addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\nvoid addTotalDirectRadiance(Geometry geometry,Material material,inout ReflectedLight reflectedLight){float shadowAttenuation=1.0;\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nshadowAttenuation=1.0;\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nshadowAttenuation*=sampleShadowMap();\n#endif\nDirectLight directionalLight;for(int i=0;i<SCENE_DIRECT_LIGHT_COUNT;i++){if(!isRendererCulledByLight(renderer_Layer.xy,scene_DirectLightCullingMask[i])){directionalLight.color=scene_DirectLightColor[i];\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nif(i==0){directionalLight.color*=shadowAttenuation;}\n#endif\ndirectionalLight.direction=scene_DirectLightDirection[i];addDirectionalDirectLightRadiance(directionalLight,geometry,material,reflectedLight);}}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nPointLight pointLight;for(int i=0;i<SCENE_POINT_LIGHT_COUNT;i++){if(!isRendererCulledByLight(renderer_Layer.xy,scene_PointLightCullingMask[i])){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])){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
3331
3337
 
3332
- 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 getReflectedVector(Geometry geometry,vec3 n){\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nvec3 r=reflect(-geometry.viewDir,geometry.anisotropicN);\n#else\nvec3 r=reflect(-geometry.viewDir,n);\n#endif\nreturn r;}vec3 getLightProbeRadiance(Geometry geometry,vec3 normal,float roughness,int maxMIPLevel,float specularIntensity){\n#ifndef SCENE_USE_SPECULAR_ENV\nreturn vec3(0);\n#else\nvec3 reflectVec=getReflectedVector(geometry,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
3338
+ 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 max(specularColor*AB.x+AB.y,0.0);}float getSpecularMIPLevel(float roughness,int maxMIPLevel){return roughness*float(maxMIPLevel);}vec3 getReflectedVector(Geometry geometry,vec3 n){\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nvec3 r=reflect(-geometry.viewDir,geometry.anisotropicN);\n#else\nvec3 r=reflect(-geometry.viewDir,n);\n#endif\nreturn r;}vec3 getLightProbeRadiance(Geometry geometry,vec3 normal,float roughness,int maxMIPLevel,float specularIntensity){\n#ifndef SCENE_USE_SPECULAR_ENV\nreturn vec3(0);\n#else\nvec3 reflectVec=getReflectedVector(geometry,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
3333
3339
 
3334
3340
  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,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,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(material.f0,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
3335
3341
 
@@ -3450,7 +3456,7 @@ var ShaderFactory = /*#__PURE__*/ function() {
3450
3456
  function ShaderFactory() {}
3451
3457
  ShaderFactory.parseCustomMacros = function parseCustomMacros(macros) {
3452
3458
  return macros.map(function(m) {
3453
- return "#define " + m + "\n";
3459
+ return "#define " + (m.value ? m.name + " " + m.value : m.name) + "\n";
3454
3460
  }).join("");
3455
3461
  };
3456
3462
  ShaderFactory.registerInclude = function registerInclude(includeName, includeSource) {
@@ -4235,29 +4241,49 @@ var ShaderFactory = /*#__PURE__*/ function() {
4235
4241
  ShaderProgram._counter = 0;
4236
4242
  })();
4237
4243
 
4244
+ /**
4245
+ * @internal
4246
+ * Shader pass type
4247
+ */ var ShaderType;
4248
+ (function(ShaderType) {
4249
+ ShaderType[ShaderType[/** init by glsl */ "Canonical"] = 0] = "Canonical";
4250
+ ShaderType[ShaderType[/** init by shader-lab */ "ShaderLab"] = 1] = "ShaderLab";
4251
+ })(ShaderType || (ShaderType = {}));
4252
+
4238
4253
  /**
4239
4254
  * Shader pass containing vertex and fragment source.
4240
4255
  */ var ShaderPass = /*#__PURE__*/ function(ShaderPart1) {
4241
4256
  _inherits(ShaderPass, ShaderPart1);
4242
- function ShaderPass(nameOrVertexSource, vertexSourceOrFragmentSource, fragmentSourceOrTags, tags) {
4257
+ function ShaderPass(nameOrVertexSource, vertexSourceOrFragmentSourceOrCode, fragmentSourceOrTagsOrVertexEntry, fragmentEntryOrTags, tags) {
4243
4258
  var _this;
4244
4259
  _this = ShaderPart1.call(this) || this;
4245
4260
  /** @internal */ _this._shaderPassId = 0;
4246
4261
  /** @internal */ _this._renderStateDataMap = {};
4247
4262
  /** @internal */ _this._shaderProgramPools = [];
4263
+ _this._platformMacros = [];
4248
4264
  _this._shaderPassId = ShaderPass._shaderPassCounter++;
4249
- if (typeof fragmentSourceOrTags === "string") {
4265
+ _this._type = ShaderType.Canonical;
4266
+ if (typeof fragmentEntryOrTags === "string") {
4267
+ _this._name = nameOrVertexSource;
4268
+ _this._shaderLabSource = vertexSourceOrFragmentSourceOrCode;
4269
+ _this._vertexEntry = fragmentSourceOrTagsOrVertexEntry;
4270
+ _this._fragmentEntry = fragmentEntryOrTags;
4271
+ tags = _extends({
4272
+ pipelineStage: exports.PipelineStage.Forward
4273
+ }, tags);
4274
+ _this._type = ShaderType.ShaderLab;
4275
+ } else if (typeof fragmentSourceOrTagsOrVertexEntry === "string") {
4250
4276
  _this._name = nameOrVertexSource;
4251
- _this._vertexSource = vertexSourceOrFragmentSource;
4252
- _this._fragmentSource = fragmentSourceOrTags;
4253
- tags = tags != null ? tags : {
4277
+ _this._vertexSource = vertexSourceOrFragmentSourceOrCode;
4278
+ _this._fragmentSource = fragmentSourceOrTagsOrVertexEntry;
4279
+ tags = fragmentEntryOrTags != null ? fragmentEntryOrTags : {
4254
4280
  pipelineStage: exports.PipelineStage.Forward
4255
4281
  };
4256
4282
  } else {
4257
4283
  _this._name = "Default";
4258
4284
  _this._vertexSource = nameOrVertexSource;
4259
- _this._fragmentSource = vertexSourceOrFragmentSource;
4260
- tags = fragmentSourceOrTags != null ? fragmentSourceOrTags : {
4285
+ _this._fragmentSource = vertexSourceOrFragmentSourceOrCode;
4286
+ tags = fragmentSourceOrTagsOrVertexEntry != null ? fragmentSourceOrTagsOrVertexEntry : {
4261
4287
  pipelineStage: exports.PipelineStage.Forward
4262
4288
  };
4263
4289
  }
@@ -4275,9 +4301,51 @@ var ShaderFactory = /*#__PURE__*/ function() {
4275
4301
  if (shaderProgram) {
4276
4302
  return shaderProgram;
4277
4303
  }
4304
+ if (this._type === ShaderType.Canonical) {
4305
+ shaderProgram = this._getCanonicalShaderProgram(engine, macroCollection);
4306
+ } else {
4307
+ shaderProgram = this._compileShaderProgram(engine, macroCollection, this._vertexEntry, this._fragmentEntry);
4308
+ }
4309
+ shaderProgramPool.cache(shaderProgram);
4310
+ return shaderProgram;
4311
+ };
4312
+ /**
4313
+ * @internal
4314
+ */ _proto._destroy = function _destroy() {
4315
+ var shaderProgramPools = this._shaderProgramPools;
4316
+ for(var i = 0, n = shaderProgramPools.length; i < n; i++){
4317
+ shaderProgramPools[i]._destroy();
4318
+ }
4319
+ shaderProgramPools.length = 0;
4320
+ };
4321
+ /**
4322
+ * Shader Lab compilation
4323
+ */ _proto._compileShaderProgram = function _compileShaderProgram(engine, macroCollection, vertexEntry, fragmentEntry) {
4324
+ var isWebGL2 = engine._hardwareRenderer.isWebGL2;
4325
+ var macros = new Array();
4326
+ ShaderMacro._getMacrosElements(macroCollection, macros);
4327
+ this._platformMacros.length = 0;
4328
+ if (engine._hardwareRenderer.canIUse(exports.GLCapabilityType.shaderTextureLod)) {
4329
+ this._platformMacros.push("HAS_TEX_LOD");
4330
+ }
4331
+ if (engine._hardwareRenderer.canIUse(exports.GLCapabilityType.standardDerivatives)) {
4332
+ this._platformMacros.push("HAS_DERIVATIVES");
4333
+ }
4334
+ if (isWebGL2) {
4335
+ this._platformMacros.push("GRAPHICS_API_WEBGL2");
4336
+ } else {
4337
+ this._platformMacros.push("GRAPHICS_API_WEBGL1");
4338
+ }
4339
+ var start = performance.now();
4340
+ var _Shader__shaderLab__parseShaderPass = Shader._shaderLab._parseShaderPass(this._shaderLabSource, vertexEntry, fragmentEntry, macros, isWebGL2 ? exports.ShaderPlatformTarget.GLES300 : exports.ShaderPlatformTarget.GLES100, this._platformMacros), vertex = _Shader__shaderLab__parseShaderPass.vertex, fragment = _Shader__shaderLab__parseShaderPass.fragment;
4341
+ Logger.info("[ShaderLab compilation] cost time: " + (performance.now() - start) + "ms");
4342
+ return new ShaderProgram(engine, vertex, fragment);
4343
+ };
4344
+ // TODO: remove it after migrate all shader to `ShaderLab`.
4345
+ _proto._getCanonicalShaderProgram = function _getCanonicalShaderProgram(engine, macroCollection) {
4278
4346
  var isWebGL2 = engine._hardwareRenderer.isWebGL2;
4279
- var macroNameList = [];
4280
- ShaderMacro._getNamesByMacros(macroCollection, macroNameList);
4347
+ var macroNameList = new Array();
4348
+ ShaderMacro._getMacrosElements(macroCollection, macroNameList);
4281
4349
  var macroNameStr = ShaderFactory.parseCustomMacros(macroNameList);
4282
4350
  var versionStr = isWebGL2 ? "#version 300 es" : "#version 100";
4283
4351
  var graphicAPI = isWebGL2 ? "#define GRAPHICS_API_WEBGL2" : "#define GRAPHICS_API_WEBGL1";
@@ -4294,19 +4362,9 @@ var ShaderFactory = /*#__PURE__*/ function() {
4294
4362
  vertexSource = ShaderFactory.convertTo300(vertexSource);
4295
4363
  fragmentSource = ShaderFactory.convertTo300(fragmentSource, true);
4296
4364
  }
4297
- shaderProgram = new ShaderProgram(engine, vertexSource, fragmentSource);
4298
- shaderProgramPool.cache(shaderProgram);
4365
+ var shaderProgram = new ShaderProgram(engine, vertexSource, fragmentSource);
4299
4366
  return shaderProgram;
4300
4367
  };
4301
- /**
4302
- * @internal
4303
- */ _proto._destroy = function _destroy() {
4304
- var shaderProgramPools = this._shaderProgramPools;
4305
- for(var i = 0, n = shaderProgramPools.length; i < n; i++){
4306
- shaderProgramPools[i]._destroy();
4307
- }
4308
- shaderProgramPools.length = 0;
4309
- };
4310
4368
  return ShaderPass;
4311
4369
  }(ShaderPart);
4312
4370
  (function() {
@@ -5010,45 +5068,44 @@ __decorate([
5010
5068
  if (!Shader._shaderLab) {
5011
5069
  throw "ShaderLab has not been set up yet.";
5012
5070
  }
5013
- var shaderInfo = Shader._shaderLab.parseShader(nameOrShaderSource);
5014
- if (shaderMap[shaderInfo.name]) {
5015
- console.error('Shader named "' + shaderInfo.name + '" already exists.');
5071
+ var shaderContent = Shader._shaderLab._parseShaderContent(nameOrShaderSource);
5072
+ if (shaderMap[shaderContent.name]) {
5073
+ console.error('Shader named "' + shaderContent.name + '" already exists.');
5016
5074
  return;
5017
5075
  }
5018
- var subShaderList = shaderInfo.subShaders.map(function(subShaderInfo) {
5019
- var passList = subShaderInfo.passes.map(function(passInfo) {
5020
- if (typeof passInfo === "string") {
5076
+ var subShaderList = shaderContent.subShaders.map(function(subShaderContent) {
5077
+ var passList = subShaderContent.passes.map(function(passInfo) {
5078
+ if (passInfo.isUsePass) {
5021
5079
  var _Shader_find_subShaders_find, _Shader_find;
5022
5080
  // Use pass reference
5023
- var paths = passInfo.split("/");
5081
+ var paths = passInfo.name.split("/");
5024
5082
  return (_Shader_find = Shader.find(paths[0])) == null ? void 0 : (_Shader_find_subShaders_find = _Shader_find.subShaders.find(function(subShader) {
5025
5083
  return subShader.name === paths[1];
5026
5084
  })) == null ? void 0 : _Shader_find_subShaders_find.passes.find(function(pass) {
5027
5085
  return pass.name === paths[2];
5028
5086
  });
5029
5087
  }
5030
- var shaderPass = new ShaderPass(passInfo.name, passInfo.vertexSource, passInfo.fragmentSource, passInfo.tags);
5088
+ var shaderPassContent = new ShaderPass(passInfo.name, passInfo.contents, passInfo.vertexEntry, passInfo.fragmentEntry, passInfo.tags);
5031
5089
  var renderStates = passInfo.renderStates;
5032
5090
  var renderState = new RenderState();
5033
- shaderPass._renderState = renderState;
5091
+ shaderPassContent._renderState = renderState;
5034
5092
  // Parse const render state
5035
- var constRenderStateInfo = renderStates[0];
5036
- for(var k in constRenderStateInfo){
5037
- Shader._applyConstRenderStates(renderState, parseInt(k), constRenderStateInfo[k]);
5093
+ var constantMap = renderStates.constantMap, variableMap = renderStates.variableMap;
5094
+ for(var k in constantMap){
5095
+ Shader._applyConstRenderStates(renderState, parseInt(k), constantMap[k]);
5038
5096
  }
5039
5097
  // Parse variable render state
5040
- var variableRenderStateInfo = renderStates[1];
5041
5098
  var renderStateDataMap = {};
5042
- for(var k1 in variableRenderStateInfo){
5043
- renderStateDataMap[k1] = ShaderProperty.getByName(variableRenderStateInfo[k1]);
5099
+ for(var k1 in variableMap){
5100
+ renderStateDataMap[k1] = ShaderProperty.getByName(variableMap[k1]);
5044
5101
  }
5045
- shaderPass._renderStateDataMap = renderStateDataMap;
5046
- return shaderPass;
5102
+ shaderPassContent._renderStateDataMap = renderStateDataMap;
5103
+ return shaderPassContent;
5047
5104
  });
5048
- return new SubShader(shaderInfo.name, passList, subShaderInfo.tags);
5105
+ return new SubShader(subShaderContent.name, passList, subShaderContent.tags);
5049
5106
  });
5050
- shader = new Shader(shaderInfo.name, subShaderList);
5051
- shaderMap[shaderInfo.name] = shader;
5107
+ shader = new Shader(shaderContent.name, subShaderList);
5108
+ shaderMap[shaderContent.name] = shader;
5052
5109
  return shader;
5053
5110
  } else {
5054
5111
  if (shaderMap[nameOrShaderSource]) {
@@ -8138,6 +8195,14 @@ var /**
8138
8195
  MSAASamples[MSAASamples[/** Multi-sample anti-aliasing with 8 samples. */ "EightX"] = 8] = "EightX";
8139
8196
  })(exports.MSAASamples || (exports.MSAASamples = {}));
8140
8197
 
8198
+ /**
8199
+ * The strategy to use when a shader replacement fails.
8200
+ */ exports.ReplacementFailureStrategy = void 0;
8201
+ (function(ReplacementFailureStrategy) {
8202
+ ReplacementFailureStrategy[ReplacementFailureStrategy[/** Keep the original shader. */ "KeepOriginalShader"] = 0] = "KeepOriginalShader";
8203
+ ReplacementFailureStrategy[ReplacementFailureStrategy[/** Do not render. */ "DoNotRender"] = 1] = "DoNotRender";
8204
+ })(exports.ReplacementFailureStrategy || (exports.ReplacementFailureStrategy = {}));
8205
+
8141
8206
  var _Camera;
8142
8207
  var MathTemp = function MathTemp() {
8143
8208
  };
@@ -8187,6 +8252,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
8187
8252
  /** @internal */ _this._virtualCamera = new VirtualCamera();
8188
8253
  /** @internal */ _this._replacementShader = null;
8189
8254
  /** @internal */ _this._replacementSubShaderTag = null;
8255
+ /** @internal */ _this._replacementFailureStrategy = null;
8190
8256
  /** @internal */ _this._cameraIndex = -1;
8191
8257
  _this._priority = 0;
8192
8258
  _this._shaderData = new ShaderData(ShaderDataGroup.Camera);
@@ -8366,6 +8432,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
8366
8432
  context.virtualCamera = virtualCamera;
8367
8433
  context.replacementShader = this._replacementShader;
8368
8434
  context.replacementTag = this._replacementSubShaderTag;
8435
+ context.replacementFailureStrategy = this._replacementFailureStrategy;
8369
8436
  // compute cull frustum.
8370
8437
  if (this.enableFrustumCulling && this._frustumChangeFlag.flag) {
8371
8438
  this._frustum.calculateFromMatrix(virtualCamera.viewProjectionMatrix);
@@ -8385,15 +8452,18 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
8385
8452
  this._renderPipeline.render(context, cubeFace, mipLevel, clearMask);
8386
8453
  this._engine._renderCount++;
8387
8454
  };
8388
- _proto.setReplacementShader = function setReplacementShader(shader, replacementTag) {
8455
+ _proto.setReplacementShader = function setReplacementShader(shader, replacementTag, failureStrategy) {
8456
+ if (failureStrategy === void 0) failureStrategy = exports.ReplacementFailureStrategy.KeepOriginalShader;
8389
8457
  this._replacementShader = shader;
8390
8458
  this._replacementSubShaderTag = typeof replacementTag === "string" ? ShaderTagKey.getByName(replacementTag) : replacementTag;
8459
+ this._replacementFailureStrategy = failureStrategy;
8391
8460
  };
8392
8461
  /**
8393
8462
  * Reset and clear the replacement shader.
8394
8463
  */ _proto.resetReplacementShader = function resetReplacementShader() {
8395
8464
  this._replacementShader = null;
8396
8465
  this._replacementSubShaderTag = null;
8466
+ this._replacementFailureStrategy = null;
8397
8467
  };
8398
8468
  /**
8399
8469
  * @inheritdoc
@@ -8507,7 +8577,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
8507
8577
  this._checkMainCanvasAntialiasWaste();
8508
8578
  };
8509
8579
  _proto._checkMainCanvasAntialiasWaste = function _checkMainCanvasAntialiasWaste() {
8510
- if (this.independentCanvasEnabled && engineMath.Vector4.equals(this._viewport, PipelineUtils.defaultViewport)) {
8580
+ if (this._phasedActiveInScene && this.independentCanvasEnabled && engineMath.Vector4.equals(this._viewport, PipelineUtils.defaultViewport)) {
8511
8581
  Logger.warn("Camera use independent canvas and viewport cover the whole screen, it is recommended to disable antialias, depth and stencil to save memory when create engine.");
8512
8582
  }
8513
8583
  };
@@ -10201,6 +10271,7 @@ var /**
10201
10271
  break;
10202
10272
  }
10203
10273
  }
10274
+ context.replacementFailureStrategy === exports.ReplacementFailureStrategy.KeepOriginalShader && this.pushRenderElementByType(renderElement, subRenderElement, materialSubShader.passes, renderStates);
10204
10275
  } else {
10205
10276
  this.pushRenderElementByType(renderElement, subRenderElement, replacementSubShaders[0].passes, renderStates);
10206
10277
  }
@@ -23345,7 +23416,7 @@ ShaderPool.init();
23345
23416
  */ _proto._initialize = function _initialize(configuration) {
23346
23417
  var _this = this;
23347
23418
  var shaderLab = configuration.shaderLab, physics = configuration.physics;
23348
- if (shaderLab) {
23419
+ if (shaderLab && !Shader._shaderLab) {
23349
23420
  Shader._shaderLab = shaderLab;
23350
23421
  }
23351
23422
  var initializePromises = new Array();
@@ -25284,6 +25355,9 @@ var TonemappingEffect = /*#__PURE__*/ function() {
25284
25355
  */ var _PostProcessManager = /*#__PURE__*/ function() {
25285
25356
  function _PostProcessManager(scene) {
25286
25357
  this.scene = scene;
25358
+ this./**
25359
+ * Whether the post process manager is active.
25360
+ */ isActive = true;
25287
25361
  var uberShader = Shader.find(_PostProcessManager.UBER_SHADER_NAME);
25288
25362
  var uberMaterial = new Material(scene.engine, uberShader);
25289
25363
  var depthState = uberMaterial.renderState.depthState;
@@ -25317,7 +25391,7 @@ var TonemappingEffect = /*#__PURE__*/ function() {
25317
25391
  get: /**
25318
25392
  * Whether has active post process effect.
25319
25393
  */ function get() {
25320
- return this._bloomEffect.enabled || this._tonemappingEffect.enabled;
25394
+ return this.isActive && (this._bloomEffect.enabled || this._tonemappingEffect.enabled);
25321
25395
  }
25322
25396
  }
25323
25397
  ]);