@galacean/engine-shader 1.6.0-beta.0

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/module.js ADDED
@@ -0,0 +1,181 @@
1
+ import { ShaderFactory } from '@galacean/engine';
2
+
3
+ function _array_like_to_array(arr, len) {
4
+ if (len == null || len > arr.length) len = arr.length;
5
+
6
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
7
+
8
+ return arr2;
9
+ }
10
+
11
+ function _unsupported_iterable_to_array(o, minLen) {
12
+ if (!o) return;
13
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
14
+
15
+ var n = Object.prototype.toString.call(o).slice(8, -1);
16
+
17
+ if (n === "Object" && o.constructor) n = o.constructor.name;
18
+ if (n === "Map" || n === "Set") return Array.from(n);
19
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
20
+ }
21
+
22
+ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
23
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
24
+
25
+ if (it) return (it = it.call(o)).next.bind(it);
26
+ // Fallback for engines without symbol support
27
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
28
+ if (it) o = it;
29
+
30
+ var i = 0;
31
+
32
+ return function() {
33
+ if (i >= o.length) return { done: true };
34
+
35
+ return { done: false, value: o[i++] };
36
+ };
37
+ }
38
+
39
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
40
+ }
41
+
42
+ var BlendShape = "#ifndef BLENDSHAPE_INCLUDED\n#define BLENDSHAPE_INCLUDED\n\n#ifdef RENDERER_HAS_BLENDSHAPE\n\t#ifdef RENDERER_BLENDSHAPE_USE_TEXTURE\n\t\tmediump sampler2DArray renderer_BlendShapeTexture;\n\t\tivec3 renderer_BlendShapeTextureInfo;\n\t\tfloat renderer_BlendShapeWeights[RENDERER_BLENDSHAPE_COUNT];\n\n\t\tvec3 getBlendShapeVertexElement(int blendShapeIndex, int vertexElementIndex){\t\t\t\n\t\t\tint y = vertexElementIndex / renderer_BlendShapeTextureInfo.y;\n\t\t\tint x = vertexElementIndex - y * renderer_BlendShapeTextureInfo.y;\n\t\t\tivec3 uv = ivec3(x, y , blendShapeIndex);\n\t\t\treturn (texelFetch(renderer_BlendShapeTexture, uv, 0)).xyz;\n\t\t}\n\t#else\n\t\t#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\n\t\t\tfloat renderer_BlendShapeWeights[2];\n\t\t#else\n\t\t\t#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) || defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\n\t\t\t\tfloat renderer_BlendShapeWeights[4];\n\t\t\t#else\n\t\t\t\tfloat renderer_BlendShapeWeights[8];\n\t\t\t#endif\n\t\t#endif\n\t#endif\n\n\tvoid calculateBlendShape(Attributes attributes, inout vec4 position\n #ifdef RENDERER_HAS_NORMAL\n ,inout vec3 normal\n\t\t\t #ifdef RENDERER_HAS_TANGENT\n \t,inout vec4 tangent\n \t#endif\n #endif\n \n\t){\n\t\t#ifdef RENDERER_BLENDSHAPE_USE_TEXTURE\t\n \t\tint vertexOffset = gl_VertexID * renderer_BlendShapeTextureInfo.x;\n \t\tfor(int i = 0; i < RENDERER_BLENDSHAPE_COUNT; i++){\n \t\t\tint vertexElementOffset = vertexOffset;\n \t\t\tfloat weight = renderer_BlendShapeWeights[i];\n \t\t\t// Warnning: Multiplying by 0 creates weird precision issues, causing rendering anomalies in Ace2 Android13\n \t\t\tif(weight != 0.0){\n \t\t\t\tposition.xyz += getBlendShapeVertexElement(i, vertexElementOffset) * weight;\n \n \t\t\t\t#if defined( RENDERER_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_NORMAL )\n \t\t\t\t\tvertexElementOffset += 1;\n \t\t\t\t\tnormal += getBlendShapeVertexElement(i, vertexElementOffset) * weight;\n \t\t\t\t#endif\n \n \t\t\t\t#if defined( RENDERER_HAS_TANGENT ) && defined(RENDERER_BLENDSHAPE_HAS_TANGENT)\n \t\t\t\t\tvertexElementOffset += 1;\n \t\t\t\t\ttangent.xyz += getBlendShapeVertexElement(i, vertexElementOffset) * weight;\n \t\t\t\t#endif\n \t\t\t}\n \n \t\t}\n \t#else\n \t\tposition.xyz += attributes.POSITION_BS0 * renderer_BlendShapeWeights[0];\n \t\tposition.xyz += attributes.POSITION_BS1 * renderer_BlendShapeWeights[1];\n\n \t\t#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\n \t\t\t#ifdef RENDERER_HAS_NORMAL\n \t\t\t\tnormal += attributes.NORMAL_BS0 * renderer_BlendShapeWeights[0];\n \t\t\t\tnormal += attributes.NORMAL_BS1 * renderer_BlendShapeWeights[1];\n \t\t\t#endif\n \n \t\t\t#ifdef RENDERER_HAS_TANGENT\n \t\t\t\ttangent.xyz += attributes.TANGENT_BS0 * renderer_BlendShapeWeights[0];\n \t\t\t\ttangent.xyz += attributes.TANGENT_BS1 * renderer_BlendShapeWeights[1];\n \t\t\t#endif\t\t\t\t\n \t\t#else\n \t\t\t#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) || defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\n \t\t\t\tposition.xyz += attributes.POSITION_BS2 * renderer_BlendShapeWeights[2];\n \t\t\t\tposition.xyz += attributes.POSITION_BS3 * renderer_BlendShapeWeights[3];\n\n \t\t\t\t#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_HAS_NORMAL )\n \t\t\t\t\tnormal += attributes.NORMAL_BS0 * renderer_BlendShapeWeights[0];\n \t\t\t\t\tnormal += attributes.NORMAL_BS1 * renderer_BlendShapeWeights[1];\n \t\t\t\t\tnormal += attributes.NORMAL_BS2 * renderer_BlendShapeWeights[2];\n \t\t\t\t\tnormal += attributes.NORMAL_BS3 * renderer_BlendShapeWeights[3];\n \t\t\t\t#endif\n\n \t\t\t\t#if defined(RENDERER_BLENDSHAPE_HAS_TANGENT) && defined( RENDERER_HAS_TANGENT )\n \t\t\t\t\ttangent.xyz += attributes.TANGENT_BS0 * renderer_BlendShapeWeights[0];\n \t\t\t\t\ttangent.xyz += attributes.TANGENT_BS1 * renderer_BlendShapeWeights[1];\n \t\t\t\t\ttangent.xyz += attributes.TANGENT_BS2 * renderer_BlendShapeWeights[2];\n \t\t\t\t\ttangent.xyz += attributes.TANGENT_BS3 * renderer_BlendShapeWeights[3];\n \t\t\t\t#endif\n \t\t\t#else\n \t\t\t\tposition.xyz += attributes.POSITION_BS2 * renderer_BlendShapeWeights[2];\n \t\t\t\tposition.xyz += attributes.POSITION_BS3 * renderer_BlendShapeWeights[3];\n \t\t\t\tposition.xyz += attributes.POSITION_BS4 * renderer_BlendShapeWeights[4];\n \t\t\t\tposition.xyz += attributes.POSITION_BS5 * renderer_BlendShapeWeights[5];\n \t\t\t\tposition.xyz += attributes.POSITION_BS6 * renderer_BlendShapeWeights[6];\n \t\t\t\tposition.xyz += attributes.POSITION_BS7 * renderer_BlendShapeWeights[7];\n \t\t\t#endif\n \t\t#endif\n \t#endif\n\t}\n\n#endif\n\n\n#endif"; // eslint-disable-line
43
+
44
+ var Common = "#ifndef COMMON_INCLUDED\n#define COMMON_INCLUDED\n\n#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// 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\nvec4 camera_DepthBufferParams;\n\nfloat remapDepthBufferLinear01(float z){\n\treturn 1.0/ (camera_DepthBufferParams.x * z + camera_DepthBufferParams.y);\n}\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\nvec3 safeNormalize(vec3 inVec)\n{\n float dp3 = max(float(HALF_MIN), dot(inVec, inVec));\n return inVec * inversesqrt(dp3);\n}\n\n#endif"; // eslint-disable-line
45
+
46
+ var Fog = "#ifndef FOG_INCLUDED\n#define FOG_INCLUDED\n\n#if SCENE_FOG_MODE != 0\n vec4 scene_FogColor;\n vec4 scene_FogParams; // (-1/(end-start), end/(end-start), density/ln(2),density/sprt(ln(2)));\n\n vec4 fog(vec4 color, vec3 positionVS){\n float fogDepth = length(positionVS);\n\n #if SCENE_FOG_MODE == 1\n // (end-z) / (end-start) = z * (-1/(end-start)) + (end/(end-start))\n float fogIntensity = clamp(fogDepth * scene_FogParams.x + scene_FogParams.y, 0.0, 1.0);\n #elif SCENE_FOG_MODE == 2\n // exp(-z * density) = exp2((-z * density)/ln(2)) = exp2(-z * density/ln(2))\n float fogIntensity = clamp(exp2(-fogDepth * scene_FogParams.z), 0.0, 1.0);\n #elif SCENE_FOG_MODE == 3\n // exp(-(z * density)^2) = exp2(-(z * density)^2/ln(2)) = exp2(-(z * density/sprt(ln(2)))^2)\n float factor = fogDepth * scene_FogParams.w;\n float fogIntensity = clamp(exp2(-factor * factor), 0.0, 1.0);\n #endif\n\n color.rgb = mix(scene_FogColor.rgb, color.rgb, fogIntensity);\n\n return color;\n }\n#endif\n\n\n#endif"; // eslint-disable-line
47
+
48
+ var Light = "#ifndef LIGHT_INCLUDED\n#define LIGHT_INCLUDED\n\n\nivec4 renderer_Layer;\n#ifndef GRAPHICS_API_WEBGL2\n bool isBitSet(float value, float mask, float bitIndex){\n return mod(floor(value / pow(2.0, bitIndex)), 2.0) == 1.0 && mod(floor(mask / pow(2.0, bitIndex)), 2.0) == 1.0;\n }\n#endif\n\nbool isRendererCulledByLight(ivec2 rendererLayer, ivec2 lightCullingMask){\n #ifdef GRAPHICS_API_WEBGL2\n return !((rendererLayer.x & lightCullingMask.x) != 0 || (rendererLayer.y & lightCullingMask.y) != 0);\n #else\n for (int i = 0; i < 16; i++) {\n if (isBitSet( float(rendererLayer.x), float(lightCullingMask.x), float(i)) || isBitSet( float(rendererLayer.y), float(lightCullingMask.y), float(i))) {\n return false;\n }\n }\n return true;\n #endif\n}\n\n// Directional light\n#ifdef SCENE_DIRECT_LIGHT_COUNT\n\n struct DirectLight {\n vec3 color;\n vec3 direction;\n };\n\n ivec2 scene_DirectLightCullingMask[SCENE_DIRECT_LIGHT_COUNT];\n vec3 scene_DirectLightColor[SCENE_DIRECT_LIGHT_COUNT];\n vec3 scene_DirectLightDirection[SCENE_DIRECT_LIGHT_COUNT];\n\n #ifdef GRAPHICS_API_WEBGL2\n DirectLight getDirectLight(int index){\n DirectLight light;\n light.color = scene_DirectLightColor[index];\n light.direction = scene_DirectLightDirection[index];\n \n return light;\n }\n #endif\n\n#endif\n\n\n// Point light\n#ifdef SCENE_POINT_LIGHT_COUNT\n\n struct PointLight {\n vec3 color;\n vec3 position;\n float distance;\n };\n\n ivec2 scene_PointLightCullingMask[ SCENE_POINT_LIGHT_COUNT ];\n vec3 scene_PointLightColor[ SCENE_POINT_LIGHT_COUNT ];\n vec3 scene_PointLightPosition[ SCENE_POINT_LIGHT_COUNT ];\n float scene_PointLightDistance[ SCENE_POINT_LIGHT_COUNT ];\n\n #ifdef GRAPHICS_API_WEBGL2\n PointLight getPointLight(int index){\n PointLight light;\n light.color = scene_PointLightColor[index];\n light.position = scene_PointLightPosition[index];\n light.distance = scene_PointLightDistance[index];\n\n return light;\n }\n #endif\n\n#endif\n\n\n// Spot light\n#ifdef SCENE_SPOT_LIGHT_COUNT\n\n struct SpotLight {\n vec3 color;\n vec3 position;\n vec3 direction;\n float distance;\n float angleCos;\n float penumbraCos;\n };\n\n ivec2 scene_SpotLightCullingMask[ SCENE_SPOT_LIGHT_COUNT ];\n vec3 scene_SpotLightColor[ SCENE_SPOT_LIGHT_COUNT ];\n vec3 scene_SpotLightPosition[ SCENE_SPOT_LIGHT_COUNT ];\n vec3 scene_SpotLightDirection[ SCENE_SPOT_LIGHT_COUNT ];\n float scene_SpotLightDistance[ SCENE_SPOT_LIGHT_COUNT ];\n float scene_SpotLightAngleCos[ SCENE_SPOT_LIGHT_COUNT ];\n float scene_SpotLightPenumbraCos[ SCENE_SPOT_LIGHT_COUNT ];\n\n #ifdef GRAPHICS_API_WEBGL2\n SpotLight getSpotLight(int index){\n SpotLight light;\n light.color = scene_SpotLightColor[index];\n light.position = scene_SpotLightPosition[index];\n light.direction = scene_SpotLightDirection[index];\n light.distance = scene_SpotLightDistance[index];\n light.angleCos = scene_SpotLightAngleCos[index];\n light.penumbraCos = scene_SpotLightPenumbraCos[index];\n\n return light;\n }\n #endif\n\n\n#endif\n\n// Ambient light\nstruct EnvMapLight {\n vec3 diffuse;\n float mipMapLevel;\n float diffuseIntensity;\n float specularIntensity;\n};\n\n\nEnvMapLight scene_EnvMapLight;\n\n#ifdef SCENE_USE_SH\n vec3 scene_EnvSH[9];\n#endif\n\n#ifdef SCENE_USE_SPECULAR_ENV\n samplerCube scene_EnvSpecularSampler;\n#endif\n\n\n\n\n#endif\n"; // eslint-disable-line
49
+
50
+ var Normal = "#ifndef NORMAL_INCLUDED\n#define NORMAL_INCLUDED\n\n\nvec3 getNormalByNormalTexture(mat3 tbn, sampler2D normalTexture, float normalIntensity, vec2 uv, bool isFrontFacing){\n vec3 normal = (texture2D(normalTexture, uv)).rgb;\n normal = normalize(tbn * ((2.0 * normal - 1.0) * vec3(normalIntensity, normalIntensity, 1.0)));\n normal *= float( isFrontFacing ) * 2.0 - 1.0;\n\n return normal;\n}\n\nmat3 getTBNByDerivatives(vec2 uv, vec3 normal, vec3 position, bool isFrontFacing){\n #ifdef HAS_DERIVATIVES\n uv = isFrontFacing? uv: -uv;\n // ref: http://www.thetenthplanet.de/archives/1180\n // get edge vectors of the pixel triangle\n\t vec3 dp1 = dFdx(position);\n\t vec3 dp2 = dFdy(position);\n\t vec2 duv1 = dFdx(uv);\n\t vec2 duv2 = dFdy(uv);\n\t // solve the linear system\n\t vec3 dp2perp = cross(dp2, normal);\n\t vec3 dp1perp = cross(normal, dp1);\n\t vec3 tangent = dp2perp * duv1.x + dp1perp * duv2.x;\n\t vec3 bitangent = dp2perp * duv1.y + dp1perp * duv2.y;\n\t // construct a scale-invariant frame \n float denom = max( dot(tangent, tangent), dot(bitangent, bitangent) );\n float invmax = (denom == 0.0) ? 0.0 : camera_ProjectionParams.x / sqrt( denom );\n\t return mat3(tangent * invmax, bitangent * invmax, normal);\n #else\n return mat3(vec3(0.0), vec3(0.0), normal);\n #endif\n}\n\n\n#endif"; // eslint-disable-line
51
+
52
+ var PBR = "Shader \"PBRShaderName\" {\n Editor {\n Properties{\n Header(\"Base\"){\n material_IOR(\"IOR\", Range(0, 5, 0.01)) = 1.5;\n material_BaseColor(\"BaseColor\", Color) = (1, 1, 1, 1);\n material_BaseTexture(\"BaseTexture\", Texture2D);\n }\n\n Header(\"Metal Roughness\") {\n material_Metal( \"Metal\", Range(0,1,0.01) ) = 1;\n material_Roughness( \"Roughness\", Range( 0, 1, 0.01 ) ) = 1;\n material_RoughnessMetallicTexture(\"RoughnessMetallicTexture\", Texture2D);\n }\n \n Header(\"Specular\") {\n material_SpecularIntensity( \"Intensity\", Range(0,2,0.01) ) = 1;\n material_SpecularColor( \"Color\", Color ) = (1, 1, 1, 1);\n material_SpecularIntensityTexture(\"IntensityTexture\", Texture2D);\n material_SpecularColorTexture(\"ColorTexture\", Texture2D);\n }\n\n Header(\"Anisotropy\") {\n anisotropy(\"Intensity\", Range(0, 1, 0.01)) = 0;\n anisotropyRotation(\"Rotation\", Range(0, 360, 1)) = 0;\n material_AnisotropyTexture(\"Texture\", Texture2D);\n }\n\n Header(\"Normal\") {\n material_NormalTexture(\"NormalTexture\", Texture2D);\n material_NormalIntensity(\"NormalIntensity\", Range(0, 5, 0.01)) = 1;\n }\n\n Header(\"Emissive\") {\n material_EmissiveColor(\"EmissiveColor\", HDRColor ) = (0, 0, 0, 1);\n material_EmissiveTexture(\"EmissiveTexture\", Texture2D);\n }\n\n Header(\"Occlusion\") {\n material_OcclusionTexture(\"OcclusionTexture\", Texture2D);\n material_OcclusionIntensity(\"OcclusionIntensity\", Range(0, 5, 0.01)) = 1;\n material_OcclusionTextureCoord(\"OcclusionTextureCoord\", Float) = 0;\n }\n \n Header(\"Clear Coat\") {\n material_ClearCoat(\"ClearCoat\", Range(0, 1, 0.01)) = 0;\n material_ClearCoatTexture(\"ClearCoatTexture\", Texture2D);\n material_ClearCoatRoughness(\"ClearCoatRoughness\", Range(0, 1, 0.01)) = 0;\n material_ClearCoatRoughnessTexture(\"ClearCoatRoughnessTexture\", Texture2D);\n material_ClearCoatNormalTexture(\"ClearCoatNormalTexture\", Texture2D);\n }\n\n Header(\"Thin Film Iridescence\"){\n iridescence(\"Iridescence\", Range(0, 1, 0.01)) = 0;\n iridescenceIOR(\"IOR\", Range(1, 5, 0.01)) = 1.3;\n iridescenceRange(\"ThicknessRange\", Vector2) = (100, 400);\n material_IridescenceThicknessTexture(\"ThicknessTexture\", Texture2D);\n material_IridescenceTexture(\"IridescenceTexture\", Texture2D);\n }\n\n Header(\"Sheen\"){\n sheenColor(\"Color\", Color ) = (0, 0, 0, 1);\n sheenIntensity(\"Intensity\", Range(0, 1, 0.01)) = 1;\n material_SheenRoughness(\"Roughness\", Range(0, 1, 0.01)) = 0;\n material_SheenTexture(\"ColorTexture\", Texture2D);\n material_SheenRoughnessTexture(\"RoughnessTexture\", Texture2D);\n }\n\n Header(\"Transmission\") {\n material_Transmission(\"Transmission\", Range(0, 1, 0.01)) = 0;\n material_TransmissionTexture(\"TransmissionTexture\", Texture2D);\n material_Thickness(\"Thickness\", Range(0, 5, 0.01)) = 0;\n material_ThicknessTexture(\"ThicknessTexture\", Texture2D);\n refractionMode(\"RefractionMode\", Enum(Sphere:0, Planar:1)) = 1;\n material_AttenuationColor(\"AttenuationColor\", Color ) = (1, 1, 1, 1);\n material_AttenuationDistance(\"AttenuationDistance\", Range(0, 1, 0.01)) = 0;\n }\n\n Header(\"Common\") {\n isTransparent(\"Transparent\", Boolean) = false;\n renderFace(\"Render Face\", Enum(Front:0, Back:1, Double:2)) = 0;\n blendMode(\"Blend Mode\", Enum(Normal:0, Additive:1)) = 0;\n material_AlphaCutoff( \"AlphaCutoff\", Range(0, 1, 0.01) ) = 0;\n material_TilingOffset(\"TilingOffset\", Vector4) = (1, 1, 0, 0);\n }\n }\n \n UIScript \"UIScriptPath\";\n }\n \n SubShader \"Default\" {\n UsePass \"pbr/Default/ShadowCaster\"\n\n Pass \"Forward Pass\" {\n Tags { pipelineStage = \"Forward\"} \n\n RenderQueueType renderQueueType;\n BlendFactor sourceColorBlendFactor;\n BlendFactor destinationColorBlendFactor;\n BlendFactor sourceAlphaBlendFactor;\n BlendFactor destinationAlphaBlendFactor;\n CullMode rasterStateCullMode;\n Bool blendEnabled;\n Bool depthWriteEnabled;\n\n DepthState customDepthState {\n WriteEnabled = depthWriteEnabled;\n }\n\n BlendState customBlendState {\n Enabled = blendEnabled;\n SourceColorBlendFactor = sourceColorBlendFactor;\n DestinationColorBlendFactor = destinationColorBlendFactor;\n SourceAlphaBlendFactor = sourceAlphaBlendFactor;\n DestinationAlphaBlendFactor = destinationAlphaBlendFactor;\n }\n\n RasterState customRasterState {\n CullMode = rasterStateCullMode;\n }\n\n DepthState = customDepthState;\n BlendState = customBlendState;\n RasterState = customRasterState;\n RenderQueueType = renderQueueType;\n \n VertexShader = PBRVertex;\n FragmentShader = PBRFragment;\n\n #include \"ForwardPassPBR.glsl\"\n }\n }\n }"; // eslint-disable-line
53
+
54
+ var Shadow = "#ifndef SHADOW_INCLUDED\n#define SHADOW_INCLUDED\n\n\n#if defined(SCENE_SHADOW_TYPE) && defined(RENDERER_IS_RECEIVE_SHADOWS)\n #define NEED_CALCULATE_SHADOWS\n#endif\n\n\n#ifdef NEED_CALCULATE_SHADOWS\n mat4 scene_ShadowMatrices[SCENE_SHADOW_CASCADED_COUNT + 1];\n vec4 scene_ShadowSplitSpheres[4];\n\n mediump int computeCascadeIndex(vec3 positionWS) {\n vec3 fromCenter0 = positionWS - scene_ShadowSplitSpheres[0].xyz;\n vec3 fromCenter1 = positionWS - scene_ShadowSplitSpheres[1].xyz;\n vec3 fromCenter2 = positionWS - scene_ShadowSplitSpheres[2].xyz;\n vec3 fromCenter3 = positionWS - scene_ShadowSplitSpheres[3].xyz;\n\n mediump vec4 comparison = vec4(\n (dot(fromCenter0, fromCenter0) < scene_ShadowSplitSpheres[0].w),\n (dot(fromCenter1, fromCenter1) < scene_ShadowSplitSpheres[1].w),\n (dot(fromCenter2, fromCenter2) < scene_ShadowSplitSpheres[2].w),\n (dot(fromCenter3, fromCenter3) < scene_ShadowSplitSpheres[3].w));\n comparison.yzw = clamp(comparison.yzw - comparison.xyz,0.0,1.0);//keep the nearest\n mediump vec4 indexCoefficient = vec4(4.0,3.0,2.0,1.0);\n mediump int index = 4 - int(dot(comparison, indexCoefficient));\n return index;\n }\n\n vec3 getShadowCoord(vec3 positionWS) {\n #if SCENE_SHADOW_CASCADED_COUNT == 1\n mediump int cascadeIndex = 0;\n #else\n mediump int cascadeIndex = computeCascadeIndex(positionWS);\n #endif\n \n #ifdef GRAPHICS_API_WEBGL2\n mat4 shadowMatrix = scene_ShadowMatrices[cascadeIndex];\n #else\n mat4 shadowMatrix;\n #if SCENE_SHADOW_CASCADED_COUNT == 4\n if (cascadeIndex == 0) {\n shadowMatrix = scene_ShadowMatrices[0];\n } else if (cascadeIndex == 1) {\n shadowMatrix = scene_ShadowMatrices[1];\n } else if (cascadeIndex == 2) {\n shadowMatrix = scene_ShadowMatrices[2];\n } else if (cascadeIndex == 3) {\n shadowMatrix = scene_ShadowMatrices[3];\n } else {\n shadowMatrix = scene_ShadowMatrices[4];\n }\n #endif\n #if SCENE_SHADOW_CASCADED_COUNT == 2\n if (cascadeIndex == 0) {\n shadowMatrix = scene_ShadowMatrices[0];\n } else if (cascadeIndex == 1) {\n shadowMatrix = scene_ShadowMatrices[1];\n } else {\n shadowMatrix = scene_ShadowMatrices[2];\n } \n #endif\n #if SCENE_SHADOW_CASCADED_COUNT == 1\n if (cascadeIndex == 0) {\n shadowMatrix = scene_ShadowMatrices[0];\n } else {\n shadowMatrix = scene_ShadowMatrices[1];\n } \n #endif\n #endif\n \n vec4 shadowCoord = shadowMatrix * vec4(positionWS, 1.0);\n return shadowCoord.xyz;\n }\n#endif\n\n\n#ifdef NEED_CALCULATE_SHADOWS\n // intensity, null, fadeScale, fadeBias\n vec4 scene_ShadowInfo;\n vec4 scene_ShadowMapSize;\n\n #ifdef GRAPHICS_API_WEBGL2\n mediump sampler2DShadow scene_ShadowMap;\n #define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) textureLod(textureName, coord3 , 0.0)\n #define TEXTURE2D_SHADOW_PARAM(shadowMap) mediump sampler2DShadow shadowMap\n #else\n sampler2D scene_ShadowMap;\n #ifdef ENGINE_NO_DEPTH_TEXTURE\n const vec4 bitShift = vec4(1.0, 1.0/256.0, 1.0/(256.0*256.0), 1.0/(256.0*256.0*256.0));\n float textureShadowMapDowngrade(sampler2D scene_ShadowMap, vec3 shadowCoord){\n vec4 rgbaDepth = texture2D(scene_ShadowMap, shadowCoord.xy);\n float unpackDepth = dot(rgbaDepth, bitShift);\n return unpackDepth < shadowCoord.z ? 0.0 : 1.0;\n }\n #define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) textureShadowMapDowngrade(textureName, coord3)\n #else\n float textureShadowMapDowngrade(sampler2D scene_ShadowMap, vec3 shadowCoord){\n float depth = texture2D(scene_ShadowMap, shadowCoord.xy).r;\n return depth < shadowCoord.z ? 0.0 : 1.0;\n }\n #define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) textureShadowMapDowngrade(textureName, coord3)\n #endif\n #define TEXTURE2D_SHADOW_PARAM(shadowMap) mediump sampler2D shadowMap\n #endif\n\n #if SCENE_SHADOW_TYPE == 2\n float sampleShadowMapFiltered4(TEXTURE2D_SHADOW_PARAM(shadowMap), vec3 shadowCoord, vec4 shadowMapSize) {\n float attenuation;\n vec4 attenuation4;\n vec2 offset=shadowMapSize.xy/2.0;\n vec3 shadowCoord0=shadowCoord + vec3(-offset,0.0);\n vec3 shadowCoord1=shadowCoord + vec3(offset.x,-offset.y,0.0);\n vec3 shadowCoord2=shadowCoord + vec3(-offset.x,offset.y,0.0);\n vec3 shadowCoord3=shadowCoord + vec3(offset,0.0);\n attenuation4.x = SAMPLE_TEXTURE2D_SHADOW(shadowMap, shadowCoord0);\n attenuation4.y = SAMPLE_TEXTURE2D_SHADOW(shadowMap, shadowCoord1);\n attenuation4.z = SAMPLE_TEXTURE2D_SHADOW(shadowMap, shadowCoord2);\n attenuation4.w = SAMPLE_TEXTURE2D_SHADOW(shadowMap, shadowCoord3);\n attenuation = dot(attenuation4, vec4(0.25));\n return attenuation;\n }\n #endif\n\n #if SCENE_SHADOW_TYPE == 3\n #include \"ShadowSampleTent.glsl\"\n\n float sampleShadowMapFiltered9(TEXTURE2D_SHADOW_PARAM(shadowMap), vec3 shadowCoord, vec4 shadowmapSize) {\n float attenuation;\n float fetchesWeights[9];\n vec2 fetchesUV[9];\n sampleShadowComputeSamplesTent5x5(shadowmapSize, shadowCoord.xy, fetchesWeights, fetchesUV);\n attenuation = fetchesWeights[0] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[0].xy, shadowCoord.z));\n attenuation += fetchesWeights[1] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[1].xy, shadowCoord.z));\n attenuation += fetchesWeights[2] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[2].xy, shadowCoord.z));\n attenuation += fetchesWeights[3] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[3].xy, shadowCoord.z));\n attenuation += fetchesWeights[4] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[4].xy, shadowCoord.z));\n attenuation += fetchesWeights[5] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[5].xy, shadowCoord.z));\n attenuation += fetchesWeights[6] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[6].xy, shadowCoord.z));\n attenuation += fetchesWeights[7] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[7].xy, shadowCoord.z));\n attenuation += fetchesWeights[8] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[8].xy, shadowCoord.z));\n return attenuation;\n }\n #endif\n\n\n float getShadowFade(vec3 positionWS){\n vec3 camToPixel = positionWS - camera_Position;\n float distanceCamToPixel2 = dot(camToPixel, camToPixel);\n return saturate( distanceCamToPixel2 * scene_ShadowInfo.z + scene_ShadowInfo.w );\n }\n\n\n float sampleShadowMap(vec3 positionWS, vec3 shadowCoord) {\n float attenuation = 1.0;\n if(shadowCoord.z > 0.0 && shadowCoord.z < 1.0) {\n #if SCENE_SHADOW_TYPE == 1\n attenuation = SAMPLE_TEXTURE2D_SHADOW(scene_ShadowMap, shadowCoord);\n #endif\n\n #if SCENE_SHADOW_TYPE == 2\n attenuation = sampleShadowMapFiltered4(scene_ShadowMap, shadowCoord, scene_ShadowMapSize);\n #endif\n\n #if SCENE_SHADOW_TYPE == 3\n attenuation = sampleShadowMapFiltered9(scene_ShadowMap, shadowCoord, scene_ShadowMapSize);\n #endif\n attenuation = mix(1.0, attenuation, scene_ShadowInfo.x);\n }\n\n float shadowFade = getShadowFade(positionWS);\n attenuation = mix(1.0, mix(attenuation, 1.0, shadowFade), scene_ShadowInfo.x);\n\n return attenuation;\n }\n#endif\n\n\n#endif"; // eslint-disable-line
55
+
56
+ var ShadowSampleTent = "#ifndef SHADOW_SAMPLE_TENT_INCLUDED\n#define SHADOW_SAMPLE_TENT_INCLUDED\n\n// ------------------------------------------------------------------\n// PCF Filtering Tent Functions\n// ------------------------------------------------------------------\n\n// Assuming a isoceles right angled triangle of height \"triangleHeight\" (as drawn below).\n// This function return the area of the triangle above the first texel(in Y the first texel).\n//\n// |\\ <-- 45 degree slop isosceles right angled triangle\n// | \\\n// ---- <-- length of this side is \"triangleHeight\"\n// _ _ _ _ <-- texels\nfloat sampleShadowGetIRTriangleTexelArea(float triangleHeight) {\n return triangleHeight - 0.5;\n}\n\n// Assuming a isoceles triangle of 1.5 texels height and 3 texels wide lying on 4 texels.\n// This function return the area of the triangle above each of those texels.\n// | <-- offset from -0.5 to 0.5, 0 meaning triangle is exactly in the center\n// / \\ <-- 45 degree slop isosceles triangle (ie tent projected in 2D)\n// / \\\n// _ _ _ _ <-- texels\n// X Y Z W <-- result indices (in computedArea.xyzw and computedAreaUncut.xyzw)\n// Top point at (right,top) in a texel,left bottom point at (middle,middle) in a texel,right bottom point at (middle,middle) in a texel.\nvoid sampleShadowGetTexelAreasTent3x3(float offset, out vec4 computedArea, out vec4 computedAreaUncut) {\n // Compute the exterior areas,a and h is same.\n float a = offset + 0.5;\n float offsetSquaredHalved = a * a * 0.5;\n computedAreaUncut.x = computedArea.x = offsetSquaredHalved - offset;\n computedAreaUncut.w = computedArea.w = offsetSquaredHalved;\n\n // Compute the middle areas\n // For Y : We find the area in Y of as if the left section of the isoceles triangle would\n // intersect the axis between Y and Z (ie where offset = 0).\n computedAreaUncut.y = sampleShadowGetIRTriangleTexelArea(1.5 - offset);\n // This area is superior to the one we are looking for if (offset < 0) thus we need to\n // subtract the area of the triangle defined by (0,1.5-offset), (0,1.5+offset), (-offset,1.5).\n float clampedOffsetLeft = min(offset,0.0);\n float areaOfSmallLeftTriangle = clampedOffsetLeft * clampedOffsetLeft;\n computedArea.y = computedAreaUncut.y - areaOfSmallLeftTriangle;\n\n // We do the same for the Z but with the right part of the isoceles triangle\n computedAreaUncut.z = sampleShadowGetIRTriangleTexelArea(1.5 + offset);\n float clampedOffsetRight = max(offset,0.0);\n float areaOfSmallRightTriangle = clampedOffsetRight * clampedOffsetRight;\n computedArea.z = computedAreaUncut.z - areaOfSmallRightTriangle;\n}\n\n// Assuming a isoceles triangle of 2.5 texel height and 5 texels wide lying on 6 texels.\n// This function return the weight of each texels area relative to the full triangle area.\n// / \\\n// _ _ _ _ _ _ <-- texels\n// 0 1 2 3 4 5 <-- computed area indices (in texelsWeights[])\n// Top point at (right,top) in a texel,left bottom point at (middle,middle) in a texel,right bottom point at (middle,middle) in a texel.\nvoid sampleShadowGetTexelWeightsTent5x5(float offset, out vec3 texelsWeightsA, out vec3 texelsWeightsB) {\n vec4 areaFrom3texelTriangle;\n vec4 areaUncutFrom3texelTriangle;\n sampleShadowGetTexelAreasTent3x3(offset, areaFrom3texelTriangle, areaUncutFrom3texelTriangle);\n\n // Triangle slope is 45 degree thus we can almost reuse the result of the 3 texel wide computation.\n // the 5 texel wide triangle can be seen as the 3 texel wide one but shifted up by one unit/texel.\n // 0.16 is 1/(the triangle area)\n texelsWeightsA.x = 0.16 * (areaFrom3texelTriangle.x);\n texelsWeightsA.y = 0.16 * (areaUncutFrom3texelTriangle.y);\n texelsWeightsA.z = 0.16 * (areaFrom3texelTriangle.y + 1.0);\n texelsWeightsB.x = 0.16 * (areaFrom3texelTriangle.z + 1.0);\n texelsWeightsB.y = 0.16 * (areaUncutFrom3texelTriangle.z);\n texelsWeightsB.z = 0.16 * (areaFrom3texelTriangle.w);\n}\n\n// 5x5 Tent filter (45 degree sloped triangles in U and V)\nvoid sampleShadowComputeSamplesTent5x5(vec4 shadowMapTextureTexelSize, vec2 coord, out float fetchesWeights[9], out vec2 fetchesUV[9])\n{\n // tent base is 5x5 base thus covering from 25 to 36 texels, thus we need 9 bilinear PCF fetches\n vec2 tentCenterInTexelSpace = coord.xy * shadowMapTextureTexelSize.zw;\n vec2 centerOfFetchesInTexelSpace = floor(tentCenterInTexelSpace + 0.5);\n vec2 offsetFromTentCenterToCenterOfFetches = tentCenterInTexelSpace - centerOfFetchesInTexelSpace;\n\n // find the weight of each texel based on the area of a 45 degree slop tent above each of them.\n vec3 texelsWeightsUA, texelsWeightsUB;\n vec3 texelsWeightsVA, texelsWeightsVB;\n sampleShadowGetTexelWeightsTent5x5(offsetFromTentCenterToCenterOfFetches.x, texelsWeightsUA, texelsWeightsUB);\n sampleShadowGetTexelWeightsTent5x5(offsetFromTentCenterToCenterOfFetches.y, texelsWeightsVA, texelsWeightsVB);\n\n // each fetch will cover a group of 2x2 texels, the weight of each group is the sum of the weights of the texels\n vec3 fetchesWeightsU = vec3(texelsWeightsUA.xz, texelsWeightsUB.y) + vec3(texelsWeightsUA.y, texelsWeightsUB.xz);\n vec3 fetchesWeightsV = vec3(texelsWeightsVA.xz, texelsWeightsVB.y) + vec3(texelsWeightsVA.y, texelsWeightsVB.xz);\n\n // move the PCF bilinear fetches to respect texels weights\n vec3 fetchesOffsetsU = vec3(texelsWeightsUA.y, texelsWeightsUB.xz) / fetchesWeightsU.xyz + vec3(-2.5,-0.5,1.5);\n vec3 fetchesOffsetsV = vec3(texelsWeightsVA.y, texelsWeightsVB.xz) / fetchesWeightsV.xyz + vec3(-2.5,-0.5,1.5);\n fetchesOffsetsU *= shadowMapTextureTexelSize.xxx;\n fetchesOffsetsV *= shadowMapTextureTexelSize.yyy;\n\n vec2 bilinearFetchOrigin = centerOfFetchesInTexelSpace * shadowMapTextureTexelSize.xy;\n fetchesUV[0] = bilinearFetchOrigin + vec2(fetchesOffsetsU.x, fetchesOffsetsV.x);\n fetchesUV[1] = bilinearFetchOrigin + vec2(fetchesOffsetsU.y, fetchesOffsetsV.x);\n fetchesUV[2] = bilinearFetchOrigin + vec2(fetchesOffsetsU.z, fetchesOffsetsV.x);\n fetchesUV[3] = bilinearFetchOrigin + vec2(fetchesOffsetsU.x, fetchesOffsetsV.y);\n fetchesUV[4] = bilinearFetchOrigin + vec2(fetchesOffsetsU.y, fetchesOffsetsV.y);\n fetchesUV[5] = bilinearFetchOrigin + vec2(fetchesOffsetsU.z, fetchesOffsetsV.y);\n fetchesUV[6] = bilinearFetchOrigin + vec2(fetchesOffsetsU.x, fetchesOffsetsV.z);\n fetchesUV[7] = bilinearFetchOrigin + vec2(fetchesOffsetsU.y, fetchesOffsetsV.z);\n fetchesUV[8] = bilinearFetchOrigin + vec2(fetchesOffsetsU.z, fetchesOffsetsV.z);\n\n fetchesWeights[0] = fetchesWeightsU.x * fetchesWeightsV.x;\n fetchesWeights[1] = fetchesWeightsU.y * fetchesWeightsV.x;\n fetchesWeights[2] = fetchesWeightsU.z * fetchesWeightsV.x;\n fetchesWeights[3] = fetchesWeightsU.x * fetchesWeightsV.y;\n fetchesWeights[4] = fetchesWeightsU.y * fetchesWeightsV.y;\n fetchesWeights[5] = fetchesWeightsU.z * fetchesWeightsV.y;\n fetchesWeights[6] = fetchesWeightsU.x * fetchesWeightsV.z;\n fetchesWeights[7] = fetchesWeightsU.y * fetchesWeightsV.z;\n fetchesWeights[8] = fetchesWeightsU.z * fetchesWeightsV.z;\n}\n\n\n#endif"; // eslint-disable-line
57
+
58
+ var Skin = "#ifndef SKIN_INCLUDED\n#define SKIN_INCLUDED\n\n\n#ifdef RENDERER_HAS_SKIN\n #ifdef RENDERER_USE_JOINT_TEXTURE\n sampler2D renderer_JointSampler;\n float renderer_JointCount;\n\n mat4 getJointMatrix(sampler2D smp, float index){\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 #else\n mat4 renderer_JointMatrix[ RENDERER_JOINTS_NUM ];\n #endif\n\n mat4 getSkinMatrix(Attributes attributes){\n #ifdef RENDERER_USE_JOINT_TEXTURE\n mat4 skinMatrix =\n attributes.WEIGHTS_0.x * getJointMatrix(renderer_JointSampler, attributes.JOINTS_0.x ) +\n attributes.WEIGHTS_0.y * getJointMatrix(renderer_JointSampler, attributes.JOINTS_0.y ) +\n attributes.WEIGHTS_0.z * getJointMatrix(renderer_JointSampler, attributes.JOINTS_0.z ) +\n attributes.WEIGHTS_0.w * getJointMatrix(renderer_JointSampler, attributes.JOINTS_0.w );\n #else\n mat4 skinMatrix =\n attributes.WEIGHTS_0.x * renderer_JointMatrix[ int( attributes.JOINTS_0.x ) ] +\n attributes.WEIGHTS_0.y * renderer_JointMatrix[ int( attributes.JOINTS_0.y ) ] +\n attributes.WEIGHTS_0.z * renderer_JointMatrix[ int( attributes.JOINTS_0.z ) ] +\n attributes.WEIGHTS_0.w * renderer_JointMatrix[ int( attributes.JOINTS_0.w ) ];\n #endif\n\n return skinMatrix;\n }\n\n#endif\n\n\n#endif"; // eslint-disable-line
59
+
60
+ var Transform = "#ifndef TRANSFORM_INCLUDED\n#define TRANSFORM_INCLUDED\n\nmat4 renderer_LocalMat;\nmat4 renderer_ModelMat;\nmat4 camera_ViewMat;\nmat4 camera_ProjMat;\nmat4 renderer_MVMat;\nmat4 renderer_MVPMat;\nmat4 renderer_NormalMat;\n\nvec3 camera_Position;\nvec3 camera_Forward; \nvec4 camera_ProjectionParams;\n\n#endif"; // eslint-disable-line
61
+
62
+ var AttributesPBR = "#ifndef ATTRIBUTES_PBR_INCLUDED\n#define ATTRIBUTES_PBR_INCLUDED\n\n\nstruct Attributes{\n \tvec3 POSITION;\n\n\t#ifdef RENDERER_HAS_BLENDSHAPE\n \t#ifndef RENDERER_BLENDSHAPE_USE_TEXTURE\n \t\tvec3 POSITION_BS0;\n \t \tvec3 POSITION_BS1;\n \t \t#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\n \t \tvec3 NORMAL_BS0;\n \t \tvec3 NORMAL_BS1;\n \t \tvec3 TANGENT_BS0;\n \t \tvec3 TANGENT_BS1;\n \t \t#else\n \t \t#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) || defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\n \t \t vec3 POSITION_BS2;\n \t \t vec3 POSITION_BS3;\n\n \t \t #ifdef RENDERER_BLENDSHAPE_HAS_NORMAL\n \t \t vec3 NORMAL_BS0;\n \t \t vec3 NORMAL_BS1;\n \t \t vec3 NORMAL_BS2;\n \t \t vec3 NORMAL_BS3;\n \t \t #endif\n\n \t \t #ifdef RENDERER_BLENDSHAPE_HAS_TANGENT\n \t \t vec3 TANGENT_BS0;\n \t \t vec3 TANGENT_BS1;\n \t \t vec3 TANGENT_BS2;\n \t \t vec3 TANGENT_BS3;\n \t \t #endif\n\n \t \t#else\n \t \t vec3 POSITION_BS2;\n \t \t vec3 POSITION_BS3;\n \t \t vec3 POSITION_BS4;\n \t \t vec3 POSITION_BS5;\n \t \t vec3 POSITION_BS6;\n \t \t vec3 POSITION_BS7;\n \t #endif\n \t#endif\n #endif\n #endif\n\n\n \t#ifdef RENDERER_HAS_UV\n \t vec2 TEXCOORD_0;\n \t#endif\n\n \t#ifdef RENDERER_HAS_UV1\n \t vec2 TEXCOORD_1;\n \t#endif\n\n \t#ifdef RENDERER_HAS_SKIN\n \t vec4 JOINTS_0;\n \t vec4 WEIGHTS_0;\n \t#endif\n\n \t#ifdef RENDERER_ENABLE_VERTEXCOLOR\n \t vec4 COLOR_0;\n \t#endif\n\n\t#ifdef RENDERER_HAS_NORMAL\n\t vec3 NORMAL;\n\t#endif\n\n #ifdef RENDERER_HAS_TANGENT\n vec4 TANGENT;\n #endif\n};\n\n\n#endif"; // eslint-disable-line
63
+
64
+ var ForwardPassPBR = "#ifndef FORWARD_PASS_PBR_INCLUDED\n#define FORWARD_PASS_PBR_INCLUDED\n\n#include \"Common.glsl\"\n#include \"Fog.glsl\"\n#include \"Transform.glsl\"\n#include \"Skin.glsl\"\n#include \"BlendShape.glsl\"\n#include \"Shadow.glsl\"\n\n#include \"AttributesPBR.glsl\"\n#include \"VaryingsPBR.glsl\"\n#include \"LightDirectPBR.glsl\"\n#include \"LightIndirectPBR.glsl\"\n#include \"VertexPBR.glsl\"\n#include \"FragmentPBR.glsl\"\n\n\nVaryings PBRVertex(Attributes attributes) {\n Varyings varyings;\n\n varyings.uv = getUV0(attributes);\n #ifdef RENDERER_HAS_UV1\n varyings.uv1 = attributes.TEXCOORD_1;\n #endif\n\n #ifdef RENDERER_ENABLE_VERTEXCOLOR\n varyings.vertexColor = attributes.COLOR_0;\n #endif\n\n\n VertexInputs vertexInputs = getVertexInputs(attributes);\n\n // positionWS\n varyings.positionWS = vertexInputs.positionWS;\n\n // positionVS\n #if SCENE_FOG_MODE != 0\n\t varyings.positionVS = vertexInputs.positionVS;\n\t#endif\n\n // normalWS、tangentWS、bitangentWS\n #ifdef RENDERER_HAS_NORMAL\n varyings.normalWS = vertexInputs.normalWS;\n #ifdef RENDERER_HAS_TANGENT\n varyings.tangentWS = vertexInputs.tangentWS;\n varyings.bitangentWS = vertexInputs.bitangentWS;\n #endif\n #endif\n\n // ShadowCoord\n #if defined(NEED_CALCULATE_SHADOWS) && (SCENE_SHADOW_CASCADED_COUNT == 1)\n varyings.shadowCoord = getShadowCoord(vertexInputs.positionWS);\n #endif\n\n gl_Position = renderer_MVPMat * vertexInputs.positionOS;\n\n return varyings;\n}\n\n\nvoid PBRFragment(Varyings varyings) {\n BSDFData bsdfData;\n\n // Get aoUV\n vec2 aoUV = varyings.uv;\n #if defined(MATERIAL_HAS_OCCLUSION_TEXTURE) && defined(RENDERER_HAS_UV1)\n if(material_OcclusionTextureCoord == 1.0){\n aoUV = varyings.uv1;\n }\n #endif\n\n SurfaceData surfaceData = getSurfaceData(varyings, aoUV, gl_FrontFacing);\n\n // Can modify surfaceData here\n initBSDFData(surfaceData, bsdfData);\n\n\n vec3 totalDiffuseColor = vec3(0, 0, 0);\n vec3 totalSpecularColor = vec3(0, 0, 0);\n\n // Get shadow attenuation\n float shadowAttenuation = 1.0;\n #if defined(SCENE_DIRECT_LIGHT_COUNT) && defined(NEED_CALCULATE_SHADOWS)\n #if SCENE_SHADOW_CASCADED_COUNT == 1\n vec3 shadowCoord = varyings.shadowCoord;\n #else\n vec3 shadowCoord = getShadowCoord(varyings.positionWS);\n #endif\n shadowAttenuation *= sampleShadowMap(varyings.positionWS, shadowCoord);\n #endif\n\n // Evaluate direct lighting\n evaluateDirectRadiance(varyings, surfaceData, bsdfData, shadowAttenuation, totalDiffuseColor, totalSpecularColor);\n\n // IBL\n evaluateIBL(varyings, surfaceData, bsdfData, totalDiffuseColor, totalSpecularColor);\n\n #ifdef MATERIAL_ENABLE_TRANSMISSION \n vec3 refractionTransmitted = evaluateTransmission(surfaceData, bsdfData);\n totalDiffuseColor = mix(totalDiffuseColor, refractionTransmitted, surfaceData.transmission);\n #endif\n\n // Final color\n vec4 color = vec4((totalDiffuseColor + totalSpecularColor).rgb, surfaceData.opacity);\n\n // Emissive\n color.rgb += surfaceData.emissiveColor;\n\n\n #if SCENE_FOG_MODE != 0\n color = fog(color, varyings.positionVS);\n #endif\n\n gl_FragColor = color;\n}\n\n\n#endif"; // eslint-disable-line
65
+
66
+ var FragmentPBR = "#ifndef MATERIAL_INPUT_PBR_INCLUDED\n#define MATERIAL_INPUT_PBR_INCLUDED\n\n#include \"Normal.glsl\"\n\nfloat material_AlphaCutoff;\nvec4 material_BaseColor;\nfloat material_Metal;\nfloat material_Roughness;\nfloat material_IOR;\nvec3 material_EmissiveColor;\nfloat material_NormalIntensity;\nfloat material_OcclusionIntensity;\nfloat material_OcclusionTextureCoord;\n\nfloat material_SpecularIntensity;\nvec3 material_SpecularColor;\n#ifdef MATERIAL_HAS_SPECULAR_TEXTURE\n sampler2D material_SpecularIntensityTexture;\n#endif\n\n#ifdef MATERIAL_HAS_SPECULAR_COLOR_TEXTURE\n sampler2D material_SpecularColorTexture;\n#endif\n\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\n float material_ClearCoat;\n float material_ClearCoatRoughness;\n\n #ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\n sampler2D material_ClearCoatTexture;\n #endif\n\n #ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\n sampler2D material_ClearCoatRoughnessTexture;\n #endif\n\n #ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\n sampler2D material_ClearCoatNormalTexture;\n #endif\n#endif\n\n#ifdef MATERIAL_ENABLE_ANISOTROPY\n vec3 material_AnisotropyInfo;\n #ifdef MATERIAL_HAS_ANISOTROPY_TEXTURE\n sampler2D material_AnisotropyTexture;\n #endif\n#endif\n\n#ifdef MATERIAL_ENABLE_IRIDESCENCE\n vec4 material_IridescenceInfo;\n #ifdef MATERIAL_HAS_IRIDESCENCE_THICKNESS_TEXTURE\n sampler2D material_IridescenceThicknessTexture;\n #endif\n\n #ifdef MATERIAL_HAS_IRIDESCENCE_TEXTURE\n sampler2D material_IridescenceTexture;\n #endif\n#endif\n\n#ifdef MATERIAL_ENABLE_SHEEN\n float material_SheenRoughness;\n vec3 material_SheenColor;\n #ifdef MATERIAL_HAS_SHEEN_TEXTURE\n sampler2D material_SheenTexture;\n #endif\n\n #ifdef MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE\n sampler2D material_SheenRoughnessTexture;\n #endif\n#endif\n\n#ifdef MATERIAL_ENABLE_TRANSMISSION\n float material_Transmission;\n #ifdef MATERIAL_HAS_TRANSMISSION_TEXTURE\n sampler2D material_TransmissionTexture;\n #endif\n\n #ifdef MATERIAL_HAS_THICKNESS\n vec3 material_AttenuationColor;\n float material_AttenuationDistance;\n float material_Thickness;\n #ifdef MATERIAL_HAS_THICKNESS_TEXTURE\n sampler2D material_ThicknessTexture;\n #endif\n #endif\n#endif\n\n// Texture\n#ifdef MATERIAL_HAS_BASETEXTURE\n sampler2D material_BaseTexture;\n#endif\n\n#ifdef MATERIAL_HAS_NORMALTEXTURE\n sampler2D material_NormalTexture;\n#endif\n\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\n sampler2D material_EmissiveTexture;\n#endif\n\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\n sampler2D material_RoughnessMetallicTexture;\n#endif\n\n#ifdef MATERIAL_HAS_OCCLUSION_TEXTURE\n sampler2D material_OcclusionTexture;\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(SurfaceData surfaceData) {\n vec3 anisotropyDirection = (surfaceData.anisotropy >= 0.0) ? surfaceData.anisotropicB : surfaceData.anisotropicT;\n vec3 anisotropicTangent = cross(anisotropyDirection, surfaceData.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(surfaceData.normal, anisotropicNormal, abs(surfaceData.anisotropy) * saturate( 5.0 * surfaceData.roughness)) );\n\n return bentNormal;\n }\n#endif\n\n\nSurfaceData getSurfaceData(Varyings v, vec2 aoUV, bool isFrontFacing){\n SurfaceData surfaceData;\n\n vec2 uv = v.uv;\n\n // common\n vec4 baseColor = material_BaseColor;\n float metallic = material_Metal;\n float roughness = material_Roughness;\n vec3 emissiveRadiance = material_EmissiveColor;\n\n #ifdef MATERIAL_HAS_BASETEXTURE\n baseColor *= texture2DSRGB(material_BaseTexture, uv);\n #endif\n\n #ifdef RENDERER_ENABLE_VERTEXCOLOR\n baseColor *= v.vertexColor;\n #endif\n\n\n #ifdef MATERIAL_IS_ALPHA_CUTOFF\n if( baseColor.a < material_AlphaCutoff ) {\n discard;\n }\n #endif\n\n #ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\n vec4 metalRoughMapColor = texture2D( material_RoughnessMetallicTexture, uv );\n roughness *= metalRoughMapColor.g;\n metallic *= metalRoughMapColor.b;\n #endif\n\n #ifdef MATERIAL_HAS_EMISSIVETEXTURE\n emissiveRadiance *= texture2DSRGB(material_EmissiveTexture, uv).rgb;\n #endif\n\n surfaceData.albedoColor = baseColor.rgb;\n surfaceData.emissiveColor = emissiveRadiance;\n surfaceData.metallic = metallic;\n surfaceData.roughness = roughness;\n surfaceData.IOR = material_IOR;\n\n #ifdef MATERIAL_IS_TRANSPARENT\n surfaceData.opacity = baseColor.a;\n #else\n surfaceData.opacity = 1.0;\n #endif\n\n\n // Geometry\n surfaceData.position = v.positionWS;\n \n #ifdef CAMERA_ORTHOGRAPHIC\n surfaceData.viewDir = -camera_Forward;\n #else\n surfaceData.viewDir = normalize(camera_Position - v.positionWS);\n #endif\n\n // Normal\n #ifdef RENDERER_HAS_NORMAL\n vec3 normal = normalize(v.normalWS);\n #elif defined(HAS_DERIVATIVES)\n vec3 pos_dx = dFdx(v.positionWS);\n vec3 pos_dy = dFdy(v.positionWS);\n vec3 normal = normalize( cross(pos_dx, pos_dy) );\n normal *= camera_ProjectionParams.x;\n #else\n vec3 normal = vec3(0, 0, 1);\n #endif\n \n normal *= float( isFrontFacing ) * 2.0 - 1.0;\n surfaceData.normal = normal;\n\n // Tangent\n #ifdef NEED_TANGENT\n #if defined(RENDERER_HAS_NORMAL) && defined(RENDERER_HAS_TANGENT)\n surfaceData.tangent = v.tangentWS;\n surfaceData.bitangent = v.bitangentWS;\n mat3 tbn = mat3(v.tangentWS, v.bitangentWS, v.normalWS);\n #else\n mat3 tbn = getTBNByDerivatives(uv, normal, v.positionWS, isFrontFacing);\n surfaceData.tangent = tbn[0];\n surfaceData.bitangent = tbn[1];\n #endif\n\n #ifdef MATERIAL_HAS_NORMALTEXTURE\n surfaceData.normal = getNormalByNormalTexture(tbn, material_NormalTexture, material_NormalIntensity, uv, isFrontFacing);\n #endif\n #endif \n\n surfaceData.dotNV = saturate( dot(surfaceData.normal, surfaceData.viewDir) );\n\n // Specular\n surfaceData.specularIntensity = material_SpecularIntensity;\n surfaceData.specularColor = material_SpecularColor;\n #ifdef MATERIAL_HAS_SPECULAR_TEXTURE\n surfaceData.specularIntensity *= texture2D( material_SpecularIntensityTexture, uv ).a;\n #endif\n\n #ifdef MATERIAL_HAS_SPECULAR_COLOR_TEXTURE\n surfaceData.specularColor *= texture2D( material_SpecularColorTexture, uv ).rgb;\n #endif\n\n // Clear Coat\n #ifdef MATERIAL_ENABLE_CLEAR_COAT\n #ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\n surfaceData.clearCoatNormal = getNormalByNormalTexture(mat3(surfaceData.tangent, surfaceData.bitangent, surfaceData.normal), material_ClearCoatNormalTexture, material_NormalIntensity, uv, isFrontFacing);\n #else\n surfaceData.clearCoatNormal = normal;\n #endif\n surfaceData.clearCoatDotNV = saturate( dot(surfaceData.clearCoatNormal, surfaceData.viewDir) );\n\n surfaceData.clearCoat = material_ClearCoat;\n surfaceData.clearCoatRoughness = material_ClearCoatRoughness;\n\n #ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\n surfaceData.clearCoat *= (texture2D( material_ClearCoatTexture, uv )).r;\n #endif\n\n #ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\n surfaceData.clearCoatRoughness *= (texture2D( material_ClearCoatRoughnessTexture, uv )).g;\n #endif\n\n surfaceData.clearCoat = saturate( surfaceData.clearCoat );\n surfaceData.clearCoatRoughness = max(MIN_PERCEPTUAL_ROUGHNESS, min(surfaceData.clearCoatRoughness + getAARoughnessFactor(surfaceData.clearCoatNormal), 1.0));\n #endif\n\n // Anisotropy\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, uv )).rgb;\n anisotropy *= anisotropyTextureInfo.b;\n anisotropicDirection.xy *= anisotropyTextureInfo.rg * 2.0 - 1.0;\n #endif\n\n surfaceData.anisotropy = anisotropy;\n surfaceData.anisotropicT = normalize(mat3(surfaceData.tangent, surfaceData.bitangent, surfaceData.normal) * anisotropicDirection);\n surfaceData.anisotropicB = normalize(cross(surfaceData.normal, surfaceData.anisotropicT));\n surfaceData.anisotropicN = getAnisotropicBentNormal(surfaceData);\n #endif\n\n // Iridescence\n #ifdef MATERIAL_ENABLE_IRIDESCENCE\n surfaceData.iridescenceFactor = material_IridescenceInfo.x;\n surfaceData.iridescenceIOR = material_IridescenceInfo.y;\n\n #ifdef MATERIAL_HAS_IRIDESCENCE_THICKNESS_TEXTURE\n float iridescenceThicknessWeight = texture2D( material_IridescenceThicknessTexture, uv).g;\n surfaceData.iridescenceThickness = mix(material_IridescenceInfo.z, material_IridescenceInfo.w, iridescenceThicknessWeight);\n #else\n surfaceData.iridescenceThickness = material_IridescenceInfo.w;\n #endif\n \n #ifdef MATERIAL_HAS_IRIDESCENCE_TEXTURE\n surfaceData.iridescenceFactor *= texture2D( material_IridescenceTexture, uv).r;\n #endif\n #endif\n\n #ifdef MATERIAL_ENABLE_SHEEN\n vec3 sheenColor = material_SheenColor;\n #ifdef MATERIAL_HAS_SHEEN_TEXTURE\n sheenColor *= texture2DSRGB(material_SheenTexture, uv).rgb;\n #endif\n surfaceData.sheenColor = sheenColor;\n\n surfaceData.sheenRoughness = material_SheenRoughness;\n #ifdef MATERIAL_HAS_SHEEN_ROUGHNESS_TEXTURE\n surfaceData.sheenRoughness *= texture2D(material_SheenRoughnessTexture, uv).a;\n #endif\n #endif\n\n #ifdef MATERIAL_ENABLE_TRANSMISSION \n surfaceData.transmission = material_Transmission;\n #ifdef MATERIAL_HAS_TRANSMISSION_TEXTURE\n surfaceData.transmission *= texture2D(material_TransmissionTexture, uv).r;\n #endif\n\n #ifdef MATERIAL_HAS_THICKNESS\n surfaceData.absorptionCoefficient = -log(material_AttenuationColor + HALF_EPS) / max(HALF_EPS, material_AttenuationDistance);\n surfaceData.thickness = max(material_Thickness, 0.0001);\n #ifdef MATERIAL_HAS_THICKNESS_TEXTURE\n surfaceData.thickness *= texture2D( material_ThicknessTexture, uv).g;\n #endif\n #endif \n #endif\n\n // Ambient Occlusion\n #ifdef MATERIAL_HAS_OCCLUSION_TEXTURE\n surfaceData.ambientOcclusion = ((texture2D(material_OcclusionTexture, aoUV)).r - 1.0) * material_OcclusionIntensity + 1.0;\n #else\n surfaceData.ambientOcclusion = 1.0;\n #endif\n\n return surfaceData;\n}\n\n\n\n#endif"; // eslint-disable-line
67
+
68
+ var LightDirectPBR = "\n#ifndef LIGHT_DIRECT_PBR_INCLUDED\n#define LIGHT_DIRECT_PBR_INCLUDED\n\n#ifndef FUNCTION_SURFACE_SHADING\n #define FUNCTION_SURFACE_SHADING surfaceShading\n#endif\n#ifndef FUNCTION_DIFFUSE_LOBE\n #define FUNCTION_DIFFUSE_LOBE diffuseLobe\n#endif\n#ifndef FUNCTION_SPECULAR_LOBE\n #define FUNCTION_SPECULAR_LOBE specularLobe\n#endif\n#ifndef FUNCTION_CLEAR_COAT_LOBE\n #define FUNCTION_CLEAR_COAT_LOBE clearCoatLobe\n#endif\n#ifndef FUNCTION_SHEEN_LOBE\n #define FUNCTION_SHEEN_LOBE sheenLobe\n#endif\n\n#include \"BSDF.glsl\"\n#include \"Light.glsl\"\n#include \"ReflectionLobe.glsl\"\n\nvoid surfaceShading(Varyings varyings, SurfaceData surfaceData, BSDFData bsdfData, vec3 incidentDirection, vec3 lightColor, inout vec3 totalDiffuseColor, inout vec3 totalSpecularColor) {\n\n vec3 diffuseColor = vec3(0);\n vec3 specularColor = vec3(0);\n float dotNL = saturate( dot( surfaceData.normal, incidentDirection ) );\n vec3 irradiance = dotNL * lightColor * PI;\n\n // ClearCoat Lobe\n float attenuation = FUNCTION_CLEAR_COAT_LOBE(varyings, surfaceData, bsdfData, incidentDirection, lightColor, specularColor);\n\n vec3 attenuationIrradiance = attenuation * irradiance;\n // Diffuse Lobe\n FUNCTION_DIFFUSE_LOBE(varyings, surfaceData, bsdfData, attenuationIrradiance, diffuseColor);\n // Specular Lobe\n FUNCTION_SPECULAR_LOBE(varyings, surfaceData, bsdfData, incidentDirection, attenuationIrradiance, specularColor);\n // Sheen Lobe\n FUNCTION_SHEEN_LOBE(varyings, surfaceData, bsdfData, incidentDirection, attenuationIrradiance, diffuseColor, specularColor);\n \n totalDiffuseColor += diffuseColor;\n totalSpecularColor += specularColor;\n\n}\n\n#ifdef SCENE_DIRECT_LIGHT_COUNT\n\n void addDirectionalDirectLightRadiance(Varyings varyings, SurfaceData surfaceData, BSDFData bsdfData, DirectLight directionalLight, inout vec3 totalDiffuseColor, inout vec3 totalSpecularColor) {\n vec3 lightColor = directionalLight.color;\n vec3 direction = -directionalLight.direction;\n\n FUNCTION_SURFACE_SHADING(varyings, surfaceData, bsdfData, direction, lightColor, totalDiffuseColor, totalSpecularColor);\n\n }\n\n#endif\n\n#ifdef SCENE_POINT_LIGHT_COUNT\n\n\tvoid addPointDirectLightRadiance(Varyings varyings, SurfaceData surfaceData, BSDFData bsdfData, PointLight pointLight, inout vec3 totalDiffuseColor, inout vec3 totalSpecularColor) {\n\t\tvec3 lVector = pointLight.position - surfaceData.position;\n\t\tvec3 direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\n\t\tvec3 lightColor = pointLight.color;\n\t\tlightColor *= clamp(1.0 - pow(lightDistance/pointLight.distance, 4.0), 0.0, 1.0);\n\n FUNCTION_SURFACE_SHADING(varyings, surfaceData, bsdfData, direction, lightColor, totalDiffuseColor, totalSpecularColor);\n\t}\n\n#endif\n\n#ifdef SCENE_SPOT_LIGHT_COUNT\n\n\tvoid addSpotDirectLightRadiance(Varyings varyings, SurfaceData surfaceData, BSDFData bsdfData, SpotLight spotLight, inout vec3 totalDiffuseColor, inout vec3 totalSpecularColor) {\n\n\t\tvec3 lVector = spotLight.position - surfaceData.position;\n\t\tvec3 direction = normalize( lVector );\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 lightColor = spotLight.color;\n\t\tlightColor *= spotEffect * decayEffect;\n\n FUNCTION_SURFACE_SHADING(varyings, surfaceData, bsdfData, direction, lightColor, totalDiffuseColor, totalSpecularColor);\n\n\t}\n\n\n#endif\n\nvoid evaluateDirectRadiance(Varyings varyings, SurfaceData surfaceData, BSDFData bsdfData, float shadowAttenuation, inout vec3 totalDiffuseColor, inout vec3 totalSpecularColor){\n #ifdef SCENE_DIRECT_LIGHT_COUNT\n\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 #ifdef GRAPHICS_API_WEBGL2\n DirectLight directionalLight = getDirectLight(i);\n #else\n DirectLight directionalLight;\n directionalLight.color = scene_DirectLightColor[i];\n directionalLight.direction = scene_DirectLightDirection[i];\n #endif\n \n #ifdef NEED_CALCULATE_SHADOWS\n if (i == 0) { // Sun light index is always 0\n directionalLight.color *= shadowAttenuation;\n }\n #endif\n addDirectionalDirectLightRadiance(varyings, surfaceData, bsdfData, directionalLight, totalDiffuseColor, totalSpecularColor );\n }\n }\n\n #endif\n\n #ifdef SCENE_POINT_LIGHT_COUNT\n\n for ( int i = 0; i < SCENE_POINT_LIGHT_COUNT; i ++ ) {\n if(!isRendererCulledByLight(renderer_Layer.xy, scene_PointLightCullingMask[i])){\n #ifdef GRAPHICS_API_WEBGL2\n PointLight pointLight = getPointLight(i);\n #else\n PointLight pointLight;\n pointLight.color = scene_PointLightColor[i];\n pointLight.position = scene_PointLightPosition[i];\n pointLight.distance = scene_PointLightDistance[i];\n #endif\n addPointDirectLightRadiance(varyings, surfaceData, bsdfData, pointLight, totalDiffuseColor, totalSpecularColor);\n } \n }\n\n #endif\n\n #ifdef SCENE_SPOT_LIGHT_COUNT\n \n for ( int i = 0; i < SCENE_SPOT_LIGHT_COUNT; i ++ ) {\n if(!isRendererCulledByLight(renderer_Layer.xy, scene_SpotLightCullingMask[i])){\n #ifdef GRAPHICS_API_WEBGL2\n SpotLight spotLight = getSpotLight(i);\n #else\n SpotLight spotLight;\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 #endif\n addSpotDirectLightRadiance( varyings, surfaceData, bsdfData, spotLight, totalDiffuseColor, totalSpecularColor);\n } \n }\n\n #endif\n}\n\n\n#endif"; // eslint-disable-line
69
+
70
+ var LightIndirectFunctions = "#ifndef LIGHT_INDIRECT_FUNCTIONS_INCLUDED\n#define LIGHT_INDIRECT_FUNCTIONS_INCLUDED\n\nvec3 getReflectedVector(SurfaceData surfaceData, vec3 n) {\n #ifdef MATERIAL_ENABLE_ANISOTROPY\n vec3 r = reflect(-surfaceData.viewDir, surfaceData.anisotropicN);\n #else\n vec3 r = reflect(-surfaceData.viewDir, n);\n #endif\n\n return r;\n}\n\nfloat getSpecularMIPLevel(float roughness, int maxMIPLevel ) {\n return roughness * float(maxMIPLevel);\n}\n\n// sh need be pre-scaled in CPU.\nvec3 getLightProbeRadiance(SurfaceData surfaceData, vec3 normal, float roughness) {\n\n #ifndef SCENE_USE_SPECULAR_ENV\n return vec3(0);\n #else\n vec3 reflectVec = getReflectedVector(surfaceData, normal);\n reflectVec.x = -reflectVec.x; // TextureCube is left-hand,so x need inverse\n \n float specularMIPLevel = getSpecularMIPLevel(roughness, int(scene_EnvMapLight.mipMapLevel) );\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 * scene_EnvMapLight.specularIntensity;\n\n #endif\n}\n\nfloat evaluateSpecularOcclusion(float dotNV, float diffuseAO, float roughness){\n float specularAOFactor = 1.0;\n #if defined(MATERIAL_HAS_OCCLUSION_TEXTURE) && defined(SCENE_USE_SPECULAR_ENV) \n specularAOFactor = saturate( pow(dotNV + diffuseAO, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + diffuseAO );\n #endif\n return specularAOFactor;\n} \n\n#endif"; // eslint-disable-line
71
+
72
+ var LightIndirectPBR = "\n#ifndef LIGHT_INDIRECT_PBR_INCLUDED\n#define LIGHT_INDIRECT_PBR_INCLUDED\n\n#ifndef FUNCTION_DIFFUSE_IBL\n #define FUNCTION_DIFFUSE_IBL evaluateDiffuseIBL\n#endif\n#ifndef FUNCTION_SPECULAR_IBL\n #define FUNCTION_SPECULAR_IBL evaluateSpecularIBL\n#endif\n#ifndef FUNCTION_CLEAR_COAT_IBL\n #define FUNCTION_CLEAR_COAT_IBL evaluateClearCoatIBL\n#endif\n#ifndef FUNCTION_SHEEN_IBL\n #define FUNCTION_SHEEN_IBL evaluateSheenIBL\n#endif\n\n#include \"LightIndirectFunctions.glsl\"\n\n// ------------------------Diffuse------------------------\n\n// sh need be pre-scaled in CPU.\nvec3 getLightProbeIrradiance(vec3 sh[9], vec3 normal){\n normal.x = -normal.x;\n vec3 result = sh[0] +\n\n sh[1] * (normal.y) +\n sh[2] * (normal.z) +\n sh[3] * (normal.x) +\n\n sh[4] * (normal.y * normal.x) +\n sh[5] * (normal.y * normal.z) +\n sh[6] * (3.0 * normal.z * normal.z - 1.0) +\n sh[7] * (normal.z * normal.x) +\n sh[8] * (normal.x * normal.x - normal.y * normal.y);\n \n return max(result, vec3(0.0));\n\n}\n\n\nvoid evaluateDiffuseIBL(Varyings varyings, SurfaceData surfaceData, BSDFData bsdfData, inout vec3 diffuseColor){\n #ifdef SCENE_USE_SH\n vec3 irradiance = getLightProbeIrradiance(scene_EnvSH, surfaceData.normal);\n irradiance *= scene_EnvMapLight.diffuseIntensity;\n #else\n vec3 irradiance = scene_EnvMapLight.diffuse * scene_EnvMapLight.diffuseIntensity;\n irradiance *= PI;\n #endif\n diffuseColor += bsdfData.diffuseAO * irradiance * BRDF_Diffuse_Lambert( bsdfData.diffuseColor );\n}\n\nfloat evaluateClearCoatIBL(Varyings varyings, SurfaceData surfaceData, BSDFData bsdfData, inout vec3 specularColor){\n float radianceAttenuation = 1.0;\n\n #ifdef MATERIAL_ENABLE_CLEAR_COAT\n vec3 clearCoatRadiance = getLightProbeRadiance(surfaceData, surfaceData.clearCoatNormal, bsdfData.clearCoatRoughness);\n float specularAO = evaluateSpecularOcclusion(surfaceData.dotNV, bsdfData.diffuseAO, bsdfData.clearCoatRoughness);\n specularColor += specularAO * clearCoatRadiance * surfaceData.clearCoat * envBRDFApprox(bsdfData.clearCoatSpecularColor, 1.0, bsdfData.clearCoatRoughness, surfaceData.clearCoatDotNV);\n radianceAttenuation -= surfaceData.clearCoat * F_Schlick( 0.04, 1.0, surfaceData.clearCoatDotNV);\n #endif\n\n return radianceAttenuation;\n}\n\nvoid evaluateSpecularIBL(Varyings varyings, SurfaceData surfaceData, BSDFData bsdfData, float radianceAttenuation, inout vec3 outSpecularColor){\n vec3 radiance = getLightProbeRadiance(surfaceData, surfaceData.normal, bsdfData.roughness);\n \n #ifdef MATERIAL_ENABLE_IRIDESCENCE\n vec3 speculaColor = mix(bsdfData.specularF0, bsdfData.iridescenceSpecularColor, surfaceData.iridescenceFactor);\n #else\n vec3 speculaColor = bsdfData.specularF0;\n #endif\n \n float specularAO = evaluateSpecularOcclusion(surfaceData.dotNV, bsdfData.diffuseAO, bsdfData.roughness);\n outSpecularColor += specularAO * radianceAttenuation * radiance * envBRDFApprox(speculaColor, bsdfData.specularF90 , bsdfData.roughness, surfaceData.dotNV);\n}\n\nvoid evaluateSheenIBL(Varyings varyings, SurfaceData surfaceData, BSDFData bsdfData, float radianceAttenuation, inout vec3 diffuseColor, inout vec3 specularColor){\n #ifdef MATERIAL_ENABLE_SHEEN\n diffuseColor *= bsdfData.sheenScaling;\n specularColor *= bsdfData.sheenScaling;\n float specularAO = evaluateSpecularOcclusion(surfaceData.dotNV, bsdfData.diffuseAO, bsdfData.sheenRoughness) ;\n vec3 reflectance = specularAO * radianceAttenuation * bsdfData.approxIBLSheenDG * surfaceData.sheenColor;\n specularColor += reflectance;\n #endif\n}\n\nvoid evaluateIBL(Varyings varyings, SurfaceData surfaceData, BSDFData bsdfData, inout vec3 totalDiffuseColor, inout vec3 totalSpecularColor){\n vec3 diffuseColor = vec3(0);\n vec3 specularColor = vec3(0);\n\n // IBL diffuse\n FUNCTION_DIFFUSE_IBL(varyings, surfaceData, bsdfData, diffuseColor);\n\n // IBL ClearCoat\n float radianceAttenuation = FUNCTION_CLEAR_COAT_IBL(varyings, surfaceData, bsdfData, specularColor);\n\n // IBL specular\n FUNCTION_SPECULAR_IBL(varyings, surfaceData, bsdfData, radianceAttenuation, specularColor);\n \n // IBL sheen\n FUNCTION_SHEEN_IBL(varyings, surfaceData, bsdfData, radianceAttenuation, diffuseColor, specularColor);\n\n totalDiffuseColor += diffuseColor;\n totalSpecularColor += specularColor;\n\n}\n\n#endif"; // eslint-disable-line
73
+
74
+ var ReflectionLobe = "#ifndef REFLECTION_LOBE_INCLUDED\n#define REFLECTION_LOBE_INCLUDED\n\nvoid diffuseLobe(Varyings varyings, SurfaceData surfaceData, BSDFData bsdfData, vec3 attenuationIrradiance, inout vec3 diffuseColor){\n diffuseColor += attenuationIrradiance * BRDF_Diffuse_Lambert( bsdfData.diffuseColor );\n}\n\nvoid specularLobe(Varyings varyings, SurfaceData surfaceData, BSDFData bsdfData, vec3 incidentDirection, vec3 attenuationIrradiance, inout vec3 specularColor){\n specularColor += attenuationIrradiance * BRDF_Specular_GGX( incidentDirection, surfaceData, bsdfData, surfaceData.normal, bsdfData.specularF0, bsdfData.roughness);\n}\n\nvoid sheenLobe(Varyings varyings, SurfaceData surfaceData, BSDFData bsdfData, vec3 incidentDirection, vec3 attenuationIrradiance, inout vec3 diffuseColor, inout vec3 specularColor){\n #ifdef MATERIAL_ENABLE_SHEEN\n diffuseColor *= bsdfData.sheenScaling;\n specularColor *= bsdfData.sheenScaling;\n\n specularColor += attenuationIrradiance * sheenBRDF(incidentDirection, surfaceData, surfaceData.sheenColor, bsdfData.sheenRoughness);\n #endif\n}\n\nfloat clearCoatLobe(Varyings varyings, SurfaceData surfaceData, BSDFData bsdfData, vec3 incidentDirection, vec3 color, inout vec3 specularColor){\n float attenuation = 1.0;\n\n #ifdef MATERIAL_ENABLE_CLEAR_COAT\n float clearCoatDotNL = saturate( dot( surfaceData.clearCoatNormal, incidentDirection ) );\n vec3 clearCoatIrradiance = clearCoatDotNL * color;\n\n specularColor += surfaceData.clearCoat * clearCoatIrradiance * BRDF_Specular_GGX( incidentDirection, surfaceData, bsdfData, surfaceData.clearCoatNormal, bsdfData.clearCoatSpecularColor, bsdfData.clearCoatRoughness );\n attenuation -= surfaceData.clearCoat * F_Schlick(0.04, 1.0, surfaceData.clearCoatDotNV);\n #endif\n\n return attenuation;\n}\n\n#endif"; // eslint-disable-line
75
+
76
+ var VaryingsPBR = "#ifndef VARYINGS_PBR_INCLUDED\n#define VARYINGS_PBR_INCLUDED\n\nstruct Varyings{\n\tvec2 uv;\n\t#ifdef RENDERER_HAS_UV1\n\t vec2 uv1;\n\t#endif\n\n\t#ifdef RENDERER_ENABLE_VERTEXCOLOR\n \t\tvec4 vertexColor;\n\t#endif\n\n\tvec3 positionWS;\n\n\t#if SCENE_FOG_MODE != 0\n\t vec3 positionVS;\n\t#endif\n\n\t#ifdef RENDERER_HAS_NORMAL\n\t vec3 normalWS;\n\t #ifdef RENDERER_HAS_TANGENT\n\t\t\tvec3 tangentWS;\n\t\t\tvec3 bitangentWS;\n\t #endif\n\t#endif\n\n\n\t#if defined(NEED_CALCULATE_SHADOWS) && (SCENE_SHADOW_CASCADED_COUNT == 1)\n\t vec3 shadowCoord;\n\t#endif\n};\n\n\n#endif"; // eslint-disable-line
77
+
78
+ var VertexPBR = "#ifndef VERTEX_INCLUDE\n#define VERTEX_INCLUDE\n\nstruct VertexInputs{\n vec4 positionOS;\n vec3 positionWS;\n\n #if SCENE_FOG_MODE != 0\n vec3 positionVS;\n #endif\n\n #ifdef RENDERER_HAS_NORMAL\n vec3 normalWS;\n #ifdef RENDERER_HAS_TANGENT\n vec3 tangentWS;\n vec3 bitangentWS;\n #endif\n #endif\n};\n\nvec4 material_TilingOffset;\nvec2 getUV0(Attributes attributes){\n vec2 uv0 = vec2(0);\n\n #ifdef RENDERER_HAS_UV\n uv0 = attributes.TEXCOORD_0;\n #endif\n\n return uv0 * material_TilingOffset.xy + material_TilingOffset.zw;\n}\n\nVertexInputs getVertexInputs(Attributes attributes){\n VertexInputs inputs;\n vec4 position = vec4(attributes.POSITION, 1.0);\n\n #ifdef RENDERER_HAS_NORMAL\n vec3 normal = vec3( attributes.NORMAL );\n #ifdef RENDERER_HAS_TANGENT\n vec4 tangent = vec4( attributes.TANGENT );\n #endif\n #endif\n\n \n // BlendShape\n #ifdef RENDERER_HAS_BLENDSHAPE\n calculateBlendShape(attributes, position\n #ifdef RENDERER_HAS_NORMAL\n ,normal\n #ifdef RENDERER_HAS_TANGENT\n ,tangent\n #endif\n #endif\n );\n #endif\n\n // Skin\n #ifdef RENDERER_HAS_SKIN\n mat4 skinMatrix = getSkinMatrix(attributes);\n position = skinMatrix * position;\n\n #if defined(RENDERER_HAS_NORMAL)\n mat3 skinNormalMatrix = INVERSE_MAT(mat3(skinMatrix));\n normal = normal * skinNormalMatrix;\n #ifdef RENDERER_HAS_TANGENT\n tangent.xyz = tangent.xyz * skinNormalMatrix;\n #endif\n #endif\n #endif\n\n // TBN world space\n #ifdef RENDERER_HAS_NORMAL\n inputs.normalWS = normalize( mat3(renderer_NormalMat) * normal );\n\n #ifdef RENDERER_HAS_TANGENT\n vec3 tangentWS = normalize( mat3(renderer_NormalMat) * tangent.xyz );\n vec3 bitangentWS = cross( inputs.normalWS, tangentWS ) * tangent.w;\n\n inputs.tangentWS = tangentWS;\n inputs.bitangentWS = bitangentWS;\n #endif\n #endif\n\n\n inputs.positionOS = position;\n vec4 positionWS = renderer_ModelMat * position;\n inputs.positionWS = positionWS.xyz / positionWS.w;\n\n #if SCENE_FOG_MODE != 0\n vec4 positionVS = renderer_MVMat * position;\n inputs.positionVS = positionVS.xyz / positionVS.w;\n #endif\n\n return inputs;\n}\n\n#endif"; // eslint-disable-line
79
+
80
+ var Refraction = "#ifndef REFRACTION_INCLUDED\n#define REFRACTION_INCLUDED\n\n#ifdef MATERIAL_ENABLE_TRANSMISSION \n\nstruct RefractionModelResult{\n float transmissionLength; // length of the transmission during refraction through the shape\n vec3 positionExit; // out ray position\n // vec3 directionExit; // out ray direction\n};\n\n//https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@15.0/manual/refraction-models.html\n void refractionModelSphere(vec3 V, vec3 positionWS, vec3 normalWS, float ior, float thickness, out RefractionModelResult ray){\n // Refracted ray\n vec3 R1 = refract(V, normalWS, 1.0 / ior);\n // Center of the tangent sphere\n // vec3 C = positionWS - normalWS * thickness * 0.5;\n\n // Second refraction (tangent sphere out)\n float dist = dot(-normalWS, R1) * thickness;\n // Out hit point in the tangent sphere\n vec3 P1 = positionWS + R1 * dist;\n // Out normal\n // vec3 N1 = safeNormalize(C - P1);\n // Out refracted ray\n // vec3 R2 = refract(R1, N1, ior);\n\n ray.transmissionLength = dist;\n ray.positionExit = P1;\n // ray.directionExit = R2; \n}\n\nvoid refractionModelPlanar(vec3 V, vec3 positionWS, vec3 normalWS, float ior, float thickness, out RefractionModelResult ray){\n // Refracted ray\n vec3 R = refract(V, normalWS, 1.0 / ior);\n // Optical depth within the thin plane\n float dist = thickness / max(dot(-normalWS, R), 1e-5f);\n\n ray.transmissionLength = dist;\n ray.positionExit = vec3(positionWS + R * dist);\n // ray.directionExit = V;\n}\n#endif\n\n#endif"; // eslint-disable-line
81
+
82
+ var BSDF = "#ifndef BSDF_INCLUDED\n#define BSDF_INCLUDED\n\n#include \"Refraction.glsl\"\n\n#define MIN_PERCEPTUAL_ROUGHNESS 0.045\n#define MIN_ROUGHNESS 0.002025\n\n#if defined(RENDERER_HAS_TANGENT) || defined(MATERIAL_ENABLE_ANISOTROPY) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_HAS_NORMALTEXTURE)\n #define NEED_TANGENT\n#endif\n\n#ifdef MATERIAL_ENABLE_SHEEN\n sampler2D scene_PrefilteredDFG;\n#endif\n\nstruct SurfaceData{\n // common\n\tvec3 albedoColor;\n\tvec3 emissiveColor;\n float metallic;\n float roughness;\n float ambientOcclusion;\n float opacity;\n float IOR;\n\n // geometry\n vec3 position;\n vec3 normal;\n\n #ifdef NEED_TANGENT\n vec3 tangent;\n vec3 bitangent;\n #endif\n\n vec3 viewDir;\n float dotNV;\n\n // Specular\n float specularIntensity;\n vec3 specularColor;\n\n // Anisotropy\n #ifdef MATERIAL_ENABLE_ANISOTROPY\n float anisotropy;\n vec3 anisotropicT;\n vec3 anisotropicB;\n vec3 anisotropicN;\n #endif\n\n // Clear coat\n #ifdef MATERIAL_ENABLE_CLEAR_COAT\n float clearCoat;\n float clearCoatRoughness;\n vec3 clearCoatNormal;\n float clearCoatDotNV;\n #endif\n\n // Iridescence\n #ifdef MATERIAL_ENABLE_IRIDESCENCE\n float iridescenceIOR;\n float iridescenceFactor;\n float iridescenceThickness;\n #endif\n\n // Sheen\n #ifdef MATERIAL_ENABLE_SHEEN\n float sheenRoughness;\n vec3 sheenColor;\n #endif\n\n // Transmission\n #ifdef MATERIAL_ENABLE_TRANSMISSION \n vec3 absorptionCoefficient;\n float transmission;\n float thickness;\n #endif\n};\n\n\nstruct BSDFData{\n vec3 diffuseColor;\n float roughness;\n vec3 envSpecularDFG;\n float diffuseAO;\n vec3 specularF0;\n float specularF90;\n\n #ifdef MATERIAL_ENABLE_CLEAR_COAT\n vec3 clearCoatSpecularColor;\n float clearCoatRoughness;\n #endif\n\n #ifdef MATERIAL_ENABLE_IRIDESCENCE\n vec3 iridescenceSpecularColor;\n #endif\n\n #ifdef MATERIAL_ENABLE_SHEEN\n float sheenRoughness;\n float sheenScaling;\n float approxIBLSheenDG;\n #endif\n \n};\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\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_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 highp vec3 d = vec3(ab * ToH, at * BoH, a2 * NoH);\n highp 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, SurfaceData surfaceData, float alpha, float dotNV, float dotNL, float dotNH) {\n vec3 t = surfaceData.anisotropicT;\n vec3 b = surfaceData.anisotropicB;\n vec3 v = surfaceData.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 + surfaceData.anisotropy), MIN_ROUGHNESS);\n float ab = max(alpha * (1.0 - surfaceData.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// GGX Distribution, Schlick Fresnel, GGX-Smith Visibility\nvec3 BRDF_Specular_GGX(vec3 incidentDirection, SurfaceData surfaceData, BSDFData bsdfData, vec3 normal, vec3 specularColor, float roughness ) {\n\n\tfloat alpha = pow2( roughness ); // UE4's roughness\n\n\tvec3 halfDir = normalize( incidentDirection + surfaceData.viewDir );\n\n\tfloat dotNL = saturate( dot( normal, incidentDirection ) );\n float dotNV = saturate( dot( normal, surfaceData.viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentDirection, halfDir ) );\n\n vec3 F = F_Schlick(specularColor, bsdfData.specularF90 , dotLH );\n #ifdef MATERIAL_ENABLE_IRIDESCENCE\n F = mix(F, bsdfData.iridescenceSpecularColor, surfaceData.iridescenceFactor);\n #endif\n\t\n\n #ifdef MATERIAL_ENABLE_ANISOTROPY\n float GD = DG_GGX_anisotropic(halfDir, incidentDirection, surfaceData, alpha, dotNV, dotNL, dotNH);\n #else\n float GD = DG_GGX(alpha, dotNV, dotNL, dotNH);\n #endif\n return F * GD;\n}\n\nvec3 BRDF_Diffuse_Lambert(vec3 diffuseColor) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\n\n#ifdef MATERIAL_ENABLE_IRIDESCENCE\n\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#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, SurfaceData surfaceData, vec3 sheenColor, float sheenRoughness) {\n vec3 halfDir = normalize(incidentDirection + surfaceData.viewDir);\n float dotNL = saturate(dot(surfaceData.normal, incidentDirection));\n float dotNH = saturate(dot(surfaceData.normal, halfDir));\n float D = D_Charlie(sheenRoughness, dotNH);\n float V = V_Neubelt(surfaceData.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// ------------------------Indirect Specular------------------------\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\n const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\n const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\n vec4 r = roughness * c0 + c1;\n\n float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n\n return f0 * AB.x + f90 * AB.y;\n\n}\n\n#ifdef MATERIAL_ENABLE_TRANSMISSION \n sampler2D camera_OpaqueTexture;\n vec3 evaluateTransmission(SurfaceData surfaceData, BSDFData bsdfData) {\n RefractionModelResult ray;\n #if REFRACTION_MODE == 0 \n // RefractionMode.Sphere\n refractionModelSphere(-surfaceData.viewDir, surfaceData.position, surfaceData.normal, surfaceData.IOR, surfaceData.thickness, ray);\n #elif REFRACTION_MODE == 1\n // RefractionMode.Planar\n refractionModelPlanar(-surfaceData.viewDir, surfaceData.position, surfaceData.normal, surfaceData.IOR, surfaceData.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 \n refractionTransmitted *= bsdfData.diffuseColor;\n \n // Since we did not calculate the true Fresnel result in the diffuse reflection, \n // it will cause the lower edge of the transmission to be too bright,\n // Therefore, we use an approximate Fresnel attenuation.\n // https://blog.selfshadow.com/publications/s2017-shading-course/imageworks/s2017_pbs_imageworks_slides_v2.pdf\n refractionTransmitted *= (1.0 - max(max(bsdfData.envSpecularDFG.r,bsdfData.envSpecularDFG.g),bsdfData.envSpecularDFG.b));\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(-surfaceData.absorptionCoefficient * ray.transmissionLength));\n refractionTransmitted *= transmittance;\n #endif\n \n return refractionTransmitted;\n }\n#endif\n\nvoid initBSDFData(SurfaceData surfaceData, out BSDFData bsdfData){\n vec3 albedoColor = surfaceData.albedoColor;\n float metallic = surfaceData.metallic;\n float roughness = surfaceData.roughness;\n\n vec3 dielectricBaseF0 = vec3(pow2( (surfaceData.IOR - 1.0) / (surfaceData.IOR + 1.0) ));\n vec3 dielectricF0 = min(dielectricBaseF0 * surfaceData.specularColor , vec3(1.0)) * surfaceData.specularIntensity;\n float dielectricF90 = surfaceData.specularIntensity; \n\n bsdfData.specularF0 = mix(dielectricF0, albedoColor, metallic);\n bsdfData.specularF90 = mix(dielectricF90, 1.0, metallic);\n\n // Simplify: albedoColor * mix((1.0 - max(max(dielectricF0.r,dielectricF0.g),dielectricF0.b)), 0.0, metallic);\n bsdfData.diffuseColor = albedoColor * (1.0-metallic) * (1.0 - max(max(dielectricF0.r,dielectricF0.g),dielectricF0.b));\n \n bsdfData.roughness = max(MIN_PERCEPTUAL_ROUGHNESS, min(roughness + getAARoughnessFactor(surfaceData.normal), 1.0));\n bsdfData.envSpecularDFG = envBRDFApprox(bsdfData.specularF0, bsdfData.specularF90 , bsdfData.roughness, surfaceData.dotNV);\n \n bsdfData.diffuseAO = surfaceData.ambientOcclusion;\n\n #ifdef MATERIAL_ENABLE_CLEAR_COAT\n bsdfData.clearCoatRoughness = max(MIN_PERCEPTUAL_ROUGHNESS, min(surfaceData.clearCoatRoughness + getAARoughnessFactor(surfaceData.clearCoatNormal), 1.0));\n bsdfData.clearCoatSpecularColor = vec3(0.04);\n #endif\n\n #ifdef MATERIAL_ENABLE_IRIDESCENCE\n float topIOR = 1.0;\n bsdfData.iridescenceSpecularColor = evalIridescenceSpecular(topIOR, surfaceData.dotNV, surfaceData.iridescenceIOR, bsdfData.specularF0, bsdfData.specularF90 , surfaceData.iridescenceThickness); \n #endif\n\n #ifdef MATERIAL_ENABLE_SHEEN\n bsdfData.sheenRoughness = max(MIN_PERCEPTUAL_ROUGHNESS, min(surfaceData.sheenRoughness + getAARoughnessFactor(surfaceData.normal), 1.0));\n bsdfData.approxIBLSheenDG = prefilteredSheenDFG(surfaceData.dotNV, bsdfData.sheenRoughness);\n bsdfData.sheenScaling = 1.0 - bsdfData.approxIBLSheenDG * max(max(surfaceData.sheenColor.r, surfaceData.sheenColor.g), surfaceData.sheenColor.b);\n #endif\n}\n\n#endif"; // eslint-disable-line
83
+
84
+ var shadingPBR = [
85
+ {
86
+ source: ForwardPassPBR,
87
+ includeKey: "ForwardPassPBR.glsl"
88
+ },
89
+ {
90
+ source: AttributesPBR,
91
+ includeKey: "AttributesPBR.glsl"
92
+ },
93
+ {
94
+ source: VaryingsPBR,
95
+ includeKey: "VaryingsPBR.glsl"
96
+ },
97
+ {
98
+ source: FragmentPBR,
99
+ includeKey: "FragmentPBR.glsl"
100
+ },
101
+ {
102
+ source: LightDirectPBR,
103
+ includeKey: "LightDirectPBR.glsl"
104
+ },
105
+ {
106
+ source: LightIndirectPBR,
107
+ includeKey: "LightIndirectPBR.glsl"
108
+ },
109
+ {
110
+ source: VertexPBR,
111
+ includeKey: "VertexPBR.glsl"
112
+ },
113
+ {
114
+ source: LightIndirectFunctions,
115
+ includeKey: "LightIndirectFunctions.glsl"
116
+ },
117
+ {
118
+ source: ReflectionLobe,
119
+ includeKey: "ReflectionLobe.glsl"
120
+ },
121
+ {
122
+ source: Refraction,
123
+ includeKey: "Refraction.glsl"
124
+ },
125
+ {
126
+ source: BSDF,
127
+ includeKey: "BSDF.glsl"
128
+ }
129
+ ];
130
+
131
+ var fragmentList = [].concat([
132
+ {
133
+ source: BlendShape,
134
+ includeKey: "BlendShape.glsl"
135
+ },
136
+ {
137
+ source: Common,
138
+ includeKey: "Common.glsl"
139
+ },
140
+ {
141
+ source: Fog,
142
+ includeKey: "Fog.glsl"
143
+ },
144
+ {
145
+ source: Light,
146
+ includeKey: "Light.glsl"
147
+ },
148
+ {
149
+ source: Normal,
150
+ includeKey: "Normal.glsl"
151
+ },
152
+ {
153
+ source: ShadowSampleTent,
154
+ includeKey: "ShadowSampleTent.glsl"
155
+ },
156
+ {
157
+ source: Shadow,
158
+ includeKey: "Shadow.glsl"
159
+ },
160
+ {
161
+ source: Transform,
162
+ includeKey: "Transform.glsl"
163
+ },
164
+ {
165
+ source: Skin,
166
+ includeKey: "Skin.glsl"
167
+ }
168
+ ], shadingPBR);
169
+
170
+ var includeRegistered = false;
171
+ function registerIncludes() {
172
+ if (includeRegistered) return;
173
+ for(var _iterator = _create_for_of_iterator_helper_loose(fragmentList), _step; !(_step = _iterator()).done;){
174
+ var sourceFragment = _step.value;
175
+ ShaderFactory.registerInclude(sourceFragment.includeKey, sourceFragment.source);
176
+ }
177
+ includeRegistered = true;
178
+ }
179
+
180
+ export { PBR as PBRSource, fragmentList, registerIncludes };
181
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sources":["../../../node_modules/.pnpm/@swc+helpers@0.5.15/node_modules/@swc/helpers/esm/_array_like_to_array.js","../../../node_modules/.pnpm/@swc+helpers@0.5.15/node_modules/@swc/helpers/esm/_unsupported_iterable_to_array.js","../../../node_modules/.pnpm/@swc+helpers@0.5.15/node_modules/@swc/helpers/esm/_create_for_of_iterator_helper_loose.js","../src/shaders/shadingPBR/index.ts","../src/shaders/index.ts","../src/index.ts"],"sourcesContent":["function _array_like_to_array(arr, len) {\n if (len == null || len > arr.length) len = arr.length;\n\n for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];\n\n return arr2;\n}\nexport { _array_like_to_array as _ };\n","import { _ as _array_like_to_array } from \"./_array_like_to_array.js\";\n\nfunction _unsupported_iterable_to_array(o, minLen) {\n if (!o) return;\n if (typeof o === \"string\") return _array_like_to_array(o, minLen);\n\n var n = Object.prototype.toString.call(o).slice(8, -1);\n\n if (n === \"Object\" && o.constructor) n = o.constructor.name;\n if (n === \"Map\" || n === \"Set\") return Array.from(n);\n if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);\n}\nexport { _unsupported_iterable_to_array as _ };\n","import { _ as _unsupported_iterable_to_array } from \"./_unsupported_iterable_to_array.js\";\n\nfunction _create_for_of_iterator_helper_loose(o, allowArrayLike) {\n var it = typeof Symbol !== \"undefined\" && o[Symbol.iterator] || o[\"@@iterator\"];\n\n if (it) return (it = it.call(o)).next.bind(it);\n // Fallback for engines without symbol support\n if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === \"number\") {\n if (it) o = it;\n\n var i = 0;\n\n return function() {\n if (i >= o.length) return { done: true };\n\n return { done: false, value: o[i++] };\n };\n }\n\n throw new TypeError(\"Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\");\n}\nexport { _create_for_of_iterator_helper_loose as _ };\n","import AttributesPBR from \"./AttributesPBR.glsl\";\nimport ForwardPassPBR from \"./ForwardPassPBR.glsl\";\nimport FragmentPBR from \"./FragmentPBR.glsl\";\nimport LightDirectPBR from \"./LightDirectPBR.glsl\";\nimport LightIndirectFunctions from \"./LightIndirectFunctions.glsl\";\nimport LightIndirectPBR from \"./LightIndirectPBR.glsl\";\nimport ReflectionLobe from \"./ReflectionLobe.glsl\";\nimport VaryingsPBR from \"./VaryingsPBR.glsl\";\nimport VertexPBR from \"./VertexPBR.glsl\";\nimport Refraction from \"./Refraction.glsl\";\nimport BSDF from \"./BSDF.glsl\";\n\nexport default [\n { source: ForwardPassPBR, includeKey: \"ForwardPassPBR.glsl\" },\n { source: AttributesPBR, includeKey: \"AttributesPBR.glsl\" },\n { source: VaryingsPBR, includeKey: \"VaryingsPBR.glsl\" },\n { source: FragmentPBR, includeKey: \"FragmentPBR.glsl\" },\n { source: LightDirectPBR, includeKey: \"LightDirectPBR.glsl\" },\n { source: LightIndirectPBR, includeKey: \"LightIndirectPBR.glsl\" },\n { source: VertexPBR, includeKey: \"VertexPBR.glsl\" },\n { source: LightIndirectFunctions, includeKey: \"LightIndirectFunctions.glsl\" },\n { source: ReflectionLobe, includeKey: \"ReflectionLobe.glsl\" },\n { source: Refraction, includeKey: \"Refraction.glsl\" },\n { source: BSDF, includeKey: \"BSDF.glsl\" }\n];\n","import BlendShape from \"./BlendShape.glsl\";\nimport Common from \"./Common.glsl\";\nimport Fog from \"./Fog.glsl\";\nimport Light from \"./Light.glsl\";\nimport Normal from \"./Normal.glsl\";\nimport PBRSource from \"./PBR.gs\";\nimport Shadow from \"./Shadow.glsl\";\nimport ShadowSampleTent from \"./ShadowSampleTent.glsl\";\nimport Skin from \"./Skin.glsl\";\nimport Transform from \"./Transform.glsl\";\nimport shadingPBR from \"./shadingPBR\";\n\ninterface IShaderFragment {\n includeKey: string;\n source: string;\n}\n\nconst fragmentList: IShaderFragment[] = [\n { source: BlendShape, includeKey: \"BlendShape.glsl\" },\n { source: Common, includeKey: \"Common.glsl\" },\n { source: Fog, includeKey: \"Fog.glsl\" },\n { source: Light, includeKey: \"Light.glsl\" },\n { source: Normal, includeKey: \"Normal.glsl\" },\n { source: ShadowSampleTent, includeKey: \"ShadowSampleTent.glsl\" },\n { source: Shadow, includeKey: \"Shadow.glsl\" },\n { source: Transform, includeKey: \"Transform.glsl\" },\n { source: Skin, includeKey: \"Skin.glsl\" },\n\n ...shadingPBR\n];\nexport { PBRSource, fragmentList };\n","import { ShaderFactory } from \"@galacean/engine\";\nimport { PBRSource, fragmentList } from \"./shaders\";\n\nlet includeRegistered = false;\n\nexport function registerIncludes() {\n if (includeRegistered) return;\n\n for (const sourceFragment of fragmentList) {\n ShaderFactory.registerInclude(sourceFragment.includeKey, sourceFragment.source);\n }\n\n includeRegistered = true;\n}\n\nexport { PBRSource, fragmentList };\n"],"names":["source","ForwardPassPBR","includeKey","AttributesPBR","VaryingsPBR","FragmentPBR","LightDirectPBR","LightIndirectPBR","VertexPBR","LightIndirectFunctions","ReflectionLobe","Refraction","BSDF","fragmentList","BlendShape","Common","Fog","Light","Normal","ShadowSampleTent","Shadow","Transform","Skin","shadingPBR","includeRegistered","registerIncludes","sourceFragment","ShaderFactory","registerInclude"],"mappings":";;AAAA,SAAS,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE;AACxC,IAAI,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC;AAC1D;AACA,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;AAC1E;AACA,IAAI,OAAO,IAAI,CAAC;AAChB;;ACJA,SAAS,8BAA8B,CAAC,CAAC,EAAE,MAAM,EAAE;AACnD,IAAI,IAAI,CAAC,CAAC,EAAE,OAAO;AACnB,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,OAAO,oBAAoB,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACtE;AACA,IAAI,IAAI,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC3D;AACA,IAAI,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC;AAChE,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,KAAK,EAAE,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACzD,IAAI,IAAI,CAAC,KAAK,WAAW,IAAI,0CAA0C,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,oBAAoB,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACxH;;ACTA,SAAS,oCAAoC,CAAC,CAAC,EAAE,cAAc,EAAE;AACjE,IAAI,IAAI,EAAE,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC;AACpF;AACA,IAAI,IAAI,EAAE,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACnD;AACA,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,8BAA8B,CAAC,CAAC,CAAC,CAAC,IAAI,cAAc,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ,EAAE;AAC7H,QAAQ,IAAI,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC;AACvB;AACA,QAAQ,IAAI,CAAC,GAAG,CAAC,CAAC;AAClB;AACA,QAAQ,OAAO,WAAW;AAC1B,YAAY,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACrD;AACA,YAAY,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AAClD,SAAS,CAAC;AACV,KAAK;AACL;AACA,IAAI,MAAM,IAAI,SAAS,CAAC,uIAAuI,CAAC,CAAC;AACjK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACRA,iBAAe;AACb,IAAA;QAAEA,MAAQC,EAAAA,cAAAA;QAAgBC,UAAY,EAAA,qBAAA;AAAsB,KAAA;AAC5D,IAAA;QAAEF,MAAQG,EAAAA,aAAAA;QAAeD,UAAY,EAAA,oBAAA;AAAqB,KAAA;AAC1D,IAAA;QAAEF,MAAQI,EAAAA,WAAAA;QAAaF,UAAY,EAAA,kBAAA;AAAmB,KAAA;AACtD,IAAA;QAAEF,MAAQK,EAAAA,WAAAA;QAAaH,UAAY,EAAA,kBAAA;AAAmB,KAAA;AACtD,IAAA;QAAEF,MAAQM,EAAAA,cAAAA;QAAgBJ,UAAY,EAAA,qBAAA;AAAsB,KAAA;AAC5D,IAAA;QAAEF,MAAQO,EAAAA,gBAAAA;QAAkBL,UAAY,EAAA,uBAAA;AAAwB,KAAA;AAChE,IAAA;QAAEF,MAAQQ,EAAAA,SAAAA;QAAWN,UAAY,EAAA,gBAAA;AAAiB,KAAA;AAClD,IAAA;QAAEF,MAAQS,EAAAA,sBAAAA;QAAwBP,UAAY,EAAA,6BAAA;AAA8B,KAAA;AAC5E,IAAA;QAAEF,MAAQU,EAAAA,cAAAA;QAAgBR,UAAY,EAAA,qBAAA;AAAsB,KAAA;AAC5D,IAAA;QAAEF,MAAQW,EAAAA,UAAAA;QAAYT,UAAY,EAAA,iBAAA;AAAkB,KAAA;AACpD,IAAA;QAAEF,MAAQY,EAAAA,IAAAA;QAAMV,UAAY,EAAA,WAAA;AAAY,KAAA;CACzC;;ACPKW,IAAAA,YAAAA,GAAAA,EAAAA,CAAAA,MAAAA,CAAAA;AACJ,IAAA;QAAEb,MAAQc,EAAAA,UAAAA;QAAYZ,UAAY,EAAA,iBAAA;AAAkB,KAAA;AACpD,IAAA;QAAEF,MAAQe,EAAAA,MAAAA;QAAQb,UAAY,EAAA,aAAA;AAAc,KAAA;AAC5C,IAAA;QAAEF,MAAQgB,EAAAA,GAAAA;QAAKd,UAAY,EAAA,UAAA;AAAW,KAAA;AACtC,IAAA;QAAEF,MAAQiB,EAAAA,KAAAA;QAAOf,UAAY,EAAA,YAAA;AAAa,KAAA;AAC1C,IAAA;QAAEF,MAAQkB,EAAAA,MAAAA;QAAQhB,UAAY,EAAA,aAAA;AAAc,KAAA;AAC5C,IAAA;QAAEF,MAAQmB,EAAAA,gBAAAA;QAAkBjB,UAAY,EAAA,uBAAA;AAAwB,KAAA;AAChE,IAAA;QAAEF,MAAQoB,EAAAA,MAAAA;QAAQlB,UAAY,EAAA,aAAA;AAAc,KAAA;AAC5C,IAAA;QAAEF,MAAQqB,EAAAA,SAAAA;QAAWnB,UAAY,EAAA,gBAAA;AAAiB,KAAA;AAClD,IAAA;QAAEF,MAAQsB,EAAAA,IAAAA;QAAMpB,UAAY,EAAA,WAAA;AAAY,KAAA;AAErCqB,CAAAA,EAAAA,UAAAA;;ACzBL,IAAIC,iBAAoB,GAAA,KAAA,CAAA;AAEjB,SAASC,gBAAAA,GAAAA;AACd,IAAA,IAAID,iBAAmB,EAAA,OAAA;AAEvB,IAAA,IAAA,IAAA,SAAA,GAAA,oCAAA,CAA6BX,YAAc,CAAA,EAAA,KAAA,EAAA,CAAA,CAAA,KAAA,GAAA,SAAA,EAAA,EAAA,IAAA,EAAA;AAAhCa,QAAAA,IAAAA,cAAAA,GAAAA,KAAAA,CAAAA,KAAAA,CAAAA;AACTC,QAAAA,aAAAA,CAAcC,eAAe,CAACF,cAAAA,CAAexB,UAAU,EAAEwB,eAAe1B,MAAM,CAAA,CAAA;AAChF,KAAA;IAEAwB,iBAAoB,GAAA,IAAA,CAAA;AACtB;;;;"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@galacean/engine-shader",
3
+ "version": "1.6.0-beta.0",
4
+ "publishConfig": {
5
+ "access": "public",
6
+ "registry": "https://registry.npmjs.org"
7
+ },
8
+ "repository": {
9
+ "url": "https://github.com/galacean/engine.git"
10
+ },
11
+ "license": "MIT",
12
+ "main": "dist/main.js",
13
+ "module": "dist/module.js",
14
+ "debug": "src/index.ts",
15
+ "browser": "dist/browser.js",
16
+ "types": "types/index.d.ts",
17
+ "umd": {
18
+ "name": "Galacean.Shader",
19
+ "globals": {
20
+ "@galacean/engine": "Galacean"
21
+ }
22
+ },
23
+ "files": [
24
+ "dist/**/*",
25
+ "types/**/*"
26
+ ],
27
+ "devDependencies": {
28
+ "@galacean/engine": "1.6.0-beta.0"
29
+ },
30
+ "peerDependencies": {
31
+ "@galacean/engine": "1.6.0-beta.0"
32
+ },
33
+ "scripts": {
34
+ "b:types": "tsc"
35
+ }
36
+ }
@@ -0,0 +1,3 @@
1
+ import { PBRSource, fragmentList } from "./shaders";
2
+ export declare function registerIncludes(): void;
3
+ export { PBRSource, fragmentList };
@@ -0,0 +1,7 @@
1
+ import PBRSource from "./PBR.gs";
2
+ interface IShaderFragment {
3
+ includeKey: string;
4
+ source: string;
5
+ }
6
+ declare const fragmentList: IShaderFragment[];
7
+ export { PBRSource, fragmentList };
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ source: string;
3
+ includeKey: string;
4
+ }[];
5
+ export default _default;