@galacean/engine 1.3.0-alpha.0 → 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.
- package/dist/browser.js +752 -144
- package/dist/browser.js.map +1 -1
- package/dist/browser.min.js +1 -1
- package/dist/browser.min.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/miniprogram.js +1 -1
- package/dist/module.js +1 -1
- package/package.json +5 -5
package/dist/browser.js
CHANGED
|
@@ -94,6 +94,15 @@
|
|
|
94
94
|
*/ MathUtil.degreeToRadian = function degreeToRadian(d) {
|
|
95
95
|
return d * MathUtil.degreeToRadFactor;
|
|
96
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* Linearly interpolate between two values
|
|
99
|
+
* @param start - Specify the start of the range in which to interpolate
|
|
100
|
+
* @param end - Specify the end of the range in which to interpolate
|
|
101
|
+
* @param t - The blend amount where 0 returns start and 1 end
|
|
102
|
+
* @returns The result of linear blending between start and end
|
|
103
|
+
*/ MathUtil.lerp = function lerp(start, end, t) {
|
|
104
|
+
return start + (end - start) * t;
|
|
105
|
+
};
|
|
97
106
|
return MathUtil;
|
|
98
107
|
}();
|
|
99
108
|
(function() {
|
|
@@ -7939,6 +7948,11 @@
|
|
|
7939
7948
|
StencilOperation[StencilOperation[/** Increments the current stencil buffer value. Wraps stencil buffer value to zero when incrementing the maximum representable unsigned value. */ "IncrementWrap"] = 6] = "IncrementWrap";
|
|
7940
7949
|
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";
|
|
7941
7950
|
})(exports.StencilOperation || (exports.StencilOperation = {}));
|
|
7951
|
+
exports.ShaderPlatformTarget = void 0;
|
|
7952
|
+
(function(ShaderPlatformTarget) {
|
|
7953
|
+
ShaderPlatformTarget[ShaderPlatformTarget["GLES100"] = 0] = "GLES100";
|
|
7954
|
+
ShaderPlatformTarget[ShaderPlatformTarget["GLES300"] = 1] = "GLES300";
|
|
7955
|
+
})(exports.ShaderPlatformTarget || (exports.ShaderPlatformTarget = {}));
|
|
7942
7956
|
/**
|
|
7943
7957
|
* Shader macro。
|
|
7944
7958
|
*/ var ShaderMacro = /*#__PURE__*/ function() {
|
|
@@ -7968,14 +7982,14 @@
|
|
|
7968
7982
|
maskMap.length++;
|
|
7969
7983
|
maskMap[index] = new Array(32);
|
|
7970
7984
|
}
|
|
7971
|
-
maskMap[index][bit] =
|
|
7985
|
+
maskMap[index][bit] = macro;
|
|
7972
7986
|
ShaderMacro._macroCounter++;
|
|
7973
7987
|
}
|
|
7974
7988
|
return macro;
|
|
7975
7989
|
};
|
|
7976
7990
|
/**
|
|
7977
7991
|
* @internal
|
|
7978
|
-
*/ ShaderMacro.
|
|
7992
|
+
*/ ShaderMacro._getMacrosElements = function _getMacrosElements(macros, out) {
|
|
7979
7993
|
var maskMap = ShaderMacro._macroMaskMap;
|
|
7980
7994
|
var mask = macros._mask;
|
|
7981
7995
|
out.length = 0;
|
|
@@ -8156,14 +8170,6 @@
|
|
|
8156
8170
|
};
|
|
8157
8171
|
return ShaderMacroCollection;
|
|
8158
8172
|
}();
|
|
8159
|
-
/**
|
|
8160
|
-
* Pipeline stage.
|
|
8161
|
-
*/ exports.PipelineStage = void 0;
|
|
8162
|
-
(function(PipelineStage) {
|
|
8163
|
-
PipelineStage[/** DepthOnly stage. */ "DepthOnly"] = "DepthOnly";
|
|
8164
|
-
PipelineStage[/** Shadow caster stage. */ "ShadowCaster"] = "ShadowCaster";
|
|
8165
|
-
PipelineStage[/** Forward shading stage. */ "Forward"] = "Forward";
|
|
8166
|
-
})(exports.PipelineStage || (exports.PipelineStage = {}));
|
|
8167
8173
|
function _extends$2() {
|
|
8168
8174
|
_extends$2 = Object.assign || function assign(target) {
|
|
8169
8175
|
for(var i = 1; i < arguments.length; i++){
|
|
@@ -8174,6 +8180,14 @@
|
|
|
8174
8180
|
};
|
|
8175
8181
|
return _extends$2.apply(this, arguments);
|
|
8176
8182
|
}
|
|
8183
|
+
/**
|
|
8184
|
+
* Pipeline stage.
|
|
8185
|
+
*/ exports.PipelineStage = void 0;
|
|
8186
|
+
(function(PipelineStage) {
|
|
8187
|
+
PipelineStage[/** DepthOnly stage. */ "DepthOnly"] = "DepthOnly";
|
|
8188
|
+
PipelineStage[/** Shadow caster stage. */ "ShadowCaster"] = "ShadowCaster";
|
|
8189
|
+
PipelineStage[/** Forward shading stage. */ "Forward"] = "Forward";
|
|
8190
|
+
})(exports.PipelineStage || (exports.PipelineStage = {}));
|
|
8177
8191
|
var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;uniform vec3 camera_Forward;uniform vec4 camera_ProjectionParams;"; // eslint-disable-line
|
|
8178
8192
|
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
|
|
8179
8193
|
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
|
|
@@ -8218,10 +8232,10 @@
|
|
|
8218
8232
|
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
|
|
8219
8233
|
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
|
|
8220
8234
|
var pbr_frag_define = "#define GLSLIFY 1\n#define MIN_PERCEPTUAL_ROUGHNESS 0.045\n#define MIN_ROUGHNESS 0.002025\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;uniform float material_NormalIntensity;uniform float material_OcclusionIntensity;uniform float material_OcclusionTextureCoord;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nuniform float material_ClearCoat;uniform float material_ClearCoatRoughness;\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\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nuniform vec3 material_AnisotropyInfo;\n#ifdef MATERIAL_HAS_ANISOTROPY_TEXTURE\nuniform sampler2D material_AnisotropyTexture;\n#endif\n#endif\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\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#ifdef MATERIAL_ENABLE_ANISOTROPY\nvec3 anisotropicT;vec3 anisotropicB;vec3 anisotropicN;float anisotropy;\n#endif\n};struct Material{vec3 diffuseColor;float roughness;vec3 specularColor;float opacity;float f0;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nfloat clearCoat;float clearCoatRoughness;\n#endif\n};"; // eslint-disable-line
|
|
8221
|
-
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
|
|
8235
|
+
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 max(max(dxy.x,dxy.y),dxy.z);\n#else\nreturn 0.0;\n#endif\n}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nvec3 getAnisotropicBentNormal(Geometry geometry,vec3 n,float roughness){vec3 anisotropyDirection=geometry.anisotropy>=0.0 ? geometry.anisotropicB : geometry.anisotropicT;vec3 anisotropicTangent=cross(anisotropyDirection,geometry.viewDir);vec3 anisotropicNormal=cross(anisotropicTangent,anisotropyDirection);vec3 bentNormal=normalize(mix(n,anisotropicNormal,abs(geometry.anisotropy)*saturate(5.0*roughness)));return bentNormal;}\n#endif\nvoid initGeometry(out Geometry geometry,bool isFrontFacing){geometry.position=v_pos;\n#ifdef CAMERA_ORTHOGRAPHIC\ngeometry.viewDir=-camera_Forward;\n#else\ngeometry.viewDir=normalize(camera_Position-v_pos);\n#endif\n#if defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY)\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#ifdef MATERIAL_ENABLE_ANISOTROPY\nfloat anisotropy=material_AnisotropyInfo.z;vec3 anisotropicDirection=vec3(material_AnisotropyInfo.xy,0.0);\n#ifdef MATERIAL_HAS_ANISOTROPY_TEXTURE\nvec3 anisotropyTextureInfo=texture2D(material_AnisotropyTexture,v_uv).rgb;anisotropy*=anisotropyTextureInfo.b;anisotropicDirection.xy*=anisotropyTextureInfo.rg*2.0-1.0;\n#endif\ngeometry.anisotropy=anisotropy;geometry.anisotropicT=normalize(tbn*anisotropicDirection);geometry.anisotropicB=normalize(cross(geometry.normal,geometry.anisotropicT));\n#endif\n}void initMaterial(out Material material,inout 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));material.f0=f0;\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(MIN_PERCEPTUAL_ROUGHNESS,min(material.roughness+getAARoughnessFactor(geometry.normal),1.0));\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(MIN_PERCEPTUAL_ROUGHNESS,min(material.clearCoatRoughness+getAARoughnessFactor(geometry.clearCoatNormal),1.0));\n#endif\n#ifdef MATERIAL_IS_TRANSPARENT\nmaterial.opacity=baseColor.a;\n#else\nmaterial.opacity=1.0;\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\ngeometry.anisotropicN=getAnisotropicBentNormal(geometry,geometry.normal,material.roughness);\n#endif\n}\n#include <brdf>\n#include <direct_irradiance_frag_define>\n#include <ibl_frag_define>\n"; // eslint-disable-line
|
|
8222
8236
|
var brdf = "#define GLSLIFY 1\nfloat F_Schlick(float f0,float dotLH){return f0+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);}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nfloat G_GGX_SmithCorrelated_Anisotropic(float at,float ab,float ToV,float BoV,float ToL,float BoL,float NoV,float NoL){float lambdaV=NoL*length(vec3(at*ToV,ab*BoV,NoV));float lambdaL=NoV*length(vec3(at*ToL,ab*BoL,NoL));return 0.5/max(lambdaV+lambdaL,EPSILON);}\n#endif\nfloat 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);}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nfloat D_GGX_Anisotropic(float at,float ab,float ToH,float BoH,float NoH){float a2=at*ab;vec3 d=vec3(ab*ToH,at*BoH,a2*NoH);float d2=dot(d,d);float b2=a2/d2;return a2*b2*b2*RECIPROCAL_PI;}\n#endif\nvec3 isotropicLobe(vec3 specularColor,float alpha,float dotNV,float dotNL,float dotNH,float dotLH){vec3 F=F_Schlick(specularColor,dotLH);float D=D_GGX(alpha,dotNH);float G=G_GGX_SmithCorrelated(alpha,dotNL,dotNV);return F*(G*D);}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nvec3 anisotropicLobe(vec3 h,vec3 l,Geometry geometry,vec3 specularColor,float alpha,float dotNV,float dotNL,float dotNH,float dotLH){vec3 t=geometry.anisotropicT;vec3 b=geometry.anisotropicB;vec3 v=geometry.viewDir;float dotTV=dot(t,v);float dotBV=dot(b,v);float dotTL=dot(t,l);float dotBL=dot(b,l);float dotTH=dot(t,h);float dotBH=dot(b,h);float at=max(alpha*(1.0+geometry.anisotropy),MIN_ROUGHNESS);float ab=max(alpha*(1.0-geometry.anisotropy),MIN_ROUGHNESS);vec3 F=F_Schlick(specularColor,dotLH);float D=D_GGX_Anisotropic(at,ab,dotTH,dotBH,dotNH);float G=G_GGX_SmithCorrelated_Anisotropic(at,ab,dotTV,dotBV,dotTL,dotBL,dotNV,dotNL);return F*(G*D);}\n#endif\nvec3 BRDF_Specular_GGX(vec3 incidentDirection,Geometry geometry,vec3 normal,vec3 specularColor,float roughness){float alpha=pow2(roughness);vec3 halfDir=normalize(incidentDirection+geometry.viewDir);float dotNL=saturate(dot(normal,incidentDirection));float dotNV=saturate(dot(normal,geometry.viewDir));float dotNH=saturate(dot(normal,halfDir));float dotLH=saturate(dot(incidentDirection,halfDir));\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nreturn anisotropicLobe(halfDir,incidentDirection,geometry,specularColor,alpha,dotNV,dotNL,dotNH,dotLH);\n#else\nreturn isotropicLobe(specularColor,alpha,dotNV,dotNL,dotNH,dotLH);\n#endif\n}vec3 BRDF_Diffuse_Lambert(vec3 diffuseColor){return RECIPROCAL_PI*diffuseColor;}"; // eslint-disable-line
|
|
8223
8237
|
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
|
|
8224
|
-
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
|
|
8238
|
+
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
|
|
8225
8239
|
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
|
|
8226
8240
|
var PBRShaderLib = {
|
|
8227
8241
|
pbr_frag_define: pbr_frag_define,
|
|
@@ -8319,7 +8333,7 @@
|
|
|
8319
8333
|
var ShaderFactory = function ShaderFactory() {};
|
|
8320
8334
|
ShaderFactory.parseCustomMacros = function parseCustomMacros(macros) {
|
|
8321
8335
|
return macros.map(function(m) {
|
|
8322
|
-
return "#define " + m + "\n";
|
|
8336
|
+
return "#define " + (m.value ? m.name + " " + m.value : m.name) + "\n";
|
|
8323
8337
|
}).join("");
|
|
8324
8338
|
};
|
|
8325
8339
|
ShaderFactory.registerInclude = function registerInclude(includeName, includeSource) {
|
|
@@ -9096,29 +9110,48 @@
|
|
|
9096
9110
|
(function() {
|
|
9097
9111
|
ShaderProgram._counter = 0;
|
|
9098
9112
|
})();
|
|
9113
|
+
/**
|
|
9114
|
+
* @internal
|
|
9115
|
+
* Shader pass type
|
|
9116
|
+
*/ var ShaderType;
|
|
9117
|
+
(function(ShaderType) {
|
|
9118
|
+
ShaderType[ShaderType[/** init by glsl */ "Canonical"] = 0] = "Canonical";
|
|
9119
|
+
ShaderType[ShaderType[/** init by shader-lab */ "ShaderLab"] = 1] = "ShaderLab";
|
|
9120
|
+
})(ShaderType || (ShaderType = {}));
|
|
9099
9121
|
/**
|
|
9100
9122
|
* Shader pass containing vertex and fragment source.
|
|
9101
9123
|
*/ var ShaderPass = /*#__PURE__*/ function(ShaderPart1) {
|
|
9102
9124
|
_inherits$2(ShaderPass, ShaderPart1);
|
|
9103
|
-
function ShaderPass(nameOrVertexSource,
|
|
9125
|
+
function ShaderPass(nameOrVertexSource, vertexSourceOrFragmentSourceOrCode, fragmentSourceOrTagsOrVertexEntry, fragmentEntryOrTags, tags) {
|
|
9104
9126
|
var _this;
|
|
9105
9127
|
_this = ShaderPart1.call(this) || this;
|
|
9106
9128
|
/** @internal */ _this._shaderPassId = 0;
|
|
9107
9129
|
/** @internal */ _this._renderStateDataMap = {};
|
|
9108
9130
|
/** @internal */ _this._shaderProgramPools = [];
|
|
9131
|
+
_this._platformMacros = [];
|
|
9109
9132
|
_this._shaderPassId = ShaderPass._shaderPassCounter++;
|
|
9110
|
-
|
|
9133
|
+
_this._type = ShaderType.Canonical;
|
|
9134
|
+
if (typeof fragmentEntryOrTags === "string") {
|
|
9111
9135
|
_this._name = nameOrVertexSource;
|
|
9112
|
-
_this.
|
|
9113
|
-
_this.
|
|
9114
|
-
|
|
9136
|
+
_this._shaderLabSource = vertexSourceOrFragmentSourceOrCode;
|
|
9137
|
+
_this._vertexEntry = fragmentSourceOrTagsOrVertexEntry;
|
|
9138
|
+
_this._fragmentEntry = fragmentEntryOrTags;
|
|
9139
|
+
tags = _extends$2({
|
|
9140
|
+
pipelineStage: exports.PipelineStage.Forward
|
|
9141
|
+
}, tags);
|
|
9142
|
+
_this._type = ShaderType.ShaderLab;
|
|
9143
|
+
} else if (typeof fragmentSourceOrTagsOrVertexEntry === "string") {
|
|
9144
|
+
_this._name = nameOrVertexSource;
|
|
9145
|
+
_this._vertexSource = vertexSourceOrFragmentSourceOrCode;
|
|
9146
|
+
_this._fragmentSource = fragmentSourceOrTagsOrVertexEntry;
|
|
9147
|
+
tags = fragmentEntryOrTags != null ? fragmentEntryOrTags : {
|
|
9115
9148
|
pipelineStage: exports.PipelineStage.Forward
|
|
9116
9149
|
};
|
|
9117
9150
|
} else {
|
|
9118
9151
|
_this._name = "Default";
|
|
9119
9152
|
_this._vertexSource = nameOrVertexSource;
|
|
9120
|
-
_this._fragmentSource =
|
|
9121
|
-
tags =
|
|
9153
|
+
_this._fragmentSource = vertexSourceOrFragmentSourceOrCode;
|
|
9154
|
+
tags = fragmentSourceOrTagsOrVertexEntry != null ? fragmentSourceOrTagsOrVertexEntry : {
|
|
9122
9155
|
pipelineStage: exports.PipelineStage.Forward
|
|
9123
9156
|
};
|
|
9124
9157
|
}
|
|
@@ -9136,9 +9169,51 @@
|
|
|
9136
9169
|
if (shaderProgram) {
|
|
9137
9170
|
return shaderProgram;
|
|
9138
9171
|
}
|
|
9172
|
+
if (this._type === ShaderType.Canonical) {
|
|
9173
|
+
shaderProgram = this._getCanonicalShaderProgram(engine, macroCollection);
|
|
9174
|
+
} else {
|
|
9175
|
+
shaderProgram = this._compileShaderProgram(engine, macroCollection, this._vertexEntry, this._fragmentEntry);
|
|
9176
|
+
}
|
|
9177
|
+
shaderProgramPool.cache(shaderProgram);
|
|
9178
|
+
return shaderProgram;
|
|
9179
|
+
};
|
|
9180
|
+
/**
|
|
9181
|
+
* @internal
|
|
9182
|
+
*/ _proto._destroy = function _destroy() {
|
|
9183
|
+
var shaderProgramPools = this._shaderProgramPools;
|
|
9184
|
+
for(var i = 0, n = shaderProgramPools.length; i < n; i++){
|
|
9185
|
+
shaderProgramPools[i]._destroy();
|
|
9186
|
+
}
|
|
9187
|
+
shaderProgramPools.length = 0;
|
|
9188
|
+
};
|
|
9189
|
+
/**
|
|
9190
|
+
* Shader Lab compilation
|
|
9191
|
+
*/ _proto._compileShaderProgram = function _compileShaderProgram(engine, macroCollection, vertexEntry, fragmentEntry) {
|
|
9139
9192
|
var isWebGL2 = engine._hardwareRenderer.isWebGL2;
|
|
9140
|
-
var
|
|
9141
|
-
ShaderMacro.
|
|
9193
|
+
var macros = new Array();
|
|
9194
|
+
ShaderMacro._getMacrosElements(macroCollection, macros);
|
|
9195
|
+
this._platformMacros.length = 0;
|
|
9196
|
+
if (engine._hardwareRenderer.canIUse(exports.GLCapabilityType.shaderTextureLod)) {
|
|
9197
|
+
this._platformMacros.push("HAS_TEX_LOD");
|
|
9198
|
+
}
|
|
9199
|
+
if (engine._hardwareRenderer.canIUse(exports.GLCapabilityType.standardDerivatives)) {
|
|
9200
|
+
this._platformMacros.push("HAS_DERIVATIVES");
|
|
9201
|
+
}
|
|
9202
|
+
if (isWebGL2) {
|
|
9203
|
+
this._platformMacros.push("GRAPHICS_API_WEBGL2");
|
|
9204
|
+
} else {
|
|
9205
|
+
this._platformMacros.push("GRAPHICS_API_WEBGL1");
|
|
9206
|
+
}
|
|
9207
|
+
var start = performance.now();
|
|
9208
|
+
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;
|
|
9209
|
+
Logger.info("[ShaderLab compilation] cost time: " + (performance.now() - start) + "ms");
|
|
9210
|
+
return new ShaderProgram(engine, vertex, fragment);
|
|
9211
|
+
};
|
|
9212
|
+
// TODO: remove it after migrate all shader to `ShaderLab`.
|
|
9213
|
+
_proto._getCanonicalShaderProgram = function _getCanonicalShaderProgram(engine, macroCollection) {
|
|
9214
|
+
var isWebGL2 = engine._hardwareRenderer.isWebGL2;
|
|
9215
|
+
var macroNameList = new Array();
|
|
9216
|
+
ShaderMacro._getMacrosElements(macroCollection, macroNameList);
|
|
9142
9217
|
var macroNameStr = ShaderFactory.parseCustomMacros(macroNameList);
|
|
9143
9218
|
var versionStr = isWebGL2 ? "#version 300 es" : "#version 100";
|
|
9144
9219
|
var graphicAPI = isWebGL2 ? "#define GRAPHICS_API_WEBGL2" : "#define GRAPHICS_API_WEBGL1";
|
|
@@ -9155,19 +9230,9 @@
|
|
|
9155
9230
|
vertexSource = ShaderFactory.convertTo300(vertexSource);
|
|
9156
9231
|
fragmentSource = ShaderFactory.convertTo300(fragmentSource, true);
|
|
9157
9232
|
}
|
|
9158
|
-
shaderProgram = new ShaderProgram(engine, vertexSource, fragmentSource);
|
|
9159
|
-
shaderProgramPool.cache(shaderProgram);
|
|
9233
|
+
var shaderProgram = new ShaderProgram(engine, vertexSource, fragmentSource);
|
|
9160
9234
|
return shaderProgram;
|
|
9161
9235
|
};
|
|
9162
|
-
/**
|
|
9163
|
-
* @internal
|
|
9164
|
-
*/ _proto._destroy = function _destroy() {
|
|
9165
|
-
var shaderProgramPools = this._shaderProgramPools;
|
|
9166
|
-
for(var i = 0, n = shaderProgramPools.length; i < n; i++){
|
|
9167
|
-
shaderProgramPools[i]._destroy();
|
|
9168
|
-
}
|
|
9169
|
-
shaderProgramPools.length = 0;
|
|
9170
|
-
};
|
|
9171
9236
|
return ShaderPass;
|
|
9172
9237
|
}(ShaderPart);
|
|
9173
9238
|
(function() {
|
|
@@ -9863,45 +9928,44 @@
|
|
|
9863
9928
|
if (!Shader._shaderLab) {
|
|
9864
9929
|
throw "ShaderLab has not been set up yet.";
|
|
9865
9930
|
}
|
|
9866
|
-
var
|
|
9867
|
-
if (shaderMap[
|
|
9868
|
-
console.error('Shader named "' +
|
|
9931
|
+
var shaderContent = Shader._shaderLab._parseShaderContent(nameOrShaderSource);
|
|
9932
|
+
if (shaderMap[shaderContent.name]) {
|
|
9933
|
+
console.error('Shader named "' + shaderContent.name + '" already exists.');
|
|
9869
9934
|
return;
|
|
9870
9935
|
}
|
|
9871
|
-
var subShaderList =
|
|
9872
|
-
var passList =
|
|
9873
|
-
if (
|
|
9936
|
+
var subShaderList = shaderContent.subShaders.map(function(subShaderContent) {
|
|
9937
|
+
var passList = subShaderContent.passes.map(function(passInfo) {
|
|
9938
|
+
if (passInfo.isUsePass) {
|
|
9874
9939
|
var _Shader_find_subShaders_find, _Shader_find;
|
|
9875
9940
|
// Use pass reference
|
|
9876
|
-
var paths = passInfo.split("/");
|
|
9941
|
+
var paths = passInfo.name.split("/");
|
|
9877
9942
|
return (_Shader_find = Shader.find(paths[0])) == null ? void 0 : (_Shader_find_subShaders_find = _Shader_find.subShaders.find(function(subShader) {
|
|
9878
9943
|
return subShader.name === paths[1];
|
|
9879
9944
|
})) == null ? void 0 : _Shader_find_subShaders_find.passes.find(function(pass) {
|
|
9880
9945
|
return pass.name === paths[2];
|
|
9881
9946
|
});
|
|
9882
9947
|
}
|
|
9883
|
-
var
|
|
9948
|
+
var shaderPassContent = new ShaderPass(passInfo.name, passInfo.contents, passInfo.vertexEntry, passInfo.fragmentEntry, passInfo.tags);
|
|
9884
9949
|
var renderStates = passInfo.renderStates;
|
|
9885
9950
|
var renderState = new RenderState();
|
|
9886
|
-
|
|
9951
|
+
shaderPassContent._renderState = renderState;
|
|
9887
9952
|
// Parse const render state
|
|
9888
|
-
var
|
|
9889
|
-
for(var k in
|
|
9890
|
-
Shader._applyConstRenderStates(renderState, parseInt(k),
|
|
9953
|
+
var constantMap = renderStates.constantMap, variableMap = renderStates.variableMap;
|
|
9954
|
+
for(var k in constantMap){
|
|
9955
|
+
Shader._applyConstRenderStates(renderState, parseInt(k), constantMap[k]);
|
|
9891
9956
|
}
|
|
9892
9957
|
// Parse variable render state
|
|
9893
|
-
var variableRenderStateInfo = renderStates[1];
|
|
9894
9958
|
var renderStateDataMap = {};
|
|
9895
|
-
for(var k1 in
|
|
9896
|
-
renderStateDataMap[k1] = ShaderProperty.getByName(
|
|
9959
|
+
for(var k1 in variableMap){
|
|
9960
|
+
renderStateDataMap[k1] = ShaderProperty.getByName(variableMap[k1]);
|
|
9897
9961
|
}
|
|
9898
|
-
|
|
9899
|
-
return
|
|
9962
|
+
shaderPassContent._renderStateDataMap = renderStateDataMap;
|
|
9963
|
+
return shaderPassContent;
|
|
9900
9964
|
});
|
|
9901
|
-
return new SubShader(
|
|
9965
|
+
return new SubShader(subShaderContent.name, passList, subShaderContent.tags);
|
|
9902
9966
|
});
|
|
9903
|
-
shader = new Shader(
|
|
9904
|
-
shaderMap[
|
|
9967
|
+
shader = new Shader(shaderContent.name, subShaderList);
|
|
9968
|
+
shaderMap[shaderContent.name] = shader;
|
|
9905
9969
|
return shader;
|
|
9906
9970
|
} else {
|
|
9907
9971
|
if (shaderMap[nameOrShaderSource]) {
|
|
@@ -10111,6 +10175,7 @@
|
|
|
10111
10175
|
TextureFormat[TextureFormat[/** RGBA format, 16 bits per channel. */ "R16G16B16A16"] = 7] = "R16G16B16A16";
|
|
10112
10176
|
TextureFormat[TextureFormat[/** RGBA format, 32 bits per channel. */ "R32G32B32A32"] = 8] = "R32G32B32A32";
|
|
10113
10177
|
TextureFormat[TextureFormat[/** RGBA unsigned integer format, 32 bits per channel. */ "R32G32B32A32_UInt"] = 9] = "R32G32B32A32_UInt";
|
|
10178
|
+
TextureFormat[TextureFormat[/** RGB unsigned float format, 11 bits in R channel, 11 bits in G channel, 10 bits in B channel. */ "R11G11B10_UFloat"] = 35] = "R11G11B10_UFloat";
|
|
10114
10179
|
TextureFormat[TextureFormat[/** RGB compressed format, 4 bits per pixel. */ "BC1"] = 10] = "BC1";
|
|
10115
10180
|
TextureFormat[TextureFormat[/** RGBA compressed format, 8 bits per pixel. */ "BC3"] = 11] = "BC3";
|
|
10116
10181
|
TextureFormat[TextureFormat[/** RGB(A) compressed format, 128 bits per 4x4 pixel block. */ "BC7"] = 12] = "BC7";
|
|
@@ -12785,22 +12850,23 @@
|
|
|
12785
12850
|
* @param height - Need texture height
|
|
12786
12851
|
* @param format - Need texture format
|
|
12787
12852
|
* @param mipmap - Need texture mipmap
|
|
12853
|
+
* @param textureWrapMode - Texture wrap mode
|
|
12854
|
+
* @param textureFilterMode - Texture filter mode
|
|
12788
12855
|
* @returns Texture
|
|
12789
|
-
*/ PipelineUtils.recreateTextureIfNeeded = function recreateTextureIfNeeded(engine, currentTexture, width, height, format, mipmap) {
|
|
12856
|
+
*/ PipelineUtils.recreateTextureIfNeeded = function recreateTextureIfNeeded(engine, currentTexture, width, height, format, mipmap, textureWrapMode, textureFilterMode) {
|
|
12790
12857
|
if (currentTexture) {
|
|
12791
12858
|
if (currentTexture.width !== width || currentTexture.height !== height || currentTexture.format !== format || currentTexture.mipmapCount > 1 !== mipmap) {
|
|
12792
12859
|
currentTexture.destroy(true);
|
|
12793
|
-
|
|
12794
|
-
|
|
12795
|
-
return texture;
|
|
12796
|
-
} else {
|
|
12797
|
-
return currentTexture;
|
|
12860
|
+
currentTexture = new Texture2D(engine, width, height, format, mipmap);
|
|
12861
|
+
currentTexture.isGCIgnored = true;
|
|
12798
12862
|
}
|
|
12799
12863
|
} else {
|
|
12800
|
-
|
|
12801
|
-
|
|
12802
|
-
return texture1;
|
|
12864
|
+
currentTexture = new Texture2D(engine, width, height, format, mipmap);
|
|
12865
|
+
currentTexture.isGCIgnored = true;
|
|
12803
12866
|
}
|
|
12867
|
+
currentTexture.wrapModeU = currentTexture.wrapModeV = textureWrapMode;
|
|
12868
|
+
currentTexture.filterMode = textureFilterMode;
|
|
12869
|
+
return currentTexture;
|
|
12804
12870
|
};
|
|
12805
12871
|
/**
|
|
12806
12872
|
* Recreate render target if needed.
|
|
@@ -12812,15 +12878,17 @@
|
|
|
12812
12878
|
* @param depthFormat - Need render target depth format
|
|
12813
12879
|
* @param mipmap - Need render target mipmap
|
|
12814
12880
|
* @param antiAliasing - Need render target anti aliasing
|
|
12881
|
+
* @param textureWrapMode - Texture wrap mode
|
|
12882
|
+
* @param textureFilterMode - Texture filter mode
|
|
12815
12883
|
* @returns Render target
|
|
12816
|
-
*/ PipelineUtils.recreateRenderTargetIfNeeded = function recreateRenderTargetIfNeeded(engine, currentRenderTarget, width, height, colorFormat, depthFormat, needDepthTexture, mipmap, antiAliasing) {
|
|
12884
|
+
*/ PipelineUtils.recreateRenderTargetIfNeeded = function recreateRenderTargetIfNeeded(engine, currentRenderTarget, width, height, colorFormat, depthFormat, needDepthTexture, mipmap, antiAliasing, textureWrapMode, textureFilterMode) {
|
|
12817
12885
|
var _currentRenderTarget;
|
|
12818
12886
|
var currentColorTexture = (_currentRenderTarget = currentRenderTarget) == null ? void 0 : _currentRenderTarget.getColorTexture(0);
|
|
12819
|
-
var colorTexture = colorFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentColorTexture, width, height, colorFormat, mipmap) : null;
|
|
12887
|
+
var colorTexture = colorFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentColorTexture, width, height, colorFormat, mipmap, textureWrapMode, textureFilterMode) : null;
|
|
12820
12888
|
if (needDepthTexture) {
|
|
12821
12889
|
var _currentRenderTarget1;
|
|
12822
12890
|
var currentDepthTexture = (_currentRenderTarget1 = currentRenderTarget) == null ? void 0 : _currentRenderTarget1.depthTexture;
|
|
12823
|
-
var _$needDepthTexture = depthFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentDepthTexture, width, height, depthFormat, mipmap) : null;
|
|
12891
|
+
var _$needDepthTexture = depthFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentDepthTexture, width, height, depthFormat, mipmap, textureWrapMode, textureFilterMode) : null;
|
|
12824
12892
|
if (currentColorTexture !== colorTexture || currentDepthTexture !== _$needDepthTexture) {
|
|
12825
12893
|
var _currentRenderTarget2;
|
|
12826
12894
|
(_currentRenderTarget2 = currentRenderTarget) == null ? void 0 : _currentRenderTarget2.destroy(true);
|
|
@@ -12829,38 +12897,46 @@
|
|
|
12829
12897
|
}
|
|
12830
12898
|
} else {
|
|
12831
12899
|
var _currentRenderTarget3;
|
|
12832
|
-
|
|
12833
|
-
if (currentColorTexture !== colorTexture || ((_currentRenderTarget3 = currentRenderTarget) == null ? void 0 : _currentRenderTarget3._depthFormat) !== needDepthFormat) {
|
|
12900
|
+
if (currentColorTexture !== colorTexture || ((_currentRenderTarget3 = currentRenderTarget) == null ? void 0 : _currentRenderTarget3._depthFormat) !== depthFormat || currentRenderTarget.antiAliasing !== antiAliasing) {
|
|
12834
12901
|
var _currentRenderTarget4;
|
|
12835
12902
|
(_currentRenderTarget4 = currentRenderTarget) == null ? void 0 : _currentRenderTarget4.destroy(true);
|
|
12836
|
-
currentRenderTarget = new RenderTarget(engine, width, height, colorTexture,
|
|
12903
|
+
currentRenderTarget = new RenderTarget(engine, width, height, colorTexture, depthFormat, antiAliasing);
|
|
12837
12904
|
currentRenderTarget.isGCIgnored = true;
|
|
12838
12905
|
}
|
|
12839
12906
|
}
|
|
12840
12907
|
return currentRenderTarget;
|
|
12841
12908
|
};
|
|
12842
12909
|
/**
|
|
12843
|
-
* Blit texture to destination render target.
|
|
12910
|
+
* Blit texture to destination render target using a triangle.
|
|
12844
12911
|
* @param engine - Engine
|
|
12845
12912
|
* @param source - Source texture
|
|
12846
12913
|
* @param destination - Destination render target
|
|
12847
12914
|
* @param mipLevel - Mip level to blit
|
|
12848
12915
|
* @param viewport - Viewport
|
|
12849
|
-
|
|
12916
|
+
* @param material - The material to use when blitting
|
|
12917
|
+
* @param passIndex - Pass index to use of the provided material
|
|
12918
|
+
*/ PipelineUtils.blitTexture = function blitTexture(engine, source, destination, mipLevel, viewport, material, passIndex) {
|
|
12850
12919
|
if (mipLevel === void 0) mipLevel = 0;
|
|
12920
|
+
if (viewport === void 0) viewport = PipelineUtils.defaultViewport;
|
|
12921
|
+
if (material === void 0) material = null;
|
|
12922
|
+
if (passIndex === void 0) passIndex = 0;
|
|
12851
12923
|
var basicResources = engine._basicResources;
|
|
12852
12924
|
var blitMesh = destination ? basicResources.flipYBlitMesh : basicResources.blitMesh;
|
|
12853
|
-
var blitMaterial = basicResources.blitMaterial;
|
|
12925
|
+
var blitMaterial = material || basicResources.blitMaterial;
|
|
12854
12926
|
var rhi = engine._hardwareRenderer;
|
|
12855
12927
|
var context = engine._renderContext;
|
|
12856
12928
|
// We not use projection matrix when blit, but we must modify flipProjection to make front face correct
|
|
12857
|
-
context.flipProjection = destination
|
|
12858
|
-
rhi.activeRenderTarget(destination, viewport
|
|
12929
|
+
context.flipProjection = !!destination;
|
|
12930
|
+
rhi.activeRenderTarget(destination, viewport, context.flipProjection, 0);
|
|
12859
12931
|
var rendererShaderData = PipelineUtils._rendererShaderData;
|
|
12860
|
-
var pass = blitMaterial.shader.subShaders[0].passes[0];
|
|
12861
|
-
var program = pass._getShaderProgram(engine, Shader._compileMacros);
|
|
12862
12932
|
rendererShaderData.setTexture(PipelineUtils._blitTextureProperty, source);
|
|
12863
12933
|
rendererShaderData.setFloat(PipelineUtils._blitMipLevelProperty, mipLevel);
|
|
12934
|
+
PipelineUtils._texelSize.set(1 / source.width, 1 / source.height, source.width, source.height);
|
|
12935
|
+
rendererShaderData.setVector4(PipelineUtils._blitTexelSizeProperty, PipelineUtils._texelSize);
|
|
12936
|
+
var pass = blitMaterial.shader.subShaders[0].passes[passIndex];
|
|
12937
|
+
var compileMacros = Shader._compileMacros;
|
|
12938
|
+
ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, blitMaterial.shaderData._macroCollection, compileMacros);
|
|
12939
|
+
var program = pass._getShaderProgram(engine, compileMacros);
|
|
12864
12940
|
program.bind();
|
|
12865
12941
|
program.groupingOtherUniformBlock();
|
|
12866
12942
|
program.uploadAll(program.rendererUniformBlock, rendererShaderData);
|
|
@@ -12877,9 +12953,16 @@
|
|
|
12877
12953
|
(function() {
|
|
12878
12954
|
PipelineUtils._blitMipLevelProperty = ShaderProperty.getByName("renderer_BlitMipLevel");
|
|
12879
12955
|
})();
|
|
12956
|
+
(function() {
|
|
12957
|
+
PipelineUtils._blitTexelSizeProperty = ShaderProperty.getByName("renderer_texelSize") // x: 1/width, y: 1/height, z: width, w: height
|
|
12958
|
+
;
|
|
12959
|
+
})();
|
|
12880
12960
|
(function() {
|
|
12881
12961
|
PipelineUtils._rendererShaderData = new ShaderData(ShaderDataGroup.Renderer);
|
|
12882
12962
|
})();
|
|
12963
|
+
(function() {
|
|
12964
|
+
PipelineUtils._texelSize = new Vector4();
|
|
12965
|
+
})();
|
|
12883
12966
|
(function() {
|
|
12884
12967
|
PipelineUtils.defaultViewport = new Vector4(0, 0, 1, 1);
|
|
12885
12968
|
})();
|
|
@@ -12941,6 +13024,13 @@
|
|
|
12941
13024
|
MSAASamples[MSAASamples[/** Multi-sample anti-aliasing with 4 samples. */ "FourX"] = 4] = "FourX";
|
|
12942
13025
|
MSAASamples[MSAASamples[/** Multi-sample anti-aliasing with 8 samples. */ "EightX"] = 8] = "EightX";
|
|
12943
13026
|
})(exports.MSAASamples || (exports.MSAASamples = {}));
|
|
13027
|
+
/**
|
|
13028
|
+
* The strategy to use when a shader replacement fails.
|
|
13029
|
+
*/ exports.ReplacementFailureStrategy = void 0;
|
|
13030
|
+
(function(ReplacementFailureStrategy) {
|
|
13031
|
+
ReplacementFailureStrategy[ReplacementFailureStrategy[/** Keep the original shader. */ "KeepOriginalShader"] = 0] = "KeepOriginalShader";
|
|
13032
|
+
ReplacementFailureStrategy[ReplacementFailureStrategy[/** Do not render. */ "DoNotRender"] = 1] = "DoNotRender";
|
|
13033
|
+
})(exports.ReplacementFailureStrategy || (exports.ReplacementFailureStrategy = {}));
|
|
12944
13034
|
var _Camera;
|
|
12945
13035
|
var MathTemp = function MathTemp() {};
|
|
12946
13036
|
(function() {
|
|
@@ -12988,6 +13078,7 @@
|
|
|
12988
13078
|
/** @internal */ _this._virtualCamera = new VirtualCamera();
|
|
12989
13079
|
/** @internal */ _this._replacementShader = null;
|
|
12990
13080
|
/** @internal */ _this._replacementSubShaderTag = null;
|
|
13081
|
+
/** @internal */ _this._replacementFailureStrategy = null;
|
|
12991
13082
|
/** @internal */ _this._cameraIndex = -1;
|
|
12992
13083
|
_this._priority = 0;
|
|
12993
13084
|
_this._shaderData = new ShaderData(ShaderDataGroup.Camera);
|
|
@@ -13001,6 +13092,8 @@
|
|
|
13001
13092
|
_this._renderTarget = null;
|
|
13002
13093
|
_this._depthBufferParams = new Vector4();
|
|
13003
13094
|
_this._opaqueTextureEnabled = false;
|
|
13095
|
+
_this._enableHDR = false;
|
|
13096
|
+
_this._enablePostProcess = false;
|
|
13004
13097
|
_this._viewport = new Vector4(0, 0, 1, 1);
|
|
13005
13098
|
_this._pixelViewport = new Rect(0, 0, 0, 0);
|
|
13006
13099
|
_this._inverseProjectionMatrix = new Matrix();
|
|
@@ -13166,6 +13259,7 @@
|
|
|
13166
13259
|
context.virtualCamera = virtualCamera;
|
|
13167
13260
|
context.replacementShader = this._replacementShader;
|
|
13168
13261
|
context.replacementTag = this._replacementSubShaderTag;
|
|
13262
|
+
context.replacementFailureStrategy = this._replacementFailureStrategy;
|
|
13169
13263
|
// compute cull frustum.
|
|
13170
13264
|
if (this.enableFrustumCulling && this._frustumChangeFlag.flag) {
|
|
13171
13265
|
this._frustum.calculateFromMatrix(virtualCamera.viewProjectionMatrix);
|
|
@@ -13185,15 +13279,18 @@
|
|
|
13185
13279
|
this._renderPipeline.render(context, cubeFace, mipLevel, clearMask);
|
|
13186
13280
|
this._engine._renderCount++;
|
|
13187
13281
|
};
|
|
13188
|
-
_proto.setReplacementShader = function setReplacementShader(shader, replacementTag) {
|
|
13282
|
+
_proto.setReplacementShader = function setReplacementShader(shader, replacementTag, failureStrategy) {
|
|
13283
|
+
if (failureStrategy === void 0) failureStrategy = exports.ReplacementFailureStrategy.KeepOriginalShader;
|
|
13189
13284
|
this._replacementShader = shader;
|
|
13190
13285
|
this._replacementSubShaderTag = typeof replacementTag === "string" ? ShaderTagKey.getByName(replacementTag) : replacementTag;
|
|
13286
|
+
this._replacementFailureStrategy = failureStrategy;
|
|
13191
13287
|
};
|
|
13192
13288
|
/**
|
|
13193
13289
|
* Reset and clear the replacement shader.
|
|
13194
13290
|
*/ _proto.resetReplacementShader = function resetReplacementShader() {
|
|
13195
13291
|
this._replacementShader = null;
|
|
13196
13292
|
this._replacementSubShaderTag = null;
|
|
13293
|
+
this._replacementFailureStrategy = null;
|
|
13197
13294
|
};
|
|
13198
13295
|
/**
|
|
13199
13296
|
* @inheritdoc
|
|
@@ -13207,6 +13304,11 @@
|
|
|
13207
13304
|
};
|
|
13208
13305
|
/**
|
|
13209
13306
|
* @internal
|
|
13307
|
+
*/ _proto._getInternalColorTextureFormat = function _getInternalColorTextureFormat() {
|
|
13308
|
+
return this._enableHDR ? this.engine._hardwareRenderer.isWebGL2 ? exports.TextureFormat.R11G11B10_UFloat : exports.TextureFormat.R16G16B16A16 : exports.TextureFormat.R8G8B8A8;
|
|
13309
|
+
};
|
|
13310
|
+
/**
|
|
13311
|
+
* @internal
|
|
13210
13312
|
* @inheritdoc
|
|
13211
13313
|
*/ _proto._onDestroy = function _onDestroy() {
|
|
13212
13314
|
var _this__renderPipeline;
|
|
@@ -13295,9 +13397,6 @@
|
|
|
13295
13397
|
}
|
|
13296
13398
|
return this._inverseProjectionMatrix;
|
|
13297
13399
|
};
|
|
13298
|
-
_proto._forceUseInternalCanvas = function _forceUseInternalCanvas() {
|
|
13299
|
-
return this.opaqueTextureEnabled;
|
|
13300
|
-
};
|
|
13301
13400
|
_proto._onPixelViewportChanged = function _onPixelViewportChanged() {
|
|
13302
13401
|
this._updatePixelViewport();
|
|
13303
13402
|
var _this__customAspectRatio;
|
|
@@ -13305,8 +13404,8 @@
|
|
|
13305
13404
|
this._checkMainCanvasAntialiasWaste();
|
|
13306
13405
|
};
|
|
13307
13406
|
_proto._checkMainCanvasAntialiasWaste = function _checkMainCanvasAntialiasWaste() {
|
|
13308
|
-
if (this.independentCanvasEnabled && Vector4.equals(this._viewport, PipelineUtils.defaultViewport)) {
|
|
13309
|
-
|
|
13407
|
+
if (this._phasedActiveInScene && this.independentCanvasEnabled && Vector4.equals(this._viewport, PipelineUtils.defaultViewport)) {
|
|
13408
|
+
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.");
|
|
13310
13409
|
}
|
|
13311
13410
|
};
|
|
13312
13411
|
_create_class$2(Camera1, [
|
|
@@ -13317,7 +13416,6 @@
|
|
|
13317
13416
|
* If enabled, the opaque texture can be accessed in the shader using `camera_OpaqueTexture`.
|
|
13318
13417
|
*
|
|
13319
13418
|
* @defaultValue `false`
|
|
13320
|
-
*
|
|
13321
13419
|
* @remarks If enabled, the `independentCanvasEnabled` property will be forced to be true.
|
|
13322
13420
|
*/ function get() {
|
|
13323
13421
|
return this._opaqueTextureEnabled;
|
|
@@ -13336,10 +13434,10 @@
|
|
|
13336
13434
|
*
|
|
13337
13435
|
* @remarks If true, the msaa in viewport can turn or off independently by `msaaSamples` property.
|
|
13338
13436
|
*/ function get() {
|
|
13339
|
-
if (this.
|
|
13340
|
-
return
|
|
13437
|
+
if (this.enableHDR || this.enablePostProcess && this.scene._postProcessManager.hasActiveEffect) {
|
|
13438
|
+
return true;
|
|
13341
13439
|
}
|
|
13342
|
-
return this.
|
|
13440
|
+
return this.opaqueTextureEnabled && !this._renderTarget;
|
|
13343
13441
|
}
|
|
13344
13442
|
},
|
|
13345
13443
|
{
|
|
@@ -13524,13 +13622,38 @@
|
|
|
13524
13622
|
key: "enableHDR",
|
|
13525
13623
|
get: /**
|
|
13526
13624
|
* Whether to enable HDR.
|
|
13527
|
-
* @
|
|
13625
|
+
* @defaultValue `false`
|
|
13626
|
+
* @remarks If enabled, the `independentCanvasEnabled` property will be forced to be true.
|
|
13528
13627
|
*/ function get() {
|
|
13529
|
-
|
|
13530
|
-
return false;
|
|
13628
|
+
return this._enableHDR;
|
|
13531
13629
|
},
|
|
13532
13630
|
set: function set(value) {
|
|
13533
|
-
|
|
13631
|
+
if (this.enableHDR !== value) {
|
|
13632
|
+
var rhi = this.engine._hardwareRenderer;
|
|
13633
|
+
var supportHDR = rhi.isWebGL2 || rhi.canIUse(exports.GLCapabilityType.textureHalfFloat);
|
|
13634
|
+
if (value && !supportHDR) {
|
|
13635
|
+
Logger.warn("Can't enable HDR in this device.");
|
|
13636
|
+
return;
|
|
13637
|
+
}
|
|
13638
|
+
this._enableHDR = value;
|
|
13639
|
+
this._checkMainCanvasAntialiasWaste();
|
|
13640
|
+
}
|
|
13641
|
+
}
|
|
13642
|
+
},
|
|
13643
|
+
{
|
|
13644
|
+
key: "enablePostProcess",
|
|
13645
|
+
get: /**
|
|
13646
|
+
* Whether to enable post process.
|
|
13647
|
+
* @defaultValue `false`
|
|
13648
|
+
* @remarks If enabled, the `independentCanvasEnabled` property will be forced to be true.
|
|
13649
|
+
*/ function get() {
|
|
13650
|
+
return this._enablePostProcess;
|
|
13651
|
+
},
|
|
13652
|
+
set: function set(value) {
|
|
13653
|
+
if (this._enablePostProcess !== value) {
|
|
13654
|
+
this._enablePostProcess = value;
|
|
13655
|
+
this._checkMainCanvasAntialiasWaste();
|
|
13656
|
+
}
|
|
13534
13657
|
}
|
|
13535
13658
|
},
|
|
13536
13659
|
{
|
|
@@ -13546,7 +13669,6 @@
|
|
|
13546
13669
|
value && this._addResourceReferCount(value, 1);
|
|
13547
13670
|
this._renderTarget = value;
|
|
13548
13671
|
this._onPixelViewportChanged();
|
|
13549
|
-
this._checkMainCanvasAntialiasWaste();
|
|
13550
13672
|
}
|
|
13551
13673
|
}
|
|
13552
13674
|
}
|
|
@@ -13628,7 +13750,7 @@
|
|
|
13628
13750
|
/**
|
|
13629
13751
|
* PipelinePass is a base class for all pipeline passes.
|
|
13630
13752
|
*/ var PipelinePass = function PipelinePass(engine) {
|
|
13631
|
-
this.
|
|
13753
|
+
this.engine = engine;
|
|
13632
13754
|
};
|
|
13633
13755
|
/**
|
|
13634
13756
|
* @internal
|
|
@@ -14495,7 +14617,7 @@
|
|
|
14495
14617
|
this._updateReceiversShaderData(light);
|
|
14496
14618
|
};
|
|
14497
14619
|
_proto._renderDirectShadowMap = function _renderDirectShadowMap(context, light) {
|
|
14498
|
-
var _this = this, engine = _this.
|
|
14620
|
+
var _this = this, engine = _this.engine, camera = _this._camera, viewports = _this._viewportOffsets, shadowSliceData = _this._shadowSliceData, splitBoundSpheres = _this._splitBoundSpheres, shadowMatrices = _this._shadowMatrices;
|
|
14499
14621
|
var _camera__renderPipeline__cullingResults = camera._renderPipeline._cullingResults, opaqueQueue = _camera__renderPipeline__cullingResults.opaqueQueue, alphaTestQueue = _camera__renderPipeline__cullingResults.alphaTestQueue;
|
|
14500
14622
|
var scene = camera.scene;
|
|
14501
14623
|
var componentsManager = scene._componentsManager;
|
|
@@ -14514,13 +14636,12 @@
|
|
|
14514
14636
|
var renderTarget;
|
|
14515
14637
|
var shadowTexture;
|
|
14516
14638
|
if (this._supportDepthTexture) {
|
|
14517
|
-
renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, null, format, true, false, 1);
|
|
14639
|
+
renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, null, format, true, false, 1, exports.TextureWrapMode.Clamp, exports.TextureFilterMode.Bilinear);
|
|
14518
14640
|
shadowTexture = renderTarget.depthTexture;
|
|
14519
14641
|
} else {
|
|
14520
|
-
renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, format, null, false, false, 1);
|
|
14642
|
+
renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, format, null, false, false, 1, exports.TextureWrapMode.Clamp, exports.TextureFilterMode.Bilinear);
|
|
14521
14643
|
shadowTexture = renderTarget.getColorTexture(0);
|
|
14522
14644
|
}
|
|
14523
|
-
shadowTexture.wrapModeU = shadowTexture.wrapModeV = exports.TextureWrapMode.Clamp;
|
|
14524
14645
|
if (engine._hardwareRenderer._isWebGL2) {
|
|
14525
14646
|
shadowTexture.depthCompareFunction = exports.TextureDepthCompareFunction.Less;
|
|
14526
14647
|
}
|
|
@@ -14769,22 +14890,17 @@
|
|
|
14769
14890
|
_inherits$2(DepthOnlyPass, PipelinePass1);
|
|
14770
14891
|
var _proto = DepthOnlyPass.prototype;
|
|
14771
14892
|
_proto.onConfig = function onConfig(camera) {
|
|
14772
|
-
var engine = this.
|
|
14893
|
+
var engine = this.engine;
|
|
14773
14894
|
var _camera_pixelViewport = camera.pixelViewport, width = _camera_pixelViewport.width, height = _camera_pixelViewport.height;
|
|
14774
|
-
var renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, null, exports.TextureFormat.Depth16, true, false, 1);
|
|
14775
|
-
var depthTexture = renderTarget.depthTexture;
|
|
14776
|
-
depthTexture.wrapModeU = depthTexture.wrapModeV = exports.TextureWrapMode.Clamp;
|
|
14777
|
-
depthTexture.filterMode = exports.TextureFilterMode.Point;
|
|
14895
|
+
var renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, null, exports.TextureFormat.Depth16, true, false, 1, exports.TextureWrapMode.Clamp, exports.TextureFilterMode.Point);
|
|
14778
14896
|
this._renderTarget = renderTarget;
|
|
14779
14897
|
};
|
|
14780
14898
|
_proto.onRender = function onRender(context, cullingResults) {
|
|
14781
|
-
var engine = this.
|
|
14899
|
+
var engine = this.engine;
|
|
14782
14900
|
var renderTarget = this._renderTarget;
|
|
14783
14901
|
var camera = context.camera;
|
|
14784
14902
|
var rhi = engine._hardwareRenderer;
|
|
14785
|
-
rhi.activeRenderTarget(renderTarget,
|
|
14786
|
-
rhi.viewport(0, 0, renderTarget.width, renderTarget.height);
|
|
14787
|
-
rhi.scissor(0, 0, renderTarget.width, renderTarget.height);
|
|
14903
|
+
rhi.activeRenderTarget(renderTarget, PipelineUtils.defaultViewport, context.flipProjection, 0);
|
|
14788
14904
|
rhi.clearRenderTarget(engine, exports.CameraClearFlags.Depth, null);
|
|
14789
14905
|
engine._renderCount++;
|
|
14790
14906
|
cullingResults.opaqueQueue.render(context, exports.PipelineStage.DepthOnly);
|
|
@@ -14808,14 +14924,11 @@
|
|
|
14808
14924
|
var isNoDownsampling = downsampling === exports.Downsampling.None;
|
|
14809
14925
|
var viewport = camera.pixelViewport;
|
|
14810
14926
|
var sizeScale = isNoDownsampling ? 1.0 : downsampling === exports.Downsampling.TwoX ? 0.5 : 0.25;
|
|
14811
|
-
var opaqueRenderTarget = PipelineUtils.recreateRenderTargetIfNeeded(this.
|
|
14812
|
-
var colorTexture = opaqueRenderTarget.getColorTexture(0);
|
|
14813
|
-
colorTexture.wrapModeU = colorTexture.wrapModeV = exports.TextureWrapMode.Clamp;
|
|
14814
|
-
colorTexture.filterMode = isNoDownsampling ? exports.TextureFilterMode.Point : exports.TextureFilterMode.Bilinear;
|
|
14927
|
+
var opaqueRenderTarget = PipelineUtils.recreateRenderTargetIfNeeded(this.engine, this._renderTarget, viewport.width * sizeScale, viewport.height * sizeScale, camera._getInternalColorTextureFormat(), null, false, false, 1, exports.TextureWrapMode.Clamp, isNoDownsampling ? exports.TextureFilterMode.Point : exports.TextureFilterMode.Bilinear);
|
|
14815
14928
|
this._renderTarget = opaqueRenderTarget;
|
|
14816
14929
|
};
|
|
14817
|
-
_proto.onRender = function onRender(context
|
|
14818
|
-
PipelineUtils.blitTexture(this.
|
|
14930
|
+
_proto.onRender = function onRender(context) {
|
|
14931
|
+
PipelineUtils.blitTexture(this.engine, this._cameraColorTexture, this._renderTarget);
|
|
14819
14932
|
context.camera.shaderData.setTexture(exports.Camera._cameraOpaqueTextureProperty, this._renderTarget.getColorTexture(0));
|
|
14820
14933
|
};
|
|
14821
14934
|
return OpaqueTexturePass;
|
|
@@ -14877,9 +14990,7 @@
|
|
|
14877
14990
|
var independentCanvasEnabled = camera.independentCanvasEnabled;
|
|
14878
14991
|
if (independentCanvasEnabled) {
|
|
14879
14992
|
var viewport = camera.pixelViewport;
|
|
14880
|
-
var internalColorTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._internalColorTarget, viewport.width, viewport.height,
|
|
14881
|
-
var colorTexture = internalColorTarget.getColorTexture(0);
|
|
14882
|
-
colorTexture.wrapModeU = colorTexture.wrapModeV = exports.TextureWrapMode.Clamp;
|
|
14993
|
+
var internalColorTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._internalColorTarget, viewport.width, viewport.height, camera._getInternalColorTextureFormat(), exports.TextureFormat.Depth24Stencil8, false, false, camera.msaaSamples, exports.TextureWrapMode.Clamp, exports.TextureFilterMode.Bilinear);
|
|
14883
14994
|
this._internalColorTarget = internalColorTarget;
|
|
14884
14995
|
} else {
|
|
14885
14996
|
var internalColorTarget1 = this._internalColorTarget;
|
|
@@ -14893,17 +15004,16 @@
|
|
|
14893
15004
|
this._drawRenderPass(context, camera, cubeFace, mipLevel, ignoreClear);
|
|
14894
15005
|
};
|
|
14895
15006
|
_proto._drawRenderPass = function _drawRenderPass(context, camera, cubeFace, mipLevel, ignoreClear) {
|
|
14896
|
-
var
|
|
15007
|
+
var _cameraRenderTarget, _cameraRenderTarget1;
|
|
14897
15008
|
var cullingResults = this._cullingResults;
|
|
14898
15009
|
var opaqueQueue = cullingResults.opaqueQueue, alphaTestQueue = cullingResults.alphaTestQueue, transparentQueue = cullingResults.transparentQueue;
|
|
14899
15010
|
var engine = camera.engine, scene = camera.scene;
|
|
14900
15011
|
var background = scene.background;
|
|
14901
|
-
var internalColorTarget = this._internalColorTarget;
|
|
14902
15012
|
var rhi = engine._hardwareRenderer;
|
|
14903
|
-
var
|
|
14904
|
-
var colorTarget =
|
|
15013
|
+
var internalColorTarget = this._internalColorTarget;
|
|
15014
|
+
var colorTarget = internalColorTarget || camera.renderTarget;
|
|
14905
15015
|
var colorViewport = internalColorTarget ? PipelineUtils.defaultViewport : camera.viewport;
|
|
14906
|
-
var needFlipProjection = camera.renderTarget && cubeFace == undefined
|
|
15016
|
+
var needFlipProjection = !!internalColorTarget || camera.renderTarget && cubeFace == undefined;
|
|
14907
15017
|
if (context.flipProjection !== needFlipProjection) {
|
|
14908
15018
|
// Just add projection matrix update type is enough
|
|
14909
15019
|
context.rendererUpdateFlag |= ContextRendererUpdateFlag.ProjectionMatrix;
|
|
@@ -14930,18 +15040,23 @@
|
|
|
14930
15040
|
colorTarget._blitRenderTarget();
|
|
14931
15041
|
var opaqueTexturePass = this._opaqueTexturePass;
|
|
14932
15042
|
opaqueTexturePass.onConfig(camera, colorTarget.getColorTexture(0));
|
|
14933
|
-
opaqueTexturePass.onRender(context
|
|
15043
|
+
opaqueTexturePass.onRender(context);
|
|
14934
15044
|
// Should revert to original render target
|
|
14935
15045
|
rhi.activeRenderTarget(colorTarget, colorViewport, context.flipProjection, mipLevel, cubeFace);
|
|
14936
15046
|
} else {
|
|
14937
15047
|
camera.shaderData.setTexture(exports.Camera._cameraOpaqueTextureProperty, null);
|
|
14938
15048
|
}
|
|
14939
15049
|
transparentQueue.render(context, exports.PipelineStage.Forward);
|
|
14940
|
-
|
|
14941
|
-
|
|
14942
|
-
if (
|
|
14943
|
-
|
|
15050
|
+
var postProcessManager = scene._postProcessManager;
|
|
15051
|
+
var cameraRenderTarget = camera.renderTarget;
|
|
15052
|
+
if (camera.enablePostProcess && postProcessManager.hasActiveEffect) {
|
|
15053
|
+
postProcessManager._render(context, internalColorTarget, cameraRenderTarget);
|
|
15054
|
+
} else if (internalColorTarget) {
|
|
15055
|
+
internalColorTarget._blitRenderTarget();
|
|
15056
|
+
PipelineUtils.blitTexture(engine, internalColorTarget.getColorTexture(0), cameraRenderTarget, 0, camera.viewport);
|
|
14944
15057
|
}
|
|
15058
|
+
(_cameraRenderTarget = cameraRenderTarget) == null ? void 0 : _cameraRenderTarget._blitRenderTarget();
|
|
15059
|
+
(_cameraRenderTarget1 = cameraRenderTarget) == null ? void 0 : _cameraRenderTarget1.generateMipmaps();
|
|
14945
15060
|
};
|
|
14946
15061
|
/**
|
|
14947
15062
|
* Push render data to render queue.
|
|
@@ -14967,6 +15082,7 @@
|
|
|
14967
15082
|
break;
|
|
14968
15083
|
}
|
|
14969
15084
|
}
|
|
15085
|
+
context.replacementFailureStrategy === exports.ReplacementFailureStrategy.KeepOriginalShader && this.pushRenderElementByType(renderElement, subRenderElement, materialSubShader.passes, renderStates);
|
|
14970
15086
|
} else {
|
|
14971
15087
|
this.pushRenderElementByType(renderElement, subRenderElement, replacementSubShaders[0].passes, renderStates);
|
|
14972
15088
|
}
|
|
@@ -23088,37 +23204,29 @@
|
|
|
23088
23204
|
-1,
|
|
23089
23205
|
0,
|
|
23090
23206
|
1,
|
|
23091
|
-
|
|
23207
|
+
3,
|
|
23092
23208
|
-1,
|
|
23093
|
-
|
|
23209
|
+
2,
|
|
23094
23210
|
1,
|
|
23095
23211
|
-1,
|
|
23096
|
-
|
|
23097
|
-
0,
|
|
23212
|
+
3,
|
|
23098
23213
|
0,
|
|
23099
|
-
1
|
|
23100
|
-
|
|
23101
|
-
1,
|
|
23102
|
-
0
|
|
23103
|
-
]); // right-top
|
|
23214
|
+
-1
|
|
23215
|
+
]); // left-top
|
|
23104
23216
|
// prettier-ignore
|
|
23105
23217
|
var flipYVertices = new Float32Array([
|
|
23106
|
-
|
|
23218
|
+
3,
|
|
23107
23219
|
-1,
|
|
23108
|
-
|
|
23220
|
+
2,
|
|
23109
23221
|
0,
|
|
23110
23222
|
-1,
|
|
23111
23223
|
-1,
|
|
23112
23224
|
0,
|
|
23113
23225
|
0,
|
|
23114
|
-
1,
|
|
23115
|
-
1,
|
|
23116
|
-
1,
|
|
23117
|
-
1,
|
|
23118
23226
|
-1,
|
|
23119
|
-
|
|
23227
|
+
3,
|
|
23120
23228
|
0,
|
|
23121
|
-
|
|
23229
|
+
2
|
|
23122
23230
|
]); // left-top
|
|
23123
23231
|
var blitMaterial = new Material(engine, Shader.find("blit"));
|
|
23124
23232
|
blitMaterial._addReferCount(1);
|
|
@@ -23156,7 +23264,7 @@
|
|
|
23156
23264
|
new VertexElement("POSITION_UV", 0, exports.VertexElementFormat.Vector4, 0)
|
|
23157
23265
|
]);
|
|
23158
23266
|
mesh.setVertexBufferBinding(new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices, exports.BufferUsage.Static), 16);
|
|
23159
|
-
mesh.addSubMesh(0,
|
|
23267
|
+
mesh.addSubMesh(0, 3, exports.MeshTopology.Triangles);
|
|
23160
23268
|
return mesh;
|
|
23161
23269
|
};
|
|
23162
23270
|
_proto._create1x1Texture = function _create1x1Texture(engine, type, format, pixel) {
|
|
@@ -27981,7 +28089,7 @@
|
|
|
27981
28089
|
*/ _proto._initialize = function _initialize(configuration) {
|
|
27982
28090
|
var _this = this;
|
|
27983
28091
|
var shaderLab = configuration.shaderLab, physics = configuration.physics;
|
|
27984
|
-
if (shaderLab) {
|
|
28092
|
+
if (shaderLab && !Shader._shaderLab) {
|
|
27985
28093
|
Shader._shaderLab = shaderLab;
|
|
27986
28094
|
}
|
|
27987
28095
|
var initializePromises = new Array();
|
|
@@ -29514,6 +29622,458 @@
|
|
|
29514
29622
|
* Each type of light source is at most 10, beyond which it will not take effect.
|
|
29515
29623
|
* */ LightManager._maxLight = 10;
|
|
29516
29624
|
})();
|
|
29625
|
+
var fragBlurH = "#define GLSLIFY 1\n#include <PostCommon>\nvarying vec2 v_uv;uniform sampler2D renderer_BlitTexture;uniform vec4 renderer_texelSize;void main(){vec2 texelSize=renderer_texelSize.xy*2.0;mediump vec4 c0=sampleTexture(renderer_BlitTexture,v_uv-vec2(texelSize.x*4.0,0.0));mediump vec4 c1=sampleTexture(renderer_BlitTexture,v_uv-vec2(texelSize.x*3.0,0.0));mediump vec4 c2=sampleTexture(renderer_BlitTexture,v_uv-vec2(texelSize.x*2.0,0.0));mediump vec4 c3=sampleTexture(renderer_BlitTexture,v_uv-vec2(texelSize.x*1.0,0.0));mediump vec4 c4=sampleTexture(renderer_BlitTexture,v_uv);mediump vec4 c5=sampleTexture(renderer_BlitTexture,v_uv+vec2(texelSize.x*1.0,0.0));mediump vec4 c6=sampleTexture(renderer_BlitTexture,v_uv+vec2(texelSize.x*2.0,0.0));mediump vec4 c7=sampleTexture(renderer_BlitTexture,v_uv+vec2(texelSize.x*3.0,0.0));mediump vec4 c8=sampleTexture(renderer_BlitTexture,v_uv+vec2(texelSize.x*4.0,0.0));gl_FragColor=c0*0.01621622+c1*0.05405405+c2*0.12162162+c3*0.19459459+c4*0.22702703+c5*0.19459459+c6*0.12162162+c7*0.05405405+c8*0.01621622;\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ngl_FragColor=linearToGamma(gl_FragColor);\n#endif\n}"; // eslint-disable-line
|
|
29626
|
+
var fragBlurV = "#define GLSLIFY 1\n#include <PostCommon>\nvarying vec2 v_uv;uniform sampler2D renderer_BlitTexture;uniform vec4 renderer_texelSize;void main(){vec2 texelSize=renderer_texelSize.xy;mediump vec4 c0=sampleTexture(renderer_BlitTexture,v_uv-vec2(0.0,texelSize.y*3.23076923));mediump vec4 c1=sampleTexture(renderer_BlitTexture,v_uv-vec2(0.0,texelSize.y*1.38461538));mediump vec4 c2=sampleTexture(renderer_BlitTexture,v_uv);mediump vec4 c3=sampleTexture(renderer_BlitTexture,v_uv+vec2(0.0,texelSize.y*1.38461538));mediump vec4 c4=sampleTexture(renderer_BlitTexture,v_uv+vec2(0.0,texelSize.y*3.23076923));gl_FragColor=c0*0.07027027+c1*0.31621622+c2*0.22702703+c3*0.31621622+c4*0.07027027;\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ngl_FragColor=linearToGamma(gl_FragColor);\n#endif\n}"; // eslint-disable-line
|
|
29627
|
+
var fragPrefilter = "#define GLSLIFY 1\n#include <PostCommon>\nvarying vec2 v_uv;uniform sampler2D renderer_BlitTexture;uniform vec4 material_BloomParams;uniform vec4 renderer_texelSize;void main(){\n#ifdef BLOOM_HQ\nvec2 texelSize=renderer_texelSize.xy;mediump vec4 A=sampleTexture(renderer_BlitTexture,v_uv+texelSize*vec2(-1.0,-1.0));mediump vec4 B=sampleTexture(renderer_BlitTexture,v_uv+texelSize*vec2(0.0,-1.0));mediump vec4 C=sampleTexture(renderer_BlitTexture,v_uv+texelSize*vec2(1.0,-1.0));mediump vec4 D=sampleTexture(renderer_BlitTexture,v_uv+texelSize*vec2(-0.5,-0.5));mediump vec4 E=sampleTexture(renderer_BlitTexture,v_uv+texelSize*vec2(0.5,-0.5));mediump vec4 F=sampleTexture(renderer_BlitTexture,v_uv+texelSize*vec2(-1.0,0.0));mediump vec4 G=sampleTexture(renderer_BlitTexture,v_uv);mediump vec4 H=sampleTexture(renderer_BlitTexture,v_uv+texelSize*vec2(1.0,0.0));mediump vec4 I=sampleTexture(renderer_BlitTexture,v_uv+texelSize*vec2(-0.5,0.5));mediump vec4 J=sampleTexture(renderer_BlitTexture,v_uv+texelSize*vec2(0.5,0.5));mediump vec4 K=sampleTexture(renderer_BlitTexture,v_uv+texelSize*vec2(-1.0,1.0));mediump vec4 L=sampleTexture(renderer_BlitTexture,v_uv+texelSize*vec2(0.0,1.0));mediump vec4 M=sampleTexture(renderer_BlitTexture,v_uv+texelSize*vec2(1.0,1.0));mediump vec2 scale=vec2(0.5,0.125);mediump vec2 div=(1.0/4.0)*scale;mediump vec4 samplerColor=(D+E+I+J)*div.x;samplerColor+=(A+B+G+F)*div.y;samplerColor+=(B+C+H+G)*div.y;samplerColor+=(F+G+L+K)*div.y;samplerColor+=(G+H+M+L)*div.y;\n#else\nmediump vec4 samplerColor=sampleTexture(renderer_BlitTexture,v_uv);\n#endif\nmediump vec3 color=samplerColor.rgb;color=min(color,HALF_MAX);mediump float brightness=max3(color);float threshold=material_BloomParams.x;float thresholdKnee=material_BloomParams.y;mediump float softness=clamp(brightness-threshold+thresholdKnee,0.0,2.0*thresholdKnee);softness=(softness*softness)/(4.0*thresholdKnee+1e-4);mediump float multiplier=max(brightness-threshold,softness)/max(brightness,1e-4);color*=multiplier;color=max(color,0.0);gl_FragColor=vec4(color,samplerColor.a);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ngl_FragColor=linearToGamma(gl_FragColor);\n#endif\n}"; // eslint-disable-line
|
|
29628
|
+
var fragUpsample = "#define GLSLIFY 1\n#include <PostCommon>\n#include <Filtering>\nvarying vec2 v_uv;uniform sampler2D renderer_BlitTexture;uniform sampler2D material_lowMipTexture;uniform vec4 material_BloomParams;uniform vec4 material_lowMipTexelSize;void main(){mediump vec4 highMip=sampleTexture(renderer_BlitTexture,v_uv);\n#ifdef BLOOM_HQ\nmediump vec4 lowMip=sampleTexture2DBicubic(material_lowMipTexture,v_uv,material_lowMipTexelSize);\n#else\nmediump vec4 lowMip=sampleTexture(material_lowMipTexture,v_uv);\n#endif\ngl_FragColor=mix(highMip,lowMip,material_BloomParams.z);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ngl_FragColor=linearToGamma(gl_FragColor);\n#endif\n}"; // eslint-disable-line
|
|
29629
|
+
exports.BloomDownScaleMode = void 0;
|
|
29630
|
+
(function(BloomDownScaleMode) {
|
|
29631
|
+
BloomDownScaleMode[BloomDownScaleMode[/**
|
|
29632
|
+
* Use this to select half size as the starting resolution.
|
|
29633
|
+
*/ "Half"] = 0] = "Half";
|
|
29634
|
+
BloomDownScaleMode[BloomDownScaleMode[/**
|
|
29635
|
+
* Use this to select quarter size as the starting resolution.
|
|
29636
|
+
*/ "Quarter"] = 1] = "Quarter";
|
|
29637
|
+
})(exports.BloomDownScaleMode || (exports.BloomDownScaleMode = {}));
|
|
29638
|
+
var BloomEffect = /*#__PURE__*/ function() {
|
|
29639
|
+
function BloomEffect(_uberMaterial) {
|
|
29640
|
+
this._uberMaterial = _uberMaterial;
|
|
29641
|
+
this._highQualityFiltering = false;
|
|
29642
|
+
this._mipDownRT = [];
|
|
29643
|
+
this._mipUpRT = [];
|
|
29644
|
+
this._maxIterations = 6;
|
|
29645
|
+
this._enabled = false;
|
|
29646
|
+
this./**
|
|
29647
|
+
* Controls the starting resolution that this effect begins processing.
|
|
29648
|
+
*/ downScale = 0;
|
|
29649
|
+
var engine = _uberMaterial.engine;
|
|
29650
|
+
var material = new Material(engine, Shader.find(BloomEffect.SHADER_NAME));
|
|
29651
|
+
var depthState = material.renderState.depthState;
|
|
29652
|
+
depthState.enabled = false;
|
|
29653
|
+
depthState.writeEnabled = false;
|
|
29654
|
+
var bloomShaderData = material.shaderData;
|
|
29655
|
+
var uberShaderData = _uberMaterial.shaderData;
|
|
29656
|
+
bloomShaderData.setVector4(BloomEffect._bloomParams, new Vector4());
|
|
29657
|
+
bloomShaderData.setVector4(BloomEffect._lowMipTexelSizeProp, new Vector4());
|
|
29658
|
+
uberShaderData.setVector4(BloomEffect._bloomIntensityParams, new Vector4(1, 1, 0, 0));
|
|
29659
|
+
uberShaderData.setVector4(BloomEffect._dirtTilingOffsetProp, new Vector4());
|
|
29660
|
+
uberShaderData.setColor(BloomEffect._tintProp, new Color(1, 1, 1, 1));
|
|
29661
|
+
this._bloomMaterial = material;
|
|
29662
|
+
this.threshold = 0.9;
|
|
29663
|
+
this.scatter = 0.7;
|
|
29664
|
+
this.intensity = 1;
|
|
29665
|
+
this.dirtIntensity = 1;
|
|
29666
|
+
}
|
|
29667
|
+
var _proto = BloomEffect.prototype;
|
|
29668
|
+
_proto.onRender = function onRender(context, srcTexture) {
|
|
29669
|
+
var camera = context.camera;
|
|
29670
|
+
var downRes = this.downScale === 0 ? 1 : 2;
|
|
29671
|
+
var pixelViewport = camera.pixelViewport;
|
|
29672
|
+
var tw = pixelViewport.width >> downRes;
|
|
29673
|
+
var th = pixelViewport.height >> downRes;
|
|
29674
|
+
// Determine the iteration count
|
|
29675
|
+
var mipCount = this._calculateMipCount(tw, th);
|
|
29676
|
+
// Prefilter
|
|
29677
|
+
this._prefilter(camera, srcTexture, tw, th, mipCount);
|
|
29678
|
+
// Down sample - gaussian pyramid
|
|
29679
|
+
this._downsample(mipCount);
|
|
29680
|
+
// Up sample (bilinear by default, HQ filtering does bicubic instead
|
|
29681
|
+
this._upsample(mipCount);
|
|
29682
|
+
// Setup bloom on uber
|
|
29683
|
+
this._setupUber(camera);
|
|
29684
|
+
};
|
|
29685
|
+
_proto._calculateMipCount = function _calculateMipCount(tw, th) {
|
|
29686
|
+
var maxSize = Math.max(tw, th);
|
|
29687
|
+
var iterations = Math.floor(Math.log2(maxSize) - 1);
|
|
29688
|
+
return Math.min(Math.max(iterations, 1), this._maxIterations);
|
|
29689
|
+
};
|
|
29690
|
+
_proto._prefilter = function _prefilter(camera, srcTexture, tw, th, mipCount) {
|
|
29691
|
+
var engine = this._uberMaterial.engine;
|
|
29692
|
+
var internalColorTextureFormat = camera._getInternalColorTextureFormat();
|
|
29693
|
+
var mipWidth = tw, mipHeight = th;
|
|
29694
|
+
for(var i = 0; i < mipCount; i++){
|
|
29695
|
+
this._mipUpRT[i] = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._mipUpRT[i], mipWidth, mipHeight, internalColorTextureFormat, null, false, false, 1, exports.TextureWrapMode.Clamp, exports.TextureFilterMode.Bilinear);
|
|
29696
|
+
this._mipDownRT[i] = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._mipDownRT[i], mipWidth, mipHeight, internalColorTextureFormat, null, false, false, 1, exports.TextureWrapMode.Clamp, exports.TextureFilterMode.Bilinear);
|
|
29697
|
+
mipWidth = Math.max(1, Math.floor(mipWidth / 2));
|
|
29698
|
+
mipHeight = Math.max(1, Math.floor(mipHeight / 2));
|
|
29699
|
+
}
|
|
29700
|
+
PipelineUtils.blitTexture(engine, srcTexture, this._mipDownRT[0], undefined, undefined, this._bloomMaterial, 0);
|
|
29701
|
+
};
|
|
29702
|
+
_proto._downsample = function _downsample(mipCount) {
|
|
29703
|
+
var material = this._bloomMaterial;
|
|
29704
|
+
var engine = material.engine;
|
|
29705
|
+
var lastDown = this._mipDownRT[0];
|
|
29706
|
+
// Down sample - gaussian pyramid
|
|
29707
|
+
for(var i = 1; i < mipCount; i++){
|
|
29708
|
+
// Classic two pass gaussian blur - use mipUp as a temporary target
|
|
29709
|
+
// First pass does 2x downsampling + 9-tap gaussian
|
|
29710
|
+
// Second pass does 9-tap gaussian using a 5-tap filter + bilinear filtering
|
|
29711
|
+
PipelineUtils.blitTexture(engine, lastDown.getColorTexture(0), this._mipUpRT[i], undefined, undefined, material, 1);
|
|
29712
|
+
PipelineUtils.blitTexture(engine, this._mipUpRT[i].getColorTexture(0), this._mipDownRT[i], undefined, undefined, material, 2);
|
|
29713
|
+
lastDown = this._mipDownRT[i];
|
|
29714
|
+
}
|
|
29715
|
+
};
|
|
29716
|
+
_proto._upsample = function _upsample(mipCount) {
|
|
29717
|
+
var material = this._bloomMaterial;
|
|
29718
|
+
var engine = material.engine;
|
|
29719
|
+
var shaderData = material.shaderData;
|
|
29720
|
+
// Up sample (bilinear by default, HQ filtering does bicubic instead
|
|
29721
|
+
for(var i = mipCount - 2; i >= 0; i--){
|
|
29722
|
+
var lowMip = i == mipCount - 2 ? this._mipDownRT[i + 1] : this._mipUpRT[i + 1];
|
|
29723
|
+
var highMip = this._mipDownRT[i];
|
|
29724
|
+
var dst = this._mipUpRT[i];
|
|
29725
|
+
shaderData.setTexture(BloomEffect._lowMipTextureProp, lowMip.getColorTexture(0));
|
|
29726
|
+
if (this.highQualityFiltering) {
|
|
29727
|
+
var texelSizeLow = shaderData.getVector4(BloomEffect._lowMipTexelSizeProp);
|
|
29728
|
+
texelSizeLow.set(1 / lowMip.width, 1 / lowMip.height, lowMip.width, lowMip.height);
|
|
29729
|
+
}
|
|
29730
|
+
PipelineUtils.blitTexture(engine, highMip.getColorTexture(0), dst, undefined, undefined, material, 3);
|
|
29731
|
+
}
|
|
29732
|
+
};
|
|
29733
|
+
_proto._setupUber = function _setupUber(camera) {
|
|
29734
|
+
var shaderData = this._uberMaterial.shaderData;
|
|
29735
|
+
var dirtTexture = this.dirtTexture;
|
|
29736
|
+
if (dirtTexture) {
|
|
29737
|
+
var dirtTilingOffset = shaderData.getVector4(BloomEffect._dirtTilingOffsetProp);
|
|
29738
|
+
var dirtRatio = dirtTexture.width / dirtTexture.height;
|
|
29739
|
+
var screenRatio = camera.aspectRatio;
|
|
29740
|
+
if (dirtRatio > screenRatio) {
|
|
29741
|
+
dirtTilingOffset.set(screenRatio / dirtRatio, 1, (1 - dirtTilingOffset.x) * 0.5, 0);
|
|
29742
|
+
} else if (dirtRatio < screenRatio) {
|
|
29743
|
+
dirtTilingOffset.set(1, dirtRatio / screenRatio, 0, (1 - dirtTilingOffset.y) * 0.5);
|
|
29744
|
+
} else {
|
|
29745
|
+
dirtTilingOffset.set(1, 1, 0, 0);
|
|
29746
|
+
}
|
|
29747
|
+
}
|
|
29748
|
+
shaderData.setTexture(BloomEffect._bloomTextureProp, this._mipUpRT[0].getColorTexture(0));
|
|
29749
|
+
};
|
|
29750
|
+
_proto._releaseRenderTargets = function _releaseRenderTargets() {
|
|
29751
|
+
var length = this._mipDownRT.length;
|
|
29752
|
+
for(var i = 0; i < length; i++){
|
|
29753
|
+
var downRT = this._mipDownRT[i];
|
|
29754
|
+
var upRT = this._mipUpRT[i];
|
|
29755
|
+
if (downRT) {
|
|
29756
|
+
downRT.getColorTexture(0).destroy(true);
|
|
29757
|
+
downRT.destroy(true);
|
|
29758
|
+
}
|
|
29759
|
+
if (upRT) {
|
|
29760
|
+
upRT.getColorTexture(0).destroy(true);
|
|
29761
|
+
upRT.destroy(true);
|
|
29762
|
+
}
|
|
29763
|
+
}
|
|
29764
|
+
this._mipDownRT.length = 0;
|
|
29765
|
+
this._mipUpRT.length = 0;
|
|
29766
|
+
};
|
|
29767
|
+
_create_class$2(BloomEffect, [
|
|
29768
|
+
{
|
|
29769
|
+
key: "enabled",
|
|
29770
|
+
get: /**
|
|
29771
|
+
* Indicates whether the post process effect is enabled.
|
|
29772
|
+
*/ function get() {
|
|
29773
|
+
return this._enabled;
|
|
29774
|
+
},
|
|
29775
|
+
set: function set(value) {
|
|
29776
|
+
if (value !== this._enabled) {
|
|
29777
|
+
this._enabled = value;
|
|
29778
|
+
if (value) {
|
|
29779
|
+
this._uberMaterial.shaderData.enableMacro(BloomEffect._enableMacro);
|
|
29780
|
+
} else {
|
|
29781
|
+
this._uberMaterial.shaderData.disableMacro(BloomEffect._enableMacro);
|
|
29782
|
+
this._releaseRenderTargets();
|
|
29783
|
+
}
|
|
29784
|
+
}
|
|
29785
|
+
}
|
|
29786
|
+
},
|
|
29787
|
+
{
|
|
29788
|
+
key: "threshold",
|
|
29789
|
+
get: /**
|
|
29790
|
+
* Set the level of brightness to filter out pixels under this level.
|
|
29791
|
+
* @remarks This value is expressed in gamma-space.
|
|
29792
|
+
*/ function get() {
|
|
29793
|
+
return this._threshold;
|
|
29794
|
+
},
|
|
29795
|
+
set: function set(value) {
|
|
29796
|
+
value = Math.max(0, value);
|
|
29797
|
+
if (value !== this._threshold) {
|
|
29798
|
+
this._threshold = value;
|
|
29799
|
+
var threshold = Color.gammaToLinearSpace(value);
|
|
29800
|
+
var thresholdKnee = threshold * 0.5; // Hardcoded soft knee
|
|
29801
|
+
var params = this._bloomMaterial.shaderData.getVector4(BloomEffect._bloomParams);
|
|
29802
|
+
params.x = threshold;
|
|
29803
|
+
params.y = thresholdKnee;
|
|
29804
|
+
}
|
|
29805
|
+
}
|
|
29806
|
+
},
|
|
29807
|
+
{
|
|
29808
|
+
key: "scatter",
|
|
29809
|
+
get: /**
|
|
29810
|
+
* Controls the radius of the bloom effect.
|
|
29811
|
+
*/ function get() {
|
|
29812
|
+
return this._scatter;
|
|
29813
|
+
},
|
|
29814
|
+
set: function set(value) {
|
|
29815
|
+
value = Math.min(Math.max(0, value), 1);
|
|
29816
|
+
if (value !== this._scatter) {
|
|
29817
|
+
this._scatter = value;
|
|
29818
|
+
var params = this._bloomMaterial.shaderData.getVector4(BloomEffect._bloomParams);
|
|
29819
|
+
var scatter = MathUtil.lerp(0.05, 0.95, value);
|
|
29820
|
+
params.z = scatter;
|
|
29821
|
+
}
|
|
29822
|
+
}
|
|
29823
|
+
},
|
|
29824
|
+
{
|
|
29825
|
+
key: "intensity",
|
|
29826
|
+
get: /**
|
|
29827
|
+
* Controls the strength of the bloom effect.
|
|
29828
|
+
*/ function get() {
|
|
29829
|
+
return this._uberMaterial.shaderData.getVector4(BloomEffect._bloomIntensityParams).x;
|
|
29830
|
+
},
|
|
29831
|
+
set: function set(value) {
|
|
29832
|
+
value = Math.max(0, value);
|
|
29833
|
+
this._uberMaterial.shaderData.getVector4(BloomEffect._bloomIntensityParams).x = value;
|
|
29834
|
+
}
|
|
29835
|
+
},
|
|
29836
|
+
{
|
|
29837
|
+
key: "tint",
|
|
29838
|
+
get: /**
|
|
29839
|
+
* Specifies the tint of the bloom effect.
|
|
29840
|
+
*/ function get() {
|
|
29841
|
+
return this._uberMaterial.shaderData.getColor(BloomEffect._tintProp);
|
|
29842
|
+
},
|
|
29843
|
+
set: function set(value) {
|
|
29844
|
+
var tint = this._uberMaterial.shaderData.getColor(BloomEffect._tintProp);
|
|
29845
|
+
if (value !== tint) {
|
|
29846
|
+
tint.copyFrom(value);
|
|
29847
|
+
}
|
|
29848
|
+
}
|
|
29849
|
+
},
|
|
29850
|
+
{
|
|
29851
|
+
key: "highQualityFiltering",
|
|
29852
|
+
get: /**
|
|
29853
|
+
* Controls whether to use bicubic sampling instead of bilinear sampling for the upSampling passes.
|
|
29854
|
+
* @remarks This is slightly more expensive but helps getting smoother visuals.
|
|
29855
|
+
*/ function get() {
|
|
29856
|
+
return this._highQualityFiltering;
|
|
29857
|
+
},
|
|
29858
|
+
set: function set(value) {
|
|
29859
|
+
if (value !== this._highQualityFiltering) {
|
|
29860
|
+
this._highQualityFiltering = value;
|
|
29861
|
+
if (value) {
|
|
29862
|
+
this._bloomMaterial.shaderData.enableMacro(BloomEffect._hqMacro);
|
|
29863
|
+
this._uberMaterial.shaderData.enableMacro(BloomEffect._hqMacro);
|
|
29864
|
+
} else {
|
|
29865
|
+
this._bloomMaterial.shaderData.disableMacro(BloomEffect._hqMacro);
|
|
29866
|
+
this._uberMaterial.shaderData.disableMacro(BloomEffect._hqMacro);
|
|
29867
|
+
}
|
|
29868
|
+
}
|
|
29869
|
+
}
|
|
29870
|
+
},
|
|
29871
|
+
{
|
|
29872
|
+
key: "dirtTexture",
|
|
29873
|
+
get: /**
|
|
29874
|
+
* Specifies a Texture to add smudges or dust to the bloom effect.
|
|
29875
|
+
*/ function get() {
|
|
29876
|
+
return this._uberMaterial.shaderData.getTexture(BloomEffect._dirtTextureProp);
|
|
29877
|
+
},
|
|
29878
|
+
set: function set(value) {
|
|
29879
|
+
this._uberMaterial.shaderData.setTexture(BloomEffect._dirtTextureProp, value);
|
|
29880
|
+
if (value) {
|
|
29881
|
+
this._uberMaterial.shaderData.enableMacro(BloomEffect._dirtMacro);
|
|
29882
|
+
} else {
|
|
29883
|
+
this._uberMaterial.shaderData.disableMacro(BloomEffect._dirtMacro);
|
|
29884
|
+
}
|
|
29885
|
+
}
|
|
29886
|
+
},
|
|
29887
|
+
{
|
|
29888
|
+
key: "dirtIntensity",
|
|
29889
|
+
get: /**
|
|
29890
|
+
* Controls the strength of the lens dirt.
|
|
29891
|
+
*/ function get() {
|
|
29892
|
+
return this._uberMaterial.shaderData.getVector4(BloomEffect._bloomIntensityParams).y;
|
|
29893
|
+
},
|
|
29894
|
+
set: function set(value) {
|
|
29895
|
+
value = Math.max(0, value);
|
|
29896
|
+
this._uberMaterial.shaderData.getVector4(BloomEffect._bloomIntensityParams).y = value;
|
|
29897
|
+
}
|
|
29898
|
+
}
|
|
29899
|
+
]);
|
|
29900
|
+
return BloomEffect;
|
|
29901
|
+
}();
|
|
29902
|
+
(function() {
|
|
29903
|
+
BloomEffect.SHADER_NAME = "PostProcessEffect Bloom";
|
|
29904
|
+
})();
|
|
29905
|
+
(function() {
|
|
29906
|
+
// Bloom shader properties
|
|
29907
|
+
BloomEffect._hqMacro = ShaderMacro.getByName("BLOOM_HQ");
|
|
29908
|
+
})();
|
|
29909
|
+
(function() {
|
|
29910
|
+
BloomEffect._dirtMacro = ShaderMacro.getByName("BLOOM_DIRT");
|
|
29911
|
+
})();
|
|
29912
|
+
(function() {
|
|
29913
|
+
BloomEffect._bloomParams = ShaderProperty.getByName("material_BloomParams") // x: threshold (linear), y: threshold knee, z: scatter
|
|
29914
|
+
;
|
|
29915
|
+
})();
|
|
29916
|
+
(function() {
|
|
29917
|
+
BloomEffect._lowMipTextureProp = ShaderProperty.getByName("material_lowMipTexture");
|
|
29918
|
+
})();
|
|
29919
|
+
(function() {
|
|
29920
|
+
BloomEffect._lowMipTexelSizeProp = ShaderProperty.getByName("material_lowMipTexelSize") // x: 1/width, y: 1/height, z: width, w: height
|
|
29921
|
+
;
|
|
29922
|
+
})();
|
|
29923
|
+
(function() {
|
|
29924
|
+
// Uber shader properties
|
|
29925
|
+
BloomEffect._enableMacro = ShaderMacro.getByName("ENABLE_EFFECT_BLOOM");
|
|
29926
|
+
})();
|
|
29927
|
+
(function() {
|
|
29928
|
+
BloomEffect._bloomTextureProp = ShaderProperty.getByName("material_BloomTexture");
|
|
29929
|
+
})();
|
|
29930
|
+
(function() {
|
|
29931
|
+
BloomEffect._dirtTextureProp = ShaderProperty.getByName("material_BloomDirtTexture");
|
|
29932
|
+
})();
|
|
29933
|
+
(function() {
|
|
29934
|
+
BloomEffect._tintProp = ShaderProperty.getByName("material_BloomTint");
|
|
29935
|
+
})();
|
|
29936
|
+
(function() {
|
|
29937
|
+
BloomEffect._bloomIntensityParams = ShaderProperty.getByName("material_BloomIntensityParams") // x: bloom intensity, y: dirt intensity
|
|
29938
|
+
;
|
|
29939
|
+
})();
|
|
29940
|
+
(function() {
|
|
29941
|
+
BloomEffect._dirtTilingOffsetProp = ShaderProperty.getByName("material_BloomDirtTilingOffset");
|
|
29942
|
+
})();
|
|
29943
|
+
Shader.create(BloomEffect.SHADER_NAME, [
|
|
29944
|
+
new ShaderPass("Bloom Prefilter", blitVs, fragPrefilter),
|
|
29945
|
+
new ShaderPass("Bloom Blur Horizontal", blitVs, fragBlurH),
|
|
29946
|
+
new ShaderPass("Bloom Blur Vertical", blitVs, fragBlurV),
|
|
29947
|
+
new ShaderPass("Bloom Upsample", blitVs, fragUpsample)
|
|
29948
|
+
]);
|
|
29949
|
+
exports.TonemappingMode = void 0;
|
|
29950
|
+
(function(TonemappingMode) {
|
|
29951
|
+
TonemappingMode[TonemappingMode[/**
|
|
29952
|
+
* Neutral tonemapper
|
|
29953
|
+
* @remarks Use this option if you only want range-remapping with minimal impact on color hue and saturation.
|
|
29954
|
+
*/ "Neutral"] = 0] = "Neutral";
|
|
29955
|
+
TonemappingMode[TonemappingMode[/**
|
|
29956
|
+
* ACES Filmic reference tonemapper (custom approximation)
|
|
29957
|
+
* @remarks
|
|
29958
|
+
* Use this option to apply a close approximation of the reference ACES tonemapper for a more filmic look.
|
|
29959
|
+
* It is more contrasted than Neutral and has an effect on actual color hue and saturation.
|
|
29960
|
+
*/ "ACES"] = 1] = "ACES";
|
|
29961
|
+
})(exports.TonemappingMode || (exports.TonemappingMode = {}));
|
|
29962
|
+
var TonemappingEffect = /*#__PURE__*/ function() {
|
|
29963
|
+
var TonemappingEffect = function TonemappingEffect(_uberMaterial) {
|
|
29964
|
+
this._uberMaterial = _uberMaterial;
|
|
29965
|
+
this._enabled = false;
|
|
29966
|
+
this.mode = 0;
|
|
29967
|
+
};
|
|
29968
|
+
_create_class$2(TonemappingEffect, [
|
|
29969
|
+
{
|
|
29970
|
+
key: "enabled",
|
|
29971
|
+
get: /**
|
|
29972
|
+
* Indicates whether the post process effect is enabled.
|
|
29973
|
+
*/ function get() {
|
|
29974
|
+
return this._enabled;
|
|
29975
|
+
},
|
|
29976
|
+
set: function set(value) {
|
|
29977
|
+
if (value !== this._enabled) {
|
|
29978
|
+
this._enabled = value;
|
|
29979
|
+
if (value) {
|
|
29980
|
+
this._uberMaterial.shaderData.enableMacro(TonemappingEffect._enableMacro);
|
|
29981
|
+
} else {
|
|
29982
|
+
this._uberMaterial.shaderData.disableMacro(TonemappingEffect._enableMacro);
|
|
29983
|
+
}
|
|
29984
|
+
}
|
|
29985
|
+
}
|
|
29986
|
+
},
|
|
29987
|
+
{
|
|
29988
|
+
key: "mode",
|
|
29989
|
+
get: /**
|
|
29990
|
+
* Use this to select a tonemapping algorithm to use.
|
|
29991
|
+
*/ function get() {
|
|
29992
|
+
return this._mode;
|
|
29993
|
+
},
|
|
29994
|
+
set: function set(value) {
|
|
29995
|
+
if (value !== this._mode) {
|
|
29996
|
+
this._mode = value;
|
|
29997
|
+
this._uberMaterial.shaderData.enableMacro("TONEMAPPING_MODE", value.toString());
|
|
29998
|
+
}
|
|
29999
|
+
}
|
|
30000
|
+
}
|
|
30001
|
+
]);
|
|
30002
|
+
return TonemappingEffect;
|
|
30003
|
+
}();
|
|
30004
|
+
(function() {
|
|
30005
|
+
TonemappingEffect._enableMacro = ShaderMacro.getByName("ENABLE_EFFECT_TONEMAPPING");
|
|
30006
|
+
})();
|
|
30007
|
+
/**
|
|
30008
|
+
* @internal
|
|
30009
|
+
*/ var _PostProcessManager = /*#__PURE__*/ function() {
|
|
30010
|
+
function _PostProcessManager(scene) {
|
|
30011
|
+
this.scene = scene;
|
|
30012
|
+
this./**
|
|
30013
|
+
* Whether the post process manager is active.
|
|
30014
|
+
*/ isActive = true;
|
|
30015
|
+
var uberShader = Shader.find(_PostProcessManager.UBER_SHADER_NAME);
|
|
30016
|
+
var uberMaterial = new Material(scene.engine, uberShader);
|
|
30017
|
+
var depthState = uberMaterial.renderState.depthState;
|
|
30018
|
+
depthState.enabled = false;
|
|
30019
|
+
depthState.writeEnabled = false;
|
|
30020
|
+
var bloomEffect = new BloomEffect(uberMaterial);
|
|
30021
|
+
var tonemappingEffect = new TonemappingEffect(uberMaterial);
|
|
30022
|
+
this._uberMaterial = uberMaterial;
|
|
30023
|
+
this._bloomEffect = bloomEffect;
|
|
30024
|
+
this._tonemappingEffect = tonemappingEffect;
|
|
30025
|
+
}
|
|
30026
|
+
var _proto = _PostProcessManager.prototype;
|
|
30027
|
+
/**
|
|
30028
|
+
* @internal
|
|
30029
|
+
*/ _proto._render = function _render(context, srcTarget, destTarget) {
|
|
30030
|
+
var camera = context.camera;
|
|
30031
|
+
var engine = camera.engine;
|
|
30032
|
+
// Should blit to resolve the MSAA
|
|
30033
|
+
srcTarget._blitRenderTarget();
|
|
30034
|
+
var srcTexture = srcTarget.getColorTexture();
|
|
30035
|
+
var bloomEffect = this._bloomEffect;
|
|
30036
|
+
if (bloomEffect.enabled) {
|
|
30037
|
+
bloomEffect.onRender(context, srcTexture);
|
|
30038
|
+
}
|
|
30039
|
+
// Done with Uber, blit it
|
|
30040
|
+
PipelineUtils.blitTexture(engine, srcTexture, destTarget, 0, camera.viewport, this._uberMaterial);
|
|
30041
|
+
};
|
|
30042
|
+
_create_class$2(_PostProcessManager, [
|
|
30043
|
+
{
|
|
30044
|
+
key: "hasActiveEffect",
|
|
30045
|
+
get: /**
|
|
30046
|
+
* Whether has active post process effect.
|
|
30047
|
+
*/ function get() {
|
|
30048
|
+
return this.isActive && (this._bloomEffect.enabled || this._tonemappingEffect.enabled);
|
|
30049
|
+
}
|
|
30050
|
+
}
|
|
30051
|
+
]);
|
|
30052
|
+
return _PostProcessManager;
|
|
30053
|
+
}();
|
|
30054
|
+
(function() {
|
|
30055
|
+
_PostProcessManager.UBER_SHADER_NAME = "UberPost";
|
|
30056
|
+
})();
|
|
30057
|
+
var Filtering = "#define GLSLIFY 1\n#ifndef FILTERING\n#define FILTERING\nvec2 bSpline3MiddleLeft(vec2 x){return 0.16666667+x*(0.5+x*(0.5-x*0.5));}vec2 bSpline3MiddleRight(vec2 x){return 0.66666667+x*(-1.0+0.5*x)*x;}vec2 bSpline3Rightmost(vec2 x){return 0.16666667+x*(-0.5+x*(0.5-x*0.16666667));}void bicubicFilter(vec2 fracCoord,out vec2 weights[2],out vec2 offsets[2]){vec2 r=bSpline3Rightmost(fracCoord);vec2 mr=bSpline3MiddleRight(fracCoord);vec2 ml=bSpline3MiddleLeft(fracCoord);vec2 l=1.0-mr-ml-r;weights[0]=r+mr;weights[1]=ml+l;offsets[0]=-1.0+mr/weights[0];offsets[1]=1.0+l/weights[1];}vec4 sampleTexture2DBicubic(sampler2D tex,vec2 coord,vec4 texSize){vec2 xy=coord*texSize.zw+0.5;vec2 ic=floor(xy);vec2 fc=fract(xy);vec2 weights[2],offsets[2];bicubicFilter(fc,weights,offsets);return weights[0].y*(weights[0].x*sampleTexture(tex,(ic+vec2(offsets[0].x,offsets[0].y)-0.5)*texSize.xy)+weights[1].x*sampleTexture(tex,(ic+vec2(offsets[1].x,offsets[0].y)-0.5)*texSize.xy))+weights[1].y*(weights[0].x*sampleTexture(tex,(ic+vec2(offsets[0].x,offsets[1].y)-0.5)*texSize.xy)+weights[1].x*sampleTexture(tex,(ic+vec2(offsets[1].x,offsets[1].y)-0.5)*texSize.xy));}\n#endif\n"; // eslint-disable-line
|
|
30058
|
+
var PostCommon = "#define GLSLIFY 1\n#ifndef POST_COMMON\n#define POST_COMMON\n#include <common>\n#define FLT_MIN 1.175494351e-38\n#define HALF_MIN 6.103515625e-5\n#define HALF_MAX 65504.0\nfloat min3(vec3 val){return min(min(val.x,val.y),val.z);}float max3(vec3 val){return max(max(val.x,val.y),val.z);}const float INVERT_LOG10=0.43429448190325176;float log10(float x){return log(x)*INVERT_LOG10;}vec4 sampleTexture(sampler2D tex,vec2 uv){vec4 color=texture2D(tex,uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ncolor=gammaToLinear(color);\n#endif\nreturn color;}\n#endif\n"; // eslint-disable-line
|
|
30059
|
+
var ACESTonemapping = "#define GLSLIFY 1\n#include <ColorTransform>\n#include <RRT>\n#include <ODT>\nvec3 ACESTonemap(vec3 color){vec3 aces=sRGB_2_AP0*color;mediump float saturation=rgb_2_saturation(aces);mediump float ycIn=rgb_2_yc(aces);mediump float s=sigmoid_shaper((saturation-0.4)/0.2);float addedGlow=1.0+glow_fwd(ycIn,RRT_GLOW_GAIN*s,RRT_GLOW_MID);aces*=addedGlow;mediump float hue=rgb_2_hue(vec3(aces));mediump float centeredHue=center_hue(hue,RRT_RED_HUE);float hueWeight=smoothstep(0.0,1.0,1.0-abs(2.0*centeredHue/RRT_RED_WIDTH));hueWeight*=hueWeight;aces.r+=hueWeight*saturation*(RRT_RED_PIVOT-aces.r)*(1.0-RRT_RED_SCALE);vec3 acescg=max(AP0_2_AP1_MAT*aces,0.0);acescg=mix(vec3(dot(acescg,AP1_RGB2Y)),acescg,RRT_SAT_FACTOR);const float a=0.0245786;const float b=0.000090537;const float c=0.983729;const float d=0.4329510;const float e=0.238081;vec3 rcpAcesCG=1.0/(acescg+FLT_MIN);mediump vec3 rgbPost=(acescg+a-b*rcpAcesCG)/(acescg*c+d+e*rcpAcesCG);vec3 linearCV=darkSurround_to_dimSurround(rgbPost);linearCV=mix(vec3(dot(linearCV,AP1_RGB2Y)),linearCV,ODT_SAT_FACTOR);vec3 XYZ=AP1_2_XYZ_MAT*linearCV;XYZ=D60_2_D65_CAT*XYZ;linearCV=XYZ_2_REC709_MAT*XYZ;return linearCV;}"; // eslint-disable-line
|
|
30060
|
+
var ColorTransform = "#define GLSLIFY 1\n#ifndef COLOR_TRANSFORM\n#define COLOR_TRANSFORM\nconst mediump mat3 sRGB_2_AP0=mat3(0.4397010,0.0897923,0.0175440,0.3829780,0.8134230,0.1115440,0.1773350,0.0967616,0.8707040);const mediump mat3 AP1_2_AP0_MAT=mat3(vec3(0.6954522414,0.0447945634,-0.0055258826),vec3(0.1406786965,0.8596711185,0.0040252103),vec3(0.1638690622,0.0955343182,1.0015006723));const mediump mat3 AP0_2_AP1_MAT=mat3(vec3(1.4514393161,-0.0765537734,0.0083161484),vec3(-0.2365107469,1.1762296998,-0.0060324498),vec3(-0.2149285693,-0.0996759264,0.9977163014));const mediump mat3 AP1_2_XYZ_MAT=mat3(vec3(0.6624541811,0.2722287168,-0.0055746495),vec3(0.1340042065,0.6740817658,0.0040607335),vec3(0.1561876870,0.0536895174,1.0103391003));const mediump mat3 XYZ_2_AP1_MAT=mat3(vec3(1.6410233797,-0.6636628587,0.0117218943),vec3(-0.3248032942,1.6153315917,-0.0082844420),vec3(-0.2364246952,0.0167563477,0.9883948585));const mediump mat3 D60_2_D65_CAT=mat3(vec3(0.987224,-0.00759836,0.00307257),vec3(-0.00611327,1.00186,-0.00509595),vec3(0.0159533,0.00533002,1.08168));const mediump mat3 XYZ_2_REC709_MAT=mat3(vec3(3.2409699419,-0.9692436363,0.0556300797),vec3(-1.5373831776,1.8759675015,-0.2039769589),vec3(-0.498610760,0.0415550574,1.0569715142));const mediump vec3 AP1_RGB2Y=vec3(0.2722287168,0.6740817658,0.0536895174);mediump float rgb_2_saturation(mediump vec3 rgb){const mediump float TINY=1e-4;mediump float mi=min3(rgb);mediump float ma=max3(rgb);return(max(ma,TINY)-max(mi,TINY))/max(ma,1e-2);}mediump float rgb_2_yc(mediump vec3 rgb){const mediump float ycRadiusWeight=1.75;mediump float r=rgb.x;mediump float g=rgb.y;mediump float b=rgb.z;mediump float k=b*(b-g)+g*(g-r)+r*(r-b);k=max(k,0.0);float chroma=k==0.0 ? 0.0 : sqrt(k);return(b+g+r+ycRadiusWeight*chroma)/3.0;}mediump float rgb_2_hue(mediump vec3 rgb){mediump float hue;if(rgb.x==rgb.y&&rgb.y==rgb.z){hue=0.0;}else{hue=(180.0/PI)*atan(sqrt(3.0)*(rgb.y-rgb.z),2.0*rgb.x-rgb.y-rgb.z);}if(hue<0.0){hue=hue+360.0;}return hue;}mediump float center_hue(mediump float hue,mediump float centerH){mediump float hueCentered=hue-centerH;if(hueCentered<-180.0){hueCentered=hueCentered+360.0;}else if(hueCentered>180.0){hueCentered=hueCentered-360.0;}return hueCentered;}\n#endif\n"; // eslint-disable-line
|
|
30061
|
+
var ODT = "#define GLSLIFY 1\n#include <Tonescale>\nconst float CINEMA_WHITE=48.0;const float CINEMA_BLACK=0.02;const float ODT_SAT_FACTOR=0.93;mediump vec3 Y_2_linCV(mediump vec3 Y,mediump float Ymax,mediump float Ymin){return(Y-Ymin)/(Ymax-Ymin);}mediump vec3 XYZ_2_xyY(mediump vec3 XYZ){mediump float divisor=max(dot(XYZ,vec3(1.0)),1e-4);return vec3(XYZ.xy/divisor,XYZ.y);}mediump vec3 xyY_2_XYZ(mediump vec3 xyY){mediump float m=xyY.z/max(xyY.y,1e-4);mediump vec3 XYZ=vec3(xyY.xz,(1.0-xyY.x-xyY.y));XYZ.xz*=m;return XYZ;}const mediump float DIM_SURROUND_GAMMA=0.9811;mediump vec3 darkSurround_to_dimSurround(mediump vec3 linearCV){mediump vec3 XYZ=AP1_2_XYZ_MAT*linearCV;mediump vec3 xyY=XYZ_2_xyY(XYZ);xyY.z=clamp(xyY.z,0.0,HALF_MAX);xyY.z=pow(xyY.z,DIM_SURROUND_GAMMA);XYZ=xyY_2_XYZ(xyY);return XYZ_2_AP1_MAT*XYZ;}mediump vec3 ODT_RGBmonitor_100nits_dim(mediump vec3 oces){mediump vec3 rgbPre=AP0_2_AP1_MAT*oces;mediump vec3 rgbPost;rgbPost.r=segmented_spline_c9_fwd(rgbPre.r);rgbPost.g=segmented_spline_c9_fwd(rgbPre.g);rgbPost.b=segmented_spline_c9_fwd(rgbPre.b);mediump vec3 linearCV=Y_2_linCV(rgbPost,CINEMA_WHITE,CINEMA_BLACK);linearCV=darkSurround_to_dimSurround(linearCV);linearCV=mix(vec3(dot(linearCV,AP1_RGB2Y)),linearCV,ODT_SAT_FACTOR);mediump vec3 XYZ=AP1_2_XYZ_MAT*linearCV;XYZ=D60_2_D65_CAT*XYZ;linearCV=XYZ_2_REC709_MAT*XYZ;linearCV=clamp(linearCV,vec3(0),vec3(1));return linearCV;}"; // eslint-disable-line
|
|
30062
|
+
var RRT = "#define GLSLIFY 1\n#include <Tonescale>\nmediump float sigmoid_shaper(mediump float x){mediump float t=max(1.0-abs(x/2.0),0.0);mediump float y=1.0+sign(x)*(1.0-t*t);return y*0.5;}mediump float glow_fwd(mediump float ycIn,mediump float glowGainIn,mediump float glowMid){mediump float glowGainOut;if(ycIn<=2.0/3.0*glowMid){glowGainOut=glowGainIn;}else if(ycIn>=2.0*glowMid){glowGainOut=0.0;}else{glowGainOut=glowGainIn*(glowMid/ycIn-1.0/2.0);}return glowGainOut;}const mediump float RRT_GLOW_GAIN=0.05;const mediump float RRT_GLOW_MID=0.08;const mediump float RRT_RED_SCALE=0.82;const mediump float RRT_RED_PIVOT=0.03;const mediump float RRT_RED_HUE=0.0;const mediump float RRT_RED_WIDTH=135.0;const mediump float RRT_SAT_FACTOR=0.96;mediump vec3 RRT(mediump vec3 aces){mediump float saturation=rgb_2_saturation(aces);mediump float ycIn=rgb_2_yc(aces);mediump float s=sigmoid_shaper((saturation-0.4)/0.2);mediump float addedGlow=1.0+glow_fwd(ycIn,RRT_GLOW_GAIN*s,RRT_GLOW_MID);aces*=addedGlow;mediump float hue=rgb_2_hue(aces);mediump float centeredHue=center_hue(hue,RRT_RED_HUE);mediump float hueWeight=smoothstep(0.0,1.0,1.0-abs(2.0*centeredHue/RRT_RED_WIDTH));hueWeight*=hueWeight;aces.r+=hueWeight*saturation*(RRT_RED_PIVOT-aces.r)*(1.0-RRT_RED_SCALE);aces=clamp(aces,0.0,HALF_MAX);mediump vec3 rgbPre=AP0_2_AP1_MAT*aces;rgbPre=clamp(rgbPre,0.0,HALF_MAX);rgbPre=mix(vec3(dot(rgbPre,AP1_RGB2Y)),rgbPre,RRT_SAT_FACTOR);mediump vec3 rgbPost;rgbPost.x=segmented_spline_c5_fwd(rgbPre.x);rgbPost.y=segmented_spline_c5_fwd(rgbPre.y);rgbPost.z=segmented_spline_c5_fwd(rgbPre.z);mediump vec3 outputVal=AP1_2_AP0_MAT*rgbPost;return outputVal;}"; // eslint-disable-line
|
|
30063
|
+
var Tonescale = "#define GLSLIFY 1\n#ifndef TONE_SCALE\n#define TONE_SCALE\nconst mediump mat3 M=mat3(vec3(0.5,-1.0,0.5),vec3(-1.0,1.0,0.5),vec3(0.5,0.0,0.0));mediump float segmented_spline_c5_fwd(mediump float x){\n#ifdef GRAPHICS_API_WEBGL2\nconst mediump float coefsLow[6]=float[6](-4.0000000000,-4.0000000000,-3.1573765773,-0.4852499958,1.8477324706,1.8477324706);const mediump float coefsHigh[6]=float[6](-0.7185482425,2.0810307172,3.6681241237,4.0000000000,4.0000000000,4.0000000000);\n#else\nconst mediump float coefsLow_0=-4.0000000000;const mediump float coefsLow_1=-4.0000000000;const mediump float coefsLow_2=-3.1573765773;const mediump float coefsLow_3=-0.4852499958;const mediump float coefsLow_4=1.8477324706;const mediump float coefsLow_5=1.8477324706;const mediump float coefsHigh_0=-0.7185482425;const mediump float coefsHigh_1=2.0810307172;const mediump float coefsHigh_2=3.6681241237;const mediump float coefsHigh_3=4.0000000000;const mediump float coefsHigh_4=4.0000000000;const mediump float coefsHigh_5=4.0000000000;\n#endif\nconst mediump vec2 minPoint=vec2(0.0000054931640625,0.0001);const mediump vec2 midPoint=vec2(0.18,0.48);const mediump vec2 maxPoint=vec2(47185.92,10000.0);const mediump float slopeLow=0.0;const mediump float slopeHigh=0.0;const int N_KNOTS_LOW=4;const int N_KNOTS_HIGH=4;mediump float logx=log10(max(x,HALF_MIN));mediump float logy;if(logx<=log10(minPoint.x)){logy=logx*slopeLow+(log10(minPoint.y)-slopeLow*log10(minPoint.x));}else if((logx>log10(minPoint.x))&&(logx<log10(midPoint.x))){mediump float knot_coord=float(N_KNOTS_LOW-1)*(logx-log10(minPoint.x))/(log10(midPoint.x)-log10(minPoint.x));int j=int(knot_coord);mediump float t=knot_coord-float(j);mediump vec3 cf;\n#ifdef GRAPHICS_API_WEBGL2\ncf=vec3(coefsLow[j],coefsLow[j+1],coefsLow[j+2]);\n#else\nif(j<=0){cf=vec3(coefsLow_0,coefsLow_1,coefsLow_2);}else if(j==1){cf=vec3(coefsLow_1,coefsLow_2,coefsLow_3);}else if(j==2){cf=vec3(coefsLow_2,coefsLow_3,coefsLow_4);}else{cf=vec3(coefsLow_3,coefsLow_4,coefsLow_5);}\n#endif\nmediump vec3 monomials=vec3(t*t,t,1.0);logy=dot(monomials,M*cf);}else if((logx>=log10(midPoint.x))&&(logx<log10(maxPoint.x))){mediump float knot_coord=float(N_KNOTS_HIGH-1)*(logx-log10(midPoint.x))/(log10(maxPoint.x)-log10(midPoint.x));int j=int(knot_coord);mediump float t=knot_coord-float(j);mediump vec3 cf;\n#ifdef GRAPHICS_API_WEBGL2\ncf=vec3(coefsHigh[j],coefsHigh[j+1],coefsHigh[j+2]);\n#else\nif(j<=0){cf=vec3(coefsHigh_0,coefsHigh_1,coefsHigh_2);}else if(j==1){cf=vec3(coefsHigh_1,coefsHigh_2,coefsHigh_3);}else if(j==2){cf=vec3(coefsHigh_2,coefsHigh_3,coefsHigh_4);}else{cf=vec3(coefsHigh_3,coefsHigh_4,coefsHigh_5);}\n#endif\nmediump vec3 monomials=vec3(t*t,t,1.0);logy=dot(monomials,M*cf);}else{logy=logx*slopeHigh+(log10(maxPoint.y)-slopeHigh*log10(maxPoint.x));}return pow(10.0,logy);}mediump float segmented_spline_c9_fwd(mediump float x){\n#ifdef GRAPHICS_API_WEBGL2\nconst mediump float coefsLow[10]=float[10](-1.6989700043,-1.6989700043,-1.4779000000,-1.2291000000,-0.8648000000,-0.4480000000,0.0051800000,0.4511080334,0.9113744414,0.9113744414);const mediump float coefsHigh[10]=float[10](0.5154386965,0.8470437783,1.1358000000,1.3802000000,1.5197000000,1.5985000000,1.6467000000,1.6746091357,1.6878733390,1.6878733390);\n#else\nconst mediump float coefsLow_0=-1.6989700043;const mediump float coefsLow_1=-1.6989700043;const mediump float coefsLow_2=-1.4779000000;const mediump float coefsLow_3=-1.2291000000;const mediump float coefsLow_4=-0.8648000000;const mediump float coefsLow_5=-0.4480000000;const mediump float coefsLow_6=0.0051800000;const mediump float coefsLow_7=0.4511080334;const mediump float coefsLow_8=0.9113744414;const mediump float coefsLow_9=0.9113744414;const mediump float coefsHigh_0=0.5154386965;const mediump float coefsHigh_1=0.8470437783;const mediump float coefsHigh_2=1.1358000000;const mediump float coefsHigh_3=1.3802000000;const mediump float coefsHigh_4=1.5197000000;const mediump float coefsHigh_5=1.5985000000;const mediump float coefsHigh_6=1.6467000000;const mediump float coefsHigh_7=1.6746091357;const mediump float coefsHigh_8=1.6878733390;const mediump float coefsHigh_9=1.6878733390;\n#endif\nconst mediump vec2 minPoint=vec2(0.0028799,0.02);const mediump vec2 midPoint=vec2(4.799999,4.8);const mediump vec2 maxPoint=vec2(1005.719,48.0);const mediump float slopeLow=0.0;const mediump float slopeHigh=0.04;const int N_KNOTS_LOW=8;const int N_KNOTS_HIGH=8;mediump float logx=log10(max(x,1e-4));mediump float logy;if(logx<=log10(minPoint.x)){logy=logx*slopeLow+(log10(minPoint.y)-slopeLow*log10(minPoint.x));}else if((logx>log10(minPoint.x))&&(logx<log10(midPoint.x))){mediump float knot_coord=float(N_KNOTS_LOW-1)*(logx-log10(minPoint.x))/(log10(midPoint.x)-log10(minPoint.x));int j=int(knot_coord);mediump float t=knot_coord-float(j);mediump vec3 cf;\n#ifdef GRAPHICS_API_WEBGL2\ncf=vec3(coefsLow[j],coefsLow[j+1],coefsLow[j+2]);\n#else\nif(j<=0){cf=vec3(coefsLow_0,coefsLow_1,coefsLow_2);}else if(j==1){cf=vec3(coefsLow_1,coefsLow_2,coefsLow_3);}else if(j==2){cf=vec3(coefsLow_2,coefsLow_3,coefsLow_4);}else if(j==3){cf=vec3(coefsLow_3,coefsLow_4,coefsLow_5);}else if(j==4){cf=vec3(coefsLow_4,coefsLow_5,coefsLow_6);}else if(j==5){cf=vec3(coefsLow_5,coefsLow_6,coefsLow_7);}else if(j==6){cf=vec3(coefsLow_6,coefsLow_7,coefsLow_8);}else{cf=vec3(coefsLow_7,coefsLow_8,coefsLow_9);}\n#endif\nmediump vec3 monomials=vec3(t*t,t,1.0);logy=dot(monomials,M*cf);}else if((logx>=log10(midPoint.x))&&(logx<log10(maxPoint.x))){mediump float knot_coord=float(N_KNOTS_HIGH-1)*(logx-log10(midPoint.x))/(log10(maxPoint.x)-log10(midPoint.x));int j=int(knot_coord);mediump float t=knot_coord-float(j);mediump vec3 cf;\n#ifdef GRAPHICS_API_WEBGL2\ncf=vec3(coefsHigh[j],coefsHigh[j+1],coefsHigh[j+2]);\n#else\nif(j<=0){cf=vec3(coefsHigh_0,coefsHigh_1,coefsHigh_2);}else if(j==1){cf=vec3(coefsHigh_1,coefsHigh_2,coefsHigh_3);}else if(j==2){cf=vec3(coefsHigh_2,coefsHigh_3,coefsHigh_4);}else if(j==3){cf=vec3(coefsHigh_3,coefsHigh_4,coefsHigh_5);}else if(j==4){cf=vec3(coefsHigh_4,coefsHigh_5,coefsHigh_6);}else if(j==5){cf=vec3(coefsHigh_5,coefsHigh_6,coefsHigh_7);}else if(j==6){cf=vec3(coefsHigh_6,coefsHigh_7,coefsHigh_8);}else{cf=vec3(coefsHigh_7,coefsHigh_8,coefsHigh_9);}\n#endif\nmediump vec3 monomials=vec3(t*t,t,1.0);logy=dot(monomials,M*cf);}else{logy=logx*slopeHigh+(log10(maxPoint.y)-slopeHigh*log10(maxPoint.x));}return pow(10.0,logy);}\n#endif\n"; // eslint-disable-line
|
|
30064
|
+
var NeutralTonemapping = "#define GLSLIFY 1\nvec3 neutralCurve(vec3 x,float a,float b,float c,float d,float e,float f){return vec3(((x*(a*x+c*b)+d*e)/(x*(a*x+b)+d*f))-e/f);}\n#define TONEMAPPING_CLAMP_MAX 435.18712\nvec3 neutralTonemap(vec3 color){const float a=0.2;const float b=0.29;const float c=0.24;const float d=0.272;const float e=0.02;const float f=0.3;\n#ifndef GL_FRAGMENT_PRECISION_HIGH\ncolor=min(color,TONEMAPPING_CLAMP_MAX);\n#endif\nconst float whiteScale=1.31338;color=neutralCurve(color*whiteScale,a,b,c,d,e,f);color*=whiteScale;return color;}"; // eslint-disable-line
|
|
30065
|
+
var UberPost = "#define GLSLIFY 1\n#include <PostCommon>\n#include <Filtering>\n#include <NeutralTonemapping>\n#include <ACESTonemapping>\nvarying vec2 v_uv;uniform sampler2D renderer_BlitTexture;uniform vec4 renderer_texelSize;\n#ifdef ENABLE_EFFECT_BLOOM\nuniform sampler2D material_BloomTexture;uniform sampler2D material_BloomDirtTexture;uniform vec4 material_BloomTint;uniform vec4 material_BloomDirtTilingOffset;uniform vec4 material_BloomIntensityParams;\n#endif\nvoid main(){mediump vec4 color=sampleTexture(renderer_BlitTexture,v_uv);\n#ifdef ENABLE_EFFECT_BLOOM\n#ifdef BLOOM_HQ\nmediump vec4 bloom=sampleTexture2DBicubic(material_BloomTexture,v_uv,renderer_texelSize);\n#else\nmediump vec4 bloom=sampleTexture(material_BloomTexture,v_uv);\n#endif\nbloom*=material_BloomIntensityParams.x;color+=bloom*material_BloomTint;\n#ifdef BLOOM_DIRT\nmediump vec4 dirt=sampleTexture(material_BloomDirtTexture,v_uv*material_BloomDirtTilingOffset.xy+material_BloomDirtTilingOffset.zw);dirt*=material_BloomIntensityParams.y;color+=dirt*bloom;\n#endif\n#endif\n#ifdef ENABLE_EFFECT_TONEMAPPING\n#if TONEMAPPING_MODE == 0\ncolor.rgb=neutralTonemap(color.rgb);\n#elif TONEMAPPING_MODE == 1\ncolor.rgb=ACESTonemap(color.rgb);\n#endif\ncolor.rgb=clamp(color.rgb,vec3(0),vec3(1));\n#endif\ngl_FragColor=color;\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ngl_FragColor=linearToGamma(gl_FragColor);\n#endif\n}"; // eslint-disable-line
|
|
30066
|
+
Object.assign(ShaderLib, {
|
|
30067
|
+
PostCommon: PostCommon,
|
|
30068
|
+
Filtering: Filtering,
|
|
30069
|
+
ODT: ODT,
|
|
30070
|
+
RRT: RRT,
|
|
30071
|
+
Tonescale: Tonescale,
|
|
30072
|
+
ColorTransform: ColorTransform,
|
|
30073
|
+
NeutralTonemapping: NeutralTonemapping,
|
|
30074
|
+
ACESTonemapping: ACESTonemapping
|
|
30075
|
+
});
|
|
30076
|
+
Shader.create(_PostProcessManager.UBER_SHADER_NAME, blitVs, UberPost);
|
|
29517
30077
|
/**
|
|
29518
30078
|
* Scene.
|
|
29519
30079
|
*/ var Scene = /*#__PURE__*/ function(EngineObject1) {
|
|
@@ -29537,6 +30097,7 @@
|
|
|
29537
30097
|
/** @internal */ _this._isActiveInEngine = false;
|
|
29538
30098
|
/** @internal */ _this._globalShaderMacro = new ShaderMacroCollection();
|
|
29539
30099
|
/** @internal */ _this._rootEntities = [];
|
|
30100
|
+
/** @internal */ _this._postProcessManager = new _PostProcessManager(_assert_this_initialized(_this));
|
|
29540
30101
|
_this._background = new Background(_this._engine);
|
|
29541
30102
|
_this._shaderData = new ShaderData(ShaderDataGroup.Scene);
|
|
29542
30103
|
_this._shadowCascades = exports.ShadowCascadesMode.NoCascades;
|
|
@@ -32424,7 +32985,8 @@
|
|
|
32424
32985
|
eventHandler.event = event;
|
|
32425
32986
|
handlers.length = 0;
|
|
32426
32987
|
for(var j = scriptCount - 1; j >= 0; j--){
|
|
32427
|
-
var
|
|
32988
|
+
var script = scripts[j];
|
|
32989
|
+
var handler = script[funcName].bind(script);
|
|
32428
32990
|
handler && handlers.push(handler);
|
|
32429
32991
|
}
|
|
32430
32992
|
eventHandlers.push(eventHandler);
|
|
@@ -38209,6 +38771,8 @@
|
|
|
38209
38771
|
BlendShapeFrame: BlendShapeFrame,
|
|
38210
38772
|
BlendState: BlendState,
|
|
38211
38773
|
BlinnPhongMaterial: BlinnPhongMaterial,
|
|
38774
|
+
get BloomDownScaleMode () { return exports.BloomDownScaleMode; },
|
|
38775
|
+
BloomEffect: BloomEffect,
|
|
38212
38776
|
BoolUpdateFlag: BoolUpdateFlag,
|
|
38213
38777
|
BoxColliderShape: BoxColliderShape,
|
|
38214
38778
|
BoxShape: BoxShape,
|
|
@@ -38331,6 +38895,7 @@
|
|
|
38331
38895
|
RenderTarget: RenderTarget,
|
|
38332
38896
|
RenderTargetBlendState: RenderTargetBlendState,
|
|
38333
38897
|
get Renderer () { return exports.Renderer; },
|
|
38898
|
+
get ReplacementFailureStrategy () { return exports.ReplacementFailureStrategy; },
|
|
38334
38899
|
ResourceManager: ResourceManager,
|
|
38335
38900
|
ReturnableObjectPool: ReturnableObjectPool,
|
|
38336
38901
|
RotationOverLifetimeModule: RotationOverLifetimeModule,
|
|
@@ -38345,6 +38910,7 @@
|
|
|
38345
38910
|
ShaderMacro: ShaderMacro,
|
|
38346
38911
|
ShaderMacroCollection: ShaderMacroCollection,
|
|
38347
38912
|
ShaderPass: ShaderPass,
|
|
38913
|
+
get ShaderPlatformTarget () { return exports.ShaderPlatformTarget; },
|
|
38348
38914
|
ShaderProperty: ShaderProperty,
|
|
38349
38915
|
get ShaderPropertyType () { return exports.ShaderPropertyType; },
|
|
38350
38916
|
ShaderTagKey: ShaderTagKey,
|
|
@@ -38395,6 +38961,8 @@
|
|
|
38395
38961
|
get TextureUsage () { return exports.TextureUsage; },
|
|
38396
38962
|
get TextureWrapMode () { return exports.TextureWrapMode; },
|
|
38397
38963
|
Time: Time,
|
|
38964
|
+
TonemappingEffect: TonemappingEffect,
|
|
38965
|
+
get TonemappingMode () { return exports.TonemappingMode; },
|
|
38398
38966
|
TrailMaterial: TrailMaterial,
|
|
38399
38967
|
TrailRenderer: TrailRenderer,
|
|
38400
38968
|
Transform: Transform,
|
|
@@ -38407,6 +38975,7 @@
|
|
|
38407
38975
|
get VertexElementFormat () { return exports.VertexElementFormat; },
|
|
38408
38976
|
get WrapMode () { return exports.WrapMode; },
|
|
38409
38977
|
XRManager: XRManager,
|
|
38978
|
+
_PostProcessManager: _PostProcessManager,
|
|
38410
38979
|
assignmentClone: assignmentClone,
|
|
38411
38980
|
deepClone: deepClone,
|
|
38412
38981
|
dependentComponents: dependentComponents,
|
|
@@ -39290,6 +39859,13 @@
|
|
|
39290
39859
|
dataType: gl.UNSIGNED_BYTE,
|
|
39291
39860
|
isCompressed: false
|
|
39292
39861
|
};
|
|
39862
|
+
case exports.TextureFormat.R11G11B10_UFloat:
|
|
39863
|
+
return {
|
|
39864
|
+
internalFormat: isWebGL2 ? gl.R11F_G11F_B10F : gl.NONE,
|
|
39865
|
+
baseFormat: gl.RGB,
|
|
39866
|
+
dataType: gl.FLOAT,
|
|
39867
|
+
isCompressed: false
|
|
39868
|
+
};
|
|
39293
39869
|
case exports.TextureFormat.R16G16B16A16:
|
|
39294
39870
|
return {
|
|
39295
39871
|
internalFormat: isWebGL2 ? gl.RGBA16F : gl.RGBA,
|
|
@@ -39552,6 +40128,7 @@
|
|
|
39552
40128
|
return false;
|
|
39553
40129
|
}
|
|
39554
40130
|
break;
|
|
40131
|
+
case exports.TextureFormat.R11G11B10_UFloat:
|
|
39555
40132
|
case exports.TextureFormat.R32G32B32A32_UInt:
|
|
39556
40133
|
case exports.TextureFormat.Depth24:
|
|
39557
40134
|
case exports.TextureFormat.Depth32:
|
|
@@ -39579,6 +40156,11 @@
|
|
|
39579
40156
|
}
|
|
39580
40157
|
}
|
|
39581
40158
|
break;
|
|
40159
|
+
case exports.TextureFormat.R11G11B10_UFloat:
|
|
40160
|
+
{
|
|
40161
|
+
isSupported = rhi.isWebGL2;
|
|
40162
|
+
}
|
|
40163
|
+
break;
|
|
39582
40164
|
}
|
|
39583
40165
|
return isSupported;
|
|
39584
40166
|
};
|
|
@@ -46798,6 +47380,29 @@
|
|
|
46798
47380
|
if (fog.fogDensity != undefined) scene.fogDensity = fog.fogDensity;
|
|
46799
47381
|
if (fog.fogColor != undefined) scene.fogColor.copyFrom(fog.fogColor);
|
|
46800
47382
|
}
|
|
47383
|
+
// Post Process
|
|
47384
|
+
var postProcessData = data.scene.postProcess;
|
|
47385
|
+
if (postProcessData) {
|
|
47386
|
+
// @ts-ignore
|
|
47387
|
+
var postProcessManager = scene._postProcessManager;
|
|
47388
|
+
var bloomEffect = postProcessManager._bloomEffect;
|
|
47389
|
+
var tonemappingEffect = postProcessManager._tonemappingEffect;
|
|
47390
|
+
postProcessManager.isActive = postProcessData.isActive;
|
|
47391
|
+
bloomEffect.enabled = postProcessData.bloom.enabled;
|
|
47392
|
+
bloomEffect.threshold = postProcessData.bloom.threshold;
|
|
47393
|
+
bloomEffect.scatter = postProcessData.bloom.scatter;
|
|
47394
|
+
bloomEffect.intensity = postProcessData.bloom.intensity;
|
|
47395
|
+
bloomEffect.tint.copyFrom(postProcessData.bloom.tint);
|
|
47396
|
+
bloomEffect.dirtIntensity = postProcessData.bloom.dirtIntensity;
|
|
47397
|
+
tonemappingEffect.enabled = postProcessData.tonemapping.enabled;
|
|
47398
|
+
tonemappingEffect.mode = postProcessData.tonemapping.mode;
|
|
47399
|
+
// @ts-ignore
|
|
47400
|
+
// prettier-ignore
|
|
47401
|
+
var dirtTexturePromise = resourceManager.getResourceByRef(postProcessData.bloom.dirtTexture).then(function(texture) {
|
|
47402
|
+
bloomEffect.dirtTexture = texture;
|
|
47403
|
+
});
|
|
47404
|
+
promises.push(dirtTexturePromise);
|
|
47405
|
+
}
|
|
46801
47406
|
return Promise.all(promises).then(function() {
|
|
46802
47407
|
resolve(scene);
|
|
46803
47408
|
});
|
|
@@ -47187,7 +47792,7 @@
|
|
|
47187
47792
|
], KHR_materials_anisotropy);
|
|
47188
47793
|
|
|
47189
47794
|
//@ts-ignore
|
|
47190
|
-
var version = "1.3.0-alpha.
|
|
47795
|
+
var version = "1.3.0-alpha.2";
|
|
47191
47796
|
console.log("Galacean engine version: " + version);
|
|
47192
47797
|
for(var key in CoreObjects){
|
|
47193
47798
|
Loader.registerClass(key, CoreObjects[key]);
|
|
@@ -47213,6 +47818,7 @@
|
|
|
47213
47818
|
exports.BlendShapeFrame = BlendShapeFrame;
|
|
47214
47819
|
exports.BlendState = BlendState;
|
|
47215
47820
|
exports.BlinnPhongMaterial = BlinnPhongMaterial;
|
|
47821
|
+
exports.BloomEffect = BloomEffect;
|
|
47216
47822
|
exports.BoolUpdateFlag = BoolUpdateFlag;
|
|
47217
47823
|
exports.BoundingBox = BoundingBox;
|
|
47218
47824
|
exports.BoundingFrustum = BoundingFrustum;
|
|
@@ -47353,6 +47959,7 @@
|
|
|
47353
47959
|
exports.TextureCube = TextureCube;
|
|
47354
47960
|
exports.TextureSheetAnimationModule = TextureSheetAnimationModule;
|
|
47355
47961
|
exports.Time = Time;
|
|
47962
|
+
exports.TonemappingEffect = TonemappingEffect;
|
|
47356
47963
|
exports.TrailMaterial = TrailMaterial;
|
|
47357
47964
|
exports.TrailRenderer = TrailRenderer;
|
|
47358
47965
|
exports.Transform = Transform;
|
|
@@ -47368,6 +47975,7 @@
|
|
|
47368
47975
|
exports.WebGLEngine = WebGLEngine;
|
|
47369
47976
|
exports.WebGLGraphicDevice = WebGLGraphicDevice;
|
|
47370
47977
|
exports.XRManager = XRManager;
|
|
47978
|
+
exports._PostProcessManager = _PostProcessManager;
|
|
47371
47979
|
exports.assignmentClone = assignmentClone;
|
|
47372
47980
|
exports.decode = decode;
|
|
47373
47981
|
exports.deepClone = deepClone;
|