@galacean/engine-core 1.4.0-alpha.1 → 1.4.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/main.js +1616 -855
  2. package/dist/main.js.map +1 -1
  3. package/dist/module.js +1606 -855
  4. package/dist/module.js.map +1 -1
  5. package/package.json +3 -3
  6. package/types/Camera.d.ts +4 -0
  7. package/types/Engine.d.ts +12 -0
  8. package/types/RenderPipeline/BasicRenderPipeline.d.ts +1 -0
  9. package/types/RenderPipeline/Blitter.d.ts +28 -0
  10. package/types/RenderPipeline/index.d.ts +2 -1
  11. package/types/Scene.d.ts +3 -0
  12. package/types/asset/AssetType.d.ts +3 -1
  13. package/types/material/BaseMaterial.d.ts +4 -2
  14. package/types/material/PBRMaterial.d.ts +70 -5
  15. package/types/material/enums/Refraction.d.ts +9 -0
  16. package/types/material/index.d.ts +1 -0
  17. package/types/physics/CharacterController.d.ts +2 -2
  18. package/types/physics/Collision.d.ts +18 -0
  19. package/types/physics/ContactPoint.d.ts +14 -0
  20. package/types/physics/DynamicCollider.d.ts +8 -2
  21. package/types/physics/PhysicsMaterial.d.ts +4 -0
  22. package/types/physics/index.d.ts +2 -0
  23. package/types/physics/joint/Joint.d.ts +7 -6
  24. package/types/physics/joint/JointLimits.d.ts +2 -2
  25. package/types/physics/shape/ColliderShape.d.ts +9 -2
  26. package/types/physics/shape/PlaneColliderShape.d.ts +2 -0
  27. package/types/postProcess/PostProcess.d.ts +60 -0
  28. package/types/postProcess/PostProcessEffect.d.ts +26 -0
  29. package/types/postProcess/PostProcessEffectParameter.d.ts +25 -0
  30. package/types/postProcess/PostProcessManager.d.ts +37 -1
  31. package/types/postProcess/PostProcessPass.d.ts +50 -0
  32. package/types/postProcess/PostProcessUberPass.d.ts +25 -0
  33. package/types/postProcess/effects/BloomEffect.d.ts +22 -64
  34. package/types/postProcess/effects/TonemappingEffect.d.ts +6 -16
  35. package/types/postProcess/index.d.ts +6 -2
  36. package/types/shader/Shader.d.ts +1 -1
package/dist/main.js CHANGED
@@ -3450,103 +3450,103 @@ Time._deltaTimeProperty = ShaderProperty.getByName("scene_DeltaTime");
3450
3450
  return GLCapabilityType;
3451
3451
  }({});
3452
3452
 
3453
- var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;uniform vec3 camera_Forward;uniform vec4 camera_ProjectionParams;"; // eslint-disable-line
3453
+ var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;\nuniform vec3 camera_Forward; \nuniform vec4 camera_ProjectionParams;"; // eslint-disable-line
3454
3454
 
3455
- 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){linearIn=max(linearIn,0.0);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
3455
+ 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\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n\nfloat pow2(float x ) {\n return x * x;\n}\n\nvec4 RGBMToLinear(vec4 value, float maxRange ) {\n return vec4( value.rgb * value.a * maxRange, 1.0 );\n}\n\nvec4 gammaToLinear(vec4 srgbIn){\n return vec4( pow(srgbIn.rgb, vec3(2.2)), srgbIn.a);\n}\n\nvec4 linearToGamma(vec4 linearIn){\n\tlinearIn = max(linearIn, 0.0);\n return vec4( pow(linearIn.rgb, vec3(1.0 / 2.2)), linearIn.a);\n}\n\nuniform vec4 camera_DepthBufferParams;\n\nfloat remapDepthBufferLinear01(float z){\n\treturn 1.0/ (camera_DepthBufferParams.x * z + camera_DepthBufferParams.y);\n}\n\n#ifdef GRAPHICS_API_WEBGL2\n\t#define INVERSE_MAT(mat) inverse(mat)\n#else\n\tmat2 inverseMat(mat2 m) {\n\t\treturn mat2(m[1][1],-m[0][1],\n\t\t\t\t-m[1][0], m[0][0]) / (m[0][0]*m[1][1] - m[0][1]*m[1][0]);\n\t}\n\tmat3 inverseMat(mat3 m) {\n\t\tfloat a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];\n\t\tfloat a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];\n\t\tfloat a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];\n\n\t\tfloat b01 = a22 * a11 - a12 * a21;\n\t\tfloat b11 = -a22 * a10 + a12 * a20;\n\t\tfloat b21 = a21 * a10 - a11 * a20;\n\n\t\tfloat det = a00 * b01 + a01 * b11 + a02 * b21;\n\n\t\treturn mat3(b01, (-a22 * a01 + a02 * a21), (a12 * a01 - a02 * a11),\n\t\t\t\t\tb11, (a22 * a00 - a02 * a20), (-a12 * a00 + a02 * a10),\n\t\t\t\t\tb21, (-a21 * a00 + a01 * a20), (a11 * a00 - a01 * a10)) / det;\n\t}\n\tmat4 inverseMat(mat4 m) {\n\t\tfloat a00 = m[0][0], a01 = m[0][1], a02 = m[0][2], a03 = m[0][3],\n\t\t\ta10 = m[1][0], a11 = m[1][1], a12 = m[1][2], a13 = m[1][3],\n\t\t\ta20 = m[2][0], a21 = m[2][1], a22 = m[2][2], a23 = m[2][3],\n\t\t\ta30 = m[3][0], a31 = m[3][1], a32 = m[3][2], a33 = m[3][3],\n\n\t\t\tb00 = a00 * a11 - a01 * a10,\n\t\t\tb01 = a00 * a12 - a02 * a10,\n\t\t\tb02 = a00 * a13 - a03 * a10,\n\t\t\tb03 = a01 * a12 - a02 * a11,\n\t\t\tb04 = a01 * a13 - a03 * a11,\n\t\t\tb05 = a02 * a13 - a03 * a12,\n\t\t\tb06 = a20 * a31 - a21 * a30,\n\t\t\tb07 = a20 * a32 - a22 * a30,\n\t\t\tb08 = a20 * a33 - a23 * a30,\n\t\t\tb09 = a21 * a32 - a22 * a31,\n\t\t\tb10 = a21 * a33 - a23 * a31,\n\t\t\tb11 = a22 * a33 - a23 * a32,\n\n\t\t\tdet = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n\n\t\treturn mat4(\n\t\t\ta11 * b11 - a12 * b10 + a13 * b09,\n\t\t\ta02 * b10 - a01 * b11 - a03 * b09,\n\t\t\ta31 * b05 - a32 * b04 + a33 * b03,\n\t\t\ta22 * b04 - a21 * b05 - a23 * b03,\n\t\t\ta12 * b08 - a10 * b11 - a13 * b07,\n\t\t\ta00 * b11 - a02 * b08 + a03 * b07,\n\t\t\ta32 * b02 - a30 * b05 - a33 * b01,\n\t\t\ta20 * b05 - a22 * b02 + a23 * b01,\n\t\t\ta10 * b10 - a11 * b08 + a13 * b06,\n\t\t\ta01 * b08 - a00 * b10 - a03 * b06,\n\t\t\ta30 * b04 - a31 * b02 + a33 * b00,\n\t\t\ta21 * b02 - a20 * b04 - a23 * b00,\n\t\t\ta11 * b07 - a10 * b09 - a12 * b06,\n\t\t\ta00 * b09 - a01 * b07 + a02 * b06,\n\t\t\ta31 * b01 - a30 * b03 - a32 * b00,\n\t\t\ta20 * b03 - a21 * b01 + a22 * b00) / det;\n\t}\n\n\t#define INVERSE_MAT(mat) inverseMat(mat)\n#endif\n"; // eslint-disable-line
3456
3456
 
3457
- 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
3457
+ var common_vert = "#define GLSLIFY 1\nattribute vec3 POSITION;\n\n#ifdef RENDERER_HAS_UV\n attribute vec2 TEXCOORD_0;\n#endif\n\n#ifdef RENDERER_HAS_UV1\n attribute vec2 TEXCOORD_1;\n#endif\n\n#ifdef RENDERER_HAS_SKIN\n attribute vec4 JOINTS_0;\n attribute vec4 WEIGHTS_0;\n\n #ifdef RENDERER_USE_JOINT_TEXTURE\n uniform sampler2D renderer_JointSampler;\n uniform float renderer_JointCount;\n\n mat4 getJointMatrix(sampler2D smp, float index)\n {\n float base = index / renderer_JointCount;\n float hf = 0.5 / renderer_JointCount;\n float v = base + hf;\n\n vec4 m0 = texture2D(smp, vec2(0.125, v ));\n vec4 m1 = texture2D(smp, vec2(0.375, v ));\n vec4 m2 = texture2D(smp, vec2(0.625, v ));\n vec4 m3 = texture2D(smp, vec2(0.875, v ));\n\n return mat4(m0, m1, m2, m3);\n\n }\n\n #else\n uniform mat4 renderer_JointMatrix[ RENDERER_JOINTS_NUM ];\n #endif\n#endif\n\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\n attribute vec4 COLOR_0;\n#endif\n\n#include <transform_declare>\n#include <camera_declare>\n\nuniform vec4 material_TilingOffset;\n\n#ifndef MATERIAL_OMIT_NORMAL\n #ifdef RENDERER_HAS_NORMAL\n attribute vec3 NORMAL;\n #endif\n\n #ifdef RENDERER_HAS_TANGENT\n attribute vec4 TANGENT;\n #endif\n#endif"; // eslint-disable-line
3458
3458
 
3459
- var transform_declare = "#define GLSLIFY 1\nuniform mat4 renderer_LocalMat;uniform mat4 renderer_ModelMat;uniform mat4 camera_ViewMat;uniform mat4 camera_ProjMat;uniform mat4 renderer_MVMat;uniform mat4 renderer_MVPMat;uniform mat4 renderer_NormalMat;"; // eslint-disable-line
3459
+ var transform_declare = "#define GLSLIFY 1\nuniform mat4 renderer_LocalMat;\nuniform mat4 renderer_ModelMat;\nuniform mat4 camera_ViewMat;\nuniform mat4 camera_ProjMat;\nuniform mat4 renderer_MVMat;\nuniform mat4 renderer_MVPMat;\nuniform mat4 renderer_NormalMat;"; // eslint-disable-line
3460
3460
 
3461
- var color_share = "#define GLSLIFY 1\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nvarying vec4 v_color;\n#endif\n"; // eslint-disable-line
3461
+ var color_share = "#define GLSLIFY 1\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\n\nvarying vec4 v_color;\n\n#endif\n"; // eslint-disable-line
3462
3462
 
3463
- var FogFragmentDeclaration = "#define GLSLIFY 1\n#if SCENE_FOG_MODE != 0\nvarying vec3 v_positionVS;uniform vec4 scene_FogColor;uniform vec4 scene_FogParams;float ComputeFogIntensity(float fogDepth){\n#if SCENE_FOG_MODE == 1\nreturn clamp(fogDepth*scene_FogParams.x+scene_FogParams.y,0.0,1.0);\n#elif SCENE_FOG_MODE == 2\nreturn clamp(exp2(-fogDepth*scene_FogParams.z),0.0,1.0);\n#elif SCENE_FOG_MODE == 3\nfloat factor=fogDepth*scene_FogParams.w;return clamp(exp2(-factor*factor),0.0,1.0);\n#endif\n}\n#endif\n"; // eslint-disable-line
3463
+ var FogFragmentDeclaration = "#define GLSLIFY 1\n#if SCENE_FOG_MODE != 0\n varying vec3 v_positionVS;\n\n uniform vec4 scene_FogColor;\n uniform vec4 scene_FogParams;// (-1/(end-start), end/(end-start), density/ln(2),density/sprt(ln(2)));\n\n float ComputeFogIntensity(float fogDepth){\n #if SCENE_FOG_MODE == 1\n // (end-z) / (end-start) = z * (-1/(end-start)) + (end/(end-start))\n return clamp(fogDepth * scene_FogParams.x + scene_FogParams.y, 0.0, 1.0);\n #elif SCENE_FOG_MODE == 2\n // exp(-z * density) = exp2((-z * density)/ln(2)) = exp2(-z * density/ln(2))\n return clamp(exp2(-fogDepth * scene_FogParams.z), 0.0, 1.0);\n #elif SCENE_FOG_MODE == 3\n // exp(-(z * density)^2) = exp2(-(z * density)^2/ln(2)) = exp2(-(z * density/sprt(ln(2)))^2)\n float factor = fogDepth * scene_FogParams.w;\n return clamp(exp2(-factor * factor), 0.0, 1.0);\n #endif\n }\n#endif\n"; // eslint-disable-line
3464
3464
 
3465
- var FogVertexDeclaration = "#define GLSLIFY 1\n#if SCENE_FOG_MODE != 0\nvarying vec3 v_positionVS;\n#endif\n"; // eslint-disable-line
3465
+ var FogVertexDeclaration = "#define GLSLIFY 1\n#if SCENE_FOG_MODE != 0\n varying vec3 v_positionVS;\n#endif\n"; // eslint-disable-line
3466
3466
 
3467
- var normal_share = "#define GLSLIFY 1\n#ifndef MATERIAL_OMIT_NORMAL\n#ifdef RENDERER_HAS_NORMAL\nvarying vec3 v_normal;\n#if defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY) )\nvarying mat3 v_TBN;\n#endif\n#endif\n#endif\n"; // eslint-disable-line
3467
+ var normal_share = "#define GLSLIFY 1\n#ifndef MATERIAL_OMIT_NORMAL\n #ifdef RENDERER_HAS_NORMAL\n varying vec3 v_normal;\n #if defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY) )\n varying mat3 v_TBN;\n #endif\n #endif\n#endif"; // eslint-disable-line
3468
3468
 
3469
- var uv_share = "#define GLSLIFY 1\nvarying vec2 v_uv;\n#ifdef RENDERER_HAS_UV1\nvarying vec2 v_uv1;\n#endif\n"; // eslint-disable-line
3469
+ var uv_share = "#define GLSLIFY 1\nvarying vec2 v_uv;\n\n#ifdef RENDERER_HAS_UV1\n varying vec2 v_uv1;\n#endif"; // eslint-disable-line
3470
3470
 
3471
- var worldpos_share = "#define GLSLIFY 1\n#ifdef MATERIAL_NEED_WORLD_POS\nvarying vec3 v_pos;\n#endif\n"; // eslint-disable-line
3471
+ var worldpos_share = "#define GLSLIFY 1\n#ifdef MATERIAL_NEED_WORLD_POS\n varying vec3 v_pos;\n#endif\n"; // eslint-disable-line
3472
3472
 
3473
- var begin_normal_vert = "#define GLSLIFY 1\n#ifndef MATERIAL_OMIT_NORMAL\n#ifdef RENDERER_HAS_NORMAL\nvec3 normal=vec3(NORMAL);\n#endif\n#ifdef RENDERER_HAS_TANGENT\nvec4 tangent=vec4(TANGENT);\n#endif\n#endif\n"; // eslint-disable-line
3473
+ var begin_normal_vert = "#define GLSLIFY 1\n#ifndef MATERIAL_OMIT_NORMAL\n #ifdef RENDERER_HAS_NORMAL\n vec3 normal = vec3( NORMAL );\n #endif\n\n #ifdef RENDERER_HAS_TANGENT\n vec4 tangent = vec4( TANGENT );\n #endif\n#endif"; // eslint-disable-line
3474
3474
 
3475
- var begin_position_vert = "#define GLSLIFY 1\nvec4 position=vec4(POSITION,1.0);"; // eslint-disable-line
3475
+ var begin_position_vert = "#define GLSLIFY 1\n vec4 position = vec4( POSITION , 1.0 );\n"; // eslint-disable-line
3476
3476
 
3477
- var blendShape_input = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_BLENDSHAPE\n#ifdef RENDERER_BLENDSHAPE_USE_TEXTURE\nuniform mediump sampler2DArray renderer_BlendShapeTexture;uniform ivec3 renderer_BlendShapeTextureInfo;uniform float renderer_BlendShapeWeights[RENDERER_BLENDSHAPE_COUNT];\n#else\nattribute vec3 POSITION_BS0;attribute vec3 POSITION_BS1;\n#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\nattribute vec3 NORMAL_BS0;attribute vec3 NORMAL_BS1;attribute vec3 TANGENT_BS0;attribute vec3 TANGENT_BS1;uniform float renderer_BlendShapeWeights[2];\n#else\n#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) || defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\nattribute vec3 POSITION_BS2;attribute vec3 POSITION_BS3;\n#ifdef RENDERER_BLENDSHAPE_HAS_NORMAL\nattribute vec3 NORMAL_BS0;attribute vec3 NORMAL_BS1;attribute vec3 NORMAL_BS2;attribute vec3 NORMAL_BS3;\n#endif\n#ifdef RENDERER_BLENDSHAPE_HAS_TANGENT\nattribute vec3 TANGENT_BS0;attribute vec3 TANGENT_BS1;attribute vec3 TANGENT_BS2;attribute vec3 TANGENT_BS3;\n#endif\nuniform float renderer_BlendShapeWeights[4];\n#else\nattribute vec3 POSITION_BS2;attribute vec3 POSITION_BS3;attribute vec3 POSITION_BS4;attribute vec3 POSITION_BS5;attribute vec3 POSITION_BS6;attribute vec3 POSITION_BS7;uniform float renderer_BlendShapeWeights[8];\n#endif\n#endif\n#endif\n#ifdef RENDERER_BLENDSHAPE_USE_TEXTURE\nvec3 getBlendShapeVertexElement(int blendShapeIndex,int vertexElementIndex){int y=vertexElementIndex/renderer_BlendShapeTextureInfo.y;int x=vertexElementIndex-y*renderer_BlendShapeTextureInfo.y;ivec3 uv=ivec3(x,y,blendShapeIndex);return texelFetch(renderer_BlendShapeTexture,uv,0).xyz;}\n#endif\n#endif\n"; // eslint-disable-line
3477
+ var blendShape_input = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_BLENDSHAPE\n\t#ifdef RENDERER_BLENDSHAPE_USE_TEXTURE\n\t\tuniform mediump sampler2DArray renderer_BlendShapeTexture;\n\t\tuniform ivec3 renderer_BlendShapeTextureInfo;\n\t\tuniform float renderer_BlendShapeWeights[RENDERER_BLENDSHAPE_COUNT];\n\t#else\n\t\tattribute vec3 POSITION_BS0;\n\t\tattribute vec3 POSITION_BS1;\n\t\t#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\n\t\t\tattribute vec3 NORMAL_BS0;\n\t\t\tattribute vec3 NORMAL_BS1;\n\t\t\tattribute vec3 TANGENT_BS0;\n\t\t\tattribute vec3 TANGENT_BS1;\n\t\t\tuniform float renderer_BlendShapeWeights[2];\n\t\t#else\n\t\t\t#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) || defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\n\t\t\t\tattribute vec3 POSITION_BS2;\n\t\t\t\tattribute vec3 POSITION_BS3;\n\t\t\t\t#ifdef RENDERER_BLENDSHAPE_HAS_NORMAL\n\t\t\t\t\tattribute vec3 NORMAL_BS0;\n\t\t\t\t\tattribute vec3 NORMAL_BS1;\n\t\t\t\t\tattribute vec3 NORMAL_BS2;\n\t\t\t\t\tattribute vec3 NORMAL_BS3;\n\t\t\t\t#endif\n\n\t\t\t\t#ifdef RENDERER_BLENDSHAPE_HAS_TANGENT\n\t\t\t\t\tattribute vec3 TANGENT_BS0;\n\t\t\t\t\tattribute vec3 TANGENT_BS1;\n\t\t\t\t\tattribute vec3 TANGENT_BS2;\n\t\t\t\t\tattribute vec3 TANGENT_BS3;\n\t\t\t\t#endif\n\n\t\t\t\tuniform float renderer_BlendShapeWeights[4];\n\t\t\t#else\n\t\t\t\tattribute vec3 POSITION_BS2;\n\t\t\t\tattribute vec3 POSITION_BS3;\n\t\t\t\tattribute vec3 POSITION_BS4;\n\t\t\t\tattribute vec3 POSITION_BS5;\n\t\t\t\tattribute vec3 POSITION_BS6;\n\t\t\t\tattribute vec3 POSITION_BS7;\n\t\t\t\tuniform float renderer_BlendShapeWeights[8];\n\t\t\t#endif\n\t\t#endif\n\t#endif\n\n\t#ifdef RENDERER_BLENDSHAPE_USE_TEXTURE\n\t\tvec3 getBlendShapeVertexElement(int blendShapeIndex, int vertexElementIndex)\n\t\t{\t\t\t\n\t\t\tint y = vertexElementIndex / renderer_BlendShapeTextureInfo.y;\n\t\t\tint x = vertexElementIndex - y * renderer_BlendShapeTextureInfo.y;\n\t\t\tivec3 uv = ivec3(x, y , blendShapeIndex);\n\t\t\treturn texelFetch(renderer_BlendShapeTexture, uv, 0).xyz;\n\t\t}\n\t#endif\n#endif\n"; // eslint-disable-line
3478
3478
 
3479
- var blendShape_vert = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_BLENDSHAPE\n#ifdef RENDERER_BLENDSHAPE_USE_TEXTURE\nint vertexOffset=gl_VertexID*renderer_BlendShapeTextureInfo.x;for(int i=0;i<RENDERER_BLENDSHAPE_COUNT;i++){int vertexElementOffset=vertexOffset;float weight=renderer_BlendShapeWeights[i];if(weight!=0.0){position.xyz+=getBlendShapeVertexElement(i,vertexElementOffset)*weight;\n#ifndef MATERIAL_OMIT_NORMAL\n#if defined( RENDERER_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_NORMAL )\nvertexElementOffset+=1;normal+=getBlendShapeVertexElement(i,vertexElementOffset)*weight;\n#endif\n#if defined( RENDERER_HAS_TANGENT ) && defined(RENDERER_BLENDSHAPE_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\nvertexElementOffset+=1;tangent.xyz+=getBlendShapeVertexElement(i,vertexElementOffset)*weight;\n#endif\n#endif\n}}\n#else\nposition.xyz+=POSITION_BS0*renderer_BlendShapeWeights[0];position.xyz+=POSITION_BS1*renderer_BlendShapeWeights[1];\n#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\n#ifndef MATERIAL_OMIT_NORMAL\n#ifdef RENDERER_HAS_NORMAL\nnormal+=NORMAL_BS0*renderer_BlendShapeWeights[0];normal+=NORMAL_BS1*renderer_BlendShapeWeights[1];\n#endif\n#if defined( RENDERER_HAS_TANGENT ) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\ntangent.xyz+=TANGENT_BS0*renderer_BlendShapeWeights[0];tangent.xyz+=TANGENT_BS1*renderer_BlendShapeWeights[1];\n#endif\n#endif\n#else\n#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) || defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\n#ifndef MATERIAL_OMIT_NORMAL\nposition.xyz+=POSITION_BS2*renderer_BlendShapeWeights[2];position.xyz+=POSITION_BS3*renderer_BlendShapeWeights[3];\n#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_HAS_NORMAL )\nnormal+=NORMAL_BS0*renderer_BlendShapeWeights[0];normal+=NORMAL_BS1*renderer_BlendShapeWeights[1];normal+=NORMAL_BS2*renderer_BlendShapeWeights[2];normal+=NORMAL_BS3*renderer_BlendShapeWeights[3];\n#endif\n#if defined(RENDERER_BLENDSHAPE_HAS_TANGENT) && defined( RENDERER_HAS_TANGENT ) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\ntangent.xyz+=TANGENT_BS0*renderer_BlendShapeWeights[0];tangent.xyz+=TANGENT_BS1*renderer_BlendShapeWeights[1];tangent.xyz+=TANGENT_BS2*renderer_BlendShapeWeights[2];tangent.xyz+=TANGENT_BS3*renderer_BlendShapeWeights[3];\n#endif\n#endif\n#else\nposition.xyz+=POSITION_BS2*renderer_BlendShapeWeights[2];position.xyz+=POSITION_BS3*renderer_BlendShapeWeights[3];position.xyz+=POSITION_BS4*renderer_BlendShapeWeights[4];position.xyz+=POSITION_BS5*renderer_BlendShapeWeights[5];position.xyz+=POSITION_BS6*renderer_BlendShapeWeights[6];position.xyz+=POSITION_BS7*renderer_BlendShapeWeights[7];\n#endif\n#endif\n#endif\n#endif\n"; // eslint-disable-line
3479
+ var blendShape_vert = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_BLENDSHAPE\n\t#ifdef RENDERER_BLENDSHAPE_USE_TEXTURE\t\n\t\tint vertexOffset = gl_VertexID * renderer_BlendShapeTextureInfo.x;\n\t\tfor(int i = 0; i < RENDERER_BLENDSHAPE_COUNT; i++){\n\t\t\tint vertexElementOffset = vertexOffset;\n\t\t\tfloat weight = renderer_BlendShapeWeights[i];\n\t\t\t// Warnning: Multiplying by 0 creates weird precision issues, causing rendering anomalies in Ace2 Android13\n\t\t\tif(weight != 0.0){\n\t\t\t\tposition.xyz += getBlendShapeVertexElement(i, vertexElementOffset) * weight;\n\t\n\t\t\t\t#ifndef MATERIAL_OMIT_NORMAL\n\t\t\t\t\t#if defined( RENDERER_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_NORMAL )\n\t\t\t\t\t\tvertexElementOffset += 1;\n\t\t\t\t\t\tnormal += getBlendShapeVertexElement(i, vertexElementOffset) * weight;\n\t\t\t\t\t#endif\n\t\n\t\t\t\t\t#if defined( RENDERER_HAS_TANGENT ) && defined(RENDERER_BLENDSHAPE_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\n\t\t\t\t\t\tvertexElementOffset += 1;\n\t\t\t\t\t\ttangent.xyz += getBlendShapeVertexElement(i, vertexElementOffset) * weight;\n\t\t\t\t\t#endif\n\t\t\t\t#endif\n\t\t\t}\n\t\t\t\n\t\t}\n\t#else\n\t\tposition.xyz += POSITION_BS0 * renderer_BlendShapeWeights[0];\n\t\tposition.xyz += POSITION_BS1 * renderer_BlendShapeWeights[1];\n\n\t\t#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\n\t\t\t#ifndef MATERIAL_OMIT_NORMAL\n\t\t\t\t#ifdef RENDERER_HAS_NORMAL\n\t\t\t\t\tnormal += NORMAL_BS0 * renderer_BlendShapeWeights[0];\n\t\t\t\t\tnormal += NORMAL_BS1 * renderer_BlendShapeWeights[1];\n\t\t\t\t#endif\n\t\t\t\t#if defined( RENDERER_HAS_TANGENT ) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\n\t\t\t\t\ttangent.xyz += TANGENT_BS0 * renderer_BlendShapeWeights[0];\n\t\t\t\t\ttangent.xyz += TANGENT_BS1 * renderer_BlendShapeWeights[1];\n\t\t\t\t#endif\t\t\t\t\n\t\t\t#endif\n\t\t#else\n\t\t\t#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) || defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\n\t\t\t\t#ifndef MATERIAL_OMIT_NORMAL\n\t\t\t\t\tposition.xyz += POSITION_BS2 * renderer_BlendShapeWeights[2];\n\t\t\t\t\tposition.xyz += POSITION_BS3 * renderer_BlendShapeWeights[3];\n\n\t\t\t\t\t#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_HAS_NORMAL )\n\t\t\t\t\t\tnormal += NORMAL_BS0 * renderer_BlendShapeWeights[0];\n\t\t\t\t\t\tnormal += NORMAL_BS1 * renderer_BlendShapeWeights[1];\n\t\t\t\t\t\tnormal += NORMAL_BS2 * renderer_BlendShapeWeights[2];\n\t\t\t\t\t\tnormal += NORMAL_BS3 * renderer_BlendShapeWeights[3];\n\t\t\t\t\t#endif\n\n\t\t\t\t\t#if defined(RENDERER_BLENDSHAPE_HAS_TANGENT) && defined( RENDERER_HAS_TANGENT ) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\n\t\t\t\t\t\ttangent.xyz += TANGENT_BS0 * renderer_BlendShapeWeights[0];\n\t\t\t\t\t\ttangent.xyz += TANGENT_BS1 * renderer_BlendShapeWeights[1];\n\t\t\t\t\t\ttangent.xyz += TANGENT_BS2 * renderer_BlendShapeWeights[2];\n\t\t\t\t\t\ttangent.xyz += TANGENT_BS3 * renderer_BlendShapeWeights[3];\n\t\t\t\t\t#endif\n\t\t\t\t#endif\n\t\t\t#else\n\t\t\t\tposition.xyz += POSITION_BS2 * renderer_BlendShapeWeights[2];\n\t\t\t\tposition.xyz += POSITION_BS3 * renderer_BlendShapeWeights[3];\n\t\t\t\tposition.xyz += POSITION_BS4 * renderer_BlendShapeWeights[4];\n\t\t\t\tposition.xyz += POSITION_BS5 * renderer_BlendShapeWeights[5];\n\t\t\t\tposition.xyz += POSITION_BS6 * renderer_BlendShapeWeights[6];\n\t\t\t\tposition.xyz += POSITION_BS7 * renderer_BlendShapeWeights[7];\n\t\t\t#endif\n\t\t#endif\n\t#endif\n#endif\n\n"; // eslint-disable-line
3480
3480
 
3481
- var color_vert = "#define GLSLIFY 1\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nv_color=COLOR_0;\n#endif\n"; // eslint-disable-line
3481
+ var color_vert = "#define GLSLIFY 1\n #ifdef RENDERER_ENABLE_VERTEXCOLOR\n\n v_color = COLOR_0;\n\n #endif\n"; // eslint-disable-line
3482
3482
 
3483
- var FogVertex = "#define GLSLIFY 1\n#if SCENE_FOG_MODE != 0\nvec4 positionVS=renderer_MVMat*position;v_positionVS=positionVS.xyz/positionVS.w;\n#endif\n"; // eslint-disable-line
3483
+ var FogVertex = "#define GLSLIFY 1\n#if SCENE_FOG_MODE != 0\n vec4 positionVS = renderer_MVMat * position;\n v_positionVS = positionVS.xyz / positionVS.w;\n#endif\n"; // eslint-disable-line
3484
3484
 
3485
- var normal_vert = "#define GLSLIFY 1\n#ifndef MATERIAL_OMIT_NORMAL\n#ifdef RENDERER_HAS_NORMAL\nv_normal=normalize(mat3(renderer_NormalMat)*normal);\n#if defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY) )\nvec3 tangentW=normalize(mat3(renderer_NormalMat)*tangent.xyz);vec3 bitangentW=cross(v_normal,tangentW)*tangent.w;v_TBN=mat3(tangentW,bitangentW,v_normal);\n#endif\n#endif\n#endif\n"; // eslint-disable-line
3485
+ var normal_vert = "#define GLSLIFY 1\n#ifndef MATERIAL_OMIT_NORMAL\n #ifdef RENDERER_HAS_NORMAL\n v_normal = normalize( mat3(renderer_NormalMat) * normal );\n\n #if defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY) )\n vec3 tangentW = normalize( mat3(renderer_NormalMat) * tangent.xyz );\n vec3 bitangentW = cross( v_normal, tangentW ) * tangent.w;\n\n v_TBN = mat3( tangentW, bitangentW, v_normal );\n #endif\n #endif\n#endif"; // eslint-disable-line
3486
3486
 
3487
- var position_vert = "#define GLSLIFY 1\ngl_Position=renderer_MVPMat*position;"; // eslint-disable-line
3487
+ var position_vert = "#define GLSLIFY 1\n gl_Position = renderer_MVPMat * position;"; // eslint-disable-line
3488
3488
 
3489
- var skinning_vert = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_SKIN\n#ifdef RENDERER_USE_JOINT_TEXTURE\nmat4 skinMatrix=WEIGHTS_0.x*getJointMatrix(renderer_JointSampler,JOINTS_0.x)+WEIGHTS_0.y*getJointMatrix(renderer_JointSampler,JOINTS_0.y)+WEIGHTS_0.z*getJointMatrix(renderer_JointSampler,JOINTS_0.z)+WEIGHTS_0.w*getJointMatrix(renderer_JointSampler,JOINTS_0.w);\n#else\nmat4 skinMatrix=WEIGHTS_0.x*renderer_JointMatrix[int(JOINTS_0.x)]+WEIGHTS_0.y*renderer_JointMatrix[int(JOINTS_0.y)]+WEIGHTS_0.z*renderer_JointMatrix[int(JOINTS_0.z)]+WEIGHTS_0.w*renderer_JointMatrix[int(JOINTS_0.w)];\n#endif\nposition=skinMatrix*position;\n#if defined(RENDERER_HAS_NORMAL) && !defined(MATERIAL_OMIT_NORMAL)\nmat3 skinNormalMatrix=INVERSE_MAT(mat3(skinMatrix));normal=normal*skinNormalMatrix;\n#if defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\ntangent.xyz=tangent.xyz*skinNormalMatrix;\n#endif\n#endif\n#endif\n"; // eslint-disable-line
3489
+ var skinning_vert = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_SKIN\n\n #ifdef RENDERER_USE_JOINT_TEXTURE\n mat4 skinMatrix =\n WEIGHTS_0.x * getJointMatrix(renderer_JointSampler, JOINTS_0.x ) +\n WEIGHTS_0.y * getJointMatrix(renderer_JointSampler, JOINTS_0.y ) +\n WEIGHTS_0.z * getJointMatrix(renderer_JointSampler, JOINTS_0.z ) +\n WEIGHTS_0.w * getJointMatrix(renderer_JointSampler, JOINTS_0.w );\n\n #else\n mat4 skinMatrix =\n WEIGHTS_0.x * renderer_JointMatrix[ int( JOINTS_0.x ) ] +\n WEIGHTS_0.y * renderer_JointMatrix[ int( JOINTS_0.y ) ] +\n WEIGHTS_0.z * renderer_JointMatrix[ int( JOINTS_0.z ) ] +\n WEIGHTS_0.w * renderer_JointMatrix[ int( JOINTS_0.w ) ];\n #endif\n\n position = skinMatrix * position;\n\n #if defined(RENDERER_HAS_NORMAL) && !defined(MATERIAL_OMIT_NORMAL)\n mat3 skinNormalMatrix = INVERSE_MAT(mat3(skinMatrix));\n normal = normal * skinNormalMatrix;\n #if defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\n tangent.xyz = tangent.xyz * skinNormalMatrix;\n #endif\n\n #endif\n\n#endif\n"; // eslint-disable-line
3490
3490
 
3491
- var uv_vert = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_UV\nv_uv=TEXCOORD_0;\n#else\nv_uv=vec2(0.,0.);\n#endif\n#ifdef RENDERER_HAS_UV1\nv_uv1=TEXCOORD_1;\n#endif\n#ifdef MATERIAL_NEED_TILING_OFFSET\nv_uv=v_uv*material_TilingOffset.xy+material_TilingOffset.zw;\n#endif\n"; // eslint-disable-line
3491
+ var uv_vert = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_UV\n v_uv = TEXCOORD_0;\n#else\n // may need this calculate normal\n v_uv = vec2( 0., 0. );\n#endif\n\n#ifdef RENDERER_HAS_UV1\n v_uv1 = TEXCOORD_1;\n#endif\n\n#ifdef MATERIAL_NEED_TILING_OFFSET\n v_uv = v_uv * material_TilingOffset.xy + material_TilingOffset.zw;\n#endif"; // eslint-disable-line
3492
3492
 
3493
- var worldpos_vert = "#define GLSLIFY 1\n#ifdef MATERIAL_NEED_WORLD_POS\nvec4 temp_pos=renderer_ModelMat*position;v_pos=temp_pos.xyz/temp_pos.w;\n#endif\n"; // eslint-disable-line
3493
+ var worldpos_vert = "#define GLSLIFY 1\n#ifdef MATERIAL_NEED_WORLD_POS\n vec4 temp_pos = renderer_ModelMat * position;\n v_pos = temp_pos.xyz / temp_pos.w;\n#endif\n"; // eslint-disable-line
3494
3494
 
3495
- var FogFragment = "#define GLSLIFY 1\n#if SCENE_FOG_MODE != 0\nfloat fogIntensity=ComputeFogIntensity(length(v_positionVS));gl_FragColor.rgb=mix(scene_FogColor.rgb,gl_FragColor.rgb,fogIntensity);\n#endif\n"; // eslint-disable-line
3495
+ var FogFragment = "#define GLSLIFY 1\n#if SCENE_FOG_MODE != 0\n float fogIntensity = ComputeFogIntensity(length(v_positionVS));\n gl_FragColor.rgb = mix(scene_FogColor.rgb, gl_FragColor.rgb, fogIntensity);\n#endif\n"; // eslint-disable-line
3496
3496
 
3497
- var light_frag_define = "#define GLSLIFY 1\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nstruct DirectLight{vec3 color;vec3 direction;};uniform ivec2 scene_DirectLightCullingMask[SCENE_DIRECT_LIGHT_COUNT];uniform vec3 scene_DirectLightColor[SCENE_DIRECT_LIGHT_COUNT];uniform vec3 scene_DirectLightDirection[SCENE_DIRECT_LIGHT_COUNT];\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nstruct PointLight{vec3 color;vec3 position;float distance;};uniform ivec2 scene_PointLightCullingMask[SCENE_POINT_LIGHT_COUNT];uniform vec3 scene_PointLightColor[SCENE_POINT_LIGHT_COUNT];uniform vec3 scene_PointLightPosition[SCENE_POINT_LIGHT_COUNT];uniform float scene_PointLightDistance[SCENE_POINT_LIGHT_COUNT];\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nstruct SpotLight{vec3 color;vec3 position;vec3 direction;float distance;float angleCos;float penumbraCos;};uniform ivec2 scene_SpotLightCullingMask[SCENE_SPOT_LIGHT_COUNT];uniform vec3 scene_SpotLightColor[SCENE_SPOT_LIGHT_COUNT];uniform vec3 scene_SpotLightPosition[SCENE_SPOT_LIGHT_COUNT];uniform vec3 scene_SpotLightDirection[SCENE_SPOT_LIGHT_COUNT];uniform float scene_SpotLightDistance[SCENE_SPOT_LIGHT_COUNT];uniform float scene_SpotLightAngleCos[SCENE_SPOT_LIGHT_COUNT];uniform float scene_SpotLightPenumbraCos[SCENE_SPOT_LIGHT_COUNT];\n#endif\nstruct EnvMapLight{vec3 diffuse;float mipMapLevel;float diffuseIntensity;float specularIntensity;};uniform EnvMapLight scene_EnvMapLight;uniform ivec4 renderer_Layer;\n#ifdef SCENE_USE_SH\nuniform vec3 scene_EnvSH[9];\n#endif\n#ifdef SCENE_USE_SPECULAR_ENV\nuniform samplerCube scene_EnvSpecularSampler;\n#endif\n#ifndef GRAPHICS_API_WEBGL2\nbool isBitSet(float value,float mask,float bitIndex){return mod(floor(value/pow(2.0,bitIndex)),2.0)==1.0&&mod(floor(mask/pow(2.0,bitIndex)),2.0)==1.0;}\n#endif\nbool isRendererCulledByLight(ivec2 rendererLayer,ivec2 lightCullingMask){\n#ifdef GRAPHICS_API_WEBGL2\nreturn!((rendererLayer.x&lightCullingMask.x)!=0||(rendererLayer.y&lightCullingMask.y)!=0);\n#else\nfor(int i=0;i<16;i++){if(isBitSet(float(rendererLayer.x),float(lightCullingMask.x),float(i))||isBitSet(float(rendererLayer.y),float(lightCullingMask.y),float(i))){return false;}}return true;\n#endif\n}"; // eslint-disable-line
3497
+ var light_frag_define = "#define GLSLIFY 1\n// Directional light\n#ifdef SCENE_DIRECT_LIGHT_COUNT\n\n struct DirectLight {\n vec3 color;\n vec3 direction;\n };\n\n uniform ivec2 scene_DirectLightCullingMask[SCENE_DIRECT_LIGHT_COUNT];\n uniform vec3 scene_DirectLightColor[SCENE_DIRECT_LIGHT_COUNT];\n uniform vec3 scene_DirectLightDirection[SCENE_DIRECT_LIGHT_COUNT];\n\n#endif\n\n// Point light\n#ifdef SCENE_POINT_LIGHT_COUNT\n\n struct PointLight {\n vec3 color;\n vec3 position;\n float distance;\n };\n\n uniform ivec2 scene_PointLightCullingMask[ SCENE_POINT_LIGHT_COUNT ];\n uniform vec3 scene_PointLightColor[ SCENE_POINT_LIGHT_COUNT ];\n uniform vec3 scene_PointLightPosition[ SCENE_POINT_LIGHT_COUNT ];\n uniform float scene_PointLightDistance[ SCENE_POINT_LIGHT_COUNT ];\n\n#endif\n\n// Spot light\n#ifdef SCENE_SPOT_LIGHT_COUNT\n\n struct SpotLight {\n vec3 color;\n vec3 position;\n vec3 direction;\n float distance;\n float angleCos;\n float penumbraCos;\n };\n\n uniform ivec2 scene_SpotLightCullingMask[ SCENE_SPOT_LIGHT_COUNT ];\n uniform vec3 scene_SpotLightColor[ SCENE_SPOT_LIGHT_COUNT ];\n uniform vec3 scene_SpotLightPosition[ SCENE_SPOT_LIGHT_COUNT ];\n uniform vec3 scene_SpotLightDirection[ SCENE_SPOT_LIGHT_COUNT ];\n uniform float scene_SpotLightDistance[ SCENE_SPOT_LIGHT_COUNT ];\n uniform float scene_SpotLightAngleCos[ SCENE_SPOT_LIGHT_COUNT ];\n uniform float scene_SpotLightPenumbraCos[ SCENE_SPOT_LIGHT_COUNT ];\n\n#endif\n\n// Ambient light\nstruct EnvMapLight {\n vec3 diffuse;\n float mipMapLevel;\n float diffuseIntensity;\n float specularIntensity;\n};\n\nuniform EnvMapLight scene_EnvMapLight;\nuniform ivec4 renderer_Layer;\n\n#ifdef SCENE_USE_SH\n uniform vec3 scene_EnvSH[9];\n#endif\n\n#ifdef SCENE_USE_SPECULAR_ENV\n uniform samplerCube scene_EnvSpecularSampler;\n#endif\n\n#ifndef GRAPHICS_API_WEBGL2\nbool isBitSet(float value, float mask, float bitIndex)\n{\n return mod(floor(value / pow(2.0, bitIndex)), 2.0) == 1.0 && mod(floor(mask / pow(2.0, bitIndex)), 2.0) == 1.0;\n}\n#endif\n\nbool isRendererCulledByLight(ivec2 rendererLayer, ivec2 lightCullingMask)\n{\n #ifdef GRAPHICS_API_WEBGL2\n return !((rendererLayer.x & lightCullingMask.x) != 0 || (rendererLayer.y & lightCullingMask.y) != 0);\n #else\n for (int i = 0; i < 16; i++) {\n if (isBitSet( float(rendererLayer.x), float(lightCullingMask.x), float(i)) || isBitSet( float(rendererLayer.y), float(lightCullingMask.y), float(i))) {\n return false;\n }\n }\n return true;\n #endif\n}\n"; // eslint-disable-line
3498
3498
 
3499
- var mobile_material_frag = "#define GLSLIFY 1\nuniform vec4 material_EmissiveColor;uniform vec4 material_BaseColor;uniform vec4 material_SpecularColor;uniform float material_Shininess;uniform float material_NormalIntensity;uniform float material_AlphaCutoff;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nuniform sampler2D material_EmissiveTexture;\n#endif\n#ifdef MATERIAL_HAS_BASETEXTURE\nuniform sampler2D material_BaseTexture;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_TEXTURE\nuniform sampler2D material_SpecularTexture;\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nuniform sampler2D material_NormalTexture;\n#endif\n"; // eslint-disable-line
3499
+ var mobile_material_frag = "#define GLSLIFY 1\nuniform vec4 material_EmissiveColor;\nuniform vec4 material_BaseColor;\nuniform vec4 material_SpecularColor;\nuniform float material_Shininess;\nuniform float material_NormalIntensity;\nuniform float material_AlphaCutoff;\n\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\n uniform sampler2D material_EmissiveTexture;\n#endif\n\n#ifdef MATERIAL_HAS_BASETEXTURE\n uniform sampler2D material_BaseTexture;\n#endif\n\n#ifdef MATERIAL_HAS_SPECULAR_TEXTURE\n uniform sampler2D material_SpecularTexture;\n#endif\n\n#ifdef MATERIAL_HAS_NORMALTEXTURE\n uniform sampler2D material_NormalTexture;\n#endif\n"; // eslint-disable-line
3500
3500
 
3501
- var begin_mobile_frag = "#define GLSLIFY 1\nvec4 ambient=vec4(0.0);vec4 emission=material_EmissiveColor;vec4 diffuse=material_BaseColor;vec4 specular=material_SpecularColor;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nvec4 emissiveTextureColor=texture2D(material_EmissiveTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nemissiveTextureColor=gammaToLinear(emissiveTextureColor);\n#endif\nemission*=emissiveTextureColor;\n#endif\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 diffuseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ndiffuseTextureColor=gammaToLinear(diffuseTextureColor);\n#endif\ndiffuse*=diffuseTextureColor;\n#endif\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\ndiffuse*=v_color;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_TEXTURE\nvec4 specularTextureColor=texture2D(material_SpecularTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularTextureColor=gammaToLinear(specularTextureColor);\n#endif\nspecular*=specularTextureColor;\n#endif\nambient=vec4(scene_EnvMapLight.diffuse*scene_EnvMapLight.diffuseIntensity,1.0)*diffuse;"; // eslint-disable-line
3501
+ var begin_mobile_frag = "#define GLSLIFY 1\n vec4 ambient = vec4(0.0);\n vec4 emission = material_EmissiveColor;\n vec4 diffuse = material_BaseColor;\n vec4 specular = material_SpecularColor;\n\n \n\n #ifdef MATERIAL_HAS_EMISSIVETEXTURE\n vec4 emissiveTextureColor = texture2D(material_EmissiveTexture, v_uv);\n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n emissiveTextureColor = gammaToLinear(emissiveTextureColor);\n #endif\n emission *= emissiveTextureColor;\n\n #endif\n\n #ifdef MATERIAL_HAS_BASETEXTURE\n vec4 diffuseTextureColor = texture2D(material_BaseTexture, v_uv);\n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n diffuseTextureColor = gammaToLinear(diffuseTextureColor);\n #endif\n diffuse *= diffuseTextureColor;\n\n #endif\n\n #ifdef RENDERER_ENABLE_VERTEXCOLOR\n\n diffuse *= v_color;\n\n #endif\n\n #ifdef MATERIAL_HAS_SPECULAR_TEXTURE\n vec4 specularTextureColor = texture2D(material_SpecularTexture, v_uv);\n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n specularTextureColor = gammaToLinear(specularTextureColor);\n #endif\n specular *= specularTextureColor;\n\n #endif\n\n ambient = vec4(scene_EnvMapLight.diffuse * scene_EnvMapLight.diffuseIntensity, 1.0) * diffuse;"; // eslint-disable-line
3502
3502
 
3503
- var begin_viewdir_frag = "#define GLSLIFY 1\n#ifdef CAMERA_ORTHOGRAPHIC\nvec3 V=-camera_Forward;\n#else\n#ifdef MATERIAL_NEED_WORLD_POS\nvec3 V=normalize(camera_Position-v_pos);\n#endif\n#endif\n"; // eslint-disable-line
3503
+ var begin_viewdir_frag = "#define GLSLIFY 1\n#ifdef CAMERA_ORTHOGRAPHIC\n vec3 V = -camera_Forward;\n#else\n #ifdef MATERIAL_NEED_WORLD_POS\n vec3 V = normalize( camera_Position - v_pos );\n #endif\n#endif"; // eslint-disable-line
3504
3504
 
3505
- var mobile_blinnphong_frag = "#define GLSLIFY 1\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nmat3 tbn=getTBN(gl_FrontFacing);vec3 N=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv,gl_FrontFacing);\n#else\nvec3 N=getNormal(gl_FrontFacing);\n#endif\nvec3 lightDiffuse=vec3(0.0,0.0,0.0);vec3 lightSpecular=vec3(0.0,0.0,0.0);float shadowAttenuation=1.0;\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nshadowAttenuation=1.0;\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nshadowAttenuation*=sampleShadowMap();\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];float d=max(dot(N,-directionalLight.direction),0.0);lightDiffuse+=directionalLight.color*d;vec3 halfDir=normalize(V-directionalLight.direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess);lightSpecular+=directionalLight.color*s;}}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nPointLight pointLight;for(int i=0;i<SCENE_POINT_LIGHT_COUNT;i++){if(!isRendererCulledByLight(renderer_Layer.xy,scene_PointLightCullingMask[i])){pointLight.color=scene_PointLightColor[i];pointLight.position=scene_PointLightPosition[i];pointLight.distance=scene_PointLightDistance[i];vec3 direction=v_pos-pointLight.position;float dist=length(direction);direction/=dist;float decay=clamp(1.0-pow(dist/pointLight.distance,4.0),0.0,1.0);float d=max(dot(N,-direction),0.0)*decay;lightDiffuse+=pointLight.color*d;vec3 halfDir=normalize(V-direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decay;lightSpecular+=pointLight.color*s;}}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nSpotLight spotLight;for(int i=0;i<SCENE_SPOT_LIGHT_COUNT;i++){if(!isRendererCulledByLight(renderer_Layer.xy,scene_SpotLightCullingMask[i])){spotLight.color=scene_SpotLightColor[i];spotLight.position=scene_SpotLightPosition[i];spotLight.direction=scene_SpotLightDirection[i];spotLight.distance=scene_SpotLightDistance[i];spotLight.angleCos=scene_SpotLightAngleCos[i];spotLight.penumbraCos=scene_SpotLightPenumbraCos[i];vec3 direction=spotLight.position-v_pos;float lightDistance=length(direction);direction/=lightDistance;float angleCos=dot(direction,-spotLight.direction);float decay=clamp(1.0-pow(lightDistance/spotLight.distance,4.0),0.0,1.0);float spotEffect=smoothstep(spotLight.penumbraCos,spotLight.angleCos,angleCos);float decayTotal=decay*spotEffect;float d=max(dot(N,direction),0.0)*decayTotal;lightDiffuse+=spotLight.color*d;vec3 halfDir=normalize(V+direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decayTotal;lightSpecular+=spotLight.color*s;}}\n#endif\ndiffuse*=vec4(lightDiffuse,1.0);specular*=vec4(lightSpecular,1.0);\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(diffuse.a<material_AlphaCutoff){discard;}\n#endif\n"; // eslint-disable-line
3505
+ var mobile_blinnphong_frag = "#define GLSLIFY 1\n #ifdef MATERIAL_HAS_NORMALTEXTURE\n mat3 tbn = getTBN(gl_FrontFacing);\n vec3 N = getNormalByNormalTexture(tbn, material_NormalTexture, material_NormalIntensity, v_uv, gl_FrontFacing);\n #else\n vec3 N = getNormal(gl_FrontFacing);\n #endif\n\n vec3 lightDiffuse = vec3( 0.0, 0.0, 0.0 );\n vec3 lightSpecular = vec3( 0.0, 0.0, 0.0 );\n float shadowAttenuation = 1.0;\n\n #ifdef SCENE_DIRECT_LIGHT_COUNT\n shadowAttenuation = 1.0;\n #ifdef SCENE_IS_CALCULATE_SHADOWS\n shadowAttenuation *= sampleShadowMap();\n #endif\n\n DirectLight directionalLight;\n for( int i = 0; i < SCENE_DIRECT_LIGHT_COUNT; i++ ) {\n if(!isRendererCulledByLight(renderer_Layer.xy, scene_DirectLightCullingMask[i])){\n directionalLight.color = scene_DirectLightColor[i];\n #ifdef SCENE_IS_CALCULATE_SHADOWS\n if (i == 0) { // Sun light index is always 0\n directionalLight.color *= shadowAttenuation;\n }\n #endif\n directionalLight.direction = scene_DirectLightDirection[i];\n \n float d = max(dot(N, -directionalLight.direction), 0.0);\n lightDiffuse += directionalLight.color * d;\n \n vec3 halfDir = normalize( V - directionalLight.direction );\n float s = pow( clamp( dot( N, halfDir ), 0.0, 1.0 ), material_Shininess );\n lightSpecular += directionalLight.color * s;\n }\n }\n\n #endif\n\n #ifdef SCENE_POINT_LIGHT_COUNT\n PointLight pointLight;\n for( int i = 0; i < SCENE_POINT_LIGHT_COUNT; i++ ) {\n if(!isRendererCulledByLight(renderer_Layer.xy, scene_PointLightCullingMask[i])){\n pointLight.color = scene_PointLightColor[i];\n pointLight.position = scene_PointLightPosition[i];\n pointLight.distance = scene_PointLightDistance[i];\n\n vec3 direction = v_pos - pointLight.position;\n float dist = length( direction );\n direction /= dist;\n float decay = clamp(1.0 - pow(dist / pointLight.distance, 4.0), 0.0, 1.0);\n\n float d = max( dot( N, -direction ), 0.0 ) * decay;\n lightDiffuse += pointLight.color * d;\n\n vec3 halfDir = normalize( V - direction );\n float s = pow( clamp( dot( N, halfDir ), 0.0, 1.0 ), material_Shininess ) * decay;\n lightSpecular += pointLight.color * s;\n }\n }\n\n #endif\n\n #ifdef SCENE_SPOT_LIGHT_COUNT\n SpotLight spotLight;\n for( int i = 0; i < SCENE_SPOT_LIGHT_COUNT; i++) {\n if(!isRendererCulledByLight(renderer_Layer.xy, scene_SpotLightCullingMask[i])){\n spotLight.color = scene_SpotLightColor[i];\n spotLight.position = scene_SpotLightPosition[i];\n spotLight.direction = scene_SpotLightDirection[i];\n spotLight.distance = scene_SpotLightDistance[i];\n spotLight.angleCos = scene_SpotLightAngleCos[i];\n spotLight.penumbraCos = scene_SpotLightPenumbraCos[i];\n\n vec3 direction = spotLight.position - v_pos;\n float lightDistance = length( direction );\n direction /= lightDistance;\n float angleCos = dot( direction, -spotLight.direction );\n float decay = clamp(1.0 - pow(lightDistance/spotLight.distance, 4.0), 0.0, 1.0);\n float spotEffect = smoothstep( spotLight.penumbraCos, spotLight.angleCos, angleCos );\n float decayTotal = decay * spotEffect;\n float d = max( dot( N, direction ), 0.0 ) * decayTotal;\n lightDiffuse += spotLight.color * d;\n\n vec3 halfDir = normalize( V + direction );\n float s = pow( clamp( dot( N, halfDir ), 0.0, 1.0 ), material_Shininess ) * decayTotal;\n lightSpecular += spotLight.color * s;\n }\n }\n\n #endif\n\n diffuse *= vec4( lightDiffuse, 1.0 );\n specular *= vec4( lightSpecular, 1.0 );\n\n #ifdef MATERIAL_IS_ALPHA_CUTOFF\n if( diffuse.a < material_AlphaCutoff ) {\n discard;\n }\n #endif\n"; // eslint-disable-line
3506
3506
 
3507
3507
  var noise_cellular = "#define GLSLIFY 1\n#include <noise_cellular_2D>\n#include <noise_cellular_3D>\n#include <noise_cellular_2x2>\n#include <noise_cellular_2x2x2>\n"; // eslint-disable-line
3508
3508
 
3509
- var noise_cellular_2D = "#define GLSLIFY 1\nvec2 cellular(vec2 P){vec2 Pi=mod289(floor(P));vec2 Pf=fract(P);vec3 oi=vec3(-1.0,0.0,1.0);vec3 of=vec3(-0.5,0.5,1.5);vec3 px=permute(Pi.x+oi);vec3 p=permute(px.x+Pi.y+oi);vec3 ox=fract(p*K)-Ko;vec3 oy=mod7(floor(p*K))*K-Ko;vec3 dx=Pf.x+0.5+jitter*ox;vec3 dy=Pf.y-of+jitter*oy;vec3 d1=dx*dx+dy*dy;p=permute(px.y+Pi.y+oi);ox=fract(p*K)-Ko;oy=mod7(floor(p*K))*K-Ko;dx=Pf.x-0.5+jitter*ox;dy=Pf.y-of+jitter*oy;vec3 d2=dx*dx+dy*dy;p=permute(px.z+Pi.y+oi);ox=fract(p*K)-Ko;oy=mod7(floor(p*K))*K-Ko;dx=Pf.x-1.5+jitter*ox;dy=Pf.y-of+jitter*oy;vec3 d3=dx*dx+dy*dy;vec3 d1a=min(d1,d2);d2=max(d1,d2);d2=min(d2,d3);d1=min(d1a,d2);d2=max(d1a,d2);d1.xy=(d1.x<d1.y)? d1.xy : d1.yx;d1.xz=(d1.x<d1.z)? d1.xz : d1.zx;d1.yz=min(d1.yz,d2.yz);d1.y=min(d1.y,d1.z);d1.y=min(d1.y,d2.x);return sqrt(d1.xy);}"; // eslint-disable-line
3509
+ var noise_cellular_2D = "#define GLSLIFY 1\n// Cellular noise (\"Worley noise\") in 2D in GLSL.\n// Copyright (c) Stefan Gustavson 2011-04-19. All rights reserved.\n// This code is released under the conditions of the MIT license.\n// See LICENSE file for details.\n// https://github.com/stegu/webgl-noise\n\n// Cellular noise, returning F1 and F2 in a vec2.\n// Standard 3x3 search window for good F1 and F2 values\nvec2 cellular( vec2 P ) {\n\n\tvec2 Pi = mod289( floor( P ) );\n \tvec2 Pf = fract( P );\n\tvec3 oi = vec3( -1.0, 0.0, 1.0);\n\tvec3 of = vec3( -0.5, 0.5, 1.5);\n\tvec3 px = permute( Pi.x + oi );\n\tvec3 p = permute( px.x + Pi.y + oi ); // p11, p12, p13\n\tvec3 ox = fract( p * K ) - Ko;\n\tvec3 oy = mod7( floor( p * K ) ) * K - Ko;\n\tvec3 dx = Pf.x + 0.5 + jitter * ox;\n\tvec3 dy = Pf.y - of + jitter * oy;\n\tvec3 d1 = dx * dx + dy * dy; // d11, d12 and d13, squared\n\tp = permute( px.y + Pi.y + oi ); // p21, p22, p23\n\tox = fract( p * K ) - Ko;\n\toy = mod7( floor( p * K ) ) * K - Ko;\n\tdx = Pf.x - 0.5 + jitter * ox;\n\tdy = Pf.y - of + jitter * oy;\n\tvec3 d2 = dx * dx + dy * dy; // d21, d22 and d23, squared\n\tp = permute( px.z + Pi.y + oi ); // p31, p32, p33\n\tox = fract( p * K ) - Ko;\n\toy = mod7( floor( p * K ) ) * K - Ko;\n\tdx = Pf.x - 1.5 + jitter * ox;\n\tdy = Pf.y - of + jitter * oy;\n\tvec3 d3 = dx * dx + dy * dy; // d31, d32 and d33, squared\n\t// Sort out the two smallest distances (F1, F2)\n\tvec3 d1a = min( d1, d2 );\n\td2 = max( d1, d2 ); // Swap to keep candidates for F2\n\td2 = min( d2, d3 ); // neither F1 nor F2 are now in d3\n\td1 = min( d1a, d2 ); // F1 is now in d1\n\td2 = max( d1a, d2 ); // Swap to keep candidates for F2\n\td1.xy = ( d1.x < d1.y ) ? d1.xy : d1.yx; // Swap if smaller\n\td1.xz = ( d1.x < d1.z ) ? d1.xz : d1.zx; // F1 is in d1.x\n\td1.yz = min( d1.yz, d2.yz ); // F2 is now not in d2.yz\n\td1.y = min( d1.y, d1.z ); // nor in d1.z\n\td1.y = min( d1.y, d2.x ); // F2 is in d1.y, we're done.\n\treturn sqrt( d1.xy );\n\n}\n"; // eslint-disable-line
3510
3510
 
3511
- var noise_cellular_2x2 = "#define GLSLIFY 1\nvec2 cellular2x2(vec2 P){vec2 Pi=mod289(floor(P));vec2 Pf=fract(P);vec4 Pfx=Pf.x+vec4(-0.5,-1.5,-0.5,-1.5);vec4 Pfy=Pf.y+vec4(-0.5,-0.5,-1.5,-1.5);vec4 p=permute(Pi.x+vec4(0.0,1.0,0.0,1.0));p=permute(p+Pi.y+vec4(0.0,0.0,1.0,1.0));vec4 ox=mod7(p)*K+Kd2;vec4 oy=mod7(floor(p*K))*K+Kd2;vec4 dx=Pfx+jitter1*ox;vec4 dy=Pfy+jitter1*oy;vec4 d=dx*dx+dy*dy;d.xy=(d.x<d.y)? d.xy : d.yx;d.xz=(d.x<d.z)? d.xz : d.zx;d.xw=(d.x<d.w)? d.xw : d.wx;d.y=min(d.y,d.z);d.y=min(d.y,d.w);return sqrt(d.xy);}"; // eslint-disable-line
3511
+ var noise_cellular_2x2 = "#define GLSLIFY 1\n// Cellular noise (\"Worley noise\") in 2D in GLSL.\n// Copyright (c) Stefan Gustavson 2011-04-19. All rights reserved.\n// This code is released under the conditions of the MIT license.\n// See LICENSE file for details.\n// https://github.com/stegu/webgl-noise\n\n// Cellular noise, returning F1 and F2 in a vec2.\n// Speeded up by using 2x2 search window instead of 3x3,\n// at the expense of some strong pattern artifacts.\n// F2 is often wrong and has sharp discontinuities.\n// If you need a smooth F2, use the slower 3x3 version.\n// F1 is sometimes wrong, too, but OK for most purposes.\nvec2 cellular2x2( vec2 P ) {\n\n\tvec2 Pi = mod289( floor( P ) );\n \tvec2 Pf = fract( P );\n\tvec4 Pfx = Pf.x + vec4( -0.5, -1.5, -0.5, -1.5 );\n\tvec4 Pfy = Pf.y + vec4( -0.5, -0.5, -1.5, -1.5 );\n\tvec4 p = permute( Pi.x + vec4( 0.0, 1.0, 0.0, 1.0 ) );\n\tp = permute( p + Pi.y + vec4( 0.0, 0.0, 1.0, 1.0 ) );\n\tvec4 ox = mod7( p ) * K + Kd2;\n\tvec4 oy = mod7( floor( p * K ) ) * K + Kd2;\n\tvec4 dx = Pfx + jitter1 * ox;\n\tvec4 dy = Pfy + jitter1 * oy;\n\tvec4 d = dx * dx + dy * dy; // d11, d12, d21 and d22, squared\n\n\t// Do it right and find both F1 and F2\n\td.xy = ( d.x < d.y ) ? d.xy : d.yx; // Swap if smaller\n\td.xz = ( d.x < d.z ) ? d.xz : d.zx;\n\td.xw = ( d.x < d.w ) ? d.xw : d.wx;\n\td.y = min( d.y, d.z );\n\td.y = min( d.y, d.w );\n\treturn sqrt( d.xy );\n\n}\n"; // eslint-disable-line
3512
3512
 
3513
- var noise_cellular_2x2x2 = "#define GLSLIFY 1\nvec2 cellular2x2x2(vec3 P){vec3 Pi=mod289(floor(P));vec3 Pf=fract(P);vec4 Pfx=Pf.x+vec4(0.0,-1.0,0.0,-1.0);vec4 Pfy=Pf.y+vec4(0.0,0.0,-1.0,-1.0);vec4 p=permute(Pi.x+vec4(0.0,1.0,0.0,1.0));p=permute(p+Pi.y+vec4(0.0,0.0,1.0,1.0));vec4 p1=permute(p+Pi.z);vec4 p2=permute(p+Pi.z+vec4(1.0));vec4 ox1=fract(p1*K)-Ko;vec4 oy1=mod7(floor(p1*K))*K-Ko;vec4 oz1=floor(p1*K2)*Kz-Kzo;vec4 ox2=fract(p2*K)-Ko;vec4 oy2=mod7(floor(p2*K))*K-Ko;vec4 oz2=floor(p2*K2)*Kz-Kzo;vec4 dx1=Pfx+jitter1*ox1;vec4 dy1=Pfy+jitter1*oy1;vec4 dz1=Pf.z+jitter1*oz1;vec4 dx2=Pfx+jitter1*ox2;vec4 dy2=Pfy+jitter1*oy2;vec4 dz2=Pf.z-1.0+jitter1*oz2;vec4 d1=dx1*dx1+dy1*dy1+dz1*dz1;vec4 d2=dx2*dx2+dy2*dy2+dz2*dz2;vec4 d=min(d1,d2);d2=max(d1,d2);d.xy=(d.x<d.y)? d.xy : d.yx;d.xz=(d.x<d.z)? d.xz : d.zx;d.xw=(d.x<d.w)? d.xw : d.wx;d.yzw=min(d.yzw,d2.yzw);d.y=min(d.y,d.z);d.y=min(d.y,d.w);d.y=min(d.y,d2.x);return sqrt(d.xy);}"; // eslint-disable-line
3513
+ var noise_cellular_2x2x2 = "#define GLSLIFY 1\n// Cellular noise (\"Worley noise\") in 3D in GLSL.\n// Copyright (c) Stefan Gustavson 2011-04-19. All rights reserved.\n// This code is released under the conditions of the MIT license.\n// See LICENSE file for details.\n// https://github.com/stegu/webgl-noise\n\n// Cellular noise, returning F1 and F2 in a vec2.\n// Speeded up by using 2x2x2 search window instead of 3x3x3,\n// at the expense of some pattern artifacts.\n// F2 is often wrong and has sharp discontinuities.\n// If you need a good F2, use the slower 3x3x3 version.\nvec2 cellular2x2x2(vec3 P) {\n\n\tvec3 Pi = mod289( floor( P ) );\n \tvec3 Pf = fract( P );\n\tvec4 Pfx = Pf.x + vec4( 0.0, -1.0, 0.0, -1.0 );\n\tvec4 Pfy = Pf.y + vec4( 0.0, 0.0, -1.0, -1.0 );\n\tvec4 p = permute( Pi.x + vec4( 0.0, 1.0, 0.0, 1.0 ) );\n\tp = permute( p + Pi.y + vec4( 0.0, 0.0, 1.0, 1.0 ) );\n\tvec4 p1 = permute( p + Pi.z ); // z+0\n\tvec4 p2 = permute( p + Pi.z + vec4( 1.0 ) ); // z+1\n\tvec4 ox1 = fract( p1 * K ) - Ko;\n\tvec4 oy1 = mod7( floor( p1 * K ) ) * K - Ko;\n\tvec4 oz1 = floor( p1 * K2 ) * Kz - Kzo; // p1 < 289 guaranteed\n\tvec4 ox2 = fract( p2 * K ) - Ko;\n\tvec4 oy2 = mod7( floor( p2 * K ) ) * K - Ko;\n\tvec4 oz2 = floor( p2 * K2 ) * Kz - Kzo;\n\tvec4 dx1 = Pfx + jitter1 * ox1;\n\tvec4 dy1 = Pfy + jitter1 * oy1;\n\tvec4 dz1 = Pf.z + jitter1 * oz1;\n\tvec4 dx2 = Pfx + jitter1 * ox2;\n\tvec4 dy2 = Pfy + jitter1 * oy2;\n\tvec4 dz2 = Pf.z - 1.0 + jitter1 * oz2;\n\tvec4 d1 = dx1 * dx1 + dy1 * dy1 + dz1 * dz1; // z+0\n\tvec4 d2 = dx2 * dx2 + dy2 * dy2 + dz2 * dz2; // z+1\n\n\t// Do it right and sort out both F1 and F2\n\tvec4 d = min( d1, d2 ); // F1 is now in d\n\td2 = max( d1, d2 ); // Make sure we keep all candidates for F2\n\td.xy = ( d.x < d.y ) ? d.xy : d.yx; // Swap smallest to d.x\n\td.xz = ( d.x < d.z ) ? d.xz : d.zx;\n\td.xw = ( d.x < d.w ) ? d.xw : d.wx; // F1 is now in d.x\n\td.yzw = min( d.yzw, d2.yzw ); // F2 now not in d2.yzw\n\td.y = min( d.y, d.z ); // nor in d.z\n\td.y = min( d.y, d.w ); // nor in d.w\n\td.y = min( d.y, d2.x ); // F2 is now in d.y\n\treturn sqrt( d.xy ); // F1 and F2\n\n}\n"; // eslint-disable-line
3514
3514
 
3515
- var noise_cellular_3D = "#define GLSLIFY 1\nvec2 cellular(vec3 P){vec3 Pi=mod289(floor(P));vec3 Pf=fract(P)-0.5;vec3 Pfx=Pf.x+vec3(1.0,0.0,-1.0);vec3 Pfy=Pf.y+vec3(1.0,0.0,-1.0);vec3 Pfz=Pf.z+vec3(1.0,0.0,-1.0);vec3 p=permute(Pi.x+vec3(-1.0,0.0,1.0));vec3 p1=permute(p+Pi.y-1.0);vec3 p2=permute(p+Pi.y);vec3 p3=permute(p+Pi.y+1.0);vec3 p11=permute(p1+Pi.z-1.0);vec3 p12=permute(p1+Pi.z);vec3 p13=permute(p1+Pi.z+1.0);vec3 p21=permute(p2+Pi.z-1.0);vec3 p22=permute(p2+Pi.z);vec3 p23=permute(p2+Pi.z+1.0);vec3 p31=permute(p3+Pi.z-1.0);vec3 p32=permute(p3+Pi.z);vec3 p33=permute(p3+Pi.z+1.0);vec3 ox11=fract(p11*K)-Ko;vec3 oy11=mod7(floor(p11*K))*K-Ko;vec3 oz11=floor(p11*K2)*Kz-Kzo;vec3 ox12=fract(p12*K)-Ko;vec3 oy12=mod7(floor(p12*K))*K-Ko;vec3 oz12=floor(p12*K2)*Kz-Kzo;vec3 ox13=fract(p13*K)-Ko;vec3 oy13=mod7(floor(p13*K))*K-Ko;vec3 oz13=floor(p13*K2)*Kz-Kzo;vec3 ox21=fract(p21*K)-Ko;vec3 oy21=mod7(floor(p21*K))*K-Ko;vec3 oz21=floor(p21*K2)*Kz-Kzo;vec3 ox22=fract(p22*K)-Ko;vec3 oy22=mod7(floor(p22*K))*K-Ko;vec3 oz22=floor(p22*K2)*Kz-Kzo;vec3 ox23=fract(p23*K)-Ko;vec3 oy23=mod7(floor(p23*K))*K-Ko;vec3 oz23=floor(p23*K2)*Kz-Kzo;vec3 ox31=fract(p31*K)-Ko;vec3 oy31=mod7(floor(p31*K))*K-Ko;vec3 oz31=floor(p31*K2)*Kz-Kzo;vec3 ox32=fract(p32*K)-Ko;vec3 oy32=mod7(floor(p32*K))*K-Ko;vec3 oz32=floor(p32*K2)*Kz-Kzo;vec3 ox33=fract(p33*K)-Ko;vec3 oy33=mod7(floor(p33*K))*K-Ko;vec3 oz33=floor(p33*K2)*Kz-Kzo;vec3 dx11=Pfx+jitter*ox11;vec3 dy11=Pfy.x+jitter*oy11;vec3 dz11=Pfz.x+jitter*oz11;vec3 dx12=Pfx+jitter*ox12;vec3 dy12=Pfy.x+jitter*oy12;vec3 dz12=Pfz.y+jitter*oz12;vec3 dx13=Pfx+jitter*ox13;vec3 dy13=Pfy.x+jitter*oy13;vec3 dz13=Pfz.z+jitter*oz13;vec3 dx21=Pfx+jitter*ox21;vec3 dy21=Pfy.y+jitter*oy21;vec3 dz21=Pfz.x+jitter*oz21;vec3 dx22=Pfx+jitter*ox22;vec3 dy22=Pfy.y+jitter*oy22;vec3 dz22=Pfz.y+jitter*oz22;vec3 dx23=Pfx+jitter*ox23;vec3 dy23=Pfy.y+jitter*oy23;vec3 dz23=Pfz.z+jitter*oz23;vec3 dx31=Pfx+jitter*ox31;vec3 dy31=Pfy.z+jitter*oy31;vec3 dz31=Pfz.x+jitter*oz31;vec3 dx32=Pfx+jitter*ox32;vec3 dy32=Pfy.z+jitter*oy32;vec3 dz32=Pfz.y+jitter*oz32;vec3 dx33=Pfx+jitter*ox33;vec3 dy33=Pfy.z+jitter*oy33;vec3 dz33=Pfz.z+jitter*oz33;vec3 d11=dx11*dx11+dy11*dy11+dz11*dz11;vec3 d12=dx12*dx12+dy12*dy12+dz12*dz12;vec3 d13=dx13*dx13+dy13*dy13+dz13*dz13;vec3 d21=dx21*dx21+dy21*dy21+dz21*dz21;vec3 d22=dx22*dx22+dy22*dy22+dz22*dz22;vec3 d23=dx23*dx23+dy23*dy23+dz23*dz23;vec3 d31=dx31*dx31+dy31*dy31+dz31*dz31;vec3 d32=dx32*dx32+dy32*dy32+dz32*dz32;vec3 d33=dx33*dx33+dy33*dy33+dz33*dz33;vec3 d1a=min(d11,d12);d12=max(d11,d12);d11=min(d1a,d13);d13=max(d1a,d13);d12=min(d12,d13);vec3 d2a=min(d21,d22);d22=max(d21,d22);d21=min(d2a,d23);d23=max(d2a,d23);d22=min(d22,d23);vec3 d3a=min(d31,d32);d32=max(d31,d32);d31=min(d3a,d33);d33=max(d3a,d33);d32=min(d32,d33);vec3 da=min(d11,d21);d21=max(d11,d21);d11=min(da,d31);d31=max(da,d31);d11.xy=(d11.x<d11.y)? d11.xy : d11.yx;d11.xz=(d11.x<d11.z)? d11.xz : d11.zx;d12=min(d12,d21);d12=min(d12,d22);d12=min(d12,d31);d12=min(d12,d32);d11.yz=min(d11.yz,d12.xy);d11.y=min(d11.y,d12.z);d11.y=min(d11.y,d11.z);return sqrt(d11.xy);}"; // eslint-disable-line
3515
+ var noise_cellular_3D = "#define GLSLIFY 1\n// Cellular noise (\"Worley noise\") in 3D in GLSL.\n// Copyright (c) Stefan Gustavson 2011-04-19. All rights reserved.\n// This code is released under the conditions of the MIT license.\n// See LICENSE file for details.\n// https://github.com/stegu/webgl-noise\n\n// Cellular noise, returning F1 and F2 in a vec2.\n// 3x3x3 search region for good F2 everywhere, but a lot\n// slower than the 2x2x2 version.\n// The code below is a bit scary even to its author,\n// but it has at least half decent performance on a\n// modern GPU. In any case, it beats any software\n// implementation of Worley noise hands down.\n\nvec2 cellular( vec3 P ) {\n\n\tvec3 Pi = mod289( floor( P ) );\n \tvec3 Pf = fract( P ) - 0.5;\n\n\tvec3 Pfx = Pf.x + vec3( 1.0, 0.0, -1.0 );\n\tvec3 Pfy = Pf.y + vec3( 1.0, 0.0, -1.0 );\n\tvec3 Pfz = Pf.z + vec3( 1.0, 0.0, -1.0 );\n\n\tvec3 p = permute( Pi.x + vec3( -1.0, 0.0, 1.0 ) );\n\tvec3 p1 = permute( p + Pi.y - 1.0 );\n\tvec3 p2 = permute( p + Pi.y );\n\tvec3 p3 = permute( p + Pi.y + 1.0 );\n\n\tvec3 p11 = permute( p1 + Pi.z - 1.0 );\n\tvec3 p12 = permute( p1 + Pi.z );\n\tvec3 p13 = permute( p1 + Pi.z + 1.0 );\n\n\tvec3 p21 = permute( p2 + Pi.z - 1.0 );\n\tvec3 p22 = permute( p2 + Pi.z );\n\tvec3 p23 = permute( p2 + Pi.z + 1.0 );\n\n\tvec3 p31 = permute( p3 + Pi.z - 1.0 );\n\tvec3 p32 = permute( p3 + Pi.z );\n\tvec3 p33 = permute( p3 + Pi.z + 1.0 );\n\n\tvec3 ox11 = fract( p11 * K ) - Ko;\n\tvec3 oy11 = mod7( floor( p11 * K ) ) * K - Ko;\n\tvec3 oz11 = floor( p11 * K2 ) * Kz - Kzo; // p11 < 289 guaranteed\n\n\tvec3 ox12 = fract( p12 * K ) - Ko;\n\tvec3 oy12 = mod7( floor( p12 * K ) ) * K - Ko;\n\tvec3 oz12 = floor( p12 * K2 ) * Kz - Kzo;\n\n\tvec3 ox13 = fract( p13 * K ) - Ko;\n\tvec3 oy13 = mod7( floor( p13 * K ) ) * K - Ko;\n\tvec3 oz13 = floor( p13 * K2 ) * Kz - Kzo;\n\n\tvec3 ox21 = fract( p21 * K ) - Ko;\n\tvec3 oy21 = mod7( floor( p21 * K ) ) * K - Ko;\n\tvec3 oz21 = floor( p21 * K2 ) * Kz - Kzo;\n\n\tvec3 ox22 = fract( p22 * K ) - Ko;\n\tvec3 oy22 = mod7( floor( p22 * K ) ) * K - Ko;\n\tvec3 oz22 = floor( p22 * K2 ) * Kz - Kzo;\n\n\tvec3 ox23 = fract( p23 * K ) - Ko;\n\tvec3 oy23 = mod7( floor( p23 * K ) ) * K - Ko;\n\tvec3 oz23 = floor( p23 * K2 ) * Kz - Kzo;\n\n\tvec3 ox31 = fract( p31 * K ) - Ko;\n\tvec3 oy31 = mod7( floor( p31 * K ) ) * K - Ko;\n\tvec3 oz31 = floor( p31 * K2 ) * Kz - Kzo;\n\n\tvec3 ox32 = fract( p32 * K ) - Ko;\n\tvec3 oy32 = mod7( floor( p32 * K ) ) * K - Ko;\n\tvec3 oz32 = floor( p32 * K2 ) * Kz - Kzo;\n\n\tvec3 ox33 = fract( p33 * K ) - Ko;\n\tvec3 oy33 = mod7( floor( p33 * K ) ) * K - Ko;\n\tvec3 oz33 = floor( p33 * K2 ) * Kz - Kzo;\n\n\tvec3 dx11 = Pfx + jitter * ox11;\n\tvec3 dy11 = Pfy.x + jitter * oy11;\n\tvec3 dz11 = Pfz.x + jitter * oz11;\n\n\tvec3 dx12 = Pfx + jitter * ox12;\n\tvec3 dy12 = Pfy.x + jitter * oy12;\n\tvec3 dz12 = Pfz.y + jitter * oz12;\n\n\tvec3 dx13 = Pfx + jitter * ox13;\n\tvec3 dy13 = Pfy.x + jitter * oy13;\n\tvec3 dz13 = Pfz.z + jitter * oz13;\n\n\tvec3 dx21 = Pfx + jitter * ox21;\n\tvec3 dy21 = Pfy.y + jitter * oy21;\n\tvec3 dz21 = Pfz.x + jitter * oz21;\n\n\tvec3 dx22 = Pfx + jitter * ox22;\n\tvec3 dy22 = Pfy.y + jitter * oy22;\n\tvec3 dz22 = Pfz.y + jitter * oz22;\n\n\tvec3 dx23 = Pfx + jitter * ox23;\n\tvec3 dy23 = Pfy.y + jitter * oy23;\n\tvec3 dz23 = Pfz.z + jitter * oz23;\n\n\tvec3 dx31 = Pfx + jitter * ox31;\n\tvec3 dy31 = Pfy.z + jitter * oy31;\n\tvec3 dz31 = Pfz.x + jitter * oz31;\n\n\tvec3 dx32 = Pfx + jitter * ox32;\n\tvec3 dy32 = Pfy.z + jitter * oy32;\n\tvec3 dz32 = Pfz.y + jitter * oz32;\n\n\tvec3 dx33 = Pfx + jitter * ox33;\n\tvec3 dy33 = Pfy.z + jitter * oy33;\n\tvec3 dz33 = Pfz.z + jitter * oz33;\n\n\tvec3 d11 = dx11 * dx11 + dy11 * dy11 + dz11 * dz11;\n\tvec3 d12 = dx12 * dx12 + dy12 * dy12 + dz12 * dz12;\n\tvec3 d13 = dx13 * dx13 + dy13 * dy13 + dz13 * dz13;\n\tvec3 d21 = dx21 * dx21 + dy21 * dy21 + dz21 * dz21;\n\tvec3 d22 = dx22 * dx22 + dy22 * dy22 + dz22 * dz22;\n\tvec3 d23 = dx23 * dx23 + dy23 * dy23 + dz23 * dz23;\n\tvec3 d31 = dx31 * dx31 + dy31 * dy31 + dz31 * dz31;\n\tvec3 d32 = dx32 * dx32 + dy32 * dy32 + dz32 * dz32;\n\tvec3 d33 = dx33 * dx33 + dy33 * dy33 + dz33 * dz33;\n\n\t// Do it right and sort out both F1 and F2\n\tvec3 d1a = min( d11, d12 );\n\td12 = max( d11, d12 );\n\td11 = min( d1a, d13 ); // Smallest now not in d12 or d13\n\td13 = max( d1a, d13 );\n\td12 = min( d12, d13 ); // 2nd smallest now not in d13\n\tvec3 d2a = min( d21, d22 );\n\td22 = max( d21, d22 );\n\td21 = min( d2a, d23 ); // Smallest now not in d22 or d23\n\td23 = max( d2a, d23 );\n\td22 = min( d22, d23 ); // 2nd smallest now not in d23\n\tvec3 d3a = min( d31, d32 );\n\td32 = max( d31, d32 );\n\td31 = min( d3a, d33 ); // Smallest now not in d32 or d33\n\td33 = max( d3a, d33 );\n\td32 = min( d32, d33 ); // 2nd smallest now not in d33\n\tvec3 da = min( d11, d21 );\n\td21 = max( d11, d21 );\n\td11 = min( da, d31 ); // Smallest now in d11\n\td31 = max( da, d31 ); // 2nd smallest now not in d31\n\td11.xy = ( d11.x < d11.y ) ? d11.xy : d11.yx;\n\td11.xz = ( d11.x < d11.z ) ? d11.xz : d11.zx; // d11.x now smallest\n\td12 = min( d12, d21 ); // 2nd smallest now not in d21\n\td12 = min( d12, d22 ); // nor in d22\n\td12 = min( d12, d31 ); // nor in d31\n\td12 = min( d12, d32 ); // nor in d32\n\td11.yz = min( d11.yz, d12.xy ); // nor in d12.yz\n\td11.y = min( d11.y, d12.z ); // Only two more to go\n\td11.y = min( d11.y, d11.z ); // Done! (Phew! )\n\treturn sqrt( d11.xy ); // F1, F2\n\n}\n"; // eslint-disable-line
3516
3516
 
3517
- var noise_common = "#define GLSLIFY 1\nvec4 mod289(vec4 x){return x-floor(x*(1.0/289.0))*289.0;}vec3 mod289(vec3 x){return x-floor(x*(1.0/289.0))*289.0;}vec2 mod289(vec2 x){return x-floor(x*(1.0/289.0))*289.0;}float mod289(float x){return x-floor(x*(1.0/289.0))*289.0;}vec4 mod7(vec4 x){return x-floor(x*(1.0/7.0))*7.0;}vec3 mod7(vec3 x){return x-floor(x*(1.0/7.0))*7.0;}vec4 permute(vec4 x){return mod289((34.0*x+1.0)*x);}vec3 permute(vec3 x){return mod289((34.0*x+1.0)*x);}float permute(float x){return mod289(((x*34.0)+1.0)*x);}vec4 taylorInvSqrt(vec4 r){return 1.79284291400159-0.85373472095314*r;}float taylorInvSqrt(float r){return 1.79284291400159-0.85373472095314*r;}vec4 fade(vec4 t){return t*t*t*(t*(t*6.0-15.0)+10.0);}vec3 fade(vec3 t){return t*t*t*(t*(t*6.0-15.0)+10.0);}vec2 fade(vec2 t){return t*t*t*(t*(t*6.0-15.0)+10.0);}\n#define K 0.142857142857\n#define Ko 0.428571428571\n#define K2 0.020408163265306\n#define Kd2 0.0714285714285\n#define Kz 0.166666666667\n#define Kzo 0.416666666667\n#define jitter 1.0\n#define jitter1 0.8\n"; // eslint-disable-line
3517
+ var noise_common = "#define GLSLIFY 1\n// Modulo 289 without a division (only multiplications)\nvec4 mod289( vec4 x ) {\n\n return x - floor( x * ( 1.0 / 289.0 ) ) * 289.0;\n\n}\n\nvec3 mod289( vec3 x ) {\n\n return x - floor( x * ( 1.0 / 289.0 ) ) * 289.0;\n\n}\n\nvec2 mod289( vec2 x ) {\n\n return x - floor( x * ( 1.0 / 289.0 ) ) * 289.0;\n\n}\n\nfloat mod289( float x ) {\n\n return x - floor( x * ( 1.0 / 289.0 ) ) * 289.0;\n\n}\n\n// Modulo 7 without a division\nvec4 mod7( vec4 x ) {\n\n return x - floor( x * ( 1.0 / 7.0 ) ) * 7.0;\n\n}\n\nvec3 mod7( vec3 x ) {\n\n return x - floor( x * ( 1.0 / 7.0 ) ) * 7.0;\n\n}\n\n// Permutation polynomial: (34x^2 + x) mod 289\nvec4 permute( vec4 x ) {\n\n return mod289( ( 34.0 * x + 1.0 ) * x);\n\n}\n\nvec3 permute( vec3 x ) {\n\n return mod289( ( 34.0 * x + 1.0 ) * x );\n\n}\n\nfloat permute( float x ) {\n\n return mod289( ( ( x * 34.0 ) + 1.0 ) * x );\n\n}\n\nvec4 taylorInvSqrt( vec4 r ) {\n\n return 1.79284291400159 - 0.85373472095314 * r;\n\n}\n\nfloat taylorInvSqrt( float r ) {\n\n return 1.79284291400159 - 0.85373472095314 * r;\n\n}\n\nvec4 fade( vec4 t ) {\n\n return t * t * t * ( t * ( t * 6.0 - 15.0 ) + 10.0 );\n\n}\n\nvec3 fade( vec3 t ) {\n\n return t * t * t * ( t * ( t * 6.0 - 15.0 ) + 10.0 );\n\n}\n\nvec2 fade( vec2 t ) {\n\n return t * t * t * ( t * ( t * 6.0 - 15.0 ) + 10.0 );\n\n}\n\n#define K 0.142857142857 // 1/7\n#define Ko 0.428571428571 // 1/2-K/2\n#define K2 0.020408163265306 // 1/(7*7)\n#define Kd2 0.0714285714285 // K/2\n#define Kz 0.166666666667 // 1/6\n#define Kzo 0.416666666667 // 1/2-1/6*2\n#define jitter 1.0 // smaller jitter gives more regular pattern\n#define jitter1 0.8 // smaller jitter gives less errors in F1 F2\n"; // eslint-disable-line
3518
3518
 
3519
3519
  var noise_perlin = "#define GLSLIFY 1\n#include <noise_perlin_2D>\n#include <noise_perlin_3D>\n#include <noise_perlin_4D>\n"; // eslint-disable-line
3520
3520
 
3521
- var noise_perlin_2D = "#define GLSLIFY 1\nfloat perlin(vec2 P){vec4 Pi=floor(P.xyxy)+vec4(0.0,0.0,1.0,1.0);vec4 Pf=fract(P.xyxy)-vec4(0.0,0.0,1.0,1.0);Pi=mod289(Pi);vec4 ix=Pi.xzxz;vec4 iy=Pi.yyww;vec4 fx=Pf.xzxz;vec4 fy=Pf.yyww;vec4 i=permute(permute(ix)+iy);vec4 gx=fract(i*(1.0/41.0))*2.0-1.0;vec4 gy=abs(gx)-0.5;vec4 tx=floor(gx+0.5);gx=gx-tx;vec2 g00=vec2(gx.x,gy.x);vec2 g10=vec2(gx.y,gy.y);vec2 g01=vec2(gx.z,gy.z);vec2 g11=vec2(gx.w,gy.w);vec4 norm=taylorInvSqrt(vec4(dot(g00,g00),dot(g01,g01),dot(g10,g10),dot(g11,g11)));g00*=norm.x;g01*=norm.y;g10*=norm.z;g11*=norm.w;float n00=dot(g00,vec2(fx.x,fy.x));float n10=dot(g10,vec2(fx.y,fy.y));float n01=dot(g01,vec2(fx.z,fy.z));float n11=dot(g11,vec2(fx.w,fy.w));vec2 fade_xy=fade(Pf.xy);vec2 n_x=mix(vec2(n00,n01),vec2(n10,n11),fade_xy.x);float n_xy=mix(n_x.x,n_x.y,fade_xy.y);return 2.3*n_xy;}float perlin(vec2 P,vec2 rep){vec4 Pi=floor(P.xyxy)+vec4(0.0,0.0,1.0,1.0);vec4 Pf=fract(P.xyxy)-vec4(0.0,0.0,1.0,1.0);Pi=mod(Pi,rep.xyxy);Pi=mod289(Pi);vec4 ix=Pi.xzxz;vec4 iy=Pi.yyww;vec4 fx=Pf.xzxz;vec4 fy=Pf.yyww;vec4 i=permute(permute(ix)+iy);vec4 gx=fract(i*(1.0/41.0))*2.0-1.0;vec4 gy=abs(gx)-0.5;vec4 tx=floor(gx+0.5);gx=gx-tx;vec2 g00=vec2(gx.x,gy.x);vec2 g10=vec2(gx.y,gy.y);vec2 g01=vec2(gx.z,gy.z);vec2 g11=vec2(gx.w,gy.w);vec4 norm=taylorInvSqrt(vec4(dot(g00,g00),dot(g01,g01),dot(g10,g10),dot(g11,g11)));g00*=norm.x;g01*=norm.y;g10*=norm.z;g11*=norm.w;float n00=dot(g00,vec2(fx.x,fy.x));float n10=dot(g10,vec2(fx.y,fy.y));float n01=dot(g01,vec2(fx.z,fy.z));float n11=dot(g11,vec2(fx.w,fy.w));vec2 fade_xy=fade(Pf.xy);vec2 n_x=mix(vec2(n00,n01),vec2(n10,n11),fade_xy.x);float n_xy=mix(n_x.x,n_x.y,fade_xy.y);return 2.3*n_xy;}"; // eslint-disable-line
3521
+ var noise_perlin_2D = "#define GLSLIFY 1\n//\n// GLSL textureless classic 2D noise \"cnoise\",\n// with an RSL-style periodic variant \"pnoise\".\n// Author: Stefan Gustavson (stefan.gustavson@liu.se)\n// Version: 2011-08-22\n//\n// Many thanks to Ian McEwan of Ashima Arts for the\n// ideas for permutation and gradient selection.\n//\n// Copyright (c) 2011 Stefan Gustavson. All rights reserved.\n// Distributed under the MIT license. See LICENSE file.\n// https://github.com/stegu/webgl-noise\n//\n\n// Classic Perlin noise\nfloat perlin( vec2 P ) {\n\n vec4 Pi = floor(P.xyxy) + vec4(0.0, 0.0, 1.0, 1.0);\n vec4 Pf = fract(P.xyxy) - vec4(0.0, 0.0, 1.0, 1.0);\n Pi = mod289(Pi); // To avoid truncation effects in permutation\n vec4 ix = Pi.xzxz;\n vec4 iy = Pi.yyww;\n vec4 fx = Pf.xzxz;\n vec4 fy = Pf.yyww;\n\n vec4 i = permute(permute(ix) + iy);\n\n vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;\n vec4 gy = abs(gx) - 0.5 ;\n vec4 tx = floor(gx + 0.5);\n gx = gx - tx;\n\n vec2 g00 = vec2(gx.x,gy.x);\n vec2 g10 = vec2(gx.y,gy.y);\n vec2 g01 = vec2(gx.z,gy.z);\n vec2 g11 = vec2(gx.w,gy.w);\n\n vec4 norm = taylorInvSqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));\n g00 *= norm.x;\n g01 *= norm.y;\n g10 *= norm.z;\n g11 *= norm.w;\n\n float n00 = dot(g00, vec2(fx.x, fy.x));\n float n10 = dot(g10, vec2(fx.y, fy.y));\n float n01 = dot(g01, vec2(fx.z, fy.z));\n float n11 = dot(g11, vec2(fx.w, fy.w));\n\n vec2 fade_xy = fade(Pf.xy);\n vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);\n float n_xy = mix(n_x.x, n_x.y, fade_xy.y);\n return 2.3 * n_xy;\n\n}\n\n// Classic Perlin noise, periodic variant\nfloat perlin( vec2 P, vec2 rep ) {\n\n vec4 Pi = floor(P.xyxy) + vec4(0.0, 0.0, 1.0, 1.0);\n vec4 Pf = fract(P.xyxy) - vec4(0.0, 0.0, 1.0, 1.0);\n Pi = mod(Pi, rep.xyxy); // To create noise with explicit period\n Pi = mod289(Pi); // To avoid truncation effects in permutation\n vec4 ix = Pi.xzxz;\n vec4 iy = Pi.yyww;\n vec4 fx = Pf.xzxz;\n vec4 fy = Pf.yyww;\n\n vec4 i = permute(permute(ix) + iy);\n\n vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;\n vec4 gy = abs(gx) - 0.5 ;\n vec4 tx = floor(gx + 0.5);\n gx = gx - tx;\n\n vec2 g00 = vec2(gx.x,gy.x);\n vec2 g10 = vec2(gx.y,gy.y);\n vec2 g01 = vec2(gx.z,gy.z);\n vec2 g11 = vec2(gx.w,gy.w);\n\n vec4 norm = taylorInvSqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));\n g00 *= norm.x;\n g01 *= norm.y;\n g10 *= norm.z;\n g11 *= norm.w;\n\n float n00 = dot(g00, vec2(fx.x, fy.x));\n float n10 = dot(g10, vec2(fx.y, fy.y));\n float n01 = dot(g01, vec2(fx.z, fy.z));\n float n11 = dot(g11, vec2(fx.w, fy.w));\n\n vec2 fade_xy = fade(Pf.xy);\n vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);\n float n_xy = mix(n_x.x, n_x.y, fade_xy.y);\n return 2.3 * n_xy;\n\n}\n"; // eslint-disable-line
3522
3522
 
3523
- var noise_perlin_3D = "#define GLSLIFY 1\nfloat perlin(vec3 P){vec3 Pi0=floor(P);vec3 Pi1=Pi0+vec3(1.0);Pi0=mod289(Pi0);Pi1=mod289(Pi1);vec3 Pf0=fract(P);vec3 Pf1=Pf0-vec3(1.0);vec4 ix=vec4(Pi0.x,Pi1.x,Pi0.x,Pi1.x);vec4 iy=vec4(Pi0.yy,Pi1.yy);vec4 iz0=Pi0.zzzz;vec4 iz1=Pi1.zzzz;vec4 ixy=permute(permute(ix)+iy);vec4 ixy0=permute(ixy+iz0);vec4 ixy1=permute(ixy+iz1);vec4 gx0=ixy0*(1.0/7.0);vec4 gy0=fract(floor(gx0)*(1.0/7.0))-0.5;gx0=fract(gx0);vec4 gz0=vec4(0.5)-abs(gx0)-abs(gy0);vec4 sz0=step(gz0,vec4(0.0));gx0-=sz0*(step(0.0,gx0)-0.5);gy0-=sz0*(step(0.0,gy0)-0.5);vec4 gx1=ixy1*(1.0/7.0);vec4 gy1=fract(floor(gx1)*(1.0/7.0))-0.5;gx1=fract(gx1);vec4 gz1=vec4(0.5)-abs(gx1)-abs(gy1);vec4 sz1=step(gz1,vec4(0.0));gx1-=sz1*(step(0.0,gx1)-0.5);gy1-=sz1*(step(0.0,gy1)-0.5);vec3 g000=vec3(gx0.x,gy0.x,gz0.x);vec3 g100=vec3(gx0.y,gy0.y,gz0.y);vec3 g010=vec3(gx0.z,gy0.z,gz0.z);vec3 g110=vec3(gx0.w,gy0.w,gz0.w);vec3 g001=vec3(gx1.x,gy1.x,gz1.x);vec3 g101=vec3(gx1.y,gy1.y,gz1.y);vec3 g011=vec3(gx1.z,gy1.z,gz1.z);vec3 g111=vec3(gx1.w,gy1.w,gz1.w);vec4 norm0=taylorInvSqrt(vec4(dot(g000,g000),dot(g010,g010),dot(g100,g100),dot(g110,g110)));g000*=norm0.x;g010*=norm0.y;g100*=norm0.z;g110*=norm0.w;vec4 norm1=taylorInvSqrt(vec4(dot(g001,g001),dot(g011,g011),dot(g101,g101),dot(g111,g111)));g001*=norm1.x;g011*=norm1.y;g101*=norm1.z;g111*=norm1.w;float n000=dot(g000,Pf0);float n100=dot(g100,vec3(Pf1.x,Pf0.yz));float n010=dot(g010,vec3(Pf0.x,Pf1.y,Pf0.z));float n110=dot(g110,vec3(Pf1.xy,Pf0.z));float n001=dot(g001,vec3(Pf0.xy,Pf1.z));float n101=dot(g101,vec3(Pf1.x,Pf0.y,Pf1.z));float n011=dot(g011,vec3(Pf0.x,Pf1.yz));float n111=dot(g111,Pf1);vec3 fade_xyz=fade(Pf0);vec4 n_z=mix(vec4(n000,n100,n010,n110),vec4(n001,n101,n011,n111),fade_xyz.z);vec2 n_yz=mix(n_z.xy,n_z.zw,fade_xyz.y);float n_xyz=mix(n_yz.x,n_yz.y,fade_xyz.x);return 2.2*n_xyz;}float perlin(vec3 P,vec3 rep){vec3 Pi0=mod(floor(P),rep);vec3 Pi1=mod(Pi0+vec3(1.0),rep);Pi0=mod289(Pi0);Pi1=mod289(Pi1);vec3 Pf0=fract(P);vec3 Pf1=Pf0-vec3(1.0);vec4 ix=vec4(Pi0.x,Pi1.x,Pi0.x,Pi1.x);vec4 iy=vec4(Pi0.yy,Pi1.yy);vec4 iz0=Pi0.zzzz;vec4 iz1=Pi1.zzzz;vec4 ixy=permute(permute(ix)+iy);vec4 ixy0=permute(ixy+iz0);vec4 ixy1=permute(ixy+iz1);vec4 gx0=ixy0*(1.0/7.0);vec4 gy0=fract(floor(gx0)*(1.0/7.0))-0.5;gx0=fract(gx0);vec4 gz0=vec4(0.5)-abs(gx0)-abs(gy0);vec4 sz0=step(gz0,vec4(0.0));gx0-=sz0*(step(0.0,gx0)-0.5);gy0-=sz0*(step(0.0,gy0)-0.5);vec4 gx1=ixy1*(1.0/7.0);vec4 gy1=fract(floor(gx1)*(1.0/7.0))-0.5;gx1=fract(gx1);vec4 gz1=vec4(0.5)-abs(gx1)-abs(gy1);vec4 sz1=step(gz1,vec4(0.0));gx1-=sz1*(step(0.0,gx1)-0.5);gy1-=sz1*(step(0.0,gy1)-0.5);vec3 g000=vec3(gx0.x,gy0.x,gz0.x);vec3 g100=vec3(gx0.y,gy0.y,gz0.y);vec3 g010=vec3(gx0.z,gy0.z,gz0.z);vec3 g110=vec3(gx0.w,gy0.w,gz0.w);vec3 g001=vec3(gx1.x,gy1.x,gz1.x);vec3 g101=vec3(gx1.y,gy1.y,gz1.y);vec3 g011=vec3(gx1.z,gy1.z,gz1.z);vec3 g111=vec3(gx1.w,gy1.w,gz1.w);vec4 norm0=taylorInvSqrt(vec4(dot(g000,g000),dot(g010,g010),dot(g100,g100),dot(g110,g110)));g000*=norm0.x;g010*=norm0.y;g100*=norm0.z;g110*=norm0.w;vec4 norm1=taylorInvSqrt(vec4(dot(g001,g001),dot(g011,g011),dot(g101,g101),dot(g111,g111)));g001*=norm1.x;g011*=norm1.y;g101*=norm1.z;g111*=norm1.w;float n000=dot(g000,Pf0);float n100=dot(g100,vec3(Pf1.x,Pf0.yz));float n010=dot(g010,vec3(Pf0.x,Pf1.y,Pf0.z));float n110=dot(g110,vec3(Pf1.xy,Pf0.z));float n001=dot(g001,vec3(Pf0.xy,Pf1.z));float n101=dot(g101,vec3(Pf1.x,Pf0.y,Pf1.z));float n011=dot(g011,vec3(Pf0.x,Pf1.yz));float n111=dot(g111,Pf1);vec3 fade_xyz=fade(Pf0);vec4 n_z=mix(vec4(n000,n100,n010,n110),vec4(n001,n101,n011,n111),fade_xyz.z);vec2 n_yz=mix(n_z.xy,n_z.zw,fade_xyz.y);float n_xyz=mix(n_yz.x,n_yz.y,fade_xyz.x);return 2.2*n_xyz;}"; // eslint-disable-line
3523
+ var noise_perlin_3D = "#define GLSLIFY 1\n//\n// GLSL textureless classic 3D noise \"cnoise\",\n// with an RSL-style periodic variant \"pnoise\".\n// Author: Stefan Gustavson (stefan.gustavson@liu.se)\n// Version: 2011-10-11\n//\n// Many thanks to Ian McEwan of Ashima Arts for the\n// ideas for permutation and gradient selection.\n//\n// Copyright (c) 2011 Stefan Gustavson. All rights reserved.\n// Distributed under the MIT license. See LICENSE file.\n// https://github.com/stegu/webgl-noise\n//\n\n// Classic Perlin noise\nfloat perlin( vec3 P ) {\n\n vec3 Pi0 = floor(P); // Integer part for indexing\n vec3 Pi1 = Pi0 + vec3(1.0); // Integer part + 1\n Pi0 = mod289(Pi0);\n Pi1 = mod289(Pi1);\n vec3 Pf0 = fract(P); // Fractional part for interpolation\n vec3 Pf1 = Pf0 - vec3(1.0); // Fractional part - 1.0\n vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);\n vec4 iy = vec4(Pi0.yy, Pi1.yy);\n vec4 iz0 = Pi0.zzzz;\n vec4 iz1 = Pi1.zzzz;\n\n vec4 ixy = permute(permute(ix) + iy);\n vec4 ixy0 = permute(ixy + iz0);\n vec4 ixy1 = permute(ixy + iz1);\n\n vec4 gx0 = ixy0 * (1.0 / 7.0);\n vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;\n gx0 = fract(gx0);\n vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);\n vec4 sz0 = step(gz0, vec4(0.0));\n gx0 -= sz0 * (step(0.0, gx0) - 0.5);\n gy0 -= sz0 * (step(0.0, gy0) - 0.5);\n\n vec4 gx1 = ixy1 * (1.0 / 7.0);\n vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;\n gx1 = fract(gx1);\n vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);\n vec4 sz1 = step(gz1, vec4(0.0));\n gx1 -= sz1 * (step(0.0, gx1) - 0.5);\n gy1 -= sz1 * (step(0.0, gy1) - 0.5);\n\n vec3 g000 = vec3(gx0.x,gy0.x,gz0.x);\n vec3 g100 = vec3(gx0.y,gy0.y,gz0.y);\n vec3 g010 = vec3(gx0.z,gy0.z,gz0.z);\n vec3 g110 = vec3(gx0.w,gy0.w,gz0.w);\n vec3 g001 = vec3(gx1.x,gy1.x,gz1.x);\n vec3 g101 = vec3(gx1.y,gy1.y,gz1.y);\n vec3 g011 = vec3(gx1.z,gy1.z,gz1.z);\n vec3 g111 = vec3(gx1.w,gy1.w,gz1.w);\n\n vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));\n g000 *= norm0.x;\n g010 *= norm0.y;\n g100 *= norm0.z;\n g110 *= norm0.w;\n vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));\n g001 *= norm1.x;\n g011 *= norm1.y;\n g101 *= norm1.z;\n g111 *= norm1.w;\n\n float n000 = dot(g000, Pf0);\n float n100 = dot(g100, vec3(Pf1.x, Pf0.yz));\n float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z));\n float n110 = dot(g110, vec3(Pf1.xy, Pf0.z));\n float n001 = dot(g001, vec3(Pf0.xy, Pf1.z));\n float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z));\n float n011 = dot(g011, vec3(Pf0.x, Pf1.yz));\n float n111 = dot(g111, Pf1);\n\n vec3 fade_xyz = fade(Pf0);\n vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z);\n vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);\n float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);\n return 2.2 * n_xyz;\n\n}\n\n// Classic Perlin noise, periodic variant\nfloat perlin( vec3 P, vec3 rep ) {\n\n vec3 Pi0 = mod(floor(P), rep); // Integer part, modulo period\n vec3 Pi1 = mod(Pi0 + vec3(1.0), rep); // Integer part + 1, mod period\n Pi0 = mod289(Pi0);\n Pi1 = mod289(Pi1);\n vec3 Pf0 = fract(P); // Fractional part for interpolation\n vec3 Pf1 = Pf0 - vec3(1.0); // Fractional part - 1.0\n vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);\n vec4 iy = vec4(Pi0.yy, Pi1.yy);\n vec4 iz0 = Pi0.zzzz;\n vec4 iz1 = Pi1.zzzz;\n\n vec4 ixy = permute(permute(ix) + iy);\n vec4 ixy0 = permute(ixy + iz0);\n vec4 ixy1 = permute(ixy + iz1);\n\n vec4 gx0 = ixy0 * (1.0 / 7.0);\n vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;\n gx0 = fract(gx0);\n vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);\n vec4 sz0 = step(gz0, vec4(0.0));\n gx0 -= sz0 * (step(0.0, gx0) - 0.5);\n gy0 -= sz0 * (step(0.0, gy0) - 0.5);\n\n vec4 gx1 = ixy1 * (1.0 / 7.0);\n vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;\n gx1 = fract(gx1);\n vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);\n vec4 sz1 = step(gz1, vec4(0.0));\n gx1 -= sz1 * (step(0.0, gx1) - 0.5);\n gy1 -= sz1 * (step(0.0, gy1) - 0.5);\n\n vec3 g000 = vec3(gx0.x,gy0.x,gz0.x);\n vec3 g100 = vec3(gx0.y,gy0.y,gz0.y);\n vec3 g010 = vec3(gx0.z,gy0.z,gz0.z);\n vec3 g110 = vec3(gx0.w,gy0.w,gz0.w);\n vec3 g001 = vec3(gx1.x,gy1.x,gz1.x);\n vec3 g101 = vec3(gx1.y,gy1.y,gz1.y);\n vec3 g011 = vec3(gx1.z,gy1.z,gz1.z);\n vec3 g111 = vec3(gx1.w,gy1.w,gz1.w);\n\n vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));\n g000 *= norm0.x;\n g010 *= norm0.y;\n g100 *= norm0.z;\n g110 *= norm0.w;\n vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));\n g001 *= norm1.x;\n g011 *= norm1.y;\n g101 *= norm1.z;\n g111 *= norm1.w;\n\n float n000 = dot(g000, Pf0);\n float n100 = dot(g100, vec3(Pf1.x, Pf0.yz));\n float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z));\n float n110 = dot(g110, vec3(Pf1.xy, Pf0.z));\n float n001 = dot(g001, vec3(Pf0.xy, Pf1.z));\n float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z));\n float n011 = dot(g011, vec3(Pf0.x, Pf1.yz));\n float n111 = dot(g111, Pf1);\n\n vec3 fade_xyz = fade(Pf0);\n vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z);\n vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);\n float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);\n return 2.2 * n_xyz;\n\n}\n"; // eslint-disable-line
3524
3524
 
3525
- var noise_perlin_4D = "#define GLSLIFY 1\nfloat perlin(vec4 P){vec4 Pi0=floor(P);vec4 Pi1=Pi0+1.0;Pi0=mod289(Pi0);Pi1=mod289(Pi1);vec4 Pf0=fract(P);vec4 Pf1=Pf0-1.0;vec4 ix=vec4(Pi0.x,Pi1.x,Pi0.x,Pi1.x);vec4 iy=vec4(Pi0.yy,Pi1.yy);vec4 iz0=vec4(Pi0.zzzz);vec4 iz1=vec4(Pi1.zzzz);vec4 iw0=vec4(Pi0.wwww);vec4 iw1=vec4(Pi1.wwww);vec4 ixy=permute(permute(ix)+iy);vec4 ixy0=permute(ixy+iz0);vec4 ixy1=permute(ixy+iz1);vec4 ixy00=permute(ixy0+iw0);vec4 ixy01=permute(ixy0+iw1);vec4 ixy10=permute(ixy1+iw0);vec4 ixy11=permute(ixy1+iw1);vec4 gx00=ixy00*(1.0/7.0);vec4 gy00=floor(gx00)*(1.0/7.0);vec4 gz00=floor(gy00)*(1.0/6.0);gx00=fract(gx00)-0.5;gy00=fract(gy00)-0.5;gz00=fract(gz00)-0.5;vec4 gw00=vec4(0.75)-abs(gx00)-abs(gy00)-abs(gz00);vec4 sw00=step(gw00,vec4(0.0));gx00-=sw00*(step(0.0,gx00)-0.5);gy00-=sw00*(step(0.0,gy00)-0.5);vec4 gx01=ixy01*(1.0/7.0);vec4 gy01=floor(gx01)*(1.0/7.0);vec4 gz01=floor(gy01)*(1.0/6.0);gx01=fract(gx01)-0.5;gy01=fract(gy01)-0.5;gz01=fract(gz01)-0.5;vec4 gw01=vec4(0.75)-abs(gx01)-abs(gy01)-abs(gz01);vec4 sw01=step(gw01,vec4(0.0));gx01-=sw01*(step(0.0,gx01)-0.5);gy01-=sw01*(step(0.0,gy01)-0.5);vec4 gx10=ixy10*(1.0/7.0);vec4 gy10=floor(gx10)*(1.0/7.0);vec4 gz10=floor(gy10)*(1.0/6.0);gx10=fract(gx10)-0.5;gy10=fract(gy10)-0.5;gz10=fract(gz10)-0.5;vec4 gw10=vec4(0.75)-abs(gx10)-abs(gy10)-abs(gz10);vec4 sw10=step(gw10,vec4(0.0));gx10-=sw10*(step(0.0,gx10)-0.5);gy10-=sw10*(step(0.0,gy10)-0.5);vec4 gx11=ixy11*(1.0/7.0);vec4 gy11=floor(gx11)*(1.0/7.0);vec4 gz11=floor(gy11)*(1.0/6.0);gx11=fract(gx11)-0.5;gy11=fract(gy11)-0.5;gz11=fract(gz11)-0.5;vec4 gw11=vec4(0.75)-abs(gx11)-abs(gy11)-abs(gz11);vec4 sw11=step(gw11,vec4(0.0));gx11-=sw11*(step(0.0,gx11)-0.5);gy11-=sw11*(step(0.0,gy11)-0.5);vec4 g0000=vec4(gx00.x,gy00.x,gz00.x,gw00.x);vec4 g1000=vec4(gx00.y,gy00.y,gz00.y,gw00.y);vec4 g0100=vec4(gx00.z,gy00.z,gz00.z,gw00.z);vec4 g1100=vec4(gx00.w,gy00.w,gz00.w,gw00.w);vec4 g0010=vec4(gx10.x,gy10.x,gz10.x,gw10.x);vec4 g1010=vec4(gx10.y,gy10.y,gz10.y,gw10.y);vec4 g0110=vec4(gx10.z,gy10.z,gz10.z,gw10.z);vec4 g1110=vec4(gx10.w,gy10.w,gz10.w,gw10.w);vec4 g0001=vec4(gx01.x,gy01.x,gz01.x,gw01.x);vec4 g1001=vec4(gx01.y,gy01.y,gz01.y,gw01.y);vec4 g0101=vec4(gx01.z,gy01.z,gz01.z,gw01.z);vec4 g1101=vec4(gx01.w,gy01.w,gz01.w,gw01.w);vec4 g0011=vec4(gx11.x,gy11.x,gz11.x,gw11.x);vec4 g1011=vec4(gx11.y,gy11.y,gz11.y,gw11.y);vec4 g0111=vec4(gx11.z,gy11.z,gz11.z,gw11.z);vec4 g1111=vec4(gx11.w,gy11.w,gz11.w,gw11.w);vec4 norm00=taylorInvSqrt(vec4(dot(g0000,g0000),dot(g0100,g0100),dot(g1000,g1000),dot(g1100,g1100)));g0000*=norm00.x;g0100*=norm00.y;g1000*=norm00.z;g1100*=norm00.w;vec4 norm01=taylorInvSqrt(vec4(dot(g0001,g0001),dot(g0101,g0101),dot(g1001,g1001),dot(g1101,g1101)));g0001*=norm01.x;g0101*=norm01.y;g1001*=norm01.z;g1101*=norm01.w;vec4 norm10=taylorInvSqrt(vec4(dot(g0010,g0010),dot(g0110,g0110),dot(g1010,g1010),dot(g1110,g1110)));g0010*=norm10.x;g0110*=norm10.y;g1010*=norm10.z;g1110*=norm10.w;vec4 norm11=taylorInvSqrt(vec4(dot(g0011,g0011),dot(g0111,g0111),dot(g1011,g1011),dot(g1111,g1111)));g0011*=norm11.x;g0111*=norm11.y;g1011*=norm11.z;g1111*=norm11.w;float n0000=dot(g0000,Pf0);float n1000=dot(g1000,vec4(Pf1.x,Pf0.yzw));float n0100=dot(g0100,vec4(Pf0.x,Pf1.y,Pf0.zw));float n1100=dot(g1100,vec4(Pf1.xy,Pf0.zw));float n0010=dot(g0010,vec4(Pf0.xy,Pf1.z,Pf0.w));float n1010=dot(g1010,vec4(Pf1.x,Pf0.y,Pf1.z,Pf0.w));float n0110=dot(g0110,vec4(Pf0.x,Pf1.yz,Pf0.w));float n1110=dot(g1110,vec4(Pf1.xyz,Pf0.w));float n0001=dot(g0001,vec4(Pf0.xyz,Pf1.w));float n1001=dot(g1001,vec4(Pf1.x,Pf0.yz,Pf1.w));float n0101=dot(g0101,vec4(Pf0.x,Pf1.y,Pf0.z,Pf1.w));float n1101=dot(g1101,vec4(Pf1.xy,Pf0.z,Pf1.w));float n0011=dot(g0011,vec4(Pf0.xy,Pf1.zw));float n1011=dot(g1011,vec4(Pf1.x,Pf0.y,Pf1.zw));float n0111=dot(g0111,vec4(Pf0.x,Pf1.yzw));float n1111=dot(g1111,Pf1);vec4 fade_xyzw=fade(Pf0);vec4 n_0w=mix(vec4(n0000,n1000,n0100,n1100),vec4(n0001,n1001,n0101,n1101),fade_xyzw.w);vec4 n_1w=mix(vec4(n0010,n1010,n0110,n1110),vec4(n0011,n1011,n0111,n1111),fade_xyzw.w);vec4 n_zw=mix(n_0w,n_1w,fade_xyzw.z);vec2 n_yzw=mix(n_zw.xy,n_zw.zw,fade_xyzw.y);float n_xyzw=mix(n_yzw.x,n_yzw.y,fade_xyzw.x);return 2.2*n_xyzw;}float perlin(vec4 P,vec4 rep){vec4 Pi0=mod(floor(P),rep);vec4 Pi1=mod(Pi0+1.0,rep);Pi0=mod289(Pi0);Pi1=mod289(Pi1);vec4 Pf0=fract(P);vec4 Pf1=Pf0-1.0;vec4 ix=vec4(Pi0.x,Pi1.x,Pi0.x,Pi1.x);vec4 iy=vec4(Pi0.yy,Pi1.yy);vec4 iz0=vec4(Pi0.zzzz);vec4 iz1=vec4(Pi1.zzzz);vec4 iw0=vec4(Pi0.wwww);vec4 iw1=vec4(Pi1.wwww);vec4 ixy=permute(permute(ix)+iy);vec4 ixy0=permute(ixy+iz0);vec4 ixy1=permute(ixy+iz1);vec4 ixy00=permute(ixy0+iw0);vec4 ixy01=permute(ixy0+iw1);vec4 ixy10=permute(ixy1+iw0);vec4 ixy11=permute(ixy1+iw1);vec4 gx00=ixy00*(1.0/7.0);vec4 gy00=floor(gx00)*(1.0/7.0);vec4 gz00=floor(gy00)*(1.0/6.0);gx00=fract(gx00)-0.5;gy00=fract(gy00)-0.5;gz00=fract(gz00)-0.5;vec4 gw00=vec4(0.75)-abs(gx00)-abs(gy00)-abs(gz00);vec4 sw00=step(gw00,vec4(0.0));gx00-=sw00*(step(0.0,gx00)-0.5);gy00-=sw00*(step(0.0,gy00)-0.5);vec4 gx01=ixy01*(1.0/7.0);vec4 gy01=floor(gx01)*(1.0/7.0);vec4 gz01=floor(gy01)*(1.0/6.0);gx01=fract(gx01)-0.5;gy01=fract(gy01)-0.5;gz01=fract(gz01)-0.5;vec4 gw01=vec4(0.75)-abs(gx01)-abs(gy01)-abs(gz01);vec4 sw01=step(gw01,vec4(0.0));gx01-=sw01*(step(0.0,gx01)-0.5);gy01-=sw01*(step(0.0,gy01)-0.5);vec4 gx10=ixy10*(1.0/7.0);vec4 gy10=floor(gx10)*(1.0/7.0);vec4 gz10=floor(gy10)*(1.0/6.0);gx10=fract(gx10)-0.5;gy10=fract(gy10)-0.5;gz10=fract(gz10)-0.5;vec4 gw10=vec4(0.75)-abs(gx10)-abs(gy10)-abs(gz10);vec4 sw10=step(gw10,vec4(0.0));gx10-=sw10*(step(0.0,gx10)-0.5);gy10-=sw10*(step(0.0,gy10)-0.5);vec4 gx11=ixy11*(1.0/7.0);vec4 gy11=floor(gx11)*(1.0/7.0);vec4 gz11=floor(gy11)*(1.0/6.0);gx11=fract(gx11)-0.5;gy11=fract(gy11)-0.5;gz11=fract(gz11)-0.5;vec4 gw11=vec4(0.75)-abs(gx11)-abs(gy11)-abs(gz11);vec4 sw11=step(gw11,vec4(0.0));gx11-=sw11*(step(0.0,gx11)-0.5);gy11-=sw11*(step(0.0,gy11)-0.5);vec4 g0000=vec4(gx00.x,gy00.x,gz00.x,gw00.x);vec4 g1000=vec4(gx00.y,gy00.y,gz00.y,gw00.y);vec4 g0100=vec4(gx00.z,gy00.z,gz00.z,gw00.z);vec4 g1100=vec4(gx00.w,gy00.w,gz00.w,gw00.w);vec4 g0010=vec4(gx10.x,gy10.x,gz10.x,gw10.x);vec4 g1010=vec4(gx10.y,gy10.y,gz10.y,gw10.y);vec4 g0110=vec4(gx10.z,gy10.z,gz10.z,gw10.z);vec4 g1110=vec4(gx10.w,gy10.w,gz10.w,gw10.w);vec4 g0001=vec4(gx01.x,gy01.x,gz01.x,gw01.x);vec4 g1001=vec4(gx01.y,gy01.y,gz01.y,gw01.y);vec4 g0101=vec4(gx01.z,gy01.z,gz01.z,gw01.z);vec4 g1101=vec4(gx01.w,gy01.w,gz01.w,gw01.w);vec4 g0011=vec4(gx11.x,gy11.x,gz11.x,gw11.x);vec4 g1011=vec4(gx11.y,gy11.y,gz11.y,gw11.y);vec4 g0111=vec4(gx11.z,gy11.z,gz11.z,gw11.z);vec4 g1111=vec4(gx11.w,gy11.w,gz11.w,gw11.w);vec4 norm00=taylorInvSqrt(vec4(dot(g0000,g0000),dot(g0100,g0100),dot(g1000,g1000),dot(g1100,g1100)));g0000*=norm00.x;g0100*=norm00.y;g1000*=norm00.z;g1100*=norm00.w;vec4 norm01=taylorInvSqrt(vec4(dot(g0001,g0001),dot(g0101,g0101),dot(g1001,g1001),dot(g1101,g1101)));g0001*=norm01.x;g0101*=norm01.y;g1001*=norm01.z;g1101*=norm01.w;vec4 norm10=taylorInvSqrt(vec4(dot(g0010,g0010),dot(g0110,g0110),dot(g1010,g1010),dot(g1110,g1110)));g0010*=norm10.x;g0110*=norm10.y;g1010*=norm10.z;g1110*=norm10.w;vec4 norm11=taylorInvSqrt(vec4(dot(g0011,g0011),dot(g0111,g0111),dot(g1011,g1011),dot(g1111,g1111)));g0011*=norm11.x;g0111*=norm11.y;g1011*=norm11.z;g1111*=norm11.w;float n0000=dot(g0000,Pf0);float n1000=dot(g1000,vec4(Pf1.x,Pf0.yzw));float n0100=dot(g0100,vec4(Pf0.x,Pf1.y,Pf0.zw));float n1100=dot(g1100,vec4(Pf1.xy,Pf0.zw));float n0010=dot(g0010,vec4(Pf0.xy,Pf1.z,Pf0.w));float n1010=dot(g1010,vec4(Pf1.x,Pf0.y,Pf1.z,Pf0.w));float n0110=dot(g0110,vec4(Pf0.x,Pf1.yz,Pf0.w));float n1110=dot(g1110,vec4(Pf1.xyz,Pf0.w));float n0001=dot(g0001,vec4(Pf0.xyz,Pf1.w));float n1001=dot(g1001,vec4(Pf1.x,Pf0.yz,Pf1.w));float n0101=dot(g0101,vec4(Pf0.x,Pf1.y,Pf0.z,Pf1.w));float n1101=dot(g1101,vec4(Pf1.xy,Pf0.z,Pf1.w));float n0011=dot(g0011,vec4(Pf0.xy,Pf1.zw));float n1011=dot(g1011,vec4(Pf1.x,Pf0.y,Pf1.zw));float n0111=dot(g0111,vec4(Pf0.x,Pf1.yzw));float n1111=dot(g1111,Pf1);vec4 fade_xyzw=fade(Pf0);vec4 n_0w=mix(vec4(n0000,n1000,n0100,n1100),vec4(n0001,n1001,n0101,n1101),fade_xyzw.w);vec4 n_1w=mix(vec4(n0010,n1010,n0110,n1110),vec4(n0011,n1011,n0111,n1111),fade_xyzw.w);vec4 n_zw=mix(n_0w,n_1w,fade_xyzw.z);vec2 n_yzw=mix(n_zw.xy,n_zw.zw,fade_xyzw.y);float n_xyzw=mix(n_yzw.x,n_yzw.y,fade_xyzw.x);return 2.2*n_xyzw;}"; // eslint-disable-line
3525
+ var noise_perlin_4D = "#define GLSLIFY 1\n//\n// GLSL textureless classic 4D noise \"cnoise\",\n// with an RSL-style periodic variant \"pnoise\".\n// Author: Stefan Gustavson (stefan.gustavson@liu.se)\n// Version: 2011-08-22\n//\n// Many thanks to Ian McEwan of Ashima Arts for the\n// ideas for permutation and gradient selection.\n//\n// Copyright (c) 2011 Stefan Gustavson. All rights reserved.\n// Distributed under the MIT license. See LICENSE file.\n// https://github.com/stegu/webgl-noise\n//\n\n// Classic Perlin noise\nfloat perlin( vec4 P ) {\n\n vec4 Pi0 = floor(P); // Integer part for indexing\n vec4 Pi1 = Pi0 + 1.0; // Integer part + 1\n Pi0 = mod289(Pi0);\n Pi1 = mod289(Pi1);\n vec4 Pf0 = fract(P); // Fractional part for interpolation\n vec4 Pf1 = Pf0 - 1.0; // Fractional part - 1.0\n vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);\n vec4 iy = vec4(Pi0.yy, Pi1.yy);\n vec4 iz0 = vec4(Pi0.zzzz);\n vec4 iz1 = vec4(Pi1.zzzz);\n vec4 iw0 = vec4(Pi0.wwww);\n vec4 iw1 = vec4(Pi1.wwww);\n\n vec4 ixy = permute(permute(ix) + iy);\n vec4 ixy0 = permute(ixy + iz0);\n vec4 ixy1 = permute(ixy + iz1);\n vec4 ixy00 = permute(ixy0 + iw0);\n vec4 ixy01 = permute(ixy0 + iw1);\n vec4 ixy10 = permute(ixy1 + iw0);\n vec4 ixy11 = permute(ixy1 + iw1);\n\n vec4 gx00 = ixy00 * (1.0 / 7.0);\n vec4 gy00 = floor(gx00) * (1.0 / 7.0);\n vec4 gz00 = floor(gy00) * (1.0 / 6.0);\n gx00 = fract(gx00) - 0.5;\n gy00 = fract(gy00) - 0.5;\n gz00 = fract(gz00) - 0.5;\n vec4 gw00 = vec4(0.75) - abs(gx00) - abs(gy00) - abs(gz00);\n vec4 sw00 = step(gw00, vec4(0.0));\n gx00 -= sw00 * (step(0.0, gx00) - 0.5);\n gy00 -= sw00 * (step(0.0, gy00) - 0.5);\n\n vec4 gx01 = ixy01 * (1.0 / 7.0);\n vec4 gy01 = floor(gx01) * (1.0 / 7.0);\n vec4 gz01 = floor(gy01) * (1.0 / 6.0);\n gx01 = fract(gx01) - 0.5;\n gy01 = fract(gy01) - 0.5;\n gz01 = fract(gz01) - 0.5;\n vec4 gw01 = vec4(0.75) - abs(gx01) - abs(gy01) - abs(gz01);\n vec4 sw01 = step(gw01, vec4(0.0));\n gx01 -= sw01 * (step(0.0, gx01) - 0.5);\n gy01 -= sw01 * (step(0.0, gy01) - 0.5);\n\n vec4 gx10 = ixy10 * (1.0 / 7.0);\n vec4 gy10 = floor(gx10) * (1.0 / 7.0);\n vec4 gz10 = floor(gy10) * (1.0 / 6.0);\n gx10 = fract(gx10) - 0.5;\n gy10 = fract(gy10) - 0.5;\n gz10 = fract(gz10) - 0.5;\n vec4 gw10 = vec4(0.75) - abs(gx10) - abs(gy10) - abs(gz10);\n vec4 sw10 = step(gw10, vec4(0.0));\n gx10 -= sw10 * (step(0.0, gx10) - 0.5);\n gy10 -= sw10 * (step(0.0, gy10) - 0.5);\n\n vec4 gx11 = ixy11 * (1.0 / 7.0);\n vec4 gy11 = floor(gx11) * (1.0 / 7.0);\n vec4 gz11 = floor(gy11) * (1.0 / 6.0);\n gx11 = fract(gx11) - 0.5;\n gy11 = fract(gy11) - 0.5;\n gz11 = fract(gz11) - 0.5;\n vec4 gw11 = vec4(0.75) - abs(gx11) - abs(gy11) - abs(gz11);\n vec4 sw11 = step(gw11, vec4(0.0));\n gx11 -= sw11 * (step(0.0, gx11) - 0.5);\n gy11 -= sw11 * (step(0.0, gy11) - 0.5);\n\n vec4 g0000 = vec4(gx00.x,gy00.x,gz00.x,gw00.x);\n vec4 g1000 = vec4(gx00.y,gy00.y,gz00.y,gw00.y);\n vec4 g0100 = vec4(gx00.z,gy00.z,gz00.z,gw00.z);\n vec4 g1100 = vec4(gx00.w,gy00.w,gz00.w,gw00.w);\n vec4 g0010 = vec4(gx10.x,gy10.x,gz10.x,gw10.x);\n vec4 g1010 = vec4(gx10.y,gy10.y,gz10.y,gw10.y);\n vec4 g0110 = vec4(gx10.z,gy10.z,gz10.z,gw10.z);\n vec4 g1110 = vec4(gx10.w,gy10.w,gz10.w,gw10.w);\n vec4 g0001 = vec4(gx01.x,gy01.x,gz01.x,gw01.x);\n vec4 g1001 = vec4(gx01.y,gy01.y,gz01.y,gw01.y);\n vec4 g0101 = vec4(gx01.z,gy01.z,gz01.z,gw01.z);\n vec4 g1101 = vec4(gx01.w,gy01.w,gz01.w,gw01.w);\n vec4 g0011 = vec4(gx11.x,gy11.x,gz11.x,gw11.x);\n vec4 g1011 = vec4(gx11.y,gy11.y,gz11.y,gw11.y);\n vec4 g0111 = vec4(gx11.z,gy11.z,gz11.z,gw11.z);\n vec4 g1111 = vec4(gx11.w,gy11.w,gz11.w,gw11.w);\n\n vec4 norm00 = taylorInvSqrt(vec4(dot(g0000, g0000), dot(g0100, g0100), dot(g1000, g1000), dot(g1100, g1100)));\n g0000 *= norm00.x;\n g0100 *= norm00.y;\n g1000 *= norm00.z;\n g1100 *= norm00.w;\n\n vec4 norm01 = taylorInvSqrt(vec4(dot(g0001, g0001), dot(g0101, g0101), dot(g1001, g1001), dot(g1101, g1101)));\n g0001 *= norm01.x;\n g0101 *= norm01.y;\n g1001 *= norm01.z;\n g1101 *= norm01.w;\n\n vec4 norm10 = taylorInvSqrt(vec4(dot(g0010, g0010), dot(g0110, g0110), dot(g1010, g1010), dot(g1110, g1110)));\n g0010 *= norm10.x;\n g0110 *= norm10.y;\n g1010 *= norm10.z;\n g1110 *= norm10.w;\n\n vec4 norm11 = taylorInvSqrt(vec4(dot(g0011, g0011), dot(g0111, g0111), dot(g1011, g1011), dot(g1111, g1111)));\n g0011 *= norm11.x;\n g0111 *= norm11.y;\n g1011 *= norm11.z;\n g1111 *= norm11.w;\n\n float n0000 = dot(g0000, Pf0);\n float n1000 = dot(g1000, vec4(Pf1.x, Pf0.yzw));\n float n0100 = dot(g0100, vec4(Pf0.x, Pf1.y, Pf0.zw));\n float n1100 = dot(g1100, vec4(Pf1.xy, Pf0.zw));\n float n0010 = dot(g0010, vec4(Pf0.xy, Pf1.z, Pf0.w));\n float n1010 = dot(g1010, vec4(Pf1.x, Pf0.y, Pf1.z, Pf0.w));\n float n0110 = dot(g0110, vec4(Pf0.x, Pf1.yz, Pf0.w));\n float n1110 = dot(g1110, vec4(Pf1.xyz, Pf0.w));\n float n0001 = dot(g0001, vec4(Pf0.xyz, Pf1.w));\n float n1001 = dot(g1001, vec4(Pf1.x, Pf0.yz, Pf1.w));\n float n0101 = dot(g0101, vec4(Pf0.x, Pf1.y, Pf0.z, Pf1.w));\n float n1101 = dot(g1101, vec4(Pf1.xy, Pf0.z, Pf1.w));\n float n0011 = dot(g0011, vec4(Pf0.xy, Pf1.zw));\n float n1011 = dot(g1011, vec4(Pf1.x, Pf0.y, Pf1.zw));\n float n0111 = dot(g0111, vec4(Pf0.x, Pf1.yzw));\n float n1111 = dot(g1111, Pf1);\n\n vec4 fade_xyzw = fade(Pf0);\n vec4 n_0w = mix(vec4(n0000, n1000, n0100, n1100), vec4(n0001, n1001, n0101, n1101), fade_xyzw.w);\n vec4 n_1w = mix(vec4(n0010, n1010, n0110, n1110), vec4(n0011, n1011, n0111, n1111), fade_xyzw.w);\n vec4 n_zw = mix(n_0w, n_1w, fade_xyzw.z);\n vec2 n_yzw = mix(n_zw.xy, n_zw.zw, fade_xyzw.y);\n float n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x);\n return 2.2 * n_xyzw;\n\n}\n\n// Classic Perlin noise, periodic version\nfloat perlin( vec4 P, vec4 rep ) {\n\n vec4 Pi0 = mod(floor(P), rep); // Integer part modulo rep\n vec4 Pi1 = mod(Pi0 + 1.0, rep); // Integer part + 1 mod rep\n Pi0 = mod289(Pi0);\n Pi1 = mod289(Pi1);\n vec4 Pf0 = fract(P); // Fractional part for interpolation\n vec4 Pf1 = Pf0 - 1.0; // Fractional part - 1.0\n vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);\n vec4 iy = vec4(Pi0.yy, Pi1.yy);\n vec4 iz0 = vec4(Pi0.zzzz);\n vec4 iz1 = vec4(Pi1.zzzz);\n vec4 iw0 = vec4(Pi0.wwww);\n vec4 iw1 = vec4(Pi1.wwww);\n\n vec4 ixy = permute(permute(ix) + iy);\n vec4 ixy0 = permute(ixy + iz0);\n vec4 ixy1 = permute(ixy + iz1);\n vec4 ixy00 = permute(ixy0 + iw0);\n vec4 ixy01 = permute(ixy0 + iw1);\n vec4 ixy10 = permute(ixy1 + iw0);\n vec4 ixy11 = permute(ixy1 + iw1);\n\n vec4 gx00 = ixy00 * (1.0 / 7.0);\n vec4 gy00 = floor(gx00) * (1.0 / 7.0);\n vec4 gz00 = floor(gy00) * (1.0 / 6.0);\n gx00 = fract(gx00) - 0.5;\n gy00 = fract(gy00) - 0.5;\n gz00 = fract(gz00) - 0.5;\n vec4 gw00 = vec4(0.75) - abs(gx00) - abs(gy00) - abs(gz00);\n vec4 sw00 = step(gw00, vec4(0.0));\n gx00 -= sw00 * (step(0.0, gx00) - 0.5);\n gy00 -= sw00 * (step(0.0, gy00) - 0.5);\n\n vec4 gx01 = ixy01 * (1.0 / 7.0);\n vec4 gy01 = floor(gx01) * (1.0 / 7.0);\n vec4 gz01 = floor(gy01) * (1.0 / 6.0);\n gx01 = fract(gx01) - 0.5;\n gy01 = fract(gy01) - 0.5;\n gz01 = fract(gz01) - 0.5;\n vec4 gw01 = vec4(0.75) - abs(gx01) - abs(gy01) - abs(gz01);\n vec4 sw01 = step(gw01, vec4(0.0));\n gx01 -= sw01 * (step(0.0, gx01) - 0.5);\n gy01 -= sw01 * (step(0.0, gy01) - 0.5);\n\n vec4 gx10 = ixy10 * (1.0 / 7.0);\n vec4 gy10 = floor(gx10) * (1.0 / 7.0);\n vec4 gz10 = floor(gy10) * (1.0 / 6.0);\n gx10 = fract(gx10) - 0.5;\n gy10 = fract(gy10) - 0.5;\n gz10 = fract(gz10) - 0.5;\n vec4 gw10 = vec4(0.75) - abs(gx10) - abs(gy10) - abs(gz10);\n vec4 sw10 = step(gw10, vec4(0.0));\n gx10 -= sw10 * (step(0.0, gx10) - 0.5);\n gy10 -= sw10 * (step(0.0, gy10) - 0.5);\n\n vec4 gx11 = ixy11 * (1.0 / 7.0);\n vec4 gy11 = floor(gx11) * (1.0 / 7.0);\n vec4 gz11 = floor(gy11) * (1.0 / 6.0);\n gx11 = fract(gx11) - 0.5;\n gy11 = fract(gy11) - 0.5;\n gz11 = fract(gz11) - 0.5;\n vec4 gw11 = vec4(0.75) - abs(gx11) - abs(gy11) - abs(gz11);\n vec4 sw11 = step(gw11, vec4(0.0));\n gx11 -= sw11 * (step(0.0, gx11) - 0.5);\n gy11 -= sw11 * (step(0.0, gy11) - 0.5);\n\n vec4 g0000 = vec4(gx00.x,gy00.x,gz00.x,gw00.x);\n vec4 g1000 = vec4(gx00.y,gy00.y,gz00.y,gw00.y);\n vec4 g0100 = vec4(gx00.z,gy00.z,gz00.z,gw00.z);\n vec4 g1100 = vec4(gx00.w,gy00.w,gz00.w,gw00.w);\n vec4 g0010 = vec4(gx10.x,gy10.x,gz10.x,gw10.x);\n vec4 g1010 = vec4(gx10.y,gy10.y,gz10.y,gw10.y);\n vec4 g0110 = vec4(gx10.z,gy10.z,gz10.z,gw10.z);\n vec4 g1110 = vec4(gx10.w,gy10.w,gz10.w,gw10.w);\n vec4 g0001 = vec4(gx01.x,gy01.x,gz01.x,gw01.x);\n vec4 g1001 = vec4(gx01.y,gy01.y,gz01.y,gw01.y);\n vec4 g0101 = vec4(gx01.z,gy01.z,gz01.z,gw01.z);\n vec4 g1101 = vec4(gx01.w,gy01.w,gz01.w,gw01.w);\n vec4 g0011 = vec4(gx11.x,gy11.x,gz11.x,gw11.x);\n vec4 g1011 = vec4(gx11.y,gy11.y,gz11.y,gw11.y);\n vec4 g0111 = vec4(gx11.z,gy11.z,gz11.z,gw11.z);\n vec4 g1111 = vec4(gx11.w,gy11.w,gz11.w,gw11.w);\n\n vec4 norm00 = taylorInvSqrt(vec4(dot(g0000, g0000), dot(g0100, g0100), dot(g1000, g1000), dot(g1100, g1100)));\n g0000 *= norm00.x;\n g0100 *= norm00.y;\n g1000 *= norm00.z;\n g1100 *= norm00.w;\n\n vec4 norm01 = taylorInvSqrt(vec4(dot(g0001, g0001), dot(g0101, g0101), dot(g1001, g1001), dot(g1101, g1101)));\n g0001 *= norm01.x;\n g0101 *= norm01.y;\n g1001 *= norm01.z;\n g1101 *= norm01.w;\n\n vec4 norm10 = taylorInvSqrt(vec4(dot(g0010, g0010), dot(g0110, g0110), dot(g1010, g1010), dot(g1110, g1110)));\n g0010 *= norm10.x;\n g0110 *= norm10.y;\n g1010 *= norm10.z;\n g1110 *= norm10.w;\n\n vec4 norm11 = taylorInvSqrt(vec4(dot(g0011, g0011), dot(g0111, g0111), dot(g1011, g1011), dot(g1111, g1111)));\n g0011 *= norm11.x;\n g0111 *= norm11.y;\n g1011 *= norm11.z;\n g1111 *= norm11.w;\n\n float n0000 = dot(g0000, Pf0);\n float n1000 = dot(g1000, vec4(Pf1.x, Pf0.yzw));\n float n0100 = dot(g0100, vec4(Pf0.x, Pf1.y, Pf0.zw));\n float n1100 = dot(g1100, vec4(Pf1.xy, Pf0.zw));\n float n0010 = dot(g0010, vec4(Pf0.xy, Pf1.z, Pf0.w));\n float n1010 = dot(g1010, vec4(Pf1.x, Pf0.y, Pf1.z, Pf0.w));\n float n0110 = dot(g0110, vec4(Pf0.x, Pf1.yz, Pf0.w));\n float n1110 = dot(g1110, vec4(Pf1.xyz, Pf0.w));\n float n0001 = dot(g0001, vec4(Pf0.xyz, Pf1.w));\n float n1001 = dot(g1001, vec4(Pf1.x, Pf0.yz, Pf1.w));\n float n0101 = dot(g0101, vec4(Pf0.x, Pf1.y, Pf0.z, Pf1.w));\n float n1101 = dot(g1101, vec4(Pf1.xy, Pf0.z, Pf1.w));\n float n0011 = dot(g0011, vec4(Pf0.xy, Pf1.zw));\n float n1011 = dot(g1011, vec4(Pf1.x, Pf0.y, Pf1.zw));\n float n0111 = dot(g0111, vec4(Pf0.x, Pf1.yzw));\n float n1111 = dot(g1111, Pf1);\n\n vec4 fade_xyzw = fade(Pf0);\n vec4 n_0w = mix(vec4(n0000, n1000, n0100, n1100), vec4(n0001, n1001, n0101, n1101), fade_xyzw.w);\n vec4 n_1w = mix(vec4(n0010, n1010, n0110, n1110), vec4(n0011, n1011, n0111, n1111), fade_xyzw.w);\n vec4 n_zw = mix(n_0w, n_1w, fade_xyzw.z);\n vec2 n_yzw = mix(n_zw.xy, n_zw.zw, fade_xyzw.y);\n float n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x);\n return 2.2 * n_xyzw;\n\n}\n"; // eslint-disable-line
3526
3526
 
3527
- var noise_psrd_2D = "#define GLSLIFY 1\nvec2 rgrad2(vec2 p,float rot){float u=permute(permute(p.x)+p.y)*0.0243902439+rot;u=fract(u)*6.28318530718;return vec2(cos(u),sin(u));}vec3 psrdnoise(vec2 pos,vec2 per,float rot){pos.y+=0.01;vec2 uv=vec2(pos.x+pos.y*0.5,pos.y);vec2 i0=floor(uv);vec2 f0=fract(uv);vec2 i1=(f0.x>f0.y)? vec2(1.0,0.0): vec2(0.0,1.0);vec2 p0=vec2(i0.x-i0.y*0.5,i0.y);vec2 p1=vec2(p0.x+i1.x-i1.y*0.5,p0.y+i1.y);vec2 p2=vec2(p0.x+0.5,p0.y+1.0);i1=i0+i1;vec2 i2=i0+vec2(1.0,1.0);vec2 d0=pos-p0;vec2 d1=pos-p1;vec2 d2=pos-p2;vec3 xw=mod(vec3(p0.x,p1.x,p2.x),per.x);vec3 yw=mod(vec3(p0.y,p1.y,p2.y),per.y);vec3 iuw=xw+0.5*yw;vec3 ivw=yw;vec2 g0=rgrad2(vec2(iuw.x,ivw.x),rot);vec2 g1=rgrad2(vec2(iuw.y,ivw.y),rot);vec2 g2=rgrad2(vec2(iuw.z,ivw.z),rot);vec3 w=vec3(dot(g0,d0),dot(g1,d1),dot(g2,d2));vec3 t=0.8-vec3(dot(d0,d0),dot(d1,d1),dot(d2,d2));vec3 dtdx=-2.0*vec3(d0.x,d1.x,d2.x);vec3 dtdy=-2.0*vec3(d0.y,d1.y,d2.y);if(t.x<0.0){dtdx.x=0.0;dtdy.x=0.0;t.x=0.0;}if(t.y<0.0){dtdx.y=0.0;dtdy.y=0.0;t.y=0.0;}if(t.z<0.0){dtdx.z=0.0;dtdy.z=0.0;t.z=0.0;}vec3 t2=t*t;vec3 t4=t2*t2;vec3 t3=t2*t;float n=dot(t4,w);vec2 dt0=vec2(dtdx.x,dtdy.x)*4.0*t3.x;vec2 dn0=t4.x*g0+dt0*w.x;vec2 dt1=vec2(dtdx.y,dtdy.y)*4.0*t3.y;vec2 dn1=t4.y*g1+dt1*w.y;vec2 dt2=vec2(dtdx.z,dtdy.z)*4.0*t3.z;vec2 dn2=t4.z*g2+dt2*w.z;return 11.0*vec3(n,dn0+dn1+dn2);}vec3 psdnoise(vec2 pos,vec2 per){return psrdnoise(pos,per,0.0);}float psrnoise(vec2 pos,vec2 per,float rot){pos.y+=0.001;vec2 uv=vec2(pos.x+pos.y*0.5,pos.y);vec2 i0=floor(uv);vec2 f0=fract(uv);vec2 i1=(f0.x>f0.y)? vec2(1.0,0.0): vec2(0.0,1.0);vec2 p0=vec2(i0.x-i0.y*0.5,i0.y);vec2 p1=vec2(p0.x+i1.x-i1.y*0.5,p0.y+i1.y);vec2 p2=vec2(p0.x+0.5,p0.y+1.0);i1=i0+i1;vec2 i2=i0+vec2(1.0,1.0);vec2 d0=pos-p0;vec2 d1=pos-p1;vec2 d2=pos-p2;vec3 xw=mod(vec3(p0.x,p1.x,p2.x),per.x);vec3 yw=mod(vec3(p0.y,p1.y,p2.y),per.y);vec3 iuw=xw+0.5*yw;vec3 ivw=yw;vec2 g0=rgrad2(vec2(iuw.x,ivw.x),rot);vec2 g1=rgrad2(vec2(iuw.y,ivw.y),rot);vec2 g2=rgrad2(vec2(iuw.z,ivw.z),rot);vec3 w=vec3(dot(g0,d0),dot(g1,d1),dot(g2,d2));vec3 t=0.8-vec3(dot(d0,d0),dot(d1,d1),dot(d2,d2));t=max(t,0.0);vec3 t2=t*t;vec3 t4=t2*t2;float n=dot(t4,w);return 11.0*n;}float psnoise(vec2 pos,vec2 per){return psrnoise(pos,per,0.0);}vec3 srdnoise(vec2 pos,float rot){pos.y+=0.001;vec2 uv=vec2(pos.x+pos.y*0.5,pos.y);vec2 i0=floor(uv);vec2 f0=fract(uv);vec2 i1=(f0.x>f0.y)? vec2(1.0,0.0): vec2(0.0,1.0);vec2 p0=vec2(i0.x-i0.y*0.5,i0.y);vec2 p1=vec2(p0.x+i1.x-i1.y*0.5,p0.y+i1.y);vec2 p2=vec2(p0.x+0.5,p0.y+1.0);i1=i0+i1;vec2 i2=i0+vec2(1.0,1.0);vec2 d0=pos-p0;vec2 d1=pos-p1;vec2 d2=pos-p2;vec3 x=vec3(p0.x,p1.x,p2.x);vec3 y=vec3(p0.y,p1.y,p2.y);vec3 iuw=x+0.5*y;vec3 ivw=y;iuw=mod289(iuw);ivw=mod289(ivw);vec2 g0=rgrad2(vec2(iuw.x,ivw.x),rot);vec2 g1=rgrad2(vec2(iuw.y,ivw.y),rot);vec2 g2=rgrad2(vec2(iuw.z,ivw.z),rot);vec3 w=vec3(dot(g0,d0),dot(g1,d1),dot(g2,d2));vec3 t=0.8-vec3(dot(d0,d0),dot(d1,d1),dot(d2,d2));vec3 dtdx=-2.0*vec3(d0.x,d1.x,d2.x);vec3 dtdy=-2.0*vec3(d0.y,d1.y,d2.y);if(t.x<0.0){dtdx.x=0.0;dtdy.x=0.0;t.x=0.0;}if(t.y<0.0){dtdx.y=0.0;dtdy.y=0.0;t.y=0.0;}if(t.z<0.0){dtdx.z=0.0;dtdy.z=0.0;t.z=0.0;}vec3 t2=t*t;vec3 t4=t2*t2;vec3 t3=t2*t;float n=dot(t4,w);vec2 dt0=vec2(dtdx.x,dtdy.x)*4.0*t3.x;vec2 dn0=t4.x*g0+dt0*w.x;vec2 dt1=vec2(dtdx.y,dtdy.y)*4.0*t3.y;vec2 dn1=t4.y*g1+dt1*w.y;vec2 dt2=vec2(dtdx.z,dtdy.z)*4.0*t3.z;vec2 dn2=t4.z*g2+dt2*w.z;return 11.0*vec3(n,dn0+dn1+dn2);}vec3 sdnoise(vec2 pos){return srdnoise(pos,0.0);}float srnoise(vec2 pos,float rot){pos.y+=0.001;vec2 uv=vec2(pos.x+pos.y*0.5,pos.y);vec2 i0=floor(uv);vec2 f0=fract(uv);vec2 i1=(f0.x>f0.y)? vec2(1.0,0.0): vec2(0.0,1.0);vec2 p0=vec2(i0.x-i0.y*0.5,i0.y);vec2 p1=vec2(p0.x+i1.x-i1.y*0.5,p0.y+i1.y);vec2 p2=vec2(p0.x+0.5,p0.y+1.0);i1=i0+i1;vec2 i2=i0+vec2(1.0,1.0);vec2 d0=pos-p0;vec2 d1=pos-p1;vec2 d2=pos-p2;vec3 x=vec3(p0.x,p1.x,p2.x);vec3 y=vec3(p0.y,p1.y,p2.y);vec3 iuw=x+0.5*y;vec3 ivw=y;iuw=mod289(iuw);ivw=mod289(ivw);vec2 g0=rgrad2(vec2(iuw.x,ivw.x),rot);vec2 g1=rgrad2(vec2(iuw.y,ivw.y),rot);vec2 g2=rgrad2(vec2(iuw.z,ivw.z),rot);vec3 w=vec3(dot(g0,d0),dot(g1,d1),dot(g2,d2));vec3 t=0.8-vec3(dot(d0,d0),dot(d1,d1),dot(d2,d2));t=max(t,0.0);vec3 t2=t*t;vec3 t4=t2*t2;float n=dot(t4,w);return 11.0*n;}float snoise(vec2 pos){return srnoise(pos,0.0);}"; // eslint-disable-line
3527
+ var noise_psrd_2D = "#define GLSLIFY 1\n// Periodic (tiling) 2-D simplex noise (hexagonal lattice gradient noise)\n// with rotating gradients and analytic derivatives.\n// Variants also without the derivative (no \"d\" in the name), without\n// the tiling property (no \"p\" in the name) and without the rotating\n// gradients (no \"r\" in the name).\n//\n// This is (yet) another variation on simplex noise. It's similar to the\n// version presented by Ken Perlin, but the grid is axis-aligned and\n// slightly stretched in the y direction to permit rectangular tiling.\n//\n// The noise can be made to tile seamlessly to any integer period in x and\n// any even integer period in y. Odd periods may be specified for y, but\n// then the actual tiling period will be twice that number.\n//\n// The rotating gradients give the appearance of a swirling motion, and can\n// serve a similar purpose for animation as motion along z in 3-D noise.\n// The rotating gradients in conjunction with the analytic derivatives\n// can make \"flow noise\" effects as presented by Perlin and Neyret.\n//\n// vec3 {p}s{r}dnoise(vec2 pos {, vec2 per} {, float rot})\n// \"pos\" is the input (x,y) coordinate\n// \"per\" is the x and y period, where per.x is a positive integer\n// and per.y is a positive even integer\n// \"rot\" is the angle to rotate the gradients (any float value,\n// where 0.0 is no rotation and 1.0 is one full turn)\n// The first component of the 3-element return vector is the noise value.\n// The second and third components are the x and y partial derivatives.\n//\n// float {p}s{r}noise(vec2 pos {, vec2 per} {, float rot})\n// \"pos\" is the input (x,y) coordinate\n// \"per\" is the x and y period, where per.x is a positive integer\n// and per.y is a positive even integer\n// \"rot\" is the angle to rotate the gradients (any float value,\n// where 0.0 is no rotation and 1.0 is one full turn)\n// The return value is the noise value.\n// Partial derivatives are not computed, making these functions faster.\n//\n// Author: Stefan Gustavson (stefan.gustavson@gmail.com)\n// Version 2016-05-10.\n//\n// Many thanks to Ian McEwan of Ashima Arts for the\n// idea of using a permutation polynomial.\n//\n// Copyright (c) 2016 Stefan Gustavson. All rights reserved.\n// Distributed under the MIT license. See LICENSE file.\n// https://github.com/stegu/webgl-noise\n//\n\n// Hashed 2-D gradients with an extra rotation.\n// (The constant 0.0243902439 is 1/41)\nvec2 rgrad2( vec2 p, float rot ) {\n\n // For more isotropic gradients, sin/cos can be used instead.\n float u = permute( permute( p.x ) + p.y ) * 0.0243902439 + rot; // Rotate by shift\n u = fract( u ) * 6.28318530718; // 2*pi\n return vec2( cos( u ), sin( u ));\n\n}\n\n//\n// 2-D tiling simplex noise with rotating gradients and analytical derivative.\n// The first component of the 3-element return vector is the noise value,\n// and the second and third components are the x and y partial derivatives.\n//\nvec3 psrdnoise(vec2 pos, vec2 per, float rot) {\n // Hack: offset y slightly to hide some rare artifacts\n pos.y += 0.01;\n // Skew to hexagonal grid\n vec2 uv = vec2(pos.x + pos.y*0.5, pos.y);\n\n vec2 i0 = floor(uv);\n vec2 f0 = fract(uv);\n // Traversal order\n vec2 i1 = (f0.x > f0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n\n // Unskewed grid points in (x,y) space\n vec2 p0 = vec2(i0.x - i0.y * 0.5, i0.y);\n vec2 p1 = vec2(p0.x + i1.x - i1.y * 0.5, p0.y + i1.y);\n vec2 p2 = vec2(p0.x + 0.5, p0.y + 1.0);\n\n // Integer grid point indices in (u,v) space\n i1 = i0 + i1;\n vec2 i2 = i0 + vec2(1.0, 1.0);\n\n // Vectors in unskewed (x,y) coordinates from\n // each of the simplex corners to the evaluation point\n vec2 d0 = pos - p0;\n vec2 d1 = pos - p1;\n vec2 d2 = pos - p2;\n\n // Wrap i0, i1 and i2 to the desired period before gradient hashing:\n // wrap points in (x,y), map to (u,v)\n vec3 xw = mod(vec3(p0.x, p1.x, p2.x), per.x);\n vec3 yw = mod(vec3(p0.y, p1.y, p2.y), per.y);\n vec3 iuw = xw + 0.5 * yw;\n vec3 ivw = yw;\n\n // Create gradients from indices\n vec2 g0 = rgrad2(vec2(iuw.x, ivw.x), rot);\n vec2 g1 = rgrad2(vec2(iuw.y, ivw.y), rot);\n vec2 g2 = rgrad2(vec2(iuw.z, ivw.z), rot);\n\n // Gradients dot vectors to corresponding corners\n // (The derivatives of this are simply the gradients)\n vec3 w = vec3(dot(g0, d0), dot(g1, d1), dot(g2, d2));\n\n // Radial weights from corners\n // 0.8 is the square of 2/sqrt(5), the distance from\n // a grid point to the nearest simplex boundary\n vec3 t = 0.8 - vec3(dot(d0, d0), dot(d1, d1), dot(d2, d2));\n\n // Partial derivatives for analytical gradient computation\n vec3 dtdx = -2.0 * vec3(d0.x, d1.x, d2.x);\n vec3 dtdy = -2.0 * vec3(d0.y, d1.y, d2.y);\n\n // Set influence of each surflet to zero outside radius sqrt(0.8)\n if (t.x < 0.0) {\n dtdx.x = 0.0;\n dtdy.x = 0.0;\n\tt.x = 0.0;\n }\n if (t.y < 0.0) {\n dtdx.y = 0.0;\n dtdy.y = 0.0;\n\tt.y = 0.0;\n }\n if (t.z < 0.0) {\n dtdx.z = 0.0;\n dtdy.z = 0.0;\n\tt.z = 0.0;\n }\n\n // Fourth power of t (and third power for derivative)\n vec3 t2 = t * t;\n vec3 t4 = t2 * t2;\n vec3 t3 = t2 * t;\n\n // Final noise value is:\n // sum of ((radial weights) times (gradient dot vector from corner))\n float n = dot(t4, w);\n\n // Final analytical derivative (gradient of a sum of scalar products)\n vec2 dt0 = vec2(dtdx.x, dtdy.x) * 4.0 * t3.x;\n vec2 dn0 = t4.x * g0 + dt0 * w.x;\n vec2 dt1 = vec2(dtdx.y, dtdy.y) * 4.0 * t3.y;\n vec2 dn1 = t4.y * g1 + dt1 * w.y;\n vec2 dt2 = vec2(dtdx.z, dtdy.z) * 4.0 * t3.z;\n vec2 dn2 = t4.z * g2 + dt2 * w.z;\n\n return 11.0*vec3(n, dn0 + dn1 + dn2);\n}\n\n//\n// 2-D tiling simplex noise with fixed gradients\n// and analytical derivative.\n// This function is implemented as a wrapper to \"psrdnoise\",\n// at the minimal cost of three extra additions.\n//\nvec3 psdnoise(vec2 pos, vec2 per) {\n return psrdnoise(pos, per, 0.0);\n}\n\n//\n// 2-D tiling simplex noise with rotating gradients,\n// but without the analytical derivative.\n//\nfloat psrnoise(vec2 pos, vec2 per, float rot) {\n // Offset y slightly to hide some rare artifacts\n pos.y += 0.001;\n // Skew to hexagonal grid\n vec2 uv = vec2(pos.x + pos.y*0.5, pos.y);\n\n vec2 i0 = floor(uv);\n vec2 f0 = fract(uv);\n // Traversal order\n vec2 i1 = (f0.x > f0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n\n // Unskewed grid points in (x,y) space\n vec2 p0 = vec2(i0.x - i0.y * 0.5, i0.y);\n vec2 p1 = vec2(p0.x + i1.x - i1.y * 0.5, p0.y + i1.y);\n vec2 p2 = vec2(p0.x + 0.5, p0.y + 1.0);\n\n // Integer grid point indices in (u,v) space\n i1 = i0 + i1;\n vec2 i2 = i0 + vec2(1.0, 1.0);\n\n // Vectors in unskewed (x,y) coordinates from\n // each of the simplex corners to the evaluation point\n vec2 d0 = pos - p0;\n vec2 d1 = pos - p1;\n vec2 d2 = pos - p2;\n\n // Wrap i0, i1 and i2 to the desired period before gradient hashing:\n // wrap points in (x,y), map to (u,v)\n vec3 xw = mod(vec3(p0.x, p1.x, p2.x), per.x);\n vec3 yw = mod(vec3(p0.y, p1.y, p2.y), per.y);\n vec3 iuw = xw + 0.5 * yw;\n vec3 ivw = yw;\n\n // Create gradients from indices\n vec2 g0 = rgrad2(vec2(iuw.x, ivw.x), rot);\n vec2 g1 = rgrad2(vec2(iuw.y, ivw.y), rot);\n vec2 g2 = rgrad2(vec2(iuw.z, ivw.z), rot);\n\n // Gradients dot vectors to corresponding corners\n // (The derivatives of this are simply the gradients)\n vec3 w = vec3(dot(g0, d0), dot(g1, d1), dot(g2, d2));\n\n // Radial weights from corners\n // 0.8 is the square of 2/sqrt(5), the distance from\n // a grid point to the nearest simplex boundary\n vec3 t = 0.8 - vec3(dot(d0, d0), dot(d1, d1), dot(d2, d2));\n\n // Set influence of each surflet to zero outside radius sqrt(0.8)\n t = max(t, 0.0);\n\n // Fourth power of t\n vec3 t2 = t * t;\n vec3 t4 = t2 * t2;\n\n // Final noise value is:\n // sum of ((radial weights) times (gradient dot vector from corner))\n float n = dot(t4, w);\n\n // Rescale to cover the range [-1,1] reasonably well\n return 11.0*n;\n}\n\n//\n// 2-D tiling simplex noise with fixed gradients,\n// without the analytical derivative.\n// This function is implemented as a wrapper to \"psrnoise\",\n// at the minimal cost of three extra additions.\n//\nfloat psnoise(vec2 pos, vec2 per) {\n return psrnoise(pos, per, 0.0);\n}\n\n//\n// 2-D non-tiling simplex noise with rotating gradients and analytical derivative.\n// The first component of the 3-element return vector is the noise value,\n// and the second and third components are the x and y partial derivatives.\n//\nvec3 srdnoise(vec2 pos, float rot) {\n // Offset y slightly to hide some rare artifacts\n pos.y += 0.001;\n // Skew to hexagonal grid\n vec2 uv = vec2(pos.x + pos.y*0.5, pos.y);\n\n vec2 i0 = floor(uv);\n vec2 f0 = fract(uv);\n // Traversal order\n vec2 i1 = (f0.x > f0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n\n // Unskewed grid points in (x,y) space\n vec2 p0 = vec2(i0.x - i0.y * 0.5, i0.y);\n vec2 p1 = vec2(p0.x + i1.x - i1.y * 0.5, p0.y + i1.y);\n vec2 p2 = vec2(p0.x + 0.5, p0.y + 1.0);\n\n // Integer grid point indices in (u,v) space\n i1 = i0 + i1;\n vec2 i2 = i0 + vec2(1.0, 1.0);\n\n // Vectors in unskewed (x,y) coordinates from\n // each of the simplex corners to the evaluation point\n vec2 d0 = pos - p0;\n vec2 d1 = pos - p1;\n vec2 d2 = pos - p2;\n\n vec3 x = vec3(p0.x, p1.x, p2.x);\n vec3 y = vec3(p0.y, p1.y, p2.y);\n vec3 iuw = x + 0.5 * y;\n vec3 ivw = y;\n\n // Avoid precision issues in permutation\n iuw = mod289(iuw);\n ivw = mod289(ivw);\n\n // Create gradients from indices\n vec2 g0 = rgrad2(vec2(iuw.x, ivw.x), rot);\n vec2 g1 = rgrad2(vec2(iuw.y, ivw.y), rot);\n vec2 g2 = rgrad2(vec2(iuw.z, ivw.z), rot);\n\n // Gradients dot vectors to corresponding corners\n // (The derivatives of this are simply the gradients)\n vec3 w = vec3(dot(g0, d0), dot(g1, d1), dot(g2, d2));\n\n // Radial weights from corners\n // 0.8 is the square of 2/sqrt(5), the distance from\n // a grid point to the nearest simplex boundary\n vec3 t = 0.8 - vec3(dot(d0, d0), dot(d1, d1), dot(d2, d2));\n\n // Partial derivatives for analytical gradient computation\n vec3 dtdx = -2.0 * vec3(d0.x, d1.x, d2.x);\n vec3 dtdy = -2.0 * vec3(d0.y, d1.y, d2.y);\n\n // Set influence of each surflet to zero outside radius sqrt(0.8)\n if (t.x < 0.0) {\n dtdx.x = 0.0;\n dtdy.x = 0.0;\n\tt.x = 0.0;\n }\n if (t.y < 0.0) {\n dtdx.y = 0.0;\n dtdy.y = 0.0;\n\tt.y = 0.0;\n }\n if (t.z < 0.0) {\n dtdx.z = 0.0;\n dtdy.z = 0.0;\n\tt.z = 0.0;\n }\n\n // Fourth power of t (and third power for derivative)\n vec3 t2 = t * t;\n vec3 t4 = t2 * t2;\n vec3 t3 = t2 * t;\n\n // Final noise value is:\n // sum of ((radial weights) times (gradient dot vector from corner))\n float n = dot(t4, w);\n\n // Final analytical derivative (gradient of a sum of scalar products)\n vec2 dt0 = vec2(dtdx.x, dtdy.x) * 4.0 * t3.x;\n vec2 dn0 = t4.x * g0 + dt0 * w.x;\n vec2 dt1 = vec2(dtdx.y, dtdy.y) * 4.0 * t3.y;\n vec2 dn1 = t4.y * g1 + dt1 * w.y;\n vec2 dt2 = vec2(dtdx.z, dtdy.z) * 4.0 * t3.z;\n vec2 dn2 = t4.z * g2 + dt2 * w.z;\n\n return 11.0*vec3(n, dn0 + dn1 + dn2);\n}\n\n//\n// 2-D non-tiling simplex noise with fixed gradients and analytical derivative.\n// This function is implemented as a wrapper to \"srdnoise\",\n// at the minimal cost of three extra additions.\n//\nvec3 sdnoise(vec2 pos) {\n return srdnoise(pos, 0.0);\n}\n\n//\n// 2-D non-tiling simplex noise with rotating gradients,\n// without the analytical derivative.\n//\nfloat srnoise(vec2 pos, float rot) {\n // Offset y slightly to hide some rare artifacts\n pos.y += 0.001;\n // Skew to hexagonal grid\n vec2 uv = vec2(pos.x + pos.y*0.5, pos.y);\n\n vec2 i0 = floor(uv);\n vec2 f0 = fract(uv);\n // Traversal order\n vec2 i1 = (f0.x > f0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n\n // Unskewed grid points in (x,y) space\n vec2 p0 = vec2(i0.x - i0.y * 0.5, i0.y);\n vec2 p1 = vec2(p0.x + i1.x - i1.y * 0.5, p0.y + i1.y);\n vec2 p2 = vec2(p0.x + 0.5, p0.y + 1.0);\n\n // Integer grid point indices in (u,v) space\n i1 = i0 + i1;\n vec2 i2 = i0 + vec2(1.0, 1.0);\n\n // Vectors in unskewed (x,y) coordinates from\n // each of the simplex corners to the evaluation point\n vec2 d0 = pos - p0;\n vec2 d1 = pos - p1;\n vec2 d2 = pos - p2;\n\n // Wrap i0, i1 and i2 to the desired period before gradient hashing:\n // wrap points in (x,y), map to (u,v)\n vec3 x = vec3(p0.x, p1.x, p2.x);\n vec3 y = vec3(p0.y, p1.y, p2.y);\n vec3 iuw = x + 0.5 * y;\n vec3 ivw = y;\n\n // Avoid precision issues in permutation\n iuw = mod289(iuw);\n ivw = mod289(ivw);\n\n // Create gradients from indices\n vec2 g0 = rgrad2(vec2(iuw.x, ivw.x), rot);\n vec2 g1 = rgrad2(vec2(iuw.y, ivw.y), rot);\n vec2 g2 = rgrad2(vec2(iuw.z, ivw.z), rot);\n\n // Gradients dot vectors to corresponding corners\n // (The derivatives of this are simply the gradients)\n vec3 w = vec3(dot(g0, d0), dot(g1, d1), dot(g2, d2));\n\n // Radial weights from corners\n // 0.8 is the square of 2/sqrt(5), the distance from\n // a grid point to the nearest simplex boundary\n vec3 t = 0.8 - vec3(dot(d0, d0), dot(d1, d1), dot(d2, d2));\n\n // Set influence of each surflet to zero outside radius sqrt(0.8)\n t = max(t, 0.0);\n\n // Fourth power of t\n vec3 t2 = t * t;\n vec3 t4 = t2 * t2;\n\n // Final noise value is:\n // sum of ((radial weights) times (gradient dot vector from corner))\n float n = dot(t4, w);\n\n // Rescale to cover the range [-1,1] reasonably well\n return 11.0*n;\n}\n\n//\n// 2-D non-tiling simplex noise with fixed gradients,\n// without the analytical derivative.\n// This function is implemented as a wrapper to \"srnoise\",\n// at the minimal cost of three extra additions.\n// Note: if this kind of noise is all you want, there are faster\n// GLSL implementations of non-tiling simplex noise out there.\n// This one is included mainly for completeness and compatibility\n// with the other functions in the file.\n//\nfloat snoise(vec2 pos) {\n return srnoise(pos, 0.0);\n}\n"; // eslint-disable-line
3528
3528
 
3529
3529
  var noise_simplex = "#define GLSLIFY 1\n#include <noise_simplex_2D>\n#include <noise_simplex_3D>\n#include <noise_simplex_3D_grad>\n#include <noise_simplex_4D>\n"; // eslint-disable-line
3530
3530
 
3531
- var noise_simplex_2D = "#define GLSLIFY 1\nfloat simplex(vec2 v){const vec4 C=vec4(0.211324865405187,0.366025403784439,-0.577350269189626,0.024390243902439);vec2 i=floor(v+dot(v,C.yy));vec2 x0=v-i+dot(i,C.xx);vec2 i1;i1=(x0.x>x0.y)? vec2(1.0,0.0): vec2(0.0,1.0);vec4 x12=x0.xyxy+C.xxzz;x12.xy-=i1;i=mod289(i);vec3 p=permute(permute(i.y+vec3(0.0,i1.y,1.0))+i.x+vec3(0.0,i1.x,1.0));vec3 m=max(0.5-vec3(dot(x0,x0),dot(x12.xy,x12.xy),dot(x12.zw,x12.zw)),0.0);m=m*m;m=m*m;vec3 x=2.0*fract(p*C.www)-1.0;vec3 h=abs(x)-0.5;vec3 ox=floor(x+0.5);vec3 a0=x-ox;m*=1.79284291400159-0.85373472095314*(a0*a0+h*h);vec3 g;g.x=a0.x*x0.x+h.x*x0.y;g.yz=a0.yz*x12.xz+h.yz*x12.yw;return 130.0*dot(m,g);}"; // eslint-disable-line
3531
+ var noise_simplex_2D = "#define GLSLIFY 1\n//\n// Description : Array and textureless GLSL 2D simplex noise function.\n// Author : Ian McEwan, Ashima Arts.\n// Maintainer : stegu\n// Lastmod : 20110822 (ijm)\n// License : Copyright (C) 2011 Ashima Arts. All rights reserved.\n// Distributed under the MIT License. See LICENSE file.\n// https://github.com/ashima/webgl-noise\n// https://github.com/stegu/webgl-noise\n//\n\nfloat simplex( vec2 v ) {\n\n const vec4 C = vec4( 0.211324865405187, // (3.0-sqrt(3.0))/6.0\n 0.366025403784439, // 0.5*(sqrt(3.0)-1.0)\n -0.577350269189626, // -1.0 + 2.0 * C.x\n 0.024390243902439 ); // 1.0 / 41.0\n // First corner\n vec2 i = floor( v + dot( v, C.yy ) );\n vec2 x0 = v - i + dot( i, C.xx );\n\n // Other corners\n vec2 i1;\n //i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0\n //i1.y = 1.0 - i1.x;\n i1 = ( x0.x > x0.y ) ? vec2( 1.0, 0.0 ) : vec2( 0.0, 1.0 );\n // x0 = x0 - 0.0 + 0.0 * C.xx ;\n // x1 = x0 - i1 + 1.0 * C.xx ;\n // x2 = x0 - 1.0 + 2.0 * C.xx ;\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n\n // Permutations\n i = mod289( i ); // Avoid truncation effects in permutation\n vec3 p = permute( permute( i.y + vec3( 0.0, i1.y, 1.0 ) )\n + i.x + vec3( 0.0, i1.x, 1.0 ) );\n\n vec3 m = max( 0.5 - vec3( dot( x0, x0 ), dot( x12.xy, x12.xy ), dot( x12.zw, x12.zw ) ), 0.0 );\n m = m*m ;\n m = m*m ;\n\n // Gradients: 41 points uniformly over a line, mapped onto a diamond.\n // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)\n\n vec3 x = 2.0 * fract( p * C.www ) - 1.0;\n vec3 h = abs( x ) - 0.5;\n vec3 ox = floor( x + 0.5 );\n vec3 a0 = x - ox;\n\n // Normalise gradients implicitly by scaling m\n // Approximation of: m *= inversesqrt( a0*a0 + h*h );\n m *= 1.79284291400159 - 0.85373472095314 * ( a0 * a0 + h * h );\n\n // Compute final noise value at P\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot( m, g );\n\n}\n"; // eslint-disable-line
3532
3532
 
3533
- var noise_simplex_3D = "#define GLSLIFY 1\nfloat simplex(vec3 v){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);m=m*m;return 42.0*dot(m*m,vec4(dot(p0,x0),dot(p1,x1),dot(p2,x2),dot(p3,x3)));}"; // eslint-disable-line
3533
+ var noise_simplex_3D = "#define GLSLIFY 1\n//\n// Description : Array and textureless GLSL 2D/3D/4D simplex\n// noise functions.\n// Author : Ian McEwan, Ashima Arts.\n// Maintainer : stegu\n// Lastmod : 20110822 (ijm)\n// License : Copyright (C) 2011 Ashima Arts. All rights reserved.\n// Distributed under the MIT License. See LICENSE file.\n// https://github.com/ashima/webgl-noise\n// https://github.com/stegu/webgl-noise\n//\n\nfloat simplex( vec3 v ) {\n\n const vec2 C = vec2( 1.0 / 6.0, 1.0 / 3.0 );\n const vec4 D = vec4( 0.0, 0.5, 1.0, 2.0 );\n\n // First corner\n vec3 i = floor( v + dot( v, C.yyy ) );\n vec3 x0 = v - i + dot( i, C.xxx );\n\n // Other corners\n vec3 g = step( x0.yzx, x0.xyz );\n vec3 l = 1.0 - g;\n vec3 i1 = min( g.xyz, l.zxy );\n vec3 i2 = max( g.xyz, l.zxy );\n\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y\n vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y\n\n // Permutations\n i = mod289( i );\n vec4 p = permute( permute( permute(\n i.z + vec4(0.0, i1.z, i2.z, 1.0 ))\n + i.y + vec4(0.0, i1.y, i2.y, 1.0 ))\n + i.x + vec4(0.0, i1.x, i2.x, 1.0 ));\n\n // Gradients: 7x7 points over a square, mapped onto an octahedron.\n // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)\n float n_ = 0.142857142857; // 1.0/7.0\n vec3 ns = n_ * D.wyz - D.xzx;\n\n vec4 j = p - 49.0 * floor( p * ns.z * ns.z ); // mod(p,7*7)\n\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)\n\n vec4 x = x_ *ns.x + ns.yyyy;\n vec4 y = y_ *ns.x + ns.yyyy;\n vec4 h = 1.0 - abs( x ) - abs( y );\n\n vec4 b0 = vec4( x.xy, y.xy );\n vec4 b1 = vec4( x.zw, y.zw );\n\n vec4 s0 = floor( b0 ) * 2.0 + 1.0;\n vec4 s1 = floor( b1 ) * 2.0 + 1.0;\n vec4 sh = - step( h, vec4( 0.0 ) );\n\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy ;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww ;\n\n vec3 p0 = vec3( a0.xy, h.x );\n vec3 p1 = vec3( a0.zw, h.y );\n vec3 p2 = vec3( a1.xy, h.z );\n vec3 p3 = vec3( a1.zw, h.w );\n\n //Normalise gradients\n vec4 norm = taylorInvSqrt( vec4( dot( p0, p0 ), dot( p1, p1 ), dot( p2, p2 ), dot( p3, p3 ) ) );\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n\n // Mix final noise value\n vec4 m = max( 0.6 - vec4( dot( x0, x0 ), dot( x1, x1 ), dot( x2, x2 ), dot( x3, x3 ) ), 0.0 );\n m = m * m;\n return 42.0 * dot( m*m, vec4( dot( p0, x0 ), dot( p1, x1 ),\n dot( p2, x2 ), dot( p3, x3 ) ) );\n\n}\n"; // eslint-disable-line
3534
3534
 
3535
- 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
3535
+ var noise_simplex_3D_grad = "#define GLSLIFY 1\n//\n// Description : Array and textureless GLSL 2D/3D/4D simplex\n// noise functions.\n// Author : Ian McEwan, Ashima Arts.\n// Maintainer : stegu\n// Lastmod : 20150104 (JcBernack)\n// License : Copyright (C) 2011 Ashima Arts. All rights reserved.\n// Distributed under the MIT License. See LICENSE file.\n// https://github.com/ashima/webgl-noise\n// https://github.com/stegu/webgl-noise\n//\n\nfloat simplex( vec3 v, out vec3 gradient ) {\n\n const vec2 C = vec2( 1.0 / 6.0, 1.0 / 3.0 );\n const vec4 D = vec4( 0.0, 0.5, 1.0, 2.0 );\n\n // First corner\n vec3 i = floor( v + dot( v, C.yyy ) );\n vec3 x0 = v - i + dot( i, C.xxx ) ;\n\n // Other corners\n vec3 g = step( x0.yzx, x0.xyz );\n vec3 l = 1.0 - g;\n vec3 i1 = min( g.xyz, l.zxy );\n vec3 i2 = max( g.xyz, l.zxy );\n\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y\n vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y\n\n // Permutations\n i = mod289( i );\n vec4 p = permute( permute( permute(\n i.z + vec4( 0.0, i1.z, i2.z, 1.0 ) )\n + i.y + vec4( 0.0, i1.y, i2.y, 1.0 ) )\n + i.x + vec4( 0.0, i1.x, i2.x, 1.0 ) );\n\n // Gradients: 7x7 points over a square, mapped onto an octahedron.\n // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)\n float n_ = 0.142857142857; // 1.0/7.0\n vec3 ns = n_ * D.wyz - D.xzx;\n\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)\n\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)\n\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs( x ) - abs( y );\n\n vec4 b0 = vec4( x.xy, y.xy );\n vec4 b1 = vec4( x.zw, y.zw );\n\n vec4 s0 = floor( b0 ) * 2.0 + 1.0;\n vec4 s1 = floor( b1 ) * 2.0 + 1.0;\n vec4 sh = - step( h, vec4( 0.0 ) );\n\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy ;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww ;\n\n vec3 p0 = vec3( a0.xy, h.x );\n vec3 p1 = vec3( a0.zw, h.y );\n vec3 p2 = vec3( a1.xy, h.z );\n vec3 p3 = vec3( a1.zw, h.w );\n\n //Normalise gradients\n vec4 norm = taylorInvSqrt( vec4( dot( p0, p0 ), dot( p1, p1 ), dot( p2, p2 ), dot( p3, p3 ) ) );\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n\n // Mix final noise value\n vec4 m = max( 0.6 - vec4( dot( x0, x0 ), dot( x1, x1 ), dot( x2, x2 ), dot( x3, x3 ) ), 0.0 );\n vec4 m2 = m * m;\n vec4 m4 = m2 * m2;\n vec4 pdotx = vec4( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 ), dot( p3, x3 ) );\n\n // Determine noise gradient\n vec4 temp = m2 * m * pdotx;\n gradient = - 8.0 * ( temp.x * x0 + temp.y * x1 + temp.z * x2 + temp.w * x3 );\n gradient += m4.x * p0 + m4.y * p1 + m4.z * p2 + m4.w * p3;\n gradient *= 42.0;\n\n return 42.0 * dot( m4, pdotx );\n\n}\n"; // eslint-disable-line
3536
3536
 
3537
- 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
3537
+ var noise_simplex_4D = "#define GLSLIFY 1\n//\n// Description : Array and textureless GLSL 2D/3D/4D simplex\n// noise functions.\n// Author : Ian McEwan, Ashima Arts.\n// Maintainer : stegu\n// Lastmod : 20110822 (ijm)\n// License : Copyright (C) 2011 Ashima Arts. All rights reserved.\n// Distributed under the MIT License. See LICENSE file.\n// https://github.com/ashima/webgl-noise\n// https://github.com/stegu/webgl-noise\n//\n\nvec4 grad4( float j, vec4 ip ) {\n\n const vec4 ones = vec4( 1.0, 1.0, 1.0, -1.0 );\n vec4 p, s;\n\n p.xyz = floor( fract( vec3( j ) * ip.xyz ) * 7.0 ) * ip.z - 1.0;\n p.w = 1.5 - dot( abs( p.xyz ), ones.xyz );\n s = vec4( lessThan( p, vec4( 0.0 ) ) );\n p.xyz = p.xyz + ( s.xyz * 2.0 - 1.0 ) * s.www;\n\n return p;\n\n}\n\n// (sqrt(5) - 1)/4 = F4, used once below\n#define F4 0.309016994374947451\n\nfloat simplex(vec4 v) {\n\n const vec4 C = vec4( 0.138196601125011, // (5 - sqrt(5))/20 G4\n 0.276393202250021, // 2 * G4\n 0.414589803375032, // 3 * G4\n -0.447213595499958); // -1 + 4 * G4\n\n // First corner\n vec4 i = floor( v + dot( v, vec4( F4 ) ) );\n vec4 x0 = v - i + dot( i, C.xxxx );\n\n // Other corners\n\n // Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI)\n vec4 i0;\n vec3 isX = step( x0.yzw, x0.xxx );\n vec3 isYZ = step( x0.zww, x0.yyz );\n i0.x = isX.x + isX.y + isX.z;\n i0.yzw = 1.0 - isX;\n i0.y += isYZ.x + isYZ.y;\n i0.zw += 1.0 - isYZ.xy;\n i0.z += isYZ.z;\n i0.w += 1.0 - isYZ.z;\n\n vec4 i3 = clamp( i0, 0.0, 1.0 );\n vec4 i2 = clamp( i0 - 1.0, 0.0, 1.0 );\n vec4 i1 = clamp( i0 - 2.0, 0.0, 1.0 );\n\n vec4 x1 = x0 - i1 + C.xxxx;\n vec4 x2 = x0 - i2 + C.yyyy;\n vec4 x3 = x0 - i3 + C.zzzz;\n vec4 x4 = x0 + C.wwww;\n\n // Permutations\n i = mod289( i );\n float j0 = permute( permute( permute( permute( i.w ) + i.z ) + i.y ) + i.x );\n vec4 j1 = permute( permute( permute( permute (\n i.w + vec4(i1.w, i2.w, i3.w, 1.0 ))\n + i.z + vec4(i1.z, i2.z, i3.z, 1.0 ))\n + i.y + vec4(i1.y, i2.y, i3.y, 1.0 ))\n + i.x + vec4(i1.x, i2.x, i3.x, 1.0 ));\n\n // Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope\n // 7*7*6 = 294, which is close to the ring size 17*17 = 289.\n vec4 ip = vec4( 1.0 / 294.0, 1.0 / 49.0, 1.0 / 7.0, 0.0 );\n\n vec4 p0 = grad4(j0, ip);\n vec4 p1 = grad4(j1.x, ip);\n vec4 p2 = grad4(j1.y, ip);\n vec4 p3 = grad4(j1.z, ip);\n vec4 p4 = grad4(j1.w, ip);\n\n // Normalise gradients\n vec4 norm = taylorInvSqrt( vec4( dot( p0, p0 ), dot( p1, p1 ), dot( p2, p2 ), dot( p3, p3 ) ) );\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n p4 *= taylorInvSqrt( dot( p4, p4 ) );\n\n // Mix contributions from the five corners\n vec3 m0 = max( 0.6 - vec3( dot( x0, x0 ), dot( x1, x1 ), dot( x2, x2 ) ), 0.0 );\n vec2 m1 = max( 0.6 - vec2( dot( x3, x3 ), dot( x4, x4 ) ), 0.0 );\n m0 = m0 * m0;\n m1 = m1 * m1;\n return 49.0 * ( dot(m0*m0, vec3( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 )))\n + dot(m1*m1, vec2( dot( p3, x3 ), dot( p4, x4 ) ) ) ) ;\n\n}\n"; // eslint-disable-line
3538
3538
 
3539
- 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
3539
+ var pbr_frag_define = "#define GLSLIFY 1\n#define MIN_PERCEPTUAL_ROUGHNESS 0.045\n#define MIN_ROUGHNESS 0.002025\n\nuniform float material_AlphaCutoff;\nuniform vec4 material_BaseColor;\nuniform float material_Metal;\nuniform float material_Roughness;\nuniform float material_IOR;\nuniform vec3 material_PBRSpecularColor;\nuniform float material_Glossiness;\nuniform vec3 material_EmissiveColor;\nuniform float material_NormalIntensity;\nuniform float material_OcclusionIntensity;\nuniform float material_OcclusionTextureCoord;\n\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\n uniform float material_ClearCoat;\n uniform float material_ClearCoatRoughness;\n\n #ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\n uniform sampler2D material_ClearCoatTexture;\n #endif\n\n #ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\n uniform sampler2D material_ClearCoatRoughnessTexture;\n #endif\n\n #ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\n uniform sampler2D material_ClearCoatNormalTexture;\n #endif\n#endif\n\n#ifdef MATERIAL_ENABLE_ANISOTROPY\n uniform vec3 material_AnisotropyInfo;\n #ifdef MATERIAL_HAS_ANISOTROPY_TEXTURE\n uniform sampler2D material_AnisotropyTexture;\n #endif\n#endif\n\n// Texture\n#ifdef MATERIAL_HAS_BASETEXTURE\n uniform sampler2D material_BaseTexture;\n#endif\n\n#ifdef MATERIAL_HAS_NORMALTEXTURE\n uniform sampler2D material_NormalTexture;\n#endif\n\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\n uniform sampler2D material_EmissiveTexture;\n#endif\n\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\n uniform sampler2D material_RoughnessMetallicTexture;\n#endif\n\n#ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\n uniform sampler2D material_SpecularGlossinessTexture;\n#endif\n\n#ifdef MATERIAL_HAS_OCCLUSION_TEXTURE\n uniform sampler2D material_OcclusionTexture;\n#endif\n\n// Runtime\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\n\nstruct Geometry {\n vec3 position;\n vec3 normal;\n vec3 viewDir;\n float dotNV;\n \n #ifdef MATERIAL_ENABLE_CLEAR_COAT\n vec3 clearCoatNormal;\n float clearCoatDotNV;\n #endif\n\n #ifdef MATERIAL_ENABLE_ANISOTROPY\n vec3 anisotropicT;\n vec3 anisotropicB;\n vec3 anisotropicN;\n float anisotropy;\n #endif\n};\n\nstruct Material {\n vec3 diffuseColor;\n float roughness;\n vec3 specularColor;\n float opacity;\n float f0;\n #ifdef MATERIAL_ENABLE_CLEAR_COAT\n float clearCoat;\n float clearCoatRoughness;\n #endif\n\n};"; // eslint-disable-line
3540
3540
 
3541
- 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
3541
+ var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\n\nfloat computeSpecularOcclusion(float ambientOcclusion, float roughness, float dotNV ) {\n return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}\n\nfloat getAARoughnessFactor(vec3 normal) {\n // Kaplanyan 2016, \"Stable specular highlights\"\n // Tokuyoshi 2017, \"Error Reduction and Simplification for Shading Anti-Aliasing\"\n // Tokuyoshi and Kaplanyan 2019, \"Improved Geometric Specular Antialiasing\"\n #ifdef HAS_DERIVATIVES\n vec3 dxy = max( abs(dFdx(normal)), abs(dFdy(normal)) );\n return max( max(dxy.x, dxy.y), dxy.z );\n #else\n return 0.0;\n #endif\n}\n\n#ifdef MATERIAL_ENABLE_ANISOTROPY\n // Aniso Bent Normals\n // Mc Alley https://www.gdcvault.com/play/1022235/Rendering-the-World-of-Far \n vec3 getAnisotropicBentNormal(Geometry geometry, vec3 n, float roughness) {\n vec3 anisotropyDirection = geometry.anisotropy >= 0.0 ? geometry.anisotropicB : geometry.anisotropicT;\n vec3 anisotropicTangent = cross(anisotropyDirection, geometry.viewDir);\n vec3 anisotropicNormal = cross(anisotropicTangent, anisotropyDirection);\n // reduce stretching for (roughness < 0.2), refer to https://advances.realtimerendering.com/s2018/Siggraph%202018%20HDRP%20talk_with%20notes.pdf 80\n vec3 bentNormal = normalize( mix(n, anisotropicNormal, abs(geometry.anisotropy) * saturate( 5.0 * roughness)) );\n\n return bentNormal;\n }\n#endif\n\nvoid initGeometry(out Geometry geometry, bool isFrontFacing){\n geometry.position = v_pos;\n #ifdef CAMERA_ORTHOGRAPHIC\n geometry.viewDir = -camera_Forward;\n #else\n geometry.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)\n mat3 tbn = getTBN(isFrontFacing);\n #endif\n\n #ifdef MATERIAL_HAS_NORMALTEXTURE\n geometry.normal = getNormalByNormalTexture(tbn, material_NormalTexture, material_NormalIntensity, v_uv, isFrontFacing);\n #else\n geometry.normal = getNormal(isFrontFacing);\n #endif\n\n geometry.dotNV = saturate( dot(geometry.normal, geometry.viewDir) );\n\n #ifdef MATERIAL_ENABLE_CLEAR_COAT\n #ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\n geometry.clearCoatNormal = getNormalByNormalTexture(tbn, material_ClearCoatNormalTexture, material_NormalIntensity, v_uv, isFrontFacing);\n #else\n geometry.clearCoatNormal = getNormal(isFrontFacing);\n #endif\n geometry.clearCoatDotNV = saturate( dot(geometry.clearCoatNormal, geometry.viewDir) );\n #endif\n\n #ifdef MATERIAL_ENABLE_ANISOTROPY\n float anisotropy = material_AnisotropyInfo.z;\n vec3 anisotropicDirection = vec3(material_AnisotropyInfo.xy, 0.0);\n #ifdef MATERIAL_HAS_ANISOTROPY_TEXTURE\n vec3 anisotropyTextureInfo = texture2D( material_AnisotropyTexture, v_uv ).rgb;\n anisotropy *= anisotropyTextureInfo.b;\n anisotropicDirection.xy *= anisotropyTextureInfo.rg * 2.0 - 1.0;\n #endif\n\n geometry.anisotropy = anisotropy;\n geometry.anisotropicT = normalize(tbn * anisotropicDirection);\n geometry.anisotropicB = normalize(cross(geometry.normal, geometry.anisotropicT));\n #endif\n}\n\nvoid initMaterial(out Material material, inout Geometry geometry){\n vec4 baseColor = material_BaseColor;\n float metal = material_Metal;\n float roughness = material_Roughness;\n vec3 specularColor = material_PBRSpecularColor;\n float glossiness = material_Glossiness;\n float alphaCutoff = material_AlphaCutoff;\n float f0 = pow2( (material_IOR - 1.0) / (material_IOR + 1.0) );\n\n material.f0 = f0;\n\n #ifdef MATERIAL_HAS_BASETEXTURE\n vec4 baseTextureColor = texture2D(material_BaseTexture, v_uv);\n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n baseTextureColor = gammaToLinear(baseTextureColor);\n #endif\n baseColor *= baseTextureColor;\n #endif\n\n #ifdef RENDERER_ENABLE_VERTEXCOLOR\n baseColor *= v_color;\n #endif\n\n #ifdef MATERIAL_IS_ALPHA_CUTOFF\n if( baseColor.a < alphaCutoff ) {\n discard;\n }\n #endif\n\n #ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\n vec4 metalRoughMapColor = texture2D( material_RoughnessMetallicTexture, v_uv );\n roughness *= metalRoughMapColor.g;\n metal *= metalRoughMapColor.b;\n #endif\n\n #ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\n vec4 specularGlossinessColor = texture2D(material_SpecularGlossinessTexture, v_uv );\n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n specularGlossinessColor = gammaToLinear(specularGlossinessColor);\n #endif\n specularColor *= specularGlossinessColor.rgb;\n glossiness *= specularGlossinessColor.a;\n #endif\n\n #ifdef IS_METALLIC_WORKFLOW\n material.diffuseColor = baseColor.rgb * ( 1.0 - metal );\n material.specularColor = mix( vec3(f0), baseColor.rgb, metal );\n material.roughness = roughness;\n #else\n float specularStrength = max( max( specularColor.r, specularColor.g ), specularColor.b );\n material.diffuseColor = baseColor.rgb * ( 1.0 - specularStrength );\n material.specularColor = specularColor;\n material.roughness = 1.0 - glossiness;\n #endif\n\n material.roughness = max(MIN_PERCEPTUAL_ROUGHNESS, min(material.roughness + getAARoughnessFactor(geometry.normal), 1.0));\n\n #ifdef MATERIAL_ENABLE_CLEAR_COAT\n material.clearCoat = material_ClearCoat;\n material.clearCoatRoughness = material_ClearCoatRoughness;\n #ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\n material.clearCoat *= texture2D( material_ClearCoatTexture, v_uv ).r;\n #endif\n #ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\n material.clearCoatRoughness *= texture2D( material_ClearCoatRoughnessTexture, v_uv ).g;\n #endif\n material.clearCoat = saturate( material.clearCoat );\n material.clearCoatRoughness = max(MIN_PERCEPTUAL_ROUGHNESS, min(material.clearCoatRoughness + getAARoughnessFactor(geometry.clearCoatNormal), 1.0));\n #endif\n\n #ifdef MATERIAL_IS_TRANSPARENT\n material.opacity = baseColor.a;\n #else\n material.opacity = 1.0;\n #endif\n #ifdef MATERIAL_ENABLE_ANISOTROPY\n geometry.anisotropicN = getAnisotropicBentNormal(geometry, geometry.normal, material.roughness);\n #endif\n\n}\n\n// direct + indirect\n#include <brdf>\n#include <direct_irradiance_frag_define>\n#include <ibl_frag_define>\n"; // eslint-disable-line
3542
3542
 
3543
- 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
3543
+ var brdf = "#define GLSLIFY 1\nfloat F_Schlick(float f0, float dotLH) {\n\treturn f0 + 0.96 * (pow(1.0 - dotLH, 5.0));\n}\n\nvec3 F_Schlick(vec3 specularColor, float dotLH ) {\n\n\t// Original approximation by Christophe Schlick '94\n\t// float fresnel = pow( 1.0 - dotLH, 5.0 );\n\n\t// Optimized variant (presented by Epic at SIGGRAPH '13)\n\t// https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n\n}\n\n// Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2\n// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf\nfloat G_GGX_SmithCorrelated(float alpha, float dotNL, float dotNV ) {\n\n\tfloat a2 = pow2( alpha );\n\n\t// dotNL and dotNV are explicitly swapped. This is not a mistake.\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\n\treturn 0.5 / max( gv + gl, EPSILON );\n\n}\n\n#ifdef MATERIAL_ENABLE_ANISOTROPY\n // Heitz 2014, \"Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs\"\n // Heitz http://jcgt.org/published/0003/02/03/paper.pdf\n float G_GGX_SmithCorrelated_Anisotropic(float at, float ab, float ToV, float BoV, float ToL, float BoL, float NoV, float NoL) {\n float lambdaV = NoL * length(vec3(at * ToV, ab * BoV, NoV));\n float lambdaL = NoV * length(vec3(at * ToL, ab * BoL, NoL));\n return 0.5 / max(lambdaV + lambdaL, EPSILON);\n }\n#endif\n\n// Microfacet Models for Refraction through Rough Surfaces - equation (33)\n// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html\n// alpha is \"roughness squared\" in Disney’s reparameterization\nfloat D_GGX(float alpha, float dotNH ) {\n\n\tfloat a2 = pow2( alpha );\n\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1\n\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n\n}\n\n#ifdef MATERIAL_ENABLE_ANISOTROPY\n // GGX Distribution Anisotropic\n // https://blog.selfshadow.com/publications/s2012-shading-course/burley/s2012_pbs_disney_brdf_notes_v3.pdf Addenda\n float D_GGX_Anisotropic(float at, float ab, float ToH, float BoH, float NoH) {\n float a2 = at * ab;\n vec3 d = vec3(ab * ToH, at * BoH, a2 * NoH);\n float d2 = dot(d, d);\n float b2 = a2 / d2;\n return a2 * b2 * b2 * RECIPROCAL_PI;\n }\n#endif\n\nvec3 isotropicLobe(vec3 specularColor, float alpha, float dotNV, float dotNL, float dotNH, float dotLH) {\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat D = D_GGX( alpha, dotNH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\n\treturn F * ( G * D );\n}\n\n#ifdef MATERIAL_ENABLE_ANISOTROPY\n vec3 anisotropicLobe(vec3 h, vec3 l, Geometry geometry, vec3 specularColor, float alpha, float dotNV, float dotNL, float dotNH, float dotLH) {\n vec3 t = geometry.anisotropicT;\n vec3 b = geometry.anisotropicB;\n vec3 v = geometry.viewDir;\n\n float dotTV = dot(t, v);\n float dotBV = dot(b, v);\n float dotTL = dot(t, l);\n float dotBL = dot(b, l);\n float dotTH = dot(t, h);\n float dotBH = dot(b, h);\n\n // Aniso parameter remapping\n // https://blog.selfshadow.com/publications/s2017-shading-course/imageworks/s2017_pbs_imageworks_slides_v2.pdf page 24\n float at = max(alpha * (1.0 + geometry.anisotropy), MIN_ROUGHNESS);\n float ab = max(alpha * (1.0 - geometry.anisotropy), MIN_ROUGHNESS);\n\n // specular anisotropic BRDF\n \tvec3 F = F_Schlick( specularColor, dotLH );\n float D = D_GGX_Anisotropic(at, ab, dotTH, dotBH, dotNH);\n float G = G_GGX_SmithCorrelated_Anisotropic(at, ab, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL);\n\n return F * ( G * D );\n }\n#endif\n\n// GGX Distribution, Schlick Fresnel, GGX-Smith Visibility\nvec3 BRDF_Specular_GGX(vec3 incidentDirection, Geometry geometry, vec3 normal, vec3 specularColor, float roughness ) {\n\n\tfloat alpha = pow2( roughness ); // UE4's roughness\n\n\tvec3 halfDir = normalize( incidentDirection + geometry.viewDir );\n\n\tfloat dotNL = saturate( dot( normal, incidentDirection ) );\n\tfloat dotNV = saturate( dot( normal, geometry.viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentDirection, halfDir ) );\n\n #ifdef MATERIAL_ENABLE_ANISOTROPY\n return anisotropicLobe(halfDir, incidentDirection, geometry, specularColor, alpha, dotNV, dotNL, dotNH, dotLH);\n #else\n return isotropicLobe(specularColor, alpha, dotNV, dotNL, dotNH, dotLH);\n #endif\n\n}\n\nvec3 BRDF_Diffuse_Lambert(vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\n"; // eslint-disable-line
3544
3544
 
3545
- 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
3545
+ var direct_irradiance_frag_define = "#define GLSLIFY 1\n#include <ShadowFragmentDeclaration>\n\nvoid addDirectRadiance(vec3 incidentDirection, vec3 color, Geometry geometry, Material material, inout ReflectedLight reflectedLight) {\n float attenuation = 1.0;\n\n #ifdef MATERIAL_ENABLE_CLEAR_COAT\n float clearCoatDotNL = saturate( dot( geometry.clearCoatNormal, incidentDirection ) );\n vec3 clearCoatIrradiance = clearCoatDotNL * color;\n\n reflectedLight.directSpecular += material.clearCoat * clearCoatIrradiance * BRDF_Specular_GGX( incidentDirection, geometry, geometry.clearCoatNormal, vec3( 0.04 ), material.clearCoatRoughness );\n attenuation -= material.clearCoat * F_Schlick(material.f0, geometry.clearCoatDotNV);\n #endif\n\n float dotNL = saturate( dot( geometry.normal, incidentDirection ) );\n vec3 irradiance = dotNL * color * PI;\n\n reflectedLight.directSpecular += attenuation * irradiance * BRDF_Specular_GGX( incidentDirection, geometry, geometry.normal, material.specularColor, material.roughness);\n reflectedLight.directDiffuse += attenuation * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\n}\n\n#ifdef SCENE_DIRECT_LIGHT_COUNT\n\n void addDirectionalDirectLightRadiance(DirectLight directionalLight, Geometry geometry, Material material, inout ReflectedLight reflectedLight) {\n vec3 color = directionalLight.color;\n vec3 direction = -directionalLight.direction;\n\n\t\taddDirectRadiance( direction, color, geometry, material, reflectedLight );\n\n }\n\n#endif\n\n#ifdef SCENE_POINT_LIGHT_COUNT\n\n\tvoid addPointDirectLightRadiance(PointLight pointLight, Geometry geometry, Material material, inout ReflectedLight reflectedLight) {\n\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tvec3 direction = normalize( lVector );\n\n\t\tfloat lightDistance = length( lVector );\n\n\t\tvec3 color = pointLight.color;\n\t\tcolor *= clamp(1.0 - pow(lightDistance/pointLight.distance, 4.0), 0.0, 1.0);\n\n\t\taddDirectRadiance( direction, color, geometry, material, reflectedLight );\n\n\t}\n\n#endif\n\n#ifdef SCENE_SPOT_LIGHT_COUNT\n\n\tvoid addSpotDirectLightRadiance(SpotLight spotLight, Geometry geometry, Material material, inout ReflectedLight reflectedLight) {\n\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tvec3 direction = normalize( lVector );\n\n\t\tfloat lightDistance = length( lVector );\n\t\tfloat angleCos = dot( direction, -spotLight.direction );\n\n\t\tfloat spotEffect = smoothstep( spotLight.penumbraCos, spotLight.angleCos, angleCos );\n\t\tfloat decayEffect = clamp(1.0 - pow(lightDistance/spotLight.distance, 4.0), 0.0, 1.0);\n\n\t\tvec3 color = spotLight.color;\n\t\tcolor *= spotEffect * decayEffect;\n\n\t\taddDirectRadiance( direction, color, geometry, material, reflectedLight );\n\n\t}\n\n#endif\n\nvoid addTotalDirectRadiance(Geometry geometry, Material material, inout ReflectedLight reflectedLight){\n float shadowAttenuation = 1.0;\n\n #ifdef SCENE_DIRECT_LIGHT_COUNT\n shadowAttenuation = 1.0;\n #ifdef SCENE_IS_CALCULATE_SHADOWS\n shadowAttenuation *= sampleShadowMap();\n #endif\n\n DirectLight directionalLight;\n for ( int i = 0; i < SCENE_DIRECT_LIGHT_COUNT; i ++ ) {\n // warning: use `continue` syntax may trigger flickering bug in safri 16.1.\n if(!isRendererCulledByLight(renderer_Layer.xy, scene_DirectLightCullingMask[i])){\n directionalLight.color = scene_DirectLightColor[i];\n #ifdef SCENE_IS_CALCULATE_SHADOWS\n if (i == 0) { // Sun light index is always 0\n directionalLight.color *= shadowAttenuation;\n }\n #endif\n directionalLight.direction = scene_DirectLightDirection[i];\n addDirectionalDirectLightRadiance( directionalLight, geometry, material, reflectedLight );\n }\n }\n\n #endif\n\n #ifdef SCENE_POINT_LIGHT_COUNT\n\n PointLight pointLight;\n\n for ( int i = 0; i < SCENE_POINT_LIGHT_COUNT; i ++ ) {\n if(!isRendererCulledByLight(renderer_Layer.xy, scene_PointLightCullingMask[i])){\n pointLight.color = scene_PointLightColor[i];\n pointLight.position = scene_PointLightPosition[i];\n pointLight.distance = scene_PointLightDistance[i];\n\n addPointDirectLightRadiance( pointLight, geometry, material, reflectedLight );\n } \n }\n\n #endif\n\n #ifdef SCENE_SPOT_LIGHT_COUNT\n\n SpotLight spotLight;\n\n for ( int i = 0; i < SCENE_SPOT_LIGHT_COUNT; i ++ ) {\n if(!isRendererCulledByLight(renderer_Layer.xy, scene_SpotLightCullingMask[i])){\n spotLight.color = scene_SpotLightColor[i];\n spotLight.position = scene_SpotLightPosition[i];\n spotLight.direction = scene_SpotLightDirection[i];\n spotLight.distance = scene_SpotLightDistance[i];\n spotLight.angleCos = scene_SpotLightAngleCos[i];\n spotLight.penumbraCos = scene_SpotLightPenumbraCos[i];\n\n addSpotDirectLightRadiance( spotLight, geometry, material, reflectedLight );\n } \n }\n\n #endif\n}"; // eslint-disable-line
3546
3546
 
3547
- 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
3547
+ var ibl_frag_define = "#define GLSLIFY 1\n// ------------------------Diffuse------------------------\n\n// sh need be pre-scaled in CPU.\nvec3 getLightProbeIrradiance(vec3 sh[9], vec3 normal){\n normal.x = -normal.x;\n vec3 result = sh[0] +\n\n sh[1] * (normal.y) +\n sh[2] * (normal.z) +\n sh[3] * (normal.x) +\n\n sh[4] * (normal.y * normal.x) +\n sh[5] * (normal.y * normal.z) +\n sh[6] * (3.0 * normal.z * normal.z - 1.0) +\n sh[7] * (normal.z * normal.x) +\n sh[8] * (normal.x * normal.x - normal.y * normal.y);\n \n return max(result, vec3(0.0));\n\n}\n\n// ------------------------Specular------------------------\n\n// ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile\nvec3 envBRDFApprox(vec3 specularColor,float roughness, float dotNV ) {\n\n const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\n const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\n vec4 r = roughness * c0 + c1;\n\n float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n\n return specularColor * AB.x + AB.y;\n}\n\nfloat getSpecularMIPLevel(float roughness, int maxMIPLevel ) {\n return roughness * float(maxMIPLevel);\n}\n\nvec3 getReflectedVector(Geometry geometry, vec3 n) {\n #ifdef MATERIAL_ENABLE_ANISOTROPY\n vec3 r = reflect(-geometry.viewDir, geometry.anisotropicN);\n #else\n vec3 r = reflect(-geometry.viewDir, n);\n #endif\n\n return r;\n}\n\nvec3 getLightProbeRadiance(Geometry geometry, vec3 normal, float roughness, int maxMIPLevel, float specularIntensity) {\n\n #ifndef SCENE_USE_SPECULAR_ENV\n return vec3(0);\n #else\n vec3 reflectVec = getReflectedVector(geometry, normal);\n reflectVec.x = -reflectVec.x; // TextureCube is left-hand,so x need inverse\n \n float specularMIPLevel = getSpecularMIPLevel(roughness, maxMIPLevel );\n\n #ifdef HAS_TEX_LOD\n vec4 envMapColor = textureCubeLodEXT( scene_EnvSpecularSampler, reflectVec, specularMIPLevel );\n #else\n vec4 envMapColor = textureCube( scene_EnvSpecularSampler, reflectVec, specularMIPLevel );\n #endif\n\n #ifdef SCENE_IS_DECODE_ENV_RGBM\n envMapColor.rgb = RGBMToLinear(envMapColor, 5.0).rgb;\n #ifdef ENGINE_IS_COLORSPACE_GAMMA\n envMapColor = linearToGamma(envMapColor);\n #endif\n #else\n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n envMapColor = gammaToLinear(envMapColor);\n #endif\n #endif\n \n return envMapColor.rgb * specularIntensity;\n\n #endif\n\n}"; // eslint-disable-line
3548
3548
 
3549
- 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
3549
+ var pbr_frag = "#define GLSLIFY 1\nGeometry geometry;\nMaterial material;\nReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\ninitGeometry(geometry, gl_FrontFacing);\ninitMaterial(material, geometry);\n\n// Direct Light\naddTotalDirectRadiance(geometry, material, reflectedLight);\n\n// IBL diffuse\n#ifdef SCENE_USE_SH\n vec3 irradiance = getLightProbeIrradiance(scene_EnvSH, geometry.normal);\n #ifdef ENGINE_IS_COLORSPACE_GAMMA\n irradiance = linearToGamma(vec4(irradiance, 1.0)).rgb;\n #endif\n irradiance *= scene_EnvMapLight.diffuseIntensity;\n#else\n vec3 irradiance = scene_EnvMapLight.diffuse * scene_EnvMapLight.diffuseIntensity;\n irradiance *= PI;\n#endif\n\nreflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\n// IBL specular\nvec3 radiance = getLightProbeRadiance(geometry, geometry.normal, material.roughness, int(scene_EnvMapLight.mipMapLevel), scene_EnvMapLight.specularIntensity);\nfloat radianceAttenuation = 1.0;\n\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\n vec3 clearCoatRadiance = getLightProbeRadiance( geometry, geometry.clearCoatNormal, material.clearCoatRoughness, int(scene_EnvMapLight.mipMapLevel), scene_EnvMapLight.specularIntensity );\n\n reflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * envBRDFApprox(vec3( 0.04 ), material.clearCoatRoughness, geometry.clearCoatDotNV);\n radianceAttenuation -= material.clearCoat * F_Schlick(material.f0, geometry.clearCoatDotNV);\n#endif\n\nreflectedLight.indirectSpecular += radianceAttenuation * radiance * envBRDFApprox(material.specularColor, material.roughness, geometry.dotNV );\n\n// Occlusion\n#ifdef MATERIAL_HAS_OCCLUSION_TEXTURE\n vec2 aoUV = v_uv;\n #ifdef RENDERER_HAS_UV1\n if(material_OcclusionTextureCoord == 1.0){\n aoUV = v_uv1;\n }\n #endif\n float ambientOcclusion = (texture2D(material_OcclusionTexture, aoUV).r - 1.0) * material_OcclusionIntensity + 1.0;\n reflectedLight.indirectDiffuse *= ambientOcclusion;\n #ifdef SCENE_USE_SPECULAR_ENV\n reflectedLight.indirectSpecular *= computeSpecularOcclusion(ambientOcclusion, material.roughness, geometry.dotNV);\n #endif\n#endif\n\n// Emissive\nvec3 emissiveRadiance = material_EmissiveColor;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\n vec4 emissiveColor = texture2D(material_EmissiveTexture, v_uv);\n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n emissiveColor = gammaToLinear(emissiveColor);\n #endif\n emissiveRadiance *= emissiveColor.rgb;\n#endif\n\n// Total\nvec3 totalRadiance = reflectedLight.directDiffuse + \n reflectedLight.indirectDiffuse + \n reflectedLight.directSpecular + \n reflectedLight.indirectSpecular + \n emissiveRadiance;\n\nvec4 targetColor =vec4(totalRadiance, material.opacity);\ngl_FragColor = targetColor;\n"; // eslint-disable-line
3550
3550
 
3551
3551
  var PBRShaderLib = {
3552
3552
  pbr_frag_define: pbr_frag_define,
@@ -3557,15 +3557,15 @@ var PBRShaderLib = {
3557
3557
  pbr_frag: pbr_frag
3558
3558
  };
3559
3559
 
3560
- var ShadowCoord = "#define GLSLIFY 1\nuniform mat4 scene_ShadowMatrices[SCENE_SHADOW_CASCADED_COUNT+1];uniform vec4 scene_ShadowSplitSpheres[4];mediump int computeCascadeIndex(vec3 positionWS){vec3 fromCenter0=positionWS-scene_ShadowSplitSpheres[0].xyz;vec3 fromCenter1=positionWS-scene_ShadowSplitSpheres[1].xyz;vec3 fromCenter2=positionWS-scene_ShadowSplitSpheres[2].xyz;vec3 fromCenter3=positionWS-scene_ShadowSplitSpheres[3].xyz;mediump vec4 comparison=vec4(dot(fromCenter0,fromCenter0)<scene_ShadowSplitSpheres[0].w,dot(fromCenter1,fromCenter1)<scene_ShadowSplitSpheres[1].w,dot(fromCenter2,fromCenter2)<scene_ShadowSplitSpheres[2].w,dot(fromCenter3,fromCenter3)<scene_ShadowSplitSpheres[3].w);comparison.yzw=clamp(comparison.yzw-comparison.xyz,0.0,1.0);mediump vec4 indexCoefficient=vec4(4.0,3.0,2.0,1.0);mediump int index=4-int(dot(comparison,indexCoefficient));return index;}vec3 getShadowCoord(){\n#if SCENE_SHADOW_CASCADED_COUNT == 1\nmediump int cascadeIndex=0;\n#else\nmediump int cascadeIndex=computeCascadeIndex(v_pos);\n#endif\n#ifdef GRAPHICS_API_WEBGL2\nmat4 shadowMatrix=scene_ShadowMatrices[cascadeIndex];\n#else\nmat4 shadowMatrix;\n#if SCENE_SHADOW_CASCADED_COUNT == 4\nif(cascadeIndex==0){shadowMatrix=scene_ShadowMatrices[0];}else if(cascadeIndex==1){shadowMatrix=scene_ShadowMatrices[1];}else if(cascadeIndex==2){shadowMatrix=scene_ShadowMatrices[2];}else if(cascadeIndex==3){shadowMatrix=scene_ShadowMatrices[3];}else{shadowMatrix=scene_ShadowMatrices[4];}\n#endif\n#if SCENE_SHADOW_CASCADED_COUNT == 2\nif(cascadeIndex==0){shadowMatrix=scene_ShadowMatrices[0];}else if(cascadeIndex==1){shadowMatrix=scene_ShadowMatrices[1];}else{shadowMatrix=scene_ShadowMatrices[2];}\n#endif\n#if SCENE_SHADOW_CASCADED_COUNT == 1\nif(cascadeIndex==0){shadowMatrix=scene_ShadowMatrices[0];}else{shadowMatrix=scene_ShadowMatrices[1];}\n#endif\n#endif\nvec4 shadowCoord=shadowMatrix*vec4(v_pos,1.0);return shadowCoord.xyz;}"; // eslint-disable-line
3560
+ var ShadowCoord = "#define GLSLIFY 1\nuniform mat4 scene_ShadowMatrices[SCENE_SHADOW_CASCADED_COUNT + 1];\nuniform vec4 scene_ShadowSplitSpheres[4];\n\nmediump int computeCascadeIndex(vec3 positionWS) {\n vec3 fromCenter0 = positionWS - scene_ShadowSplitSpheres[0].xyz;\n vec3 fromCenter1 = positionWS - scene_ShadowSplitSpheres[1].xyz;\n vec3 fromCenter2 = positionWS - scene_ShadowSplitSpheres[2].xyz;\n vec3 fromCenter3 = positionWS - scene_ShadowSplitSpheres[3].xyz;\n\n mediump vec4 comparison = vec4(\n dot(fromCenter0, fromCenter0) < scene_ShadowSplitSpheres[0].w,\n dot(fromCenter1, fromCenter1) < scene_ShadowSplitSpheres[1].w,\n dot(fromCenter2, fromCenter2) < scene_ShadowSplitSpheres[2].w,\n dot(fromCenter3, fromCenter3) < scene_ShadowSplitSpheres[3].w);\n comparison.yzw = clamp(comparison.yzw - comparison.xyz,0.0,1.0);//keep the nearest\n mediump vec4 indexCoefficient = vec4(4.0,3.0,2.0,1.0);\n mediump int index = 4 - int(dot(comparison, indexCoefficient));\n return index;\n}\n\nvec3 getShadowCoord() {\n #if SCENE_SHADOW_CASCADED_COUNT == 1\n mediump int cascadeIndex = 0;\n #else\n mediump int cascadeIndex = computeCascadeIndex(v_pos);\n #endif\n\n #ifdef GRAPHICS_API_WEBGL2\n mat4 shadowMatrix = scene_ShadowMatrices[cascadeIndex];\n #else\n mat4 shadowMatrix;\n #if SCENE_SHADOW_CASCADED_COUNT == 4\n if (cascadeIndex == 0) {\n shadowMatrix = scene_ShadowMatrices[0];\n } else if (cascadeIndex == 1) {\n shadowMatrix = scene_ShadowMatrices[1];\n } else if (cascadeIndex == 2) {\n shadowMatrix = scene_ShadowMatrices[2];\n } else if (cascadeIndex == 3) {\n shadowMatrix = scene_ShadowMatrices[3];\n } else {\n shadowMatrix = scene_ShadowMatrices[4];\n }\n #endif\n #if SCENE_SHADOW_CASCADED_COUNT == 2\n if (cascadeIndex == 0) {\n shadowMatrix = scene_ShadowMatrices[0];\n } else if (cascadeIndex == 1) {\n shadowMatrix = scene_ShadowMatrices[1];\n } else {\n shadowMatrix = scene_ShadowMatrices[2];\n } \n #endif\n #if SCENE_SHADOW_CASCADED_COUNT == 1\n if (cascadeIndex == 0) {\n shadowMatrix = scene_ShadowMatrices[0];\n } else {\n shadowMatrix = scene_ShadowMatrices[1];\n } \n #endif\n #endif\n\n vec4 shadowCoord = shadowMatrix * vec4(v_pos, 1.0);\n return shadowCoord.xyz;\n}\n"; // eslint-disable-line
3561
3561
 
3562
- var ShadowFragmentDeclaration = "#define GLSLIFY 1\n#if defined(SCENE_SHADOW_TYPE) && defined(RENDERER_IS_RECEIVE_SHADOWS)\n#define SCENE_IS_CALCULATE_SHADOWS\n#endif\n#ifdef SCENE_IS_CALCULATE_SHADOWS\n#if SCENE_SHADOW_CASCADED_COUNT == 1\nvarying vec3 v_shadowCoord;\n#else\n#include <ShadowCoord>\n#endif\nuniform vec4 scene_ShadowInfo;uniform vec4 scene_ShadowMapSize;\n#ifdef GRAPHICS_API_WEBGL2\nuniform mediump sampler2DShadow scene_ShadowMap;\n#define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) textureLod(textureName, coord3 , 0.0)\n#define TEXTURE2D_SHADOW_PARAM(shadowMap) mediump sampler2DShadow shadowMap\n#else\nuniform sampler2D scene_ShadowMap;\n#ifdef ENGINE_NO_DEPTH_TEXTURE\nconst vec4 bitShift=vec4(1.0,1.0/256.0,1.0/(256.0*256.0),1.0/(256.0*256.0*256.0));float unpack(const in vec4 rgbaDepth){return dot(rgbaDepth,bitShift);}\n#define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) (unpack(texture2D(textureName, coord3.xy)) < coord3.z ? 0.0 : 1.0)\n#else\n#define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) (texture2D(textureName, coord3.xy).r < coord3.z ? 0.0 : 1.0)\n#endif\n#define TEXTURE2D_SHADOW_PARAM(shadowMap) mediump sampler2D shadowMap\n#endif\n#if SCENE_SHADOW_TYPE == 2\nfloat sampleShadowMapFiltered4(TEXTURE2D_SHADOW_PARAM(shadowMap),vec3 shadowCoord,vec4 shadowMapSize){float attenuation;vec4 attenuation4;vec2 offset=shadowMapSize.xy/2.0;vec3 shadowCoord0=shadowCoord+vec3(-offset,0.0);vec3 shadowCoord1=shadowCoord+vec3(offset.x,-offset.y,0.0);vec3 shadowCoord2=shadowCoord+vec3(-offset.x,offset.y,0.0);vec3 shadowCoord3=shadowCoord+vec3(offset,0.0);attenuation4.x=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord0);attenuation4.y=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord1);attenuation4.z=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord2);attenuation4.w=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord3);attenuation=dot(attenuation4,vec4(0.25));return attenuation;}\n#endif\n#if SCENE_SHADOW_TYPE == 3\n#include <shadow_sample_tent>\nfloat sampleShadowMapFiltered9(TEXTURE2D_SHADOW_PARAM(shadowMap),vec3 shadowCoord,vec4 shadowmapSize){float attenuation;float fetchesWeights[9];vec2 fetchesUV[9];sampleShadowComputeSamplesTent5x5(shadowmapSize,shadowCoord.xy,fetchesWeights,fetchesUV);attenuation=fetchesWeights[0]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[0].xy,shadowCoord.z));attenuation+=fetchesWeights[1]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[1].xy,shadowCoord.z));attenuation+=fetchesWeights[2]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[2].xy,shadowCoord.z));attenuation+=fetchesWeights[3]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[3].xy,shadowCoord.z));attenuation+=fetchesWeights[4]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[4].xy,shadowCoord.z));attenuation+=fetchesWeights[5]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[5].xy,shadowCoord.z));attenuation+=fetchesWeights[6]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[6].xy,shadowCoord.z));attenuation+=fetchesWeights[7]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[7].xy,shadowCoord.z));attenuation+=fetchesWeights[8]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[8].xy,shadowCoord.z));return attenuation;}\n#endif\nfloat getShadowFade(vec3 positionWS){vec3 camToPixel=positionWS-camera_Position;float distanceCamToPixel2=dot(camToPixel,camToPixel);return saturate(distanceCamToPixel2*scene_ShadowInfo.z+scene_ShadowInfo.w);}float sampleShadowMap(){\n#if SCENE_SHADOW_CASCADED_COUNT == 1\nvec3 shadowCoord=v_shadowCoord;\n#else\nvec3 shadowCoord=getShadowCoord();\n#endif\nfloat attenuation=1.0;if(shadowCoord.z>0.0&&shadowCoord.z<1.0){\n#if SCENE_SHADOW_TYPE == 1\nattenuation=SAMPLE_TEXTURE2D_SHADOW(scene_ShadowMap,shadowCoord);\n#endif\n#if SCENE_SHADOW_TYPE == 2\nattenuation=sampleShadowMapFiltered4(scene_ShadowMap,shadowCoord,scene_ShadowMapSize);\n#endif\n#if SCENE_SHADOW_TYPE == 3\nattenuation=sampleShadowMapFiltered9(scene_ShadowMap,shadowCoord,scene_ShadowMapSize);\n#endif\nfloat shadowFade=getShadowFade(v_pos);attenuation=mix(1.0,mix(attenuation,1.0,shadowFade),scene_ShadowInfo.x);}return attenuation;}\n#endif\n"; // eslint-disable-line
3562
+ var ShadowFragmentDeclaration = "#define GLSLIFY 1\n#if defined(SCENE_SHADOW_TYPE) && defined(RENDERER_IS_RECEIVE_SHADOWS)\n #define SCENE_IS_CALCULATE_SHADOWS\n#endif\n\n#ifdef SCENE_IS_CALCULATE_SHADOWS\n #if SCENE_SHADOW_CASCADED_COUNT == 1\n varying vec3 v_shadowCoord;\n #else\n #include <ShadowCoord>\n #endif\n \n // intensity, null, fadeScale, fadeBias\n uniform vec4 scene_ShadowInfo;\n uniform vec4 scene_ShadowMapSize;\n\n #ifdef GRAPHICS_API_WEBGL2\n uniform mediump sampler2DShadow scene_ShadowMap;\n #define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) textureLod(textureName, coord3 , 0.0)\n #define TEXTURE2D_SHADOW_PARAM(shadowMap) mediump sampler2DShadow shadowMap\n #else\n uniform sampler2D scene_ShadowMap;\n #ifdef ENGINE_NO_DEPTH_TEXTURE\n const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0*256.0), 1.0/(256.0*256.0*256.0));\n /**\n * Unpack depth value.\n */\n float unpack(const in vec4 rgbaDepth) {\n return dot(rgbaDepth, bitShift);\n }\n #define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) (unpack(texture2D(textureName, coord3.xy)) < coord3.z ? 0.0 : 1.0)\n #else\n #define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) (texture2D(textureName, coord3.xy).r < coord3.z ? 0.0 : 1.0)\n #endif\n #define TEXTURE2D_SHADOW_PARAM(shadowMap) mediump sampler2D shadowMap\n #endif\n\n #if SCENE_SHADOW_TYPE == 2\n float sampleShadowMapFiltered4(TEXTURE2D_SHADOW_PARAM(shadowMap), vec3 shadowCoord, vec4 shadowMapSize) {\n float attenuation;\n vec4 attenuation4;\n vec2 offset=shadowMapSize.xy/2.0;\n vec3 shadowCoord0=shadowCoord + vec3(-offset,0.0);\n vec3 shadowCoord1=shadowCoord + vec3(offset.x,-offset.y,0.0);\n vec3 shadowCoord2=shadowCoord + vec3(-offset.x,offset.y,0.0);\n vec3 shadowCoord3=shadowCoord + vec3(offset,0.0);\n attenuation4.x = SAMPLE_TEXTURE2D_SHADOW(shadowMap, shadowCoord0);\n attenuation4.y = SAMPLE_TEXTURE2D_SHADOW(shadowMap, shadowCoord1);\n attenuation4.z = SAMPLE_TEXTURE2D_SHADOW(shadowMap, shadowCoord2);\n attenuation4.w = SAMPLE_TEXTURE2D_SHADOW(shadowMap, shadowCoord3);\n attenuation = dot(attenuation4, vec4(0.25));\n return attenuation;\n }\n #endif\n\n #if SCENE_SHADOW_TYPE == 3\n #include <shadow_sample_tent>\n\n float sampleShadowMapFiltered9(TEXTURE2D_SHADOW_PARAM(shadowMap), vec3 shadowCoord, vec4 shadowmapSize) {\n float attenuation;\n float fetchesWeights[9];\n vec2 fetchesUV[9];\n sampleShadowComputeSamplesTent5x5(shadowmapSize, shadowCoord.xy, fetchesWeights, fetchesUV);\n attenuation = fetchesWeights[0] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[0].xy, shadowCoord.z));\n attenuation += fetchesWeights[1] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[1].xy, shadowCoord.z));\n attenuation += fetchesWeights[2] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[2].xy, shadowCoord.z));\n attenuation += fetchesWeights[3] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[3].xy, shadowCoord.z));\n attenuation += fetchesWeights[4] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[4].xy, shadowCoord.z));\n attenuation += fetchesWeights[5] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[5].xy, shadowCoord.z));\n attenuation += fetchesWeights[6] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[6].xy, shadowCoord.z));\n attenuation += fetchesWeights[7] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[7].xy, shadowCoord.z));\n attenuation += fetchesWeights[8] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[8].xy, shadowCoord.z));\n return attenuation;\n }\n #endif\n\n float getShadowFade(vec3 positionWS){\n vec3 camToPixel = positionWS - camera_Position;\n float distanceCamToPixel2 = dot(camToPixel, camToPixel);\n return saturate( distanceCamToPixel2 * scene_ShadowInfo.z + scene_ShadowInfo.w );\n }\n\n float sampleShadowMap() {\n #if SCENE_SHADOW_CASCADED_COUNT == 1\n vec3 shadowCoord = v_shadowCoord;\n #else\n vec3 shadowCoord = getShadowCoord();\n #endif\n \n float attenuation = 1.0;\n if(shadowCoord.z > 0.0 && shadowCoord.z < 1.0) {\n #if SCENE_SHADOW_TYPE == 1\n attenuation = SAMPLE_TEXTURE2D_SHADOW(scene_ShadowMap, shadowCoord);\n #endif\n\n #if SCENE_SHADOW_TYPE == 2\n attenuation = sampleShadowMapFiltered4(scene_ShadowMap, shadowCoord, scene_ShadowMapSize);\n #endif\n\n #if SCENE_SHADOW_TYPE == 3\n attenuation = sampleShadowMapFiltered9(scene_ShadowMap, shadowCoord, scene_ShadowMapSize);\n #endif\n\n float shadowFade = getShadowFade(v_pos);\n attenuation = mix(1.0, mix(attenuation, 1.0, shadowFade), scene_ShadowInfo.x);\n }\n return attenuation;\n }\n#endif"; // eslint-disable-line
3563
3563
 
3564
- var shadow_sample_tent = "#define GLSLIFY 1\nfloat sampleShadowGetIRTriangleTexelArea(float triangleHeight){return triangleHeight-0.5;}void sampleShadowGetTexelAreasTent3x3(float offset,out vec4 computedArea,out vec4 computedAreaUncut){float a=offset+0.5;float offsetSquaredHalved=a*a*0.5;computedAreaUncut.x=computedArea.x=offsetSquaredHalved-offset;computedAreaUncut.w=computedArea.w=offsetSquaredHalved;computedAreaUncut.y=sampleShadowGetIRTriangleTexelArea(1.5-offset);float clampedOffsetLeft=min(offset,0.0);float areaOfSmallLeftTriangle=clampedOffsetLeft*clampedOffsetLeft;computedArea.y=computedAreaUncut.y-areaOfSmallLeftTriangle;computedAreaUncut.z=sampleShadowGetIRTriangleTexelArea(1.5+offset);float clampedOffsetRight=max(offset,0.0);float areaOfSmallRightTriangle=clampedOffsetRight*clampedOffsetRight;computedArea.z=computedAreaUncut.z-areaOfSmallRightTriangle;}void sampleShadowGetTexelWeightsTent5x5(float offset,out vec3 texelsWeightsA,out vec3 texelsWeightsB){vec4 areaFrom3texelTriangle;vec4 areaUncutFrom3texelTriangle;sampleShadowGetTexelAreasTent3x3(offset,areaFrom3texelTriangle,areaUncutFrom3texelTriangle);texelsWeightsA.x=0.16*(areaFrom3texelTriangle.x);texelsWeightsA.y=0.16*(areaUncutFrom3texelTriangle.y);texelsWeightsA.z=0.16*(areaFrom3texelTriangle.y+1.0);texelsWeightsB.x=0.16*(areaFrom3texelTriangle.z+1.0);texelsWeightsB.y=0.16*(areaUncutFrom3texelTriangle.z);texelsWeightsB.z=0.16*(areaFrom3texelTriangle.w);}void sampleShadowComputeSamplesTent5x5(vec4 shadowMapTextureTexelSize,vec2 coord,out float fetchesWeights[9],out vec2 fetchesUV[9]){vec2 tentCenterInTexelSpace=coord.xy*shadowMapTextureTexelSize.zw;vec2 centerOfFetchesInTexelSpace=floor(tentCenterInTexelSpace+0.5);vec2 offsetFromTentCenterToCenterOfFetches=tentCenterInTexelSpace-centerOfFetchesInTexelSpace;vec3 texelsWeightsUA,texelsWeightsUB;vec3 texelsWeightsVA,texelsWeightsVB;sampleShadowGetTexelWeightsTent5x5(offsetFromTentCenterToCenterOfFetches.x,texelsWeightsUA,texelsWeightsUB);sampleShadowGetTexelWeightsTent5x5(offsetFromTentCenterToCenterOfFetches.y,texelsWeightsVA,texelsWeightsVB);vec3 fetchesWeightsU=vec3(texelsWeightsUA.xz,texelsWeightsUB.y)+vec3(texelsWeightsUA.y,texelsWeightsUB.xz);vec3 fetchesWeightsV=vec3(texelsWeightsVA.xz,texelsWeightsVB.y)+vec3(texelsWeightsVA.y,texelsWeightsVB.xz);vec3 fetchesOffsetsU=vec3(texelsWeightsUA.y,texelsWeightsUB.xz)/fetchesWeightsU.xyz+vec3(-2.5,-0.5,1.5);vec3 fetchesOffsetsV=vec3(texelsWeightsVA.y,texelsWeightsVB.xz)/fetchesWeightsV.xyz+vec3(-2.5,-0.5,1.5);fetchesOffsetsU*=shadowMapTextureTexelSize.xxx;fetchesOffsetsV*=shadowMapTextureTexelSize.yyy;vec2 bilinearFetchOrigin=centerOfFetchesInTexelSpace*shadowMapTextureTexelSize.xy;fetchesUV[0]=bilinearFetchOrigin+vec2(fetchesOffsetsU.x,fetchesOffsetsV.x);fetchesUV[1]=bilinearFetchOrigin+vec2(fetchesOffsetsU.y,fetchesOffsetsV.x);fetchesUV[2]=bilinearFetchOrigin+vec2(fetchesOffsetsU.z,fetchesOffsetsV.x);fetchesUV[3]=bilinearFetchOrigin+vec2(fetchesOffsetsU.x,fetchesOffsetsV.y);fetchesUV[4]=bilinearFetchOrigin+vec2(fetchesOffsetsU.y,fetchesOffsetsV.y);fetchesUV[5]=bilinearFetchOrigin+vec2(fetchesOffsetsU.z,fetchesOffsetsV.y);fetchesUV[6]=bilinearFetchOrigin+vec2(fetchesOffsetsU.x,fetchesOffsetsV.z);fetchesUV[7]=bilinearFetchOrigin+vec2(fetchesOffsetsU.y,fetchesOffsetsV.z);fetchesUV[8]=bilinearFetchOrigin+vec2(fetchesOffsetsU.z,fetchesOffsetsV.z);fetchesWeights[0]=fetchesWeightsU.x*fetchesWeightsV.x;fetchesWeights[1]=fetchesWeightsU.y*fetchesWeightsV.x;fetchesWeights[2]=fetchesWeightsU.z*fetchesWeightsV.x;fetchesWeights[3]=fetchesWeightsU.x*fetchesWeightsV.y;fetchesWeights[4]=fetchesWeightsU.y*fetchesWeightsV.y;fetchesWeights[5]=fetchesWeightsU.z*fetchesWeightsV.y;fetchesWeights[6]=fetchesWeightsU.x*fetchesWeightsV.z;fetchesWeights[7]=fetchesWeightsU.y*fetchesWeightsV.z;fetchesWeights[8]=fetchesWeightsU.z*fetchesWeightsV.z;}"; // eslint-disable-line
3564
+ var shadow_sample_tent = "#define GLSLIFY 1\n// ------------------------------------------------------------------\n// PCF Filtering Tent Functions\n// ------------------------------------------------------------------\n\n// Assuming a isoceles right angled triangle of height \"triangleHeight\" (as drawn below).\n// This function return the area of the triangle above the first texel(in Y the first texel).\n//\n// |\\ <-- 45 degree slop isosceles right angled triangle\n// | \\\n// ---- <-- length of this side is \"triangleHeight\"\n// _ _ _ _ <-- texels\nfloat sampleShadowGetIRTriangleTexelArea(float triangleHeight) {\n return triangleHeight - 0.5;\n}\n\n// Assuming a isoceles triangle of 1.5 texels height and 3 texels wide lying on 4 texels.\n// This function return the area of the triangle above each of those texels.\n// | <-- offset from -0.5 to 0.5, 0 meaning triangle is exactly in the center\n// / \\ <-- 45 degree slop isosceles triangle (ie tent projected in 2D)\n// / \\\n// _ _ _ _ <-- texels\n// X Y Z W <-- result indices (in computedArea.xyzw and computedAreaUncut.xyzw)\n// Top point at (right,top) in a texel,left bottom point at (middle,middle) in a texel,right bottom point at (middle,middle) in a texel.\nvoid sampleShadowGetTexelAreasTent3x3(float offset, out vec4 computedArea, out vec4 computedAreaUncut) {\n // Compute the exterior areas,a and h is same.\n float a = offset + 0.5;\n float offsetSquaredHalved = a * a * 0.5;\n computedAreaUncut.x = computedArea.x = offsetSquaredHalved - offset;\n computedAreaUncut.w = computedArea.w = offsetSquaredHalved;\n\n // Compute the middle areas\n // For Y : We find the area in Y of as if the left section of the isoceles triangle would\n // intersect the axis between Y and Z (ie where offset = 0).\n computedAreaUncut.y = sampleShadowGetIRTriangleTexelArea(1.5 - offset);\n // This area is superior to the one we are looking for if (offset < 0) thus we need to\n // subtract the area of the triangle defined by (0,1.5-offset), (0,1.5+offset), (-offset,1.5).\n float clampedOffsetLeft = min(offset,0.0);\n float areaOfSmallLeftTriangle = clampedOffsetLeft * clampedOffsetLeft;\n computedArea.y = computedAreaUncut.y - areaOfSmallLeftTriangle;\n\n // We do the same for the Z but with the right part of the isoceles triangle\n computedAreaUncut.z = sampleShadowGetIRTriangleTexelArea(1.5 + offset);\n float clampedOffsetRight = max(offset,0.0);\n float areaOfSmallRightTriangle = clampedOffsetRight * clampedOffsetRight;\n computedArea.z = computedAreaUncut.z - areaOfSmallRightTriangle;\n}\n\n// Assuming a isoceles triangle of 2.5 texel height and 5 texels wide lying on 6 texels.\n// This function return the weight of each texels area relative to the full triangle area.\n// / \\\n// _ _ _ _ _ _ <-- texels\n// 0 1 2 3 4 5 <-- computed area indices (in texelsWeights[])\n// Top point at (right,top) in a texel,left bottom point at (middle,middle) in a texel,right bottom point at (middle,middle) in a texel.\nvoid sampleShadowGetTexelWeightsTent5x5(float offset, out vec3 texelsWeightsA, out vec3 texelsWeightsB) {\n vec4 areaFrom3texelTriangle;\n vec4 areaUncutFrom3texelTriangle;\n sampleShadowGetTexelAreasTent3x3(offset, areaFrom3texelTriangle, areaUncutFrom3texelTriangle);\n\n // Triangle slope is 45 degree thus we can almost reuse the result of the 3 texel wide computation.\n // the 5 texel wide triangle can be seen as the 3 texel wide one but shifted up by one unit/texel.\n // 0.16 is 1/(the triangle area)\n texelsWeightsA.x = 0.16 * (areaFrom3texelTriangle.x);\n texelsWeightsA.y = 0.16 * (areaUncutFrom3texelTriangle.y);\n texelsWeightsA.z = 0.16 * (areaFrom3texelTriangle.y + 1.0);\n texelsWeightsB.x = 0.16 * (areaFrom3texelTriangle.z + 1.0);\n texelsWeightsB.y = 0.16 * (areaUncutFrom3texelTriangle.z);\n texelsWeightsB.z = 0.16 * (areaFrom3texelTriangle.w);\n}\n\n// 5x5 Tent filter (45 degree sloped triangles in U and V)\nvoid sampleShadowComputeSamplesTent5x5(vec4 shadowMapTextureTexelSize, vec2 coord, out float fetchesWeights[9], out vec2 fetchesUV[9])\n{\n // tent base is 5x5 base thus covering from 25 to 36 texels, thus we need 9 bilinear PCF fetches\n vec2 tentCenterInTexelSpace = coord.xy * shadowMapTextureTexelSize.zw;\n vec2 centerOfFetchesInTexelSpace = floor(tentCenterInTexelSpace + 0.5);\n vec2 offsetFromTentCenterToCenterOfFetches = tentCenterInTexelSpace - centerOfFetchesInTexelSpace;\n\n // find the weight of each texel based on the area of a 45 degree slop tent above each of them.\n vec3 texelsWeightsUA, texelsWeightsUB;\n vec3 texelsWeightsVA, texelsWeightsVB;\n sampleShadowGetTexelWeightsTent5x5(offsetFromTentCenterToCenterOfFetches.x, texelsWeightsUA, texelsWeightsUB);\n sampleShadowGetTexelWeightsTent5x5(offsetFromTentCenterToCenterOfFetches.y, texelsWeightsVA, texelsWeightsVB);\n\n // each fetch will cover a group of 2x2 texels, the weight of each group is the sum of the weights of the texels\n vec3 fetchesWeightsU = vec3(texelsWeightsUA.xz, texelsWeightsUB.y) + vec3(texelsWeightsUA.y, texelsWeightsUB.xz);\n vec3 fetchesWeightsV = vec3(texelsWeightsVA.xz, texelsWeightsVB.y) + vec3(texelsWeightsVA.y, texelsWeightsVB.xz);\n\n // move the PCF bilinear fetches to respect texels weights\n vec3 fetchesOffsetsU = vec3(texelsWeightsUA.y, texelsWeightsUB.xz) / fetchesWeightsU.xyz + vec3(-2.5,-0.5,1.5);\n vec3 fetchesOffsetsV = vec3(texelsWeightsVA.y, texelsWeightsVB.xz) / fetchesWeightsV.xyz + vec3(-2.5,-0.5,1.5);\n fetchesOffsetsU *= shadowMapTextureTexelSize.xxx;\n fetchesOffsetsV *= shadowMapTextureTexelSize.yyy;\n\n vec2 bilinearFetchOrigin = centerOfFetchesInTexelSpace * shadowMapTextureTexelSize.xy;\n fetchesUV[0] = bilinearFetchOrigin + vec2(fetchesOffsetsU.x, fetchesOffsetsV.x);\n fetchesUV[1] = bilinearFetchOrigin + vec2(fetchesOffsetsU.y, fetchesOffsetsV.x);\n fetchesUV[2] = bilinearFetchOrigin + vec2(fetchesOffsetsU.z, fetchesOffsetsV.x);\n fetchesUV[3] = bilinearFetchOrigin + vec2(fetchesOffsetsU.x, fetchesOffsetsV.y);\n fetchesUV[4] = bilinearFetchOrigin + vec2(fetchesOffsetsU.y, fetchesOffsetsV.y);\n fetchesUV[5] = bilinearFetchOrigin + vec2(fetchesOffsetsU.z, fetchesOffsetsV.y);\n fetchesUV[6] = bilinearFetchOrigin + vec2(fetchesOffsetsU.x, fetchesOffsetsV.z);\n fetchesUV[7] = bilinearFetchOrigin + vec2(fetchesOffsetsU.y, fetchesOffsetsV.z);\n fetchesUV[8] = bilinearFetchOrigin + vec2(fetchesOffsetsU.z, fetchesOffsetsV.z);\n\n fetchesWeights[0] = fetchesWeightsU.x * fetchesWeightsV.x;\n fetchesWeights[1] = fetchesWeightsU.y * fetchesWeightsV.x;\n fetchesWeights[2] = fetchesWeightsU.z * fetchesWeightsV.x;\n fetchesWeights[3] = fetchesWeightsU.x * fetchesWeightsV.y;\n fetchesWeights[4] = fetchesWeightsU.y * fetchesWeightsV.y;\n fetchesWeights[5] = fetchesWeightsU.z * fetchesWeightsV.y;\n fetchesWeights[6] = fetchesWeightsU.x * fetchesWeightsV.z;\n fetchesWeights[7] = fetchesWeightsU.y * fetchesWeightsV.z;\n fetchesWeights[8] = fetchesWeightsU.z * fetchesWeightsV.z;\n}"; // eslint-disable-line
3565
3565
 
3566
- var ShadowVertexDeclaration = "#define GLSLIFY 1\n#if defined(SCENE_SHADOW_TYPE) && defined(RENDERER_IS_RECEIVE_SHADOWS)\n#define SCENE_IS_CALCULATE_SHADOWS\n#endif\n#ifdef SCENE_IS_CALCULATE_SHADOWS\n#if SCENE_SHADOW_CASCADED_COUNT==1\n#include <ShadowCoord>\nvarying vec3 v_shadowCoord;\n#endif\n#endif\n"; // eslint-disable-line
3566
+ var ShadowVertexDeclaration = "#define GLSLIFY 1\n#if defined(SCENE_SHADOW_TYPE) && defined(RENDERER_IS_RECEIVE_SHADOWS)\n #define SCENE_IS_CALCULATE_SHADOWS\n#endif\n\n#ifdef SCENE_IS_CALCULATE_SHADOWS\n #if SCENE_SHADOW_CASCADED_COUNT==1\n #include <ShadowCoord>\n varying vec3 v_shadowCoord;\n #endif\n#endif"; // eslint-disable-line
3567
3567
 
3568
- var ShadowVertex = "#define GLSLIFY 1\n#ifdef SCENE_IS_CALCULATE_SHADOWS\n#if SCENE_SHADOW_CASCADED_COUNT == 1\nv_shadowCoord=getShadowCoord();\n#endif\n#endif\n"; // eslint-disable-line
3568
+ var ShadowVertex = "#define GLSLIFY 1\n#ifdef SCENE_IS_CALCULATE_SHADOWS\n #if SCENE_SHADOW_CASCADED_COUNT == 1\n v_shadowCoord = getShadowCoord();\n #endif\n#endif"; // eslint-disable-line
3569
3569
 
3570
3570
  var ShadowLib = {
3571
3571
  ShadowCoord: ShadowCoord,
@@ -3575,27 +3575,27 @@ var ShadowLib = {
3575
3575
  ShadowVertex: ShadowVertex
3576
3576
  };
3577
3577
 
3578
- var particle_common = "#define GLSLIFY 1\nvec3 rotationByEuler(in vec3 vector,in vec3 rot){float halfRoll=rot.z*0.5;float halfPitch=rot.x*0.5;float halfYaw=rot.y*0.5;float sinRoll=sin(halfRoll);float cosRoll=cos(halfRoll);float sinPitch=sin(halfPitch);float cosPitch=cos(halfPitch);float sinYaw=sin(halfYaw);float cosYaw=cos(halfYaw);float quaX=(cosYaw*sinPitch*cosRoll)+(sinYaw*cosPitch*sinRoll);float quaY=(sinYaw*cosPitch*cosRoll)-(cosYaw*sinPitch*sinRoll);float quaZ=(cosYaw*cosPitch*sinRoll)-(sinYaw*sinPitch*cosRoll);float quaW=(cosYaw*cosPitch*cosRoll)+(sinYaw*sinPitch*sinRoll);float x=quaX+quaX;float y=quaY+quaY;float z=quaZ+quaZ;float wx=quaW*x;float wy=quaW*y;float wz=quaW*z;float xx=quaX*x;float xy=quaX*y;float xz=quaX*z;float yy=quaY*y;float yz=quaY*z;float zz=quaZ*z;return vec3(((vector.x*((1.0-yy)-zz))+(vector.y*(xy-wz)))+(vector.z*(xz+wy)),((vector.x*(xy+wz))+(vector.y*((1.0-xx)-zz)))+(vector.z*(yz-wx)),((vector.x*(xz-wy))+(vector.y*(yz+wx)))+(vector.z*((1.0-xx)-yy)));}vec3 rotationByAxis(in vec3 vector,in vec3 axis,in float angle){float halfAngle=angle*0.5;float sin=sin(halfAngle);float quaX=axis.x*sin;float quaY=axis.y*sin;float quaZ=axis.z*sin;float quaW=cos(halfAngle);float x=quaX+quaX;float y=quaY+quaY;float z=quaZ+quaZ;float wx=quaW*x;float wy=quaW*y;float wz=quaW*z;float xx=quaX*x;float xy=quaX*y;float xz=quaX*z;float yy=quaY*y;float yz=quaY*z;float zz=quaZ*z;return vec3(((vector.x*((1.0-yy)-zz))+(vector.y*(xy-wz)))+(vector.z*(xz+wy)),((vector.x*(xy+wz))+(vector.y*((1.0-xx)-zz)))+(vector.z*(yz-wx)),((vector.x*(xz-wy))+(vector.y*(yz+wx)))+(vector.z*((1.0-xx)-yy)));}vec3 rotationByQuaternions(in vec3 v,in vec4 q){return v+2.0*cross(q.xyz,cross(q.xyz,v)+q.w*v);}float evaluateParticleCurve(in vec2 keys[4],in float normalizedAge){float value;for(int i=1;i<4;i++){vec2 key=keys[i];float time=key.x;if(time>=normalizedAge){vec2 lastKey=keys[i-1];float lastTime=lastKey.x;float age=(normalizedAge-lastTime)/(time-lastTime);value=mix(lastKey.y,key.y,age);break;}}return value;}float evaluateParticleCurveCumulative(in vec2 keys[4],in float normalizedAge){float cumulativeValue=0.0;for(int i=1;i<4;i++){vec2 key=keys[i];float time=key.x;vec2 lastKey=keys[i-1];float lastValue=lastKey.y;if(time>=normalizedAge){float lastTime=lastKey.x;float offsetTime=normalizedAge-lastTime;float age=offsetTime/(time-lastTime);cumulativeValue+=(lastValue+mix(lastValue,key.y,age))*0.5*offsetTime;break;}else{cumulativeValue+=(lastValue+key.y)*0.5*(time-lastKey.x);}}return cumulativeValue;}"; // eslint-disable-line
3578
+ var particle_common = "#define GLSLIFY 1\n\nvec3 rotationByEuler(in vec3 vector, in vec3 rot) {\n float halfRoll = rot.z * 0.5;\n float halfPitch = rot.x * 0.5;\n float halfYaw = rot.y * 0.5;\n\n float sinRoll = sin(halfRoll);\n float cosRoll = cos(halfRoll);\n float sinPitch = sin(halfPitch);\n float cosPitch = cos(halfPitch);\n float sinYaw = sin(halfYaw);\n float cosYaw = cos(halfYaw);\n\n float quaX = (cosYaw * sinPitch * cosRoll) + (sinYaw * cosPitch * sinRoll);\n float quaY = (sinYaw * cosPitch * cosRoll) - (cosYaw * sinPitch * sinRoll);\n float quaZ = (cosYaw * cosPitch * sinRoll) - (sinYaw * sinPitch * cosRoll);\n float quaW = (cosYaw * cosPitch * cosRoll) + (sinYaw * sinPitch * sinRoll);\n\n // vec4 q=vec4(quaX,quaY,quaZ,quaW);\n // vec3 temp = cross(q.xyz, vector) + q.w * vector;\n // return (cross(temp, -q.xyz) + dot(q.xyz,vector) * q.xyz + q.w * temp);\n\n float x = quaX + quaX;\n float y = quaY + quaY;\n float z = quaZ + quaZ;\n float wx = quaW * x;\n float wy = quaW * y;\n float wz = quaW * z;\n float xx = quaX * x;\n float xy = quaX * y;\n float xz = quaX * z;\n float yy = quaY * y;\n float yz = quaY * z;\n float zz = quaZ * z;\n\n return vec3(((vector.x * ((1.0 - yy) - zz)) + (vector.y * (xy - wz))) + (vector.z * (xz + wy)),\n\t((vector.x * (xy + wz)) + (vector.y * ((1.0 - xx) - zz))) + (vector.z * (yz - wx)),\n\t((vector.x * (xz - wy)) + (vector.y * (yz + wx))) + (vector.z * ((1.0 - xx) - yy)));\n}\n\n//假定axis已经归一化\nvec3 rotationByAxis(in vec3 vector, in vec3 axis, in float angle) {\n float halfAngle = angle * 0.5;\n float sin = sin(halfAngle);\n\n float quaX = axis.x * sin;\n float quaY = axis.y * sin;\n float quaZ = axis.z * sin;\n float quaW = cos(halfAngle);\n\n // vec4 q=vec4(quaX,quaY,quaZ,quaW);\n // vec3 temp = cross(q.xyz, vector) + q.w * vector;\n // return (cross(temp, -q.xyz) + dot(q.xyz,vector) * q.xyz + q.w * temp);\n\n float x = quaX + quaX;\n float y = quaY + quaY;\n float z = quaZ + quaZ;\n float wx = quaW * x;\n float wy = quaW * y;\n float wz = quaW * z;\n float xx = quaX * x;\n float xy = quaX * y;\n float xz = quaX * z;\n float yy = quaY * y;\n float yz = quaY * z;\n float zz = quaZ * z;\n\n return vec3(((vector.x * ((1.0 - yy) - zz)) + (vector.y * (xy - wz))) + (vector.z * (xz + wy)),\n\t((vector.x * (xy + wz)) + (vector.y * ((1.0 - xx) - zz))) + (vector.z * (yz - wx)),\n\t((vector.x * (xz - wy)) + (vector.y * (yz + wx))) + (vector.z * ((1.0 - xx) - yy)));\n}\n\nvec3 rotationByQuaternions(in vec3 v, in vec4 q) {\n return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v);\n}\n\nfloat evaluateParticleCurve(in vec2 keys[4], in float normalizedAge) {\n float value;\n for (int i = 1; i < 4; i++) {\n vec2 key = keys[i];\n float time = key.x;\n if (time >= normalizedAge) {\n vec2 lastKey = keys[i - 1];\n float lastTime = lastKey.x;\n float age = (normalizedAge - lastTime) / (time - lastTime);\n value = mix(lastKey.y, key.y, age);\n break;\n }\n }\n return value;\n}\n\nfloat evaluateParticleCurveCumulative(in vec2 keys[4], in float normalizedAge){\n float cumulativeValue = 0.0;\n for (int i = 1; i < 4; i++){\n\t vec2 key = keys[i];\n\t float time = key.x;\n\t vec2 lastKey = keys[i - 1];\n\t float lastValue = lastKey.y;\n\n\t if (time >= normalizedAge){\n\t\t float lastTime = lastKey.x;\n float offsetTime = normalizedAge - lastTime;\n\t\t float age = offsetTime / (time - lastTime);\n\t\t cumulativeValue += (lastValue + mix(lastValue, key.y, age)) * 0.5 * offsetTime;\n\t\t break;\n\t\t}\n\t else{\n\t\t cumulativeValue += (lastValue + key.y) * 0.5 * (time - lastKey.x);\n\t\t}\n\t}\n return cumulativeValue;\n}"; // eslint-disable-line
3579
3579
 
3580
- var velocity_over_lifetime_module = "#define GLSLIFY 1\n#if defined(RENDERER_VOL_CONSTANT) || defined(RENDERER_VOL_CURVE) || defined(RENDERER_VOL_RANDOM_CONSTANT) || defined(RENDERER_VOL_RANDOM_CURVE)\nuniform int renderer_VOLSpace;\n#if defined(RENDERER_VOL_CONSTANT) || defined(RENDERER_VOL_RANDOM_CONSTANT)\nuniform vec3 renderer_VOLMaxConst;\n#ifdef RENDERER_VOL_RANDOM_CONSTANT\nuniform vec3 renderer_VOLMinConst;\n#endif\n#endif\n#if defined(RENDERER_VOL_CURVE) || defined(RENDERER_VOL_RANDOM_CURVE)\nuniform vec2 renderer_VOLMaxGradientX[4];uniform vec2 renderer_VOLMaxGradientY[4];uniform vec2 renderer_VOLMaxGradientZ[4];\n#ifdef RENDERER_VOL_RANDOM_CURVE\nuniform vec2 renderer_VOLMinGradientX[4];uniform vec2 renderer_VOLMinGradientY[4];uniform vec2 renderer_VOLMinGradientZ[4];\n#endif\n#endif\n#endif\n#if defined(RENDERER_VOL_CONSTANT) || defined(RENDERER_VOL_CURVE) || defined(RENDERER_VOL_RANDOM_CONSTANT) || defined(RENDERER_VOL_RANDOM_CURVE)\nvec3 computeParticleLifeVelocity(in float normalizedAge){vec3 velocity;\n#if defined(RENDERER_VOL_CONSTANT) || defined(RENDERER_VOL_RANDOM_CONSTANT)\nvelocity=renderer_VOLMaxConst;\n#ifdef RENDERER_VOL_RANDOM_CONSTANT\nvelocity=mix(renderer_VOLMinConst,velocity,vec3(a_Random1.y,a_Random1.z,a_Random1.w));\n#endif\n#endif\n#if defined(RENDERER_VOL_CURVE) || defined(RENDERER_VOL_RANDOM_CURVE)\nvelocity=vec3(evaluateParticleCurve(renderer_VOLMaxGradientX,normalizedAge),evaluateParticleCurve(renderer_VOLMaxGradientY,normalizedAge),evaluateParticleCurve(renderer_VOLMaxGradientZ,normalizedAge));\n#endif\n#ifdef RENDERER_VOL_RANDOM_CURVE\nvelocity=vec3(mix(velocity.x,evaluateParticleCurve(renderer_VOLMinGradientX,normalizedAge),a_Random1.y),mix(velocity.y,evaluateParticleCurve(renderer_VOLMinGradientY,normalizedAge),a_Random1.z),mix(velocity.z,evaluateParticleCurve(renderer_VOLMinGradientZ,normalizedAge),a_Random1.w));\n#endif\nreturn velocity;}\n#endif\nvec3 getStartPosition(vec3 startVelocity,float age,vec3 dragData){vec3 startPosition;float lastTime=min(startVelocity.x/dragData.x,age);startPosition=lastTime*(startVelocity-0.5*dragData*lastTime);return startPosition;}vec3 computeParticlePosition(in vec3 startVelocity,in vec3 lifeVelocity,in float age,in float normalizedAge,vec3 gravityVelocity,vec4 worldRotation,vec3 dragData){vec3 startPosition=getStartPosition(startVelocity,age,dragData);vec3 lifePosition;\n#if defined(RENDERER_VOL_CONSTANT) || defined(RENDERER_VOL_CURVE) || defined(RENDERER_VOL_RANDOM_CONSTANT) || defined(RENDERER_VOL_RANDOM_CURVE)\n#if defined(RENDERER_VOL_CONSTANT)|| defined(RENDERER_VOL_RANDOM_CONSTANT)\nlifePosition=lifeVelocity*age;\n#endif\n#if defined(RENDERER_VOL_CURVE) || defined(RENDERER_VOL_RANDOM_CURVE)\nlifePosition=vec3(evaluateParticleCurveCumulative(renderer_VOLMaxGradientX,normalizedAge),evaluateParticleCurveCumulative(renderer_VOLMaxGradientY,normalizedAge),evaluateParticleCurveCumulative(renderer_VOLMaxGradientZ,normalizedAge));\n#ifdef RENDERER_VOL_RANDOM_CURVE\nlifePosition=vec3(mix(evaluateParticleCurveCumulative(renderer_VOLMinGradientX,normalizedAge),lifePosition.x,a_Random1.y),mix(evaluateParticleCurveCumulative(renderer_VOLMinGradientY,normalizedAge),lifePosition.y,a_Random1.z),mix(evaluateParticleCurveCumulative(renderer_VOLMinGradientZ,normalizedAge),lifePosition.z,a_Random1.w));\n#endif\nlifePosition*=vec3(a_ShapePositionStartLifeTime.w);\n#endif\nvec3 finalPosition;if(renderer_VOLSpace==0){finalPosition=rotationByQuaternions(a_ShapePositionStartLifeTime.xyz+startPosition+lifePosition,worldRotation);}else{finalPosition=rotationByQuaternions(a_ShapePositionStartLifeTime.xyz+startPosition,worldRotation)+lifePosition;}\n#else\nvec3 finalPosition=rotationByQuaternions(a_ShapePositionStartLifeTime.xyz+startPosition,worldRotation);\n#endif\nif(renderer_SimulationSpace==0){finalPosition=finalPosition+renderer_WorldPosition;}else if(renderer_SimulationSpace==1){finalPosition=finalPosition+a_SimulationWorldPosition;}finalPosition+=0.5*gravityVelocity*age;return finalPosition;}"; // eslint-disable-line
3580
+ var velocity_over_lifetime_module = "#define GLSLIFY 1\n#if defined(RENDERER_VOL_CONSTANT) || defined(RENDERER_VOL_CURVE) || defined(RENDERER_VOL_RANDOM_CONSTANT) || defined(RENDERER_VOL_RANDOM_CURVE)\n uniform int renderer_VOLSpace;\n\n #if defined(RENDERER_VOL_CONSTANT) || defined(RENDERER_VOL_RANDOM_CONSTANT)\n uniform vec3 renderer_VOLMaxConst;\n\n #ifdef RENDERER_VOL_RANDOM_CONSTANT\n uniform vec3 renderer_VOLMinConst;\n #endif\n #endif\n\n #if defined(RENDERER_VOL_CURVE) || defined(RENDERER_VOL_RANDOM_CURVE)\n uniform vec2 renderer_VOLMaxGradientX[4]; // x:time y:value\n uniform vec2 renderer_VOLMaxGradientY[4]; // x:time y:value\n uniform vec2 renderer_VOLMaxGradientZ[4]; // x:time y:value\n\n #ifdef RENDERER_VOL_RANDOM_CURVE\n uniform vec2 renderer_VOLMinGradientX[4]; // x:time y:value\n uniform vec2 renderer_VOLMinGradientY[4]; // x:time y:value\n uniform vec2 renderer_VOLMinGradientZ[4]; // x:time y:value\n #endif\n #endif\n#endif\n\n#if defined(RENDERER_VOL_CONSTANT) || defined(RENDERER_VOL_CURVE) || defined(RENDERER_VOL_RANDOM_CONSTANT) || defined(RENDERER_VOL_RANDOM_CURVE)\n vec3 computeParticleLifeVelocity(in float normalizedAge) {\n vec3 velocity;\n #if defined(RENDERER_VOL_CONSTANT) || defined(RENDERER_VOL_RANDOM_CONSTANT)\n velocity = renderer_VOLMaxConst;\n #ifdef RENDERER_VOL_RANDOM_CONSTANT\n velocity = mix(renderer_VOLMinConst, velocity, vec3(a_Random1.y, a_Random1.z, a_Random1.w));\n #endif\n #endif\n \n #if defined(RENDERER_VOL_CURVE) || defined(RENDERER_VOL_RANDOM_CURVE)\n velocity = vec3(evaluateParticleCurve(renderer_VOLMaxGradientX, normalizedAge), evaluateParticleCurve(renderer_VOLMaxGradientY, normalizedAge), evaluateParticleCurve(renderer_VOLMaxGradientZ, normalizedAge));\n #endif\n \n #ifdef RENDERER_VOL_RANDOM_CURVE\n velocity = vec3(\n mix(velocity.x, evaluateParticleCurve(renderer_VOLMinGradientX, normalizedAge), a_Random1.y),\n mix(velocity.y, evaluateParticleCurve(renderer_VOLMinGradientY, normalizedAge), a_Random1.z),\n mix(velocity.z, evaluateParticleCurve(renderer_VOLMinGradientZ, normalizedAge), a_Random1.w));\n #endif\n\n return velocity;\n }\n#endif\n\nvec3 getStartPosition(vec3 startVelocity, float age, vec3 dragData) {\n vec3 startPosition;\n float lastTime = min(startVelocity.x / dragData.x, age); // todo 0/0\n startPosition = lastTime * (startVelocity - 0.5 * dragData * lastTime);\n return startPosition;\n}\n\nvec3 computeParticlePosition(in vec3 startVelocity, in vec3 lifeVelocity, in float age, in float normalizedAge, vec3 gravityVelocity, vec4 worldRotation, vec3 dragData) {\n vec3 startPosition = getStartPosition(startVelocity, age, dragData);\n vec3 lifePosition;\n #if defined(RENDERER_VOL_CONSTANT) || defined(RENDERER_VOL_CURVE) || defined(RENDERER_VOL_RANDOM_CONSTANT) || defined(RENDERER_VOL_RANDOM_CURVE)\n #if defined(RENDERER_VOL_CONSTANT)|| defined(RENDERER_VOL_RANDOM_CONSTANT)\n // @todo:just RENDERER_VOL_CONSTANT and RENDERER_VOL_RANDOM_CONSTANT need `lifeVelocity`\n lifePosition = lifeVelocity * age;\n #endif\n\n #if defined(RENDERER_VOL_CURVE) || defined(RENDERER_VOL_RANDOM_CURVE)\n lifePosition = vec3(\n evaluateParticleCurveCumulative(renderer_VOLMaxGradientX, normalizedAge),\n evaluateParticleCurveCumulative(renderer_VOLMaxGradientY, normalizedAge),\n evaluateParticleCurveCumulative(renderer_VOLMaxGradientZ, normalizedAge));\n\n #ifdef RENDERER_VOL_RANDOM_CURVE\n lifePosition = vec3(\n mix(evaluateParticleCurveCumulative(renderer_VOLMinGradientX, normalizedAge), lifePosition.x, a_Random1.y),\n mix(evaluateParticleCurveCumulative(renderer_VOLMinGradientY, normalizedAge), lifePosition.y, a_Random1.z),\n mix(evaluateParticleCurveCumulative(renderer_VOLMinGradientZ, normalizedAge), lifePosition.z, a_Random1.w));\n #endif\n\n lifePosition *= vec3(a_ShapePositionStartLifeTime.w);\n #endif\n \n vec3 finalPosition;\n if (renderer_VOLSpace == 0) {\n finalPosition = rotationByQuaternions(a_ShapePositionStartLifeTime.xyz + startPosition + lifePosition, worldRotation);\n } else {\n finalPosition = rotationByQuaternions(a_ShapePositionStartLifeTime.xyz + startPosition, worldRotation) + lifePosition;\n }\n #else\n vec3 finalPosition = rotationByQuaternions(a_ShapePositionStartLifeTime.xyz + startPosition, worldRotation);\n #endif\n\n if (renderer_SimulationSpace == 0) {\n finalPosition = finalPosition + renderer_WorldPosition;\n } else if (renderer_SimulationSpace == 1) {\n\t finalPosition = finalPosition + a_SimulationWorldPosition;\n\t}\n\n finalPosition += 0.5 * gravityVelocity * age;\n\n return finalPosition;\n}\n"; // eslint-disable-line
3581
3581
 
3582
- var rotation_over_lifetime_module = "#define GLSLIFY 1\n#if defined(RENDERER_ROL_CONSTANT_MODE) || defined(RENDERER_ROL_CURVE_MODE)\n#ifdef RENDERER_ROL_CURVE_MODE\nuniform vec2 renderer_ROLMaxCurveZ[4];\n#ifdef RENDERER_ROL_IS_RANDOM_TWO\nuniform vec2 renderer_ROLMinCurveZ[4];\n#endif\n#else\nuniform vec3 renderer_ROLMaxConst;\n#ifdef RENDERER_ROL_IS_RANDOM_TWO\nuniform vec3 renderer_ROLMinConst;\n#endif\n#endif\n#endif\nfloat computeParticleRotationFloat(in float rotation,in float age,in float normalizedAge){\n#if defined(RENDERER_ROL_CONSTANT_MODE) || defined(RENDERER_ROL_CURVE_MODE)\n#ifdef RENDERER_ROL_CURVE_MODE\nfloat lifeRotation=evaluateParticleCurveCumulative(renderer_ROLMaxCurveZ,normalizedAge);\n#ifdef RENDERER_ROL_IS_RANDOM_TWO\nlifeRotation=mix(evaluateParticleCurveCumulative(renderer_ROLMinCurveZ,normalizedAge),lifeRotation,a_Random0.w);\n#endif\nrotation+=lifeRotation*a_ShapePositionStartLifeTime.w;\n#else\nfloat lifeRotation=renderer_ROLMaxConst.z;\n#ifdef RENDERER_ROL_IS_RANDOM_TWO\nlifeRotation=mix(renderer_ROLMinConst.z,lifeRotation,a_Random0.w);\n#endif\nrotation+=lifeRotation*age;\n#endif\n#endif\nreturn rotation;}\n#if defined(RENDERER_MODE_MESH) && (defined(ROTATION_OVER_LIFETIME) || defined(ROTATION_OVER_LIFETIME_SEPARATE))\nvec3 computeParticleRotationVec3(in vec3 rotation,in float age,in float normalizedAge){\n#ifdef ROTATION_OVER_LIFETIME\n#ifdef ROTATION_OVER_LIFETIME_CONSTANT\nfloat ageRot=u_ROLAngularVelocityConst*age;rotation+=ageRot;\n#endif\n#ifdef ROTATION_OVER_LIFETIME_CURVE\nrotation+=getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge);\n#endif\n#ifdef ROTATION_OVER_LIFETIME_RANDOM_CONSTANTS\nfloat ageRot=mix(u_ROLAngularVelocityConst,u_ROLAngularVelocityConstMax,a_Random0.w)*age;rotation+=ageRot;\n#endif\n#ifdef ROTATION_OVER_LIFETIME_RANDOM_CURVES\nrotation+=mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMax,normalizedAge),a_Random0.w);\n#endif\n#endif\n#ifdef ROTATION_OVER_LIFETIME_SEPARATE\n#ifdef ROTATION_OVER_LIFETIME_CONSTANT\nvec3 ageRot=u_ROLAngularVelocityConstSeparate*age;rotation+=ageRot;\n#endif\n#ifdef ROTATION_OVER_LIFETIME_CURVE\nrotation+=vec3(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge));\n#endif\n#ifdef ROTATION_OVER_LIFETIME_RANDOM_CONSTANTS\nvec3 ageRot=mix(u_ROLAngularVelocityConstSeparate,renderer_ROLMaxConst,a_Random0.w)*age;rotation+=ageRot;\n#endif\n#ifdef ROTATION_OVER_LIFETIME_RANDOM_CURVES\nrotation+=vec3(mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(renderer_ROLMaxCurveX,normalizedAge),a_Random0.w),mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(renderer_ROLMaxCurveY,normalizedAge),a_Random0.w),mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge),getTotalValueFromGradientFloat(renderer_ROLMaxCurveZ,normalizedAge),a_Random0.w));\n#endif\n#endif\nreturn rotation;}\n#endif\n"; // eslint-disable-line
3582
+ var rotation_over_lifetime_module = "#define GLSLIFY 1\n#if defined(RENDERER_ROL_CONSTANT_MODE) || defined(RENDERER_ROL_CURVE_MODE)\n #ifdef RENDERER_ROL_CURVE_MODE\n uniform vec2 renderer_ROLMaxCurveZ[4];\n // #ifdef RENDERER_ROL_IS_SEPARATE\n // uniform vec2 renderer_ROLMaxCurveX[4];\n // uniform vec2 renderer_ROLMaxCurveY[4];\n // #endif\n #ifdef RENDERER_ROL_IS_RANDOM_TWO\n uniform vec2 renderer_ROLMinCurveZ[4];\n // #ifdef RENDERER_ROL_IS_SEPARATE\n // uniform vec2 renderer_ROLMinCurveX[4];\n // uniform vec2 renderer_ROLMinCurveY[4];\n // #endif\n #endif\n #else\n uniform vec3 renderer_ROLMaxConst;\n #ifdef RENDERER_ROL_IS_RANDOM_TWO\n uniform vec3 renderer_ROLMinConst;\n #endif\n #endif\n#endif\n\nfloat computeParticleRotationFloat(in float rotation, in float age, in float normalizedAge) {\n #if defined(RENDERER_ROL_CONSTANT_MODE) || defined(RENDERER_ROL_CURVE_MODE)\n #ifdef RENDERER_ROL_CURVE_MODE\n float lifeRotation = evaluateParticleCurveCumulative(renderer_ROLMaxCurveZ, normalizedAge);\n #ifdef RENDERER_ROL_IS_RANDOM_TWO\n lifeRotation = mix(evaluateParticleCurveCumulative(renderer_ROLMinCurveZ, normalizedAge), lifeRotation, a_Random0.w);\n #endif\n rotation += lifeRotation * a_ShapePositionStartLifeTime.w;\n #else\n float lifeRotation = renderer_ROLMaxConst.z;\n #ifdef RENDERER_ROL_IS_RANDOM_TWO\n lifeRotation = mix(renderer_ROLMinConst.z, lifeRotation, a_Random0.w);\n #endif\n rotation += lifeRotation * age;\n #endif\n #endif\n return rotation;\n}\n\n#if defined(RENDERER_MODE_MESH) && (defined(ROTATION_OVER_LIFETIME) || defined(ROTATION_OVER_LIFETIME_SEPARATE))\nvec3 computeParticleRotationVec3(in vec3 rotation,\n in float age,\n in float normalizedAge) {\n#ifdef ROTATION_OVER_LIFETIME\n #ifdef ROTATION_OVER_LIFETIME_CONSTANT\n float ageRot = u_ROLAngularVelocityConst * age;\n rotation += ageRot;\n #endif\n #ifdef ROTATION_OVER_LIFETIME_CURVE\n rotation += getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient, normalizedAge);\n #endif\n #ifdef ROTATION_OVER_LIFETIME_RANDOM_CONSTANTS\n float ageRot = mix(u_ROLAngularVelocityConst, u_ROLAngularVelocityConstMax, a_Random0.w) * age;\n rotation += ageRot;\n #endif\n #ifdef ROTATION_OVER_LIFETIME_RANDOM_CURVES\n rotation += mix(\n getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient, normalizedAge),\n getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMax,\n normalizedAge),\n a_Random0.w);\n #endif\n#endif\n\n#ifdef ROTATION_OVER_LIFETIME_SEPARATE\n #ifdef ROTATION_OVER_LIFETIME_CONSTANT\n vec3 ageRot = u_ROLAngularVelocityConstSeparate * age;\n rotation += ageRot;\n #endif\n #ifdef ROTATION_OVER_LIFETIME_CURVE\n rotation += vec3(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientX,\n normalizedAge),\n getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientY,\n normalizedAge),\n getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,\n normalizedAge));\n #endif\n #ifdef ROTATION_OVER_LIFETIME_RANDOM_CONSTANTS\n vec3 ageRot = mix(u_ROLAngularVelocityConstSeparate,\n renderer_ROLMaxConst,\n a_Random0.w)\n * age;\n rotation += ageRot;\n #endif\n #ifdef ROTATION_OVER_LIFETIME_RANDOM_CURVES\n rotation += vec3(mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientX,\n normalizedAge),\n getTotalValueFromGradientFloat(renderer_ROLMaxCurveX,\n normalizedAge),\n a_Random0.w),\n mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientY,\n normalizedAge),\n getTotalValueFromGradientFloat(renderer_ROLMaxCurveY,\n normalizedAge),\n a_Random0.w),\n mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,\n normalizedAge),\n getTotalValueFromGradientFloat(renderer_ROLMaxCurveZ,\n normalizedAge),\n a_Random0.w));\n #endif\n#endif\n return rotation;\n}\n#endif\n"; // eslint-disable-line
3583
3583
 
3584
- var size_over_lifetime_module = "#define GLSLIFY 1\n#ifdef RENDERER_SOL_CURVE_MODE\nuniform vec2 renderer_SOLMaxCurveX[4];\n#ifdef RENDERER_SOL_IS_SEPARATE\nuniform vec2 renderer_SOLMaxCurveY[4];uniform vec2 renderer_SOLMaxCurveZ[4];\n#endif\n#ifdef RENDERER_SOL_IS_RANDOM_TWO\nuniform vec2 renderer_SOLMinCurveX[4];\n#ifdef RENDERER_SOL_IS_SEPARATE\nuniform vec2 renderer_SOLMinCurveY[4];uniform vec2 renderer_SOLMinCurveZ[4];\n#endif\n#endif\n#endif\nvec2 computeParticleSizeBillboard(in vec2 size,in float normalizedAge){\n#ifdef RENDERER_SOL_CURVE_MODE\nfloat lifeSizeX=evaluateParticleCurve(renderer_SOLMaxCurveX,normalizedAge);\n#ifdef RENDERER_SOL_IS_RANDOM_TWO\nlifeSizeX=mix(evaluateParticleCurve(renderer_SOLMinCurveX,normalizedAge),lifeSizeX,a_Random0.z);\n#endif\n#ifdef RENDERER_SOL_IS_SEPARATE\nfloat lifeSizeY=evaluateParticleCurve(renderer_SOLMaxCurveY,normalizedAge);\n#ifdef RENDERER_SOL_IS_RANDOM_TWO\nlifeSizeY=mix(evaluateParticleCurve(renderer_SOLMinCurveY,normalizedAge),lifeSizeY,a_Random0.z);\n#endif\nsize*=vec2(lifeSizeX,lifeSizeY);\n#else\nsize*=lifeSizeX;\n#endif\n#endif\nreturn size;}\n#ifdef RENDERER_MODE_MESH\nvec3 computeParticleSizeMesh(in vec3 size,in float normalizedAge){\n#ifdef RENDERER_SOL_CURVE\nsize*=evaluateParticleCurve(renderer_SOLMaxCurveX,normalizedAge);\n#endif\n#ifdef RENDERER_SOL_RANDOM_CURVES\nsize*=mix(evaluateParticleCurve(renderer_SOLMaxCurveX,normalizedAge),evaluateParticleCurve(u_SOLSizeGradientMax,normalizedAge),a_Random0.z);\n#endif\n#ifdef RENDERER_SOL_CURVE_SEPARATE\nsize*=vec3(evaluateParticleCurve(renderer_SOLMinCurveX,normalizedAge),evaluateParticleCurve(renderer_SOLMinCurveY,normalizedAge),evaluateParticleCurve(renderer_SOLMinCurveZ,normalizedAge));\n#endif\n#ifdef RENDERER_SOL_RANDOM_CURVES_SEPARATE\nsize*=vec3(mix(evaluateParticleCurve(renderer_SOLMinCurveX,normalizedAge),evaluateParticleCurve(renderer_SOLMaxCurveX,normalizedAge),a_Random0.z),mix(evaluateParticleCurve(renderer_SOLMinCurveY,normalizedAge),evaluateParticleCurve(renderer_SOLMaxCurveY,normalizedAge),a_Random0.z),mix(evaluateParticleCurve(renderer_SOLMinCurveZ,normalizedAge),evaluateParticleCurve(renderer_SOLMaxCurveZ,normalizedAge),a_Random0.z));\n#endif\nreturn size;}\n#endif\n"; // eslint-disable-line
3584
+ var size_over_lifetime_module = "#define GLSLIFY 1\n#ifdef RENDERER_SOL_CURVE_MODE\n uniform vec2 renderer_SOLMaxCurveX[4]; // x:time y:value\n #ifdef RENDERER_SOL_IS_SEPARATE\n uniform vec2 renderer_SOLMaxCurveY[4]; // x:time y:value\n uniform vec2 renderer_SOLMaxCurveZ[4]; // x:time y:value\n #endif\n\n #ifdef RENDERER_SOL_IS_RANDOM_TWO\n uniform vec2 renderer_SOLMinCurveX[4]; // x:time y:value\n #ifdef RENDERER_SOL_IS_SEPARATE\n uniform vec2 renderer_SOLMinCurveY[4]; // x:time y:value\n uniform vec2 renderer_SOLMinCurveZ[4]; // x:time y:value\n #endif\n #endif\n#endif\n\nvec2 computeParticleSizeBillboard(in vec2 size, in float normalizedAge) {\n #ifdef RENDERER_SOL_CURVE_MODE\n float lifeSizeX = evaluateParticleCurve(renderer_SOLMaxCurveX, normalizedAge);\n #ifdef RENDERER_SOL_IS_RANDOM_TWO\n lifeSizeX = mix(evaluateParticleCurve(renderer_SOLMinCurveX, normalizedAge), lifeSizeX, a_Random0.z);\n #endif\n\n #ifdef RENDERER_SOL_IS_SEPARATE\n float lifeSizeY = evaluateParticleCurve(renderer_SOLMaxCurveY, normalizedAge);\n #ifdef RENDERER_SOL_IS_RANDOM_TWO\n lifeSizeY = mix(evaluateParticleCurve(renderer_SOLMinCurveY, normalizedAge), lifeSizeY, a_Random0.z);\n #endif\n size *= vec2(lifeSizeX, lifeSizeY);\n #else\n size *= lifeSizeX;\n #endif\n #endif\n return size;\n}\n\n#ifdef RENDERER_MODE_MESH\n vec3 computeParticleSizeMesh(in vec3 size, in float normalizedAge) {\n #ifdef RENDERER_SOL_CURVE\n size *= evaluateParticleCurve(renderer_SOLMaxCurveX, normalizedAge);\n #endif\n #ifdef RENDERER_SOL_RANDOM_CURVES\n size *= mix(evaluateParticleCurve(renderer_SOLMaxCurveX, normalizedAge),\n evaluateParticleCurve(u_SOLSizeGradientMax, normalizedAge),\n a_Random0.z);\n #endif\n #ifdef RENDERER_SOL_CURVE_SEPARATE\n size *= vec3(evaluateParticleCurve(renderer_SOLMinCurveX, normalizedAge),\n evaluateParticleCurve(renderer_SOLMinCurveY, normalizedAge),\n evaluateParticleCurve(renderer_SOLMinCurveZ, normalizedAge));\n #endif\n #ifdef RENDERER_SOL_RANDOM_CURVES_SEPARATE\n size *= vec3(mix(evaluateParticleCurve(renderer_SOLMinCurveX, normalizedAge),\n evaluateParticleCurve(renderer_SOLMaxCurveX, normalizedAge),\n a_Random0.z),\n mix(evaluateParticleCurve(renderer_SOLMinCurveY, normalizedAge),\n evaluateParticleCurve(renderer_SOLMaxCurveY, normalizedAge),\n a_Random0.z),\n mix(evaluateParticleCurve(renderer_SOLMinCurveZ, normalizedAge),\n evaluateParticleCurve(renderer_SOLMaxCurveZ, normalizedAge),\n a_Random0.z));\n #endif\n return size;\n }\n#endif"; // eslint-disable-line
3585
3585
 
3586
- var color_over_lifetime_module = "#define GLSLIFY 1\n#if defined(RENDERER_COL_GRADIENT) || defined(RENDERER_COL_RANDOM_GRADIENTS)\nuniform vec4 renderer_COLMaxGradientColor[4];uniform vec2 renderer_COLMaxGradientAlpha[4];\n#ifdef RENDERER_COL_RANDOM_GRADIENTS\nuniform vec4 renderer_COLMinGradientColor[4];uniform vec2 renderer_COLMinGradientAlpha[4];\n#endif\nuniform vec4 renderer_COLGradientKeysMaxTime;\n#endif\n#if defined(RENDERER_COL_GRADIENT) || defined(RENDERER_COL_RANDOM_GRADIENTS)\nvec4 evaluateParticleGradient(in vec4 colorKeys[4],in float colorKeysMaxTime,in vec2 alphaKeys[4],in float alphaKeysMaxTime,in float normalizedAge){vec4 value;float alphaAge=min(normalizedAge,alphaKeysMaxTime);for(int i=0;i<4;i++){vec2 key=alphaKeys[i];float time=key.x;if(alphaAge<=time){if(i==0){value.a=alphaKeys[0].y;}else{vec2 lastKey=alphaKeys[i-1];float lastTime=lastKey.x;float age=(alphaAge-lastTime)/(time-lastTime);value.a=mix(lastKey.y,key.y,age);}break;}}float colorAge=min(normalizedAge,colorKeysMaxTime);for(int i=0;i<4;i++){vec4 key=colorKeys[i];float time=key.x;if(colorAge<=time){if(i==0){value.rgb=colorKeys[0].yzw;}else{vec4 lastKey=colorKeys[i-1];float lastTime=lastKey.x;float age=(colorAge-lastTime)/(time-lastTime);value.rgb=mix(lastKey.yzw,key.yzw,age);}break;}}return value;}\n#endif\nvec4 computeParticleColor(in vec4 color,in float normalizedAge){\n#if defined(RENDERER_COL_GRADIENT) || defined(RENDERER_COL_RANDOM_GRADIENTS)\nvec4 gradientColor=evaluateParticleGradient(renderer_COLMaxGradientColor,renderer_COLGradientKeysMaxTime.z,renderer_COLMaxGradientAlpha,renderer_COLGradientKeysMaxTime.w,normalizedAge);\n#endif\n#ifdef RENDERER_COL_RANDOM_GRADIENTS\ngradientColor=mix(evaluateParticleGradient(renderer_COLMinGradientColor,renderer_COLGradientKeysMaxTime.x,renderer_COLMinGradientAlpha,renderer_COLGradientKeysMaxTime.y,normalizedAge),gradientColor,a_Random0.y);\n#endif\n#if defined(RENDERER_COL_GRADIENT) || defined(RENDERER_COL_RANDOM_GRADIENTS)\ncolor*=gradientColor;\n#endif\nreturn color;}"; // eslint-disable-line
3586
+ var color_over_lifetime_module = "#define GLSLIFY 1\n#if defined(RENDERER_COL_GRADIENT) || defined(RENDERER_COL_RANDOM_GRADIENTS)\n uniform vec4 renderer_COLMaxGradientColor[4]; // x:time y:r z:g w:b\n uniform vec2 renderer_COLMaxGradientAlpha[4]; // x:time y:alpha\n\n #ifdef RENDERER_COL_RANDOM_GRADIENTS\n uniform vec4 renderer_COLMinGradientColor[4]; // x:time y:r z:g w:b\n uniform vec2 renderer_COLMinGradientAlpha[4]; // x:time y:alpha\n #endif\n\n uniform vec4 renderer_COLGradientKeysMaxTime; // x: minColorKeysMaxTime, y: minAlphaKeysMaxTime, z: maxColorKeysMaxTime, w: maxAlphaKeysMaxTime\n#endif\n\n#if defined(RENDERER_COL_GRADIENT) || defined(RENDERER_COL_RANDOM_GRADIENTS)\n vec4 evaluateParticleGradient(in vec4 colorKeys[4], in float colorKeysMaxTime, in vec2 alphaKeys[4], in float alphaKeysMaxTime, in float normalizedAge){\n vec4 value;\n float alphaAge = min(normalizedAge, alphaKeysMaxTime);\n for(int i = 0; i < 4; i++){\n vec2 key = alphaKeys[i];\n float time = key.x;\n if(alphaAge <= time){\n if(i == 0){\n value.a = alphaKeys[0].y;\n }\n else {\n vec2 lastKey = alphaKeys[i-1];\n float lastTime = lastKey.x;\n float age = (alphaAge - lastTime) / (time - lastTime);\n value.a = mix(lastKey.y, key.y, age);\n }\n break;\n }\n }\n \n float colorAge = min(normalizedAge, colorKeysMaxTime);\n for(int i = 0; i < 4; i++){\n vec4 key = colorKeys[i];\n float time = key.x;\n if(colorAge <= time){\n if(i == 0){\n value.rgb = colorKeys[0].yzw;\n }\n else {\n vec4 lastKey = colorKeys[i-1];\n float lastTime = lastKey.x;\n float age = (colorAge - lastTime) / (time-lastTime);\n value.rgb = mix(lastKey.yzw, key.yzw, age);\n }\n break;\n }\n }\n return value;\n }\n#endif\n\nvec4 computeParticleColor(in vec4 color, in float normalizedAge) {\n #if defined(RENDERER_COL_GRADIENT) || defined(RENDERER_COL_RANDOM_GRADIENTS)\n vec4 gradientColor = evaluateParticleGradient(renderer_COLMaxGradientColor, renderer_COLGradientKeysMaxTime.z, renderer_COLMaxGradientAlpha, renderer_COLGradientKeysMaxTime.w, normalizedAge);\n #endif\n\n #ifdef RENDERER_COL_RANDOM_GRADIENTS\n gradientColor = mix(evaluateParticleGradient(renderer_COLMinGradientColor,renderer_COLGradientKeysMaxTime.x, renderer_COLMinGradientAlpha, renderer_COLGradientKeysMaxTime.y, normalizedAge), gradientColor, a_Random0.y);\n #endif\n\n #if defined(RENDERER_COL_GRADIENT) || defined(RENDERER_COL_RANDOM_GRADIENTS)\n color *= gradientColor;\n #endif\n\n return color;\n}\n"; // eslint-disable-line
3587
3587
 
3588
- var texture_sheet_animation_module = "#define GLSLIFY 1\n#if defined(RENDERER_TSA_FRAME_CURVE) || defined(RENDERER_TSA_FRAME_RANDOM_CURVES)\nuniform float renderer_TSACycles;uniform vec3 renderer_TSATillingParams;uniform vec2 renderer_TSAFrameMaxCurve[4];\n#ifdef RENDERER_TSA_FRAME_RANDOM_CURVES\nuniform vec2 renderer_TSAFrameMinCurve[4];\n#endif\n#endif\nvec2 computeParticleUV(in vec2 uv,in float normalizedAge){\n#if defined(RENDERER_TSA_FRAME_CURVE) || defined(RENDERER_TSA_FRAME_RANDOM_CURVES)\nfloat scaledNormalizedAge=normalizedAge*renderer_TSACycles;float cycleNormalizedAge=scaledNormalizedAge-floor(scaledNormalizedAge);float normalizedFrame=evaluateParticleCurve(renderer_TSAFrameMaxCurve,cycleNormalizedAge);\n#ifdef RENDERER_TSA_FRAME_RANDOM_CURVES\nnormalizedFrame=mix(evaluateParticleCurve(renderer_TSAFrameMinCurve,cycleNormalizedAge),normalizedFrame,a_Random1.x);\n#endif\nfloat frame=floor(normalizedFrame*renderer_TSATillingParams.z);float tileRow=frame*renderer_TSATillingParams.x;float tileRowIndex=floor(tileRow);uv.x+=tileRow-tileRowIndex;uv.y+=tileRowIndex*renderer_TSATillingParams.y;\n#endif\nreturn uv;}"; // eslint-disable-line
3588
+ var texture_sheet_animation_module = "#define GLSLIFY 1\n#if defined(RENDERER_TSA_FRAME_CURVE) || defined(RENDERER_TSA_FRAME_RANDOM_CURVES)\n uniform float renderer_TSACycles;\n uniform vec3 renderer_TSATillingParams; // x:subU y:subV z:tileCount\n uniform vec2 renderer_TSAFrameMaxCurve[4]; // x:time y:value\n\n #ifdef RENDERER_TSA_FRAME_RANDOM_CURVES\n uniform vec2 renderer_TSAFrameMinCurve[4]; // x:time y:value\n #endif\n#endif\n\nvec2 computeParticleUV(in vec2 uv, in float normalizedAge) {\n #if defined(RENDERER_TSA_FRAME_CURVE) || defined(RENDERER_TSA_FRAME_RANDOM_CURVES)\n float scaledNormalizedAge = normalizedAge * renderer_TSACycles;\n float cycleNormalizedAge = scaledNormalizedAge - floor(scaledNormalizedAge);\n float normalizedFrame = evaluateParticleCurve(renderer_TSAFrameMaxCurve, cycleNormalizedAge);\n #ifdef RENDERER_TSA_FRAME_RANDOM_CURVES\n normalizedFrame = mix(evaluateParticleCurve(renderer_TSAFrameMinCurve, cycleNormalizedAge), normalizedFrame, a_Random1.x);\n #endif\n\n float frame = floor(normalizedFrame * renderer_TSATillingParams.z);\n\n float tileRow = frame * renderer_TSATillingParams.x;\n float tileRowIndex = floor(tileRow);\n uv.x += tileRow - tileRowIndex;\n uv.y += tileRowIndex * renderer_TSATillingParams.y;\n #endif\n \n return uv;\n}\n"; // eslint-disable-line
3589
3589
 
3590
- var sphere_billboard = "#define GLSLIFY 1\n#ifdef RENDERER_MODE_SPHERE_BILLBOARD\nvec2 corner=a_CornerTextureCoordinate.xy+renderer_PivotOffset.xy;vec3 sideVector=normalize(cross(camera_Forward,camera_Up));vec3 upVector=normalize(cross(sideVector,camera_Forward));corner*=computeParticleSizeBillboard(a_StartSize.xy,normalizedAge);\n#if defined(RENDERER_ROL_CONSTANT_MODE) || defined(RENDERER_ROL_CURVE_MODE)\nif(renderer_ThreeDStartRotation){vec3 rotation=vec3(a_StartRotation0.xy,computeParticleRotationFloat(a_StartRotation0.z,age,normalizedAge));center+=renderer_SizeScale.xzy*rotationByEuler(corner.x*sideVector+corner.y*upVector,rotation);}else{float rot=computeParticleRotationFloat(a_StartRotation0.x,age,normalizedAge);float c=cos(rot);float s=sin(rot);mat2 rotation=mat2(c,-s,s,c);corner=rotation*corner;center+=renderer_SizeScale.xzy*(corner.x*sideVector+corner.y*upVector);}\n#else\nif(renderer_ThreeDStartRotation){center+=renderer_SizeScale.xzy*rotationByEuler(corner.x*sideVector+corner.y*upVector,a_StartRotation0);}else{float c=cos(a_StartRotation0.x);float s=sin(a_StartRotation0.x);mat2 rotation=mat2(c,-s,s,c);corner=rotation*corner;center+=renderer_SizeScale.xzy*(corner.x*sideVector+corner.y*upVector);}\n#endif\n#endif\n"; // eslint-disable-line
3590
+ var sphere_billboard = "#define GLSLIFY 1\n#ifdef RENDERER_MODE_SPHERE_BILLBOARD\n\tvec2 corner = a_CornerTextureCoordinate.xy + renderer_PivotOffset.xy;\n\tvec3 sideVector = normalize(cross(camera_Forward, camera_Up));\n\tvec3 upVector = normalize(cross(sideVector, camera_Forward));\n\tcorner *= computeParticleSizeBillboard(a_StartSize.xy, normalizedAge);\n #if defined(RENDERER_ROL_CONSTANT_MODE) || defined(RENDERER_ROL_CURVE_MODE)\n if (renderer_ThreeDStartRotation) {\n vec3 rotation = vec3(a_StartRotation0.xy, computeParticleRotationFloat(a_StartRotation0.z, age, normalizedAge));\n center += renderer_SizeScale.xzy * rotationByEuler(corner.x * sideVector + corner.y * upVector, rotation);\n } else {\n float rot = computeParticleRotationFloat(a_StartRotation0.x, age, normalizedAge);\n float c = cos(rot);\n float s = sin(rot);\n mat2 rotation = mat2(c, -s, s, c);\n corner = rotation * corner;\n center += renderer_SizeScale.xzy * (corner.x * sideVector + corner.y * upVector);\n }\n #else\n if (renderer_ThreeDStartRotation) {\n center += renderer_SizeScale.xzy * rotationByEuler(corner.x * sideVector + corner.y * upVector, a_StartRotation0);\n } else {\n float c = cos(a_StartRotation0.x);\n float s = sin(a_StartRotation0.x);\n mat2 rotation = mat2(c, -s, s, c);\n corner = rotation * corner;\n center += renderer_SizeScale.xzy * (corner.x * sideVector + corner.y * upVector);\n }\n #endif\n#endif"; // eslint-disable-line
3591
3591
 
3592
- var stretched_billboard = "#define GLSLIFY 1\n#ifdef RENDERER_MODE_STRETCHED_BILLBOARD\nvec2 corner=a_CornerTextureCoordinate.xy+renderer_PivotOffset.xy;vec3 velocity;\n#if defined(RENDERER_VOL_CONSTANT) || defined(RENDERER_VOL_CURVE) || defined(RENDERER_VOL_RANDOM_CONSTANT) || defined(RENDERER_VOL_RANDOM_CURVE)\nif(renderer_VOLSpace==0){velocity=rotationByQuaternions(renderer_SizeScale*(startVelocity+lifeVelocity),worldRotation)+gravityVelocity;}else{velocity=rotationByQuaternions(renderer_SizeScale*startVelocity,worldRotation)+lifeVelocity+gravityVelocity;}\n#else\nvelocity=rotationByQuaternions(renderer_SizeScale*startVelocity,worldRotation)+gravityVelocity;\n#endif\nvec3 cameraUpVector=normalize(velocity);vec3 direction=normalize(center-camera_Position);vec3 sideVector=normalize(cross(direction,normalize(velocity)));sideVector=renderer_SizeScale.xzy*sideVector;cameraUpVector=length(vec3(renderer_SizeScale.x,0.0,0.0))*cameraUpVector;vec2 size=computeParticleSizeBillboard(a_StartSize.xy,normalizedAge);const mat2 rotationZHalfPI=mat2(0.0,-1.0,1.0,0.0);corner=rotationZHalfPI*corner;corner.y=corner.y-abs(corner.y);float speed=length(velocity);center+=sign(renderer_SizeScale.x)*(sign(renderer_StretchedBillboardLengthScale)*size.x*corner.x*sideVector+(speed*renderer_StretchedBillboardSpeedScale+size.y*renderer_StretchedBillboardLengthScale)*corner.y*cameraUpVector);\n#endif\n"; // eslint-disable-line
3592
+ var stretched_billboard = "#define GLSLIFY 1\n#ifdef RENDERER_MODE_STRETCHED_BILLBOARD\n\tvec2 corner = a_CornerTextureCoordinate.xy + renderer_PivotOffset.xy;\n\tvec3 velocity;\n #if defined(RENDERER_VOL_CONSTANT) || defined(RENDERER_VOL_CURVE) || defined(RENDERER_VOL_RANDOM_CONSTANT) || defined(RENDERER_VOL_RANDOM_CURVE)\n if (renderer_VOLSpace == 0){\n velocity = rotationByQuaternions(renderer_SizeScale * (startVelocity + lifeVelocity),\n worldRotation)\n + gravityVelocity;\n\t\t}\n else{\n velocity = rotationByQuaternions(renderer_SizeScale * startVelocity, worldRotation) + lifeVelocity + gravityVelocity;\n\t\t}\n #else\n\t velocity = rotationByQuaternions(renderer_SizeScale * startVelocity, worldRotation) + gravityVelocity;\n #endif\n\tvec3 cameraUpVector = normalize(velocity);\n\tvec3 direction = normalize(center - camera_Position);\n\tvec3 sideVector = normalize(cross(direction, normalize(velocity)));\n\n\tsideVector = renderer_SizeScale.xzy * sideVector;\n\tcameraUpVector = length(vec3(renderer_SizeScale.x, 0.0, 0.0)) * cameraUpVector;\n\n\tvec2 size = computeParticleSizeBillboard(a_StartSize.xy, normalizedAge);\n\n\tconst mat2 rotationZHalfPI = mat2(0.0, -1.0, 1.0, 0.0);\n\tcorner = rotationZHalfPI * corner;\n\tcorner.y = corner.y - abs(corner.y);\n\n\tfloat speed = length(velocity); // TODO:\n\tcenter += sign(renderer_SizeScale.x) * (sign(renderer_StretchedBillboardLengthScale) * size.x * corner.x * sideVector\n\t + (speed * renderer_StretchedBillboardSpeedScale + size.y * renderer_StretchedBillboardLengthScale) * corner.y * cameraUpVector);\n#endif"; // eslint-disable-line
3593
3593
 
3594
- var vertical_billboard = "#define GLSLIFY 1\n#ifdef RENDERER_MODE_VERTICAL_BILLBOARD\nvec2 corner=a_CornerTextureCoordinate.xy+renderer_PivotOffset.xy;const vec3 cameraUpVector=vec3(0.0,1.0,0.0);vec3 sideVector=normalize(cross(camera_Forward,cameraUpVector));float rot=computeParticleRotationFloat(a_StartRotation0.x,age,normalizedAge);float c=cos(rot);float s=sin(rot);mat2 rotation=mat2(c,-s,s,c);corner=rotation*corner*cos(0.78539816339744830961566084581988);corner*=computeParticleSizeBillboard(a_StartSize.xy,normalizedAge);center+=renderer_SizeScale.xzy*(corner.x*sideVector+corner.y*cameraUpVector);\n#endif\n"; // eslint-disable-line
3594
+ var vertical_billboard = "#define GLSLIFY 1\n#ifdef RENDERER_MODE_VERTICAL_BILLBOARD\n\tvec2 corner = a_CornerTextureCoordinate.xy + renderer_PivotOffset.xy; // Billboard模式z轴无效\n\tconst vec3 cameraUpVector = vec3(0.0, 1.0, 0.0);\n\tvec3 sideVector = normalize(cross(camera_Forward, cameraUpVector));\n\n\tfloat rot = computeParticleRotationFloat(a_StartRotation0.x, age, normalizedAge);\n\tfloat c = cos(rot);\n\tfloat s = sin(rot);\n\tmat2 rotation = mat2(c, -s, s, c);\n\tcorner = rotation * corner * cos(0.78539816339744830961566084581988); // TODO:临时缩小cos45,不确定U3D原因\n\tcorner *= computeParticleSizeBillboard(a_StartSize.xy, normalizedAge);\n\tcenter += renderer_SizeScale.xzy * (corner.x * sideVector + corner.y * cameraUpVector);\n#endif"; // eslint-disable-line
3595
3595
 
3596
- var horizontal_billboard = "#define GLSLIFY 1\n#ifdef RENDERER_MODE_HORIZONTAL_BILLBOARD\nvec2 corner=a_CornerTextureCoordinate.xy+renderer_PivotOffset.xy;const vec3 cameraUpVector=vec3(0.0,0.0,1.0);const vec3 sideVector=vec3(-1.0,0.0,0.0);float rot=computeParticleRotationFloat(a_StartRotation0.x,age,normalizedAge);float c=cos(rot);float s=sin(rot);mat2 rotation=mat2(c,-s,s,c);corner=rotation*corner*cos(0.78539816339744830961566084581988);corner*=computeParticleSizeBillboard(a_StartSize.xy,normalizedAge);center+=renderer_SizeScale.xzy*(corner.x*sideVector+corner.y*cameraUpVector);\n#endif\n"; // eslint-disable-line
3596
+ var horizontal_billboard = "#define GLSLIFY 1\n#ifdef RENDERER_MODE_HORIZONTAL_BILLBOARD\n\tvec2 corner = a_CornerTextureCoordinate.xy + renderer_PivotOffset.xy; // Billboard模式z轴无效\n\tconst vec3 cameraUpVector = vec3(0.0, 0.0, 1.0);\n\tconst vec3 sideVector = vec3(-1.0, 0.0, 0.0);\n\n\tfloat rot = computeParticleRotationFloat(a_StartRotation0.x, age, normalizedAge);\n\tfloat c = cos(rot);\n\tfloat s = sin(rot);\n\tmat2 rotation = mat2(c, -s, s, c);\n\tcorner = rotation * corner * cos(0.78539816339744830961566084581988); // TODO:临时缩小cos45,不确定U3D原因\n\tcorner *= computeParticleSizeBillboard(a_StartSize.xy, normalizedAge);\n\tcenter += renderer_SizeScale.xzy * (corner.x * sideVector + corner.y * cameraUpVector);\n#endif"; // eslint-disable-line
3597
3597
 
3598
- var particle_mesh = "#define GLSLIFY 1\n#ifdef RENDERER_MODE_MESH\nvec3 size=computeParticleSizeMesh(a_StartSize,normalizedAge);\n#if defined(RENDERER_ROL_CONSTANT_MODE) || defined(RENDERER_ROL_CURVE_MODE)\nif(renderer_ThreeDStartRotation){vec3 rotation=vec3(a_StartRotation0.xy,computeParticleRotationFloat(a_StartRotation0.z,age,normalizedAge));center+=rotationByQuaternions(renderer_SizeScale*rotationByEuler(a_MeshPosition*size,rotation),worldRotation);}else{\n#ifdef RENDERER_ROL_IS_SEPARATE\nfloat angle=computeParticleRotationFloat(a_StartRotation0.x,age,normalizedAge);if(a_ShapePositionStartLifeTime.x!=0.0||a_ShapePositionStartLifeTime.y!=0.0){center+=(rotationByQuaternions(rotationByAxis(renderer_SizeScale*a_MeshPosition*size,normalize(cross(vec3(0.0,0.0,1.0),vec3(a_ShapePositionStartLifeTime.xy,0.0))),angle),worldRotation));}else{\n#ifdef SHAPE\ncenter+=renderer_SizeScale.xzy*(rotationByQuaternions(rotationByAxis(a_MeshPosition*size,vec3(0.0,-1.0,0.0),angle),worldRotation));\n#else\nif(renderer_SimulationSpace==1)center+=rotationByAxis(renderer_SizeScale*a_MeshPosition*size,vec3(0.0,0.0,-1.0),angle);else if(renderer_SimulationSpace==0)center+=rotationByQuaternions(renderer_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,0.0,-1.0),angle),worldRotation);\n#endif\n}\n#endif\n#ifdef ROTATION_OVER_LIFETIME_SEPARATE\nvec3 angle=computeParticleRotationVec3(vec3(0.0,0.0,-a_StartRotation0.x),age,normalizedAge);center+=(rotationByQuaternions(rotationByEuler(renderer_SizeScale*a_MeshPosition*size,vec3(angle.x,angle.y,angle.z)),worldRotation));\n#endif\n}\n#else\nif(renderer_ThreeDStartRotation){center+=rotationByQuaternions(renderer_SizeScale*rotationByEuler(a_MeshPosition*size,a_StartRotation0),worldRotation);}else{if(a_ShapePositionStartLifeTime.x!=0.0||a_ShapePositionStartLifeTime.y!=0.0){if(renderer_SimulationSpace==1)center+=rotationByAxis(renderer_SizeScale*a_MeshPosition*size,normalize(cross(vec3(0.0,0.0,1.0),vec3(a_ShapePositionStartLifeTime.xy,0.0))),a_StartRotation0.x);else if(renderer_SimulationSpace==0)center+=(rotationByQuaternions(renderer_SizeScale*rotationByAxis(a_MeshPosition*size,normalize(cross(vec3(0.0,0.0,1.0),vec3(a_ShapePositionStartLifeTime.xy,0.0))),a_StartRotation0.x),worldRotation));}else{\n#ifdef SHAPE\nif(renderer_SimulationSpace==1)center+=renderer_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,-1.0,0.0),a_StartRotation0.x);else if(renderer_SimulationSpace==0)center+=rotationByQuaternions(renderer_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,-1.0,0.0),a_StartRotation0.x),worldRotation);\n#else\nif(renderer_SimulationSpace==1)center+=rotationByAxis(renderer_SizeScale*a_MeshPosition*size,vec3(0.0,0.0,-1.0),a_StartRotation0.x);else if(renderer_SimulationSpace==0)center+=rotationByQuaternions(renderer_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,0.0,-1.0),a_StartRotation0.x),worldRotation);\n#endif\n}}\n#endif\nv_MeshColor=a_MeshColor;\n#endif\n"; // eslint-disable-line
3598
+ var particle_mesh = "#define GLSLIFY 1\n#ifdef RENDERER_MODE_MESH\n\tvec3 size = computeParticleSizeMesh(a_StartSize, normalizedAge);\n #if defined(RENDERER_ROL_CONSTANT_MODE) || defined(RENDERER_ROL_CURVE_MODE)\n if (renderer_ThreeDStartRotation) {\n vec3 rotation = vec3(\n a_StartRotation0.xy,\n computeParticleRotationFloat(a_StartRotation0.z, age, normalizedAge));\n center += rotationByQuaternions(\n renderer_SizeScale * rotationByEuler(a_MeshPosition * size, rotation),\n worldRotation);\n } else {\n #ifdef RENDERER_ROL_IS_SEPARATE\n float angle = computeParticleRotationFloat(a_StartRotation0.x, age, normalizedAge);\n if (a_ShapePositionStartLifeTime.x != 0.0 || a_ShapePositionStartLifeTime.y != 0.0) {\n center += (rotationByQuaternions(\n rotationByAxis(\n renderer_SizeScale * a_MeshPosition * size,\n normalize(cross(vec3(0.0, 0.0, 1.0),\n vec3(a_ShapePositionStartLifeTime.xy, 0.0))),\n angle),\n worldRotation)); //已验证\n } else {\n #ifdef SHAPE\n center += renderer_SizeScale.xzy * (rotationByQuaternions(rotationByAxis(a_MeshPosition * size, vec3(0.0, -1.0, 0.0), angle), worldRotation));\n #else\n if (renderer_SimulationSpace == 1)\n center += rotationByAxis(renderer_SizeScale * a_MeshPosition * size,\n vec3(0.0, 0.0, -1.0),\n angle); //已验证\n else if (renderer_SimulationSpace == 0)\n center += rotationByQuaternions(\n renderer_SizeScale * rotationByAxis(a_MeshPosition * size, vec3(0.0, 0.0, -1.0), angle),\n worldRotation); //已验证\n #endif\n }\n #endif\n #ifdef ROTATION_OVER_LIFETIME_SEPARATE\n // TODO:是否应合并if(renderer_ThreeDStartRotation)分支代码,待测试\n vec3 angle = computeParticleRotationVec3(\n vec3(0.0, 0.0, -a_StartRotation0.x), age, normalizedAge);\n center += (rotationByQuaternions(\n rotationByEuler(renderer_SizeScale * a_MeshPosition * size,\n vec3(angle.x, angle.y, angle.z)),\n worldRotation)); //已验证\n #endif\n }\n #else\n if (renderer_ThreeDStartRotation) {\n center += rotationByQuaternions(\n renderer_SizeScale * rotationByEuler(a_MeshPosition * size, a_StartRotation0),\n worldRotation); //已验证\n } else {\n if (a_ShapePositionStartLifeTime.x != 0.0 || a_ShapePositionStartLifeTime.y != 0.0) {\n if (renderer_SimulationSpace == 1)\n center += rotationByAxis(\n renderer_SizeScale * a_MeshPosition * size,\n normalize(cross(vec3(0.0, 0.0, 1.0),\n vec3(a_ShapePositionStartLifeTime.xy, 0.0))),\n a_StartRotation0.x);\n else if (renderer_SimulationSpace == 0)\n center += (rotationByQuaternions(\n renderer_SizeScale * rotationByAxis(a_MeshPosition * size, normalize(cross(vec3(0.0, 0.0, 1.0),\n vec3(a_ShapePositionStartLifeTime.xy, 0.0))), a_StartRotation0.x),\n worldRotation)); //已验证\n } else {\n #ifdef SHAPE\n if (renderer_SimulationSpace == 1)\n center += renderer_SizeScale * rotationByAxis(a_MeshPosition * size, vec3(0.0, -1.0, 0.0), a_StartRotation0.x);\n else if (renderer_SimulationSpace == 0)\n center += rotationByQuaternions(\n renderer_SizeScale * rotationByAxis(a_MeshPosition * size, vec3(0.0, -1.0, 0.0), a_StartRotation0.x),\n worldRotation);\n #else\n if (renderer_SimulationSpace == 1)\n center += rotationByAxis(renderer_SizeScale * a_MeshPosition * size,\n vec3(0.0, 0.0, -1.0),\n a_StartRotation0.x);\n else if (renderer_SimulationSpace == 0)\n center += rotationByQuaternions(\n renderer_SizeScale * rotationByAxis(a_MeshPosition * size, vec3(0.0, 0.0, -1.0), a_StartRotation0.x),\n worldRotation); //已验证\n #endif\n }\n }\n #endif\n\tv_MeshColor = a_MeshColor;\n#endif"; // eslint-disable-line
3599
3599
 
3600
3600
  var ParticleShaderLib = {
3601
3601
  particle_common: particle_common,
@@ -3611,7 +3611,7 @@ var ParticleShaderLib = {
3611
3611
  particle_mesh: particle_mesh
3612
3612
  };
3613
3613
 
3614
- var normal_get = "#define GLSLIFY 1\nvec3 getNormal(bool isFrontFacing){\n#ifdef RENDERER_HAS_NORMAL\nvec3 normal=normalize(v_normal);\n#elif defined(HAS_DERIVATIVES)\nvec3 pos_dx=dFdx(v_pos);vec3 pos_dy=dFdy(v_pos);vec3 normal=normalize(cross(pos_dx,pos_dy));normal*=camera_ProjectionParams.x;\n#else\nvec3 normal=vec3(0,0,1);\n#endif\nnormal*=float(isFrontFacing)*2.0-1.0;return normal;}vec3 getNormalByNormalTexture(mat3 tbn,sampler2D normalTexture,float normalIntensity,vec2 uv,bool isFrontFacing){vec3 normal=texture2D(normalTexture,uv).rgb;normal=normalize(tbn*((2.0*normal-1.0)*vec3(normalIntensity,normalIntensity,1.0)));normal*=float(isFrontFacing)*2.0-1.0;return normal;}mat3 getTBN(bool isFrontFacing){\n#if defined(RENDERER_HAS_NORMAL) && defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY) )\nmat3 tbn=v_TBN;\n#else\nvec3 normal=getNormal(isFrontFacing);vec3 position=v_pos;vec2 uv=isFrontFacing? v_uv:-v_uv;\n#ifdef HAS_DERIVATIVES\nvec3 dp1=dFdx(position);vec3 dp2=dFdy(position);vec2 duv1=dFdx(uv);vec2 duv2=dFdy(uv);vec3 dp2perp=cross(dp2,normal);vec3 dp1perp=cross(normal,dp1);vec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;vec3 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;float denom=max(dot(tangent,tangent),dot(bitangent,bitangent));float invmax=(denom==0.0)? 0.0 : camera_ProjectionParams.x/sqrt(denom);mat3 tbn=mat3(tangent*invmax,bitangent*invmax,normal);\n#else\nmat3 tbn=mat3(vec3(0.0),vec3(0.0),normal);\n#endif\n#endif\nreturn tbn;}"; // eslint-disable-line
3614
+ var normal_get = "#define GLSLIFY 1\n// gl_FrontFacing has random value on Adreno GPUs\n// the Adreno bug is only when gl_FrontFacing is inside a function\n// https://bugs.chromium.org/p/chromium/issues/detail?id=1154842\nvec3 getNormal(bool isFrontFacing){\n #ifdef RENDERER_HAS_NORMAL\n vec3 normal = normalize(v_normal);\n #elif defined(HAS_DERIVATIVES)\n vec3 pos_dx = dFdx(v_pos);\n vec3 pos_dy = dFdy(v_pos);\n vec3 normal = normalize( cross(pos_dx, pos_dy) );\n normal *= camera_ProjectionParams.x;\n #else\n vec3 normal = vec3(0, 0, 1);\n #endif\n\n normal *= float( isFrontFacing ) * 2.0 - 1.0;\n return normal;\n}\n\nvec3 getNormalByNormalTexture(mat3 tbn, sampler2D normalTexture, float normalIntensity, vec2 uv, bool isFrontFacing){\n vec3 normal = texture2D(normalTexture, uv).rgb;\n normal = normalize(tbn * ((2.0 * normal - 1.0) * vec3(normalIntensity, normalIntensity, 1.0)));\n normal *= float( isFrontFacing ) * 2.0 - 1.0;\n\n return normal;\n}\n\nmat3 getTBN(bool isFrontFacing){\n #if defined(RENDERER_HAS_NORMAL) && defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY) )\n mat3 tbn = v_TBN;\n #else\n vec3 normal = getNormal(isFrontFacing);\n vec3 position = v_pos;\n vec2 uv = isFrontFacing? v_uv: -v_uv;\n\n #ifdef HAS_DERIVATIVES\n // ref: http://www.thetenthplanet.de/archives/1180\n // get edge vectors of the pixel triangle\n\t vec3 dp1 = dFdx(position);\n\t vec3 dp2 = dFdy(position);\n\t vec2 duv1 = dFdx(uv);\n\t vec2 duv2 = dFdy(uv);\n\n\t // solve the linear system\n\t vec3 dp2perp = cross(dp2, normal);\n\t vec3 dp1perp = cross(normal, dp1);\n\t vec3 tangent = dp2perp * duv1.x + dp1perp * duv2.x;\n\t vec3 bitangent = dp2perp * duv1.y + dp1perp * duv2.y;\n\n\t // construct a scale-invariant frame \n float denom = max( dot(tangent, tangent), dot(bitangent, bitangent) );\n float invmax = (denom == 0.0) ? 0.0 : camera_ProjectionParams.x / sqrt( denom );\n\t mat3 tbn = mat3(tangent * invmax, bitangent * invmax, normal);\n #else\n mat3 tbn = mat3(vec3(0.0), vec3(0.0), normal);\n #endif\n #endif\n\t\n return tbn;\n}"; // eslint-disable-line
3615
3615
 
3616
3616
  var ShaderLib = _extends({
3617
3617
  common: common,
@@ -8792,62 +8792,8 @@ __decorate([
8792
8792
  }
8793
8793
  return currentRenderTarget;
8794
8794
  };
8795
- /**
8796
- * Blit texture to destination render target using a triangle.
8797
- * @param engine - Engine
8798
- * @param source - Source texture
8799
- * @param destination - Destination render target
8800
- * @param mipLevel - Mip level to blit
8801
- * @param viewport - Viewport
8802
- * @param material - The material to use when blitting
8803
- * @param passIndex - Pass index to use of the provided material
8804
- * @param flipYOfSource - Whether flip Y axis of source texture
8805
- */ PipelineUtils.blitTexture = function blitTexture(engine, source, destination, mipLevel, viewport, material, passIndex, flipYOfSource) {
8806
- if (mipLevel === void 0) mipLevel = 0;
8807
- if (viewport === void 0) viewport = PipelineUtils.defaultViewport;
8808
- if (material === void 0) material = null;
8809
- if (passIndex === void 0) passIndex = 0;
8810
- if (flipYOfSource === void 0) flipYOfSource = false;
8811
- var basicResources = engine._basicResources;
8812
- var blitMesh = destination ? basicResources.flipYBlitMesh : basicResources.blitMesh;
8813
- var blitMaterial = material || basicResources.blitMaterial;
8814
- var rhi = engine._hardwareRenderer;
8815
- var context = engine._renderContext;
8816
- // We not use projection matrix when blit, but we must modify flipProjection to make front face correct
8817
- context.flipProjection = !!destination;
8818
- rhi.activeRenderTarget(destination, viewport, context.flipProjection, 0);
8819
- var rendererShaderData = PipelineUtils._rendererShaderData;
8820
- rendererShaderData.setTexture(PipelineUtils._blitTextureProperty, source);
8821
- rendererShaderData.setFloat(PipelineUtils._blitMipLevelProperty, mipLevel);
8822
- PipelineUtils._texelSize.set(1 / source.width, 1 / source.height, source.width, source.height);
8823
- rendererShaderData.setVector4(PipelineUtils._blitTexelSizeProperty, PipelineUtils._texelSize);
8824
- if (flipYOfSource) {
8825
- rendererShaderData.enableMacro(PipelineUtils._flipYTextureMacro);
8826
- } else {
8827
- rendererShaderData.disableMacro(PipelineUtils._flipYTextureMacro);
8828
- }
8829
- var pass = blitMaterial.shader.subShaders[0].passes[passIndex];
8830
- var compileMacros = Shader._compileMacros;
8831
- ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, rendererShaderData._macroCollection, compileMacros);
8832
- ShaderMacroCollection.unionCollection(compileMacros, blitMaterial.shaderData._macroCollection, compileMacros);
8833
- var program = pass._getShaderProgram(engine, compileMacros);
8834
- program.bind();
8835
- program.groupingOtherUniformBlock();
8836
- program.uploadAll(program.rendererUniformBlock, rendererShaderData);
8837
- program.uploadAll(program.materialUniformBlock, blitMaterial.shaderData);
8838
- program.uploadUnGroupTextures();
8839
- (pass._renderState || blitMaterial.renderState)._applyStates(engine, false, pass._renderStateDataMap, blitMaterial.shaderData);
8840
- rhi.drawPrimitive(blitMesh._primitive, blitMesh.subMesh, program);
8841
- };
8842
8795
  return PipelineUtils;
8843
8796
  }();
8844
- PipelineUtils._blitTextureProperty = ShaderProperty.getByName("renderer_BlitTexture");
8845
- PipelineUtils._blitMipLevelProperty = ShaderProperty.getByName("renderer_BlitMipLevel");
8846
- PipelineUtils._blitTexelSizeProperty = ShaderProperty.getByName("renderer_texelSize") // x: 1/width, y: 1/height, z: width, w: height
8847
- ;
8848
- PipelineUtils._flipYTextureMacro = ShaderMacro.getByName("renderer_FlipYBlitTexture");
8849
- PipelineUtils._rendererShaderData = new ShaderData(ShaderDataGroup.Renderer);
8850
- PipelineUtils._texelSize = new engineMath.Vector4();
8851
8797
  PipelineUtils.defaultViewport = new engineMath.Vector4(0, 0, 1, 1);
8852
8798
 
8853
8799
  /**
@@ -8939,6 +8885,8 @@ exports.Camera = /*#__PURE__*/ function(Component) {
8939
8885
  * Culling mask - which layers the camera renders.
8940
8886
  * @remarks Support bit manipulation, corresponding to `Layer`.
8941
8887
  */ _this.cullingMask = Layer.Everything, /**
8888
+ * Determines which PostProcess to use.
8889
+ */ _this.postProcessMask = Layer.Everything, /**
8942
8890
  * Depth texture mode.
8943
8891
  * If `DepthTextureMode.PrePass` is used, the depth texture can be accessed in the shader using `camera_DepthTexture`.
8944
8892
  *
@@ -9285,7 +9233,7 @@ exports.Camera = /*#__PURE__*/ function(Component) {
9285
9233
  * @remarks If true, the msaa in viewport can turn or off independently by `msaaSamples` property.
9286
9234
  */ function get() {
9287
9235
  // Uber pass need internal RT
9288
- if (this.enablePostProcess && this.scene._postProcessManager.hasActiveEffect) {
9236
+ if (this.enablePostProcess && this.scene.postProcessManager._isValid()) {
9289
9237
  return true;
9290
9238
  }
9291
9239
  if (this.enableHDR || this.opaqueTextureEnabled) {
@@ -9826,6 +9774,62 @@ RenderContext._flipYViewProjectionMatrix = new engineMath.Matrix();
9826
9774
  return RenderQueue;
9827
9775
  }();
9828
9776
 
9777
+ /**
9778
+ * A helper class to blit texture to destination render target.
9779
+ */ var Blitter = /*#__PURE__*/ function() {
9780
+ function Blitter() {}
9781
+ /**
9782
+ * Blit texture to destination render target using a triangle.
9783
+ * @param engine - Engine
9784
+ * @param source - Source texture
9785
+ * @param destination - Destination render target
9786
+ * @param mipLevel - Mip level to blit
9787
+ * @param viewport - Viewport
9788
+ * @param material - The material to use when blit
9789
+ * @param passIndex - Pass index to use of the provided material
9790
+ * @param flipYOfSource - Whether flip Y axis of source texture
9791
+ */ Blitter.blitTexture = function blitTexture(engine, source, destination, mipLevel, viewport, material, passIndex, sourceScaleOffset) {
9792
+ if (mipLevel === void 0) mipLevel = 0;
9793
+ if (viewport === void 0) viewport = PipelineUtils.defaultViewport;
9794
+ if (material === void 0) material = null;
9795
+ if (passIndex === void 0) passIndex = 0;
9796
+ var basicResources = engine._basicResources;
9797
+ var blitMesh = destination ? basicResources.flipYBlitMesh : basicResources.blitMesh;
9798
+ var blitMaterial = material || basicResources.blitMaterial;
9799
+ var rhi = engine._hardwareRenderer;
9800
+ var context = engine._renderContext;
9801
+ // We not use projection matrix when blit, but we must modify flipProjection to make front face correct
9802
+ context.flipProjection = !!destination;
9803
+ rhi.activeRenderTarget(destination, viewport, context.flipProjection, 0);
9804
+ var rendererShaderData = Blitter._rendererShaderData;
9805
+ rendererShaderData.setTexture(Blitter._blitTextureProperty, source);
9806
+ rendererShaderData.setFloat(Blitter._blitMipLevelProperty, mipLevel);
9807
+ Blitter._texelSize.set(1 / source.width, 1 / source.height, source.width, source.height);
9808
+ rendererShaderData.setVector4(Blitter._blitTexelSizeProperty, Blitter._texelSize);
9809
+ rendererShaderData.setVector4(Blitter._sourceScaleOffsetProperty, sourceScaleOffset != null ? sourceScaleOffset : Blitter._defaultScaleOffset);
9810
+ var pass = blitMaterial.shader.subShaders[0].passes[passIndex];
9811
+ var compileMacros = Shader._compileMacros;
9812
+ ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, blitMaterial.shaderData._macroCollection, compileMacros);
9813
+ var program = pass._getShaderProgram(engine, compileMacros);
9814
+ program.bind();
9815
+ program.groupingOtherUniformBlock();
9816
+ program.uploadAll(program.rendererUniformBlock, rendererShaderData);
9817
+ program.uploadAll(program.materialUniformBlock, blitMaterial.shaderData);
9818
+ program.uploadUnGroupTextures();
9819
+ (pass._renderState || blitMaterial.renderState)._applyStates(engine, false, pass._renderStateDataMap, blitMaterial.shaderData);
9820
+ rhi.drawPrimitive(blitMesh._primitive, blitMesh.subMesh, program);
9821
+ };
9822
+ return Blitter;
9823
+ }();
9824
+ Blitter._blitTextureProperty = ShaderProperty.getByName("renderer_BlitTexture");
9825
+ Blitter._blitMipLevelProperty = ShaderProperty.getByName("renderer_BlitMipLevel");
9826
+ Blitter._blitTexelSizeProperty = ShaderProperty.getByName("renderer_texelSize") // x: 1/width, y: 1/height, z: width, w: height
9827
+ ;
9828
+ Blitter._sourceScaleOffsetProperty = ShaderProperty.getByName("renderer_SourceScaleOffset");
9829
+ Blitter._rendererShaderData = new ShaderData(ShaderDataGroup.Renderer);
9830
+ Blitter._texelSize = new engineMath.Vector4();
9831
+ Blitter._defaultScaleOffset = new engineMath.Vector4(1, 1, 0, 0);
9832
+
9829
9833
  /**
9830
9834
  * @internal
9831
9835
  */ var ShadowSliceData = function ShadowSliceData() {
@@ -10655,7 +10659,7 @@ CascadedShadowCasterPass._tempMatrix0 = new engineMath.Matrix();
10655
10659
  this._renderTarget = opaqueRenderTarget;
10656
10660
  };
10657
10661
  _proto.onRender = function onRender(context) {
10658
- PipelineUtils.blitTexture(this.engine, this._cameraColorTexture, this._renderTarget);
10662
+ Blitter.blitTexture(this.engine, this._cameraColorTexture, this._renderTarget);
10659
10663
  context.camera.shaderData.setTexture(exports.Camera._cameraOpaqueTextureProperty, this._renderTarget.getColorTexture(0));
10660
10664
  };
10661
10665
  return OpaqueTexturePass;
@@ -10669,6 +10673,7 @@ CascadedShadowCasterPass._tempMatrix0 = new engineMath.Matrix();
10669
10673
  this._internalColorTarget = null;
10670
10674
  this._canUseBlitFrameBuffer = false;
10671
10675
  this._shouldGrabColor = false;
10676
+ this._sourceScaleOffset = new engineMath.Vector4(1, 1, 0, 0);
10672
10677
  this._camera = camera;
10673
10678
  var engine = camera.engine;
10674
10679
  this._cullingResults = new CullingResults();
@@ -10795,8 +10800,11 @@ CascadedShadowCasterPass._tempMatrix0 = new engineMath.Matrix();
10795
10800
  // Copy RT's color buffer to grab texture
10796
10801
  rhi.copyRenderTargetToSubTexture(camera.renderTarget, this._grabTexture, camera.viewport);
10797
10802
  // Then blit grab texture to internal RT's color buffer
10798
- PipelineUtils.blitTexture(engine, this._grabTexture, internalColorTarget, 0, undefined, undefined, undefined, // Only flip Y axis in webgl context
10799
- !camera.renderTarget);
10803
+ var sourceScaleOffset = this._sourceScaleOffset;
10804
+ sourceScaleOffset.y = camera.renderTarget ? 1 : -1;
10805
+ sourceScaleOffset.w = camera.renderTarget ? 0 : 1;
10806
+ // `uv.y = 1.0 - uv.y` if grab from screen
10807
+ Blitter.blitTexture(engine, this._grabTexture, internalColorTarget, 0, undefined, undefined, undefined, sourceScaleOffset);
10800
10808
  } else {
10801
10809
  rhi.clearRenderTarget(engine, CameraClearFlags.All, color);
10802
10810
  }
@@ -10833,13 +10841,16 @@ CascadedShadowCasterPass._tempMatrix0 = new engineMath.Matrix();
10833
10841
  transparentQueue.render(context, PipelineStage.Forward);
10834
10842
  // Revert stencil buffer generated by mask
10835
10843
  maskManager.clearMask(context, PipelineStage.Forward);
10836
- var postProcessManager = scene._postProcessManager;
10844
+ var postProcessManager = scene.postProcessManager;
10837
10845
  var cameraRenderTarget = camera.renderTarget;
10838
- if (camera.enablePostProcess && postProcessManager.hasActiveEffect) {
10839
- postProcessManager._render(context, internalColorTarget, cameraRenderTarget);
10840
- } else if (internalColorTarget) {
10841
- internalColorTarget._blitRenderTarget();
10842
- PipelineUtils.blitTexture(engine, internalColorTarget.getColorTexture(0), cameraRenderTarget, 0, camera.viewport);
10846
+ if (camera.enablePostProcess && postProcessManager._isValid()) {
10847
+ postProcessManager._render(camera, internalColorTarget, cameraRenderTarget);
10848
+ } else {
10849
+ postProcessManager._releaseSwapRenderTarget();
10850
+ if (internalColorTarget) {
10851
+ internalColorTarget._blitRenderTarget();
10852
+ Blitter.blitTexture(engine, internalColorTarget.getColorTexture(0), cameraRenderTarget, 0, camera.viewport);
10853
+ }
10843
10854
  }
10844
10855
  cameraRenderTarget == null ? void 0 : cameraRenderTarget._blitRenderTarget();
10845
10856
  cameraRenderTarget == null ? void 0 : cameraRenderTarget.generateMipmaps();
@@ -12568,6 +12579,50 @@ var BaseMaterial = /*#__PURE__*/ function(Material) {
12568
12579
  target._isTransparent = this._isTransparent;
12569
12580
  target._blendMode = this._blendMode;
12570
12581
  };
12582
+ _proto._seIsTransparent = function _seIsTransparent(value) {
12583
+ if (value !== this._isTransparent) {
12584
+ this.setIsTransparent(0, value);
12585
+ var shaderData = this.shaderData;
12586
+ if (value) {
12587
+ // Use alpha test queue to simulate transparent shadow
12588
+ shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
12589
+ } else {
12590
+ var alphaCutoff = shaderData.getFloat(BaseMaterial._alphaCutoffProp);
12591
+ if (alphaCutoff) {
12592
+ shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
12593
+ } else {
12594
+ shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.Opaque);
12595
+ }
12596
+ }
12597
+ this._isTransparent = value;
12598
+ }
12599
+ };
12600
+ _proto._setAlphaCutoff = function _setAlphaCutoff(value) {
12601
+ var shaderData = this.shaderData;
12602
+ if (shaderData.getFloat(BaseMaterial._alphaCutoffProp) !== value) {
12603
+ if (value) {
12604
+ shaderData.enableMacro(BaseMaterial._alphaCutoffMacro);
12605
+ shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
12606
+ } else {
12607
+ shaderData.disableMacro(BaseMaterial._alphaCutoffMacro);
12608
+ if (this._isTransparent) {
12609
+ shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
12610
+ } else {
12611
+ shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.Opaque);
12612
+ }
12613
+ }
12614
+ var renderStates = this.renderStates;
12615
+ for(var i = 0, n = renderStates.length; i < n; i++){
12616
+ var renderState = renderStates[i];
12617
+ if (value > 0) {
12618
+ renderState.renderQueueType = renderState.blendState.targetBlendState.enabled ? RenderQueueType.Transparent : RenderQueueType.AlphaTest;
12619
+ } else {
12620
+ renderState.renderQueueType = renderState.blendState.targetBlendState.enabled ? RenderQueueType.Transparent : RenderQueueType.Opaque;
12621
+ }
12622
+ }
12623
+ shaderData.setFloat(BaseMaterial._alphaCutoffProp, value);
12624
+ }
12625
+ };
12571
12626
  _create_class(BaseMaterial, [
12572
12627
  {
12573
12628
  key: "shader",
@@ -12609,22 +12664,7 @@ var BaseMaterial = /*#__PURE__*/ function(Material) {
12609
12664
  return this._isTransparent;
12610
12665
  },
12611
12666
  set: function set(value) {
12612
- if (value !== this._isTransparent) {
12613
- this.setIsTransparent(0, value);
12614
- var shaderData = this.shaderData;
12615
- if (value) {
12616
- // Use alpha test queue to simulate transparent shadow
12617
- shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
12618
- } else {
12619
- var alphaCutoff = shaderData.getFloat(BaseMaterial._alphaCutoffProp);
12620
- if (alphaCutoff) {
12621
- shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
12622
- } else {
12623
- shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.Opaque);
12624
- }
12625
- }
12626
- this._isTransparent = value;
12627
- }
12667
+ this._seIsTransparent(value);
12628
12668
  }
12629
12669
  },
12630
12670
  {
@@ -12653,30 +12693,7 @@ var BaseMaterial = /*#__PURE__*/ function(Material) {
12653
12693
  return this.shaderData.getFloat(BaseMaterial._alphaCutoffProp);
12654
12694
  },
12655
12695
  set: function set(value) {
12656
- var shaderData = this.shaderData;
12657
- if (shaderData.getFloat(BaseMaterial._alphaCutoffProp) !== value) {
12658
- if (value) {
12659
- shaderData.enableMacro(BaseMaterial._alphaCutoffMacro);
12660
- shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
12661
- } else {
12662
- shaderData.disableMacro(BaseMaterial._alphaCutoffMacro);
12663
- if (this._isTransparent) {
12664
- shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.AlphaTest);
12665
- } else {
12666
- shaderData.setFloat(BaseMaterial._shadowCasterRenderQueueProp, RenderQueueType.Opaque);
12667
- }
12668
- }
12669
- var renderStates = this.renderStates;
12670
- for(var i = 0, n = renderStates.length; i < n; i++){
12671
- var renderState = renderStates[i];
12672
- if (value > 0) {
12673
- renderState.renderQueueType = renderState.blendState.targetBlendState.enabled ? RenderQueueType.Transparent : RenderQueueType.AlphaTest;
12674
- } else {
12675
- renderState.renderQueueType = renderState.blendState.targetBlendState.enabled ? RenderQueueType.Transparent : RenderQueueType.Opaque;
12676
- }
12677
- }
12678
- shaderData.setFloat(BaseMaterial._alphaCutoffProp, value);
12679
- }
12696
+ this._setAlphaCutoff(value);
12680
12697
  }
12681
12698
  },
12682
12699
  {
@@ -13152,6 +13169,14 @@ PBRBaseMaterial._clearCoatRoughnessProp = ShaderProperty.getByName("material_Cle
13152
13169
  PBRBaseMaterial._clearCoatRoughnessTextureProp = ShaderProperty.getByName("material_ClearCoatRoughnessTexture");
13153
13170
  PBRBaseMaterial._clearCoatNormalTextureProp = ShaderProperty.getByName("material_ClearCoatNormalTexture");
13154
13171
 
13172
+ /**
13173
+ * Refraction mode.
13174
+ */ var RefractionMode = /*#__PURE__*/ function(RefractionMode) {
13175
+ /** Use the sphere refraction model when light passes through the surface. */ RefractionMode[RefractionMode["Sphere"] = 0] = "Sphere";
13176
+ /** Use the planar refraction model when light passes through the surface. */ RefractionMode[RefractionMode["Planar"] = 1] = "Planar";
13177
+ return RefractionMode;
13178
+ }({});
13179
+
13155
13180
  /**
13156
13181
  * PBR (Metallic-Roughness Workflow) Material.
13157
13182
  */ var PBRMaterial = /*#__PURE__*/ function(PBRBaseMaterial) {
@@ -13167,28 +13192,19 @@ PBRBaseMaterial._clearCoatNormalTextureProp = ShaderProperty.getByName("material
13167
13192
  shaderData.setVector4(PBRMaterial._iridescenceInfoProp, new engineMath.Vector4(0, 1.3, 100, 400));
13168
13193
  var sheenColor = new engineMath.Color(0, 0, 0);
13169
13194
  shaderData.setColor(PBRMaterial._sheenColorProp, sheenColor);
13195
+ _this.refractionMode = RefractionMode.Planar;
13196
+ shaderData.setFloat(PBRMaterial._transmissionProp, 0);
13197
+ shaderData.setFloat(PBRMaterial._thicknessProp, 0);
13198
+ shaderData.setFloat(PBRMaterial._attenuationDistanceProp, Infinity);
13199
+ var attenuationColor = new engineMath.Color(1, 1, 1);
13200
+ shaderData.setColor(PBRMaterial._attenuationColorProp, attenuationColor);
13170
13201
  // @ts-ignore
13171
13202
  _this._iridescenceRange._onValueChanged = _this._onIridescenceRangeChanged.bind(_this);
13172
13203
  // @ts-ignore
13173
- sheenColor._onValueChanged = function() {
13174
- var enableSheen = sheenColor.r + sheenColor.g + sheenColor.b > 0;
13175
- if (enableSheen !== _this._sheenEnabled) {
13176
- _this._sheenEnabled = enableSheen;
13177
- if (enableSheen) {
13178
- _this.shaderData.enableMacro("MATERIAL_ENABLE_SHEEN");
13179
- } else {
13180
- _this.shaderData.disableMacro("MATERIAL_ENABLE_SHEEN");
13181
- }
13182
- }
13183
- };
13204
+ sheenColor._onValueChanged = _this._onSheenColorChanged.bind(_this);
13184
13205
  return _this;
13185
13206
  }
13186
13207
  var _proto = PBRMaterial.prototype;
13187
- _proto._onIridescenceRangeChanged = function _onIridescenceRangeChanged() {
13188
- var iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
13189
- iridescenceInfo.z = this._iridescenceRange.x;
13190
- iridescenceInfo.w = this._iridescenceRange.y;
13191
- };
13192
13208
  /**
13193
13209
  * @inheritdoc
13194
13210
  */ _proto.clone = function clone() {
@@ -13196,6 +13212,23 @@ PBRBaseMaterial._clearCoatNormalTextureProp = ShaderProperty.getByName("material
13196
13212
  this.cloneTo(dest);
13197
13213
  return dest;
13198
13214
  };
13215
+ _proto._onIridescenceRangeChanged = function _onIridescenceRangeChanged() {
13216
+ var iridescenceInfo = this.shaderData.getVector4(PBRMaterial._iridescenceInfoProp);
13217
+ iridescenceInfo.z = this._iridescenceRange.x;
13218
+ iridescenceInfo.w = this._iridescenceRange.y;
13219
+ };
13220
+ _proto._onSheenColorChanged = function _onSheenColorChanged() {
13221
+ var sheenColor = this.sheenColor;
13222
+ var enableSheen = sheenColor.r + sheenColor.g + sheenColor.b > 0;
13223
+ if (enableSheen !== this._sheenEnabled) {
13224
+ this._sheenEnabled = enableSheen;
13225
+ if (enableSheen) {
13226
+ this.shaderData.enableMacro("MATERIAL_ENABLE_SHEEN");
13227
+ } else {
13228
+ this.shaderData.disableMacro("MATERIAL_ENABLE_SHEEN");
13229
+ }
13230
+ }
13231
+ };
13199
13232
  _create_class(PBRMaterial, [
13200
13233
  {
13201
13234
  key: "ior",
@@ -13450,6 +13483,154 @@ PBRBaseMaterial._clearCoatNormalTextureProp = ShaderProperty.getByName("material
13450
13483
  this.shaderData.disableMacro("MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE");
13451
13484
  }
13452
13485
  }
13486
+ },
13487
+ {
13488
+ key: "refractionMode",
13489
+ get: /**
13490
+ * Refraction switch.
13491
+ * @remarks Use refractionMode to set the refraction shape.
13492
+ */ function get() {
13493
+ return this._refractionMode;
13494
+ },
13495
+ set: function set(value) {
13496
+ if (value !== this._refractionMode) {
13497
+ this._refractionMode = value;
13498
+ this.shaderData.enableMacro("REFRACTION_MODE", value.toString());
13499
+ }
13500
+ }
13501
+ },
13502
+ {
13503
+ key: "isTransparent",
13504
+ get: /**
13505
+ * @inheritdoc
13506
+ */ function get() {
13507
+ return this._isTransparent;
13508
+ },
13509
+ set: function set(value) {
13510
+ this._seIsTransparent(value);
13511
+ if (this.transmission > 0) {
13512
+ // If transmission enabled, always use transparent queue to ensure get correct opaque texture
13513
+ this.renderState.renderQueueType = RenderQueueType.Transparent;
13514
+ }
13515
+ }
13516
+ },
13517
+ {
13518
+ key: "alphaCutoff",
13519
+ get: /**
13520
+ * @inheritdoc
13521
+ */ function get() {
13522
+ return this.shaderData.getFloat(BaseMaterial._alphaCutoffProp);
13523
+ },
13524
+ set: function set(value) {
13525
+ this._setAlphaCutoff(value);
13526
+ if (this.transmission > 0) {
13527
+ // If transmission enabled, always use transparent queue to ensure get correct opaque texture
13528
+ this.renderState.renderQueueType = RenderQueueType.Transparent;
13529
+ }
13530
+ }
13531
+ },
13532
+ {
13533
+ key: "transmission",
13534
+ get: /**
13535
+ * Transmission factor.
13536
+ * @defaultValue `0.0`
13537
+ */ function get() {
13538
+ return this.shaderData.getFloat(PBRMaterial._transmissionProp);
13539
+ },
13540
+ set: function set(value) {
13541
+ value = engineMath.MathUtil.clamp(value, 0, 1);
13542
+ if (!!this.shaderData.getFloat(PBRMaterial._transmissionProp) !== !!value) {
13543
+ if (value > 0) {
13544
+ this.shaderData.enableMacro(PBRMaterial._transmissionMacro);
13545
+ this.renderState.renderQueueType = RenderQueueType.Transparent;
13546
+ } else {
13547
+ this.shaderData.disableMacro(PBRMaterial._transmissionMacro);
13548
+ }
13549
+ }
13550
+ this.shaderData.setFloat(PBRMaterial._transmissionProp, value);
13551
+ }
13552
+ },
13553
+ {
13554
+ key: "transmissionTexture",
13555
+ get: /**
13556
+ * Transmission texture.
13557
+ * @remarks Use red channel, and multiply 'transmission'.
13558
+ */ function get() {
13559
+ return this.shaderData.getTexture(PBRMaterial._transmissionTextureProp);
13560
+ },
13561
+ set: function set(value) {
13562
+ this.shaderData.setTexture(PBRMaterial._transmissionTextureProp, value);
13563
+ if (value) {
13564
+ this.shaderData.enableMacro(PBRMaterial._transmissionTextureMacro);
13565
+ } else {
13566
+ this.shaderData.disableMacro(PBRMaterial._transmissionTextureMacro);
13567
+ }
13568
+ }
13569
+ },
13570
+ {
13571
+ key: "attenuationColor",
13572
+ get: /**
13573
+ * Attenuation color.
13574
+ * @defaultValue `[1,1,1]`
13575
+ */ function get() {
13576
+ return this.shaderData.getColor(PBRMaterial._attenuationColorProp);
13577
+ },
13578
+ set: function set(value) {
13579
+ var attenuationColor = this.shaderData.getColor(PBRMaterial._attenuationColorProp);
13580
+ if (value !== attenuationColor) {
13581
+ attenuationColor.copyFrom(value);
13582
+ }
13583
+ }
13584
+ },
13585
+ {
13586
+ key: "attenuationDistance",
13587
+ get: /**
13588
+ * Attenuation distance, greater than 0.0.
13589
+ * @defaultValue `infinity`
13590
+ */ function get() {
13591
+ return this.shaderData.getFloat(PBRMaterial._attenuationDistanceProp);
13592
+ },
13593
+ set: function set(value) {
13594
+ value = Math.max(0, value);
13595
+ this.shaderData.setFloat(PBRMaterial._attenuationDistanceProp, value);
13596
+ }
13597
+ },
13598
+ {
13599
+ key: "thickness",
13600
+ get: /**
13601
+ * Thickness, greater than or equal to 0.0.
13602
+ * @defaultValue `0.0`
13603
+ */ function get() {
13604
+ return this.shaderData.getFloat(PBRMaterial._thicknessProp);
13605
+ },
13606
+ set: function set(value) {
13607
+ value = Math.max(0, value);
13608
+ if (!!this.shaderData.getFloat(PBRMaterial._thicknessProp) !== !!value) {
13609
+ if (value > 0) {
13610
+ this.shaderData.enableMacro(PBRMaterial._thicknessMacro);
13611
+ } else {
13612
+ this.shaderData.disableMacro(PBRMaterial._thicknessMacro);
13613
+ }
13614
+ }
13615
+ this.shaderData.setFloat(PBRMaterial._thicknessProp, value);
13616
+ }
13617
+ },
13618
+ {
13619
+ key: "thicknessTexture",
13620
+ get: /**
13621
+ * Thickness texture.
13622
+ * @remarks Use green channel, and multiply 'thickness', range is 0.0 to 1.0.
13623
+ */ function get() {
13624
+ return this.shaderData.getTexture(PBRMaterial._thicknessTextureProp);
13625
+ },
13626
+ set: function set(value) {
13627
+ this.shaderData.setTexture(PBRMaterial._thicknessTextureProp, value);
13628
+ if (value) {
13629
+ this.shaderData.enableMacro(PBRMaterial._thicknessTextureMacro);
13630
+ } else {
13631
+ this.shaderData.disableMacro(PBRMaterial._thicknessTextureMacro);
13632
+ }
13633
+ }
13453
13634
  }
13454
13635
  ]);
13455
13636
  return PBRMaterial;
@@ -13467,6 +13648,16 @@ PBRMaterial._sheenColorProp = ShaderProperty.getByName("material_SheenColor");
13467
13648
  PBRMaterial._sheenRoughnessProp = ShaderProperty.getByName("material_SheenRoughness");
13468
13649
  PBRMaterial._sheenTextureProp = ShaderProperty.getByName("material_SheenTexture");
13469
13650
  PBRMaterial._sheenRoughnessTextureProp = ShaderProperty.getByName("material_SheenRoughnessTexture");
13651
+ PBRMaterial._transmissionMacro = ShaderMacro.getByName("MATERIAL_ENABLE_TRANSMISSION");
13652
+ PBRMaterial._thicknessMacro = ShaderMacro.getByName("MATERIAL_HAS_THICKNESS");
13653
+ PBRMaterial._thicknessTextureMacro = ShaderMacro.getByName("MATERIAL_HAS_THICKNESS_TEXTURE");
13654
+ PBRMaterial._transmissionTextureMacro = ShaderMacro.getByName("MATERIAL_HAS_TRANSMISSION_TEXTURE");
13655
+ PBRMaterial._transmissionProp = ShaderProperty.getByName("material_Transmission");
13656
+ PBRMaterial._transmissionTextureProp = ShaderProperty.getByName("material_TransmissionTexture");
13657
+ PBRMaterial._attenuationColorProp = ShaderProperty.getByName("material_AttenuationColor");
13658
+ PBRMaterial._attenuationDistanceProp = ShaderProperty.getByName("material_AttenuationDistance");
13659
+ PBRMaterial._thicknessProp = ShaderProperty.getByName("material_Thickness");
13660
+ PBRMaterial._thicknessTextureProp = ShaderProperty.getByName("material_ThicknessTexture");
13470
13661
 
13471
13662
  /**
13472
13663
  * PBR (Specular-Glossiness Workflow) Material.
@@ -18767,6 +18958,7 @@ PrimitiveChunk.subMeshPool = new ReturnableObjectPool(SubMesh, 10);
18767
18958
  /** Source Font, include ttf, otf and woff. */ AssetType["SourceFont"] = "SourceFont";
18768
18959
  /** AudioClip, include ogg, wav and mp3. */ AssetType["Audio"] = "Audio";
18769
18960
  /** Project asset. */ AssetType["Project"] = "project";
18961
+ /** PhysicsMaterial. */ AssetType["PhysicsMaterial"] = "PhysicsMaterial";
18770
18962
  return AssetType;
18771
18963
  }({});
18772
18964
 
@@ -19304,8 +19496,8 @@ var MultiExecutor = /*#__PURE__*/ function() {
19304
19496
  this._subAssetPromiseCallbacks = {};
19305
19497
  this.//-----------------Editor temp solution-----------------
19306
19498
  /** @internal */ _objectPool = Object.create(null);
19307
- this./** @internal */ _editorResourceConfig = Object.create(null);
19308
- this./** @internal */ _virtualPathMap = Object.create(null);
19499
+ this./** @internal */ _idResourceMap = Object.create(null);
19500
+ this./** @internal */ _virtualPathResourceMap = Object.create(null);
19309
19501
  }
19310
19502
  var _proto = ResourceManager.prototype;
19311
19503
  _proto.load = function load(assetInfo) {
@@ -19382,8 +19574,9 @@ var MultiExecutor = /*#__PURE__*/ function() {
19382
19574
  /**
19383
19575
  * @internal
19384
19576
  */ _proto._getRemoteUrl = function _getRemoteUrl(url) {
19385
- var _this__virtualPathMap_url;
19386
- return (_this__virtualPathMap_url = this._virtualPathMap[url]) != null ? _this__virtualPathMap_url : url;
19577
+ var _this__virtualPathResourceMap_url;
19578
+ var _this__virtualPathResourceMap_url_path;
19579
+ return (_this__virtualPathResourceMap_url_path = (_this__virtualPathResourceMap_url = this._virtualPathResourceMap[url]) == null ? void 0 : _this__virtualPathResourceMap_url.path) != null ? _this__virtualPathResourceMap_url_path : url;
19387
19580
  };
19388
19581
  /**
19389
19582
  * @internal
@@ -19399,9 +19592,9 @@ var MultiExecutor = /*#__PURE__*/ function() {
19399
19592
  /**
19400
19593
  * @internal
19401
19594
  */ _proto._onSubAssetSuccess = function _onSubAssetSuccess(assetBaseURL, assetSubPath, value) {
19402
- var _this__subAssetPromiseCallbacks_remoteAssetBaseURL;
19403
- var _this__virtualPathMap_assetBaseURL;
19404
- var remoteAssetBaseURL = (_this__virtualPathMap_assetBaseURL = this._virtualPathMap[assetBaseURL]) != null ? _this__virtualPathMap_assetBaseURL : assetBaseURL;
19595
+ var _this__virtualPathResourceMap_assetBaseURL, _this__subAssetPromiseCallbacks_remoteAssetBaseURL;
19596
+ var _this__virtualPathResourceMap_assetBaseURL_path;
19597
+ var remoteAssetBaseURL = (_this__virtualPathResourceMap_assetBaseURL_path = (_this__virtualPathResourceMap_assetBaseURL = this._virtualPathResourceMap[assetBaseURL]) == null ? void 0 : _this__virtualPathResourceMap_assetBaseURL.path) != null ? _this__virtualPathResourceMap_assetBaseURL_path : assetBaseURL;
19405
19598
  var subPromiseCallback = (_this__subAssetPromiseCallbacks_remoteAssetBaseURL = this._subAssetPromiseCallbacks[remoteAssetBaseURL]) == null ? void 0 : _this__subAssetPromiseCallbacks_remoteAssetBaseURL[assetSubPath];
19406
19599
  if (subPromiseCallback) {
19407
19600
  subPromiseCallback.resolve(value);
@@ -19527,6 +19720,7 @@ var MultiExecutor = /*#__PURE__*/ function() {
19527
19720
  };
19528
19721
  _proto._loadSingleItem = function _loadSingleItem(itemOrURL) {
19529
19722
  var _this = this;
19723
+ var _this__virtualPathResourceMap_assetBaseURL;
19530
19724
  var item = this._assignDefaultOptions(typeof itemOrURL === "string" ? {
19531
19725
  url: itemOrURL
19532
19726
  } : itemOrURL);
@@ -19536,9 +19730,9 @@ var MultiExecutor = /*#__PURE__*/ function() {
19536
19730
  // Parse url
19537
19731
  var _this__parseURL = this._parseURL(url), assetBaseURL = _this__parseURL.assetBaseURL, queryPath = _this__parseURL.queryPath;
19538
19732
  var paths = queryPath ? this._parseQueryPath(queryPath) : [];
19539
- var _this__virtualPathMap_assetBaseURL;
19733
+ var _this__virtualPathResourceMap_assetBaseURL_path;
19540
19734
  // Get remote asset base url
19541
- var remoteAssetBaseURL = (_this__virtualPathMap_assetBaseURL = this._virtualPathMap[assetBaseURL]) != null ? _this__virtualPathMap_assetBaseURL : assetBaseURL;
19735
+ var remoteAssetBaseURL = (_this__virtualPathResourceMap_assetBaseURL_path = (_this__virtualPathResourceMap_assetBaseURL = this._virtualPathResourceMap[assetBaseURL]) == null ? void 0 : _this__virtualPathResourceMap_assetBaseURL.path) != null ? _this__virtualPathResourceMap_assetBaseURL_path : assetBaseURL;
19542
19736
  // Check cache
19543
19737
  var cacheObject = this._assetUrlPool[remoteAssetBaseURL];
19544
19738
  if (cacheObject) {
@@ -19703,9 +19897,9 @@ var MultiExecutor = /*#__PURE__*/ function() {
19703
19897
  if (obj) {
19704
19898
  promise = Promise.resolve(obj);
19705
19899
  } else {
19706
- var resourceConfig = this._editorResourceConfig[refId];
19900
+ var resourceConfig = this._idResourceMap[refId];
19707
19901
  if (!resourceConfig) {
19708
- Logger.warn("refId:" + refId + " is not find in this._editorResourceConfig.");
19902
+ Logger.warn("refId:" + refId + " is not find in this._idResourceMap.");
19709
19903
  return Promise.resolve(null);
19710
19904
  }
19711
19905
  var url = resourceConfig.virtualPath;
@@ -19727,8 +19921,11 @@ var MultiExecutor = /*#__PURE__*/ function() {
19727
19921
  */ _proto.initVirtualResources = function initVirtualResources(config) {
19728
19922
  var _this = this;
19729
19923
  config.forEach(function(element) {
19730
- _this._virtualPathMap[element.virtualPath] = element.path;
19731
- _this._editorResourceConfig[element.id] = element;
19924
+ _this._virtualPathResourceMap[element.virtualPath] = element;
19925
+ _this._idResourceMap[element.id] = element;
19926
+ if (element.dependentAssetMap) {
19927
+ _this._virtualPathResourceMap[element.virtualPath].dependentAssetMap = element.dependentAssetMap;
19928
+ }
19732
19929
  });
19733
19930
  };
19734
19931
  /**
@@ -20499,9 +20696,55 @@ exports.Collider = __decorate([
20499
20696
  dependentComponents(Transform, DependentMode.CheckOnly)
20500
20697
  ], exports.Collider);
20501
20698
 
20502
- var Collision = function Collision() {
20699
+ /**
20700
+ * Describes a contact point where the collision occurs.
20701
+ */ var ContactPoint = function ContactPoint() {
20702
+ /** The position of the contact point between the shapes, in world space. */ this.position = new engineMath.Vector3();
20703
+ /** The normal of the contacting surfaces at the contact point. The normal direction points from the second shape to the first shape. */ this.normal = new engineMath.Vector3();
20704
+ /** The impulse applied at the contact point, in world space. Divide by the simulation time step to get a force value. */ this.impulse = new engineMath.Vector3();
20503
20705
  };
20504
20706
 
20707
+ /**
20708
+ * Collision information between two shapes when they collide.
20709
+ */ var Collision = /*#__PURE__*/ function() {
20710
+ function Collision() {}
20711
+ var _proto = Collision.prototype;
20712
+ /**
20713
+ * Get contact points.
20714
+ * @param outContacts - The result of contact points
20715
+ * @returns The actual count of contact points
20716
+ *
20717
+ * @remarks To optimize performance, the engine does not modify the length of the array you pass.
20718
+ * You need to obtain the actual number of contact points from the function's return value.
20719
+ */ _proto.getContacts = function getContacts(outContacts) {
20720
+ var nativeCollision = this._nativeCollision;
20721
+ var factor = nativeCollision.shape0Id < nativeCollision.shape1Id ? 1 : -1;
20722
+ var nativeContactPoints = nativeCollision.getContacts();
20723
+ var length = nativeContactPoints.size();
20724
+ for(var i = 0; i < length; i++){
20725
+ var _outContacts, _i;
20726
+ var nativeContractPoint = nativeContactPoints.get(i);
20727
+ var contact = (_outContacts = outContacts)[_i = i] || (_outContacts[_i] = new ContactPoint());
20728
+ contact.position.copyFrom(nativeContractPoint.position);
20729
+ contact.normal.copyFrom(nativeContractPoint.normal).scale(factor);
20730
+ contact.impulse.copyFrom(nativeContractPoint.impulse).scale(factor);
20731
+ contact.separation = nativeContractPoint.separation;
20732
+ }
20733
+ return length;
20734
+ };
20735
+ _create_class(Collision, [
20736
+ {
20737
+ key: "contactCount",
20738
+ get: /**
20739
+ * Count of contact points.
20740
+ */ function get() {
20741
+ return this._nativeCollision.contactCount;
20742
+ }
20743
+ }
20744
+ ]);
20745
+ return Collision;
20746
+ }();
20747
+
20505
20748
  /**
20506
20749
  * A physics scene is a collection of colliders and constraints which can interact.
20507
20750
  */ var PhysicsScene = /*#__PURE__*/ function() {
@@ -20510,57 +20753,60 @@ var Collision = function Collision() {
20510
20753
  this._fixedTimeStep = 1 / 60;
20511
20754
  this._colliders = new DisorderedArray();
20512
20755
  this._gravity = new engineMath.Vector3(0, -9.81, 0);
20513
- this._onContactEnter = function(obj1, obj2) {
20756
+ this._onContactEnter = function(nativeCollision) {
20514
20757
  var physicalObjectsMap = Engine._physicalObjectsMap;
20515
- var shape1 = physicalObjectsMap[obj1];
20516
- var shape2 = physicalObjectsMap[obj2];
20758
+ var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
20759
+ var shape1 = physicalObjectsMap[shape0Id];
20760
+ var shape2 = physicalObjectsMap[shape1Id];
20761
+ var collision = PhysicsScene._collision;
20762
+ collision._nativeCollision = nativeCollision;
20517
20763
  shape1.collider.entity._scripts.forEach(function(element) {
20518
- var collision = PhysicsScene._collision;
20519
20764
  collision.shape = shape2;
20520
20765
  element.onCollisionEnter(collision);
20521
20766
  }, function(element, index) {
20522
20767
  element._entityScriptsIndex = index;
20523
20768
  });
20524
20769
  shape2.collider.entity._scripts.forEach(function(element) {
20525
- var collision = PhysicsScene._collision;
20526
20770
  collision.shape = shape1;
20527
20771
  element.onCollisionEnter(collision);
20528
20772
  }, function(element, index) {
20529
20773
  element._entityScriptsIndex = index;
20530
20774
  });
20531
20775
  };
20532
- this._onContactExit = function(obj1, obj2) {
20776
+ this._onContactExit = function(nativeCollision) {
20533
20777
  var physicalObjectsMap = Engine._physicalObjectsMap;
20534
- var shape1 = physicalObjectsMap[obj1];
20535
- var shape2 = physicalObjectsMap[obj2];
20778
+ var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
20779
+ var shape1 = physicalObjectsMap[shape0Id];
20780
+ var shape2 = physicalObjectsMap[shape1Id];
20781
+ var collision = PhysicsScene._collision;
20782
+ collision._nativeCollision = nativeCollision;
20536
20783
  shape1.collider.entity._scripts.forEach(function(element) {
20537
- var collision = PhysicsScene._collision;
20538
20784
  collision.shape = shape2;
20539
20785
  element.onCollisionExit(collision);
20540
20786
  }, function(element, index) {
20541
20787
  element._entityScriptsIndex = index;
20542
20788
  });
20543
20789
  shape2.collider.entity._scripts.forEach(function(element) {
20544
- var collision = PhysicsScene._collision;
20545
20790
  collision.shape = shape1;
20546
20791
  element.onCollisionExit(collision);
20547
20792
  }, function(element, index) {
20548
20793
  element._entityScriptsIndex = index;
20549
20794
  });
20550
20795
  };
20551
- this._onContactStay = function(obj1, obj2) {
20796
+ this._onContactStay = function(nativeCollision) {
20552
20797
  var physicalObjectsMap = Engine._physicalObjectsMap;
20553
- var shape1 = physicalObjectsMap[obj1];
20554
- var shape2 = physicalObjectsMap[obj2];
20798
+ var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
20799
+ var shape1 = physicalObjectsMap[shape0Id];
20800
+ var shape2 = physicalObjectsMap[shape1Id];
20801
+ var collision = PhysicsScene._collision;
20802
+ collision._nativeCollision = nativeCollision;
20555
20803
  shape1.collider.entity._scripts.forEach(function(element) {
20556
- var collision = PhysicsScene._collision;
20557
20804
  collision.shape = shape2;
20558
20805
  element.onCollisionStay(collision);
20559
20806
  }, function(element, index) {
20560
20807
  element._entityScriptsIndex = index;
20561
20808
  });
20562
20809
  shape2.collider.entity._scripts.forEach(function(element) {
20563
- var collision = PhysicsScene._collision;
20564
20810
  collision.shape = shape1;
20565
20811
  element.onCollisionStay(collision);
20566
20812
  }, function(element, index) {
@@ -20796,7 +21042,7 @@ PhysicsScene._collision = new Collision();
20796
21042
  _inherits(CharacterController, Collider);
20797
21043
  function CharacterController(entity) {
20798
21044
  var _this;
20799
- _this = Collider.call(this, entity) || this, _this._stepOffset = 0.5, _this._nonWalkableMode = ControllerNonWalkableMode.PreventClimbing, _this._upDirection = new engineMath.Vector3(0, 1, 0), _this._slopeLimit = 0.707;
21045
+ _this = Collider.call(this, entity) || this, _this._stepOffset = 0.5, _this._nonWalkableMode = ControllerNonWalkableMode.PreventClimbing, _this._upDirection = new engineMath.Vector3(0, 1, 0), _this._slopeLimit = 45;
20800
21046
  _this._nativeCollider = PhysicsScene._nativePhysics.createCharacterController();
20801
21047
  _this._setUpDirection = _this._setUpDirection.bind(_this);
20802
21048
  //@ts-ignore
@@ -20917,8 +21163,8 @@ PhysicsScene._collision = new Collision();
20917
21163
  {
20918
21164
  key: "slopeLimit",
20919
21165
  get: /**
20920
- * The slope limit for the controller, the value is the cosine value of the maximum slope angle.
20921
- * @defaultValue 0.707(the cosine value of 45 degrees)
21166
+ * The slope limit in degrees for the controller, the value is the cosine value of the maximum slope angle.
21167
+ * @defaultValue 45 degrees
20922
21168
  */ function get() {
20923
21169
  return this._slopeLimit;
20924
21170
  },
@@ -20935,6 +21181,9 @@ PhysicsScene._collision = new Collision();
20935
21181
  __decorate([
20936
21182
  deepClone
20937
21183
  ], CharacterController.prototype, "_upDirection", void 0);
21184
+ __decorate([
21185
+ ignoreClone
21186
+ ], CharacterController.prototype, "_setUpDirection", null);
20938
21187
 
20939
21188
  /**
20940
21189
  * A dynamic collider can act with self-defined movement or physical force.
@@ -20942,7 +21191,7 @@ __decorate([
20942
21191
  _inherits(DynamicCollider, Collider);
20943
21192
  function DynamicCollider(entity) {
20944
21193
  var _this;
20945
- _this = Collider.call(this, entity) || this, _this._linearDamping = 0, _this._angularDamping = 0.05, _this._linearVelocity = new engineMath.Vector3(), _this._angularVelocity = new engineMath.Vector3(), _this._mass = 1.0, _this._centerOfMass = new engineMath.Vector3(), _this._inertiaTensor = new engineMath.Vector3(1, 1, 1), _this._maxAngularVelocity = 100, _this._maxDepenetrationVelocity = 1.0000000331813535e32, _this._solverIterations = 4, _this._isKinematic = false, _this._constraints = 0, _this._collisionDetectionMode = 0, _this._sleepThreshold = 5e-3, _this._automaticCenterOfMass = true, _this._automaticInertiaTensor = true;
21194
+ _this = Collider.call(this, entity) || this, _this._linearDamping = 0, _this._angularDamping = 0.05, _this._linearVelocity = new engineMath.Vector3(), _this._angularVelocity = new engineMath.Vector3(), _this._mass = 1.0, _this._centerOfMass = new engineMath.Vector3(), _this._inertiaTensor = new engineMath.Vector3(1, 1, 1), _this._maxAngularVelocity = 18000 / Math.PI, _this._maxDepenetrationVelocity = 1.0000000331813535e32, _this._solverIterations = 4, _this._useGravity = true, _this._isKinematic = false, _this._constraints = 0, _this._collisionDetectionMode = 0, _this._sleepThreshold = 5e-3, _this._automaticCenterOfMass = true, _this._automaticInertiaTensor = true;
20946
21195
  var transform = _this.entity.transform;
20947
21196
  _this._nativeCollider = PhysicsScene._nativePhysics.createDynamicCollider(transform.worldPosition, transform.worldRotationQuaternion);
20948
21197
  _this._setLinearVelocity = _this._setLinearVelocity.bind(_this);
@@ -21111,7 +21360,7 @@ __decorate([
21111
21360
  {
21112
21361
  key: "angularVelocity",
21113
21362
  get: /**
21114
- * The angular velocity vector of the dynamic collider measured in radians per second.
21363
+ * The angular velocity vector of the dynamic collider measured in degrees per second.
21115
21364
  */ function get() {
21116
21365
  //@ts-ignore
21117
21366
  this._angularVelocity._onValueChanged = null;
@@ -21219,7 +21468,7 @@ __decorate([
21219
21468
  {
21220
21469
  key: "maxAngularVelocity",
21221
21470
  get: /**
21222
- * The maximum angular velocity of the collider measured in radians per second. (Default 7) range { 0, infinity }.
21471
+ * The maximum angular velocity of the collider measured in degrees per second.
21223
21472
  */ function get() {
21224
21473
  return this._maxAngularVelocity;
21225
21474
  },
@@ -21272,6 +21521,20 @@ __decorate([
21272
21521
  }
21273
21522
  }
21274
21523
  },
21524
+ {
21525
+ key: "useGravity",
21526
+ get: /**
21527
+ * Controls whether gravity affects the dynamic collider.
21528
+ */ function get() {
21529
+ return this._useGravity;
21530
+ },
21531
+ set: function set(value) {
21532
+ if (this._useGravity !== value) {
21533
+ this._useGravity = value;
21534
+ this._nativeCollider.setUseGravity(value);
21535
+ }
21536
+ }
21537
+ },
21275
21538
  {
21276
21539
  key: "isKinematic",
21277
21540
  get: /**
@@ -21396,8 +21659,8 @@ __decorate([
21396
21659
  }
21397
21660
  var _proto = PhysicsMaterial.prototype;
21398
21661
  /**
21399
- * @internal
21400
- */ _proto._destroy = function _destroy() {
21662
+ * Destroy the material when the material is no be used by any shape.
21663
+ */ _proto.destroy = function destroy() {
21401
21664
  !this._destroyed && this._nativeMaterial.destroy();
21402
21665
  this._destroyed = true;
21403
21666
  };
@@ -21516,8 +21779,9 @@ exports.Joint = /*#__PURE__*/ function(Component) {
21516
21779
  _this = Component.call(this, entity) || this, _this._colliderInfo = new JointColliderInfo(), _this._connectedColliderInfo = new JointColliderInfo(), _this._force = Infinity, _this._torque = Infinity, _this._automaticConnectedAnchor = true;
21517
21780
  //@ts-ignore
21518
21781
  _this._colliderInfo.anchor._onValueChanged = _this._updateActualAnchor.bind(_this, 1);
21782
+ _this._updateConnectedActualAnchor = _this._updateActualAnchor.bind(_this, 2);
21519
21783
  //@ts-ignore
21520
- _this._connectedColliderInfo.anchor._onValueChanged = _this._updateActualAnchor.bind(_this, 2);
21784
+ _this._connectedColliderInfo.anchor._onValueChanged = _this._updateConnectedActualAnchor;
21521
21785
  _this._onSelfTransformChanged = _this._onSelfTransformChanged.bind(_this);
21522
21786
  _this._onConnectedTransformChanged = _this._onConnectedTransformChanged.bind(_this);
21523
21787
  // @ts-ignore
@@ -21618,7 +21882,7 @@ exports.Joint = /*#__PURE__*/ function(Component) {
21618
21882
  (_this__connectedColliderInfo_collider = this._connectedColliderInfo.collider) == null ? void 0 : _this__connectedColliderInfo_collider.entity._updateFlagManager.removeListener(this._onConnectedTransformChanged);
21619
21883
  value == null ? void 0 : value.entity._updateFlagManager.addListener(this._onConnectedTransformChanged);
21620
21884
  this._connectedColliderInfo.collider = value;
21621
- (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setConnectedCollider(value._nativeCollider);
21885
+ (_this__nativeJoint = this._nativeJoint) == null ? void 0 : _this__nativeJoint.setConnectedCollider(value == null ? void 0 : value._nativeCollider);
21622
21886
  if (this._automaticConnectedAnchor) {
21623
21887
  this._calculateConnectedAnchor();
21624
21888
  } else {
@@ -21630,8 +21894,7 @@ exports.Joint = /*#__PURE__*/ function(Component) {
21630
21894
  {
21631
21895
  key: "anchor",
21632
21896
  get: /**
21633
- * The connected anchor position.
21634
- * @remarks If connectedCollider is set, this anchor is relative offset, or the anchor is world position.
21897
+ * The anchor position.
21635
21898
  */ function get() {
21636
21899
  return this._colliderInfo.anchor;
21637
21900
  },
@@ -21649,11 +21912,20 @@ exports.Joint = /*#__PURE__*/ function(Component) {
21649
21912
  get: /**
21650
21913
  * The connected anchor position.
21651
21914
  * @remarks If connectedCollider is set, this anchor is relative offset, or the anchor is world position.
21915
+ * The connectedAnchor is automatically calculated, if you want to set it manually, please set automaticConnectedAnchor to false
21652
21916
  */ function get() {
21653
- return this._connectedColliderInfo.anchor;
21917
+ var connectedColliderAnchor = this._connectedColliderInfo.anchor;
21918
+ if (this._automaticConnectedAnchor) {
21919
+ //@ts-ignore
21920
+ connectedColliderAnchor._onValueChanged = null;
21921
+ this._calculateConnectedAnchor();
21922
+ //@ts-ignore
21923
+ connectedColliderAnchor._onValueChanged = this._updateConnectedActualAnchor;
21924
+ }
21925
+ return connectedColliderAnchor;
21654
21926
  },
21655
21927
  set: function set(value) {
21656
- if (this.automaticConnectedAnchor) {
21928
+ if (this._automaticConnectedAnchor) {
21657
21929
  console.warn("Cannot set connectedAnchor when automaticConnectedAnchor is true.");
21658
21930
  return;
21659
21931
  }
@@ -21679,7 +21951,7 @@ exports.Joint = /*#__PURE__*/ function(Component) {
21679
21951
  {
21680
21952
  key: "connectedMassScale",
21681
21953
  get: /**
21682
- * The scale to apply to the inverse mass of collider 0 for resolving this constraint.
21954
+ * The scale to apply to the mass of collider 0 for resolving this constraint.
21683
21955
  */ function get() {
21684
21956
  return this._connectedColliderInfo.massScale;
21685
21957
  },
@@ -21694,7 +21966,7 @@ exports.Joint = /*#__PURE__*/ function(Component) {
21694
21966
  {
21695
21967
  key: "massScale",
21696
21968
  get: /**
21697
- * The scale to apply to the inverse mass of collider 1 for resolving this constraint.
21969
+ * The scale to apply to the mass of collider 1 for resolving this constraint.
21698
21970
  */ function get() {
21699
21971
  return this._colliderInfo.massScale;
21700
21972
  },
@@ -21709,7 +21981,7 @@ exports.Joint = /*#__PURE__*/ function(Component) {
21709
21981
  {
21710
21982
  key: "connectedInertiaScale",
21711
21983
  get: /**
21712
- * The scale to apply to the inverse inertia of collider0 for resolving this constraint.
21984
+ * The scale to apply to the inertia of collider0 for resolving this constraint.
21713
21985
  */ function get() {
21714
21986
  return this._connectedColliderInfo.inertiaScale;
21715
21987
  },
@@ -21724,7 +21996,7 @@ exports.Joint = /*#__PURE__*/ function(Component) {
21724
21996
  {
21725
21997
  key: "inertiaScale",
21726
21998
  get: /**
21727
- * The scale to apply to the inverse inertia of collider1 for resolving this constraint.
21999
+ * The scale to apply to the inertia of collider1 for resolving this constraint.
21728
22000
  */ function get() {
21729
22001
  return this._colliderInfo.inertiaScale;
21730
22002
  },
@@ -21781,15 +22053,15 @@ __decorate([
21781
22053
  ], exports.Joint.prototype, "_nativeJoint", void 0);
21782
22054
  __decorate([
21783
22055
  ignoreClone
21784
- ], exports.Joint.prototype, "_onSelfTransformChanged", null);
22056
+ ], exports.Joint.prototype, "_updateConnectedActualAnchor", void 0);
21785
22057
  __decorate([
21786
22058
  ignoreClone
21787
- ], exports.Joint.prototype, "_onConnectedTransformChanged", null);
22059
+ ], exports.Joint.prototype, "_onSelfTransformChanged", null);
21788
22060
  __decorate([
21789
22061
  ignoreClone
21790
- ], exports.Joint.prototype, "_updateActualAnchor", null);
22062
+ ], exports.Joint.prototype, "_onConnectedTransformChanged", null);
21791
22063
  exports.Joint = __decorate([
21792
- dependentComponents(exports.Collider, DependentMode.CheckOnly)
22064
+ dependentComponents(DynamicCollider, DependentMode.AutoAdd)
21793
22065
  ], exports.Joint);
21794
22066
  /**
21795
22067
  * @internal
@@ -22147,15 +22419,15 @@ __decorate([
22147
22419
  {
22148
22420
  key: "max",
22149
22421
  get: /**
22150
- * The upper angular limit (in radians) of the joint.
22422
+ * The upper angular limit (in degrees) of the joint.
22151
22423
  */ function get() {
22152
22424
  return this._max;
22153
22425
  },
22154
22426
  set: function set(value) {
22155
- if (value < this._min) {
22156
- throw new Error("Max limit must be greater than min limit");
22157
- }
22158
22427
  if (this._max !== value) {
22428
+ if (value < this._min) {
22429
+ this._min = value;
22430
+ }
22159
22431
  this._max = value;
22160
22432
  this._updateFlagManager.dispatch();
22161
22433
  }
@@ -22164,15 +22436,15 @@ __decorate([
22164
22436
  {
22165
22437
  key: "min",
22166
22438
  get: /**
22167
- * The lower angular limit (in radians) of the joint.
22439
+ * The lower angular limit (in degrees) of the joint.
22168
22440
  */ function get() {
22169
22441
  return this._min;
22170
22442
  },
22171
22443
  set: function set(value) {
22172
- if (value > this._max) {
22173
- throw new Error("Min limit must be less than max limit");
22174
- }
22175
22444
  if (this._min !== value) {
22445
+ if (value > this._max) {
22446
+ this._max = value;
22447
+ }
22176
22448
  this._min = value;
22177
22449
  this._updateFlagManager.dispatch();
22178
22450
  }
@@ -22250,8 +22522,10 @@ __decorate([
22250
22522
  return this._targetVelocity;
22251
22523
  },
22252
22524
  set: function set(value) {
22253
- this._targetVelocity = value;
22254
- this._updateFlagManager.dispatch();
22525
+ if (this._targetVelocity !== value) {
22526
+ this._targetVelocity = value;
22527
+ this._updateFlagManager.dispatch();
22528
+ }
22255
22529
  }
22256
22530
  },
22257
22531
  {
@@ -22262,8 +22536,10 @@ __decorate([
22262
22536
  return this._forceLimit;
22263
22537
  },
22264
22538
  set: function set(value) {
22265
- this._forceLimit = value;
22266
- this._updateFlagManager.dispatch();
22539
+ if (this._forceLimit !== value) {
22540
+ this._forceLimit = value;
22541
+ this._updateFlagManager.dispatch();
22542
+ }
22267
22543
  }
22268
22544
  },
22269
22545
  {
@@ -22274,8 +22550,10 @@ __decorate([
22274
22550
  return this._gearRatio;
22275
22551
  },
22276
22552
  set: function set(value) {
22277
- this._gearRatio = value;
22278
- this._updateFlagManager.dispatch();
22553
+ if (this._gearRatio !== value) {
22554
+ this._gearRatio = value;
22555
+ this._updateFlagManager.dispatch();
22556
+ }
22279
22557
  }
22280
22558
  },
22281
22559
  {
@@ -22286,8 +22564,10 @@ __decorate([
22286
22564
  return this._freeSpin;
22287
22565
  },
22288
22566
  set: function set(value) {
22289
- this._freeSpin = value;
22290
- this._updateFlagManager.dispatch();
22567
+ if (this._freeSpin !== value) {
22568
+ this._freeSpin = value;
22569
+ this._updateFlagManager.dispatch();
22570
+ }
22291
22571
  }
22292
22572
  }
22293
22573
  ]);
@@ -22322,6 +22602,26 @@ __decorate([
22322
22602
  }
22323
22603
  var _proto = ColliderShape.prototype;
22324
22604
  /**
22605
+ * Get the distance and the closest point on the shape from a point.
22606
+ * @param point - Location in world space you want to find the closest point to
22607
+ * @param outClosestPoint - The closest point on the shape in world space
22608
+ * @returns The distance between the point and the shape
22609
+ */ _proto.getClosestPoint = function getClosestPoint(point, outClosestPoint) {
22610
+ var collider = this._collider;
22611
+ if (collider.enabled === false || collider.entity._isActiveInHierarchy === false) {
22612
+ console.warn("The collider is not active in scene.");
22613
+ return -1;
22614
+ }
22615
+ var res = this._nativeShape.pointDistance(point);
22616
+ var distance = res.w;
22617
+ if (distance > 0) {
22618
+ outClosestPoint.set(res.x, res.y, res.z);
22619
+ } else {
22620
+ outClosestPoint.copyFrom(point);
22621
+ }
22622
+ return Math.sqrt(distance);
22623
+ };
22624
+ /**
22325
22625
  * @internal
22326
22626
  */ _proto._cloneTo = function _cloneTo(target) {
22327
22627
  target._syncNative();
@@ -22387,11 +22687,14 @@ __decorate([
22387
22687
  {
22388
22688
  key: "material",
22389
22689
  get: /**
22390
- * Physical material.
22690
+ * Physical material, material can't be null.
22391
22691
  */ function get() {
22392
22692
  return this._material;
22393
22693
  },
22394
22694
  set: function set(value) {
22695
+ if (!value) {
22696
+ throw new Error("The physics material of the shape can't be null.");
22697
+ }
22395
22698
  if (this._material !== value) {
22396
22699
  this._material = value;
22397
22700
  this._nativeShape.setMaterial(value._nativeMaterial);
@@ -22401,7 +22704,7 @@ __decorate([
22401
22704
  {
22402
22705
  key: "rotation",
22403
22706
  get: /**
22404
- * The local rotation of this ColliderShape.
22707
+ * The local rotation of this ColliderShape, in degrees.
22405
22708
  */ function get() {
22406
22709
  return this._rotation;
22407
22710
  },
@@ -22552,6 +22855,11 @@ __decorate([
22552
22855
  _this._nativeShape = PhysicsScene._nativePhysics.createPlaneColliderShape(_this._id, _this._material._nativeMaterial);
22553
22856
  return _this;
22554
22857
  }
22858
+ var _proto = PlaneColliderShape.prototype;
22859
+ _proto.getClosestPoint = function getClosestPoint(point, closestPoint) {
22860
+ console.error("PlaneColliderShape is not support getClosestPoint");
22861
+ return -1;
22862
+ };
22555
22863
  return PlaneColliderShape;
22556
22864
  }(ColliderShape);
22557
22865
 
@@ -23183,217 +23491,732 @@ ParticleBufferUtils.boundsFloatStride = 8;
23183
23491
  ParticleBufferUtils.boundsTimeOffset = 6;
23184
23492
  ParticleBufferUtils.boundsMaxLifetimeOffset = 7;
23185
23493
 
23186
- var blitFs = "#define GLSLIFY 1\nuniform mediump sampler2D renderer_BlitTexture;\n#ifdef HAS_TEX_LOD\nuniform float renderer_BlitMipLevel;\n#endif\nvarying vec2 v_uv;void main(){vec2 uv=v_uv;\n#ifdef renderer_FlipYBlitTexture\nuv.y=1.0-uv.y;\n#endif\n#ifdef HAS_TEX_LOD\ngl_FragColor=texture2DLodEXT(renderer_BlitTexture,uv,renderer_BlitMipLevel);\n#else\ngl_FragColor=texture2D(renderer_BlitTexture,uv);\n#endif\n}"; // eslint-disable-line
23187
-
23188
- var blitVs = "#define GLSLIFY 1\nattribute vec4 POSITION_UV;varying vec2 v_uv;void main(){gl_Position=vec4(POSITION_UV.xy,0.0,1.0);v_uv=POSITION_UV.zw;}"; // eslint-disable-line
23189
-
23190
- var skyProceduralFs = "#define GLSLIFY 1\n#include <common>\nconst float MIE_G=-0.990;const float MIE_G2=0.9801;const float SKY_GROUND_THRESHOLD=0.02;uniform float material_SunSize;uniform float material_SunSizeConvergence;uniform vec4 scene_SunlightColor;uniform vec3 scene_SunlightDirection;varying vec3 v_GroundColor;varying vec3 v_SkyColor;\n#ifdef MATERIAL_SUN_HIGH_QUALITY\nvarying vec3 v_Vertex;\n#elif defined(MATERIAL_SUN_SIMPLE)\nvarying vec3 v_RayDir;\n#else\nvarying float v_SkyGroundFactor;\n#endif\n#if defined(MATERIAL_SUN_HIGH_QUALITY)||defined(MATERIAL_SUN_SIMPLE)\nvarying vec3 v_SunColor;\n#endif\n#if defined(ENGINE_IS_COLORSPACE_GAMMA)\n#define LINEAR_2_OUTPUT(color) sqrt(color)\n#endif\nfloat getMiePhase(float eyeCos,float eyeCos2){float temp=1.0+MIE_G2-2.0*MIE_G*eyeCos;temp=pow(temp,pow(material_SunSize,0.65)*10.0);temp=max(temp,1.0e-4);temp=1.5*((1.0-MIE_G2)/(2.0+MIE_G2))*(1.0+eyeCos2)/temp;return temp;}float calcSunAttenuation(vec3 lightPos,vec3 ray){\n#ifdef MATERIAL_SUN_HIGH_QUALITY\nfloat focusedEyeCos=pow(clamp(dot(lightPos,ray),0.0,1.0),material_SunSizeConvergence);return getMiePhase(-focusedEyeCos,focusedEyeCos*focusedEyeCos);\n#else\nvec3 delta=lightPos-ray;float dist=length(delta);float spot=1.0-smoothstep(0.0,material_SunSize,dist);return spot*spot;\n#endif\n}void main(){vec3 col=vec3(0.0,0.0,0.0);\n#ifdef MATERIAL_SUN_HIGH_QUALITY\nvec3 ray=normalize(v_Vertex);float y=ray.y/SKY_GROUND_THRESHOLD;\n#elif defined(MATERIAL_SUN_SIMPLE)\nvec3 ray=v_RayDir;float y=ray.y/SKY_GROUND_THRESHOLD;\n#else\nfloat y=v_SkyGroundFactor;\n#endif\ncol=mix(v_SkyColor,v_GroundColor,clamp(y,0.0,1.0));\n#if defined(MATERIAL_SUN_HIGH_QUALITY)||defined(MATERIAL_SUN_SIMPLE)\nif(y<0.0)col+=v_SunColor*calcSunAttenuation(-scene_SunlightDirection,-ray);\n#endif\n#ifdef ENGINE_IS_COLORSPACE_GAMMA\ncol=LINEAR_2_OUTPUT(col);\n#endif\ngl_FragColor=vec4(col,1.0);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ngl_FragColor=linearToGamma(gl_FragColor);\n#endif\n}"; // eslint-disable-line
23191
-
23192
- var skyProceduralVs = "#define GLSLIFY 1\n#define OUTER_RADIUS 1.025\n#define RAYLEIGH (mix(0.0, 0.0025, pow(material_AtmosphereThickness,2.5)))\n#define MIE 0.0010\n#define SUN_BRIGHTNESS 20.0\n#define MAX_SCATTER 50.0\nconst float SKY_GROUND_THRESHOLD=0.02;const float outerRadius=OUTER_RADIUS;const float outerRadius2=OUTER_RADIUS*OUTER_RADIUS;const float innerRadius=1.0;const float innerRadius2=1.0;const float cameraHeight=0.0001;const float HDSundiskIntensityFactor=15.0;const float simpleSundiskIntensityFactor=27.0;const float sunScale=400.0*SUN_BRIGHTNESS;const float kmESun=MIE*SUN_BRIGHTNESS;const float km4PI=MIE*4.0*3.14159265;const float scale=1.0/(OUTER_RADIUS-1.0);const float scaleDepth=0.25;const float scaleOverScaleDepth=(1.0/(OUTER_RADIUS-1.0))/0.25;const float samples=2.0;const vec3 c_DefaultScatteringWavelength=vec3(0.65,0.57,0.475);const vec3 c_VariableRangeForScatteringWavelength=vec3(0.15,0.15,0.15);attribute vec4 POSITION;uniform mat4 camera_VPMat;uniform vec3 material_SkyTint;uniform vec3 material_GroundTint;uniform float material_Exposure;uniform float material_AtmosphereThickness;uniform vec4 scene_SunlightColor;uniform vec3 scene_SunlightDirection;varying vec3 v_GroundColor;varying vec3 v_SkyColor;\n#ifdef MATERIAL_SUN_HIGH_QUALITY\nvarying vec3 v_Vertex;\n#elif defined(MATERIAL_SUN_SIMPLE)\nvarying vec3 v_RayDir;\n#else\nvarying float v_SkyGroundFactor;\n#endif\n#if defined(MATERIAL_SUN_HIGH_QUALITY)||defined(MATERIAL_SUN_SIMPLE)\nvarying vec3 v_SunColor;\n#endif\n#if defined(ENGINE_IS_COLORSPACE_GAMMA)\n#define COLOR_2_GAMMA(color) color\n#define COLOR_2_LINEAR(color) color*color\n#else\n#define GAMMA 2.2\n#define COLOR_2_GAMMA(color) pow(color,vec3(1.0/GAMMA))\n#define COLOR_2_LINEAR(color) color\n#endif\nfloat getRayleighPhase(vec3 light,vec3 ray){float eyeCos=dot(light,ray);return 0.75+0.75*eyeCos*eyeCos;}float scaleAngle(float inCos){float x=1.0-inCos;return 0.25*exp(-0.00287+x*(0.459+x*(3.83+x*(-6.80+x*5.25))));}void main(){gl_Position=camera_VPMat*vec4(POSITION.xyz,1.0);vec3 skyTintInGammaSpace=COLOR_2_GAMMA(material_SkyTint);vec3 scatteringWavelength=mix(c_DefaultScatteringWavelength-c_VariableRangeForScatteringWavelength,c_DefaultScatteringWavelength+c_VariableRangeForScatteringWavelength,vec3(1.0)-skyTintInGammaSpace);vec3 invWavelength=1.0/pow(scatteringWavelength,vec3(4.0));float krESun=RAYLEIGH*SUN_BRIGHTNESS;float kr4PI=RAYLEIGH*4.0*3.14159265;vec3 cameraPos=vec3(0.0,innerRadius+cameraHeight,0.0);vec3 eyeRay=normalize(POSITION.xyz);float far=0.0;vec3 cIn,cOut;if(eyeRay.y>=0.0){far=sqrt(outerRadius2+innerRadius2*eyeRay.y*eyeRay.y-innerRadius2)-innerRadius*eyeRay.y;float height=innerRadius+cameraHeight;float depth=exp(scaleOverScaleDepth*-cameraHeight);float startAngle=dot(eyeRay,cameraPos)/height;float startOffset=depth*scaleAngle(startAngle);float sampleLength=far/samples;float scaledLength=sampleLength*scale;vec3 sampleRay=eyeRay*sampleLength;vec3 samplePoint=cameraPos+sampleRay*0.5;vec3 frontColor=vec3(0.0);{float height=length(samplePoint);float depth=exp(scaleOverScaleDepth*(innerRadius-height));float lightAngle=dot(-scene_SunlightDirection,samplePoint)/height;float cameraAngle=dot(eyeRay,samplePoint)/height;float scatter=(startOffset+depth*(scaleAngle(lightAngle)-scaleAngle(cameraAngle)));vec3 attenuate=exp(-clamp(scatter,0.0,MAX_SCATTER)*(invWavelength*kr4PI+km4PI));frontColor+=attenuate*(depth*scaledLength);samplePoint+=sampleRay;}{float height=length(samplePoint);float depth=exp(scaleOverScaleDepth*(innerRadius-height));float lightAngle=dot(-scene_SunlightDirection,samplePoint)/height;float cameraAngle=dot(eyeRay,samplePoint)/height;float scatter=(startOffset+depth*(scaleAngle(lightAngle)-scaleAngle(cameraAngle)));vec3 attenuate=exp(-clamp(scatter,0.0,MAX_SCATTER)*(invWavelength*kr4PI+km4PI));frontColor+=attenuate*(depth*scaledLength);samplePoint+=sampleRay;}cIn=frontColor*(invWavelength*krESun);cOut=frontColor*kmESun;}else{far=(-cameraHeight)/(min(-0.001,eyeRay.y));vec3 pos=cameraPos+far*eyeRay;float depth=exp((-cameraHeight)*(1.0/scaleDepth));float cameraAngle=dot(-eyeRay,pos);float lightAngle=dot(-scene_SunlightDirection,pos);float cameraScale=scaleAngle(cameraAngle);float lightScale=scaleAngle(lightAngle);float cameraOffset=depth*cameraScale;float temp=lightScale+cameraScale;float sampleLength=far/samples;float scaledLength=sampleLength*scale;vec3 sampleRay=eyeRay*sampleLength;vec3 samplePoint=cameraPos+sampleRay*0.5;vec3 frontColor=vec3(0.0,0.0,0.0);vec3 attenuate;{float height=length(samplePoint);float depth=exp(scaleOverScaleDepth*(innerRadius-height));float scatter=depth*temp-cameraOffset;attenuate=exp(-clamp(scatter,0.0,MAX_SCATTER)*(invWavelength*kr4PI+km4PI));frontColor+=attenuate*(depth*scaledLength);samplePoint+=sampleRay;}cIn=frontColor*(invWavelength*krESun+kmESun);cOut=clamp(attenuate,0.0,1.0);}\n#ifdef MATERIAL_SUN_HIGH_QUALITY\nv_Vertex=-POSITION.xyz;\n#elif defined(MATERIAL_SUN_SIMPLE)\nv_RayDir=-eyeRay;\n#else\nv_SkyGroundFactor=-eyeRay.y/SKY_GROUND_THRESHOLD;\n#endif\nv_GroundColor=material_Exposure*(cIn+COLOR_2_LINEAR(material_GroundTint)*cOut);v_SkyColor=material_Exposure*(cIn*getRayleighPhase(-scene_SunlightDirection,-eyeRay));float lightColorIntensity=clamp(length(scene_SunlightColor.xyz),0.25,1.0);\n#ifdef MATERIAL_SUN_HIGH_QUALITY\nv_SunColor=HDSundiskIntensityFactor*clamp(cOut,0.0,1.0)*scene_SunlightColor.xyz/lightColorIntensity;\n#elif defined(MATERIAL_SUN_SIMPLE)\nv_SunColor=simpleSundiskIntensityFactor*clamp(cOut*sunScale,0.0,1.0)*scene_SunlightColor.xyz/lightColorIntensity;\n#endif\n}"; // eslint-disable-line
23193
-
23194
- var backgroundTextureFs = "#define GLSLIFY 1\nuniform sampler2D material_BaseTexture;varying vec2 v_uv;void main(){gl_FragColor=texture2D(material_BaseTexture,v_uv);}"; // eslint-disable-line
23195
-
23196
- var backgroundTextureVs = "#define GLSLIFY 1\nattribute vec3 POSITION;attribute vec2 TEXCOORD_0;varying vec2 v_uv;uniform vec4 camera_ProjectionParams;void main(){gl_Position=vec4(POSITION,1.0);gl_Position.y*=camera_ProjectionParams.x;v_uv=TEXCOORD_0;}"; // eslint-disable-line
23197
-
23198
- var blinnPhongFs = "#define GLSLIFY 1\n#include <common>\n#include <camera_declare>\n#include <uv_share>\n#include <normal_share>\n#include <color_share>\n#include <worldpos_share>\n#include <light_frag_define>\n#include <ShadowFragmentDeclaration>\n#include <mobile_material_frag>\n#include <FogFragmentDeclaration>\n#include <normal_get>\nvoid main(){\n#include <begin_mobile_frag>\n#include <begin_viewdir_frag>\n#include <mobile_blinnphong_frag>\ngl_FragColor=emission+ambient+diffuse+specular;\n#ifdef MATERIAL_IS_TRANSPARENT\ngl_FragColor.a=diffuse.a;\n#else\ngl_FragColor.a=1.0;\n#endif\n#include <FogFragment>\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ngl_FragColor=linearToGamma(gl_FragColor);\n#endif\n}"; // eslint-disable-line
23199
-
23200
- var blinnPhongVs = "#define GLSLIFY 1\n#include <common>\n#include <common_vert>\n#include <blendShape_input>\n#include <uv_share>\n#include <color_share>\n#include <normal_share>\n#include <worldpos_share>\n#include <ShadowVertexDeclaration>\n#include <FogVertexDeclaration>\nvoid main(){\n#include <begin_position_vert>\n#include <begin_normal_vert>\n#include <blendShape_vert>\n#include <skinning_vert>\n#include <uv_vert>\n#include <color_vert>\n#include <normal_vert>\n#include <worldpos_vert>\n#include <position_vert>\n#include <ShadowVertex>\n#include <FogVertex>\n}"; // eslint-disable-line
23201
-
23202
- var depthOnlyFs = "#define GLSLIFY 1\nvoid main(){}"; // eslint-disable-line
23203
-
23204
- var depthOnlyVs = "#define GLSLIFY 1\n#include <common>\n#include <common_vert>\n#include <blendShape_input>\nuniform mat4 camera_VPMat;void main(){\n#include <begin_position_vert>\n#include <blendShape_vert>\n#include <skinning_vert>\n#include <position_vert>\n}"; // eslint-disable-line
23205
-
23206
- var particleFs = "#define GLSLIFY 1\n#include <common>\nvarying vec4 v_Color;varying vec2 v_TextureCoordinate;uniform sampler2D material_BaseTexture;uniform vec4 material_BaseColor;\n#ifdef RENDERER_MODE_MESH\nvarying vec4 v_MeshColor;\n#endif\nvoid main(){vec4 color=material_BaseColor*v_Color;\n#ifdef RENDERER_MODE_MESH\ncolor*=v_MeshColor;\n#endif\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 textureColor=texture2D(material_BaseTexture,v_TextureCoordinate);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ntextureColor=gammaToLinear(textureColor);\n#endif\ncolor*=textureColor;\n#endif\ngl_FragColor=color;\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ngl_FragColor=linearToGamma(gl_FragColor);\n#endif\n}"; // eslint-disable-line
23207
-
23208
- var particleVs = "#define GLSLIFY 1\n#if defined(RENDERER_MODE_SPHERE_BILLBOARD) || defined(RENDERER_MODE_STRETCHED_BILLBOARD) || defined(RENDERER_MODE_HORIZONTAL_BILLBOARD) || defined(RENDERER_MODE_VERTICAL_BILLBOARD)\nattribute vec4 a_CornerTextureCoordinate;\n#endif\n#ifdef RENDERER_MODE_MESH\nattribute vec3 a_MeshPosition;attribute vec4 a_MeshColor;attribute vec2 a_MeshTextureCoordinate;varying vec4 v_MeshColor;\n#endif\nattribute vec4 a_ShapePositionStartLifeTime;attribute vec4 a_DirectionTime;attribute vec4 a_StartColor;attribute vec3 a_StartSize;attribute vec3 a_StartRotation0;attribute float a_StartSpeed;attribute vec4 a_Random0;\n#if defined(RENDERER_TSA_FRAME_RANDOM_CURVES) || defined(RENDERER_VOL_RANDOM_CONSTANT) || defined(RENDERER_VOL_RANDOM_CURVE)\nattribute vec4 a_Random1;\n#endif\nattribute vec3 a_SimulationWorldPosition;attribute vec4 a_SimulationWorldRotation;varying vec4 v_Color;\n#ifdef MATERIAL_HAS_BASETEXTURE\nattribute vec4 a_SimulationUV;varying vec2 v_TextureCoordinate;\n#endif\nuniform float renderer_CurrentTime;uniform vec3 renderer_Gravity;uniform vec2 u_DragConstant;uniform vec3 renderer_WorldPosition;uniform vec4 renderer_WorldRotation;uniform bool renderer_ThreeDStartRotation;uniform int renderer_ScalingMode;uniform vec3 renderer_PositionScale;uniform vec3 renderer_SizeScale;uniform vec3 renderer_PivotOffset;uniform mat4 camera_ViewMat;uniform mat4 camera_ProjMat;\n#ifdef RENDERER_MODE_STRETCHED_BILLBOARD\nuniform vec3 camera_Position;\n#endif\nuniform vec3 camera_Forward;uniform vec3 camera_Up;uniform float renderer_StretchedBillboardLengthScale;uniform float renderer_StretchedBillboardSpeedScale;uniform int renderer_SimulationSpace;\n#include <particle_common>\n#include <velocity_over_lifetime_module>\n#include <color_over_lifetime_module>\n#include <size_over_lifetime_module>\n#include <rotation_over_lifetime_module>\n#include <texture_sheet_animation_module>\nvoid main(){float age=renderer_CurrentTime-a_DirectionTime.w;float normalizedAge=age/a_ShapePositionStartLifeTime.w;vec3 lifeVelocity;if(normalizedAge<1.0){vec3 startVelocity=a_DirectionTime.xyz*a_StartSpeed;\n#if defined(RENDERER_VOL_CONSTANT) || defined(RENDERER_VOL_CURVE) || defined(RENDERER_VOL_RANDOM_CONSTANT) || defined(RENDERER_VOL_RANDOM_CURVE)\nlifeVelocity=computeParticleLifeVelocity(normalizedAge);\n#endif\nvec3 gravityVelocity=renderer_Gravity*a_Random0.x*age;vec4 worldRotation;if(renderer_SimulationSpace==0){worldRotation=renderer_WorldRotation;}else{worldRotation=a_SimulationWorldRotation;}vec3 dragData=a_DirectionTime.xyz*mix(u_DragConstant.x,u_DragConstant.y,a_Random0.x);vec3 center=computeParticlePosition(startVelocity,lifeVelocity,age,normalizedAge,gravityVelocity,worldRotation,dragData);\n#include <sphere_billboard>\n#include <stretched_billboard>\n#include <horizontal_billboard>\n#include <vertical_billboard>\n#include <particle_mesh>\ngl_Position=camera_ProjMat*camera_ViewMat*vec4(center,1.0);v_Color=computeParticleColor(a_StartColor,normalizedAge);\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec2 simulateUV;\n#if defined(RENDERER_MODE_SPHERE_BILLBOARD) || defined(RENDERER_MODE_STRETCHED_BILLBOARD) || defined(RENDERER_MODE_HORIZONTAL_BILLBOARD) || defined(RENDERER_MODE_VERTICAL_BILLBOARD)\nsimulateUV=a_CornerTextureCoordinate.zw*a_SimulationUV.xy+a_SimulationUV.zw;v_TextureCoordinate=computeParticleUV(simulateUV,normalizedAge);\n#endif\n#ifdef RENDERER_MODE_MESH\nsimulateUV=a_SimulationUV.xy+a_MeshTextureCoordinate*a_SimulationUV.zw;v_TextureCoordinate=computeParticleUV(simulateUV,normalizedAge);\n#endif\n#endif\n}else{gl_Position=vec4(2.0,2.0,2.0,1.0);}}"; // eslint-disable-line
23209
-
23210
- var pbrSpecularFs = "#define GLSLIFY 1\n#include <common>\n#include <camera_declare>\n#include <FogFragmentDeclaration>\n#include <uv_share>\n#include <normal_share>\n#include <color_share>\n#include <worldpos_share>\n#include <light_frag_define>\n#include <pbr_frag_define>\n#include <pbr_helper>\nvoid main(){\n#include <pbr_frag>\n#include <FogFragment>\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ngl_FragColor=linearToGamma(gl_FragColor);\n#endif\n}"; // eslint-disable-line
23211
-
23212
- var pbrFs = "#define GLSLIFY 1\n#define IS_METALLIC_WORKFLOW\n#include <common>\n#include <camera_declare>\n#include <FogFragmentDeclaration>\n#include <uv_share>\n#include <normal_share>\n#include <color_share>\n#include <worldpos_share>\n#include <light_frag_define>\n#include <pbr_frag_define>\n#include <pbr_helper>\nvoid main(){\n#include <pbr_frag>\n#include <FogFragment>\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ngl_FragColor=linearToGamma(gl_FragColor);\n#endif\n}"; // eslint-disable-line
23213
-
23214
- var pbrVs = "#define GLSLIFY 1\n#include <common>\n#include <common_vert>\n#include <blendShape_input>\n#include <uv_share>\n#include <color_share>\n#include <normal_share>\n#include <worldpos_share>\n#include <ShadowVertexDeclaration>\n#include <FogVertexDeclaration>\nvoid main(){\n#include <begin_position_vert>\n#include <begin_normal_vert>\n#include <blendShape_vert>\n#include <skinning_vert>\n#include <uv_vert>\n#include <color_vert>\n#include <normal_vert>\n#include <worldpos_vert>\n#include <position_vert>\n#include <ShadowVertex>\n#include <FogVertex>\n}"; // eslint-disable-line
23215
-
23216
- var shadowMapFs = "#define GLSLIFY 1\n#ifdef ENGINE_NO_DEPTH_TEXTURE\nvec4 pack(float depth){const vec4 bitShift=vec4(1.0,256.0,256.0*256.0,256.0*256.0*256.0);const vec4 bitMask=vec4(1.0/256.0,1.0/256.0,1.0/256.0,0.0);vec4 rgbaDepth=fract(depth*bitShift);rgbaDepth-=rgbaDepth.gbaa*bitMask;return rgbaDepth;}\n#endif\nuniform vec4 material_BaseColor;uniform sampler2D material_BaseTexture;uniform float material_AlphaCutoff;varying vec2 v_uv;void main(){\n#if defined(MATERIAL_IS_ALPHA_CUTOFF) || (defined(SCENE_ENABLE_TRANSPARENT_SHADOW) && defined(MATERIAL_IS_TRANSPARENT))\nfloat alpha=material_BaseColor.a;\n#ifdef MATERIAL_HAS_BASETEXTURE\nalpha*=texture2D(material_BaseTexture,v_uv).a;\n#endif\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(alpha<material_AlphaCutoff){discard;}\n#endif\n#if defined(SCENE_ENABLE_TRANSPARENT_SHADOW) && defined(MATERIAL_IS_TRANSPARENT)\nfloat noise=fract(52.982919*fract(dot(vec2(0.06711,0.00584),gl_FragCoord.xy)));if(alpha<=noise){discard;};\n#endif\n#endif\n#ifdef ENGINE_NO_DEPTH_TEXTURE\ngl_FragColor=pack(gl_FragCoord.z);\n#else\ngl_FragColor=vec4(0.0,0.0,0.0,0.0);\n#endif\n}"; // eslint-disable-line
23217
-
23218
- var shadowMapVs = "#define GLSLIFY 1\n#include <common>\n#include <common_vert>\n#include <blendShape_input>\n#include <normal_share>\n#include <uv_share>\nuniform mat4 camera_VPMat;uniform vec2 scene_ShadowBias;uniform vec3 scene_LightDirection;vec3 applyShadowBias(vec3 positionWS){positionWS-=scene_LightDirection*scene_ShadowBias.x;return positionWS;}vec3 applyShadowNormalBias(vec3 positionWS,vec3 normalWS){float invNdotL=1.0-clamp(dot(-scene_LightDirection,normalWS),0.0,1.0);float scale=invNdotL*scene_ShadowBias.y;positionWS+=normalWS*vec3(scale);return positionWS;}void main(){\n#include <begin_position_vert>\n#include <begin_normal_vert>\n#include <blendShape_vert>\n#include <skinning_vert>\n#include <uv_vert>\nvec4 positionWS=renderer_ModelMat*position;positionWS.xyz=applyShadowBias(positionWS.xyz);\n#ifndef MATERIAL_OMIT_NORMAL\n#ifdef RENDERER_HAS_NORMAL\nvec3 normalWS=normalize(mat3(renderer_NormalMat)*normal);positionWS.xyz=applyShadowNormalBias(positionWS.xyz,normalWS);\n#endif\n#endif\nvec4 positionCS=camera_VPMat*positionWS;positionCS.z=max(positionCS.z,-1.0);gl_Position=positionCS;}"; // eslint-disable-line
23219
-
23220
- var skyboxFs = "#define GLSLIFY 1\n#include <common>\nuniform samplerCube material_CubeTexture;varying vec3 v_cubeUV;uniform float material_Exposure;uniform vec4 material_TintColor;void main(){vec4 textureColor=textureCube(material_CubeTexture,v_cubeUV);\n#ifdef MATERIAL_IS_DECODE_SKY_RGBM\ntextureColor=RGBMToLinear(textureColor,5.0);\n#elif !defined(ENGINE_IS_COLORSPACE_GAMMA)\ntextureColor=gammaToLinear(textureColor);\n#endif\ntextureColor.rgb*=material_Exposure*material_TintColor.rgb;gl_FragColor=textureColor;\n#if defined(MATERIAL_IS_DECODE_SKY_RGBM) || !defined(ENGINE_IS_COLORSPACE_GAMMA)\ngl_FragColor=linearToGamma(gl_FragColor);\n#endif\n}"; // eslint-disable-line
23221
-
23222
- var skyboxVs = "#define GLSLIFY 1\n#include <common_vert>\nuniform mat4 camera_VPMat;varying vec3 v_cubeUV;uniform float material_Rotation;vec4 rotateY(vec4 v,float angle){const float deg2rad=3.1415926/180.0;float radian=angle*deg2rad;float sina=sin(radian);float cosa=cos(radian);mat2 m=mat2(cosa,-sina,sina,cosa);return vec4(m*v.xz,v.yw).xzyw;}void main(){v_cubeUV=vec3(-POSITION.x,POSITION.yz);gl_Position=camera_VPMat*rotateY(vec4(POSITION,1.0),material_Rotation);}"; // eslint-disable-line
23223
-
23224
- var spriteMaskFs = "#define GLSLIFY 1\nuniform sampler2D renderer_MaskTexture;uniform float renderer_MaskAlphaCutoff;varying vec2 v_uv;void main(){vec4 color=texture2D(renderer_MaskTexture,v_uv);if(color.a<renderer_MaskAlphaCutoff){discard;}gl_FragColor=color;}"; // eslint-disable-line
23225
-
23226
- var spriteMaskVs = "#define GLSLIFY 1\nuniform mat4 camera_VPMat;attribute vec3 POSITION;attribute vec2 TEXCOORD_0;varying vec2 v_uv;void main(){gl_Position=camera_VPMat*vec4(POSITION,1.0);v_uv=TEXCOORD_0;}"; // eslint-disable-line
23227
-
23228
- var spriteFs = "#define GLSLIFY 1\nuniform sampler2D renderer_SpriteTexture;varying vec2 v_uv;varying vec4 v_color;void main(){vec4 baseColor=texture2D(renderer_SpriteTexture,v_uv);gl_FragColor=baseColor*v_color;}"; // eslint-disable-line
23229
-
23230
- var spriteVs = "#define GLSLIFY 1\nuniform mat4 renderer_MVPMat;attribute vec3 POSITION;attribute vec2 TEXCOORD_0;attribute vec4 COLOR_0;varying vec2 v_uv;varying vec4 v_color;void main(){gl_Position=renderer_MVPMat*vec4(POSITION,1.0);v_uv=TEXCOORD_0;v_color=COLOR_0;}"; // eslint-disable-line
23231
-
23232
- var textFs = "#define GLSLIFY 1\nuniform sampler2D renderElement_TextTexture;varying vec2 v_uv;varying vec4 v_color;void main(){vec4 baseColor=texture2D(renderElement_TextTexture,v_uv);gl_FragColor=baseColor*v_color;}"; // eslint-disable-line
23233
-
23234
- var textVs = "#define GLSLIFY 1\nuniform mat4 renderer_MVPMat;attribute vec3 POSITION;attribute vec2 TEXCOORD_0;attribute vec4 COLOR_0;varying vec2 v_uv;varying vec4 v_color;void main(){gl_Position=renderer_MVPMat*vec4(POSITION,1.0);v_uv=TEXCOORD_0;v_color=COLOR_0;}"; // eslint-disable-line
23235
-
23236
- var unlitFs = "#define GLSLIFY 1\n#include <common>\n#include <uv_share>\n#include <FogFragmentDeclaration>\nuniform vec4 material_BaseColor;uniform float material_AlphaCutoff;\n#ifdef MATERIAL_HAS_BASETEXTURE\nuniform sampler2D material_BaseTexture;\n#endif\nvoid main(){vec4 baseColor=material_BaseColor;\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 textureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ntextureColor=gammaToLinear(textureColor);\n#endif\nbaseColor*=textureColor;\n#endif\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(baseColor.a<material_AlphaCutoff){discard;}\n#endif\ngl_FragColor=baseColor;\n#ifndef MATERIAL_IS_TRANSPARENT\ngl_FragColor.a=1.0;\n#endif\n#include <FogFragment>\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ngl_FragColor=linearToGamma(gl_FragColor);\n#endif\n}"; // eslint-disable-line
23237
-
23238
- var unlitVs = "#define GLSLIFY 1\n#include <common>\n#include <common_vert>\n#include <blendShape_input>\n#include <uv_share>\n#include <FogVertexDeclaration>\nvoid main(){\n#include <begin_position_vert>\n#include <blendShape_vert>\n#include <skinning_vert>\n#include <uv_vert>\n#include <position_vert>\n#include <FogVertex>\n}"; // eslint-disable-line
23494
+ var blitVs = "#define GLSLIFY 1\nattribute vec4 POSITION_UV;\nvarying vec2 v_uv;\n\nvoid main() {\t\n\tgl_Position = vec4(POSITION_UV.xy, 0.0, 1.0);\t\n\tv_uv = POSITION_UV.zw;\n}"; // eslint-disable-line
23239
23495
 
23240
23496
  /**
23241
- * Internal shader pool.
23242
- * @internal
23243
- */ var ShaderPool = /*#__PURE__*/ function() {
23244
- function ShaderPool() {}
23245
- ShaderPool.init = function init() {
23246
- var shadowCasterPass = new ShaderPass("ShadowCaster", shadowMapVs, shadowMapFs, {
23247
- pipelineStage: PipelineStage.ShadowCaster
23248
- });
23249
- shadowCasterPass._renderState = new RenderState();
23250
- shadowCasterPass._renderStateDataMap[RenderStateElementKey.RenderQueueType] = BaseMaterial._shadowCasterRenderQueueProp;
23251
- var depthOnlyPass = new ShaderPass("DepthOnly", depthOnlyVs, depthOnlyFs, {
23252
- pipelineStage: PipelineStage.DepthOnly
23253
- });
23254
- var basePasses = [
23255
- shadowCasterPass,
23256
- depthOnlyPass
23257
- ];
23258
- var forwardPassTags = {
23259
- pipelineStage: PipelineStage.Forward
23260
- };
23261
- Shader.create("blinn-phong", [].concat([
23262
- new ShaderPass("Forward", blinnPhongVs, blinnPhongFs, forwardPassTags)
23263
- ], basePasses));
23264
- Shader.create("pbr", [].concat([
23265
- new ShaderPass("Forward", pbrVs, pbrFs, forwardPassTags)
23266
- ], basePasses));
23267
- Shader.create("pbr-specular", [].concat([
23268
- new ShaderPass("Forward", pbrVs, pbrSpecularFs, forwardPassTags)
23269
- ], basePasses));
23270
- Shader.create("unlit", [].concat([
23271
- new ShaderPass("Forward", unlitVs, unlitFs, forwardPassTags)
23272
- ], basePasses));
23273
- Shader.create("blit", [
23274
- new ShaderPass("Forward", blitVs, blitFs, forwardPassTags)
23275
- ]);
23276
- Shader.create("skybox", [
23277
- new ShaderPass("Forward", skyboxVs, skyboxFs, forwardPassTags)
23278
- ]);
23279
- Shader.create("SkyProcedural", [
23280
- new ShaderPass("Forward", skyProceduralVs, skyProceduralFs, forwardPassTags)
23281
- ]);
23282
- Shader.create("particle-shader", [
23283
- new ShaderPass("Forward", particleVs, particleFs, forwardPassTags)
23284
- ]);
23285
- Shader.create("SpriteMask", [
23286
- new ShaderPass("Forward", spriteMaskVs, spriteMaskFs, forwardPassTags)
23287
- ]);
23288
- Shader.create("Sprite", [
23289
- new ShaderPass("Forward", spriteVs, spriteFs, forwardPassTags)
23290
- ]);
23291
- Shader.create("Text", [
23292
- new ShaderPass("Forward", textVs, textFs, forwardPassTags)
23293
- ]);
23294
- Shader.create("background-texture", [
23295
- new ShaderPass("Forward", backgroundTextureVs, backgroundTextureFs, forwardPassTags)
23296
- ]);
23497
+ * Represents a parameter of a post process effect.
23498
+ * @remarks
23499
+ * The parameter will be mixed to a final value and be used in post process manager.
23500
+ */ var PostProcessEffectParameter = /*#__PURE__*/ function() {
23501
+ function PostProcessEffectParameter(value, needLerpOrMin, max, needLerp) {
23502
+ /**
23503
+ * Whether the parameter is enabled.
23504
+ */ this.enabled = true;
23505
+ this._needLerp = false;
23506
+ if (typeof value === "number") {
23507
+ if (typeof needLerpOrMin === "boolean") {
23508
+ this._needLerp = needLerpOrMin;
23509
+ this._min = Number.NEGATIVE_INFINITY;
23510
+ this._max = Number.POSITIVE_INFINITY;
23511
+ } else if (typeof needLerpOrMin === "number") {
23512
+ this._min = needLerpOrMin;
23513
+ this._max = max != null ? max : Number.POSITIVE_INFINITY;
23514
+ this._needLerp = needLerp != null ? needLerp : false;
23515
+ } else if (needLerpOrMin == undefined) {
23516
+ this._min = Number.NEGATIVE_INFINITY;
23517
+ this._max = Number.POSITIVE_INFINITY;
23518
+ }
23519
+ } else {
23520
+ this._needLerp = needLerpOrMin != null ? needLerpOrMin : false;
23521
+ }
23522
+ this.value = value;
23523
+ }
23524
+ var _proto = PostProcessEffectParameter.prototype;
23525
+ /**
23526
+ * @internal
23527
+ */ _proto._lerp = function _lerp(to, factor) {
23528
+ if (this._needLerp) {
23529
+ var _this_value;
23530
+ switch((_this_value = this.value) == null ? void 0 : _this_value.constructor){
23531
+ case Number:
23532
+ this.value = engineMath.MathUtil.lerp(this.value, to, factor);
23533
+ break;
23534
+ case engineMath.Color:
23535
+ engineMath.Color.lerp(this.value, to, factor, this.value);
23536
+ break;
23537
+ case engineMath.Vector2:
23538
+ engineMath.Vector2.lerp(this.value, to, factor, this.value);
23539
+ break;
23540
+ case engineMath.Vector3:
23541
+ engineMath.Vector3.lerp(this.value, to, factor, this.value);
23542
+ break;
23543
+ case engineMath.Vector4:
23544
+ engineMath.Vector4.lerp(this.value, to, factor, this.value);
23545
+ break;
23546
+ default:
23547
+ if (factor > 0) {
23548
+ this.value = to;
23549
+ }
23550
+ }
23551
+ } else if (factor > 0) {
23552
+ this.value = to;
23553
+ }
23297
23554
  };
23298
- return ShaderPool;
23555
+ _create_class(PostProcessEffectParameter, [
23556
+ {
23557
+ key: "value",
23558
+ get: /**
23559
+ * The value of the parameter.
23560
+ */ function get() {
23561
+ return this._value;
23562
+ },
23563
+ set: function set(value) {
23564
+ if ((value == null ? void 0 : value.constructor) === Number) {
23565
+ this._value = engineMath.MathUtil.clamp(value, this._min, this._max);
23566
+ } else {
23567
+ this._value = value;
23568
+ }
23569
+ }
23570
+ }
23571
+ ]);
23572
+ return PostProcessEffectParameter;
23299
23573
  }();
23300
23574
 
23301
23575
  /**
23302
- * Shader program pool.
23303
- * @internal
23304
- */ var ShaderProgramPool = /*#__PURE__*/ function() {
23305
- function ShaderProgramPool(engine) {
23306
- this.engine = engine;
23307
- this._cacheHierarchyDepth = 1;
23308
- this._cacheMap = Object.create(null);
23576
+ * The base class for post process effect.
23577
+ */ var PostProcessEffect = /*#__PURE__*/ function() {
23578
+ function PostProcessEffect() {
23579
+ this._enabled = true;
23580
+ this._parameters = [];
23581
+ this._parameterInitialized = false;
23309
23582
  }
23310
- var _proto = ShaderProgramPool.prototype;
23311
- /**
23312
- * Get shader program by macro collection.
23313
- * @param macros - macro collection
23314
- * @returns shader program
23315
- */ _proto.get = function get(macros) {
23316
- var cacheMap = this._cacheMap;
23317
- var maskLength = macros._length;
23318
- var cacheHierarchyDepth = this._cacheHierarchyDepth;
23319
- if (maskLength > cacheHierarchyDepth) {
23320
- this._resizeCacheMapHierarchy(cacheMap, 0, cacheHierarchyDepth, maskLength - cacheHierarchyDepth);
23321
- this._cacheHierarchyDepth = maskLength;
23322
- }
23323
- var mask = macros._mask;
23324
- var endIndex = macros._length - 1;
23325
- var maxEndIndex = this._cacheHierarchyDepth - 1;
23326
- for(var i = 0; i < maxEndIndex; i++){
23327
- var subMask = endIndex < i ? 0 : mask[i];
23328
- var subCacheShaders = cacheMap[subMask];
23329
- subCacheShaders || (cacheMap[subMask] = subCacheShaders = Object.create(null));
23330
- cacheMap = subCacheShaders;
23331
- }
23332
- var cacheKey = endIndex < maxEndIndex ? 0 : mask[maxEndIndex];
23333
- var shader = cacheMap[cacheKey];
23334
- if (!shader) {
23335
- this._lastQueryKey = cacheKey;
23336
- this._lastQueryMap = cacheMap;
23337
- }
23338
- return shader;
23339
- };
23583
+ var _proto = PostProcessEffect.prototype;
23340
23584
  /**
23341
- * Cache the shader program.
23342
- *
23585
+ * Whether the post process effect is valid.
23343
23586
  * @remarks
23344
- * The method must return an empty value after calling get() to run normally.
23345
- *
23346
- * @param shaderProgram - shader program
23347
- */ _proto.cache = function cache(shaderProgram) {
23348
- this._lastQueryMap[this._lastQueryKey] = shaderProgram;
23587
+ * This method can be overridden to control the effect's real validity.
23588
+ */ _proto.isValid = function isValid() {
23589
+ return this._enabled;
23349
23590
  };
23350
23591
  /**
23351
23592
  * @internal
23352
- */ _proto._destroy = function _destroy() {
23353
- this._recursiveDestroy(0, this._cacheMap);
23354
- this._cacheMap = Object.create(null);
23355
- };
23356
- _proto._recursiveDestroy = function _recursiveDestroy(hierarchy, cacheMap) {
23357
- if (hierarchy === this._cacheHierarchyDepth - 1) {
23358
- for(var k in cacheMap){
23359
- cacheMap[k].destroy();
23593
+ */ _proto._lerp = function _lerp(to, factor) {
23594
+ var parameters = this._getParameters();
23595
+ var toParameters = to._getParameters();
23596
+ for(var i = 0, n = parameters.length; i < n; i++){
23597
+ var toParameter = toParameters[i];
23598
+ if (toParameter.enabled) {
23599
+ parameters[i]._lerp(toParameter.value, factor);
23360
23600
  }
23361
- return;
23362
- }
23363
- ++hierarchy;
23364
- for(var k1 in cacheMap){
23365
- this._recursiveDestroy(hierarchy, cacheMap[k1]);
23366
23601
  }
23367
23602
  };
23368
- _proto._resizeCacheMapHierarchy = function _resizeCacheMapHierarchy(cacheMap, hierarchy, currentHierarchy, increaseHierarchy) {
23369
- // Only expand but not shrink
23370
- if (hierarchy == currentHierarchy - 1) {
23371
- for(var k in cacheMap){
23372
- var shader = cacheMap[k];
23373
- var subCacheMap = cacheMap;
23374
- for(var i = 0; i < increaseHierarchy; i++){
23375
- subCacheMap[i == 0 ? k : 0] = subCacheMap = Object.create(null);
23603
+ /**
23604
+ * Get all parameters of the post process effect.
23605
+ * @remarks
23606
+ * Only get the parameters that are initialized in the constructor.
23607
+ * It will don't take effect if you add a new parameter after the post process effect is created, such as `effect.** = new PostProcessEffectParameter(1)`
23608
+ */ _proto._getParameters = function _getParameters() {
23609
+ if (!this._parameterInitialized) {
23610
+ this._parameterInitialized = true;
23611
+ for(var key in this){
23612
+ var value = this[key];
23613
+ if (_instanceof(value, PostProcessEffectParameter)) {
23614
+ this._parameters.push(value);
23376
23615
  }
23377
- subCacheMap[0] = shader;
23378
- }
23379
- } else {
23380
- hierarchy++;
23381
- for(var k1 in cacheMap){
23382
- this._resizeCacheMapHierarchy(cacheMap[k1], hierarchy, currentHierarchy, increaseHierarchy);
23383
23616
  }
23384
23617
  }
23618
+ return this._parameters;
23385
23619
  };
23386
- return ShaderProgramPool;
23620
+ _create_class(PostProcessEffect, [
23621
+ {
23622
+ key: "enabled",
23623
+ get: /**
23624
+ * Indicates whether the post process effect is enabled.
23625
+ */ function get() {
23626
+ return this._enabled;
23627
+ },
23628
+ set: function set(value) {
23629
+ if (value === this._enabled) {
23630
+ return;
23631
+ }
23632
+ this._enabled = value;
23633
+ }
23634
+ }
23635
+ ]);
23636
+ return PostProcessEffect;
23387
23637
  }();
23388
23638
 
23639
+ var fragBlurH = "#define GLSLIFY 1\n#include <PostCommon>\n\nvarying vec2 v_uv;\nuniform sampler2D renderer_BlitTexture;\nuniform vec4 renderer_texelSize; // x: 1/width, y: 1/height, z: width, w: height\n\nvoid main(){\n\tvec2 texelSize = renderer_texelSize.xy * 2.0;\n\n // 9-tap gaussian blur on the downsampled source\n mediump vec4 c0 = sampleTexture(renderer_BlitTexture, v_uv - vec2(texelSize.x * 4.0, 0.0));\n mediump vec4 c1 = sampleTexture(renderer_BlitTexture, v_uv - vec2(texelSize.x * 3.0, 0.0));\n mediump vec4 c2 = sampleTexture(renderer_BlitTexture, v_uv - vec2(texelSize.x * 2.0, 0.0));\n mediump vec4 c3 = sampleTexture(renderer_BlitTexture, v_uv - vec2(texelSize.x * 1.0, 0.0));\n mediump vec4 c4 = sampleTexture(renderer_BlitTexture, v_uv);\n mediump vec4 c5 = sampleTexture(renderer_BlitTexture, v_uv + vec2(texelSize.x * 1.0, 0.0));\n mediump vec4 c6 = sampleTexture(renderer_BlitTexture, v_uv + vec2(texelSize.x * 2.0, 0.0));\n mediump vec4 c7 = sampleTexture(renderer_BlitTexture, v_uv + vec2(texelSize.x * 3.0, 0.0));\n mediump vec4 c8 = sampleTexture(renderer_BlitTexture, v_uv + vec2(texelSize.x * 4.0, 0.0));\n\n gl_FragColor = c0 * 0.01621622 + c1 * 0.05405405 + c2 * 0.12162162 + c3 * 0.19459459\n + c4 * 0.22702703\n + c5 * 0.19459459 + c6 * 0.12162162 + c7 * 0.05405405 + c8 * 0.01621622;\n\n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}"; // eslint-disable-line
23640
+
23641
+ var fragBlurV = "#define GLSLIFY 1\n#include <PostCommon>\n\nvarying vec2 v_uv;\nuniform sampler2D renderer_BlitTexture;\nuniform vec4 renderer_texelSize; // x: 1/width, y: 1/height, z: width, w: height\n\nvoid main(){\n vec2 texelSize = renderer_texelSize.xy;\n\n // Optimized bilinear 5-tap gaussian on the same-sized source (9-tap equivalent)\n mediump vec4 c0 = sampleTexture(renderer_BlitTexture, v_uv - vec2(0.0, texelSize.y * 3.23076923));\n mediump vec4 c1 = sampleTexture(renderer_BlitTexture, v_uv - vec2(0.0, texelSize.y * 1.38461538));\n mediump vec4 c2 = sampleTexture(renderer_BlitTexture, v_uv);\n mediump vec4 c3 = sampleTexture(renderer_BlitTexture, v_uv + vec2(0.0, texelSize.y * 1.38461538));\n mediump vec4 c4 = sampleTexture(renderer_BlitTexture, v_uv + vec2(0.0, texelSize.y * 3.23076923));\n\n gl_FragColor = c0 * 0.07027027 + c1 * 0.31621622\n + c2 * 0.22702703\n + c3 * 0.31621622 + c4 * 0.07027027;\n\n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}"; // eslint-disable-line
23642
+
23643
+ var fragPrefilter = "#define GLSLIFY 1\n#include <PostCommon>\n\nvarying vec2 v_uv;\nuniform sampler2D renderer_BlitTexture;\nuniform vec4 material_BloomParams; // x: threshold (linear), y: threshold knee, z: scatter\nuniform vec4 renderer_texelSize; // x: 1/width, y: 1/height, z: width, w: height\n\nvoid main(){\n\t#ifdef BLOOM_HQ\n vec2 texelSize = renderer_texelSize.xy;\n mediump vec4 A = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-1.0, -1.0));\n mediump vec4 B = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.0, -1.0));\n mediump vec4 C = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(1.0, -1.0));\n mediump vec4 D = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-0.5, -0.5));\n mediump vec4 E = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.5, -0.5));\n mediump vec4 F = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-1.0, 0.0));\n mediump vec4 G = sampleTexture(renderer_BlitTexture, v_uv);\n mediump vec4 H = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(1.0, 0.0));\n mediump vec4 I = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-0.5, 0.5));\n mediump vec4 J = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.5, 0.5));\n mediump vec4 K = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-1.0, 1.0));\n mediump vec4 L = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.0, 1.0));\n mediump vec4 M = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(1.0, 1.0));\n\n mediump vec2 scale = vec2(0.5, 0.125);\n mediump vec2 div = (1.0 / 4.0) * scale;\n\n mediump vec4 samplerColor = (D + E + I + J) * div.x;\n samplerColor += (A + B + G + F) * div.y;\n samplerColor += (B + C + H + G) * div.y;\n samplerColor += (F + G + L + K) * div.y;\n samplerColor += (G + H + M + L) * div.y;\n #else\n mediump vec4 samplerColor = sampleTexture(renderer_BlitTexture, v_uv);\n #endif\n\n mediump vec3 color = samplerColor.rgb;\n\n // User controlled clamp to limit crazy high broken spec\n color = min(color, HALF_MAX);\n\n // Thresholding\n mediump float brightness = max3(color);\n float threshold = material_BloomParams.x;\n float thresholdKnee = material_BloomParams.y;\n mediump float softness = clamp(brightness - threshold + thresholdKnee, 0.0, 2.0 * thresholdKnee);\n softness = (softness * softness) / (4.0 * thresholdKnee + 1e-4);\n mediump float multiplier = max(brightness - threshold, softness) / max(brightness, 1e-4);\n color *= multiplier;\n\n // Clamp colors to positive once in prefilter. Encode can have a sqrt, and sqrt(-x) == NaN. Up/Downsample passes would then spread the NaN.\n color = max(color, 0.0);\n\n gl_FragColor = vec4(color, samplerColor.a);\n \n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}"; // eslint-disable-line
23644
+
23645
+ var fragUpsample = "#define GLSLIFY 1\n#include <PostCommon>\n#include <Filtering>\n\nvarying vec2 v_uv;\nuniform sampler2D renderer_BlitTexture;\nuniform sampler2D material_lowMipTexture;\nuniform vec4 material_BloomParams; // x: threshold (linear), y: threshold knee, z: scatter\nuniform vec4 material_lowMipTexelSize; // x: 1/width, y: 1/height, z: width, w: height\n\nvoid main(){\n mediump vec4 highMip = sampleTexture(renderer_BlitTexture, v_uv);\n\n #ifdef BLOOM_HQ\n mediump vec4 lowMip = sampleTexture2DBicubic(material_lowMipTexture, v_uv, material_lowMipTexelSize);\n #else\n mediump vec4 lowMip = sampleTexture(material_lowMipTexture, v_uv);\n #endif\n \n gl_FragColor = mix(highMip, lowMip, material_BloomParams.z);\n \n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}"; // eslint-disable-line
23646
+
23389
23647
  /**
23390
- * Clearable Object Pool.
23391
- */ var ClearableObjectPool = /*#__PURE__*/ function(ObjectPool) {
23392
- _inherits(ClearableObjectPool, ObjectPool);
23393
- function ClearableObjectPool(type) {
23648
+ * This controls the size of the bloom texture.
23649
+ */ var BloomDownScaleMode = /*#__PURE__*/ function(BloomDownScaleMode) {
23650
+ /** Use this to select half size as the starting resolution. */ BloomDownScaleMode[BloomDownScaleMode["Half"] = 0] = "Half";
23651
+ /** Use this to select quarter size as the starting resolution. */ BloomDownScaleMode[BloomDownScaleMode["Quarter"] = 1] = "Quarter";
23652
+ return BloomDownScaleMode;
23653
+ }({});
23654
+ var BloomEffect = /*#__PURE__*/ function(PostProcessEffect) {
23655
+ _inherits(BloomEffect, PostProcessEffect);
23656
+ function BloomEffect() {
23394
23657
  var _this;
23395
- _this = ObjectPool.call(this, type) || this, _this._usedElementCount = 0;
23396
- _this._elements = [];
23658
+ _this = PostProcessEffect.apply(this, arguments) || this, /**
23659
+ * Controls whether to use bicubic sampling instead of bilinear sampling for the upSampling passes.
23660
+ * @remarks This is slightly more expensive but helps getting smoother visuals.
23661
+ */ _this.highQualityFiltering = new PostProcessEffectParameter(false), /**
23662
+ * Controls the starting resolution that this effect begins processing.
23663
+ */ _this.downScale = new PostProcessEffectParameter(0), /**
23664
+ * Specifies a Texture to add smudges or dust to the bloom effect.
23665
+ */ _this.dirtTexture = new PostProcessEffectParameter(null), /**
23666
+ * Set the level of brightness to filter out pixels under this level.
23667
+ * @remarks This value is expressed in gamma-space.
23668
+ */ _this.threshold = new PostProcessEffectParameter(0.9, 0, Number.POSITIVE_INFINITY, true), /**
23669
+ * Controls the radius of the bloom effect.
23670
+ */ _this.scatter = new PostProcessEffectParameter(0.7, 0, 1, true), /**
23671
+ * Controls the strength of the bloom effect.
23672
+ */ _this.intensity = new PostProcessEffectParameter(0, 0, Number.POSITIVE_INFINITY, true), /**
23673
+ * Controls the strength of the lens dirt.
23674
+ */ _this.dirtIntensity = new PostProcessEffectParameter(0, 0, Number.POSITIVE_INFINITY, true), /**
23675
+ * Specifies the tint of the bloom effect.
23676
+ */ _this.tint = new PostProcessEffectParameter(new engineMath.Color(1, 1, 1, 1), true);
23677
+ return _this;
23678
+ }
23679
+ var _proto = BloomEffect.prototype;
23680
+ /** @inheritdoc */ _proto.isValid = function isValid() {
23681
+ return this.enabled && this.intensity.value > 0;
23682
+ };
23683
+ return BloomEffect;
23684
+ }(PostProcessEffect);
23685
+ BloomEffect.SHADER_NAME = "PostProcessEffect Bloom";
23686
+ // Bloom shader properties
23687
+ /** @internal */ BloomEffect._maxIterations = 6;
23688
+ /** @internal */ BloomEffect._hqMacro = ShaderMacro.getByName("BLOOM_HQ");
23689
+ /** @internal */ BloomEffect._dirtMacro = ShaderMacro.getByName("BLOOM_DIRT");
23690
+ /** @internal */ BloomEffect._bloomParams = ShaderProperty.getByName("material_BloomParams") // x: threshold (linear), y: threshold knee, z: scatter
23691
+ ;
23692
+ /** @internal */ BloomEffect._lowMipTextureProp = ShaderProperty.getByName("material_lowMipTexture");
23693
+ /** @internal */ BloomEffect._lowMipTexelSizeProp = ShaderProperty.getByName("material_lowMipTexelSize") // x: 1/width, y: 1/height, z: width, w: height
23694
+ ;
23695
+ // Uber shader properties
23696
+ /** @internal */ BloomEffect._enableMacro = ShaderMacro.getByName("ENABLE_EFFECT_BLOOM");
23697
+ /** @internal */ BloomEffect._bloomTextureProp = ShaderProperty.getByName("material_BloomTexture");
23698
+ /** @internal */ BloomEffect._dirtTextureProp = ShaderProperty.getByName("material_BloomDirtTexture");
23699
+ /** @internal */ BloomEffect._tintProp = ShaderProperty.getByName("material_BloomTint");
23700
+ /** @internal */ BloomEffect._bloomIntensityParams = ShaderProperty.getByName("material_BloomIntensityParams") // x: bloom intensity, y: dirt intensity
23701
+ ;
23702
+ /** @internal */ BloomEffect._dirtTilingOffsetProp = ShaderProperty.getByName("material_BloomDirtTilingOffset");
23703
+ Shader.create(BloomEffect.SHADER_NAME, [
23704
+ new ShaderPass("Bloom Prefilter", blitVs, fragPrefilter),
23705
+ new ShaderPass("Bloom Blur Horizontal", blitVs, fragBlurH),
23706
+ new ShaderPass("Bloom Blur Vertical", blitVs, fragBlurV),
23707
+ new ShaderPass("Bloom Upsample", blitVs, fragUpsample)
23708
+ ]);
23709
+
23710
+ /**
23711
+ * Options to select a tonemapping algorithm to use.
23712
+ */ var TonemappingMode = /*#__PURE__*/ function(TonemappingMode) {
23713
+ /**
23714
+ * Neutral tonemapper.
23715
+ * @remarks Use this option if you only want range-remapping with minimal impact on color hue and saturation.
23716
+ */ TonemappingMode[TonemappingMode["Neutral"] = 0] = "Neutral";
23717
+ /**
23718
+ * ACES Filmic reference tonemapper (custom approximation).
23719
+ * @remarks
23720
+ * Use this option to apply a close approximation of the reference ACES tonemapper for a more filmic look.
23721
+ * It is more contrasted than Neutral and has an effect on actual color hue and saturation.
23722
+ */ TonemappingMode[TonemappingMode["ACES"] = 1] = "ACES";
23723
+ return TonemappingMode;
23724
+ }({});
23725
+ var TonemappingEffect = /*#__PURE__*/ function(PostProcessEffect) {
23726
+ _inherits(TonemappingEffect, PostProcessEffect);
23727
+ function TonemappingEffect() {
23728
+ var _this;
23729
+ _this = PostProcessEffect.apply(this, arguments) || this, /**
23730
+ * Use this to select a tonemapping algorithm to use.
23731
+ */ _this.mode = new PostProcessEffectParameter(0, false);
23732
+ return _this;
23733
+ }
23734
+ return TonemappingEffect;
23735
+ }(PostProcessEffect);
23736
+ /** @internal */ TonemappingEffect._enableMacro = ShaderMacro.getByName("ENABLE_EFFECT_TONEMAPPING");
23737
+
23738
+ /**
23739
+ * Controls when the post process pass executes.
23740
+ */ var PostProcessPassEvent = /*#__PURE__*/ function(PostProcessPassEvent) {
23741
+ /** Before the uber pass. */ PostProcessPassEvent[PostProcessPassEvent["BeforeUber"] = 0] = "BeforeUber";
23742
+ /** After the uber pass. */ PostProcessPassEvent[PostProcessPassEvent["AfterUber"] = 100] = "AfterUber";
23743
+ return PostProcessPassEvent;
23744
+ }({});
23745
+ /**
23746
+ * Post process pass.
23747
+ */ var PostProcessPass = /*#__PURE__*/ function(EngineObject) {
23748
+ _inherits(PostProcessPass, EngineObject);
23749
+ function PostProcessPass() {
23750
+ var _this;
23751
+ _this = EngineObject.apply(this, arguments) || this, _this._event = 100, _this._isActive = true;
23752
+ return _this;
23753
+ }
23754
+ var _proto = PostProcessPass.prototype;
23755
+ /**
23756
+ * Whether the post process pass is valid in current post process manager.
23757
+ * @remarks
23758
+ * This method can be overridden to control the pass's real validity.
23759
+ * @param postProcessManager - The post process manager
23760
+ */ _proto.isValid = function isValid(postProcessManager) {
23761
+ return this._isActive;
23762
+ };
23763
+ /**
23764
+ * @inheritdoc
23765
+ */ _proto._onDestroy = function _onDestroy() {
23766
+ EngineObject.prototype._onDestroy.call(this);
23767
+ this.engine._removePostProcessPass(this);
23768
+ };
23769
+ _create_class(PostProcessPass, [
23770
+ {
23771
+ key: "event",
23772
+ get: /**
23773
+ * When the post process pass is rendered.
23774
+ * @remarks
23775
+ * Users can also inject pass events in a specific point by doing PostProcessPassEvent + offset.
23776
+ */ function get() {
23777
+ return this._event;
23778
+ },
23779
+ set: function set(value) {
23780
+ if (value !== this._event) {
23781
+ this._event = value;
23782
+ if (this._isActive) {
23783
+ this.engine._postProcessPassNeedRefresh = true;
23784
+ }
23785
+ }
23786
+ }
23787
+ },
23788
+ {
23789
+ key: "isActive",
23790
+ get: /**
23791
+ * Whether the post process pass is active.
23792
+ */ function get() {
23793
+ return this._isActive;
23794
+ },
23795
+ set: function set(value) {
23796
+ if (value !== this._isActive) {
23797
+ this._isActive = value;
23798
+ this.engine._postProcessPassNeedRefresh = true;
23799
+ }
23800
+ }
23801
+ }
23802
+ ]);
23803
+ return PostProcessPass;
23804
+ }(EngineObject);
23805
+
23806
+ var Filtering = "#define GLSLIFY 1\n#ifndef FILTERING\n#define FILTERING\n\nvec2 bSpline3MiddleLeft(vec2 x){\n return 0.16666667 + x * (0.5 + x * (0.5 - x * 0.5));\n}\n\nvec2 bSpline3MiddleRight(vec2 x){\n return 0.66666667 + x * (-1.0 + 0.5 * x) * x;\n}\n\nvec2 bSpline3Rightmost(vec2 x){\n return 0.16666667 + x * (-0.5 + x * (0.5 - x * 0.16666667));\n}\n\n// Compute weights & offsets for 4x bilinear taps for the bicubic B-Spline filter.\n// The fractional coordinate should be in the [0, 1] range (centered on 0.5).\n// Inspired by: http://vec3.ca/bicubic-filtering-in-fewer-taps/\nvoid bicubicFilter(vec2 fracCoord, out vec2 weights[2], out vec2 offsets[2]){\n vec2 r = bSpline3Rightmost(fracCoord);\n vec2 mr = bSpline3MiddleRight(fracCoord);\n vec2 ml = bSpline3MiddleLeft(fracCoord);\n vec2 l = 1.0 - mr - ml - r;\n\n weights[0] = r + mr;\n weights[1] = ml + l;\n offsets[0] = -1.0 + mr / weights[0];\n offsets[1] = 1.0 + l / weights[1];\n}\n\n// texSize: (1/width, 1/height, width, height)\nvec4 sampleTexture2DBicubic(sampler2D tex, vec2 coord, vec4 texSize){\n\tvec2 xy = coord * texSize.zw + 0.5;\n vec2 ic = floor(xy);\n vec2 fc = fract(xy);\n\n vec2 weights[2], offsets[2];\n bicubicFilter(fc, weights, offsets);\n\n return weights[0].y * (weights[0].x * sampleTexture(tex, (ic + vec2(offsets[0].x, offsets[0].y) - 0.5) * texSize.xy) +\n \tweights[1].x * sampleTexture(tex, (ic + vec2(offsets[1].x, offsets[0].y) - 0.5) * texSize.xy)) +\n weights[1].y * (weights[0].x * sampleTexture(tex, (ic + vec2(offsets[0].x, offsets[1].y) - 0.5) * texSize.xy) +\n weights[1].x * sampleTexture(tex, (ic + vec2(offsets[1].x, offsets[1].y) - 0.5) * texSize.xy));\n}\n\n#endif"; // eslint-disable-line
23807
+
23808
+ var PostCommon = "#define GLSLIFY 1\n#ifndef POST_COMMON\n#define POST_COMMON\n\n#include <common>\n#define FLT_MIN 1.175494351e-38 // Minimum normalized positive floating-point number\n#define HALF_MIN 6.103515625e-5 // 2^-14, the same value for 10, 11 and 16-bit: https://www.khronos.org/opengl/wiki/Small_Float_Formats\n#define HALF_MAX 65504.0 // (2 - 2^-10) * 2^15\n\nfloat min3(vec3 val) { return min(min(val.x, val.y), val.z); }\nfloat max3(vec3 val) { return max(max(val.x, val.y), val.z); }\n\nconst float INVERT_LOG10 = 0.43429448190325176;\n\nfloat log10(float x){\n return log(x) * INVERT_LOG10;\n}\n\nvec4 sampleTexture(sampler2D tex, vec2 uv){\n vec4 color = texture2D(tex, uv);\n\n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n color = gammaToLinear(color);\n #endif \n\n return color;\n}\n\n#endif"; // eslint-disable-line
23809
+
23810
+ var ACESTonemapping = "#define GLSLIFY 1\n#include <ColorTransform>\n#include <RRT>\n#include <ODT>\n\nvec3 ACESTonemap(vec3 color){\n vec3 aces = sRGB_2_AP0 * color;\n \n // --- Glow module --- //\n mediump float saturation = rgb_2_saturation(aces);\n mediump float ycIn = rgb_2_yc(aces);\n mediump float s = sigmoid_shaper((saturation - 0.4) / 0.2);\n float addedGlow = 1.0 + glow_fwd(ycIn, RRT_GLOW_GAIN * s, RRT_GLOW_MID);\n aces *= addedGlow;\n\n // --- Red modifier --- //\n mediump float hue = rgb_2_hue(vec3(aces));\n mediump float centeredHue = center_hue(hue, RRT_RED_HUE);\n float hueWeight = smoothstep(0.0, 1.0, 1.0 - abs(2.0 * centeredHue / RRT_RED_WIDTH));\n hueWeight *= hueWeight;\n\n aces.r += hueWeight * saturation * (RRT_RED_PIVOT - aces.r) * (1.0 - RRT_RED_SCALE);\n\n // --- ACES to RGB rendering space --- //\n vec3 acescg = max(AP0_2_AP1_MAT * aces, 0.0);\n\n // --- Global desaturation --- //\n acescg = mix(vec3(dot(acescg, AP1_RGB2Y)), acescg, RRT_SAT_FACTOR);\n\n // Apply RRT and ODT\n // https://github.com/TheRealMJP/BakingLab/blob/master/BakingLab/ACES.hlsl\n const float a = 0.0245786;\n const float b = 0.000090537;\n const float c = 0.983729;\n const float d = 0.4329510;\n const float e = 0.238081;\n\n // To reduce the likelyhood of extremely large values, we avoid using the x^2 term and therefore\n // divide numerator and denominator by it. This will lead to the constant factors of the\n // quadratic in the numerator and denominator to be divided by x; we add a tiny epsilon to avoid divide by 0.\n vec3 rcpAcesCG = 1.0 / (acescg + FLT_MIN);\n mediump vec3 rgbPost = (acescg + a - b * rcpAcesCG) /\n (acescg * c + d + e * rcpAcesCG);\n\n // Apply gamma adjustment to compensate for dim surround\n vec3 linearCV = darkSurround_to_dimSurround(rgbPost);\n\n // Apply desaturation to compensate for luminance difference\n linearCV = mix(vec3(dot(linearCV, AP1_RGB2Y)), linearCV, ODT_SAT_FACTOR);\n\n // Convert to display primary encoding\n // Rendering space RGB to XYZ\n vec3 XYZ = AP1_2_XYZ_MAT * linearCV;\n\n // Apply CAT from ACES white point to assumed observer adapted white point\n XYZ = D60_2_D65_CAT * XYZ;\n\n // CIE XYZ to display primaries\n linearCV = XYZ_2_REC709_MAT * XYZ;\n\n return linearCV;\n\n}"; // eslint-disable-line
23811
+
23812
+ var ColorTransform = "#define GLSLIFY 1\n#ifndef COLOR_TRANSFORM\n#define COLOR_TRANSFORM\n\n// Precomputed matrices (pre-transposed)\n// See https://github.com/ampas/aces-dev/blob/master/transforms/ctl/README-MATRIX.md\n \n const mediump mat3 sRGB_2_AP0 = mat3(\n 0.4397010, 0.0897923, 0.0175440,\n 0.3829780, 0.8134230, 0.1115440,\n 0.1773350, 0.0967616, 0.8707040\n );\n\n const mediump mat3 AP1_2_AP0_MAT = mat3(\n vec3(0.6954522414, 0.0447945634, -0.0055258826),\n vec3(0.1406786965, 0.8596711185, 0.0040252103),\n vec3(0.1638690622, 0.0955343182, 1.0015006723)\n );\n\n const mediump mat3 AP0_2_AP1_MAT = mat3(\n\tvec3(1.4514393161, -0.0765537734, 0.0083161484),\n vec3(-0.2365107469, 1.1762296998, -0.0060324498),\n vec3(-0.2149285693, -0.0996759264, 0.9977163014)\n );\n\n const mediump mat3 AP1_2_XYZ_MAT = mat3(\n vec3(0.6624541811, 0.2722287168, -0.0055746495),\n vec3(0.1340042065, 0.6740817658, 0.0040607335),\n vec3(0.1561876870, 0.0536895174, 1.0103391003)\n );\n\n const mediump mat3 XYZ_2_AP1_MAT = mat3(\n vec3(1.6410233797, -0.6636628587, 0.0117218943),\n vec3(-0.3248032942, 1.6153315917, -0.0082844420),\n vec3(-0.2364246952, 0.0167563477, 0.9883948585)\n );\n\n const mediump mat3 D60_2_D65_CAT = mat3(\n vec3(0.987224, -0.00759836, 0.00307257),\n vec3(-0.00611327, 1.00186, -0.00509595),\n vec3(0.0159533, 0.00533002, 1.08168)\n );\n\n const mediump mat3 XYZ_2_REC709_MAT = mat3(\n vec3(3.2409699419, -0.9692436363, 0.0556300797),\n vec3(-1.5373831776, 1.8759675015, -0.2039769589),\n vec3(-0.498610760, 0.0415550574, 1.0569715142)\n );\n\n const mediump vec3 AP1_RGB2Y = vec3(0.2722287168, 0.6740817658, 0.0536895174);\n\n mediump float rgb_2_saturation(mediump vec3 rgb){\n const mediump float TINY = 1e-4;\n mediump float mi = min3(rgb);\n mediump float ma = max3(rgb);\n return (max(ma, TINY) - max(mi, TINY)) / max(ma, 1e-2);\n }\n\n mediump float rgb_2_yc(mediump vec3 rgb){\n const mediump float ycRadiusWeight = 1.75;\n\n // Converts RGB to a luminance proxy, here called YC\n // YC is ~ Y + K * Chroma\n // Constant YC is a cone-shaped surface in RGB space, with the tip on the\n // neutral axis, towards white.\n // YC is normalized: RGB 1 1 1 maps to YC = 1\n //\n // ycRadiusWeight defaults to 1.75, although can be overridden in function\n // call to rgb_2_yc\n // ycRadiusWeight = 1 -> YC for pure cyan, magenta, yellow == YC for neutral\n // of same value\n // ycRadiusWeight = 2 -> YC for pure red, green, blue == YC for neutral of\n // same value.\n\n mediump float r = rgb.x;\n mediump float g = rgb.y;\n mediump float b = rgb.z;\n mediump float k = b * (b - g) + g * (g - r) + r * (r - b);\n k = max(k, 0.0); // Clamp to avoid precision issue causing k < 0, making sqrt(k) undefined\n float chroma = k == 0.0 ? 0.0 : sqrt(k); // Avoid NaN\n\n return (b + g + r + ycRadiusWeight * chroma) / 3.0;\n }\n\n mediump float rgb_2_hue(mediump vec3 rgb){\n // Returns a geometric hue angle in degrees (0-360) based on RGB values.\n // For neutral colors, hue is undefined and the function will return a quiet NaN value.\n mediump float hue;\n if (rgb.x == rgb.y && rgb.y == rgb.z){\n hue = 0.0; // RGB triplets where RGB are equal have an undefined hue\n } else{\n hue = (180.0 / PI) * atan(sqrt(3.0) * (rgb.y - rgb.z), 2.0 * rgb.x - rgb.y - rgb.z);\n }\n\n if (hue < 0.0){\n hue = hue + 360.0;\n } \n\n return hue;\n }\n\n mediump float center_hue(mediump float hue, mediump float centerH){\n mediump float hueCentered = hue - centerH;\n if (hueCentered < -180.0){\n hueCentered = hueCentered + 360.0;\n } else if (hueCentered > 180.0){\n hueCentered = hueCentered - 360.0;\n } \n\n return hueCentered;\n }\n\n#endif"; // eslint-disable-line
23813
+
23814
+ var ODT = "#define GLSLIFY 1\n#include <Tonescale>\n\n// Output Device Transform - RGB computer monitor\n\nconst float CINEMA_WHITE = 48.0;\nconst float CINEMA_BLACK = 0.02; // CINEMA_WHITE / 2400.0;\nconst float ODT_SAT_FACTOR = 0.93;\n\nmediump vec3 Y_2_linCV(mediump vec3 Y, mediump float Ymax, mediump float Ymin){\n return (Y - Ymin) / (Ymax - Ymin);\n}\n\nmediump vec3 XYZ_2_xyY(mediump vec3 XYZ){\n mediump float divisor = max(dot(XYZ, vec3(1.0)), 1e-4);\n return vec3(XYZ.xy / divisor, XYZ.y);\n}\n\nmediump vec3 xyY_2_XYZ(mediump vec3 xyY){\n mediump float m = xyY.z / max(xyY.y, 1e-4);\n mediump vec3 XYZ = vec3(xyY.xz, (1.0 - xyY.x - xyY.y));\n XYZ.xz *= m;\n return XYZ;\n}\n\nconst mediump float DIM_SURROUND_GAMMA = 0.9811;\n\nmediump vec3 darkSurround_to_dimSurround(mediump vec3 linearCV){\n // Extra conversions to float3/vec3 are required to avoid floating-point precision issues on some platforms.\n\n mediump vec3 XYZ = AP1_2_XYZ_MAT * linearCV;\n mediump vec3 xyY = XYZ_2_xyY(XYZ);\n xyY.z = clamp(xyY.z, 0.0, HALF_MAX);\n xyY.z = pow(xyY.z, DIM_SURROUND_GAMMA);\n XYZ = xyY_2_XYZ(xyY);\n\n return XYZ_2_AP1_MAT * XYZ;\n}\n\n//\n// Summary :\n// This transform is intended for mapping OCES onto a desktop computer monitor\n// typical of those used in motion picture visual effects production. These\n// monitors may occasionally be referred to as \"sRGB\" displays, however, the\n// monitor for which this transform is designed does not exactly match the\n// specifications in IEC 61966-2-1:1999.\n//\n// The assumed observer adapted white is D65, and the viewing environment is\n// that of a dim surround.\n//\n// The monitor specified is intended to be more typical of those found in\n// visual effects production.\n//\n// Device Primaries :\n// Primaries are those specified in Rec. ITU-R BT.709\n// CIE 1931 chromaticities: x y Y\n// Red: 0.64 0.33\n// Green: 0.3 0.6\n// Blue: 0.15 0.06\n// White: 0.3127 0.329 100 cd/m^2\n//\n// Display EOTF :\n// The reference electro-optical transfer function specified in\n// IEC 61966-2-1:1999.\n//\n// Signal Range:\n// This transform outputs full range code values.\n//\n// Assumed observer adapted white point:\n// CIE 1931 chromaticities: x y\n// 0.3127 0.329\n//\n\n// Viewing Environment:\n// This ODT has a compensation for viewing environment variables more typical\n// of those associated with video mastering.\n//\nmediump vec3 ODT_RGBmonitor_100nits_dim(mediump vec3 oces){\n // The metal compiler does not optimize structure access\n // const SegmentedSplineParams_c9 ODT_48nits = SegmentedSplineParams_c9(\n // // coefsLow[10]\n // float[10]( -1.6989700043, -1.6989700043, -1.4779000000, -1.2291000000, -0.8648000000, -0.4480000000, 0.0051800000, 0.4511080334, 0.9113744414, 0.9113744414),\n // // coefsHigh[10]\n // float[10]( 0.5154386965, 0.8470437783, 1.1358000000, 1.3802000000, 1.5197000000, 1.5985000000, 1.6467000000, 1.6746091357, 1.6878733390, 1.6878733390 ),\n // vec2(segmented_spline_c5_fwd(0.18*pow(2.,-6.5)), 0.02), // minPoint\n // vec2(segmented_spline_c5_fwd(0.18), 4.8), // midPoint\n // vec2(segmented_spline_c5_fwd(0.18*pow(2.,6.5)), 48.0), // maxPoint\n // 0.0, // slopeLow\n // 0.04 // slopeHigh\n // );\n\n // OCES to RGB rendering space\n mediump vec3 rgbPre = AP0_2_AP1_MAT * oces;\n\n // Apply the tonescale independently in rendering-space RGB\n mediump vec3 rgbPost;\n\n // rgbPost.r = segmented_spline_c9_fwd(rgbPre.r, ODT_48nits);\n // rgbPost.g = segmented_spline_c9_fwd(rgbPre.g, ODT_48nits);\n // rgbPost.b = segmented_spline_c9_fwd(rgbPre.b, ODT_48nits);\n\n rgbPost.r = segmented_spline_c9_fwd(rgbPre.r);\n rgbPost.g = segmented_spline_c9_fwd(rgbPre.g);\n rgbPost.b = segmented_spline_c9_fwd(rgbPre.b);\n\n // Scale luminance to linear code value\n mediump vec3 linearCV = Y_2_linCV(rgbPost, CINEMA_WHITE, CINEMA_BLACK);\n\n // Apply gamma adjustment to compensate for dim surround\n linearCV = darkSurround_to_dimSurround(linearCV);\n\n // Apply desaturation to compensate for luminance difference\n linearCV = mix(vec3(dot(linearCV, AP1_RGB2Y)), linearCV, ODT_SAT_FACTOR);\n\n // Convert to display primary encoding\n // Rendering space RGB to XYZ\n mediump vec3 XYZ = AP1_2_XYZ_MAT * linearCV;\n\n // Apply CAT from ACES white point to assumed observer adapted white point\n XYZ = D60_2_D65_CAT * XYZ;\n\n // CIE XYZ to display primaries\n linearCV = XYZ_2_REC709_MAT * XYZ;\n\n // Handle out-of-gamut values\n // Clip values < 0 or > 1 (i.e. projecting outside the display primaries)\n linearCV = clamp(linearCV, vec3(0), vec3(1));\n\n // Unity already draws to a sRGB target\n return linearCV;\n}"; // eslint-disable-line
23815
+
23816
+ var RRT = "#define GLSLIFY 1\n#include <Tonescale>\n\n// Reference Rendering Transform (RRT)\n\n// Sigmoid function in the range 0 to 1 spanning -2 to +2.\nmediump float sigmoid_shaper(mediump float x){\n mediump float t = max(1.0 - abs(x / 2.0), 0.0);\n mediump float y = 1.0 + sign(x) * (1.0 - t * t);\n\n return y * 0.5;\n}\n\nmediump float glow_fwd(mediump float ycIn, mediump float glowGainIn, mediump float glowMid){\n mediump float glowGainOut;\n\n if (ycIn <= 2.0 / 3.0 * glowMid){\n glowGainOut = glowGainIn;\n } else if (ycIn >= 2.0 * glowMid){\n glowGainOut = 0.0;\n } else{\n glowGainOut = glowGainIn * (glowMid / ycIn - 1.0 / 2.0);\n }\n\n return glowGainOut;\n}\n\n// \"Glow\" module constants\nconst mediump float RRT_GLOW_GAIN = 0.05;\nconst mediump float RRT_GLOW_MID = 0.08;\n\n// Red modifier constants\nconst mediump float RRT_RED_SCALE = 0.82;\nconst mediump float RRT_RED_PIVOT = 0.03;\nconst mediump float RRT_RED_HUE = 0.0;\nconst mediump float RRT_RED_WIDTH = 135.0;\n\n// Desaturation contants\nconst mediump float RRT_SAT_FACTOR = 0.96;\n\n// ACES to OCES\nmediump vec3 RRT(mediump vec3 aces){\n // --- Glow module --- //\n mediump float saturation = rgb_2_saturation(aces);\n mediump float ycIn = rgb_2_yc(aces);\n mediump float s = sigmoid_shaper((saturation - 0.4) / 0.2);\n mediump float addedGlow = 1.0 + glow_fwd(ycIn, RRT_GLOW_GAIN * s, RRT_GLOW_MID);\n aces *= addedGlow;\n\n // --- Red modifier --- //\n mediump float hue = rgb_2_hue(aces);\n mediump float centeredHue = center_hue(hue, RRT_RED_HUE);\n\n mediump float hueWeight = smoothstep(0.0, 1.0, 1.0 - abs(2.0 * centeredHue / RRT_RED_WIDTH));\n hueWeight *= hueWeight;\n\n aces.r += hueWeight * saturation * (RRT_RED_PIVOT - aces.r) * (1.0 - RRT_RED_SCALE);\n\n // --- ACES to RGB rendering space --- //\n aces = clamp(aces, 0.0, HALF_MAX); // avoids saturated negative colors from becoming positive in the matrix\n mediump vec3 rgbPre = AP0_2_AP1_MAT * aces;\n rgbPre = clamp(rgbPre, 0.0, HALF_MAX);\n\n // --- Global desaturation --- //\n rgbPre = mix(vec3(dot(rgbPre, AP1_RGB2Y)), rgbPre, RRT_SAT_FACTOR);\n\n // --- Apply the tonescale independently in rendering-space RGB --- //\n mediump vec3 rgbPost;\n rgbPost.x = segmented_spline_c5_fwd(rgbPre.x);\n rgbPost.y = segmented_spline_c5_fwd(rgbPre.y);\n rgbPost.z = segmented_spline_c5_fwd(rgbPre.z);\n\n // --- RGB rendering space to OCES --- //\n mediump vec3 outputVal = AP1_2_AP0_MAT * rgbPost;\n\n return outputVal;\n}"; // eslint-disable-line
23817
+
23818
+ var Tonescale = "#define GLSLIFY 1\n #ifndef TONE_SCALE\n #define TONE_SCALE\n \n const mediump mat3 M = mat3(\n vec3(0.5, -1.0, 0.5),\n vec3(-1.0, 1.0, 0.5),\n vec3(0.5, 0.0, 0.0)\n );\n\n mediump float segmented_spline_c5_fwd(mediump float x){\n #ifdef GRAPHICS_API_WEBGL2\n const mediump float coefsLow[6] = float[6](-4.0000000000, -4.0000000000, -3.1573765773, -0.4852499958, 1.8477324706, 1.8477324706); // coefs for B-spline between minPoint and midPoint (units of log luminance)\n const mediump float coefsHigh[6] = float[6](-0.7185482425, 2.0810307172, 3.6681241237, 4.0000000000, 4.0000000000, 4.0000000000); // coefs for B-spline between midPoint and maxPoint (units of log luminance)\n #else\n const mediump float coefsLow_0 = -4.0000000000;\n const mediump float coefsLow_1 = -4.0000000000;\n const mediump float coefsLow_2 = -3.1573765773;\n const mediump float coefsLow_3 = -0.4852499958;\n const mediump float coefsLow_4 = 1.8477324706;\n const mediump float coefsLow_5 = 1.8477324706;\n\n const mediump float coefsHigh_0 = -0.7185482425;\n const mediump float coefsHigh_1 = 2.0810307172;\n const mediump float coefsHigh_2 = 3.6681241237;\n const mediump float coefsHigh_3 = 4.0000000000;\n const mediump float coefsHigh_4 = 4.0000000000;\n const mediump float coefsHigh_5 = 4.0000000000;\n #endif\n\n // const vec2 minPoint = vec2(0.18 * exp2(-15.0), 0.0001); // {luminance, luminance} linear extension below this\n const mediump vec2 minPoint = vec2(0.0000054931640625, 0.0001); // {luminance, luminance} linear extension below this\n const mediump vec2 midPoint = vec2(0.18, 0.48); // {luminance, luminance}\n // const vec2 maxPoint = vec2(0.18 * exp2(18.0), 10000.0); // {luminance, luminance} linear extension above this\n const mediump vec2 maxPoint = vec2(47185.92, 10000.0); // {luminance, luminance} linear extension above this\n const mediump float slopeLow = 0.0; // log-log slope of low linear extension\n const mediump float slopeHigh = 0.0; // log-log slope of high linear extension\n\n const int N_KNOTS_LOW = 4;\n const int N_KNOTS_HIGH = 4;\n\n // Check for negatives or zero before taking the log. If negative or zero,\n // set to ACESMIN.1\n mediump float logx = log10(max(x, HALF_MIN));\n mediump float logy;\n\n if (logx <= log10(minPoint.x)){\n logy = logx * slopeLow + (log10(minPoint.y) - slopeLow * log10(minPoint.x));\n } else if ((logx > log10(minPoint.x)) && (logx < log10(midPoint.x))){\n mediump float knot_coord = float(N_KNOTS_LOW - 1) * (logx - log10(minPoint.x)) / (log10(midPoint.x) - log10(minPoint.x));\n int j = int(knot_coord);\n mediump float t = knot_coord - float(j);\n\n mediump vec3 cf;\n #ifdef GRAPHICS_API_WEBGL2\n cf = vec3(coefsLow[j], coefsLow[j + 1], coefsLow[j + 2]);\n #else\n if (j <= 0) {\n cf = vec3(coefsLow_0, coefsLow_1, coefsLow_2);\n } else if (j == 1) {\n cf = vec3(coefsLow_1, coefsLow_2, coefsLow_3);\n } else if (j == 2) {\n cf = vec3(coefsLow_2, coefsLow_3, coefsLow_4);\n } else { // if (j == 3)\n cf = vec3(coefsLow_3, coefsLow_4, coefsLow_5);\n }\n #endif\n\n mediump vec3 monomials = vec3(t * t, t, 1.0);\n logy = dot(monomials, M * cf);\n } else if ((logx >= log10(midPoint.x)) && (logx < log10(maxPoint.x))){\n mediump float knot_coord = float(N_KNOTS_HIGH - 1) * (logx - log10(midPoint.x)) / (log10(maxPoint.x) - log10(midPoint.x));\n int j = int(knot_coord);\n mediump float t = knot_coord - float(j);\n\n mediump vec3 cf;\n #ifdef GRAPHICS_API_WEBGL2\n cf = vec3(coefsHigh[j], coefsHigh[j + 1], coefsHigh[j + 2]);\n #else\n if (j <= 0) {\n cf = vec3(coefsHigh_0, coefsHigh_1, coefsHigh_2);\n } else if (j == 1) {\n cf = vec3(coefsHigh_1, coefsHigh_2, coefsHigh_3);\n } else if (j == 2) {\n cf = vec3(coefsHigh_2, coefsHigh_3, coefsHigh_4);\n } else { // if (j == 3)\n cf = vec3(coefsHigh_3, coefsHigh_4, coefsHigh_5);\n }\n #endif\n\n mediump vec3 monomials = vec3(t * t, t, 1.0);\n logy = dot(monomials, M * cf);\n } else {\n logy = logx * slopeHigh + (log10(maxPoint.y) - slopeHigh * log10(maxPoint.x));\n }\n\n return pow(10.0, logy);\n }\n\n // The metal compiler does not optimize structure access\n // struct SegmentedSplineParams_c9{\n // float coefsLow[10]; // coefs for B-spline between minPoint and midPoint (units of log luminance)\n // float coefsHigh[10]; // coefs for B-spline between midPoint and maxPoint (units of log luminance)\n // mediump vec2 minPoint; // {luminance, luminance} linear extension below this\n // mediump vec2 midPoint; // {luminance, luminance}\n // mediump vec2 maxPoint; // {luminance, luminance} linear extension above this\n // float slopeLow; // log-log slope of low linear extension\n // float slopeHigh; // log-log slope of high linear extension\n // };\n\n mediump float segmented_spline_c9_fwd(mediump float x){\n // ODT_48nits\n #ifdef GRAPHICS_API_WEBGL2\n const 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);\n 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\n const mediump float coefsLow_0 = -1.6989700043;\n const mediump float coefsLow_1 = -1.6989700043;\n const mediump float coefsLow_2 = -1.4779000000;\n const mediump float coefsLow_3 = -1.2291000000;\n const mediump float coefsLow_4 = -0.8648000000;\n const mediump float coefsLow_5 = -0.4480000000;\n const mediump float coefsLow_6 = 0.0051800000;\n const mediump float coefsLow_7 = 0.4511080334;\n const mediump float coefsLow_8 = 0.9113744414;\n const mediump float coefsLow_9 = 0.9113744414;\n\n const mediump float coefsHigh_0 = 0.5154386965;\n const mediump float coefsHigh_1 = 0.8470437783;\n const mediump float coefsHigh_2 = 1.1358000000;\n const mediump float coefsHigh_3 = 1.3802000000;\n const mediump float coefsHigh_4 = 1.5197000000;\n const mediump float coefsHigh_5 = 1.5985000000;\n const mediump float coefsHigh_6 = 1.6467000000;\n const mediump float coefsHigh_7 = 1.6746091357;\n const mediump float coefsHigh_8 = 1.6878733390;\n const mediump float coefsHigh_9 = 1.6878733390;\n #endif\n\n // mediump vec2 minPoint = vec2(segmented_spline_c5_fwd(0.18 * pow(2.0, -6.5)), 0.02);\n // mediump vec2 midPoint = vec2(segmented_spline_c5_fwd(0.18), 4.8);\n // mediump vec2 maxPoint = vec2(segmented_spline_c5_fwd(0.18 * pow(2., 6.5)), 48.0);\n\n const mediump vec2 minPoint = vec2(0.0028799, 0.02);\n const mediump vec2 midPoint = vec2(4.799999, 4.8);\n const mediump vec2 maxPoint = vec2(1005.719, 48.0);\n\n const mediump float slopeLow = 0.0;\n const mediump float slopeHigh = 0.04;\n\n const int N_KNOTS_LOW = 8;\n const int N_KNOTS_HIGH = 8;\n\n // Check for negatives or zero before taking the log. If negative or zero,\n // set to OCESMIN.\n mediump float logx = log10(max(x, 1e-4));\n mediump float logy;\n\n if (logx <= log10(minPoint.x)) {\n logy = logx * slopeLow + (log10(minPoint.y) - slopeLow * log10(minPoint.x));\n } else if ((logx > log10(minPoint.x)) && (logx < log10(midPoint.x))) {\n mediump float knot_coord = float(N_KNOTS_LOW - 1) * (logx - log10(minPoint.x)) / (log10(midPoint.x) - log10(minPoint.x));\n int j = int(knot_coord);\n mediump float t = knot_coord - float(j);\n\n mediump vec3 cf;\n #ifdef GRAPHICS_API_WEBGL2\n cf = vec3(coefsLow[j], coefsLow[j + 1], coefsLow[j + 2]);\n #else\n if (j <= 0) {\n cf = vec3(coefsLow_0, coefsLow_1, coefsLow_2);\n } else if (j == 1) {\n cf = vec3(coefsLow_1, coefsLow_2, coefsLow_3);\n } else if (j == 2) {\n cf = vec3(coefsLow_2, coefsLow_3, coefsLow_4);\n } else if (j == 3) {\n cf = vec3(coefsLow_3, coefsLow_4, coefsLow_5);\n } else if (j == 4) {\n cf = vec3(coefsLow_4, coefsLow_5, coefsLow_6);\n } else if (j == 5) {\n cf = vec3(coefsLow_5, coefsLow_6, coefsLow_7);\n } else if (j == 6) {\n cf = vec3(coefsLow_6, coefsLow_7, coefsLow_8);\n } else { // if (j == 7)\n cf = vec3(coefsLow_7, coefsLow_8, coefsLow_9);\n }\n #endif\n\n mediump vec3 monomials = vec3(t * t, t, 1.0);\n logy = dot(monomials, M * cf);\n } else if ((logx >= log10(midPoint.x)) && (logx < log10(maxPoint.x))) {\n mediump float knot_coord = float(N_KNOTS_HIGH - 1) * (logx - log10(midPoint.x)) / (log10(maxPoint.x) - log10(midPoint.x));\n int j = int(knot_coord);\n mediump float t = knot_coord - float(j);\n\n mediump vec3 cf;\n #ifdef GRAPHICS_API_WEBGL2\n cf = vec3(coefsHigh[j], coefsHigh[j + 1], coefsHigh[j + 2]);\n #else\n if (j <= 0) {\n cf = vec3(coefsHigh_0, coefsHigh_1, coefsHigh_2);\n } else if (j == 1) {\n cf = vec3(coefsHigh_1, coefsHigh_2, coefsHigh_3);\n } else if (j == 2) {\n cf = vec3(coefsHigh_2, coefsHigh_3, coefsHigh_4);\n } else if (j == 3) {\n cf = vec3(coefsHigh_3, coefsHigh_4, coefsHigh_5);\n } else if (j == 4) {\n cf = vec3(coefsHigh_4, coefsHigh_5, coefsHigh_6);\n } else if (j == 5) {\n cf = vec3(coefsHigh_5, coefsHigh_6, coefsHigh_7);\n } else if (j == 6) {\n cf = vec3(coefsHigh_6, coefsHigh_7, coefsHigh_8);\n } else { // if (j == 7)\n cf = vec3(coefsHigh_7, coefsHigh_8, coefsHigh_9);\n }\n #endif\n\n mediump vec3 monomials = vec3(t * t, t, 1.0);\n logy = dot(monomials, M * cf);\n } else {\n logy = logx * slopeHigh + (log10(maxPoint.y) - slopeHigh * log10(maxPoint.x));\n }\n\n return pow(10.0, logy);\n }\n\n#endif"; // eslint-disable-line
23819
+
23820
+ var NeutralTonemapping = "#define GLSLIFY 1\n// Neutral tonemapping (Hable/Hejl/Frostbite)\n// Input is linear RGB\n// More accuracy to avoid NaN on extremely high values.\nvec3 neutralCurve(vec3 x, float a, float b, float c, float d, float e, float f){\n return vec3(((x * (a * x + c * b) + d * e) / (x * (a * x + b) + d * f)) - e / f);\n}\n\n#define TONEMAPPING_CLAMP_MAX 435.18712 //(-b + sqrt(b * b - 4 * a * (HALF_MAX - d * f))) / (2 * a * whiteScale)\n//Extremely high values cause NaN output when using fp16, we clamp to avoid the performace hit of switching to fp32\n//The overflow happens in (x * (a * x + b) + d * f) of the NeutralCurve, highest value that avoids fp16 precision errors is ~571.56873\n//Since whiteScale is constant (~1.31338) max input is ~435.18712\n\nvec3 neutralTonemap(vec3 color){\n const float a = 0.2;\n const float b = 0.29;\n const float c = 0.24;\n const float d = 0.272;\n const float e = 0.02;\n const float f = 0.3;\n // const float whiteLevel = 5.3;\n // const float whiteClip = 1.0;\n\n #ifndef GL_FRAGMENT_PRECISION_HIGH\n color = min(color, TONEMAPPING_CLAMP_MAX);\n #endif\n\n // 1.0 / neutralCurve(whiteLevel, a, b, c, d, e, f);\n const float whiteScale = 1.31338; \n color = neutralCurve(color * whiteScale, a, b, c, d, e, f);\n color *= whiteScale;\n\n // Post-curve white point adjustment\n // color /= whiteClip;\n\n return color;\n}"; // eslint-disable-line
23821
+
23822
+ var UberPost = "#define GLSLIFY 1\n#include <PostCommon>\n#include <Filtering>\n#include <NeutralTonemapping>\n#include <ACESTonemapping>\n\nvarying vec2 v_uv;\nuniform sampler2D renderer_BlitTexture;\nuniform vec4 renderer_texelSize; // x: 1/width, y: 1/height, z: width, w: height\n#ifdef ENABLE_EFFECT_BLOOM\n\tuniform sampler2D material_BloomTexture;\n\tuniform sampler2D material_BloomDirtTexture;\n\tuniform vec4 material_BloomTint;\n\tuniform vec4 material_BloomDirtTilingOffset;\n\tuniform vec4 material_BloomIntensityParams; // x: bloom intensity, y: dirt intensity\n#endif\n\nvoid main(){\n\tmediump vec4 color = sampleTexture(renderer_BlitTexture, v_uv);\n\n\t#ifdef ENABLE_EFFECT_BLOOM\n \t#ifdef BLOOM_HQ\n \t mediump vec4 bloom = sampleTexture2DBicubic(material_BloomTexture, v_uv, renderer_texelSize);\n \t#else\n \t mediump vec4 bloom = sampleTexture(material_BloomTexture, v_uv);\n \t#endif\n\n \tbloom *= material_BloomIntensityParams.x;\n \tcolor += bloom * material_BloomTint;\n\n \t#ifdef BLOOM_DIRT\n \t mediump vec4 dirt = sampleTexture(material_BloomDirtTexture, v_uv * material_BloomDirtTilingOffset.xy + material_BloomDirtTilingOffset.zw);\n \t dirt *= material_BloomIntensityParams.y;\n \t // Additive bloom (artist friendly)\n \t color += dirt * bloom;\n \t#endif\n\t#endif\n\n\t#ifdef ENABLE_EFFECT_TONEMAPPING\n\t\t#if TONEMAPPING_MODE == 0\n \t\tcolor.rgb = neutralTonemap(color.rgb);\n \t#elif TONEMAPPING_MODE == 1\n \t\tcolor.rgb = ACESTonemap(color.rgb);\n \t#endif\n\n \tcolor.rgb = clamp(color.rgb, vec3(0), vec3(1));\n\t#endif\n\n gl_FragColor = color;\n\n\t#ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}"; // eslint-disable-line
23823
+
23824
+ var PostProcessUberPass = /*#__PURE__*/ function(PostProcessPass) {
23825
+ _inherits(PostProcessUberPass, PostProcessPass);
23826
+ function PostProcessUberPass(engine) {
23827
+ var _this;
23828
+ _this = PostProcessPass.call(this, engine) || this, _this._mipDownRT = [], _this._mipUpRT = [];
23829
+ _this.event = PostProcessPassEvent.AfterUber - 1;
23830
+ // Uber Material
23831
+ var uberMaterial = new Material(engine, Shader.find(PostProcessUberPass.UBER_SHADER_NAME));
23832
+ var uberDepthState = uberMaterial.renderState.depthState;
23833
+ uberDepthState.enabled = false;
23834
+ uberDepthState.writeEnabled = false;
23835
+ _this._uberMaterial = uberMaterial;
23836
+ // Bloom Material
23837
+ var bloomMaterial = new Material(engine, Shader.find(BloomEffect.SHADER_NAME));
23838
+ var bloomDepthState = bloomMaterial.renderState.depthState;
23839
+ bloomDepthState.enabled = false;
23840
+ bloomDepthState.writeEnabled = false;
23841
+ _this._bloomMaterial = bloomMaterial;
23842
+ // ShaderData initialization
23843
+ var bloomShaderData = bloomMaterial.shaderData;
23844
+ var uberShaderData = uberMaterial.shaderData;
23845
+ bloomShaderData.setVector4(BloomEffect._bloomParams, new engineMath.Vector4());
23846
+ bloomShaderData.setVector4(BloomEffect._lowMipTexelSizeProp, new engineMath.Vector4());
23847
+ uberShaderData.setVector4(BloomEffect._bloomIntensityParams, new engineMath.Vector4());
23848
+ uberShaderData.setVector4(BloomEffect._dirtTilingOffsetProp, new engineMath.Vector4());
23849
+ uberShaderData.setColor(BloomEffect._tintProp, new engineMath.Color());
23850
+ return _this;
23851
+ }
23852
+ var _proto = PostProcessUberPass.prototype;
23853
+ /** @inheritdoc */ _proto.isValid = function isValid(postProcessManager) {
23854
+ if (!this.isActive) {
23855
+ return false;
23856
+ }
23857
+ var bloomBlend = postProcessManager.getBlendEffect(BloomEffect);
23858
+ var tonemappingBlend = postProcessManager.getBlendEffect(TonemappingEffect);
23859
+ return (bloomBlend == null ? void 0 : bloomBlend.isValid()) || (tonemappingBlend == null ? void 0 : tonemappingBlend.isValid());
23860
+ };
23861
+ /**
23862
+ * @inheritdoc
23863
+ */ _proto.onRender = function onRender(camera, srcTexture, destTarget) {
23864
+ var postProcessManager = camera.scene.postProcessManager;
23865
+ var uberShaderData = this._uberMaterial.shaderData;
23866
+ var bloomBlend = postProcessManager.getBlendEffect(BloomEffect);
23867
+ var tonemappingBlend = postProcessManager.getBlendEffect(TonemappingEffect);
23868
+ if (bloomBlend == null ? void 0 : bloomBlend.isValid()) {
23869
+ this._setupBloom(bloomBlend, camera, srcTexture);
23870
+ uberShaderData.enableMacro(BloomEffect._enableMacro);
23871
+ } else {
23872
+ uberShaderData.disableMacro(BloomEffect._enableMacro);
23873
+ this._releaseBloomRenderTargets();
23874
+ }
23875
+ if (tonemappingBlend == null ? void 0 : tonemappingBlend.isValid()) {
23876
+ uberShaderData.enableMacro("TONEMAPPING_MODE", tonemappingBlend.mode.value.toString());
23877
+ uberShaderData.enableMacro(TonemappingEffect._enableMacro);
23878
+ } else {
23879
+ uberShaderData.disableMacro(TonemappingEffect._enableMacro);
23880
+ }
23881
+ Blitter.blitTexture(camera.engine, srcTexture, destTarget, 0, camera.viewport, this._uberMaterial, undefined);
23882
+ };
23883
+ /**
23884
+ * @inheritdoc
23885
+ */ _proto._onDestroy = function _onDestroy() {
23886
+ PostProcessPass.prototype._onDestroy.call(this);
23887
+ this._releaseBloomRenderTargets();
23888
+ this._uberMaterial.destroy();
23889
+ this._bloomMaterial.destroy();
23890
+ };
23891
+ _proto._setupBloom = function _setupBloom(bloomBlend, camera, srcTexture) {
23892
+ var engine = camera.engine;
23893
+ var bloomMaterial = this._bloomMaterial;
23894
+ var bloomShaderData = bloomMaterial.shaderData;
23895
+ var uberMaterial = this._uberMaterial;
23896
+ var uberShaderData = uberMaterial.shaderData;
23897
+ var downScale = bloomBlend.downScale, threshold = bloomBlend.threshold, scatter = bloomBlend.scatter, intensity = bloomBlend.intensity, tint = bloomBlend.tint, highQualityFiltering = bloomBlend.highQualityFiltering, dirtTexture = bloomBlend.dirtTexture, dirtIntensity = bloomBlend.dirtIntensity;
23898
+ // Update shaderData
23899
+ var thresholdLinear = engineMath.Color.gammaToLinearSpace(threshold.value);
23900
+ var thresholdKnee = thresholdLinear * 0.5; // Hardcoded soft knee
23901
+ var bloomParams = bloomShaderData.getVector4(BloomEffect._bloomParams);
23902
+ var scatterLerp = engineMath.MathUtil.lerp(0.05, 0.95, scatter.value);
23903
+ bloomParams.x = threshold.value;
23904
+ bloomParams.y = thresholdKnee;
23905
+ bloomParams.z = scatterLerp;
23906
+ var bloomIntensityParams = uberShaderData.getVector4(BloomEffect._bloomIntensityParams);
23907
+ bloomIntensityParams.x = intensity.value;
23908
+ bloomIntensityParams.y = dirtIntensity.value;
23909
+ var tintParam = uberShaderData.getColor(BloomEffect._tintProp);
23910
+ tintParam.copyFrom(tint.value);
23911
+ if (highQualityFiltering.value) {
23912
+ bloomShaderData.enableMacro(BloomEffect._hqMacro);
23913
+ uberShaderData.enableMacro(BloomEffect._hqMacro);
23914
+ } else {
23915
+ bloomShaderData.disableMacro(BloomEffect._hqMacro);
23916
+ uberShaderData.disableMacro(BloomEffect._hqMacro);
23917
+ }
23918
+ uberShaderData.setTexture(BloomEffect._dirtTextureProp, dirtTexture.value);
23919
+ if (dirtTexture) {
23920
+ uberShaderData.enableMacro(BloomEffect._dirtMacro);
23921
+ } else {
23922
+ uberShaderData.disableMacro(BloomEffect._dirtMacro);
23923
+ }
23924
+ // Determine the iteration count
23925
+ var downRes = downScale.value === BloomDownScaleMode.Half ? 1 : 2;
23926
+ var pixelViewport = camera.pixelViewport;
23927
+ var tw = pixelViewport.width >> downRes;
23928
+ var th = pixelViewport.height >> downRes;
23929
+ var maxSize = Math.max(tw, th);
23930
+ var iterations = Math.floor(Math.log2(maxSize) - 1);
23931
+ var mipCount = Math.min(Math.max(iterations, 1), BloomEffect._maxIterations);
23932
+ // Prefilter
23933
+ var internalColorTextureFormat = camera._getInternalColorTextureFormat();
23934
+ var mipWidth = tw, mipHeight = th;
23935
+ for(var i = 0; i < mipCount; i++){
23936
+ this._mipUpRT[i] = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._mipUpRT[i], mipWidth, mipHeight, internalColorTextureFormat, null, false, false, 1, TextureWrapMode.Clamp, TextureFilterMode.Bilinear);
23937
+ this._mipDownRT[i] = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._mipDownRT[i], mipWidth, mipHeight, internalColorTextureFormat, null, false, false, 1, TextureWrapMode.Clamp, TextureFilterMode.Bilinear);
23938
+ mipWidth = Math.max(1, Math.floor(mipWidth / 2));
23939
+ mipHeight = Math.max(1, Math.floor(mipHeight / 2));
23940
+ }
23941
+ Blitter.blitTexture(engine, srcTexture, this._mipDownRT[0], undefined, undefined, bloomMaterial, 0);
23942
+ // Down sample - gaussian pyramid
23943
+ var lastDown = this._mipDownRT[0];
23944
+ for(var i1 = 1; i1 < mipCount; i1++){
23945
+ // Classic two pass gaussian blur - use mipUp as a temporary target
23946
+ // First pass does 2x downsampling + 9-tap gaussian
23947
+ // Second pass does 9-tap gaussian using a 5-tap filter + bilinear filtering
23948
+ Blitter.blitTexture(engine, lastDown.getColorTexture(0), this._mipUpRT[i1], undefined, undefined, bloomMaterial, 1);
23949
+ Blitter.blitTexture(engine, this._mipUpRT[i1].getColorTexture(0), this._mipDownRT[i1], undefined, undefined, bloomMaterial, 2);
23950
+ lastDown = this._mipDownRT[i1];
23951
+ }
23952
+ // Up sample (bilinear by default, HQ filtering does bicubic instead
23953
+ for(var i2 = mipCount - 2; i2 >= 0; i2--){
23954
+ var lowMip = i2 == mipCount - 2 ? this._mipDownRT[i2 + 1] : this._mipUpRT[i2 + 1];
23955
+ var highMip = this._mipDownRT[i2];
23956
+ var dst = this._mipUpRT[i2];
23957
+ bloomShaderData.setTexture(BloomEffect._lowMipTextureProp, lowMip.getColorTexture(0));
23958
+ if (highQualityFiltering) {
23959
+ var texelSizeLow = bloomShaderData.getVector4(BloomEffect._lowMipTexelSizeProp);
23960
+ texelSizeLow.set(1 / lowMip.width, 1 / lowMip.height, lowMip.width, lowMip.height);
23961
+ }
23962
+ Blitter.blitTexture(engine, highMip.getColorTexture(0), dst, undefined, undefined, bloomMaterial, 3);
23963
+ }
23964
+ // Setup bloom on uber
23965
+ if (dirtTexture.value) {
23966
+ var dirtTilingOffset = uberShaderData.getVector4(BloomEffect._dirtTilingOffsetProp);
23967
+ var dirtRatio = dirtTexture.value.width / dirtTexture.value.height;
23968
+ var screenRatio = camera.aspectRatio;
23969
+ if (dirtRatio > screenRatio) {
23970
+ dirtTilingOffset.set(screenRatio / dirtRatio, 1, (1 - dirtTilingOffset.x) * 0.5, 0);
23971
+ } else if (dirtRatio < screenRatio) {
23972
+ dirtTilingOffset.set(1, dirtRatio / screenRatio, 0, (1 - dirtTilingOffset.y) * 0.5);
23973
+ } else {
23974
+ dirtTilingOffset.set(1, 1, 0, 0);
23975
+ }
23976
+ }
23977
+ uberShaderData.setTexture(BloomEffect._bloomTextureProp, this._mipUpRT[0].getColorTexture(0));
23978
+ };
23979
+ _proto._releaseBloomRenderTargets = function _releaseBloomRenderTargets() {
23980
+ var length = this._mipDownRT.length;
23981
+ for(var i = 0; i < length; i++){
23982
+ var downRT = this._mipDownRT[i];
23983
+ var upRT = this._mipUpRT[i];
23984
+ if (downRT) {
23985
+ downRT.getColorTexture(0).destroy(true);
23986
+ downRT.destroy(true);
23987
+ }
23988
+ if (upRT) {
23989
+ upRT.getColorTexture(0).destroy(true);
23990
+ upRT.destroy(true);
23991
+ }
23992
+ }
23993
+ this._mipDownRT.length = 0;
23994
+ this._mipUpRT.length = 0;
23995
+ };
23996
+ return PostProcessUberPass;
23997
+ }(PostProcessPass);
23998
+ PostProcessUberPass.UBER_SHADER_NAME = "UberPost";
23999
+ Object.assign(ShaderLib, {
24000
+ PostCommon: PostCommon,
24001
+ Filtering: Filtering,
24002
+ ODT: ODT,
24003
+ RRT: RRT,
24004
+ Tonescale: Tonescale,
24005
+ ColorTransform: ColorTransform,
24006
+ NeutralTonemapping: NeutralTonemapping,
24007
+ ACESTonemapping: ACESTonemapping
24008
+ });
24009
+ Shader.create(PostProcessUberPass.UBER_SHADER_NAME, blitVs, UberPost);
24010
+
24011
+ var blitFs = "#define GLSLIFY 1\nuniform mediump sampler2D renderer_BlitTexture;\n#ifdef HAS_TEX_LOD\n\tuniform float renderer_BlitMipLevel;\n#endif\n\nuniform vec4 renderer_SourceScaleOffset;\n\nvarying vec2 v_uv;\n\nvoid main() {\n\tvec2 uv = v_uv;\n\tuv = uv * renderer_SourceScaleOffset.xy + renderer_SourceScaleOffset.zw;\n\n\t#ifdef HAS_TEX_LOD\n\t\tgl_FragColor = texture2DLodEXT( renderer_BlitTexture, uv, renderer_BlitMipLevel );\n\t#else\n\t\tgl_FragColor = texture2D( renderer_BlitTexture, uv );\n\t#endif\n}\n\n"; // eslint-disable-line
24012
+
24013
+ var skyProceduralFs = "#define GLSLIFY 1\n// This code uses the Unity skybox-Procedural shader algorithm, developed by Unity and licensed under the Unity Companion License. \n// The original implementation can be found at unity build-in shader(DefaultResourcesExtra/Skybox-Procedural.shader)\n\n#include <common>\n\nconst float MIE_G = -0.990;\nconst float MIE_G2 = 0.9801;\nconst float SKY_GROUND_THRESHOLD = 0.02;\n\nuniform float material_SunSize;\nuniform float material_SunSizeConvergence;\nuniform vec4 scene_SunlightColor;\nuniform vec3 scene_SunlightDirection;\n\nvarying vec3 v_GroundColor;\nvarying vec3 v_SkyColor;\n\n#ifdef MATERIAL_SUN_HIGH_QUALITY\n\tvarying vec3 v_Vertex;\n#elif defined(MATERIAL_SUN_SIMPLE)\n\tvarying vec3 v_RayDir;\n#else\n\tvarying float v_SkyGroundFactor;\n#endif\n\n#if defined(MATERIAL_SUN_HIGH_QUALITY)||defined(MATERIAL_SUN_SIMPLE)\n\tvarying vec3 v_SunColor;\n#endif\n\n#if defined(ENGINE_IS_COLORSPACE_GAMMA)\n\t#define LINEAR_2_OUTPUT(color) sqrt(color)\n#endif\n\n// Calculates the Mie phase function\nfloat getMiePhase(float eyeCos, float eyeCos2) {\n\tfloat temp = 1.0 + MIE_G2 - 2.0 * MIE_G * eyeCos;\n\ttemp = pow(temp, pow(material_SunSize,0.65) * 10.0);\n\ttemp = max(temp,1.0e-4); // prevent division by zero, esp. in half precision\n\ttemp = 1.5 * ((1.0 - MIE_G2) / (2.0 + MIE_G2)) * (1.0 + eyeCos2) / temp;\n\treturn temp;\n}\n\n// Calculates the sun shape\nfloat calcSunAttenuation(vec3 lightPos, vec3 ray) {\n\t#ifdef MATERIAL_SUN_HIGH_QUALITY\n\t\tfloat focusedEyeCos = pow(clamp(dot(lightPos, ray),0.0,1.0), material_SunSizeConvergence);\n\t\treturn getMiePhase(-focusedEyeCos, focusedEyeCos * focusedEyeCos);\n\t#else //MATERIAL_SUN_SIMPLE\n\t\tvec3 delta = lightPos - ray;\n\t\tfloat dist = length(delta);\n\t\tfloat spot = 1.0 - smoothstep(0.0, material_SunSize, dist);\n\t\treturn spot * spot;\n\t#endif\n}\n\nvoid main() {\n\t// if y > 1 [eyeRay.y < -SKY_GROUND_THRESHOLD] - ground\n\t// if y >= 0 and < 1 [eyeRay.y <= 0 and > -SKY_GROUND_THRESHOLD] - horizon\n\t// if y < 0 [eyeRay.y > 0] - sky\n\tvec3 col = vec3(0.0, 0.0, 0.0);\n\n\t#ifdef MATERIAL_SUN_HIGH_QUALITY\n\t\tvec3 ray = normalize(v_Vertex);\n\t\tfloat y = ray.y / SKY_GROUND_THRESHOLD;\n\t#elif defined(MATERIAL_SUN_SIMPLE) \n\t\tvec3 ray = v_RayDir;\n\t\tfloat y = ray.y / SKY_GROUND_THRESHOLD;\t\n\t#else\n\t\tfloat y = v_SkyGroundFactor;\n\t#endif\n\n\t// if we did precalculate color in vprog: just do lerp between them\n\tcol = mix(v_SkyColor, v_GroundColor, clamp(y,0.0,1.0));\n\n\t#if defined(MATERIAL_SUN_HIGH_QUALITY)||defined(MATERIAL_SUN_SIMPLE)\n\t\tif (y < 0.0)\n\t\t\tcol += v_SunColor * calcSunAttenuation(-scene_SunlightDirection, -ray);\n\t#endif\n\n #ifdef ENGINE_IS_COLORSPACE_GAMMA\n\t\tcol = LINEAR_2_OUTPUT(col); // linear space convert to gamma space\n\t#endif\n\n\tgl_FragColor = vec4(col,1.0);\n\n\t#ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}\n\n"; // eslint-disable-line
24014
+
24015
+ var skyProceduralVs = "#define GLSLIFY 1\n// This code uses the Unity skybox-Procedural shader algorithm, developed by Unity and licensed under the Unity Companion License. \n// The original implementation can be found at unity build-in shader(DefaultResourcesExtra/Skybox-Procedural.shader)\n\n#define OUTER_RADIUS 1.025\n#define RAYLEIGH (mix(0.0, 0.0025, pow(material_AtmosphereThickness,2.5)))\t// Rayleigh constant\n#define MIE 0.0010\t// Mie constant\n#define SUN_BRIGHTNESS 20.0\t// Sun brightness\n#define MAX_SCATTER 50.0 // Maximum scattering value, to prevent math overflows on Adrenos\n\nconst float SKY_GROUND_THRESHOLD = 0.02;\nconst float outerRadius = OUTER_RADIUS;\nconst float outerRadius2 = OUTER_RADIUS*OUTER_RADIUS;\nconst float innerRadius = 1.0;\nconst float innerRadius2 = 1.0;\nconst float cameraHeight = 0.0001;\n\nconst float HDSundiskIntensityFactor = 15.0;\nconst float simpleSundiskIntensityFactor = 27.0;\n\nconst float sunScale = 400.0 * SUN_BRIGHTNESS;\nconst float kmESun = MIE * SUN_BRIGHTNESS;\nconst float km4PI = MIE * 4.0 * 3.14159265;\nconst float scale = 1.0 / (OUTER_RADIUS - 1.0);\nconst float scaleDepth = 0.25;\nconst float scaleOverScaleDepth = (1.0 / (OUTER_RADIUS - 1.0)) / 0.25;\nconst float samples = 2.0; // THIS IS UNROLLED MANUALLY, DON'T TOUCH\n\n// RGB wavelengths .35 (.62=158), .43 (.68=174), .525 (.75=190)\nconst vec3 c_DefaultScatteringWavelength = vec3(0.65, 0.57, 0.475);\nconst vec3 c_VariableRangeForScatteringWavelength = vec3(0.15, 0.15, 0.15);\n\nattribute vec4 POSITION;\n\nuniform mat4 camera_VPMat;\nuniform vec3 material_SkyTint;\nuniform vec3 material_GroundTint;\nuniform float material_Exposure;\nuniform float material_AtmosphereThickness;\nuniform vec4 scene_SunlightColor;\nuniform vec3 scene_SunlightDirection;\n\nvarying vec3 v_GroundColor;\nvarying vec3 v_SkyColor;\n\n#ifdef MATERIAL_SUN_HIGH_QUALITY\n\tvarying vec3 v_Vertex;\n#elif defined(MATERIAL_SUN_SIMPLE)\n\tvarying vec3 v_RayDir;\n#else\n\tvarying float v_SkyGroundFactor;\n#endif\n\n#if defined(MATERIAL_SUN_HIGH_QUALITY)||defined(MATERIAL_SUN_SIMPLE)\n\tvarying vec3 v_SunColor;\n#endif\n\n#if defined(ENGINE_IS_COLORSPACE_GAMMA)\n\t#define COLOR_2_GAMMA(color) color\n\t#define COLOR_2_LINEAR(color) color*color\n#else\n\t#define GAMMA 2.2\n\t#define COLOR_2_GAMMA(color) pow(color,vec3(1.0/GAMMA))\n\t#define COLOR_2_LINEAR(color) color\n#endif\n\n// Calculates the Rayleigh phase function\nfloat getRayleighPhase(vec3 light, vec3 ray) \n{\n\tfloat eyeCos = dot(light, ray);\n\treturn 0.75 + 0.75 * eyeCos * eyeCos;\n}\n\nfloat scaleAngle(float inCos)\n{\n\tfloat x = 1.0 - inCos;\n\treturn 0.25 * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));\n}\n\nvoid main () {\n\tgl_Position = camera_VPMat*vec4(POSITION.xyz,1.0);\n\n \tvec3 skyTintInGammaSpace = COLOR_2_GAMMA(material_SkyTint);\n\tvec3 scatteringWavelength = mix(c_DefaultScatteringWavelength-c_VariableRangeForScatteringWavelength,c_DefaultScatteringWavelength+c_VariableRangeForScatteringWavelength,vec3(1.0) - skyTintInGammaSpace); // using Tint in sRGB+ gamma allows for more visually linear interpolation and to keep (0.5) at (128, gray in sRGB) point\n\tvec3 invWavelength = 1.0 / pow(scatteringWavelength, vec3(4.0));\n\n\tfloat krESun = RAYLEIGH * SUN_BRIGHTNESS;\n\tfloat kr4PI = RAYLEIGH * 4.0 * 3.14159265;\n\n\tvec3 cameraPos = vec3(0.0,innerRadius + cameraHeight,0.0); // The camera's current position\n\n\t// Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)\n\tvec3 eyeRay = normalize(POSITION.xyz);\n\n\tfloat far = 0.0;\n\tvec3 cIn, cOut;\n\tif (eyeRay.y >= 0.0) {\n\t\t// Sky \n\t\t// Calculate the length of the \"atmosphere\"\n\t\tfar = sqrt(outerRadius2 + innerRadius2 * eyeRay.y * eyeRay.y - innerRadius2) - innerRadius * eyeRay.y;\n\n\t\t// Calculate the ray's starting position, then calculate its scattering offset\n\t\tfloat height = innerRadius + cameraHeight;\n\t\tfloat depth = exp(scaleOverScaleDepth * -cameraHeight);\n\t\tfloat startAngle = dot(eyeRay, cameraPos) / height;\n\t\tfloat startOffset = depth*scaleAngle(startAngle);\n\n\t\t// Initialize the scattering loop variables\n\t\tfloat sampleLength = far / samples;\n\t\tfloat scaledLength = sampleLength * scale;\n\t\tvec3 sampleRay = eyeRay * sampleLength;\n\t\tvec3 samplePoint = cameraPos + sampleRay * 0.5;\n\n\t\tvec3 frontColor = vec3(0.0);\n\t\t//unrolling this manually to avoid some platform for loop slow\n\t\t{\n\t\t\tfloat height = length(samplePoint);\n\t\t\tfloat depth = exp(scaleOverScaleDepth * (innerRadius - height));\n\t\t\tfloat lightAngle = dot(-scene_SunlightDirection, samplePoint) / height;\n\t\t\tfloat cameraAngle = dot(eyeRay, samplePoint) / height;\n\t\t\tfloat scatter = (startOffset + depth*(scaleAngle(lightAngle) - scaleAngle(cameraAngle)));\n\t\t\tvec3 attenuate = exp(-clamp(scatter, 0.0, MAX_SCATTER) * (invWavelength * kr4PI + km4PI));\n\n\t\t\tfrontColor += attenuate * (depth * scaledLength);\n\t\t\tsamplePoint += sampleRay;\n\t\t}\n\t\t{\n\t\t\tfloat height = length(samplePoint);\n\t\t\tfloat depth = exp(scaleOverScaleDepth * (innerRadius - height));\n\t\t\tfloat lightAngle = dot(-scene_SunlightDirection, samplePoint) / height;\n\t\t\tfloat cameraAngle = dot(eyeRay, samplePoint) / height;\n\t\t\tfloat scatter = (startOffset + depth*(scaleAngle(lightAngle) - scaleAngle(cameraAngle)));\n\t\t\tvec3 attenuate = exp(-clamp(scatter, 0.0, MAX_SCATTER) * (invWavelength * kr4PI + km4PI));\n\n\t\t\tfrontColor += attenuate * (depth * scaledLength);\n\t\t\tsamplePoint += sampleRay;\n\t\t}\n\n\t\t// Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader\n\t\tcIn = frontColor * (invWavelength * krESun);\n\t\tcOut = frontColor * kmESun;\n\t} else {\n\t\t// Ground\n\t\tfar = (-cameraHeight) / (min(-0.001, eyeRay.y));\n\t\tvec3 pos = cameraPos + far * eyeRay;\n\n\t\t// Calculate the ray's starting position, then calculate its scattering offset\n\t\tfloat depth = exp((-cameraHeight) * (1.0/scaleDepth));\n\t\tfloat cameraAngle = dot(-eyeRay, pos);\n\t\tfloat lightAngle = dot(-scene_SunlightDirection, pos);\n\t\tfloat cameraScale = scaleAngle(cameraAngle);\n\t\tfloat lightScale = scaleAngle(lightAngle);\n\t\tfloat cameraOffset = depth*cameraScale;\n\t\tfloat temp = lightScale + cameraScale;\n\n\t\t// Initialize the scattering loop variables\n\t\tfloat sampleLength = far / samples;\n\t\tfloat scaledLength = sampleLength * scale;\n\t\tvec3 sampleRay = eyeRay * sampleLength;\n\t\tvec3 samplePoint = cameraPos + sampleRay * 0.5;\n\n\t\t// Now loop through the sample rays\n\t\tvec3 frontColor = vec3(0.0, 0.0, 0.0);\n\t\tvec3 attenuate;\n\n\t\t// Loop removed because we kept hitting SM2.0 temp variable limits. Doesn't affect the image too much\n\t\t{\n\t\t\tfloat height = length(samplePoint);\n\t\t\tfloat depth = exp(scaleOverScaleDepth * (innerRadius - height));\n\t\t\tfloat scatter = depth*temp - cameraOffset;\n\t\t\tattenuate = exp(-clamp(scatter, 0.0, MAX_SCATTER) * (invWavelength * kr4PI + km4PI));\n\t\t\tfrontColor += attenuate * (depth * scaledLength);\n\t\t\tsamplePoint += sampleRay;\n\t\t}\n\n\t\tcIn = frontColor * (invWavelength * krESun + kmESun);\n\t\tcOut = clamp(attenuate, 0.0, 1.0);\n\t}\n\n\t#ifdef MATERIAL_SUN_HIGH_QUALITY\n\t\tv_Vertex = -POSITION.xyz;\n\t#elif defined(MATERIAL_SUN_SIMPLE) \n\t\tv_RayDir = -eyeRay;\n\t#else\n\t\tv_SkyGroundFactor = -eyeRay.y / SKY_GROUND_THRESHOLD;\n\t#endif\n\n\t// if we want to calculate color in vprog:\n\t// 1. in case of linear: multiply by _Exposure in here (even in case of lerp it will be common multiplier, so we can skip mul in fshader)\n\t// 2. in case of gamma: do sqrt right away instead of doing that in fshader\n\t\n\tv_GroundColor = material_Exposure * (cIn + COLOR_2_LINEAR(material_GroundTint) * cOut);\n\tv_SkyColor = material_Exposure * (cIn * getRayleighPhase(-scene_SunlightDirection, -eyeRay));\n\n\t\n\t// The sun should have a stable intensity in its course in the sky. Moreover it should match the highlight of a purely specular material.\n\t// This matching was done using the standard shader BRDF1 on the 5/31/2017\n\t// Finally we want the sun to be always bright even in LDR thus the normalization of the lightColor for low intensity.\n\tfloat lightColorIntensity = clamp(length(scene_SunlightColor.xyz), 0.25, 1.0);\n\n\t#ifdef MATERIAL_SUN_HIGH_QUALITY \n\t\tv_SunColor = HDSundiskIntensityFactor * clamp(cOut,0.0,1.0) * scene_SunlightColor.xyz / lightColorIntensity;\n\t#elif defined(MATERIAL_SUN_SIMPLE) \n\t\tv_SunColor = simpleSundiskIntensityFactor * clamp(cOut * sunScale,0.0,1.0) * scene_SunlightColor.xyz / lightColorIntensity;\n\t#endif\n}\n"; // eslint-disable-line
24016
+
24017
+ var backgroundTextureFs = "#define GLSLIFY 1\nuniform sampler2D material_BaseTexture;\n\nvarying vec2 v_uv;\n\nvoid main() {\n gl_FragColor = texture2D(material_BaseTexture, v_uv);\n}"; // eslint-disable-line
24018
+
24019
+ var backgroundTextureVs = "#define GLSLIFY 1\nattribute vec3 POSITION;\nattribute vec2 TEXCOORD_0;\nvarying vec2 v_uv;\nuniform vec4 camera_ProjectionParams;\n\nvoid main() {\n gl_Position = vec4(POSITION, 1.0);\n gl_Position.y *= camera_ProjectionParams.x;\n \n v_uv = TEXCOORD_0;\n}"; // eslint-disable-line
24020
+
24021
+ var blinnPhongFs = "#define GLSLIFY 1\n#include <common>\n#include <camera_declare>\n\n#include <uv_share>\n#include <normal_share>\n#include <color_share>\n#include <worldpos_share>\n\n#include <light_frag_define>\n#include <ShadowFragmentDeclaration>\n#include <mobile_material_frag>\n\n#include <FogFragmentDeclaration>\n#include <normal_get>\n\nvoid main() {\n\n #include <begin_mobile_frag>\n #include <begin_viewdir_frag>\n #include <mobile_blinnphong_frag>\n\n gl_FragColor = emission + ambient + diffuse + specular;\n\n #ifdef MATERIAL_IS_TRANSPARENT\n gl_FragColor.a = diffuse.a;\n #else\n gl_FragColor.a = 1.0;\n #endif\n\n #include <FogFragment>\n\n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}\n"; // eslint-disable-line
24022
+
24023
+ var blinnPhongVs = "#define GLSLIFY 1\n#include <common>\n#include <common_vert>\n#include <blendShape_input>\n#include <uv_share>\n#include <color_share>\n#include <normal_share>\n#include <worldpos_share>\n\n#include <ShadowVertexDeclaration>\n#include <FogVertexDeclaration>\n\nvoid main() {\n\n #include <begin_position_vert>\n #include <begin_normal_vert>\n #include <blendShape_vert>\n #include <skinning_vert>\n #include <uv_vert>\n #include <color_vert>\n #include <normal_vert>\n #include <worldpos_vert>\n #include <position_vert>\n\n #include <ShadowVertex>\n #include <FogVertex>\n}\n"; // eslint-disable-line
24024
+
24025
+ var depthOnlyFs = "#define GLSLIFY 1\nvoid main() {\n}"; // eslint-disable-line
24026
+
24027
+ var depthOnlyVs = "#define GLSLIFY 1\n#include <common>\n#include <common_vert>\n#include <blendShape_input>\nuniform mat4 camera_VPMat;\n\nvoid main() {\n\n #include <begin_position_vert>\n #include <blendShape_vert>\n #include <skinning_vert>\n #include <position_vert>\n\n}\n"; // eslint-disable-line
24028
+
24029
+ var particleFs = "#define GLSLIFY 1\n#include <common>\n\nvarying vec4 v_Color;\nvarying vec2 v_TextureCoordinate;\nuniform sampler2D material_BaseTexture;\nuniform vec4 material_BaseColor;\n\n#ifdef RENDERER_MODE_MESH\n\tvarying vec4 v_MeshColor;\n#endif\n\nvoid main() {\n\tvec4 color = material_BaseColor * v_Color;\n\n\t#ifdef RENDERER_MODE_MESH\n\t\tcolor *= v_MeshColor;\n\t#endif\n\n\t#ifdef MATERIAL_HAS_BASETEXTURE\n\t\tvec4 textureColor = texture2D(material_BaseTexture,v_TextureCoordinate);\n\t\t#ifndef ENGINE_IS_COLORSPACE_GAMMA\n textureColor = gammaToLinear(textureColor);\n #endif\n\t\tcolor *= textureColor;\n\t#endif\n\tgl_FragColor = color; \n\n\t #ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}"; // eslint-disable-line
24030
+
24031
+ var particleVs = "#define GLSLIFY 1\n#if defined(RENDERER_MODE_SPHERE_BILLBOARD) || defined(RENDERER_MODE_STRETCHED_BILLBOARD) || defined(RENDERER_MODE_HORIZONTAL_BILLBOARD) || defined(RENDERER_MODE_VERTICAL_BILLBOARD)\n attribute vec4 a_CornerTextureCoordinate;\n#endif\n\n#ifdef RENDERER_MODE_MESH\n attribute vec3 a_MeshPosition;\n attribute vec4 a_MeshColor;\n attribute vec2 a_MeshTextureCoordinate;\n varying vec4 v_MeshColor;\n#endif\n\nattribute vec4 a_ShapePositionStartLifeTime;\nattribute vec4 a_DirectionTime;\nattribute vec4 a_StartColor;\nattribute vec3 a_StartSize;\nattribute vec3 a_StartRotation0;\nattribute float a_StartSpeed;\n\n//#if defined(COLOR_OVER_LIFETIME) || defined(RENDERER_COL_RANDOM_GRADIENTS) || defined(RENDERER_SOL_RANDOM_CURVES) || defined(RENDERER_SOL_RANDOM_CURVES_SEPARATE) || defined(ROTATION_OVER_LIFE_TIME_RANDOM_CONSTANTS) || defined(ROTATION_OVER_LIFETIME_RANDOM_CURVES)\n attribute vec4 a_Random0;\n//#endif\n\n#if defined(RENDERER_TSA_FRAME_RANDOM_CURVES) || defined(RENDERER_VOL_RANDOM_CONSTANT) || defined(RENDERER_VOL_RANDOM_CURVE)\n attribute vec4 a_Random1; // x:texture sheet animation random\n#endif\n\nattribute vec3 a_SimulationWorldPosition;\nattribute vec4 a_SimulationWorldRotation;\n\nvarying vec4 v_Color;\n#ifdef MATERIAL_HAS_BASETEXTURE\n attribute vec4 a_SimulationUV;\n varying vec2 v_TextureCoordinate;\n#endif\n\nuniform float renderer_CurrentTime;\nuniform vec3 renderer_Gravity;\nuniform vec2 u_DragConstant;\nuniform vec3 renderer_WorldPosition;\nuniform vec4 renderer_WorldRotation;\nuniform bool renderer_ThreeDStartRotation;\nuniform int renderer_ScalingMode;\nuniform vec3 renderer_PositionScale;\nuniform vec3 renderer_SizeScale;\nuniform vec3 renderer_PivotOffset;\n\nuniform mat4 camera_ViewMat;\nuniform mat4 camera_ProjMat;\n\n#ifdef RENDERER_MODE_STRETCHED_BILLBOARD\n uniform vec3 camera_Position;\n#endif\nuniform vec3 camera_Forward; // TODO:只有几种广告牌模式需要用\nuniform vec3 camera_Up;\n\nuniform float renderer_StretchedBillboardLengthScale;\nuniform float renderer_StretchedBillboardSpeedScale;\nuniform int renderer_SimulationSpace;\n\n#include <particle_common>\n#include <velocity_over_lifetime_module>\n#include <color_over_lifetime_module>\n#include <size_over_lifetime_module>\n#include <rotation_over_lifetime_module>\n#include <texture_sheet_animation_module>\n\nvoid main() {\n float age = renderer_CurrentTime - a_DirectionTime.w;\n float normalizedAge = age / a_ShapePositionStartLifeTime.w;\n vec3 lifeVelocity;\n if (normalizedAge < 1.0) {\n vec3 startVelocity = a_DirectionTime.xyz * a_StartSpeed;\n #if defined(RENDERER_VOL_CONSTANT) || defined(RENDERER_VOL_CURVE) || defined(RENDERER_VOL_RANDOM_CONSTANT) || defined(RENDERER_VOL_RANDOM_CURVE)\n lifeVelocity = computeParticleLifeVelocity(normalizedAge); \n #endif\n \n vec3 gravityVelocity = renderer_Gravity * a_Random0.x * age;\n\n vec4 worldRotation;\n if (renderer_SimulationSpace == 0) {\n worldRotation = renderer_WorldRotation;\n } else {\n worldRotation = a_SimulationWorldRotation;\n }\n\n //drag\n vec3 dragData = a_DirectionTime.xyz * mix(u_DragConstant.x, u_DragConstant.y, a_Random0.x);\n vec3 center = computeParticlePosition(startVelocity, lifeVelocity, age, normalizedAge, gravityVelocity, worldRotation, dragData); //计算粒子位置\n\n #include <sphere_billboard>\n #include <stretched_billboard>\n #include <horizontal_billboard>\n #include <vertical_billboard>\n #include <particle_mesh>\n\n gl_Position = camera_ProjMat * camera_ViewMat * vec4(center, 1.0);\n v_Color = computeParticleColor(a_StartColor, normalizedAge);\n\n #ifdef MATERIAL_HAS_BASETEXTURE\n vec2 simulateUV;\n #if defined(RENDERER_MODE_SPHERE_BILLBOARD) || defined(RENDERER_MODE_STRETCHED_BILLBOARD) || defined(RENDERER_MODE_HORIZONTAL_BILLBOARD) || defined(RENDERER_MODE_VERTICAL_BILLBOARD)\n simulateUV = a_CornerTextureCoordinate.zw * a_SimulationUV.xy + a_SimulationUV.zw;\n v_TextureCoordinate = computeParticleUV(simulateUV, normalizedAge);\n #endif\n #ifdef RENDERER_MODE_MESH\n simulateUV = a_SimulationUV.xy + a_MeshTextureCoordinate * a_SimulationUV.zw;\n v_TextureCoordinate = computeParticleUV(simulateUV, normalizedAge);\n #endif\n #endif\n } else {\n\t gl_Position = vec4(2.0, 2.0, 2.0, 1.0); // Discard use out of X(-1,1),Y(-1,1),Z(0,1)\n }\n}\n"; // eslint-disable-line
24032
+
24033
+ var pbrSpecularFs = "#define GLSLIFY 1\n#include <common>\n#include <camera_declare>\n\n#include <FogFragmentDeclaration>\n\n#include <uv_share>\n#include <normal_share>\n#include <color_share>\n#include <worldpos_share>\n\n#include <light_frag_define>\n\n#include <pbr_frag_define>\n#include <pbr_helper>\n\nvoid main() {\n #include <pbr_frag>\n #include <FogFragment>\n\n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}\n"; // eslint-disable-line
24034
+
24035
+ var pbrFs = "#define GLSLIFY 1\n#define IS_METALLIC_WORKFLOW\n#include <common>\n#include <camera_declare>\n\n#include <FogFragmentDeclaration>\n\n#include <uv_share>\n#include <normal_share>\n#include <color_share>\n#include <worldpos_share>\n\n#include <light_frag_define>\n\n#include <pbr_frag_define>\n#include <pbr_helper>\n\nvoid main() {\n #include <pbr_frag>\n #include <FogFragment>\n \n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}\n"; // eslint-disable-line
24036
+
24037
+ var pbrVs = "#define GLSLIFY 1\n#include <common>\n#include <common_vert>\n#include <blendShape_input>\n#include <uv_share>\n#include <color_share>\n#include <normal_share>\n#include <worldpos_share>\n\n#include <ShadowVertexDeclaration>\n#include <FogVertexDeclaration>\n\nvoid main() {\n\n #include <begin_position_vert>\n #include <begin_normal_vert>\n #include <blendShape_vert>\n #include <skinning_vert>\n #include <uv_vert>\n #include <color_vert>\n #include <normal_vert>\n #include <worldpos_vert>\n #include <position_vert>\n\n #include <ShadowVertex>\n #include <FogVertex>\n}\n"; // eslint-disable-line
24038
+
24039
+ var shadowMapFs = "#define GLSLIFY 1\n#ifdef ENGINE_NO_DEPTH_TEXTURE\n /**\n * Decompose and save depth value.\n */\n vec4 pack (float depth) {\n // Use rgba 4 bytes with a total of 32 bits to store the z value, and the accuracy of 1 byte is 1/256.\n const vec4 bitShift = vec4(1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0);\n const vec4 bitMask = vec4(1.0/256.0, 1.0/256.0, 1.0/256.0, 0.0);\n\n vec4 rgbaDepth = fract(depth * bitShift); // Calculate the z value of each point\n\n // Cut off the value which do not fit in 8 bits\n rgbaDepth -= rgbaDepth.gbaa * bitMask;\n\n return rgbaDepth;\n }\n#endif\n\nuniform vec4 material_BaseColor;\nuniform sampler2D material_BaseTexture;\nuniform float material_AlphaCutoff;\nvarying vec2 v_uv;\n\nvoid main() {\n #if defined(MATERIAL_IS_ALPHA_CUTOFF) || (defined(SCENE_ENABLE_TRANSPARENT_SHADOW) && defined(MATERIAL_IS_TRANSPARENT))\n float alpha = material_BaseColor.a;\n #ifdef MATERIAL_HAS_BASETEXTURE\n alpha *= texture2D(material_BaseTexture, v_uv).a;\n #endif\n \n #ifdef MATERIAL_IS_ALPHA_CUTOFF\n if(alpha < material_AlphaCutoff){\n discard;\n }\n #endif\n \n #if defined(SCENE_ENABLE_TRANSPARENT_SHADOW) && defined(MATERIAL_IS_TRANSPARENT)\n // Interleaved gradient noise\n float noise = fract(52.982919 * fract(dot(vec2(0.06711, 0.00584), gl_FragCoord.xy)));\n if (alpha <= noise) {\n discard;\n };\n #endif\n #endif\n\n #ifdef ENGINE_NO_DEPTH_TEXTURE\n gl_FragColor = pack(gl_FragCoord.z);\n #else\n gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n #endif\n}"; // eslint-disable-line
24040
+
24041
+ var shadowMapVs = "#define GLSLIFY 1\n#include <common>\n#include <common_vert>\n#include <blendShape_input>\n#include <normal_share>\n#include <uv_share>\nuniform mat4 camera_VPMat;\nuniform vec2 scene_ShadowBias; // x: depth bias, y: normal bias\nuniform vec3 scene_LightDirection;\n\nvec3 applyShadowBias(vec3 positionWS) {\n positionWS -= scene_LightDirection * scene_ShadowBias.x;\n return positionWS;\n}\n\nvec3 applyShadowNormalBias(vec3 positionWS, vec3 normalWS) {\n float invNdotL = 1.0 - clamp(dot(-scene_LightDirection, normalWS), 0.0, 1.0);\n float scale = invNdotL * scene_ShadowBias.y;\n positionWS += normalWS * vec3(scale);\n return positionWS;\n}\n\nvoid main() {\n\n #include <begin_position_vert>\n #include <begin_normal_vert>\n #include <blendShape_vert>\n #include <skinning_vert>\n #include <uv_vert>\n \n vec4 positionWS = renderer_ModelMat * position;\n\n positionWS.xyz = applyShadowBias(positionWS.xyz);\n #ifndef MATERIAL_OMIT_NORMAL\n #ifdef RENDERER_HAS_NORMAL\n vec3 normalWS = normalize( mat3(renderer_NormalMat) * normal );\n positionWS.xyz = applyShadowNormalBias(positionWS.xyz, normalWS);\n #endif\n #endif\n\n vec4 positionCS = camera_VPMat * positionWS;\n positionCS.z = max(positionCS.z, -1.0);// clamp to min ndc z\n\n gl_Position = positionCS;\n\n}\n"; // eslint-disable-line
24042
+
24043
+ var skyboxFs = "#define GLSLIFY 1\n#include <common>\nuniform samplerCube material_CubeTexture;\n\nvarying vec3 v_cubeUV;\nuniform float material_Exposure;\nuniform vec4 material_TintColor;\n\nvoid main() {\n vec4 textureColor = textureCube( material_CubeTexture, v_cubeUV );\n\n #ifdef MATERIAL_IS_DECODE_SKY_RGBM\n textureColor = RGBMToLinear(textureColor, 5.0);\n #elif !defined(ENGINE_IS_COLORSPACE_GAMMA)\n textureColor = gammaToLinear(textureColor);\n #endif\n\n textureColor.rgb *= material_Exposure * material_TintColor.rgb;\n \n gl_FragColor = textureColor;\n\n #if defined(MATERIAL_IS_DECODE_SKY_RGBM) || !defined(ENGINE_IS_COLORSPACE_GAMMA)\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}\n"; // eslint-disable-line
24044
+
24045
+ var skyboxVs = "#define GLSLIFY 1\n#include <common_vert>\n\nuniform mat4 camera_VPMat;\n\nvarying vec3 v_cubeUV;\nuniform float material_Rotation;\n\nvec4 rotateY(vec4 v, float angle) {\n\tconst float deg2rad = 3.1415926 / 180.0;\n\tfloat radian = angle * deg2rad;\n\tfloat sina = sin(radian);\n\tfloat cosa = cos(radian);\n\tmat2 m = mat2(cosa, -sina, sina, cosa);\n\treturn vec4(m * v.xz, v.yw).xzyw;\n}\n\nvoid main() {\n v_cubeUV = vec3( -POSITION.x, POSITION.yz ); // TextureCube is left-hand,so x need inverse\n gl_Position = camera_VPMat * rotateY(vec4(POSITION, 1.0), material_Rotation);\n}\n"; // eslint-disable-line
24046
+
24047
+ var spriteMaskFs = "#define GLSLIFY 1\nuniform sampler2D renderer_MaskTexture;\nuniform float renderer_MaskAlphaCutoff;\nvarying vec2 v_uv;\n\nvoid main()\n{\n vec4 color = texture2D(renderer_MaskTexture, v_uv);\n if (color.a < renderer_MaskAlphaCutoff) {\n discard;\n }\n\n gl_FragColor = color;\n}\n"; // eslint-disable-line
24048
+
24049
+ var spriteMaskVs = "#define GLSLIFY 1\nuniform mat4 camera_VPMat;\n\nattribute vec3 POSITION;\nattribute vec2 TEXCOORD_0;\n\nvarying vec2 v_uv;\n\nvoid main()\n{\n gl_Position = camera_VPMat * vec4(POSITION, 1.0);\n v_uv = TEXCOORD_0;\n}\n"; // eslint-disable-line
24050
+
24051
+ var spriteFs = "#define GLSLIFY 1\nuniform sampler2D renderer_SpriteTexture;\n\nvarying vec2 v_uv;\nvarying vec4 v_color;\n\nvoid main()\n{\n vec4 baseColor = texture2D(renderer_SpriteTexture, v_uv);\n gl_FragColor = baseColor * v_color;\n}\n"; // eslint-disable-line
24052
+
24053
+ var spriteVs = "#define GLSLIFY 1\nuniform mat4 renderer_MVPMat;\n\nattribute vec3 POSITION;\nattribute vec2 TEXCOORD_0;\nattribute vec4 COLOR_0;\n\nvarying vec2 v_uv;\nvarying vec4 v_color;\n\nvoid main()\n{\n gl_Position = renderer_MVPMat * vec4(POSITION, 1.0);\n\n v_uv = TEXCOORD_0;\n v_color = COLOR_0;\n}\n"; // eslint-disable-line
24054
+
24055
+ var textFs = "#define GLSLIFY 1\nuniform sampler2D renderElement_TextTexture;\n\nvarying vec2 v_uv;\nvarying vec4 v_color;\n\nvoid main()\n{\n vec4 baseColor = texture2D(renderElement_TextTexture, v_uv);\n gl_FragColor = baseColor * v_color;\n}\n"; // eslint-disable-line
24056
+
24057
+ var textVs = "#define GLSLIFY 1\nuniform mat4 renderer_MVPMat;\n\nattribute vec3 POSITION;\nattribute vec2 TEXCOORD_0;\nattribute vec4 COLOR_0;\n\nvarying vec2 v_uv;\nvarying vec4 v_color;\n\nvoid main()\n{\n gl_Position = renderer_MVPMat * vec4(POSITION, 1.0);\n\n v_uv = TEXCOORD_0;\n v_color = COLOR_0;\n}\n"; // eslint-disable-line
24058
+
24059
+ var unlitFs = "#define GLSLIFY 1\n#include <common>\n#include <uv_share>\n#include <FogFragmentDeclaration>\n\nuniform vec4 material_BaseColor;\nuniform float material_AlphaCutoff;\n\n#ifdef MATERIAL_HAS_BASETEXTURE\n uniform sampler2D material_BaseTexture;\n#endif\n\nvoid main() {\n vec4 baseColor = material_BaseColor;\n\n #ifdef MATERIAL_HAS_BASETEXTURE\n vec4 textureColor = texture2D(material_BaseTexture, v_uv);\n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n textureColor = gammaToLinear(textureColor);\n #endif\n baseColor *= textureColor;\n #endif\n\n #ifdef MATERIAL_IS_ALPHA_CUTOFF\n if( baseColor.a < material_AlphaCutoff ) {\n discard;\n }\n #endif\n\n gl_FragColor = baseColor;\n\n #ifndef MATERIAL_IS_TRANSPARENT\n gl_FragColor.a = 1.0;\n #endif\n\n #include <FogFragment>\n\n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}\n"; // eslint-disable-line
24060
+
24061
+ var unlitVs = "#define GLSLIFY 1\n#include <common>\n#include <common_vert>\n#include <blendShape_input>\n#include <uv_share>\n#include <FogVertexDeclaration>\n\nvoid main() {\n\n #include <begin_position_vert>\n #include <blendShape_vert>\n #include <skinning_vert>\n #include <uv_vert>\n #include <position_vert>\n\n #include <FogVertex>\n}\n"; // eslint-disable-line
24062
+
24063
+ /**
24064
+ * Internal shader pool.
24065
+ * @internal
24066
+ */ var ShaderPool = /*#__PURE__*/ function() {
24067
+ function ShaderPool() {}
24068
+ ShaderPool.init = function init() {
24069
+ var shadowCasterPass = new ShaderPass("ShadowCaster", shadowMapVs, shadowMapFs, {
24070
+ pipelineStage: PipelineStage.ShadowCaster
24071
+ });
24072
+ shadowCasterPass._renderState = new RenderState();
24073
+ shadowCasterPass._renderStateDataMap[RenderStateElementKey.RenderQueueType] = BaseMaterial._shadowCasterRenderQueueProp;
24074
+ var depthOnlyPass = new ShaderPass("DepthOnly", depthOnlyVs, depthOnlyFs, {
24075
+ pipelineStage: PipelineStage.DepthOnly
24076
+ });
24077
+ var basePasses = [
24078
+ shadowCasterPass,
24079
+ depthOnlyPass
24080
+ ];
24081
+ var forwardPassTags = {
24082
+ pipelineStage: PipelineStage.Forward
24083
+ };
24084
+ Shader.create("blinn-phong", [].concat([
24085
+ new ShaderPass("Forward", blinnPhongVs, blinnPhongFs, forwardPassTags)
24086
+ ], basePasses));
24087
+ Shader.create("pbr", [].concat([
24088
+ new ShaderPass("Forward", pbrVs, pbrFs, forwardPassTags)
24089
+ ], basePasses));
24090
+ Shader.create("pbr-specular", [].concat([
24091
+ new ShaderPass("Forward", pbrVs, pbrSpecularFs, forwardPassTags)
24092
+ ], basePasses));
24093
+ Shader.create("unlit", [].concat([
24094
+ new ShaderPass("Forward", unlitVs, unlitFs, forwardPassTags)
24095
+ ], basePasses));
24096
+ Shader.create("blit", [
24097
+ new ShaderPass("Forward", blitVs, blitFs, forwardPassTags)
24098
+ ]);
24099
+ Shader.create("skybox", [
24100
+ new ShaderPass("Forward", skyboxVs, skyboxFs, forwardPassTags)
24101
+ ]);
24102
+ Shader.create("SkyProcedural", [
24103
+ new ShaderPass("Forward", skyProceduralVs, skyProceduralFs, forwardPassTags)
24104
+ ]);
24105
+ Shader.create("particle-shader", [
24106
+ new ShaderPass("Forward", particleVs, particleFs, forwardPassTags)
24107
+ ]);
24108
+ Shader.create("SpriteMask", [
24109
+ new ShaderPass("Forward", spriteMaskVs, spriteMaskFs, forwardPassTags)
24110
+ ]);
24111
+ Shader.create("Sprite", [
24112
+ new ShaderPass("Forward", spriteVs, spriteFs, forwardPassTags)
24113
+ ]);
24114
+ Shader.create("Text", [
24115
+ new ShaderPass("Forward", textVs, textFs, forwardPassTags)
24116
+ ]);
24117
+ Shader.create("background-texture", [
24118
+ new ShaderPass("Forward", backgroundTextureVs, backgroundTextureFs, forwardPassTags)
24119
+ ]);
24120
+ };
24121
+ return ShaderPool;
24122
+ }();
24123
+
24124
+ /**
24125
+ * Shader program pool.
24126
+ * @internal
24127
+ */ var ShaderProgramPool = /*#__PURE__*/ function() {
24128
+ function ShaderProgramPool(engine) {
24129
+ this.engine = engine;
24130
+ this._cacheHierarchyDepth = 1;
24131
+ this._cacheMap = Object.create(null);
24132
+ }
24133
+ var _proto = ShaderProgramPool.prototype;
24134
+ /**
24135
+ * Get shader program by macro collection.
24136
+ * @param macros - macro collection
24137
+ * @returns shader program
24138
+ */ _proto.get = function get(macros) {
24139
+ var cacheMap = this._cacheMap;
24140
+ var maskLength = macros._length;
24141
+ var cacheHierarchyDepth = this._cacheHierarchyDepth;
24142
+ if (maskLength > cacheHierarchyDepth) {
24143
+ this._resizeCacheMapHierarchy(cacheMap, 0, cacheHierarchyDepth, maskLength - cacheHierarchyDepth);
24144
+ this._cacheHierarchyDepth = maskLength;
24145
+ }
24146
+ var mask = macros._mask;
24147
+ var endIndex = macros._length - 1;
24148
+ var maxEndIndex = this._cacheHierarchyDepth - 1;
24149
+ for(var i = 0; i < maxEndIndex; i++){
24150
+ var subMask = endIndex < i ? 0 : mask[i];
24151
+ var subCacheShaders = cacheMap[subMask];
24152
+ subCacheShaders || (cacheMap[subMask] = subCacheShaders = Object.create(null));
24153
+ cacheMap = subCacheShaders;
24154
+ }
24155
+ var cacheKey = endIndex < maxEndIndex ? 0 : mask[maxEndIndex];
24156
+ var shader = cacheMap[cacheKey];
24157
+ if (!shader) {
24158
+ this._lastQueryKey = cacheKey;
24159
+ this._lastQueryMap = cacheMap;
24160
+ }
24161
+ return shader;
24162
+ };
24163
+ /**
24164
+ * Cache the shader program.
24165
+ *
24166
+ * @remarks
24167
+ * The method must return an empty value after calling get() to run normally.
24168
+ *
24169
+ * @param shaderProgram - shader program
24170
+ */ _proto.cache = function cache(shaderProgram) {
24171
+ this._lastQueryMap[this._lastQueryKey] = shaderProgram;
24172
+ };
24173
+ /**
24174
+ * @internal
24175
+ */ _proto._destroy = function _destroy() {
24176
+ this._recursiveDestroy(0, this._cacheMap);
24177
+ this._cacheMap = Object.create(null);
24178
+ };
24179
+ _proto._recursiveDestroy = function _recursiveDestroy(hierarchy, cacheMap) {
24180
+ if (hierarchy === this._cacheHierarchyDepth - 1) {
24181
+ for(var k in cacheMap){
24182
+ cacheMap[k].destroy();
24183
+ }
24184
+ return;
24185
+ }
24186
+ ++hierarchy;
24187
+ for(var k1 in cacheMap){
24188
+ this._recursiveDestroy(hierarchy, cacheMap[k1]);
24189
+ }
24190
+ };
24191
+ _proto._resizeCacheMapHierarchy = function _resizeCacheMapHierarchy(cacheMap, hierarchy, currentHierarchy, increaseHierarchy) {
24192
+ // Only expand but not shrink
24193
+ if (hierarchy == currentHierarchy - 1) {
24194
+ for(var k in cacheMap){
24195
+ var shader = cacheMap[k];
24196
+ var subCacheMap = cacheMap;
24197
+ for(var i = 0; i < increaseHierarchy; i++){
24198
+ subCacheMap[i == 0 ? k : 0] = subCacheMap = Object.create(null);
24199
+ }
24200
+ subCacheMap[0] = shader;
24201
+ }
24202
+ } else {
24203
+ hierarchy++;
24204
+ for(var k1 in cacheMap){
24205
+ this._resizeCacheMapHierarchy(cacheMap[k1], hierarchy, currentHierarchy, increaseHierarchy);
24206
+ }
24207
+ }
24208
+ };
24209
+ return ShaderProgramPool;
24210
+ }();
24211
+
24212
+ /**
24213
+ * Clearable Object Pool.
24214
+ */ var ClearableObjectPool = /*#__PURE__*/ function(ObjectPool) {
24215
+ _inherits(ClearableObjectPool, ObjectPool);
24216
+ function ClearableObjectPool(type) {
24217
+ var _this;
24218
+ _this = ObjectPool.call(this, type) || this, _this._usedElementCount = 0;
24219
+ _this._elements = [];
23397
24220
  return _this;
23398
24221
  }
23399
24222
  var _proto = ClearableObjectPool.prototype;
@@ -23457,7 +24280,7 @@ ShaderPool.init();
23457
24280
  _inherits(Engine, EventDispatcher);
23458
24281
  function Engine(canvas, hardwareRenderer, configuration) {
23459
24282
  var _this;
23460
- _this = EventDispatcher.call(this) || this, /** @internal */ _this._physicsInitialized = false, /* @internal */ _this._lastRenderState = new RenderState(), /* @internal */ _this._renderElementPool = new ClearableObjectPool(RenderElement), /* @internal */ _this._subRenderElementPool = new ClearableObjectPool(SubRenderElement), /* @internal */ _this._textSubRenderElementPool = new ClearableObjectPool(SubRenderElement), /* @internal */ _this._charRenderInfoPool = new ReturnableObjectPool(CharRenderInfo, 50), /* @internal */ _this._renderContext = new RenderContext(), /* @internal */ _this._renderCount = 0, /* @internal */ _this._shaderProgramPools = [], /** @internal */ _this._fontMap = {}, /** @internal @todo: temporary solution */ _this._macroCollection = new ShaderMacroCollection(), _this._settings = {}, _this._resourceManager = new ResourceManager(_this), _this._sceneManager = new SceneManager(_this), _this._vSyncCount = 1, _this._targetFrameRate = 60, _this._time = new Time(), _this._isPaused = true, _this._vSyncCounter = 1, _this._targetFrameInterval = 1000 / 60, _this._destroyed = false, _this._frameInProcess = false, _this._waitingDestroy = false, _this._isDeviceLost = false, _this._waitingGC = false, _this._animate = function() {
24283
+ _this = EventDispatcher.call(this) || this, /** @internal */ _this._physicsInitialized = false, /* @internal */ _this._lastRenderState = new RenderState(), /* @internal */ _this._renderElementPool = new ClearableObjectPool(RenderElement), /* @internal */ _this._subRenderElementPool = new ClearableObjectPool(SubRenderElement), /* @internal */ _this._textSubRenderElementPool = new ClearableObjectPool(SubRenderElement), /* @internal */ _this._charRenderInfoPool = new ReturnableObjectPool(CharRenderInfo, 50), /* @internal */ _this._renderContext = new RenderContext(), /* @internal */ _this._renderCount = 0, /* @internal */ _this._shaderProgramPools = [], /** @internal */ _this._fontMap = {}, /** @internal @todo: temporary solution */ _this._macroCollection = new ShaderMacroCollection(), /** @internal */ _this._postProcessPassNeedRefresh = false, _this._settings = {}, _this._resourceManager = new ResourceManager(_this), _this._sceneManager = new SceneManager(_this), _this._vSyncCount = 1, _this._targetFrameRate = 60, _this._time = new Time(), _this._isPaused = true, _this._vSyncCounter = 1, _this._targetFrameInterval = 1000 / 60, _this._destroyed = false, _this._frameInProcess = false, _this._waitingDestroy = false, _this._isDeviceLost = false, _this._waitingGC = false, _this._postProcessPasses = new Array(), _this._activePostProcessPasses = new Array(), _this._animate = function() {
23461
24284
  if (_this._vSyncCount) {
23462
24285
  var _this_xrManager;
23463
24286
  var raf = ((_this_xrManager = _this.xrManager) == null ? void 0 : _this_xrManager._getRequestAnimationFrame()) || requestAnimationFrame;
@@ -23504,6 +24327,8 @@ ShaderPool.init();
23504
24327
  innerSettings.colorSpace = colorSpace;
23505
24328
  _this._basicResources = new BasicResources(_this);
23506
24329
  _this._particleBufferUtils = new ParticleBufferUtils(_this);
24330
+ var uberPass = new PostProcessUberPass(_this);
24331
+ _this.addPostProcessPass(uberPass);
23507
24332
  return _this;
23508
24333
  }
23509
24334
  var _proto = Engine.prototype;
@@ -23551,6 +24376,7 @@ ShaderPool.init();
23551
24376
  (_this_xrManager = this.xrManager) == null ? void 0 : _this_xrManager._update();
23552
24377
  var _this = this, inputManager = _this.inputManager, physicsInitialized = _this._physicsInitialized;
23553
24378
  inputManager._update();
24379
+ this._refreshActivePostProcessPasses();
23554
24380
  var scenes = this._sceneManager._scenes.getLoopArray();
23555
24381
  var sceneCount = scenes.length;
23556
24382
  // Sort cameras and fire script `onStart`
@@ -23627,6 +24453,58 @@ ShaderPool.init();
23627
24453
  */ _proto.forceRestoreDevice = function forceRestoreDevice() {
23628
24454
  this._hardwareRenderer.forceRestoreDevice();
23629
24455
  };
24456
+ /**
24457
+ * Add a post process pass.
24458
+ * @param pass - Post process pass to add
24459
+ */ _proto.addPostProcessPass = function addPostProcessPass(pass) {
24460
+ if (pass.engine !== this) {
24461
+ throw "The pass is not belong to this engine.";
24462
+ }
24463
+ var passes = this._postProcessPasses;
24464
+ if (passes.indexOf(pass) === -1) {
24465
+ passes.push(pass);
24466
+ pass.isActive && (this._postProcessPassNeedRefresh = true);
24467
+ }
24468
+ };
24469
+ /**
24470
+ * @internal
24471
+ */ _proto._removePostProcessPass = function _removePostProcessPass(pass) {
24472
+ var passes = this._postProcessPasses;
24473
+ var index = passes.indexOf(pass);
24474
+ if (index !== -1) {
24475
+ passes.splice(index, 1);
24476
+ pass.isActive && (this._postProcessPassNeedRefresh = true);
24477
+ }
24478
+ };
24479
+ /**
24480
+ * @internal
24481
+ */ _proto._refreshActivePostProcessPasses = function _refreshActivePostProcessPasses() {
24482
+ if (this._postProcessPassNeedRefresh) {
24483
+ this._postProcessPassNeedRefresh = false;
24484
+ var postProcessPasses = this._postProcessPasses;
24485
+ var activePostProcesses = this._activePostProcessPasses;
24486
+ activePostProcesses.length = 0;
24487
+ // Filter
24488
+ for(var i = 0, n = postProcessPasses.length; i < n; i++){
24489
+ var pass = postProcessPasses[i];
24490
+ if (pass.isActive) {
24491
+ activePostProcesses.push(pass);
24492
+ }
24493
+ }
24494
+ // Sort
24495
+ if (activePostProcesses.length) {
24496
+ activePostProcesses.sort(function(a, b) {
24497
+ return a.event - b.event;
24498
+ });
24499
+ }
24500
+ }
24501
+ };
24502
+ /**
24503
+ * @internal
24504
+ */ _proto._getActivePostProcessPasses = function _getActivePostProcessPasses() {
24505
+ this._refreshActivePostProcessPasses();
24506
+ return this._activePostProcessPasses;
24507
+ };
23630
24508
  _proto._destroy = function _destroy() {
23631
24509
  var _this_xrManager;
23632
24510
  this._sceneManager._destroyAllScene();
@@ -23692,6 +24570,8 @@ ShaderPool.init();
23692
24570
  cameras.forEach(function(camera) {
23693
24571
  var componentsManager = scene._componentsManager;
23694
24572
  componentsManager.callCameraOnBeginRender(camera);
24573
+ // Update post process manager
24574
+ scene.postProcessManager._update(camera);
23695
24575
  camera.render();
23696
24576
  componentsManager.callCameraOnEndRender(camera);
23697
24577
  // Temp solution for webgl implement bug
@@ -23858,6 +24738,14 @@ ShaderPool.init();
23858
24738
  this._targetFrameInterval = 1000 / value;
23859
24739
  }
23860
24740
  },
24741
+ {
24742
+ key: "postProcessPasses",
24743
+ get: /**
24744
+ * All post process passes.
24745
+ */ function get() {
24746
+ return this._postProcessPasses;
24747
+ }
24748
+ },
23861
24749
  {
23862
24750
  key: "destroyed",
23863
24751
  get: /**
@@ -25232,462 +26120,325 @@ SpotLight._penumbraCosProperty = ShaderProperty.getByName("scene_SpotLightPenumb
25232
26120
  maxIntensity = intensity;
25233
26121
  sunlight = currentLight;
25234
26122
  }
25235
- }
25236
- }
25237
- return sunlight;
25238
- };
25239
- return LightManager;
25240
- }();
25241
- /** @internal */ LightManager._sunlightColorProperty = ShaderProperty.getByName("scene_SunlightColor");
25242
- /** @internal */ LightManager._sunlightDirectionProperty = ShaderProperty.getByName("scene_SunlightDirection");
25243
- /**
25244
- * Each type of light source is at most 10, beyond which it will not take effect.
25245
- * */ LightManager._maxLight = 10;
25246
-
25247
- 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
25248
-
25249
- 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
25250
-
25251
- 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
25252
-
25253
- 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
25254
-
25255
- /**
25256
- * This controls the size of the bloom texture.
25257
- */ var BloomDownScaleMode = /*#__PURE__*/ function(BloomDownScaleMode) {
25258
- /**
25259
- * Use this to select half size as the starting resolution.
25260
- */ BloomDownScaleMode[BloomDownScaleMode["Half"] = 0] = "Half";
25261
- /**
25262
- * Use this to select quarter size as the starting resolution.
25263
- */ BloomDownScaleMode[BloomDownScaleMode["Quarter"] = 1] = "Quarter";
25264
- return BloomDownScaleMode;
25265
- }({});
25266
- var BloomEffect = /*#__PURE__*/ function() {
25267
- function BloomEffect(_uberMaterial) {
25268
- this._uberMaterial = _uberMaterial;
25269
- this._highQualityFiltering = false;
25270
- this._mipDownRT = [];
25271
- this._mipUpRT = [];
25272
- this._maxIterations = 6;
25273
- this._enabled = false;
25274
- this./**
25275
- * Controls the starting resolution that this effect begins processing.
25276
- */ downScale = 0;
25277
- var engine = _uberMaterial.engine;
25278
- var material = new Material(engine, Shader.find(BloomEffect.SHADER_NAME));
25279
- var depthState = material.renderState.depthState;
25280
- depthState.enabled = false;
25281
- depthState.writeEnabled = false;
25282
- var bloomShaderData = material.shaderData;
25283
- var uberShaderData = _uberMaterial.shaderData;
25284
- bloomShaderData.setVector4(BloomEffect._bloomParams, new engineMath.Vector4());
25285
- bloomShaderData.setVector4(BloomEffect._lowMipTexelSizeProp, new engineMath.Vector4());
25286
- uberShaderData.setVector4(BloomEffect._bloomIntensityParams, new engineMath.Vector4(1, 1, 0, 0));
25287
- uberShaderData.setVector4(BloomEffect._dirtTilingOffsetProp, new engineMath.Vector4());
25288
- uberShaderData.setColor(BloomEffect._tintProp, new engineMath.Color(1, 1, 1, 1));
25289
- this._bloomMaterial = material;
25290
- this.threshold = 0.9;
25291
- this.scatter = 0.7;
25292
- this.intensity = 1;
25293
- this.dirtIntensity = 1;
25294
- }
25295
- var _proto = BloomEffect.prototype;
25296
- _proto.onRender = function onRender(context, srcTexture) {
25297
- var camera = context.camera;
25298
- var downRes = this.downScale === 0 ? 1 : 2;
25299
- var pixelViewport = camera.pixelViewport;
25300
- var tw = pixelViewport.width >> downRes;
25301
- var th = pixelViewport.height >> downRes;
25302
- // Determine the iteration count
25303
- var mipCount = this._calculateMipCount(tw, th);
25304
- // Prefilter
25305
- this._prefilter(camera, srcTexture, tw, th, mipCount);
25306
- // Down sample - gaussian pyramid
25307
- this._downsample(mipCount);
25308
- // Up sample (bilinear by default, HQ filtering does bicubic instead
25309
- this._upsample(mipCount);
25310
- // Setup bloom on uber
25311
- this._setupUber(camera);
25312
- };
25313
- _proto._calculateMipCount = function _calculateMipCount(tw, th) {
25314
- var maxSize = Math.max(tw, th);
25315
- var iterations = Math.floor(Math.log2(maxSize) - 1);
25316
- return Math.min(Math.max(iterations, 1), this._maxIterations);
25317
- };
25318
- _proto._prefilter = function _prefilter(camera, srcTexture, tw, th, mipCount) {
25319
- var engine = this._uberMaterial.engine;
25320
- var internalColorTextureFormat = camera._getInternalColorTextureFormat();
25321
- var mipWidth = tw, mipHeight = th;
25322
- for(var i = 0; i < mipCount; i++){
25323
- this._mipUpRT[i] = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._mipUpRT[i], mipWidth, mipHeight, internalColorTextureFormat, null, false, false, 1, TextureWrapMode.Clamp, TextureFilterMode.Bilinear);
25324
- this._mipDownRT[i] = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._mipDownRT[i], mipWidth, mipHeight, internalColorTextureFormat, null, false, false, 1, TextureWrapMode.Clamp, TextureFilterMode.Bilinear);
25325
- mipWidth = Math.max(1, Math.floor(mipWidth / 2));
25326
- mipHeight = Math.max(1, Math.floor(mipHeight / 2));
25327
- }
25328
- PipelineUtils.blitTexture(engine, srcTexture, this._mipDownRT[0], undefined, undefined, this._bloomMaterial, 0);
25329
- };
25330
- _proto._downsample = function _downsample(mipCount) {
25331
- var material = this._bloomMaterial;
25332
- var engine = material.engine;
25333
- var lastDown = this._mipDownRT[0];
25334
- // Down sample - gaussian pyramid
25335
- for(var i = 1; i < mipCount; i++){
25336
- // Classic two pass gaussian blur - use mipUp as a temporary target
25337
- // First pass does 2x downsampling + 9-tap gaussian
25338
- // Second pass does 9-tap gaussian using a 5-tap filter + bilinear filtering
25339
- PipelineUtils.blitTexture(engine, lastDown.getColorTexture(0), this._mipUpRT[i], undefined, undefined, material, 1);
25340
- PipelineUtils.blitTexture(engine, this._mipUpRT[i].getColorTexture(0), this._mipDownRT[i], undefined, undefined, material, 2);
25341
- lastDown = this._mipDownRT[i];
26123
+ }
25342
26124
  }
26125
+ return sunlight;
25343
26126
  };
25344
- _proto._upsample = function _upsample(mipCount) {
25345
- var material = this._bloomMaterial;
25346
- var engine = material.engine;
25347
- var shaderData = material.shaderData;
25348
- // Up sample (bilinear by default, HQ filtering does bicubic instead
25349
- for(var i = mipCount - 2; i >= 0; i--){
25350
- var lowMip = i == mipCount - 2 ? this._mipDownRT[i + 1] : this._mipUpRT[i + 1];
25351
- var highMip = this._mipDownRT[i];
25352
- var dst = this._mipUpRT[i];
25353
- shaderData.setTexture(BloomEffect._lowMipTextureProp, lowMip.getColorTexture(0));
25354
- if (this.highQualityFiltering) {
25355
- var texelSizeLow = shaderData.getVector4(BloomEffect._lowMipTexelSizeProp);
25356
- texelSizeLow.set(1 / lowMip.width, 1 / lowMip.height, lowMip.width, lowMip.height);
26127
+ return LightManager;
26128
+ }();
26129
+ /** @internal */ LightManager._sunlightColorProperty = ShaderProperty.getByName("scene_SunlightColor");
26130
+ /** @internal */ LightManager._sunlightDirectionProperty = ShaderProperty.getByName("scene_SunlightDirection");
26131
+ /**
26132
+ * Each type of light source is at most 10, beyond which it will not take effect.
26133
+ * */ LightManager._maxLight = 10;
26134
+
26135
+ /**
26136
+ * Post Process component can be used for global or local post-processing.
26137
+ */ var PostProcess = /*#__PURE__*/ function(Component) {
26138
+ _inherits(PostProcess, Component);
26139
+ function PostProcess() {
26140
+ var _this;
26141
+ _this = Component.apply(this, arguments) || this, /**
26142
+ * The layer to which the PostProcess belongs.
26143
+ */ _this.layer = Layer.Layer0, /**
26144
+ * The outer distance to start blending from, only takes effect when the `isGlobal` is false.
26145
+ */ _this.blendDistance = 0, /** @internal */ _this._effects = [], _this._priority = 0, _this._isGlobal = true;
26146
+ return _this;
26147
+ }
26148
+ var _proto = PostProcess.prototype;
26149
+ /**
26150
+ * Get the PostProcessEffect by type.
26151
+ * @param type - The type of PostProcessEffect
26152
+ * @returns The PostProcessEffect found
26153
+ */ _proto.getEffect = function getEffect(type) {
26154
+ var effects = this._effects;
26155
+ var length = effects.length;
26156
+ for(var i = 0; i < length; i++){
26157
+ var effect = effects[i];
26158
+ if (_instanceof(effect, type)) {
26159
+ return effect;
25357
26160
  }
25358
- PipelineUtils.blitTexture(engine, highMip.getColorTexture(0), dst, undefined, undefined, material, 3);
25359
26161
  }
25360
26162
  };
25361
- _proto._setupUber = function _setupUber(camera) {
25362
- var shaderData = this._uberMaterial.shaderData;
25363
- var dirtTexture = this.dirtTexture;
25364
- if (dirtTexture) {
25365
- var dirtTilingOffset = shaderData.getVector4(BloomEffect._dirtTilingOffsetProp);
25366
- var dirtRatio = dirtTexture.width / dirtTexture.height;
25367
- var screenRatio = camera.aspectRatio;
25368
- if (dirtRatio > screenRatio) {
25369
- dirtTilingOffset.set(screenRatio / dirtRatio, 1, (1 - dirtTilingOffset.x) * 0.5, 0);
25370
- } else if (dirtRatio < screenRatio) {
25371
- dirtTilingOffset.set(1, dirtRatio / screenRatio, 0, (1 - dirtTilingOffset.y) * 0.5);
25372
- } else {
25373
- dirtTilingOffset.set(1, 1, 0, 0);
25374
- }
26163
+ /**
26164
+ * Add a PostProcessEffect to the PostProcess.
26165
+ * @remarks Only one effect of the same type can be added to the PostProcess.
26166
+ * @param type - The type of PostProcessEffect
26167
+ * @returns The PostProcessEffect added
26168
+ */ _proto.addEffect = function addEffect(type) {
26169
+ if (this.getEffect(type)) {
26170
+ Logger.error('effect "' + type.name + '" already exists in the PostProcess.');
26171
+ return;
25375
26172
  }
25376
- shaderData.setTexture(BloomEffect._bloomTextureProp, this._mipUpRT[0].getColorTexture(0));
26173
+ var effect = new type();
26174
+ this._effects.push(effect);
26175
+ return effect;
25377
26176
  };
25378
- _proto._releaseRenderTargets = function _releaseRenderTargets() {
25379
- var length = this._mipDownRT.length;
26177
+ /**
26178
+ * Remove a PostProcessEffect from the PostProcess.
26179
+ * @param type - The type of PostProcessEffect
26180
+ * @returns The PostProcessEffect removed
26181
+ */ _proto.removeEffect = function removeEffect(type) {
26182
+ var effects = this._effects;
26183
+ var length = effects.length;
25380
26184
  for(var i = 0; i < length; i++){
25381
- var downRT = this._mipDownRT[i];
25382
- var upRT = this._mipUpRT[i];
25383
- if (downRT) {
25384
- downRT.getColorTexture(0).destroy(true);
25385
- downRT.destroy(true);
25386
- }
25387
- if (upRT) {
25388
- upRT.getColorTexture(0).destroy(true);
25389
- upRT.destroy(true);
26185
+ var effect = effects[i];
26186
+ if (_instanceof(effect, type)) {
26187
+ effects.splice(i, 1);
26188
+ return effect;
25390
26189
  }
25391
26190
  }
25392
- this._mipDownRT.length = 0;
25393
- this._mipUpRT.length = 0;
25394
26191
  };
25395
- _create_class(BloomEffect, [
25396
- {
25397
- key: "enabled",
25398
- get: /**
25399
- * Indicates whether the post process effect is enabled.
25400
- */ function get() {
25401
- return this._enabled;
25402
- },
25403
- set: function set(value) {
25404
- if (value !== this._enabled) {
25405
- this._enabled = value;
25406
- if (value) {
25407
- this._uberMaterial.shaderData.enableMacro(BloomEffect._enableMacro);
25408
- } else {
25409
- this._uberMaterial.shaderData.disableMacro(BloomEffect._enableMacro);
25410
- this._releaseRenderTargets();
25411
- }
25412
- }
25413
- }
25414
- },
25415
- {
25416
- key: "threshold",
25417
- get: /**
25418
- * Set the level of brightness to filter out pixels under this level.
25419
- * @remarks This value is expressed in gamma-space.
25420
- */ function get() {
25421
- return this._threshold;
25422
- },
25423
- set: function set(value) {
25424
- value = Math.max(0, value);
25425
- if (value !== this._threshold) {
25426
- this._threshold = value;
25427
- var threshold = engineMath.Color.gammaToLinearSpace(value);
25428
- var thresholdKnee = threshold * 0.5; // Hardcoded soft knee
25429
- var params = this._bloomMaterial.shaderData.getVector4(BloomEffect._bloomParams);
25430
- params.x = threshold;
25431
- params.y = thresholdKnee;
25432
- }
25433
- }
25434
- },
25435
- {
25436
- key: "scatter",
25437
- get: /**
25438
- * Controls the radius of the bloom effect.
25439
- */ function get() {
25440
- return this._scatter;
25441
- },
25442
- set: function set(value) {
25443
- value = engineMath.MathUtil.clamp(value, 0, 1);
25444
- if (value !== this._scatter) {
25445
- this._scatter = value;
25446
- var params = this._bloomMaterial.shaderData.getVector4(BloomEffect._bloomParams);
25447
- var scatter = engineMath.MathUtil.lerp(0.05, 0.95, value);
25448
- params.z = scatter;
25449
- }
25450
- }
25451
- },
25452
- {
25453
- key: "intensity",
25454
- get: /**
25455
- * Controls the strength of the bloom effect.
25456
- */ function get() {
25457
- return this._uberMaterial.shaderData.getVector4(BloomEffect._bloomIntensityParams).x;
25458
- },
25459
- set: function set(value) {
25460
- value = Math.max(0, value);
25461
- this._uberMaterial.shaderData.getVector4(BloomEffect._bloomIntensityParams).x = value;
25462
- }
25463
- },
25464
- {
25465
- key: "tint",
25466
- get: /**
25467
- * Specifies the tint of the bloom effect.
25468
- */ function get() {
25469
- return this._uberMaterial.shaderData.getColor(BloomEffect._tintProp);
25470
- },
25471
- set: function set(value) {
25472
- var tint = this._uberMaterial.shaderData.getColor(BloomEffect._tintProp);
25473
- if (value !== tint) {
25474
- tint.copyFrom(value);
25475
- }
25476
- }
25477
- },
26192
+ /**
26193
+ * @inheritdoc
26194
+ */ _proto._onEnableInScene = function _onEnableInScene() {
26195
+ this.scene.postProcessManager._addPostProcess(this);
26196
+ };
26197
+ /**
26198
+ * @inheritdoc
26199
+ */ _proto._onDisableInScene = function _onDisableInScene() {
26200
+ this.scene.postProcessManager._removePostProcess(this);
26201
+ };
26202
+ _create_class(PostProcess, [
25478
26203
  {
25479
- key: "highQualityFiltering",
26204
+ key: "isGlobal",
25480
26205
  get: /**
25481
- * Controls whether to use bicubic sampling instead of bilinear sampling for the upSampling passes.
25482
- * @remarks This is slightly more expensive but helps getting smoother visuals.
26206
+ * Whether the PostProcess is global.
26207
+ * @remarks
26208
+ * Specifies whether to apply the PostProcess to the entire Scene or in Colliders.
26209
+ * Only support local PostProcess in physics enabled Scenes.
25483
26210
  */ function get() {
25484
- return this._highQualityFiltering;
26211
+ return this._isGlobal;
25485
26212
  },
25486
26213
  set: function set(value) {
25487
- if (value !== this._highQualityFiltering) {
25488
- this._highQualityFiltering = value;
25489
- if (value) {
25490
- this._bloomMaterial.shaderData.enableMacro(BloomEffect._hqMacro);
25491
- this._uberMaterial.shaderData.enableMacro(BloomEffect._hqMacro);
25492
- } else {
25493
- this._bloomMaterial.shaderData.disableMacro(BloomEffect._hqMacro);
25494
- this._uberMaterial.shaderData.disableMacro(BloomEffect._hqMacro);
26214
+ if (value !== this._isGlobal) {
26215
+ if (!value && !this.engine._physicsInitialized) {
26216
+ Logger.warn("Only support local PostProcess in physics enabled Scenes.");
26217
+ return;
25495
26218
  }
26219
+ this._isGlobal = value;
25496
26220
  }
25497
26221
  }
25498
26222
  },
25499
26223
  {
25500
- key: "dirtTexture",
26224
+ key: "priority",
25501
26225
  get: /**
25502
- * Specifies a Texture to add smudges or dust to the bloom effect.
26226
+ * A value which determines which PostProcess is being used when PostProcess have an equal amount of influence on the Scene.
26227
+ * @remarks
26228
+ * PostProcess with a higher priority will override lower ones.
25503
26229
  */ function get() {
25504
- return this._uberMaterial.shaderData.getTexture(BloomEffect._dirtTextureProp);
26230
+ return this._priority;
25505
26231
  },
25506
26232
  set: function set(value) {
25507
- this._uberMaterial.shaderData.setTexture(BloomEffect._dirtTextureProp, value);
25508
- if (value) {
25509
- this._uberMaterial.shaderData.enableMacro(BloomEffect._dirtMacro);
25510
- } else {
25511
- this._uberMaterial.shaderData.disableMacro(BloomEffect._dirtMacro);
26233
+ this._priority = value;
26234
+ if (this.scene) {
26235
+ this.scene.postProcessManager._postProcessNeedSorting = true;
25512
26236
  }
25513
26237
  }
25514
- },
25515
- {
25516
- key: "dirtIntensity",
25517
- get: /**
25518
- * Controls the strength of the lens dirt.
25519
- */ function get() {
25520
- return this._uberMaterial.shaderData.getVector4(BloomEffect._bloomIntensityParams).y;
25521
- },
25522
- set: function set(value) {
25523
- value = Math.max(0, value);
25524
- this._uberMaterial.shaderData.getVector4(BloomEffect._bloomIntensityParams).y = value;
25525
- }
25526
26238
  }
25527
26239
  ]);
25528
- return BloomEffect;
25529
- }();
25530
- BloomEffect.SHADER_NAME = "PostProcessEffect Bloom";
25531
- // Bloom shader properties
25532
- BloomEffect._hqMacro = ShaderMacro.getByName("BLOOM_HQ");
25533
- BloomEffect._dirtMacro = ShaderMacro.getByName("BLOOM_DIRT");
25534
- BloomEffect._bloomParams = ShaderProperty.getByName("material_BloomParams") // x: threshold (linear), y: threshold knee, z: scatter
25535
- ;
25536
- BloomEffect._lowMipTextureProp = ShaderProperty.getByName("material_lowMipTexture");
25537
- BloomEffect._lowMipTexelSizeProp = ShaderProperty.getByName("material_lowMipTexelSize") // x: 1/width, y: 1/height, z: width, w: height
25538
- ;
25539
- // Uber shader properties
25540
- BloomEffect._enableMacro = ShaderMacro.getByName("ENABLE_EFFECT_BLOOM");
25541
- BloomEffect._bloomTextureProp = ShaderProperty.getByName("material_BloomTexture");
25542
- BloomEffect._dirtTextureProp = ShaderProperty.getByName("material_BloomDirtTexture");
25543
- BloomEffect._tintProp = ShaderProperty.getByName("material_BloomTint");
25544
- BloomEffect._bloomIntensityParams = ShaderProperty.getByName("material_BloomIntensityParams") // x: bloom intensity, y: dirt intensity
25545
- ;
25546
- BloomEffect._dirtTilingOffsetProp = ShaderProperty.getByName("material_BloomDirtTilingOffset");
25547
- Shader.create(BloomEffect.SHADER_NAME, [
25548
- new ShaderPass("Bloom Prefilter", blitVs, fragPrefilter),
25549
- new ShaderPass("Bloom Blur Horizontal", blitVs, fragBlurH),
25550
- new ShaderPass("Bloom Blur Vertical", blitVs, fragBlurV),
25551
- new ShaderPass("Bloom Upsample", blitVs, fragUpsample)
25552
- ]);
26240
+ return PostProcess;
26241
+ }(Component);
26242
+ __decorate([
26243
+ deepClone
26244
+ ], PostProcess.prototype, "_effects", void 0);
25553
26245
 
25554
26246
  /**
25555
- * Options to select a tonemapping algorithm to use.
25556
- */ var TonemappingMode = /*#__PURE__*/ function(TonemappingMode) {
26247
+ * A global manager of the PostProcess.
26248
+ */ var PostProcessManager = /*#__PURE__*/ function() {
26249
+ function PostProcessManager(scene) {
26250
+ this.scene = scene;
26251
+ this./** @internal */ _postProcessNeedSorting = false;
26252
+ this./** @internal */ _postProcessPassNeedSorting = false;
26253
+ this._activePostProcesses = [];
26254
+ this._blendEffectMap = new Map();
26255
+ this._defaultEffectMap = new Map();
26256
+ this._remainActivePassCount = 0;
26257
+ }
26258
+ var _proto = PostProcessManager.prototype;
25557
26259
  /**
25558
- * Neutral tonemapper
25559
- * @remarks Use this option if you only want range-remapping with minimal impact on color hue and saturation.
25560
- */ TonemappingMode[TonemappingMode["Neutral"] = 0] = "Neutral";
26260
+ * @internal
26261
+ * Whether has any valid post process pass.
26262
+ */ _proto._isValid = function _isValid() {
26263
+ var scene = this.scene;
26264
+ var engine = scene.engine;
26265
+ var activePasses = engine._getActivePostProcessPasses();
26266
+ return activePasses.some(function(pass) {
26267
+ return pass.isValid(scene.postProcessManager);
26268
+ });
26269
+ };
25561
26270
  /**
25562
- * ACES Filmic reference tonemapper (custom approximation)
25563
- * @remarks
25564
- * Use this option to apply a close approximation of the reference ACES tonemapper for a more filmic look.
25565
- * It is more contrasted than Neutral and has an effect on actual color hue and saturation.
25566
- */ TonemappingMode[TonemappingMode["ACES"] = 1] = "ACES";
25567
- return TonemappingMode;
25568
- }({});
25569
- var TonemappingEffect = /*#__PURE__*/ function() {
25570
- function TonemappingEffect(_uberMaterial) {
25571
- this._uberMaterial = _uberMaterial;
25572
- this._enabled = false;
25573
- this.mode = 0;
25574
- }
25575
- _create_class(TonemappingEffect, [
25576
- {
25577
- key: "enabled",
25578
- get: /**
25579
- * Indicates whether the post process effect is enabled.
25580
- */ function get() {
25581
- return this._enabled;
25582
- },
25583
- set: function set(value) {
25584
- if (value !== this._enabled) {
25585
- this._enabled = value;
25586
- if (value) {
25587
- this._uberMaterial.shaderData.enableMacro(TonemappingEffect._enableMacro);
25588
- } else {
25589
- this._uberMaterial.shaderData.disableMacro(TonemappingEffect._enableMacro);
26271
+ * @internal
26272
+ */ _proto._update = function _update(camera) {
26273
+ // Start by resetting post process effect instance to default values
26274
+ this._resetDefaultValue();
26275
+ // Sort post process
26276
+ this._sortActivePostProcess();
26277
+ var activePostProcesses = this._activePostProcesses;
26278
+ for(var i = 0, n = activePostProcesses.length; i < n; i++){
26279
+ var postProcess = activePostProcesses[i];
26280
+ if (!(camera.postProcessMask & postProcess.layer)) {
26281
+ continue;
26282
+ }
26283
+ var isGlobal = postProcess.isGlobal;
26284
+ var interpFactor = 1; // Global default value
26285
+ if (!isGlobal) {
26286
+ var currentColliders = PostProcessManager._tempColliders;
26287
+ var cameraPosition = camera.entity.transform.worldPosition;
26288
+ var blendDistance = postProcess.blendDistance;
26289
+ var hasColliderShape = false;
26290
+ // Find closest distance to current postProcess, 0 means it's inside it
26291
+ var closestDistance = Number.POSITIVE_INFINITY;
26292
+ postProcess.entity.getComponents(exports.Collider, currentColliders);
26293
+ for(var i1 = 0; i1 < currentColliders.length; i1++){
26294
+ var collider = currentColliders[i1];
26295
+ if (!collider.enabled) {
26296
+ continue;
26297
+ }
26298
+ var shapes = collider.shapes;
26299
+ for(var j = 0; j < shapes.length; j++){
26300
+ var currentShape = shapes[j];
26301
+ hasColliderShape = true;
26302
+ var distance = currentShape.getClosestPoint(cameraPosition, PostProcessManager._tempVector3);
26303
+ if (distance < closestDistance) {
26304
+ closestDistance = distance;
26305
+ }
25590
26306
  }
25591
26307
  }
26308
+ if (!hasColliderShape) {
26309
+ Logger.warn('No collider shape found in the entity:"' + postProcess.entity.name + '", the local mode of post process will not take effect.');
26310
+ continue;
26311
+ }
26312
+ // Post process has no influence, ignore it
26313
+ if (closestDistance > blendDistance) {
26314
+ continue;
26315
+ }
26316
+ if (blendDistance > 0) {
26317
+ interpFactor = 1 - closestDistance / blendDistance;
26318
+ }
25592
26319
  }
25593
- },
25594
- {
25595
- key: "mode",
25596
- get: /**
25597
- * Use this to select a tonemapping algorithm to use.
25598
- */ function get() {
25599
- return this._mode;
25600
- },
25601
- set: function set(value) {
25602
- if (value !== this._mode) {
25603
- this._mode = value;
25604
- this._uberMaterial.shaderData.enableMacro("TONEMAPPING_MODE", value.toString());
26320
+ var effects = postProcess._effects;
26321
+ for(var j1 = 0; j1 < effects.length; j1++){
26322
+ var effect = effects[j1];
26323
+ if (!effect.enabled) {
26324
+ continue;
25605
26325
  }
26326
+ var PostConstructor = effect.constructor;
26327
+ var blendEffect = this._blendEffectMap.get(PostConstructor);
26328
+ if (!blendEffect) {
26329
+ blendEffect = new PostConstructor();
26330
+ this._blendEffectMap.set(PostConstructor, blendEffect);
26331
+ }
26332
+ blendEffect._lerp(effect, interpFactor);
26333
+ blendEffect.enabled = true;
25606
26334
  }
25607
26335
  }
25608
- ]);
25609
- return TonemappingEffect;
25610
- }();
25611
- TonemappingEffect._enableMacro = ShaderMacro.getByName("ENABLE_EFFECT_TONEMAPPING");
25612
-
25613
- /**
25614
- * @internal
25615
- */ var _PostProcessManager = /*#__PURE__*/ function() {
25616
- function _PostProcessManager(scene) {
25617
- this.scene = scene;
25618
- this./**
25619
- * Whether the post process manager is active.
25620
- */ isActive = true;
25621
- var uberShader = Shader.find(_PostProcessManager.UBER_SHADER_NAME);
25622
- var uberMaterial = new Material(scene.engine, uberShader);
25623
- var depthState = uberMaterial.renderState.depthState;
25624
- depthState.enabled = false;
25625
- depthState.writeEnabled = false;
25626
- var bloomEffect = new BloomEffect(uberMaterial);
25627
- var tonemappingEffect = new TonemappingEffect(uberMaterial);
25628
- this._uberMaterial = uberMaterial;
25629
- this._bloomEffect = bloomEffect;
25630
- this._tonemappingEffect = tonemappingEffect;
25631
- }
25632
- var _proto = _PostProcessManager.prototype;
26336
+ };
25633
26337
  /**
25634
26338
  * @internal
25635
- */ _proto._render = function _render(context, srcTarget, destTarget) {
25636
- var camera = context.camera;
25637
- var engine = camera.engine;
25638
- // Should blit to resolve the MSAA
25639
- srcTarget._blitRenderTarget();
25640
- var srcTexture = srcTarget.getColorTexture();
25641
- var bloomEffect = this._bloomEffect;
25642
- if (bloomEffect.enabled) {
25643
- bloomEffect.onRender(context, srcTexture);
26339
+ */ _proto._addPostProcess = function _addPostProcess(postProcess) {
26340
+ this._activePostProcesses.push(postProcess);
26341
+ this._postProcessNeedSorting = true;
26342
+ };
26343
+ /**
26344
+ * @internal
26345
+ */ _proto._removePostProcess = function _removePostProcess(postProcess) {
26346
+ var index = this._activePostProcesses.indexOf(postProcess);
26347
+ if (index >= 0) {
26348
+ this._activePostProcesses.splice(index, 1);
26349
+ this._postProcessNeedSorting = true;
25644
26350
  }
25645
- // Done with Uber, blit it
25646
- PipelineUtils.blitTexture(engine, srcTexture, destTarget, 0, camera.viewport, this._uberMaterial);
25647
26351
  };
25648
- _create_class(_PostProcessManager, [
25649
- {
25650
- key: "hasActiveEffect",
25651
- get: /**
25652
- * Whether has active post process effect.
25653
- */ function get() {
25654
- return this.isActive && (this._bloomEffect.enabled || this._tonemappingEffect.enabled);
26352
+ /**
26353
+ * Get the blend effect by type.
26354
+ * @remarks
26355
+ * The blend effect is a post process effect that is used to blend all result of the effects by the type.
26356
+ * @param type - The type of PostProcessEffect
26357
+ * @returns The PostProcessEffect instance found
26358
+ */ _proto.getBlendEffect = function getBlendEffect(type) {
26359
+ return this._blendEffectMap.get(type);
26360
+ };
26361
+ /**
26362
+ * @internal
26363
+ */ _proto._render = function _render(camera, srcRenderTarget, destRenderTarget) {
26364
+ var engine = this.scene.engine;
26365
+ this._srcRenderTarget = srcRenderTarget;
26366
+ this._destRenderTarget = destRenderTarget;
26367
+ // Should blit to resolve the MSAA
26368
+ srcRenderTarget._blitRenderTarget();
26369
+ var activePasses = engine._getActivePostProcessPasses();
26370
+ this._remainActivePassCount = activePasses.length;
26371
+ this._initSwapRenderTarget(camera);
26372
+ for(var i = 0, n = activePasses.length; i < n; i++){
26373
+ var pass = activePasses[i];
26374
+ pass.onRender(camera, this._getCurrentSourceTexture(), this._currentDestRenderTarget);
26375
+ this._remainActivePassCount--;
26376
+ this._swapRT();
26377
+ }
26378
+ };
26379
+ /**
26380
+ * @internal
26381
+ */ _proto._releaseSwapRenderTarget = function _releaseSwapRenderTarget() {
26382
+ var swapRenderTarget = this._swapRenderTarget;
26383
+ if (swapRenderTarget) {
26384
+ var _swapRenderTarget_getColorTexture;
26385
+ (_swapRenderTarget_getColorTexture = swapRenderTarget.getColorTexture(0)) == null ? void 0 : _swapRenderTarget_getColorTexture.destroy(true);
26386
+ swapRenderTarget.destroy(true);
26387
+ this._swapRenderTarget = null;
26388
+ }
26389
+ };
26390
+ _proto._sortActivePostProcess = function _sortActivePostProcess() {
26391
+ if (this._postProcessNeedSorting) {
26392
+ var postProcesses = this._activePostProcesses;
26393
+ if (postProcesses.length) {
26394
+ postProcesses.sort(function(a, b) {
26395
+ return a.priority - b.priority;
26396
+ });
25655
26397
  }
26398
+ this._postProcessNeedSorting = false;
25656
26399
  }
25657
- ]);
25658
- return _PostProcessManager;
26400
+ };
26401
+ _proto._resetDefaultValue = function _resetDefaultValue() {
26402
+ var _this = this;
26403
+ this._blendEffectMap.forEach(function(blendEffect, typeofBlendEffect) {
26404
+ var defaultEffect = _this._defaultEffectMap.get(typeofBlendEffect);
26405
+ if (!defaultEffect) {
26406
+ defaultEffect = new typeofBlendEffect();
26407
+ _this._defaultEffectMap.set(typeofBlendEffect, defaultEffect);
26408
+ }
26409
+ // Reset effectInstance's value by defaultEffect
26410
+ blendEffect._lerp(defaultEffect, 1);
26411
+ blendEffect.enabled = false;
26412
+ });
26413
+ };
26414
+ _proto._initSwapRenderTarget = function _initSwapRenderTarget(camera) {
26415
+ if (this._remainActivePassCount > 1) {
26416
+ var viewport = camera.pixelViewport;
26417
+ var swapRenderTarget = PipelineUtils.recreateRenderTargetIfNeeded(this.scene.engine, this._swapRenderTarget, viewport.width, viewport.height, camera._getInternalColorTextureFormat(), TextureFormat.Depth24Stencil8, false, false, 1, TextureWrapMode.Clamp, TextureFilterMode.Bilinear);
26418
+ this._swapRenderTarget = swapRenderTarget;
26419
+ this._currentDestRenderTarget = this._swapRenderTarget;
26420
+ } else {
26421
+ this._currentDestRenderTarget = this._destRenderTarget;
26422
+ }
26423
+ this._currentSourceRenderTarget = this._srcRenderTarget;
26424
+ };
26425
+ _proto._swapRT = function _swapRT() {
26426
+ var currentSourceRenderTarget = this._currentSourceRenderTarget;
26427
+ var currentDestRenderTarget = this._currentDestRenderTarget;
26428
+ this._currentSourceRenderTarget = currentDestRenderTarget;
26429
+ if (this._remainActivePassCount > 1) {
26430
+ this._currentDestRenderTarget = currentSourceRenderTarget;
26431
+ } else {
26432
+ this._currentDestRenderTarget = this._destRenderTarget;
26433
+ }
26434
+ };
26435
+ _proto._getCurrentSourceTexture = function _getCurrentSourceTexture() {
26436
+ return this._currentSourceRenderTarget.getColorTexture(0);
26437
+ };
26438
+ return PostProcessManager;
25659
26439
  }();
25660
- _PostProcessManager.UBER_SHADER_NAME = "UberPost";
25661
-
25662
- 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
25663
-
25664
- 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
25665
-
25666
- 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
25667
-
25668
- 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
25669
-
25670
- 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
25671
-
25672
- 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
25673
-
25674
- 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
25675
-
25676
- 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
25677
-
25678
- 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
25679
-
25680
- Object.assign(ShaderLib, {
25681
- PostCommon: PostCommon,
25682
- Filtering: Filtering,
25683
- ODT: ODT,
25684
- RRT: RRT,
25685
- Tonescale: Tonescale,
25686
- ColorTransform: ColorTransform,
25687
- NeutralTonemapping: NeutralTonemapping,
25688
- ACESTonemapping: ACESTonemapping
25689
- });
25690
- Shader.create(_PostProcessManager.UBER_SHADER_NAME, blitVs, UberPost);
26440
+ PostProcessManager._tempColliders = [];
26441
+ PostProcessManager._tempVector3 = new engineMath.Vector3();
25691
26442
 
25692
26443
  /**
25693
26444
  * Scene.
@@ -25698,7 +26449,7 @@ Shader.create(_PostProcessManager.UBER_SHADER_NAME, blitVs, UberPost);
25698
26449
  _this = EngineObject.call(this, engine) || this, /** Physics. */ _this.physics = new PhysicsScene(_this), /** If cast shadows. */ _this.castShadows = true, /** The resolution of the shadow maps. */ _this.shadowResolution = ShadowResolution.Medium, /** The splits of two cascade distribution. */ _this.shadowTwoCascadeSplits = 1.0 / 3.0, /** The splits of four cascade distribution. */ _this.shadowFourCascadeSplits = new engineMath.Vector3(1.0 / 15, 3.0 / 15.0, 7.0 / 15.0), /** Max Shadow distance. */ _this.shadowDistance = 50, /**
25699
26450
  * Last shadow fade distance in percentage, range [0,1].
25700
26451
  * @remarks Value 0 is used for no shadow fade.
25701
- */ _this.shadowFadeBorder = 0.1, /* @internal */ _this._lightManager = new LightManager(), /* @internal */ _this._componentsManager = new ComponentsManager(), /** @internal */ _this._maskManager = new MaskManager(), /** @internal */ _this._isActiveInEngine = false, /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection(), /** @internal */ _this._rootEntities = [], /** @internal */ _this._postProcessManager = new _PostProcessManager(_this), _this._background = new Background(_this._engine), _this._shaderData = new ShaderData(ShaderDataGroup.Scene), _this._shadowCascades = ShadowCascadesMode.NoCascades, _this._fogMode = FogMode.None, _this._fogColor = new engineMath.Color(0.5, 0.5, 0.5, 1.0), _this._fogStart = 0, _this._fogEnd = 300, _this._fogDensity = 0.01, _this._fogParams = new engineMath.Vector4(), _this._isActive = true, _this._enableTransparentShadow = false;
26452
+ */ _this.shadowFadeBorder = 0.1, /** Post process manager. */ _this.postProcessManager = new PostProcessManager(_this), /* @internal */ _this._lightManager = new LightManager(), /* @internal */ _this._componentsManager = new ComponentsManager(), /** @internal */ _this._maskManager = new MaskManager(), /** @internal */ _this._isActiveInEngine = false, /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection(), /** @internal */ _this._rootEntities = [], _this._background = new Background(_this._engine), _this._shaderData = new ShaderData(ShaderDataGroup.Scene), _this._shadowCascades = ShadowCascadesMode.NoCascades, _this._fogMode = FogMode.None, _this._fogColor = new engineMath.Color(0.5, 0.5, 0.5, 1.0), _this._fogStart = 0, _this._fogEnd = 300, _this._fogDensity = 0.01, _this._fogParams = new engineMath.Vector4(), _this._isActive = true, _this._enableTransparentShadow = false;
25702
26453
  _this.name = name || "";
25703
26454
  var shaderData = _this.shaderData;
25704
26455
  shaderData._addReferCount(1);
@@ -33843,9 +34594,9 @@ ConeShape._tempVector31 = new engineMath.Vector3();
33843
34594
  return SphereShape;
33844
34595
  }(BaseShape);
33845
34596
 
33846
- var FRAG_SHADER = "#define GLSLIFY 1\nvarying vec2 v_uv;uniform sampler2D u_texture;void main(void){gl_FragColor=texture2D(u_texture,v_uv);}"; // eslint-disable-line
34597
+ var FRAG_SHADER = "#define GLSLIFY 1\nvarying vec2 v_uv;\n\nuniform sampler2D u_texture;\n\nvoid main(void) {\n\n gl_FragColor = texture2D(u_texture, v_uv);\n\n}\n"; // eslint-disable-line
33847
34598
 
33848
- var VERT_SHADER = "#define GLSLIFY 1\nattribute vec3 POSITION;attribute vec2 TEXCOORD_0;varying vec2 v_uv;uniform mat4 camera_ProjMat;uniform mat4 camera_ViewMat;void main(){gl_Position=camera_ProjMat*camera_ViewMat*vec4(POSITION,1.0);v_uv=TEXCOORD_0;}"; // eslint-disable-line
34599
+ var VERT_SHADER = "#define GLSLIFY 1\nattribute vec3 POSITION;\nattribute vec2 TEXCOORD_0;\n\nvarying vec2 v_uv;\n\nuniform mat4 camera_ProjMat;\nuniform mat4 camera_ViewMat;\n\nvoid main() {\n\n gl_Position = camera_ProjMat * camera_ViewMat * vec4( POSITION, 1.0 );\n v_uv = TEXCOORD_0;\n\n}\n"; // eslint-disable-line
33849
34600
 
33850
34601
  Shader.create("trail", VERT_SHADER, FRAG_SHADER);
33851
34602
  var TrailMaterial = /*#__PURE__*/ function(Material) {
@@ -34622,6 +35373,7 @@ exports.BlendShape = BlendShape;
34622
35373
  exports.BlendShapeFrame = BlendShapeFrame;
34623
35374
  exports.BlendState = BlendState;
34624
35375
  exports.BlinnPhongMaterial = BlinnPhongMaterial;
35376
+ exports.Blitter = Blitter;
34625
35377
  exports.BloomDownScaleMode = BloomDownScaleMode;
34626
35378
  exports.BloomEffect = BloomEffect;
34627
35379
  exports.BoolUpdateFlag = BoolUpdateFlag;
@@ -34643,6 +35395,7 @@ exports.ClearableObjectPool = ClearableObjectPool;
34643
35395
  exports.CloneManager = CloneManager;
34644
35396
  exports.ColliderShape = ColliderShape;
34645
35397
  exports.ColliderShapeUpAxis = ColliderShapeUpAxis;
35398
+ exports.Collision = Collision;
34646
35399
  exports.CollisionDetectionMode = CollisionDetectionMode;
34647
35400
  exports.ColorOverLifetimeModule = ColorOverLifetimeModule;
34648
35401
  exports.ColorSpace = ColorSpace;
@@ -34651,6 +35404,7 @@ exports.CompareFunction = CompareFunction;
34651
35404
  exports.Component = Component;
34652
35405
  exports.ConeEmitType = ConeEmitType;
34653
35406
  exports.ConeShape = ConeShape;
35407
+ exports.ContactPoint = ContactPoint;
34654
35408
  exports.ContentRestorer = ContentRestorer;
34655
35409
  exports.ControllerCollisionFlag = ControllerCollisionFlag;
34656
35410
  exports.ControllerNonWalkableMode = ControllerNonWalkableMode;
@@ -34731,11 +35485,19 @@ exports.PointLight = PointLight;
34731
35485
  exports.Pointer = Pointer;
34732
35486
  exports.PointerButton = PointerButton;
34733
35487
  exports.PointerPhase = PointerPhase;
35488
+ exports.PostProcess = PostProcess;
35489
+ exports.PostProcessEffect = PostProcessEffect;
35490
+ exports.PostProcessEffectParameter = PostProcessEffectParameter;
35491
+ exports.PostProcessManager = PostProcessManager;
35492
+ exports.PostProcessPass = PostProcessPass;
35493
+ exports.PostProcessPassEvent = PostProcessPassEvent;
35494
+ exports.PostProcessUberPass = PostProcessUberPass;
34734
35495
  exports.Primitive = Primitive;
34735
35496
  exports.PrimitiveMesh = PrimitiveMesh;
34736
35497
  exports.Probe = Probe;
34737
35498
  exports.RasterState = RasterState;
34738
35499
  exports.ReferResource = ReferResource;
35500
+ exports.RefractionMode = RefractionMode;
34739
35501
  exports.RenderBufferDepthFormat = RenderBufferDepthFormat;
34740
35502
  exports.RenderFace = RenderFace;
34741
35503
  exports.RenderQueue = RenderQueue;
@@ -34825,7 +35587,6 @@ exports.VertexElement = VertexElement;
34825
35587
  exports.VertexElementFormat = VertexElementFormat;
34826
35588
  exports.WrapMode = WrapMode;
34827
35589
  exports.XRManager = XRManager;
34828
- exports._PostProcessManager = _PostProcessManager;
34829
35590
  exports.assignmentClone = assignmentClone;
34830
35591
  exports.deepClone = deepClone;
34831
35592
  exports.dependentComponents = dependentComponents;