@galacean/engine 2.0.0-alpha.5 → 2.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.js CHANGED
@@ -9799,7 +9799,7 @@
9799
9799
  return PipelineStage;
9800
9800
  }({});
9801
9801
  var camera_declare = "uniform vec3 camera_Position;\nuniform vec3 camera_Forward; "; // eslint-disable-line
9802
- var common = "#define PI 3.14159265359\n#define RECIPROCAL_PI 0.31830988618\n#define EPSILON 1e-6\n#define LOG2 1.442695\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_EPS 4.8828125e-4 // 2^-11, machine epsilon: 1 + EPS = 1 (half of the ULP for 1.0f)\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 value){\n return vec4( pow(value.rgb, vec3(2.2)), value.a);\n}\n\nvec4 linearToGamma(vec4 value){\n\tvalue = max(value, 0.0);\n return vec4( pow(value.rgb, vec3(1.0 / 2.2)), value.a);\n}\n\n\n// https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_framebuffer_sRGB.txt\n// https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_texture_sRGB_decode.txt\nfloat sRGBToLinear(float value){\n float linearRGBLo = value / 12.92;\n float linearRGBHi = pow((value + 0.055) / 1.055, 2.4);\n float linearRGB = (value <= 0.04045) ? linearRGBLo : linearRGBHi;\n return linearRGB;\n}\n\nvec4 sRGBToLinear(vec4 value){\n return vec4(sRGBToLinear(value.r), sRGBToLinear(value.g), sRGBToLinear(value.b), value.a);\n}\n\nfloat linearToSRGB(float value){\n\tvalue = max(value, 0.0);\n return (value <= 0.0031308) ? (value * 12.9232102) : 1.055 * pow(value, 1.0 / 2.4) - 0.055;\n}\n\nvec4 linearToSRGB(vec4 value){\n return vec4(linearToSRGB(value.r), linearToSRGB(value.g), linearToSRGB(value.b), value.a);\n}\n\n// Compatible with devices that do not even support EXT_sRGB in WebGL1.0.\nvec4 texture2DSRGB(sampler2D tex, vec2 uv) {\n\tvec4 color = texture2D(tex, uv);\n\t#ifdef ENGINE_NO_SRGB\n\t\tcolor = sRGBToLinear(color);\n\t#endif\n\treturn color;\n}\n\nvec4 outputSRGBCorrection(vec4 linearIn){\n #ifdef ENGINE_OUTPUT_SRGB_CORRECT\n \treturn linearToSRGB(linearIn);\n #else \n \treturn linearIn;\n #endif\n}\n\n\nuniform vec4 camera_DepthBufferParams;\nuniform vec4 camera_ProjectionParams;\n\nfloat remapDepthBufferLinear01(float depth){\n\treturn 1.0 / (camera_DepthBufferParams.x * depth + camera_DepthBufferParams.y);\n}\n\nfloat remapDepthBufferEyeDepth(float depth){\n\t#ifdef CAMERA_ORTHOGRAPHIC\n\t\treturn camera_ProjectionParams.y + (camera_ProjectionParams.z - camera_ProjectionParams.y) * depth;\n\t#else\n\t\treturn 1.0 / (camera_DepthBufferParams.z * depth + camera_DepthBufferParams.w);\n\t#endif\n}\n\n// From Next Generation Post Processing in Call of Duty: Advanced Warfare [Jimenez 2014]\n// http://advances.realtimerendering.com/s2014/index.html\n// sampleCoord must not be normalized (e.g. window coordinates)\nfloat interleavedGradientNoise(vec2 sampleCoord)\n{\n\tconst vec3 magic = vec3(0.06711056, 0.00583715, 52.9829189);\n\treturn fract(magic.z * fract(dot(sampleCoord, magic.xy)));\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\n\nvec3 safeNormalize(vec3 inVec) {\n float dp3 = max(float(HALF_MIN), dot(inVec, inVec));\n return inVec * inversesqrt(dp3);\n}\n"; // eslint-disable-line
9802
+ var common = "#define PI 3.14159265359\n#define RECIPROCAL_PI 0.31830988618\n#define EPSILON 1e-6\n#define LOG2 1.442695\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_EPS 4.8828125e-4 // 2^-11, machine epsilon: 1 + EPS = 1 (half of the ULP for 1.0f)\n\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n\nfloat pow2(float x ) {\n return x * x;\n}\n\nvec4 gammaToLinear(vec4 value){\n return vec4( pow(value.rgb, vec3(2.2)), value.a);\n}\n\nvec4 linearToGamma(vec4 value){\n\tvalue = max(value, 0.0);\n return vec4( pow(value.rgb, vec3(1.0 / 2.2)), value.a);\n}\n\n\n// https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_framebuffer_sRGB.txt\n// https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_texture_sRGB_decode.txt\nfloat sRGBToLinear(float value){\n float linearRGBLo = value / 12.92;\n float linearRGBHi = pow((value + 0.055) / 1.055, 2.4);\n float linearRGB = (value <= 0.04045) ? linearRGBLo : linearRGBHi;\n return linearRGB;\n}\n\nvec4 sRGBToLinear(vec4 value){\n return vec4(sRGBToLinear(value.r), sRGBToLinear(value.g), sRGBToLinear(value.b), value.a);\n}\n\nfloat linearToSRGB(float value){\n\tvalue = max(value, 0.0);\n return (value <= 0.0031308) ? (value * 12.9232102) : 1.055 * pow(value, 1.0 / 2.4) - 0.055;\n}\n\nvec4 linearToSRGB(vec4 value){\n return vec4(linearToSRGB(value.r), linearToSRGB(value.g), linearToSRGB(value.b), value.a);\n}\n\n// Compatible with devices that do not even support EXT_sRGB in WebGL1.0.\nvec4 texture2DSRGB(sampler2D tex, vec2 uv) {\n\tvec4 color = texture2D(tex, uv);\n\t#ifdef ENGINE_NO_SRGB\n\t\tcolor = sRGBToLinear(color);\n\t#endif\n\treturn color;\n}\n\nvec4 outputSRGBCorrection(vec4 linearIn){\n #ifdef ENGINE_OUTPUT_SRGB_CORRECT\n \treturn linearToSRGB(linearIn);\n #else \n \treturn linearIn;\n #endif\n}\n\n\nuniform vec4 camera_DepthBufferParams;\nuniform vec4 camera_ProjectionParams;\n\nfloat remapDepthBufferLinear01(float depth){\n\treturn 1.0 / (camera_DepthBufferParams.x * depth + camera_DepthBufferParams.y);\n}\n\nfloat remapDepthBufferEyeDepth(float depth){\n\t#ifdef CAMERA_ORTHOGRAPHIC\n\t\treturn camera_ProjectionParams.y + (camera_ProjectionParams.z - camera_ProjectionParams.y) * depth;\n\t#else\n\t\treturn 1.0 / (camera_DepthBufferParams.z * depth + camera_DepthBufferParams.w);\n\t#endif\n}\n\n// From Next Generation Post Processing in Call of Duty: Advanced Warfare [Jimenez 2014]\n// http://advances.realtimerendering.com/s2014/index.html\n// sampleCoord must not be normalized (e.g. window coordinates)\nfloat interleavedGradientNoise(vec2 sampleCoord)\n{\n\tconst vec3 magic = vec3(0.06711056, 0.00583715, 52.9829189);\n\treturn fract(magic.z * fract(dot(sampleCoord, magic.xy)));\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\n\nvec3 safeNormalize(vec3 inVec) {\n float dp3 = max(float(HALF_MIN), dot(inVec, inVec));\n return inVec * inversesqrt(dp3);\n}\n"; // eslint-disable-line
9803
9803
  var common_vert = "attribute 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\n#include <transform_declare>\n#include <camera_declare>\n\nuniform vec4 material_TilingOffset;\n\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
9804
9804
  var transform_declare = "uniform 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
9805
9805
  var color_share = "#ifdef RENDERER_ENABLE_VERTEXCOLOR\n\nvarying vec4 v_color;\n\n#endif\n"; // eslint-disable-line
@@ -9847,7 +9847,7 @@
9847
9847
  var pbr_helper = "#include <normal_get>\n#include <brdf>\n#include <btdf>\n\n// direct + indirect\n#include <direct_irradiance_frag_define>\n#include <ibl_frag_define>\n\nuniform sampler2D camera_AOTexture;\n\nfloat evaluateAmbientOcclusion(vec2 uv)\n{\n #ifdef MATERIAL_IS_TRANSPARENT\n return 1.0;\n #else\n return texture2D(camera_AOTexture, uv).r;\n #endif\n}\n\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\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 float alphaCutoff = material_AlphaCutoff;\n material.IOR = material_IOR;\n\n #ifdef MATERIAL_HAS_BASETEXTURE\n baseColor *= texture2DSRGB(material_BaseTexture, v_uv);\n #endif\n\n #ifdef RENDERER_ENABLE_VERTEXCOLOR\n baseColor *= v_color;\n #endif\n\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 // Specular\n material.specularIntensity = material_SpecularIntensity;\n material.specularColor = material_SpecularColor;\n #ifdef MATERIAL_HAS_SPECULAR_TEXTURE\n material.specularIntensity *= texture2D( material_SpecularIntensityTexture, v_uv ).a;\n #endif\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\n material.roughness = max(MIN_PERCEPTUAL_ROUGHNESS, min(roughness + getAARoughnessFactor(geometry.normal), 1.0));\n\n #ifdef MATERIAL_ENABLE_ANISOTROPY\n geometry.anisotropicN = getAnisotropicBentNormal(geometry, geometry.normal, material.roughness);\n #endif\n\n vec3 dielectricBaseF0 = vec3(pow2( (material.IOR - 1.0) / (material.IOR + 1.0) ));\n vec3 dielectricF0 = min(dielectricBaseF0 * material.specularColor , vec3(1.0)) * material.specularIntensity;\n float dielectricF90 = material.specularIntensity; \n\n material.specularF0 = mix(dielectricF0, baseColor.rgb, metal);\n material.specularF90 = mix(dielectricF90, 1.0, metal);\n material.resolvedSpecularF0 = material.specularF0;\n\n // Simplify: albedoColor * mix((1.0 - max(max(dielectricF0.r,dielectricF0.g),dielectricF0.b)), 0.0, metallic);\n material.diffuseColor = baseColor.rgb * (1.0 - metal) * (1.0 - max(max(dielectricF0.r,dielectricF0.g),dielectricF0.b));\n // Environment BRDF\n vec2 dfg = envDFGApprox(material.roughness, geometry.dotNV);\n\n // AO\n float diffuseAO = 1.0;\n float specularAO = 1.0;\n\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 diffuseAO = ((texture2D(material_OcclusionTexture, aoUV)).r - 1.0) * material_OcclusionIntensity + 1.0;\n #endif\n\n #ifdef SCENE_ENABLE_AMBIENT_OCCLUSION\n float ambientAO = evaluateAmbientOcclusion((v_PositionCS.xy / v_PositionCS.w) * 0.5 + 0.5);\n diffuseAO = min(diffuseAO, ambientAO);\n #endif\n\n #if (defined(MATERIAL_HAS_OCCLUSION_TEXTURE) || defined(SCENE_ENABLE_AMBIENT_OCCLUSION))&& defined(SCENE_USE_SPECULAR_ENV) \n specularAO = saturate( pow( geometry.dotNV + diffuseAO, exp2( - 16.0 * material.roughness - 1.0 ) ) - 1.0 + diffuseAO );\n #endif\n\n material.diffuseAO = diffuseAO;\n material.specularAO = specularAO;\n\n // Sheen\n #ifdef MATERIAL_ENABLE_SHEEN\n vec3 sheenColor = material_SheenColor;\n #ifdef MATERIAL_HAS_SHEEN_TEXTURE\n sheenColor *= texture2DSRGB(material_SheenTexture, v_uv).rgb;\n #endif\n material.sheenColor = sheenColor;\n\n material.sheenRoughness = material_SheenRoughness;\n #ifdef MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE\n material.sheenRoughness *= texture2D(material_SheenRoughnessTexture, v_uv).a;\n #endif\n\n material.sheenRoughness = max(MIN_PERCEPTUAL_ROUGHNESS, min(material.sheenRoughness + getAARoughnessFactor(geometry.normal), 1.0));\n material.approxIBLSheenDG = prefilteredSheenDFG(geometry.dotNV, material.sheenRoughness);\n material.sheenScaling = 1.0 - material.approxIBLSheenDG * max(max(material.sheenColor.r, material.sheenColor.g), material.sheenColor.b);\n #endif\n\n // Iridescence\n #ifdef MATERIAL_ENABLE_IRIDESCENCE\n material.iridescenceFactor = material_IridescenceInfo.x;\n material.iridescenceIOR = material_IridescenceInfo.y;\n\n #ifdef MATERIAL_HAS_IRIDESCENCE_THICKNESS_TEXTURE\n float iridescenceThicknessWeight = texture2D( material_IridescenceThicknessTexture, v_uv).g;\n material.iridescenceThickness = mix(material_IridescenceInfo.z, material_IridescenceInfo.w, iridescenceThicknessWeight);\n #else\n material.iridescenceThickness = material_IridescenceInfo.w;\n #endif\n\n #ifdef MATERIAL_HAS_IRIDESCENCE_TEXTURE\n material.iridescenceFactor *= texture2D( material_IridescenceTexture, v_uv).r;\n #endif\n \n #ifdef MATERIAL_ENABLE_IRIDESCENCE\n float topIOR = 1.0;\n material.iridescenceSpecularColor = evalIridescenceSpecular(topIOR, geometry.dotNV, material.iridescenceIOR, material.specularF0, material.specularF90, material.iridescenceThickness);\n material.resolvedSpecularF0 = mix(material.resolvedSpecularF0, material.iridescenceSpecularColor, material.iridescenceFactor);\n #endif\n #endif\n\n material.envSpecularDFG = material.resolvedSpecularF0 * dfg.x + material.specularF90 * dfg.y;\n\n // Multi-scattering energy compensation\n // Ref: Kulla & Conty 2017, \"Revisiting Physically Based Shading at Imageworks\"\n // Ref: Lagarde & Golubev 2018, simplified multiplier approach\n material.energyCompensation = 1.0 + material.resolvedSpecularF0 * (1.0 / max(dfg.x + dfg.y, EPSILON) - 1.0);\n\n // Transmission\n #ifdef MATERIAL_ENABLE_TRANSMISSION \n material.transmission = material_Transmission;\n #ifdef MATERIAL_HAS_TRANSMISSION_TEXTURE\n material.transmission *= texture2D(material_TransmissionTexture, v_uv).r;\n #endif\n\n #ifdef MATERIAL_HAS_THICKNESS\n material.absorptionCoefficient = -log(material_AttenuationColor + HALF_EPS) / max(HALF_EPS, material_AttenuationDistance);\n material.thickness = max(material_Thickness, 0.0001);\n #ifdef MATERIAL_HAS_THICKNESS_TEXTURE\n material.thickness *= texture2D( material_ThicknessTexture, v_uv).g;\n #endif\n #endif \n #endif\n}\n\n"; // eslint-disable-line
9848
9848
  var brdf = "\n#ifdef MATERIAL_ENABLE_SHEEN\n uniform sampler2D scene_PrefilteredDFG;\n#endif\n\nfloat F_Schlick(float f0, float f90, float dotLH) {\n\treturn f0 + (f90 - f0) * (pow(1.0 - dotLH, 5.0));\n}\n\nvec3 F_Schlick(vec3 f0, float f90, 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 (f90 - f0 ) * fresnel + f0;\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_SHEEN\n // http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf\n float D_Charlie(float roughness, float dotNH) {\n float invAlpha = 1.0 / roughness;\n float cos2h = dotNH * dotNH;\n float sin2h = max(1.0 - cos2h, 0.0078125); // 2^(-14/2), so sin2h^2 > 0 in fp16\n return (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);\n }\n\n // Neubelt and Pettineo 2013, \"Crafting a Next-gen Material Pipeline for The Order: 1886\".\n float V_Neubelt(float NoV, float NoL) {\n return saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));\n }\n\n vec3 sheenBRDF(vec3 incidentDirection, Geometry geometry, vec3 sheenColor, float sheenRoughness) {\n vec3 halfDir = normalize(incidentDirection + geometry.viewDir);\n float dotNL = saturate(dot(geometry.normal, incidentDirection));\n float dotNH = saturate(dot(geometry.normal, halfDir));\n float D = D_Charlie(sheenRoughness, dotNH);\n float V = V_Neubelt(geometry.dotNV, dotNL);\n vec3 F = sheenColor;\n return D * V * F;\n }\n\n float prefilteredSheenDFG(float dotNV, float sheenRoughness) {\n #ifdef HAS_TEX_LOD\n return texture2DLodEXT(scene_PrefilteredDFG, vec2(dotNV, sheenRoughness), 0.0).b;\n #else\n return texture2D(scene_PrefilteredDFG, vec2(dotNV, sheenRoughness),0.0).b;\n #endif \n }\n#endif\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\nfloat DG_GGX(float alpha, float dotNV, float dotNL, float dotNH) {\n\tfloat D = D_GGX( alpha, dotNH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n return G * D;\n}\n\n#ifdef MATERIAL_ENABLE_ANISOTROPY\n float DG_GGX_anisotropic(vec3 h, vec3 l, Geometry geometry, float alpha, float dotNV, float dotNL, float dotNH) {\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 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 G * D;\n }\n#endif\n\n#ifdef MATERIAL_ENABLE_IRIDESCENCE\n vec3 iorToFresnel0(vec3 transmittedIOR, float incidentIOR) {\n return pow((transmittedIOR - incidentIOR) / (transmittedIOR + incidentIOR),vec3(2.0));\n } \n\n float iorToFresnel0(float transmittedIOR, float incidentIOR) {\n return pow((transmittedIOR - incidentIOR) / (transmittedIOR + incidentIOR),2.0);\n } \n\n // Assume air interface for top\n // Note: We don't handle the case fresnel0 == 1\n vec3 fresnelToIOR(vec3 f0){\n vec3 sqrtF0 = sqrt(f0);\n return (vec3(1.0) + sqrtF0) / (vec3(1.0) - sqrtF0);\n }\n\n // Fresnel equations for dielectric/dielectric interfaces.\n // Ref: https://belcour.github.io/blog/research/publication/2017/05/01/brdf-thin-film.html\n // Evaluation XYZ sensitivity curves in Fourier space\n vec3 evalSensitivity(float opd, vec3 shift){\n // Use Gaussian fits, given by 3 parameters: val, pos and var\n float phase = 2.0 * PI * opd * 1.0e-9;\n const vec3 val = vec3(5.4856e-13, 4.4201e-13, 5.2481e-13);\n const vec3 pos = vec3(1.6810e+06, 1.7953e+06, 2.2084e+06);\n const vec3 var = vec3(4.3278e+09, 9.3046e+09, 6.6121e+09);\n vec3 xyz = val * sqrt(2.0 * PI * var) * cos(pos * phase + shift) * exp(-var * pow2(phase));\n xyz.x += 9.7470e-14 * sqrt(2.0 * PI * 4.5282e+09) * cos(2.2399e+06 * phase + shift[0]) * exp(-4.5282e+09 * pow2(phase));\n xyz /= 1.0685e-7;\n // XYZ to RGB color space\n const mat3 XYZ_TO_RGB = mat3( 3.2404542, -0.9692660, 0.0556434,\n -1.5371385, 1.8760108, -0.2040259,\n -0.4985314, 0.0415560, 1.0572252);\n vec3 rgb = XYZ_TO_RGB * xyz;\n return rgb;\n }\n\n vec3 evalIridescenceSpecular(float outsideIOR, float dotNV, float thinIOR, vec3 baseF0, float baseF90, float iridescenceThickness){ \n vec3 iridescence = vec3(1.0);\n // Force iridescenceIOR -> outsideIOR when thinFilmThickness -> 0.0\n float iridescenceIOR = mix( outsideIOR, thinIOR, smoothstep( 0.0, 0.03, iridescenceThickness ) );\n // Evaluate the cosTheta on the base layer (Snell law)\n float sinTheta2Sq = pow( outsideIOR / iridescenceIOR, 2.0) * (1.0 - pow( dotNV, 2.0));\n float cosTheta2Sq = 1.0 - sinTheta2Sq;\n // Handle total internal reflection\n if (cosTheta2Sq < 0.0) {\n return iridescence;\n }\n float cosTheta2 = sqrt(cosTheta2Sq);\n \n // First interface\n float f0 = iorToFresnel0(iridescenceIOR, outsideIOR);\n float reflectance = F_Schlick(f0, baseF90, dotNV);\n float t121 = 1.0 - reflectance;\n float phi12 = 0.0;\n // iridescenceIOR has limited greater than 1.0\n // if (iridescenceIOR < outsideIOR) {phi12 = PI;} \n float phi21 = PI - phi12;\n \n // Second interface\n vec3 baseIOR = fresnelToIOR(clamp(baseF0, 0.0, 0.9999)); // guard against 1.0\n vec3 r1 = iorToFresnel0(baseIOR, iridescenceIOR);\n vec3 r23 = F_Schlick(r1, baseF90, cosTheta2);\n vec3 phi23 =vec3(0.0);\n if (baseIOR[0] < iridescenceIOR) {phi23[0] = PI;}\n if (baseIOR[1] < iridescenceIOR) {phi23[1] = PI;}\n if (baseIOR[2] < iridescenceIOR) {phi23[2] = PI;}\n \n // Phase shift\n float opd = 2.0 * iridescenceIOR * iridescenceThickness * cosTheta2;\n vec3 phi = vec3(phi21) + phi23;\n \n // Compound terms\n vec3 r123 = clamp(reflectance * r23, 1e-5, 0.9999);\n vec3 sr123 = sqrt(r123);\n vec3 rs = pow2(t121) * r23 / (vec3(1.0) - r123);\n // Reflectance term for m = 0 (DC term amplitude)\n vec3 c0 = reflectance + rs;\n iridescence = c0;\n // Reflectance term for m > 0 (pairs of diracs)\n vec3 cm = rs - t121;\n for (int m = 1; m <= 2; ++m) {\n cm *= sr123;\n vec3 sm = 2.0 * evalSensitivity(float(m) * opd, float(m) * phi);\n iridescence += cm * sm;\n }\n return iridescence = max(iridescence, vec3(0.0)); \n }\n#endif\n\n// GGX Distribution, Schlick Fresnel, GGX-Smith Visibility\nvec3 BRDF_Specular_GGX(vec3 incidentDirection, Geometry geometry, Material material, 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 vec3 F = F_Schlick( specularColor, material.specularF90, dotLH );\n #ifdef MATERIAL_ENABLE_IRIDESCENCE\n F = mix(F, material.iridescenceSpecularColor, material.iridescenceFactor);\n #endif\n\n #ifdef MATERIAL_ENABLE_ANISOTROPY\n float GD = DG_GGX_anisotropic(halfDir, incidentDirection, geometry, alpha, dotNV, dotNL, dotNH);\n #else\n float GD = DG_GGX(alpha, dotNV, dotNL, dotNH);\n #endif\n\n return F * GD;\n}\n\nvec3 BRDF_Diffuse_Lambert(vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\n"; // eslint-disable-line
9849
9849
  var direct_irradiance_frag_define = "#include <ShadowFragmentDeclaration>\n\nvoid sheenLobe(Geometry geometry, Material material, vec3 incidentDirection, vec3 attenuationIrradiance, inout vec3 diffuseColor, inout vec3 specularColor){\n #ifdef MATERIAL_ENABLE_SHEEN\n diffuseColor *= material.sheenScaling;\n specularColor *= material.sheenScaling;\n\n specularColor += attenuationIrradiance * sheenBRDF(incidentDirection, geometry, material.sheenColor, material.sheenRoughness);\n #endif\n}\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, material, geometry.clearCoatNormal, vec3( 0.04 ), material.clearCoatRoughness );\n attenuation -= material.clearCoat * F_Schlick(0.04, 1.0, 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, material, geometry.normal, material.specularF0, material.roughness) * material.energyCompensation;\n reflectedLight.directDiffuse += attenuation * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\n // Sheen Lobe\n sheenLobe(geometry, material, incidentDirection, attenuation * irradiance, reflectedLight.directDiffuse, reflectedLight.directSpecular);\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\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
9850
- var ibl_frag_define = "// ------------------------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// Returns raw DFG approximation coefficients (split-sum LUT approximation)\nvec2 envDFGApprox(float roughness, float dotNV) {\n const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n return vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\n\n// ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile\nvec3 envBRDFApprox(vec3 f0, float f90, float roughness, float dotNV ) {\n vec2 AB = envDFGApprox(roughness, dotNV);\n return f0 * AB.x + f90 * AB.y;\n}\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 #elif defined(ENGINE_NO_SRGB)\n envMapColor = sRGBToLinear(envMapColor);\n #endif\n \n return envMapColor.rgb * specularIntensity;\n\n #endif\n\n}\n\n\nvoid evaluateSheenIBL(Geometry geometry, Material material, float radianceAttenuation, inout vec3 diffuseColor, inout vec3 specularColor){\n #ifdef MATERIAL_ENABLE_SHEEN\n diffuseColor *= material.sheenScaling;\n specularColor *= material.sheenScaling;\n\n vec3 reflectance = material.specularAO * radianceAttenuation * material.approxIBLSheenDG * material.sheenColor;\n specularColor += reflectance;\n #endif\n}"; // eslint-disable-line
9850
+ var ibl_frag_define = "// ------------------------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// Returns raw DFG approximation coefficients (split-sum LUT approximation)\nvec2 envDFGApprox(float roughness, float dotNV) {\n const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n return vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\n\n// ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile\nvec3 envBRDFApprox(vec3 f0, float f90, float roughness, float dotNV ) {\n vec2 AB = envDFGApprox(roughness, dotNV);\n return f0 * AB.x + f90 * AB.y;\n}\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 ENGINE_NO_SRGB\n envMapColor = sRGBToLinear(envMapColor);\n #endif\n \n return envMapColor.rgb * specularIntensity;\n\n #endif\n\n}\n\n\nvoid evaluateSheenIBL(Geometry geometry, Material material, float radianceAttenuation, inout vec3 diffuseColor, inout vec3 specularColor){\n #ifdef MATERIAL_ENABLE_SHEEN\n diffuseColor *= material.sheenScaling;\n specularColor *= material.sheenScaling;\n\n vec3 reflectance = material.specularAO * radianceAttenuation * material.approxIBLSheenDG * material.sheenColor;\n specularColor += reflectance;\n #endif\n}"; // eslint-disable-line
9851
9851
  var pbr_frag = "Geometry 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 irradiance *= scene_EnvMapLight.diffuseIntensity;\n#else\n vec3 irradiance = scene_EnvMapLight.diffuse * scene_EnvMapLight.diffuseIntensity;\n irradiance *= PI;\n#endif\n\nreflectedLight.indirectDiffuse += material.diffuseAO * 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// IBL Clear Coat\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 += material.specularAO * clearCoatRadiance * material.clearCoat * envBRDFApprox(vec3( 0.04 ), 1.0, material.clearCoatRoughness, geometry.clearCoatDotNV);\n radianceAttenuation -= material.clearCoat * F_Schlick(0.04, 1.0, geometry.clearCoatDotNV);\n#endif\n\nreflectedLight.indirectSpecular += material.specularAO * radianceAttenuation * radiance * envBRDFApprox(material.resolvedSpecularF0, material.specularF90, material.roughness, geometry.dotNV) * material.energyCompensation;\n\n\n// IBL Sheen\nevaluateSheenIBL(geometry, material, radianceAttenuation, reflectedLight.indirectDiffuse, reflectedLight.indirectSpecular);\n\n\n// Final color\nvec3 totalDiffuseColor = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\nvec3 totalSpecularColor = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\n#ifdef MATERIAL_ENABLE_TRANSMISSION \n vec3 refractionTransmitted = evaluateTransmission(geometry, material);\n totalDiffuseColor = mix(totalDiffuseColor, refractionTransmitted, material.transmission);\n#endif\n\nvec4 finalColor = vec4(totalDiffuseColor + totalSpecularColor, material.opacity);\n\n\n// Emissive\nvec3 emissiveRadiance = material_EmissiveColor;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\n emissiveRadiance *= texture2DSRGB(material_EmissiveTexture, v_uv).rgb;\n#endif\n\nfinalColor.rgb += emissiveRadiance;\n\n\ngl_FragColor = finalColor;\n"; // eslint-disable-line
9852
9852
  var btdf = "#include <refraction>\n\n#ifdef MATERIAL_ENABLE_TRANSMISSION \n uniform sampler2D camera_OpaqueTexture;\n vec3 evaluateTransmission(Geometry geometry, Material material) {\n RefractionModelResult ray;\n #if REFRACTION_MODE == 0 \n // RefractionMode.Sphere\n refractionModelSphere(-geometry.viewDir, geometry.position, geometry.normal, material.IOR, material.thickness, ray);\n #elif REFRACTION_MODE == 1\n // RefractionMode.Planar\n refractionModelPlanar(-geometry.viewDir, geometry.position, geometry.normal, material.IOR, material.thickness, ray);\n #endif\n\n vec3 refractedRayExit = ray.positionExit;\n\n // We calculate the screen space position of the refracted point\n vec4 samplingPositionNDC = camera_ProjMat * camera_ViewMat * vec4( refractedRayExit, 1.0 );\n vec2 refractionCoords = (samplingPositionNDC.xy / samplingPositionNDC.w) * 0.5 + 0.5;\n\n // Sample the opaque texture to get the transmitted light\n vec3 refractionTransmitted = texture2DSRGB(camera_OpaqueTexture, refractionCoords).rgb;\n refractionTransmitted *= material.diffuseColor;\n \n // Use specularFGD as an approximation of the fresnel effect\n // https://blog.selfshadow.com/publications/s2017-shading-course/imageworks/s2017_pbs_imageworks_slides_v2.pdf\n refractionTransmitted *= (1.0 - material.envSpecularDFG);\n\n #ifdef MATERIAL_HAS_THICKNESS\n // Absorption coefficient from Disney: http://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf\n vec3 transmittance = min(vec3(1.0), exp(-material.absorptionCoefficient * ray.transmissionLength));\n refractionTransmitted *= transmittance;\n #endif\n \n return refractionTransmitted;\n }\n#endif"; // eslint-disable-line
9853
9853
  var refraction = "#ifdef MATERIAL_ENABLE_TRANSMISSION \n\tstruct RefractionModelResult {\n\t float transmissionLength; // length of the transmission during refraction through the shape\n\t vec3 positionExit; // out ray position\n\t // vec3 directionExit; // out ray direction\n\t};\n\n\t//https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@15.0/manual/refraction-models.html\n\t void refractionModelSphere(vec3 V, vec3 positionWS, vec3 normalWS, float ior, float thickness, out RefractionModelResult ray) {\n\t // Refracted ray\n\t vec3 R1 = refract(V, normalWS, 1.0 / ior);\n\t // Center of the tangent sphere\n\t // vec3 C = positionWS - normalWS * thickness * 0.5;\n\n\t // Second refraction (tangent sphere out)\n\t float dist = dot(-normalWS, R1) * thickness;\n\t // Out hit point in the tangent sphere\n\t vec3 P1 = positionWS + R1 * dist;\n\t // Out normal\n\t // vec3 N1 = safeNormalize(C - P1);\n\t // Out refracted ray\n\t // vec3 R2 = refract(R1, N1, ior);\n\n\t ray.transmissionLength = dist;\n\t ray.positionExit = P1;\n\t // ray.directionExit = R2; \n\t}\n\n\tvoid refractionModelPlanar(vec3 V, vec3 positionWS, vec3 normalWS, float ior, float thickness, out RefractionModelResult ray) {\n\t // Refracted ray\n\t vec3 R = refract(V, normalWS, 1.0 / ior);\n\t // Optical depth within the thin plane\n\t float dist = thickness / max(dot(-normalWS, R), 1e-5f);\n\n\t ray.transmissionLength = dist;\n\t ray.positionExit = vec3(positionWS + R * dist);\n\t // ray.directionExit = V;\n\t}\n\n#endif"; // eslint-disable-line
@@ -28932,7 +28932,6 @@
28932
28932
  /** Sprite Atlas. */ AssetType["SpriteAtlas"] = "SpriteAtlas";
28933
28933
  /** Ambient light. */ AssetType["Env"] = "Environment";
28934
28934
  /** Scene. */ AssetType["Scene"] = "Scene";
28935
- /** HDR to cube. */ AssetType["HDR"] = "HDR";
28936
28935
  /** Font. */ AssetType["Font"] = "Font";
28937
28936
  /** Source Font, include ttf, otf and woff. */ AssetType["SourceFont"] = "SourceFont";
28938
28937
  /** AudioClip, include ogg, wav and mp3. */ AssetType["Audio"] = "Audio";
@@ -29346,7 +29345,6 @@
29346
29345
  this._contentRestorerPool = Object.create(null);
29347
29346
  this._subAssetPromiseCallbacks = {};
29348
29347
  this./** @internal */ _objectPool = Object.create(null);
29349
- this./** @internal */ _idResourceMap = Object.create(null);
29350
29348
  this./** @internal */ _virtualPathResourceMap = Object.create(null);
29351
29349
  }
29352
29350
  var _proto = ResourceManager.prototype;
@@ -29745,30 +29743,29 @@
29745
29743
  * @internal
29746
29744
  * @beta Just for internal editor, not recommended for developers.
29747
29745
  */ _proto.getResourceByRef = function getResourceByRef(ref) {
29748
- var refId = ref.refId, key = ref.key, isClone = ref.isClone;
29749
- var obj = this._objectPool[refId];
29750
- var promise;
29751
- if (obj) {
29752
- promise = AssetPromise.resolve(obj);
29753
- } else {
29754
- var resourceConfig = this._idResourceMap[refId];
29755
- if (!resourceConfig) {
29756
- Logger.warn("refId:" + refId + " is not find in this._idResourceMap.");
29757
- return AssetPromise.resolve(null);
29758
- }
29759
- var url = resourceConfig.virtualPath;
29760
- if (key) {
29761
- url += "?q=" + key;
29762
- }
29763
- promise = this.load({
29764
- url: url,
29765
- type: resourceConfig.type,
29766
- params: resourceConfig.params
29767
- });
29746
+ var url = ref.url, key = ref.key, isClone = ref.isClone;
29747
+ if (!url) {
29748
+ Logger.warn("ResourceManager.getResourceByRef: url is empty.");
29749
+ return AssetPromise.resolve(null);
29750
+ }
29751
+ var cached = this._objectPool[url];
29752
+ if (cached) {
29753
+ return AssetPromise.resolve(isClone ? cached.clone() : cached);
29754
+ }
29755
+ var mapped = this._virtualPathResourceMap[url];
29756
+ if (!mapped) {
29757
+ Logger.warn('ResourceManager.getResourceByRef: url "' + url + '" not found in virtualPathResourceMap.');
29758
+ return AssetPromise.resolve(null);
29768
29759
  }
29769
- return promise.then(function(item) {
29770
- return isClone ? item.clone() : item;
29760
+ var loadUrl = key ? url + "?q=" + key : url;
29761
+ var promise = this.load({
29762
+ url: loadUrl,
29763
+ type: mapped.type,
29764
+ params: mapped.params
29771
29765
  });
29766
+ return isClone ? promise.then(function(item) {
29767
+ return item.clone();
29768
+ }) : promise;
29772
29769
  };
29773
29770
  /**
29774
29771
  * @internal
@@ -29777,7 +29774,6 @@
29777
29774
  var _this = this;
29778
29775
  config.forEach(function(element) {
29779
29776
  _this._virtualPathResourceMap[element.virtualPath] = element;
29780
- _this._idResourceMap[element.id] = element;
29781
29777
  if (element.dependentAssetMap) {
29782
29778
  _this._virtualPathResourceMap[element.virtualPath].dependentAssetMap = element.dependentAssetMap;
29783
29779
  }
@@ -31095,7 +31091,7 @@
31095
31091
  var pbrVs = "#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#include <PositionClipSpaceDeclaration>\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 #include <PositionClipSpaceVertex>\n}\n"; // eslint-disable-line
31096
31092
  var shadowMapFs = "#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\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
31097
31093
  var shadowMapVs = "#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\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
31098
- var skyboxFs = "#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_NO_SRGB)\n textureColor = sRGBToLinear(textureColor);\n #endif\n\n textureColor.rgb *= material_Exposure * material_TintColor.rgb;\n \n gl_FragColor = textureColor;\n}\n"; // eslint-disable-line
31094
+ var skyboxFs = "#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 ENGINE_NO_SRGB\n textureColor = sRGBToLinear(textureColor);\n #endif\n\n textureColor.rgb *= material_Exposure * material_TintColor.rgb;\n \n gl_FragColor = textureColor;\n}\n"; // eslint-disable-line
31099
31095
  var skyboxVs = "#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
31100
31096
  var spriteMaskFs = "uniform 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
31101
31097
  var spriteMaskVs = "uniform 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
@@ -32260,7 +32256,7 @@
32260
32256
  _inherits$2(AmbientLight, ReferResource);
32261
32257
  function AmbientLight(engine) {
32262
32258
  var _this;
32263
- _this = ReferResource.call(this, engine) || this, _this._diffuseSolidColor = new Color(0.03696758874771872, 0.0421494543549785, 0.05455383078270364), _this._diffuseIntensity = 1.0, _this._specularIntensity = 1.0, _this._diffuseMode = DiffuseMode.SolidColor, _this._shArray = new Float32Array(27), _this._scenes = [], _this._specularTextureDecodeRGBM = false;
32259
+ _this = ReferResource.call(this, engine) || this, _this._diffuseSolidColor = new Color(0.03696758874771872, 0.0421494543549785, 0.05455383078270364), _this._diffuseIntensity = 1.0, _this._specularIntensity = 1.0, _this._diffuseMode = DiffuseMode.SolidColor, _this._shArray = new Float32Array(27), _this._scenes = [];
32264
32260
  return _this;
32265
32261
  }
32266
32262
  var _proto = AmbientLight.prototype;
@@ -32275,7 +32271,6 @@
32275
32271
  shaderData.setFloat(AmbientLight._specularIntensityProperty, this._specularIntensity);
32276
32272
  shaderData.setFloatArray(AmbientLight._diffuseSHProperty, this._shArray);
32277
32273
  this._setDiffuseMode(shaderData);
32278
- this._setSpecularTextureDecodeRGBM(shaderData);
32279
32274
  this._setSpecularTexture(shaderData);
32280
32275
  };
32281
32276
  /**
@@ -32305,13 +32300,6 @@
32305
32300
  sceneShaderData.disableMacro(AmbientLight._specularMacro);
32306
32301
  }
32307
32302
  };
32308
- _proto._setSpecularTextureDecodeRGBM = function _setSpecularTextureDecodeRGBM(sceneShaderData) {
32309
- if (this._specularTextureDecodeRGBM) {
32310
- sceneShaderData.enableMacro(AmbientLight._decodeRGBMMacro);
32311
- } else {
32312
- sceneShaderData.disableMacro(AmbientLight._decodeRGBMMacro);
32313
- }
32314
- };
32315
32303
  _proto._preComputeSH = function _preComputeSH(sh, out) {
32316
32304
  /**
32317
32305
  * Basis constants
@@ -32366,21 +32354,6 @@
32366
32354
  out[26] = src[26] * 0.429042;
32367
32355
  };
32368
32356
  _create_class$2(AmbientLight, [
32369
- {
32370
- key: "specularTextureDecodeRGBM",
32371
- get: /**
32372
- * Whether to decode from specularTexture with RGBM format.
32373
- */ function get() {
32374
- return this._specularTextureDecodeRGBM;
32375
- },
32376
- set: function set(value) {
32377
- this._specularTextureDecodeRGBM = value;
32378
- var scenes = this._scenes;
32379
- for(var i = 0, n = scenes.length; i < n; i++){
32380
- this._setSpecularTextureDecodeRGBM(scenes[i].shaderData);
32381
- }
32382
- }
32383
- },
32384
32357
  {
32385
32358
  key: "diffuseMode",
32386
32359
  get: /**
@@ -32478,7 +32451,6 @@
32478
32451
  }(ReferResource);
32479
32452
  AmbientLight._shMacro = ShaderMacro.getByName("SCENE_USE_SH");
32480
32453
  AmbientLight._specularMacro = ShaderMacro.getByName("SCENE_USE_SPECULAR_ENV");
32481
- AmbientLight._decodeRGBMMacro = ShaderMacro.getByName("SCENE_IS_DECODE_ENV_RGBM");
32482
32454
  AmbientLight._diffuseColorProperty = ShaderProperty.getByName("scene_EnvMapLight.diffuse");
32483
32455
  AmbientLight._diffuseSHProperty = ShaderProperty.getByName("scene_EnvSH");
32484
32456
  AmbientLight._diffuseIntensityProperty = ShaderProperty.getByName("scene_EnvMapLight.diffuseIntensity");
@@ -37453,7 +37425,7 @@
37453
37425
  _inherits$2(SkyBoxMaterial, Material);
37454
37426
  function SkyBoxMaterial(engine) {
37455
37427
  var _this;
37456
- _this = Material.call(this, engine, Shader.find("skybox")) || this, _this._textureDecodeRGBM = false, _this._tintColor = new Color(1, 1, 1, 1);
37428
+ _this = Material.call(this, engine, Shader.find("skybox")) || this, _this._tintColor = new Color(1, 1, 1, 1);
37457
37429
  _this.renderState.rasterState.cullMode = CullMode.Off;
37458
37430
  _this.renderState.depthState.compareFunction = CompareFunction.LessEqual;
37459
37431
  _this.shaderData.setFloat(SkyBoxMaterial._rotationProp, 0);
@@ -37468,22 +37440,6 @@
37468
37440
  return dest;
37469
37441
  };
37470
37442
  _create_class$2(SkyBoxMaterial, [
37471
- {
37472
- key: "textureDecodeRGBM",
37473
- get: /**
37474
- * Whether to decode texture with RGBM format.
37475
- */ function get() {
37476
- return this._textureDecodeRGBM;
37477
- },
37478
- set: function set(value) {
37479
- this._textureDecodeRGBM = value;
37480
- if (value) {
37481
- this.shaderData.enableMacro(SkyBoxMaterial._decodeSkyRGBMMacro);
37482
- } else {
37483
- this.shaderData.disableMacro(SkyBoxMaterial._decodeSkyRGBMMacro);
37484
- }
37485
- }
37486
- },
37487
37443
  {
37488
37444
  key: "texture",
37489
37445
  get: /**
@@ -37537,7 +37493,6 @@
37537
37493
  SkyBoxMaterial._textureCubeProp = ShaderProperty.getByName("material_CubeTexture");
37538
37494
  SkyBoxMaterial._rotationProp = ShaderProperty.getByName("material_Rotation");
37539
37495
  SkyBoxMaterial._exposureProp = ShaderProperty.getByName("material_Exposure");
37540
- SkyBoxMaterial._decodeSkyRGBMMacro = ShaderMacro.getByName("MATERIAL_IS_DECODE_SKY_RGBM");
37541
37496
  /**
37542
37497
  * Sun mode.
37543
37498
  */ var SunMode = /*#__PURE__*/ function(SunMode) {
@@ -45757,7 +45712,9 @@
45757
45712
  decoderMap[type] = target;
45758
45713
  };
45759
45714
  }
45760
- var FileHeader = /*#__PURE__*/ function() {
45715
+ /**
45716
+ * Binary format: [MAGIC(4B)] [totalLength(4B)] [version(1B)] [typeLen(2B)] [type] [nameLen(2B)] [name] [data...]
45717
+ */ var FileHeader = /*#__PURE__*/ function() {
45761
45718
  function FileHeader() {
45762
45719
  this.totalLength = 0;
45763
45720
  this.version = 0;
@@ -45765,14 +45722,23 @@
45765
45722
  this.name = "";
45766
45723
  this.headerLength = 0;
45767
45724
  }
45725
+ FileHeader.checkMagic = function checkMagic(arrayBuffer) {
45726
+ if (arrayBuffer.byteLength < 4) return false;
45727
+ var view = new DataView(arrayBuffer);
45728
+ return view.getUint32(0, true) === FileHeader.MAGIC;
45729
+ };
45768
45730
  FileHeader.decode = function decode(arrayBuffer) {
45769
45731
  var dataView = new DataView(arrayBuffer);
45770
- var totalLen = dataView.getUint32(0, true);
45771
- var fileVersion = dataView.getUint8(4);
45772
- var typeLen = dataView.getUint16(5, true);
45773
- var typeUint8Array = new Uint8Array(arrayBuffer, 7, typeLen);
45774
- var nameLen = dataView.getUint16(7 + typeLen, true);
45775
- var nameUint8Array = new Uint8Array(arrayBuffer, 9 + typeLen, nameLen);
45732
+ if (!FileHeader.checkMagic(arrayBuffer)) {
45733
+ throw new Error("Invalid Galacean binary file: missing GLCN magic header.");
45734
+ }
45735
+ var offset = 4;
45736
+ var totalLen = dataView.getUint32(offset, true);
45737
+ var fileVersion = dataView.getUint8(offset + 4);
45738
+ var typeLen = dataView.getUint16(offset + 5, true);
45739
+ var typeUint8Array = new Uint8Array(arrayBuffer, offset + 7, typeLen);
45740
+ var nameLen = dataView.getUint16(offset + 7 + typeLen, true);
45741
+ var nameUint8Array = new Uint8Array(arrayBuffer, offset + 9 + typeLen, nameLen);
45776
45742
  var name = Utils.decodeText(nameUint8Array);
45777
45743
  var type = Utils.decodeText(typeUint8Array);
45778
45744
  var header = new FileHeader();
@@ -45780,7 +45746,7 @@
45780
45746
  header.name = name;
45781
45747
  header.type = type;
45782
45748
  header.version = fileVersion;
45783
- header.headerLength = nameUint8Array.byteLength + typeUint8Array.byteLength + 9;
45749
+ header.headerLength = offset + nameUint8Array.byteLength + typeUint8Array.byteLength + 9;
45784
45750
  return header;
45785
45751
  };
45786
45752
  _create_class(FileHeader, [
@@ -45793,6 +45759,8 @@
45793
45759
  ]);
45794
45760
  return FileHeader;
45795
45761
  }();
45762
+ FileHeader.MAGIC = 0x4e434c47 // "GLCN" in little-endian
45763
+ ;
45796
45764
  var InterpolableValueType = /*#__PURE__*/ function(InterpolableValueType) {
45797
45765
  InterpolableValueType[InterpolableValueType["Float"] = 0] = "Float";
45798
45766
  InterpolableValueType[InterpolableValueType["FloatArray"] = 1] = "FloatArray";
@@ -46193,12 +46161,12 @@
46193
46161
  this.rootIds.length = 0;
46194
46162
  this.strippedIds.length = 0;
46195
46163
  };
46196
- /** @internal */ _proto._addDependentAsset = function _addDependentAsset(refID, promise) {
46164
+ /** @internal */ _proto._addDependentAsset = function _addDependentAsset(url, promise) {
46197
46165
  var _this = this;
46198
46166
  var tasks = this._tasks;
46199
- if (tasks.has(refID)) return;
46167
+ if (tasks.has(url)) return;
46200
46168
  ++this._total;
46201
- tasks.add(refID);
46169
+ tasks.add(url);
46202
46170
  promise.finally(function() {
46203
46171
  ++_this._loaded;
46204
46172
  _this._setTaskCompleteProgress(_this._loaded, _this._total);
@@ -46305,7 +46273,7 @@
46305
46273
  // reference object
46306
46274
  // @ts-ignore
46307
46275
  return context.resourceManager.getResourceByRef(value).then(function(resource) {
46308
- if (context.type === ParserType.Prefab) {
46276
+ if (resource && context.type === ParserType.Prefab) {
46309
46277
  // @ts-ignore
46310
46278
  context.resource._addDependenceAsset(resource);
46311
46279
  }
@@ -46348,18 +46316,18 @@
46348
46316
  _proto._getEntityByConfig = function _getEntityByConfig(entityConfig) {
46349
46317
  var _this = this;
46350
46318
  // @ts-ignore
46351
- var assetRefId = entityConfig.assetRefId;
46319
+ var assetUrl = entityConfig.assetUrl;
46352
46320
  var engine = this._context.engine;
46353
- if (assetRefId) {
46321
+ if (assetUrl) {
46354
46322
  return engine.resourceManager // @ts-ignore
46355
46323
  .getResourceByRef({
46356
- refId: assetRefId,
46324
+ url: assetUrl,
46357
46325
  key: entityConfig.key,
46358
46326
  isClone: entityConfig.isClone
46359
46327
  }).then(function(entity) {
46360
46328
  // @ts-ignore
46361
- var resource = engine.resourceManager._objectPool[assetRefId];
46362
- if (_this._context.type === ParserType.Prefab) {
46329
+ var resource = engine.resourceManager._objectPool[assetUrl];
46330
+ if (resource && _this._context.type === ParserType.Prefab) {
46363
46331
  // @ts-ignore
46364
46332
  _this._context.resource._addDependenceAsset(resource);
46365
46333
  }
@@ -46382,7 +46350,7 @@
46382
46350
  return value["classType"] !== undefined;
46383
46351
  };
46384
46352
  ReflectionParser._isAssetRef = function _isAssetRef(value) {
46385
- return value["refId"] !== undefined;
46353
+ return value["url"] !== undefined;
46386
46354
  };
46387
46355
  ReflectionParser._isEntityRef = function _isEntityRef(value) {
46388
46356
  return value["entityId"] !== undefined;
@@ -46400,7 +46368,7 @@
46400
46368
  function Texture2DDecoder() {}
46401
46369
  Texture2DDecoder.decode = function decode(engine, bufferReader, restoredTexture) {
46402
46370
  return new AssetPromise(function(resolve, reject) {
46403
- var objectId = bufferReader.nextStr();
46371
+ var url = bufferReader.nextStr();
46404
46372
  var mipmap = !!bufferReader.nextUint8();
46405
46373
  var filterMode = bufferReader.nextUint8();
46406
46374
  var anisoLevel = bufferReader.nextUint8();
@@ -46429,7 +46397,7 @@
46429
46397
  }
46430
46398
  }
46431
46399
  // @ts-ignore
46432
- engine.resourceManager._objectPool[objectId] = texture2D;
46400
+ engine.resourceManager._objectPool[url] = texture2D;
46433
46401
  resolve(texture2D);
46434
46402
  } else {
46435
46403
  var blob = new window.Blob([
@@ -46723,7 +46691,7 @@
46723
46691
  _proto._getEntityByConfig = function _getEntityByConfig(entityConfig, engine) {
46724
46692
  var _this = this;
46725
46693
  var entityPromise;
46726
- if (entityConfig.assetRefId) {
46694
+ if (entityConfig.assetUrl) {
46727
46695
  entityPromise = this._parsePrefab(entityConfig, engine);
46728
46696
  } else if (entityConfig.strippedId) {
46729
46697
  entityPromise = this._parseStrippedEntity(entityConfig);
@@ -46743,10 +46711,10 @@
46743
46711
  };
46744
46712
  _proto._parsePrefab = function _parsePrefab(entityConfig, engine) {
46745
46713
  var _this = this;
46746
- var assetRefId = entityConfig.assetRefId;
46714
+ var assetUrl = entityConfig.assetUrl;
46747
46715
  return engine.resourceManager // @ts-ignore
46748
46716
  .getResourceByRef({
46749
- refId: assetRefId
46717
+ url: assetUrl
46750
46718
  }).then(function(prefabResource) {
46751
46719
  var entity = _instanceof1(prefabResource, PrefabResource) ? prefabResource.instantiate() : prefabResource.instantiateSceneRoot();
46752
46720
  var instanceContext = new ParserContext(engine, ParserType.Prefab, null);
@@ -46797,7 +46765,7 @@
46797
46765
  var componentConfigMap = context.componentConfigMap;
46798
46766
  for(var i = 0, n = components.length; i < n; i++){
46799
46767
  var componentConfig = components[i];
46800
- var key = !componentConfig.refId ? componentConfig.class : componentConfig.refId;
46768
+ var key = !componentConfig.url ? componentConfig.class : componentConfig.url;
46801
46769
  var componentId = componentConfig.id;
46802
46770
  var component = entity.addComponent(Loader.getClass(key));
46803
46771
  componentMap.set(componentId, component);
@@ -46844,52 +46812,6 @@
46844
46812
  _proto._addEntityPlugin = function _addEntityPlugin(entityId, entity) {};
46845
46813
  return HierarchyParser;
46846
46814
  }();
46847
- exports.EditorTextureLoader = /*#__PURE__*/ function(Loader) {
46848
- _inherits(EditorTextureLoader, Loader);
46849
- function EditorTextureLoader() {
46850
- return Loader.apply(this, arguments) || this;
46851
- }
46852
- var _proto = EditorTextureLoader.prototype;
46853
- _proto.load = function load(item, resourceManager) {
46854
- var requestConfig = _extends({}, item, {
46855
- type: "arraybuffer"
46856
- });
46857
- var url = item.url;
46858
- return new AssetPromise(function(resolve, reject) {
46859
- resourceManager // @ts-ignore
46860
- ._request(url, requestConfig).then(function(data) {
46861
- decode(data, resourceManager.engine).then(function(texture) {
46862
- resourceManager.addContentRestorer(new EditorTexture2DContentRestorer(texture, url, requestConfig));
46863
- resolve(texture);
46864
- });
46865
- }).catch(reject);
46866
- });
46867
- };
46868
- return EditorTextureLoader;
46869
- }(Loader);
46870
- exports.EditorTextureLoader = __decorate([
46871
- resourceLoader("EditorTexture2D", [
46872
- "prefab"
46873
- ], true)
46874
- ], exports.EditorTextureLoader);
46875
- var EditorTexture2DContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
46876
- _inherits(EditorTexture2DContentRestorer, ContentRestorer);
46877
- function EditorTexture2DContentRestorer(resource, url, requestConfig) {
46878
- var _this;
46879
- _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
46880
- return _this;
46881
- }
46882
- var _proto = EditorTexture2DContentRestorer.prototype;
46883
- _proto.restoreContent = function restoreContent() {
46884
- var texture = this.resource;
46885
- var engine = texture.engine;
46886
- return engine.resourceManager // @ts-ignore
46887
- ._request(this.url, this.requestConfig).then(function(data) {
46888
- return decode(data, engine, texture);
46889
- });
46890
- };
46891
- return EditorTexture2DContentRestorer;
46892
- }(ContentRestorer);
46893
46815
  var MaterialLoaderType = /*#__PURE__*/ function(MaterialLoaderType) {
46894
46816
  MaterialLoaderType["Vector2"] = "Vector2";
46895
46817
  MaterialLoaderType["Vector3"] = "Vector3";
@@ -46928,11 +46850,11 @@
46928
46850
  var customAmbientLight = ambient.customAmbientLight, ambientLight = ambient.ambientLight;
46929
46851
  if (useCustomAmbient && customAmbientLight) {
46930
46852
  // @ts-ignore
46931
- context._addDependentAsset(customAmbientLight.refId, resourceManager.getResourceByRef(customAmbientLight));
46853
+ context._addDependentAsset(customAmbientLight.url, resourceManager.getResourceByRef(customAmbientLight));
46932
46854
  }
46933
46855
  if (ambientLight && (!useCustomAmbient || useSH)) {
46934
46856
  // @ts-ignore
46935
- context._addDependentAsset(ambientLight.refId, resourceManager.getResourceByRef(ambientLight));
46857
+ context._addDependentAsset(ambientLight.url, resourceManager.getResourceByRef(ambientLight));
46936
46858
  }
46937
46859
  }
46938
46860
  var background = scene.background;
@@ -46940,14 +46862,14 @@
46940
46862
  if (backgroundMode === BackgroundMode.Texture) {
46941
46863
  var texture = background.texture;
46942
46864
  // @ts-ignore
46943
- texture && context._addDependentAsset(texture.refId, resourceManager.getResourceByRef(texture));
46865
+ texture && context._addDependentAsset(texture.url, resourceManager.getResourceByRef(texture));
46944
46866
  } else if (backgroundMode === BackgroundMode.Sky) {
46945
46867
  var skyMesh = background.skyMesh, skyMaterial = background.skyMaterial;
46946
46868
  if (skyMesh && skyMaterial) {
46947
46869
  // @ts-ignore
46948
- context._addDependentAsset(skyMesh.refId, resourceManager.getResourceByRef(skyMesh));
46870
+ context._addDependentAsset(skyMesh.url, resourceManager.getResourceByRef(skyMesh));
46949
46871
  // @ts-ignore
46950
- context._addDependentAsset(skyMaterial.refId, resourceManager.getResourceByRef(skyMaterial));
46872
+ context._addDependentAsset(skyMaterial.url, resourceManager.getResourceByRef(skyMaterial));
46951
46873
  }
46952
46874
  }
46953
46875
  };
@@ -46963,12 +46885,12 @@
46963
46885
  var entities = file.entities;
46964
46886
  for(var i = 0, n = entities.length; i < n; i++){
46965
46887
  var entity = entities[i];
46966
- if (!!entity.assetRefId) {
46888
+ if (!!entity.assetUrl) {
46967
46889
  var context = this.context;
46968
- var refId = entity.assetRefId, key = entity.key;
46890
+ var url = entity.assetUrl, key = entity.key;
46969
46891
  // @ts-ignore
46970
- context._addDependentAsset(refId, context.resourceManager.getResourceByRef({
46971
- refId: refId,
46892
+ context._addDependentAsset(url, context.resourceManager.getResourceByRef({
46893
+ url: url,
46972
46894
  key: key
46973
46895
  }));
46974
46896
  } else if (entity.strippedId) {
@@ -46993,7 +46915,7 @@
46993
46915
  if (ReflectionParser._isAssetRef(value)) {
46994
46916
  var context = this.context;
46995
46917
  // @ts-ignore
46996
- context._addDependentAsset(value.refId, context.resourceManager.getResourceByRef(value));
46918
+ context._addDependentAsset(value.url, context.resourceManager.getResourceByRef(value));
46997
46919
  } else {
46998
46920
  for(var key in value){
46999
46921
  this._searchDependentAssets(value[key]);
@@ -47055,7 +46977,7 @@
47055
46977
  };
47056
46978
  _proto._parseKeyframeValue = function _parseKeyframeValue(keyframe, resourceManager) {
47057
46979
  var value = keyframe.value;
47058
- if ((typeof value === "undefined" ? "undefined" : _type_of1(value)) === "object" && (value == null ? void 0 : value.refId)) {
46980
+ if ((typeof value === "undefined" ? "undefined" : _type_of1(value)) === "object" && (value == null ? void 0 : value.url)) {
47059
46981
  return new Promise(function(resolve) {
47060
46982
  resourceManager // @ts-ignore
47061
46983
  .getResourceByRef(value).then(function(asset) {
@@ -47071,7 +46993,7 @@
47071
46993
  }(Loader);
47072
46994
  AnimationClipLoader = __decorate([
47073
46995
  resourceLoader(AssetType.AnimationClip, [
47074
- "ani"
46996
+ "anim"
47075
46997
  ])
47076
46998
  ], AnimationClipLoader);
47077
46999
  var AnimatorControllerLoader = /*#__PURE__*/ function(Loader1) {
@@ -47182,8 +47104,8 @@
47182
47104
  }(Loader);
47183
47105
  AnimatorControllerLoader = __decorate([
47184
47106
  resourceLoader(AssetType.AnimatorController, [
47185
- "json"
47186
- ], false)
47107
+ "animCtrl"
47108
+ ])
47187
47109
  ], AnimatorControllerLoader);
47188
47110
  var base64Regex = /^data:(.+?);base64,/;
47189
47111
  var BufferLoader = /*#__PURE__*/ function(Loader) {
@@ -47210,8 +47132,7 @@
47210
47132
  }(Loader);
47211
47133
  BufferLoader = __decorate([
47212
47134
  resourceLoader(AssetType.Buffer, [
47213
- "bin",
47214
- "r3bin"
47135
+ "bin"
47215
47136
  ])
47216
47137
  ], BufferLoader);
47217
47138
  var EnvLoader = /*#__PURE__*/ function(Loader) {
@@ -47237,7 +47158,6 @@
47237
47158
  sh.copyFromArray(new Float32Array(arraybuffer, 0, 27));
47238
47159
  ambientLight.diffuseSphericalHarmonics = sh;
47239
47160
  ambientLight.specularTexture = texture;
47240
- ambientLight.specularTextureDecodeRGBM = true;
47241
47161
  resolve(ambientLight);
47242
47162
  }).catch(function(e) {
47243
47163
  reject(e);
@@ -47250,7 +47170,7 @@
47250
47170
  var _this;
47251
47171
  var shByteLength = 27 * 4;
47252
47172
  var size = (_this = new Uint16Array(buffer, shByteLength, 1)) == null ? void 0 : _this[0];
47253
- texture || (texture = new TextureCube(engine, size, undefined, undefined, false));
47173
+ texture || (texture = new TextureCube(engine, size, TextureFormat.R16G16B16A16, true, false));
47254
47174
  texture.filterMode = TextureFilterMode.Trilinear;
47255
47175
  var mipmapCount = texture.mipmapCount;
47256
47176
  var offset = shByteLength + 2;
@@ -47258,8 +47178,8 @@
47258
47178
  var mipSize = size >> mipLevel;
47259
47179
  for(var face = 0; face < 6; face++){
47260
47180
  var dataSize = mipSize * mipSize * 4;
47261
- var data = new Uint8Array(buffer, offset, dataSize);
47262
- offset += dataSize;
47181
+ var data = new Uint16Array(buffer, offset, dataSize);
47182
+ offset += dataSize * 2;
47263
47183
  texture.setPixelBuffer(TextureCubeFace.PositiveX + face, data, mipLevel);
47264
47184
  }
47265
47185
  }
@@ -50750,340 +50670,6 @@
50750
50670
  "prefab"
50751
50671
  ])
50752
50672
  ], PrefabLoader);
50753
- var PI = Math.PI;
50754
- // referenece: https://www.flipcode.com/archives/HDR_Image_Reader.shtml
50755
- var HDRLoader = /*#__PURE__*/ function(Loader) {
50756
- _inherits(HDRLoader, Loader);
50757
- function HDRLoader() {
50758
- return Loader.apply(this, arguments) || this;
50759
- }
50760
- var _proto = HDRLoader.prototype;
50761
- _proto.load = function load(item, resourceManager) {
50762
- return new AssetPromise(function(resolve, reject) {
50763
- var engine = resourceManager.engine;
50764
- var requestConfig = _extends({}, item, {
50765
- type: "arraybuffer"
50766
- });
50767
- var url = item.url;
50768
- resourceManager // @ts-ignore
50769
- ._request(url, requestConfig).then(function(buffer) {
50770
- var texture = HDRLoader._setTextureByBuffer(engine, buffer);
50771
- engine.resourceManager.addContentRestorer(new HDRContentRestorer(texture, url, requestConfig));
50772
- resolve(texture);
50773
- }).catch(reject);
50774
- });
50775
- };
50776
- /**
50777
- * @internal
50778
- */ HDRLoader._setTextureByBuffer = function _setTextureByBuffer(engine, buffer, texture) {
50779
- var bufferArray = new Uint8Array(buffer);
50780
- var _HDRLoader__parseHeader = HDRLoader._parseHeader(bufferArray), width = _HDRLoader__parseHeader.width, height = _HDRLoader__parseHeader.height, dataPosition = _HDRLoader__parseHeader.dataPosition;
50781
- var cubeSize = height >> 1;
50782
- texture || (texture = new TextureCube(engine, cubeSize, undefined, undefined, false));
50783
- var pixels = HDRLoader._readPixels(bufferArray.subarray(dataPosition), width, height);
50784
- var cubeMapData = HDRLoader._convertToCubemap(pixels, width, height, cubeSize);
50785
- for(var faceIndex = 0; faceIndex < 6; faceIndex++){
50786
- texture.setPixelBuffer(TextureCubeFace.PositiveX + faceIndex, cubeMapData[faceIndex], 0);
50787
- }
50788
- texture.generateMipmaps();
50789
- return texture;
50790
- };
50791
- HDRLoader._convertToCubemap = function _convertToCubemap(pixels, inputWidth, inputHeight, size) {
50792
- if (!pixels) {
50793
- throw "ConvertPanoramaToCubemap: input cannot be null";
50794
- }
50795
- if (pixels.length != inputWidth * inputHeight * 4) {
50796
- throw "ConvertPanoramaToCubemap: input size is wrong";
50797
- }
50798
- var textureRight = this._createCubemapData(size, this._faceRight, pixels, inputWidth, inputHeight);
50799
- var textureLeft = this._createCubemapData(size, this._faceLeft, pixels, inputWidth, inputHeight);
50800
- var textureUp = this._createCubemapData(size, this._faceUp, pixels, inputWidth, inputHeight);
50801
- var textureDown = this._createCubemapData(size, this._faceBottom, pixels, inputWidth, inputHeight);
50802
- var textureFront = this._createCubemapData(size, this._faceFront, pixels, inputWidth, inputHeight);
50803
- var textureBack = this._createCubemapData(size, this._faceBack, pixels, inputWidth, inputHeight);
50804
- return [
50805
- textureRight,
50806
- textureLeft,
50807
- textureUp,
50808
- textureDown,
50809
- textureFront,
50810
- textureBack
50811
- ];
50812
- };
50813
- HDRLoader._createCubemapData = function _createCubemapData(texSize, faceData, pixels, inputWidth, inputHeight) {
50814
- var textureArray = new Uint8ClampedArray(texSize * texSize * 4);
50815
- var rotDX1 = this._tempVector3.set(0, 0, 0).add(faceData[1]).subtract(faceData[0]).scale(1 / texSize);
50816
- var rotDX2 = this._temp2Vector3.set(0, 0, 0).add(faceData[3]).subtract(faceData[2]).scale(1 / texSize);
50817
- var dy = 1 / texSize;
50818
- var fy = 0;
50819
- for(var y = 0; y < texSize; y++){
50820
- var xv1 = this._temp3Vector3.set(0, 0, 0).add(faceData[0]);
50821
- var xv2 = this._temp4Vector3.set(0, 0, 0).add(faceData[2]);
50822
- for(var x = 0; x < texSize; x++){
50823
- var v = this._temp5Vector3.set(0, 0, 0).add(xv2).subtract(xv1).scale(fy).add(xv1);
50824
- v.normalize();
50825
- var color = this._calcProjectionSpherical(v, pixels, inputWidth, inputHeight);
50826
- this._RGBEToLinear(color);
50827
- this._linearToRGBM(color, 5);
50828
- // 4 channels per pixels
50829
- var index = y * texSize * 4 + x * 4;
50830
- textureArray[index] = color.r;
50831
- textureArray[index + 1] = color.g;
50832
- textureArray[index + 2] = color.b;
50833
- textureArray[index + 3] = color.a;
50834
- xv1.add(rotDX1);
50835
- xv2.add(rotDX2);
50836
- }
50837
- fy += dy;
50838
- }
50839
- return textureArray;
50840
- };
50841
- HDRLoader._calcProjectionSpherical = function _calcProjectionSpherical(vDir, pixels, inputWidth, inputHeight) {
50842
- var theta = Math.atan2(vDir.z, vDir.x);
50843
- var phi = Math.acos(vDir.y);
50844
- while(theta < -PI){
50845
- theta += 2 * PI;
50846
- }
50847
- while(theta > PI){
50848
- theta -= 2 * PI;
50849
- }
50850
- var dx = theta / PI;
50851
- var dy = phi / PI;
50852
- // recenter.
50853
- dx = dx * 0.5 + 0.5;
50854
- var px = Math.round(dx * inputWidth);
50855
- if (px < 0) {
50856
- px = 0;
50857
- } else if (px >= inputWidth) {
50858
- px = inputWidth - 1;
50859
- }
50860
- var py = Math.round(dy * inputHeight);
50861
- if (py < 0) {
50862
- py = 0;
50863
- } else if (py >= inputHeight) {
50864
- py = inputHeight - 1;
50865
- }
50866
- var inputY = inputHeight - py - 1;
50867
- var index = inputY * inputWidth * 4 + px * 4;
50868
- var r = pixels[index];
50869
- var g = pixels[index + 1];
50870
- var b = pixels[index + 2];
50871
- var a = pixels[index + 3];
50872
- return new Color(r, g, b, a);
50873
- };
50874
- HDRLoader._readStringLine = function _readStringLine(uint8array, startIndex) {
50875
- var line = "";
50876
- var character = "";
50877
- for(var i = startIndex; i < uint8array.length - startIndex; i++){
50878
- character = String.fromCharCode(uint8array[i]);
50879
- if (character == "\n") {
50880
- break;
50881
- }
50882
- line += character;
50883
- }
50884
- return line;
50885
- };
50886
- HDRLoader._parseHeader = function _parseHeader(uint8array) {
50887
- var height = 0;
50888
- var width = 0;
50889
- var line = this._readStringLine(uint8array, 0);
50890
- if (line[0] != "#" || line[1] != "?") {
50891
- throw "Bad HDR Format.";
50892
- }
50893
- var endOfHeader = false;
50894
- var findFormat = false;
50895
- var lineIndex = 0;
50896
- do {
50897
- lineIndex += line.length + 1;
50898
- line = this._readStringLine(uint8array, lineIndex);
50899
- if (line == "FORMAT=32-bit_rle_rgbe") {
50900
- findFormat = true;
50901
- } else if (line.length == 0) {
50902
- endOfHeader = true;
50903
- }
50904
- }while (!endOfHeader);
50905
- if (!findFormat) {
50906
- throw "HDR Bad header format, unsupported FORMAT";
50907
- }
50908
- lineIndex += line.length + 1;
50909
- line = this._readStringLine(uint8array, lineIndex);
50910
- var sizeRegexp = /^\-Y (.*) \+X (.*)$/g;
50911
- var match = sizeRegexp.exec(line);
50912
- // TODO. Support +Y and -X if needed.
50913
- if (!match || match.length < 3) {
50914
- throw "HDR Bad header format, no size";
50915
- }
50916
- width = parseInt(match[2]);
50917
- height = parseInt(match[1]);
50918
- if (width < 8 || width > 0x7fff) {
50919
- throw "HDR Bad header format, unsupported size";
50920
- }
50921
- lineIndex += line.length + 1;
50922
- return {
50923
- height: height,
50924
- width: width,
50925
- dataPosition: lineIndex
50926
- };
50927
- };
50928
- HDRLoader._readPixels = function _readPixels(buffer, width, height) {
50929
- var scanLineWidth = width;
50930
- var byteLength = buffer.byteLength;
50931
- var dataRGBA = new Uint8Array(4 * width * height);
50932
- var offset = 0, pos = 0;
50933
- var ptrEnd = 4 * scanLineWidth;
50934
- var scanLineBuffer = new Uint8Array(ptrEnd);
50935
- var numScanLines = height; // read in each successive scanLine
50936
- while(numScanLines > 0 && pos < byteLength){
50937
- var a = buffer[pos++];
50938
- var b = buffer[pos++];
50939
- var c = buffer[pos++];
50940
- var d = buffer[pos++];
50941
- if (a != 2 || b != 2 || c & 0x80 || width < 8 || width > 32767) {
50942
- // this file is not run length encoded
50943
- // read values sequentially
50944
- return buffer;
50945
- }
50946
- if ((c << 8 | d) != scanLineWidth) {
50947
- // eslint-disable-next-line no-throw-literal
50948
- throw "HDR Bad header format, wrong scan line width";
50949
- }
50950
- // read each of the four channels for the scanline into the buffer
50951
- // first red, then green, then blue, then exponent
50952
- var ptr = 0, count = void 0;
50953
- while(ptr < ptrEnd && pos < byteLength){
50954
- count = buffer[pos++];
50955
- var isEncodedRun = count > 128;
50956
- if (isEncodedRun) count -= 128;
50957
- if (0 === count || ptr + count > ptrEnd) {
50958
- throw "HDR Bad Format, bad scanline data (run)";
50959
- }
50960
- if (isEncodedRun) {
50961
- // a (encoded) run of the same value
50962
- var byteValue = buffer[pos++];
50963
- for(var i = 0; i < count; i++){
50964
- scanLineBuffer[ptr++] = byteValue;
50965
- } //ptr += count;
50966
- } else {
50967
- // a literal-run
50968
- scanLineBuffer.set(buffer.subarray(pos, pos + count), ptr);
50969
- ptr += count;
50970
- pos += count;
50971
- }
50972
- } // now convert data from buffer into rgba
50973
- // first red, then green, then blue, then exponent (alpha)
50974
- var l = scanLineWidth; //scanLine_buffer.byteLength;
50975
- for(var i1 = 0; i1 < l; i1++){
50976
- var off = 0;
50977
- dataRGBA[offset] = scanLineBuffer[i1 + off];
50978
- off += scanLineWidth;
50979
- dataRGBA[offset + 1] = scanLineBuffer[i1 + off];
50980
- off += scanLineWidth;
50981
- dataRGBA[offset + 2] = scanLineBuffer[i1 + off];
50982
- off += scanLineWidth;
50983
- dataRGBA[offset + 3] = scanLineBuffer[i1 + off];
50984
- offset += 4;
50985
- }
50986
- numScanLines--;
50987
- }
50988
- return dataRGBA;
50989
- };
50990
- HDRLoader._RGBEToLinear = function _RGBEToLinear(color) {
50991
- var scaleFactor = Math.pow(2, color.a - 128) / 255;
50992
- color.r *= scaleFactor;
50993
- color.g *= scaleFactor;
50994
- color.b *= scaleFactor;
50995
- color.a = 1;
50996
- };
50997
- HDRLoader._linearToRGBM = function _linearToRGBM(color, maxRange) {
50998
- var maxRGB = Math.max(color.r, Math.max(color.g, color.b));
50999
- var M = Math.min(maxRGB / maxRange, 1);
51000
- M = Math.ceil(M * 255);
51001
- var scaleFactor = 65025 / (M * maxRange); // 255 * (255 / (M * maxRange) )
51002
- color.r *= scaleFactor;
51003
- color.g *= scaleFactor;
51004
- color.b *= scaleFactor;
51005
- color.a *= M;
51006
- };
51007
- return HDRLoader;
51008
- }(Loader);
51009
- HDRLoader._rightBottomBack = new Vector3(1.0, -1.0, -1.0);
51010
- HDRLoader._rightBottomFront = new Vector3(1.0, -1.0, 1.0);
51011
- HDRLoader._rightUpBack = new Vector3(1.0, 1.0, -1.0);
51012
- HDRLoader._rightUpFront = new Vector3(1.0, 1.0, 1.0);
51013
- HDRLoader._leftBottomBack = new Vector3(-1.0, -1.0, -1.0);
51014
- HDRLoader._leftBottomFront = new Vector3(-1.0, -1.0, 1.0);
51015
- HDRLoader._leftUpBack = new Vector3(-1.0, 1.0, -1.0);
51016
- HDRLoader._leftUpFront = new Vector3(-1.0, 1.0, 1.0);
51017
- HDRLoader._faceRight = [
51018
- HDRLoader._rightBottomBack,
51019
- HDRLoader._rightBottomFront,
51020
- HDRLoader._rightUpBack,
51021
- HDRLoader._rightUpFront
51022
- ];
51023
- HDRLoader._faceLeft = [
51024
- HDRLoader._leftBottomFront,
51025
- HDRLoader._leftBottomBack,
51026
- HDRLoader._leftUpFront,
51027
- HDRLoader._leftUpBack
51028
- ];
51029
- HDRLoader._faceUp = [
51030
- HDRLoader._leftBottomFront,
51031
- HDRLoader._rightBottomFront,
51032
- HDRLoader._leftBottomBack,
51033
- HDRLoader._rightBottomBack
51034
- ];
51035
- HDRLoader._faceBottom = [
51036
- HDRLoader._leftUpBack,
51037
- HDRLoader._rightUpBack,
51038
- HDRLoader._leftUpFront,
51039
- HDRLoader._rightUpFront
51040
- ];
51041
- HDRLoader._faceFront = [
51042
- HDRLoader._leftBottomBack,
51043
- HDRLoader._rightBottomBack,
51044
- HDRLoader._leftUpBack,
51045
- HDRLoader._rightUpBack
51046
- ];
51047
- HDRLoader._faceBack = [
51048
- HDRLoader._rightBottomFront,
51049
- HDRLoader._leftBottomFront,
51050
- HDRLoader._rightUpFront,
51051
- HDRLoader._leftUpFront
51052
- ];
51053
- HDRLoader._tempVector3 = new Vector3();
51054
- HDRLoader._temp2Vector3 = new Vector3();
51055
- HDRLoader._temp3Vector3 = new Vector3();
51056
- HDRLoader._temp4Vector3 = new Vector3();
51057
- HDRLoader._temp5Vector3 = new Vector3();
51058
- HDRLoader = __decorate([
51059
- resourceLoader(AssetType.HDR, [
51060
- "hdr"
51061
- ])
51062
- ], HDRLoader);
51063
- /**
51064
- * @internal
51065
- */ var HDRContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
51066
- _inherits(HDRContentRestorer, ContentRestorer);
51067
- function HDRContentRestorer(resource, url, requestConfig) {
51068
- var _this;
51069
- _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
51070
- return _this;
51071
- }
51072
- var _proto = HDRContentRestorer.prototype;
51073
- _proto.restoreContent = function restoreContent() {
51074
- var _this = this;
51075
- return new AssetPromise(function(resolve, reject) {
51076
- var resource = _this.resource;
51077
- var engine = resource.engine;
51078
- engine.resourceManager // @ts-ignore
51079
- ._request(_this.url, _this.requestConfig).then(function(buffer) {
51080
- HDRLoader._setTextureByBuffer(engine, buffer, resource);
51081
- resolve(resource);
51082
- }).catch(reject);
51083
- });
51084
- };
51085
- return HDRContentRestorer;
51086
- }(ContentRestorer);
51087
50673
  var JSONLoader = /*#__PURE__*/ function(Loader) {
51088
50674
  _inherits(JSONLoader, Loader);
51089
50675
  function JSONLoader() {
@@ -51479,7 +51065,7 @@
51479
51065
  }(Loader);
51480
51066
  MaterialLoader = __decorate([
51481
51067
  resourceLoader(AssetType.Material, [
51482
- "json"
51068
+ "mat"
51483
51069
  ])
51484
51070
  ], MaterialLoader);
51485
51071
  var MeshLoader = /*#__PURE__*/ function(Loader) {
@@ -51599,7 +51185,7 @@
51599
51185
  }(Loader);
51600
51186
  ProjectLoader = __decorate([
51601
51187
  resourceLoader(AssetType.Project, [
51602
- "proj"
51188
+ "project"
51603
51189
  ], false)
51604
51190
  ], ProjectLoader);
51605
51191
  var SourceFontLoader = /*#__PURE__*/ function(Loader) {
@@ -51815,27 +51401,20 @@
51815
51401
  "txt"
51816
51402
  ])
51817
51403
  ], TextLoader);
51818
- /**
51819
- * @internal
51820
- */ var Texture2DContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
51821
- _inherits(Texture2DContentRestorer, ContentRestorer);
51822
- function Texture2DContentRestorer(resource, url, requestConfig) {
51823
- var _this;
51824
- _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
51825
- return _this;
51826
- }
51827
- var _proto = Texture2DContentRestorer.prototype;
51828
- _proto.restoreContent = function restoreContent() {
51829
- var _this = this;
51830
- return request(this.url, this.requestConfig).then(function(image) {
51831
- var resource = _this.resource;
51832
- resource.setImageSource(image);
51833
- resource.generateMipmaps();
51834
- return resource;
51835
- });
51836
- };
51837
- return Texture2DContentRestorer;
51838
- }(ContentRestorer);
51404
+ function loadImageFromBuffer(buffer) {
51405
+ return new AssetPromise(function(resolve, reject) {
51406
+ var blob = new Blob([
51407
+ buffer
51408
+ ]);
51409
+ var img = new Image();
51410
+ img.onload = function() {
51411
+ URL.revokeObjectURL(img.src);
51412
+ resolve(img);
51413
+ };
51414
+ img.onerror = reject;
51415
+ img.src = URL.createObjectURL(blob);
51416
+ });
51417
+ }
51839
51418
  var Texture2DLoader = /*#__PURE__*/ function(Loader) {
51840
51419
  _inherits(Texture2DLoader, Loader);
51841
51420
  function Texture2DLoader() {
@@ -51843,36 +51422,48 @@
51843
51422
  }
51844
51423
  var _proto = Texture2DLoader.prototype;
51845
51424
  _proto.load = function load(item, resourceManager) {
51425
+ var _this = this;
51426
+ var url = item.url;
51427
+ var requestConfig = _extends({}, item, {
51428
+ type: "arraybuffer"
51429
+ });
51846
51430
  return new AssetPromise(function(resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) {
51847
- var url = item.url;
51848
- var requestConfig = _extends({}, item, {
51849
- type: "image"
51850
- });
51851
51431
  resourceManager // @ts-ignore
51852
- ._request(url, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(image) {
51853
- var _item_params;
51854
- var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? TextureFormat.R8G8B8A8 : _ref_format, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode, _ref_isSRGBColorSpace = _ref.isSRGBColorSpace, isSRGBColorSpace = _ref_isSRGBColorSpace === void 0 ? true : _ref_isSRGBColorSpace, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap;
51855
- var width = image.width, height = image.height;
51856
- var engine = resourceManager.engine;
51857
- var generateMipmap = TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, mipmap, isSRGBColorSpace);
51858
- var texture = new Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
51859
- texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
51860
- texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
51861
- texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
51862
- texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
51863
- texture.setImageSource(image);
51864
- generateMipmap && texture.generateMipmaps();
51865
- if (url.indexOf("data:") !== 0) {
51866
- var index = url.lastIndexOf("/");
51867
- texture.name = url.substring(index + 1);
51432
+ ._request(url, requestConfig).onProgress(setTaskCompleteProgress, setTaskDetailProgress).then(function(buffer) {
51433
+ if (FileHeader.checkMagic(buffer)) {
51434
+ decode(buffer, resourceManager.engine).then(function(texture) {
51435
+ resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
51436
+ resolve(texture);
51437
+ }, reject);
51438
+ } else {
51439
+ loadImageFromBuffer(buffer).then(function(img) {
51440
+ var texture = _this._createTexture(img, item, resourceManager);
51441
+ resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
51442
+ resolve(texture);
51443
+ }, reject);
51868
51444
  }
51869
- resourceManager.addContentRestorer(new Texture2DContentRestorer(texture, url, requestConfig));
51870
- resolve(texture);
51871
- }).catch(function(e) {
51872
- reject(e);
51873
- });
51445
+ }).catch(reject);
51874
51446
  });
51875
51447
  };
51448
+ _proto._createTexture = function _createTexture(img, item, resourceManager) {
51449
+ var _item_params;
51450
+ var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? TextureFormat.R8G8B8A8 : _ref_format, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode, _ref_isSRGBColorSpace = _ref.isSRGBColorSpace, isSRGBColorSpace = _ref_isSRGBColorSpace === void 0 ? true : _ref_isSRGBColorSpace, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap;
51451
+ var width = img.width, height = img.height;
51452
+ var engine = resourceManager.engine;
51453
+ var generateMipmap = TextureUtils.supportGenerateMipmapsWithCorrection(engine, width, height, format, mipmap, isSRGBColorSpace);
51454
+ var texture = new Texture2D(engine, width, height, format, generateMipmap, isSRGBColorSpace);
51455
+ texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
51456
+ texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
51457
+ texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
51458
+ texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
51459
+ texture.setImageSource(img);
51460
+ generateMipmap && texture.generateMipmaps();
51461
+ var url = item.url;
51462
+ if (url.indexOf("data:") !== 0) {
51463
+ texture.name = url.substring(url.lastIndexOf("/") + 1);
51464
+ }
51465
+ return texture;
51466
+ };
51876
51467
  return Texture2DLoader;
51877
51468
  }(Loader);
51878
51469
  Texture2DLoader = __decorate([
@@ -51880,38 +51471,317 @@
51880
51471
  "png",
51881
51472
  "jpg",
51882
51473
  "webp",
51883
- "jpeg"
51474
+ "jpeg",
51475
+ "tex"
51884
51476
  ])
51885
51477
  ], Texture2DLoader);
51886
- /**
51887
- * @internal
51888
- */ var TextureCubeContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
51889
- _inherits(TextureCubeContentRestorer, ContentRestorer);
51890
- function TextureCubeContentRestorer(resource, urls, requestConfig) {
51478
+ var Texture2DContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
51479
+ _inherits(Texture2DContentRestorer, ContentRestorer);
51480
+ function Texture2DContentRestorer(resource, url, requestConfig) {
51891
51481
  var _this;
51892
- _this = ContentRestorer.call(this, resource) || this, _this.urls = urls, _this.requestConfig = requestConfig;
51482
+ _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
51893
51483
  return _this;
51894
51484
  }
51895
- var _proto = TextureCubeContentRestorer.prototype;
51485
+ var _proto = Texture2DContentRestorer.prototype;
51896
51486
  _proto.restoreContent = function restoreContent() {
51897
- var _this = this;
51898
- return new AssetPromise(function(resolve, reject) {
51899
- Promise.all(_this.urls.map(function(url) {
51900
- return request(url, _this.requestConfig);
51901
- })).then(function(images) {
51902
- var resource = _this.resource;
51903
- for(var faceIndex = 0; faceIndex < 6; faceIndex++){
51904
- resource.setImageSource(TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
51905
- }
51906
- resource.generateMipmaps();
51907
- resolve(resource);
51908
- }).catch(function(e) {
51909
- reject(e);
51910
- });
51487
+ var texture = this.resource;
51488
+ var engine = texture.engine;
51489
+ return engine.resourceManager // @ts-ignore
51490
+ ._request(this.url, this.requestConfig).then(function(buffer) {
51491
+ if (FileHeader.checkMagic(buffer)) {
51492
+ return decode(buffer, engine, texture);
51493
+ } else {
51494
+ return loadImageFromBuffer(buffer).then(function(img) {
51495
+ texture.setImageSource(img);
51496
+ texture.generateMipmaps();
51497
+ return texture;
51498
+ });
51499
+ }
51911
51500
  });
51912
51501
  };
51913
- return TextureCubeContentRestorer;
51502
+ return Texture2DContentRestorer;
51914
51503
  }(ContentRestorer);
51504
+ /**
51505
+ * @internal
51506
+ * HDR panorama to cubemap decoder.
51507
+ */ var HDRDecoder = /*#__PURE__*/ function() {
51508
+ function HDRDecoder() {}
51509
+ HDRDecoder.parseHeader = function parseHeader(uint8array) {
51510
+ var line = this._readStringLine(uint8array, 0);
51511
+ if (line[0] !== "#" || line[1] !== "?") {
51512
+ throw "HDRDecoder: invalid file header";
51513
+ }
51514
+ var endOfHeader = false;
51515
+ var findFormat = false;
51516
+ var lineIndex = 0;
51517
+ do {
51518
+ lineIndex += line.length + 1;
51519
+ line = this._readStringLine(uint8array, lineIndex);
51520
+ if (line === "FORMAT=32-bit_rle_rgbe") findFormat = true;
51521
+ else if (line.length === 0) endOfHeader = true;
51522
+ }while (!endOfHeader);
51523
+ if (!findFormat) {
51524
+ throw "HDRDecoder: unsupported format, expected 32-bit_rle_rgbe";
51525
+ }
51526
+ lineIndex += line.length + 1;
51527
+ line = this._readStringLine(uint8array, lineIndex);
51528
+ var match = /^\-Y (.*) \+X (.*)$/g.exec(line);
51529
+ if (!match || match.length < 3) {
51530
+ throw "HDRDecoder: missing image size, only -Y +X layout is supported";
51531
+ }
51532
+ var width = parseInt(match[2]);
51533
+ var height = parseInt(match[1]);
51534
+ if (width < 8 || width > 0x7fff) {
51535
+ throw "HDRDecoder: unsupported image width, must be between 8 and 32767";
51536
+ }
51537
+ return {
51538
+ height: height,
51539
+ width: width,
51540
+ dataPosition: lineIndex + line.length + 1
51541
+ };
51542
+ };
51543
+ HDRDecoder.decodeFaces = function decodeFaces(bufferArray, header, onFace) {
51544
+ var width = header.width, height = header.height, dataPosition = header.dataPosition;
51545
+ var cubeSize = height >> 1;
51546
+ var pixels = HDRDecoder._readPixels(bufferArray.subarray(dataPosition), width, height);
51547
+ var faces = HDRDecoder._faces;
51548
+ var faceBuffer = new Uint16Array(cubeSize * cubeSize * 4);
51549
+ for(var faceIndex = 0; faceIndex < 6; faceIndex++){
51550
+ HDRDecoder._createCubemapData(cubeSize, faces[faceIndex], pixels, width, height, faceBuffer);
51551
+ onFace(faceIndex, faceBuffer);
51552
+ }
51553
+ };
51554
+ HDRDecoder._generateFloat2HalfTables = function _generateFloat2HalfTables() {
51555
+ var baseTable = new Uint32Array(512);
51556
+ var shiftTable = new Uint32Array(512);
51557
+ for(var i = 0; i < 256; ++i){
51558
+ var e = i - 127;
51559
+ if (e < -27) {
51560
+ baseTable[i] = 0x0000;
51561
+ baseTable[i | 0x100] = 0x8000;
51562
+ shiftTable[i] = 24;
51563
+ shiftTable[i | 0x100] = 24;
51564
+ } else if (e < -14) {
51565
+ baseTable[i] = 0x0400 >> -e - 14;
51566
+ baseTable[i | 0x100] = 0x0400 >> -e - 14 | 0x8000;
51567
+ shiftTable[i] = -e - 1;
51568
+ shiftTable[i | 0x100] = -e - 1;
51569
+ } else if (e <= 15) {
51570
+ baseTable[i] = e + 15 << 10;
51571
+ baseTable[i | 0x100] = e + 15 << 10 | 0x8000;
51572
+ shiftTable[i] = 13;
51573
+ shiftTable[i | 0x100] = 13;
51574
+ } else if (e < 128) {
51575
+ baseTable[i] = 0x7c00;
51576
+ baseTable[i | 0x100] = 0xfc00;
51577
+ shiftTable[i] = 24;
51578
+ shiftTable[i | 0x100] = 24;
51579
+ } else {
51580
+ baseTable[i] = 0x7c00;
51581
+ baseTable[i | 0x100] = 0xfc00;
51582
+ shiftTable[i] = 13;
51583
+ shiftTable[i | 0x100] = 13;
51584
+ }
51585
+ }
51586
+ return {
51587
+ baseTable: baseTable,
51588
+ shiftTable: shiftTable
51589
+ };
51590
+ };
51591
+ HDRDecoder._createCubemapData = function _createCubemapData(texSize, face, pixels, inputWidth, inputHeight, facePixels) {
51592
+ var invSize = 1 / texSize;
51593
+ var rotDX1X = (face[3] - face[0]) * invSize;
51594
+ var rotDX1Y = (face[4] - face[1]) * invSize;
51595
+ var rotDX1Z = (face[5] - face[2]) * invSize;
51596
+ var rotDX2X = (face[9] - face[6]) * invSize;
51597
+ var rotDX2Y = (face[10] - face[7]) * invSize;
51598
+ var rotDX2Z = (face[11] - face[8]) * invSize;
51599
+ var floatView = HDRDecoder._floatView;
51600
+ var uint32View = HDRDecoder._uint32View;
51601
+ var _HDRDecoder__float2HalfTables = HDRDecoder._float2HalfTables, baseTable = _HDRDecoder__float2HalfTables.baseTable, shiftTable = _HDRDecoder__float2HalfTables.shiftTable;
51602
+ var one = HDRDecoder._one;
51603
+ var fy = 0;
51604
+ for(var y = 0; y < texSize; y++){
51605
+ var xv1X = face[0], xv1Y = face[1], xv1Z = face[2];
51606
+ var xv2X = face[6], xv2Y = face[7], xv2Z = face[8];
51607
+ for(var x = 0; x < texSize; x++){
51608
+ var dirX = xv1X + (xv2X - xv1X) * fy;
51609
+ var dirY = xv1Y + (xv2Y - xv1Y) * fy;
51610
+ var dirZ = xv1Z + (xv2Z - xv1Z) * fy;
51611
+ var invLen = 1 / Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);
51612
+ dirX *= invLen;
51613
+ dirY *= invLen;
51614
+ dirZ *= invLen;
51615
+ var px = Math.round((Math.atan2(dirZ, dirX) / Math.PI * 0.5 + 0.5) * inputWidth);
51616
+ if (px < 0) px = 0;
51617
+ else if (px >= inputWidth) px = inputWidth - 1;
51618
+ var py = Math.round(Math.acos(dirY) / Math.PI * inputHeight);
51619
+ if (py < 0) py = 0;
51620
+ else if (py >= inputHeight) py = inputHeight - 1;
51621
+ var srcIndex = (inputHeight - py - 1) * inputWidth * 4 + px * 4;
51622
+ var scaleFactor = Math.pow(2, pixels[srcIndex + 3] - 128) / 255;
51623
+ var dstIndex = y * texSize * 4 + x * 4;
51624
+ for(var c = 0; c < 3; c++){
51625
+ floatView[0] = pixels[srcIndex + c] * scaleFactor;
51626
+ var f = uint32View[0];
51627
+ var e = f >> 23 & 0x1ff;
51628
+ facePixels[dstIndex + c] = baseTable[e] + ((f & 0x007fffff) >> shiftTable[e]);
51629
+ }
51630
+ facePixels[dstIndex + 3] = one;
51631
+ xv1X += rotDX1X;
51632
+ xv1Y += rotDX1Y;
51633
+ xv1Z += rotDX1Z;
51634
+ xv2X += rotDX2X;
51635
+ xv2Y += rotDX2Y;
51636
+ xv2Z += rotDX2Z;
51637
+ }
51638
+ fy += invSize;
51639
+ }
51640
+ };
51641
+ HDRDecoder._readStringLine = function _readStringLine(uint8array, startIndex) {
51642
+ var line = "";
51643
+ for(var i = startIndex, n = uint8array.length; i < n; i++){
51644
+ var character = String.fromCharCode(uint8array[i]);
51645
+ if (character === "\n") break;
51646
+ line += character;
51647
+ }
51648
+ return line;
51649
+ };
51650
+ HDRDecoder._readPixels = function _readPixels(buffer, width, height) {
51651
+ var byteLength = buffer.byteLength;
51652
+ var dataRGBA = new Uint8Array(4 * width * height);
51653
+ var offset = 0;
51654
+ var pos = 0;
51655
+ var ptrEnd = 4 * width;
51656
+ var scanLineBuffer = new Uint8Array(ptrEnd);
51657
+ var numScanLines = height;
51658
+ while(numScanLines > 0 && pos < byteLength){
51659
+ var a = buffer[pos++];
51660
+ var b = buffer[pos++];
51661
+ var c = buffer[pos++];
51662
+ var d = buffer[pos++];
51663
+ if (a !== 2 || b !== 2 || c & 0x80 || width < 8 || width > 32767) return buffer;
51664
+ if ((c << 8 | d) !== width) throw "HDRDecoder: wrong scanline width";
51665
+ var ptr = 0;
51666
+ while(ptr < ptrEnd && pos < byteLength){
51667
+ var count = buffer[pos++];
51668
+ var isEncodedRun = count > 128;
51669
+ if (isEncodedRun) count -= 128;
51670
+ if (count === 0 || ptr + count > ptrEnd) throw "HDRDecoder: bad scanline data";
51671
+ if (isEncodedRun) {
51672
+ var byteValue = buffer[pos++];
51673
+ for(var i = 0; i < count; i++)scanLineBuffer[ptr++] = byteValue;
51674
+ } else {
51675
+ scanLineBuffer.set(buffer.subarray(pos, pos + count), ptr);
51676
+ ptr += count;
51677
+ pos += count;
51678
+ }
51679
+ }
51680
+ for(var i1 = 0; i1 < width; i1++, offset += 4){
51681
+ dataRGBA[offset] = scanLineBuffer[i1];
51682
+ dataRGBA[offset + 1] = scanLineBuffer[i1 + width];
51683
+ dataRGBA[offset + 2] = scanLineBuffer[i1 + width * 2];
51684
+ dataRGBA[offset + 3] = scanLineBuffer[i1 + width * 3];
51685
+ }
51686
+ numScanLines--;
51687
+ }
51688
+ return dataRGBA;
51689
+ };
51690
+ return HDRDecoder;
51691
+ }();
51692
+ // Float32 to Float16 lookup tables (http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf)
51693
+ HDRDecoder._float2HalfTables = HDRDecoder._generateFloat2HalfTables();
51694
+ HDRDecoder._floatView = new Float32Array(1);
51695
+ HDRDecoder._uint32View = new Uint32Array(HDRDecoder._floatView.buffer);
51696
+ HDRDecoder._one = 0x3c00 // Half float for 1.0
51697
+ ;
51698
+ // prettier-ignore
51699
+ HDRDecoder._faces = [
51700
+ /* +X */ [
51701
+ 1,
51702
+ -1,
51703
+ -1,
51704
+ 1,
51705
+ -1,
51706
+ 1,
51707
+ 1,
51708
+ 1,
51709
+ -1,
51710
+ 1,
51711
+ 1,
51712
+ 1
51713
+ ],
51714
+ /* -X */ [
51715
+ -1,
51716
+ -1,
51717
+ 1,
51718
+ -1,
51719
+ -1,
51720
+ -1,
51721
+ -1,
51722
+ 1,
51723
+ 1,
51724
+ -1,
51725
+ 1,
51726
+ -1
51727
+ ],
51728
+ /* +Y */ [
51729
+ -1,
51730
+ -1,
51731
+ 1,
51732
+ 1,
51733
+ -1,
51734
+ 1,
51735
+ -1,
51736
+ -1,
51737
+ -1,
51738
+ 1,
51739
+ -1,
51740
+ -1
51741
+ ],
51742
+ /* -Y */ [
51743
+ -1,
51744
+ 1,
51745
+ -1,
51746
+ 1,
51747
+ 1,
51748
+ -1,
51749
+ -1,
51750
+ 1,
51751
+ 1,
51752
+ 1,
51753
+ 1,
51754
+ 1
51755
+ ],
51756
+ /* +Z */ [
51757
+ -1,
51758
+ -1,
51759
+ -1,
51760
+ 1,
51761
+ -1,
51762
+ -1,
51763
+ -1,
51764
+ 1,
51765
+ -1,
51766
+ 1,
51767
+ 1,
51768
+ -1
51769
+ ],
51770
+ /* -Z */ [
51771
+ 1,
51772
+ -1,
51773
+ 1,
51774
+ -1,
51775
+ -1,
51776
+ 1,
51777
+ 1,
51778
+ 1,
51779
+ 1,
51780
+ -1,
51781
+ 1,
51782
+ 1
51783
+ ]
51784
+ ];
51915
51785
  var TextureCubeLoader = /*#__PURE__*/ function(Loader) {
51916
51786
  _inherits(TextureCubeLoader, Loader);
51917
51787
  function TextureCubeLoader() {
@@ -51919,6 +51789,44 @@
51919
51789
  }
51920
51790
  var _proto = TextureCubeLoader.prototype;
51921
51791
  _proto.load = function load(item, resourceManager) {
51792
+ if (item.urls) {
51793
+ return this._loadCubeFaces(item, resourceManager);
51794
+ } else {
51795
+ return this._loadHDR(item, resourceManager);
51796
+ }
51797
+ };
51798
+ _proto._loadHDR = function _loadHDR(item, resourceManager) {
51799
+ return new AssetPromise(function(resolve, reject) {
51800
+ var engine = resourceManager.engine;
51801
+ var url = item.url;
51802
+ var requestConfig = _extends({}, item, {
51803
+ type: "arraybuffer"
51804
+ });
51805
+ resourceManager // @ts-ignore
51806
+ ._request(url, requestConfig).then(function(buffer) {
51807
+ if (!SystemInfo.supportsTextureFormat(engine, TextureFormat.R16G16B16A16)) {
51808
+ reject(new Error("TextureCubeLoader: HDR texture requires half float support."));
51809
+ return;
51810
+ }
51811
+ var _item_params;
51812
+ var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode;
51813
+ var bufferArray = new Uint8Array(buffer);
51814
+ var header = HDRDecoder.parseHeader(bufferArray);
51815
+ var texture = new TextureCube(engine, header.height >> 1, TextureFormat.R16G16B16A16, mipmap, false);
51816
+ HDRDecoder.decodeFaces(bufferArray, header, function(faceIndex, data) {
51817
+ texture.setPixelBuffer(TextureCubeFace.PositiveX + faceIndex, data, 0);
51818
+ });
51819
+ texture.generateMipmaps();
51820
+ texture.anisoLevel = anisoLevel != null ? anisoLevel : texture.anisoLevel;
51821
+ texture.filterMode = filterMode != null ? filterMode : texture.filterMode;
51822
+ texture.wrapModeU = wrapModeU != null ? wrapModeU : texture.wrapModeU;
51823
+ texture.wrapModeV = wrapModeV != null ? wrapModeV : texture.wrapModeV;
51824
+ resourceManager.addContentRestorer(new HDRContentRestorer(texture, url, requestConfig));
51825
+ resolve(texture);
51826
+ }).catch(reject);
51827
+ });
51828
+ };
51829
+ _proto._loadCubeFaces = function _loadCubeFaces(item, resourceManager) {
51922
51830
  return new AssetPromise(function(resolve, reject) {
51923
51831
  var urls = item.urls;
51924
51832
  var requestConfig = _extends({}, item, {
@@ -51932,7 +51840,7 @@
51932
51840
  var _ref = (_item_params = item.params) != null ? _item_params : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? TextureFormat.R8G8B8A8 : _ref_format, anisoLevel = _ref.anisoLevel, wrapModeU = _ref.wrapModeU, wrapModeV = _ref.wrapModeV, filterMode = _ref.filterMode, _ref_isSRGBColorSpace = _ref.isSRGBColorSpace, isSRGBColorSpace = _ref_isSRGBColorSpace === void 0 ? true : _ref_isSRGBColorSpace, _ref_mipmap = _ref.mipmap, mipmap = _ref_mipmap === void 0 ? true : _ref_mipmap;
51933
51841
  var _images_ = images[0], width = _images_.width, height = _images_.height;
51934
51842
  if (width !== height) {
51935
- console.error("The cube texture must have the same width and height");
51843
+ reject(new Error("The cube texture must have the same width and height"));
51936
51844
  return;
51937
51845
  }
51938
51846
  var engine = resourceManager.engine;
@@ -51945,21 +51853,70 @@
51945
51853
  for(var faceIndex = 0; faceIndex < 6; faceIndex++){
51946
51854
  texture.setImageSource(TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
51947
51855
  }
51948
- generateMipmap && texture.generateMipmaps();
51949
- resourceManager.addContentRestorer(new TextureCubeContentRestorer(texture, urls, requestConfig));
51856
+ texture.generateMipmaps();
51857
+ resourceManager.addContentRestorer(new CubeFaceContentRestorer(texture, urls, requestConfig));
51950
51858
  resolve(texture);
51951
- }).catch(function(e) {
51952
- reject(e);
51953
- });
51859
+ }).catch(reject);
51954
51860
  });
51955
51861
  };
51956
51862
  return TextureCubeLoader;
51957
51863
  }(Loader);
51958
51864
  TextureCubeLoader = __decorate([
51959
51865
  resourceLoader(AssetType.TextureCube, [
51960
- ""
51866
+ "texCube",
51867
+ "hdr"
51961
51868
  ])
51962
51869
  ], TextureCubeLoader);
51870
+ var HDRContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
51871
+ _inherits(HDRContentRestorer, ContentRestorer);
51872
+ function HDRContentRestorer(resource, url, requestConfig) {
51873
+ var _this;
51874
+ _this = ContentRestorer.call(this, resource) || this, _this.url = url, _this.requestConfig = requestConfig;
51875
+ return _this;
51876
+ }
51877
+ var _proto = HDRContentRestorer.prototype;
51878
+ _proto.restoreContent = function restoreContent() {
51879
+ var _this = this;
51880
+ return new AssetPromise(function(resolve, reject) {
51881
+ var resource = _this.resource;
51882
+ resource.engine.resourceManager // @ts-ignore
51883
+ ._request(_this.url, _this.requestConfig).then(function(buffer) {
51884
+ var bufferArray = new Uint8Array(buffer);
51885
+ HDRDecoder.decodeFaces(bufferArray, HDRDecoder.parseHeader(bufferArray), function(faceIndex, data) {
51886
+ resource.setPixelBuffer(TextureCubeFace.PositiveX + faceIndex, data, 0);
51887
+ });
51888
+ resource.generateMipmaps();
51889
+ resolve(resource);
51890
+ }).catch(reject);
51891
+ });
51892
+ };
51893
+ return HDRContentRestorer;
51894
+ }(ContentRestorer);
51895
+ var CubeFaceContentRestorer = /*#__PURE__*/ function(ContentRestorer) {
51896
+ _inherits(CubeFaceContentRestorer, ContentRestorer);
51897
+ function CubeFaceContentRestorer(resource, urls, requestConfig) {
51898
+ var _this;
51899
+ _this = ContentRestorer.call(this, resource) || this, _this.urls = urls, _this.requestConfig = requestConfig;
51900
+ return _this;
51901
+ }
51902
+ var _proto = CubeFaceContentRestorer.prototype;
51903
+ _proto.restoreContent = function restoreContent() {
51904
+ var _this = this;
51905
+ return new AssetPromise(function(resolve, reject) {
51906
+ Promise.all(_this.urls.map(function(url) {
51907
+ return request(url, _this.requestConfig);
51908
+ })).then(function(images) {
51909
+ var resource = _this.resource;
51910
+ for(var faceIndex = 0; faceIndex < 6; faceIndex++){
51911
+ resource.setImageSource(TextureCubeFace.PositiveX + faceIndex, images[faceIndex], 0);
51912
+ }
51913
+ resource.generateMipmaps();
51914
+ resolve(resource);
51915
+ }).catch(reject);
51916
+ });
51917
+ };
51918
+ return CubeFaceContentRestorer;
51919
+ }(ContentRestorer);
51963
51920
  var AudioLoader = /*#__PURE__*/ function(Loader) {
51964
51921
  _inherits(AudioLoader, Loader);
51965
51922
  function AudioLoader() {
@@ -52105,7 +52062,7 @@
52105
52062
  }(Loader);
52106
52063
  PhysicsMaterialLoader = __decorate([
52107
52064
  resourceLoader(AssetType.PhysicsMaterial, [
52108
- "mesh"
52065
+ "physMat"
52109
52066
  ])
52110
52067
  ], PhysicsMaterialLoader);
52111
52068
  var SceneLoader = /*#__PURE__*/ function(Loader) {
@@ -52139,7 +52096,6 @@
52139
52096
  scene.ambientLight.specularIntensity = ambient.specularIntensity;
52140
52097
  scene.ambientLight.diffuseMode = ambient.diffuseMode;
52141
52098
  scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
52142
- scene.ambientLight.specularTextureDecodeRGBM = true;
52143
52099
  if (useCustomAmbient && ambient.customAmbientLight) {
52144
52100
  promises.push(resourceManager.getResourceByRef(ambient.customAmbientLight).then(function(ambientLight) {
52145
52101
  scene.ambientLight.specularTexture = ambientLight == null ? void 0 : ambientLight.specularTexture;
@@ -52757,7 +52713,7 @@
52757
52713
  ], EXT_texture_webp);
52758
52714
 
52759
52715
  //@ts-ignore
52760
- var version = "2.0.0-alpha.5";
52716
+ var version = "2.0.0-alpha.7";
52761
52717
  console.log("Galacean Engine Version: " + version);
52762
52718
  for(var key in CoreObjects){
52763
52719
  Loader.registerClass(key, CoreObjects[key]);