@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
@@ -2995,6 +2995,12 @@ exports.RenderStateDataKey = void 0;
2995
2995
  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";
2996
2996
  })(exports.StencilOperation || (exports.StencilOperation = {}));
2997
2997
 
2998
+ exports.ShaderPlatformTarget = void 0;
2999
+ (function(ShaderPlatformTarget) {
3000
+ ShaderPlatformTarget[ShaderPlatformTarget["GLES100"] = 0] = "GLES100";
3001
+ ShaderPlatformTarget[ShaderPlatformTarget["GLES300"] = 1] = "GLES300";
3002
+ })(exports.ShaderPlatformTarget || (exports.ShaderPlatformTarget = {}));
3003
+
2998
3004
  /**
2999
3005
  * Shader macro。
3000
3006
  */ var ShaderMacro = /*#__PURE__*/ function() {
@@ -3024,14 +3030,14 @@ exports.RenderStateDataKey = void 0;
3024
3030
  maskMap.length++;
3025
3031
  maskMap[index] = new Array(32);
3026
3032
  }
3027
- maskMap[index][bit] = key;
3033
+ maskMap[index][bit] = macro;
3028
3034
  ShaderMacro._macroCounter++;
3029
3035
  }
3030
3036
  return macro;
3031
3037
  };
3032
3038
  /**
3033
3039
  * @internal
3034
- */ ShaderMacro._getNamesByMacros = function _getNamesByMacros(macros, out) {
3040
+ */ ShaderMacro._getMacrosElements = function _getMacrosElements(macros, out) {
3035
3041
  var maskMap = ShaderMacro._macroMaskMap;
3036
3042
  var mask = macros._mask;
3037
3043
  out.length = 0;
@@ -3214,15 +3220,6 @@ exports.RenderStateDataKey = void 0;
3214
3220
  return ShaderMacroCollection;
3215
3221
  }();
3216
3222
 
3217
- /**
3218
- * Pipeline stage.
3219
- */ exports.PipelineStage = void 0;
3220
- (function(PipelineStage) {
3221
- PipelineStage[/** DepthOnly stage. */ "DepthOnly"] = "DepthOnly";
3222
- PipelineStage[/** Shadow caster stage. */ "ShadowCaster"] = "ShadowCaster";
3223
- PipelineStage[/** Forward shading stage. */ "Forward"] = "Forward";
3224
- })(exports.PipelineStage || (exports.PipelineStage = {}));
3225
-
3226
3223
  function _extends() {
3227
3224
  _extends = Object.assign || function assign(target) {
3228
3225
  for (var i = 1; i < arguments.length; i++) {
@@ -3236,6 +3233,15 @@ function _extends() {
3236
3233
  return _extends.apply(this, arguments);
3237
3234
  }
3238
3235
 
3236
+ /**
3237
+ * Pipeline stage.
3238
+ */ exports.PipelineStage = void 0;
3239
+ (function(PipelineStage) {
3240
+ PipelineStage[/** DepthOnly stage. */ "DepthOnly"] = "DepthOnly";
3241
+ PipelineStage[/** Shadow caster stage. */ "ShadowCaster"] = "ShadowCaster";
3242
+ PipelineStage[/** Forward shading stage. */ "Forward"] = "Forward";
3243
+ })(exports.PipelineStage || (exports.PipelineStage = {}));
3244
+
3239
3245
  var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;uniform vec3 camera_Forward;uniform vec4 camera_ProjectionParams;"; // eslint-disable-line
3240
3246
 
3241
3247
  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
@@ -3330,7 +3336,7 @@ var brdf = "#define GLSLIFY 1\nfloat F_Schlick(float f0,float dotLH){return f0+0
3330
3336
 
3331
3337
  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
3332
3338
 
3333
- 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
3339
+ 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
3334
3340
 
3335
3341
  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
3336
3342
 
@@ -3451,7 +3457,7 @@ var ShaderFactory = /*#__PURE__*/ function() {
3451
3457
  function ShaderFactory() {}
3452
3458
  ShaderFactory.parseCustomMacros = function parseCustomMacros(macros) {
3453
3459
  return macros.map(function(m) {
3454
- return "#define " + m + "\n";
3460
+ return "#define " + (m.value ? m.name + " " + m.value : m.name) + "\n";
3455
3461
  }).join("");
3456
3462
  };
3457
3463
  ShaderFactory.registerInclude = function registerInclude(includeName, includeSource) {
@@ -4236,29 +4242,49 @@ var ShaderFactory = /*#__PURE__*/ function() {
4236
4242
  ShaderProgram._counter = 0;
4237
4243
  })();
4238
4244
 
4245
+ /**
4246
+ * @internal
4247
+ * Shader pass type
4248
+ */ var ShaderType;
4249
+ (function(ShaderType) {
4250
+ ShaderType[ShaderType[/** init by glsl */ "Canonical"] = 0] = "Canonical";
4251
+ ShaderType[ShaderType[/** init by shader-lab */ "ShaderLab"] = 1] = "ShaderLab";
4252
+ })(ShaderType || (ShaderType = {}));
4253
+
4239
4254
  /**
4240
4255
  * Shader pass containing vertex and fragment source.
4241
4256
  */ var ShaderPass = /*#__PURE__*/ function(ShaderPart1) {
4242
4257
  _inherits(ShaderPass, ShaderPart1);
4243
- function ShaderPass(nameOrVertexSource, vertexSourceOrFragmentSource, fragmentSourceOrTags, tags) {
4258
+ function ShaderPass(nameOrVertexSource, vertexSourceOrFragmentSourceOrCode, fragmentSourceOrTagsOrVertexEntry, fragmentEntryOrTags, tags) {
4244
4259
  var _this;
4245
4260
  _this = ShaderPart1.call(this) || this;
4246
4261
  /** @internal */ _this._shaderPassId = 0;
4247
4262
  /** @internal */ _this._renderStateDataMap = {};
4248
4263
  /** @internal */ _this._shaderProgramPools = [];
4264
+ _this._platformMacros = [];
4249
4265
  _this._shaderPassId = ShaderPass._shaderPassCounter++;
4250
- if (typeof fragmentSourceOrTags === "string") {
4266
+ _this._type = ShaderType.Canonical;
4267
+ if (typeof fragmentEntryOrTags === "string") {
4268
+ _this._name = nameOrVertexSource;
4269
+ _this._shaderLabSource = vertexSourceOrFragmentSourceOrCode;
4270
+ _this._vertexEntry = fragmentSourceOrTagsOrVertexEntry;
4271
+ _this._fragmentEntry = fragmentEntryOrTags;
4272
+ tags = _extends({
4273
+ pipelineStage: exports.PipelineStage.Forward
4274
+ }, tags);
4275
+ _this._type = ShaderType.ShaderLab;
4276
+ } else if (typeof fragmentSourceOrTagsOrVertexEntry === "string") {
4251
4277
  _this._name = nameOrVertexSource;
4252
- _this._vertexSource = vertexSourceOrFragmentSource;
4253
- _this._fragmentSource = fragmentSourceOrTags;
4254
- tags = tags != null ? tags : {
4278
+ _this._vertexSource = vertexSourceOrFragmentSourceOrCode;
4279
+ _this._fragmentSource = fragmentSourceOrTagsOrVertexEntry;
4280
+ tags = fragmentEntryOrTags != null ? fragmentEntryOrTags : {
4255
4281
  pipelineStage: exports.PipelineStage.Forward
4256
4282
  };
4257
4283
  } else {
4258
4284
  _this._name = "Default";
4259
4285
  _this._vertexSource = nameOrVertexSource;
4260
- _this._fragmentSource = vertexSourceOrFragmentSource;
4261
- tags = fragmentSourceOrTags != null ? fragmentSourceOrTags : {
4286
+ _this._fragmentSource = vertexSourceOrFragmentSourceOrCode;
4287
+ tags = fragmentSourceOrTagsOrVertexEntry != null ? fragmentSourceOrTagsOrVertexEntry : {
4262
4288
  pipelineStage: exports.PipelineStage.Forward
4263
4289
  };
4264
4290
  }
@@ -4276,9 +4302,51 @@ var ShaderFactory = /*#__PURE__*/ function() {
4276
4302
  if (shaderProgram) {
4277
4303
  return shaderProgram;
4278
4304
  }
4305
+ if (this._type === ShaderType.Canonical) {
4306
+ shaderProgram = this._getCanonicalShaderProgram(engine, macroCollection);
4307
+ } else {
4308
+ shaderProgram = this._compileShaderProgram(engine, macroCollection, this._vertexEntry, this._fragmentEntry);
4309
+ }
4310
+ shaderProgramPool.cache(shaderProgram);
4311
+ return shaderProgram;
4312
+ };
4313
+ /**
4314
+ * @internal
4315
+ */ _proto._destroy = function _destroy() {
4316
+ var shaderProgramPools = this._shaderProgramPools;
4317
+ for(var i = 0, n = shaderProgramPools.length; i < n; i++){
4318
+ shaderProgramPools[i]._destroy();
4319
+ }
4320
+ shaderProgramPools.length = 0;
4321
+ };
4322
+ /**
4323
+ * Shader Lab compilation
4324
+ */ _proto._compileShaderProgram = function _compileShaderProgram(engine, macroCollection, vertexEntry, fragmentEntry) {
4325
+ var isWebGL2 = engine._hardwareRenderer.isWebGL2;
4326
+ var macros = new Array();
4327
+ ShaderMacro._getMacrosElements(macroCollection, macros);
4328
+ this._platformMacros.length = 0;
4329
+ if (engine._hardwareRenderer.canIUse(exports.GLCapabilityType.shaderTextureLod)) {
4330
+ this._platformMacros.push("HAS_TEX_LOD");
4331
+ }
4332
+ if (engine._hardwareRenderer.canIUse(exports.GLCapabilityType.standardDerivatives)) {
4333
+ this._platformMacros.push("HAS_DERIVATIVES");
4334
+ }
4335
+ if (isWebGL2) {
4336
+ this._platformMacros.push("GRAPHICS_API_WEBGL2");
4337
+ } else {
4338
+ this._platformMacros.push("GRAPHICS_API_WEBGL1");
4339
+ }
4340
+ var start = engineMiniprogramAdapter.performance.now();
4341
+ 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;
4342
+ Logger.info("[ShaderLab compilation] cost time: " + (engineMiniprogramAdapter.performance.now() - start) + "ms");
4343
+ return new ShaderProgram(engine, vertex, fragment);
4344
+ };
4345
+ // TODO: remove it after migrate all shader to `ShaderLab`.
4346
+ _proto._getCanonicalShaderProgram = function _getCanonicalShaderProgram(engine, macroCollection) {
4279
4347
  var isWebGL2 = engine._hardwareRenderer.isWebGL2;
4280
- var macroNameList = [];
4281
- ShaderMacro._getNamesByMacros(macroCollection, macroNameList);
4348
+ var macroNameList = new Array();
4349
+ ShaderMacro._getMacrosElements(macroCollection, macroNameList);
4282
4350
  var macroNameStr = ShaderFactory.parseCustomMacros(macroNameList);
4283
4351
  var versionStr = isWebGL2 ? "#version 300 es" : "#version 100";
4284
4352
  var graphicAPI = isWebGL2 ? "#define GRAPHICS_API_WEBGL2" : "#define GRAPHICS_API_WEBGL1";
@@ -4295,19 +4363,9 @@ var ShaderFactory = /*#__PURE__*/ function() {
4295
4363
  vertexSource = ShaderFactory.convertTo300(vertexSource);
4296
4364
  fragmentSource = ShaderFactory.convertTo300(fragmentSource, true);
4297
4365
  }
4298
- shaderProgram = new ShaderProgram(engine, vertexSource, fragmentSource);
4299
- shaderProgramPool.cache(shaderProgram);
4366
+ var shaderProgram = new ShaderProgram(engine, vertexSource, fragmentSource);
4300
4367
  return shaderProgram;
4301
4368
  };
4302
- /**
4303
- * @internal
4304
- */ _proto._destroy = function _destroy() {
4305
- var shaderProgramPools = this._shaderProgramPools;
4306
- for(var i = 0, n = shaderProgramPools.length; i < n; i++){
4307
- shaderProgramPools[i]._destroy();
4308
- }
4309
- shaderProgramPools.length = 0;
4310
- };
4311
4369
  return ShaderPass;
4312
4370
  }(ShaderPart);
4313
4371
  (function() {
@@ -5011,45 +5069,44 @@ __decorate([
5011
5069
  if (!Shader._shaderLab) {
5012
5070
  throw "ShaderLab has not been set up yet.";
5013
5071
  }
5014
- var shaderInfo = Shader._shaderLab.parseShader(nameOrShaderSource);
5015
- if (shaderMap[shaderInfo.name]) {
5016
- console.error('Shader named "' + shaderInfo.name + '" already exists.');
5072
+ var shaderContent = Shader._shaderLab._parseShaderContent(nameOrShaderSource);
5073
+ if (shaderMap[shaderContent.name]) {
5074
+ console.error('Shader named "' + shaderContent.name + '" already exists.');
5017
5075
  return;
5018
5076
  }
5019
- var subShaderList = shaderInfo.subShaders.map(function(subShaderInfo) {
5020
- var passList = subShaderInfo.passes.map(function(passInfo) {
5021
- if (typeof passInfo === "string") {
5077
+ var subShaderList = shaderContent.subShaders.map(function(subShaderContent) {
5078
+ var passList = subShaderContent.passes.map(function(passInfo) {
5079
+ if (passInfo.isUsePass) {
5022
5080
  var _Shader_find_subShaders_find, _Shader_find;
5023
5081
  // Use pass reference
5024
- var paths = passInfo.split("/");
5082
+ var paths = passInfo.name.split("/");
5025
5083
  return (_Shader_find = Shader.find(paths[0])) == null ? void 0 : (_Shader_find_subShaders_find = _Shader_find.subShaders.find(function(subShader) {
5026
5084
  return subShader.name === paths[1];
5027
5085
  })) == null ? void 0 : _Shader_find_subShaders_find.passes.find(function(pass) {
5028
5086
  return pass.name === paths[2];
5029
5087
  });
5030
5088
  }
5031
- var shaderPass = new ShaderPass(passInfo.name, passInfo.vertexSource, passInfo.fragmentSource, passInfo.tags);
5089
+ var shaderPassContent = new ShaderPass(passInfo.name, passInfo.contents, passInfo.vertexEntry, passInfo.fragmentEntry, passInfo.tags);
5032
5090
  var renderStates = passInfo.renderStates;
5033
5091
  var renderState = new RenderState();
5034
- shaderPass._renderState = renderState;
5092
+ shaderPassContent._renderState = renderState;
5035
5093
  // Parse const render state
5036
- var constRenderStateInfo = renderStates[0];
5037
- for(var k in constRenderStateInfo){
5038
- Shader._applyConstRenderStates(renderState, parseInt(k), constRenderStateInfo[k]);
5094
+ var constantMap = renderStates.constantMap, variableMap = renderStates.variableMap;
5095
+ for(var k in constantMap){
5096
+ Shader._applyConstRenderStates(renderState, parseInt(k), constantMap[k]);
5039
5097
  }
5040
5098
  // Parse variable render state
5041
- var variableRenderStateInfo = renderStates[1];
5042
5099
  var renderStateDataMap = {};
5043
- for(var k1 in variableRenderStateInfo){
5044
- renderStateDataMap[k1] = ShaderProperty.getByName(variableRenderStateInfo[k1]);
5100
+ for(var k1 in variableMap){
5101
+ renderStateDataMap[k1] = ShaderProperty.getByName(variableMap[k1]);
5045
5102
  }
5046
- shaderPass._renderStateDataMap = renderStateDataMap;
5047
- return shaderPass;
5103
+ shaderPassContent._renderStateDataMap = renderStateDataMap;
5104
+ return shaderPassContent;
5048
5105
  });
5049
- return new SubShader(shaderInfo.name, passList, subShaderInfo.tags);
5106
+ return new SubShader(subShaderContent.name, passList, subShaderContent.tags);
5050
5107
  });
5051
- shader = new Shader(shaderInfo.name, subShaderList);
5052
- shaderMap[shaderInfo.name] = shader;
5108
+ shader = new Shader(shaderContent.name, subShaderList);
5109
+ shaderMap[shaderContent.name] = shader;
5053
5110
  return shader;
5054
5111
  } else {
5055
5112
  if (shaderMap[nameOrShaderSource]) {
@@ -8139,6 +8196,14 @@ var /**
8139
8196
  MSAASamples[MSAASamples[/** Multi-sample anti-aliasing with 8 samples. */ "EightX"] = 8] = "EightX";
8140
8197
  })(exports.MSAASamples || (exports.MSAASamples = {}));
8141
8198
 
8199
+ /**
8200
+ * The strategy to use when a shader replacement fails.
8201
+ */ exports.ReplacementFailureStrategy = void 0;
8202
+ (function(ReplacementFailureStrategy) {
8203
+ ReplacementFailureStrategy[ReplacementFailureStrategy[/** Keep the original shader. */ "KeepOriginalShader"] = 0] = "KeepOriginalShader";
8204
+ ReplacementFailureStrategy[ReplacementFailureStrategy[/** Do not render. */ "DoNotRender"] = 1] = "DoNotRender";
8205
+ })(exports.ReplacementFailureStrategy || (exports.ReplacementFailureStrategy = {}));
8206
+
8142
8207
  var _Camera;
8143
8208
  var MathTemp = function MathTemp() {
8144
8209
  };
@@ -8188,6 +8253,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
8188
8253
  /** @internal */ _this._virtualCamera = new VirtualCamera();
8189
8254
  /** @internal */ _this._replacementShader = null;
8190
8255
  /** @internal */ _this._replacementSubShaderTag = null;
8256
+ /** @internal */ _this._replacementFailureStrategy = null;
8191
8257
  /** @internal */ _this._cameraIndex = -1;
8192
8258
  _this._priority = 0;
8193
8259
  _this._shaderData = new ShaderData(ShaderDataGroup.Camera);
@@ -8367,6 +8433,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
8367
8433
  context.virtualCamera = virtualCamera;
8368
8434
  context.replacementShader = this._replacementShader;
8369
8435
  context.replacementTag = this._replacementSubShaderTag;
8436
+ context.replacementFailureStrategy = this._replacementFailureStrategy;
8370
8437
  // compute cull frustum.
8371
8438
  if (this.enableFrustumCulling && this._frustumChangeFlag.flag) {
8372
8439
  this._frustum.calculateFromMatrix(virtualCamera.viewProjectionMatrix);
@@ -8386,15 +8453,18 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
8386
8453
  this._renderPipeline.render(context, cubeFace, mipLevel, clearMask);
8387
8454
  this._engine._renderCount++;
8388
8455
  };
8389
- _proto.setReplacementShader = function setReplacementShader(shader, replacementTag) {
8456
+ _proto.setReplacementShader = function setReplacementShader(shader, replacementTag, failureStrategy) {
8457
+ if (failureStrategy === void 0) failureStrategy = exports.ReplacementFailureStrategy.KeepOriginalShader;
8390
8458
  this._replacementShader = shader;
8391
8459
  this._replacementSubShaderTag = typeof replacementTag === "string" ? ShaderTagKey.getByName(replacementTag) : replacementTag;
8460
+ this._replacementFailureStrategy = failureStrategy;
8392
8461
  };
8393
8462
  /**
8394
8463
  * Reset and clear the replacement shader.
8395
8464
  */ _proto.resetReplacementShader = function resetReplacementShader() {
8396
8465
  this._replacementShader = null;
8397
8466
  this._replacementSubShaderTag = null;
8467
+ this._replacementFailureStrategy = null;
8398
8468
  };
8399
8469
  /**
8400
8470
  * @inheritdoc
@@ -8508,7 +8578,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
8508
8578
  this._checkMainCanvasAntialiasWaste();
8509
8579
  };
8510
8580
  _proto._checkMainCanvasAntialiasWaste = function _checkMainCanvasAntialiasWaste() {
8511
- if (this.independentCanvasEnabled && miniprogram.Vector4.equals(this._viewport, PipelineUtils.defaultViewport)) {
8581
+ if (this._phasedActiveInScene && this.independentCanvasEnabled && miniprogram.Vector4.equals(this._viewport, PipelineUtils.defaultViewport)) {
8512
8582
  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.");
8513
8583
  }
8514
8584
  };
@@ -10202,6 +10272,7 @@ var /**
10202
10272
  break;
10203
10273
  }
10204
10274
  }
10275
+ context.replacementFailureStrategy === exports.ReplacementFailureStrategy.KeepOriginalShader && this.pushRenderElementByType(renderElement, subRenderElement, materialSubShader.passes, renderStates);
10205
10276
  } else {
10206
10277
  this.pushRenderElementByType(renderElement, subRenderElement, replacementSubShaders[0].passes, renderStates);
10207
10278
  }
@@ -23346,7 +23417,7 @@ ShaderPool.init();
23346
23417
  */ _proto._initialize = function _initialize(configuration) {
23347
23418
  var _this = this;
23348
23419
  var shaderLab = configuration.shaderLab, physics = configuration.physics;
23349
- if (shaderLab) {
23420
+ if (shaderLab && !Shader._shaderLab) {
23350
23421
  Shader._shaderLab = shaderLab;
23351
23422
  }
23352
23423
  var initializePromises = new Array();
@@ -25285,6 +25356,9 @@ var TonemappingEffect = /*#__PURE__*/ function() {
25285
25356
  */ var _PostProcessManager = /*#__PURE__*/ function() {
25286
25357
  function _PostProcessManager(scene) {
25287
25358
  this.scene = scene;
25359
+ this./**
25360
+ * Whether the post process manager is active.
25361
+ */ isActive = true;
25288
25362
  var uberShader = Shader.find(_PostProcessManager.UBER_SHADER_NAME);
25289
25363
  var uberMaterial = new Material(scene.engine, uberShader);
25290
25364
  var depthState = uberMaterial.renderState.depthState;
@@ -25318,7 +25392,7 @@ var TonemappingEffect = /*#__PURE__*/ function() {
25318
25392
  get: /**
25319
25393
  * Whether has active post process effect.
25320
25394
  */ function get() {
25321
- return this._bloomEffect.enabled || this._tonemappingEffect.enabled;
25395
+ return this.isActive && (this._bloomEffect.enabled || this._tonemappingEffect.enabled);
25322
25396
  }
25323
25397
  }
25324
25398
  ]);