text: "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),t=require("@babel/runtime/helpers/createClass"),i=require("@babel/runtime/helpers/assertThisInitialized"),u=require("@babel/runtime/helpers/inheritsLoose"),n=require("@babel/runtime/helpers/defineProperty");function _(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=_(t),a=_(i),m=_(u),o=_(n),p=function(e){function t(t){var i;return void 0===t&&(t={}),i=e.call(this,t)||this,o.default(a.default(i),"_debug",{value:0}),o.default(a.default(i),"_tDepth",{value:null}),o.default(a.default(i),"_distortionMap",{value:null}),o.default(a.default(i),"_tDiffuse",{value:null}),o.default(a.default(i),"_u_mipmap_0",{value:null}),o.default(a.default(i),"_u_mipmap_1",{value:null}),o.default(a.default(i),"_u_mipmap_2",{value:null}),o.default(a.default(i),"_u_mipmap_3",{value:null}),o.default(a.default(i),"_u_mipmap_4",{value:null}),o.default(a.default(i),"_u_mipmap_5",{value:null}),o.default(a.default(i),"_u_mipmap_6",{value:null}),o.default(a.default(i),"_u_mipmap_7",{value:null}),o.default(a.default(i),"_u_mipmap_res_0",{value:null}),o.default(a.default(i),"_u_mipmap_res_1",{value:null}),o.default(a.default(i),"_u_mipmap_res_2",{value:null}),o.default(a.default(i),"_u_mipmap_res_3",{value:null}),o.default(a.default(i),"_u_mipmap_res_4",{value:null}),o.default(a.default(i),"_u_mipmap_res_5",{value:null}),o.default(a.default(i),"_u_mipmap_res_6",{value:null}),o.default(a.default(i),"_u_mipmap_res_7",{value:null}),o.default(a.default(i),"_textureMatrix",{value:null}),o.default(a.default(i),"_mirror",{value:0}),o.default(a.default(i),"_mixBlur",{value:0}),o.default(a.default(i),"_blurStrength",{value:.5}),o.default(a.default(i),"_minDepthThreshold",{value:.9}),o.default(a.default(i),"_maxDepthThreshold",{value:1}),o.default(a.default(i),"_depthScale",{value:0}),o.default(a.default(i),"_depthToBlurRatioBias",{value:.25}),o.default(a.default(i),"_distortion",{value:1}),i.setValues(t),i}return m.default(t,e),t.prototype.onBeforeCompile=function(e){var t;(null==(t=e.defines)?void 0:t.USE_UV)||(e.defines.USE_UV=""),e.uniforms.debug=this._debug,e.uniforms.tDiffuse=this._tDiffuse,e.uniforms.tDepth=this._tDepth,e.uniforms.distortionMap=this._distortionMap,e.uniforms.u_mipmap_0=this._u_mipmap_0,e.uniforms.u_mipmap_1=this._u_mipmap_1,e.uniforms.u_mipmap_2=this._u_mipmap_2,e.uniforms.u_mipmap_3=this._u_mipmap_3,e.uniforms.u_mipmap_4=this._u_mipmap_4,e.uniforms.u_mipmap_5=this._u_mipmap_5,e.uniforms.u_mipmap_6=this._u_mipmap_6,e.uniforms.u_mipmap_7=this._u_mipmap_7,e.uniforms.u_mipmap_res_0=this._u_mipmap_res_0,e.uniforms.u_mipmap_res_1=this._u_mipmap_res_1,e.uniforms.u_mipmap_res_2=this._u_mipmap_res_2,e.uniforms.u_mipmap_res_3=this._u_mipmap_res_3,e.uniforms.u_mipmap_res_4=this._u_mipmap_res_4,e.uniforms.u_mipmap_res_5=this._u_mipmap_res_5,e.uniforms.u_mipmap_res_6=this._u_mipmap_res_6,e.uniforms.u_mipmap_res_7=this._u_mipmap_res_7,e.uniforms.textureMatrix=this._textureMatrix,e.uniforms.mirror=this._mirror,e.uniforms.mixBlur=this._mixBlur,e.uniforms.mixStrength=this._blurStrength,e.uniforms.minDepthThreshold=this._minDepthThreshold,e.uniforms.maxDepthThreshold=this._maxDepthThreshold,e.uniforms.depthScale=this._depthScale,e.uniforms.depthToBlurRatioBias=this._depthToBlurRatioBias,e.uniforms.distortion=this._distortion,e.vertexShader="\n        uniform mat4 textureMatrix;\n        varying vec4 my_vUv;     \n      "+e.vertexShader,e.vertexShader=e.vertexShader.replace("#include <project_vertex>","#include <project_vertex>\n        my_vUv = textureMatrix * vec4( position, 1.0 );\n        gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );"),e.fragmentShader="\n        uniform int debug;\n        uniform sampler2D tDiffuse;\n        uniform sampler2D tDepth;\n        uniform sampler2D distortionMap;\n        uniform sampler2D u_mipmap_0;\n        uniform sampler2D u_mipmap_1;\n        uniform sampler2D u_mipmap_2;\n        uniform sampler2D u_mipmap_3;\n        uniform sampler2D u_mipmap_4;\n        uniform sampler2D u_mipmap_5;\n        uniform sampler2D u_mipmap_6;\n        uniform sampler2D u_mipmap_7;\n        uniform vec2 u_mipmap_res_0;\n        uniform vec2 u_mipmap_res_1;\n        uniform vec2 u_mipmap_res_2;\n        uniform vec2 u_mipmap_res_3;\n        uniform vec2 u_mipmap_res_4;\n        uniform vec2 u_mipmap_res_5;\n        uniform vec2 u_mipmap_res_6;\n        uniform vec2 u_mipmap_res_7;\n        uniform float distortion;\n        uniform float cameraNear;\n\t\t\t  uniform float cameraFar;\n        uniform float mixBlur;\n        uniform float mirror;\n        uniform float mixStrength;\n        uniform float minDepthThreshold;\n        uniform float maxDepthThreshold;\n        uniform float depthScale;\n        uniform float depthToBlurRatioBias;\n        varying vec4 my_vUv;  \n        \n        // from http://www.java-gaming.org/index.php?topic=35123.0\n        vec4 cubic( float v ) {\n          vec4 n = vec4( 1.0, 2.0, 3.0, 4.0 ) - v;\n          vec4 s = n * n * n;\n          float x = s.x;\n          float y = s.y - 4.0 * s.x;\n          float z = s.z - 4.0 * s.y + 6.0 * s.x;\n          float w = 6.0 - x - y - z;\n          return vec4( x, y, z, w ) * ( 1.0 / 6.0 );\n        }\n        \n        vec4 textureBicubic( sampler2D sampler, vec2 texCoords, vec2 texSize ) {\n          vec2 invTexSize = 1.0 / texSize;\n          texCoords = texCoords * texSize - 0.5;\n          vec2 fxy = fract( texCoords );\n          texCoords -= fxy;\n\n          vec4 xcubic = cubic( fxy.x );\n          vec4 ycubic = cubic( fxy.y );\n          vec4 c = texCoords.xxyy + vec2 ( - 0.5, + 1.5 ).xyxy;\n          vec4 s = vec4( xcubic.xz + xcubic.yw, ycubic.xz + ycubic.yw );\n\n          vec4 offset = c + vec4( xcubic.yw, ycubic.yw ) / s;\n          offset *= invTexSize.xxyy;\n        \n          vec4 sample0 = texture2D( sampler, offset.xz);\n          vec4 sample1 = texture2D( sampler, offset.yz);\n          vec4 sample2 = texture2D( sampler, offset.xw);\n          vec4 sample3 = texture2D( sampler, offset.yw);\n        \n          float sx = s.x / ( s.x + s.y );\n          float sy = s.z / ( s.z + s.w );\n\n          return mix(\n            mix(\n              sample3,\n              sample2,\n              sx\n            ),\n            mix(\n              sample1,\n              sample0,\n              sx\n            ),\n            sy\n          );\n        }\n\n\n        "+e.fragmentShader,e.fragmentShader=e.fragmentShader.replace("#include <emissivemap_fragment>","#include <emissivemap_fragment>\n    \n      float depthFactor = 1.0;\n      float distortionFactor = 0.0;\n      vec3 my_normal = vec3(0.0);\n      float reflectorRoughnessFactor = roughness;\n      vec3 coord = my_vUv.xyz / my_vUv.w;\n\n      #ifdef USE_DISTORTION\n        distortionFactor = texture2D(distortionMap, vUv).r * distortion;\n      #endif\n\n      #ifdef USE_NORMALMAP\n        vec4 normalColor = texture2D(normalMap, vUv * normalScale);\n        my_normal = normalize( vec3( normalColor.r * 2.0 - 1.0, normalColor.b ,  normalColor.g * 2.0 - 1.0 ) );\n      #endif\n\n      #ifdef USE_ROUGHNESSMAP\n        vec4 reflectorTexelRoughness = texture2D( roughnessMap, vUv );\n        reflectorRoughnessFactor *= reflectorTexelRoughness.g;\n      #endif\n\n      vec2 proj_vUv = coord.xy + coord.z * my_normal.xz * 0.01;\n      proj_vUv.x += distortionFactor;\n      proj_vUv.y += distortionFactor;\n      \n      float lod = 1.0 - min(1.0, mixBlur * reflectorRoughnessFactor);\n\n      #ifdef USE_DEPTH\n        vec4 depth = texture2D(tDepth, proj_vUv);\n        depthFactor = smoothstep(minDepthThreshold, maxDepthThreshold, 1.0-(depth.r * depth.a));\n        depthFactor *= depthScale;\n        depthFactor = max(0.0001, min(1.0, depthFactor + depthToBlurRatioBias));\n      #endif\n\n      vec4 baseColor = texture2D(tDiffuse, proj_vUv);\n      vec4 mixedColor;\n\n      float _lod = (1.0 - pow(1.0 - lod, 4.0)) * 8.0;\n      if (_lod < 1.) {\n        vec4 one = textureBicubic(u_mipmap_7, proj_vUv, u_mipmap_res_7);\n        vec4 two = textureBicubic(u_mipmap_6, proj_vUv, u_mipmap_res_6);\n        mixedColor = mix(one, two, _lod);\n      } else if (_lod < 2.) {\n        vec4 one = textureBicubic(u_mipmap_6, proj_vUv, u_mipmap_res_6);\n        vec4 two = textureBicubic(u_mipmap_5, proj_vUv, u_mipmap_res_5);\n        mixedColor = mix(one, two, _lod - 1.0);\n      } else if (_lod < 3.) {\n        vec4 one = textureBicubic(u_mipmap_5, proj_vUv, u_mipmap_res_5);\n        vec4 two = textureBicubic(u_mipmap_4, proj_vUv, u_mipmap_res_4);\n        mixedColor = mix(one, two, _lod - 2.0);\n      } else if (_lod < 4.) {\n        vec4 one = textureBicubic(u_mipmap_4, proj_vUv, u_mipmap_res_4);\n        vec4 two = textureBicubic(u_mipmap_3, proj_vUv, u_mipmap_res_3);\n        mixedColor = mix(one, two, _lod - 3.0);\n      } else if (_lod < 5.) {\n        vec4 one = textureBicubic(u_mipmap_3, proj_vUv, u_mipmap_res_3);\n        vec4 two = textureBicubic(u_mipmap_2, proj_vUv, u_mipmap_res_2);\n        mixedColor = mix(one, two, _lod - 4.0);\n      } else if (_lod < 6.) {\n        vec4 one = textureBicubic(u_mipmap_2, proj_vUv, u_mipmap_res_2);\n        vec4 two = textureBicubic(u_mipmap_1, proj_vUv, u_mipmap_res_1);\n        mixedColor = mix(one, two, _lod - 5.0);\n      } else if (_lod < 7.) {\n        vec4 one = textureBicubic(u_mipmap_1, proj_vUv, u_mipmap_res_1);\n        vec4 two = textureBicubic(u_mipmap_0, proj_vUv, u_mipmap_res_0);\n        mixedColor = mix(one, two, _lod - 6.0);\n      } else {\n        vec4 one = textureBicubic(u_mipmap_0, proj_vUv, u_mipmap_res_0);\n        mixedColor = mix(one, baseColor, _lod - 7.0);\n      }\n\n      mixedColor.rgb *= depthFactor;\n      diffuseColor.rgb = diffuseColor.rgb * ((1.0 - min(1.0, mirror)) + mixedColor.rgb * mixStrength);     \n      diffuseColor = sRGBToLinear(diffuseColor);\n\n      if (debug == 1) {\n        diffuseColor = sRGBToLinear(vec4(vec3(depthFactor), 1.0));\n      }\n      if (debug == 2) {\n        diffuseColor = sRGBToLinear(texture2D(tDiffuse, proj_vUv));\n      }\n      if (debug == 3) {\n        diffuseColor = sRGBToLinear(texture2D(distortionMap, vUv));\n      }\n      if (debug == 4) {\n        diffuseColor = sRGBToLinear(vec4(vec3(lod), 1.0));\n      }\n      ")},r.default(t,[{key:"tDiffuse",get:function(){return this._tDiffuse.value},set:function(e){this._tDiffuse.value=e}},{key:"tDepth",get:function(){return this._tDepth.value},set:function(e){this._tDepth.value=e}},{key:"distortionMap",get:function(){return this._distortionMap.value},set:function(e){this._distortionMap.value=e}},{key:"u_mipmap_0",get:function(){return this._u_mipmap_0.value},set:function(e){this._u_mipmap_0.value=e}},{key:"u_mipmap_1",get:function(){return this._u_mipmap_1.value},set:function(e){this._u_mipmap_1.value=e}},{key:"u_mipmap_2",get:function(){return this._u_mipmap_2.value},set:function(e){this._u_mipmap_2.value=e}},{key:"u_mipmap_3",get:function(){return this._u_mipmap_3.value},set:function(e){this._u_mipmap_3.value=e}},{key:"u_mipmap_4",get:function(){return this._u_mipmap_4.value},set:function(e){this._u_mipmap_4.value=e}},{key:"u_mipmap_5",get:function(){return this._u_mipmap_5.value},set:function(e){this._u_mipmap_5.value=e}},{key:"u_mipmap_6",get:function(){return this._u_mipmap_6.value},set:function(e){this._u_mipmap_6.value=e}},{key:"u_mipmap_7",get:function(){return this._u_mipmap_7.value},set:function(e){this._u_mipmap_7.value=e}},{key:"u_mipmap_res_0",get:function(){return this._u_mipmap_res_0.value},set:function(e){this._u_mipmap_res_0.value=e}},{key:"u_mipmap_res_1",get:function(){return this._u_mipmap_res_1.value},set:function(e){this._u_mipmap_res_1.value=e}},{key:"u_mipmap_res_2",get:function(){return this._u_mipmap_res_2.value},set:function(e){this._u_mipmap_res_2.value=e}},{key:"u_mipmap_res_3",get:function(){return this._u_mipmap_res_3.value},set:function(e){this._u_mipmap_res_3.value=e}},{key:"u_mipmap_res_4",get:function(){return this._u_mipmap_res_4.value},set:function(e){this._u_mipmap_res_4.value=e}},{key:"u_mipmap_res_5",get:function(){return this._u_mipmap_res_5.value},set:function(e){this._u_mipmap_res_5.value=e}},{key:"u_mipmap_res_6",get:function(){return this._u_mipmap_res_6.value},set:function(e){this._u_mipmap_res_6.value=e}},{key:"u_mipmap_res_7",get:function(){return this._u_mipmap_res_7.value},set:function(e){this._u_mipmap_res_7.value=e}},{key:"textureMatrix",get:function(){return this._textureMatrix.value},set:function(e){this._textureMatrix.value=e}},{key:"mirror",get:function(){return this._mirror.value},set:function(e){this._mirror.value=e}},{key:"mixBlur",get:function(){return this._mixBlur.value},set:function(e){this._mixBlur.value=e}},{key:"mixStrength",get:function(){return this._blurStrength.value},set:function(e){this._blurStrength.value=e}},{key:"minDepthThreshold",get:function(){return this._minDepthThreshold.value},set:function(e){this._minDepthThreshold.value=e}},{key:"maxDepthThreshold",get:function(){return this._maxDepthThreshold.value},set:function(e){this._maxDepthThreshold.value=e}},{key:"depthScale",get:function(){return this._depthScale.value},set:function(e){this._depthScale.value=e}},{key:"debug",get:function(){return this._debug.value},set:function(e){this._debug.value=e}},{key:"depthToBlurRatioBias",get:function(){return this._depthToBlurRatioBias.value},set:function(e){this._depthToBlurRatioBias.value=e}},{key:"distortion",get:function(){return this._distortion.value},set:function(e){this._distortion.value=e}}]),t}(e.MeshStandardMaterial);exports.MeshReflectorMaterial=p;
  