(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.FilmShader = mod.exports; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports) { "use strict"; Object.defineProperty(_exports, "__esModule", { value: true }); _exports.FilmShader = void 0; /** * Film grain & scanlines shader * * - ported from HLSL to WebGL / GLSL * http://www.truevision3d.com/forums/showcase/staticnoise_colorblackwhite_scanline_shaders-t18698.0.html * * Screen Space Static Postprocessor * * Produces an analogue noise overlay similar to a film grain / TV static * * Original implementation and noise algorithm * Pat 'Hawthorne' Shearon * * Optimized scanlines + noise version with intensity scaling * Georg 'Leviathan' Steinrohder * * This version is provided under a Creative Commons Attribution 3.0 License * http://creativecommons.org/licenses/by/3.0/ */ var FilmShader = { uniforms: { 'tDiffuse': { value: null }, 'time': { value: 0.0 }, 'nIntensity': { value: 0.5 }, 'sIntensity': { value: 0.05 }, 'sCount': { value: 4096 }, 'grayscale': { value: 1 } }, 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\t// control parameter\n\t\tuniform float time;\n\n\t\tuniform bool grayscale;\n\n\t\t// noise effect intensity value (0 = no effect, 1 = full effect)\n\t\tuniform float nIntensity;\n\n\t\t// scanlines effect intensity value (0 = no effect, 1 = full effect)\n\t\tuniform float sIntensity;\n\n\t\t// scanlines effect count value (0 = no effect, 4096 = full effect)\n\t\tuniform float sCount;\n\n\t\tuniform sampler2D tDiffuse;\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t// sample the source\n\t\t\tvec4 cTextureScreen = texture2D( tDiffuse, vUv );\n\n\t\t// make some noise\n\t\t\tfloat dx = rand( vUv + time );\n\n\t\t// add noise\n\t\t\tvec3 cResult = cTextureScreen.rgb + cTextureScreen.rgb * clamp( 0.1 + dx, 0.0, 1.0 );\n\n\t\t// get us a sine and cosine\n\t\t\tvec2 sc = vec2( sin( vUv.y * sCount ), cos( vUv.y * sCount ) );\n\n\t\t// add scanlines\n\t\t\tcResult += cTextureScreen.rgb * vec3( sc.x, sc.y, sc.x ) * sIntensity;\n\n\t\t// interpolate between source and result by intensity\n\t\t\tcResult = cTextureScreen.rgb + clamp( nIntensity, 0.0,1.0 ) * ( cResult - cTextureScreen.rgb );\n\n\t\t// convert to grayscale if desired\n\t\t\tif( grayscale ) {\n\n\t\t\t\tcResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 );\n\n\t\t\t}\n\n\t\t\tgl_FragColor = vec4( cResult, cTextureScreen.a );\n\n\t\t}" }; _exports.FilmShader = FilmShader; });