(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.ToneMapShader = mod.exports; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports) { "use strict"; Object.defineProperty(_exports, "__esModule", { value: true }); _exports.ToneMapShader = void 0; /** * Full-screen tone-mapping shader based on http://www.cis.rit.edu/people/faculty/ferwerda/publications/sig02_paper.pdf */ var ToneMapShader = { uniforms: { 'tDiffuse': { value: null }, 'averageLuminance': { value: 1.0 }, 'luminanceMap': { value: null }, 'maxLuminance': { value: 16.0 }, 'minLuminance': { value: 0.01 }, 'middleGrey': { value: 0.6 } }, vertexShader: /* glsl */ "\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}", fragmentShader: /* glsl */ "\n\n\t\t#include <common>\n\n\t\tuniform sampler2D tDiffuse;\n\n\t\tvarying vec2 vUv;\n\n\t\tuniform float middleGrey;\n\t\tuniform float minLuminance;\n\t\tuniform float maxLuminance;\n\t\t#ifdef ADAPTED_LUMINANCE\n\t\t\tuniform sampler2D luminanceMap;\n\t\t#else\n\t\t\tuniform float averageLuminance;\n\t\t#endif\n\n\t\tvec3 ToneMap( vec3 vColor ) {\n\t\t\t#ifdef ADAPTED_LUMINANCE\n\t\t\t\t// Get the calculated average luminance\n\t\t\t\tfloat fLumAvg = texture2D(luminanceMap, vec2(0.5, 0.5)).r;\n\t\t\t#else\n\t\t\t\tfloat fLumAvg = averageLuminance;\n\t\t\t#endif\n\n\t\t\t// Calculate the luminance of the current pixel\n\t\t\tfloat fLumPixel = linearToRelativeLuminance( vColor );\n\n\t\t\t// Apply the modified operator (Eq. 4)\n\t\t\tfloat fLumScaled = (fLumPixel * middleGrey) / max( minLuminance, fLumAvg );\n\n\t\t\tfloat fLumCompressed = (fLumScaled * (1.0 + (fLumScaled / (maxLuminance * maxLuminance)))) / (1.0 + fLumScaled);\n\t\t\treturn fLumCompressed * vColor;\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvec4 texel = texture2D( tDiffuse, vUv );\n\n\t\t\tgl_FragColor = vec4( ToneMap( texel.xyz ), texel.w );\n\n\t\t}" }; _exports.ToneMapShader = ToneMapShader; });