(function (global, factory) { if (typeof define === "function" && define.amd) { define(["exports"], factory); } else if (typeof exports !== "undefined") { factory(exports); } else { var mod = { exports: {} }; factory(mod.exports); global.WaterRefractionShader = mod.exports; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports) { "use strict"; Object.defineProperty(_exports, "__esModule", { value: true }); _exports.WaterRefractionShader = void 0; var WaterRefractionShader = { uniforms: { 'color': { value: null }, 'time': { value: 0 }, 'tDiffuse': { value: null }, 'tDudv': { value: null }, 'textureMatrix': { value: null } }, vertexShader: /* glsl */ "\n\n\t\tuniform mat4 textureMatrix;\n\n\t\tvarying vec2 vUv;\n\t\tvarying vec4 vUvRefraction;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\n\t\t\tvUvRefraction = textureMatrix * vec4( position, 1.0 );\n\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}", fragmentShader: /* glsl */ "\n\n\t\tuniform vec3 color;\n\t\tuniform float time;\n\t\tuniform sampler2D tDiffuse;\n\t\tuniform sampler2D tDudv;\n\n\t\tvarying vec2 vUv;\n\t\tvarying vec4 vUvRefraction;\n\n\t\tfloat blendOverlay( float base, float blend ) {\n\n\t\t\treturn( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );\n\n\t\t}\n\n\t\tvec3 blendOverlay( vec3 base, vec3 blend ) {\n\n\t\t\treturn vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ),blendOverlay( base.b, blend.b ) );\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t float waveStrength = 0.5;\n\t\t float waveSpeed = 0.03;\n\n\t\t\t// simple distortion (ripple) via dudv map (see https://www.youtube.com/watch?v=6B7IF6GOu7s)\n\n\t\t\tvec2 distortedUv = texture2D( tDudv, vec2( vUv.x + time * waveSpeed, vUv.y ) ).rg * waveStrength;\n\t\t\tdistortedUv = vUv.xy + vec2( distortedUv.x, distortedUv.y + time * waveSpeed );\n\t\t\tvec2 distortion = ( texture2D( tDudv, distortedUv ).rg * 2.0 - 1.0 ) * waveStrength;\n\n\t\t\t// new uv coords\n\n\t\t vec4 uv = vec4( vUvRefraction );\n\t\t uv.xy += distortion;\n\n\t\t\tvec4 base = texture2DProj( tDiffuse, uv );\n\n\t\t\tgl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );\n\n\t\t}" }; _exports.WaterRefractionShader = WaterRefractionShader; });