From aaf551fa05edef68bfd3545724c5c804d40c4ce3 Mon Sep 17 00:00:00 2001 From: pissang Date: Fri, 9 Jun 2017 15:48:27 +0800 Subject: [PATCH] Dump 0.3.7 --- dist/qtek.js | 231 +++++++++++++++++++++++------------------------ dist/qtek.min.js | 24 ++--- package.json | 2 +- src/version.js | 2 +- 4 files changed, 127 insertions(+), 132 deletions(-) diff --git a/dist/qtek.js b/dist/qtek.js index 09cc101a3..cefccc251 100644 --- a/dist/qtek.js +++ b/dist/qtek.js @@ -9183,6 +9183,7 @@ return /******/ (function(modules) { // webpackBootstrap * Set camera view matrix */ setViewMatrix: function (viewMatrix) { + Matrix4.copy(this.viewMatrix, viewMatrix); Matrix4.invert(this.worldTransform, viewMatrix); this.decomposeWorldTransform(); }, @@ -12005,11 +12006,15 @@ return /******/ (function(modules) { // webpackBootstrap var sx = vec3.length(x); var sy = vec3.length(y); var sz = vec3.length(z); + + // if determine is negative, we need to invert one scale + var det = this.determinant(); + if (det < 0) { + sx = -sx; + } + if (scale) { - scale.x = sx; - scale.y = sy; - scale.z = sz; - scale._dirty = true; + scale.set(sx, sy, sz); } position.set(el[12], el[13], el[14]); @@ -13071,7 +13076,7 @@ return /******/ (function(modules) { // webpackBootstrap * @param {qtek.math.Vector3} [origin] * @param {qtek.math.Vector3} [direction] */ - var Ray = function(origin, direction) { + var Ray = function (origin, direction) { /** * @type {qtek.math.Vector3} */ @@ -13093,7 +13098,7 @@ return /******/ (function(modules) { // webpackBootstrap * @param {qtek.math.Vector3} [out] * @return {qtek.math.Vector3} */ - intersectPlane: function(plane, out) { + intersectPlane: function (plane, out) { var pn = plane.normal._array; var d = plane.distance; var ro = this.origin._array; @@ -13117,7 +13122,7 @@ return /******/ (function(modules) { // webpackBootstrap * Mirror the ray against plane * @param {qtek.math.Plane} plane */ - mirrorAgainstPlane: function(plane) { + mirrorAgainstPlane: function (plane) { // Distance to plane var d = vec3.dot(plane.normal._array, this.direction._array); vec3.scaleAndAdd(this.direction._array, this.direction._array, plane.normal._array, -d * 2); @@ -13199,7 +13204,7 @@ return /******/ (function(modules) { // webpackBootstrap * @param {qtek.math.Vector3} * @return {qtek.math.Vector3} */ - intersectBoundingBox: function(bbox, out) { + intersectBoundingBox: function (bbox, out) { var dir = this.direction._array; var origin = this.origin._array; var min = bbox.min._array; @@ -13281,7 +13286,7 @@ return /******/ (function(modules) { // webpackBootstrap * @param {qtek.math.Vector3} [barycenteric] barycentric coords * @return {qtek.math.Vector3} */ - intersectTriangle: (function() { + intersectTriangle: (function () { var eBA = vec3.create(); var eCA = vec3.create(); @@ -13349,7 +13354,7 @@ return /******/ (function(modules) { // webpackBootstrap * Apply an affine transform matrix to the ray * @return {qtek.math.Matrix4} matrix */ - applyTransform: function(matrix) { + applyTransform: function (matrix) { Vector3.add(this.direction, this.direction, this.origin); Vector3.transformMat4(this.origin, this.origin, matrix); Vector3.transformMat4(this.direction, this.direction, matrix); @@ -13362,7 +13367,7 @@ return /******/ (function(modules) { // webpackBootstrap * Copy values from another ray * @param {qtek.math.Ray} ray */ - copy: function(ray) { + copy: function (ray) { Vector3.copy(this.origin, ray.origin); Vector3.copy(this.direction, ray.direction); }, @@ -13371,7 +13376,7 @@ return /******/ (function(modules) { // webpackBootstrap * Clone a new ray * @return {qtek.math.Ray} */ - clone: function() { + clone: function () { var ray = new Ray(); ray.copy(this); return ray; @@ -17347,7 +17352,7 @@ return /******/ (function(modules) { // webpackBootstrap }, isUseIndices: function () { - return this.indices; + return !!this.indices; }, initIndicesFromArray: function (array) { @@ -17737,52 +17742,36 @@ return /******/ (function(modules) { // webpackBootstrap return; } - var vertexUseCount = []; - - for (var i = 0, len = this.vertexCount; i < len; i++) { - vertexUseCount[i] = 0; - } if (this.indices.length > 0xffff) { this.indices = new vendor.Uint32Array(this.indices); } - var cursor = 0; var attributes = this.attributes; var indices = this.indices; - // Cursor not use vertexNumber in case vertex array length is larger than face used. - for (var i = 0; i < indices.length; i++) { - cursor = Math.max(cursor, indices[i] + 1); - } - var attributeNameList = this.getEnabledAttributes(); + var oldAttrValues = {}; for (var a = 0; a < attributeNameList.length; a++) { var name = attributeNameList[a]; - var valueArr = attributes[name].value; + oldAttrValues[name] = attributes[name].value; attributes[name].init(this.indices.length); - var expandedArray = attributes[name].value; - for (var i = 0; i < valueArr.length; i++) { - expandedArray[i] = valueArr[i]; - } } + var cursor = 0; for (var i = 0; i < indices.length; i++) { var ii = indices[i]; - if (vertexUseCount[ii] > 0) { - for (var a = 0; a < attributeNameList.length; a++) { - var name = attributeNameList[a]; - var array = attributes[name].value; - var size = attributes[name].size; - - for (var k = 0; k < size; k++) { - array[cursor * size + k] = array[ii * size + k]; - } + for (var a = 0; a < attributeNameList.length; a++) { + var name = attributeNameList[a]; + var array = attributes[name].value; + var size = attributes[name].size; + + for (var k = 0; k < size; k++) { + array[cursor * size + k] = oldAttrValues[name][ii * size + k]; } - indices[i] = cursor; - cursor++; } - vertexUseCount[ii]++; + indices[i] = cursor; + cursor++; } this.dirty(); @@ -18813,7 +18802,7 @@ return /******/ (function(modules) { // webpackBootstrap */ isTextureEnabled: function (symbol) { var textureStatus = this._textureStatus; - return textureStatus[symbol] + return !!textureStatus[symbol] && textureStatus[symbol].enabled; }, @@ -20399,7 +20388,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "\n@export qtek.compositor.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\n\nvarying vec2 v_Texcoord;\n\nvoid main()\n{\n v_Texcoord = texcoord;\n gl_Position = worldViewProjection * vec4(position, 1.0);\n}\n\n@end"; + module.exports = "\n@export qtek.compositor.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\n\nvarying vec2 v_Texcoord;\n\nvoid main()\n{\n v_Texcoord = texcoord;\n gl_Position = worldViewProjection * vec4(position, 1.0);\n}\n\n@end"; /***/ }, @@ -22665,7 +22654,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "vec3 calcAmbientSHLight(int idx, vec3 N) {\n int offset = 9 * idx;\n\n return ambientSHLightCoefficients[0]\n + ambientSHLightCoefficients[1] * N.x\n + ambientSHLightCoefficients[2] * N.y\n + ambientSHLightCoefficients[3] * N.z\n + ambientSHLightCoefficients[4] * N.x * N.z\n + ambientSHLightCoefficients[5] * N.z * N.y\n + ambientSHLightCoefficients[6] * N.y * N.x\n + ambientSHLightCoefficients[7] * (3.0 * N.z * N.z - 1.0)\n + ambientSHLightCoefficients[8] * (N.x * N.x - N.y * N.y);\n}"; + module.exports = "vec3 calcAmbientSHLight(int idx, vec3 N) {\n int offset = 9 * idx;\n\n return ambientSHLightCoefficients[0]\n + ambientSHLightCoefficients[1] * N.x\n + ambientSHLightCoefficients[2] * N.y\n + ambientSHLightCoefficients[3] * N.z\n + ambientSHLightCoefficients[4] * N.x * N.z\n + ambientSHLightCoefficients[5] * N.z * N.y\n + ambientSHLightCoefficients[6] * N.y * N.x\n + ambientSHLightCoefficients[7] * (3.0 * N.z * N.z - 1.0)\n + ambientSHLightCoefficients[8] * (N.x * N.x - N.y * N.y);\n}"; /***/ }, @@ -22673,7 +22662,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.prez.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvoid main()\n{\n\n vec3 skinnedPosition = position;\n\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n#endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0);\n}\n\n@end\n\n\n@export qtek.prez.fragment\n\nvoid main()\n{\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n}\n\n@end"; + module.exports = "@export qtek.prez.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvoid main()\n{\n\n vec3 skinnedPosition = position;\n\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n#endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0);\n}\n\n@end\n\n\n@export qtek.prez.fragment\n\nvoid main()\n{\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n}\n\n@end"; /***/ }, @@ -22681,7 +22670,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.deferred.gbuffer.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 worldInverseTranspose : WORLDINVERSETRANSPOSE;\nuniform mat4 world : WORLD;\n\nuniform vec2 uvRepeat;\nuniform vec2 uvOffset;\n\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\n\n#ifdef FIRST_PASS\nattribute vec3 normal : NORMAL;\n#endif\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\n\n#ifdef FIRST_PASS\nvarying vec3 v_Normal;\n\nattribute vec4 tangent : TANGENT;\nvarying vec3 v_Tangent;\nvarying vec3 v_Bitangent;\n#endif\n\n\nvarying vec2 v_Texcoord;\nvarying vec4 v_ProjPos;\n\nvoid main()\n{\n\n vec3 skinnedPosition = position;\n\n#ifdef FIRST_PASS\n vec3 skinnedNormal = normal;\n vec3 skinnedTangent = tangent.xyz;\n bool hasTangent = dot(tangent, tangent) > 0.0;\n#endif\n\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n\n #ifdef FIRST_PASS\n skinnedNormal = (skinMatrixWS * vec4(normal, 0.0)).xyz;\n if (hasTangent) {\n skinnedTangent = (skinMatrixWS * vec4(tangent.xyz, 0.0)).xyz;\n }\n #endif\n#endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0);\n\n v_Texcoord = texcoord * uvRepeat + uvOffset;\n\n#ifdef FIRST_PASS\n v_Normal = normalize((worldInverseTranspose * vec4(skinnedNormal, 0.0)).xyz);\n\n if (hasTangent) {\n v_Tangent = normalize((worldInverseTranspose * vec4(skinnedTangent, 0.0)).xyz);\n v_Bitangent = normalize(cross(v_Normal, v_Tangent) * tangent.w);\n }\n#endif\n\n v_ProjPos = gl_Position;\n}\n\n\n@end\n\n\n@export qtek.deferred.gbuffer1.fragment\n\nuniform float glossiness;\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Normal;\n\nuniform sampler2D normalMap;\nvarying vec3 v_Tangent;\nvarying vec3 v_Bitangent;\n\nuniform sampler2D roughnessMap;\n\nuniform bool useRoughnessMap;\n\nvarying vec4 v_ProjPos;\n\nvoid main()\n{\n vec3 N = v_Normal;\n\n if (dot(v_Tangent, v_Tangent) > 0.0) {\n vec3 normalTexel = texture2D(normalMap, v_Texcoord).xyz;\n if (dot(normalTexel, normalTexel) > 0.0) { N = normalTexel * 2.0 - 1.0;\n mat3 tbn = mat3(v_Tangent, v_Bitangent, v_Normal);\n N = normalize(tbn * N);\n }\n }\n\n gl_FragColor.rgb = (N + 1.0) * 0.5;\n\n \n float g = glossiness;\n\n if (useRoughnessMap) {\n vec4 glossTexel = texture2D(roughnessMap, v_Texcoord);\n g = clamp(-glossTexel.r + g * 2.0, 0.0, 1.0);\n }\n\n\n gl_FragColor.a = g;\n\n }\n@end\n\n@export qtek.deferred.gbuffer2.fragment\n\nuniform sampler2D diffuseMap;\nuniform sampler2D metalnessMap;\n\nuniform vec3 color;\nuniform float metalness;\n\nuniform bool useMetalnessMap;\nuniform bool linear;\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.srgb\n\nvoid main ()\n{\n float m = metalness;\n\n if (useMetalnessMap) {\n vec4 metalnessTexel = texture2D(metalnessMap, v_Texcoord);\n m = clamp(metalnessTexel.r + (m * 2.0 - 1.0), 0.0, 1.0);\n }\n vec4 texel = texture2D(diffuseMap, v_Texcoord);\n if (linear) {\n texel = sRGBToLinear(texel);\n }\n\n gl_FragColor.rgb = texel.rgb * color;\n\n gl_FragColor.a = m;\n}\n\n@end\n\n\n@export qtek.deferred.gbuffer.debug\n\n@import qtek.deferred.chunk.light_head\nuniform int debug: 0;\n\nvoid main ()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n if (debug == 0) {\n gl_FragColor = vec4(N, 1.0);\n }\n else if (debug == 1) {\n gl_FragColor = vec4(vec3(z), 1.0);\n }\n else if (debug == 2) {\n gl_FragColor = vec4(position, 1.0);\n }\n else if (debug == 3) {\n gl_FragColor = vec4(vec3(glossiness), 1.0);\n }\n else if (debug == 4) {\n gl_FragColor = vec4(vec3(metalness), 1.0);\n }\n else {\n gl_FragColor = vec4(albedo, 1.0);\n }\n}\n@end"; + module.exports = "@export qtek.deferred.gbuffer.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 worldInverseTranspose : WORLDINVERSETRANSPOSE;\nuniform mat4 world : WORLD;\n\nuniform vec2 uvRepeat;\nuniform vec2 uvOffset;\n\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\n\n#ifdef FIRST_PASS\nattribute vec3 normal : NORMAL;\n#endif\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\n\n#ifdef FIRST_PASS\nvarying vec3 v_Normal;\n\nattribute vec4 tangent : TANGENT;\nvarying vec3 v_Tangent;\nvarying vec3 v_Bitangent;\n#endif\n\n\nvarying vec2 v_Texcoord;\nvarying vec4 v_ProjPos;\n\nvoid main()\n{\n\n vec3 skinnedPosition = position;\n\n#ifdef FIRST_PASS\n vec3 skinnedNormal = normal;\n vec3 skinnedTangent = tangent.xyz;\n bool hasTangent = dot(tangent, tangent) > 0.0;\n#endif\n\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n\n #ifdef FIRST_PASS\n skinnedNormal = (skinMatrixWS * vec4(normal, 0.0)).xyz;\n if (hasTangent) {\n skinnedTangent = (skinMatrixWS * vec4(tangent.xyz, 0.0)).xyz;\n }\n #endif\n#endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0);\n\n v_Texcoord = texcoord * uvRepeat + uvOffset;\n\n#ifdef FIRST_PASS\n v_Normal = normalize((worldInverseTranspose * vec4(skinnedNormal, 0.0)).xyz);\n\n if (hasTangent) {\n v_Tangent = normalize((worldInverseTranspose * vec4(skinnedTangent, 0.0)).xyz);\n v_Bitangent = normalize(cross(v_Normal, v_Tangent) * tangent.w);\n }\n#endif\n\n v_ProjPos = gl_Position;\n}\n\n\n@end\n\n\n@export qtek.deferred.gbuffer1.fragment\n\nuniform float glossiness;\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Normal;\n\nuniform sampler2D normalMap;\nvarying vec3 v_Tangent;\nvarying vec3 v_Bitangent;\n\nuniform sampler2D roughnessMap;\n\nuniform bool useRoughnessMap;\n\nvarying vec4 v_ProjPos;\n\nvoid main()\n{\n vec3 N = v_Normal;\n\n if (dot(v_Tangent, v_Tangent) > 0.0) {\n vec3 normalTexel = texture2D(normalMap, v_Texcoord).xyz;\n if (dot(normalTexel, normalTexel) > 0.0) { N = normalTexel * 2.0 - 1.0;\n mat3 tbn = mat3(v_Tangent, v_Bitangent, v_Normal);\n N = normalize(tbn * N);\n }\n }\n\n gl_FragColor.rgb = (N + 1.0) * 0.5;\n\n \n float g = glossiness;\n\n if (useRoughnessMap) {\n vec4 glossTexel = texture2D(roughnessMap, v_Texcoord);\n g = clamp(-glossTexel.r + g * 2.0, 0.0, 1.0);\n }\n\n\n gl_FragColor.a = g;\n\n }\n@end\n\n@export qtek.deferred.gbuffer2.fragment\n\nuniform sampler2D diffuseMap;\nuniform sampler2D metalnessMap;\n\nuniform vec3 color;\nuniform float metalness;\n\nuniform bool useMetalnessMap;\nuniform bool linear;\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.srgb\n\nvoid main ()\n{\n float m = metalness;\n\n if (useMetalnessMap) {\n vec4 metalnessTexel = texture2D(metalnessMap, v_Texcoord);\n m = clamp(metalnessTexel.r + (m * 2.0 - 1.0), 0.0, 1.0);\n }\n vec4 texel = texture2D(diffuseMap, v_Texcoord);\n if (linear) {\n texel = sRGBToLinear(texel);\n }\n\n gl_FragColor.rgb = texel.rgb * color;\n\n gl_FragColor.a = m;\n}\n\n@end\n\n\n@export qtek.deferred.gbuffer.debug\n\n@import qtek.deferred.chunk.light_head\nuniform int debug: 0;\n\nvoid main ()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n if (debug == 0) {\n gl_FragColor = vec4(N, 1.0);\n }\n else if (debug == 1) {\n gl_FragColor = vec4(vec3(z), 1.0);\n }\n else if (debug == 2) {\n gl_FragColor = vec4(position, 1.0);\n }\n else if (debug == 3) {\n gl_FragColor = vec4(vec3(glossiness), 1.0);\n }\n else if (debug == 4) {\n gl_FragColor = vec4(vec3(metalness), 1.0);\n }\n else {\n gl_FragColor = vec4(albedo, 1.0);\n }\n}\n@end"; /***/ }, @@ -22689,7 +22678,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.deferred.chunk.light_head\n\nuniform sampler2D gBufferTexture1;\nuniform sampler2D gBufferTexture2;\nuniform sampler2D gBufferTexture3;\n\nuniform vec2 windowSize: WINDOW_SIZE;\n\nuniform vec4 viewport: VIEWPORT;\n\nuniform mat4 viewProjectionInv;\n\n\n#ifdef DEPTH_ENCODED\n@import qtek.util.decode_float\n#endif\n\n@end\n\n@export qtek.deferred.chunk.gbuffer_read\n \n vec2 uv = gl_FragCoord.xy / windowSize;\n\n vec2 uv2 = (gl_FragCoord.xy - viewport.xy) / viewport.zw;\n\n vec4 texel1 = texture2D(gBufferTexture1, uv);\n vec4 texel3 = texture2D(gBufferTexture3, uv);\n if (dot(texel1.rgb, vec3(1.0)) == 0.0) {\n discard;\n }\n\n float glossiness = texel1.a;\n float metalness = texel3.a;\n\n vec3 N = texel1.rgb * 2.0 - 1.0;\n\n float z = texture2D(gBufferTexture2, uv).r * 2.0 - 1.0;\n\n vec2 xy = uv2 * 2.0 - 1.0;\n\n vec4 projectedPos = vec4(xy, z, 1.0);\n vec4 p4 = viewProjectionInv * projectedPos;\n\n vec3 position = p4.xyz / p4.w;\n\n vec3 albedo = texel3.rgb;\n\n vec3 diffuseColor = albedo * (1.0 - metalness);\n vec3 specularColor = mix(vec3(0.04), albedo, metalness);\n@end\n\n@export qtek.deferred.chunk.light_equation\n\nfloat D_Phong(in float g, in float ndh) {\n float a = pow(8192.0, g);\n return (a + 2.0) / 8.0 * pow(ndh, a);\n}\n\nfloat D_GGX(in float g, in float ndh) {\n float r = 1.0 - g;\n float a = r * r;\n float tmp = ndh * ndh * (a - 1.0) + 1.0;\n return a / (3.1415926 * tmp * tmp);\n}\n\nvec3 F_Schlick(in float ndv, vec3 spec) {\n return spec + (1.0 - spec) * pow(1.0 - ndv, 5.0);\n}\n\nvec3 lightEquation(\n in vec3 lightColor, in vec3 diffuseColor, in vec3 specularColor,\n in float ndl, in float ndh, in float ndv, in float g\n)\n{\n return ndl * lightColor\n * (diffuseColor + D_Phong(g, ndh) * F_Schlick(ndv, specularColor));\n}\n\n@end"; + module.exports = "@export qtek.deferred.chunk.light_head\n\nuniform sampler2D gBufferTexture1;\nuniform sampler2D gBufferTexture2;\nuniform sampler2D gBufferTexture3;\n\nuniform vec2 windowSize: WINDOW_SIZE;\n\nuniform vec4 viewport: VIEWPORT;\n\nuniform mat4 viewProjectionInv;\n\n\n#ifdef DEPTH_ENCODED\n@import qtek.util.decode_float\n#endif\n\n@end\n\n@export qtek.deferred.chunk.gbuffer_read\n \n vec2 uv = gl_FragCoord.xy / windowSize;\n\n vec2 uv2 = (gl_FragCoord.xy - viewport.xy) / viewport.zw;\n\n vec4 texel1 = texture2D(gBufferTexture1, uv);\n vec4 texel3 = texture2D(gBufferTexture3, uv);\n if (dot(texel1.rgb, vec3(1.0)) == 0.0) {\n discard;\n }\n\n float glossiness = texel1.a;\n float metalness = texel3.a;\n\n vec3 N = texel1.rgb * 2.0 - 1.0;\n\n float z = texture2D(gBufferTexture2, uv).r * 2.0 - 1.0;\n\n vec2 xy = uv2 * 2.0 - 1.0;\n\n vec4 projectedPos = vec4(xy, z, 1.0);\n vec4 p4 = viewProjectionInv * projectedPos;\n\n vec3 position = p4.xyz / p4.w;\n\n vec3 albedo = texel3.rgb;\n\n vec3 diffuseColor = albedo * (1.0 - metalness);\n vec3 specularColor = mix(vec3(0.04), albedo, metalness);\n@end\n\n@export qtek.deferred.chunk.light_equation\n\nfloat D_Phong(in float g, in float ndh) {\n float a = pow(8192.0, g);\n return (a + 2.0) / 8.0 * pow(ndh, a);\n}\n\nfloat D_GGX(in float g, in float ndh) {\n float r = 1.0 - g;\n float a = r * r;\n float tmp = ndh * ndh * (a - 1.0) + 1.0;\n return a / (3.1415926 * tmp * tmp);\n}\n\nvec3 F_Schlick(in float ndv, vec3 spec) {\n return spec + (1.0 - spec) * pow(1.0 - ndv, 5.0);\n}\n\nvec3 lightEquation(\n in vec3 lightColor, in vec3 diffuseColor, in vec3 specularColor,\n in float ndl, in float ndh, in float ndv, in float g\n)\n{\n return ndl * lightColor\n * (diffuseColor + D_Phong(g, ndh) * F_Schlick(ndv, specularColor));\n}\n\n@end"; /***/ }, @@ -23791,7 +23780,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "\n@export qtek.util.rand\nhighp float rand(vec2 uv) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot(uv.xy, vec2(a,b)), sn = mod(dt, 3.141592653589793);\n return fract(sin(sn) * c);\n}\n@end\n\n@export qtek.util.calculate_attenuation\n\nuniform float attenuationFactor : 5.0;\n\nfloat lightAttenuation(float dist, float range)\n{\n float attenuation = 1.0;\n attenuation = dist*dist/(range*range+1.0);\n float att_s = attenuationFactor;\n attenuation = 1.0/(attenuation*att_s+1.0);\n att_s = 1.0/(att_s+1.0);\n attenuation = attenuation - att_s;\n attenuation /= 1.0 - att_s;\n return clamp(attenuation, 0.0, 1.0);\n}\n\n@end\n\n@export qtek.util.edge_factor\n\nfloat edgeFactor(float width)\n{\n vec3 d = fwidth(v_Barycentric);\n vec3 a3 = smoothstep(vec3(0.0), d * width, v_Barycentric);\n return min(min(a3.x, a3.y), a3.z);\n}\n\n@end\n\n@export qtek.util.encode_float\nvec4 encodeFloat(const in float depth)\n{\n \n \n const vec4 bitShifts = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);\n const vec4 bit_mask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);\n vec4 res = fract(depth * bitShifts);\n res -= res.xxyz * bit_mask;\n\n return res;\n}\n@end\n\n@export qtek.util.decode_float\nfloat decodeFloat(const in vec4 color)\n{\n \n \n const vec4 bitShifts = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0);\n return dot(color, bitShifts);\n}\n@end\n\n\n@export qtek.util.float\n@import qtek.util.encode_float\n@import qtek.util.decode_float\n@end\n\n\n\n@export qtek.util.rgbm_decode\nvec3 RGBMDecode(vec4 rgbm, float range) {\n return range * rgbm.rgb * rgbm.a;\n }\n@end\n\n@export qtek.util.rgbm_encode\nvec4 RGBMEncode(vec3 color, float range) {\n if (dot(color, color) == 0.0) {\n return vec4(0.0);\n }\n vec4 rgbm;\n color /= range;\n rgbm.a = clamp(max(max(color.r, color.g), max(color.b, 1e-6)), 0.0, 1.0);\n rgbm.a = ceil(rgbm.a * 255.0) / 255.0;\n rgbm.rgb = color / rgbm.a;\n return rgbm;\n}\n@end\n\n@export qtek.util.rgbm\n@import qtek.util.rgbm_decode\n@import qtek.util.rgbm_encode\n\nvec4 decodeHDR(vec4 color)\n{\n#if defined(RGBM_DECODE) || defined(RGBM)\n return vec4(RGBMDecode(color, 51.5), 1.0);\n#else\n return color;\n#endif\n}\n\nvec4 encodeHDR(vec4 color)\n{\n#if defined(RGBM_ENCODE) || defined(RGBM)\n return RGBMEncode(color.xyz, 51.5);\n#else\n return color;\n#endif\n}\n\n@end\n\n\n@export qtek.util.srgb\n\nvec4 sRGBToLinear(in vec4 value) {\n return vec4(mix(pow(value.rgb * 0.9478672986 + vec3(0.0521327014), vec3(2.4)), value.rgb * 0.0773993808, vec3(lessThanEqual(value.rgb, vec3(0.04045)))), value.w);\n}\n\nvec4 linearTosRGB(in vec4 value) {\n return vec4(mix(pow(value.rgb, vec3(0.41666)) * 1.055 - vec3(0.055), value.rgb * 12.92, vec3(lessThanEqual(value.rgb, vec3(0.0031308)))), value.w);\n}\n@end\n\n\n@export qtek.chunk.skin_matrix\n\nmat4 skinMatrixWS;\nif (joint.x >= 0.0)\n{\n skinMatrixWS = skinMatrix[int(joint.x)] * weight.x;\n}\nif (joint.y >= 0.0)\n{\n skinMatrixWS += skinMatrix[int(joint.y)] * weight.y;\n}\nif (joint.z >= 0.0)\n{\n skinMatrixWS += skinMatrix[int(joint.z)] * weight.z;\n}\nif (joint.w >= 0.0)\n{\n skinMatrixWS += skinMatrix[int(joint.w)] * (1.0-weight.x-weight.y-weight.z);\n}\n@end\n\n\n\n@export qtek.util.parallax_correct\n\nvec3 parallaxCorrect(in vec3 dir, in vec3 pos, in vec3 boxMin, in vec3 boxMax) {\n vec3 first = (boxMax - pos) / dir;\n vec3 second = (boxMin - pos) / dir;\n\n vec3 further = max(first, second);\n float dist = min(further.x, min(further.y, further.z));\n\n vec3 fixedPos = pos + dir * dist;\n vec3 boxCenter = (boxMax + boxMin) * 0.5;\n\n return normalize(fixedPos - boxCenter);\n}\n\n@end\n\n\n\n@export qtek.util.clamp_sample\nvec4 clampSample(const in sampler2D texture, const in vec2 coord)\n{\n#ifdef STEREO\n float eye = step(0.5, coord.x) * 0.5;\n vec2 coordClamped = clamp(coord, vec2(eye, 0.0), vec2(0.5 + eye, 1.0));\n#else\n vec2 coordClamped = clamp(coord, vec2(0.0), vec2(1.0));\n#endif\n return texture2D(texture, coordClamped);\n}\n@end"; + module.exports = "\n@export qtek.util.rand\nhighp float rand(vec2 uv) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot(uv.xy, vec2(a,b)), sn = mod(dt, 3.141592653589793);\n return fract(sin(sn) * c);\n}\n@end\n\n@export qtek.util.calculate_attenuation\n\nuniform float attenuationFactor : 5.0;\n\nfloat lightAttenuation(float dist, float range)\n{\n float attenuation = 1.0;\n attenuation = dist*dist/(range*range+1.0);\n float att_s = attenuationFactor;\n attenuation = 1.0/(attenuation*att_s+1.0);\n att_s = 1.0/(att_s+1.0);\n attenuation = attenuation - att_s;\n attenuation /= 1.0 - att_s;\n return clamp(attenuation, 0.0, 1.0);\n}\n\n@end\n\n@export qtek.util.edge_factor\n\nfloat edgeFactor(float width)\n{\n vec3 d = fwidth(v_Barycentric);\n vec3 a3 = smoothstep(vec3(0.0), d * width, v_Barycentric);\n return min(min(a3.x, a3.y), a3.z);\n}\n\n@end\n\n@export qtek.util.encode_float\nvec4 encodeFloat(const in float depth)\n{\n \n \n const vec4 bitShifts = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);\n const vec4 bit_mask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);\n vec4 res = fract(depth * bitShifts);\n res -= res.xxyz * bit_mask;\n\n return res;\n}\n@end\n\n@export qtek.util.decode_float\nfloat decodeFloat(const in vec4 color)\n{\n \n \n const vec4 bitShifts = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0);\n return dot(color, bitShifts);\n}\n@end\n\n\n@export qtek.util.float\n@import qtek.util.encode_float\n@import qtek.util.decode_float\n@end\n\n\n\n@export qtek.util.rgbm_decode\nvec3 RGBMDecode(vec4 rgbm, float range) {\n return range * rgbm.rgb * rgbm.a;\n }\n@end\n\n@export qtek.util.rgbm_encode\nvec4 RGBMEncode(vec3 color, float range) {\n if (dot(color, color) == 0.0) {\n return vec4(0.0);\n }\n vec4 rgbm;\n color /= range;\n rgbm.a = clamp(max(max(color.r, color.g), max(color.b, 1e-6)), 0.0, 1.0);\n rgbm.a = ceil(rgbm.a * 255.0) / 255.0;\n rgbm.rgb = color / rgbm.a;\n return rgbm;\n}\n@end\n\n@export qtek.util.rgbm\n@import qtek.util.rgbm_decode\n@import qtek.util.rgbm_encode\n\nvec4 decodeHDR(vec4 color)\n{\n#if defined(RGBM_DECODE) || defined(RGBM)\n return vec4(RGBMDecode(color, 51.5), 1.0);\n#else\n return color;\n#endif\n}\n\nvec4 encodeHDR(vec4 color)\n{\n#if defined(RGBM_ENCODE) || defined(RGBM)\n return RGBMEncode(color.xyz, 51.5);\n#else\n return color;\n#endif\n}\n\n@end\n\n\n@export qtek.util.srgb\n\nvec4 sRGBToLinear(in vec4 value) {\n return vec4(mix(pow(value.rgb * 0.9478672986 + vec3(0.0521327014), vec3(2.4)), value.rgb * 0.0773993808, vec3(lessThanEqual(value.rgb, vec3(0.04045)))), value.w);\n}\n\nvec4 linearTosRGB(in vec4 value) {\n return vec4(mix(pow(value.rgb, vec3(0.41666)) * 1.055 - vec3(0.055), value.rgb * 12.92, vec3(lessThanEqual(value.rgb, vec3(0.0031308)))), value.w);\n}\n@end\n\n\n@export qtek.chunk.skin_matrix\n\nmat4 skinMatrixWS;\nif (joint.x >= 0.0)\n{\n skinMatrixWS = skinMatrix[int(joint.x)] * weight.x;\n}\nif (joint.y >= 0.0)\n{\n skinMatrixWS += skinMatrix[int(joint.y)] * weight.y;\n}\nif (joint.z >= 0.0)\n{\n skinMatrixWS += skinMatrix[int(joint.z)] * weight.z;\n}\nif (joint.w >= 0.0)\n{\n skinMatrixWS += skinMatrix[int(joint.w)] * (1.0-weight.x-weight.y-weight.z);\n}\n@end\n\n\n\n@export qtek.util.parallax_correct\n\nvec3 parallaxCorrect(in vec3 dir, in vec3 pos, in vec3 boxMin, in vec3 boxMax) {\n vec3 first = (boxMax - pos) / dir;\n vec3 second = (boxMin - pos) / dir;\n\n vec3 further = max(first, second);\n float dist = min(further.x, min(further.y, further.z));\n\n vec3 fixedPos = pos + dir * dist;\n vec3 boxCenter = (boxMax + boxMin) * 0.5;\n\n return normalize(fixedPos - boxCenter);\n}\n\n@end\n\n\n\n@export qtek.util.clamp_sample\nvec4 clampSample(const in sampler2D texture, const in vec2 coord)\n{\n#ifdef STEREO\n float eye = step(0.5, coord.x) * 0.5;\n vec2 coordClamped = clamp(coord, vec2(eye, 0.0), vec2(0.5 + eye, 1.0));\n#else\n vec2 coordClamped = clamp(coord, vec2(0.0), vec2(1.0));\n#endif\n return texture2D(texture, coordClamped);\n}\n@end"; /***/ }, @@ -23799,7 +23788,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.deferred.light_volume.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\n\nvarying vec3 v_Position;\n\nvoid main()\n{\n gl_Position = worldViewProjection * vec4(position, 1.0);\n\n v_Position = position;\n}\n\n@end"; + module.exports = "@export qtek.deferred.light_volume.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\n\nvarying vec3 v_Position;\n\nvoid main()\n{\n gl_Position = worldViewProjection * vec4(position, 1.0);\n\n v_Position = position;\n}\n\n@end"; /***/ }, @@ -23807,7 +23796,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.deferred.spot_light\n\n@import qtek.deferred.chunk.light_head\n\n@import qtek.deferred.chunk.light_equation\n\n@import qtek.util.calculate_attenuation\n\nuniform vec3 lightPosition;\nuniform vec3 lightDirection;\nuniform vec3 lightColor;\nuniform float umbraAngleCosine;\nuniform float penumbraAngleCosine;\nuniform float lightRange;\nuniform float falloffFactor;\n\nuniform vec3 eyePosition;\n\n#ifdef SHADOWMAP_ENABLED\nuniform sampler2D lightShadowMap;\nuniform mat4 lightMatrix;\nuniform float lightShadowMapSize;\n#endif\n\n@import qtek.plugin.shadow_map_common\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n vec3 L = lightPosition - position;\n vec3 V = normalize(eyePosition - position);\n\n float dist = length(L);\n L /= dist;\n\n\n float attenuation = lightAttenuation(dist, lightRange);\n float c = dot(-normalize(lightDirection), L);\n\n float falloff = clamp((c - umbraAngleCosine) / (penumbraAngleCosine - umbraAngleCosine), 0.0, 1.0);\n falloff = pow(falloff, falloffFactor);\n\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n\n gl_FragColor.rgb = (1.0 - falloff) * attenuation * lightEquation(\n lightColor, diffuseColor, specularColor, ndl, ndh, ndv, glossiness\n );\n\n#ifdef SHADOWMAP_ENABLED\n float shadowContrib = computeShadowContrib(\n lightShadowMap, lightMatrix, position, lightShadowMapSize\n );\n gl_FragColor.rgb *= shadowContrib;\n#endif\n\n gl_FragColor.a = 1.0;\n}\n@end\n"; + module.exports = "@export qtek.deferred.spot_light\n\n@import qtek.deferred.chunk.light_head\n\n@import qtek.deferred.chunk.light_equation\n\n@import qtek.util.calculate_attenuation\n\nuniform vec3 lightPosition;\nuniform vec3 lightDirection;\nuniform vec3 lightColor;\nuniform float umbraAngleCosine;\nuniform float penumbraAngleCosine;\nuniform float lightRange;\nuniform float falloffFactor;\n\nuniform vec3 eyePosition;\n\n#ifdef SHADOWMAP_ENABLED\nuniform sampler2D lightShadowMap;\nuniform mat4 lightMatrix;\nuniform float lightShadowMapSize;\n#endif\n\n@import qtek.plugin.shadow_map_common\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n vec3 L = lightPosition - position;\n vec3 V = normalize(eyePosition - position);\n\n float dist = length(L);\n L /= dist;\n\n\n float attenuation = lightAttenuation(dist, lightRange);\n float c = dot(-normalize(lightDirection), L);\n\n float falloff = clamp((c - umbraAngleCosine) / (penumbraAngleCosine - umbraAngleCosine), 0.0, 1.0);\n falloff = pow(falloff, falloffFactor);\n\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n\n gl_FragColor.rgb = (1.0 - falloff) * attenuation * lightEquation(\n lightColor, diffuseColor, specularColor, ndl, ndh, ndv, glossiness\n );\n\n#ifdef SHADOWMAP_ENABLED\n float shadowContrib = computeShadowContrib(\n lightShadowMap, lightMatrix, position, lightShadowMapSize\n );\n gl_FragColor.rgb *= shadowContrib;\n#endif\n\n gl_FragColor.a = 1.0;\n}\n@end\n"; /***/ }, @@ -23815,7 +23804,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.deferred.directional_light\n\n@import qtek.deferred.chunk.light_head\n\n@import qtek.deferred.chunk.light_equation\n\nuniform vec3 lightDirection;\nuniform vec3 lightColor;\n\nuniform vec3 eyePosition;\n\n#ifdef SHADOWMAP_ENABLED\nuniform sampler2D lightShadowMap;\nuniform float lightShadowMapSize;\nuniform mat4 lightMatrices[SHADOW_CASCADE];\nuniform float shadowCascadeClipsNear[SHADOW_CASCADE];\nuniform float shadowCascadeClipsFar[SHADOW_CASCADE];\n#endif\n\n@import qtek.plugin.shadow_map_common\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n vec3 L = -normalize(lightDirection);\n vec3 V = normalize(eyePosition - position);\n\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n\n gl_FragColor.rgb = lightEquation(\n lightColor, diffuseColor, specularColor, ndl, ndh, ndv, glossiness\n );\n\n#ifdef SHADOWMAP_ENABLED\n float shadowContrib = 1.0;\n for (int _idx_ = 0; _idx_ < SHADOW_CASCADE; _idx_++) {{\n if (\n z >= shadowCascadeClipsNear[_idx_] &&\n z <= shadowCascadeClipsFar[_idx_]\n ) {\n shadowContrib = computeShadowContrib(\n lightShadowMap, lightMatrices[_idx_], position, lightShadowMapSize,\n vec2(1.0 / float(SHADOW_CASCADE), 1.0),\n vec2(float(_idx_) / float(SHADOW_CASCADE), 0.0)\n );\n }\n }}\n\n gl_FragColor.rgb *= shadowContrib;\n#endif\n\n gl_FragColor.a = 1.0;\n}\n@end\n"; + module.exports = "@export qtek.deferred.directional_light\n\n@import qtek.deferred.chunk.light_head\n\n@import qtek.deferred.chunk.light_equation\n\nuniform vec3 lightDirection;\nuniform vec3 lightColor;\n\nuniform vec3 eyePosition;\n\n#ifdef SHADOWMAP_ENABLED\nuniform sampler2D lightShadowMap;\nuniform float lightShadowMapSize;\nuniform mat4 lightMatrices[SHADOW_CASCADE];\nuniform float shadowCascadeClipsNear[SHADOW_CASCADE];\nuniform float shadowCascadeClipsFar[SHADOW_CASCADE];\n#endif\n\n@import qtek.plugin.shadow_map_common\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n vec3 L = -normalize(lightDirection);\n vec3 V = normalize(eyePosition - position);\n\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n\n gl_FragColor.rgb = lightEquation(\n lightColor, diffuseColor, specularColor, ndl, ndh, ndv, glossiness\n );\n\n#ifdef SHADOWMAP_ENABLED\n float shadowContrib = 1.0;\n for (int _idx_ = 0; _idx_ < SHADOW_CASCADE; _idx_++) {{\n if (\n z >= shadowCascadeClipsNear[_idx_] &&\n z <= shadowCascadeClipsFar[_idx_]\n ) {\n shadowContrib = computeShadowContrib(\n lightShadowMap, lightMatrices[_idx_], position, lightShadowMapSize,\n vec2(1.0 / float(SHADOW_CASCADE), 1.0),\n vec2(float(_idx_) / float(SHADOW_CASCADE), 0.0)\n );\n }\n }}\n\n gl_FragColor.rgb *= shadowContrib;\n#endif\n\n gl_FragColor.a = 1.0;\n}\n@end\n"; /***/ }, @@ -23823,7 +23812,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.deferred.ambient_light\n\nuniform sampler2D gBufferTexture1;\nuniform sampler2D gBufferTexture3;\nuniform vec3 lightColor;\n\nuniform vec2 windowSize: WINDOW_SIZE;\n\nvoid main()\n{\n vec2 uv = gl_FragCoord.xy / windowSize;\n\n vec4 texel1 = texture2D(gBufferTexture1, uv);\n if (dot(texel1.rgb, vec3(1.0)) == 0.0) {\n discard;\n }\n\n vec3 albedo = texture2D(gBufferTexture3, uv).rgb;\n gl_FragColor.rgb = lightColor * albedo;\n gl_FragColor.a = 1.0;\n}\n@end"; + module.exports = "@export qtek.deferred.ambient_light\n\nuniform sampler2D gBufferTexture1;\nuniform sampler2D gBufferTexture3;\nuniform vec3 lightColor;\n\nuniform vec2 windowSize: WINDOW_SIZE;\n\nvoid main()\n{\n vec2 uv = gl_FragCoord.xy / windowSize;\n\n vec4 texel1 = texture2D(gBufferTexture1, uv);\n if (dot(texel1.rgb, vec3(1.0)) == 0.0) {\n discard;\n }\n\n vec3 albedo = texture2D(gBufferTexture3, uv).rgb;\n gl_FragColor.rgb = lightColor * albedo;\n gl_FragColor.a = 1.0;\n}\n@end"; /***/ }, @@ -23831,7 +23820,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.deferred.ambient_sh_light\n\nuniform sampler2D gBufferTexture1;\nuniform sampler2D gBufferTexture3;\n\nuniform vec3 lightColor;\nuniform vec3 lightCoefficients[9];\n\nuniform vec2 windowSize: WINDOW_SIZE;\n\nvec3 calcAmbientSHLight(vec3 N) {\n return lightCoefficients[0]\n + lightCoefficients[1] * N.x\n + lightCoefficients[2] * N.y\n + lightCoefficients[3] * N.z\n + lightCoefficients[4] * N.x * N.z\n + lightCoefficients[5] * N.z * N.y\n + lightCoefficients[6] * N.y * N.x\n + lightCoefficients[7] * (3.0 * N.z * N.z - 1.0)\n + lightCoefficients[8] * (N.x * N.x - N.y * N.y);\n}\n\nvoid main()\n{\n vec2 uv = gl_FragCoord.xy / windowSize;\n\n vec4 texel1 = texture2D(gBufferTexture1, uv);\n if (dot(texel1.rgb, vec3(1.0)) == 0.0) {\n discard;\n }\n vec3 N = texel1.rgb * 2.0 - 1.0;\n vec3 albedo = texture2D(gBufferTexture3, uv).rgb;\n gl_FragColor.rgb = lightColor * albedo * calcAmbientSHLight(N);\n gl_FragColor.a = 1.0;\n}\n@end"; + module.exports = "@export qtek.deferred.ambient_sh_light\n\nuniform sampler2D gBufferTexture1;\nuniform sampler2D gBufferTexture3;\n\nuniform vec3 lightColor;\nuniform vec3 lightCoefficients[9];\n\nuniform vec2 windowSize: WINDOW_SIZE;\n\nvec3 calcAmbientSHLight(vec3 N) {\n return lightCoefficients[0]\n + lightCoefficients[1] * N.x\n + lightCoefficients[2] * N.y\n + lightCoefficients[3] * N.z\n + lightCoefficients[4] * N.x * N.z\n + lightCoefficients[5] * N.z * N.y\n + lightCoefficients[6] * N.y * N.x\n + lightCoefficients[7] * (3.0 * N.z * N.z - 1.0)\n + lightCoefficients[8] * (N.x * N.x - N.y * N.y);\n}\n\nvoid main()\n{\n vec2 uv = gl_FragCoord.xy / windowSize;\n\n vec4 texel1 = texture2D(gBufferTexture1, uv);\n if (dot(texel1.rgb, vec3(1.0)) == 0.0) {\n discard;\n }\n vec3 N = texel1.rgb * 2.0 - 1.0;\n vec3 albedo = texture2D(gBufferTexture3, uv).rgb;\n gl_FragColor.rgb = lightColor * albedo * calcAmbientSHLight(N);\n gl_FragColor.a = 1.0;\n}\n@end"; /***/ }, @@ -23839,7 +23828,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.deferred.ambient_cubemap_light\n\n@import qtek.deferred.chunk.light_head\n\nuniform vec3 lightColor;\nuniform samplerCube lightCubemap;\nuniform sampler2D brdfLookup;\n\nuniform vec3 eyePosition;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n vec3 V = normalize(eyePosition - position);\n vec3 L = reflect(-V, N);\n\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n float rough = clamp(1.0 - glossiness, 0.0, 1.0);\n float bias = rough * 5.0;\n vec2 brdfParam = texture2D(brdfLookup, vec2(rough, ndv)).xy;\n vec3 envWeight = specularColor * brdfParam.x + brdfParam.y;\n\n vec3 envTexel = RGBMDecode(textureCubeLodEXT(lightCubemap, L, bias), 51.5);\n gl_FragColor.rgb = lightColor * envTexel * envWeight;\n\n gl_FragColor.a = 1.0;\n}\n@end"; + module.exports = "@export qtek.deferred.ambient_cubemap_light\n\n@import qtek.deferred.chunk.light_head\n\nuniform vec3 lightColor;\nuniform samplerCube lightCubemap;\nuniform sampler2D brdfLookup;\n\nuniform vec3 eyePosition;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n vec3 V = normalize(eyePosition - position);\n vec3 L = reflect(-V, N);\n\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n float rough = clamp(1.0 - glossiness, 0.0, 1.0);\n float bias = rough * 5.0;\n vec2 brdfParam = texture2D(brdfLookup, vec2(rough, ndv)).xy;\n vec3 envWeight = specularColor * brdfParam.x + brdfParam.y;\n\n vec3 envTexel = RGBMDecode(textureCubeLodEXT(lightCubemap, L, bias), 51.5);\n gl_FragColor.rgb = lightColor * envTexel * envWeight;\n\n gl_FragColor.a = 1.0;\n}\n@end"; /***/ }, @@ -23847,7 +23836,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.deferred.point_light\n\n@import qtek.deferred.chunk.light_head\n\n@import qtek.util.calculate_attenuation\n\n@import qtek.deferred.chunk.light_equation\n\nuniform vec3 lightPosition;\nuniform vec3 lightColor;\nuniform float lightRange;\n\nuniform vec3 eyePosition;\n\n#ifdef SHADOWMAP_ENABLED\nuniform samplerCube lightShadowMap;\nuniform float lightShadowMapSize;\n#endif\n\nvarying vec3 v_Position;\n\n@import qtek.plugin.shadow_map_common\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n vec3 L = lightPosition - position;\n vec3 V = normalize(eyePosition - position);\n\n float dist = length(L);\n L /= dist;\n\n vec3 H = normalize(L + V);\n\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n float attenuation = lightAttenuation(dist, lightRange);\n gl_FragColor.rgb = attenuation * lightEquation(\n lightColor, diffuseColor, specularColor, ndl, ndh, ndv, glossiness\n );\n\n#ifdef SHADOWMAP_ENABLED\n float shadowContrib = computeShadowContribOmni(\n lightShadowMap, -L * dist, lightRange\n );\n gl_FragColor.rgb *= clamp(shadowContrib, 0.0, 1.0);\n#endif\n\n gl_FragColor.a = 1.0;\n}\n@end"; + module.exports = "@export qtek.deferred.point_light\n\n@import qtek.deferred.chunk.light_head\n\n@import qtek.util.calculate_attenuation\n\n@import qtek.deferred.chunk.light_equation\n\nuniform vec3 lightPosition;\nuniform vec3 lightColor;\nuniform float lightRange;\n\nuniform vec3 eyePosition;\n\n#ifdef SHADOWMAP_ENABLED\nuniform samplerCube lightShadowMap;\nuniform float lightShadowMapSize;\n#endif\n\nvarying vec3 v_Position;\n\n@import qtek.plugin.shadow_map_common\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n vec3 L = lightPosition - position;\n vec3 V = normalize(eyePosition - position);\n\n float dist = length(L);\n L /= dist;\n\n vec3 H = normalize(L + V);\n\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n float attenuation = lightAttenuation(dist, lightRange);\n gl_FragColor.rgb = attenuation * lightEquation(\n lightColor, diffuseColor, specularColor, ndl, ndh, ndv, glossiness\n );\n\n#ifdef SHADOWMAP_ENABLED\n float shadowContrib = computeShadowContribOmni(\n lightShadowMap, -L * dist, lightRange\n );\n gl_FragColor.rgb *= clamp(shadowContrib, 0.0, 1.0);\n#endif\n\n gl_FragColor.a = 1.0;\n}\n@end"; /***/ }, @@ -23855,7 +23844,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.deferred.sphere_light\n\n@import qtek.deferred.chunk.light_head\n\n@import qtek.util.calculate_attenuation\n\n@import qtek.deferred.chunk.light_equation\n\nuniform vec3 lightPosition;\nuniform vec3 lightColor;\nuniform float lightRange;\nuniform float lightRadius;\n\nuniform vec3 eyePosition;\n\nvarying vec3 v_Position;\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n\n vec3 L = lightPosition - position;\n\n vec3 V = normalize(eyePosition - position);\n\n float dist = length(L);\n vec3 R = reflect(V, N);\n float tmp = dot(L, R);\n vec3 cToR = tmp * R - L;\n float d = length(cToR);\n L = L + cToR * clamp(lightRadius / d, 0.0, 1.0);\n\n L = normalize(L);\n\n vec3 H = normalize(L + V);\n\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n float attenuation = lightAttenuation(dist, lightRange);\n gl_FragColor.rgb = lightColor * ndl * attenuation;\n\n glossiness = clamp(glossiness - lightRadius / 2.0 / dist, 0.0, 1.0);\n\n gl_FragColor.rgb = attenuation * lightEquation(\n lightColor, diffuseColor, specularColor, ndl, ndh, ndv, glossiness\n );\n\n gl_FragColor.a = 1.0;\n}\n@end"; + module.exports = "@export qtek.deferred.sphere_light\n\n@import qtek.deferred.chunk.light_head\n\n@import qtek.util.calculate_attenuation\n\n@import qtek.deferred.chunk.light_equation\n\nuniform vec3 lightPosition;\nuniform vec3 lightColor;\nuniform float lightRange;\nuniform float lightRadius;\n\nuniform vec3 eyePosition;\n\nvarying vec3 v_Position;\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n\n vec3 L = lightPosition - position;\n\n vec3 V = normalize(eyePosition - position);\n\n float dist = length(L);\n vec3 R = reflect(V, N);\n float tmp = dot(L, R);\n vec3 cToR = tmp * R - L;\n float d = length(cToR);\n L = L + cToR * clamp(lightRadius / d, 0.0, 1.0);\n\n L = normalize(L);\n\n vec3 H = normalize(L + V);\n\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n float attenuation = lightAttenuation(dist, lightRange);\n gl_FragColor.rgb = lightColor * ndl * attenuation;\n\n glossiness = clamp(glossiness - lightRadius / 2.0 / dist, 0.0, 1.0);\n\n gl_FragColor.rgb = attenuation * lightEquation(\n lightColor, diffuseColor, specularColor, ndl, ndh, ndv, glossiness\n );\n\n gl_FragColor.a = 1.0;\n}\n@end"; /***/ }, @@ -23863,7 +23852,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.deferred.tube_light\n\n@import qtek.deferred.chunk.light_head\n\n@import qtek.util.calculate_attenuation\n\n@import qtek.deferred.chunk.light_equation\n\nuniform vec3 lightPosition;\nuniform vec3 lightColor;\nuniform float lightRange;\nuniform vec3 lightExtend;\n\nuniform vec3 eyePosition;\n\nvarying vec3 v_Position;\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n vec3 L = lightPosition - position;\n\n vec3 V = normalize(eyePosition - position);\n\n vec3 R = reflect(V, N);\n\n vec3 L0 = lightPosition - lightExtend - position;\n vec3 L1 = lightPosition + lightExtend - position;\n vec3 LD = L1 - L0;\n\n float len0 = length(L0);\n float len1 = length(L1);\n float irra = 2.0 * clamp(dot(N, L0) / (2.0 * len0) + dot(N, L1) / (2.0 * len1), 0.0, 1.0);\n\n float LDDotR = dot(R, LD);\n float t = (LDDotR * dot(R, L0) - dot(L0, LD)) / (dot(LD, LD) - LDDotR * LDDotR);\n t = clamp(t, 0.0, 1.0);\n L = L0 + t * LD;\n float dist = length(L);\n L /= dist;\n\n vec3 H = normalize(L + V);\n\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n\n glossiness = clamp(glossiness - 0.0 / 2.0 / dist, 0.0, 1.0);\n\n gl_FragColor.rgb = lightColor * irra * lightAttenuation(dist, lightRange)\n * (diffuseColor + D_Phong(glossiness, ndh) * F_Schlick(ndv, specularColor));\n\n gl_FragColor.a = 1.0;\n}\n@end"; + module.exports = "@export qtek.deferred.tube_light\n\n@import qtek.deferred.chunk.light_head\n\n@import qtek.util.calculate_attenuation\n\n@import qtek.deferred.chunk.light_equation\n\nuniform vec3 lightPosition;\nuniform vec3 lightColor;\nuniform float lightRange;\nuniform vec3 lightExtend;\n\nuniform vec3 eyePosition;\n\nvarying vec3 v_Position;\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n vec3 L = lightPosition - position;\n\n vec3 V = normalize(eyePosition - position);\n\n vec3 R = reflect(V, N);\n\n vec3 L0 = lightPosition - lightExtend - position;\n vec3 L1 = lightPosition + lightExtend - position;\n vec3 LD = L1 - L0;\n\n float len0 = length(L0);\n float len1 = length(L1);\n float irra = 2.0 * clamp(dot(N, L0) / (2.0 * len0) + dot(N, L1) / (2.0 * len1), 0.0, 1.0);\n\n float LDDotR = dot(R, LD);\n float t = (LDDotR * dot(R, L0) - dot(L0, LD)) / (dot(LD, LD) - LDDotR * LDDotR);\n t = clamp(t, 0.0, 1.0);\n L = L0 + t * LD;\n float dist = length(L);\n L /= dist;\n\n vec3 H = normalize(L + V);\n\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n\n glossiness = clamp(glossiness - 0.0 / 2.0 / dist, 0.0, 1.0);\n\n gl_FragColor.rgb = lightColor * irra * lightAttenuation(dist, lightRange)\n * (diffuseColor + D_Phong(glossiness, ndh) * F_Schlick(ndv, specularColor));\n\n gl_FragColor.a = 1.0;\n}\n@end"; /***/ }, @@ -24675,7 +24664,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.skybox.vertex\n\nuniform mat4 world : WORLD;\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\n\nvarying vec3 v_WorldPosition;\n\nvoid main()\n{\n v_WorldPosition = (world * vec4(position, 1.0)).xyz;\n gl_Position = worldViewProjection * vec4(position, 1.0);\n}\n\n@end\n\n@export qtek.skybox.fragment\n\nuniform mat4 viewInverse : VIEWINVERSE;\nuniform samplerCube environmentMap;\nuniform float lod: 0.0;\n\nvarying vec3 v_WorldPosition;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec3 eyePos = viewInverse[3].xyz;\n vec3 viewDirection = normalize(v_WorldPosition - eyePos);\n\n vec3 tex = decodeHDR(textureCubeLodEXT(environmentMap, viewDirection, lod)).rgb;\n\n#ifdef SRGB_DECODE\n tex.rgb = pow(tex.rgb, vec3(2.2));\n#endif\n\n gl_FragColor = encodeHDR(vec4(tex, 1.0));\n}\n@end"; + module.exports = "@export qtek.skybox.vertex\n\nuniform mat4 world : WORLD;\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\n\nvarying vec3 v_WorldPosition;\n\nvoid main()\n{\n v_WorldPosition = (world * vec4(position, 1.0)).xyz;\n gl_Position = worldViewProjection * vec4(position, 1.0);\n}\n\n@end\n\n@export qtek.skybox.fragment\n\nuniform mat4 viewInverse : VIEWINVERSE;\nuniform samplerCube environmentMap;\nuniform float lod: 0.0;\n\nvarying vec3 v_WorldPosition;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec3 eyePos = viewInverse[3].xyz;\n vec3 viewDirection = normalize(v_WorldPosition - eyePos);\n\n vec3 tex = decodeHDR(textureCubeLodEXT(environmentMap, viewDirection, lod)).rgb;\n\n#ifdef SRGB_DECODE\n tex.rgb = pow(tex.rgb, vec3(2.2));\n#endif\n\n gl_FragColor = encodeHDR(vec4(tex, 1.0));\n}\n@end"; /***/ }, @@ -25530,7 +25519,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.basic.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nuniform vec2 uvRepeat : [1.0, 1.0];\nuniform vec2 uvOffset : [0.0, 0.0];\n\nattribute vec2 texcoord : TEXCOORD_0;\nattribute vec3 position : POSITION;\n\nattribute vec3 barycentric;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Barycentric;\n\nvoid main()\n{\n vec3 skinnedPosition = position;\n\n#ifdef SKINNING\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n#endif\n\n v_Texcoord = texcoord * uvRepeat + uvOffset;\n v_Barycentric = barycentric;\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0);\n}\n\n@end\n\n\n\n\n@export qtek.basic.fragment\n\n#define ALPHA_TEST_THRESHOLD 0.5\n\nvarying vec2 v_Texcoord;\nuniform sampler2D diffuseMap;\nuniform vec3 color : [1.0, 1.0, 1.0];\nuniform vec3 emission : [0.0, 0.0, 0.0];\nuniform float alpha : 1.0;\n\nuniform float lineWidth : 0.0;\nuniform vec3 lineColor : [0.0, 0.0, 0.0];\nvarying vec3 v_Barycentric;\n\n@import qtek.util.edge_factor\n\n@import qtek.util.rgbm\n\n@import qtek.util.srgb\n\nvoid main()\n{\n\n#ifdef RENDER_TEXCOORD\n gl_FragColor = vec4(v_Texcoord, 1.0, 1.0);\n return;\n#endif\n\n gl_FragColor = vec4(color, alpha);\n\n#ifdef DIFFUSEMAP_ENABLED\n vec4 tex = decodeHDR(texture2D(diffuseMap, v_Texcoord));\n\n#ifdef SRGB_DECODE\n tex = sRGBToLinear(tex);\n#endif\n\n#if defined(DIFFUSEMAP_ALPHA_ALPHA)\n gl_FragColor.a = tex.a;\n#endif\n\n gl_FragColor.rgb *= tex.rgb;\n#endif\n\n gl_FragColor.rgb += emission;\n if( lineWidth > 0.01)\n {\n gl_FragColor.rgb = gl_FragColor.rgb * mix(lineColor, vec3(1.0), edgeFactor(lineWidth));\n }\n\n#ifdef GAMMA_ENCODE\n gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(1 / 2.2));\n#endif\n\n#ifdef ALPHA_TEST\n if (gl_FragColor.a < ALPHA_TEST_THRESHOLD) {\n discard;\n }\n#endif\n\n gl_FragColor = encodeHDR(gl_FragColor);\n\n}\n\n@end"; + module.exports = "@export qtek.basic.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nuniform vec2 uvRepeat : [1.0, 1.0];\nuniform vec2 uvOffset : [0.0, 0.0];\n\nattribute vec2 texcoord : TEXCOORD_0;\nattribute vec3 position : POSITION;\n\nattribute vec3 barycentric;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Barycentric;\n\nvoid main()\n{\n vec3 skinnedPosition = position;\n\n#ifdef SKINNING\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n#endif\n\n v_Texcoord = texcoord * uvRepeat + uvOffset;\n v_Barycentric = barycentric;\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0);\n}\n\n@end\n\n\n\n\n@export qtek.basic.fragment\n\n#define ALPHA_TEST_THRESHOLD 0.5\n\nvarying vec2 v_Texcoord;\nuniform sampler2D diffuseMap;\nuniform vec3 color : [1.0, 1.0, 1.0];\nuniform vec3 emission : [0.0, 0.0, 0.0];\nuniform float alpha : 1.0;\n\nuniform float lineWidth : 0.0;\nuniform vec3 lineColor : [0.0, 0.0, 0.0];\nvarying vec3 v_Barycentric;\n\n@import qtek.util.edge_factor\n\n@import qtek.util.rgbm\n\n@import qtek.util.srgb\n\nvoid main()\n{\n\n#ifdef RENDER_TEXCOORD\n gl_FragColor = vec4(v_Texcoord, 1.0, 1.0);\n return;\n#endif\n\n gl_FragColor = vec4(color, alpha);\n\n#ifdef DIFFUSEMAP_ENABLED\n vec4 tex = decodeHDR(texture2D(diffuseMap, v_Texcoord));\n\n#ifdef SRGB_DECODE\n tex = sRGBToLinear(tex);\n#endif\n\n#if defined(DIFFUSEMAP_ALPHA_ALPHA)\n gl_FragColor.a = tex.a;\n#endif\n\n gl_FragColor.rgb *= tex.rgb;\n#endif\n\n gl_FragColor.rgb += emission;\n if( lineWidth > 0.01)\n {\n gl_FragColor.rgb = gl_FragColor.rgb * mix(lineColor, vec3(1.0), edgeFactor(lineWidth));\n }\n\n#ifdef GAMMA_ENCODE\n gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(1 / 2.2));\n#endif\n\n#ifdef ALPHA_TEST\n if (gl_FragColor.a < ALPHA_TEST_THRESHOLD) {\n discard;\n }\n#endif\n\n gl_FragColor = encodeHDR(gl_FragColor);\n\n}\n\n@end"; /***/ }, @@ -25889,7 +25878,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "#define SAMPLE_NUMBER 1024\n#define PI 3.14159265358979\n\n\nuniform sampler2D normalDistribution;\n\nuniform vec2 viewportSize : [512, 256];\n\nconst vec3 N = vec3(0.0, 0.0, 1.0);\nconst float fSampleNumber = float(SAMPLE_NUMBER);\n\nvec3 importanceSampleNormal(float i, float roughness, vec3 N) {\n vec3 H = texture2D(normalDistribution, vec2(roughness, i)).rgb;\n\n vec3 upVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);\n vec3 tangentX = normalize(cross(upVector, N));\n vec3 tangentY = cross(N, tangentX);\n return tangentX * H.x + tangentY * H.y + N * H.z;\n}\n\nfloat G_Smith(float roughness, float NoV, float NoL) {\n float k = roughness * roughness / 2.0;\n float G1V = NoV / (NoV * (1.0 - k) + k);\n float G1L = NoL / (NoL * (1.0 - k) + k);\n return G1L * G1V;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / viewportSize;\n float NoV = uv.x;\n float roughness = uv.y;\n\n vec3 V;\n V.x = sqrt(1.0 - NoV * NoV);\n V.y = 0.0;\n V.z = NoV;\n\n float A = 0.0;\n float B = 0.0;\n\n for (int i = 0; i < SAMPLE_NUMBER; i++) {\n vec3 H = importanceSampleNormal(float(i) / fSampleNumber, roughness, N);\n vec3 L = reflect(-V, H);\n float NoL = clamp(L.z, 0.0, 1.0);\n float NoH = clamp(H.z, 0.0, 1.0);\n float VoH = clamp(dot(V, H), 0.0, 1.0);\n\n if (NoL > 0.0) {\n float G = G_Smith(roughness, NoV, NoL);\n float G_Vis = G * VoH / (NoH * NoV);\n float Fc = pow(1.0 - VoH, 5.0);\n A += (1.0 - Fc) * G_Vis;\n B += Fc * G_Vis;\n }\n }\n\n gl_FragColor = vec4(vec2(A, B) / fSampleNumber, 0.0, 1.0);\n}\n"; + module.exports = "#define SAMPLE_NUMBER 1024\n#define PI 3.14159265358979\n\n\nuniform sampler2D normalDistribution;\n\nuniform vec2 viewportSize : [512, 256];\n\nconst vec3 N = vec3(0.0, 0.0, 1.0);\nconst float fSampleNumber = float(SAMPLE_NUMBER);\n\nvec3 importanceSampleNormal(float i, float roughness, vec3 N) {\n vec3 H = texture2D(normalDistribution, vec2(roughness, i)).rgb;\n\n vec3 upVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);\n vec3 tangentX = normalize(cross(upVector, N));\n vec3 tangentY = cross(N, tangentX);\n return tangentX * H.x + tangentY * H.y + N * H.z;\n}\n\nfloat G_Smith(float roughness, float NoV, float NoL) {\n float k = roughness * roughness / 2.0;\n float G1V = NoV / (NoV * (1.0 - k) + k);\n float G1L = NoL / (NoL * (1.0 - k) + k);\n return G1L * G1V;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / viewportSize;\n float NoV = uv.x;\n float roughness = uv.y;\n\n vec3 V;\n V.x = sqrt(1.0 - NoV * NoV);\n V.y = 0.0;\n V.z = NoV;\n\n float A = 0.0;\n float B = 0.0;\n\n for (int i = 0; i < SAMPLE_NUMBER; i++) {\n vec3 H = importanceSampleNormal(float(i) / fSampleNumber, roughness, N);\n vec3 L = reflect(-V, H);\n float NoL = clamp(L.z, 0.0, 1.0);\n float NoH = clamp(H.z, 0.0, 1.0);\n float VoH = clamp(dot(V, H), 0.0, 1.0);\n\n if (NoL > 0.0) {\n float G = G_Smith(roughness, NoV, NoL);\n float G_Vis = G * VoH / (NoH * NoV);\n float Fc = pow(1.0 - VoH, 5.0);\n A += (1.0 - Fc) * G_Vis;\n B += Fc * G_Vis;\n }\n }\n\n gl_FragColor = vec4(vec2(A, B) / fSampleNumber, 0.0, 1.0);\n}\n"; /***/ }, @@ -25897,7 +25886,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "#define SAMPLE_NUMBER 1024\n#define PI 3.14159265358979\n\nuniform mat4 viewInverse : VIEWINVERSE;\nuniform samplerCube environmentMap;\nuniform sampler2D normalDistribution;\n\nuniform float roughness : 0.5;\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_WorldPosition;\n\nconst float fSampleNumber = float(SAMPLE_NUMBER);\n\n@import qtek.util.rgbm\n\nvec3 importanceSampleNormal(float i, float roughness, vec3 N) {\n vec3 H = texture2D(normalDistribution, vec2(roughness, i)).rgb;\n\n vec3 upVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);\n vec3 tangentX = normalize(cross(upVector, N));\n vec3 tangentY = cross(N, tangentX);\n return tangentX * H.x + tangentY * H.y + N * H.z;\n}\n\nvoid main() {\n\n vec3 eyePos = viewInverse[3].xyz;\n vec3 V = normalize(v_WorldPosition - eyePos);\n\n vec3 N = V;\n vec3 R = V;\n\n vec3 prefilteredColor = vec3(0.0);\n float totalWeight = 0.0;\n\n\n for (int i = 0; i < SAMPLE_NUMBER; i++) {\n vec3 H = importanceSampleNormal(float(i) / fSampleNumber, roughness, N);\n vec3 L = reflect(-V, H);\n\n float NoL = clamp(dot(N, L), 0.0, 1.0);\n if (NoL > 0.0) {\n prefilteredColor += decodeHDR(textureCube(environmentMap, L)).rgb * NoL;\n totalWeight += NoL;\n }\n }\n\n gl_FragColor = encodeHDR(vec4(prefilteredColor / totalWeight, 1.0));\n}\n"; + module.exports = "#define SAMPLE_NUMBER 1024\n#define PI 3.14159265358979\n\nuniform mat4 viewInverse : VIEWINVERSE;\nuniform samplerCube environmentMap;\nuniform sampler2D normalDistribution;\n\nuniform float roughness : 0.5;\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_WorldPosition;\n\nconst float fSampleNumber = float(SAMPLE_NUMBER);\n\n@import qtek.util.rgbm\n\nvec3 importanceSampleNormal(float i, float roughness, vec3 N) {\n vec3 H = texture2D(normalDistribution, vec2(roughness, i)).rgb;\n\n vec3 upVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);\n vec3 tangentX = normalize(cross(upVector, N));\n vec3 tangentY = cross(N, tangentX);\n return tangentX * H.x + tangentY * H.y + N * H.z;\n}\n\nvoid main() {\n\n vec3 eyePos = viewInverse[3].xyz;\n vec3 V = normalize(v_WorldPosition - eyePos);\n\n vec3 N = V;\n vec3 R = V;\n\n vec3 prefilteredColor = vec3(0.0);\n float totalWeight = 0.0;\n\n\n for (int i = 0; i < SAMPLE_NUMBER; i++) {\n vec3 H = importanceSampleNormal(float(i) / fSampleNumber, roughness, N);\n vec3 L = reflect(-V, H);\n\n float NoL = clamp(dot(N, L), 0.0, 1.0);\n if (NoL > 0.0) {\n prefilteredColor += decodeHDR(textureCube(environmentMap, L)).rgb * NoL;\n totalWeight += NoL;\n }\n }\n\n gl_FragColor = encodeHDR(vec4(prefilteredColor / totalWeight, 1.0));\n}\n"; /***/ }, @@ -26020,7 +26009,7 @@ return /******/ (function(modules) { // webpackBootstrap value: function (instance) { instance.__dir = instance.__dir || new Vector3(); // Direction is target to eye - return instance.__dir.copy(instance.worldTransform.z).negate()._array; + return instance.__dir.copy(instance.worldTransform.z).normalize().negate()._array; } }, directionalLightColor: { @@ -26223,7 +26212,7 @@ return /******/ (function(modules) { // webpackBootstrap spotLightPosition: { type: '3f', value: function (instance) { - return instance.getWorldPosition()._array; + return instance.getWorldPosition().normalize()._array; } }, spotLightRange: { @@ -26846,17 +26835,17 @@ return /******/ (function(modules) { // webpackBootstrap /** * @type {string} */ - rootPath: '', + rootPath: null, /** * @type {string} */ - textureRootPath: '', + textureRootPath: null, /** * @type {string} */ - bufferRootPath: '', + bufferRootPath: null, /** * @type {string} @@ -26897,23 +26886,23 @@ return /******/ (function(modules) { // webpackBootstrap /** * @param {string} url */ - load: function(url) { + load: function (url) { var self = this; - if (!this.rootPath) { + if (this.rootPath == null) { this.rootPath = url.slice(0, url.lastIndexOf('/')); } request.get({ url: url, - onprogress: function(percent, loaded, total) { + onprogress: function (percent, loaded, total) { self.trigger('progress', percent, loaded, total); }, - onerror: function(e) { + onerror: function (e) { self.trigger('error', e); }, responseType: 'text', - onload: function(data) { + onload: function (data) { self.parse(JSON.parse(data)); } }); @@ -26923,7 +26912,7 @@ return /******/ (function(modules) { // webpackBootstrap * @param {Object} json * @return {qtek.loader.GLTF.IResult} */ - parse: function(json) { + parse: function (json) { var self = this; var loading = 0; @@ -26940,7 +26929,7 @@ return /******/ (function(modules) { // webpackBootstrap // Mount on the root node if given var rootNode = this.rootNode || new Scene(); // Load buffers - util.each(json.buffers, function(bufferInfo, name) { + util.each(json.buffers, function (bufferInfo, name) { loading++; var path = bufferInfo.uri; @@ -26949,13 +26938,13 @@ return /******/ (function(modules) { // webpackBootstrap if (path == null) { path = bufferInfo.path; } - self._loadBuffer(path, function(buffer) { + self._loadBuffer(path, function (buffer) { lib.buffers[name] = buffer; loading--; if (loading === 0) { afterLoadBuffer(); } - }, function() { + }, function () { loading--; if (loading === 0) { afterLoadBuffer(); @@ -27028,18 +27017,21 @@ return /******/ (function(modules) { // webpackBootstrap }; }, - _loadBuffer: function(path, onsuccess, onerror) { - var root = this.bufferRootPath || this.rootPath; - if (root) { - path = root + '/' + path; + _loadBuffer: function (path, onsuccess, onerror) { + var rootPath = this.bufferRootPath; + if (rootPath == null) { + rootPath = this.rootPath; + } + if (rootPath) { + path = rootPath + '/' + path; } request.get({ url: path, responseType: 'arraybuffer', - onload: function(buffer) { + onload: function (buffer) { onsuccess && onsuccess(buffer); }, - onerror: function(buffer) { + onerror: function (buffer) { onerror && onerror(buffer); } }); @@ -27047,7 +27039,7 @@ return /******/ (function(modules) { // webpackBootstrap // https://github.com/KhronosGroup/glTF/issues/100 // https://github.com/KhronosGroup/glTF/issues/193 - _parseSkins: function(json, lib) { + _parseSkins: function (json, lib) { // Create skeletons and joints var haveInvBindMatrices = false; @@ -27082,7 +27074,7 @@ return /******/ (function(modules) { // webpackBootstrap lib.skeletons[name] = skeleton; } - var bindNodeToJoint = function(jointsMap, nodeName, parentIndex, rootNode) { + var bindNodeToJoint = function (jointsMap, nodeName, parentIndex, rootNode) { var node = lib.nodes[nodeName]; var nodeInfo = json.nodes[nodeName]; var joint = jointsMap[nodeInfo.jointId]; @@ -27111,7 +27103,7 @@ return /******/ (function(modules) { // webpackBootstrap return joint; }; - var getJointIndex = function(joint) { + var getJointIndex = function (joint) { return joint.index; }; @@ -27191,13 +27183,16 @@ return /******/ (function(modules) { // webpackBootstrap } }, - _parseTextures: function(json, lib) { - var root = this.textureRootPath || this.rootPath; - util.each(json.textures, function(textureInfo, name){ + _parseTextures: function (json, lib) { + var rootPath = this.textureRootPath; + if (rootPath == null) { + rootPath = this.rootPath; + } + util.each(json.textures, function (textureInfo, name){ var samplerInfo = json.samplers[textureInfo.sampler]; var parameters = {}; ['wrapS', 'wrapT', 'magFilter', 'minFilter'] - .forEach(function(name) { + .forEach(function (name) { var value = samplerInfo[name]; if (value != null) { if (typeof(value) === 'string') { @@ -27220,7 +27215,7 @@ return /******/ (function(modules) { // webpackBootstrap if (target === glenum.TEXTURE_2D) { var texture = new Texture2D(parameters); var imageInfo = json.images[textureInfo.source]; - texture.load(util.relative2absolute(imageInfo.path, root)); + texture.load(util.relative2absolute(imageInfo.path, rootPath)); lib.textures[name] = texture; } else if(target === glenum.TEXTURE_CUBE_MAP) { @@ -27231,7 +27226,7 @@ return /******/ (function(modules) { // webpackBootstrap // Only phong material is support yet // TODO support custom material - _parseMaterials: function(json, lib) { + _parseMaterials: function (json, lib) { var techniques = {}; // Parse techniques for (var name in json.techniques) { @@ -27360,7 +27355,7 @@ return /******/ (function(modules) { // webpackBootstrap } }, - _parseMeshes: function(json, lib) { + _parseMeshes: function (json, lib) { var self = this; var meshKeys = Object.keys(json.meshes); @@ -27512,7 +27507,7 @@ return /******/ (function(modules) { // webpackBootstrap } }, - _parseNodes: function(json, lib) { + _parseNodes: function (json, lib) { for (var name in json.nodes) { var nodeInfo = json.nodes[name]; @@ -27629,7 +27624,7 @@ return /******/ (function(modules) { // webpackBootstrap } }, - _parseLight: function(lightInfo) { + _parseLight: function (lightInfo) { // TODO Light parameters switch(lightInfo.type) { case 'point': @@ -27657,7 +27652,7 @@ return /******/ (function(modules) { // webpackBootstrap return light; }, - _parseAnimations: function(json, lib) { + _parseAnimations: function (json, lib) { // TODO Only support nodes animation now var nodeAnimationClips = lib.clips = {}; @@ -28184,7 +28179,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "\n\n@export qtek.standard.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 worldInverseTranspose : WORLDINVERSETRANSPOSE;\nuniform mat4 world : WORLD;\n\nuniform vec2 uvRepeat : [1.0, 1.0];\nuniform vec2 uvOffset : [0.0, 0.0];\n\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\n\n#if defined(AOMAP_ENABLED)\nattribute vec2 texcoord2 : TEXCOORD_1;\n#endif\n\nattribute vec3 normal : NORMAL;\nattribute vec4 tangent : TANGENT;\n\n#ifdef VERTEX_COLOR\nattribute vec4 color : COLOR;\n#endif\n\nattribute vec3 barycentric;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\nvarying vec3 v_Barycentric;\n\n#ifdef NORMALMAP_ENABLED\nvarying vec3 v_Tangent;\nvarying vec3 v_Bitangent;\n#endif\n\n#ifdef VERTEX_COLOR\nvarying vec4 v_Color;\n#endif\n\n\n#if defined(AOMAP_ENABLED)\nvarying vec2 v_Texcoord2;\n#endif\n\nvoid main()\n{\n\n vec3 skinnedPosition = position;\n vec3 skinnedNormal = normal;\n vec3 skinnedTangent = tangent.xyz;\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n skinnedNormal = (skinMatrixWS * vec4(normal, 0.0)).xyz;\n skinnedTangent = (skinMatrixWS * vec4(tangent.xyz, 0.0)).xyz;\n#endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0);\n\n v_Texcoord = texcoord * uvRepeat + uvOffset;\n v_WorldPosition = (world * vec4(skinnedPosition, 1.0)).xyz;\n v_Barycentric = barycentric;\n\n v_Normal = normalize((worldInverseTranspose * vec4(skinnedNormal, 0.0)).xyz);\n\n#ifdef NORMALMAP_ENABLED\n v_Tangent = normalize((worldInverseTranspose * vec4(skinnedTangent, 0.0)).xyz);\n v_Bitangent = normalize(cross(v_Normal, v_Tangent) * tangent.w);\n#endif\n\n#ifdef VERTEX_COLOR\n v_Color = color;\n#endif\n\n#if defined(AOMAP_ENABLED)\n v_Texcoord2 = texcoord2;\n#endif\n}\n\n@end\n\n\n@export qtek.standard.fragment\n\n#define PI 3.14159265358979\n#define ALPHA_TEST_THRESHOLD 0.5\n\n#define GLOSS_CHANEL 0\n#define ROUGHNESS_CHANEL 0\n#define METALNESS_CHANEL 1\n\nuniform mat4 viewInverse : VIEWINVERSE;\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\n\n#ifdef NORMALMAP_ENABLED\nvarying vec3 v_Tangent;\nvarying vec3 v_Bitangent;\nuniform sampler2D normalMap;\n#endif\n\n#ifdef DIFFUSEMAP_ENABLED\nuniform sampler2D diffuseMap;\n#endif\n\n#ifdef SPECULARMAP_ENABLED\nuniform sampler2D specularMap;\n#endif\n\n#ifdef USE_ROUGHNESS\nuniform float roughness : 0.5;\n #ifdef ROUGHNESSMAP_ENABLED\nuniform sampler2D roughnessMap;\n #endif\n#else\nuniform float glossiness: 0.5;\n #ifdef GLOSSMAP_ENABLED\nuniform sampler2D glossMap;\n #endif\n#endif\n\n#ifdef METALNESSMAP_ENABLED\nuniform sampler2D metalnessMap;\n#endif\n\n#ifdef ENVIRONMENTMAP_ENABLED\nuniform samplerCube environmentMap;\n\n #ifdef PARALLAX_CORRECTED\nuniform vec3 environmentBoxMin;\nuniform vec3 environmentBoxMax;\n #endif\n\n#endif\n\n#ifdef BRDFLOOKUP_ENABLED\nuniform sampler2D brdfLookup;\n#endif\n\n#ifdef EMISSIVEMAP_ENABLED\nuniform sampler2D emissiveMap;\n#endif\n\n#ifdef SSAOMAP_ENABLED\nuniform sampler2D ssaoMap;\nuniform vec4 viewport : VIEWPORT;\n#endif\n\n#ifdef AOMAP_ENABLED\nuniform sampler2D aoMap;\nuniform float aoIntensity;\nvarying vec2 v_Texcoord2;\n#endif\n\nuniform vec3 color : [1.0, 1.0, 1.0];\nuniform float alpha : 1.0;\n\n\n#ifdef USE_METALNESS\nuniform float metalness : 0.0;\n#else\nuniform vec3 specularColor : [0.1, 0.1, 0.1];\n#endif\n\nuniform vec3 emission : [0.0, 0.0, 0.0];\n\nuniform float emissionIntensity: 1;\n\nuniform float lineWidth : 0.0;\nuniform vec3 lineColor : [0.0, 0.0, 0.0];\nvarying vec3 v_Barycentric;\n\n#ifdef ENVIRONMENTMAP_PREFILTER\nuniform float maxMipmapLevel: 5;\n#endif\n\n#ifdef AMBIENT_LIGHT_COUNT\n@import qtek.header.ambient_light\n#endif\n\n#ifdef AMBIENT_SH_LIGHT_COUNT\n@import qtek.header.ambient_sh_light\n#endif\n\n#ifdef AMBIENT_CUBEMAP_LIGHT_COUNT\n@import qtek.header.ambient_cubemap_light\n#endif\n\n#ifdef POINT_LIGHT_COUNT\n@import qtek.header.point_light\n#endif\n#ifdef DIRECTIONAL_LIGHT_COUNT\n@import qtek.header.directional_light\n#endif\n#ifdef SPOT_LIGHT_COUNT\n@import qtek.header.spot_light\n#endif\n\n@import qtek.util.calculate_attenuation\n\n@import qtek.util.edge_factor\n\n@import qtek.util.rgbm\n\n@import qtek.util.srgb\n\n@import qtek.plugin.compute_shadow_map\n\n@import qtek.util.parallax_correct\n\n\nfloat G_Smith(float g, float ndv, float ndl)\n{\n float roughness = 1.0 - g;\n float k = roughness * roughness / 2.0;\n float G1V = ndv / (ndv * (1.0 - k) + k);\n float G1L = ndl / (ndl * (1.0 - k) + k);\n return G1L * G1V;\n}\nvec3 F_Schlick(float ndv, vec3 spec) {\n return spec + (1.0 - spec) * pow(1.0 - ndv, 5.0);\n}\n\nfloat D_Phong(float g, float ndh) {\n float a = pow(8192.0, g);\n return (a + 2.0) / 8.0 * pow(ndh, a);\n}\n\nfloat D_GGX(float g, float ndh) {\n float r = 1.0 - g;\n float a = r * r;\n float tmp = ndh * ndh * (a - 1.0) + 1.0;\n return a / (PI * tmp * tmp);\n}\n\n\nvoid main()\n{\n vec4 albedoColor = vec4(color, alpha);\n vec3 eyePos = viewInverse[3].xyz;\n vec3 V = normalize(eyePos - v_WorldPosition);\n\n#ifdef DIFFUSEMAP_ENABLED\n vec4 texel = texture2D(diffuseMap, v_Texcoord);\n #ifdef SRGB_DECODE\n texel = sRGBToLinear(texel);\n #endif\n albedoColor.rgb *= texel.rgb;\n #ifdef DIFFUSEMAP_ALPHA_ALPHA\n albedoColor.a *= texel.a;\n #endif\n\n#endif\n\n\n#ifdef USE_METALNESS\n float m = metalness;\n\n #ifdef METALNESSMAP_ENABLED\n float m2 = texture2D(metalnessMap, v_Texcoord)[METALNESS_CHANEL];\n m = clamp(m2 + (m - 0.5) * 2.0, 0.0, 1.0);\n #endif\n\n vec3 baseColor = albedoColor.rgb;\n albedoColor.rgb = baseColor * (1.0 - m);\n vec3 spec = mix(vec3(0.04), baseColor, m);\n#else\n vec3 spec = specularColor;\n#endif\n\n#ifdef USE_ROUGHNESS\n float g = 1.0 - roughness;\n #ifdef ROUGHNESSMAP_ENABLED\n float g2 = 1.0 - texture2D(roughnessMap, v_Texcoord)[ROUGHNESS_CHANEL];\n g = clamp(g2 + (g - 0.5) * 2.0, 0.0, 1.0);\n #endif\n#else\n float g = glossiness;\n #ifdef GLOSSMAP_ENABLED\n float g2 = texture2D(glossMap, v_Texcoord)[GLOSS_CHANEL];\n g = clamp(g2 + (g - 0.5) * 2.0, 0.0, 1.0);\n #endif\n#endif\n\n#ifdef SPECULARMAP_ENABLED\n spec *= texture2D(specularMap, v_Texcoord).rgb;\n#endif\n\n vec3 N = v_Normal;\n#ifdef NORMALMAP_ENABLED\n if (dot(v_Tangent, v_Tangent) > 0.0) {\n vec3 normalTexel = texture2D(normalMap, v_Texcoord).xyz;\n if (dot(normalTexel, normalTexel) > 0.0) { N = normalTexel * 2.0 - 1.0;\n mat3 tbn = mat3(v_Tangent, v_Bitangent, v_Normal);\n N = normalize(tbn * N);\n }\n }\n#endif\n\n vec3 diffuseTerm = vec3(0.0, 0.0, 0.0);\n vec3 specularTerm = vec3(0.0, 0.0, 0.0);\n\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n vec3 fresnelTerm = F_Schlick(ndv, spec);\n\n#ifdef AMBIENT_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_LIGHT_COUNT; _idx_++)\n {{\n diffuseTerm += ambientLightColor[_idx_];\n }}\n#endif\n\n#ifdef AMBIENT_SH_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_SH_LIGHT_COUNT; _idx_++)\n {{\n diffuseTerm += calcAmbientSHLight(_idx_, N) * ambientSHLightColor[_idx_];\n }}\n#endif\n\n#ifdef POINT_LIGHT_COUNT\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsPoint[POINT_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfPointLights(v_WorldPosition, shadowContribsPoint);\n }\n#endif\n for(int _idx_ = 0; _idx_ < POINT_LIGHT_COUNT; _idx_++)\n {{\n\n vec3 lightPosition = pointLightPosition[_idx_];\n vec3 lc = pointLightColor[_idx_];\n float range = pointLightRange[_idx_];\n\n vec3 L = lightPosition - v_WorldPosition;\n\n float dist = length(L);\n float attenuation = lightAttenuation(dist, range);\n L /= dist;\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n\n float shadowContrib = 1.0;\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\n if(shadowEnabled)\n {\n shadowContrib = shadowContribsPoint[_idx_];\n }\n#endif\n\n vec3 li = lc * ndl * attenuation * shadowContrib;\n diffuseTerm += li;\n specularTerm += li * fresnelTerm * D_Phong(g, ndh);\n }}\n#endif\n\n#ifdef DIRECTIONAL_LIGHT_COUNT\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir);\n }\n#endif\n for(int _idx_ = 0; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++)\n {{\n\n vec3 L = -normalize(directionalLightDirection[_idx_]);\n vec3 lc = directionalLightColor[_idx_];\n\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n\n float shadowContrib = 1.0;\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n if(shadowEnabled)\n {\n shadowContrib = shadowContribsDir[_idx_];\n }\n#endif\n\n vec3 li = lc * ndl * shadowContrib;\n\n diffuseTerm += li;\n specularTerm += li * fresnelTerm * D_Phong(g, ndh);\n }}\n#endif\n\n#ifdef SPOT_LIGHT_COUNT\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsSpot[SPOT_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfSpotLights(v_WorldPosition, shadowContribsSpot);\n }\n#endif\n for(int i = 0; i < SPOT_LIGHT_COUNT; i++)\n {\n vec3 lightPosition = spotLightPosition[i];\n vec3 spotLightDirection = -normalize(spotLightDirection[i]);\n vec3 lc = spotLightColor[i];\n float range = spotLightRange[i];\n float a = spotLightUmbraAngleCosine[i];\n float b = spotLightPenumbraAngleCosine[i];\n float falloffFactor = spotLightFalloffFactor[i];\n\n vec3 L = lightPosition - v_WorldPosition;\n float dist = length(L);\n float attenuation = lightAttenuation(dist, range);\n\n L /= dist;\n float c = dot(spotLightDirection, L);\n\n float falloff;\n falloff = clamp((c - a) /( b - a), 0.0, 1.0);\n falloff = pow(falloff, falloffFactor);\n\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n\n float shadowContrib = 1.0;\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\n if (shadowEnabled)\n {\n shadowContrib = shadowContribsSpot[i];\n }\n#endif\n\n vec3 li = lc * attenuation * (1.0 - falloff) * shadowContrib * ndl;\n\n diffuseTerm += li;\n specularTerm += li * fresnelTerm * D_Phong(g, ndh);\n }\n#endif\n\n vec4 outColor = albedoColor;\n outColor.rgb *= diffuseTerm;\n\n outColor.rgb += specularTerm;\n\n\n#ifdef AMBIENT_CUBEMAP_LIGHT_COUNT\n vec3 L = reflect(-V, N);\n float rough2 = clamp(1.0 - g, 0.0, 1.0);\n float bias2 = rough2 * 5.0;\n vec2 brdfParam2 = texture2D(ambientCubemapLightBRDFLookup[0], vec2(rough2, ndv)).xy;\n vec3 envWeight2 = spec * brdfParam2.x + brdfParam2.y;\n vec3 envTexel2;\n for(int _idx_ = 0; _idx_ < AMBIENT_CUBEMAP_LIGHT_COUNT; _idx_++)\n {{\n envTexel2 = RGBMDecode(textureCubeLodEXT(ambientCubemapLightCubemap[_idx_], L, bias2), 51.5);\n outColor.rgb += ambientCubemapLightColor[_idx_] * envTexel2 * envWeight2;\n }}\n#endif\n\n#ifdef ENVIRONMENTMAP_ENABLED\n\n vec3 envWeight = g * fresnelTerm;\n vec3 L = reflect(-V, N);\n\n #ifdef PARALLAX_CORRECTED\n L = parallaxCorrect(L, v_WorldPosition, environmentBoxMin, environmentBoxMax);\n #endif\n\n #ifdef ENVIRONMENTMAP_PREFILTER\n float rough = clamp(1.0 - g, 0.0, 1.0);\n float bias = rough * maxMipmapLevel;\n vec3 envTexel = decodeHDR(textureCubeLodEXT(environmentMap, L, bias)).rgb;\n\n #ifdef BRDFLOOKUP_ENABLED\n vec2 brdfParam = texture2D(brdfLookup, vec2(rough, ndv)).xy;\n envWeight = spec * brdfParam.x + brdfParam.y;\n #endif\n\n #else\n vec3 envTexel = textureCube(environmentMap, L).xyz;\n #endif\n\n outColor.rgb += envTexel * envWeight;\n#endif\n\n float aoFactor = 1.0;\n#ifdef SSAOMAP_ENABLED\n aoFactor = min(texture2D(ssaoMap, (gl_FragCoord.xy - viewport.xy) / viewport.zw).r, aoFactor);\n#endif\n\n#ifdef AOMAP_ENABLED\n aoFactor = min(1.0 - clamp((1.0 - texture2D(aoMap, v_Texcoord2).r) * aoIntensity, 0.0, 1.0), aoFactor);\n#endif\n\n outColor.rgb *= aoFactor;\n\n vec3 lEmission = emission;\n#ifdef EMISSIVEMAP_ENABLED\n lEmission *= texture2D(emissiveMap, v_Texcoord).rgb;\n#endif\n outColor.rgb += lEmission * emissionIntensity;\n\n#ifdef GAMMA_ENCODE\n outColor.rgb = pow(outColor.rgb, vec3(1 / 2.2));\n#endif\n\n if(lineWidth > 0.)\n {\n outColor.rgb = mix(lineColor, vec3(outColor.rgb), edgeFactor(lineWidth));\n }\n\n#ifdef ALPHA_TEST\n if (outColor.a < ALPHA_TEST_THRESHOLD) {\n discard;\n }\n#endif\n\n gl_FragColor = encodeHDR(outColor);\n}\n\n@end\n"; + module.exports = "\n\n@export qtek.standard.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 worldInverseTranspose : WORLDINVERSETRANSPOSE;\nuniform mat4 world : WORLD;\n\nuniform vec2 uvRepeat : [1.0, 1.0];\nuniform vec2 uvOffset : [0.0, 0.0];\n\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\n\n#if defined(AOMAP_ENABLED)\nattribute vec2 texcoord2 : TEXCOORD_1;\n#endif\n\nattribute vec3 normal : NORMAL;\nattribute vec4 tangent : TANGENT;\n\n#ifdef VERTEX_COLOR\nattribute vec4 color : COLOR;\n#endif\n\nattribute vec3 barycentric;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\nvarying vec3 v_Barycentric;\n\n#ifdef NORMALMAP_ENABLED\nvarying vec3 v_Tangent;\nvarying vec3 v_Bitangent;\n#endif\n\n#ifdef VERTEX_COLOR\nvarying vec4 v_Color;\n#endif\n\n\n#if defined(AOMAP_ENABLED)\nvarying vec2 v_Texcoord2;\n#endif\n\nvoid main()\n{\n\n vec3 skinnedPosition = position;\n vec3 skinnedNormal = normal;\n vec3 skinnedTangent = tangent.xyz;\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n skinnedNormal = (skinMatrixWS * vec4(normal, 0.0)).xyz;\n skinnedTangent = (skinMatrixWS * vec4(tangent.xyz, 0.0)).xyz;\n#endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0);\n\n v_Texcoord = texcoord * uvRepeat + uvOffset;\n v_WorldPosition = (world * vec4(skinnedPosition, 1.0)).xyz;\n v_Barycentric = barycentric;\n\n v_Normal = normalize((worldInverseTranspose * vec4(skinnedNormal, 0.0)).xyz);\n\n#ifdef NORMALMAP_ENABLED\n v_Tangent = normalize((worldInverseTranspose * vec4(skinnedTangent, 0.0)).xyz);\n v_Bitangent = normalize(cross(v_Normal, v_Tangent) * tangent.w);\n#endif\n\n#ifdef VERTEX_COLOR\n v_Color = color;\n#endif\n\n#if defined(AOMAP_ENABLED)\n v_Texcoord2 = texcoord2;\n#endif\n}\n\n@end\n\n\n@export qtek.standard.fragment\n\n#define PI 3.14159265358979\n#define ALPHA_TEST_THRESHOLD 0.5\n\n#define GLOSS_CHANEL 0\n#define ROUGHNESS_CHANEL 0\n#define METALNESS_CHANEL 1\n\nuniform mat4 viewInverse : VIEWINVERSE;\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\n\n#ifdef NORMALMAP_ENABLED\nvarying vec3 v_Tangent;\nvarying vec3 v_Bitangent;\nuniform sampler2D normalMap;\n#endif\n\n#ifdef DIFFUSEMAP_ENABLED\nuniform sampler2D diffuseMap;\n#endif\n\n#ifdef SPECULARMAP_ENABLED\nuniform sampler2D specularMap;\n#endif\n\n#ifdef USE_ROUGHNESS\nuniform float roughness : 0.5;\n #ifdef ROUGHNESSMAP_ENABLED\nuniform sampler2D roughnessMap;\n #endif\n#else\nuniform float glossiness: 0.5;\n #ifdef GLOSSMAP_ENABLED\nuniform sampler2D glossMap;\n #endif\n#endif\n\n#ifdef METALNESSMAP_ENABLED\nuniform sampler2D metalnessMap;\n#endif\n\n#ifdef ENVIRONMENTMAP_ENABLED\nuniform samplerCube environmentMap;\n\n #ifdef PARALLAX_CORRECTED\nuniform vec3 environmentBoxMin;\nuniform vec3 environmentBoxMax;\n #endif\n\n#endif\n\n#ifdef BRDFLOOKUP_ENABLED\nuniform sampler2D brdfLookup;\n#endif\n\n#ifdef EMISSIVEMAP_ENABLED\nuniform sampler2D emissiveMap;\n#endif\n\n#ifdef SSAOMAP_ENABLED\nuniform sampler2D ssaoMap;\nuniform vec4 viewport : VIEWPORT;\n#endif\n\n#ifdef AOMAP_ENABLED\nuniform sampler2D aoMap;\nuniform float aoIntensity;\nvarying vec2 v_Texcoord2;\n#endif\n\nuniform vec3 color : [1.0, 1.0, 1.0];\nuniform float alpha : 1.0;\n\n\n#ifdef USE_METALNESS\nuniform float metalness : 0.0;\n#else\nuniform vec3 specularColor : [0.1, 0.1, 0.1];\n#endif\n\nuniform vec3 emission : [0.0, 0.0, 0.0];\n\nuniform float emissionIntensity: 1;\n\nuniform float lineWidth : 0.0;\nuniform vec3 lineColor : [0.0, 0.0, 0.0];\nvarying vec3 v_Barycentric;\n\n#ifdef ENVIRONMENTMAP_PREFILTER\nuniform float maxMipmapLevel: 5;\n#endif\n\n#ifdef AMBIENT_LIGHT_COUNT\n@import qtek.header.ambient_light\n#endif\n\n#ifdef AMBIENT_SH_LIGHT_COUNT\n@import qtek.header.ambient_sh_light\n#endif\n\n#ifdef AMBIENT_CUBEMAP_LIGHT_COUNT\n@import qtek.header.ambient_cubemap_light\n#endif\n\n#ifdef POINT_LIGHT_COUNT\n@import qtek.header.point_light\n#endif\n#ifdef DIRECTIONAL_LIGHT_COUNT\n@import qtek.header.directional_light\n#endif\n#ifdef SPOT_LIGHT_COUNT\n@import qtek.header.spot_light\n#endif\n\n@import qtek.util.calculate_attenuation\n\n@import qtek.util.edge_factor\n\n@import qtek.util.rgbm\n\n@import qtek.util.srgb\n\n@import qtek.plugin.compute_shadow_map\n\n@import qtek.util.parallax_correct\n\n\nfloat G_Smith(float g, float ndv, float ndl)\n{\n float roughness = 1.0 - g;\n float k = roughness * roughness / 2.0;\n float G1V = ndv / (ndv * (1.0 - k) + k);\n float G1L = ndl / (ndl * (1.0 - k) + k);\n return G1L * G1V;\n}\nvec3 F_Schlick(float ndv, vec3 spec) {\n return spec + (1.0 - spec) * pow(1.0 - ndv, 5.0);\n}\n\nfloat D_Phong(float g, float ndh) {\n float a = pow(8192.0, g);\n return (a + 2.0) / 8.0 * pow(ndh, a);\n}\n\nfloat D_GGX(float g, float ndh) {\n float r = 1.0 - g;\n float a = r * r;\n float tmp = ndh * ndh * (a - 1.0) + 1.0;\n return a / (PI * tmp * tmp);\n}\n\n\nvoid main()\n{\n vec4 albedoColor = vec4(color, alpha);\n vec3 eyePos = viewInverse[3].xyz;\n vec3 V = normalize(eyePos - v_WorldPosition);\n\n#ifdef DIFFUSEMAP_ENABLED\n vec4 texel = texture2D(diffuseMap, v_Texcoord);\n #ifdef SRGB_DECODE\n texel = sRGBToLinear(texel);\n #endif\n albedoColor.rgb *= texel.rgb;\n #ifdef DIFFUSEMAP_ALPHA_ALPHA\n albedoColor.a *= texel.a;\n #endif\n\n#endif\n\n\n#ifdef USE_METALNESS\n float m = metalness;\n\n #ifdef METALNESSMAP_ENABLED\n float m2 = texture2D(metalnessMap, v_Texcoord)[METALNESS_CHANEL];\n m = clamp(m2 + (m - 0.5) * 2.0, 0.0, 1.0);\n #endif\n\n vec3 baseColor = albedoColor.rgb;\n albedoColor.rgb = baseColor * (1.0 - m);\n vec3 spec = mix(vec3(0.04), baseColor, m);\n#else\n vec3 spec = specularColor;\n#endif\n\n#ifdef USE_ROUGHNESS\n float g = 1.0 - roughness;\n #ifdef ROUGHNESSMAP_ENABLED\n float g2 = 1.0 - texture2D(roughnessMap, v_Texcoord)[ROUGHNESS_CHANEL];\n g = clamp(g2 + (g - 0.5) * 2.0, 0.0, 1.0);\n #endif\n#else\n float g = glossiness;\n #ifdef GLOSSMAP_ENABLED\n float g2 = texture2D(glossMap, v_Texcoord)[GLOSS_CHANEL];\n g = clamp(g2 + (g - 0.5) * 2.0, 0.0, 1.0);\n #endif\n#endif\n\n#ifdef SPECULARMAP_ENABLED\n spec *= texture2D(specularMap, v_Texcoord).rgb;\n#endif\n\n vec3 N = v_Normal;\n#ifdef NORMALMAP_ENABLED\n if (dot(v_Tangent, v_Tangent) > 0.0) {\n vec3 normalTexel = texture2D(normalMap, v_Texcoord).xyz;\n if (dot(normalTexel, normalTexel) > 0.0) { N = normalTexel * 2.0 - 1.0;\n mat3 tbn = mat3(v_Tangent, v_Bitangent, v_Normal);\n N = normalize(tbn * N);\n }\n }\n#endif\n\n vec3 diffuseTerm = vec3(0.0, 0.0, 0.0);\n vec3 specularTerm = vec3(0.0, 0.0, 0.0);\n\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n vec3 fresnelTerm = F_Schlick(ndv, spec);\n\n#ifdef AMBIENT_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_LIGHT_COUNT; _idx_++)\n {{\n diffuseTerm += ambientLightColor[_idx_];\n }}\n#endif\n\n#ifdef AMBIENT_SH_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_SH_LIGHT_COUNT; _idx_++)\n {{\n diffuseTerm += calcAmbientSHLight(_idx_, N) * ambientSHLightColor[_idx_];\n }}\n#endif\n\n#ifdef POINT_LIGHT_COUNT\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsPoint[POINT_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfPointLights(v_WorldPosition, shadowContribsPoint);\n }\n#endif\n for(int _idx_ = 0; _idx_ < POINT_LIGHT_COUNT; _idx_++)\n {{\n\n vec3 lightPosition = pointLightPosition[_idx_];\n vec3 lc = pointLightColor[_idx_];\n float range = pointLightRange[_idx_];\n\n vec3 L = lightPosition - v_WorldPosition;\n\n float dist = length(L);\n float attenuation = lightAttenuation(dist, range);\n L /= dist;\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n\n float shadowContrib = 1.0;\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\n if(shadowEnabled)\n {\n shadowContrib = shadowContribsPoint[_idx_];\n }\n#endif\n\n vec3 li = lc * ndl * attenuation * shadowContrib;\n diffuseTerm += li;\n specularTerm += li * fresnelTerm * D_Phong(g, ndh);\n }}\n#endif\n\n#ifdef DIRECTIONAL_LIGHT_COUNT\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir);\n }\n#endif\n for(int _idx_ = 0; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++)\n {{\n\n vec3 L = -normalize(directionalLightDirection[_idx_]);\n vec3 lc = directionalLightColor[_idx_];\n\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n\n float shadowContrib = 1.0;\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n if(shadowEnabled)\n {\n shadowContrib = shadowContribsDir[_idx_];\n }\n#endif\n\n vec3 li = lc * ndl * shadowContrib;\n\n diffuseTerm += li;\n specularTerm += li * fresnelTerm * D_Phong(g, ndh);\n }}\n#endif\n\n#ifdef SPOT_LIGHT_COUNT\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsSpot[SPOT_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfSpotLights(v_WorldPosition, shadowContribsSpot);\n }\n#endif\n for(int i = 0; i < SPOT_LIGHT_COUNT; i++)\n {\n vec3 lightPosition = spotLightPosition[i];\n vec3 spotLightDirection = -normalize(spotLightDirection[i]);\n vec3 lc = spotLightColor[i];\n float range = spotLightRange[i];\n float a = spotLightUmbraAngleCosine[i];\n float b = spotLightPenumbraAngleCosine[i];\n float falloffFactor = spotLightFalloffFactor[i];\n\n vec3 L = lightPosition - v_WorldPosition;\n float dist = length(L);\n float attenuation = lightAttenuation(dist, range);\n\n L /= dist;\n float c = dot(spotLightDirection, L);\n\n float falloff;\n falloff = clamp((c - a) /( b - a), 0.0, 1.0);\n falloff = pow(falloff, falloffFactor);\n\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n\n float shadowContrib = 1.0;\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\n if (shadowEnabled)\n {\n shadowContrib = shadowContribsSpot[i];\n }\n#endif\n\n vec3 li = lc * attenuation * (1.0 - falloff) * shadowContrib * ndl;\n\n diffuseTerm += li;\n specularTerm += li * fresnelTerm * D_Phong(g, ndh);\n }\n#endif\n\n vec4 outColor = albedoColor;\n outColor.rgb *= diffuseTerm;\n\n outColor.rgb += specularTerm;\n\n\n#ifdef AMBIENT_CUBEMAP_LIGHT_COUNT\n vec3 L = reflect(-V, N);\n float rough2 = clamp(1.0 - g, 0.0, 1.0);\n float bias2 = rough2 * 5.0;\n vec2 brdfParam2 = texture2D(ambientCubemapLightBRDFLookup[0], vec2(rough2, ndv)).xy;\n vec3 envWeight2 = spec * brdfParam2.x + brdfParam2.y;\n vec3 envTexel2;\n for(int _idx_ = 0; _idx_ < AMBIENT_CUBEMAP_LIGHT_COUNT; _idx_++)\n {{\n envTexel2 = RGBMDecode(textureCubeLodEXT(ambientCubemapLightCubemap[_idx_], L, bias2), 51.5);\n outColor.rgb += ambientCubemapLightColor[_idx_] * envTexel2 * envWeight2;\n }}\n#endif\n\n#ifdef ENVIRONMENTMAP_ENABLED\n\n vec3 envWeight = g * fresnelTerm;\n vec3 L = reflect(-V, N);\n\n #ifdef PARALLAX_CORRECTED\n L = parallaxCorrect(L, v_WorldPosition, environmentBoxMin, environmentBoxMax);\n #endif\n\n #ifdef ENVIRONMENTMAP_PREFILTER\n float rough = clamp(1.0 - g, 0.0, 1.0);\n float bias = rough * maxMipmapLevel;\n vec3 envTexel = decodeHDR(textureCubeLodEXT(environmentMap, L, bias)).rgb;\n\n #ifdef BRDFLOOKUP_ENABLED\n vec2 brdfParam = texture2D(brdfLookup, vec2(rough, ndv)).xy;\n envWeight = spec * brdfParam.x + brdfParam.y;\n #endif\n\n #else\n vec3 envTexel = textureCube(environmentMap, L).xyz;\n #endif\n\n outColor.rgb += envTexel * envWeight;\n#endif\n\n float aoFactor = 1.0;\n#ifdef SSAOMAP_ENABLED\n aoFactor = min(texture2D(ssaoMap, (gl_FragCoord.xy - viewport.xy) / viewport.zw).r, aoFactor);\n#endif\n\n#ifdef AOMAP_ENABLED\n aoFactor = min(1.0 - clamp((1.0 - texture2D(aoMap, v_Texcoord2).r) * aoIntensity, 0.0, 1.0), aoFactor);\n#endif\n\n outColor.rgb *= aoFactor;\n\n vec3 lEmission = emission;\n#ifdef EMISSIVEMAP_ENABLED\n lEmission *= texture2D(emissiveMap, v_Texcoord).rgb;\n#endif\n outColor.rgb += lEmission * emissionIntensity;\n\n#ifdef GAMMA_ENCODE\n outColor.rgb = pow(outColor.rgb, vec3(1 / 2.2));\n#endif\n\n if(lineWidth > 0.)\n {\n outColor.rgb = mix(lineColor, vec3(outColor.rgb), edgeFactor(lineWidth));\n }\n\n#ifdef ALPHA_TEST\n if (outColor.a < ALPHA_TEST_THRESHOLD) {\n discard;\n }\n#endif\n\n gl_FragColor = encodeHDR(outColor);\n}\n\n@end\n"; /***/ }, @@ -28569,7 +28564,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "/**\n * http: */\n\n@export qtek.lambert.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 worldInverseTranspose : WORLDINVERSETRANSPOSE;\nuniform mat4 world : WORLD;\n\nuniform vec2 uvRepeat : [1.0, 1.0];\nuniform vec2 uvOffset : [0.0, 0.0];\n\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\nattribute vec3 normal : NORMAL;\n\nattribute vec3 barycentric;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\nvarying vec3 v_Barycentric;\n\nvoid main()\n{\n\n vec3 skinnedPosition = position;\n vec3 skinnedNormal = normal;\n\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n skinnedNormal = (skinMatrixWS * vec4(normal, 0.0)).xyz;\n#endif\n\n gl_Position = worldViewProjection * vec4( skinnedPosition, 1.0 );\n\n v_Texcoord = texcoord * uvRepeat + uvOffset;\n v_Normal = normalize( ( worldInverseTranspose * vec4(skinnedNormal, 0.0) ).xyz );\n v_WorldPosition = ( world * vec4( skinnedPosition, 1.0) ).xyz;\n\n v_Barycentric = barycentric;\n}\n\n@end\n\n\n@export qtek.lambert.fragment\n\n#define ALPHA_TEST_THRESHOLD 0.5\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\n\nuniform sampler2D diffuseMap;\nuniform sampler2D alphaMap;\n\nuniform vec3 color : [1.0, 1.0, 1.0];\nuniform vec3 emission : [0.0, 0.0, 0.0];\nuniform float alpha : 1.0;\n\nuniform float lineWidth : 0.0;\nuniform vec3 lineColor : [0.0, 0.0, 0.0];\nvarying vec3 v_Barycentric;\n\n#ifdef AMBIENT_LIGHT_COUNT\n@import qtek.header.ambient_light\n#endif\n#ifdef AMBIENT_SH_LIGHT_COUNT\n@import qtek.header.ambient_sh_light\n#endif\n#ifdef POINT_LIGHT_COUNT\n@import qtek.header.point_light\n#endif\n#ifdef DIRECTIONAL_LIGHT_COUNT\n@import qtek.header.directional_light\n#endif\n#ifdef SPOT_LIGHT_COUNT\n@import qtek.header.spot_light\n#endif\n\n@import qtek.util.calculate_attenuation\n\n@import qtek.util.edge_factor\n\n@import qtek.util.rgbm\n\n@import qtek.plugin.compute_shadow_map\n\nvoid main()\n{\n#ifdef RENDER_NORMAL\n gl_FragColor = vec4(v_Normal * 0.5 + 0.5, 1.0);\n return;\n#endif\n#ifdef RENDER_TEXCOORD\n gl_FragColor = vec4(v_Texcoord, 1.0, 1.0);\n return;\n#endif\n\n gl_FragColor = vec4(color, alpha);\n\n#ifdef DIFFUSEMAP_ENABLED\n vec4 tex = texture2D( diffuseMap, v_Texcoord );\n#ifdef SRGB_DECODE\n tex.rgb = pow(tex.rgb, vec3(2.2));\n#endif\n gl_FragColor.rgb *= tex.rgb;\n#ifdef DIFFUSEMAP_ALPHA_ALPHA\n gl_FragColor.a *= tex.a;\n#endif\n#endif\n\n vec3 diffuseColor = vec3(0.0, 0.0, 0.0);\n\n#ifdef AMBIENT_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_LIGHT_COUNT; _idx_++)\n {\n diffuseColor += ambientLightColor[_idx_];\n }\n#endif\n#ifdef AMBIENT_SH_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_SH_LIGHT_COUNT; _idx_++)\n {{\n diffuseColor += calcAmbientSHLight(_idx_, v_Normal) * ambientSHLightColor[_idx_];\n }}\n#endif\n#ifdef POINT_LIGHT_COUNT\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsPoint[POINT_LIGHT_COUNT];\n if( shadowEnabled )\n {\n computeShadowOfPointLights(v_WorldPosition, shadowContribsPoint);\n }\n#endif\n for(int i = 0; i < POINT_LIGHT_COUNT; i++)\n {\n\n vec3 lightPosition = pointLightPosition[i];\n vec3 lightColor = pointLightColor[i];\n float range = pointLightRange[i];\n\n vec3 lightDirection = lightPosition - v_WorldPosition;\n\n float dist = length(lightDirection);\n float attenuation = lightAttenuation(dist, range);\n\n lightDirection /= dist;\n\n float ndl = dot( v_Normal, lightDirection );\n\n float shadowContrib = 1.0;\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\n if( shadowEnabled )\n {\n shadowContrib = shadowContribsPoint[i];\n }\n#endif\n\n diffuseColor += lightColor * clamp(ndl, 0.0, 1.0) * attenuation * shadowContrib;\n }\n#endif\n#ifdef DIRECTIONAL_LIGHT_COUNT\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir);\n }\n#endif\n for(int i = 0; i < DIRECTIONAL_LIGHT_COUNT; i++)\n {\n vec3 lightDirection = -directionalLightDirection[i];\n vec3 lightColor = directionalLightColor[i];\n\n float ndl = dot(v_Normal, normalize(lightDirection));\n\n float shadowContrib = 1.0;\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n if( shadowEnabled )\n {\n shadowContrib = shadowContribsDir[i];\n }\n#endif\n\n diffuseColor += lightColor * clamp(ndl, 0.0, 1.0) * shadowContrib;\n }\n#endif\n\n#ifdef SPOT_LIGHT_COUNT\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsSpot[SPOT_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfSpotLights(v_WorldPosition, shadowContribsSpot);\n }\n#endif\n for(int i = 0; i < SPOT_LIGHT_COUNT; i++)\n {\n vec3 lightPosition = -spotLightPosition[i];\n vec3 spotLightDirection = -normalize( spotLightDirection[i] );\n vec3 lightColor = spotLightColor[i];\n float range = spotLightRange[i];\n float a = spotLightUmbraAngleCosine[i];\n float b = spotLightPenumbraAngleCosine[i];\n float falloffFactor = spotLightFalloffFactor[i];\n\n vec3 lightDirection = lightPosition - v_WorldPosition;\n float dist = length(lightDirection);\n float attenuation = lightAttenuation(dist, range);\n\n lightDirection /= dist;\n float c = dot(spotLightDirection, lightDirection);\n\n float falloff;\n falloff = clamp((c - a) /( b - a), 0.0, 1.0);\n falloff = pow(falloff, falloffFactor);\n\n float ndl = dot(v_Normal, lightDirection);\n ndl = clamp(ndl, 0.0, 1.0);\n\n float shadowContrib = 1.0;\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\n if( shadowEnabled )\n {\n shadowContrib = shadowContribsSpot[i];\n }\n#endif\n diffuseColor += lightColor * ndl * attenuation * (1.0-falloff) * shadowContrib;\n }\n#endif\n\n gl_FragColor.rgb *= diffuseColor;\n gl_FragColor.rgb += emission;\n if(lineWidth > 0.01)\n {\n gl_FragColor.rgb = gl_FragColor.rgb * mix(lineColor, vec3(1.0), edgeFactor(lineWidth));\n }\n\n#ifdef ALPHA_TEST\n if (gl_FragColor.a < ALPHA_TEST_THRESHOLD) {\n discard;\n }\n#endif\n\n gl_FragColor = encodeHDR(gl_FragColor);\n}\n\n@end"; + module.exports = "/**\n * http: */\n\n@export qtek.lambert.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 worldInverseTranspose : WORLDINVERSETRANSPOSE;\nuniform mat4 world : WORLD;\n\nuniform vec2 uvRepeat : [1.0, 1.0];\nuniform vec2 uvOffset : [0.0, 0.0];\n\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\nattribute vec3 normal : NORMAL;\n\nattribute vec3 barycentric;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\nvarying vec3 v_Barycentric;\n\nvoid main()\n{\n\n vec3 skinnedPosition = position;\n vec3 skinnedNormal = normal;\n\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n skinnedNormal = (skinMatrixWS * vec4(normal, 0.0)).xyz;\n#endif\n\n gl_Position = worldViewProjection * vec4( skinnedPosition, 1.0 );\n\n v_Texcoord = texcoord * uvRepeat + uvOffset;\n v_Normal = normalize( ( worldInverseTranspose * vec4(skinnedNormal, 0.0) ).xyz );\n v_WorldPosition = ( world * vec4( skinnedPosition, 1.0) ).xyz;\n\n v_Barycentric = barycentric;\n}\n\n@end\n\n\n@export qtek.lambert.fragment\n\n#define ALPHA_TEST_THRESHOLD 0.5\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\n\nuniform sampler2D diffuseMap;\nuniform sampler2D alphaMap;\n\nuniform vec3 color : [1.0, 1.0, 1.0];\nuniform vec3 emission : [0.0, 0.0, 0.0];\nuniform float alpha : 1.0;\n\nuniform float lineWidth : 0.0;\nuniform vec3 lineColor : [0.0, 0.0, 0.0];\nvarying vec3 v_Barycentric;\n\n#ifdef AMBIENT_LIGHT_COUNT\n@import qtek.header.ambient_light\n#endif\n#ifdef AMBIENT_SH_LIGHT_COUNT\n@import qtek.header.ambient_sh_light\n#endif\n#ifdef POINT_LIGHT_COUNT\n@import qtek.header.point_light\n#endif\n#ifdef DIRECTIONAL_LIGHT_COUNT\n@import qtek.header.directional_light\n#endif\n#ifdef SPOT_LIGHT_COUNT\n@import qtek.header.spot_light\n#endif\n\n@import qtek.util.calculate_attenuation\n\n@import qtek.util.edge_factor\n\n@import qtek.util.rgbm\n\n@import qtek.plugin.compute_shadow_map\n\nvoid main()\n{\n#ifdef RENDER_NORMAL\n gl_FragColor = vec4(v_Normal * 0.5 + 0.5, 1.0);\n return;\n#endif\n#ifdef RENDER_TEXCOORD\n gl_FragColor = vec4(v_Texcoord, 1.0, 1.0);\n return;\n#endif\n\n gl_FragColor = vec4(color, alpha);\n\n#ifdef DIFFUSEMAP_ENABLED\n vec4 tex = texture2D( diffuseMap, v_Texcoord );\n#ifdef SRGB_DECODE\n tex.rgb = pow(tex.rgb, vec3(2.2));\n#endif\n gl_FragColor.rgb *= tex.rgb;\n#ifdef DIFFUSEMAP_ALPHA_ALPHA\n gl_FragColor.a *= tex.a;\n#endif\n#endif\n\n vec3 diffuseColor = vec3(0.0, 0.0, 0.0);\n\n#ifdef AMBIENT_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_LIGHT_COUNT; _idx_++)\n {\n diffuseColor += ambientLightColor[_idx_];\n }\n#endif\n#ifdef AMBIENT_SH_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_SH_LIGHT_COUNT; _idx_++)\n {{\n diffuseColor += calcAmbientSHLight(_idx_, v_Normal) * ambientSHLightColor[_idx_];\n }}\n#endif\n#ifdef POINT_LIGHT_COUNT\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsPoint[POINT_LIGHT_COUNT];\n if( shadowEnabled )\n {\n computeShadowOfPointLights(v_WorldPosition, shadowContribsPoint);\n }\n#endif\n for(int i = 0; i < POINT_LIGHT_COUNT; i++)\n {\n\n vec3 lightPosition = pointLightPosition[i];\n vec3 lightColor = pointLightColor[i];\n float range = pointLightRange[i];\n\n vec3 lightDirection = lightPosition - v_WorldPosition;\n\n float dist = length(lightDirection);\n float attenuation = lightAttenuation(dist, range);\n\n lightDirection /= dist;\n\n float ndl = dot( v_Normal, lightDirection );\n\n float shadowContrib = 1.0;\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\n if( shadowEnabled )\n {\n shadowContrib = shadowContribsPoint[i];\n }\n#endif\n\n diffuseColor += lightColor * clamp(ndl, 0.0, 1.0) * attenuation * shadowContrib;\n }\n#endif\n#ifdef DIRECTIONAL_LIGHT_COUNT\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir);\n }\n#endif\n for(int i = 0; i < DIRECTIONAL_LIGHT_COUNT; i++)\n {\n vec3 lightDirection = -directionalLightDirection[i];\n vec3 lightColor = directionalLightColor[i];\n\n float ndl = dot(v_Normal, normalize(lightDirection));\n\n float shadowContrib = 1.0;\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n if( shadowEnabled )\n {\n shadowContrib = shadowContribsDir[i];\n }\n#endif\n\n diffuseColor += lightColor * clamp(ndl, 0.0, 1.0) * shadowContrib;\n }\n#endif\n\n#ifdef SPOT_LIGHT_COUNT\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsSpot[SPOT_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfSpotLights(v_WorldPosition, shadowContribsSpot);\n }\n#endif\n for(int i = 0; i < SPOT_LIGHT_COUNT; i++)\n {\n vec3 lightPosition = -spotLightPosition[i];\n vec3 spotLightDirection = -normalize( spotLightDirection[i] );\n vec3 lightColor = spotLightColor[i];\n float range = spotLightRange[i];\n float a = spotLightUmbraAngleCosine[i];\n float b = spotLightPenumbraAngleCosine[i];\n float falloffFactor = spotLightFalloffFactor[i];\n\n vec3 lightDirection = lightPosition - v_WorldPosition;\n float dist = length(lightDirection);\n float attenuation = lightAttenuation(dist, range);\n\n lightDirection /= dist;\n float c = dot(spotLightDirection, lightDirection);\n\n float falloff;\n falloff = clamp((c - a) /( b - a), 0.0, 1.0);\n falloff = pow(falloff, falloffFactor);\n\n float ndl = dot(v_Normal, lightDirection);\n ndl = clamp(ndl, 0.0, 1.0);\n\n float shadowContrib = 1.0;\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\n if( shadowEnabled )\n {\n shadowContrib = shadowContribsSpot[i];\n }\n#endif\n diffuseColor += lightColor * ndl * attenuation * (1.0-falloff) * shadowContrib;\n }\n#endif\n\n gl_FragColor.rgb *= diffuseColor;\n gl_FragColor.rgb += emission;\n if(lineWidth > 0.01)\n {\n gl_FragColor.rgb = gl_FragColor.rgb * mix(lineColor, vec3(1.0), edgeFactor(lineWidth));\n }\n\n#ifdef ALPHA_TEST\n if (gl_FragColor.a < ALPHA_TEST_THRESHOLD) {\n discard;\n }\n#endif\n\n gl_FragColor = encodeHDR(gl_FragColor);\n}\n\n@end"; /***/ }, @@ -28577,7 +28572,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.wireframe.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 world : WORLD;\n\nattribute vec3 position : POSITION;\nattribute vec3 barycentric;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec3 v_Barycentric;\n\nvoid main()\n{\n\n vec3 skinnedPosition = position;\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n#endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0 );\n\n v_Barycentric = barycentric;\n}\n\n@end\n\n\n@export qtek.wireframe.fragment\n\nuniform vec3 color : [0.0, 0.0, 0.0];\n\nuniform float alpha : 1.0;\nuniform float lineWidth : 1.0;\n\nvarying vec3 v_Barycentric;\n\n\n@import qtek.util.edge_factor\n\nvoid main()\n{\n\n gl_FragColor.rgb = color;\n gl_FragColor.a = (1.0-edgeFactor(lineWidth)) * alpha;\n}\n\n@end"; + module.exports = "@export qtek.wireframe.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 world : WORLD;\n\nattribute vec3 position : POSITION;\nattribute vec3 barycentric;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec3 v_Barycentric;\n\nvoid main()\n{\n\n vec3 skinnedPosition = position;\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n#endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0 );\n\n v_Barycentric = barycentric;\n}\n\n@end\n\n\n@export qtek.wireframe.fragment\n\nuniform vec3 color : [0.0, 0.0, 0.0];\n\nuniform float alpha : 1.0;\nuniform float lineWidth : 1.0;\n\nvarying vec3 v_Barycentric;\n\n\n@import qtek.util.edge_factor\n\nvoid main()\n{\n\n gl_FragColor.rgb = color;\n gl_FragColor.a = (1.0-edgeFactor(lineWidth)) * alpha;\n}\n\n@end"; /***/ }, @@ -28585,7 +28580,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.compositor.coloradjust\n\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float brightness : 0.0;\nuniform float contrast : 1.0;\nuniform float exposure : 0.0;\nuniform float gamma : 1.0;\nuniform float saturation : 1.0;\n\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\n\nvoid main()\n{\n vec4 tex = texture2D( texture, v_Texcoord);\n\n vec3 color = clamp(tex.rgb + vec3(brightness), 0.0, 1.0);\n color = clamp( (color-vec3(0.5))*contrast+vec3(0.5), 0.0, 1.0);\n color = clamp( color * pow(2.0, exposure), 0.0, 1.0);\n color = clamp( pow(color, vec3(gamma)), 0.0, 1.0);\n float luminance = dot( color, w );\n color = mix(vec3(luminance), color, saturation);\n\n gl_FragColor = vec4(color, tex.a);\n}\n\n@end\n\n@export qtek.compositor.brightness\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float brightness : 0.0;\n\nvoid main()\n{\n vec4 tex = texture2D( texture, v_Texcoord);\n vec3 color = tex.rgb + vec3(brightness);\n gl_FragColor = vec4(color, tex.a);\n}\n@end\n\n@export qtek.compositor.contrast\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float contrast : 1.0;\n\nvoid main()\n{\n vec4 tex = texture2D( texture, v_Texcoord);\n vec3 color = (tex.rgb-vec3(0.5))*contrast+vec3(0.5);\n gl_FragColor = vec4(color, tex.a);\n}\n@end\n\n@export qtek.compositor.exposure\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float exposure : 0.0;\n\nvoid main()\n{\n vec4 tex = texture2D(texture, v_Texcoord);\n vec3 color = tex.rgb * pow(2.0, exposure);\n gl_FragColor = vec4(color, tex.a);\n}\n@end\n\n@export qtek.compositor.gamma\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float gamma : 1.0;\n\nvoid main()\n{\n vec4 tex = texture2D(texture, v_Texcoord);\n vec3 color = pow(tex.rgb, vec3(gamma));\n gl_FragColor = vec4(color, tex.a);\n}\n@end\n\n@export qtek.compositor.saturation\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float saturation : 1.0;\n\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\n\nvoid main()\n{\n vec4 tex = texture2D(texture, v_Texcoord);\n vec3 color = tex.rgb;\n float luminance = dot(color, w);\n color = mix(vec3(luminance), color, saturation);\n gl_FragColor = vec4(color, tex.a);\n}\n@end"; + module.exports = "@export qtek.compositor.coloradjust\n\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float brightness : 0.0;\nuniform float contrast : 1.0;\nuniform float exposure : 0.0;\nuniform float gamma : 1.0;\nuniform float saturation : 1.0;\n\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\n\nvoid main()\n{\n vec4 tex = texture2D( texture, v_Texcoord);\n\n vec3 color = clamp(tex.rgb + vec3(brightness), 0.0, 1.0);\n color = clamp( (color-vec3(0.5))*contrast+vec3(0.5), 0.0, 1.0);\n color = clamp( color * pow(2.0, exposure), 0.0, 1.0);\n color = clamp( pow(color, vec3(gamma)), 0.0, 1.0);\n float luminance = dot( color, w );\n color = mix(vec3(luminance), color, saturation);\n\n gl_FragColor = vec4(color, tex.a);\n}\n\n@end\n\n@export qtek.compositor.brightness\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float brightness : 0.0;\n\nvoid main()\n{\n vec4 tex = texture2D( texture, v_Texcoord);\n vec3 color = tex.rgb + vec3(brightness);\n gl_FragColor = vec4(color, tex.a);\n}\n@end\n\n@export qtek.compositor.contrast\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float contrast : 1.0;\n\nvoid main()\n{\n vec4 tex = texture2D( texture, v_Texcoord);\n vec3 color = (tex.rgb-vec3(0.5))*contrast+vec3(0.5);\n gl_FragColor = vec4(color, tex.a);\n}\n@end\n\n@export qtek.compositor.exposure\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float exposure : 0.0;\n\nvoid main()\n{\n vec4 tex = texture2D(texture, v_Texcoord);\n vec3 color = tex.rgb * pow(2.0, exposure);\n gl_FragColor = vec4(color, tex.a);\n}\n@end\n\n@export qtek.compositor.gamma\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float gamma : 1.0;\n\nvoid main()\n{\n vec4 tex = texture2D(texture, v_Texcoord);\n vec3 color = pow(tex.rgb, vec3(gamma));\n gl_FragColor = vec4(color, tex.a);\n}\n@end\n\n@export qtek.compositor.saturation\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float saturation : 1.0;\n\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\n\nvoid main()\n{\n vec4 tex = texture2D(texture, v_Texcoord);\n vec3 color = tex.rgb;\n float luminance = dot(color, w);\n color = mix(vec3(luminance), color, saturation);\n gl_FragColor = vec4(color, tex.a);\n}\n@end"; /***/ }, @@ -28593,7 +28588,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.compositor.kernel.gaussian_9\nfloat gaussianKernel[9];\ngaussianKernel[0] = 0.07;\ngaussianKernel[1] = 0.09;\ngaussianKernel[2] = 0.12;\ngaussianKernel[3] = 0.14;\ngaussianKernel[4] = 0.16;\ngaussianKernel[5] = 0.14;\ngaussianKernel[6] = 0.12;\ngaussianKernel[7] = 0.09;\ngaussianKernel[8] = 0.07;\n@end\n\n@export qtek.compositor.kernel.gaussian_13\n\nfloat gaussianKernel[13];\n\ngaussianKernel[0] = 0.02;\ngaussianKernel[1] = 0.03;\ngaussianKernel[2] = 0.06;\ngaussianKernel[3] = 0.08;\ngaussianKernel[4] = 0.11;\ngaussianKernel[5] = 0.13;\ngaussianKernel[6] = 0.14;\ngaussianKernel[7] = 0.13;\ngaussianKernel[8] = 0.11;\ngaussianKernel[9] = 0.08;\ngaussianKernel[10] = 0.06;\ngaussianKernel[11] = 0.03;\ngaussianKernel[12] = 0.02;\n\n@end\n\n\n@export qtek.compositor.gaussian_blur\n\nuniform sampler2D texture; varying vec2 v_Texcoord;\n\nuniform float blurSize : 2.0;\nuniform vec2 textureSize : [512.0, 512.0];\nuniform float blurDir : 0.0;\n\n@import qtek.util.rgbm\n@import qtek.util.clamp_sample\n\nvoid main (void)\n{\n @import qtek.compositor.kernel.gaussian_9\n\n vec2 off = blurSize / textureSize;\n off *= vec2(1.0 - blurDir, blurDir);\n\n vec4 sum = vec4(0.0);\n float weightAll = 0.0;\n\n for (int i = 0; i < 9; i++) {\n float w = gaussianKernel[i];\n sum += decodeHDR(clampSample(texture, v_Texcoord + float(i - 4) * off)) * w;\n weightAll += w;\n }\n gl_FragColor = encodeHDR(sum / weightAll);\n}\n\n@end\n\n@export qtek.compositor.box_blur\n\nuniform sampler2D texture;\nvarying vec2 v_Texcoord;\n\nuniform float blurSize : 3.0;\nuniform vec2 textureSize : [512.0, 512.0];\n\n@import qtek.util.rgbm\n@import qtek.util.clamp_sample\n\nvoid main(void)\n{\n\n vec4 tex = decodeHDR(texture2D(texture, v_Texcoord));\n vec2 offset = blurSize / textureSize;\n\n tex += decodeHDR(clampSample(texture, v_Texcoord + vec2(offset.x, 0.0) ));\n tex += decodeHDR(clampSample(texture, v_Texcoord + vec2(offset.x, offset.y) ));\n tex += decodeHDR(clampSample(texture, v_Texcoord + vec2(-offset.x, offset.y) ));\n tex += decodeHDR(clampSample(texture, v_Texcoord + vec2(0.0, offset.y) ));\n tex += decodeHDR(clampSample(texture, v_Texcoord + vec2(-offset.x, 0.0) ));\n tex += decodeHDR(clampSample(texture, v_Texcoord + vec2(-offset.x, -offset.y) ));\n tex += decodeHDR(clampSample(texture, v_Texcoord + vec2(offset.x, -offset.y) ));\n tex += decodeHDR(clampSample(texture, v_Texcoord + vec2(0.0, -offset.y) ));\n\n tex /= 9.0;\n\n \n gl_FragColor = encodeHDR(tex);\n}\n\n@end"; + module.exports = "@export qtek.compositor.kernel.gaussian_9\nfloat gaussianKernel[9];\ngaussianKernel[0] = 0.07;\ngaussianKernel[1] = 0.09;\ngaussianKernel[2] = 0.12;\ngaussianKernel[3] = 0.14;\ngaussianKernel[4] = 0.16;\ngaussianKernel[5] = 0.14;\ngaussianKernel[6] = 0.12;\ngaussianKernel[7] = 0.09;\ngaussianKernel[8] = 0.07;\n@end\n\n@export qtek.compositor.kernel.gaussian_13\n\nfloat gaussianKernel[13];\n\ngaussianKernel[0] = 0.02;\ngaussianKernel[1] = 0.03;\ngaussianKernel[2] = 0.06;\ngaussianKernel[3] = 0.08;\ngaussianKernel[4] = 0.11;\ngaussianKernel[5] = 0.13;\ngaussianKernel[6] = 0.14;\ngaussianKernel[7] = 0.13;\ngaussianKernel[8] = 0.11;\ngaussianKernel[9] = 0.08;\ngaussianKernel[10] = 0.06;\ngaussianKernel[11] = 0.03;\ngaussianKernel[12] = 0.02;\n\n@end\n\n\n@export qtek.compositor.gaussian_blur\n\nuniform sampler2D texture; varying vec2 v_Texcoord;\n\nuniform float blurSize : 2.0;\nuniform vec2 textureSize : [512.0, 512.0];\nuniform float blurDir : 0.0;\n\n@import qtek.util.rgbm\n@import qtek.util.clamp_sample\n\nvoid main (void)\n{\n @import qtek.compositor.kernel.gaussian_9\n\n vec2 off = blurSize / textureSize;\n off *= vec2(1.0 - blurDir, blurDir);\n\n vec4 sum = vec4(0.0);\n float weightAll = 0.0;\n\n for (int i = 0; i < 9; i++) {\n float w = gaussianKernel[i];\n sum += decodeHDR(clampSample(texture, v_Texcoord + float(i - 4) * off)) * w;\n weightAll += w;\n }\n gl_FragColor = encodeHDR(sum / weightAll);\n}\n\n@end"; /***/ }, @@ -28601,7 +28596,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.compositor.hdr.log_lum\n\nvarying vec2 v_Texcoord;\n\nuniform sampler2D texture;\n\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec4 tex = decodeHDR(texture2D(texture, v_Texcoord));\n float luminance = dot(tex.rgb, w);\n luminance = log(luminance + 0.001);\n\n gl_FragColor = encodeHDR(vec4(vec3(luminance), 1.0));\n}\n\n@end\n\n@export qtek.compositor.hdr.lum_adaption\nvarying vec2 v_Texcoord;\n\nuniform sampler2D adaptedLum;\nuniform sampler2D currentLum;\n\nuniform float frameTime : 0.02;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n float fAdaptedLum = decodeHDR(texture2D(adaptedLum, vec2(0.5, 0.5))).r;\n float fCurrentLum = exp(encodeHDR(texture2D(currentLum, vec2(0.5, 0.5))).r);\n\n fAdaptedLum += (fCurrentLum - fAdaptedLum) * (1.0 - pow(0.98, 30.0 * frameTime));\n gl_FragColor = encodeHDR(vec4(vec3(fAdaptedLum), 1.0));\n}\n@end\n\n@export qtek.compositor.lum\n\nvarying vec2 v_Texcoord;\n\nuniform sampler2D texture;\n\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\n\nvoid main()\n{\n vec4 tex = texture2D( texture, v_Texcoord );\n float luminance = dot(tex.rgb, w);\n\n gl_FragColor = vec4(vec3(luminance), 1.0);\n}\n\n@end"; + module.exports = "@export qtek.compositor.hdr.log_lum\n\nvarying vec2 v_Texcoord;\n\nuniform sampler2D texture;\n\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec4 tex = decodeHDR(texture2D(texture, v_Texcoord));\n float luminance = dot(tex.rgb, w);\n luminance = log(luminance + 0.001);\n\n gl_FragColor = encodeHDR(vec4(vec3(luminance), 1.0));\n}\n\n@end\n\n@export qtek.compositor.hdr.lum_adaption\nvarying vec2 v_Texcoord;\n\nuniform sampler2D adaptedLum;\nuniform sampler2D currentLum;\n\nuniform float frameTime : 0.02;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n float fAdaptedLum = decodeHDR(texture2D(adaptedLum, vec2(0.5, 0.5))).r;\n float fCurrentLum = exp(encodeHDR(texture2D(currentLum, vec2(0.5, 0.5))).r);\n\n fAdaptedLum += (fCurrentLum - fAdaptedLum) * (1.0 - pow(0.98, 30.0 * frameTime));\n gl_FragColor = encodeHDR(vec4(vec3(fAdaptedLum), 1.0));\n}\n@end\n\n@export qtek.compositor.lum\n\nvarying vec2 v_Texcoord;\n\nuniform sampler2D texture;\n\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\n\nvoid main()\n{\n vec4 tex = texture2D( texture, v_Texcoord );\n float luminance = dot(tex.rgb, w);\n\n gl_FragColor = vec4(vec3(luminance), 1.0);\n}\n\n@end"; /***/ }, @@ -28609,7 +28604,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "\n@export qtek.compositor.lut\n\nvarying vec2 v_Texcoord;\n\nuniform sampler2D texture;\nuniform sampler2D lookup;\n\nvoid main()\n{\n\n vec4 tex = texture2D(texture, v_Texcoord);\n\n float blueColor = tex.b * 63.0;\n\n vec2 quad1;\n quad1.y = floor(floor(blueColor) / 8.0);\n quad1.x = floor(blueColor) - (quad1.y * 8.0);\n\n vec2 quad2;\n quad2.y = floor(ceil(blueColor) / 8.0);\n quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n\n vec2 texPos1;\n texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.r);\n texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.g);\n\n vec2 texPos2;\n texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.r);\n texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.g);\n\n vec4 newColor1 = texture2D(lookup, texPos1);\n vec4 newColor2 = texture2D(lookup, texPos2);\n\n vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n gl_FragColor = vec4(newColor.rgb, tex.w);\n}\n\n@end"; + module.exports = "\n@export qtek.compositor.lut\n\nvarying vec2 v_Texcoord;\n\nuniform sampler2D texture;\nuniform sampler2D lookup;\n\nvoid main()\n{\n\n vec4 tex = texture2D(texture, v_Texcoord);\n\n float blueColor = tex.b * 63.0;\n\n vec2 quad1;\n quad1.y = floor(floor(blueColor) / 8.0);\n quad1.x = floor(blueColor) - (quad1.y * 8.0);\n\n vec2 quad2;\n quad2.y = floor(ceil(blueColor) / 8.0);\n quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n\n vec2 texPos1;\n texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.r);\n texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.g);\n\n vec2 texPos2;\n texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.r);\n texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.g);\n\n vec4 newColor1 = texture2D(lookup, texPos1);\n vec4 newColor2 = texture2D(lookup, texPos2);\n\n vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n gl_FragColor = vec4(newColor.rgb, tex.w);\n}\n\n@end"; /***/ }, @@ -28617,7 +28612,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.compositor.vignette\n\n#define OUTPUT_ALPHA\n\nvarying vec2 v_Texcoord;\n\nuniform sampler2D texture;\n\nuniform float darkness: 1;\nuniform float offset: 1;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec4 texel = decodeHDR(texture2D(texture, v_Texcoord));\n\n gl_FragColor.rgb = texel.rgb;\n\n vec2 uv = (v_Texcoord - vec2(0.5)) * vec2(offset);\n\n gl_FragColor = encodeHDR(vec4(mix(texel.rgb, vec3(1.0 - darkness), dot(uv, uv)), texel.a));\n}\n\n@end"; + module.exports = "@export qtek.compositor.vignette\n\n#define OUTPUT_ALPHA\n\nvarying vec2 v_Texcoord;\n\nuniform sampler2D texture;\n\nuniform float darkness: 1;\nuniform float offset: 1;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec4 texel = decodeHDR(texture2D(texture, v_Texcoord));\n\n gl_FragColor.rgb = texel.rgb;\n\n vec2 uv = (v_Texcoord - vec2(0.5)) * vec2(offset);\n\n gl_FragColor = encodeHDR(vec4(mix(texel.rgb, vec3(1.0 - darkness), dot(uv, uv)), texel.a));\n}\n\n@end"; /***/ }, @@ -28625,7 +28620,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.compositor.output\n\n#define OUTPUT_ALPHA\n\nvarying vec2 v_Texcoord;\n\nuniform sampler2D texture;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec4 tex = decodeHDR(texture2D(texture, v_Texcoord));\n\n gl_FragColor.rgb = tex.rgb;\n\n#ifdef OUTPUT_ALPHA\n gl_FragColor.a = tex.a;\n#else\n gl_FragColor.a = 1.0;\n#endif\n\n gl_FragColor = encodeHDR(gl_FragColor);\n\n #ifdef PREMULTIPLY_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif\n}\n\n@end"; + module.exports = "@export qtek.compositor.output\n\n#define OUTPUT_ALPHA\n\nvarying vec2 v_Texcoord;\n\nuniform sampler2D texture;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec4 tex = decodeHDR(texture2D(texture, v_Texcoord));\n\n gl_FragColor.rgb = tex.rgb;\n\n#ifdef OUTPUT_ALPHA\n gl_FragColor.a = tex.a;\n#else\n gl_FragColor.a = 1.0;\n#endif\n\n gl_FragColor = encodeHDR(gl_FragColor);\n\n #ifdef PREMULTIPLY_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif\n}\n\n@end"; /***/ }, @@ -28633,7 +28628,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.compositor.bright\n\nuniform sampler2D texture;\n\nuniform float threshold : 1;\nuniform float scale : 1.0;\n\nuniform vec2 textureSize: [512, 512];\n\nvarying vec2 v_Texcoord;\n\nconst vec3 lumWeight = vec3(0.2125, 0.7154, 0.0721);\n\n@import qtek.util.rgbm\n\n\nvec4 median(vec4 a, vec4 b, vec4 c)\n{\n return a + b + c - min(min(a, b), c) - max(max(a, b), c);\n}\n\nvoid main()\n{\n vec4 texel = decodeHDR(texture2D(texture, v_Texcoord));\n\n#ifdef ANTI_FLICKER\n vec3 d = 1.0 / textureSize.xyx * vec3(1.0, 1.0, 0.0);\n\n vec4 s1 = decodeHDR(texture2D(texture, v_Texcoord - d.xz));\n vec4 s2 = decodeHDR(texture2D(texture, v_Texcoord + d.xz));\n vec4 s3 = decodeHDR(texture2D(texture, v_Texcoord - d.zy));\n vec4 s4 = decodeHDR(texture2D(texture, v_Texcoord + d.zy));\n texel = median(median(texel, s1, s2), s3, s4);\n\n#endif\n\n float lum = dot(texel.rgb, lumWeight);\n vec4 color;\n if (lum > threshold)\n {\n color = vec4(texel.rgb * scale, texel.a);\n }\n else\n {\n color = vec4(vec3(0.0), 1.0);\n }\n\n gl_FragColor = encodeHDR(color);\n}\n@end\n"; + module.exports = "@export qtek.compositor.bright\n\nuniform sampler2D texture;\n\nuniform float threshold : 1;\nuniform float scale : 1.0;\n\nuniform vec2 textureSize: [512, 512];\n\nvarying vec2 v_Texcoord;\n\nconst vec3 lumWeight = vec3(0.2125, 0.7154, 0.0721);\n\n@import qtek.util.rgbm\n\n\nvec4 median(vec4 a, vec4 b, vec4 c)\n{\n return a + b + c - min(min(a, b), c) - max(max(a, b), c);\n}\n\nvoid main()\n{\n vec4 texel = decodeHDR(texture2D(texture, v_Texcoord));\n\n#ifdef ANTI_FLICKER\n vec3 d = 1.0 / textureSize.xyx * vec3(1.0, 1.0, 0.0);\n\n vec4 s1 = decodeHDR(texture2D(texture, v_Texcoord - d.xz));\n vec4 s2 = decodeHDR(texture2D(texture, v_Texcoord + d.xz));\n vec4 s3 = decodeHDR(texture2D(texture, v_Texcoord - d.zy));\n vec4 s4 = decodeHDR(texture2D(texture, v_Texcoord + d.zy));\n texel = median(median(texel, s1, s2), s3, s4);\n\n#endif\n\n float lum = dot(texel.rgb, lumWeight);\n vec4 color;\n if (lum > threshold)\n {\n color = vec4(texel.rgb * scale, texel.a);\n }\n else\n {\n color = vec4(vec3(0.0), texel.a);\n }\n\n gl_FragColor = encodeHDR(color);\n}\n@end\n"; /***/ }, @@ -28641,7 +28636,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.compositor.downsample\n\nuniform sampler2D texture;\nuniform vec2 textureSize : [512, 512];\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\nfloat brightness(vec3 c)\n{\n return max(max(c.r, c.g), c.b);\n}\n\n@import qtek.util.clamp_sample\n\nvoid main()\n{\n vec4 d = vec4(-1.0, -1.0, 1.0, 1.0) / textureSize.xyxy;\n\n#ifdef ANTI_FLICKER\n vec3 s1 = decodeHDR(clampSample(texture, v_Texcoord + d.xy)).rgb;\n vec3 s2 = decodeHDR(clampSample(texture, v_Texcoord + d.zy)).rgb;\n vec3 s3 = decodeHDR(clampSample(texture, v_Texcoord + d.xw)).rgb;\n vec3 s4 = decodeHDR(clampSample(texture, v_Texcoord + d.zw)).rgb;\n\n float s1w = 1.0 / (brightness(s1) + 1.0);\n float s2w = 1.0 / (brightness(s2) + 1.0);\n float s3w = 1.0 / (brightness(s3) + 1.0);\n float s4w = 1.0 / (brightness(s4) + 1.0);\n float oneDivideSum = 1.0 / (s1w + s2w + s3w + s4w);\n\n vec4 color = vec4(\n (s1 * s1w + s2 * s2w + s3 * s3w + s4 * s4w) * oneDivideSum,\n 1.0\n );\n#else\n vec4 color = decodeHDR(clampSample(texture, v_Texcoord + d.xy));\n color += decodeHDR(clampSample(texture, v_Texcoord + d.zy));\n color += decodeHDR(clampSample(texture, v_Texcoord + d.xw));\n color += decodeHDR(clampSample(texture, v_Texcoord + d.zw));\n color *= 0.25;\n#endif\n\n gl_FragColor = encodeHDR(color);\n}\n\n@end"; + module.exports = "@export qtek.compositor.downsample\n\nuniform sampler2D texture;\nuniform vec2 textureSize : [512, 512];\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\nfloat brightness(vec3 c)\n{\n return max(max(c.r, c.g), c.b);\n}\n\n@import qtek.util.clamp_sample\n\nvoid main()\n{\n vec4 d = vec4(-1.0, -1.0, 1.0, 1.0) / textureSize.xyxy;\n\n#ifdef ANTI_FLICKER\n vec3 s1 = decodeHDR(clampSample(texture, v_Texcoord + d.xy)).rgb;\n vec3 s2 = decodeHDR(clampSample(texture, v_Texcoord + d.zy)).rgb;\n vec3 s3 = decodeHDR(clampSample(texture, v_Texcoord + d.xw)).rgb;\n vec3 s4 = decodeHDR(clampSample(texture, v_Texcoord + d.zw)).rgb;\n\n float s1w = 1.0 / (brightness(s1) + 1.0);\n float s2w = 1.0 / (brightness(s2) + 1.0);\n float s3w = 1.0 / (brightness(s3) + 1.0);\n float s4w = 1.0 / (brightness(s4) + 1.0);\n float oneDivideSum = 1.0 / (s1w + s2w + s3w + s4w);\n\n vec4 color = vec4(\n (s1 * s1w + s2 * s2w + s3 * s3w + s4 * s4w) * oneDivideSum,\n 1.0\n );\n#else\n vec4 color = decodeHDR(clampSample(texture, v_Texcoord + d.xy));\n color += decodeHDR(clampSample(texture, v_Texcoord + d.zy));\n color += decodeHDR(clampSample(texture, v_Texcoord + d.xw));\n color += decodeHDR(clampSample(texture, v_Texcoord + d.zw));\n color *= 0.25;\n#endif\n\n gl_FragColor = encodeHDR(color);\n}\n\n@end"; /***/ }, @@ -28649,7 +28644,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "\n@export qtek.compositor.upsample\n\n#define HIGH_QUALITY\n\nuniform sampler2D texture;\nuniform vec2 textureSize : [512, 512];\n\nuniform float sampleScale: 0.5;\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n\n@import qtek.util.clamp_sample\n\nvoid main()\n{\n\n#ifdef HIGH_QUALITY\n vec4 d = vec4(1.0, 1.0, -1.0, 0.0) / textureSize.xyxy * sampleScale;\n\n vec4 s;\n s = decodeHDR(clampSample(texture, v_Texcoord - d.xy));\n s += decodeHDR(clampSample(texture, v_Texcoord - d.wy)) * 2.0;\n s += decodeHDR(clampSample(texture, v_Texcoord - d.zy));\n\n s += decodeHDR(clampSample(texture, v_Texcoord + d.zw)) * 2.0;\n s += decodeHDR(clampSample(texture, v_Texcoord )) * 4.0;\n s += decodeHDR(clampSample(texture, v_Texcoord + d.xw)) * 2.0;\n\n s += decodeHDR(clampSample(texture, v_Texcoord + d.zy));\n s += decodeHDR(clampSample(texture, v_Texcoord + d.wy)) * 2.0;\n s += decodeHDR(clampSample(texture, v_Texcoord + d.xy));\n\n gl_FragColor = encodeHDR(s / 16.0);\n#else\n vec4 d = vec4(-1.0, -1.0, +1.0, +1.0) / textureSize.xyxy;\n\n vec4 s;\n s = decodeHDR(clampSample(texture, v_Texcoord + d.xy));\n s += decodeHDR(clampSample(texture, v_Texcoord + d.zy));\n s += decodeHDR(clampSample(texture, v_Texcoord + d.xw));\n s += decodeHDR(clampSample(texture, v_Texcoord + d.zw));\n\n gl_FragColor = encodeHDR(s / 4.0);\n#endif\n}\n\n@end"; + module.exports = "\n@export qtek.compositor.upsample\n\n#define HIGH_QUALITY\n\nuniform sampler2D texture;\nuniform vec2 textureSize : [512, 512];\n\nuniform float sampleScale: 0.5;\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n\n@import qtek.util.clamp_sample\n\nvoid main()\n{\n\n#ifdef HIGH_QUALITY\n vec4 d = vec4(1.0, 1.0, -1.0, 0.0) / textureSize.xyxy * sampleScale;\n\n vec4 s;\n s = decodeHDR(clampSample(texture, v_Texcoord - d.xy));\n s += decodeHDR(clampSample(texture, v_Texcoord - d.wy)) * 2.0;\n s += decodeHDR(clampSample(texture, v_Texcoord - d.zy));\n\n s += decodeHDR(clampSample(texture, v_Texcoord + d.zw)) * 2.0;\n s += decodeHDR(clampSample(texture, v_Texcoord )) * 4.0;\n s += decodeHDR(clampSample(texture, v_Texcoord + d.xw)) * 2.0;\n\n s += decodeHDR(clampSample(texture, v_Texcoord + d.zy));\n s += decodeHDR(clampSample(texture, v_Texcoord + d.wy)) * 2.0;\n s += decodeHDR(clampSample(texture, v_Texcoord + d.xy));\n\n gl_FragColor = encodeHDR(s / 16.0);\n#else\n vec4 d = vec4(-1.0, -1.0, +1.0, +1.0) / textureSize.xyxy;\n\n vec4 s;\n s = decodeHDR(clampSample(texture, v_Texcoord + d.xy));\n s += decodeHDR(clampSample(texture, v_Texcoord + d.zy));\n s += decodeHDR(clampSample(texture, v_Texcoord + d.xw));\n s += decodeHDR(clampSample(texture, v_Texcoord + d.zw));\n\n gl_FragColor = encodeHDR(s / 4.0);\n#endif\n}\n\n@end"; /***/ }, @@ -28657,7 +28652,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.compositor.hdr.composite\n\nuniform sampler2D texture;\n#ifdef BLOOM_ENABLED\nuniform sampler2D bloom;\n#endif\n#ifdef LENSFLARE_ENABLED\nuniform sampler2D lensflare;\nuniform sampler2D lensdirt;\n#endif\n\n#ifdef LUM_ENABLED\nuniform sampler2D lum;\n#endif\n\n#ifdef LUT_ENABLED\nuniform sampler2D lut;\n#endif\n\n#ifdef COLOR_CORRECTION\nuniform float brightness : 0.0;\nuniform float contrast : 1.0;\nuniform float saturation : 1.0;\n#endif\n\n#ifdef VIGNETTE\nuniform float vignetteDarkness: 1.0;\nuniform float vignetteOffset: 1.0;\n#endif\n\nuniform float exposure : 1.0;\nuniform float bloomIntensity : 0.25;\nuniform float lensflareIntensity : 1;\n\nvarying vec2 v_Texcoord;\n\nconst vec3 whiteScale = vec3(11.2);\n\n@import qtek.util.srgb\n\nvec3 uncharted2ToneMap(vec3 x)\n{\n const float A = 0.22; const float B = 0.30; const float C = 0.10; const float D = 0.20; const float E = 0.01; const float F = 0.30; \n return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;\n}\n\nvec3 filmicToneMap(vec3 color)\n{\n vec3 x = max(vec3(0.0), color - 0.004);\n return (x*(6.2*x+0.5))/(x*(6.2*x+1.7)+0.06);\n}\n\nvec3 ACESToneMapping(vec3 color)\n{\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\n\nfloat eyeAdaption(float fLum)\n{\n return mix(0.2, fLum, 0.5);\n}\n\n#ifdef LUT_ENABLED\nvec3 lutTransform(vec3 color) {\n float blueColor = color.b * 63.0;\n\n vec2 quad1;\n quad1.y = floor(floor(blueColor) / 8.0);\n quad1.x = floor(blueColor) - (quad1.y * 8.0);\n\n vec2 quad2;\n quad2.y = floor(ceil(blueColor) / 8.0);\n quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n\n vec2 texPos1;\n texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r);\n texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g);\n\n vec2 texPos2;\n texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r);\n texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g);\n\n vec4 newColor1 = texture2D(lut, texPos1);\n vec4 newColor2 = texture2D(lut, texPos2);\n\n vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n return newColor.rgb;\n}\n#endif\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec4 texel = vec4(0.0);\n#ifdef TEXTURE_ENABLED\n texel += decodeHDR(texture2D(texture, v_Texcoord));\n#endif\n\n#ifdef BLOOM_ENABLED\n vec4 bloomTexel = decodeHDR(texture2D(bloom, v_Texcoord));\n texel.rgb += bloomTexel.rgb * bloomTexel.a * bloomIntensity;\n#endif\n\n#ifdef LENSFLARE_ENABLED\n texel.rgb += decodeHDR(texture2D(lensflare, v_Texcoord)).rgb * texture2D(lensdirt, v_Texcoord).rgb * lensflareIntensity;\n#endif\n\n#ifdef LUM_ENABLED\n float fLum = texture2D(lum, vec2(0.5, 0.5)).r;\n float adaptedLumDest = 3.0 / (max(0.1, 1.0 + 10.0*eyeAdaption(fLum)));\n float exposureBias = adaptedLumDest * exposure;\n#else\n float exposureBias = exposure;\n#endif\n texel.rgb *= exposureBias;\n\n texel.rgb = ACESToneMapping(texel.rgb);\n texel = linearTosRGB(texel);\n\n#ifdef LUT_ENABLED\n texel.rgb = lutTransform(clamp(texel.rgb,vec3(0.0),vec3(1.0)));\n#endif\n\n#ifdef COLOR_CORRECTION\n texel.rgb = clamp(texel.rgb + vec3(brightness), 0.0, 1.0);\n texel.rgb = clamp((texel.rgb - vec3(0.5))*contrast+vec3(0.5), 0.0, 1.0);\n float lum = dot(texel.rgb, vec3(0.2125, 0.7154, 0.0721));\n texel.rgb = mix(vec3(lum), texel.rgb, saturation);\n#endif\n\n#ifdef VIGNETTE\n vec2 uv = (v_Texcoord - vec2(0.5)) * vec2(vignetteOffset);\n texel.rgb = mix(texel.rgb, vec3(1.0 - vignetteDarkness), dot(uv, uv));\n#endif\n\n gl_FragColor = encodeHDR(texel);\n\n#ifdef DEBUG\n #if DEBUG == 1\n gl_FragColor = encodeHDR(decodeHDR(texture2D(texture, v_Texcoord)));\n #elif DEBUG == 2\n gl_FragColor = encodeHDR(decodeHDR(texture2D(bloom, v_Texcoord)) * bloomIntensity);\n #elif DEBUG == 3\n gl_FragColor = encodeHDR(decodeHDR(texture2D(lensflare, v_Texcoord) * lensflareIntensity));\n #endif\n#endif\n #ifdef PREMULTIPLY_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif\n}\n\n@end"; + module.exports = "@export qtek.compositor.hdr.composite\n\nuniform sampler2D texture;\n#ifdef BLOOM_ENABLED\nuniform sampler2D bloom;\n#endif\n#ifdef LENSFLARE_ENABLED\nuniform sampler2D lensflare;\nuniform sampler2D lensdirt;\n#endif\n\n#ifdef LUM_ENABLED\nuniform sampler2D lum;\n#endif\n\n#ifdef LUT_ENABLED\nuniform sampler2D lut;\n#endif\n\n#ifdef COLOR_CORRECTION\nuniform float brightness : 0.0;\nuniform float contrast : 1.0;\nuniform float saturation : 1.0;\n#endif\n\n#ifdef VIGNETTE\nuniform float vignetteDarkness: 1.0;\nuniform float vignetteOffset: 1.0;\n#endif\n\nuniform float exposure : 1.0;\nuniform float bloomIntensity : 0.25;\nuniform float lensflareIntensity : 1;\n\nvarying vec2 v_Texcoord;\n\nconst vec3 whiteScale = vec3(11.2);\n\n@import qtek.util.srgb\n\nvec3 uncharted2ToneMap(vec3 x)\n{\n const float A = 0.22; const float B = 0.30; const float C = 0.10; const float D = 0.20; const float E = 0.01; const float F = 0.30; \n return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;\n}\n\nvec3 filmicToneMap(vec3 color)\n{\n vec3 x = max(vec3(0.0), color - 0.004);\n return (x*(6.2*x+0.5))/(x*(6.2*x+1.7)+0.06);\n}\n\nvec3 ACESToneMapping(vec3 color)\n{\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\n\nfloat eyeAdaption(float fLum)\n{\n return mix(0.2, fLum, 0.5);\n}\n\n#ifdef LUT_ENABLED\nvec3 lutTransform(vec3 color) {\n float blueColor = color.b * 63.0;\n\n vec2 quad1;\n quad1.y = floor(floor(blueColor) / 8.0);\n quad1.x = floor(blueColor) - (quad1.y * 8.0);\n\n vec2 quad2;\n quad2.y = floor(ceil(blueColor) / 8.0);\n quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n\n vec2 texPos1;\n texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r);\n texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g);\n\n vec2 texPos2;\n texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r);\n texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g);\n\n vec4 newColor1 = texture2D(lut, texPos1);\n vec4 newColor2 = texture2D(lut, texPos2);\n\n vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n return newColor.rgb;\n}\n#endif\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec4 texel = vec4(0.0);\n vec4 originalTexel = vec4(0.0);\n#ifdef TEXTURE_ENABLED\n texel = decodeHDR(texture2D(texture, v_Texcoord));\n originalTexel = texel;\n#endif\n\n#ifdef BLOOM_ENABLED\n vec4 bloomTexel = decodeHDR(texture2D(bloom, v_Texcoord));\n texel.rgb += bloomTexel.rgb * bloomIntensity;\n texel.a += bloomTexel.a * bloomIntensity;\n#endif\n\n#ifdef LENSFLARE_ENABLED\n texel += decodeHDR(texture2D(lensflare, v_Texcoord)) * texture2D(lensdirt, v_Texcoord) * lensflareIntensity;\n#endif\n\n texel.a = min(texel.a, 1.0);\n\n#ifdef LUM_ENABLED\n float fLum = texture2D(lum, vec2(0.5, 0.5)).r;\n float adaptedLumDest = 3.0 / (max(0.1, 1.0 + 10.0*eyeAdaption(fLum)));\n float exposureBias = adaptedLumDest * exposure;\n#else\n float exposureBias = exposure;\n#endif\n texel.rgb *= exposureBias;\n\n texel.rgb = ACESToneMapping(texel.rgb);\n texel = linearTosRGB(texel);\n\n#ifdef LUT_ENABLED\n texel.rgb = lutTransform(clamp(texel.rgb,vec3(0.0),vec3(1.0)));\n#endif\n\n#ifdef COLOR_CORRECTION\n texel.rgb = clamp(texel.rgb + vec3(brightness), 0.0, 1.0);\n texel.rgb = clamp((texel.rgb - vec3(0.5))*contrast+vec3(0.5), 0.0, 1.0);\n float lum = dot(texel.rgb, vec3(0.2125, 0.7154, 0.0721));\n texel.rgb = mix(vec3(lum), texel.rgb, saturation);\n#endif\n\n#ifdef VIGNETTE\n vec2 uv = (v_Texcoord - vec2(0.5)) * vec2(vignetteOffset);\n texel.rgb = mix(texel.rgb, vec3(1.0 - vignetteDarkness), dot(uv, uv));\n#endif\n\n gl_FragColor = encodeHDR(texel);\n\n#ifdef DEBUG\n #if DEBUG == 1\n gl_FragColor = encodeHDR(decodeHDR(texture2D(texture, v_Texcoord)));\n #elif DEBUG == 2\n gl_FragColor = encodeHDR(decodeHDR(texture2D(bloom, v_Texcoord)) * bloomIntensity);\n #elif DEBUG == 3\n gl_FragColor = encodeHDR(decodeHDR(texture2D(lensflare, v_Texcoord) * lensflareIntensity));\n #endif\n#endif\n\n if (originalTexel.a <= 0.01) {\n gl_FragColor.rgb /= gl_FragColor.a;\n }\n #ifdef PREMULTIPLY_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif\n}\n\n@end"; /***/ }, @@ -28665,7 +28660,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.compositor.dof.coc\n\nuniform sampler2D depth;\n\nuniform float zNear: 0.1;\nuniform float zFar: 2000;\n\nuniform float focalDist: 3;\nuniform float focalRange: 1;\nuniform float focalLength: 30;\nuniform float fstop: 2.8;\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.encode_float\n\nvoid main()\n{\n float z = texture2D(depth, v_Texcoord).r * 2.0 - 1.0;\n\n float dist = 2.0 * zNear * zFar / (zFar + zNear - z * (zFar - zNear));\n\n float aperture = focalLength / fstop;\n\n float coc;\n\n float uppper = focalDist + focalRange;\n float lower = focalDist - focalRange;\n if (dist <= uppper && dist >= lower) {\n coc = 0.5;\n }\n else {\n float focalAdjusted = dist > uppper ? uppper : lower;\n\n coc = abs(aperture * (focalLength * (dist - focalAdjusted)) / (dist * (focalAdjusted - focalLength)));\n coc = clamp(coc, 0.0, 0.4) / 0.4000001;\n\n if (dist < lower) {\n coc = -coc;\n }\n coc = coc * 0.5 + 0.5;\n }\n\n gl_FragColor = encodeFloat(coc);\n}\n\n@end\n\n@export qtek.compositor.dof.premultiply\n\nuniform sampler2D texture;\nuniform sampler2D coc;\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n\n@import qtek.util.decode_float\n\nvoid main() {\n float fCoc = max(abs(decodeFloat(texture2D(coc, v_Texcoord)) * 2.0 - 1.0), 0.1);\n gl_FragColor = encodeHDR(\n vec4(decodeHDR(texture2D(texture, v_Texcoord)).rgb * fCoc, 1.0)\n );\n}\n@end\n\n\n@export qtek.compositor.dof.min_coc\nuniform sampler2D coc;\nvarying vec2 v_Texcoord;\nuniform vec2 textureSize : [512.0, 512.0];\n\n@import qtek.util.float\n\nvoid main()\n{\n vec4 d = vec4(-1.0, -1.0, 1.0, 1.0) / textureSize.xyxy;\n\n float fCoc = decodeFloat(texture2D(coc, v_Texcoord + d.xy));\n fCoc = min(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.zy)));\n fCoc = min(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.xw)));\n fCoc = min(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.zw)));\n\n gl_FragColor = encodeFloat(fCoc);\n}\n\n@end\n\n\n@export qtek.compositor.dof.max_coc\nuniform sampler2D coc;\nvarying vec2 v_Texcoord;\nuniform vec2 textureSize : [512.0, 512.0];\n\n@import qtek.util.float\n\nvoid main()\n{\n\n vec4 d = vec4(-1.0, -1.0, 1.0, 1.0) / textureSize.xyxy;\n\n float fCoc = decodeFloat(texture2D(coc, v_Texcoord + d.xy));\n fCoc = max(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.zy)));\n fCoc = max(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.xw)));\n fCoc = max(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.zw)));\n\n gl_FragColor = encodeFloat(fCoc);\n}\n\n@end\n\n\n\n\n@export qtek.compositor.dof.coc_upsample\n\n#define HIGH_QUALITY\n\nuniform sampler2D coc;\nuniform vec2 textureSize : [512, 512];\n\nuniform float sampleScale: 0.5;\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.float\n\nvoid main()\n{\n\n#ifdef HIGH_QUALITY\n vec4 d = vec4(1.0, 1.0, -1.0, 0.0) / textureSize.xyxy * sampleScale;\n\n float s;\n s = decodeFloat(texture2D(coc, v_Texcoord - d.xy));\n s += decodeFloat(texture2D(coc, v_Texcoord - d.wy)) * 2.0;\n s += decodeFloat(texture2D(coc, v_Texcoord - d.zy));\n\n s += decodeFloat(texture2D(coc, v_Texcoord + d.zw)) * 2.0;\n s += decodeFloat(texture2D(coc, v_Texcoord )) * 4.0;\n s += decodeFloat(texture2D(coc, v_Texcoord + d.xw)) * 2.0;\n\n s += decodeFloat(texture2D(coc, v_Texcoord + d.zy));\n s += decodeFloat(texture2D(coc, v_Texcoord + d.wy)) * 2.0;\n s += decodeFloat(texture2D(coc, v_Texcoord + d.xy));\n\n gl_FragColor = encodeFloat(s / 16.0);\n#else\n vec4 d = vec4(-1.0, -1.0, +1.0, +1.0) / textureSize.xyxy;\n\n float s;\n s = decodeFloat(texture2D(coc, v_Texcoord + d.xy));\n s += decodeFloat(texture2D(coc, v_Texcoord + d.zy));\n s += decodeFloat(texture2D(coc, v_Texcoord + d.xw));\n s += decodeFloat(texture2D(coc, v_Texcoord + d.zw));\n\n gl_FragColor = encodeFloat(s / 4.0);\n#endif\n}\n\n@end\n\n\n\n@export qtek.compositor.dof.upsample\n\n#define HIGH_QUALITY\n\nuniform sampler2D coc;\nuniform sampler2D texture;\nuniform vec2 textureSize : [512, 512];\n\nuniform float sampleScale: 0.5;\n\nvarying vec2 v_Texcoord;\n\n\n@import qtek.util.rgbm\n\n@import qtek.util.decode_float\n\nfloat tap(vec2 uv, inout vec4 color, float baseWeight) {\n float weight = abs(decodeFloat(texture2D(coc, uv)) * 2.0 - 1.0) * baseWeight;\n color += decodeHDR(texture2D(texture, uv)) * weight;\n return weight;\n}\n\nvoid main()\n{\n#ifdef HIGH_QUALITY\n vec4 d = vec4(1.0, 1.0, -1.0, 0.0) / textureSize.xyxy * sampleScale;\n\n vec4 color = vec4(0.0);\n float baseWeight = 1.0 / 16.0;\n float w = tap(v_Texcoord - d.xy, color, baseWeight);\n w += tap(v_Texcoord - d.wy, color, baseWeight * 2.0);\n w += tap(v_Texcoord - d.zy, color, baseWeight);\n\n w += tap(v_Texcoord + d.zw, color, baseWeight * 2.0);\n w += tap(v_Texcoord , color, baseWeight * 4.0);\n w += tap(v_Texcoord + d.xw, color, baseWeight * 2.0);\n\n w += tap(v_Texcoord + d.zy, color, baseWeight);\n w += tap(v_Texcoord + d.wy, color, baseWeight * 2.0);\n w += tap(v_Texcoord + d.xy, color, baseWeight);\n\n gl_FragColor = encodeHDR(color / w);\n#else\n vec4 d = vec4(-1.0, -1.0, +1.0, +1.0) / textureSize.xyxy;\n\n vec4 color = vec4(0.0);\n float baseWeight = 1.0 / 4.0;\n float w = tap(v_Texcoord + d.xy, color, baseWeight);\n w += tap(v_Texcoord + d.zy, color, baseWeight);\n w += tap(v_Texcoord + d.xw, color, baseWeight);\n w += tap(v_Texcoord + d.zw, color, baseWeight);\n\n gl_FragColor = encodeHDR(color / w);\n#endif\n}\n\n@end\n\n\n\n@export qtek.compositor.dof.downsample\n\nuniform sampler2D texture;\nuniform sampler2D coc;\nuniform vec2 textureSize : [512, 512];\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n\n@import qtek.util.decode_float\n\nfloat tap(vec2 uv, inout vec4 color) {\n float weight = abs(decodeFloat(texture2D(coc, uv)) * 2.0 - 1.0) * 0.25;\n color += decodeHDR(texture2D(texture, uv)) * weight;\n return weight;\n}\n\nvoid main()\n{\n vec4 d = vec4(-1.0, -1.0, 1.0, 1.0) / textureSize.xyxy;\n\n vec4 color = vec4(0.0);\n float weight = tap(v_Texcoord + d.xy, color);\n weight += tap(v_Texcoord + d.zy, color);\n weight += tap(v_Texcoord + d.xw, color);\n weight += tap(v_Texcoord + d.zw, color);\n color /= weight;\n\n gl_FragColor = encodeHDR(color);\n}\n\n@end\n\n\n\n@export qtek.compositor.dof.hexagonal_blur_frag\n\n@import qtek.util.float\n\n\nvec4 doBlur(sampler2D targetTexture, vec2 offset) {\n#ifdef BLUR_COC\n float cocSum = 0.0;\n#else\n vec4 color = vec4(0.0);\n#endif\n\n float weightSum = 0.0;\n float kernelWeight = 1.0 / float(KERNEL_SIZE);\n\n for (int i = 0; i < KERNEL_SIZE; i++) {\n vec2 coord = v_Texcoord + offset * float(i);\n\n float w = kernelWeight;\n#ifdef BLUR_COC\n float fCoc = decodeFloat(texture2D(targetTexture, coord)) * 2.0 - 1.0;\n cocSum += clamp(fCoc, -1.0, 0.0) * w;\n#else\n float fCoc = decodeFloat(texture2D(coc, coord)) * 2.0 - 1.0;\n vec4 texel = texture2D(targetTexture, coord);\n #if !defined(BLUR_NEARFIELD)\n w *= abs(fCoc);\n #endif\n color += decodeHDR(texel) * w;\n#endif\n\n weightSum += w;\n }\n#ifdef BLUR_COC\n return encodeFloat(clamp(cocSum / weightSum, -1.0, 0.0) * 0.5 + 0.5);\n#else\n return color / weightSum;\n#endif\n}\n\n@end\n\n\n@export qtek.compositor.dof.hexagonal_blur_1\n\n#define KERNEL_SIZE 5\n\nuniform sampler2D texture;\nuniform sampler2D coc;\nvarying vec2 v_Texcoord;\n\nuniform float blurSize : 1.0;\n\nuniform vec2 textureSize : [512.0, 512.0];\n\n@import qtek.util.rgbm\n\n@import qtek.compositor.dof.hexagonal_blur_frag\n\nvoid main()\n{\n vec2 offset = blurSize / textureSize;\n\n#if !defined(BLUR_NEARFIELD) && !defined(BLUR_COC)\n offset *= abs(decodeFloat(texture2D(coc, v_Texcoord)) * 2.0 - 1.0);\n#endif\n\n gl_FragColor = doBlur(texture, vec2(0.0, offset.y));\n#if !defined(BLUR_COC)\n gl_FragColor = encodeHDR(gl_FragColor);\n#endif\n}\n\n@end\n\n@export qtek.compositor.dof.hexagonal_blur_2\n\n#define KERNEL_SIZE 5\n\nuniform sampler2D texture;\nuniform sampler2D coc;\nvarying vec2 v_Texcoord;\n\nuniform float blurSize : 1.0;\n\nuniform vec2 textureSize : [512.0, 512.0];\n\n@import qtek.util.rgbm\n\n@import qtek.compositor.dof.hexagonal_blur_frag\n\nvoid main()\n{\n vec2 offset = blurSize / textureSize;\n#if !defined(BLUR_NEARFIELD) && !defined(BLUR_COC)\n offset *= abs(decodeFloat(texture2D(coc, v_Texcoord)) * 2.0 - 1.0);\n#endif\n\n offset.y /= 2.0;\n\n gl_FragColor = doBlur(texture, -offset);\n#if !defined(BLUR_COC)\n gl_FragColor = encodeHDR(gl_FragColor);\n#endif\n}\n@end\n\n@export qtek.compositor.dof.hexagonal_blur_3\n\n#define KERNEL_SIZE 5\n\nuniform sampler2D texture1;\nuniform sampler2D texture2;\nuniform sampler2D coc;\n\nvarying vec2 v_Texcoord;\n\nuniform float blurSize : 1.0;\n\nuniform vec2 textureSize : [512.0, 512.0];\n\n@import qtek.util.rgbm\n\n@import qtek.compositor.dof.hexagonal_blur_frag\n\nvoid main()\n{\n vec2 offset = blurSize / textureSize;\n\n#if !defined(BLUR_NEARFIELD) && !defined(BLUR_COC)\n offset *= abs(decodeFloat(texture2D(coc, v_Texcoord)) * 2.0 - 1.0);\n#endif\n\n offset.y /= 2.0;\n vec2 vDownRight = vec2(offset.x, -offset.y);\n\n vec4 texel1 = doBlur(texture1, -offset);\n vec4 texel2 = doBlur(texture1, vDownRight);\n vec4 texel3 = doBlur(texture2, vDownRight);\n\n#ifdef BLUR_COC\n float coc1 = decodeFloat(texel1) * 2.0 - 1.0;\n float coc2 = decodeFloat(texel2) * 2.0 - 1.0;\n float coc3 = decodeFloat(texel3) * 2.0 - 1.0;\n gl_FragColor = encodeFloat(\n ((coc1 + coc2 + coc3) / 3.0) * 0.5 + 0.5\n );\n\n#else\n vec4 color = (texel1 + texel2 + texel3) / 3.0;\n gl_FragColor = encodeHDR(color);\n#endif\n}\n\n@end\n\n@export qtek.compositor.dof.composite\n\n#define DEBUG 0\n\nuniform sampler2D original;\nuniform sampler2D blurred;\nuniform sampler2D nearfield;\nuniform sampler2D coc;\nuniform sampler2D nearcoc;\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n@import qtek.util.float\n\nvoid main()\n{\n vec4 blurredColor = decodeHDR(texture2D(blurred, v_Texcoord));\n vec4 originalColor = decodeHDR(texture2D(original, v_Texcoord));\n\n float fCoc = decodeFloat(texture2D(coc, v_Texcoord));\n\n fCoc = abs(fCoc * 2.0 - 1.0);\n\n float weight = smoothstep(0.0, 1.0, fCoc);\n \n#ifdef NEARFIELD_ENABLED\n vec4 nearfieldColor = decodeHDR(texture2D(nearfield, v_Texcoord));\n float fNearCoc = decodeFloat(texture2D(nearcoc, v_Texcoord));\n fNearCoc = abs(fNearCoc * 2.0 - 1.0);\n\n gl_FragColor = encodeHDR(\n mix(\n nearfieldColor, mix(originalColor, blurredColor, weight),\n pow(1.0 - fNearCoc, 4.0)\n )\n );\n#else\n gl_FragColor = encodeHDR(mix(originalColor, blurredColor, weight));\n#endif\n\n#if DEBUG == 1\n gl_FragColor = vec4(vec3(fCoc), 1.0);\n#elif DEBUG == 2\n gl_FragColor = vec4(vec3(fNearCoc), 1.0);\n#elif DEBUG == 3\n gl_FragColor = encodeHDR(blurredColor);\n#elif DEBUG == 4\n gl_FragColor = encodeHDR(nearfieldColor);\n#endif\n}\n\n@end"; + module.exports = "@export qtek.compositor.dof.coc\n\nuniform sampler2D depth;\n\nuniform float zNear: 0.1;\nuniform float zFar: 2000;\n\nuniform float focalDist: 3;\nuniform float focalRange: 1;\nuniform float focalLength: 30;\nuniform float fstop: 2.8;\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.encode_float\n\nvoid main()\n{\n float z = texture2D(depth, v_Texcoord).r * 2.0 - 1.0;\n\n float dist = 2.0 * zNear * zFar / (zFar + zNear - z * (zFar - zNear));\n\n float aperture = focalLength / fstop;\n\n float coc;\n\n float uppper = focalDist + focalRange;\n float lower = focalDist - focalRange;\n if (dist <= uppper && dist >= lower) {\n coc = 0.5;\n }\n else {\n float focalAdjusted = dist > uppper ? uppper : lower;\n\n coc = abs(aperture * (focalLength * (dist - focalAdjusted)) / (dist * (focalAdjusted - focalLength)));\n coc = clamp(coc, 0.0, 0.4) / 0.4000001;\n\n if (dist < lower) {\n coc = -coc;\n }\n coc = coc * 0.5 + 0.5;\n }\n\n gl_FragColor = encodeFloat(coc);\n}\n\n@end\n\n@export qtek.compositor.dof.premultiply\n\nuniform sampler2D texture;\nuniform sampler2D coc;\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n\n@import qtek.util.decode_float\n\nvoid main() {\n float fCoc = max(abs(decodeFloat(texture2D(coc, v_Texcoord)) * 2.0 - 1.0), 0.1);\n gl_FragColor = encodeHDR(\n vec4(decodeHDR(texture2D(texture, v_Texcoord)).rgb * fCoc, 1.0)\n );\n}\n@end\n\n\n@export qtek.compositor.dof.min_coc\nuniform sampler2D coc;\nvarying vec2 v_Texcoord;\nuniform vec2 textureSize : [512.0, 512.0];\n\n@import qtek.util.float\n\nvoid main()\n{\n vec4 d = vec4(-1.0, -1.0, 1.0, 1.0) / textureSize.xyxy;\n\n float fCoc = decodeFloat(texture2D(coc, v_Texcoord + d.xy));\n fCoc = min(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.zy)));\n fCoc = min(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.xw)));\n fCoc = min(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.zw)));\n\n gl_FragColor = encodeFloat(fCoc);\n}\n\n@end\n\n\n@export qtek.compositor.dof.max_coc\nuniform sampler2D coc;\nvarying vec2 v_Texcoord;\nuniform vec2 textureSize : [512.0, 512.0];\n\n@import qtek.util.float\n\nvoid main()\n{\n\n vec4 d = vec4(-1.0, -1.0, 1.0, 1.0) / textureSize.xyxy;\n\n float fCoc = decodeFloat(texture2D(coc, v_Texcoord + d.xy));\n fCoc = max(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.zy)));\n fCoc = max(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.xw)));\n fCoc = max(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.zw)));\n\n gl_FragColor = encodeFloat(fCoc);\n}\n\n@end\n\n\n\n\n@export qtek.compositor.dof.coc_upsample\n\n#define HIGH_QUALITY\n\nuniform sampler2D coc;\nuniform vec2 textureSize : [512, 512];\n\nuniform float sampleScale: 0.5;\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.float\n\nvoid main()\n{\n\n#ifdef HIGH_QUALITY\n vec4 d = vec4(1.0, 1.0, -1.0, 0.0) / textureSize.xyxy * sampleScale;\n\n float s;\n s = decodeFloat(texture2D(coc, v_Texcoord - d.xy));\n s += decodeFloat(texture2D(coc, v_Texcoord - d.wy)) * 2.0;\n s += decodeFloat(texture2D(coc, v_Texcoord - d.zy));\n\n s += decodeFloat(texture2D(coc, v_Texcoord + d.zw)) * 2.0;\n s += decodeFloat(texture2D(coc, v_Texcoord )) * 4.0;\n s += decodeFloat(texture2D(coc, v_Texcoord + d.xw)) * 2.0;\n\n s += decodeFloat(texture2D(coc, v_Texcoord + d.zy));\n s += decodeFloat(texture2D(coc, v_Texcoord + d.wy)) * 2.0;\n s += decodeFloat(texture2D(coc, v_Texcoord + d.xy));\n\n gl_FragColor = encodeFloat(s / 16.0);\n#else\n vec4 d = vec4(-1.0, -1.0, +1.0, +1.0) / textureSize.xyxy;\n\n float s;\n s = decodeFloat(texture2D(coc, v_Texcoord + d.xy));\n s += decodeFloat(texture2D(coc, v_Texcoord + d.zy));\n s += decodeFloat(texture2D(coc, v_Texcoord + d.xw));\n s += decodeFloat(texture2D(coc, v_Texcoord + d.zw));\n\n gl_FragColor = encodeFloat(s / 4.0);\n#endif\n}\n\n@end\n\n\n\n@export qtek.compositor.dof.upsample\n\n#define HIGH_QUALITY\n\nuniform sampler2D coc;\nuniform sampler2D texture;\nuniform vec2 textureSize : [512, 512];\n\nuniform float sampleScale: 0.5;\n\nvarying vec2 v_Texcoord;\n\n\n@import qtek.util.rgbm\n\n@import qtek.util.decode_float\n\nfloat tap(vec2 uv, inout vec4 color, float baseWeight) {\n float weight = abs(decodeFloat(texture2D(coc, uv)) * 2.0 - 1.0) * baseWeight;\n color += decodeHDR(texture2D(texture, uv)) * weight;\n return weight;\n}\n\nvoid main()\n{\n#ifdef HIGH_QUALITY\n vec4 d = vec4(1.0, 1.0, -1.0, 0.0) / textureSize.xyxy * sampleScale;\n\n vec4 color = vec4(0.0);\n float baseWeight = 1.0 / 16.0;\n float w = tap(v_Texcoord - d.xy, color, baseWeight);\n w += tap(v_Texcoord - d.wy, color, baseWeight * 2.0);\n w += tap(v_Texcoord - d.zy, color, baseWeight);\n\n w += tap(v_Texcoord + d.zw, color, baseWeight * 2.0);\n w += tap(v_Texcoord , color, baseWeight * 4.0);\n w += tap(v_Texcoord + d.xw, color, baseWeight * 2.0);\n\n w += tap(v_Texcoord + d.zy, color, baseWeight);\n w += tap(v_Texcoord + d.wy, color, baseWeight * 2.0);\n w += tap(v_Texcoord + d.xy, color, baseWeight);\n\n gl_FragColor = encodeHDR(color / w);\n#else\n vec4 d = vec4(-1.0, -1.0, +1.0, +1.0) / textureSize.xyxy;\n\n vec4 color = vec4(0.0);\n float baseWeight = 1.0 / 4.0;\n float w = tap(v_Texcoord + d.xy, color, baseWeight);\n w += tap(v_Texcoord + d.zy, color, baseWeight);\n w += tap(v_Texcoord + d.xw, color, baseWeight);\n w += tap(v_Texcoord + d.zw, color, baseWeight);\n\n gl_FragColor = encodeHDR(color / w);\n#endif\n}\n\n@end\n\n\n\n@export qtek.compositor.dof.downsample\n\nuniform sampler2D texture;\nuniform sampler2D coc;\nuniform vec2 textureSize : [512, 512];\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n\n@import qtek.util.decode_float\n\nfloat tap(vec2 uv, inout vec4 color) {\n float weight = abs(decodeFloat(texture2D(coc, uv)) * 2.0 - 1.0) * 0.25;\n color += decodeHDR(texture2D(texture, uv)) * weight;\n return weight;\n}\n\nvoid main()\n{\n vec4 d = vec4(-1.0, -1.0, 1.0, 1.0) / textureSize.xyxy;\n\n vec4 color = vec4(0.0);\n float weight = tap(v_Texcoord + d.xy, color);\n weight += tap(v_Texcoord + d.zy, color);\n weight += tap(v_Texcoord + d.xw, color);\n weight += tap(v_Texcoord + d.zw, color);\n color /= weight;\n\n gl_FragColor = encodeHDR(color);\n}\n\n@end\n\n\n\n@export qtek.compositor.dof.hexagonal_blur_frag\n\n@import qtek.util.float\n\n\nvec4 doBlur(sampler2D targetTexture, vec2 offset) {\n#ifdef BLUR_COC\n float cocSum = 0.0;\n#else\n vec4 color = vec4(0.0);\n#endif\n\n float weightSum = 0.0;\n float kernelWeight = 1.0 / float(KERNEL_SIZE);\n\n for (int i = 0; i < KERNEL_SIZE; i++) {\n vec2 coord = v_Texcoord + offset * float(i);\n\n float w = kernelWeight;\n#ifdef BLUR_COC\n float fCoc = decodeFloat(texture2D(targetTexture, coord)) * 2.0 - 1.0;\n cocSum += clamp(fCoc, -1.0, 0.0) * w;\n#else\n float fCoc = decodeFloat(texture2D(coc, coord)) * 2.0 - 1.0;\n vec4 texel = texture2D(targetTexture, coord);\n #if !defined(BLUR_NEARFIELD)\n w *= abs(fCoc);\n #endif\n color += decodeHDR(texel) * w;\n#endif\n\n weightSum += w;\n }\n#ifdef BLUR_COC\n return encodeFloat(clamp(cocSum / weightSum, -1.0, 0.0) * 0.5 + 0.5);\n#else\n return color / weightSum;\n#endif\n}\n\n@end\n\n\n@export qtek.compositor.dof.hexagonal_blur_1\n\n#define KERNEL_SIZE 5\n\nuniform sampler2D texture;\nuniform sampler2D coc;\nvarying vec2 v_Texcoord;\n\nuniform float blurSize : 1.0;\n\nuniform vec2 textureSize : [512.0, 512.0];\n\n@import qtek.util.rgbm\n\n@import qtek.compositor.dof.hexagonal_blur_frag\n\nvoid main()\n{\n vec2 offset = blurSize / textureSize;\n\n#if !defined(BLUR_NEARFIELD) && !defined(BLUR_COC)\n offset *= abs(decodeFloat(texture2D(coc, v_Texcoord)) * 2.0 - 1.0);\n#endif\n\n gl_FragColor = doBlur(texture, vec2(0.0, offset.y));\n#if !defined(BLUR_COC)\n gl_FragColor = encodeHDR(gl_FragColor);\n#endif\n}\n\n@end\n\n@export qtek.compositor.dof.hexagonal_blur_2\n\n#define KERNEL_SIZE 5\n\nuniform sampler2D texture;\nuniform sampler2D coc;\nvarying vec2 v_Texcoord;\n\nuniform float blurSize : 1.0;\n\nuniform vec2 textureSize : [512.0, 512.0];\n\n@import qtek.util.rgbm\n\n@import qtek.compositor.dof.hexagonal_blur_frag\n\nvoid main()\n{\n vec2 offset = blurSize / textureSize;\n#if !defined(BLUR_NEARFIELD) && !defined(BLUR_COC)\n offset *= abs(decodeFloat(texture2D(coc, v_Texcoord)) * 2.0 - 1.0);\n#endif\n\n offset.y /= 2.0;\n\n gl_FragColor = doBlur(texture, -offset);\n#if !defined(BLUR_COC)\n gl_FragColor = encodeHDR(gl_FragColor);\n#endif\n}\n@end\n\n@export qtek.compositor.dof.hexagonal_blur_3\n\n#define KERNEL_SIZE 5\n\nuniform sampler2D texture1;\nuniform sampler2D texture2;\nuniform sampler2D coc;\n\nvarying vec2 v_Texcoord;\n\nuniform float blurSize : 1.0;\n\nuniform vec2 textureSize : [512.0, 512.0];\n\n@import qtek.util.rgbm\n\n@import qtek.compositor.dof.hexagonal_blur_frag\n\nvoid main()\n{\n vec2 offset = blurSize / textureSize;\n\n#if !defined(BLUR_NEARFIELD) && !defined(BLUR_COC)\n offset *= abs(decodeFloat(texture2D(coc, v_Texcoord)) * 2.0 - 1.0);\n#endif\n\n offset.y /= 2.0;\n vec2 vDownRight = vec2(offset.x, -offset.y);\n\n vec4 texel1 = doBlur(texture1, -offset);\n vec4 texel2 = doBlur(texture1, vDownRight);\n vec4 texel3 = doBlur(texture2, vDownRight);\n\n#ifdef BLUR_COC\n float coc1 = decodeFloat(texel1) * 2.0 - 1.0;\n float coc2 = decodeFloat(texel2) * 2.0 - 1.0;\n float coc3 = decodeFloat(texel3) * 2.0 - 1.0;\n gl_FragColor = encodeFloat(\n ((coc1 + coc2 + coc3) / 3.0) * 0.5 + 0.5\n );\n\n#else\n vec4 color = (texel1 + texel2 + texel3) / 3.0;\n gl_FragColor = encodeHDR(color);\n#endif\n}\n\n@end\n\n@export qtek.compositor.dof.composite\n\n#define DEBUG 0\n\nuniform sampler2D original;\nuniform sampler2D blurred;\nuniform sampler2D nearfield;\nuniform sampler2D coc;\nuniform sampler2D nearcoc;\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n@import qtek.util.float\n\nvoid main()\n{\n vec4 blurredColor = decodeHDR(texture2D(blurred, v_Texcoord));\n vec4 originalColor = decodeHDR(texture2D(original, v_Texcoord));\n\n float fCoc = decodeFloat(texture2D(coc, v_Texcoord));\n\n fCoc = abs(fCoc * 2.0 - 1.0);\n\n float weight = smoothstep(0.0, 1.0, fCoc);\n \n#ifdef NEARFIELD_ENABLED\n vec4 nearfieldColor = decodeHDR(texture2D(nearfield, v_Texcoord));\n float fNearCoc = decodeFloat(texture2D(nearcoc, v_Texcoord));\n fNearCoc = abs(fNearCoc * 2.0 - 1.0);\n\n gl_FragColor = encodeHDR(\n mix(\n nearfieldColor, mix(originalColor, blurredColor, weight),\n pow(1.0 - fNearCoc, 4.0)\n )\n );\n#else\n gl_FragColor = encodeHDR(mix(originalColor, blurredColor, weight));\n#endif\n\n#if DEBUG == 1\n gl_FragColor = vec4(vec3(fCoc), 1.0);\n#elif DEBUG == 2\n gl_FragColor = vec4(vec3(fNearCoc), 1.0);\n#elif DEBUG == 3\n gl_FragColor = encodeHDR(blurredColor);\n#elif DEBUG == 4\n gl_FragColor = encodeHDR(nearfieldColor);\n#endif\n}\n\n@end"; /***/ }, @@ -28673,7 +28668,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.compositor.lensflare\n\n#define SAMPLE_NUMBER 8\n\nuniform sampler2D texture;\nuniform sampler2D lenscolor;\n\nuniform vec2 textureSize : [512, 512];\n\nuniform float dispersal : 0.3;\nuniform float haloWidth : 0.4;\nuniform float distortion : 1.0;\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n\nvec4 textureDistorted(\n in vec2 texcoord,\n in vec2 direction,\n in vec3 distortion\n) {\n return vec4(\n decodeHDR(texture2D(texture, texcoord + direction * distortion.r)).r,\n decodeHDR(texture2D(texture, texcoord + direction * distortion.g)).g,\n decodeHDR(texture2D(texture, texcoord + direction * distortion.b)).b,\n 1.0\n );\n}\n\nvoid main()\n{\n vec2 texcoord = -v_Texcoord + vec2(1.0); vec2 textureOffset = 1.0 / textureSize;\n\n vec2 ghostVec = (vec2(0.5) - texcoord) * dispersal;\n vec2 haloVec = normalize(ghostVec) * haloWidth;\n\n vec3 distortion = vec3(-textureOffset.x * distortion, 0.0, textureOffset.x * distortion);\n vec4 result = vec4(0.0);\n for (int i = 0; i < SAMPLE_NUMBER; i++)\n {\n vec2 offset = fract(texcoord + ghostVec * float(i));\n\n float weight = length(vec2(0.5) - offset) / length(vec2(0.5));\n weight = pow(1.0 - weight, 10.0);\n\n result += textureDistorted(offset, normalize(ghostVec), distortion) * weight;\n }\n\n result *= texture2D(lenscolor, vec2(length(vec2(0.5) - texcoord)) / length(vec2(0.5)));\n float weight = length(vec2(0.5) - fract(texcoord + haloVec)) / length(vec2(0.5));\n weight = pow(1.0 - weight, 10.0);\n vec2 offset = fract(texcoord + haloVec);\n result += textureDistorted(offset, normalize(ghostVec), distortion) * weight;\n\n gl_FragColor = result;\n}\n@end"; + module.exports = "@export qtek.compositor.lensflare\n\n#define SAMPLE_NUMBER 8\n\nuniform sampler2D texture;\nuniform sampler2D lenscolor;\n\nuniform vec2 textureSize : [512, 512];\n\nuniform float dispersal : 0.3;\nuniform float haloWidth : 0.4;\nuniform float distortion : 1.0;\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n\nvec4 textureDistorted(\n in vec2 texcoord,\n in vec2 direction,\n in vec3 distortion\n) {\n return vec4(\n decodeHDR(texture2D(texture, texcoord + direction * distortion.r)).r,\n decodeHDR(texture2D(texture, texcoord + direction * distortion.g)).g,\n decodeHDR(texture2D(texture, texcoord + direction * distortion.b)).b,\n 1.0\n );\n}\n\nvoid main()\n{\n vec2 texcoord = -v_Texcoord + vec2(1.0); vec2 textureOffset = 1.0 / textureSize;\n\n vec2 ghostVec = (vec2(0.5) - texcoord) * dispersal;\n vec2 haloVec = normalize(ghostVec) * haloWidth;\n\n vec3 distortion = vec3(-textureOffset.x * distortion, 0.0, textureOffset.x * distortion);\n vec4 result = vec4(0.0);\n for (int i = 0; i < SAMPLE_NUMBER; i++)\n {\n vec2 offset = fract(texcoord + ghostVec * float(i));\n\n float weight = length(vec2(0.5) - offset) / length(vec2(0.5));\n weight = pow(1.0 - weight, 10.0);\n\n result += textureDistorted(offset, normalize(ghostVec), distortion) * weight;\n }\n\n result *= texture2D(lenscolor, vec2(length(vec2(0.5) - texcoord)) / length(vec2(0.5)));\n float weight = length(vec2(0.5) - fract(texcoord + haloVec)) / length(vec2(0.5));\n weight = pow(1.0 - weight, 10.0);\n vec2 offset = fract(texcoord + haloVec);\n result += textureDistorted(offset, normalize(ghostVec), distortion) * weight;\n\n gl_FragColor = result;\n}\n@end"; /***/ }, @@ -28681,7 +28676,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.compositor.blend\n#ifdef TEXTURE1_ENABLED\nuniform sampler2D texture1;\nuniform float weight1 : 1.0;\n#endif\n#ifdef TEXTURE2_ENABLED\nuniform sampler2D texture2;\nuniform float weight2 : 1.0;\n#endif\n#ifdef TEXTURE3_ENABLED\nuniform sampler2D texture3;\nuniform float weight3 : 1.0;\n#endif\n#ifdef TEXTURE4_ENABLED\nuniform sampler2D texture4;\nuniform float weight4 : 1.0;\n#endif\n#ifdef TEXTURE5_ENABLED\nuniform sampler2D texture5;\nuniform float weight5 : 1.0;\n#endif\n#ifdef TEXTURE6_ENABLED\nuniform sampler2D texture6;\nuniform float weight6 : 1.0;\n#endif\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec4 tex = vec4(0.0);\n#ifdef TEXTURE1_ENABLED\n tex += decodeHDR(texture2D(texture1, v_Texcoord)) * weight1;\n#endif\n#ifdef TEXTURE2_ENABLED\n tex += decodeHDR(texture2D(texture2, v_Texcoord)) * weight2;\n#endif\n#ifdef TEXTURE3_ENABLED\n tex += decodeHDR(texture2D(texture3, v_Texcoord)) * weight3;\n#endif\n#ifdef TEXTURE4_ENABLED\n tex += decodeHDR(texture2D(texture4, v_Texcoord)) * weight4;\n#endif\n#ifdef TEXTURE5_ENABLED\n tex += decodeHDR(texture2D(texture5, v_Texcoord)) * weight5;\n#endif\n#ifdef TEXTURE6_ENABLED\n tex += decodeHDR(texture2D(texture6, v_Texcoord)) * weight6;\n#endif\n\n gl_FragColor = encodeHDR(tex);\n}\n@end"; + module.exports = "@export qtek.compositor.blend\n#ifdef TEXTURE1_ENABLED\nuniform sampler2D texture1;\nuniform float weight1 : 1.0;\n#endif\n#ifdef TEXTURE2_ENABLED\nuniform sampler2D texture2;\nuniform float weight2 : 1.0;\n#endif\n#ifdef TEXTURE3_ENABLED\nuniform sampler2D texture3;\nuniform float weight3 : 1.0;\n#endif\n#ifdef TEXTURE4_ENABLED\nuniform sampler2D texture4;\nuniform float weight4 : 1.0;\n#endif\n#ifdef TEXTURE5_ENABLED\nuniform sampler2D texture5;\nuniform float weight5 : 1.0;\n#endif\n#ifdef TEXTURE6_ENABLED\nuniform sampler2D texture6;\nuniform float weight6 : 1.0;\n#endif\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec4 tex = vec4(0.0);\n#ifdef TEXTURE1_ENABLED\n tex += decodeHDR(texture2D(texture1, v_Texcoord)) * weight1;\n#endif\n#ifdef TEXTURE2_ENABLED\n tex += decodeHDR(texture2D(texture2, v_Texcoord)) * weight2;\n#endif\n#ifdef TEXTURE3_ENABLED\n tex += decodeHDR(texture2D(texture3, v_Texcoord)) * weight3;\n#endif\n#ifdef TEXTURE4_ENABLED\n tex += decodeHDR(texture2D(texture4, v_Texcoord)) * weight4;\n#endif\n#ifdef TEXTURE5_ENABLED\n tex += decodeHDR(texture2D(texture5, v_Texcoord)) * weight5;\n#endif\n#ifdef TEXTURE6_ENABLED\n tex += decodeHDR(texture2D(texture6, v_Texcoord)) * weight6;\n#endif\n\n gl_FragColor = encodeHDR(tex);\n}\n@end"; /***/ }, @@ -28689,7 +28684,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.compositor.fxaa\n\nuniform sampler2D texture;\nuniform vec4 viewport : VIEWPORT;\n\nvarying vec2 v_Texcoord;\n\n#define FXAA_REDUCE_MIN (1.0/128.0)\n#define FXAA_REDUCE_MUL (1.0/8.0)\n#define FXAA_SPAN_MAX 8.0\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec2 resolution = 1.0 / viewport.zw;\n vec3 rgbNW = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( -1.0, -1.0 ) ) * resolution ) ).xyz;\n vec3 rgbNE = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( 1.0, -1.0 ) ) * resolution ) ).xyz;\n vec3 rgbSW = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( -1.0, 1.0 ) ) * resolution ) ).xyz;\n vec3 rgbSE = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( 1.0, 1.0 ) ) * resolution ) ).xyz;\n vec4 rgbaM = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution ) );\n vec3 rgbM = rgbaM.xyz;\n float opacity = rgbaM.w;\n\n vec3 luma = vec3( 0.299, 0.587, 0.114 );\n\n float lumaNW = dot( rgbNW, luma );\n float lumaNE = dot( rgbNE, luma );\n float lumaSW = dot( rgbSW, luma );\n float lumaSE = dot( rgbSE, luma );\n float lumaM = dot( rgbM, luma );\n float lumaMin = min( lumaM, min( min( lumaNW, lumaNE ), min( lumaSW, lumaSE ) ) );\n float lumaMax = max( lumaM, max( max( lumaNW, lumaNE) , max( lumaSW, lumaSE ) ) );\n\n vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\n float dirReduce = max( ( lumaNW + lumaNE + lumaSW + lumaSE ) * ( 0.25 * FXAA_REDUCE_MUL ), FXAA_REDUCE_MIN );\n\n float rcpDirMin = 1.0 / ( min( abs( dir.x ), abs( dir.y ) ) + dirReduce );\n dir = min( vec2( FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max( vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * resolution;\n\n vec3 rgbA = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * ( 1.0 / 3.0 - 0.5 ) ) ).xyz;\n rgbA += decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * ( 2.0 / 3.0 - 0.5 ) ) ).xyz;\n rgbA *= 0.5;\n\n vec3 rgbB = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * -0.5 ) ).xyz;\n rgbB += decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * 0.5 ) ).xyz;\n rgbB *= 0.25;\n rgbB += rgbA * 0.5;\n\n float lumaB = dot( rgbB, luma );\n\n if ( ( lumaB < lumaMin ) || ( lumaB > lumaMax ) )\n {\n gl_FragColor = vec4( rgbA, opacity );\n\n }\n else {\n\n gl_FragColor = vec4( rgbB, opacity );\n\n }\n}\n\n@end"; + module.exports = "@export qtek.compositor.fxaa\n\nuniform sampler2D texture;\nuniform vec4 viewport : VIEWPORT;\n\nvarying vec2 v_Texcoord;\n\n#define FXAA_REDUCE_MIN (1.0/128.0)\n#define FXAA_REDUCE_MUL (1.0/8.0)\n#define FXAA_SPAN_MAX 8.0\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec2 resolution = 1.0 / viewport.zw;\n vec3 rgbNW = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( -1.0, -1.0 ) ) * resolution ) ).xyz;\n vec3 rgbNE = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( 1.0, -1.0 ) ) * resolution ) ).xyz;\n vec3 rgbSW = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( -1.0, 1.0 ) ) * resolution ) ).xyz;\n vec3 rgbSE = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( 1.0, 1.0 ) ) * resolution ) ).xyz;\n vec4 rgbaM = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution ) );\n vec3 rgbM = rgbaM.xyz;\n float opacity = rgbaM.w;\n\n vec3 luma = vec3( 0.299, 0.587, 0.114 );\n\n float lumaNW = dot( rgbNW, luma );\n float lumaNE = dot( rgbNE, luma );\n float lumaSW = dot( rgbSW, luma );\n float lumaSE = dot( rgbSE, luma );\n float lumaM = dot( rgbM, luma );\n float lumaMin = min( lumaM, min( min( lumaNW, lumaNE ), min( lumaSW, lumaSE ) ) );\n float lumaMax = max( lumaM, max( max( lumaNW, lumaNE) , max( lumaSW, lumaSE ) ) );\n\n vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\n float dirReduce = max( ( lumaNW + lumaNE + lumaSW + lumaSE ) * ( 0.25 * FXAA_REDUCE_MUL ), FXAA_REDUCE_MIN );\n\n float rcpDirMin = 1.0 / ( min( abs( dir.x ), abs( dir.y ) ) + dirReduce );\n dir = min( vec2( FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max( vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * resolution;\n\n vec3 rgbA = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * ( 1.0 / 3.0 - 0.5 ) ) ).xyz;\n rgbA += decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * ( 2.0 / 3.0 - 0.5 ) ) ).xyz;\n rgbA *= 0.5;\n\n vec3 rgbB = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * -0.5 ) ).xyz;\n rgbB += decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * 0.5 ) ).xyz;\n rgbB *= 0.25;\n rgbB += rgbA * 0.5;\n\n float lumaB = dot( rgbB, luma );\n\n if ( ( lumaB < lumaMin ) || ( lumaB > lumaMax ) )\n {\n gl_FragColor = vec4( rgbA, opacity );\n\n }\n else {\n\n gl_FragColor = vec4( rgbB, opacity );\n\n }\n}\n\n@end"; /***/ }, @@ -28697,7 +28692,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.compositor.fxaa3\n\nuniform sampler2D texture;\nuniform vec4 viewport : VIEWPORT;\n\nuniform float subpixel: 0.75;\nuniform float edgeThreshold: 0.125;\nuniform float edgeThresholdMin: 0.0625;\n\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n\nfloat FxaaLuma(vec4 rgba) { return rgba.y; }\nvec4 FxaaPixelShader(\n vec2 pos\n ,sampler2D tex\n ,vec2 fxaaQualityRcpFrame\n ,float fxaaQualitySubpix\n ,float fxaaQualityEdgeThreshold\n ,float fxaaQualityEdgeThresholdMin\n) {\n vec2 posM;\n posM.x = pos.x;\n posM.y = pos.y;\n vec4 rgbyM = decodeHDR(texture2D(texture, posM, 0.0));\n float lumaS = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2( 0.0, 1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaE = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2( 1.0, 0.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaN = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2( 0.0,-1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaW = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2(-1.0, 0.0) * fxaaQualityRcpFrame.xy), 0.0)));\n\n float maxSM = max(lumaS, rgbyM.y);\n float minSM = min(lumaS, rgbyM.y);\n float maxESM = max(lumaE, maxSM);\n float minESM = min(lumaE, minSM);\n float maxWN = max(lumaN, lumaW);\n float minWN = min(lumaN, lumaW);\n float rangeMax = max(maxWN, maxESM);\n float rangeMin = min(minWN, minESM);\n float rangeMaxScaled = rangeMax * fxaaQualityEdgeThreshold;\n float range = rangeMax - rangeMin;\n float rangeMaxClamped = max(fxaaQualityEdgeThresholdMin, rangeMaxScaled);\n bool earlyExit = range < rangeMaxClamped;\n if(earlyExit) return rgbyM;\n float lumaNW = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2(-1.0,-1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaSE = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2( 1.0, 1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaNE = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2( 1.0,-1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaSW = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2(-1.0, 1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n\n float lumaNS = lumaN + lumaS;\n float lumaWE = lumaW + lumaE;\n float subpixRcpRange = 1.0/range;\n float subpixNSWE = lumaNS + lumaWE;\n float edgeHorz1 = (-2.0 * rgbyM.y) + lumaNS;\n float edgeVert1 = (-2.0 * rgbyM.y) + lumaWE;\n float lumaNESE = lumaNE + lumaSE;\n float lumaNWNE = lumaNW + lumaNE;\n float edgeHorz2 = (-2.0 * lumaE) + lumaNESE;\n float edgeVert2 = (-2.0 * lumaN) + lumaNWNE;\n float lumaNWSW = lumaNW + lumaSW;\n float lumaSWSE = lumaSW + lumaSE;\n float edgeHorz4 = (abs(edgeHorz1) * 2.0) + abs(edgeHorz2);\n float edgeVert4 = (abs(edgeVert1) * 2.0) + abs(edgeVert2);\n float edgeHorz3 = (-2.0 * lumaW) + lumaNWSW;\n float edgeVert3 = (-2.0 * lumaS) + lumaSWSE;\n float edgeHorz = abs(edgeHorz3) + edgeHorz4;\n float edgeVert = abs(edgeVert3) + edgeVert4;\n float subpixNWSWNESE = lumaNWSW + lumaNESE;\n float lengthSign = fxaaQualityRcpFrame.x;\n bool horzSpan = edgeHorz >= edgeVert;\n float subpixA = subpixNSWE * 2.0 + subpixNWSWNESE;\n if(!horzSpan) lumaN = lumaW;\n if(!horzSpan) lumaS = lumaE;\n if(horzSpan) lengthSign = fxaaQualityRcpFrame.y;\n float subpixB = (subpixA * (1.0/12.0)) - rgbyM.y;\n float gradientN = lumaN - rgbyM.y;\n float gradientS = lumaS - rgbyM.y;\n float lumaNN = lumaN + rgbyM.y;\n float lumaSS = lumaS + rgbyM.y;\n bool pairN = abs(gradientN) >= abs(gradientS);\n float gradient = max(abs(gradientN), abs(gradientS));\n if(pairN) lengthSign = -lengthSign;\n float subpixC = clamp(abs(subpixB) * subpixRcpRange, 0.0, 1.0);\n vec2 posB;\n posB.x = posM.x;\n posB.y = posM.y;\n vec2 offNP;\n offNP.x = (!horzSpan) ? 0.0 : fxaaQualityRcpFrame.x;\n offNP.y = ( horzSpan) ? 0.0 : fxaaQualityRcpFrame.y;\n if(!horzSpan) posB.x += lengthSign * 0.5;\n if( horzSpan) posB.y += lengthSign * 0.5;\n vec2 posN;\n posN.x = posB.x - offNP.x * 1.0;\n posN.y = posB.y - offNP.y * 1.0;\n vec2 posP;\n posP.x = posB.x + offNP.x * 1.0;\n posP.y = posB.y + offNP.y * 1.0;\n float subpixD = ((-2.0)*subpixC) + 3.0;\n float lumaEndN = FxaaLuma(decodeHDR(texture2D(texture, posN, 0.0)));\n float subpixE = subpixC * subpixC;\n float lumaEndP = FxaaLuma(decodeHDR(texture2D(texture, posP, 0.0)));\n if(!pairN) lumaNN = lumaSS;\n float gradientScaled = gradient * 1.0/4.0;\n float lumaMM = rgbyM.y - lumaNN * 0.5;\n float subpixF = subpixD * subpixE;\n bool lumaMLTZero = lumaMM < 0.0;\n lumaEndN -= lumaNN * 0.5;\n lumaEndP -= lumaNN * 0.5;\n bool doneN = abs(lumaEndN) >= gradientScaled;\n bool doneP = abs(lumaEndP) >= gradientScaled;\n if(!doneN) posN.x -= offNP.x * 1.5;\n if(!doneN) posN.y -= offNP.y * 1.5;\n bool doneNP = (!doneN) || (!doneP);\n if(!doneP) posP.x += offNP.x * 1.5;\n if(!doneP) posP.y += offNP.y * 1.5;\n if(doneNP) {\n if(!doneN) lumaEndN = FxaaLuma(decodeHDR(texture2D(texture, posN.xy, 0.0)));\n if(!doneP) lumaEndP = FxaaLuma(decodeHDR(texture2D(texture, posP.xy, 0.0)));\n if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n doneN = abs(lumaEndN) >= gradientScaled;\n doneP = abs(lumaEndP) >= gradientScaled;\n if(!doneN) posN.x -= offNP.x * 2.0;\n if(!doneN) posN.y -= offNP.y * 2.0;\n doneNP = (!doneN) || (!doneP);\n if(!doneP) posP.x += offNP.x * 2.0;\n if(!doneP) posP.y += offNP.y * 2.0;\n\n if(doneNP) {\n if(!doneN) lumaEndN = FxaaLuma(decodeHDR(texture2D(texture, posN.xy, 0.0)));\n if(!doneP) lumaEndP = FxaaLuma(decodeHDR(texture2D(texture, posP.xy, 0.0)));\n if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n doneN = abs(lumaEndN) >= gradientScaled;\n doneP = abs(lumaEndP) >= gradientScaled;\n if(!doneN) posN.x -= offNP.x * 4.0;\n if(!doneN) posN.y -= offNP.y * 4.0;\n doneNP = (!doneN) || (!doneP);\n if(!doneP) posP.x += offNP.x * 4.0;\n if(!doneP) posP.y += offNP.y * 4.0;\n\n if(doneNP) {\n if(!doneN) lumaEndN = FxaaLuma(decodeHDR(texture2D(texture, posN.xy, 0.0)));\n if(!doneP) lumaEndP = FxaaLuma(decodeHDR(texture2D(texture, posP.xy, 0.0)));\n if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n doneN = abs(lumaEndN) >= gradientScaled;\n doneP = abs(lumaEndP) >= gradientScaled;\n if(!doneN) posN.x -= offNP.x * 12.0;\n if(!doneN) posN.y -= offNP.y * 12.0;\n doneNP = (!doneN) || (!doneP);\n if(!doneP) posP.x += offNP.x * 12.0;\n if(!doneP) posP.y += offNP.y * 12.0;\n }\n }\n }\n float dstN = posM.x - posN.x;\n float dstP = posP.x - posM.x;\n if(!horzSpan) dstN = posM.y - posN.y;\n if(!horzSpan) dstP = posP.y - posM.y;\n bool goodSpanN = (lumaEndN < 0.0) != lumaMLTZero;\n float spanLength = (dstP + dstN);\n bool goodSpanP = (lumaEndP < 0.0) != lumaMLTZero;\n float spanLengthRcp = 1.0/spanLength;\n bool directionN = dstN < dstP;\n float dst = min(dstN, dstP);\n bool goodSpan = directionN ? goodSpanN : goodSpanP;\n float subpixG = subpixF * subpixF;\n float pixelOffset = (dst * (-spanLengthRcp)) + 0.5;\n float subpixH = subpixG * fxaaQualitySubpix;\n float pixelOffsetGood = goodSpan ? pixelOffset : 0.0;\n float pixelOffsetSubpix = max(pixelOffsetGood, subpixH);\n if(!horzSpan) posM.x += pixelOffsetSubpix * lengthSign;\n if( horzSpan) posM.y += pixelOffsetSubpix * lengthSign;\n return vec4(decodeHDR(texture2D(texture, posM, 0.0)).xyz, rgbyM.y);\n\n}\n\nvoid main()\n{\n vec4 color = FxaaPixelShader(\n v_Texcoord,\n texture,\n vec2(1.0) / viewport.zw,\n subpixel,\n edgeThreshold,\n edgeThresholdMin\n );\n gl_FragColor = vec4(color.rgb, 1.0);\n}\n@end"; + module.exports = "@export qtek.compositor.fxaa3\n\nuniform sampler2D texture;\nuniform vec4 viewport : VIEWPORT;\n\nuniform float subpixel: 0.75;\nuniform float edgeThreshold: 0.125;\nuniform float edgeThresholdMin: 0.0625;\n\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n\nfloat FxaaLuma(vec4 rgba) { return rgba.y; }\nvec4 FxaaPixelShader(\n vec2 pos\n ,sampler2D tex\n ,vec2 fxaaQualityRcpFrame\n ,float fxaaQualitySubpix\n ,float fxaaQualityEdgeThreshold\n ,float fxaaQualityEdgeThresholdMin\n) {\n vec2 posM;\n posM.x = pos.x;\n posM.y = pos.y;\n vec4 rgbyM = decodeHDR(texture2D(texture, posM, 0.0));\n float lumaS = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2( 0.0, 1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaE = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2( 1.0, 0.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaN = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2( 0.0,-1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaW = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2(-1.0, 0.0) * fxaaQualityRcpFrame.xy), 0.0)));\n\n float maxSM = max(lumaS, rgbyM.y);\n float minSM = min(lumaS, rgbyM.y);\n float maxESM = max(lumaE, maxSM);\n float minESM = min(lumaE, minSM);\n float maxWN = max(lumaN, lumaW);\n float minWN = min(lumaN, lumaW);\n float rangeMax = max(maxWN, maxESM);\n float rangeMin = min(minWN, minESM);\n float rangeMaxScaled = rangeMax * fxaaQualityEdgeThreshold;\n float range = rangeMax - rangeMin;\n float rangeMaxClamped = max(fxaaQualityEdgeThresholdMin, rangeMaxScaled);\n bool earlyExit = range < rangeMaxClamped;\n if(earlyExit) return rgbyM;\n float lumaNW = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2(-1.0,-1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaSE = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2( 1.0, 1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaNE = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2( 1.0,-1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaSW = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2(-1.0, 1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n\n float lumaNS = lumaN + lumaS;\n float lumaWE = lumaW + lumaE;\n float subpixRcpRange = 1.0/range;\n float subpixNSWE = lumaNS + lumaWE;\n float edgeHorz1 = (-2.0 * rgbyM.y) + lumaNS;\n float edgeVert1 = (-2.0 * rgbyM.y) + lumaWE;\n float lumaNESE = lumaNE + lumaSE;\n float lumaNWNE = lumaNW + lumaNE;\n float edgeHorz2 = (-2.0 * lumaE) + lumaNESE;\n float edgeVert2 = (-2.0 * lumaN) + lumaNWNE;\n float lumaNWSW = lumaNW + lumaSW;\n float lumaSWSE = lumaSW + lumaSE;\n float edgeHorz4 = (abs(edgeHorz1) * 2.0) + abs(edgeHorz2);\n float edgeVert4 = (abs(edgeVert1) * 2.0) + abs(edgeVert2);\n float edgeHorz3 = (-2.0 * lumaW) + lumaNWSW;\n float edgeVert3 = (-2.0 * lumaS) + lumaSWSE;\n float edgeHorz = abs(edgeHorz3) + edgeHorz4;\n float edgeVert = abs(edgeVert3) + edgeVert4;\n float subpixNWSWNESE = lumaNWSW + lumaNESE;\n float lengthSign = fxaaQualityRcpFrame.x;\n bool horzSpan = edgeHorz >= edgeVert;\n float subpixA = subpixNSWE * 2.0 + subpixNWSWNESE;\n if(!horzSpan) lumaN = lumaW;\n if(!horzSpan) lumaS = lumaE;\n if(horzSpan) lengthSign = fxaaQualityRcpFrame.y;\n float subpixB = (subpixA * (1.0/12.0)) - rgbyM.y;\n float gradientN = lumaN - rgbyM.y;\n float gradientS = lumaS - rgbyM.y;\n float lumaNN = lumaN + rgbyM.y;\n float lumaSS = lumaS + rgbyM.y;\n bool pairN = abs(gradientN) >= abs(gradientS);\n float gradient = max(abs(gradientN), abs(gradientS));\n if(pairN) lengthSign = -lengthSign;\n float subpixC = clamp(abs(subpixB) * subpixRcpRange, 0.0, 1.0);\n vec2 posB;\n posB.x = posM.x;\n posB.y = posM.y;\n vec2 offNP;\n offNP.x = (!horzSpan) ? 0.0 : fxaaQualityRcpFrame.x;\n offNP.y = ( horzSpan) ? 0.0 : fxaaQualityRcpFrame.y;\n if(!horzSpan) posB.x += lengthSign * 0.5;\n if( horzSpan) posB.y += lengthSign * 0.5;\n vec2 posN;\n posN.x = posB.x - offNP.x * 1.0;\n posN.y = posB.y - offNP.y * 1.0;\n vec2 posP;\n posP.x = posB.x + offNP.x * 1.0;\n posP.y = posB.y + offNP.y * 1.0;\n float subpixD = ((-2.0)*subpixC) + 3.0;\n float lumaEndN = FxaaLuma(decodeHDR(texture2D(texture, posN, 0.0)));\n float subpixE = subpixC * subpixC;\n float lumaEndP = FxaaLuma(decodeHDR(texture2D(texture, posP, 0.0)));\n if(!pairN) lumaNN = lumaSS;\n float gradientScaled = gradient * 1.0/4.0;\n float lumaMM = rgbyM.y - lumaNN * 0.5;\n float subpixF = subpixD * subpixE;\n bool lumaMLTZero = lumaMM < 0.0;\n lumaEndN -= lumaNN * 0.5;\n lumaEndP -= lumaNN * 0.5;\n bool doneN = abs(lumaEndN) >= gradientScaled;\n bool doneP = abs(lumaEndP) >= gradientScaled;\n if(!doneN) posN.x -= offNP.x * 1.5;\n if(!doneN) posN.y -= offNP.y * 1.5;\n bool doneNP = (!doneN) || (!doneP);\n if(!doneP) posP.x += offNP.x * 1.5;\n if(!doneP) posP.y += offNP.y * 1.5;\n if(doneNP) {\n if(!doneN) lumaEndN = FxaaLuma(decodeHDR(texture2D(texture, posN.xy, 0.0)));\n if(!doneP) lumaEndP = FxaaLuma(decodeHDR(texture2D(texture, posP.xy, 0.0)));\n if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n doneN = abs(lumaEndN) >= gradientScaled;\n doneP = abs(lumaEndP) >= gradientScaled;\n if(!doneN) posN.x -= offNP.x * 2.0;\n if(!doneN) posN.y -= offNP.y * 2.0;\n doneNP = (!doneN) || (!doneP);\n if(!doneP) posP.x += offNP.x * 2.0;\n if(!doneP) posP.y += offNP.y * 2.0;\n\n if(doneNP) {\n if(!doneN) lumaEndN = FxaaLuma(decodeHDR(texture2D(texture, posN.xy, 0.0)));\n if(!doneP) lumaEndP = FxaaLuma(decodeHDR(texture2D(texture, posP.xy, 0.0)));\n if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n doneN = abs(lumaEndN) >= gradientScaled;\n doneP = abs(lumaEndP) >= gradientScaled;\n if(!doneN) posN.x -= offNP.x * 4.0;\n if(!doneN) posN.y -= offNP.y * 4.0;\n doneNP = (!doneN) || (!doneP);\n if(!doneP) posP.x += offNP.x * 4.0;\n if(!doneP) posP.y += offNP.y * 4.0;\n\n if(doneNP) {\n if(!doneN) lumaEndN = FxaaLuma(decodeHDR(texture2D(texture, posN.xy, 0.0)));\n if(!doneP) lumaEndP = FxaaLuma(decodeHDR(texture2D(texture, posP.xy, 0.0)));\n if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n doneN = abs(lumaEndN) >= gradientScaled;\n doneP = abs(lumaEndP) >= gradientScaled;\n if(!doneN) posN.x -= offNP.x * 12.0;\n if(!doneN) posN.y -= offNP.y * 12.0;\n doneNP = (!doneN) || (!doneP);\n if(!doneP) posP.x += offNP.x * 12.0;\n if(!doneP) posP.y += offNP.y * 12.0;\n }\n }\n }\n float dstN = posM.x - posN.x;\n float dstP = posP.x - posM.x;\n if(!horzSpan) dstN = posM.y - posN.y;\n if(!horzSpan) dstP = posP.y - posM.y;\n bool goodSpanN = (lumaEndN < 0.0) != lumaMLTZero;\n float spanLength = (dstP + dstN);\n bool goodSpanP = (lumaEndP < 0.0) != lumaMLTZero;\n float spanLengthRcp = 1.0/spanLength;\n bool directionN = dstN < dstP;\n float dst = min(dstN, dstP);\n bool goodSpan = directionN ? goodSpanN : goodSpanP;\n float subpixG = subpixF * subpixF;\n float pixelOffset = (dst * (-spanLengthRcp)) + 0.5;\n float subpixH = subpixG * fxaaQualitySubpix;\n float pixelOffsetGood = goodSpan ? pixelOffset : 0.0;\n float pixelOffsetSubpix = max(pixelOffsetGood, subpixH);\n if(!horzSpan) posM.x += pixelOffsetSubpix * lengthSign;\n if( horzSpan) posM.y += pixelOffsetSubpix * lengthSign;\n return vec4(decodeHDR(texture2D(texture, posM, 0.0)).xyz, rgbyM.y);\n\n}\n\nvoid main()\n{\n vec4 color = FxaaPixelShader(\n v_Texcoord,\n texture,\n vec2(1.0) / viewport.zw,\n subpixel,\n edgeThreshold,\n edgeThresholdMin\n );\n gl_FragColor = vec4(color.rgb, 1.0);\n}\n@end"; /***/ }, @@ -31179,7 +31174,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.particle.vertex\n\nuniform mat4 worldView : WORLDVIEW;\nuniform mat4 projection : PROJECTION;\n\nattribute vec3 position : POSITION;\nattribute vec3 normal : NORMAL;\n\n#ifdef UV_ANIMATION\nattribute vec2 texcoord0 : TEXCOORD_0;\nattribute vec2 texcoord1 : TEXCOORD_1;\n\nvarying vec2 v_Uv0;\nvarying vec2 v_Uv1;\n#endif\n\nvarying float v_Age;\n\nvoid main() {\n v_Age = normal.x;\n float rotation = normal.y;\n\n vec4 worldViewPosition = worldView * vec4(position, 1.0);\n gl_Position = projection * worldViewPosition;\n float w = gl_Position.w;\n gl_PointSize = normal.z * projection[0].x / w;\n\n #ifdef UV_ANIMATION\n v_Uv0 = texcoord0;\n v_Uv1 = texcoord1;\n #endif\n}\n\n@end\n\n@export qtek.particle.fragment\n\nuniform sampler2D sprite;\nuniform sampler2D gradient;\nuniform vec3 color : [1.0, 1.0, 1.0];\nuniform float alpha : 1.0;\n\nvarying float v_Age;\n\n#ifdef UV_ANIMATION\nvarying vec2 v_Uv0;\nvarying vec2 v_Uv1;\n#endif\n\nvoid main() {\n vec4 color = vec4(color, alpha);\n #ifdef SPRITE_ENABLED\n #ifdef UV_ANIMATION\n color *= texture2D(sprite, mix(v_Uv0, v_Uv1, gl_PointCoord));\n #else\n color *= texture2D(sprite, gl_PointCoord);\n #endif\n #endif\n #ifdef GRADIENT_ENABLED\n color *= texture2D(gradient, vec2(v_Age, 0.5));\n #endif\n gl_FragColor = color;\n}\n\n@end"; + module.exports = "@export qtek.particle.vertex\n\nuniform mat4 worldView : WORLDVIEW;\nuniform mat4 projection : PROJECTION;\n\nattribute vec3 position : POSITION;\nattribute vec3 normal : NORMAL;\n\n#ifdef UV_ANIMATION\nattribute vec2 texcoord0 : TEXCOORD_0;\nattribute vec2 texcoord1 : TEXCOORD_1;\n\nvarying vec2 v_Uv0;\nvarying vec2 v_Uv1;\n#endif\n\nvarying float v_Age;\n\nvoid main() {\n v_Age = normal.x;\n float rotation = normal.y;\n\n vec4 worldViewPosition = worldView * vec4(position, 1.0);\n gl_Position = projection * worldViewPosition;\n float w = gl_Position.w;\n gl_PointSize = normal.z * projection[0].x / w;\n\n #ifdef UV_ANIMATION\n v_Uv0 = texcoord0;\n v_Uv1 = texcoord1;\n #endif\n}\n\n@end\n\n@export qtek.particle.fragment\n\nuniform sampler2D sprite;\nuniform sampler2D gradient;\nuniform vec3 color : [1.0, 1.0, 1.0];\nuniform float alpha : 1.0;\n\nvarying float v_Age;\n\n#ifdef UV_ANIMATION\nvarying vec2 v_Uv0;\nvarying vec2 v_Uv1;\n#endif\n\nvoid main() {\n vec4 color = vec4(color, alpha);\n #ifdef SPRITE_ENABLED\n #ifdef UV_ANIMATION\n color *= texture2D(sprite, mix(v_Uv0, v_Uv1, gl_PointCoord));\n #else\n color *= texture2D(sprite, gl_PointCoord);\n #endif\n #endif\n #ifdef GRADIENT_ENABLED\n color *= texture2D(gradient, vec2(v_Age, 0.5));\n #endif\n gl_FragColor = color;\n}\n\n@end"; /***/ }, @@ -31375,7 +31370,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.picking.color.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvoid main(){\n\n vec3 skinnedPosition = position;\n\n #ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n #endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0);\n}\n\n@end\n\n@end\n@export qtek.picking.color.fragment\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\n\nvoid main() {\n gl_FragColor = color;\n}\n\n@end"; + module.exports = "@export qtek.picking.color.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvoid main(){\n\n vec3 skinnedPosition = position;\n\n #ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n #endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0);\n}\n\n@end\n\n@end\n@export qtek.picking.color.fragment\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\n\nvoid main() {\n gl_FragColor = color;\n}\n\n@end"; /***/ }, @@ -33206,7 +33201,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.sm.depth.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\n\n#ifdef SHADOW_TRANSPARENT\nattribute vec2 texcoord : TEXCOORD_0;\n#endif\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec4 v_ViewPosition;\n\n#ifdef SHADOW_TRANSPARENT\nvarying vec2 v_Texcoord;\n#endif\n\nvoid main(){\n\n vec3 skinnedPosition = position;\n\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n#endif\n\n v_ViewPosition = worldViewProjection * vec4(skinnedPosition, 1.0);\n gl_Position = v_ViewPosition;\n\n#ifdef SHADOW_TRANSPARENT\n v_Texcoord = texcoord;\n#endif\n}\n@end\n\n@export qtek.sm.depth.fragment\n\nvarying vec4 v_ViewPosition;\n\n#ifdef SHADOW_TRANSPARENT\nvarying vec2 v_Texcoord;\n#endif\n\nuniform float bias : 0.001;\nuniform float slopeScale : 1.0;\n\n#ifdef SHADOW_TRANSPARENT\nuniform sampler2D transparentMap;\n#endif\n\n@import qtek.util.encode_float\n\nvoid main(){\n float depth = v_ViewPosition.z / v_ViewPosition.w;\n \n#ifdef USE_VSM\n depth = depth * 0.5 + 0.5;\n float moment1 = depth;\n float moment2 = depth * depth;\n\n float dx = dFdx(depth);\n float dy = dFdy(depth);\n moment2 += 0.25*(dx*dx+dy*dy);\n\n gl_FragColor = vec4(moment1, moment2, 0.0, 1.0);\n#else\n float dx = dFdx(depth);\n float dy = dFdy(depth);\n depth += sqrt(dx*dx + dy*dy) * slopeScale + bias;\n\n#ifdef SHADOW_TRANSPARENT\n if (texture2D(transparentMap, v_Texcoord).a <= 0.1) {\n gl_FragColor = encodeFloat(0.9999);\n return;\n }\n#endif\n\n gl_FragColor = encodeFloat(depth * 0.5 + 0.5);\n#endif\n}\n@end\n\n@export qtek.sm.debug_depth\n\nuniform sampler2D depthMap;\nvarying vec2 v_Texcoord;\n\n@import qtek.util.decode_float\n\nvoid main() {\n vec4 tex = texture2D(depthMap, v_Texcoord);\n#ifdef USE_VSM\n gl_FragColor = vec4(tex.rgb, 1.0);\n#else\n float depth = decodeFloat(tex);\n gl_FragColor = vec4(depth, depth, depth, 1.0);\n#endif\n}\n\n@end\n\n\n@export qtek.sm.distance.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 world : WORLD;\n\nattribute vec3 position : POSITION;\n\n#ifdef SKINNING\nattribute vec3 boneWeight;\nattribute vec4 boneIndex;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec3 v_WorldPosition;\n\nvoid main (){\n\n vec3 skinnedPosition = position;\n#ifdef SKINNING\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n#endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition , 1.0);\n v_WorldPosition = (world * vec4(skinnedPosition, 1.0)).xyz;\n}\n\n@end\n\n@export qtek.sm.distance.fragment\n\nuniform vec3 lightPosition;\nuniform float range : 100;\n\nvarying vec3 v_WorldPosition;\n\n@import qtek.util.encode_float\n\nvoid main(){\n float dist = distance(lightPosition, v_WorldPosition);\n#ifdef USE_VSM\n gl_FragColor = vec4(dist, dist * dist, 0.0, 0.0);\n#else\n dist = dist / range;\n gl_FragColor = encodeFloat(dist);\n#endif\n}\n@end\n\n@export qtek.plugin.shadow_map_common\n\n@import qtek.util.decode_float\n\nfloat tapShadowMap(sampler2D map, vec2 uv, float z){\n vec4 tex = texture2D(map, uv);\n return step(z, decodeFloat(tex) * 2.0 - 1.0);\n}\n\nfloat pcf(sampler2D map, vec2 uv, float z, float textureSize, vec2 scale) {\n\n float shadowContrib = tapShadowMap(map, uv, z);\n vec2 offset = vec2(1.0 / textureSize) * scale;\n#ifdef PCF_KERNEL_SIZE\n for (int _idx_ = 0; _idx_ < PCF_KERNEL_SIZE; _idx_++) {{\n shadowContrib += tapShadowMap(map, uv + offset * pcfKernel[_idx_], z);\n }}\n\n return shadowContrib / float(PCF_KERNEL_SIZE + 1);\n#endif\n shadowContrib += tapShadowMap(map, uv+vec2(offset.x, 0.0), z);\n shadowContrib += tapShadowMap(map, uv+vec2(offset.x, offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(0.0, offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, 0.0), z);\n shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, -offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(offset.x, -offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(0.0, -offset.y), z);\n\n return shadowContrib;\n}\n\nfloat pcf(sampler2D map, vec2 uv, float z, float textureSize) {\n return pcf(map, uv, z, textureSize, vec2(1.0));\n}\n\nfloat chebyshevUpperBound(vec2 moments, float z){\n float p = 0.0;\n z = z * 0.5 + 0.5;\n if (z <= moments.x) {\n p = 1.0;\n }\n float variance = moments.y - moments.x * moments.x;\n variance = max(variance, 0.0000001);\n float mD = moments.x - z;\n float pMax = variance / (variance + mD * mD);\n pMax = clamp((pMax-0.4)/(1.0-0.4), 0.0, 1.0);\n return max(p, pMax);\n}\nfloat computeShadowContrib(\n sampler2D map, mat4 lightVPM, vec3 position, float textureSize, vec2 scale, vec2 offset\n) {\n\n vec4 posInLightSpace = lightVPM * vec4(position, 1.0);\n posInLightSpace.xyz /= posInLightSpace.w;\n float z = posInLightSpace.z;\n if(all(greaterThan(posInLightSpace.xyz, vec3(-0.99, -0.99, -1.0))) &&\n all(lessThan(posInLightSpace.xyz, vec3(0.99, 0.99, 1.0)))){\n vec2 uv = (posInLightSpace.xy+1.0) / 2.0;\n\n #ifdef USE_VSM\n vec2 moments = texture2D(map, uv * scale + offset).xy;\n return chebyshevUpperBound(moments, z);\n #else\n return pcf(map, uv * scale + offset, z, textureSize, scale);\n #endif\n }\n return 1.0;\n}\n\nfloat computeShadowContrib(sampler2D map, mat4 lightVPM, vec3 position, float textureSize) {\n return computeShadowContrib(map, lightVPM, position, textureSize, vec2(1.0), vec2(0.0));\n}\n\nfloat computeShadowContribOmni(samplerCube map, vec3 direction, float range)\n{\n float dist = length(direction);\n vec4 shadowTex = textureCube(map, direction);\n\n#ifdef USE_VSM\n vec2 moments = shadowTex.xy;\n float variance = moments.y - moments.x * moments.x;\n float mD = moments.x - dist;\n float p = variance / (variance + mD * mD);\n if(moments.x + 0.001 < dist){\n return clamp(p, 0.0, 1.0);\n }else{\n return 1.0;\n }\n#else\n return step(dist, (decodeFloat(shadowTex) + 0.0002) * range);\n#endif\n}\n\n@end\n\n\n\n@export qtek.plugin.compute_shadow_map\n\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT) || defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT) || defined(POINT_LIGHT_SHADOWMAP_COUNT)\n\n#ifdef SPOT_LIGHT_SHADOWMAP_COUNT\nuniform sampler2D spotLightShadowMaps[SPOT_LIGHT_SHADOWMAP_COUNT];\nuniform mat4 spotLightMatrices[SPOT_LIGHT_SHADOWMAP_COUNT];\nuniform float spotLightShadowMapSizes[SPOT_LIGHT_SHADOWMAP_COUNT];\n#endif\n\n#ifdef DIRECTIONAL_LIGHT_SHADOWMAP_COUNT\n#if defined(SHADOW_CASCADE)\nuniform sampler2D directionalLightShadowMaps[1];\nuniform mat4 directionalLightMatrices[SHADOW_CASCADE];\nuniform float directionalLightShadowMapSizes[1];\nuniform float shadowCascadeClipsNear[SHADOW_CASCADE];\nuniform float shadowCascadeClipsFar[SHADOW_CASCADE];\n#else\nuniform sampler2D directionalLightShadowMaps[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT];\nuniform mat4 directionalLightMatrices[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT];\nuniform float directionalLightShadowMapSizes[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT];\n#endif\n#endif\n\n#ifdef POINT_LIGHT_SHADOWMAP_COUNT\nuniform samplerCube pointLightShadowMaps[POINT_LIGHT_SHADOWMAP_COUNT];\nuniform float pointLightShadowMapSizes[POINT_LIGHT_SHADOWMAP_COUNT];\n#endif\n\nuniform bool shadowEnabled : true;\n\n#ifdef PCF_KERNEL_SIZE\nuniform vec2 pcfKernel[PCF_KERNEL_SIZE];\n#endif\n\n@import qtek.plugin.shadow_map_common\n\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\n\nvoid computeShadowOfSpotLights(vec3 position, inout float shadowContribs[SPOT_LIGHT_COUNT] ) {\n float shadowContrib;\n for(int _idx_ = 0; _idx_ < SPOT_LIGHT_SHADOWMAP_COUNT; _idx_++) {{\n shadowContrib = computeShadowContrib(\n spotLightShadowMaps[_idx_], spotLightMatrices[_idx_], position,\n spotLightShadowMapSizes[_idx_]\n );\n shadowContribs[_idx_] = shadowContrib;\n }}\n for(int _idx_ = SPOT_LIGHT_SHADOWMAP_COUNT; _idx_ < SPOT_LIGHT_COUNT; _idx_++){{\n shadowContribs[_idx_] = 1.0;\n }}\n}\n\n#endif\n\n\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n\n#ifdef SHADOW_CASCADE\n\nvoid computeShadowOfDirectionalLights(vec3 position, inout float shadowContribs[DIRECTIONAL_LIGHT_COUNT]){\n float depth = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far)\n / (gl_DepthRange.far - gl_DepthRange.near);\n\n float shadowContrib;\n shadowContribs[0] = 1.0;\n\n for (int _idx_ = 0; _idx_ < SHADOW_CASCADE; _idx_++) {{\n if (\n depth >= shadowCascadeClipsNear[_idx_] &&\n depth <= shadowCascadeClipsFar[_idx_]\n ) {\n shadowContrib = computeShadowContrib(\n directionalLightShadowMaps[0], directionalLightMatrices[_idx_], position,\n directionalLightShadowMapSizes[0],\n vec2(1.0 / float(SHADOW_CASCADE), 1.0),\n vec2(float(_idx_) / float(SHADOW_CASCADE), 0.0)\n );\n shadowContribs[0] = shadowContrib;\n }\n }}\n for(int _idx_ = DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++) {{\n shadowContribs[_idx_] = 1.0;\n }}\n}\n\n#else\n\nvoid computeShadowOfDirectionalLights(vec3 position, inout float shadowContribs[DIRECTIONAL_LIGHT_COUNT]){\n float shadowContrib;\n\n for(int _idx_ = 0; _idx_ < DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_++) {{\n shadowContrib = computeShadowContrib(\n directionalLightShadowMaps[_idx_], directionalLightMatrices[_idx_], position,\n directionalLightShadowMapSizes[_idx_]\n );\n shadowContribs[_idx_] = shadowContrib;\n }}\n for(int _idx_ = DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++) {{\n shadowContribs[_idx_] = 1.0;\n }}\n}\n#endif\n\n#endif\n\n\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\n\nvoid computeShadowOfPointLights(vec3 position, inout float shadowContribs[POINT_LIGHT_COUNT] ){\n vec3 lightPosition;\n vec3 direction;\n for(int _idx_ = 0; _idx_ < POINT_LIGHT_SHADOWMAP_COUNT; _idx_++) {{\n lightPosition = pointLightPosition[_idx_];\n direction = position - lightPosition;\n shadowContribs[_idx_] = computeShadowContribOmni(pointLightShadowMaps[_idx_], direction, pointLightRange[_idx_]);\n }}\n for(int _idx_ = POINT_LIGHT_SHADOWMAP_COUNT; _idx_ < POINT_LIGHT_COUNT; _idx_++) {{\n shadowContribs[_idx_] = 1.0;\n }}\n}\n\n#endif\n\n#endif\n\n@end"; + module.exports = "@export qtek.sm.depth.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\n\n#ifdef SHADOW_TRANSPARENT\nattribute vec2 texcoord : TEXCOORD_0;\n#endif\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec4 v_ViewPosition;\n\n#ifdef SHADOW_TRANSPARENT\nvarying vec2 v_Texcoord;\n#endif\n\nvoid main(){\n\n vec3 skinnedPosition = position;\n\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n#endif\n\n v_ViewPosition = worldViewProjection * vec4(skinnedPosition, 1.0);\n gl_Position = v_ViewPosition;\n\n#ifdef SHADOW_TRANSPARENT\n v_Texcoord = texcoord;\n#endif\n}\n@end\n\n@export qtek.sm.depth.fragment\n\nvarying vec4 v_ViewPosition;\n\n#ifdef SHADOW_TRANSPARENT\nvarying vec2 v_Texcoord;\n#endif\n\nuniform float bias : 0.001;\nuniform float slopeScale : 1.0;\n\n#ifdef SHADOW_TRANSPARENT\nuniform sampler2D transparentMap;\n#endif\n\n@import qtek.util.encode_float\n\nvoid main(){\n float depth = v_ViewPosition.z / v_ViewPosition.w;\n \n#ifdef USE_VSM\n depth = depth * 0.5 + 0.5;\n float moment1 = depth;\n float moment2 = depth * depth;\n\n float dx = dFdx(depth);\n float dy = dFdy(depth);\n moment2 += 0.25*(dx*dx+dy*dy);\n\n gl_FragColor = vec4(moment1, moment2, 0.0, 1.0);\n#else\n float dx = dFdx(depth);\n float dy = dFdy(depth);\n depth += sqrt(dx*dx + dy*dy) * slopeScale + bias;\n\n#ifdef SHADOW_TRANSPARENT\n if (texture2D(transparentMap, v_Texcoord).a <= 0.1) {\n gl_FragColor = encodeFloat(0.9999);\n return;\n }\n#endif\n\n gl_FragColor = encodeFloat(depth * 0.5 + 0.5);\n#endif\n}\n@end\n\n@export qtek.sm.debug_depth\n\nuniform sampler2D depthMap;\nvarying vec2 v_Texcoord;\n\n@import qtek.util.decode_float\n\nvoid main() {\n vec4 tex = texture2D(depthMap, v_Texcoord);\n#ifdef USE_VSM\n gl_FragColor = vec4(tex.rgb, 1.0);\n#else\n float depth = decodeFloat(tex);\n gl_FragColor = vec4(depth, depth, depth, 1.0);\n#endif\n}\n\n@end\n\n\n@export qtek.sm.distance.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 world : WORLD;\n\nattribute vec3 position : POSITION;\n\n#ifdef SKINNING\nattribute vec3 boneWeight;\nattribute vec4 boneIndex;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec3 v_WorldPosition;\n\nvoid main (){\n\n vec3 skinnedPosition = position;\n#ifdef SKINNING\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n#endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition , 1.0);\n v_WorldPosition = (world * vec4(skinnedPosition, 1.0)).xyz;\n}\n\n@end\n\n@export qtek.sm.distance.fragment\n\nuniform vec3 lightPosition;\nuniform float range : 100;\n\nvarying vec3 v_WorldPosition;\n\n@import qtek.util.encode_float\n\nvoid main(){\n float dist = distance(lightPosition, v_WorldPosition);\n#ifdef USE_VSM\n gl_FragColor = vec4(dist, dist * dist, 0.0, 0.0);\n#else\n dist = dist / range;\n gl_FragColor = encodeFloat(dist);\n#endif\n}\n@end\n\n@export qtek.plugin.shadow_map_common\n\n@import qtek.util.decode_float\n\nfloat tapShadowMap(sampler2D map, vec2 uv, float z){\n vec4 tex = texture2D(map, uv);\n return step(z, decodeFloat(tex) * 2.0 - 1.0);\n}\n\nfloat pcf(sampler2D map, vec2 uv, float z, float textureSize, vec2 scale) {\n\n float shadowContrib = tapShadowMap(map, uv, z);\n vec2 offset = vec2(1.0 / textureSize) * scale;\n#ifdef PCF_KERNEL_SIZE\n for (int _idx_ = 0; _idx_ < PCF_KERNEL_SIZE; _idx_++) {{\n shadowContrib += tapShadowMap(map, uv + offset * pcfKernel[_idx_], z);\n }}\n\n return shadowContrib / float(PCF_KERNEL_SIZE + 1);\n#endif\n shadowContrib += tapShadowMap(map, uv+vec2(offset.x, 0.0), z);\n shadowContrib += tapShadowMap(map, uv+vec2(offset.x, offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(0.0, offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, 0.0), z);\n shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, -offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(offset.x, -offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(0.0, -offset.y), z);\n\n return shadowContrib;\n}\n\nfloat pcf(sampler2D map, vec2 uv, float z, float textureSize) {\n return pcf(map, uv, z, textureSize, vec2(1.0));\n}\n\nfloat chebyshevUpperBound(vec2 moments, float z){\n float p = 0.0;\n z = z * 0.5 + 0.5;\n if (z <= moments.x) {\n p = 1.0;\n }\n float variance = moments.y - moments.x * moments.x;\n variance = max(variance, 0.0000001);\n float mD = moments.x - z;\n float pMax = variance / (variance + mD * mD);\n pMax = clamp((pMax-0.4)/(1.0-0.4), 0.0, 1.0);\n return max(p, pMax);\n}\nfloat computeShadowContrib(\n sampler2D map, mat4 lightVPM, vec3 position, float textureSize, vec2 scale, vec2 offset\n) {\n\n vec4 posInLightSpace = lightVPM * vec4(position, 1.0);\n posInLightSpace.xyz /= posInLightSpace.w;\n float z = posInLightSpace.z;\n if(all(greaterThan(posInLightSpace.xyz, vec3(-0.99, -0.99, -1.0))) &&\n all(lessThan(posInLightSpace.xyz, vec3(0.99, 0.99, 1.0)))){\n vec2 uv = (posInLightSpace.xy+1.0) / 2.0;\n\n #ifdef USE_VSM\n vec2 moments = texture2D(map, uv * scale + offset).xy;\n return chebyshevUpperBound(moments, z);\n #else\n return pcf(map, uv * scale + offset, z, textureSize, scale);\n #endif\n }\n return 1.0;\n}\n\nfloat computeShadowContrib(sampler2D map, mat4 lightVPM, vec3 position, float textureSize) {\n return computeShadowContrib(map, lightVPM, position, textureSize, vec2(1.0), vec2(0.0));\n}\n\nfloat computeShadowContribOmni(samplerCube map, vec3 direction, float range)\n{\n float dist = length(direction);\n vec4 shadowTex = textureCube(map, direction);\n\n#ifdef USE_VSM\n vec2 moments = shadowTex.xy;\n float variance = moments.y - moments.x * moments.x;\n float mD = moments.x - dist;\n float p = variance / (variance + mD * mD);\n if(moments.x + 0.001 < dist){\n return clamp(p, 0.0, 1.0);\n }else{\n return 1.0;\n }\n#else\n return step(dist, (decodeFloat(shadowTex) + 0.0002) * range);\n#endif\n}\n\n@end\n\n\n\n@export qtek.plugin.compute_shadow_map\n\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT) || defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT) || defined(POINT_LIGHT_SHADOWMAP_COUNT)\n\n#ifdef SPOT_LIGHT_SHADOWMAP_COUNT\nuniform sampler2D spotLightShadowMaps[SPOT_LIGHT_SHADOWMAP_COUNT];\nuniform mat4 spotLightMatrices[SPOT_LIGHT_SHADOWMAP_COUNT];\nuniform float spotLightShadowMapSizes[SPOT_LIGHT_SHADOWMAP_COUNT];\n#endif\n\n#ifdef DIRECTIONAL_LIGHT_SHADOWMAP_COUNT\n#if defined(SHADOW_CASCADE)\nuniform sampler2D directionalLightShadowMaps[1];\nuniform mat4 directionalLightMatrices[SHADOW_CASCADE];\nuniform float directionalLightShadowMapSizes[1];\nuniform float shadowCascadeClipsNear[SHADOW_CASCADE];\nuniform float shadowCascadeClipsFar[SHADOW_CASCADE];\n#else\nuniform sampler2D directionalLightShadowMaps[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT];\nuniform mat4 directionalLightMatrices[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT];\nuniform float directionalLightShadowMapSizes[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT];\n#endif\n#endif\n\n#ifdef POINT_LIGHT_SHADOWMAP_COUNT\nuniform samplerCube pointLightShadowMaps[POINT_LIGHT_SHADOWMAP_COUNT];\nuniform float pointLightShadowMapSizes[POINT_LIGHT_SHADOWMAP_COUNT];\n#endif\n\nuniform bool shadowEnabled : true;\n\n#ifdef PCF_KERNEL_SIZE\nuniform vec2 pcfKernel[PCF_KERNEL_SIZE];\n#endif\n\n@import qtek.plugin.shadow_map_common\n\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\n\nvoid computeShadowOfSpotLights(vec3 position, inout float shadowContribs[SPOT_LIGHT_COUNT] ) {\n float shadowContrib;\n for(int _idx_ = 0; _idx_ < SPOT_LIGHT_SHADOWMAP_COUNT; _idx_++) {{\n shadowContrib = computeShadowContrib(\n spotLightShadowMaps[_idx_], spotLightMatrices[_idx_], position,\n spotLightShadowMapSizes[_idx_]\n );\n shadowContribs[_idx_] = shadowContrib;\n }}\n for(int _idx_ = SPOT_LIGHT_SHADOWMAP_COUNT; _idx_ < SPOT_LIGHT_COUNT; _idx_++){{\n shadowContribs[_idx_] = 1.0;\n }}\n}\n\n#endif\n\n\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n\n#ifdef SHADOW_CASCADE\n\nvoid computeShadowOfDirectionalLights(vec3 position, inout float shadowContribs[DIRECTIONAL_LIGHT_COUNT]){\n float depth = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far)\n / (gl_DepthRange.far - gl_DepthRange.near);\n\n float shadowContrib;\n shadowContribs[0] = 1.0;\n\n for (int _idx_ = 0; _idx_ < SHADOW_CASCADE; _idx_++) {{\n if (\n depth >= shadowCascadeClipsNear[_idx_] &&\n depth <= shadowCascadeClipsFar[_idx_]\n ) {\n shadowContrib = computeShadowContrib(\n directionalLightShadowMaps[0], directionalLightMatrices[_idx_], position,\n directionalLightShadowMapSizes[0],\n vec2(1.0 / float(SHADOW_CASCADE), 1.0),\n vec2(float(_idx_) / float(SHADOW_CASCADE), 0.0)\n );\n shadowContribs[0] = shadowContrib;\n }\n }}\n for(int _idx_ = DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++) {{\n shadowContribs[_idx_] = 1.0;\n }}\n}\n\n#else\n\nvoid computeShadowOfDirectionalLights(vec3 position, inout float shadowContribs[DIRECTIONAL_LIGHT_COUNT]){\n float shadowContrib;\n\n for(int _idx_ = 0; _idx_ < DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_++) {{\n shadowContrib = computeShadowContrib(\n directionalLightShadowMaps[_idx_], directionalLightMatrices[_idx_], position,\n directionalLightShadowMapSizes[_idx_]\n );\n shadowContribs[_idx_] = shadowContrib;\n }}\n for(int _idx_ = DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++) {{\n shadowContribs[_idx_] = 1.0;\n }}\n}\n#endif\n\n#endif\n\n\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\n\nvoid computeShadowOfPointLights(vec3 position, inout float shadowContribs[POINT_LIGHT_COUNT] ){\n vec3 lightPosition;\n vec3 direction;\n for(int _idx_ = 0; _idx_ < POINT_LIGHT_SHADOWMAP_COUNT; _idx_++) {{\n lightPosition = pointLightPosition[_idx_];\n direction = position - lightPosition;\n shadowContribs[_idx_] = computeShadowContribOmni(pointLightShadowMaps[_idx_], direction, pointLightRange[_idx_]);\n }}\n for(int _idx_ = POINT_LIGHT_SHADOWMAP_COUNT; _idx_ < POINT_LIGHT_COUNT; _idx_++) {{\n shadowContribs[_idx_] = 1.0;\n }}\n}\n\n#endif\n\n#endif\n\n@end"; /***/ }, @@ -34213,7 +34208,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "uniform samplerCube environmentMap;\n\nvarying vec2 v_Texcoord;\n\n#define TEXTURE_SIZE 16\n\nmat3 front = mat3(\n 1.0, 0.0, 0.0,\n 0.0, 1.0, 0.0,\n 0.0, 0.0, 1.0\n);\n\nmat3 back = mat3(\n -1.0, 0.0, 0.0,\n 0.0, 1.0, 0.0,\n 0.0, 0.0, -1.0\n);\n\nmat3 left = mat3(\n 0.0, 0.0, -1.0,\n 0.0, 1.0, 0.0,\n 1.0, 0.0, 0.0\n);\n\nmat3 right = mat3(\n 0.0, 0.0, 1.0,\n 0.0, 1.0, 0.0,\n -1.0, 0.0, 0.0\n);\n\nmat3 up = mat3(\n 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0,\n 0.0, -1.0, 0.0\n);\n\nmat3 down = mat3(\n 1.0, 0.0, 0.0,\n 0.0, 0.0, -1.0,\n 0.0, 1.0, 0.0\n);\n\n\nfloat harmonics(vec3 normal){\n int index = int(gl_FragCoord.x);\n\n float x = normal.x;\n float y = normal.y;\n float z = normal.z;\n\n if(index==0){\n return 1.0;\n }\n else if(index==1){\n return x;\n }\n else if(index==2){\n return y;\n }\n else if(index==3){\n return z;\n }\n else if(index==4){\n return x*z;\n }\n else if(index==5){\n return y*z;\n }\n else if(index==6){\n return x*y;\n }\n else if(index==7){\n return 3.0*z*z - 1.0;\n }\n else{\n return x*x - y*y;\n }\n}\n\nvec3 sampleSide(mat3 rot)\n{\n\n vec3 result = vec3(0.0);\n float divider = 0.0;\n for (int i = 0; i < TEXTURE_SIZE * TEXTURE_SIZE; i++) {\n float x = mod(float(i), float(TEXTURE_SIZE));\n float y = float(i / TEXTURE_SIZE);\n\n vec2 sidecoord = ((vec2(x, y) + vec2(0.5, 0.5)) / vec2(TEXTURE_SIZE)) * 2.0 - 1.0;\n vec3 normal = normalize(vec3(sidecoord, -1.0));\n vec3 fetchNormal = rot * normal;\n vec3 texel = textureCube(environmentMap, fetchNormal).rgb;\n\n result += harmonics(fetchNormal) * texel * -normal.z;\n\n divider += -normal.z;\n }\n\n return result / divider;\n}\n\nvoid main()\n{\n vec3 result = (\n sampleSide(front) +\n sampleSide(back) +\n sampleSide(left) +\n sampleSide(right) +\n sampleSide(up) +\n sampleSide(down)\n ) / 6.0;\n gl_FragColor = vec4(result, 1.0);\n}"; + module.exports = "uniform samplerCube environmentMap;\n\nvarying vec2 v_Texcoord;\n\n#define TEXTURE_SIZE 16\n\nmat3 front = mat3(\n 1.0, 0.0, 0.0,\n 0.0, 1.0, 0.0,\n 0.0, 0.0, 1.0\n);\n\nmat3 back = mat3(\n -1.0, 0.0, 0.0,\n 0.0, 1.0, 0.0,\n 0.0, 0.0, -1.0\n);\n\nmat3 left = mat3(\n 0.0, 0.0, -1.0,\n 0.0, 1.0, 0.0,\n 1.0, 0.0, 0.0\n);\n\nmat3 right = mat3(\n 0.0, 0.0, 1.0,\n 0.0, 1.0, 0.0,\n -1.0, 0.0, 0.0\n);\n\nmat3 up = mat3(\n 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0,\n 0.0, -1.0, 0.0\n);\n\nmat3 down = mat3(\n 1.0, 0.0, 0.0,\n 0.0, 0.0, -1.0,\n 0.0, 1.0, 0.0\n);\n\n\nfloat harmonics(vec3 normal){\n int index = int(gl_FragCoord.x);\n\n float x = normal.x;\n float y = normal.y;\n float z = normal.z;\n\n if(index==0){\n return 1.0;\n }\n else if(index==1){\n return x;\n }\n else if(index==2){\n return y;\n }\n else if(index==3){\n return z;\n }\n else if(index==4){\n return x*z;\n }\n else if(index==5){\n return y*z;\n }\n else if(index==6){\n return x*y;\n }\n else if(index==7){\n return 3.0*z*z - 1.0;\n }\n else{\n return x*x - y*y;\n }\n}\n\nvec3 sampleSide(mat3 rot)\n{\n\n vec3 result = vec3(0.0);\n float divider = 0.0;\n for (int i = 0; i < TEXTURE_SIZE * TEXTURE_SIZE; i++) {\n float x = mod(float(i), float(TEXTURE_SIZE));\n float y = float(i / TEXTURE_SIZE);\n\n vec2 sidecoord = ((vec2(x, y) + vec2(0.5, 0.5)) / vec2(TEXTURE_SIZE)) * 2.0 - 1.0;\n vec3 normal = normalize(vec3(sidecoord, -1.0));\n vec3 fetchNormal = rot * normal;\n vec3 texel = textureCube(environmentMap, fetchNormal).rgb;\n\n result += harmonics(fetchNormal) * texel * -normal.z;\n\n divider += -normal.z;\n }\n\n return result / divider;\n}\n\nvoid main()\n{\n vec3 result = (\n sampleSide(front) +\n sampleSide(back) +\n sampleSide(left) +\n sampleSide(right) +\n sampleSide(up) +\n sampleSide(down)\n ) / 6.0;\n gl_FragColor = vec4(result, 1.0);\n}"; /***/ }, @@ -34221,7 +34216,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = '0.3.6'; + module.exports = '0.3.7'; /***/ }, @@ -34423,7 +34418,7 @@ return /******/ (function(modules) { // webpackBootstrap /***/ function(module, exports) { - module.exports = "@export qtek.vr.disorter.output.vertex\n\nattribute vec2 texcoord: TEXCOORD_0;\nattribute vec3 position: POSITION;\n\nvarying vec2 v_Texcoord;\n\nvoid main()\n{\n\n v_Texcoord = texcoord;\n\n gl_Position = vec4(position.xy, 0.5, 1.0);\n}\n\n@end\n\n@export qtek.vr.disorter.output.fragment\n\nuniform sampler2D texture;\n\nvarying vec2 v_Texcoord;\n\nvoid main()\n{\n gl_FragColor = texture2D(texture, v_Texcoord);\n}\n@end"; + module.exports = "@export qtek.vr.disorter.output.vertex\n\nattribute vec2 texcoord: TEXCOORD_0;\nattribute vec3 position: POSITION;\n\nvarying vec2 v_Texcoord;\n\nvoid main()\n{\n\n v_Texcoord = texcoord;\n\n gl_Position = vec4(position.xy, 0.5, 1.0);\n}\n\n@end\n\n@export qtek.vr.disorter.output.fragment\n\nuniform sampler2D texture;\n\nvarying vec2 v_Texcoord;\n\nvoid main()\n{\n gl_FragColor = texture2D(texture, v_Texcoord);\n}\n@end"; /***/ }, diff --git a/dist/qtek.min.js b/dist/qtek.min.js index 6de18dea8..01e69123e 100644 --- a/dist/qtek.min.js +++ b/dist/qtek.min.js @@ -1,13 +1,13 @@ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.qtek=e():t.qtek=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){t.exports=n(116)},function(t,e,n){!function(t){"use strict";var n={};n.exports=e,function(t){if(!e)var e=1e-6;if(!n)var n="undefined"!=typeof Float32Array?Float32Array:Array;if(!r)var r=Math.random;var i={};i.setMatrixArrayType=function(t){n=t},"undefined"!=typeof t&&(t.glMatrix=i);var a=Math.PI/180;i.toRadian=function(t){return t*a};var o={};o.create=function(){var t=new n(2);return t[0]=0,t[1]=0,t},o.clone=function(t){var e=new n(2);return e[0]=t[0],e[1]=t[1],e},o.fromValues=function(t,e){var r=new n(2);return r[0]=t,r[1]=e,r},o.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t},o.set=function(t,e,n){return t[0]=e,t[1]=n,t},o.add=function(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t},o.subtract=function(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t},o.sub=o.subtract,o.multiply=function(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t},o.mul=o.multiply,o.divide=function(t,e,n){return t[0]=e[0]/n[0],t[1]=e[1]/n[1],t},o.div=o.divide,o.min=function(t,e,n){return t[0]=Math.min(e[0],n[0]),t[1]=Math.min(e[1],n[1]),t},o.max=function(t,e,n){return t[0]=Math.max(e[0],n[0]),t[1]=Math.max(e[1],n[1]),t},o.scale=function(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t},o.scaleAndAdd=function(t,e,n,r){return t[0]=e[0]+n[0]*r,t[1]=e[1]+n[1]*r,t},o.distance=function(t,e){var n=e[0]-t[0],r=e[1]-t[1];return Math.sqrt(n*n+r*r)},o.dist=o.distance,o.squaredDistance=function(t,e){var n=e[0]-t[0],r=e[1]-t[1];return n*n+r*r},o.sqrDist=o.squaredDistance,o.length=function(t){var e=t[0],n=t[1];return Math.sqrt(e*e+n*n)},o.len=o.length,o.squaredLength=function(t){var e=t[0],n=t[1];return e*e+n*n},o.sqrLen=o.squaredLength,o.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t},o.inverse=function(t,e){return t[0]=1/e[0],t[1]=1/e[1],t},o.normalize=function(t,e){var n=e[0],r=e[1],i=n*n+r*r;return i>0&&(i=1/Math.sqrt(i),t[0]=e[0]*i,t[1]=e[1]*i),t},o.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]},o.cross=function(t,e,n){var r=e[0]*n[1]-e[1]*n[0];return t[0]=t[1]=0,t[2]=r,t},o.lerp=function(t,e,n,r){var i=e[0],a=e[1];return t[0]=i+r*(n[0]-i),t[1]=a+r*(n[1]-a),t},o.random=function(t,e){e=e||1;var n=2*r()*Math.PI;return t[0]=Math.cos(n)*e,t[1]=Math.sin(n)*e,t},o.transformMat2=function(t,e,n){var r=e[0],i=e[1];return t[0]=n[0]*r+n[2]*i,t[1]=n[1]*r+n[3]*i,t},o.transformMat2d=function(t,e,n){var r=e[0],i=e[1];return t[0]=n[0]*r+n[2]*i+n[4],t[1]=n[1]*r+n[3]*i+n[5],t},o.transformMat3=function(t,e,n){var r=e[0],i=e[1];return t[0]=n[0]*r+n[3]*i+n[6],t[1]=n[1]*r+n[4]*i+n[7],t},o.transformMat4=function(t,e,n){var r=e[0],i=e[1];return t[0]=n[0]*r+n[4]*i+n[12],t[1]=n[1]*r+n[5]*i+n[13],t},o.forEach=function(){var t=o.create();return function(e,n,r,i,a,o){var s,u;for(n||(n=2),r||(r=0),u=i?Math.min(i*n+r,e.length):e.length,s=r;s0&&(a=1/Math.sqrt(a),t[0]=e[0]*a,t[1]=e[1]*a,t[2]=e[2]*a),t},s.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]},s.cross=function(t,e,n){var r=e[0],i=e[1],a=e[2],o=n[0],s=n[1],u=n[2];return t[0]=i*u-a*s,t[1]=a*o-r*u,t[2]=r*s-i*o,t},s.lerp=function(t,e,n,r){var i=e[0],a=e[1],o=e[2];return t[0]=i+r*(n[0]-i),t[1]=a+r*(n[1]-a),t[2]=o+r*(n[2]-o),t},s.random=function(t,e){e=e||1;var n=2*r()*Math.PI,i=2*r()-1,a=Math.sqrt(1-i*i)*e;return t[0]=Math.cos(n)*a,t[1]=Math.sin(n)*a,t[2]=i*e,t},s.transformMat4=function(t,e,n){var r=e[0],i=e[1],a=e[2],o=n[3]*r+n[7]*i+n[11]*a+n[15];return o=o||1,t[0]=(n[0]*r+n[4]*i+n[8]*a+n[12])/o,t[1]=(n[1]*r+n[5]*i+n[9]*a+n[13])/o,t[2]=(n[2]*r+n[6]*i+n[10]*a+n[14])/o,t},s.transformMat3=function(t,e,n){var r=e[0],i=e[1],a=e[2];return t[0]=r*n[0]+i*n[3]+a*n[6],t[1]=r*n[1]+i*n[4]+a*n[7],t[2]=r*n[2]+i*n[5]+a*n[8],t},s.transformQuat=function(t,e,n){var r=e[0],i=e[1],a=e[2],o=n[0],s=n[1],u=n[2],l=n[3],c=l*r+s*a-u*i,h=l*i+u*r-o*a,f=l*a+o*i-s*r,d=-o*r-s*i-u*a;return t[0]=c*l+d*-o+h*-u-f*-s,t[1]=h*l+d*-s+f*-o-c*-u,t[2]=f*l+d*-u+c*-s-h*-o,t},s.rotateX=function(t,e,n,r){var i=[],a=[];return i[0]=e[0]-n[0],i[1]=e[1]-n[1],i[2]=e[2]-n[2],a[0]=i[0],a[1]=i[1]*Math.cos(r)-i[2]*Math.sin(r),a[2]=i[1]*Math.sin(r)+i[2]*Math.cos(r),t[0]=a[0]+n[0],t[1]=a[1]+n[1],t[2]=a[2]+n[2],t},s.rotateY=function(t,e,n,r){var i=[],a=[];return i[0]=e[0]-n[0],i[1]=e[1]-n[1],i[2]=e[2]-n[2],a[0]=i[2]*Math.sin(r)+i[0]*Math.cos(r),a[1]=i[1],a[2]=i[2]*Math.cos(r)-i[0]*Math.sin(r),t[0]=a[0]+n[0],t[1]=a[1]+n[1],t[2]=a[2]+n[2],t},s.rotateZ=function(t,e,n,r){var i=[],a=[];return i[0]=e[0]-n[0],i[1]=e[1]-n[1],i[2]=e[2]-n[2],a[0]=i[0]*Math.cos(r)-i[1]*Math.sin(r),a[1]=i[0]*Math.sin(r)+i[1]*Math.cos(r),a[2]=i[2],t[0]=a[0]+n[0],t[1]=a[1]+n[1],t[2]=a[2]+n[2],t},s.forEach=function(){var t=s.create();return function(e,n,r,i,a,o){var s,u;for(n||(n=3),r||(r=0),u=i?Math.min(i*n+r,e.length):e.length,s=r;s1?0:Math.acos(i)},s.str=function(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"},"undefined"!=typeof t&&(t.vec3=s);var u={};u.create=function(){var t=new n(4);return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t},u.clone=function(t){var e=new n(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},u.fromValues=function(t,e,r,i){var a=new n(4);return a[0]=t,a[1]=e,a[2]=r,a[3]=i,a},u.copy=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},u.set=function(t,e,n,r,i){return t[0]=e,t[1]=n,t[2]=r,t[3]=i,t},u.add=function(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t[3]=e[3]+n[3],t},u.subtract=function(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t[3]=e[3]-n[3],t},u.sub=u.subtract,u.multiply=function(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t[3]=e[3]*n[3],t},u.mul=u.multiply,u.divide=function(t,e,n){return t[0]=e[0]/n[0],t[1]=e[1]/n[1],t[2]=e[2]/n[2],t[3]=e[3]/n[3],t},u.div=u.divide,u.min=function(t,e,n){return t[0]=Math.min(e[0],n[0]),t[1]=Math.min(e[1],n[1]),t[2]=Math.min(e[2],n[2]),t[3]=Math.min(e[3],n[3]),t},u.max=function(t,e,n){return t[0]=Math.max(e[0],n[0]),t[1]=Math.max(e[1],n[1]),t[2]=Math.max(e[2],n[2]),t[3]=Math.max(e[3],n[3]),t},u.scale=function(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t},u.scaleAndAdd=function(t,e,n,r){return t[0]=e[0]+n[0]*r,t[1]=e[1]+n[1]*r,t[2]=e[2]+n[2]*r,t[3]=e[3]+n[3]*r,t},u.distance=function(t,e){var n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2],a=e[3]-t[3];return Math.sqrt(n*n+r*r+i*i+a*a)},u.dist=u.distance,u.squaredDistance=function(t,e){var n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2],a=e[3]-t[3];return n*n+r*r+i*i+a*a},u.sqrDist=u.squaredDistance,u.length=function(t){var e=t[0],n=t[1],r=t[2],i=t[3];return Math.sqrt(e*e+n*n+r*r+i*i)},u.len=u.length,u.squaredLength=function(t){var e=t[0],n=t[1],r=t[2],i=t[3];return e*e+n*n+r*r+i*i},u.sqrLen=u.squaredLength,u.negate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t},u.inverse=function(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t[3]=1/e[3],t},u.normalize=function(t,e){var n=e[0],r=e[1],i=e[2],a=e[3],o=n*n+r*r+i*i+a*a;return o>0&&(o=1/Math.sqrt(o),t[0]=e[0]*o,t[1]=e[1]*o,t[2]=e[2]*o,t[3]=e[3]*o),t},u.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]},u.lerp=function(t,e,n,r){var i=e[0],a=e[1],o=e[2],s=e[3];return t[0]=i+r*(n[0]-i),t[1]=a+r*(n[1]-a),t[2]=o+r*(n[2]-o),t[3]=s+r*(n[3]-s),t},u.random=function(t,e){return e=e||1,t[0]=r(),t[1]=r(),t[2]=r(),t[3]=r(),u.normalize(t,t),u.scale(t,t,e),t},u.transformMat4=function(t,e,n){var r=e[0],i=e[1],a=e[2],o=e[3];return t[0]=n[0]*r+n[4]*i+n[8]*a+n[12]*o,t[1]=n[1]*r+n[5]*i+n[9]*a+n[13]*o,t[2]=n[2]*r+n[6]*i+n[10]*a+n[14]*o,t[3]=n[3]*r+n[7]*i+n[11]*a+n[15]*o,t},u.transformQuat=function(t,e,n){var r=e[0],i=e[1],a=e[2],o=n[0],s=n[1],u=n[2],l=n[3],c=l*r+s*a-u*i,h=l*i+u*r-o*a,f=l*a+o*i-s*r,d=-o*r-s*i-u*a;return t[0]=c*l+d*-o+h*-u-f*-s,t[1]=h*l+d*-s+f*-o-c*-u,t[2]=f*l+d*-u+c*-s-h*-o,t},u.forEach=function(){var t=u.create();return function(e,n,r,i,a,o){var s,u;for(n||(n=4),r||(r=0),u=i?Math.min(i*n+r,e.length):e.length,s=r;s.999999?(r[0]=0,r[1]=0,r[2]=0,r[3]=1,r):(s.cross(t,i,a),r[0]=t[0],r[1]=t[1],r[2]=t[2],r[3]=1+o,d.normalize(r,r))}}(),d.setAxes=function(){var t=h.create();return function(e,n,r,i){return t[0]=r[0],t[3]=r[1],t[6]=r[2],t[1]=i[0],t[4]=i[1],t[7]=i[2],t[2]=-n[0],t[5]=-n[1],t[8]=-n[2],d.normalize(e,d.fromMat3(e,t))}}(),d.clone=u.clone,d.fromValues=u.fromValues,d.copy=u.copy,d.set=u.set,d.identity=function(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t},d.setAxisAngle=function(t,e,n){n=.5*n;var r=Math.sin(n);return t[0]=r*e[0],t[1]=r*e[1],t[2]=r*e[2],t[3]=Math.cos(n),t},d.add=u.add,d.multiply=function(t,e,n){var r=e[0],i=e[1],a=e[2],o=e[3],s=n[0],u=n[1],l=n[2],c=n[3];return t[0]=r*c+o*s+i*l-a*u,t[1]=i*c+o*u+a*s-r*l,t[2]=a*c+o*l+r*u-i*s,t[3]=o*c-r*s-i*u-a*l,t},d.mul=d.multiply,d.scale=u.scale,d.rotateX=function(t,e,n){n*=.5;var r=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(n),u=Math.cos(n);return t[0]=r*u+o*s,t[1]=i*u+a*s,t[2]=a*u-i*s,t[3]=o*u-r*s,t},d.rotateY=function(t,e,n){n*=.5;var r=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(n),u=Math.cos(n);return t[0]=r*u-a*s,t[1]=i*u+o*s,t[2]=a*u+r*s,t[3]=o*u-i*s,t},d.rotateZ=function(t,e,n){n*=.5;var r=e[0],i=e[1],a=e[2],o=e[3],s=Math.sin(n),u=Math.cos(n);return t[0]=r*u+i*s,t[1]=i*u-r*s,t[2]=a*u+o*s,t[3]=o*u-a*s,t},d.calculateW=function(t,e){var n=e[0],r=e[1],i=e[2];return t[0]=n,t[1]=r,t[2]=i,t[3]=Math.sqrt(Math.abs(1-n*n-r*r-i*i)),t},d.dot=u.dot,d.lerp=u.lerp,d.slerp=function(t,e,n,r){var i,a,o,s,u,l=e[0],c=e[1],h=e[2],f=e[3],d=n[0],_=n[1],p=n[2],m=n[3];return a=l*d+c*_+h*p+f*m,a<0&&(a=-a,d=-d,_=-_,p=-p,m=-m),1-a>1e-6?(i=Math.acos(a),o=Math.sin(i),s=Math.sin((1-r)*i)/o,u=Math.sin(r*i)/o):(s=1-r,u=r),t[0]=s*l+u*d,t[1]=s*c+u*_,t[2]=s*h+u*p,t[3]=s*f+u*m,t},d.invert=function(t,e){var n=e[0],r=e[1],i=e[2],a=e[3],o=n*n+r*r+i*i+a*a,s=o?1/o:0;return t[0]=-n*s,t[1]=-r*s,t[2]=-i*s,t[3]=a*s,t},d.conjugate=function(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t},d.length=u.length,d.len=d.length,d.squaredLength=u.squaredLength,d.sqrLen=d.squaredLength,d.normalize=u.normalize,d.fromMat3=function(t,e){var n,r=e[0]+e[4]+e[8];if(r>0)n=Math.sqrt(r+1),t[3]=.5*n,n=.5/n,t[0]=(e[5]-e[7])*n,t[1]=(e[6]-e[2])*n,t[2]=(e[1]-e[3])*n;else{var i=0;e[4]>e[0]&&(i=1),e[8]>e[3*i+i]&&(i=2);var a=(i+1)%3,o=(i+2)%3;n=Math.sqrt(e[3*i+i]-e[3*a+a]-e[3*o+o]+1),t[i]=.5*n,n=.5/n,t[3]=(e[3*a+o]-e[3*o+a])*n,t[a]=(e[3*a+i]+e[3*i+a])*n,t[o]=(e[3*o+i]+e[3*i+o])*n}return t},d.str=function(t){return"quat("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"},"undefined"!=typeof t&&(t.quat=d)}(n.exports)}(this)},function(t,e,n){"use strict";var r=n(67),i=n(40),a=n(17),o=function(){this.__GUID__=a.genGUID()};o.__initializers__=[function(t){a.extend(this,t)}],a.extend(o,r),a.extend(o.prototype,i),t.exports=o},function(t,e,n){"use strict";function r(t,e,n){return tn?n:t}var i=n(1),a=i.vec3,o=function(t,e,n){t=t||0,e=e||0,n=n||0,this._array=a.fromValues(t,e,n),this._dirty=!0};o.prototype={constructor:o,add:function(t){return a.add(this._array,this._array,t._array),this._dirty=!0,this},set:function(t,e,n){return this._array[0]=t,this._array[1]=e,this._array[2]=n,this._dirty=!0,this},setArray:function(t){return this._array[0]=t[0],this._array[1]=t[1],this._array[2]=t[2],this._dirty=!0,this},clone:function(){return new o(this.x,this.y,this.z)},copy:function(t){return a.copy(this._array,t._array),this._dirty=!0,this},cross:function(t,e){return a.cross(this._array,t._array,e._array),this._dirty=!0,this},dist:function(t){return a.dist(this._array,t._array)},distance:function(t){return a.distance(this._array,t._array)},div:function(t){return a.div(this._array,this._array,t._array),this._dirty=!0,this},divide:function(t){return a.divide(this._array,this._array,t._array),this._dirty=!0,this},dot:function(t){return a.dot(this._array,t._array)},len:function(){return a.len(this._array)},length:function(){return a.length(this._array)},lerp:function(t,e,n){return a.lerp(this._array,t._array,e._array,n),this._dirty=!0,this},min:function(t){return a.min(this._array,this._array,t._array),this._dirty=!0,this},max:function(t){return a.max(this._array,this._array,t._array),this._dirty=!0,this},mul:function(t){return a.mul(this._array,this._array,t._array),this._dirty=!0,this},multiply:function(t){return a.multiply(this._array,this._array,t._array),this._dirty=!0,this},negate:function(){return a.negate(this._array,this._array),this._dirty=!0,this},normalize:function(){return a.normalize(this._array,this._array),this._dirty=!0,this},random:function(t){return a.random(this._array,t),this._dirty=!0,this},scale:function(t){return a.scale(this._array,this._array,t),this._dirty=!0,this},scaleAndAdd:function(t,e){return a.scaleAndAdd(this._array,this._array,t._array,e),this._dirty=!0,this},sqrDist:function(t){return a.sqrDist(this._array,t._array)},squaredDistance:function(t){return a.squaredDistance(this._array,t._array)},sqrLen:function(){return a.sqrLen(this._array)},squaredLength:function(){return a.squaredLength(this._array)},sub:function(t){return a.sub(this._array,this._array,t._array),this._dirty=!0,this},subtract:function(t){return a.subtract(this._array,this._array,t._array),this._dirty=!0,this},transformMat3:function(t){return a.transformMat3(this._array,this._array,t._array),this._dirty=!0,this},transformMat4:function(t){return a.transformMat4(this._array,this._array,t._array),this._dirty=!0,this},transformQuat:function(t){return a.transformQuat(this._array,this._array,t._array),this._dirty=!0,this},applyProjection:function(t){var e=this._array;if(t=t._array,0===t[15]){var n=-1/e[2];e[0]=t[0]*e[0]*n,e[1]=t[5]*e[1]*n,e[2]=(t[10]*e[2]+t[14])*n}else e[0]=t[0]*e[0]+t[12],e[1]=t[5]*e[1]+t[13],e[2]=t[10]*e[2]+t[14];return this._dirty=!0,this},eulerFromQuat:function(t,e){o.eulerFromQuat(this,t,e)},eulerFromMat3:function(t,e){o.eulerFromMat3(this,t,e); -},toString:function(){return"["+Array.prototype.join.call(this._array,",")+"]"},toArray:function(){return Array.prototype.slice.call(this._array)}};var s=Object.defineProperty;if(s){var u=o.prototype;s(u,"x",{get:function(){return this._array[0]},set:function(t){this._array[0]=t,this._dirty=!0}}),s(u,"y",{get:function(){return this._array[1]},set:function(t){this._array[1]=t,this._dirty=!0}}),s(u,"z",{get:function(){return this._array[2]},set:function(t){this._array[2]=t,this._dirty=!0}})}o.add=function(t,e,n){return a.add(t._array,e._array,n._array),t._dirty=!0,t},o.set=function(t,e,n,r){a.set(t._array,e,n,r),t._dirty=!0},o.copy=function(t,e){return a.copy(t._array,e._array),t._dirty=!0,t},o.cross=function(t,e,n){return a.cross(t._array,e._array,n._array),t._dirty=!0,t},o.dist=function(t,e){return a.distance(t._array,e._array)},o.distance=o.dist,o.div=function(t,e,n){return a.divide(t._array,e._array,n._array),t._dirty=!0,t},o.divide=o.div,o.dot=function(t,e){return a.dot(t._array,e._array)},o.len=function(t){return a.length(t._array)},o.lerp=function(t,e,n,r){return a.lerp(t._array,e._array,n._array,r),t._dirty=!0,t},o.min=function(t,e,n){return a.min(t._array,e._array,n._array),t._dirty=!0,t},o.max=function(t,e,n){return a.max(t._array,e._array,n._array),t._dirty=!0,t},o.mul=function(t,e,n){return a.multiply(t._array,e._array,n._array),t._dirty=!0,t},o.multiply=o.mul,o.negate=function(t,e){return a.negate(t._array,e._array),t._dirty=!0,t},o.normalize=function(t,e){return a.normalize(t._array,e._array),t._dirty=!0,t},o.random=function(t,e){return a.random(t._array,e),t._dirty=!0,t},o.scale=function(t,e,n){return a.scale(t._array,e._array,n),t._dirty=!0,t},o.scaleAndAdd=function(t,e,n,r){return a.scaleAndAdd(t._array,e._array,n._array,r),t._dirty=!0,t},o.sqrDist=function(t,e){return a.sqrDist(t._array,e._array)},o.squaredDistance=o.sqrDist,o.sqrLen=function(t){return a.sqrLen(t._array)},o.squaredLength=o.sqrLen,o.sub=function(t,e,n){return a.subtract(t._array,e._array,n._array),t._dirty=!0,t},o.subtract=o.sub,o.transformMat3=function(t,e,n){return a.transformMat3(t._array,e._array,n._array),t._dirty=!0,t},o.transformMat4=function(t,e,n){return a.transformMat4(t._array,e._array,n._array),t._dirty=!0,t},o.transformQuat=function(t,e,n){return a.transformQuat(t._array,e._array,n._array),t._dirty=!0,t};var l=Math.atan2,c=Math.asin,h=Math.abs;o.eulerFromQuat=function(t,e,n){t._dirty=!0,e=e._array;var i=t._array,a=e[0],o=e[1],s=e[2],u=e[3],h=a*a,f=o*o,d=s*s,_=u*u,n=(n||"XYZ").toUpperCase();switch(n){case"XYZ":i[0]=l(2*(a*u-o*s),_-h-f+d),i[1]=c(r(2*(a*s+o*u),-1,1)),i[2]=l(2*(s*u-a*o),_+h-f-d);break;case"YXZ":i[0]=c(r(2*(a*u-o*s),-1,1)),i[1]=l(2*(a*s+o*u),_-h-f+d),i[2]=l(2*(a*o+s*u),_-h+f-d);break;case"ZXY":i[0]=c(r(2*(a*u+o*s),-1,1)),i[1]=l(2*(o*u-s*a),_-h-f+d),i[2]=l(2*(s*u-a*o),_-h+f-d);break;case"ZYX":i[0]=l(2*(a*u+s*o),_-h-f+d),i[1]=c(r(2*(o*u-a*s),-1,1)),i[2]=l(2*(a*o+s*u),_+h-f-d);break;case"YZX":i[0]=l(2*(a*u-s*o),_-h+f-d),i[1]=l(2*(o*u-a*s),_+h-f-d),i[2]=c(r(2*(a*o+s*u),-1,1));break;case"XZY":i[0]=l(2*(a*u+o*s),_-h+f-d),i[1]=l(2*(a*s+o*u),_+h-f-d),i[2]=c(r(2*(s*u-a*o),-1,1));break;default:console.warn("Unkown order: "+n)}return t},o.eulerFromMat3=function(t,e,n){var i=e._array,a=i[0],o=i[3],s=i[6],u=i[1],f=i[4],d=i[7],_=i[2],p=i[5],m=i[8],v=t._array,n=(n||"XYZ").toUpperCase();switch(n){case"XYZ":v[1]=c(r(s,-1,1)),h(s)<.99999?(v[0]=l(-d,m),v[2]=l(-o,a)):(v[0]=l(p,f),v[2]=0);break;case"YXZ":v[0]=c(-r(d,-1,1)),h(d)<.99999?(v[1]=l(s,m),v[2]=l(u,f)):(v[1]=l(-_,a),v[2]=0);break;case"ZXY":v[0]=c(r(p,-1,1)),h(p)<.99999?(v[1]=l(-_,m),v[2]=l(-o,f)):(v[1]=0,v[2]=l(u,a));break;case"ZYX":v[1]=c(-r(_,-1,1)),h(_)<.99999?(v[0]=l(p,m),v[2]=l(u,a)):(v[0]=0,v[2]=l(-o,f));break;case"YZX":v[2]=c(r(u,-1,1)),h(u)<.99999?(v[0]=l(-d,f),v[1]=l(-_,a)):(v[0]=0,v[1]=l(s,m));break;case"XZY":v[2]=c(-r(o,-1,1)),h(o)<.99999?(v[0]=l(p,f),v[1]=l(s,a)):(v[0]=l(-d,m),v[1]=0);break;default:console.warn("Unkown order: "+n)}return t._dirty=!0,t},o.POSITIVE_X=new o(1,0,0),o.NEGATIVE_X=new o((-1),0,0),o.POSITIVE_Y=new o(0,1,0),o.NEGATIVE_Y=new o(0,(-1),0),o.POSITIVE_Z=new o(0,0,1),o.NEGATIVE_Z=new o(0,0,(-1)),o.UP=new o(0,1,0),o.ZERO=new o(0,0,0),t.exports=o},function(t,e,n){"use strict";function r(){return{locations:{},attriblocations:{}}}function i(t,e,n){if(!t.getShaderParameter(e,t.COMPILE_STATUS))return[t.getShaderInfoLog(e),a(n)].join("\n")}function a(t){for(var e=t.split("\n"),n=0,r=e.length;n0&&r.push("#define "+i.toUpperCase()+"_COUNT "+a)}for(var o in n){var s=n[o];s.enabled&&r.push("#define "+o.toUpperCase()+"_ENABLED")}for(var o in t){var u=t[o];null===u?r.push("#define "+o):r.push("#define "+o+" "+u.toString())}return r.join("\n")},_unrollLoop:function(t,e){function n(t,n,i,a){var o="";isNaN(n)&&(n=n in e?e[n]:r[n]),isNaN(i)&&(i=i in e?e[i]:r[i]);for(var s=parseInt(n);s=0)n.attribSemantics[u]={symbol:a,type:c},h=!1;else if(E.indexOf(u)>=0){var f=!1,d=u;u.match(/TRANSPOSE$/)&&(f=!0,d=u.slice(0,-9)),n.matrixSemantics[u]={symbol:a,type:c,isTranspose:f,semanticNoTranspose:d},h=!1}else if(T.indexOf(u)>=0)n.uniformSemantics[u]={symbol:a,type:c},h=!1;else if("unconfigurable"===u)h=!1;else{if(l=n._parseDefaultValue(i,u),!l)throw new Error('Unkown semantic "'+u+'"');u=""}h&&(e[a]={type:c,value:o?y.array:l||y[i],semantic:u||null})}return["uniform",i,a,o].join(" ")+";\n"}}var e={},n=this,r="vertex";this._uniformList=[],this._vertexProcessedWithoutDefine=this._vertexProcessedWithoutDefine.replace(_,t),r="fragment",this._fragmentProcessedWithoutDefine=this._fragmentProcessedWithoutDefine.replace(_,t),n.matrixSemanticKeys=Object.keys(this.matrixSemantics),this.uniformTemplates=e},_parseDefaultValue:function(t,e){var n=/\[\s*(.*)\s*\]/;{if("vec2"!==t&&"vec3"!==t&&"vec4"!==t)return"bool"===t?function(){return"true"===e.toLowerCase()}:"float"===t?function(){return parseFloat(e)}:"int"===t?function(){return parseInt(e)}:void 0;var r=n.exec(e)[1];if(r){var i=r.split(/\s*,\s*/);return function(){return new l.Float32Array(i)}}}},createUniforms:function(){var t={};for(var e in this.uniformTemplates){var n=this.uniformTemplates[e];t[e]={type:n.type,value:n.value()}}return t},attached:function(){this._attacheMaterialNumber++},detached:function(){this._attacheMaterialNumber--},isAttachedToAny:function(){return 0!==this._attacheMaterialNumber},_parseAttributes:function(){function t(t,r,i,a,o){if(r&&i){var s=1;switch(r){case"vec4":s=4;break;case"vec3":s=3;break;case"vec2":s=2;break;case"float":s=1}if(e[i]={type:"float",size:s,semantic:o||null},o){if(x.indexOf(o)<0)throw new Error('Unkown semantic "'+o+'"');n.attribSemantics[o]={symbol:i,type:r}}}return["attribute",r,i].join(" ")+";\n"}var e={},n=this;this._vertexProcessedWithoutDefine=this._vertexProcessedWithoutDefine.replace(p,t),this.attributeTemplates=e},_parseDefines:function(){function t(t,r,i){var a="vertex"===n?e.vertexDefines:e.fragmentDefines;return a[r]||("false"==i?a[r]=!1:"true"==i?a[r]=!0:a[r]=i?parseFloat(i):null),""}var e=this,n="vertex";this._vertexProcessedWithoutDefine=this._vertexProcessedWithoutDefine.replace(m,t),n="fragment",this._fragmentProcessedWithoutDefine=this._fragmentProcessedWithoutDefine.replace(m,t)},_buildProgram:function(t,e,n){var r=this._cache;r.get("program")&&t.deleteProgram(r.get("program"));var a=t.createProgram(),o=t.createShader(t.VERTEX_SHADER);t.shaderSource(o,e),t.compileShader(o);var s=t.createShader(t.FRAGMENT_SHADER);t.shaderSource(s,n),t.compileShader(s);var u=i(t,o,e);if(u)return u;if(u=i(t,s,n))return u;if(t.attachShader(a,o),t.attachShader(a,s),this.attribSemantics.POSITION)t.bindAttribLocation(a,0,this.attribSemantics.POSITION.symbol);else{var l=Object.keys(this.attributeTemplates);t.bindAttribLocation(a,0,l[0])}if(t.linkProgram(a),!t.getProgramParameter(a,t.LINK_STATUS))return"Could not link program\nVALIDATE_STATUS: "+t.getProgramParameter(a,t.VALIDATE_STATUS)+", gl error ["+t.getError()+"]";for(var c=0;c=0},set:function(t,e){if("object"==typeof t)for(var n in t){var r=t[n];this.set(n,r)}else{var i=this.uniforms[t];i&&(i.value=e)}},get:function(t){var e=this.uniforms[t];if(e)return e.value},attachShader:function(t,e){this.shader&&this.shader.detached();var n=this.uniforms;this.uniforms=t.createUniforms(),this.shader=t;var r=this.uniforms;if(this._enabledUniforms=Object.keys(r),this._enabledUniforms.sort(),e)for(var i in n)r[i]&&(r[i].value=n[i].value);t.attached()},detachShader:function(){this.shader.detached(),this.shader=null,this.uniforms={}},clone:function(){var t=new this.constructor({name:this.name,shader:this.shader});for(var e in this.uniforms)t.uniforms[e].value=this.uniforms[e].value;return t.depthTest=this.depthTest,t.depthMask=this.depthMask,t.transparent=this.transparent,t.blend=this.blend,t},dispose:function(t,e){if(e)for(var n in this.uniforms){var r=this.uniforms[n].value;if(r)if(r instanceof i)r.dispose(t);else if(r instanceof Array)for(var a=0;a>e;return t+1},dispose:function(t){var e=this._cache;e.use(t.__GLID__);var n=e.get("webgl_texture");n&&t.deleteTexture(n),e.deleteContext(t.__GLID__)},isRenderable:function(){},isPowerOfTwo:function(){}});Object.defineProperty(o.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t}}),Object.defineProperty(o.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t}}),o.BYTE=i.BYTE,o.UNSIGNED_BYTE=i.UNSIGNED_BYTE,o.SHORT=i.SHORT,o.UNSIGNED_SHORT=i.UNSIGNED_SHORT,o.INT=i.INT,o.UNSIGNED_INT=i.UNSIGNED_INT,o.FLOAT=i.FLOAT,o.HALF_FLOAT=36193,o.UNSIGNED_INT_24_8_WEBGL=34042,o.DEPTH_COMPONENT=i.DEPTH_COMPONENT,o.DEPTH_STENCIL=i.DEPTH_STENCIL,o.ALPHA=i.ALPHA,o.RGB=i.RGB,o.RGBA=i.RGBA,o.LUMINANCE=i.LUMINANCE,o.LUMINANCE_ALPHA=i.LUMINANCE_ALPHA,o.COMPRESSED_RGB_S3TC_DXT1_EXT=33776,o.COMPRESSED_RGBA_S3TC_DXT1_EXT=33777,o.COMPRESSED_RGBA_S3TC_DXT3_EXT=33778,o.COMPRESSED_RGBA_S3TC_DXT5_EXT=33779,o.NEAREST=i.NEAREST,o.LINEAR=i.LINEAR,o.NEAREST_MIPMAP_NEAREST=i.NEAREST_MIPMAP_NEAREST,o.LINEAR_MIPMAP_NEAREST=i.LINEAR_MIPMAP_NEAREST,o.NEAREST_MIPMAP_LINEAR=i.NEAREST_MIPMAP_LINEAR,o.LINEAR_MIPMAP_LINEAR=i.LINEAR_MIPMAP_LINEAR,o.REPEAT=i.REPEAT,o.CLAMP_TO_EDGE=i.CLAMP_TO_EDGE,o.MIRRORED_REPEAT=i.MIRRORED_REPEAT,t.exports=o},function(t,e,n){var r=n(7),i=n(16),a=n(5),o=n(50),s=o.isPowerOfTwo,u=r.extend(function(){return{image:null,pixels:null,mipmaps:[]}},{update:function(t){t.bindTexture(t.TEXTURE_2D,this._cache.get("webgl_texture")),this.beforeUpdate(t);var e=this.format,n=this.type;t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,this.wrapS),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,this.wrapT),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,this.magFilter),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,this.minFilter);var r=i.getExtension(t,"EXT_texture_filter_anisotropic");if(r&&this.anisotropic>1&&t.texParameterf(t.TEXTURE_2D,r.TEXTURE_MAX_ANISOTROPY_EXT,this.anisotropic),36193===n){var o=i.getExtension(t,"OES_texture_half_float");o||(n=a.FLOAT)}if(this.mipmaps.length)for(var s=this.width,u=this.height,l=0;l=r.COMPRESSED_RGB_S3TC_DXT1_EXT?t.compressedTexImage2D(t.TEXTURE_2D,n,o,i,a,0,e.pixels):t.texImage2D(t.TEXTURE_2D,n,o,i,a,0,o,s,e.pixels)},generateMipmap:function(t){this.useMipmap&&!this.NPOT&&(t.bindTexture(t.TEXTURE_2D,this._cache.get("webgl_texture")),t.generateMipmap(t.TEXTURE_2D))},isPowerOfTwo:function(){var t,e;return this.image?(t=this.image.width,e=this.image.height):(t=this.width,e=this.height),s(t)&&s(e)},isRenderable:function(){return this.image?"CANVAS"===this.image.nodeName||"VIDEO"===this.image.nodeName||this.image.complete:!(!this.width||!this.height)},bind:function(t){t.bindTexture(t.TEXTURE_2D,this.getWebGLTexture(t))},unbind:function(t){t.bindTexture(t.TEXTURE_2D,null)},load:function(t){var e=new Image,n=this;return e.onload=function(){n.dirty(),n.trigger("success",n),e.onload=null; -},e.onerror=function(){n.trigger("error",n),e.onerror=null},e.src=t,this.image=e,this}});Object.defineProperty(u.prototype,"width",{get:function(){return this.image?this.image.width:this._width},set:function(t){this.image?console.warn("Texture from image can't set width"):(this._width!==t&&this.dirty(),this._width=t)}}),Object.defineProperty(u.prototype,"height",{get:function(){return this.image?this.image.height:this._height},set:function(t){this.image?console.warn("Texture from image can't set height"):(this._height!==t&&this.dirty(),this._height=t)}}),t.exports=u},function(t,e,n){"use strict";var r=n(3),i=n(1),a=i.vec3,o=a.copy,s=a.set,u=function(t,e){this.min=t||new r(1/0,1/0,1/0),this.max=e||new r((-(1/0)),(-(1/0)),(-(1/0)))};u.prototype={constructor:u,updateFromVertices:function(t){if(t.length>0){var e=this.min,n=this.max,r=e._array,i=n._array;o(r,t[0]),o(i,t[0]);for(var a=1;ai[0]&&(i[0]=s[0]),s[1]>i[1]&&(i[1]=s[1]),s[2]>i[2]&&(i[2]=s[2])}e._dirty=!0,n._dirty=!0}},union:function(t){var e=this.min,n=this.max;return a.min(e._array,e._array,t.min._array),a.max(n._array,n._array,t.max._array),e._dirty=!0,n._dirty=!0,this},intersection:function(t){var e=this.min,n=this.max;return a.max(e._array,e._array,t.min._array),a.min(n._array,n._array,t.max._array),e._dirty=!0,n._dirty=!0,this},intersectBoundingBox:function(t){var e=this.min._array,n=this.max._array,r=t.min._array,i=t.max._array;return!(e[0]>i[0]||e[1]>i[1]||e[2]>i[2]||n[0]=i[0]&&n[1]>=i[1]&&n[2]>=i[2]},containPoint:function(t){var e=this.min._array,n=this.max._array,r=t._array;return e[0]<=r[0]&&e[1]<=r[1]&&e[2]<=r[2]&&n[0]>=r[0]&&n[1]>=r[1]&&n[2]>=r[2]},isFinite:function(){var t=this.min._array,e=this.max._array;return isFinite(t[0])&&isFinite(t[1])&&isFinite(t[2])&&isFinite(e[0])&&isFinite(e[1])&&isFinite(e[2])},applyTransform:function(){var t=a.create(),e=a.create(),n=a.create(),r=a.create(),i=a.create(),o=a.create();return function(a){var s=this.min._array,u=this.max._array,l=a._array;return t[0]=l[0]*s[0],t[1]=l[1]*s[0],t[2]=l[2]*s[0],e[0]=l[0]*u[0],e[1]=l[1]*u[0],e[2]=l[2]*u[0],n[0]=l[4]*s[1],n[1]=l[5]*s[1],n[2]=l[6]*s[1],r[0]=l[4]*u[1],r[1]=l[5]*u[1],r[2]=l[6]*u[1],i[0]=l[8]*s[2],i[1]=l[9]*s[2],i[2]=l[10]*s[2],o[0]=l[8]*u[2],o[1]=l[9]*u[2],o[2]=l[10]*u[2],s[0]=Math.min(t[0],e[0])+Math.min(n[0],r[0])+Math.min(i[0],o[0])+l[12],s[1]=Math.min(t[1],e[1])+Math.min(n[1],r[1])+Math.min(i[1],o[1])+l[13],s[2]=Math.min(t[2],e[2])+Math.min(n[2],r[2])+Math.min(i[2],o[2])+l[14],u[0]=Math.max(t[0],e[0])+Math.max(n[0],r[0])+Math.max(i[0],o[0])+l[12],u[1]=Math.max(t[1],e[1])+Math.max(n[1],r[1])+Math.max(i[1],o[1])+l[13],u[2]=Math.max(t[2],e[2])+Math.max(n[2],r[2])+Math.max(i[2],o[2])+l[14],this.min._dirty=!0,this.max._dirty=!0,this}}(),applyProjection:function(t){var e=this.min._array,n=this.max._array,r=t._array,i=e[0],a=e[1],o=e[2],s=n[0],u=n[1],l=e[2],c=n[0],h=n[1],f=n[2];if(1===r[15])e[0]=r[0]*i+r[12],e[1]=r[5]*a+r[13],n[2]=r[10]*o+r[14],n[0]=r[0]*c+r[12],n[1]=r[5]*h+r[13],e[2]=r[10]*f+r[14];else{var d=-1/o;e[0]=r[0]*i*d,e[1]=r[5]*a*d,n[2]=(r[10]*o+r[14])*d,d=-1/l,n[0]=r[0]*s*d,n[1]=r[5]*u*d,d=-1/f,e[2]=(r[10]*f+r[14])*d}return this.min._dirty=!0,this.max._dirty=!0,this},updateVertices:function(){var t=this.vertices;if(!t){for(var t=[],e=0;e<8;e++)t[e]=a.fromValues(0,0,0);this.vertices=t}var n=this.min._array,r=this.max._array;return s(t[0],n[0],n[1],n[2]),s(t[1],n[0],r[1],n[2]),s(t[2],r[0],n[1],n[2]),s(t[3],r[0],r[1],n[2]),s(t[4],n[0],n[1],r[2]),s(t[5],n[0],r[1],r[2]),s(t[6],r[0],n[1],r[2]),s(t[7],r[0],r[1],r[2]),this},copy:function(t){var e=this.min,n=this.max;return o(e._array,t.min._array),o(n._array,t.max._array),e._dirty=!0,n._dirty=!0,this},clone:function(){var t=new u;return t.copy(this),t}},t.exports=u},function(t,e,n){"use strict";var r=n(1),i=n(3),a=r.mat4,o=r.vec3,s=r.mat3,u=r.quat,l=function(){this._axisX=new i,this._axisY=new i,this._axisZ=new i,this._array=a.create(),this._dirty=!0};l.prototype={constructor:l,setArray:function(t){for(var e=0;eo[0]&&(o[0]=u),l>o[1]&&(o[1]=l),h>o[2]&&(o[2]=h)}n._dirty=!0,r._dirty=!0}},dirty:function(){for(var t=this.getEnabledAttributes(),e=0;e=0){e||(e=f());var n=this.indices;return e[0]=n[3*t],e[1]=n[3*t+1],e[2]=n[3*t+2],e}},setTriangleIndices:function(t,e){var n=this.indices;n[3*t]=e[0],n[3*t+1]=e[1],n[3*t+2]=e[2]},isUseIndices:function(){return this.indices},initIndicesFromArray:function(t){var e,n=this.vertexCount>65535?s.Uint32Array:s.Uint16Array;if(t[0]&&t[0].length){var r=0,i=3;e=new n(t.length*i);for(var a=0;a=0&&(e.splice(n,1),delete this.attributes[t],!0)},getEnabledAttributes:function(){var t=this._enabledAttributes,e=this._attributeList;if(t)return t;for(var n=[],r=this.vertexCount,i=0;i65535&&(this.indices=new s.Uint32Array(this.indices));for(var r=0,i=this.attributes,a=this.indices,e=0;e0){for(var u=0;u1&&t.texParameterf(t.TEXTURE_CUBE_MAP,r.TEXTURE_MAX_ANISOTROPY_EXT,this.anisotropic),36193===n){var i=a.getExtension(t,"OES_texture_half_float");i||(n=o.FLOAT)}if(this.mipmaps.length)for(var s=this.width,u=this.height,l=0;l1&&(e=1);var n;return n=this.easing?this.easing(e):e,this.fire("frame",n),1===e?this._loop&&this._loopRemained>0?(this._restartInLoop(t),this._loopRemained--,"restart"):(this._needsRemove=!0,"finish"):null}},setTime:function(t){return this.step(t+this._startTime)},restart:function(t){var e=0;t=t,t&&(this._elapse(t),e=this._elapsedTime%this.life),t=t||(new Date).getTime(),this._startTime=t-e+this.delay,this._elapsedTime=0,this._currentTime=t-e,this._needsRemove=!1},_restartInLoop:function(t){this._startTime=t+this.gap,this._currentTime=t,this._elapsedTime=0},_elapse:function(t){this._elapsedTime+=(t-this._currentTime)*this.playbackRate,this._currentTime=t},fire:function(t,e){var n="on"+t;this[n]&&this[n](this.target,e)},clone:function(){var t=new this.constructor;return t.name=this.name,t._loop=this._loop,t._loopRemained=this._loopRemained,t.life=this.life,t.gap=this.gap,t.delay=this.delay,t}},a.prototype.constructor=a,t.exports=a},function(t,e,n){"use strict";var r=n(2),i=n(30),a=n(42),o=n(4),s=n(6),u=n(15),l=n(16),c=n(5);o["import"](n(131));var h=new a,f=new u({geometry:h,frustumCulling:!1}),d=new i,_=r.extend(function(){return{fragment:"",outputs:null,material:null,blendWithPrevious:!1,clearColor:!1,clearDepth:!0}},function(){var t=new o({vertex:o.source("qtek.compositor.vertex"),fragment:this.fragment}),e=new s({shader:t});t.enableTexturesAll(),this.material=e},{setUniform:function(t,e){var n=this.material.uniforms[t];n&&(n.value=e)},getUniform:function(t){var e=this.material.uniforms[t];if(e)return e.value},attachOutput:function(t,e){this.outputs||(this.outputs={}),e=e||c.COLOR_ATTACHMENT0,this.outputs[e]=t},detachOutput:function(t){for(var e in this.outputs)this.outputs[e]===t&&(this.outputs[e]=null)},bind:function(t,e){if(this.outputs)for(var n in this.outputs){var r=this.outputs[n];r&&e.attach(r,n)}e&&e.bind(t)},unbind:function(t,e){e.unbind(t)},render:function(t,e){var n=t.gl;if(e){this.bind(t,e);var r=l.getExtension(n,"EXT_draw_buffers");if(r&&this.outputs){var i=[];for(var a in this.outputs)a=+a,a>=n.COLOR_ATTACHMENT0&&a<=n.COLOR_ATTACHMENT0+8&&i.push(a);r.drawBuffersEXT(i)}}this.trigger("beforerender",this,t);var o=this.clearDepth?n.DEPTH_BUFFER_BIT:0;if(n.depthMask(!0),this.clearColor){o|=n.COLOR_BUFFER_BIT,n.colorMask(!0,!0,!0,!0);var s=this.clearColor;s instanceof Array&&n.clearColor(s[0],s[1],s[2],s[3])}n.clear(o),this.blendWithPrevious?(n.enable(n.BLEND),this.material.transparent=!0):(n.disable(n.BLEND),this.material.transparent=!1),this.renderQuad(t),this.trigger("afterrender",this,t),e&&this.unbind(t,e)},renderQuad:function(t){f.material=this.material,t.renderQueue([f],d)},dispose:function(t){this.material.dispose(t)}});t.exports=_},function(t,e,n){"use strict";var r=n(33),i=r.extend({fov:50,aspect:1,near:.1,far:2e3},{updateProjectionMatrix:function(){var t=this.fov/180*Math.PI;this.projectionMatrix.perspective(t,this.aspect,this.near,this.far)},decomposeProjectionMatrix:function(){var t=this.projectionMatrix._array,e=2*Math.atan(1/t[5]);this.fov=e/Math.PI*180,this.aspect=t[5]/t[0],this.near=t[14]/(t[10]-1),this.far=t[14]/(t[10]+1)},clone:function(){var t=r.prototype.clone.call(this);return t.fov=this.fov,t.aspect=this.aspect,t.near=this.near,t.far=this.far,t}});t.exports=i},function(t,e,n){"use strict";var r=n(2),i=r.extend(function(){return{name:"",inputLinks:{},outputLinks:{},_prevOutputTextures:{},_outputTextures:{},_outputReferences:{},_rendering:!1,_rendered:!1,_compositor:null}},{updateParameter:function(t,e){var n=this.outputs[t],r=n.parameters,i=n._parametersCopy;if(i||(i=n._parametersCopy={}),r)for(var a in r)"width"!==a&&"height"!==a&&(i[a]=r[a]);var o,s;return o=r.width instanceof Function?r.width.call(this,e):r.width,s=r.height instanceof Function?r.height.call(this,e):r.height,i.width===o&&i.height===s||this._outputTextures[t]&&this._outputTextures[t].dispose(e.gl),i.width=o,i.height=s,i},setParameter:function(t,e){},getParameter:function(t){},setParameters:function(t){for(var e in t)this.setParameter(e,t[e])},render:function(){},getOutput:function(t,e){if(null==e)return e=t,this._outputTextures[e];var n=this.outputs[e];if(n)return this._rendered?n.outputLastFrame?this._prevOutputTextures[e]:this._outputTextures[e]:this._rendering?(this._prevOutputTextures[e]||(this._prevOutputTextures[e]=this._compositor.allocateTexture(n.parameters||{})),this._prevOutputTextures[e]):(this.render(t),this._outputTextures[e])},removeReference:function(t){if(this._outputReferences[t]--,0===this._outputReferences[t]){var e=this.outputs[t];e.keepLastFrame?(this._prevOutputTextures[t]&&this._compositor.releaseTexture(this._prevOutputTextures[t]),this._prevOutputTextures[t]=this._outputTextures[t]):this._compositor.releaseTexture(this._outputTextures[t])}},link:function(t,e,n){this.inputLinks[t]={node:e,pin:n},e.outputLinks[n]||(e.outputLinks[n]=[]),e.outputLinks[n].push({node:this,pin:t});var r=this.pass.material.shader;r.enableTexture(t)},clear:function(){this.inputLinks={},this.outputLinks={}},updateReference:function(t){if(!this._rendering){this._rendering=!0;for(var e in this.inputLinks){var n=this.inputLinks[e];n.node.updateReference(n.pin)}this._rendering=!1}t&&this._outputReferences[t]++},beforeFrame:function(){this._rendered=!1;for(var t in this.outputLinks)this._outputReferences[t]=0},afterFrame:function(){for(var t in this.outputLinks)if(this._outputReferences[t]>0){var e=this.outputs[t];e.keepLastFrame?(this._prevOutputTextures[t]&&this._compositor.releaseTexture(this._prevOutputTextures[t]),this._prevOutputTextures[t]=this._outputTextures[t]):this._compositor.releaseTexture(this._outputTextures[t])}}});t.exports=i},function(t,e,n){"use strict";function r(t,e){if(e.castShadow&&!t.castShadow)return!0}var i=n(19),a=n(11),o=n(9),s=i.extend(function(){return{material:null,autoUpdate:!0,opaqueQueue:[],transparentQueue:[],lights:[],viewBoundingBoxLastFrame:new o,_lightUniforms:{},_lightNumber:{},_opaqueObjectCount:0,_transparentObjectCount:0,_nodeRepository:{}}},function(){this._scene=this},{addToScene:function(t){t.name&&(this._nodeRepository[t.name]=t)},removeFromScene:function(t){t.name&&delete this._nodeRepository[t.name]},getNode:function(t){return this._nodeRepository[t]},cloneNode:function(t){var e=t.clone(),n={},r=function(i,a){i.skeleton&&(a.skeleton=i.skeleton.clone(t,e),a.joints=i.joints.slice()),i.material&&(n[i.material.__GUID__]={oldMat:i.material});for(var o=0;o0&&this._updateRenderQueue(r)}},_updateLightUniforms:function(){var t=this.lights;t.sort(r);var e=this._lightUniforms;for(var n in e)for(var i in e[n])e[n][i].value.length=0;for(var a=0;a0},beforeRender:function(t){},afterRender:function(t,e){},getBoundingBox:function(t,e){return e=a.prototype.getBoundingBox.call(this,t,e),this.geometry&&this.geometry.boundingBox&&e.union(this.geometry.boundingBox),e},render:function(t,e){var e=e||this.material.shader,n=this.geometry,a=this.mode,h=n.vertexCount,f=n.isUseIndices(),d=s.getExtension(t,"OES_element_index_uint"),_=d&&h>65535,p=_?t.UNSIGNED_INT:t.UNSIGNED_SHORT,m=s.getExtension(t,"OES_vertex_array_object"),v=!n.dynamic,g=this._renderInfo;g.vertexCount=h,g.triangleCount=0,g.drawCallCount=0;var y=!1;if(i=t.__GLID__+"-"+n.__GUID__+"-"+e.__GUID__,i!==u?y=!0:(h>65535&&!d&&f||m&&v||n._cache.isDirty())&&(y=!0),u=i,y){var x=this._drawCache[i];if(!x){var T=n.getBufferChunks(t);if(!T)return;x=[];for(var E=0;Eh)){var f=Math.sqrt(h-c),d=u-f,_=u+f;return i||(i=new r),d<0?_<0?null:(a.scaleAndAdd(i._array,o,s,_),i):(a.scaleAndAdd(i._array,o,s,d),i)}}}(),intersectBoundingBox:function(t,e){var n,i,o,s,u,l,c=this.direction._array,h=this.origin._array,f=t.min._array,d=t.max._array,_=1/c[0],p=1/c[1],m=1/c[2];if(_>=0?(n=(f[0]-h[0])*_,i=(d[0]-h[0])*_):(i=(f[0]-h[0])*_,n=(d[0]-h[0])*_),p>=0?(o=(f[1]-h[1])*p,s=(d[1]-h[1])*p):(s=(f[1]-h[1])*p,o=(d[1]-h[1])*p),n>s||o>i)return null;if((o>n||n!==n)&&(n=o),(s=0?(u=(f[2]-h[2])*m,l=(d[2]-h[2])*m):(l=(f[2]-h[2])*m,u=(d[2]-h[2])*m),n>l||u>i)return null;if((u>n||n!==n)&&(n=u),(l=0?n:i;return e||(e=new r),a.scaleAndAdd(e._array,h,c,v),e},intersectTriangle:function(){var t=a.create(),e=a.create(),n=a.create(),i=a.create();return function(s,u,l,c,h,f){var d=this.direction._array,_=this.origin._array;s=s._array,u=u._array,l=l._array,a.sub(t,u,s),a.sub(e,l,s),a.cross(i,e,d);var p=a.dot(t,i);if(c){if(p>-o)return null}else if(p>-o&&p1)return null;a.cross(i,t,n);var v=a.dot(d,i)/p;if(v<0||v>1||m+v>1)return null;a.cross(i,t,e);var g=-a.dot(n,i)/p;return g<0?null:(h||(h=new r),f&&r.set(f,1-m-v,m,v),a.scaleAndAdd(h._array,_,d,g),h)}}(),applyTransform:function(t){r.add(this.direction,this.direction,this.origin),r.transformMat4(this.origin,this.origin,t),r.transformMat4(this.direction,this.direction,t),r.sub(this.direction,this.direction,this.origin),r.normalize(this.direction,this.direction)},copy:function(t){r.copy(this.origin,t.origin),r.copy(this.direction,t.direction)},clone:function(){var t=new s;return t.copy(this),t}},t.exports=s},function(t,e,n){var r=n(2),i=n(3),a=n(22),o=n(14),s=["px","nx","py","ny","pz","nz"],u=r.extend(function(){var t={position:new i,far:1e3,near:.1,texture:null,shadowMapPass:null},e=t._cameras={px:new a({fov:90}),nx:new a({fov:90}),py:new a({fov:90}),ny:new a({fov:90}),pz:new a({fov:90}),nz:new a({fov:90})};return e.px.lookAt(i.POSITIVE_X,i.NEGATIVE_Y),e.nx.lookAt(i.NEGATIVE_X,i.NEGATIVE_Y),e.py.lookAt(i.POSITIVE_Y,i.POSITIVE_Z),e.ny.lookAt(i.NEGATIVE_Y,i.NEGATIVE_Z),e.pz.lookAt(i.POSITIVE_Z,i.NEGATIVE_Y),e.nz.lookAt(i.NEGATIVE_Z,i.NEGATIVE_Y),t._frameBuffer=new o,t},{getCamera:function(t){return this._cameras[t]},render:function(t,e,n){var r=t.gl;n||e.update();for(var a=this.texture.width,o=2*Math.atan(a/(a-.5))/Math.PI*180,u=0;u<6;u++){var l=s[u],c=this._cameras[l];if(i.copy(c.position,this.position),c.far=this.far,c.near=this.near,c.fov=o,this.shadowMapPass){c.update();var h=e.getBoundingBox(function(t){return!t.invisible});h.applyTransform(c.viewMatrix),e.viewBoundingBoxLastFrame.copy(h),this.shadowMapPass.render(t,e,c,!0)}this._frameBuffer.attach(this.texture,r.COLOR_ATTACHMENT0,r.TEXTURE_CUBE_MAP_POSITIVE_X+u),this._frameBuffer.bind(t),t.render(e,c,!0),this._frameBuffer.unbind(t)}},dispose:function(t){this._frameBuffer.dispose(t)}});t.exports=u},function(t,e,n){"use strict";var r=n(19),i=n(10),a=n(47),o=n(31),s=n(1),u=s.vec3,l=s.vec4,c=r.extend(function(){return{projectionMatrix:new i,invProjectionMatrix:new i,viewMatrix:new i,frustum:new a}},function(){this.update(!0)},{update:function(t){r.prototype.update.call(this,t),i.invert(this.viewMatrix,this.worldTransform),this.updateProjectionMatrix(),i.invert(this.invProjectionMatrix,this.projectionMatrix),this.frustum.setFromProjection(this.projectionMatrix)},setViewMatrix:function(t){i.invert(this.worldTransform,t),this.decomposeWorldTransform()},decomposeProjectionMatrix:function(){},setProjectionMatrix:function(t){i.copy(this.projectionMatrix,t),i.invert(this.invProjectionMatrix,t),this.decomposeProjectionMatrix()},updateProjectionMatrix:function(){},castRay:function(){var t=l.create();return function(e,n){var r=void 0!==n?n:new o,i=e._array[0],a=e._array[1];return l.set(t,i,a,-1,1),l.transformMat4(t,t,this.invProjectionMatrix._array),l.transformMat4(t,t,this.worldTransform._array),u.scale(r.origin._array,t,1/t[3]),l.set(t,i,a,1,1),l.transformMat4(t,t,this.invProjectionMatrix._array),l.transformMat4(t,t,this.worldTransform._array),u.scale(t,t,1/t[3]),u.sub(r.direction._array,t,r.origin._array),u.normalize(r.direction._array,r.direction._array),r.direction._dirty=!0,r.origin._dirty=!0,r}}()});t.exports=c},function(t,e,n){"use strict";var r=n(2),i=r.extend({name:"",index:-1,parentIndex:-1,node:null,rootNode:null});t.exports=i},function(t,e,n){"use strict";var r=n(2),i=n(16),a=n(5),o=(n(13),n(9)),s=n(10),u=(n(28),n(6)),l=n(27),c=n(4);c["import"](n(77)),c["import"](n(53));var h=n(1),f=h.mat4,d=h.vec3,_=f.create,p=0,m={},v=r.extend(function(){return{canvas:null,_width:100,_height:100,devicePixelRatio:window.devicePixelRatio||1,clearColor:[0,0,0,0],clearBit:17664,alpha:!0,depth:!0,stencil:!1,antialias:!0,premultipliedAlpha:!0,preserveDrawingBuffer:!1,throwError:!0,gl:null,viewport:{},__currentFrameBuffer:null,_viewportStack:[],_clearStack:[],_sceneRendering:null}},function(){this.canvas||(this.canvas=document.createElement("canvas"));var t=this.canvas;try{var e={alpha:this.alpha,depth:this.depth,stencil:this.stencil,antialias:this.antialias,premultipliedAlpha:this.premultipliedAlpha,preserveDrawingBuffer:this.preserveDrawingBuffer};if(this.gl=t.getContext("webgl",e)||t.getContext("experimental-webgl",e),!this.gl)throw new Error;null==this.gl.__GLID__&&(this.gl.__GLID__=p++,i.initialize(this.gl)),this.resize()}catch(n){throw"Error creating WebGL Context "+n}},{resize:function(t,e){var n=this.canvas,r=this.devicePixelRatio;null!=t?(n.style.width=t+"px",n.style.height=e+"px",n.width=t*r,n.height=e*r,this._width=t,this._height=e):(this._width=n.width/r,this._height=n.height/r),this.setViewport(0,0,this._width,this._height)},getWidth:function(){return this._width},getHeight:function(){return this._height},getViewportAspect:function(){var t=this.viewport;return t.width/t.height},setDevicePixelRatio:function(t){this.devicePixelRatio=t,this.resize(this._width,this._height)},getDevicePixelRatio:function(){return this.devicePixelRatio},getExtension:function(t){return i.getExtension(this.gl,t)},setViewport:function(t,e,n,r,i){if("object"==typeof t){var a=t;t=a.x,e=a.y,n=a.width,r=a.height,i=a.devicePixelRatio}i=i||this.devicePixelRatio,this.gl.viewport(t*i,e*i,n*i,r*i),this.viewport={x:t,y:e,width:n,height:r,devicePixelRatio:i}},saveViewport:function(){this._viewportStack.push(this.viewport)},restoreViewport:function(){this._viewportStack.length>0&&this.setViewport(this._viewportStack.pop())},saveClear:function(){this._clearStack.push({clearBit:this.clearBit,clearColor:this.clearColor})},restoreClear:function(){if(this._clearStack.length>0){var t=this._clearStack.pop();this.clearColor=t.clearColor,this.clearBit=t.clearBit}},bindSceneRendering:function(t){this._sceneRendering=t},beforeRenderObject:function(){},afterRenderObject:function(){},render:function(t,e,n,r){var i=this.gl;this._sceneRendering=t;var a=this.clearColor;if(this.clearBit){i.colorMask(!0,!0,!0,!0),i.depthMask(!0);var o=this.viewport,s=!1,u=o.devicePixelRatio;(o.width!==this._width||o.height!==this._height||u&&u!==this.devicePixelRatio||o.x||o.y)&&(s=!0,i.enable(i.SCISSOR_TEST),i.scissor(o.x*u,o.y*u,o.width*u,o.height*u)),i.clearColor(a[0],a[1],a[2],a[3]),i.clear(this.clearBit),s&&i.disable(i.SCISSOR_TEST)}n||t.update(!1),e.getScene()||e.update(!0);var l=t.opaqueQueue,c=t.transparentQueue,h=t.material;if(t.trigger("beforerender",this,t,e),c.length>0)for(var p=_(),m=d.create(),v=0;v0&&t.min._array[2]<0&&(t.max._array[2]=-1e-20),t.applyProjection(e);var u=t.min._array,l=t.max._array;if(l[0]<-1||u[0]>1||l[1]<-1||u[1]>1||l[2]<-1||u[2]>1)return!0}return!1}}(),disposeScene:function(t){this.disposeNode(t,!0,!0),t.dispose()},disposeNode:function(t,e,n){var r={},i=this.gl;t.getParent()&&t.getParent().remove(t),t.traverse(function(t){t.geometry&&e&&t.geometry.dispose(i),t.material&&(r[t.material.__GUID__]=t.material),t.dispose&&t.dispose(i)});for(var a in r){var o=r[a];o.dispose(i,n)}},disposeShader:function(t){t.dispose(this.gl)},disposeGeometry:function(t){t.dispose(this.gl)},disposeTexture:function(t){t.dispose(this.gl)},disposeFrameBuffer:function(t){t.dispose(this.gl)},dispose:function(){i.dispose(this.gl)},screenToNDC:function(t,e,n){n||(n=new l),e=this._height-e;var r=this.viewport,i=n._array;return i[0]=(t-r.x)/r.width,i[0]=2*i[0]-1,i[1]=(e-r.y)/r.height,i[1]=2*i[1]-1,n}});v.opaqueSortFunc=v.prototype.opaqueSortFunc=function(t,e){return t.renderOrder===e.renderOrder?t.material.shader===e.material.shader?t.material===e.material?t.geometry.__GUID__-e.geometry.__GUID__:t.material.__GUID__-e.material.__GUID__:t.material.shader.__GUID__-e.material.shader.__GUID__:t.renderOrder-e.renderOrder},v.transparentSortFunc=v.prototype.transparentSortFunc=function(t,e){return t.renderOrder===e.renderOrder?t.__depth===e.__depth?t.material.shader===e.material.shader?t.material===e.material?t.geometry.__GUID__-e.geometry.__GUID__:t.material.__GUID__-e.material.__GUID__:t.material.shader.__GUID__-e.material.shader.__GUID__:t.__depth-e.__depth:t.renderOrder-e.renderOrder};var g={WORLD:_(),VIEW:_(),PROJECTION:_(),WORLDVIEW:_(),VIEWPROJECTION:_(),WORLDVIEWPROJECTION:_(),WORLDINVERSE:_(),VIEWINVERSE:_(),PROJECTIONINVERSE:_(),WORLDVIEWINVERSE:_(),VIEWPROJECTIONINVERSE:_(),WORLDVIEWPROJECTIONINVERSE:_(),WORLDTRANSPOSE:_(),VIEWTRANSPOSE:_(),PROJECTIONTRANSPOSE:_(),WORLDVIEWTRANSPOSE:_(),VIEWPROJECTIONTRANSPOSE:_(),WORLDVIEWPROJECTIONTRANSPOSE:_(),WORLDINVERSETRANSPOSE:_(),VIEWINVERSETRANSPOSE:_(),PROJECTIONINVERSETRANSPOSE:_(),WORLDVIEWINVERSETRANSPOSE:_(),VIEWPROJECTIONINVERSETRANSPOSE:_(),WORLDVIEWPROJECTIONINVERSETRANSPOSE:_()};v.COLOR_BUFFER_BIT=a.COLOR_BUFFER_BIT,v.DEPTH_BUFFER_BIT=a.DEPTH_BUFFER_BIT,v.STENCIL_BUFFER_BIT=a.STENCIL_BUFFER_BIT,t.exports=v},function(t,e,n){"use strict";function r(t,e,n){for(var r=e,i=0;i=t.time)return this.keyFrames.splice(e,0,t),e}this.life=t.time,this.keyFrames.push(t)},u.prototype.addKeyFrames=function(t){for(var e=0;ei[i.length-1].time)){if(t=a-1?a-1:this._cacheKey+1,l=u;l>=0;l--)if(i[l].time<=t&&i[l][e])n=i[l],this._cacheKey=l,this._cacheTime=t;else if(i[l][e]){r=i[l];break}}else for(var l=this._cacheKey;l65535?Uint32Array:Uint16Array,p=this.indices=new _(e*t*6),m=this.radius,v=this.phiStart,g=this.phiLength,y=this.thetaStart,x=this.thetaLength,m=this.radius,T=[],E=[],b=0,S=1/m;for(d=0;d<=t;d++)for(f=0;f<=e;f++)c=f/e,h=d/t,s=-m*Math.cos(v+c*g)*Math.sin(y+h*x),u=m*Math.cos(y+h*x),l=m*Math.sin(v+c*g)*Math.sin(y+h*x),T[0]=s,T[1]=u,T[2]=l,E[0]=c,E[1]=h,n.set(b,T),r.set(b,E),T[0]*=S,T[1]*=S,T[2]*=S,i.set(b,T),b++;var A,N,w,M,C=e+1,R=0;for(d=0;dthis.distance,i=1;i<8;i++)if(a.dot(e[i]._array,n)>this.distance!=r)return!0},intersectLine:function(){var t=a.create();return function(e,n,i){var o=this.distanceToPoint(e),s=this.distanceToPoint(n);if(o>0&&s>0||o<0&&s<0)return null;var u=this.normal._array,l=this.distance,c=e._array;a.sub(t,n._array,e._array),a.normalize(t,t);var h=a.dot(u,t);if(0===h)return null;i||(i=new r);var f=(a.dot(u,c)-l)/h;return a.scaleAndAdd(i._array,c,t,-f),i._dirty=!0,i}}(),applyTransform:function(){var t=o.create(),e=s.create(),n=s.create();return n[3]=1,function(r){r=r._array,a.scale(n,this.normal._array,this.distance),s.transformMat4(n,n,r),this.distance=a.dot(n,this.normal._array),o.invert(t,r),o.transpose(t,t),e[3]=0,a.copy(e,this.normal._array),s.transformMat4(e,e,t),a.copy(this.normal._array,e)}}(),copy:function(t){a.copy(this.normal._array,t.normal._array),this.normal._dirty=!0,this.distance=t.distance},clone:function(){var t=new u;return t.copy(this),t}},t.exports=u},function(t,e,n){"use strict";var r=n(1),i=r.quat,a=function(t,e,n,r){t=t||0,e=e||0,n=n||0,r=void 0===r?1:r,this._array=i.fromValues(t,e,n,r),this._dirty=!0};a.prototype={constructor:a,add:function(t){return i.add(this._array,this._array,t._array),this._dirty=!0,this},calculateW:function(){return i.calculateW(this._array,this._array),this._dirty=!0,this},set:function(t,e,n,r){return this._array[0]=t,this._array[1]=e,this._array[2]=n,this._array[3]=r,this._dirty=!0,this},setArray:function(t){return this._array[0]=t[0],this._array[1]=t[1],this._array[2]=t[2],this._array[3]=t[3],this._dirty=!0,this},clone:function(){return new a(this.x,this.y,this.z,this.w)},conjugate:function(){return i.conjugate(this._array,this._array),this._dirty=!0,this},copy:function(t){return i.copy(this._array,t._array),this._dirty=!0,this},dot:function(t){return i.dot(this._array,t._array)},fromMat3:function(t){return i.fromMat3(this._array,t._array),this._dirty=!0,this},fromMat4:function(){var t=r.mat3,e=t.create();return function(n){return t.fromMat4(e,n._array),t.transpose(e,e),i.fromMat3(this._array,e),this._dirty=!0,this}}(),identity:function(){return i.identity(this._array),this._dirty=!0,this},invert:function(){return i.invert(this._array,this._array),this._dirty=!0,this},len:function(){return i.len(this._array)},length:function(){return i.length(this._array)},lerp:function(t,e,n){return i.lerp(this._array,t._array,e._array,n),this._dirty=!0,this},mul:function(t){return i.mul(this._array,this._array,t._array),this._dirty=!0,this},mulLeft:function(t){return i.multiply(this._array,t._array,this._array),this._dirty=!0,this},multiply:function(t){return i.multiply(this._array,this._array,t._array),this._dirty=!0,this},multiplyLeft:function(t){return i.multiply(this._array,t._array,this._array),this._dirty=!0,this},normalize:function(){return i.normalize(this._array,this._array),this._dirty=!0,this},rotateX:function(t){return i.rotateX(this._array,this._array,t),this._dirty=!0,this},rotateY:function(t){return i.rotateY(this._array,this._array,t),this._dirty=!0,this},rotateZ:function(t){return i.rotateZ(this._array,this._array,t),this._dirty=!0,this},rotationTo:function(t,e){return i.rotationTo(this._array,t._array,e._array),this._dirty=!0,this},setAxes:function(t,e,n){return i.setAxes(this._array,t._array,e._array,n._array),this._dirty=!0,this},setAxisAngle:function(t,e){return i.setAxisAngle(this._array,t._array,e),this._dirty=!0,this},slerp:function(t,e,n){return i.slerp(this._array,t._array,e._array,n),this._dirty=!0,this},sqrLen:function(){return i.sqrLen(this._array)},squaredLength:function(){return i.squaredLength(this._array)},fromEuler:function(t,e){return a.fromEuler(this,t,e)},toString:function(){return"["+Array.prototype.join.call(this._array,",")+"]"},toArray:function(){return Array.prototype.slice.call(this._array)}};var o=Object.defineProperty;if(o){var s=a.prototype;o(s,"x",{get:function(){return this._array[0]},set:function(t){this._array[0]=t,this._dirty=!0}}),o(s,"y",{get:function(){return this._array[1]},set:function(t){this._array[1]=t,this._dirty=!0}}),o(s,"z",{get:function(){return this._array[2]},set:function(t){this._array[2]=t,this._dirty=!0}}),o(s,"w",{get:function(){return this._array[3]},set:function(t){this._array[3]=t,this._dirty=!0}})}a.add=function(t,e,n){return i.add(t._array,e._array,n._array),t._dirty=!0,t},a.set=function(t,e,n,r,a){i.set(t._array,e,n,r,a),t._dirty=!0},a.copy=function(t,e){return i.copy(t._array,e._array),t._dirty=!0,t},a.calculateW=function(t,e){return i.calculateW(t._array,e._array),t._dirty=!0,t},a.conjugate=function(t,e){return i.conjugate(t._array,e._array),t._dirty=!0,t},a.identity=function(t){return i.identity(t._array),t._dirty=!0,t},a.invert=function(t,e){return i.invert(t._array,e._array),t._dirty=!0,t},a.dot=function(t,e){return i.dot(t._array,e._array)},a.len=function(t){return i.length(t._array)},a.lerp=function(t,e,n,r){return i.lerp(t._array,e._array,n._array,r),t._dirty=!0,t},a.slerp=function(t,e,n,r){return i.slerp(t._array,e._array,n._array,r),t._dirty=!0,t},a.mul=function(t,e,n){return i.multiply(t._array,e._array,n._array),t._dirty=!0,t},a.multiply=a.mul,a.rotateX=function(t,e,n){return i.rotateX(t._array,e._array,n),t._dirty=!0,t},a.rotateY=function(t,e,n){return i.rotateY(t._array,e._array,n),t._dirty=!0,t},a.rotateZ=function(t,e,n){return i.rotateZ(t._array,e._array,n),t._dirty=!0,t},a.setAxisAngle=function(t,e,n){return i.setAxisAngle(t._array,e._array,n),t._dirty=!0,t}, -a.normalize=function(t,e){return i.normalize(t._array,e._array),t._dirty=!0,t},a.sqrLen=function(t){return i.sqrLen(t._array)},a.squaredLength=a.sqrLen,a.fromMat3=function(t,e){return i.fromMat3(t._array,e._array),t._dirty=!0,t},a.setAxes=function(t,e,n,r){return i.setAxes(t._array,e._array,n._array,r._array),t._dirty=!0,t},a.rotationTo=function(t,e,n){return i.rotationTo(t._array,e._array,n._array),t._dirty=!0,t},a.fromEuler=function(t,e,n){t._dirty=!0,e=e._array;var r=t._array,i=Math.cos(e[0]/2),a=Math.cos(e[1]/2),o=Math.cos(e[2]/2),s=Math.sin(e[0]/2),u=Math.sin(e[1]/2),l=Math.sin(e[2]/2),n=(n||"XYZ").toUpperCase();switch(n){case"XYZ":r[0]=s*a*o+i*u*l,r[1]=i*u*o-s*a*l,r[2]=i*a*l+s*u*o,r[3]=i*a*o-s*u*l;break;case"YXZ":r[0]=s*a*o+i*u*l,r[1]=i*u*o-s*a*l,r[2]=i*a*l-s*u*o,r[3]=i*a*o+s*u*l;break;case"ZXY":r[0]=s*a*o-i*u*l,r[1]=i*u*o+s*a*l,r[2]=i*a*l+s*u*o,r[3]=i*a*o-s*u*l;break;case"ZYX":r[0]=s*a*o-i*u*l,r[1]=i*u*o+s*a*l,r[2]=i*a*l-s*u*o,r[3]=i*a*o+s*u*l;break;case"YZX":r[0]=s*a*o+i*u*l,r[1]=i*u*o+s*a*l,r[2]=i*a*l-s*u*o,r[3]=i*a*o-s*u*l;break;case"XZY":r[0]=s*a*o-i*u*l,r[1]=i*u*o-s*a*l,r[2]=i*a*l+s*u*o,r[3]=i*a*o+s*u*l}},t.exports=a},function(t,e){var n={};n.isPowerOfTwo=function(t){return 0===(t&t-1)},n.nextPowerOfTwo=function(t){return t--,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,t|=t>>16,t++,t},n.nearestPowerOfTwo=function(t){return Math.pow(2,Math.round(Math.log(t)/Math.LN2))},t.exports=n},function(t,e,n){var r=n(15),i=n(69),a=n(4),o=n(6);a["import"](n(78));var s=r.extend(function(){var t=new a({vertex:a.source("qtek.skybox.vertex"),fragment:a.source("qtek.skybox.fragment")}),e=new o({shader:t,depthMask:!1});return{scene:null,geometry:new i,material:e,environmentMap:null,culling:!1}},function(){var t=this.scene;t&&this.attachScene(t),this.environmentMap&&this.setEnvironmentMap(this.environmentMap)},{attachScene:function(t){this.scene&&this.detachScene(),this.scene=t,t.on("beforerender",this._beforeRenderScene,this)},detachScene:function(){this.scene&&this.scene.off("beforerender",this._beforeRenderScene),this.scene=null},dispose:function(t){this.detachScene(),this.geometry.dispose(t),this.material.dispose(t)},setEnvironmentMap:function(t){this.material.set("environmentMap",t)},getEnvironmentMap:function(){return this.material.get("environmentMap")},_beforeRenderScene:function(t,e,n){this.renderSkybox(t,n)},renderSkybox:function(t,e){this.position.copy(e.getWorldPosition()),this.update(),t.gl.disable(t.gl.BLEND),t.renderQueue([this],e)}});t.exports=s},function(t,e,n){var r=n(15),i=n(43),a=n(4),o=n(6);a["import"](n(76));var s=r.extend(function(){var t=new a({vertex:a.source("qtek.basic.vertex"),fragment:a.source("qtek.basic.fragment")});t.enableTexture("diffuseMap");var e=new o({shader:t,depthMask:!1});return{scene:null,geometry:new i({widthSegments:30,heightSegments:30}),material:e,environmentMap:null,culling:!1}},function(){var t=this.scene;t&&this.attachScene(t),this.environmentMap&&this.setEnvironmentMap(this.environmentMap)},{attachScene:function(t){this.scene&&this.detachScene(),this.scene=t,t.on("beforerender",this._beforeRenderScene,this)},detachScene:function(){this.scene&&this.scene.off("beforerender",this._beforeRenderScene),this.scene=null},_beforeRenderScene:function(t,e,n){this.position.copy(n.getWorldPosition()),this.update(),t.renderQueue([this],n)},setEnvironmentMap:function(t){this.material.set("diffuseMap",t)},getEnvironmentMap:function(){return this.material.get("diffuseMap")},dispose:function(t){this.detachScene(),this.geometry.dispose(t),this.material.dispose(t)}});t.exports=s},function(t,e){t.exports="@export qtek.prez.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvoid main()\n{\n\n vec3 skinnedPosition = position;\n\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n#endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0);\n}\n\n@end\n\n\n@export qtek.prez.fragment\n\nvoid main()\n{\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n}\n\n@end"},function(t,e,n){"use strict";var r=n(8),i=n(18),a=n(26),o=n(32),s=n(52),u=n(24),l=n(82),c=n(84),h={loadTexture:function(t,e,n,a){var o;if("function"==typeof e?(n=e,a=n,e={}):e=e||{},"string"==typeof t){if(t.match(/.hdr$/)||"hdr"===e.fileType)return o=new r({width:0,height:0}),h._fetchTexture(t,function(t){c.parseRGBE(t,o,e.exposure),o.dirty(),n&&n(o)},a),o;t.match(/.dds$/)||"dds"===e.fileType?(o=new r({width:0,height:0}),h._fetchTexture(t,function(t){l.parse(t,o),o.dirty(),n&&n(o)},a)):(o=new r,o.load(t),o.success(n),o.error(a))}else if("object"==typeof t&&"undefined"!=typeof t.px){var o=new i;o.load(t),o.success(n),o.error(a)}return o},loadPanorama:function(t,e,n,r,i,a){var o=this;"function"==typeof r?(i=r,a=i,r={}):r=r||{},h.loadTexture(e,r,function(e){e.flipY=r.flipY||!1,o.panoramaToCubeMap(t,e,n,r),e.dispose(t.gl),i&&i(n)},a)},panoramaToCubeMap:function(t,e,n,r){var i=new o,a=new s({scene:new u});return a.material.set("diffuseMap",e),r=r||{},r.encodeRGBM&&a.material.shader.define("fragment","RGBM_ENCODE"),i.texture=n,i.render(t,a.scene),i.texture=null,i.dispose(t),n},_fetchTexture:function(t,e,n){a.get({url:t,responseType:"arraybuffer",onload:e,onerror:n})},createChessboard:function(t,e,n,i){t=t||512,e=e||64,n=n||"black",i=i||"white";var a=Math.ceil(t/e),o=document.createElement("canvas");o.width=t,o.height=t;var s=o.getContext("2d");s.fillStyle=i,s.fillRect(0,0,t,t),s.fillStyle=n;for(var u=0;u=0){var r=t[n.parentIndex].node;r.add(n.node)}else this.roots.push(n)}},addClip:function(t,e){for(var n=0;n0&&this._clips.splice(e,1)},removeClipsAll:function(){this._clips=[]},getClip:function(t){if(this._clips[t])return this._clips[t].clip},getClipNumber:function(){return this._clips.length},updateJointMatrices:function(){var t=u.create();return function(){for(var e=0;ei;if(a)t.length=i;else for(var o=r;o=0&&!(E[N]<=e);N--);N=Math.min(N,v-2)}else{for(N=O;Ne);N++);N=Math.min(N-1,v-2)}O=N,k=e;var n=E[N+1]-E[N];0!==n&&(R=(e-E[N])/n,m?(I=b[N],L=b[0===N?N:N-1],P=b[N>v-2?v-1:N+1],D=b[N>v-3?v-1:N+2],u?_(t,i,u(d(t,i),L,I,P,D,R)):y?l(L,I,P,D,R,R*R,R*R*R,d(t,i),x):_(t,i,c(L,I,P,D,R,R*R,R*R*R))):u?_(t,i,u(d(t,i),b[N],b[N+1],R)):y?o(b[N],b[N+1],R,d(t,i),x):_(t,i,a(b[N],b[N+1],R)))},B=new p({target:t._target,life:T,loop:t._loop,delay:t._delay,onframe:F,onfinish:n});return e&&"spline"!==e&&B.setEasing(e),B}}}function _(t,e,n,a,o){this._tracks={},this._target=t,this._loop=e||!1,this._getter=n||r,this._setter=a||i,this._interpolater=o||null,this._delay=0,this._doneList=[],this._onframeList=[],this._clipList=[]}var p=n(20),m=Array.prototype.slice;_.prototype={constructor:_,when:function(t,e){for(var n in e)this._tracks[n]||(this._tracks[n]=[],0!==t&&this._tracks[n].push({time:0,value:u(this._getter(this._target,n))})),this._tracks[n].push({time:parseInt(t),value:e[n]});return this},during:function(t){return this._onframeList.push(t),this},_doneCallback:function(){this._tracks={},this._clipList.length=0;for(var t=this._doneList,e=t.length,n=0;n1e-6?(o=Math.acos(s),u=Math.sin(o),l=Math.sin((1-r)*o)/u,c=Math.sin(r*o)/u):(l=1-r,c=r),t[0]=l*h+c*p,t[1]=l*f+c*m,t[2]=l*d+c*v,t[3]=l*_+c*g,t}var a=n(20),o=n(37),s=n(1),u=s.quat,l=s.vec3,c=function(t){t=t||{},a.call(this,t),this.position=l.create(),this.rotation=u.create(),this.scale=l.fromValues(1,1,1),this.channels={time:null,position:null,rotation:null,scale:null},this._cacheKey=0,this._cacheTime=0};c.prototype=Object.create(a.prototype),c.prototype.constructor=c,c.prototype.step=function(t){var e=a.prototype.step.call(this,t);return"finish"!==e&&this.setTime(this._elapsedTime),e},c.prototype.setTime=function(t){if(this.channels.time){var e=this.channels,n=e.time.length,a=-1;if(t=0;s--)if(e.time[s-1]<=t&&e.time[s]>t){a=s-1;break}}else for(var s=this._cacheKey;st){a=s;break}if(a>-1){this._cacheKey=a,this._cacheTime=t;var u=a,l=a+1,c=e.time[u],h=e.time[l],f=(t-c)/(h-c);e.rotation&&i(this.rotation,e.rotation,e.rotation,f,4*u,4*l),e.position&&r(this.position,e.position,e.position,f,3*u,3*l),e.scale&&r(this.scale,e.scale,e.scale,f,3*u,3*l)}a==n-2&&(this._cacheKey=0,this._cacheTime=0)}},c.prototype.getSubClip=function(t,e){var n=new c({name:this.name}),r=this.channels.time[0];t=Math.min(Math.max(t,r),this.life),e=Math.min(Math.max(e,r),this.life);var i=this._findRange(t),a=this._findRange(e),o=a[0]-i[0]+1;0===i[1]&&0===a[1]&&(o-=1),this.channels.rotation&&(n.channels.rotation=new Float32Array(4*o)),this.channels.position&&(n.channels.position=new Float32Array(3*o)),this.channels.scale&&(n.channels.scale=new Float32Array(3*o)),this.channels.time&&(n.channels.time=new Float32Array(o)),this.setTime(t);for(var s=0;s<3;s++)n.channels.rotation[s]=this.rotation[s],n.channels.position[s]=this.position[s],n.channels.scale[s]=this.scale[s];n.channels.time[0]=0,n.channels.rotation[3]=this.rotation[3];for(var s=1;st&&(r=i);var a=0;if(r>=0)var o=e.time[r],s=e.time[r+1],a=(t-o)/(s-o);return[r,a]},c.prototype.blend1D=o.prototype.blend1D,c.prototype.blend2D=o.prototype.blend2D,c.prototype.additiveBlend=o.prototype.additiveBlend,c.prototype.subtractiveBlend=o.prototype.subtractiveBlend,c.prototype.clone=function(){var t=a.prototype.clone.call(this);return t.channels={time:this.channels.time||null,position:this.channels.position||null,rotation:this.channels.rotation||null,scale:this.channels.scale||null},l.copy(t.position,this.position),u.copy(t.rotation,this.rotation),l.copy(t.scale,this.scale),t},t.exports=c},function(t,e,n){"use strict";var r=n(20),i=n(37),a=n(1),o=a.quat,s=a.vec3,u=function(t){if(t=t||{},r.call(this,t),this.jointClips=[],this.life=0,t.jointClips&&t.jointClips.length>0)for(var e=0;e0){var e=this.outputs[t];e.keepLastFrame?(this._prevOutputTextures[t]&&this._compositor.releaseTexture(this._prevOutputTextures[t]),this._prevOutputTextures[t]=this._outputTextures[t]):this._compositor.releaseTexture(this._outputTextures[t])}}});t.exports=a},function(t,e,n){"use strict";var r=n(2),i=n(23),a=r.extend(function(){return{nodes:[]}},{dirty:function(){this._dirty=!0},addNode:function(t){this.nodes.indexOf(t)>=0||(this.nodes.push(t),this._dirty=!0)},removeNode:function(t){"string"==typeof t&&(t=this.getNodeByName(t));var e=this.nodes.indexOf(t);e>=0&&(this.nodes.splice(e,1),this._dirty=!0)},getNodeByName:function(t){for(var e=0;e=e.COLOR_ATTACHMENT0&&c<=e.COLOR_ATTACHMENT0+8&&f.push(c);h.drawBuffersEXT(f)}t.saveClear(),t.clearBit=a.DEPTH_BUFFER_BIT|a.COLOR_BUFFER_BIT,n=t.render(this.scene,this.camera,!this.autoUpdateScene,this.preZ),t.restoreClear(),r.unbind(t)}else n=t.render(this.scene,this.camera,!this.autoUpdateScene,this.preZ);this.trigger("afterrender",n),this._rendering=!1,this._rendered=!0}});t.exports=s},function(t,e,n){"use strict";var r=n(23),i=r.extend(function(){ -return{texture:null,outputs:{color:{}}}},function(){},{getOutput:function(t,e){return this.texture},beforeFrame:function(){},afterFrame:function(){}});t.exports=i},function(t,e){"use strict";function n(t,e,n){"object"==typeof e&&(n=e,e=null);var a,o=this;if(!(t instanceof Function)){a=[];for(var s in t)t.hasOwnProperty(s)&&a.push(s)}var u=function(e){if(o.apply(this,arguments),t instanceof Function?r(this,t.call(this,e)):i(this,t,a),this.constructor===u)for(var n=u.__initializers__,s=0;s0&&(r.shader.define("vertex","SKINNING"),r.shader.define("vertex","JOINT_COUNT",t),i.shader.define("vertex","SKINNING"),i.shader.define("vertex","JOINT_COUNT",t)),n={material1:r,material2:i},e[t]=n}return n.used=!0,n},_resetGBufferMaterials:function(){for(var t in this._gBufferMaterials)this._gBufferMaterials[t].used=!1},_cleanGBufferMaterials:function(t){for(var e in this._gBufferMaterials){var n=this._gBufferMaterials[e];n.used||(n.material1.dispose(t),n.material2.dispose(t))}},_replaceGBufferMat:function(t,e){for(var n=0;n 0.01)\n {\n gl_FragColor.rgb = gl_FragColor.rgb * mix(lineColor, vec3(1.0), edgeFactor(lineWidth));\n }\n\n#ifdef GAMMA_ENCODE\n gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(1 / 2.2));\n#endif\n\n#ifdef ALPHA_TEST\n if (gl_FragColor.a < ALPHA_TEST_THRESHOLD) {\n discard;\n }\n#endif\n\n gl_FragColor = encodeHDR(gl_FragColor);\n\n}\n\n@end"},function(t,e,n){var r="uniform vec3 ",i="uniform float ",a="@export qtek.header.",o="@end",s=":unconfigurable;";t.exports=[a+"directional_light",r+"directionalLightDirection[DIRECTIONAL_LIGHT_COUNT]"+s,r+"directionalLightColor[DIRECTIONAL_LIGHT_COUNT]"+s,o,a+"ambient_light",r+"ambientLightColor[AMBIENT_LIGHT_COUNT]"+s,o,a+"ambient_sh_light",r+"ambientSHLightColor[AMBIENT_SH_LIGHT_COUNT]"+s,r+"ambientSHLightCoefficients[AMBIENT_SH_LIGHT_COUNT * 9]"+s,n(144),o,a+"ambient_cubemap_light",r+"ambientCubemapLightColor[AMBIENT_CUBEMAP_LIGHT_COUNT]"+s,"uniform samplerCube ambientCubemapLightCubemap[AMBIENT_CUBEMAP_LIGHT_COUNT]"+s,"uniform sampler2D ambientCubemapLightBRDFLookup[AMBIENT_CUBEMAP_LIGHT_COUNT]"+s,o,a+"point_light",r+"pointLightPosition[POINT_LIGHT_COUNT]"+s,i+"pointLightRange[POINT_LIGHT_COUNT]"+s,r+"pointLightColor[POINT_LIGHT_COUNT]"+s,o,a+"spot_light",r+"spotLightPosition[SPOT_LIGHT_COUNT]"+s,r+"spotLightDirection[SPOT_LIGHT_COUNT]"+s,i+"spotLightRange[SPOT_LIGHT_COUNT]"+s,i+"spotLightUmbraAngleCosine[SPOT_LIGHT_COUNT]"+s,i+"spotLightPenumbraAngleCosine[SPOT_LIGHT_COUNT]"+s,i+"spotLightFalloffFactor[SPOT_LIGHT_COUNT]"+s,r+"spotLightColor[SPOT_LIGHT_COUNT]"+s,o].join("\n")},function(t,e){t.exports="@export qtek.skybox.vertex\n\nuniform mat4 world : WORLD;\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\n\nvarying vec3 v_WorldPosition;\n\nvoid main()\n{\n v_WorldPosition = (world * vec4(position, 1.0)).xyz;\n gl_Position = worldViewProjection * vec4(position, 1.0);\n}\n\n@end\n\n@export qtek.skybox.fragment\n\nuniform mat4 viewInverse : VIEWINVERSE;\nuniform samplerCube environmentMap;\nuniform float lod: 0.0;\n\nvarying vec3 v_WorldPosition;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec3 eyePos = viewInverse[3].xyz;\n vec3 viewDirection = normalize(v_WorldPosition - eyePos);\n\n vec3 tex = decodeHDR(textureCubeLodEXT(environmentMap, viewDirection, lod)).rgb;\n\n#ifdef SRGB_DECODE\n tex.rgb = pow(tex.rgb, vec3(2.2));\n#endif\n\n gl_FragColor = encodeHDR(vec4(tex, 1.0));\n}\n@end"},function(t,e){t.exports="\n\n@export qtek.standard.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 worldInverseTranspose : WORLDINVERSETRANSPOSE;\nuniform mat4 world : WORLD;\n\nuniform vec2 uvRepeat : [1.0, 1.0];\nuniform vec2 uvOffset : [0.0, 0.0];\n\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\n\n#if defined(AOMAP_ENABLED)\nattribute vec2 texcoord2 : TEXCOORD_1;\n#endif\n\nattribute vec3 normal : NORMAL;\nattribute vec4 tangent : TANGENT;\n\n#ifdef VERTEX_COLOR\nattribute vec4 color : COLOR;\n#endif\n\nattribute vec3 barycentric;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\nvarying vec3 v_Barycentric;\n\n#ifdef NORMALMAP_ENABLED\nvarying vec3 v_Tangent;\nvarying vec3 v_Bitangent;\n#endif\n\n#ifdef VERTEX_COLOR\nvarying vec4 v_Color;\n#endif\n\n\n#if defined(AOMAP_ENABLED)\nvarying vec2 v_Texcoord2;\n#endif\n\nvoid main()\n{\n\n vec3 skinnedPosition = position;\n vec3 skinnedNormal = normal;\n vec3 skinnedTangent = tangent.xyz;\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n skinnedNormal = (skinMatrixWS * vec4(normal, 0.0)).xyz;\n skinnedTangent = (skinMatrixWS * vec4(tangent.xyz, 0.0)).xyz;\n#endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0);\n\n v_Texcoord = texcoord * uvRepeat + uvOffset;\n v_WorldPosition = (world * vec4(skinnedPosition, 1.0)).xyz;\n v_Barycentric = barycentric;\n\n v_Normal = normalize((worldInverseTranspose * vec4(skinnedNormal, 0.0)).xyz);\n\n#ifdef NORMALMAP_ENABLED\n v_Tangent = normalize((worldInverseTranspose * vec4(skinnedTangent, 0.0)).xyz);\n v_Bitangent = normalize(cross(v_Normal, v_Tangent) * tangent.w);\n#endif\n\n#ifdef VERTEX_COLOR\n v_Color = color;\n#endif\n\n#if defined(AOMAP_ENABLED)\n v_Texcoord2 = texcoord2;\n#endif\n}\n\n@end\n\n\n@export qtek.standard.fragment\n\n#define PI 3.14159265358979\n#define ALPHA_TEST_THRESHOLD 0.5\n\n#define GLOSS_CHANEL 0\n#define ROUGHNESS_CHANEL 0\n#define METALNESS_CHANEL 1\n\nuniform mat4 viewInverse : VIEWINVERSE;\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\n\n#ifdef NORMALMAP_ENABLED\nvarying vec3 v_Tangent;\nvarying vec3 v_Bitangent;\nuniform sampler2D normalMap;\n#endif\n\n#ifdef DIFFUSEMAP_ENABLED\nuniform sampler2D diffuseMap;\n#endif\n\n#ifdef SPECULARMAP_ENABLED\nuniform sampler2D specularMap;\n#endif\n\n#ifdef USE_ROUGHNESS\nuniform float roughness : 0.5;\n #ifdef ROUGHNESSMAP_ENABLED\nuniform sampler2D roughnessMap;\n #endif\n#else\nuniform float glossiness: 0.5;\n #ifdef GLOSSMAP_ENABLED\nuniform sampler2D glossMap;\n #endif\n#endif\n\n#ifdef METALNESSMAP_ENABLED\nuniform sampler2D metalnessMap;\n#endif\n\n#ifdef ENVIRONMENTMAP_ENABLED\nuniform samplerCube environmentMap;\n\n #ifdef PARALLAX_CORRECTED\nuniform vec3 environmentBoxMin;\nuniform vec3 environmentBoxMax;\n #endif\n\n#endif\n\n#ifdef BRDFLOOKUP_ENABLED\nuniform sampler2D brdfLookup;\n#endif\n\n#ifdef EMISSIVEMAP_ENABLED\nuniform sampler2D emissiveMap;\n#endif\n\n#ifdef SSAOMAP_ENABLED\nuniform sampler2D ssaoMap;\nuniform vec4 viewport : VIEWPORT;\n#endif\n\n#ifdef AOMAP_ENABLED\nuniform sampler2D aoMap;\nuniform float aoIntensity;\nvarying vec2 v_Texcoord2;\n#endif\n\nuniform vec3 color : [1.0, 1.0, 1.0];\nuniform float alpha : 1.0;\n\n\n#ifdef USE_METALNESS\nuniform float metalness : 0.0;\n#else\nuniform vec3 specularColor : [0.1, 0.1, 0.1];\n#endif\n\nuniform vec3 emission : [0.0, 0.0, 0.0];\n\nuniform float emissionIntensity: 1;\n\nuniform float lineWidth : 0.0;\nuniform vec3 lineColor : [0.0, 0.0, 0.0];\nvarying vec3 v_Barycentric;\n\n#ifdef ENVIRONMENTMAP_PREFILTER\nuniform float maxMipmapLevel: 5;\n#endif\n\n#ifdef AMBIENT_LIGHT_COUNT\n@import qtek.header.ambient_light\n#endif\n\n#ifdef AMBIENT_SH_LIGHT_COUNT\n@import qtek.header.ambient_sh_light\n#endif\n\n#ifdef AMBIENT_CUBEMAP_LIGHT_COUNT\n@import qtek.header.ambient_cubemap_light\n#endif\n\n#ifdef POINT_LIGHT_COUNT\n@import qtek.header.point_light\n#endif\n#ifdef DIRECTIONAL_LIGHT_COUNT\n@import qtek.header.directional_light\n#endif\n#ifdef SPOT_LIGHT_COUNT\n@import qtek.header.spot_light\n#endif\n\n@import qtek.util.calculate_attenuation\n\n@import qtek.util.edge_factor\n\n@import qtek.util.rgbm\n\n@import qtek.util.srgb\n\n@import qtek.plugin.compute_shadow_map\n\n@import qtek.util.parallax_correct\n\n\nfloat G_Smith(float g, float ndv, float ndl)\n{\n float roughness = 1.0 - g;\n float k = roughness * roughness / 2.0;\n float G1V = ndv / (ndv * (1.0 - k) + k);\n float G1L = ndl / (ndl * (1.0 - k) + k);\n return G1L * G1V;\n}\nvec3 F_Schlick(float ndv, vec3 spec) {\n return spec + (1.0 - spec) * pow(1.0 - ndv, 5.0);\n}\n\nfloat D_Phong(float g, float ndh) {\n float a = pow(8192.0, g);\n return (a + 2.0) / 8.0 * pow(ndh, a);\n}\n\nfloat D_GGX(float g, float ndh) {\n float r = 1.0 - g;\n float a = r * r;\n float tmp = ndh * ndh * (a - 1.0) + 1.0;\n return a / (PI * tmp * tmp);\n}\n\n\nvoid main()\n{\n vec4 albedoColor = vec4(color, alpha);\n vec3 eyePos = viewInverse[3].xyz;\n vec3 V = normalize(eyePos - v_WorldPosition);\n\n#ifdef DIFFUSEMAP_ENABLED\n vec4 texel = texture2D(diffuseMap, v_Texcoord);\n #ifdef SRGB_DECODE\n texel = sRGBToLinear(texel);\n #endif\n albedoColor.rgb *= texel.rgb;\n #ifdef DIFFUSEMAP_ALPHA_ALPHA\n albedoColor.a *= texel.a;\n #endif\n\n#endif\n\n\n#ifdef USE_METALNESS\n float m = metalness;\n\n #ifdef METALNESSMAP_ENABLED\n float m2 = texture2D(metalnessMap, v_Texcoord)[METALNESS_CHANEL];\n m = clamp(m2 + (m - 0.5) * 2.0, 0.0, 1.0);\n #endif\n\n vec3 baseColor = albedoColor.rgb;\n albedoColor.rgb = baseColor * (1.0 - m);\n vec3 spec = mix(vec3(0.04), baseColor, m);\n#else\n vec3 spec = specularColor;\n#endif\n\n#ifdef USE_ROUGHNESS\n float g = 1.0 - roughness;\n #ifdef ROUGHNESSMAP_ENABLED\n float g2 = 1.0 - texture2D(roughnessMap, v_Texcoord)[ROUGHNESS_CHANEL];\n g = clamp(g2 + (g - 0.5) * 2.0, 0.0, 1.0);\n #endif\n#else\n float g = glossiness;\n #ifdef GLOSSMAP_ENABLED\n float g2 = texture2D(glossMap, v_Texcoord)[GLOSS_CHANEL];\n g = clamp(g2 + (g - 0.5) * 2.0, 0.0, 1.0);\n #endif\n#endif\n\n#ifdef SPECULARMAP_ENABLED\n spec *= texture2D(specularMap, v_Texcoord).rgb;\n#endif\n\n vec3 N = v_Normal;\n#ifdef NORMALMAP_ENABLED\n if (dot(v_Tangent, v_Tangent) > 0.0) {\n vec3 normalTexel = texture2D(normalMap, v_Texcoord).xyz;\n if (dot(normalTexel, normalTexel) > 0.0) { N = normalTexel * 2.0 - 1.0;\n mat3 tbn = mat3(v_Tangent, v_Bitangent, v_Normal);\n N = normalize(tbn * N);\n }\n }\n#endif\n\n vec3 diffuseTerm = vec3(0.0, 0.0, 0.0);\n vec3 specularTerm = vec3(0.0, 0.0, 0.0);\n\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n vec3 fresnelTerm = F_Schlick(ndv, spec);\n\n#ifdef AMBIENT_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_LIGHT_COUNT; _idx_++)\n {{\n diffuseTerm += ambientLightColor[_idx_];\n }}\n#endif\n\n#ifdef AMBIENT_SH_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_SH_LIGHT_COUNT; _idx_++)\n {{\n diffuseTerm += calcAmbientSHLight(_idx_, N) * ambientSHLightColor[_idx_];\n }}\n#endif\n\n#ifdef POINT_LIGHT_COUNT\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsPoint[POINT_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfPointLights(v_WorldPosition, shadowContribsPoint);\n }\n#endif\n for(int _idx_ = 0; _idx_ < POINT_LIGHT_COUNT; _idx_++)\n {{\n\n vec3 lightPosition = pointLightPosition[_idx_];\n vec3 lc = pointLightColor[_idx_];\n float range = pointLightRange[_idx_];\n\n vec3 L = lightPosition - v_WorldPosition;\n\n float dist = length(L);\n float attenuation = lightAttenuation(dist, range);\n L /= dist;\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n\n float shadowContrib = 1.0;\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\n if(shadowEnabled)\n {\n shadowContrib = shadowContribsPoint[_idx_];\n }\n#endif\n\n vec3 li = lc * ndl * attenuation * shadowContrib;\n diffuseTerm += li;\n specularTerm += li * fresnelTerm * D_Phong(g, ndh);\n }}\n#endif\n\n#ifdef DIRECTIONAL_LIGHT_COUNT\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir);\n }\n#endif\n for(int _idx_ = 0; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++)\n {{\n\n vec3 L = -normalize(directionalLightDirection[_idx_]);\n vec3 lc = directionalLightColor[_idx_];\n\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n\n float shadowContrib = 1.0;\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n if(shadowEnabled)\n {\n shadowContrib = shadowContribsDir[_idx_];\n }\n#endif\n\n vec3 li = lc * ndl * shadowContrib;\n\n diffuseTerm += li;\n specularTerm += li * fresnelTerm * D_Phong(g, ndh);\n }}\n#endif\n\n#ifdef SPOT_LIGHT_COUNT\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsSpot[SPOT_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfSpotLights(v_WorldPosition, shadowContribsSpot);\n }\n#endif\n for(int i = 0; i < SPOT_LIGHT_COUNT; i++)\n {\n vec3 lightPosition = spotLightPosition[i];\n vec3 spotLightDirection = -normalize(spotLightDirection[i]);\n vec3 lc = spotLightColor[i];\n float range = spotLightRange[i];\n float a = spotLightUmbraAngleCosine[i];\n float b = spotLightPenumbraAngleCosine[i];\n float falloffFactor = spotLightFalloffFactor[i];\n\n vec3 L = lightPosition - v_WorldPosition;\n float dist = length(L);\n float attenuation = lightAttenuation(dist, range);\n\n L /= dist;\n float c = dot(spotLightDirection, L);\n\n float falloff;\n falloff = clamp((c - a) /( b - a), 0.0, 1.0);\n falloff = pow(falloff, falloffFactor);\n\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n\n float shadowContrib = 1.0;\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\n if (shadowEnabled)\n {\n shadowContrib = shadowContribsSpot[i];\n }\n#endif\n\n vec3 li = lc * attenuation * (1.0 - falloff) * shadowContrib * ndl;\n\n diffuseTerm += li;\n specularTerm += li * fresnelTerm * D_Phong(g, ndh);\n }\n#endif\n\n vec4 outColor = albedoColor;\n outColor.rgb *= diffuseTerm;\n\n outColor.rgb += specularTerm;\n\n\n#ifdef AMBIENT_CUBEMAP_LIGHT_COUNT\n vec3 L = reflect(-V, N);\n float rough2 = clamp(1.0 - g, 0.0, 1.0);\n float bias2 = rough2 * 5.0;\n vec2 brdfParam2 = texture2D(ambientCubemapLightBRDFLookup[0], vec2(rough2, ndv)).xy;\n vec3 envWeight2 = spec * brdfParam2.x + brdfParam2.y;\n vec3 envTexel2;\n for(int _idx_ = 0; _idx_ < AMBIENT_CUBEMAP_LIGHT_COUNT; _idx_++)\n {{\n envTexel2 = RGBMDecode(textureCubeLodEXT(ambientCubemapLightCubemap[_idx_], L, bias2), 51.5);\n outColor.rgb += ambientCubemapLightColor[_idx_] * envTexel2 * envWeight2;\n }}\n#endif\n\n#ifdef ENVIRONMENTMAP_ENABLED\n\n vec3 envWeight = g * fresnelTerm;\n vec3 L = reflect(-V, N);\n\n #ifdef PARALLAX_CORRECTED\n L = parallaxCorrect(L, v_WorldPosition, environmentBoxMin, environmentBoxMax);\n #endif\n\n #ifdef ENVIRONMENTMAP_PREFILTER\n float rough = clamp(1.0 - g, 0.0, 1.0);\n float bias = rough * maxMipmapLevel;\n vec3 envTexel = decodeHDR(textureCubeLodEXT(environmentMap, L, bias)).rgb;\n\n #ifdef BRDFLOOKUP_ENABLED\n vec2 brdfParam = texture2D(brdfLookup, vec2(rough, ndv)).xy;\n envWeight = spec * brdfParam.x + brdfParam.y;\n #endif\n\n #else\n vec3 envTexel = textureCube(environmentMap, L).xyz;\n #endif\n\n outColor.rgb += envTexel * envWeight;\n#endif\n\n float aoFactor = 1.0;\n#ifdef SSAOMAP_ENABLED\n aoFactor = min(texture2D(ssaoMap, (gl_FragCoord.xy - viewport.xy) / viewport.zw).r, aoFactor);\n#endif\n\n#ifdef AOMAP_ENABLED\n aoFactor = min(1.0 - clamp((1.0 - texture2D(aoMap, v_Texcoord2).r) * aoIntensity, 0.0, 1.0), aoFactor);\n#endif\n\n outColor.rgb *= aoFactor;\n\n vec3 lEmission = emission;\n#ifdef EMISSIVEMAP_ENABLED\n lEmission *= texture2D(emissiveMap, v_Texcoord).rgb;\n#endif\n outColor.rgb += lEmission * emissionIntensity;\n\n#ifdef GAMMA_ENCODE\n outColor.rgb = pow(outColor.rgb, vec3(1 / 2.2));\n#endif\n\n if(lineWidth > 0.)\n {\n outColor.rgb = mix(lineColor, vec3(outColor.rgb), edgeFactor(lineWidth));\n }\n\n#ifdef ALPHA_TEST\n if (outColor.a < ALPHA_TEST_THRESHOLD) {\n discard;\n }\n#endif\n\n gl_FragColor = encodeHDR(outColor);\n}\n\n@end\n"; -},function(t,e){t.exports="\n@export qtek.util.rand\nhighp float rand(vec2 uv) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot(uv.xy, vec2(a,b)), sn = mod(dt, 3.141592653589793);\n return fract(sin(sn) * c);\n}\n@end\n\n@export qtek.util.calculate_attenuation\n\nuniform float attenuationFactor : 5.0;\n\nfloat lightAttenuation(float dist, float range)\n{\n float attenuation = 1.0;\n attenuation = dist*dist/(range*range+1.0);\n float att_s = attenuationFactor;\n attenuation = 1.0/(attenuation*att_s+1.0);\n att_s = 1.0/(att_s+1.0);\n attenuation = attenuation - att_s;\n attenuation /= 1.0 - att_s;\n return clamp(attenuation, 0.0, 1.0);\n}\n\n@end\n\n@export qtek.util.edge_factor\n\nfloat edgeFactor(float width)\n{\n vec3 d = fwidth(v_Barycentric);\n vec3 a3 = smoothstep(vec3(0.0), d * width, v_Barycentric);\n return min(min(a3.x, a3.y), a3.z);\n}\n\n@end\n\n@export qtek.util.encode_float\nvec4 encodeFloat(const in float depth)\n{\n \n \n const vec4 bitShifts = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);\n const vec4 bit_mask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);\n vec4 res = fract(depth * bitShifts);\n res -= res.xxyz * bit_mask;\n\n return res;\n}\n@end\n\n@export qtek.util.decode_float\nfloat decodeFloat(const in vec4 color)\n{\n \n \n const vec4 bitShifts = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0);\n return dot(color, bitShifts);\n}\n@end\n\n\n@export qtek.util.float\n@import qtek.util.encode_float\n@import qtek.util.decode_float\n@end\n\n\n\n@export qtek.util.rgbm_decode\nvec3 RGBMDecode(vec4 rgbm, float range) {\n return range * rgbm.rgb * rgbm.a;\n }\n@end\n\n@export qtek.util.rgbm_encode\nvec4 RGBMEncode(vec3 color, float range) {\n if (dot(color, color) == 0.0) {\n return vec4(0.0);\n }\n vec4 rgbm;\n color /= range;\n rgbm.a = clamp(max(max(color.r, color.g), max(color.b, 1e-6)), 0.0, 1.0);\n rgbm.a = ceil(rgbm.a * 255.0) / 255.0;\n rgbm.rgb = color / rgbm.a;\n return rgbm;\n}\n@end\n\n@export qtek.util.rgbm\n@import qtek.util.rgbm_decode\n@import qtek.util.rgbm_encode\n\nvec4 decodeHDR(vec4 color)\n{\n#if defined(RGBM_DECODE) || defined(RGBM)\n return vec4(RGBMDecode(color, 51.5), 1.0);\n#else\n return color;\n#endif\n}\n\nvec4 encodeHDR(vec4 color)\n{\n#if defined(RGBM_ENCODE) || defined(RGBM)\n return RGBMEncode(color.xyz, 51.5);\n#else\n return color;\n#endif\n}\n\n@end\n\n\n@export qtek.util.srgb\n\nvec4 sRGBToLinear(in vec4 value) {\n return vec4(mix(pow(value.rgb * 0.9478672986 + vec3(0.0521327014), vec3(2.4)), value.rgb * 0.0773993808, vec3(lessThanEqual(value.rgb, vec3(0.04045)))), value.w);\n}\n\nvec4 linearTosRGB(in vec4 value) {\n return vec4(mix(pow(value.rgb, vec3(0.41666)) * 1.055 - vec3(0.055), value.rgb * 12.92, vec3(lessThanEqual(value.rgb, vec3(0.0031308)))), value.w);\n}\n@end\n\n\n@export qtek.chunk.skin_matrix\n\nmat4 skinMatrixWS;\nif (joint.x >= 0.0)\n{\n skinMatrixWS = skinMatrix[int(joint.x)] * weight.x;\n}\nif (joint.y >= 0.0)\n{\n skinMatrixWS += skinMatrix[int(joint.y)] * weight.y;\n}\nif (joint.z >= 0.0)\n{\n skinMatrixWS += skinMatrix[int(joint.z)] * weight.z;\n}\nif (joint.w >= 0.0)\n{\n skinMatrixWS += skinMatrix[int(joint.w)] * (1.0-weight.x-weight.y-weight.z);\n}\n@end\n\n\n\n@export qtek.util.parallax_correct\n\nvec3 parallaxCorrect(in vec3 dir, in vec3 pos, in vec3 boxMin, in vec3 boxMax) {\n vec3 first = (boxMax - pos) / dir;\n vec3 second = (boxMin - pos) / dir;\n\n vec3 further = max(first, second);\n float dist = min(further.x, min(further.y, further.z));\n\n vec3 fixedPos = pos + dir * dist;\n vec3 boxCenter = (boxMax + boxMin) * 0.5;\n\n return normalize(fixedPos - boxCenter);\n}\n\n@end\n\n\n\n@export qtek.util.clamp_sample\nvec4 clampSample(const in sampler2D texture, const in vec2 coord)\n{\n#ifdef STEREO\n float eye = step(0.5, coord.x) * 0.5;\n vec2 coordClamped = clamp(coord, vec2(eye, 0.0), vec2(0.5 + eye, 1.0));\n#else\n vec2 coordClamped = clamp(coord, vec2(0.0), vec2(1.0));\n#endif\n return texture2D(texture, coordClamped);\n}\n@end"},function(t,e,n){var r=n(8),i=n(18),a=n(7),o=n(14),s=n(21),u=n(6),l=n(4),c=n(51),h=n(24),f=n(32),d=n(13),_=n(54),p=n(151),m=n(152),v={},g=["px","nx","py","ny","pz","nz"];v.prefilterEnvironmentMap=function(t,e,n,s,p){p&&s||(s=v.generateNormalDistribution(),p=v.integrateBRDF(t,s)),n=n||{};var y=n.width||64,x=n.height||64,T=n.type||e.type,E=new i({width:y,height:x,type:T,flipY:!1,mipmaps:[]});E.isPowerOfTwo()||console.warn("Width and height must be power of two to enable mipmap.");var b=Math.min(y,x),S=Math.log(b)/Math.log(2)+1,A=new u({shader:new l({vertex:l.source("qtek.skybox.vertex"),fragment:m})});A.set("normalDistribution",s),n.encodeRGBM&&A.shader.define("fragment","RGBM_ENCODE"),n.decodeRGBM&&A.shader.define("fragment","RGBM_DECODE");var N,w=new h;if(e instanceof r){var M=new i({width:y,height:x,type:T===a.FLOAT?a.HALF_FLOAT:T});_.panoramaToCubeMap(t,e,M,{encodeRGBM:n.decodeRGBM}),e=M}N=new c({scene:w,material:A}),N.material.set("environmentMap",e);var C=new f({texture:E});n.encodeRGBM&&(T=E.type=a.UNSIGNED_BYTE);for(var R=new r({width:y,height:x,type:T}),L=new o({depthBuffer:!1}),I=d[T===a.UNSIGNED_BYTE?"Uint8Array":"Float32Array"],P=0;P>>16)>>>0;u=((1431655765&u)<<1|(2863311530&u)>>>1)>>>0,u=((858993459&u)<<2|(3435973836&u)>>>2)>>>0,u=((252645135&u)<<4|(4042322160&u)>>>4)>>>0,u=(((16711935&u)<<8|(4278255360&u)>>>8)>>>0)/4294967296;for(var l=0;ll&&(l=t[e][0]),t[e][1]c&&(c=t[e][1]);n=l-s,r=c-u,i=Math.max(n,r),a=s+.5*n,o=u+.5*r,t.push([a-20*i,o-i],[a,o+20*i],[a+20*i,o-i])}function r(t,e,n,r){var i,a,o,s,u,l,c=t[e],h=t[n],f=t[r],d=h[0]-c[0],_=h[1]-c[1],p=f[0]-c[0],m=f[1]-c[1],v=d*(c[0]+h[0])+_*(c[1]+h[1]),g=p*(c[0]+f[0])+m*(c[1]+f[1]),y=2*(d*(f[1]-h[1])-_*(f[0]-h[0]));return Math.abs(y)<1e-6?(i=Math.min(c[0],h[0],f[0]),a=Math.min(c[1],h[1],f[1]),o=.5*(Math.max(c[0],h[0],f[0])-i),s=.5*(Math.max(c[1],h[1],f[1])-a),u=i+o,l=a+s):(u=(m*v-_*g)/y,l=(d*g-p*v)/y,o=u-c[0],s=l-c[1]),{i:e,j:n,k:r,x:u,y:l,r:o*o+s*s}}function i(t){var e,n,r,i,a,o=t.length;t:for(;o;)for(n=t[--o],e=t[--o],r=o;r;)if(a=t[--r],i=t[--r],e===i&&n===a||e===a&&n===i){t.splice(o,2),t.splice(r,2),o-=2;continue t}}var a={triangulate:function(t,e){var a,o,s,u,l,c,h,f,d,_,p,m=t.length;if(m<3)return[];if(t=t.slice(0),e)for(a=m;a--;)t[a]=t[a][e];for(s=new Array(m),a=m;a--;)s[a]=a;for(s.sort(function(e,n){return t[n][0]-t[e][0]}),n(t),u=[r(t,m+0,m+1,m+2)],l=[],c=[],a=s.length;a--;){for(p=s[a],c.length=0,o=u.length;o--;)h=t[p][0]-u[o].x,h>0&&h*h>u[o].r?(l.push(u[o]),u.splice(o,1)):(f=t[p][1]-u[o].y,h*h+f*f>u[o].r||(c.push(u[o].i,u[o].j,u[o].j,u[o].k,u[o].k,u[o].i),u.splice(o,1)));for(i(c),o=c.length;o;)_=c[--o],d=c[--o],u.push(r(t,d,_,p))}for(a=u.length;a--;)l.push(u[a]);for(u.length=0,a=l.length;a--;)if(l[a].it[0][0]&&e[0]>t[1][0]&&e[0]>t[2][0]||e[1]t[0][1]&&e[1]>t[1][1]&&e[1]>t[2][1])return null;var n=t[1][0]-t[0][0],r=t[2][0]-t[0][0],i=t[1][1]-t[0][1],a=t[2][1]-t[0][1],o=n*a-r*i;if(0===o)return null;var s=(a*(e[0]-t[0][0])-r*(e[1]-t[0][1]))/o,u=(n*(e[1]-t[0][1])-i*(e[0]-t[0][0]))/o;return s<0||u<0||s+u>1?null:[s,u]}};t.exports=a},function(t,e,n){"use strict";function r(t,e,n,r){if(t[3]>0){var i=Math.pow(2,t[3]-128-8+r);e[n+0]=t[0]*i,e[n+1]=t[1]*i,e[n+2]=t[2]*i}else e[n+0]=0,e[n+1]=0,e[n+2]=0;return e[n+3]=1,e}function i(t,e,n){for(var r="",i=e;i0;)if(t[o][0]=e[n++],t[o][1]=e[n++],t[o][2]=e[n++],t[o][3]=e[n++],1===t[o][0]&&1===t[o][1]&&1===t[o][2]){for(var u=t[o][3]<>>0;u>0;u--)a(t[o-1],t[o]),o++,s--;i+=8}else o++,s--,i=0;return n}function s(t,e,n,r){if(rf)return o(t,e,n,r);var i=e[n++];if(2!=i)return o(t,e,n-1,r);if(t[0][1]=e[n++],t[0][2]=e[n++],i=e[n++],(t[0][2]<<8>>>0|i)>>>0!==r)return null;for(var i=0;i<4;i++)for(var a=0;a128){s=(127&s)>>>0;for(var u=e[n++];s--;)t[a++][i]=u}else for(;s--;)t[a++][i]=e[n++]}return n}var u=n(7),l=n(8),c=String.fromCharCode,h=8,f=32767,d={parseRGBE:function(t,e,n){null==n&&(n=0);var a=new Uint8Array(t),o=a.length;if("#?"===i(a,0,2)){for(var h=2;h=o)){h+=2;for(var f="";h=0&&this._clips.splice(e,1)},removeAnimator:function(t){for(var e=t.getClips(),n=0;nt)this.inputs.unshift(r);else if(this.inputs[i-1].position<=t)this.inputs.push(r);else{var a=this._findKey(t);this.inputs.splice(a,r)}return r},a.prototype.step=function(t){var e=r.prototype.step.call(this,t);return"finish"!==e&&this.setTime(this._elapsedTime),e},a.prototype.setTime=function(t){var e=this.position,n=this.inputs,i=n.length,a=n[0].position,o=n[i-1].position;if(e<=a||e>=o){var s=e<=a?n[0]:n[i-1],u=s.clip,l=s.offset;u.setTime((t+l)%u.life),u.output instanceof r?this.output.copy(u.output):this.output.copy(u)}else{var c=this._findKey(e),h=n[c],f=n[c+1],d=h.clip,_=f.clip;d.setTime((t+h.offset)%d.life),_.setTime((t+f.offset)%_.life);var p=(this.position-h.position)/(f.position-h.position),m=d.output instanceof r?d.output:d,v=_.output instanceof r?_.output:_;this.output.blend1D(m,v,p)}},a.prototype.clone=function(t){var e=r.prototype.clone.call(this);e.output=this.output.clone();for(var n=0;n=n[i].position&&t=0;i--)t>=n[i].position&&t=0&&(this._cacheKey=e,this._cachePosition=t),e},t.exports=a},function(t,e,n){"use strict";var r=n(20),i=n(83),a=n(27),o=function(t){t=t||{},r.call(this,t),this.output=t.output||null,this.inputs=t.inputs||[],this.position=new a,this._cacheTriangle=null,this._triangles=[],this._updateTriangles()};o.prototype=new r,o.prototype.constructor=o,o.prototype.addInput=function(t,e,n){var r={position:t,clip:e,offset:n||0};return this.inputs.push(r),this.life=Math.max(e.life,this.life),this._updateTriangles(),r},o.prototype._updateTriangles=function(){var t=this.inputs.map(function(t){return t.position});this._triangles=i.triangulate(t,"_array")},o.prototype.step=function(t){var e=r.prototype.step.call(this,t);return"finish"!==e&&this.setTime(this._elapsedTime),e},o.prototype.setTime=function(t){var e=this._findTriangle(this.position);if(e){var n=e[1],i=e[2],a=e[0],o=this.inputs[a.indices[0]],s=this.inputs[a.indices[1]],u=this.inputs[a.indices[2]],l=o.clip,c=s.clip,h=u.clip;l.setTime((t+o.offset)%l.life),c.setTime((t+s.offset)%c.life),h.setTime((t+u.offset)%h.life);var f=l.output instanceof r?l.output:l,d=c.output instanceof r?c.output:c,_=h.output instanceof r?h.output:h;this.output.blend2D(f,d,_,n,i)}},o.prototype.clone=function(t){var e=r.prototype.clone.call(this);e.output=this.output.clone();for(var n=0;n0,l=e.color;e.depth=0,u&&p.set(l,0,0,0,0);for(var c=!0,h=1/r,f=0;f-g&&_-g&&m-g&&v0){var v=d[0],w=(v[0]+1)*u,M=(-v[1]+1)*c;e.fillStyle=m,"rectangle"===A?e.fillRect(w-N,M-N,S,S):"circle"===A&&(e.beginPath(),e.arc(w,M,N,0,2*Math.PI),e.fill())}}}e.restore()},dispose:function(){this._triangles.clear(),this._lines.clear(),this._points.clear(),this._primitives=[],this.ctx=null,this.canvas=null}});t.exports=T},function(t,e,n){"use strict";var r=n(2),i=r.extend({cancelBubble:!1},{stopPropagation:function(){this.cancelBubble=!0}});i["throw"]=function(t,e,n){var r=new i(n);for(r.type=t,r.target=e;e&&!r.cancelBubble;)r.currentTarget=e,e.trigger(t,r),e=e.getParent()},t.exports=i},function(t,e,n){"use strict";var r=n(39),i=function(t){this._list=new r,this._map={},this._maxSize=t||10};i.prototype.setMaxSize=function(t){this._maxSize=t},i.prototype.put=function(t,e){if("undefined"==typeof this._map[t]){var n=this._list.length();if(n>=this._maxSize&&n>0){var r=this._list.head;this._list.remove(r),delete this._map[r.key]}var i=this._list.insert(e);i.key=t,this._map[t]=i}},i.prototype.get=function(t){var e=this._map[t];if("undefined"!=typeof e)return e!==this._list.tail&&(this._list.remove(e),this._list.insertEntry(e)),e.value},i.prototype.remove=function(t){var e=this._map[t];"undefined"!=typeof e&&(delete this._map[t],this._list.remove(e))},i.prototype.clear=function(){this._list.clear(),this._map={}},t.exports=i},function(t,e,n){"use strict";var r=n(2),i=n(4),a=n(6),o=n(14),s=n(21),u=n(8),l=n(7),c=n(15),h=n(43),f=n(41),d=n(70),_=n(10),p=n(3),m=n(68);i["import"](n(80)),i["import"](n(139)),i["import"](n(142)),i["import"](n(137)),i["import"](n(133)),i["import"](n(135)),i["import"](n(134)),i["import"](n(140)),i["import"](n(141)),i["import"](n(143)),i["import"](n(53));var v={},g=r.extend(function(){var t=i.source("qtek.compositor.vertex"),e=i.source("qtek.deferred.light_volume.vertex"),n=new i({vertex:t,fragment:i.source("qtek.deferred.directional_light")}),r=n.clone();r.define("fragment","SHADOWMAP_ENABLED");var c=function(t){t.blendEquation(t.FUNC_ADD),t.blendFunc(t.ONE,t.ONE)},v=function(t){return new a({shader:t,blend:c,transparent:!0,depthMask:!1})},g=function(t,n){var r=new i({vertex:e,fragment:i.source("qtek.deferred."+t)});return n&&r.define("fragment","SHADOWMAP_ENABLED"),r},y=new f({capSegments:10}),x=new _;x.rotateX(Math.PI/2).translate(new p(0,(-1),0)),y.applyTransform(x);var T=new d({capSegments:10});return x.identity().rotateZ(Math.PI/2),T.applyTransform(x),{shadowMapPass:null,autoResize:!0,_createLightPassMat:v,_gBuffer:new m,_lightAccumFrameBuffer:new o({depthBuffer:!1}),_lightAccumTex:new u({type:l.HALF_FLOAT,minFilter:l.NEAREST,magFilter:l.NEAREST}),_fullQuadPass:new s({blendWithPrevious:!0}),_directionalLightMat:v(n),_directionalLightMatWithShadow:v(r),_ambientMat:v(new i({vertex:t,fragment:i.source("qtek.deferred.ambient_light")})),_ambientSHMat:v(new i({vertex:t,fragment:i.source("qtek.deferred.ambient_sh_light")})),_ambientCubemapMat:v(new i({vertex:t,fragment:i.source("qtek.deferred.ambient_cubemap_light")})),_spotLightShader:g("spot_light"),_pointLightShader:g("point_light"),_spotLightShaderWithShadow:g("spot_light",!0),_pointLightShaderWithShadow:g("point_light",!0),_sphereLightShader:g("sphere_light"),_tubeLightShader:g("tube_light"),_lightSphereGeo:new h({widthSegments:10,heightSegements:10}),_lightConeGeo:y,_lightCylinderGeo:T,_outputPass:new s({fragment:i.source("qtek.compositor.output")})}},{render:function(t,e,n,r){r=r||{},r.renderToTarget=r.renderToTarget||!1,r.notUpdateShadow=r.notUpdateShadow||!1,r.notUpdateScene=r.notUpdateScene||!1,r.notUpdateScene||e.update(!1,!0),n.update(!0);var i=t.getDevicePixelRatio();!this.autoResize||t.getWidth()*i===this._lightAccumTex.width&&t.getHeight()*i===this._lightAccumTex.height||this.resize(t.getWidth()*i,t.getHeight()*i),this._gBuffer.update(t,e,n),this._accumulateLightBuffer(t,e,n,!r.notUpdateShadow),r.renderToTarget||(this._outputPass.setUniform("texture",this._lightAccumTex),this._outputPass.render(t))},getTargetTexture:function(){return this._lightAccumTex},getTargetFrameBuffer:function(){return this._lightAccumFrameBuffer},getGBuffer:function(){return this._gBuffer},setViewport:function(t,e,n,r,i){this._gBuffer.setViewport(t,e,n,r,i),this._lightAccumFrameBuffer.viewport=this._gBuffer.getViewport()},resize:function(t,e){this._lightAccumTex.width=t,this._lightAccumTex.height=e,this._gBuffer.resize(t,e)},_accumulateLightBuffer:function(t,e,n,r){for(var i=t.gl,a=this._lightAccumTex,o=this._lightAccumFrameBuffer,s=n.getWorldPosition()._array,u=0;u1?F.name=[s.name,l].join("-"):F.name=s.name),e.meshes[a].push(F)}}},_parseNodes:function(t,e){for(var n in t.nodes){var r,i=t.nodes[n];if(i.camera&&this.includeCamera){var a=t.cameras[i.camera];"perspective"===a.projection?r=new m({name:i.name,aspect:a.aspect_ratio,fov:a.xfov,far:a.zfar,near:a.znear}):(r=new v,console.warn("TODO:Orthographic camera")),r.setName(i.name),e.cameras[i.name]=r}else if(i.lights&&this.includeLight){for(var o=[],s=0;s0&&o.scaleAndAdd(t._array,t._array,this.force._array,r/n)}});t.exports=s},function(t,e,n){"use strict";var r=n(29),i=n(12),a=n(6),o=n(4);o["import"](n(107));var s=new o({vertex:o.source("qtek.particle.vertex"),fragment:o.source("qtek.particle.fragment")});s.enableTexture("sprite");var u=r.extend({loop:!0,oneshot:!1,duration:1,spriteAnimationTileX:1,spriteAnimationTileY:1,spriteAnimationRepeat:0,mode:r.POINTS,ignorePicking:!0,_elapsedTime:0,_emitting:!0},function(){this.geometry=new i({dynamic:!0}),this.material||(this.material=new a({shader:s,transparent:!0,depthMask:!1})),this._particles=[],this._fields=[],this._emitters=[]},{culling:!1,frustumCulling:!1,castShadow:!1,receiveShadow:!1,addEmitter:function(t){this._emitters.push(t)},removeEmitter:function(t){this._emitters.splice(this._emitters.indexOf(t),1)},addField:function(t){this._fields.push(t)},removeField:function(t){this._fields.splice(this._fields.indexOf(t),1)},reset:function(){for(var t=0;t=i.life?(i.emitter.kill(i),e[n]=e[r-1],e.pop(),r--):n++}for(var n=0;n0)for(var a=0;a1,o=t.attributes.position.value,s=t.attributes.normal.value,u=t.attributes.texcoord0.value,l=t.attributes.texcoord1.value,c=this._particles.length;o&&o.length===3*c||(o=t.attributes.position.value=new Float32Array(3*c),s=t.attributes.normal.value=new Float32Array(3*c),a&&(u=t.attributes.texcoord0.value=new Float32Array(2*c),l=t.attributes.texcoord1.value=new Float32Array(2*c)));for(var h=1/e,f=0;fthis.duration&&!this.loop},dispose:function(t){for(var e=0;e>16,n=t-(e<<8)>>8,r=t-(e<<16)-(n<<8);return[e,n,r]}function i(t,e,n){return(t<<16)+(e<<8)+n}var a=n(2),o=n(14),s=n(8),u=n(4),l=n(6);u["import"](n(110));var c=a.extend(function(){return{renderer:null,downSampleRatio:1,width:100,height:100,lookupOffset:1,_frameBuffer:null,_texture:null,_shader:null,_idMaterials:[],_lookupTable:[],_meshMaterials:[],_idOffset:0}},function(){this.renderer&&(this.width=this.renderer.getWidth(),this.height=this.renderer.getHeight()),this._init()},{_init:function(){this._texture=new s({width:this.width*this.downSampleRatio,height:this.height*this.downSampleRatio}),this._frameBuffer=new o,this._shader=new u({vertex:u.source("qtek.picking.color.vertex"),fragment:u.source("qtek.picking.color.fragment")})},setPrecision:function(t){this._texture.width=this.width*t,this._texture.height=this.height*t,this.downSampleRatio=t},resize:function(t,e){this._texture.width=t*this.downSampleRatio,this._texture.height=e*this.downSampleRatio,this.width=t,this.height=e,this._texture.dirty()},update:function(t,e){var n=this.renderer;n.getWidth()===this.width&&n.getHeight()===this.height||this.resize(n.width,n.height),this._frameBuffer.attach(this._texture),this._frameBuffer.bind(n),this._idOffset=this.lookupOffset,this._setMaterial(t),n.render(t,e),this._restoreMaterial(),this._frameBuffer.unbind(n)},_setMaterial:function(t){for(var e=0;e0&&a<=this.minPolarAngle?e.rotateAround(this.origin,i,-a+this.minPolarAngle):this._offsetRoll<0&&a>=this.maxPolarAngle&&e.rotateAround(this.origin,i,-a+this.maxPolarAngle),this._offsetRoll=this._offsetPitch=0}if(0!==this._forward){var o=e.position.distance(this.origin),s=o+this._forward*o/5e3;sthis.minDistance&&e.position.scaleAndAdd(n,this._forward*o/5e3),this._forward=0}}}));t.exports=s},function(t,e,n){var r=n(2),i=(n(72),r.extend(function(){console.warn("TODO")},{render:function(t,e,n){}}));t.exports=i},function(t,e,n){var r=n(2),i=n(5),a=n(3),o=n(9),s=n(47),u=n(10),l=n(35),c=n(4),h=(n(11),n(15),n(46)),f=n(44),d=n(45),_=(n(28),n(6)),p=n(14),m=n(7),v=n(8),g=n(18),y=n(22),x=n(30),T=n(21),E=n(38),b=n(1),S=b.mat4,A=(b.vec3,["px","nx","py","ny","pz","nz"]);c["import"](n(146));var N=r.extend(function(){return{softShadow:N.PCF,shadowBlur:1,lightFrustumBias:2,kernelPCF:new Float32Array([1,0,1,1,-1,1,0,1,-1,0,-1,-1,1,-1,0,-1]),_frameBuffer:new p,_textures:{},_shadowMapNumber:{POINT_LIGHT:0,DIRECTIONAL_LIGHT:0,SPOT_LIGHT:0},_meshMaterials:{},_depthMaterials:{},_depthShaders:{},_distanceMaterials:{},_opaqueCasters:[],_receivers:[],_lightsCastShadow:[],_lightCameras:{},_texturePool:new E}},function(){this._gaussianPassH=new T({fragment:c.source("qtek.compositor.gaussian_blur")}),this._gaussianPassV=new T({fragment:c.source("qtek.compositor.gaussian_blur")}),this._gaussianPassH.setUniform("blurSize",this.shadowBlur),this._gaussianPassH.setUniform("blurDir",0),this._gaussianPassV.setUniform("blurSize",this.shadowBlur),this._gaussianPassV.setUniform("blurDir",1),this._outputDepthPass=new T({fragment:c.source("qtek.sm.debug_depth")})},{render:function(t,e,n,r){this.trigger("beforerender",this,t,e,n),this._renderShadowPass(t,e,n,r),this.trigger("afterrender",this,t,e,n)},renderDebug:function(t,e){t.saveClear();var n=t.viewport,r=0,i=0,a=e||n.width/4,o=a;this.softShadow===N.VSM?this._outputDepthPass.material.shader.define("fragment","USE_VSM"):this._outputDepthPass.material.shader.undefine("fragment","USE_VSM");for(var s in this._textures){var u=this._textures[s];t.setViewport(r,i,a*u.width/u.height,o),this._outputDepthPass.setUniform("depthMap",u),this._outputDepthPass.render(t),r+=a*u.width/u.height}t.setViewport(n),t.restoreClear()},_bindDepthMaterial:function(t,e,n){for(var r=0;r0&&(f.define("vertex","SKINNING"),f.define("vertex","JOINT_COUNT",l)),s&&f.define("both","SHADOW_TRANSPARENT"),this._depthShaders[a]=f),h||(h=new _({shader:f}),this._depthMaterials[i]=h),o.material=h,this.softShadow===N.VSM?f.define("fragment","USE_VSM"):f.undefine("fragment","USE_VSM"),h.setUniform("bias",e),h.setUniform("slopeScale",n),s&&h.set("shadowTransparentMap",u))}},_bindDistanceMaterial:function(t,e){for(var n=e.getWorldPosition()._array,r=0;r0&&(o.shader.define("vertex","SKINNING"),o.shader.define("vertex","JOINT_COUNT",a)),this._distanceMaterials[a]=o),i.material=o,this.softShadow===N.VSM?o.shader.define("fragment","USE_VSM"):o.shader.undefine("fragment","USE_VSM")),o.set("lightPosition",n),o.set("range",e.range)}},saveMaterial:function(t){for(var e=0;e1&&(m=g,g.shadowCascade>4)){console.warn("Support at most 4 cascade");continue}this.renderDirectionalLightShadow(t,e,n,g,this._opaqueCasters,_,c,l)}else g instanceof h?this.renderSpotLightShadow(t,g,this._opaqueCasters,u,s):g instanceof d&&this.renderPointLightShadow(t,g,this._opaqueCasters,p);this._shadowMapNumber[g.type]++}this.restoreMaterial(this._opaqueCasters);var y=_.slice(),x=_.slice();y.pop(),x.shift(),y.reverse(),x.reverse(),c.reverse();for(var T=s.map(i),E=l.map(i),b={},v=0;v0&&(N.fragmentDefines[R]=C,w=!0)}w&&N.dirty(),m?N.define("fragment","SHADOW_CASCADE",m.shadowCascade):N.undefine("fragment","SHADOW_CASCADE"),b[N.__GUID__]=!0}s.length>0&&(A.setUniform("spotLightShadowMaps",s),A.setUniform("spotLightMatrices",u),A.setUniform("spotLightShadowMapSizes",T)),l.length>0&&(A.setUniform("directionalLightShadowMaps",l),m&&(A.setUniform("shadowCascadeClipsNear",y),A.setUniform("shadowCascadeClipsFar",x)),A.setUniform("directionalLightMatrices",c),A.setUniform("directionalLightShadowMapSizes",E)),p.length>0&&A.setUniform("pointLightShadowMaps",p)}}},renderDirectionalLightShadow:function(){var t=new s,e=new u,n=new o,r=new u,i=new u,a=new u,c=new u;return function(o,s,h,f,d,_,p,m){var v=f.shadowBias;this._bindDepthMaterial(d,v,f.shadowSlopeScale),d.sort(l.opaqueSortFunc);var g=Math.min(-s.viewBoundingBoxLastFrame.min.z,h.far),y=Math.max(-s.viewBoundingBoxLastFrame.max.z,h.near),x=this._getDirectionalLightCamera(f,s,h),T=a._array;c.copy(x.projectionMatrix),S.invert(i._array,x.worldTransform._array),S.multiply(i._array,i._array,h.worldTransform._array),S.multiply(T,c._array,i._array);for(var E=[],b=h.fov/180*Math.PI,A=h.aspect,w=(h.near+h.far)/(h.near-h.far),M=2*h.near*h.far/(h.near-h.far),C=0;C<=f.shadowCascade;C++){var R=y*Math.pow(g/y,C/f.shadowCascade),L=y+(g-y)*C/f.shadowCascade,I=R*f.cascadeSplitLogFactor+L*(1-f.cascadeSplitLogFactor);E.push(I),_.push(-(-I*w+M)/-I)}var P=this._getTexture(f,f.shadowCascade);m.push(P);var D=o.viewport,O=o.gl;this._frameBuffer.attach(P),this._frameBuffer.bind(o),O.clear(O.COLOR_BUFFER_BIT|O.DEPTH_BUFFER_BIT);for(var C=0;C threshold)\n {\n color = vec4(texel.rgb * scale, texel.a);\n }\n else\n {\n color = vec4(vec3(0.0), 1.0);\n }\n\n gl_FragColor = encodeHDR(color);\n}\n@end\n"; -},function(t,e){t.exports="@export qtek.compositor.coloradjust\n\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float brightness : 0.0;\nuniform float contrast : 1.0;\nuniform float exposure : 0.0;\nuniform float gamma : 1.0;\nuniform float saturation : 1.0;\n\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\n\nvoid main()\n{\n vec4 tex = texture2D( texture, v_Texcoord);\n\n vec3 color = clamp(tex.rgb + vec3(brightness), 0.0, 1.0);\n color = clamp( (color-vec3(0.5))*contrast+vec3(0.5), 0.0, 1.0);\n color = clamp( color * pow(2.0, exposure), 0.0, 1.0);\n color = clamp( pow(color, vec3(gamma)), 0.0, 1.0);\n float luminance = dot( color, w );\n color = mix(vec3(luminance), color, saturation);\n\n gl_FragColor = vec4(color, tex.a);\n}\n\n@end\n\n@export qtek.compositor.brightness\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float brightness : 0.0;\n\nvoid main()\n{\n vec4 tex = texture2D( texture, v_Texcoord);\n vec3 color = tex.rgb + vec3(brightness);\n gl_FragColor = vec4(color, tex.a);\n}\n@end\n\n@export qtek.compositor.contrast\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float contrast : 1.0;\n\nvoid main()\n{\n vec4 tex = texture2D( texture, v_Texcoord);\n vec3 color = (tex.rgb-vec3(0.5))*contrast+vec3(0.5);\n gl_FragColor = vec4(color, tex.a);\n}\n@end\n\n@export qtek.compositor.exposure\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float exposure : 0.0;\n\nvoid main()\n{\n vec4 tex = texture2D(texture, v_Texcoord);\n vec3 color = tex.rgb * pow(2.0, exposure);\n gl_FragColor = vec4(color, tex.a);\n}\n@end\n\n@export qtek.compositor.gamma\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float gamma : 1.0;\n\nvoid main()\n{\n vec4 tex = texture2D(texture, v_Texcoord);\n vec3 color = pow(tex.rgb, vec3(gamma));\n gl_FragColor = vec4(color, tex.a);\n}\n@end\n\n@export qtek.compositor.saturation\nvarying vec2 v_Texcoord;\nuniform sampler2D texture;\n\nuniform float saturation : 1.0;\n\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\n\nvoid main()\n{\n vec4 tex = texture2D(texture, v_Texcoord);\n vec3 color = tex.rgb;\n float luminance = dot(color, w);\n color = mix(vec3(luminance), color, saturation);\n gl_FragColor = vec4(color, tex.a);\n}\n@end"},function(t,e){t.exports="@export qtek.compositor.dof.coc\n\nuniform sampler2D depth;\n\nuniform float zNear: 0.1;\nuniform float zFar: 2000;\n\nuniform float focalDist: 3;\nuniform float focalRange: 1;\nuniform float focalLength: 30;\nuniform float fstop: 2.8;\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.encode_float\n\nvoid main()\n{\n float z = texture2D(depth, v_Texcoord).r * 2.0 - 1.0;\n\n float dist = 2.0 * zNear * zFar / (zFar + zNear - z * (zFar - zNear));\n\n float aperture = focalLength / fstop;\n\n float coc;\n\n float uppper = focalDist + focalRange;\n float lower = focalDist - focalRange;\n if (dist <= uppper && dist >= lower) {\n coc = 0.5;\n }\n else {\n float focalAdjusted = dist > uppper ? uppper : lower;\n\n coc = abs(aperture * (focalLength * (dist - focalAdjusted)) / (dist * (focalAdjusted - focalLength)));\n coc = clamp(coc, 0.0, 0.4) / 0.4000001;\n\n if (dist < lower) {\n coc = -coc;\n }\n coc = coc * 0.5 + 0.5;\n }\n\n gl_FragColor = encodeFloat(coc);\n}\n\n@end\n\n@export qtek.compositor.dof.premultiply\n\nuniform sampler2D texture;\nuniform sampler2D coc;\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n\n@import qtek.util.decode_float\n\nvoid main() {\n float fCoc = max(abs(decodeFloat(texture2D(coc, v_Texcoord)) * 2.0 - 1.0), 0.1);\n gl_FragColor = encodeHDR(\n vec4(decodeHDR(texture2D(texture, v_Texcoord)).rgb * fCoc, 1.0)\n );\n}\n@end\n\n\n@export qtek.compositor.dof.min_coc\nuniform sampler2D coc;\nvarying vec2 v_Texcoord;\nuniform vec2 textureSize : [512.0, 512.0];\n\n@import qtek.util.float\n\nvoid main()\n{\n vec4 d = vec4(-1.0, -1.0, 1.0, 1.0) / textureSize.xyxy;\n\n float fCoc = decodeFloat(texture2D(coc, v_Texcoord + d.xy));\n fCoc = min(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.zy)));\n fCoc = min(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.xw)));\n fCoc = min(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.zw)));\n\n gl_FragColor = encodeFloat(fCoc);\n}\n\n@end\n\n\n@export qtek.compositor.dof.max_coc\nuniform sampler2D coc;\nvarying vec2 v_Texcoord;\nuniform vec2 textureSize : [512.0, 512.0];\n\n@import qtek.util.float\n\nvoid main()\n{\n\n vec4 d = vec4(-1.0, -1.0, 1.0, 1.0) / textureSize.xyxy;\n\n float fCoc = decodeFloat(texture2D(coc, v_Texcoord + d.xy));\n fCoc = max(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.zy)));\n fCoc = max(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.xw)));\n fCoc = max(fCoc, decodeFloat(texture2D(coc, v_Texcoord + d.zw)));\n\n gl_FragColor = encodeFloat(fCoc);\n}\n\n@end\n\n\n\n\n@export qtek.compositor.dof.coc_upsample\n\n#define HIGH_QUALITY\n\nuniform sampler2D coc;\nuniform vec2 textureSize : [512, 512];\n\nuniform float sampleScale: 0.5;\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.float\n\nvoid main()\n{\n\n#ifdef HIGH_QUALITY\n vec4 d = vec4(1.0, 1.0, -1.0, 0.0) / textureSize.xyxy * sampleScale;\n\n float s;\n s = decodeFloat(texture2D(coc, v_Texcoord - d.xy));\n s += decodeFloat(texture2D(coc, v_Texcoord - d.wy)) * 2.0;\n s += decodeFloat(texture2D(coc, v_Texcoord - d.zy));\n\n s += decodeFloat(texture2D(coc, v_Texcoord + d.zw)) * 2.0;\n s += decodeFloat(texture2D(coc, v_Texcoord )) * 4.0;\n s += decodeFloat(texture2D(coc, v_Texcoord + d.xw)) * 2.0;\n\n s += decodeFloat(texture2D(coc, v_Texcoord + d.zy));\n s += decodeFloat(texture2D(coc, v_Texcoord + d.wy)) * 2.0;\n s += decodeFloat(texture2D(coc, v_Texcoord + d.xy));\n\n gl_FragColor = encodeFloat(s / 16.0);\n#else\n vec4 d = vec4(-1.0, -1.0, +1.0, +1.0) / textureSize.xyxy;\n\n float s;\n s = decodeFloat(texture2D(coc, v_Texcoord + d.xy));\n s += decodeFloat(texture2D(coc, v_Texcoord + d.zy));\n s += decodeFloat(texture2D(coc, v_Texcoord + d.xw));\n s += decodeFloat(texture2D(coc, v_Texcoord + d.zw));\n\n gl_FragColor = encodeFloat(s / 4.0);\n#endif\n}\n\n@end\n\n\n\n@export qtek.compositor.dof.upsample\n\n#define HIGH_QUALITY\n\nuniform sampler2D coc;\nuniform sampler2D texture;\nuniform vec2 textureSize : [512, 512];\n\nuniform float sampleScale: 0.5;\n\nvarying vec2 v_Texcoord;\n\n\n@import qtek.util.rgbm\n\n@import qtek.util.decode_float\n\nfloat tap(vec2 uv, inout vec4 color, float baseWeight) {\n float weight = abs(decodeFloat(texture2D(coc, uv)) * 2.0 - 1.0) * baseWeight;\n color += decodeHDR(texture2D(texture, uv)) * weight;\n return weight;\n}\n\nvoid main()\n{\n#ifdef HIGH_QUALITY\n vec4 d = vec4(1.0, 1.0, -1.0, 0.0) / textureSize.xyxy * sampleScale;\n\n vec4 color = vec4(0.0);\n float baseWeight = 1.0 / 16.0;\n float w = tap(v_Texcoord - d.xy, color, baseWeight);\n w += tap(v_Texcoord - d.wy, color, baseWeight * 2.0);\n w += tap(v_Texcoord - d.zy, color, baseWeight);\n\n w += tap(v_Texcoord + d.zw, color, baseWeight * 2.0);\n w += tap(v_Texcoord , color, baseWeight * 4.0);\n w += tap(v_Texcoord + d.xw, color, baseWeight * 2.0);\n\n w += tap(v_Texcoord + d.zy, color, baseWeight);\n w += tap(v_Texcoord + d.wy, color, baseWeight * 2.0);\n w += tap(v_Texcoord + d.xy, color, baseWeight);\n\n gl_FragColor = encodeHDR(color / w);\n#else\n vec4 d = vec4(-1.0, -1.0, +1.0, +1.0) / textureSize.xyxy;\n\n vec4 color = vec4(0.0);\n float baseWeight = 1.0 / 4.0;\n float w = tap(v_Texcoord + d.xy, color, baseWeight);\n w += tap(v_Texcoord + d.zy, color, baseWeight);\n w += tap(v_Texcoord + d.xw, color, baseWeight);\n w += tap(v_Texcoord + d.zw, color, baseWeight);\n\n gl_FragColor = encodeHDR(color / w);\n#endif\n}\n\n@end\n\n\n\n@export qtek.compositor.dof.downsample\n\nuniform sampler2D texture;\nuniform sampler2D coc;\nuniform vec2 textureSize : [512, 512];\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n\n@import qtek.util.decode_float\n\nfloat tap(vec2 uv, inout vec4 color) {\n float weight = abs(decodeFloat(texture2D(coc, uv)) * 2.0 - 1.0) * 0.25;\n color += decodeHDR(texture2D(texture, uv)) * weight;\n return weight;\n}\n\nvoid main()\n{\n vec4 d = vec4(-1.0, -1.0, 1.0, 1.0) / textureSize.xyxy;\n\n vec4 color = vec4(0.0);\n float weight = tap(v_Texcoord + d.xy, color);\n weight += tap(v_Texcoord + d.zy, color);\n weight += tap(v_Texcoord + d.xw, color);\n weight += tap(v_Texcoord + d.zw, color);\n color /= weight;\n\n gl_FragColor = encodeHDR(color);\n}\n\n@end\n\n\n\n@export qtek.compositor.dof.hexagonal_blur_frag\n\n@import qtek.util.float\n\n\nvec4 doBlur(sampler2D targetTexture, vec2 offset) {\n#ifdef BLUR_COC\n float cocSum = 0.0;\n#else\n vec4 color = vec4(0.0);\n#endif\n\n float weightSum = 0.0;\n float kernelWeight = 1.0 / float(KERNEL_SIZE);\n\n for (int i = 0; i < KERNEL_SIZE; i++) {\n vec2 coord = v_Texcoord + offset * float(i);\n\n float w = kernelWeight;\n#ifdef BLUR_COC\n float fCoc = decodeFloat(texture2D(targetTexture, coord)) * 2.0 - 1.0;\n cocSum += clamp(fCoc, -1.0, 0.0) * w;\n#else\n float fCoc = decodeFloat(texture2D(coc, coord)) * 2.0 - 1.0;\n vec4 texel = texture2D(targetTexture, coord);\n #if !defined(BLUR_NEARFIELD)\n w *= abs(fCoc);\n #endif\n color += decodeHDR(texel) * w;\n#endif\n\n weightSum += w;\n }\n#ifdef BLUR_COC\n return encodeFloat(clamp(cocSum / weightSum, -1.0, 0.0) * 0.5 + 0.5);\n#else\n return color / weightSum;\n#endif\n}\n\n@end\n\n\n@export qtek.compositor.dof.hexagonal_blur_1\n\n#define KERNEL_SIZE 5\n\nuniform sampler2D texture;\nuniform sampler2D coc;\nvarying vec2 v_Texcoord;\n\nuniform float blurSize : 1.0;\n\nuniform vec2 textureSize : [512.0, 512.0];\n\n@import qtek.util.rgbm\n\n@import qtek.compositor.dof.hexagonal_blur_frag\n\nvoid main()\n{\n vec2 offset = blurSize / textureSize;\n\n#if !defined(BLUR_NEARFIELD) && !defined(BLUR_COC)\n offset *= abs(decodeFloat(texture2D(coc, v_Texcoord)) * 2.0 - 1.0);\n#endif\n\n gl_FragColor = doBlur(texture, vec2(0.0, offset.y));\n#if !defined(BLUR_COC)\n gl_FragColor = encodeHDR(gl_FragColor);\n#endif\n}\n\n@end\n\n@export qtek.compositor.dof.hexagonal_blur_2\n\n#define KERNEL_SIZE 5\n\nuniform sampler2D texture;\nuniform sampler2D coc;\nvarying vec2 v_Texcoord;\n\nuniform float blurSize : 1.0;\n\nuniform vec2 textureSize : [512.0, 512.0];\n\n@import qtek.util.rgbm\n\n@import qtek.compositor.dof.hexagonal_blur_frag\n\nvoid main()\n{\n vec2 offset = blurSize / textureSize;\n#if !defined(BLUR_NEARFIELD) && !defined(BLUR_COC)\n offset *= abs(decodeFloat(texture2D(coc, v_Texcoord)) * 2.0 - 1.0);\n#endif\n\n offset.y /= 2.0;\n\n gl_FragColor = doBlur(texture, -offset);\n#if !defined(BLUR_COC)\n gl_FragColor = encodeHDR(gl_FragColor);\n#endif\n}\n@end\n\n@export qtek.compositor.dof.hexagonal_blur_3\n\n#define KERNEL_SIZE 5\n\nuniform sampler2D texture1;\nuniform sampler2D texture2;\nuniform sampler2D coc;\n\nvarying vec2 v_Texcoord;\n\nuniform float blurSize : 1.0;\n\nuniform vec2 textureSize : [512.0, 512.0];\n\n@import qtek.util.rgbm\n\n@import qtek.compositor.dof.hexagonal_blur_frag\n\nvoid main()\n{\n vec2 offset = blurSize / textureSize;\n\n#if !defined(BLUR_NEARFIELD) && !defined(BLUR_COC)\n offset *= abs(decodeFloat(texture2D(coc, v_Texcoord)) * 2.0 - 1.0);\n#endif\n\n offset.y /= 2.0;\n vec2 vDownRight = vec2(offset.x, -offset.y);\n\n vec4 texel1 = doBlur(texture1, -offset);\n vec4 texel2 = doBlur(texture1, vDownRight);\n vec4 texel3 = doBlur(texture2, vDownRight);\n\n#ifdef BLUR_COC\n float coc1 = decodeFloat(texel1) * 2.0 - 1.0;\n float coc2 = decodeFloat(texel2) * 2.0 - 1.0;\n float coc3 = decodeFloat(texel3) * 2.0 - 1.0;\n gl_FragColor = encodeFloat(\n ((coc1 + coc2 + coc3) / 3.0) * 0.5 + 0.5\n );\n\n#else\n vec4 color = (texel1 + texel2 + texel3) / 3.0;\n gl_FragColor = encodeHDR(color);\n#endif\n}\n\n@end\n\n@export qtek.compositor.dof.composite\n\n#define DEBUG 0\n\nuniform sampler2D original;\nuniform sampler2D blurred;\nuniform sampler2D nearfield;\nuniform sampler2D coc;\nuniform sampler2D nearcoc;\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n@import qtek.util.float\n\nvoid main()\n{\n vec4 blurredColor = decodeHDR(texture2D(blurred, v_Texcoord));\n vec4 originalColor = decodeHDR(texture2D(original, v_Texcoord));\n\n float fCoc = decodeFloat(texture2D(coc, v_Texcoord));\n\n fCoc = abs(fCoc * 2.0 - 1.0);\n\n float weight = smoothstep(0.0, 1.0, fCoc);\n \n#ifdef NEARFIELD_ENABLED\n vec4 nearfieldColor = decodeHDR(texture2D(nearfield, v_Texcoord));\n float fNearCoc = decodeFloat(texture2D(nearcoc, v_Texcoord));\n fNearCoc = abs(fNearCoc * 2.0 - 1.0);\n\n gl_FragColor = encodeHDR(\n mix(\n nearfieldColor, mix(originalColor, blurredColor, weight),\n pow(1.0 - fNearCoc, 4.0)\n )\n );\n#else\n gl_FragColor = encodeHDR(mix(originalColor, blurredColor, weight));\n#endif\n\n#if DEBUG == 1\n gl_FragColor = vec4(vec3(fCoc), 1.0);\n#elif DEBUG == 2\n gl_FragColor = vec4(vec3(fNearCoc), 1.0);\n#elif DEBUG == 3\n gl_FragColor = encodeHDR(blurredColor);\n#elif DEBUG == 4\n gl_FragColor = encodeHDR(nearfieldColor);\n#endif\n}\n\n@end"},function(t,e){t.exports="@export qtek.compositor.downsample\n\nuniform sampler2D texture;\nuniform vec2 textureSize : [512, 512];\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\nfloat brightness(vec3 c)\n{\n return max(max(c.r, c.g), c.b);\n}\n\n@import qtek.util.clamp_sample\n\nvoid main()\n{\n vec4 d = vec4(-1.0, -1.0, 1.0, 1.0) / textureSize.xyxy;\n\n#ifdef ANTI_FLICKER\n vec3 s1 = decodeHDR(clampSample(texture, v_Texcoord + d.xy)).rgb;\n vec3 s2 = decodeHDR(clampSample(texture, v_Texcoord + d.zy)).rgb;\n vec3 s3 = decodeHDR(clampSample(texture, v_Texcoord + d.xw)).rgb;\n vec3 s4 = decodeHDR(clampSample(texture, v_Texcoord + d.zw)).rgb;\n\n float s1w = 1.0 / (brightness(s1) + 1.0);\n float s2w = 1.0 / (brightness(s2) + 1.0);\n float s3w = 1.0 / (brightness(s3) + 1.0);\n float s4w = 1.0 / (brightness(s4) + 1.0);\n float oneDivideSum = 1.0 / (s1w + s2w + s3w + s4w);\n\n vec4 color = vec4(\n (s1 * s1w + s2 * s2w + s3 * s3w + s4 * s4w) * oneDivideSum,\n 1.0\n );\n#else\n vec4 color = decodeHDR(clampSample(texture, v_Texcoord + d.xy));\n color += decodeHDR(clampSample(texture, v_Texcoord + d.zy));\n color += decodeHDR(clampSample(texture, v_Texcoord + d.xw));\n color += decodeHDR(clampSample(texture, v_Texcoord + d.zw));\n color *= 0.25;\n#endif\n\n gl_FragColor = encodeHDR(color);\n}\n\n@end"},function(t,e){t.exports="@export qtek.compositor.fxaa\n\nuniform sampler2D texture;\nuniform vec4 viewport : VIEWPORT;\n\nvarying vec2 v_Texcoord;\n\n#define FXAA_REDUCE_MIN (1.0/128.0)\n#define FXAA_REDUCE_MUL (1.0/8.0)\n#define FXAA_SPAN_MAX 8.0\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec2 resolution = 1.0 / viewport.zw;\n vec3 rgbNW = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( -1.0, -1.0 ) ) * resolution ) ).xyz;\n vec3 rgbNE = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( 1.0, -1.0 ) ) * resolution ) ).xyz;\n vec3 rgbSW = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( -1.0, 1.0 ) ) * resolution ) ).xyz;\n vec3 rgbSE = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( 1.0, 1.0 ) ) * resolution ) ).xyz;\n vec4 rgbaM = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution ) );\n vec3 rgbM = rgbaM.xyz;\n float opacity = rgbaM.w;\n\n vec3 luma = vec3( 0.299, 0.587, 0.114 );\n\n float lumaNW = dot( rgbNW, luma );\n float lumaNE = dot( rgbNE, luma );\n float lumaSW = dot( rgbSW, luma );\n float lumaSE = dot( rgbSE, luma );\n float lumaM = dot( rgbM, luma );\n float lumaMin = min( lumaM, min( min( lumaNW, lumaNE ), min( lumaSW, lumaSE ) ) );\n float lumaMax = max( lumaM, max( max( lumaNW, lumaNE) , max( lumaSW, lumaSE ) ) );\n\n vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n\n float dirReduce = max( ( lumaNW + lumaNE + lumaSW + lumaSE ) * ( 0.25 * FXAA_REDUCE_MUL ), FXAA_REDUCE_MIN );\n\n float rcpDirMin = 1.0 / ( min( abs( dir.x ), abs( dir.y ) ) + dirReduce );\n dir = min( vec2( FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max( vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * resolution;\n\n vec3 rgbA = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * ( 1.0 / 3.0 - 0.5 ) ) ).xyz;\n rgbA += decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * ( 2.0 / 3.0 - 0.5 ) ) ).xyz;\n rgbA *= 0.5;\n\n vec3 rgbB = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * -0.5 ) ).xyz;\n rgbB += decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * 0.5 ) ).xyz;\n rgbB *= 0.25;\n rgbB += rgbA * 0.5;\n\n float lumaB = dot( rgbB, luma );\n\n if ( ( lumaB < lumaMin ) || ( lumaB > lumaMax ) )\n {\n gl_FragColor = vec4( rgbA, opacity );\n\n }\n else {\n\n gl_FragColor = vec4( rgbB, opacity );\n\n }\n}\n\n@end"},function(t,e){t.exports="@export qtek.compositor.fxaa3\n\nuniform sampler2D texture;\nuniform vec4 viewport : VIEWPORT;\n\nuniform float subpixel: 0.75;\nuniform float edgeThreshold: 0.125;\nuniform float edgeThresholdMin: 0.0625;\n\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n\nfloat FxaaLuma(vec4 rgba) { return rgba.y; }\nvec4 FxaaPixelShader(\n vec2 pos\n ,sampler2D tex\n ,vec2 fxaaQualityRcpFrame\n ,float fxaaQualitySubpix\n ,float fxaaQualityEdgeThreshold\n ,float fxaaQualityEdgeThresholdMin\n) {\n vec2 posM;\n posM.x = pos.x;\n posM.y = pos.y;\n vec4 rgbyM = decodeHDR(texture2D(texture, posM, 0.0));\n float lumaS = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2( 0.0, 1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaE = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2( 1.0, 0.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaN = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2( 0.0,-1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaW = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2(-1.0, 0.0) * fxaaQualityRcpFrame.xy), 0.0)));\n\n float maxSM = max(lumaS, rgbyM.y);\n float minSM = min(lumaS, rgbyM.y);\n float maxESM = max(lumaE, maxSM);\n float minESM = min(lumaE, minSM);\n float maxWN = max(lumaN, lumaW);\n float minWN = min(lumaN, lumaW);\n float rangeMax = max(maxWN, maxESM);\n float rangeMin = min(minWN, minESM);\n float rangeMaxScaled = rangeMax * fxaaQualityEdgeThreshold;\n float range = rangeMax - rangeMin;\n float rangeMaxClamped = max(fxaaQualityEdgeThresholdMin, rangeMaxScaled);\n bool earlyExit = range < rangeMaxClamped;\n if(earlyExit) return rgbyM;\n float lumaNW = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2(-1.0,-1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaSE = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2( 1.0, 1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaNE = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2( 1.0,-1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n float lumaSW = FxaaLuma(decodeHDR(texture2D(texture, posM + (vec2(-1.0, 1.0) * fxaaQualityRcpFrame.xy), 0.0)));\n\n float lumaNS = lumaN + lumaS;\n float lumaWE = lumaW + lumaE;\n float subpixRcpRange = 1.0/range;\n float subpixNSWE = lumaNS + lumaWE;\n float edgeHorz1 = (-2.0 * rgbyM.y) + lumaNS;\n float edgeVert1 = (-2.0 * rgbyM.y) + lumaWE;\n float lumaNESE = lumaNE + lumaSE;\n float lumaNWNE = lumaNW + lumaNE;\n float edgeHorz2 = (-2.0 * lumaE) + lumaNESE;\n float edgeVert2 = (-2.0 * lumaN) + lumaNWNE;\n float lumaNWSW = lumaNW + lumaSW;\n float lumaSWSE = lumaSW + lumaSE;\n float edgeHorz4 = (abs(edgeHorz1) * 2.0) + abs(edgeHorz2);\n float edgeVert4 = (abs(edgeVert1) * 2.0) + abs(edgeVert2);\n float edgeHorz3 = (-2.0 * lumaW) + lumaNWSW;\n float edgeVert3 = (-2.0 * lumaS) + lumaSWSE;\n float edgeHorz = abs(edgeHorz3) + edgeHorz4;\n float edgeVert = abs(edgeVert3) + edgeVert4;\n float subpixNWSWNESE = lumaNWSW + lumaNESE;\n float lengthSign = fxaaQualityRcpFrame.x;\n bool horzSpan = edgeHorz >= edgeVert;\n float subpixA = subpixNSWE * 2.0 + subpixNWSWNESE;\n if(!horzSpan) lumaN = lumaW;\n if(!horzSpan) lumaS = lumaE;\n if(horzSpan) lengthSign = fxaaQualityRcpFrame.y;\n float subpixB = (subpixA * (1.0/12.0)) - rgbyM.y;\n float gradientN = lumaN - rgbyM.y;\n float gradientS = lumaS - rgbyM.y;\n float lumaNN = lumaN + rgbyM.y;\n float lumaSS = lumaS + rgbyM.y;\n bool pairN = abs(gradientN) >= abs(gradientS);\n float gradient = max(abs(gradientN), abs(gradientS));\n if(pairN) lengthSign = -lengthSign;\n float subpixC = clamp(abs(subpixB) * subpixRcpRange, 0.0, 1.0);\n vec2 posB;\n posB.x = posM.x;\n posB.y = posM.y;\n vec2 offNP;\n offNP.x = (!horzSpan) ? 0.0 : fxaaQualityRcpFrame.x;\n offNP.y = ( horzSpan) ? 0.0 : fxaaQualityRcpFrame.y;\n if(!horzSpan) posB.x += lengthSign * 0.5;\n if( horzSpan) posB.y += lengthSign * 0.5;\n vec2 posN;\n posN.x = posB.x - offNP.x * 1.0;\n posN.y = posB.y - offNP.y * 1.0;\n vec2 posP;\n posP.x = posB.x + offNP.x * 1.0;\n posP.y = posB.y + offNP.y * 1.0;\n float subpixD = ((-2.0)*subpixC) + 3.0;\n float lumaEndN = FxaaLuma(decodeHDR(texture2D(texture, posN, 0.0)));\n float subpixE = subpixC * subpixC;\n float lumaEndP = FxaaLuma(decodeHDR(texture2D(texture, posP, 0.0)));\n if(!pairN) lumaNN = lumaSS;\n float gradientScaled = gradient * 1.0/4.0;\n float lumaMM = rgbyM.y - lumaNN * 0.5;\n float subpixF = subpixD * subpixE;\n bool lumaMLTZero = lumaMM < 0.0;\n lumaEndN -= lumaNN * 0.5;\n lumaEndP -= lumaNN * 0.5;\n bool doneN = abs(lumaEndN) >= gradientScaled;\n bool doneP = abs(lumaEndP) >= gradientScaled;\n if(!doneN) posN.x -= offNP.x * 1.5;\n if(!doneN) posN.y -= offNP.y * 1.5;\n bool doneNP = (!doneN) || (!doneP);\n if(!doneP) posP.x += offNP.x * 1.5;\n if(!doneP) posP.y += offNP.y * 1.5;\n if(doneNP) {\n if(!doneN) lumaEndN = FxaaLuma(decodeHDR(texture2D(texture, posN.xy, 0.0)));\n if(!doneP) lumaEndP = FxaaLuma(decodeHDR(texture2D(texture, posP.xy, 0.0)));\n if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n doneN = abs(lumaEndN) >= gradientScaled;\n doneP = abs(lumaEndP) >= gradientScaled;\n if(!doneN) posN.x -= offNP.x * 2.0;\n if(!doneN) posN.y -= offNP.y * 2.0;\n doneNP = (!doneN) || (!doneP);\n if(!doneP) posP.x += offNP.x * 2.0;\n if(!doneP) posP.y += offNP.y * 2.0;\n\n if(doneNP) {\n if(!doneN) lumaEndN = FxaaLuma(decodeHDR(texture2D(texture, posN.xy, 0.0)));\n if(!doneP) lumaEndP = FxaaLuma(decodeHDR(texture2D(texture, posP.xy, 0.0)));\n if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n doneN = abs(lumaEndN) >= gradientScaled;\n doneP = abs(lumaEndP) >= gradientScaled;\n if(!doneN) posN.x -= offNP.x * 4.0;\n if(!doneN) posN.y -= offNP.y * 4.0;\n doneNP = (!doneN) || (!doneP);\n if(!doneP) posP.x += offNP.x * 4.0;\n if(!doneP) posP.y += offNP.y * 4.0;\n\n if(doneNP) {\n if(!doneN) lumaEndN = FxaaLuma(decodeHDR(texture2D(texture, posN.xy, 0.0)));\n if(!doneP) lumaEndP = FxaaLuma(decodeHDR(texture2D(texture, posP.xy, 0.0)));\n if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;\n if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;\n doneN = abs(lumaEndN) >= gradientScaled;\n doneP = abs(lumaEndP) >= gradientScaled;\n if(!doneN) posN.x -= offNP.x * 12.0;\n if(!doneN) posN.y -= offNP.y * 12.0;\n doneNP = (!doneN) || (!doneP);\n if(!doneP) posP.x += offNP.x * 12.0;\n if(!doneP) posP.y += offNP.y * 12.0;\n }\n }\n }\n float dstN = posM.x - posN.x;\n float dstP = posP.x - posM.x;\n if(!horzSpan) dstN = posM.y - posN.y;\n if(!horzSpan) dstP = posP.y - posM.y;\n bool goodSpanN = (lumaEndN < 0.0) != lumaMLTZero;\n float spanLength = (dstP + dstN);\n bool goodSpanP = (lumaEndP < 0.0) != lumaMLTZero;\n float spanLengthRcp = 1.0/spanLength;\n bool directionN = dstN < dstP;\n float dst = min(dstN, dstP);\n bool goodSpan = directionN ? goodSpanN : goodSpanP;\n float subpixG = subpixF * subpixF;\n float pixelOffset = (dst * (-spanLengthRcp)) + 0.5;\n float subpixH = subpixG * fxaaQualitySubpix;\n float pixelOffsetGood = goodSpan ? pixelOffset : 0.0;\n float pixelOffsetSubpix = max(pixelOffsetGood, subpixH);\n if(!horzSpan) posM.x += pixelOffsetSubpix * lengthSign;\n if( horzSpan) posM.y += pixelOffsetSubpix * lengthSign;\n return vec4(decodeHDR(texture2D(texture, posM, 0.0)).xyz, rgbyM.y);\n\n}\n\nvoid main()\n{\n vec4 color = FxaaPixelShader(\n v_Texcoord,\n texture,\n vec2(1.0) / viewport.zw,\n subpixel,\n edgeThreshold,\n edgeThresholdMin\n );\n gl_FragColor = vec4(color.rgb, 1.0);\n}\n@end"},function(t,e){t.exports="@export qtek.compositor.hdr.composite\n\nuniform sampler2D texture;\n#ifdef BLOOM_ENABLED\nuniform sampler2D bloom;\n#endif\n#ifdef LENSFLARE_ENABLED\nuniform sampler2D lensflare;\nuniform sampler2D lensdirt;\n#endif\n\n#ifdef LUM_ENABLED\nuniform sampler2D lum;\n#endif\n\n#ifdef LUT_ENABLED\nuniform sampler2D lut;\n#endif\n\n#ifdef COLOR_CORRECTION\nuniform float brightness : 0.0;\nuniform float contrast : 1.0;\nuniform float saturation : 1.0;\n#endif\n\n#ifdef VIGNETTE\nuniform float vignetteDarkness: 1.0;\nuniform float vignetteOffset: 1.0;\n#endif\n\nuniform float exposure : 1.0;\nuniform float bloomIntensity : 0.25;\nuniform float lensflareIntensity : 1;\n\nvarying vec2 v_Texcoord;\n\nconst vec3 whiteScale = vec3(11.2);\n\n@import qtek.util.srgb\n\nvec3 uncharted2ToneMap(vec3 x)\n{\n const float A = 0.22; const float B = 0.30; const float C = 0.10; const float D = 0.20; const float E = 0.01; const float F = 0.30; \n return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;\n}\n\nvec3 filmicToneMap(vec3 color)\n{\n vec3 x = max(vec3(0.0), color - 0.004);\n return (x*(6.2*x+0.5))/(x*(6.2*x+1.7)+0.06);\n}\n\nvec3 ACESToneMapping(vec3 color)\n{\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\n\nfloat eyeAdaption(float fLum)\n{\n return mix(0.2, fLum, 0.5);\n}\n\n#ifdef LUT_ENABLED\nvec3 lutTransform(vec3 color) {\n float blueColor = color.b * 63.0;\n\n vec2 quad1;\n quad1.y = floor(floor(blueColor) / 8.0);\n quad1.x = floor(blueColor) - (quad1.y * 8.0);\n\n vec2 quad2;\n quad2.y = floor(ceil(blueColor) / 8.0);\n quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n\n vec2 texPos1;\n texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r);\n texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g);\n\n vec2 texPos2;\n texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r);\n texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g);\n\n vec4 newColor1 = texture2D(lut, texPos1);\n vec4 newColor2 = texture2D(lut, texPos2);\n\n vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n return newColor.rgb;\n}\n#endif\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec4 texel = vec4(0.0);\n#ifdef TEXTURE_ENABLED\n texel += decodeHDR(texture2D(texture, v_Texcoord));\n#endif\n\n#ifdef BLOOM_ENABLED\n vec4 bloomTexel = decodeHDR(texture2D(bloom, v_Texcoord));\n texel.rgb += bloomTexel.rgb * bloomTexel.a * bloomIntensity;\n#endif\n\n#ifdef LENSFLARE_ENABLED\n texel.rgb += decodeHDR(texture2D(lensflare, v_Texcoord)).rgb * texture2D(lensdirt, v_Texcoord).rgb * lensflareIntensity;\n#endif\n\n#ifdef LUM_ENABLED\n float fLum = texture2D(lum, vec2(0.5, 0.5)).r;\n float adaptedLumDest = 3.0 / (max(0.1, 1.0 + 10.0*eyeAdaption(fLum)));\n float exposureBias = adaptedLumDest * exposure;\n#else\n float exposureBias = exposure;\n#endif\n texel.rgb *= exposureBias;\n\n texel.rgb = ACESToneMapping(texel.rgb);\n texel = linearTosRGB(texel);\n\n#ifdef LUT_ENABLED\n texel.rgb = lutTransform(clamp(texel.rgb,vec3(0.0),vec3(1.0)));\n#endif\n\n#ifdef COLOR_CORRECTION\n texel.rgb = clamp(texel.rgb + vec3(brightness), 0.0, 1.0);\n texel.rgb = clamp((texel.rgb - vec3(0.5))*contrast+vec3(0.5), 0.0, 1.0);\n float lum = dot(texel.rgb, vec3(0.2125, 0.7154, 0.0721));\n texel.rgb = mix(vec3(lum), texel.rgb, saturation);\n#endif\n\n#ifdef VIGNETTE\n vec2 uv = (v_Texcoord - vec2(0.5)) * vec2(vignetteOffset);\n texel.rgb = mix(texel.rgb, vec3(1.0 - vignetteDarkness), dot(uv, uv));\n#endif\n\n gl_FragColor = encodeHDR(texel);\n\n#ifdef DEBUG\n #if DEBUG == 1\n gl_FragColor = encodeHDR(decodeHDR(texture2D(texture, v_Texcoord)));\n #elif DEBUG == 2\n gl_FragColor = encodeHDR(decodeHDR(texture2D(bloom, v_Texcoord)) * bloomIntensity);\n #elif DEBUG == 3\n gl_FragColor = encodeHDR(decodeHDR(texture2D(lensflare, v_Texcoord) * lensflareIntensity));\n #endif\n#endif\n #ifdef PREMULTIPLY_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif\n}\n\n@end"},function(t,e){t.exports="@export qtek.compositor.lensflare\n\n#define SAMPLE_NUMBER 8\n\nuniform sampler2D texture;\nuniform sampler2D lenscolor;\n\nuniform vec2 textureSize : [512, 512];\n\nuniform float dispersal : 0.3;\nuniform float haloWidth : 0.4;\nuniform float distortion : 1.0;\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n\nvec4 textureDistorted(\n in vec2 texcoord,\n in vec2 direction,\n in vec3 distortion\n) {\n return vec4(\n decodeHDR(texture2D(texture, texcoord + direction * distortion.r)).r,\n decodeHDR(texture2D(texture, texcoord + direction * distortion.g)).g,\n decodeHDR(texture2D(texture, texcoord + direction * distortion.b)).b,\n 1.0\n );\n}\n\nvoid main()\n{\n vec2 texcoord = -v_Texcoord + vec2(1.0); vec2 textureOffset = 1.0 / textureSize;\n\n vec2 ghostVec = (vec2(0.5) - texcoord) * dispersal;\n vec2 haloVec = normalize(ghostVec) * haloWidth;\n\n vec3 distortion = vec3(-textureOffset.x * distortion, 0.0, textureOffset.x * distortion);\n vec4 result = vec4(0.0);\n for (int i = 0; i < SAMPLE_NUMBER; i++)\n {\n vec2 offset = fract(texcoord + ghostVec * float(i));\n\n float weight = length(vec2(0.5) - offset) / length(vec2(0.5));\n weight = pow(1.0 - weight, 10.0);\n\n result += textureDistorted(offset, normalize(ghostVec), distortion) * weight;\n }\n\n result *= texture2D(lenscolor, vec2(length(vec2(0.5) - texcoord)) / length(vec2(0.5)));\n float weight = length(vec2(0.5) - fract(texcoord + haloVec)) / length(vec2(0.5));\n weight = pow(1.0 - weight, 10.0);\n vec2 offset = fract(texcoord + haloVec);\n result += textureDistorted(offset, normalize(ghostVec), distortion) * weight;\n\n gl_FragColor = result;\n}\n@end"; -},function(t,e){t.exports="@export qtek.compositor.hdr.log_lum\n\nvarying vec2 v_Texcoord;\n\nuniform sampler2D texture;\n\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec4 tex = decodeHDR(texture2D(texture, v_Texcoord));\n float luminance = dot(tex.rgb, w);\n luminance = log(luminance + 0.001);\n\n gl_FragColor = encodeHDR(vec4(vec3(luminance), 1.0));\n}\n\n@end\n\n@export qtek.compositor.hdr.lum_adaption\nvarying vec2 v_Texcoord;\n\nuniform sampler2D adaptedLum;\nuniform sampler2D currentLum;\n\nuniform float frameTime : 0.02;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n float fAdaptedLum = decodeHDR(texture2D(adaptedLum, vec2(0.5, 0.5))).r;\n float fCurrentLum = exp(encodeHDR(texture2D(currentLum, vec2(0.5, 0.5))).r);\n\n fAdaptedLum += (fCurrentLum - fAdaptedLum) * (1.0 - pow(0.98, 30.0 * frameTime));\n gl_FragColor = encodeHDR(vec4(vec3(fAdaptedLum), 1.0));\n}\n@end\n\n@export qtek.compositor.lum\n\nvarying vec2 v_Texcoord;\n\nuniform sampler2D texture;\n\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\n\nvoid main()\n{\n vec4 tex = texture2D( texture, v_Texcoord );\n float luminance = dot(tex.rgb, w);\n\n gl_FragColor = vec4(vec3(luminance), 1.0);\n}\n\n@end"},function(t,e){t.exports="\n@export qtek.compositor.lut\n\nvarying vec2 v_Texcoord;\n\nuniform sampler2D texture;\nuniform sampler2D lookup;\n\nvoid main()\n{\n\n vec4 tex = texture2D(texture, v_Texcoord);\n\n float blueColor = tex.b * 63.0;\n\n vec2 quad1;\n quad1.y = floor(floor(blueColor) / 8.0);\n quad1.x = floor(blueColor) - (quad1.y * 8.0);\n\n vec2 quad2;\n quad2.y = floor(ceil(blueColor) / 8.0);\n quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n\n vec2 texPos1;\n texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.r);\n texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.g);\n\n vec2 texPos2;\n texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.r);\n texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.g);\n\n vec4 newColor1 = texture2D(lookup, texPos1);\n vec4 newColor2 = texture2D(lookup, texPos2);\n\n vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n gl_FragColor = vec4(newColor.rgb, tex.w);\n}\n\n@end"},function(t,e){t.exports="@export qtek.compositor.output\n\n#define OUTPUT_ALPHA\n\nvarying vec2 v_Texcoord;\n\nuniform sampler2D texture;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec4 tex = decodeHDR(texture2D(texture, v_Texcoord));\n\n gl_FragColor.rgb = tex.rgb;\n\n#ifdef OUTPUT_ALPHA\n gl_FragColor.a = tex.a;\n#else\n gl_FragColor.a = 1.0;\n#endif\n\n gl_FragColor = encodeHDR(gl_FragColor);\n\n #ifdef PREMULTIPLY_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif\n}\n\n@end"},function(t,e){t.exports="\n@export qtek.compositor.upsample\n\n#define HIGH_QUALITY\n\nuniform sampler2D texture;\nuniform vec2 textureSize : [512, 512];\n\nuniform float sampleScale: 0.5;\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.rgbm\n\n@import qtek.util.clamp_sample\n\nvoid main()\n{\n\n#ifdef HIGH_QUALITY\n vec4 d = vec4(1.0, 1.0, -1.0, 0.0) / textureSize.xyxy * sampleScale;\n\n vec4 s;\n s = decodeHDR(clampSample(texture, v_Texcoord - d.xy));\n s += decodeHDR(clampSample(texture, v_Texcoord - d.wy)) * 2.0;\n s += decodeHDR(clampSample(texture, v_Texcoord - d.zy));\n\n s += decodeHDR(clampSample(texture, v_Texcoord + d.zw)) * 2.0;\n s += decodeHDR(clampSample(texture, v_Texcoord )) * 4.0;\n s += decodeHDR(clampSample(texture, v_Texcoord + d.xw)) * 2.0;\n\n s += decodeHDR(clampSample(texture, v_Texcoord + d.zy));\n s += decodeHDR(clampSample(texture, v_Texcoord + d.wy)) * 2.0;\n s += decodeHDR(clampSample(texture, v_Texcoord + d.xy));\n\n gl_FragColor = encodeHDR(s / 16.0);\n#else\n vec4 d = vec4(-1.0, -1.0, +1.0, +1.0) / textureSize.xyxy;\n\n vec4 s;\n s = decodeHDR(clampSample(texture, v_Texcoord + d.xy));\n s += decodeHDR(clampSample(texture, v_Texcoord + d.zy));\n s += decodeHDR(clampSample(texture, v_Texcoord + d.xw));\n s += decodeHDR(clampSample(texture, v_Texcoord + d.zw));\n\n gl_FragColor = encodeHDR(s / 4.0);\n#endif\n}\n\n@end"},function(t,e){t.exports="\n@export qtek.compositor.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\n\nvarying vec2 v_Texcoord;\n\nvoid main()\n{\n v_Texcoord = texcoord;\n gl_Position = worldViewProjection * vec4(position, 1.0);\n}\n\n@end"},function(t,e){t.exports="@export qtek.compositor.vignette\n\n#define OUTPUT_ALPHA\n\nvarying vec2 v_Texcoord;\n\nuniform sampler2D texture;\n\nuniform float darkness: 1;\nuniform float offset: 1;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec4 texel = decodeHDR(texture2D(texture, v_Texcoord));\n\n gl_FragColor.rgb = texel.rgb;\n\n vec2 uv = (v_Texcoord - vec2(0.5)) * vec2(offset);\n\n gl_FragColor = encodeHDR(vec4(mix(texel.rgb, vec3(1.0 - darkness), dot(uv, uv)), texel.a));\n}\n\n@end"},function(t,e){t.exports="@export qtek.deferred.ambient_light\n\nuniform sampler2D gBufferTexture1;\nuniform sampler2D gBufferTexture3;\nuniform vec3 lightColor;\n\nuniform vec2 windowSize: WINDOW_SIZE;\n\nvoid main()\n{\n vec2 uv = gl_FragCoord.xy / windowSize;\n\n vec4 texel1 = texture2D(gBufferTexture1, uv);\n if (dot(texel1.rgb, vec3(1.0)) == 0.0) {\n discard;\n }\n\n vec3 albedo = texture2D(gBufferTexture3, uv).rgb;\n gl_FragColor.rgb = lightColor * albedo;\n gl_FragColor.a = 1.0;\n}\n@end"},function(t,e){t.exports="@export qtek.deferred.ambient_cubemap_light\n\n@import qtek.deferred.chunk.light_head\n\nuniform vec3 lightColor;\nuniform samplerCube lightCubemap;\nuniform sampler2D brdfLookup;\n\nuniform vec3 eyePosition;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n vec3 V = normalize(eyePosition - position);\n vec3 L = reflect(-V, N);\n\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n float rough = clamp(1.0 - glossiness, 0.0, 1.0);\n float bias = rough * 5.0;\n vec2 brdfParam = texture2D(brdfLookup, vec2(rough, ndv)).xy;\n vec3 envWeight = specularColor * brdfParam.x + brdfParam.y;\n\n vec3 envTexel = RGBMDecode(textureCubeLodEXT(lightCubemap, L, bias), 51.5);\n gl_FragColor.rgb = lightColor * envTexel * envWeight;\n\n gl_FragColor.a = 1.0;\n}\n@end"},function(t,e){t.exports="@export qtek.deferred.ambient_sh_light\n\nuniform sampler2D gBufferTexture1;\nuniform sampler2D gBufferTexture3;\n\nuniform vec3 lightColor;\nuniform vec3 lightCoefficients[9];\n\nuniform vec2 windowSize: WINDOW_SIZE;\n\nvec3 calcAmbientSHLight(vec3 N) {\n return lightCoefficients[0]\n + lightCoefficients[1] * N.x\n + lightCoefficients[2] * N.y\n + lightCoefficients[3] * N.z\n + lightCoefficients[4] * N.x * N.z\n + lightCoefficients[5] * N.z * N.y\n + lightCoefficients[6] * N.y * N.x\n + lightCoefficients[7] * (3.0 * N.z * N.z - 1.0)\n + lightCoefficients[8] * (N.x * N.x - N.y * N.y);\n}\n\nvoid main()\n{\n vec2 uv = gl_FragCoord.xy / windowSize;\n\n vec4 texel1 = texture2D(gBufferTexture1, uv);\n if (dot(texel1.rgb, vec3(1.0)) == 0.0) {\n discard;\n }\n vec3 N = texel1.rgb * 2.0 - 1.0;\n vec3 albedo = texture2D(gBufferTexture3, uv).rgb;\n gl_FragColor.rgb = lightColor * albedo * calcAmbientSHLight(N);\n gl_FragColor.a = 1.0;\n}\n@end"},function(t,e){t.exports="@export qtek.deferred.chunk.light_head\n\nuniform sampler2D gBufferTexture1;\nuniform sampler2D gBufferTexture2;\nuniform sampler2D gBufferTexture3;\n\nuniform vec2 windowSize: WINDOW_SIZE;\n\nuniform vec4 viewport: VIEWPORT;\n\nuniform mat4 viewProjectionInv;\n\n\n#ifdef DEPTH_ENCODED\n@import qtek.util.decode_float\n#endif\n\n@end\n\n@export qtek.deferred.chunk.gbuffer_read\n \n vec2 uv = gl_FragCoord.xy / windowSize;\n\n vec2 uv2 = (gl_FragCoord.xy - viewport.xy) / viewport.zw;\n\n vec4 texel1 = texture2D(gBufferTexture1, uv);\n vec4 texel3 = texture2D(gBufferTexture3, uv);\n if (dot(texel1.rgb, vec3(1.0)) == 0.0) {\n discard;\n }\n\n float glossiness = texel1.a;\n float metalness = texel3.a;\n\n vec3 N = texel1.rgb * 2.0 - 1.0;\n\n float z = texture2D(gBufferTexture2, uv).r * 2.0 - 1.0;\n\n vec2 xy = uv2 * 2.0 - 1.0;\n\n vec4 projectedPos = vec4(xy, z, 1.0);\n vec4 p4 = viewProjectionInv * projectedPos;\n\n vec3 position = p4.xyz / p4.w;\n\n vec3 albedo = texel3.rgb;\n\n vec3 diffuseColor = albedo * (1.0 - metalness);\n vec3 specularColor = mix(vec3(0.04), albedo, metalness);\n@end\n\n@export qtek.deferred.chunk.light_equation\n\nfloat D_Phong(in float g, in float ndh) {\n float a = pow(8192.0, g);\n return (a + 2.0) / 8.0 * pow(ndh, a);\n}\n\nfloat D_GGX(in float g, in float ndh) {\n float r = 1.0 - g;\n float a = r * r;\n float tmp = ndh * ndh * (a - 1.0) + 1.0;\n return a / (3.1415926 * tmp * tmp);\n}\n\nvec3 F_Schlick(in float ndv, vec3 spec) {\n return spec + (1.0 - spec) * pow(1.0 - ndv, 5.0);\n}\n\nvec3 lightEquation(\n in vec3 lightColor, in vec3 diffuseColor, in vec3 specularColor,\n in float ndl, in float ndh, in float ndv, in float g\n)\n{\n return ndl * lightColor\n * (diffuseColor + D_Phong(g, ndh) * F_Schlick(ndv, specularColor));\n}\n\n@end"},function(t,e){t.exports="@export qtek.deferred.directional_light\n\n@import qtek.deferred.chunk.light_head\n\n@import qtek.deferred.chunk.light_equation\n\nuniform vec3 lightDirection;\nuniform vec3 lightColor;\n\nuniform vec3 eyePosition;\n\n#ifdef SHADOWMAP_ENABLED\nuniform sampler2D lightShadowMap;\nuniform float lightShadowMapSize;\nuniform mat4 lightMatrices[SHADOW_CASCADE];\nuniform float shadowCascadeClipsNear[SHADOW_CASCADE];\nuniform float shadowCascadeClipsFar[SHADOW_CASCADE];\n#endif\n\n@import qtek.plugin.shadow_map_common\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n vec3 L = -normalize(lightDirection);\n vec3 V = normalize(eyePosition - position);\n\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n\n gl_FragColor.rgb = lightEquation(\n lightColor, diffuseColor, specularColor, ndl, ndh, ndv, glossiness\n );\n\n#ifdef SHADOWMAP_ENABLED\n float shadowContrib = 1.0;\n for (int _idx_ = 0; _idx_ < SHADOW_CASCADE; _idx_++) {{\n if (\n z >= shadowCascadeClipsNear[_idx_] &&\n z <= shadowCascadeClipsFar[_idx_]\n ) {\n shadowContrib = computeShadowContrib(\n lightShadowMap, lightMatrices[_idx_], position, lightShadowMapSize,\n vec2(1.0 / float(SHADOW_CASCADE), 1.0),\n vec2(float(_idx_) / float(SHADOW_CASCADE), 0.0)\n );\n }\n }}\n\n gl_FragColor.rgb *= shadowContrib;\n#endif\n\n gl_FragColor.a = 1.0;\n}\n@end\n"},function(t,e){t.exports="@export qtek.deferred.gbuffer.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 worldInverseTranspose : WORLDINVERSETRANSPOSE;\nuniform mat4 world : WORLD;\n\nuniform vec2 uvRepeat;\nuniform vec2 uvOffset;\n\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\n\n#ifdef FIRST_PASS\nattribute vec3 normal : NORMAL;\n#endif\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\n\n#ifdef FIRST_PASS\nvarying vec3 v_Normal;\n\nattribute vec4 tangent : TANGENT;\nvarying vec3 v_Tangent;\nvarying vec3 v_Bitangent;\n#endif\n\n\nvarying vec2 v_Texcoord;\nvarying vec4 v_ProjPos;\n\nvoid main()\n{\n\n vec3 skinnedPosition = position;\n\n#ifdef FIRST_PASS\n vec3 skinnedNormal = normal;\n vec3 skinnedTangent = tangent.xyz;\n bool hasTangent = dot(tangent, tangent) > 0.0;\n#endif\n\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n\n #ifdef FIRST_PASS\n skinnedNormal = (skinMatrixWS * vec4(normal, 0.0)).xyz;\n if (hasTangent) {\n skinnedTangent = (skinMatrixWS * vec4(tangent.xyz, 0.0)).xyz;\n }\n #endif\n#endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0);\n\n v_Texcoord = texcoord * uvRepeat + uvOffset;\n\n#ifdef FIRST_PASS\n v_Normal = normalize((worldInverseTranspose * vec4(skinnedNormal, 0.0)).xyz);\n\n if (hasTangent) {\n v_Tangent = normalize((worldInverseTranspose * vec4(skinnedTangent, 0.0)).xyz);\n v_Bitangent = normalize(cross(v_Normal, v_Tangent) * tangent.w);\n }\n#endif\n\n v_ProjPos = gl_Position;\n}\n\n\n@end\n\n\n@export qtek.deferred.gbuffer1.fragment\n\nuniform float glossiness;\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Normal;\n\nuniform sampler2D normalMap;\nvarying vec3 v_Tangent;\nvarying vec3 v_Bitangent;\n\nuniform sampler2D roughnessMap;\n\nuniform bool useRoughnessMap;\n\nvarying vec4 v_ProjPos;\n\nvoid main()\n{\n vec3 N = v_Normal;\n\n if (dot(v_Tangent, v_Tangent) > 0.0) {\n vec3 normalTexel = texture2D(normalMap, v_Texcoord).xyz;\n if (dot(normalTexel, normalTexel) > 0.0) { N = normalTexel * 2.0 - 1.0;\n mat3 tbn = mat3(v_Tangent, v_Bitangent, v_Normal);\n N = normalize(tbn * N);\n }\n }\n\n gl_FragColor.rgb = (N + 1.0) * 0.5;\n\n \n float g = glossiness;\n\n if (useRoughnessMap) {\n vec4 glossTexel = texture2D(roughnessMap, v_Texcoord);\n g = clamp(-glossTexel.r + g * 2.0, 0.0, 1.0);\n }\n\n\n gl_FragColor.a = g;\n\n }\n@end\n\n@export qtek.deferred.gbuffer2.fragment\n\nuniform sampler2D diffuseMap;\nuniform sampler2D metalnessMap;\n\nuniform vec3 color;\nuniform float metalness;\n\nuniform bool useMetalnessMap;\nuniform bool linear;\n\nvarying vec2 v_Texcoord;\n\n@import qtek.util.srgb\n\nvoid main ()\n{\n float m = metalness;\n\n if (useMetalnessMap) {\n vec4 metalnessTexel = texture2D(metalnessMap, v_Texcoord);\n m = clamp(metalnessTexel.r + (m * 2.0 - 1.0), 0.0, 1.0);\n }\n vec4 texel = texture2D(diffuseMap, v_Texcoord);\n if (linear) {\n texel = sRGBToLinear(texel);\n }\n\n gl_FragColor.rgb = texel.rgb * color;\n\n gl_FragColor.a = m;\n}\n\n@end\n\n\n@export qtek.deferred.gbuffer.debug\n\n@import qtek.deferred.chunk.light_head\nuniform int debug: 0;\n\nvoid main ()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n if (debug == 0) {\n gl_FragColor = vec4(N, 1.0);\n }\n else if (debug == 1) {\n gl_FragColor = vec4(vec3(z), 1.0);\n }\n else if (debug == 2) {\n gl_FragColor = vec4(position, 1.0);\n }\n else if (debug == 3) {\n gl_FragColor = vec4(vec3(glossiness), 1.0);\n }\n else if (debug == 4) {\n gl_FragColor = vec4(vec3(metalness), 1.0);\n }\n else {\n gl_FragColor = vec4(albedo, 1.0);\n }\n}\n@end"},function(t,e){t.exports="@export qtek.deferred.light_volume.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\n\nvarying vec3 v_Position;\n\nvoid main()\n{\n gl_Position = worldViewProjection * vec4(position, 1.0);\n\n v_Position = position;\n}\n\n@end"},function(t,e){t.exports="@export qtek.deferred.point_light\n\n@import qtek.deferred.chunk.light_head\n\n@import qtek.util.calculate_attenuation\n\n@import qtek.deferred.chunk.light_equation\n\nuniform vec3 lightPosition;\nuniform vec3 lightColor;\nuniform float lightRange;\n\nuniform vec3 eyePosition;\n\n#ifdef SHADOWMAP_ENABLED\nuniform samplerCube lightShadowMap;\nuniform float lightShadowMapSize;\n#endif\n\nvarying vec3 v_Position;\n\n@import qtek.plugin.shadow_map_common\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n vec3 L = lightPosition - position;\n vec3 V = normalize(eyePosition - position);\n\n float dist = length(L);\n L /= dist;\n\n vec3 H = normalize(L + V);\n\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n float attenuation = lightAttenuation(dist, lightRange);\n gl_FragColor.rgb = attenuation * lightEquation(\n lightColor, diffuseColor, specularColor, ndl, ndh, ndv, glossiness\n );\n\n#ifdef SHADOWMAP_ENABLED\n float shadowContrib = computeShadowContribOmni(\n lightShadowMap, -L * dist, lightRange\n );\n gl_FragColor.rgb *= clamp(shadowContrib, 0.0, 1.0);\n#endif\n\n gl_FragColor.a = 1.0;\n}\n@end"},function(t,e){t.exports="@export qtek.deferred.sphere_light\n\n@import qtek.deferred.chunk.light_head\n\n@import qtek.util.calculate_attenuation\n\n@import qtek.deferred.chunk.light_equation\n\nuniform vec3 lightPosition;\nuniform vec3 lightColor;\nuniform float lightRange;\nuniform float lightRadius;\n\nuniform vec3 eyePosition;\n\nvarying vec3 v_Position;\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n\n vec3 L = lightPosition - position;\n\n vec3 V = normalize(eyePosition - position);\n\n float dist = length(L);\n vec3 R = reflect(V, N);\n float tmp = dot(L, R);\n vec3 cToR = tmp * R - L;\n float d = length(cToR);\n L = L + cToR * clamp(lightRadius / d, 0.0, 1.0);\n\n L = normalize(L);\n\n vec3 H = normalize(L + V);\n\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n float attenuation = lightAttenuation(dist, lightRange);\n gl_FragColor.rgb = lightColor * ndl * attenuation;\n\n glossiness = clamp(glossiness - lightRadius / 2.0 / dist, 0.0, 1.0);\n\n gl_FragColor.rgb = attenuation * lightEquation(\n lightColor, diffuseColor, specularColor, ndl, ndh, ndv, glossiness\n );\n\n gl_FragColor.a = 1.0;\n}\n@end"},function(t,e){t.exports="@export qtek.deferred.spot_light\n\n@import qtek.deferred.chunk.light_head\n\n@import qtek.deferred.chunk.light_equation\n\n@import qtek.util.calculate_attenuation\n\nuniform vec3 lightPosition;\nuniform vec3 lightDirection;\nuniform vec3 lightColor;\nuniform float umbraAngleCosine;\nuniform float penumbraAngleCosine;\nuniform float lightRange;\nuniform float falloffFactor;\n\nuniform vec3 eyePosition;\n\n#ifdef SHADOWMAP_ENABLED\nuniform sampler2D lightShadowMap;\nuniform mat4 lightMatrix;\nuniform float lightShadowMapSize;\n#endif\n\n@import qtek.plugin.shadow_map_common\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n vec3 L = lightPosition - position;\n vec3 V = normalize(eyePosition - position);\n\n float dist = length(L);\n L /= dist;\n\n\n float attenuation = lightAttenuation(dist, lightRange);\n float c = dot(-normalize(lightDirection), L);\n\n float falloff = clamp((c - umbraAngleCosine) / (penumbraAngleCosine - umbraAngleCosine), 0.0, 1.0);\n falloff = pow(falloff, falloffFactor);\n\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n\n gl_FragColor.rgb = (1.0 - falloff) * attenuation * lightEquation(\n lightColor, diffuseColor, specularColor, ndl, ndh, ndv, glossiness\n );\n\n#ifdef SHADOWMAP_ENABLED\n float shadowContrib = computeShadowContrib(\n lightShadowMap, lightMatrix, position, lightShadowMapSize\n );\n gl_FragColor.rgb *= shadowContrib;\n#endif\n\n gl_FragColor.a = 1.0;\n}\n@end\n"},function(t,e){t.exports="@export qtek.deferred.tube_light\n\n@import qtek.deferred.chunk.light_head\n\n@import qtek.util.calculate_attenuation\n\n@import qtek.deferred.chunk.light_equation\n\nuniform vec3 lightPosition;\nuniform vec3 lightColor;\nuniform float lightRange;\nuniform vec3 lightExtend;\n\nuniform vec3 eyePosition;\n\nvarying vec3 v_Position;\n\nvoid main()\n{\n @import qtek.deferred.chunk.gbuffer_read\n\n vec3 L = lightPosition - position;\n\n vec3 V = normalize(eyePosition - position);\n\n vec3 R = reflect(V, N);\n\n vec3 L0 = lightPosition - lightExtend - position;\n vec3 L1 = lightPosition + lightExtend - position;\n vec3 LD = L1 - L0;\n\n float len0 = length(L0);\n float len1 = length(L1);\n float irra = 2.0 * clamp(dot(N, L0) / (2.0 * len0) + dot(N, L1) / (2.0 * len1), 0.0, 1.0);\n\n float LDDotR = dot(R, LD);\n float t = (LDDotR * dot(R, L0) - dot(L0, LD)) / (dot(LD, LD) - LDDotR * LDDotR);\n t = clamp(t, 0.0, 1.0);\n L = L0 + t * LD;\n float dist = length(L);\n L /= dist;\n\n vec3 H = normalize(L + V);\n\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n\n glossiness = clamp(glossiness - 0.0 / 2.0 / dist, 0.0, 1.0);\n\n gl_FragColor.rgb = lightColor * irra * lightAttenuation(dist, lightRange)\n * (diffuseColor + D_Phong(glossiness, ndh) * F_Schlick(ndv, specularColor));\n\n gl_FragColor.a = 1.0;\n}\n@end"},function(t,e){t.exports="vec3 calcAmbientSHLight(int idx, vec3 N) {\n int offset = 9 * idx;\n\n return ambientSHLightCoefficients[0]\n + ambientSHLightCoefficients[1] * N.x\n + ambientSHLightCoefficients[2] * N.y\n + ambientSHLightCoefficients[3] * N.z\n + ambientSHLightCoefficients[4] * N.x * N.z\n + ambientSHLightCoefficients[5] * N.z * N.y\n + ambientSHLightCoefficients[6] * N.y * N.x\n + ambientSHLightCoefficients[7] * (3.0 * N.z * N.z - 1.0)\n + ambientSHLightCoefficients[8] * (N.x * N.x - N.y * N.y);\n}"},function(t,e){t.exports="/**\n * http: */\n\n@export qtek.lambert.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 worldInverseTranspose : WORLDINVERSETRANSPOSE;\nuniform mat4 world : WORLD;\n\nuniform vec2 uvRepeat : [1.0, 1.0];\nuniform vec2 uvOffset : [0.0, 0.0];\n\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\nattribute vec3 normal : NORMAL;\n\nattribute vec3 barycentric;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\nvarying vec3 v_Barycentric;\n\nvoid main()\n{\n\n vec3 skinnedPosition = position;\n vec3 skinnedNormal = normal;\n\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n skinnedNormal = (skinMatrixWS * vec4(normal, 0.0)).xyz;\n#endif\n\n gl_Position = worldViewProjection * vec4( skinnedPosition, 1.0 );\n\n v_Texcoord = texcoord * uvRepeat + uvOffset;\n v_Normal = normalize( ( worldInverseTranspose * vec4(skinnedNormal, 0.0) ).xyz );\n v_WorldPosition = ( world * vec4( skinnedPosition, 1.0) ).xyz;\n\n v_Barycentric = barycentric;\n}\n\n@end\n\n\n@export qtek.lambert.fragment\n\n#define ALPHA_TEST_THRESHOLD 0.5\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\n\nuniform sampler2D diffuseMap;\nuniform sampler2D alphaMap;\n\nuniform vec3 color : [1.0, 1.0, 1.0];\nuniform vec3 emission : [0.0, 0.0, 0.0];\nuniform float alpha : 1.0;\n\nuniform float lineWidth : 0.0;\nuniform vec3 lineColor : [0.0, 0.0, 0.0];\nvarying vec3 v_Barycentric;\n\n#ifdef AMBIENT_LIGHT_COUNT\n@import qtek.header.ambient_light\n#endif\n#ifdef AMBIENT_SH_LIGHT_COUNT\n@import qtek.header.ambient_sh_light\n#endif\n#ifdef POINT_LIGHT_COUNT\n@import qtek.header.point_light\n#endif\n#ifdef DIRECTIONAL_LIGHT_COUNT\n@import qtek.header.directional_light\n#endif\n#ifdef SPOT_LIGHT_COUNT\n@import qtek.header.spot_light\n#endif\n\n@import qtek.util.calculate_attenuation\n\n@import qtek.util.edge_factor\n\n@import qtek.util.rgbm\n\n@import qtek.plugin.compute_shadow_map\n\nvoid main()\n{\n#ifdef RENDER_NORMAL\n gl_FragColor = vec4(v_Normal * 0.5 + 0.5, 1.0);\n return;\n#endif\n#ifdef RENDER_TEXCOORD\n gl_FragColor = vec4(v_Texcoord, 1.0, 1.0);\n return;\n#endif\n\n gl_FragColor = vec4(color, alpha);\n\n#ifdef DIFFUSEMAP_ENABLED\n vec4 tex = texture2D( diffuseMap, v_Texcoord );\n#ifdef SRGB_DECODE\n tex.rgb = pow(tex.rgb, vec3(2.2));\n#endif\n gl_FragColor.rgb *= tex.rgb;\n#ifdef DIFFUSEMAP_ALPHA_ALPHA\n gl_FragColor.a *= tex.a;\n#endif\n#endif\n\n vec3 diffuseColor = vec3(0.0, 0.0, 0.0);\n\n#ifdef AMBIENT_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_LIGHT_COUNT; _idx_++)\n {\n diffuseColor += ambientLightColor[_idx_];\n }\n#endif\n#ifdef AMBIENT_SH_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_SH_LIGHT_COUNT; _idx_++)\n {{\n diffuseColor += calcAmbientSHLight(_idx_, v_Normal) * ambientSHLightColor[_idx_];\n }}\n#endif\n#ifdef POINT_LIGHT_COUNT\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsPoint[POINT_LIGHT_COUNT];\n if( shadowEnabled )\n {\n computeShadowOfPointLights(v_WorldPosition, shadowContribsPoint);\n }\n#endif\n for(int i = 0; i < POINT_LIGHT_COUNT; i++)\n {\n\n vec3 lightPosition = pointLightPosition[i];\n vec3 lightColor = pointLightColor[i];\n float range = pointLightRange[i];\n\n vec3 lightDirection = lightPosition - v_WorldPosition;\n\n float dist = length(lightDirection);\n float attenuation = lightAttenuation(dist, range);\n\n lightDirection /= dist;\n\n float ndl = dot( v_Normal, lightDirection );\n\n float shadowContrib = 1.0;\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\n if( shadowEnabled )\n {\n shadowContrib = shadowContribsPoint[i];\n }\n#endif\n\n diffuseColor += lightColor * clamp(ndl, 0.0, 1.0) * attenuation * shadowContrib;\n }\n#endif\n#ifdef DIRECTIONAL_LIGHT_COUNT\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir);\n }\n#endif\n for(int i = 0; i < DIRECTIONAL_LIGHT_COUNT; i++)\n {\n vec3 lightDirection = -directionalLightDirection[i];\n vec3 lightColor = directionalLightColor[i];\n\n float ndl = dot(v_Normal, normalize(lightDirection));\n\n float shadowContrib = 1.0;\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n if( shadowEnabled )\n {\n shadowContrib = shadowContribsDir[i];\n }\n#endif\n\n diffuseColor += lightColor * clamp(ndl, 0.0, 1.0) * shadowContrib;\n }\n#endif\n\n#ifdef SPOT_LIGHT_COUNT\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsSpot[SPOT_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfSpotLights(v_WorldPosition, shadowContribsSpot);\n }\n#endif\n for(int i = 0; i < SPOT_LIGHT_COUNT; i++)\n {\n vec3 lightPosition = -spotLightPosition[i];\n vec3 spotLightDirection = -normalize( spotLightDirection[i] );\n vec3 lightColor = spotLightColor[i];\n float range = spotLightRange[i];\n float a = spotLightUmbraAngleCosine[i];\n float b = spotLightPenumbraAngleCosine[i];\n float falloffFactor = spotLightFalloffFactor[i];\n\n vec3 lightDirection = lightPosition - v_WorldPosition;\n float dist = length(lightDirection);\n float attenuation = lightAttenuation(dist, range);\n\n lightDirection /= dist;\n float c = dot(spotLightDirection, lightDirection);\n\n float falloff;\n falloff = clamp((c - a) /( b - a), 0.0, 1.0);\n falloff = pow(falloff, falloffFactor);\n\n float ndl = dot(v_Normal, lightDirection);\n ndl = clamp(ndl, 0.0, 1.0);\n\n float shadowContrib = 1.0;\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\n if( shadowEnabled )\n {\n shadowContrib = shadowContribsSpot[i];\n }\n#endif\n diffuseColor += lightColor * ndl * attenuation * (1.0-falloff) * shadowContrib;\n }\n#endif\n\n gl_FragColor.rgb *= diffuseColor;\n gl_FragColor.rgb += emission;\n if(lineWidth > 0.01)\n {\n gl_FragColor.rgb = gl_FragColor.rgb * mix(lineColor, vec3(1.0), edgeFactor(lineWidth));\n }\n\n#ifdef ALPHA_TEST\n if (gl_FragColor.a < ALPHA_TEST_THRESHOLD) {\n discard;\n }\n#endif\n\n gl_FragColor = encodeHDR(gl_FragColor);\n}\n\n@end"},function(t,e){t.exports="@export qtek.sm.depth.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\n\n#ifdef SHADOW_TRANSPARENT\nattribute vec2 texcoord : TEXCOORD_0;\n#endif\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec4 v_ViewPosition;\n\n#ifdef SHADOW_TRANSPARENT\nvarying vec2 v_Texcoord;\n#endif\n\nvoid main(){\n\n vec3 skinnedPosition = position;\n\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n#endif\n\n v_ViewPosition = worldViewProjection * vec4(skinnedPosition, 1.0);\n gl_Position = v_ViewPosition;\n\n#ifdef SHADOW_TRANSPARENT\n v_Texcoord = texcoord;\n#endif\n}\n@end\n\n@export qtek.sm.depth.fragment\n\nvarying vec4 v_ViewPosition;\n\n#ifdef SHADOW_TRANSPARENT\nvarying vec2 v_Texcoord;\n#endif\n\nuniform float bias : 0.001;\nuniform float slopeScale : 1.0;\n\n#ifdef SHADOW_TRANSPARENT\nuniform sampler2D transparentMap;\n#endif\n\n@import qtek.util.encode_float\n\nvoid main(){\n float depth = v_ViewPosition.z / v_ViewPosition.w;\n \n#ifdef USE_VSM\n depth = depth * 0.5 + 0.5;\n float moment1 = depth;\n float moment2 = depth * depth;\n\n float dx = dFdx(depth);\n float dy = dFdy(depth);\n moment2 += 0.25*(dx*dx+dy*dy);\n\n gl_FragColor = vec4(moment1, moment2, 0.0, 1.0);\n#else\n float dx = dFdx(depth);\n float dy = dFdy(depth);\n depth += sqrt(dx*dx + dy*dy) * slopeScale + bias;\n\n#ifdef SHADOW_TRANSPARENT\n if (texture2D(transparentMap, v_Texcoord).a <= 0.1) {\n gl_FragColor = encodeFloat(0.9999);\n return;\n }\n#endif\n\n gl_FragColor = encodeFloat(depth * 0.5 + 0.5);\n#endif\n}\n@end\n\n@export qtek.sm.debug_depth\n\nuniform sampler2D depthMap;\nvarying vec2 v_Texcoord;\n\n@import qtek.util.decode_float\n\nvoid main() {\n vec4 tex = texture2D(depthMap, v_Texcoord);\n#ifdef USE_VSM\n gl_FragColor = vec4(tex.rgb, 1.0);\n#else\n float depth = decodeFloat(tex);\n gl_FragColor = vec4(depth, depth, depth, 1.0);\n#endif\n}\n\n@end\n\n\n@export qtek.sm.distance.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 world : WORLD;\n\nattribute vec3 position : POSITION;\n\n#ifdef SKINNING\nattribute vec3 boneWeight;\nattribute vec4 boneIndex;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec3 v_WorldPosition;\n\nvoid main (){\n\n vec3 skinnedPosition = position;\n#ifdef SKINNING\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n#endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition , 1.0);\n v_WorldPosition = (world * vec4(skinnedPosition, 1.0)).xyz;\n}\n\n@end\n\n@export qtek.sm.distance.fragment\n\nuniform vec3 lightPosition;\nuniform float range : 100;\n\nvarying vec3 v_WorldPosition;\n\n@import qtek.util.encode_float\n\nvoid main(){\n float dist = distance(lightPosition, v_WorldPosition);\n#ifdef USE_VSM\n gl_FragColor = vec4(dist, dist * dist, 0.0, 0.0);\n#else\n dist = dist / range;\n gl_FragColor = encodeFloat(dist);\n#endif\n}\n@end\n\n@export qtek.plugin.shadow_map_common\n\n@import qtek.util.decode_float\n\nfloat tapShadowMap(sampler2D map, vec2 uv, float z){\n vec4 tex = texture2D(map, uv);\n return step(z, decodeFloat(tex) * 2.0 - 1.0);\n}\n\nfloat pcf(sampler2D map, vec2 uv, float z, float textureSize, vec2 scale) {\n\n float shadowContrib = tapShadowMap(map, uv, z);\n vec2 offset = vec2(1.0 / textureSize) * scale;\n#ifdef PCF_KERNEL_SIZE\n for (int _idx_ = 0; _idx_ < PCF_KERNEL_SIZE; _idx_++) {{\n shadowContrib += tapShadowMap(map, uv + offset * pcfKernel[_idx_], z);\n }}\n\n return shadowContrib / float(PCF_KERNEL_SIZE + 1);\n#endif\n shadowContrib += tapShadowMap(map, uv+vec2(offset.x, 0.0), z);\n shadowContrib += tapShadowMap(map, uv+vec2(offset.x, offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(0.0, offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, 0.0), z);\n shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, -offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(offset.x, -offset.y), z);\n shadowContrib += tapShadowMap(map, uv+vec2(0.0, -offset.y), z);\n\n return shadowContrib;\n}\n\nfloat pcf(sampler2D map, vec2 uv, float z, float textureSize) {\n return pcf(map, uv, z, textureSize, vec2(1.0));\n}\n\nfloat chebyshevUpperBound(vec2 moments, float z){\n float p = 0.0;\n z = z * 0.5 + 0.5;\n if (z <= moments.x) {\n p = 1.0;\n }\n float variance = moments.y - moments.x * moments.x;\n variance = max(variance, 0.0000001);\n float mD = moments.x - z;\n float pMax = variance / (variance + mD * mD);\n pMax = clamp((pMax-0.4)/(1.0-0.4), 0.0, 1.0);\n return max(p, pMax);\n}\nfloat computeShadowContrib(\n sampler2D map, mat4 lightVPM, vec3 position, float textureSize, vec2 scale, vec2 offset\n) {\n\n vec4 posInLightSpace = lightVPM * vec4(position, 1.0);\n posInLightSpace.xyz /= posInLightSpace.w;\n float z = posInLightSpace.z;\n if(all(greaterThan(posInLightSpace.xyz, vec3(-0.99, -0.99, -1.0))) &&\n all(lessThan(posInLightSpace.xyz, vec3(0.99, 0.99, 1.0)))){\n vec2 uv = (posInLightSpace.xy+1.0) / 2.0;\n\n #ifdef USE_VSM\n vec2 moments = texture2D(map, uv * scale + offset).xy;\n return chebyshevUpperBound(moments, z);\n #else\n return pcf(map, uv * scale + offset, z, textureSize, scale);\n #endif\n }\n return 1.0;\n}\n\nfloat computeShadowContrib(sampler2D map, mat4 lightVPM, vec3 position, float textureSize) {\n return computeShadowContrib(map, lightVPM, position, textureSize, vec2(1.0), vec2(0.0));\n}\n\nfloat computeShadowContribOmni(samplerCube map, vec3 direction, float range)\n{\n float dist = length(direction);\n vec4 shadowTex = textureCube(map, direction);\n\n#ifdef USE_VSM\n vec2 moments = shadowTex.xy;\n float variance = moments.y - moments.x * moments.x;\n float mD = moments.x - dist;\n float p = variance / (variance + mD * mD);\n if(moments.x + 0.001 < dist){\n return clamp(p, 0.0, 1.0);\n }else{\n return 1.0;\n }\n#else\n return step(dist, (decodeFloat(shadowTex) + 0.0002) * range);\n#endif\n}\n\n@end\n\n\n\n@export qtek.plugin.compute_shadow_map\n\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT) || defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT) || defined(POINT_LIGHT_SHADOWMAP_COUNT)\n\n#ifdef SPOT_LIGHT_SHADOWMAP_COUNT\nuniform sampler2D spotLightShadowMaps[SPOT_LIGHT_SHADOWMAP_COUNT];\nuniform mat4 spotLightMatrices[SPOT_LIGHT_SHADOWMAP_COUNT];\nuniform float spotLightShadowMapSizes[SPOT_LIGHT_SHADOWMAP_COUNT];\n#endif\n\n#ifdef DIRECTIONAL_LIGHT_SHADOWMAP_COUNT\n#if defined(SHADOW_CASCADE)\nuniform sampler2D directionalLightShadowMaps[1];\nuniform mat4 directionalLightMatrices[SHADOW_CASCADE];\nuniform float directionalLightShadowMapSizes[1];\nuniform float shadowCascadeClipsNear[SHADOW_CASCADE];\nuniform float shadowCascadeClipsFar[SHADOW_CASCADE];\n#else\nuniform sampler2D directionalLightShadowMaps[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT];\nuniform mat4 directionalLightMatrices[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT];\nuniform float directionalLightShadowMapSizes[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT];\n#endif\n#endif\n\n#ifdef POINT_LIGHT_SHADOWMAP_COUNT\nuniform samplerCube pointLightShadowMaps[POINT_LIGHT_SHADOWMAP_COUNT];\nuniform float pointLightShadowMapSizes[POINT_LIGHT_SHADOWMAP_COUNT];\n#endif\n\nuniform bool shadowEnabled : true;\n\n#ifdef PCF_KERNEL_SIZE\nuniform vec2 pcfKernel[PCF_KERNEL_SIZE];\n#endif\n\n@import qtek.plugin.shadow_map_common\n\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\n\nvoid computeShadowOfSpotLights(vec3 position, inout float shadowContribs[SPOT_LIGHT_COUNT] ) {\n float shadowContrib;\n for(int _idx_ = 0; _idx_ < SPOT_LIGHT_SHADOWMAP_COUNT; _idx_++) {{\n shadowContrib = computeShadowContrib(\n spotLightShadowMaps[_idx_], spotLightMatrices[_idx_], position,\n spotLightShadowMapSizes[_idx_]\n );\n shadowContribs[_idx_] = shadowContrib;\n }}\n for(int _idx_ = SPOT_LIGHT_SHADOWMAP_COUNT; _idx_ < SPOT_LIGHT_COUNT; _idx_++){{\n shadowContribs[_idx_] = 1.0;\n }}\n}\n\n#endif\n\n\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n\n#ifdef SHADOW_CASCADE\n\nvoid computeShadowOfDirectionalLights(vec3 position, inout float shadowContribs[DIRECTIONAL_LIGHT_COUNT]){\n float depth = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far)\n / (gl_DepthRange.far - gl_DepthRange.near);\n\n float shadowContrib;\n shadowContribs[0] = 1.0;\n\n for (int _idx_ = 0; _idx_ < SHADOW_CASCADE; _idx_++) {{\n if (\n depth >= shadowCascadeClipsNear[_idx_] &&\n depth <= shadowCascadeClipsFar[_idx_]\n ) {\n shadowContrib = computeShadowContrib(\n directionalLightShadowMaps[0], directionalLightMatrices[_idx_], position,\n directionalLightShadowMapSizes[0],\n vec2(1.0 / float(SHADOW_CASCADE), 1.0),\n vec2(float(_idx_) / float(SHADOW_CASCADE), 0.0)\n );\n shadowContribs[0] = shadowContrib;\n }\n }}\n for(int _idx_ = DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++) {{\n shadowContribs[_idx_] = 1.0;\n }}\n}\n\n#else\n\nvoid computeShadowOfDirectionalLights(vec3 position, inout float shadowContribs[DIRECTIONAL_LIGHT_COUNT]){\n float shadowContrib;\n\n for(int _idx_ = 0; _idx_ < DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_++) {{\n shadowContrib = computeShadowContrib(\n directionalLightShadowMaps[_idx_], directionalLightMatrices[_idx_], position,\n directionalLightShadowMapSizes[_idx_]\n );\n shadowContribs[_idx_] = shadowContrib;\n }}\n for(int _idx_ = DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++) {{\n shadowContribs[_idx_] = 1.0;\n }}\n}\n#endif\n\n#endif\n\n\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\n\nvoid computeShadowOfPointLights(vec3 position, inout float shadowContribs[POINT_LIGHT_COUNT] ){\n vec3 lightPosition;\n vec3 direction;\n for(int _idx_ = 0; _idx_ < POINT_LIGHT_SHADOWMAP_COUNT; _idx_++) {{\n lightPosition = pointLightPosition[_idx_];\n direction = position - lightPosition;\n shadowContribs[_idx_] = computeShadowContribOmni(pointLightShadowMaps[_idx_], direction, pointLightRange[_idx_]);\n }}\n for(int _idx_ = POINT_LIGHT_SHADOWMAP_COUNT; _idx_ < POINT_LIGHT_COUNT; _idx_++) {{\n shadowContribs[_idx_] = 1.0;\n }}\n}\n\n#endif\n\n#endif\n\n@end"; -},function(t,e){t.exports="@export qtek.wireframe.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 world : WORLD;\n\nattribute vec3 position : POSITION;\nattribute vec3 barycentric;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec3 v_Barycentric;\n\nvoid main()\n{\n\n vec3 skinnedPosition = position;\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n#endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0 );\n\n v_Barycentric = barycentric;\n}\n\n@end\n\n\n@export qtek.wireframe.fragment\n\nuniform vec3 color : [0.0, 0.0, 0.0];\n\nuniform float alpha : 1.0;\nuniform float lineWidth : 1.0;\n\nvarying vec3 v_Barycentric;\n\n\n@import qtek.util.edge_factor\n\nvoid main()\n{\n\n gl_FragColor.rgb = color;\n gl_FragColor.a = (1.0-edgeFactor(lineWidth)) * alpha;\n}\n\n@end"},function(t,e,n){function r(t,e){this.p0=t,this.p1=e,this._linkedListEntry=null}function i(t,e,n,r,i,a){return(n-t)*(a-r)-(r-e)*(i-n)}function a(t,e,n,r,a,o,s,u){return!(i(t,e,a,o,s,u)<=0||i(t,e,s,u,n,r)<=0||i(s,u,a,o,n,r)<=0)}var o=n(39),s=n(13),u=1,l=2,c=function(){this._points,this._triangles,this.maxGridNumber=50,this.minGridNumber=0,this._gridNumber=20,this._boundingBox=[[1/0,1/0],[-(1/0),-(1/0)]],this._nPoints=0,this._nTriangle=0,this._pointTypes,this._grids=[],this._gridWidth=0,this._gridHeight=0,this._edgeList=new o,this._edgeOut=[],this._edgeIn=[],this._candidates=[]};c.prototype.triangulate=function(t){if(this._nPoints=t.length/2,!(this._nPoints<3))return this._gridNumber=Math.ceil(Math.sqrt(this._nPoints)),this._gridNumber=Math.max(Math.min(this._gridNumber,this.maxGridNumber),this.minGridNumber),this._points=t,this._reset(),this._prepare(),this._earClipping(),this._triangles.length=3*this._nTriangle,this._triangles},c.prototype._reset=function(){this._nTriangle=0,this._edgeList.clear(),this._candidates.length=0,this._pointTypes=new s.Int8Array(this._points.length),this._boundingBox[0][0]=this._boundingBox[0][1]=1/0,this._boundingBox[1][0]=this._boundingBox[1][1]=-(1/0);for(var t=this._gridNumber*this._gridNumber,e=this._grids.length,n=0;nt[1][0]&&(t[1][0]=h),f>t[1][1]&&(t[1][1]=f),t[0][0]-=.1,t[0][1]-=.1,t[1][0]+=.1,t[1][1]+=.1;var p=i(s,c,h,f,d,_);this._pointTypes[r]=p<=0?u:l,p<=0&&this._candidates.push(r),a=r,r++}this._gridWidth=(t[1][0]-t[0][0])/this._gridNumber,this._gridHeight=(t[1][1]-t[0][1])/this._gridNumber;for(var r=0;rn&&(n=s),u>r&&(r=u),ln&&(n=l),c>r&&(r=c),i[0][0]=Math.floor((t-h[0][0])/this._gridWidth),i[1][0]=Math.floor((n-h[0][0])/this._gridWidth),i[0][1]=Math.floor((e-h[0][1])/this._gridHeight),i[1][1]=Math.floor((r-h[0][1])/this._gridHeight),i}}(),c.prototype.isTriangleConvex2=function(t,e,n){return this.triangleArea(t,e,n)<0},c.prototype.triangleArea=function(t,e,n){var r=this._points,i=r[2*t],a=r[2*t+1],o=r[2*e],s=r[2*e+1],u=r[2*n],l=r[2*n+1];return(o-i)*(l-s)-(s-a)*(u-o)};var h={flatPoints:function(t){for(var e=new s.Float64Array(2*t.length),n=0;n=65535?u.indices=new Uint32Array(3*v):u.indices=new Uint16Array(3*v);for(var E=0,b=0,S=a.isUseIndices(),A=0;A0;){for(var E=[],b=[],S=[],A=0,g=0;g=0&&b[L]===-1&&(A65535?H.indices=new Uint32Array(3*k.triangles.length):H.indices=new Uint16Array(3*k.triangles.length);var Y=0;W=0;for(var g=0;g=0?H.attributes.joint.value[J]=F[L]:H.attributes.joint.value[J]=-1}W++}H.indices[Y++]=D[C]}H.updateBoundingBox(),I.add(G)}for(var $=t.children(),g=0;g<$.length;g++)I.add($[g]);if(I.position.copy(t.position),I.rotation.copy(t.rotation),I.scale.copy(t.scale),n&&t.getParent()){var tt=t.getParent();tt.remove(t),tt.add(I)}return I}}};t.exports=h},function(t,e,n){function r(t,e){var n=t[0],r=t[1],i=t[2];return 0===e?1:1===e?n:2===e?r:3===e?i:4===e?n*i:5===e?r*i:6===e?n*r:7===e?3*i*i-1:n*n-r*r}function i(t,e,n,i){for(var a=new u.Float32Array(27),o=_.create(),s=_.create(),l=_.create(),c=0;c<9;c++){for(var h=_.create(),f=0;f 0.0) {\n float G = G_Smith(roughness, NoV, NoL);\n float G_Vis = G * VoH / (NoH * NoV);\n float Fc = pow(1.0 - VoH, 5.0);\n A += (1.0 - Fc) * G_Vis;\n B += Fc * G_Vis;\n }\n }\n\n gl_FragColor = vec4(vec2(A, B) / fSampleNumber, 0.0, 1.0);\n}\n"},function(t,e){t.exports="#define SAMPLE_NUMBER 1024\n#define PI 3.14159265358979\n\nuniform mat4 viewInverse : VIEWINVERSE;\nuniform samplerCube environmentMap;\nuniform sampler2D normalDistribution;\n\nuniform float roughness : 0.5;\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_WorldPosition;\n\nconst float fSampleNumber = float(SAMPLE_NUMBER);\n\n@import qtek.util.rgbm\n\nvec3 importanceSampleNormal(float i, float roughness, vec3 N) {\n vec3 H = texture2D(normalDistribution, vec2(roughness, i)).rgb;\n\n vec3 upVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);\n vec3 tangentX = normalize(cross(upVector, N));\n vec3 tangentY = cross(N, tangentX);\n return tangentX * H.x + tangentY * H.y + N * H.z;\n}\n\nvoid main() {\n\n vec3 eyePos = viewInverse[3].xyz;\n vec3 V = normalize(v_WorldPosition - eyePos);\n\n vec3 N = V;\n vec3 R = V;\n\n vec3 prefilteredColor = vec3(0.0);\n float totalWeight = 0.0;\n\n\n for (int i = 0; i < SAMPLE_NUMBER; i++) {\n vec3 H = importanceSampleNormal(float(i) / fSampleNumber, roughness, N);\n vec3 L = reflect(-V, H);\n\n float NoL = clamp(dot(N, L), 0.0, 1.0);\n if (NoL > 0.0) {\n prefilteredColor += decodeHDR(textureCube(environmentMap, L)).rgb * NoL;\n totalWeight += NoL;\n }\n }\n\n gl_FragColor = encodeHDR(vec4(prefilteredColor / totalWeight, 1.0));\n}\n"},function(t,e){t.exports="uniform samplerCube environmentMap;\n\nvarying vec2 v_Texcoord;\n\n#define TEXTURE_SIZE 16\n\nmat3 front = mat3(\n 1.0, 0.0, 0.0,\n 0.0, 1.0, 0.0,\n 0.0, 0.0, 1.0\n);\n\nmat3 back = mat3(\n -1.0, 0.0, 0.0,\n 0.0, 1.0, 0.0,\n 0.0, 0.0, -1.0\n);\n\nmat3 left = mat3(\n 0.0, 0.0, -1.0,\n 0.0, 1.0, 0.0,\n 1.0, 0.0, 0.0\n);\n\nmat3 right = mat3(\n 0.0, 0.0, 1.0,\n 0.0, 1.0, 0.0,\n -1.0, 0.0, 0.0\n);\n\nmat3 up = mat3(\n 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0,\n 0.0, -1.0, 0.0\n);\n\nmat3 down = mat3(\n 1.0, 0.0, 0.0,\n 0.0, 0.0, -1.0,\n 0.0, 1.0, 0.0\n);\n\n\nfloat harmonics(vec3 normal){\n int index = int(gl_FragCoord.x);\n\n float x = normal.x;\n float y = normal.y;\n float z = normal.z;\n\n if(index==0){\n return 1.0;\n }\n else if(index==1){\n return x;\n }\n else if(index==2){\n return y;\n }\n else if(index==3){\n return z;\n }\n else if(index==4){\n return x*z;\n }\n else if(index==5){\n return y*z;\n }\n else if(index==6){\n return x*y;\n }\n else if(index==7){\n return 3.0*z*z - 1.0;\n }\n else{\n return x*x - y*y;\n }\n}\n\nvec3 sampleSide(mat3 rot)\n{\n\n vec3 result = vec3(0.0);\n float divider = 0.0;\n for (int i = 0; i < TEXTURE_SIZE * TEXTURE_SIZE; i++) {\n float x = mod(float(i), float(TEXTURE_SIZE));\n float y = float(i / TEXTURE_SIZE);\n\n vec2 sidecoord = ((vec2(x, y) + vec2(0.5, 0.5)) / vec2(TEXTURE_SIZE)) * 2.0 - 1.0;\n vec3 normal = normalize(vec3(sidecoord, -1.0));\n vec3 fetchNormal = rot * normal;\n vec3 texel = textureCube(environmentMap, fetchNormal).rgb;\n\n result += harmonics(fetchNormal) * texel * -normal.z;\n\n divider += -normal.z;\n }\n\n return result / divider;\n}\n\nvoid main()\n{\n vec3 result = (\n sampleSide(front) +\n sampleSide(back) +\n sampleSide(left) +\n sampleSide(right) +\n sampleSide(up) +\n sampleSide(down)\n ) / 6.0;\n gl_FragColor = vec4(result, 1.0);\n}"},function(t,e){t.exports="0.3.6"},function(t,e,n){function r(t,e,n){return t*(1-n)+e*n}var i=n(15),a=n(6),o=n(12),s=n(4),u=n(2),l=n(22);s["import"](n(157));var c=u.extend(function(){return{clearColor:[0,0,0,1],_mesh:new i({geometry:new o,culling:!1,material:new a({depthTest:!1,shader:new s({vertex:s.source("qtek.vr.disorter.output.vertex"),fragment:s.source("qtek.vr.disorter.output.fragment")})})}),_fakeCamera:new l}},{render:function(t,e){var n=this.clearColor,r=t.gl;r.clearColor(n[0],n[1],n[2],n[3]),r.clear(r.COLOR_BUFFER_BIT),r.disable(r.BLEND),this._mesh.material.set("texture",e),t.saveViewport(),t.setViewport(0,0,t.getWidth(),t.getHeight()),t.renderQueue([this._mesh],this._fakeCamera),t.restoreViewport()},updateFromVRDisplay:function(t){t.deviceInfo_?this._updateMesh(20,20,t.deviceInfo_):console.warn("Cant get vrDisplay.deviceInfo_, seems code changed")},_updateMesh:function(t,e,n){var i=this._mesh.geometry.attributes.position,a=this._mesh.geometry.attributes.texcoord0;i.init(2*t*e),a.init(2*t*e);for(var o=n.getLeftEyeVisibleTanAngles(),s=n.getLeftEyeNoLensTanAngles(),u=n.getLeftEyeVisibleScreenRect(s),l=0,c=[],h=[],f=0;f<2;f++){for(var d=0;d0&&r.push("#define "+i.toUpperCase()+"_COUNT "+a)}for(var o in n){var s=n[o];s.enabled&&r.push("#define "+o.toUpperCase()+"_ENABLED")}for(var o in t){var u=t[o];null===u?r.push("#define "+o):r.push("#define "+o+" "+u.toString())}return r.join("\n")},_unrollLoop:function(t,e){function n(t,n,i,a){var o="";isNaN(n)&&(n=n in e?e[n]:r[n]),isNaN(i)&&(i=i in e?e[i]:r[i]);for(var s=parseInt(n);s=0)n.attribSemantics[u]={symbol:a,type:c},h=!1;else if(E.indexOf(u)>=0){var f=!1,d=u;u.match(/TRANSPOSE$/)&&(f=!0,d=u.slice(0,-9)),n.matrixSemantics[u]={symbol:a,type:c,isTranspose:f,semanticNoTranspose:d},h=!1}else if(T.indexOf(u)>=0)n.uniformSemantics[u]={symbol:a,type:c},h=!1;else if("unconfigurable"===u)h=!1;else{if(l=n._parseDefaultValue(i,u),!l)throw new Error('Unkown semantic "'+u+'"');u=""}h&&(e[a]={type:c,value:o?y.array:l||y[i],semantic:u||null})}return["uniform",i,a,o].join(" ")+";\n"}}var e={},n=this,r="vertex";this._uniformList=[],this._vertexProcessedWithoutDefine=this._vertexProcessedWithoutDefine.replace(_,t),r="fragment",this._fragmentProcessedWithoutDefine=this._fragmentProcessedWithoutDefine.replace(_,t),n.matrixSemanticKeys=Object.keys(this.matrixSemantics),this.uniformTemplates=e},_parseDefaultValue:function(t,e){var n=/\[\s*(.*)\s*\]/;{if("vec2"!==t&&"vec3"!==t&&"vec4"!==t)return"bool"===t?function(){return"true"===e.toLowerCase()}:"float"===t?function(){return parseFloat(e)}:"int"===t?function(){return parseInt(e)}:void 0;var r=n.exec(e)[1];if(r){var i=r.split(/\s*,\s*/);return function(){return new l.Float32Array(i)}}}},createUniforms:function(){var t={};for(var e in this.uniformTemplates){var n=this.uniformTemplates[e];t[e]={type:n.type,value:n.value()}}return t},attached:function(){this._attacheMaterialNumber++},detached:function(){this._attacheMaterialNumber--},isAttachedToAny:function(){return 0!==this._attacheMaterialNumber},_parseAttributes:function(){function t(t,r,i,a,o){if(r&&i){var s=1;switch(r){case"vec4":s=4;break;case"vec3":s=3;break;case"vec2":s=2;break;case"float":s=1}if(e[i]={type:"float",size:s,semantic:o||null},o){if(x.indexOf(o)<0)throw new Error('Unkown semantic "'+o+'"');n.attribSemantics[o]={symbol:i,type:r}}}return["attribute",r,i].join(" ")+";\n"}var e={},n=this;this._vertexProcessedWithoutDefine=this._vertexProcessedWithoutDefine.replace(p,t),this.attributeTemplates=e},_parseDefines:function(){function t(t,r,i){var a="vertex"===n?e.vertexDefines:e.fragmentDefines;return a[r]||("false"==i?a[r]=!1:"true"==i?a[r]=!0:a[r]=i?parseFloat(i):null),""}var e=this,n="vertex";this._vertexProcessedWithoutDefine=this._vertexProcessedWithoutDefine.replace(m,t),n="fragment",this._fragmentProcessedWithoutDefine=this._fragmentProcessedWithoutDefine.replace(m,t)},_buildProgram:function(t,e,n){var r=this._cache;r.get("program")&&t.deleteProgram(r.get("program"));var a=t.createProgram(),o=t.createShader(t.VERTEX_SHADER);t.shaderSource(o,e),t.compileShader(o);var s=t.createShader(t.FRAGMENT_SHADER);t.shaderSource(s,n),t.compileShader(s);var u=i(t,o,e);if(u)return u;if(u=i(t,s,n))return u;if(t.attachShader(a,o),t.attachShader(a,s),this.attribSemantics.POSITION)t.bindAttribLocation(a,0,this.attribSemantics.POSITION.symbol);else{var l=Object.keys(this.attributeTemplates);t.bindAttribLocation(a,0,l[0])}if(t.linkProgram(a),!t.getProgramParameter(a,t.LINK_STATUS))return"Could not link program\nVALIDATE_STATUS: "+t.getProgramParameter(a,t.VALIDATE_STATUS)+", gl error ["+t.getError()+"]";for(var c=0;c=0},set:function(t,e){if("object"==typeof t)for(var n in t){var r=t[n];this.set(n,r)}else{var i=this.uniforms[t];i&&(i.value=e)}},get:function(t){var e=this.uniforms[t];if(e)return e.value},attachShader:function(t,e){this.shader&&this.shader.detached();var n=this.uniforms;this.uniforms=t.createUniforms(),this.shader=t;var r=this.uniforms;if(this._enabledUniforms=Object.keys(r),this._enabledUniforms.sort(),e)for(var i in n)r[i]&&(r[i].value=n[i].value);t.attached()},detachShader:function(){this.shader.detached(),this.shader=null,this.uniforms={}},clone:function(){var t=new this.constructor({name:this.name,shader:this.shader});for(var e in this.uniforms)t.uniforms[e].value=this.uniforms[e].value;return t.depthTest=this.depthTest,t.depthMask=this.depthMask,t.transparent=this.transparent,t.blend=this.blend,t},dispose:function(t,e){if(e)for(var n in this.uniforms){var r=this.uniforms[n].value;if(r)if(r instanceof i)r.dispose(t);else if(r instanceof Array)for(var a=0;a>e;return t+1},dispose:function(t){var e=this._cache;e.use(t.__GLID__);var n=e.get("webgl_texture");n&&t.deleteTexture(n),e.deleteContext(t.__GLID__)},isRenderable:function(){},isPowerOfTwo:function(){}});Object.defineProperty(o.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t}}),Object.defineProperty(o.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t}}),o.BYTE=i.BYTE,o.UNSIGNED_BYTE=i.UNSIGNED_BYTE,o.SHORT=i.SHORT,o.UNSIGNED_SHORT=i.UNSIGNED_SHORT,o.INT=i.INT,o.UNSIGNED_INT=i.UNSIGNED_INT,o.FLOAT=i.FLOAT,o.HALF_FLOAT=36193,o.UNSIGNED_INT_24_8_WEBGL=34042,o.DEPTH_COMPONENT=i.DEPTH_COMPONENT,o.DEPTH_STENCIL=i.DEPTH_STENCIL,o.ALPHA=i.ALPHA,o.RGB=i.RGB,o.RGBA=i.RGBA,o.LUMINANCE=i.LUMINANCE,o.LUMINANCE_ALPHA=i.LUMINANCE_ALPHA,o.COMPRESSED_RGB_S3TC_DXT1_EXT=33776,o.COMPRESSED_RGBA_S3TC_DXT1_EXT=33777,o.COMPRESSED_RGBA_S3TC_DXT3_EXT=33778,o.COMPRESSED_RGBA_S3TC_DXT5_EXT=33779,o.NEAREST=i.NEAREST,o.LINEAR=i.LINEAR,o.NEAREST_MIPMAP_NEAREST=i.NEAREST_MIPMAP_NEAREST,o.LINEAR_MIPMAP_NEAREST=i.LINEAR_MIPMAP_NEAREST,o.NEAREST_MIPMAP_LINEAR=i.NEAREST_MIPMAP_LINEAR,o.LINEAR_MIPMAP_LINEAR=i.LINEAR_MIPMAP_LINEAR,o.REPEAT=i.REPEAT,o.CLAMP_TO_EDGE=i.CLAMP_TO_EDGE,o.MIRRORED_REPEAT=i.MIRRORED_REPEAT,t.exports=o},function(t,e,n){var r=n(7),i=n(16),a=n(5),o=n(50),s=o.isPowerOfTwo,u=r.extend(function(){return{image:null,pixels:null,mipmaps:[]}},{update:function(t){t.bindTexture(t.TEXTURE_2D,this._cache.get("webgl_texture")),this.beforeUpdate(t);var e=this.format,n=this.type;t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,this.wrapS),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,this.wrapT),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,this.magFilter),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,this.minFilter);var r=i.getExtension(t,"EXT_texture_filter_anisotropic");if(r&&this.anisotropic>1&&t.texParameterf(t.TEXTURE_2D,r.TEXTURE_MAX_ANISOTROPY_EXT,this.anisotropic),36193===n){var o=i.getExtension(t,"OES_texture_half_float");o||(n=a.FLOAT)}if(this.mipmaps.length)for(var s=this.width,u=this.height,l=0;l=r.COMPRESSED_RGB_S3TC_DXT1_EXT?t.compressedTexImage2D(t.TEXTURE_2D,n,o,i,a,0,e.pixels):t.texImage2D(t.TEXTURE_2D,n,o,i,a,0,o,s,e.pixels)},generateMipmap:function(t){this.useMipmap&&!this.NPOT&&(t.bindTexture(t.TEXTURE_2D,this._cache.get("webgl_texture")),t.generateMipmap(t.TEXTURE_2D))},isPowerOfTwo:function(){var t,e;return this.image?(t=this.image.width,e=this.image.height):(t=this.width,e=this.height),s(t)&&s(e)},isRenderable:function(){return this.image?"CANVAS"===this.image.nodeName||"VIDEO"===this.image.nodeName||this.image.complete:!(!this.width||!this.height)},bind:function(t){t.bindTexture(t.TEXTURE_2D,this.getWebGLTexture(t))},unbind:function(t){t.bindTexture(t.TEXTURE_2D,null)},load:function(t){var e=new Image,n=this;return e.onload=function(){n.dirty(),n.trigger("success",n),e.onload=null; +},e.onerror=function(){n.trigger("error",n),e.onerror=null},e.src=t,this.image=e,this}});Object.defineProperty(u.prototype,"width",{get:function(){return this.image?this.image.width:this._width},set:function(t){this.image?console.warn("Texture from image can't set width"):(this._width!==t&&this.dirty(),this._width=t)}}),Object.defineProperty(u.prototype,"height",{get:function(){return this.image?this.image.height:this._height},set:function(t){this.image?console.warn("Texture from image can't set height"):(this._height!==t&&this.dirty(),this._height=t)}}),t.exports=u},function(t,e,n){"use strict";var r=n(3),i=n(1),a=i.vec3,o=a.copy,s=a.set,u=function(t,e){this.min=t||new r(1/0,1/0,1/0),this.max=e||new r((-(1/0)),(-(1/0)),(-(1/0)))};u.prototype={constructor:u,updateFromVertices:function(t){if(t.length>0){var e=this.min,n=this.max,r=e._array,i=n._array;o(r,t[0]),o(i,t[0]);for(var a=1;ai[0]&&(i[0]=s[0]),s[1]>i[1]&&(i[1]=s[1]),s[2]>i[2]&&(i[2]=s[2])}e._dirty=!0,n._dirty=!0}},union:function(t){var e=this.min,n=this.max;return a.min(e._array,e._array,t.min._array),a.max(n._array,n._array,t.max._array),e._dirty=!0,n._dirty=!0,this},intersection:function(t){var e=this.min,n=this.max;return a.max(e._array,e._array,t.min._array),a.min(n._array,n._array,t.max._array),e._dirty=!0,n._dirty=!0,this},intersectBoundingBox:function(t){var e=this.min._array,n=this.max._array,r=t.min._array,i=t.max._array;return!(e[0]>i[0]||e[1]>i[1]||e[2]>i[2]||n[0]=i[0]&&n[1]>=i[1]&&n[2]>=i[2]},containPoint:function(t){var e=this.min._array,n=this.max._array,r=t._array;return e[0]<=r[0]&&e[1]<=r[1]&&e[2]<=r[2]&&n[0]>=r[0]&&n[1]>=r[1]&&n[2]>=r[2]},isFinite:function(){var t=this.min._array,e=this.max._array;return isFinite(t[0])&&isFinite(t[1])&&isFinite(t[2])&&isFinite(e[0])&&isFinite(e[1])&&isFinite(e[2])},applyTransform:function(){var t=a.create(),e=a.create(),n=a.create(),r=a.create(),i=a.create(),o=a.create();return function(a){var s=this.min._array,u=this.max._array,l=a._array;return t[0]=l[0]*s[0],t[1]=l[1]*s[0],t[2]=l[2]*s[0],e[0]=l[0]*u[0],e[1]=l[1]*u[0],e[2]=l[2]*u[0],n[0]=l[4]*s[1],n[1]=l[5]*s[1],n[2]=l[6]*s[1],r[0]=l[4]*u[1],r[1]=l[5]*u[1],r[2]=l[6]*u[1],i[0]=l[8]*s[2],i[1]=l[9]*s[2],i[2]=l[10]*s[2],o[0]=l[8]*u[2],o[1]=l[9]*u[2],o[2]=l[10]*u[2],s[0]=Math.min(t[0],e[0])+Math.min(n[0],r[0])+Math.min(i[0],o[0])+l[12],s[1]=Math.min(t[1],e[1])+Math.min(n[1],r[1])+Math.min(i[1],o[1])+l[13],s[2]=Math.min(t[2],e[2])+Math.min(n[2],r[2])+Math.min(i[2],o[2])+l[14],u[0]=Math.max(t[0],e[0])+Math.max(n[0],r[0])+Math.max(i[0],o[0])+l[12],u[1]=Math.max(t[1],e[1])+Math.max(n[1],r[1])+Math.max(i[1],o[1])+l[13],u[2]=Math.max(t[2],e[2])+Math.max(n[2],r[2])+Math.max(i[2],o[2])+l[14],this.min._dirty=!0,this.max._dirty=!0,this}}(),applyProjection:function(t){var e=this.min._array,n=this.max._array,r=t._array,i=e[0],a=e[1],o=e[2],s=n[0],u=n[1],l=e[2],c=n[0],h=n[1],f=n[2];if(1===r[15])e[0]=r[0]*i+r[12],e[1]=r[5]*a+r[13],n[2]=r[10]*o+r[14],n[0]=r[0]*c+r[12],n[1]=r[5]*h+r[13],e[2]=r[10]*f+r[14];else{var d=-1/o;e[0]=r[0]*i*d,e[1]=r[5]*a*d,n[2]=(r[10]*o+r[14])*d,d=-1/l,n[0]=r[0]*s*d,n[1]=r[5]*u*d,d=-1/f,e[2]=(r[10]*f+r[14])*d}return this.min._dirty=!0,this.max._dirty=!0,this},updateVertices:function(){var t=this.vertices;if(!t){for(var t=[],e=0;e<8;e++)t[e]=a.fromValues(0,0,0);this.vertices=t}var n=this.min._array,r=this.max._array;return s(t[0],n[0],n[1],n[2]),s(t[1],n[0],r[1],n[2]),s(t[2],r[0],n[1],n[2]),s(t[3],r[0],r[1],n[2]),s(t[4],n[0],n[1],r[2]),s(t[5],n[0],r[1],r[2]),s(t[6],r[0],n[1],r[2]),s(t[7],r[0],r[1],r[2]),this},copy:function(t){var e=this.min,n=this.max;return o(e._array,t.min._array),o(n._array,t.max._array),e._dirty=!0,n._dirty=!0,this},clone:function(){var t=new u;return t.copy(this),t}},t.exports=u},function(t,e,n){"use strict";var r=n(1),i=n(3),a=r.mat4,o=r.vec3,s=r.mat3,u=r.quat,l=function(){this._axisX=new i,this._axisY=new i,this._axisZ=new i,this._array=a.create(),this._dirty=!0};l.prototype={constructor:l,setArray:function(t){for(var e=0;eo[0]&&(o[0]=u),l>o[1]&&(o[1]=l),h>o[2]&&(o[2]=h)}n._dirty=!0,r._dirty=!0}},dirty:function(){for(var t=this.getEnabledAttributes(),e=0;e=0){e||(e=f());var n=this.indices;return e[0]=n[3*t],e[1]=n[3*t+1],e[2]=n[3*t+2],e}},setTriangleIndices:function(t,e){var n=this.indices;n[3*t]=e[0],n[3*t+1]=e[1],n[3*t+2]=e[2]},isUseIndices:function(){return!!this.indices},initIndicesFromArray:function(t){var e,n=this.vertexCount>65535?s.Uint32Array:s.Uint16Array;if(t[0]&&t[0].length){var r=0,i=3;e=new n(t.length*i);for(var a=0;a=0&&(e.splice(n,1),delete this.attributes[t],!0)},getEnabledAttributes:function(){var t=this._enabledAttributes,e=this._attributeList;if(t)return t;for(var n=[],r=this.vertexCount,i=0;i65535&&(this.indices=new s.Uint32Array(this.indices));for(var t=this.attributes,e=this.indices,n=this.getEnabledAttributes(),r={},i=0;i1&&t.texParameterf(t.TEXTURE_CUBE_MAP,r.TEXTURE_MAX_ANISOTROPY_EXT,this.anisotropic),36193===n){var i=a.getExtension(t,"OES_texture_half_float");i||(n=o.FLOAT)}if(this.mipmaps.length)for(var s=this.width,u=this.height,l=0;l1&&(e=1);var n;return n=this.easing?this.easing(e):e,this.fire("frame",n),1===e?this._loop&&this._loopRemained>0?(this._restartInLoop(t),this._loopRemained--,"restart"):(this._needsRemove=!0,"finish"):null}},setTime:function(t){return this.step(t+this._startTime)},restart:function(t){var e=0;t=t,t&&(this._elapse(t),e=this._elapsedTime%this.life),t=t||(new Date).getTime(),this._startTime=t-e+this.delay,this._elapsedTime=0,this._currentTime=t-e,this._needsRemove=!1},_restartInLoop:function(t){this._startTime=t+this.gap,this._currentTime=t,this._elapsedTime=0},_elapse:function(t){this._elapsedTime+=(t-this._currentTime)*this.playbackRate,this._currentTime=t},fire:function(t,e){var n="on"+t;this[n]&&this[n](this.target,e)},clone:function(){var t=new this.constructor;return t.name=this.name,t._loop=this._loop,t._loopRemained=this._loopRemained,t.life=this.life,t.gap=this.gap,t.delay=this.delay,t}},a.prototype.constructor=a,t.exports=a},function(t,e,n){"use strict";var r=n(2),i=n(30),a=n(42),o=n(4),s=n(6),u=n(15),l=n(16),c=n(5);o["import"](n(131));var h=new a,f=new u({geometry:h,frustumCulling:!1}),d=new i,_=r.extend(function(){return{fragment:"",outputs:null,material:null,blendWithPrevious:!1,clearColor:!1,clearDepth:!0}},function(){var t=new o({vertex:o.source("qtek.compositor.vertex"),fragment:this.fragment}),e=new s({shader:t});t.enableTexturesAll(),this.material=e},{setUniform:function(t,e){var n=this.material.uniforms[t];n&&(n.value=e)},getUniform:function(t){var e=this.material.uniforms[t];if(e)return e.value},attachOutput:function(t,e){this.outputs||(this.outputs={}),e=e||c.COLOR_ATTACHMENT0,this.outputs[e]=t},detachOutput:function(t){for(var e in this.outputs)this.outputs[e]===t&&(this.outputs[e]=null)},bind:function(t,e){if(this.outputs)for(var n in this.outputs){var r=this.outputs[n];r&&e.attach(r,n)}e&&e.bind(t)},unbind:function(t,e){e.unbind(t)},render:function(t,e){var n=t.gl;if(e){this.bind(t,e);var r=l.getExtension(n,"EXT_draw_buffers");if(r&&this.outputs){var i=[];for(var a in this.outputs)a=+a,a>=n.COLOR_ATTACHMENT0&&a<=n.COLOR_ATTACHMENT0+8&&i.push(a);r.drawBuffersEXT(i)}}this.trigger("beforerender",this,t);var o=this.clearDepth?n.DEPTH_BUFFER_BIT:0;if(n.depthMask(!0),this.clearColor){o|=n.COLOR_BUFFER_BIT,n.colorMask(!0,!0,!0,!0);var s=this.clearColor;s instanceof Array&&n.clearColor(s[0],s[1],s[2],s[3])}n.clear(o),this.blendWithPrevious?(n.enable(n.BLEND),this.material.transparent=!0):(n.disable(n.BLEND),this.material.transparent=!1),this.renderQuad(t),this.trigger("afterrender",this,t),e&&this.unbind(t,e)},renderQuad:function(t){f.material=this.material,t.renderQueue([f],d)},dispose:function(t){this.material.dispose(t)}});t.exports=_},function(t,e,n){"use strict";var r=n(33),i=r.extend({fov:50,aspect:1,near:.1,far:2e3},{updateProjectionMatrix:function(){var t=this.fov/180*Math.PI;this.projectionMatrix.perspective(t,this.aspect,this.near,this.far)},decomposeProjectionMatrix:function(){var t=this.projectionMatrix._array,e=2*Math.atan(1/t[5]);this.fov=e/Math.PI*180,this.aspect=t[5]/t[0],this.near=t[14]/(t[10]-1),this.far=t[14]/(t[10]+1)},clone:function(){var t=r.prototype.clone.call(this);return t.fov=this.fov,t.aspect=this.aspect,t.near=this.near,t.far=this.far,t}});t.exports=i},function(t,e,n){"use strict";var r=n(2),i=r.extend(function(){return{name:"",inputLinks:{},outputLinks:{},_prevOutputTextures:{},_outputTextures:{},_outputReferences:{},_rendering:!1,_rendered:!1,_compositor:null}},{updateParameter:function(t,e){var n=this.outputs[t],r=n.parameters,i=n._parametersCopy;if(i||(i=n._parametersCopy={}),r)for(var a in r)"width"!==a&&"height"!==a&&(i[a]=r[a]);var o,s;return o=r.width instanceof Function?r.width.call(this,e):r.width,s=r.height instanceof Function?r.height.call(this,e):r.height,i.width===o&&i.height===s||this._outputTextures[t]&&this._outputTextures[t].dispose(e.gl),i.width=o,i.height=s,i},setParameter:function(t,e){},getParameter:function(t){},setParameters:function(t){for(var e in t)this.setParameter(e,t[e])},render:function(){},getOutput:function(t,e){if(null==e)return e=t,this._outputTextures[e];var n=this.outputs[e];if(n)return this._rendered?n.outputLastFrame?this._prevOutputTextures[e]:this._outputTextures[e]:this._rendering?(this._prevOutputTextures[e]||(this._prevOutputTextures[e]=this._compositor.allocateTexture(n.parameters||{})),this._prevOutputTextures[e]):(this.render(t),this._outputTextures[e])},removeReference:function(t){if(this._outputReferences[t]--,0===this._outputReferences[t]){var e=this.outputs[t];e.keepLastFrame?(this._prevOutputTextures[t]&&this._compositor.releaseTexture(this._prevOutputTextures[t]),this._prevOutputTextures[t]=this._outputTextures[t]):this._compositor.releaseTexture(this._outputTextures[t])}},link:function(t,e,n){this.inputLinks[t]={node:e,pin:n},e.outputLinks[n]||(e.outputLinks[n]=[]),e.outputLinks[n].push({node:this,pin:t});var r=this.pass.material.shader;r.enableTexture(t)},clear:function(){this.inputLinks={},this.outputLinks={}},updateReference:function(t){if(!this._rendering){this._rendering=!0;for(var e in this.inputLinks){var n=this.inputLinks[e];n.node.updateReference(n.pin)}this._rendering=!1}t&&this._outputReferences[t]++},beforeFrame:function(){this._rendered=!1;for(var t in this.outputLinks)this._outputReferences[t]=0},afterFrame:function(){for(var t in this.outputLinks)if(this._outputReferences[t]>0){var e=this.outputs[t];e.keepLastFrame?(this._prevOutputTextures[t]&&this._compositor.releaseTexture(this._prevOutputTextures[t]),this._prevOutputTextures[t]=this._outputTextures[t]):this._compositor.releaseTexture(this._outputTextures[t])}}});t.exports=i},function(t,e,n){"use strict";function r(t,e){if(e.castShadow&&!t.castShadow)return!0}var i=n(19),a=n(11),o=n(9),s=i.extend(function(){return{material:null,autoUpdate:!0,opaqueQueue:[],transparentQueue:[],lights:[],viewBoundingBoxLastFrame:new o,_lightUniforms:{},_lightNumber:{},_opaqueObjectCount:0,_transparentObjectCount:0,_nodeRepository:{}}},function(){this._scene=this},{addToScene:function(t){t.name&&(this._nodeRepository[t.name]=t)},removeFromScene:function(t){t.name&&delete this._nodeRepository[t.name]},getNode:function(t){return this._nodeRepository[t]},cloneNode:function(t){var e=t.clone(),n={},r=function(i,a){i.skeleton&&(a.skeleton=i.skeleton.clone(t,e),a.joints=i.joints.slice()),i.material&&(n[i.material.__GUID__]={oldMat:i.material});for(var o=0;o0&&this._updateRenderQueue(r)}},_updateLightUniforms:function(){var t=this.lights;t.sort(r);var e=this._lightUniforms;for(var n in e)for(var i in e[n])e[n][i].value.length=0;for(var a=0;a0},beforeRender:function(t){},afterRender:function(t,e){},getBoundingBox:function(t,e){return e=a.prototype.getBoundingBox.call(this,t,e),this.geometry&&this.geometry.boundingBox&&e.union(this.geometry.boundingBox),e},render:function(t,e){var e=e||this.material.shader,n=this.geometry,a=this.mode,h=n.vertexCount,f=n.isUseIndices(),d=s.getExtension(t,"OES_element_index_uint"),_=d&&h>65535,p=_?t.UNSIGNED_INT:t.UNSIGNED_SHORT,m=s.getExtension(t,"OES_vertex_array_object"),v=!n.dynamic,g=this._renderInfo;g.vertexCount=h,g.triangleCount=0,g.drawCallCount=0;var y=!1;if(i=t.__GLID__+"-"+n.__GUID__+"-"+e.__GUID__,i!==u?y=!0:(h>65535&&!d&&f||m&&v||n._cache.isDirty())&&(y=!0),u=i,y){var x=this._drawCache[i];if(!x){var T=n.getBufferChunks(t);if(!T)return;x=[];for(var E=0;Eh)){var f=Math.sqrt(h-c),d=u-f,_=u+f;return i||(i=new r),d<0?_<0?null:(a.scaleAndAdd(i._array,o,s,_),i):(a.scaleAndAdd(i._array,o,s,d),i)}}}(),intersectBoundingBox:function(t,e){var n,i,o,s,u,l,c=this.direction._array,h=this.origin._array,f=t.min._array,d=t.max._array,_=1/c[0],p=1/c[1],m=1/c[2];if(_>=0?(n=(f[0]-h[0])*_,i=(d[0]-h[0])*_):(i=(f[0]-h[0])*_,n=(d[0]-h[0])*_),p>=0?(o=(f[1]-h[1])*p,s=(d[1]-h[1])*p):(s=(f[1]-h[1])*p,o=(d[1]-h[1])*p),n>s||o>i)return null;if((o>n||n!==n)&&(n=o),(s=0?(u=(f[2]-h[2])*m,l=(d[2]-h[2])*m):(l=(f[2]-h[2])*m,u=(d[2]-h[2])*m),n>l||u>i)return null;if((u>n||n!==n)&&(n=u),(l=0?n:i;return e||(e=new r),a.scaleAndAdd(e._array,h,c,v),e},intersectTriangle:function(){var t=a.create(),e=a.create(),n=a.create(),i=a.create();return function(s,u,l,c,h,f){var d=this.direction._array,_=this.origin._array;s=s._array,u=u._array,l=l._array,a.sub(t,u,s),a.sub(e,l,s),a.cross(i,e,d);var p=a.dot(t,i);if(c){if(p>-o)return null}else if(p>-o&&p1)return null;a.cross(i,t,n);var v=a.dot(d,i)/p;if(v<0||v>1||m+v>1)return null;a.cross(i,t,e);var g=-a.dot(n,i)/p;return g<0?null:(h||(h=new r),f&&r.set(f,1-m-v,m,v),a.scaleAndAdd(h._array,_,d,g),h)}}(),applyTransform:function(t){r.add(this.direction,this.direction,this.origin),r.transformMat4(this.origin,this.origin,t),r.transformMat4(this.direction,this.direction,t),r.sub(this.direction,this.direction,this.origin),r.normalize(this.direction,this.direction)},copy:function(t){r.copy(this.origin,t.origin),r.copy(this.direction,t.direction)},clone:function(){var t=new s;return t.copy(this),t}},t.exports=s},function(t,e,n){var r=n(2),i=n(3),a=n(22),o=n(14),s=["px","nx","py","ny","pz","nz"],u=r.extend(function(){var t={position:new i,far:1e3,near:.1,texture:null,shadowMapPass:null},e=t._cameras={px:new a({fov:90}),nx:new a({fov:90}),py:new a({fov:90}),ny:new a({fov:90}),pz:new a({fov:90}),nz:new a({fov:90})};return e.px.lookAt(i.POSITIVE_X,i.NEGATIVE_Y),e.nx.lookAt(i.NEGATIVE_X,i.NEGATIVE_Y),e.py.lookAt(i.POSITIVE_Y,i.POSITIVE_Z),e.ny.lookAt(i.NEGATIVE_Y,i.NEGATIVE_Z),e.pz.lookAt(i.POSITIVE_Z,i.NEGATIVE_Y),e.nz.lookAt(i.NEGATIVE_Z,i.NEGATIVE_Y),t._frameBuffer=new o,t},{getCamera:function(t){return this._cameras[t]},render:function(t,e,n){var r=t.gl;n||e.update();for(var a=this.texture.width,o=2*Math.atan(a/(a-.5))/Math.PI*180,u=0;u<6;u++){var l=s[u],c=this._cameras[l];if(i.copy(c.position,this.position),c.far=this.far,c.near=this.near,c.fov=o,this.shadowMapPass){c.update();var h=e.getBoundingBox(function(t){return!t.invisible});h.applyTransform(c.viewMatrix),e.viewBoundingBoxLastFrame.copy(h),this.shadowMapPass.render(t,e,c,!0)}this._frameBuffer.attach(this.texture,r.COLOR_ATTACHMENT0,r.TEXTURE_CUBE_MAP_POSITIVE_X+u),this._frameBuffer.bind(t),t.render(e,c,!0),this._frameBuffer.unbind(t)}},dispose:function(t){this._frameBuffer.dispose(t)}});t.exports=u},function(t,e,n){"use strict";var r=n(19),i=n(10),a=n(47),o=n(31),s=n(1),u=s.vec3,l=s.vec4,c=r.extend(function(){return{projectionMatrix:new i,invProjectionMatrix:new i,viewMatrix:new i,frustum:new a}},function(){this.update(!0)},{update:function(t){r.prototype.update.call(this,t),i.invert(this.viewMatrix,this.worldTransform),this.updateProjectionMatrix(),i.invert(this.invProjectionMatrix,this.projectionMatrix),this.frustum.setFromProjection(this.projectionMatrix)},setViewMatrix:function(t){i.copy(this.viewMatrix,t),i.invert(this.worldTransform,t),this.decomposeWorldTransform()},decomposeProjectionMatrix:function(){},setProjectionMatrix:function(t){i.copy(this.projectionMatrix,t),i.invert(this.invProjectionMatrix,t),this.decomposeProjectionMatrix()},updateProjectionMatrix:function(){},castRay:function(){var t=l.create();return function(e,n){var r=void 0!==n?n:new o,i=e._array[0],a=e._array[1];return l.set(t,i,a,-1,1),l.transformMat4(t,t,this.invProjectionMatrix._array),l.transformMat4(t,t,this.worldTransform._array),u.scale(r.origin._array,t,1/t[3]),l.set(t,i,a,1,1),l.transformMat4(t,t,this.invProjectionMatrix._array),l.transformMat4(t,t,this.worldTransform._array),u.scale(t,t,1/t[3]),u.sub(r.direction._array,t,r.origin._array),u.normalize(r.direction._array,r.direction._array),r.direction._dirty=!0,r.origin._dirty=!0,r}}()});t.exports=c},function(t,e,n){"use strict";var r=n(2),i=r.extend({name:"",index:-1,parentIndex:-1,node:null,rootNode:null});t.exports=i},function(t,e,n){"use strict";var r=n(2),i=n(16),a=n(5),o=(n(13),n(9)),s=n(10),u=(n(28),n(6)),l=n(27),c=n(4);c["import"](n(77)),c["import"](n(53));var h=n(1),f=h.mat4,d=h.vec3,_=f.create,p=0,m={},v=r.extend(function(){return{canvas:null,_width:100,_height:100,devicePixelRatio:window.devicePixelRatio||1,clearColor:[0,0,0,0],clearBit:17664,alpha:!0,depth:!0,stencil:!1,antialias:!0,premultipliedAlpha:!0,preserveDrawingBuffer:!1,throwError:!0,gl:null,viewport:{},__currentFrameBuffer:null,_viewportStack:[],_clearStack:[],_sceneRendering:null}},function(){this.canvas||(this.canvas=document.createElement("canvas"));var t=this.canvas;try{var e={alpha:this.alpha,depth:this.depth,stencil:this.stencil,antialias:this.antialias,premultipliedAlpha:this.premultipliedAlpha,preserveDrawingBuffer:this.preserveDrawingBuffer};if(this.gl=t.getContext("webgl",e)||t.getContext("experimental-webgl",e),!this.gl)throw new Error;null==this.gl.__GLID__&&(this.gl.__GLID__=p++,i.initialize(this.gl)),this.resize()}catch(n){throw"Error creating WebGL Context "+n}},{resize:function(t,e){var n=this.canvas,r=this.devicePixelRatio;null!=t?(n.style.width=t+"px",n.style.height=e+"px",n.width=t*r,n.height=e*r,this._width=t,this._height=e):(this._width=n.width/r,this._height=n.height/r),this.setViewport(0,0,this._width,this._height)},getWidth:function(){return this._width},getHeight:function(){return this._height},getViewportAspect:function(){var t=this.viewport;return t.width/t.height},setDevicePixelRatio:function(t){this.devicePixelRatio=t,this.resize(this._width,this._height)},getDevicePixelRatio:function(){return this.devicePixelRatio},getExtension:function(t){return i.getExtension(this.gl,t)},setViewport:function(t,e,n,r,i){if("object"==typeof t){var a=t;t=a.x,e=a.y,n=a.width,r=a.height,i=a.devicePixelRatio}i=i||this.devicePixelRatio,this.gl.viewport(t*i,e*i,n*i,r*i),this.viewport={x:t,y:e,width:n,height:r,devicePixelRatio:i}},saveViewport:function(){this._viewportStack.push(this.viewport)},restoreViewport:function(){this._viewportStack.length>0&&this.setViewport(this._viewportStack.pop())},saveClear:function(){this._clearStack.push({clearBit:this.clearBit,clearColor:this.clearColor})},restoreClear:function(){if(this._clearStack.length>0){var t=this._clearStack.pop();this.clearColor=t.clearColor,this.clearBit=t.clearBit}},bindSceneRendering:function(t){this._sceneRendering=t},beforeRenderObject:function(){},afterRenderObject:function(){},render:function(t,e,n,r){var i=this.gl;this._sceneRendering=t;var a=this.clearColor;if(this.clearBit){i.colorMask(!0,!0,!0,!0),i.depthMask(!0);var o=this.viewport,s=!1,u=o.devicePixelRatio;(o.width!==this._width||o.height!==this._height||u&&u!==this.devicePixelRatio||o.x||o.y)&&(s=!0,i.enable(i.SCISSOR_TEST),i.scissor(o.x*u,o.y*u,o.width*u,o.height*u)),i.clearColor(a[0],a[1],a[2],a[3]),i.clear(this.clearBit),s&&i.disable(i.SCISSOR_TEST)}n||t.update(!1),e.getScene()||e.update(!0);var l=t.opaqueQueue,c=t.transparentQueue,h=t.material;if(t.trigger("beforerender",this,t,e),c.length>0)for(var p=_(),m=d.create(),v=0;v0&&t.min._array[2]<0&&(t.max._array[2]=-1e-20),t.applyProjection(e);var u=t.min._array,l=t.max._array;if(l[0]<-1||u[0]>1||l[1]<-1||u[1]>1||l[2]<-1||u[2]>1)return!0}return!1}}(),disposeScene:function(t){this.disposeNode(t,!0,!0),t.dispose()},disposeNode:function(t,e,n){var r={},i=this.gl;t.getParent()&&t.getParent().remove(t),t.traverse(function(t){t.geometry&&e&&t.geometry.dispose(i),t.material&&(r[t.material.__GUID__]=t.material),t.dispose&&t.dispose(i)});for(var a in r){var o=r[a];o.dispose(i,n)}},disposeShader:function(t){t.dispose(this.gl)},disposeGeometry:function(t){t.dispose(this.gl)},disposeTexture:function(t){t.dispose(this.gl)},disposeFrameBuffer:function(t){t.dispose(this.gl)},dispose:function(){i.dispose(this.gl)},screenToNDC:function(t,e,n){n||(n=new l),e=this._height-e;var r=this.viewport,i=n._array;return i[0]=(t-r.x)/r.width,i[0]=2*i[0]-1,i[1]=(e-r.y)/r.height,i[1]=2*i[1]-1,n}});v.opaqueSortFunc=v.prototype.opaqueSortFunc=function(t,e){return t.renderOrder===e.renderOrder?t.material.shader===e.material.shader?t.material===e.material?t.geometry.__GUID__-e.geometry.__GUID__:t.material.__GUID__-e.material.__GUID__:t.material.shader.__GUID__-e.material.shader.__GUID__:t.renderOrder-e.renderOrder},v.transparentSortFunc=v.prototype.transparentSortFunc=function(t,e){return t.renderOrder===e.renderOrder?t.__depth===e.__depth?t.material.shader===e.material.shader?t.material===e.material?t.geometry.__GUID__-e.geometry.__GUID__:t.material.__GUID__-e.material.__GUID__:t.material.shader.__GUID__-e.material.shader.__GUID__:t.__depth-e.__depth:t.renderOrder-e.renderOrder};var g={WORLD:_(),VIEW:_(),PROJECTION:_(),WORLDVIEW:_(),VIEWPROJECTION:_(),WORLDVIEWPROJECTION:_(),WORLDINVERSE:_(),VIEWINVERSE:_(),PROJECTIONINVERSE:_(),WORLDVIEWINVERSE:_(),VIEWPROJECTIONINVERSE:_(),WORLDVIEWPROJECTIONINVERSE:_(),WORLDTRANSPOSE:_(),VIEWTRANSPOSE:_(),PROJECTIONTRANSPOSE:_(),WORLDVIEWTRANSPOSE:_(),VIEWPROJECTIONTRANSPOSE:_(),WORLDVIEWPROJECTIONTRANSPOSE:_(),WORLDINVERSETRANSPOSE:_(),VIEWINVERSETRANSPOSE:_(),PROJECTIONINVERSETRANSPOSE:_(),WORLDVIEWINVERSETRANSPOSE:_(),VIEWPROJECTIONINVERSETRANSPOSE:_(),WORLDVIEWPROJECTIONINVERSETRANSPOSE:_()};v.COLOR_BUFFER_BIT=a.COLOR_BUFFER_BIT,v.DEPTH_BUFFER_BIT=a.DEPTH_BUFFER_BIT,v.STENCIL_BUFFER_BIT=a.STENCIL_BUFFER_BIT,t.exports=v},function(t,e,n){"use strict";function r(t,e,n){for(var r=e,i=0;i=t.time)return this.keyFrames.splice(e,0,t),e}this.life=t.time,this.keyFrames.push(t)},u.prototype.addKeyFrames=function(t){for(var e=0;ei[i.length-1].time)){if(t=a-1?a-1:this._cacheKey+1,l=u;l>=0;l--)if(i[l].time<=t&&i[l][e])n=i[l],this._cacheKey=l,this._cacheTime=t;else if(i[l][e]){r=i[l];break}}else for(var l=this._cacheKey;l65535?Uint32Array:Uint16Array,p=this.indices=new _(e*t*6),m=this.radius,v=this.phiStart,g=this.phiLength,y=this.thetaStart,x=this.thetaLength,m=this.radius,T=[],E=[],b=0,S=1/m;for(d=0;d<=t;d++)for(f=0;f<=e;f++)c=f/e,h=d/t,s=-m*Math.cos(v+c*g)*Math.sin(y+h*x),u=m*Math.cos(y+h*x),l=m*Math.sin(v+c*g)*Math.sin(y+h*x),T[0]=s,T[1]=u,T[2]=l,E[0]=c,E[1]=h,n.set(b,T),r.set(b,E),T[0]*=S,T[1]*=S,T[2]*=S,i.set(b,T),b++;var A,N,w,M,C=e+1,R=0;for(d=0;dthis.distance,i=1;i<8;i++)if(a.dot(e[i]._array,n)>this.distance!=r)return!0},intersectLine:function(){var t=a.create();return function(e,n,i){var o=this.distanceToPoint(e),s=this.distanceToPoint(n);if(o>0&&s>0||o<0&&s<0)return null;var u=this.normal._array,l=this.distance,c=e._array;a.sub(t,n._array,e._array),a.normalize(t,t);var h=a.dot(u,t);if(0===h)return null;i||(i=new r);var f=(a.dot(u,c)-l)/h;return a.scaleAndAdd(i._array,c,t,-f),i._dirty=!0,i}}(),applyTransform:function(){var t=o.create(),e=s.create(),n=s.create();return n[3]=1,function(r){r=r._array,a.scale(n,this.normal._array,this.distance),s.transformMat4(n,n,r),this.distance=a.dot(n,this.normal._array),o.invert(t,r),o.transpose(t,t),e[3]=0,a.copy(e,this.normal._array),s.transformMat4(e,e,t),a.copy(this.normal._array,e)}}(),copy:function(t){a.copy(this.normal._array,t.normal._array),this.normal._dirty=!0,this.distance=t.distance},clone:function(){var t=new u;return t.copy(this),t}},t.exports=u},function(t,e,n){"use strict";var r=n(1),i=r.quat,a=function(t,e,n,r){t=t||0,e=e||0,n=n||0,r=void 0===r?1:r,this._array=i.fromValues(t,e,n,r),this._dirty=!0};a.prototype={constructor:a,add:function(t){return i.add(this._array,this._array,t._array),this._dirty=!0,this},calculateW:function(){return i.calculateW(this._array,this._array),this._dirty=!0,this},set:function(t,e,n,r){return this._array[0]=t,this._array[1]=e,this._array[2]=n,this._array[3]=r,this._dirty=!0,this},setArray:function(t){return this._array[0]=t[0],this._array[1]=t[1],this._array[2]=t[2],this._array[3]=t[3],this._dirty=!0,this},clone:function(){return new a(this.x,this.y,this.z,this.w)},conjugate:function(){return i.conjugate(this._array,this._array),this._dirty=!0,this},copy:function(t){return i.copy(this._array,t._array),this._dirty=!0,this},dot:function(t){return i.dot(this._array,t._array)},fromMat3:function(t){return i.fromMat3(this._array,t._array),this._dirty=!0,this},fromMat4:function(){var t=r.mat3,e=t.create();return function(n){return t.fromMat4(e,n._array),t.transpose(e,e),i.fromMat3(this._array,e),this._dirty=!0,this}}(),identity:function(){return i.identity(this._array),this._dirty=!0,this},invert:function(){return i.invert(this._array,this._array),this._dirty=!0,this},len:function(){return i.len(this._array)},length:function(){return i.length(this._array)},lerp:function(t,e,n){return i.lerp(this._array,t._array,e._array,n),this._dirty=!0,this},mul:function(t){return i.mul(this._array,this._array,t._array),this._dirty=!0,this},mulLeft:function(t){return i.multiply(this._array,t._array,this._array),this._dirty=!0,this},multiply:function(t){return i.multiply(this._array,this._array,t._array),this._dirty=!0,this},multiplyLeft:function(t){return i.multiply(this._array,t._array,this._array),this._dirty=!0,this},normalize:function(){return i.normalize(this._array,this._array),this._dirty=!0,this},rotateX:function(t){return i.rotateX(this._array,this._array,t),this._dirty=!0,this},rotateY:function(t){return i.rotateY(this._array,this._array,t),this._dirty=!0,this},rotateZ:function(t){return i.rotateZ(this._array,this._array,t),this._dirty=!0,this},rotationTo:function(t,e){return i.rotationTo(this._array,t._array,e._array),this._dirty=!0,this},setAxes:function(t,e,n){return i.setAxes(this._array,t._array,e._array,n._array),this._dirty=!0,this},setAxisAngle:function(t,e){return i.setAxisAngle(this._array,t._array,e),this._dirty=!0,this},slerp:function(t,e,n){return i.slerp(this._array,t._array,e._array,n),this._dirty=!0,this},sqrLen:function(){return i.sqrLen(this._array)},squaredLength:function(){return i.squaredLength(this._array)},fromEuler:function(t,e){return a.fromEuler(this,t,e)},toString:function(){return"["+Array.prototype.join.call(this._array,",")+"]"},toArray:function(){return Array.prototype.slice.call(this._array)}};var o=Object.defineProperty;if(o){var s=a.prototype;o(s,"x",{get:function(){return this._array[0]},set:function(t){this._array[0]=t,this._dirty=!0}}),o(s,"y",{get:function(){return this._array[1]},set:function(t){this._array[1]=t,this._dirty=!0}}),o(s,"z",{get:function(){return this._array[2]},set:function(t){this._array[2]=t,this._dirty=!0}}),o(s,"w",{get:function(){return this._array[3]},set:function(t){this._array[3]=t,this._dirty=!0}})}a.add=function(t,e,n){return i.add(t._array,e._array,n._array),t._dirty=!0,t},a.set=function(t,e,n,r,a){i.set(t._array,e,n,r,a),t._dirty=!0},a.copy=function(t,e){return i.copy(t._array,e._array),t._dirty=!0,t},a.calculateW=function(t,e){return i.calculateW(t._array,e._array),t._dirty=!0,t},a.conjugate=function(t,e){return i.conjugate(t._array,e._array),t._dirty=!0,t},a.identity=function(t){return i.identity(t._array),t._dirty=!0,t},a.invert=function(t,e){return i.invert(t._array,e._array),t._dirty=!0,t},a.dot=function(t,e){return i.dot(t._array,e._array)},a.len=function(t){return i.length(t._array)},a.lerp=function(t,e,n,r){return i.lerp(t._array,e._array,n._array,r),t._dirty=!0,t},a.slerp=function(t,e,n,r){return i.slerp(t._array,e._array,n._array,r),t._dirty=!0,t},a.mul=function(t,e,n){return i.multiply(t._array,e._array,n._array),t._dirty=!0,t},a.multiply=a.mul,a.rotateX=function(t,e,n){return i.rotateX(t._array,e._array,n),t._dirty=!0,t},a.rotateY=function(t,e,n){return i.rotateY(t._array,e._array,n),t._dirty=!0,t},a.rotateZ=function(t,e,n){return i.rotateZ(t._array,e._array,n),t._dirty=!0,t},a.setAxisAngle=function(t,e,n){return i.setAxisAngle(t._array,e._array,n),t._dirty=!0,t},a.normalize=function(t,e){return i.normalize(t._array,e._array),t._dirty=!0,t},a.sqrLen=function(t){return i.sqrLen(t._array)},a.squaredLength=a.sqrLen,a.fromMat3=function(t,e){ +return i.fromMat3(t._array,e._array),t._dirty=!0,t},a.setAxes=function(t,e,n,r){return i.setAxes(t._array,e._array,n._array,r._array),t._dirty=!0,t},a.rotationTo=function(t,e,n){return i.rotationTo(t._array,e._array,n._array),t._dirty=!0,t},a.fromEuler=function(t,e,n){t._dirty=!0,e=e._array;var r=t._array,i=Math.cos(e[0]/2),a=Math.cos(e[1]/2),o=Math.cos(e[2]/2),s=Math.sin(e[0]/2),u=Math.sin(e[1]/2),l=Math.sin(e[2]/2),n=(n||"XYZ").toUpperCase();switch(n){case"XYZ":r[0]=s*a*o+i*u*l,r[1]=i*u*o-s*a*l,r[2]=i*a*l+s*u*o,r[3]=i*a*o-s*u*l;break;case"YXZ":r[0]=s*a*o+i*u*l,r[1]=i*u*o-s*a*l,r[2]=i*a*l-s*u*o,r[3]=i*a*o+s*u*l;break;case"ZXY":r[0]=s*a*o-i*u*l,r[1]=i*u*o+s*a*l,r[2]=i*a*l+s*u*o,r[3]=i*a*o-s*u*l;break;case"ZYX":r[0]=s*a*o-i*u*l,r[1]=i*u*o+s*a*l,r[2]=i*a*l-s*u*o,r[3]=i*a*o+s*u*l;break;case"YZX":r[0]=s*a*o+i*u*l,r[1]=i*u*o+s*a*l,r[2]=i*a*l-s*u*o,r[3]=i*a*o-s*u*l;break;case"XZY":r[0]=s*a*o-i*u*l,r[1]=i*u*o-s*a*l,r[2]=i*a*l+s*u*o,r[3]=i*a*o+s*u*l}},t.exports=a},function(t,e){var n={};n.isPowerOfTwo=function(t){return 0===(t&t-1)},n.nextPowerOfTwo=function(t){return t--,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,t|=t>>16,t++,t},n.nearestPowerOfTwo=function(t){return Math.pow(2,Math.round(Math.log(t)/Math.LN2))},t.exports=n},function(t,e,n){var r=n(15),i=n(69),a=n(4),o=n(6);a["import"](n(78));var s=r.extend(function(){var t=new a({vertex:a.source("qtek.skybox.vertex"),fragment:a.source("qtek.skybox.fragment")}),e=new o({shader:t,depthMask:!1});return{scene:null,geometry:new i,material:e,environmentMap:null,culling:!1}},function(){var t=this.scene;t&&this.attachScene(t),this.environmentMap&&this.setEnvironmentMap(this.environmentMap)},{attachScene:function(t){this.scene&&this.detachScene(),this.scene=t,t.on("beforerender",this._beforeRenderScene,this)},detachScene:function(){this.scene&&this.scene.off("beforerender",this._beforeRenderScene),this.scene=null},dispose:function(t){this.detachScene(),this.geometry.dispose(t),this.material.dispose(t)},setEnvironmentMap:function(t){this.material.set("environmentMap",t)},getEnvironmentMap:function(){return this.material.get("environmentMap")},_beforeRenderScene:function(t,e,n){this.renderSkybox(t,n)},renderSkybox:function(t,e){this.position.copy(e.getWorldPosition()),this.update(),t.gl.disable(t.gl.BLEND),t.renderQueue([this],e)}});t.exports=s},function(t,e,n){var r=n(15),i=n(43),a=n(4),o=n(6);a["import"](n(76));var s=r.extend(function(){var t=new a({vertex:a.source("qtek.basic.vertex"),fragment:a.source("qtek.basic.fragment")});t.enableTexture("diffuseMap");var e=new o({shader:t,depthMask:!1});return{scene:null,geometry:new i({widthSegments:30,heightSegments:30}),material:e,environmentMap:null,culling:!1}},function(){var t=this.scene;t&&this.attachScene(t),this.environmentMap&&this.setEnvironmentMap(this.environmentMap)},{attachScene:function(t){this.scene&&this.detachScene(),this.scene=t,t.on("beforerender",this._beforeRenderScene,this)},detachScene:function(){this.scene&&this.scene.off("beforerender",this._beforeRenderScene),this.scene=null},_beforeRenderScene:function(t,e,n){this.position.copy(n.getWorldPosition()),this.update(),t.renderQueue([this],n)},setEnvironmentMap:function(t){this.material.set("diffuseMap",t)},getEnvironmentMap:function(){return this.material.get("diffuseMap")},dispose:function(t){this.detachScene(),this.geometry.dispose(t),this.material.dispose(t)}});t.exports=s},function(t,e){t.exports="@export qtek.prez.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvoid main()\n{\n\n vec3 skinnedPosition = position;\n\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n#endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0);\n}\n\n@end\n\n\n@export qtek.prez.fragment\n\nvoid main()\n{\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n}\n\n@end"},function(t,e,n){"use strict";var r=n(8),i=n(18),a=n(26),o=n(32),s=n(52),u=n(24),l=n(82),c=n(84),h={loadTexture:function(t,e,n,a){var o;if("function"==typeof e?(n=e,a=n,e={}):e=e||{},"string"==typeof t){if(t.match(/.hdr$/)||"hdr"===e.fileType)return o=new r({width:0,height:0}),h._fetchTexture(t,function(t){c.parseRGBE(t,o,e.exposure),o.dirty(),n&&n(o)},a),o;t.match(/.dds$/)||"dds"===e.fileType?(o=new r({width:0,height:0}),h._fetchTexture(t,function(t){l.parse(t,o),o.dirty(),n&&n(o)},a)):(o=new r,o.load(t),o.success(n),o.error(a))}else if("object"==typeof t&&"undefined"!=typeof t.px){var o=new i;o.load(t),o.success(n),o.error(a)}return o},loadPanorama:function(t,e,n,r,i,a){var o=this;"function"==typeof r?(i=r,a=i,r={}):r=r||{},h.loadTexture(e,r,function(e){e.flipY=r.flipY||!1,o.panoramaToCubeMap(t,e,n,r),e.dispose(t.gl),i&&i(n)},a)},panoramaToCubeMap:function(t,e,n,r){var i=new o,a=new s({scene:new u});return a.material.set("diffuseMap",e),r=r||{},r.encodeRGBM&&a.material.shader.define("fragment","RGBM_ENCODE"),i.texture=n,i.render(t,a.scene),i.texture=null,i.dispose(t),n},_fetchTexture:function(t,e,n){a.get({url:t,responseType:"arraybuffer",onload:e,onerror:n})},createChessboard:function(t,e,n,i){t=t||512,e=e||64,n=n||"black",i=i||"white";var a=Math.ceil(t/e),o=document.createElement("canvas");o.width=t,o.height=t;var s=o.getContext("2d");s.fillStyle=i,s.fillRect(0,0,t,t),s.fillStyle=n;for(var u=0;u=0){var r=t[n.parentIndex].node;r.add(n.node)}else this.roots.push(n)}},addClip:function(t,e){for(var n=0;n0&&this._clips.splice(e,1)},removeClipsAll:function(){this._clips=[]},getClip:function(t){if(this._clips[t])return this._clips[t].clip},getClipNumber:function(){return this._clips.length},updateJointMatrices:function(){var t=u.create();return function(){for(var e=0;ei;if(a)t.length=i;else for(var o=r;o=0&&!(E[N]<=e);N--);N=Math.min(N,v-2)}else{for(N=O;Ne);N++);N=Math.min(N-1,v-2)}O=N,F=e;var n=E[N+1]-E[N];0!==n&&(R=(e-E[N])/n,m?(I=b[N],L=b[0===N?N:N-1],P=b[N>v-2?v-1:N+1],D=b[N>v-3?v-1:N+2],u?_(t,i,u(d(t,i),L,I,P,D,R)):y?l(L,I,P,D,R,R*R,R*R*R,d(t,i),x):_(t,i,c(L,I,P,D,R,R*R,R*R*R))):u?_(t,i,u(d(t,i),b[N],b[N+1],R)):y?o(b[N],b[N+1],R,d(t,i),x):_(t,i,a(b[N],b[N+1],R)))},B=new p({target:t._target,life:T,loop:t._loop,delay:t._delay,onframe:k,onfinish:n});return e&&"spline"!==e&&B.setEasing(e),B}}}function _(t,e,n,a,o){this._tracks={},this._target=t,this._loop=e||!1,this._getter=n||r,this._setter=a||i,this._interpolater=o||null,this._delay=0,this._doneList=[],this._onframeList=[],this._clipList=[]}var p=n(20),m=Array.prototype.slice;_.prototype={constructor:_,when:function(t,e){for(var n in e)this._tracks[n]||(this._tracks[n]=[],0!==t&&this._tracks[n].push({time:0,value:u(this._getter(this._target,n))})),this._tracks[n].push({time:parseInt(t),value:e[n]});return this},during:function(t){return this._onframeList.push(t),this},_doneCallback:function(){this._tracks={},this._clipList.length=0;for(var t=this._doneList,e=t.length,n=0;n1e-6?(o=Math.acos(s),u=Math.sin(o),l=Math.sin((1-r)*o)/u,c=Math.sin(r*o)/u):(l=1-r,c=r),t[0]=l*h+c*p,t[1]=l*f+c*m,t[2]=l*d+c*v,t[3]=l*_+c*g,t}var a=n(20),o=n(37),s=n(1),u=s.quat,l=s.vec3,c=function(t){t=t||{},a.call(this,t),this.position=l.create(),this.rotation=u.create(),this.scale=l.fromValues(1,1,1),this.channels={time:null,position:null,rotation:null,scale:null},this._cacheKey=0,this._cacheTime=0};c.prototype=Object.create(a.prototype),c.prototype.constructor=c,c.prototype.step=function(t){var e=a.prototype.step.call(this,t);return"finish"!==e&&this.setTime(this._elapsedTime),e},c.prototype.setTime=function(t){if(this.channels.time){var e=this.channels,n=e.time.length,a=-1;if(t=0;s--)if(e.time[s-1]<=t&&e.time[s]>t){a=s-1;break}}else for(var s=this._cacheKey;st){a=s;break}if(a>-1){this._cacheKey=a,this._cacheTime=t;var u=a,l=a+1,c=e.time[u],h=e.time[l],f=(t-c)/(h-c);e.rotation&&i(this.rotation,e.rotation,e.rotation,f,4*u,4*l),e.position&&r(this.position,e.position,e.position,f,3*u,3*l),e.scale&&r(this.scale,e.scale,e.scale,f,3*u,3*l)}a==n-2&&(this._cacheKey=0,this._cacheTime=0)}},c.prototype.getSubClip=function(t,e){var n=new c({name:this.name}),r=this.channels.time[0];t=Math.min(Math.max(t,r),this.life),e=Math.min(Math.max(e,r),this.life);var i=this._findRange(t),a=this._findRange(e),o=a[0]-i[0]+1;0===i[1]&&0===a[1]&&(o-=1),this.channels.rotation&&(n.channels.rotation=new Float32Array(4*o)),this.channels.position&&(n.channels.position=new Float32Array(3*o)),this.channels.scale&&(n.channels.scale=new Float32Array(3*o)),this.channels.time&&(n.channels.time=new Float32Array(o)),this.setTime(t);for(var s=0;s<3;s++)n.channels.rotation[s]=this.rotation[s],n.channels.position[s]=this.position[s],n.channels.scale[s]=this.scale[s];n.channels.time[0]=0,n.channels.rotation[3]=this.rotation[3];for(var s=1;st&&(r=i);var a=0;if(r>=0)var o=e.time[r],s=e.time[r+1],a=(t-o)/(s-o);return[r,a]},c.prototype.blend1D=o.prototype.blend1D,c.prototype.blend2D=o.prototype.blend2D,c.prototype.additiveBlend=o.prototype.additiveBlend,c.prototype.subtractiveBlend=o.prototype.subtractiveBlend,c.prototype.clone=function(){var t=a.prototype.clone.call(this);return t.channels={time:this.channels.time||null,position:this.channels.position||null,rotation:this.channels.rotation||null,scale:this.channels.scale||null},l.copy(t.position,this.position),u.copy(t.rotation,this.rotation),l.copy(t.scale,this.scale),t},t.exports=c},function(t,e,n){"use strict";var r=n(20),i=n(37),a=n(1),o=a.quat,s=a.vec3,u=function(t){if(t=t||{},r.call(this,t),this.jointClips=[],this.life=0,t.jointClips&&t.jointClips.length>0)for(var e=0;e0){var e=this.outputs[t];e.keepLastFrame?(this._prevOutputTextures[t]&&this._compositor.releaseTexture(this._prevOutputTextures[t]),this._prevOutputTextures[t]=this._outputTextures[t]):this._compositor.releaseTexture(this._outputTextures[t])}}});t.exports=a},function(t,e,n){"use strict";var r=n(2),i=n(23),a=r.extend(function(){return{nodes:[]}},{dirty:function(){this._dirty=!0},addNode:function(t){this.nodes.indexOf(t)>=0||(this.nodes.push(t),this._dirty=!0)},removeNode:function(t){"string"==typeof t&&(t=this.getNodeByName(t));var e=this.nodes.indexOf(t);e>=0&&(this.nodes.splice(e,1),this._dirty=!0)},getNodeByName:function(t){for(var e=0;e=e.COLOR_ATTACHMENT0&&c<=e.COLOR_ATTACHMENT0+8&&f.push(c);h.drawBuffersEXT(f)}t.saveClear(),t.clearBit=a.DEPTH_BUFFER_BIT|a.COLOR_BUFFER_BIT,n=t.render(this.scene,this.camera,!this.autoUpdateScene,this.preZ),t.restoreClear(),r.unbind(t)}else n=t.render(this.scene,this.camera,!this.autoUpdateScene,this.preZ);this.trigger("afterrender",n),this._rendering=!1,this._rendered=!0}});t.exports=s},function(t,e,n){"use strict";var r=n(23),i=r.extend(function(){return{texture:null,outputs:{color:{}}}},function(){},{getOutput:function(t,e){return this.texture},beforeFrame:function(){},afterFrame:function(){}});t.exports=i},function(t,e){ +"use strict";function n(t,e,n){"object"==typeof e&&(n=e,e=null);var a,o=this;if(!(t instanceof Function)){a=[];for(var s in t)t.hasOwnProperty(s)&&a.push(s)}var u=function(e){if(o.apply(this,arguments),t instanceof Function?r(this,t.call(this,e)):i(this,t,a),this.constructor===u)for(var n=u.__initializers__,s=0;s0&&(r.shader.define("vertex","SKINNING"),r.shader.define("vertex","JOINT_COUNT",t),i.shader.define("vertex","SKINNING"),i.shader.define("vertex","JOINT_COUNT",t)),n={material1:r,material2:i},e[t]=n}return n.used=!0,n},_resetGBufferMaterials:function(){for(var t in this._gBufferMaterials)this._gBufferMaterials[t].used=!1},_cleanGBufferMaterials:function(t){for(var e in this._gBufferMaterials){var n=this._gBufferMaterials[e];n.used||(n.material1.dispose(t),n.material2.dispose(t))}},_replaceGBufferMat:function(t,e){for(var n=0;n 0.01)\n {\n gl_FragColor.rgb = gl_FragColor.rgb * mix(lineColor, vec3(1.0), edgeFactor(lineWidth));\n }\n\n#ifdef GAMMA_ENCODE\n gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(1 / 2.2));\n#endif\n\n#ifdef ALPHA_TEST\n if (gl_FragColor.a < ALPHA_TEST_THRESHOLD) {\n discard;\n }\n#endif\n\n gl_FragColor = encodeHDR(gl_FragColor);\n\n}\n\n@end"},function(t,e,n){var r="uniform vec3 ",i="uniform float ",a="@export qtek.header.",o="@end",s=":unconfigurable;";t.exports=[a+"directional_light",r+"directionalLightDirection[DIRECTIONAL_LIGHT_COUNT]"+s,r+"directionalLightColor[DIRECTIONAL_LIGHT_COUNT]"+s,o,a+"ambient_light",r+"ambientLightColor[AMBIENT_LIGHT_COUNT]"+s,o,a+"ambient_sh_light",r+"ambientSHLightColor[AMBIENT_SH_LIGHT_COUNT]"+s,r+"ambientSHLightCoefficients[AMBIENT_SH_LIGHT_COUNT * 9]"+s,n(144),o,a+"ambient_cubemap_light",r+"ambientCubemapLightColor[AMBIENT_CUBEMAP_LIGHT_COUNT]"+s,"uniform samplerCube ambientCubemapLightCubemap[AMBIENT_CUBEMAP_LIGHT_COUNT]"+s,"uniform sampler2D ambientCubemapLightBRDFLookup[AMBIENT_CUBEMAP_LIGHT_COUNT]"+s,o,a+"point_light",r+"pointLightPosition[POINT_LIGHT_COUNT]"+s,i+"pointLightRange[POINT_LIGHT_COUNT]"+s,r+"pointLightColor[POINT_LIGHT_COUNT]"+s,o,a+"spot_light",r+"spotLightPosition[SPOT_LIGHT_COUNT]"+s,r+"spotLightDirection[SPOT_LIGHT_COUNT]"+s,i+"spotLightRange[SPOT_LIGHT_COUNT]"+s,i+"spotLightUmbraAngleCosine[SPOT_LIGHT_COUNT]"+s,i+"spotLightPenumbraAngleCosine[SPOT_LIGHT_COUNT]"+s,i+"spotLightFalloffFactor[SPOT_LIGHT_COUNT]"+s,r+"spotLightColor[SPOT_LIGHT_COUNT]"+s,o].join("\n")},function(t,e){t.exports="@export qtek.skybox.vertex\n\nuniform mat4 world : WORLD;\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position : POSITION;\n\nvarying vec3 v_WorldPosition;\n\nvoid main()\n{\n v_WorldPosition = (world * vec4(position, 1.0)).xyz;\n gl_Position = worldViewProjection * vec4(position, 1.0);\n}\n\n@end\n\n@export qtek.skybox.fragment\n\nuniform mat4 viewInverse : VIEWINVERSE;\nuniform samplerCube environmentMap;\nuniform float lod: 0.0;\n\nvarying vec3 v_WorldPosition;\n\n@import qtek.util.rgbm\n\nvoid main()\n{\n vec3 eyePos = viewInverse[3].xyz;\n vec3 viewDirection = normalize(v_WorldPosition - eyePos);\n\n vec3 tex = decodeHDR(textureCubeLodEXT(environmentMap, viewDirection, lod)).rgb;\n\n#ifdef SRGB_DECODE\n tex.rgb = pow(tex.rgb, vec3(2.2));\n#endif\n\n gl_FragColor = encodeHDR(vec4(tex, 1.0));\n}\n@end"},function(t,e){t.exports="\n\n@export qtek.standard.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform mat4 worldInverseTranspose : WORLDINVERSETRANSPOSE;\nuniform mat4 world : WORLD;\n\nuniform vec2 uvRepeat : [1.0, 1.0];\nuniform vec2 uvOffset : [0.0, 0.0];\n\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\n\n#if defined(AOMAP_ENABLED)\nattribute vec2 texcoord2 : TEXCOORD_1;\n#endif\n\nattribute vec3 normal : NORMAL;\nattribute vec4 tangent : TANGENT;\n\n#ifdef VERTEX_COLOR\nattribute vec4 color : COLOR;\n#endif\n\nattribute vec3 barycentric;\n\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\n#endif\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\nvarying vec3 v_Barycentric;\n\n#ifdef NORMALMAP_ENABLED\nvarying vec3 v_Tangent;\nvarying vec3 v_Bitangent;\n#endif\n\n#ifdef VERTEX_COLOR\nvarying vec4 v_Color;\n#endif\n\n\n#if defined(AOMAP_ENABLED)\nvarying vec2 v_Texcoord2;\n#endif\n\nvoid main()\n{\n\n vec3 skinnedPosition = position;\n vec3 skinnedNormal = normal;\n vec3 skinnedTangent = tangent.xyz;\n#ifdef SKINNING\n\n @import qtek.chunk.skin_matrix\n\n skinnedPosition = (skinMatrixWS * vec4(position, 1.0)).xyz;\n skinnedNormal = (skinMatrixWS * vec4(normal, 0.0)).xyz;\n skinnedTangent = (skinMatrixWS * vec4(tangent.xyz, 0.0)).xyz;\n#endif\n\n gl_Position = worldViewProjection * vec4(skinnedPosition, 1.0);\n\n v_Texcoord = texcoord * uvRepeat + uvOffset;\n v_WorldPosition = (world * vec4(skinnedPosition, 1.0)).xyz;\n v_Barycentric = barycentric;\n\n v_Normal = normalize((worldInverseTranspose * vec4(skinnedNormal, 0.0)).xyz);\n\n#ifdef NORMALMAP_ENABLED\n v_Tangent = normalize((worldInverseTranspose * vec4(skinnedTangent, 0.0)).xyz);\n v_Bitangent = normalize(cross(v_Normal, v_Tangent) * tangent.w);\n#endif\n\n#ifdef VERTEX_COLOR\n v_Color = color;\n#endif\n\n#if defined(AOMAP_ENABLED)\n v_Texcoord2 = texcoord2;\n#endif\n}\n\n@end\n\n\n@export qtek.standard.fragment\n\n#define PI 3.14159265358979\n#define ALPHA_TEST_THRESHOLD 0.5\n\n#define GLOSS_CHANEL 0\n#define ROUGHNESS_CHANEL 0\n#define METALNESS_CHANEL 1\n\nuniform mat4 viewInverse : VIEWINVERSE;\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_Normal;\nvarying vec3 v_WorldPosition;\n\n#ifdef NORMALMAP_ENABLED\nvarying vec3 v_Tangent;\nvarying vec3 v_Bitangent;\nuniform sampler2D normalMap;\n#endif\n\n#ifdef DIFFUSEMAP_ENABLED\nuniform sampler2D diffuseMap;\n#endif\n\n#ifdef SPECULARMAP_ENABLED\nuniform sampler2D specularMap;\n#endif\n\n#ifdef USE_ROUGHNESS\nuniform float roughness : 0.5;\n #ifdef ROUGHNESSMAP_ENABLED\nuniform sampler2D roughnessMap;\n #endif\n#else\nuniform float glossiness: 0.5;\n #ifdef GLOSSMAP_ENABLED\nuniform sampler2D glossMap;\n #endif\n#endif\n\n#ifdef METALNESSMAP_ENABLED\nuniform sampler2D metalnessMap;\n#endif\n\n#ifdef ENVIRONMENTMAP_ENABLED\nuniform samplerCube environmentMap;\n\n #ifdef PARALLAX_CORRECTED\nuniform vec3 environmentBoxMin;\nuniform vec3 environmentBoxMax;\n #endif\n\n#endif\n\n#ifdef BRDFLOOKUP_ENABLED\nuniform sampler2D brdfLookup;\n#endif\n\n#ifdef EMISSIVEMAP_ENABLED\nuniform sampler2D emissiveMap;\n#endif\n\n#ifdef SSAOMAP_ENABLED\nuniform sampler2D ssaoMap;\nuniform vec4 viewport : VIEWPORT;\n#endif\n\n#ifdef AOMAP_ENABLED\nuniform sampler2D aoMap;\nuniform float aoIntensity;\nvarying vec2 v_Texcoord2;\n#endif\n\nuniform vec3 color : [1.0, 1.0, 1.0];\nuniform float alpha : 1.0;\n\n\n#ifdef USE_METALNESS\nuniform float metalness : 0.0;\n#else\nuniform vec3 specularColor : [0.1, 0.1, 0.1];\n#endif\n\nuniform vec3 emission : [0.0, 0.0, 0.0];\n\nuniform float emissionIntensity: 1;\n\nuniform float lineWidth : 0.0;\nuniform vec3 lineColor : [0.0, 0.0, 0.0];\nvarying vec3 v_Barycentric;\n\n#ifdef ENVIRONMENTMAP_PREFILTER\nuniform float maxMipmapLevel: 5;\n#endif\n\n#ifdef AMBIENT_LIGHT_COUNT\n@import qtek.header.ambient_light\n#endif\n\n#ifdef AMBIENT_SH_LIGHT_COUNT\n@import qtek.header.ambient_sh_light\n#endif\n\n#ifdef AMBIENT_CUBEMAP_LIGHT_COUNT\n@import qtek.header.ambient_cubemap_light\n#endif\n\n#ifdef POINT_LIGHT_COUNT\n@import qtek.header.point_light\n#endif\n#ifdef DIRECTIONAL_LIGHT_COUNT\n@import qtek.header.directional_light\n#endif\n#ifdef SPOT_LIGHT_COUNT\n@import qtek.header.spot_light\n#endif\n\n@import qtek.util.calculate_attenuation\n\n@import qtek.util.edge_factor\n\n@import qtek.util.rgbm\n\n@import qtek.util.srgb\n\n@import qtek.plugin.compute_shadow_map\n\n@import qtek.util.parallax_correct\n\n\nfloat G_Smith(float g, float ndv, float ndl)\n{\n float roughness = 1.0 - g;\n float k = roughness * roughness / 2.0;\n float G1V = ndv / (ndv * (1.0 - k) + k);\n float G1L = ndl / (ndl * (1.0 - k) + k);\n return G1L * G1V;\n}\nvec3 F_Schlick(float ndv, vec3 spec) {\n return spec + (1.0 - spec) * pow(1.0 - ndv, 5.0);\n}\n\nfloat D_Phong(float g, float ndh) {\n float a = pow(8192.0, g);\n return (a + 2.0) / 8.0 * pow(ndh, a);\n}\n\nfloat D_GGX(float g, float ndh) {\n float r = 1.0 - g;\n float a = r * r;\n float tmp = ndh * ndh * (a - 1.0) + 1.0;\n return a / (PI * tmp * tmp);\n}\n\n\nvoid main()\n{\n vec4 albedoColor = vec4(color, alpha);\n vec3 eyePos = viewInverse[3].xyz;\n vec3 V = normalize(eyePos - v_WorldPosition);\n\n#ifdef DIFFUSEMAP_ENABLED\n vec4 texel = texture2D(diffuseMap, v_Texcoord);\n #ifdef SRGB_DECODE\n texel = sRGBToLinear(texel);\n #endif\n albedoColor.rgb *= texel.rgb;\n #ifdef DIFFUSEMAP_ALPHA_ALPHA\n albedoColor.a *= texel.a;\n #endif\n\n#endif\n\n\n#ifdef USE_METALNESS\n float m = metalness;\n\n #ifdef METALNESSMAP_ENABLED\n float m2 = texture2D(metalnessMap, v_Texcoord)[METALNESS_CHANEL];\n m = clamp(m2 + (m - 0.5) * 2.0, 0.0, 1.0);\n #endif\n\n vec3 baseColor = albedoColor.rgb;\n albedoColor.rgb = baseColor * (1.0 - m);\n vec3 spec = mix(vec3(0.04), baseColor, m);\n#else\n vec3 spec = specularColor;\n#endif\n\n#ifdef USE_ROUGHNESS\n float g = 1.0 - roughness;\n #ifdef ROUGHNESSMAP_ENABLED\n float g2 = 1.0 - texture2D(roughnessMap, v_Texcoord)[ROUGHNESS_CHANEL];\n g = clamp(g2 + (g - 0.5) * 2.0, 0.0, 1.0);\n #endif\n#else\n float g = glossiness;\n #ifdef GLOSSMAP_ENABLED\n float g2 = texture2D(glossMap, v_Texcoord)[GLOSS_CHANEL];\n g = clamp(g2 + (g - 0.5) * 2.0, 0.0, 1.0);\n #endif\n#endif\n\n#ifdef SPECULARMAP_ENABLED\n spec *= texture2D(specularMap, v_Texcoord).rgb;\n#endif\n\n vec3 N = v_Normal;\n#ifdef NORMALMAP_ENABLED\n if (dot(v_Tangent, v_Tangent) > 0.0) {\n vec3 normalTexel = texture2D(normalMap, v_Texcoord).xyz;\n if (dot(normalTexel, normalTexel) > 0.0) { N = normalTexel * 2.0 - 1.0;\n mat3 tbn = mat3(v_Tangent, v_Bitangent, v_Normal);\n N = normalize(tbn * N);\n }\n }\n#endif\n\n vec3 diffuseTerm = vec3(0.0, 0.0, 0.0);\n vec3 specularTerm = vec3(0.0, 0.0, 0.0);\n\n float ndv = clamp(dot(N, V), 0.0, 1.0);\n vec3 fresnelTerm = F_Schlick(ndv, spec);\n\n#ifdef AMBIENT_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_LIGHT_COUNT; _idx_++)\n {{\n diffuseTerm += ambientLightColor[_idx_];\n }}\n#endif\n\n#ifdef AMBIENT_SH_LIGHT_COUNT\n for(int _idx_ = 0; _idx_ < AMBIENT_SH_LIGHT_COUNT; _idx_++)\n {{\n diffuseTerm += calcAmbientSHLight(_idx_, N) * ambientSHLightColor[_idx_];\n }}\n#endif\n\n#ifdef POINT_LIGHT_COUNT\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsPoint[POINT_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfPointLights(v_WorldPosition, shadowContribsPoint);\n }\n#endif\n for(int _idx_ = 0; _idx_ < POINT_LIGHT_COUNT; _idx_++)\n {{\n\n vec3 lightPosition = pointLightPosition[_idx_];\n vec3 lc = pointLightColor[_idx_];\n float range = pointLightRange[_idx_];\n\n vec3 L = lightPosition - v_WorldPosition;\n\n float dist = length(L);\n float attenuation = lightAttenuation(dist, range);\n L /= dist;\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n\n float shadowContrib = 1.0;\n#if defined(POINT_LIGHT_SHADOWMAP_COUNT)\n if(shadowEnabled)\n {\n shadowContrib = shadowContribsPoint[_idx_];\n }\n#endif\n\n vec3 li = lc * ndl * attenuation * shadowContrib;\n diffuseTerm += li;\n specularTerm += li * fresnelTerm * D_Phong(g, ndh);\n }}\n#endif\n\n#ifdef DIRECTIONAL_LIGHT_COUNT\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir);\n }\n#endif\n for(int _idx_ = 0; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++)\n {{\n\n vec3 L = -normalize(directionalLightDirection[_idx_]);\n vec3 lc = directionalLightColor[_idx_];\n\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n\n float shadowContrib = 1.0;\n#if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT)\n if(shadowEnabled)\n {\n shadowContrib = shadowContribsDir[_idx_];\n }\n#endif\n\n vec3 li = lc * ndl * shadowContrib;\n\n diffuseTerm += li;\n specularTerm += li * fresnelTerm * D_Phong(g, ndh);\n }}\n#endif\n\n#ifdef SPOT_LIGHT_COUNT\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\n float shadowContribsSpot[SPOT_LIGHT_COUNT];\n if(shadowEnabled)\n {\n computeShadowOfSpotLights(v_WorldPosition, shadowContribsSpot);\n }\n#endif\n for(int i = 0; i < SPOT_LIGHT_COUNT; i++)\n {\n vec3 lightPosition = spotLightPosition[i];\n vec3 spotLightDirection = -normalize(spotLightDirection[i]);\n vec3 lc = spotLightColor[i];\n float range = spotLightRange[i];\n float a = spotLightUmbraAngleCosine[i];\n float b = spotLightPenumbraAngleCosine[i];\n float falloffFactor = spotLightFalloffFactor[i];\n\n vec3 L = lightPosition - v_WorldPosition;\n float dist = length(L);\n float attenuation = lightAttenuation(dist, range);\n\n L /= dist;\n float c = dot(spotLightDirection, L);\n\n float falloff;\n falloff = clamp((c - a) /( b - a), 0.0, 1.0);\n falloff = pow(falloff, falloffFactor);\n\n vec3 H = normalize(L + V);\n float ndl = clamp(dot(N, L), 0.0, 1.0);\n float ndh = clamp(dot(N, H), 0.0, 1.0);\n\n float shadowContrib = 1.0;\n#if defined(SPOT_LIGHT_SHADOWMAP_COUNT)\n if (shadowEnabled)\n {\n shadowContrib = shadowContribsSpot[i];\n }\n#endif\n\n vec3 li = lc * attenuation * (1.0 - falloff) * shadowContrib * ndl;\n\n diffuseTerm += li;\n specularTerm += li * fresnelTerm * D_Phong(g, ndh);\n }\n#endif\n\n vec4 outColor = albedoColor;\n outColor.rgb *= diffuseTerm;\n\n outColor.rgb += specularTerm;\n\n\n#ifdef AMBIENT_CUBEMAP_LIGHT_COUNT\n vec3 L = reflect(-V, N);\n float rough2 = clamp(1.0 - g, 0.0, 1.0);\n float bias2 = rough2 * 5.0;\n vec2 brdfParam2 = texture2D(ambientCubemapLightBRDFLookup[0], vec2(rough2, ndv)).xy;\n vec3 envWeight2 = spec * brdfParam2.x + brdfParam2.y;\n vec3 envTexel2;\n for(int _idx_ = 0; _idx_ < AMBIENT_CUBEMAP_LIGHT_COUNT; _idx_++)\n {{\n envTexel2 = RGBMDecode(textureCubeLodEXT(ambientCubemapLightCubemap[_idx_], L, bias2), 51.5);\n outColor.rgb += ambientCubemapLightColor[_idx_] * envTexel2 * envWeight2;\n }}\n#endif\n\n#ifdef ENVIRONMENTMAP_ENABLED\n\n vec3 envWeight = g * fresnelTerm;\n vec3 L = reflect(-V, N);\n\n #ifdef PARALLAX_CORRECTED\n L = parallaxCorrect(L, v_WorldPosition, environmentBoxMin, environmentBoxMax);\n #endif\n\n #ifdef ENVIRONMENTMAP_PREFILTER\n float rough = clamp(1.0 - g, 0.0, 1.0);\n float bias = rough * maxMipmapLevel;\n vec3 envTexel = decodeHDR(textureCubeLodEXT(environmentMap, L, bias)).rgb;\n\n #ifdef BRDFLOOKUP_ENABLED\n vec2 brdfParam = texture2D(brdfLookup, vec2(rough, ndv)).xy;\n envWeight = spec * brdfParam.x + brdfParam.y;\n #endif\n\n #else\n vec3 envTexel = textureCube(environmentMap, L).xyz;\n #endif\n\n outColor.rgb += envTexel * envWeight;\n#endif\n\n float aoFactor = 1.0;\n#ifdef SSAOMAP_ENABLED\n aoFactor = min(texture2D(ssaoMap, (gl_FragCoord.xy - viewport.xy) / viewport.zw).r, aoFactor);\n#endif\n\n#ifdef AOMAP_ENABLED\n aoFactor = min(1.0 - clamp((1.0 - texture2D(aoMap, v_Texcoord2).r) * aoIntensity, 0.0, 1.0), aoFactor);\n#endif\n\n outColor.rgb *= aoFactor;\n\n vec3 lEmission = emission;\n#ifdef EMISSIVEMAP_ENABLED\n lEmission *= texture2D(emissiveMap, v_Texcoord).rgb;\n#endif\n outColor.rgb += lEmission * emissionIntensity;\n\n#ifdef GAMMA_ENCODE\n outColor.rgb = pow(outColor.rgb, vec3(1 / 2.2));\n#endif\n\n if(lineWidth > 0.)\n {\n outColor.rgb = mix(lineColor, vec3(outColor.rgb), edgeFactor(lineWidth));\n }\n\n#ifdef ALPHA_TEST\n if (outColor.a < ALPHA_TEST_THRESHOLD) {\n discard;\n }\n#endif\n\n gl_FragColor = encodeHDR(outColor);\n}\n\n@end\n"; +},function(t,e){t.exports="\n@export qtek.util.rand\nhighp float rand(vec2 uv) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot(uv.xy, vec2(a,b)), sn = mod(dt, 3.141592653589793);\n return fract(sin(sn) * c);\n}\n@end\n\n@export qtek.util.calculate_attenuation\n\nuniform float attenuationFactor : 5.0;\n\nfloat lightAttenuation(float dist, float range)\n{\n float attenuation = 1.0;\n attenuation = dist*dist/(range*range+1.0);\n float att_s = attenuationFactor;\n attenuation = 1.0/(attenuation*att_s+1.0);\n att_s = 1.0/(att_s+1.0);\n attenuation = attenuation - att_s;\n attenuation /= 1.0 - att_s;\n return clamp(attenuation, 0.0, 1.0);\n}\n\n@end\n\n@export qtek.util.edge_factor\n\nfloat edgeFactor(float width)\n{\n vec3 d = fwidth(v_Barycentric);\n vec3 a3 = smoothstep(vec3(0.0), d * width, v_Barycentric);\n return min(min(a3.x, a3.y), a3.z);\n}\n\n@end\n\n@export qtek.util.encode_float\nvec4 encodeFloat(const in float depth)\n{\n \n \n const vec4 bitShifts = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);\n const vec4 bit_mask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);\n vec4 res = fract(depth * bitShifts);\n res -= res.xxyz * bit_mask;\n\n return res;\n}\n@end\n\n@export qtek.util.decode_float\nfloat decodeFloat(const in vec4 color)\n{\n \n \n const vec4 bitShifts = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0);\n return dot(color, bitShifts);\n}\n@end\n\n\n@export qtek.util.float\n@import qtek.util.encode_float\n@import qtek.util.decode_float\n@end\n\n\n\n@export qtek.util.rgbm_decode\nvec3 RGBMDecode(vec4 rgbm, float range) {\n return range * rgbm.rgb * rgbm.a;\n }\n@end\n\n@export qtek.util.rgbm_encode\nvec4 RGBMEncode(vec3 color, float range) {\n if (dot(color, color) == 0.0) {\n return vec4(0.0);\n }\n vec4 rgbm;\n color /= range;\n rgbm.a = clamp(max(max(color.r, color.g), max(color.b, 1e-6)), 0.0, 1.0);\n rgbm.a = ceil(rgbm.a * 255.0) / 255.0;\n rgbm.rgb = color / rgbm.a;\n return rgbm;\n}\n@end\n\n@export qtek.util.rgbm\n@import qtek.util.rgbm_decode\n@import qtek.util.rgbm_encode\n\nvec4 decodeHDR(vec4 color)\n{\n#if defined(RGBM_DECODE) || defined(RGBM)\n return vec4(RGBMDecode(color, 51.5), 1.0);\n#else\n return color;\n#endif\n}\n\nvec4 encodeHDR(vec4 color)\n{\n#if defined(RGBM_ENCODE) || defined(RGBM)\n return RGBMEncode(color.xyz, 51.5);\n#else\n return color;\n#endif\n}\n\n@end\n\n\n@export qtek.util.srgb\n\nvec4 sRGBToLinear(in vec4 value) {\n return vec4(mix(pow(value.rgb * 0.9478672986 + vec3(0.0521327014), vec3(2.4)), value.rgb * 0.0773993808, vec3(lessThanEqual(value.rgb, vec3(0.04045)))), value.w);\n}\n\nvec4 linearTosRGB(in vec4 value) {\n return vec4(mix(pow(value.rgb, vec3(0.41666)) * 1.055 - vec3(0.055), value.rgb * 12.92, vec3(lessThanEqual(value.rgb, vec3(0.0031308)))), value.w);\n}\n@end\n\n\n@export qtek.chunk.skin_matrix\n\nmat4 skinMatrixWS;\nif (joint.x >= 0.0)\n{\n skinMatrixWS = skinMatrix[int(joint.x)] * weight.x;\n}\nif (joint.y >= 0.0)\n{\n skinMatrixWS += skinMatrix[int(joint.y)] * weight.y;\n}\nif (joint.z >= 0.0)\n{\n skinMatrixWS += skinMatrix[int(joint.z)] * weight.z;\n}\nif (joint.w >= 0.0)\n{\n skinMatrixWS += skinMatrix[int(joint.w)] * (1.0-weight.x-weight.y-weight.z);\n}\n@end\n\n\n\n@export qtek.util.parallax_correct\n\nvec3 parallaxCorrect(in vec3 dir, in vec3 pos, in vec3 boxMin, in vec3 boxMax) {\n vec3 first = (boxMax - pos) / dir;\n vec3 second = (boxMin - pos) / dir;\n\n vec3 further = max(first, second);\n float dist = min(further.x, min(further.y, further.z));\n\n vec3 fixedPos = pos + dir * dist;\n vec3 boxCenter = (boxMax + boxMin) * 0.5;\n\n return normalize(fixedPos - boxCenter);\n}\n\n@end\n\n\n\n@export qtek.util.clamp_sample\nvec4 clampSample(const in sampler2D texture, const in vec2 coord)\n{\n#ifdef STEREO\n float eye = step(0.5, coord.x) * 0.5;\n vec2 coordClamped = clamp(coord, vec2(eye, 0.0), vec2(0.5 + eye, 1.0));\n#else\n vec2 coordClamped = clamp(coord, vec2(0.0), vec2(1.0));\n#endif\n return texture2D(texture, coordClamped);\n}\n@end"},function(t,e,n){var r=n(8),i=n(18),a=n(7),o=n(14),s=n(21),u=n(6),l=n(4),c=n(51),h=n(24),f=n(32),d=n(13),_=n(54),p=n(151),m=n(152),v={},g=["px","nx","py","ny","pz","nz"];v.prefilterEnvironmentMap=function(t,e,n,s,p){p&&s||(s=v.generateNormalDistribution(),p=v.integrateBRDF(t,s)),n=n||{};var y=n.width||64,x=n.height||64,T=n.type||e.type,E=new i({width:y,height:x,type:T,flipY:!1,mipmaps:[]});E.isPowerOfTwo()||console.warn("Width and height must be power of two to enable mipmap.");var b=Math.min(y,x),S=Math.log(b)/Math.log(2)+1,A=new u({shader:new l({vertex:l.source("qtek.skybox.vertex"),fragment:m})});A.set("normalDistribution",s),n.encodeRGBM&&A.shader.define("fragment","RGBM_ENCODE"),n.decodeRGBM&&A.shader.define("fragment","RGBM_DECODE");var N,w=new h;if(e instanceof r){var M=new i({width:y,height:x,type:T===a.FLOAT?a.HALF_FLOAT:T});_.panoramaToCubeMap(t,e,M,{encodeRGBM:n.decodeRGBM}),e=M}N=new c({scene:w,material:A}),N.material.set("environmentMap",e);var C=new f({texture:E});n.encodeRGBM&&(T=E.type=a.UNSIGNED_BYTE);for(var R=new r({width:y,height:x,type:T}),L=new o({depthBuffer:!1}),I=d[T===a.UNSIGNED_BYTE?"Uint8Array":"Float32Array"],P=0;P>>16)>>>0;u=((1431655765&u)<<1|(2863311530&u)>>>1)>>>0,u=((858993459&u)<<2|(3435973836&u)>>>2)>>>0,u=((252645135&u)<<4|(4042322160&u)>>>4)>>>0,u=(((16711935&u)<<8|(4278255360&u)>>>8)>>>0)/4294967296;for(var l=0;ll&&(l=t[e][0]),t[e][1]c&&(c=t[e][1]);n=l-s,r=c-u,i=Math.max(n,r),a=s+.5*n,o=u+.5*r,t.push([a-20*i,o-i],[a,o+20*i],[a+20*i,o-i])}function r(t,e,n,r){var i,a,o,s,u,l,c=t[e],h=t[n],f=t[r],d=h[0]-c[0],_=h[1]-c[1],p=f[0]-c[0],m=f[1]-c[1],v=d*(c[0]+h[0])+_*(c[1]+h[1]),g=p*(c[0]+f[0])+m*(c[1]+f[1]),y=2*(d*(f[1]-h[1])-_*(f[0]-h[0]));return Math.abs(y)<1e-6?(i=Math.min(c[0],h[0],f[0]),a=Math.min(c[1],h[1],f[1]),o=.5*(Math.max(c[0],h[0],f[0])-i),s=.5*(Math.max(c[1],h[1],f[1])-a),u=i+o,l=a+s):(u=(m*v-_*g)/y,l=(d*g-p*v)/y,o=u-c[0],s=l-c[1]),{i:e,j:n,k:r,x:u,y:l,r:o*o+s*s}}function i(t){var e,n,r,i,a,o=t.length;t:for(;o;)for(n=t[--o],e=t[--o],r=o;r;)if(a=t[--r],i=t[--r],e===i&&n===a||e===a&&n===i){t.splice(o,2),t.splice(r,2),o-=2;continue t}}var a={triangulate:function(t,e){var a,o,s,u,l,c,h,f,d,_,p,m=t.length;if(m<3)return[];if(t=t.slice(0),e)for(a=m;a--;)t[a]=t[a][e];for(s=new Array(m),a=m;a--;)s[a]=a;for(s.sort(function(e,n){return t[n][0]-t[e][0]}),n(t),u=[r(t,m+0,m+1,m+2)],l=[],c=[],a=s.length;a--;){for(p=s[a],c.length=0,o=u.length;o--;)h=t[p][0]-u[o].x,h>0&&h*h>u[o].r?(l.push(u[o]),u.splice(o,1)):(f=t[p][1]-u[o].y,h*h+f*f>u[o].r||(c.push(u[o].i,u[o].j,u[o].j,u[o].k,u[o].k,u[o].i),u.splice(o,1)));for(i(c),o=c.length;o;)_=c[--o],d=c[--o],u.push(r(t,d,_,p))}for(a=u.length;a--;)l.push(u[a]);for(u.length=0,a=l.length;a--;)if(l[a].it[0][0]&&e[0]>t[1][0]&&e[0]>t[2][0]||e[1]t[0][1]&&e[1]>t[1][1]&&e[1]>t[2][1])return null;var n=t[1][0]-t[0][0],r=t[2][0]-t[0][0],i=t[1][1]-t[0][1],a=t[2][1]-t[0][1],o=n*a-r*i;if(0===o)return null;var s=(a*(e[0]-t[0][0])-r*(e[1]-t[0][1]))/o,u=(n*(e[1]-t[0][1])-i*(e[0]-t[0][0]))/o;return s<0||u<0||s+u>1?null:[s,u]}};t.exports=a},function(t,e,n){"use strict";function r(t,e,n,r){if(t[3]>0){var i=Math.pow(2,t[3]-128-8+r);e[n+0]=t[0]*i,e[n+1]=t[1]*i,e[n+2]=t[2]*i}else e[n+0]=0,e[n+1]=0,e[n+2]=0;return e[n+3]=1,e}function i(t,e,n){for(var r="",i=e;i0;)if(t[o][0]=e[n++],t[o][1]=e[n++],t[o][2]=e[n++],t[o][3]=e[n++],1===t[o][0]&&1===t[o][1]&&1===t[o][2]){for(var u=t[o][3]<>>0;u>0;u--)a(t[o-1],t[o]),o++,s--;i+=8}else o++,s--,i=0;return n}function s(t,e,n,r){if(rf)return o(t,e,n,r);var i=e[n++];if(2!=i)return o(t,e,n-1,r);if(t[0][1]=e[n++],t[0][2]=e[n++],i=e[n++],(t[0][2]<<8>>>0|i)>>>0!==r)return null;for(var i=0;i<4;i++)for(var a=0;a128){s=(127&s)>>>0;for(var u=e[n++];s--;)t[a++][i]=u}else for(;s--;)t[a++][i]=e[n++]}return n}var u=n(7),l=n(8),c=String.fromCharCode,h=8,f=32767,d={parseRGBE:function(t,e,n){null==n&&(n=0);var a=new Uint8Array(t),o=a.length;if("#?"===i(a,0,2)){for(var h=2;h=o)){h+=2;for(var f="";h=0&&this._clips.splice(e,1)},removeAnimator:function(t){for(var e=t.getClips(),n=0;nt)this.inputs.unshift(r);else if(this.inputs[i-1].position<=t)this.inputs.push(r);else{var a=this._findKey(t);this.inputs.splice(a,r)}return r},a.prototype.step=function(t){var e=r.prototype.step.call(this,t);return"finish"!==e&&this.setTime(this._elapsedTime),e},a.prototype.setTime=function(t){var e=this.position,n=this.inputs,i=n.length,a=n[0].position,o=n[i-1].position;if(e<=a||e>=o){var s=e<=a?n[0]:n[i-1],u=s.clip,l=s.offset;u.setTime((t+l)%u.life),u.output instanceof r?this.output.copy(u.output):this.output.copy(u)}else{var c=this._findKey(e),h=n[c],f=n[c+1],d=h.clip,_=f.clip;d.setTime((t+h.offset)%d.life),_.setTime((t+f.offset)%_.life);var p=(this.position-h.position)/(f.position-h.position),m=d.output instanceof r?d.output:d,v=_.output instanceof r?_.output:_;this.output.blend1D(m,v,p)}},a.prototype.clone=function(t){var e=r.prototype.clone.call(this);e.output=this.output.clone();for(var n=0;n=n[i].position&&t=0;i--)t>=n[i].position&&t=0&&(this._cacheKey=e,this._cachePosition=t),e},t.exports=a},function(t,e,n){"use strict";var r=n(20),i=n(83),a=n(27),o=function(t){t=t||{},r.call(this,t),this.output=t.output||null,this.inputs=t.inputs||[],this.position=new a,this._cacheTriangle=null,this._triangles=[],this._updateTriangles()};o.prototype=new r,o.prototype.constructor=o,o.prototype.addInput=function(t,e,n){var r={position:t,clip:e,offset:n||0};return this.inputs.push(r),this.life=Math.max(e.life,this.life),this._updateTriangles(),r},o.prototype._updateTriangles=function(){var t=this.inputs.map(function(t){return t.position});this._triangles=i.triangulate(t,"_array")},o.prototype.step=function(t){var e=r.prototype.step.call(this,t);return"finish"!==e&&this.setTime(this._elapsedTime),e},o.prototype.setTime=function(t){var e=this._findTriangle(this.position);if(e){var n=e[1],i=e[2],a=e[0],o=this.inputs[a.indices[0]],s=this.inputs[a.indices[1]],u=this.inputs[a.indices[2]],l=o.clip,c=s.clip,h=u.clip;l.setTime((t+o.offset)%l.life),c.setTime((t+s.offset)%c.life),h.setTime((t+u.offset)%h.life);var f=l.output instanceof r?l.output:l,d=c.output instanceof r?c.output:c,_=h.output instanceof r?h.output:h;this.output.blend2D(f,d,_,n,i)}},o.prototype.clone=function(t){var e=r.prototype.clone.call(this);e.output=this.output.clone();for(var n=0;n0,l=e.color;e.depth=0,u&&p.set(l,0,0,0,0);for(var c=!0,h=1/r,f=0;f-g&&_-g&&m-g&&v0){var v=d[0],w=(v[0]+1)*u,M=(-v[1]+1)*c;e.fillStyle=m,"rectangle"===A?e.fillRect(w-N,M-N,S,S):"circle"===A&&(e.beginPath(),e.arc(w,M,N,0,2*Math.PI),e.fill())}}}e.restore()},dispose:function(){this._triangles.clear(),this._lines.clear(),this._points.clear(),this._primitives=[],this.ctx=null,this.canvas=null}});t.exports=T},function(t,e,n){"use strict";var r=n(2),i=r.extend({cancelBubble:!1},{stopPropagation:function(){this.cancelBubble=!0}});i["throw"]=function(t,e,n){var r=new i(n);for(r.type=t,r.target=e;e&&!r.cancelBubble;)r.currentTarget=e,e.trigger(t,r),e=e.getParent()},t.exports=i},function(t,e,n){"use strict";var r=n(39),i=function(t){this._list=new r,this._map={},this._maxSize=t||10};i.prototype.setMaxSize=function(t){this._maxSize=t},i.prototype.put=function(t,e){if("undefined"==typeof this._map[t]){var n=this._list.length();if(n>=this._maxSize&&n>0){var r=this._list.head;this._list.remove(r),delete this._map[r.key]}var i=this._list.insert(e);i.key=t,this._map[t]=i}},i.prototype.get=function(t){var e=this._map[t];if("undefined"!=typeof e)return e!==this._list.tail&&(this._list.remove(e),this._list.insertEntry(e)),e.value},i.prototype.remove=function(t){var e=this._map[t];"undefined"!=typeof e&&(delete this._map[t],this._list.remove(e))},i.prototype.clear=function(){this._list.clear(),this._map={}},t.exports=i},function(t,e,n){"use strict";var r=n(2),i=n(4),a=n(6),o=n(14),s=n(21),u=n(8),l=n(7),c=n(15),h=n(43),f=n(41),d=n(70),_=n(10),p=n(3),m=n(68);i["import"](n(80)),i["import"](n(139)),i["import"](n(142)),i["import"](n(137)),i["import"](n(133)),i["import"](n(135)),i["import"](n(134)),i["import"](n(140)),i["import"](n(141)),i["import"](n(143)),i["import"](n(53));var v={},g=r.extend(function(){var t=i.source("qtek.compositor.vertex"),e=i.source("qtek.deferred.light_volume.vertex"),n=new i({vertex:t,fragment:i.source("qtek.deferred.directional_light")}),r=n.clone();r.define("fragment","SHADOWMAP_ENABLED");var c=function(t){t.blendEquation(t.FUNC_ADD),t.blendFunc(t.ONE,t.ONE)},v=function(t){return new a({shader:t,blend:c,transparent:!0,depthMask:!1})},g=function(t,n){var r=new i({vertex:e,fragment:i.source("qtek.deferred."+t)});return n&&r.define("fragment","SHADOWMAP_ENABLED"),r},y=new f({capSegments:10}),x=new _;x.rotateX(Math.PI/2).translate(new p(0,(-1),0)),y.applyTransform(x);var T=new d({capSegments:10});return x.identity().rotateZ(Math.PI/2),T.applyTransform(x),{shadowMapPass:null,autoResize:!0,_createLightPassMat:v,_gBuffer:new m,_lightAccumFrameBuffer:new o({depthBuffer:!1}),_lightAccumTex:new u({type:l.HALF_FLOAT,minFilter:l.NEAREST,magFilter:l.NEAREST}),_fullQuadPass:new s({blendWithPrevious:!0}),_directionalLightMat:v(n),_directionalLightMatWithShadow:v(r),_ambientMat:v(new i({vertex:t,fragment:i.source("qtek.deferred.ambient_light")})),_ambientSHMat:v(new i({vertex:t,fragment:i.source("qtek.deferred.ambient_sh_light")})),_ambientCubemapMat:v(new i({vertex:t,fragment:i.source("qtek.deferred.ambient_cubemap_light")})),_spotLightShader:g("spot_light"),_pointLightShader:g("point_light"),_spotLightShaderWithShadow:g("spot_light",!0),_pointLightShaderWithShadow:g("point_light",!0),_sphereLightShader:g("sphere_light"),_tubeLightShader:g("tube_light"),_lightSphereGeo:new h({widthSegments:10,heightSegements:10}),_lightConeGeo:y,_lightCylinderGeo:T,_outputPass:new s({fragment:i.source("qtek.compositor.output")})}},{render:function(t,e,n,r){r=r||{},r.renderToTarget=r.renderToTarget||!1,r.notUpdateShadow=r.notUpdateShadow||!1,r.notUpdateScene=r.notUpdateScene||!1,r.notUpdateScene||e.update(!1,!0),n.update(!0);var i=t.getDevicePixelRatio();!this.autoResize||t.getWidth()*i===this._lightAccumTex.width&&t.getHeight()*i===this._lightAccumTex.height||this.resize(t.getWidth()*i,t.getHeight()*i),this._gBuffer.update(t,e,n),this._accumulateLightBuffer(t,e,n,!r.notUpdateShadow),r.renderToTarget||(this._outputPass.setUniform("texture",this._lightAccumTex),this._outputPass.render(t))},getTargetTexture:function(){return this._lightAccumTex},getTargetFrameBuffer:function(){return this._lightAccumFrameBuffer},getGBuffer:function(){return this._gBuffer},setViewport:function(t,e,n,r,i){this._gBuffer.setViewport(t,e,n,r,i),this._lightAccumFrameBuffer.viewport=this._gBuffer.getViewport()},resize:function(t,e){this._lightAccumTex.width=t,this._lightAccumTex.height=e,this._gBuffer.resize(t,e)},_accumulateLightBuffer:function(t,e,n,r){for(var i=t.gl,a=this._lightAccumTex,o=this._lightAccumFrameBuffer,s=n.getWorldPosition()._array,u=0;u1?k.name=[s.name,l].join("-"):k.name=s.name),e.meshes[a].push(k)}}},_parseNodes:function(t,e){for(var n in t.nodes){var r,i=t.nodes[n];if(i.camera&&this.includeCamera){var a=t.cameras[i.camera];"perspective"===a.projection?r=new m({name:i.name,aspect:a.aspect_ratio,fov:a.xfov,far:a.zfar,near:a.znear}):(r=new v,console.warn("TODO:Orthographic camera")),r.setName(i.name),e.cameras[i.name]=r}else if(i.lights&&this.includeLight){for(var o=[],s=0;s0&&o.scaleAndAdd(t._array,t._array,this.force._array,r/n)}});t.exports=s},function(t,e,n){"use strict";var r=n(29),i=n(12),a=n(6),o=n(4);o["import"](n(107));var s=new o({vertex:o.source("qtek.particle.vertex"),fragment:o.source("qtek.particle.fragment")});s.enableTexture("sprite");var u=r.extend({loop:!0,oneshot:!1,duration:1,spriteAnimationTileX:1,spriteAnimationTileY:1,spriteAnimationRepeat:0,mode:r.POINTS,ignorePicking:!0,_elapsedTime:0,_emitting:!0},function(){this.geometry=new i({dynamic:!0}),this.material||(this.material=new a({shader:s,transparent:!0,depthMask:!1})),this._particles=[],this._fields=[],this._emitters=[]},{culling:!1,frustumCulling:!1,castShadow:!1,receiveShadow:!1,addEmitter:function(t){this._emitters.push(t)},removeEmitter:function(t){this._emitters.splice(this._emitters.indexOf(t),1)},addField:function(t){this._fields.push(t)},removeField:function(t){this._fields.splice(this._fields.indexOf(t),1)},reset:function(){for(var t=0;t=i.life?(i.emitter.kill(i),e[n]=e[r-1],e.pop(),r--):n++}for(var n=0;n0)for(var a=0;a1,o=t.attributes.position.value,s=t.attributes.normal.value,u=t.attributes.texcoord0.value,l=t.attributes.texcoord1.value,c=this._particles.length;o&&o.length===3*c||(o=t.attributes.position.value=new Float32Array(3*c),s=t.attributes.normal.value=new Float32Array(3*c),a&&(u=t.attributes.texcoord0.value=new Float32Array(2*c),l=t.attributes.texcoord1.value=new Float32Array(2*c)));for(var h=1/e,f=0;fthis.duration&&!this.loop},dispose:function(t){for(var e=0;e>16,n=t-(e<<8)>>8,r=t-(e<<16)-(n<<8);return[e,n,r]}function i(t,e,n){return(t<<16)+(e<<8)+n}var a=n(2),o=n(14),s=n(8),u=n(4),l=n(6);u["import"](n(110));var c=a.extend(function(){return{renderer:null,downSampleRatio:1,width:100,height:100,lookupOffset:1,_frameBuffer:null,_texture:null,_shader:null,_idMaterials:[],_lookupTable:[],_meshMaterials:[],_idOffset:0}},function(){this.renderer&&(this.width=this.renderer.getWidth(),this.height=this.renderer.getHeight()),this._init()},{_init:function(){this._texture=new s({width:this.width*this.downSampleRatio,height:this.height*this.downSampleRatio}),this._frameBuffer=new o,this._shader=new u({vertex:u.source("qtek.picking.color.vertex"),fragment:u.source("qtek.picking.color.fragment")})},setPrecision:function(t){this._texture.width=this.width*t,this._texture.height=this.height*t,this.downSampleRatio=t},resize:function(t,e){this._texture.width=t*this.downSampleRatio,this._texture.height=e*this.downSampleRatio,this.width=t,this.height=e,this._texture.dirty()},update:function(t,e){var n=this.renderer;n.getWidth()===this.width&&n.getHeight()===this.height||this.resize(n.width,n.height),this._frameBuffer.attach(this._texture),this._frameBuffer.bind(n),this._idOffset=this.lookupOffset,this._setMaterial(t),n.render(t,e),this._restoreMaterial(),this._frameBuffer.unbind(n)},_setMaterial:function(t){for(var e=0;e0&&a<=this.minPolarAngle?e.rotateAround(this.origin,i,-a+this.minPolarAngle):this._offsetRoll<0&&a>=this.maxPolarAngle&&e.rotateAround(this.origin,i,-a+this.maxPolarAngle),this._offsetRoll=this._offsetPitch=0}if(0!==this._forward){var o=e.position.distance(this.origin),s=o+this._forward*o/5e3;sthis.minDistance&&e.position.scaleAndAdd(n,this._forward*o/5e3),this._forward=0}}}));t.exports=s},function(t,e,n){var r=n(2),i=(n(72),r.extend(function(){console.warn("TODO")},{render:function(t,e,n){}}));t.exports=i},function(t,e,n){var r=n(2),i=n(5),a=n(3),o=n(9),s=n(47),u=n(10),l=n(35),c=n(4),h=(n(11),n(15),n(46)),f=n(44),d=n(45),_=(n(28),n(6)),p=n(14),m=n(7),v=n(8),g=n(18),y=n(22),x=n(30),T=n(21),E=n(38),b=n(1),S=b.mat4,A=(b.vec3,["px","nx","py","ny","pz","nz"]);c["import"](n(146));var N=r.extend(function(){return{softShadow:N.PCF,shadowBlur:1,lightFrustumBias:2,kernelPCF:new Float32Array([1,0,1,1,-1,1,0,1,-1,0,-1,-1,1,-1,0,-1]),_frameBuffer:new p,_textures:{},_shadowMapNumber:{POINT_LIGHT:0,DIRECTIONAL_LIGHT:0,SPOT_LIGHT:0},_meshMaterials:{},_depthMaterials:{},_depthShaders:{},_distanceMaterials:{},_opaqueCasters:[],_receivers:[],_lightsCastShadow:[],_lightCameras:{},_texturePool:new E}},function(){this._gaussianPassH=new T({fragment:c.source("qtek.compositor.gaussian_blur")}),this._gaussianPassV=new T({fragment:c.source("qtek.compositor.gaussian_blur")}),this._gaussianPassH.setUniform("blurSize",this.shadowBlur),this._gaussianPassH.setUniform("blurDir",0),this._gaussianPassV.setUniform("blurSize",this.shadowBlur),this._gaussianPassV.setUniform("blurDir",1),this._outputDepthPass=new T({fragment:c.source("qtek.sm.debug_depth")})},{render:function(t,e,n,r){this.trigger("beforerender",this,t,e,n),this._renderShadowPass(t,e,n,r),this.trigger("afterrender",this,t,e,n)},renderDebug:function(t,e){t.saveClear();var n=t.viewport,r=0,i=0,a=e||n.width/4,o=a;this.softShadow===N.VSM?this._outputDepthPass.material.shader.define("fragment","USE_VSM"):this._outputDepthPass.material.shader.undefine("fragment","USE_VSM");for(var s in this._textures){var u=this._textures[s];t.setViewport(r,i,a*u.width/u.height,o),this._outputDepthPass.setUniform("depthMap",u),this._outputDepthPass.render(t),r+=a*u.width/u.height}t.setViewport(n),t.restoreClear()},_bindDepthMaterial:function(t,e,n){for(var r=0;r0&&(f.define("vertex","SKINNING"),f.define("vertex","JOINT_COUNT",l)),s&&f.define("both","SHADOW_TRANSPARENT"),this._depthShaders[a]=f),h||(h=new _({shader:f}),this._depthMaterials[i]=h),o.material=h,this.softShadow===N.VSM?f.define("fragment","USE_VSM"):f.undefine("fragment","USE_VSM"),h.setUniform("bias",e),h.setUniform("slopeScale",n),s&&h.set("shadowTransparentMap",u))}},_bindDistanceMaterial:function(t,e){for(var n=e.getWorldPosition()._array,r=0;r0&&(o.shader.define("vertex","SKINNING"),o.shader.define("vertex","JOINT_COUNT",a)),this._distanceMaterials[a]=o),i.material=o,this.softShadow===N.VSM?o.shader.define("fragment","USE_VSM"):o.shader.undefine("fragment","USE_VSM")),o.set("lightPosition",n),o.set("range",e.range)}},saveMaterial:function(t){for(var e=0;e1&&(m=g,g.shadowCascade>4)){console.warn("Support at most 4 cascade");continue}this.renderDirectionalLightShadow(t,e,n,g,this._opaqueCasters,_,c,l)}else g instanceof h?this.renderSpotLightShadow(t,g,this._opaqueCasters,u,s):g instanceof d&&this.renderPointLightShadow(t,g,this._opaqueCasters,p);this._shadowMapNumber[g.type]++}this.restoreMaterial(this._opaqueCasters);var y=_.slice(),x=_.slice();y.pop(),x.shift(),y.reverse(),x.reverse(),c.reverse();for(var T=s.map(i),E=l.map(i),b={},v=0;v0&&(N.fragmentDefines[R]=C,w=!0)}w&&N.dirty(),m?N.define("fragment","SHADOW_CASCADE",m.shadowCascade):N.undefine("fragment","SHADOW_CASCADE"),b[N.__GUID__]=!0}s.length>0&&(A.setUniform("spotLightShadowMaps",s),A.setUniform("spotLightMatrices",u),A.setUniform("spotLightShadowMapSizes",T)),l.length>0&&(A.setUniform("directionalLightShadowMaps",l),m&&(A.setUniform("shadowCascadeClipsNear",y),A.setUniform("shadowCascadeClipsFar",x)),A.setUniform("directionalLightMatrices",c),A.setUniform("directionalLightShadowMapSizes",E)),p.length>0&&A.setUniform("pointLightShadowMaps",p)}}},renderDirectionalLightShadow:function(){var t=new s,e=new u,n=new o,r=new u,i=new u,a=new u,c=new u;return function(o,s,h,f,d,_,p,m){var v=f.shadowBias;this._bindDepthMaterial(d,v,f.shadowSlopeScale),d.sort(l.opaqueSortFunc);var g=Math.min(-s.viewBoundingBoxLastFrame.min.z,h.far),y=Math.max(-s.viewBoundingBoxLastFrame.max.z,h.near),x=this._getDirectionalLightCamera(f,s,h),T=a._array;c.copy(x.projectionMatrix),S.invert(i._array,x.worldTransform._array),S.multiply(i._array,i._array,h.worldTransform._array),S.multiply(T,c._array,i._array);for(var E=[],b=h.fov/180*Math.PI,A=h.aspect,w=(h.near+h.far)/(h.near-h.far),M=2*h.near*h.far/(h.near-h.far),C=0;C<=f.shadowCascade;C++){var R=y*Math.pow(g/y,C/f.shadowCascade),L=y+(g-y)*C/f.shadowCascade,I=R*f.cascadeSplitLogFactor+L*(1-f.cascadeSplitLogFactor);E.push(I),_.push(-(-I*w+M)/-I)}var P=this._getTexture(f,f.shadowCascade);m.push(P);var D=o.viewport,O=o.gl;this._frameBuffer.attach(P),this._frameBuffer.bind(o),O.clear(O.COLOR_BUFFER_BIT|O.DEPTH_BUFFER_BIT);for(var C=0;Ct[1][0]&&(t[1][0]=h),f>t[1][1]&&(t[1][1]=f),t[0][0]-=.1,t[0][1]-=.1,t[1][0]+=.1,t[1][1]+=.1;var p=i(s,c,h,f,d,_);this._pointTypes[r]=p<=0?u:l,p<=0&&this._candidates.push(r),a=r,r++}this._gridWidth=(t[1][0]-t[0][0])/this._gridNumber,this._gridHeight=(t[1][1]-t[0][1])/this._gridNumber;for(var r=0;rn&&(n=s),u>r&&(r=u),ln&&(n=l),c>r&&(r=c),i[0][0]=Math.floor((t-h[0][0])/this._gridWidth),i[1][0]=Math.floor((n-h[0][0])/this._gridWidth),i[0][1]=Math.floor((e-h[0][1])/this._gridHeight),i[1][1]=Math.floor((r-h[0][1])/this._gridHeight),i}}(),c.prototype.isTriangleConvex2=function(t,e,n){return this.triangleArea(t,e,n)<0},c.prototype.triangleArea=function(t,e,n){var r=this._points,i=r[2*t],a=r[2*t+1],o=r[2*e],s=r[2*e+1],u=r[2*n],l=r[2*n+1];return(o-i)*(l-s)-(s-a)*(u-o)};var h={flatPoints:function(t){for(var e=new s.Float64Array(2*t.length),n=0;n=65535?u.indices=new Uint32Array(3*v):u.indices=new Uint16Array(3*v);for(var E=0,b=0,S=a.isUseIndices(),A=0;A0;){for(var E=[],b=[],S=[],A=0,g=0;g=0&&b[L]===-1&&(A65535?H.indices=new Uint32Array(3*F.triangles.length):H.indices=new Uint16Array(3*F.triangles.length);var Y=0;W=0;for(var g=0;g=0?H.attributes.joint.value[J]=k[L]:H.attributes.joint.value[J]=-1}W++}H.indices[Y++]=D[C]}H.updateBoundingBox(),I.add(G)}for(var $=t.children(),g=0;g<$.length;g++)I.add($[g]);if(I.position.copy(t.position),I.rotation.copy(t.rotation),I.scale.copy(t.scale),n&&t.getParent()){var tt=t.getParent();tt.remove(t),tt.add(I)}return I}}};t.exports=h},function(t,e,n){function r(t,e){var n=t[0],r=t[1],i=t[2];return 0===e?1:1===e?n:2===e?r:3===e?i:4===e?n*i:5===e?r*i:6===e?n*r:7===e?3*i*i-1:n*n-r*r}function i(t,e,n,i){for(var a=new u.Float32Array(27),o=_.create(),s=_.create(),l=_.create(),c=0;c<9;c++){for(var h=_.create(),f=0;f 0.0) {\n float G = G_Smith(roughness, NoV, NoL);\n float G_Vis = G * VoH / (NoH * NoV);\n float Fc = pow(1.0 - VoH, 5.0);\n A += (1.0 - Fc) * G_Vis;\n B += Fc * G_Vis;\n }\n }\n\n gl_FragColor = vec4(vec2(A, B) / fSampleNumber, 0.0, 1.0);\n}\n"},function(t,e){t.exports="#define SAMPLE_NUMBER 1024\n#define PI 3.14159265358979\n\nuniform mat4 viewInverse : VIEWINVERSE;\nuniform samplerCube environmentMap;\nuniform sampler2D normalDistribution;\n\nuniform float roughness : 0.5;\n\nvarying vec2 v_Texcoord;\nvarying vec3 v_WorldPosition;\n\nconst float fSampleNumber = float(SAMPLE_NUMBER);\n\n@import qtek.util.rgbm\n\nvec3 importanceSampleNormal(float i, float roughness, vec3 N) {\n vec3 H = texture2D(normalDistribution, vec2(roughness, i)).rgb;\n\n vec3 upVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);\n vec3 tangentX = normalize(cross(upVector, N));\n vec3 tangentY = cross(N, tangentX);\n return tangentX * H.x + tangentY * H.y + N * H.z;\n}\n\nvoid main() {\n\n vec3 eyePos = viewInverse[3].xyz;\n vec3 V = normalize(v_WorldPosition - eyePos);\n\n vec3 N = V;\n vec3 R = V;\n\n vec3 prefilteredColor = vec3(0.0);\n float totalWeight = 0.0;\n\n\n for (int i = 0; i < SAMPLE_NUMBER; i++) {\n vec3 H = importanceSampleNormal(float(i) / fSampleNumber, roughness, N);\n vec3 L = reflect(-V, H);\n\n float NoL = clamp(dot(N, L), 0.0, 1.0);\n if (NoL > 0.0) {\n prefilteredColor += decodeHDR(textureCube(environmentMap, L)).rgb * NoL;\n totalWeight += NoL;\n }\n }\n\n gl_FragColor = encodeHDR(vec4(prefilteredColor / totalWeight, 1.0));\n}\n"},function(t,e){t.exports="uniform samplerCube environmentMap;\n\nvarying vec2 v_Texcoord;\n\n#define TEXTURE_SIZE 16\n\nmat3 front = mat3(\n 1.0, 0.0, 0.0,\n 0.0, 1.0, 0.0,\n 0.0, 0.0, 1.0\n);\n\nmat3 back = mat3(\n -1.0, 0.0, 0.0,\n 0.0, 1.0, 0.0,\n 0.0, 0.0, -1.0\n);\n\nmat3 left = mat3(\n 0.0, 0.0, -1.0,\n 0.0, 1.0, 0.0,\n 1.0, 0.0, 0.0\n);\n\nmat3 right = mat3(\n 0.0, 0.0, 1.0,\n 0.0, 1.0, 0.0,\n -1.0, 0.0, 0.0\n);\n\nmat3 up = mat3(\n 1.0, 0.0, 0.0,\n 0.0, 0.0, 1.0,\n 0.0, -1.0, 0.0\n);\n\nmat3 down = mat3(\n 1.0, 0.0, 0.0,\n 0.0, 0.0, -1.0,\n 0.0, 1.0, 0.0\n);\n\n\nfloat harmonics(vec3 normal){\n int index = int(gl_FragCoord.x);\n\n float x = normal.x;\n float y = normal.y;\n float z = normal.z;\n\n if(index==0){\n return 1.0;\n }\n else if(index==1){\n return x;\n }\n else if(index==2){\n return y;\n }\n else if(index==3){\n return z;\n }\n else if(index==4){\n return x*z;\n }\n else if(index==5){\n return y*z;\n }\n else if(index==6){\n return x*y;\n }\n else if(index==7){\n return 3.0*z*z - 1.0;\n }\n else{\n return x*x - y*y;\n }\n}\n\nvec3 sampleSide(mat3 rot)\n{\n\n vec3 result = vec3(0.0);\n float divider = 0.0;\n for (int i = 0; i < TEXTURE_SIZE * TEXTURE_SIZE; i++) {\n float x = mod(float(i), float(TEXTURE_SIZE));\n float y = float(i / TEXTURE_SIZE);\n\n vec2 sidecoord = ((vec2(x, y) + vec2(0.5, 0.5)) / vec2(TEXTURE_SIZE)) * 2.0 - 1.0;\n vec3 normal = normalize(vec3(sidecoord, -1.0));\n vec3 fetchNormal = rot * normal;\n vec3 texel = textureCube(environmentMap, fetchNormal).rgb;\n\n result += harmonics(fetchNormal) * texel * -normal.z;\n\n divider += -normal.z;\n }\n\n return result / divider;\n}\n\nvoid main()\n{\n vec3 result = (\n sampleSide(front) +\n sampleSide(back) +\n sampleSide(left) +\n sampleSide(right) +\n sampleSide(up) +\n sampleSide(down)\n ) / 6.0;\n gl_FragColor = vec4(result, 1.0);\n}"},function(t,e){t.exports="0.3.7"},function(t,e,n){function r(t,e,n){return t*(1-n)+e*n}var i=n(15),a=n(6),o=n(12),s=n(4),u=n(2),l=n(22);s["import"](n(157));var c=u.extend(function(){return{clearColor:[0,0,0,1],_mesh:new i({geometry:new o,culling:!1,material:new a({depthTest:!1,shader:new s({vertex:s.source("qtek.vr.disorter.output.vertex"),fragment:s.source("qtek.vr.disorter.output.fragment")})})}),_fakeCamera:new l}},{render:function(t,e){var n=this.clearColor,r=t.gl;r.clearColor(n[0],n[1],n[2],n[3]),r.clear(r.COLOR_BUFFER_BIT),r.disable(r.BLEND),this._mesh.material.set("texture",e),t.saveViewport(),t.setViewport(0,0,t.getWidth(),t.getHeight()),t.renderQueue([this._mesh],this._fakeCamera),t.restoreViewport()},updateFromVRDisplay:function(t){t.deviceInfo_?this._updateMesh(20,20,t.deviceInfo_):console.warn("Cant get vrDisplay.deviceInfo_, seems code changed")},_updateMesh:function(t,e,n){var i=this._mesh.geometry.attributes.position,a=this._mesh.geometry.attributes.texcoord0;i.init(2*t*e),a.init(2*t*e);for(var o=n.getLeftEyeVisibleTanAngles(),s=n.getLeftEyeNoLensTanAngles(),u=n.getLeftEyeVisibleScreenRect(s),l=0,c=[],h=[],f=0;f<2;f++){for(var d=0;d