1 line
14 KiB
Plaintext
1 line
14 KiB
Plaintext
|
|
{"version":3,"file":"AdaptiveToneMappingPass.cjs","sources":["../../src/postprocessing/AdaptiveToneMappingPass.js"],"sourcesContent":["import {\n LinearMipmapLinearFilter,\n MeshBasicMaterial,\n NoBlending,\n ShaderMaterial,\n UniformsUtils,\n WebGLRenderTarget,\n} from 'three'\nimport { Pass, FullScreenQuad } from './Pass'\nimport { CopyShader } from '../shaders/CopyShader'\nimport { LuminosityShader } from '../shaders/LuminosityShader'\nimport { ToneMapShader } from '../shaders/ToneMapShader'\n\n/**\n * Generate a texture that represents the luminosity of the current scene, adapted over time\n * to simulate the optic nerve responding to the amount of light it is receiving.\n * Based on a GDC2007 presentation by Wolfgang Engel titled \"Post-Processing Pipeline\"\n *\n * Full-screen tone-mapping shader based on http://www.graphics.cornell.edu/~jaf/publications/sig02_paper.pdf\n */\n\nclass AdaptiveToneMappingPass extends Pass {\n constructor(adaptive, resolution) {\n super()\n\n this.resolution = resolution !== undefined ? resolution : 256\n this.needsInit = true\n this.adaptive = adaptive !== undefined ? !!adaptive : true\n\n this.luminanceRT = null\n this.previousLuminanceRT = null\n this.currentLuminanceRT = null\n\n const copyShader = CopyShader\n\n this.copyUniforms = UniformsUtils.clone(copyShader.uniforms)\n\n this.materialCopy = new ShaderMaterial({\n uniforms: this.copyUniforms,\n vertexShader: copyShader.vertexShader,\n fragmentShader: copyShader.fragmentShader,\n blending: NoBlending,\n depthTest: false,\n })\n\n this.materialLuminance = new ShaderMaterial({\n uniforms: UniformsUtils.clone(LuminosityShader.uniforms),\n vertexShader: LuminosityShader.vertexShader,\n fragmentShader: LuminosityShader.fragmentShader,\n blending: NoBlending,\n })\n\n this.adaptLuminanceShader = {\n defines: {\n MIP_LEVEL_1X1: (Math.log(this.resolution) / Math.log(2.0)).toFixed(1),\n },\n uniforms: {\n lastLum: { value: null },\n currentLum: { value: null },\n minLuminance: { value: 0.01 },\n delta: { value: 0.016 },\n tau: { value: 1.0 },\n },\n vertexShader: `varying vec2 vUv;\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvUv = uv;\n\t\t\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t\t\t}`,\n\n fragmentShader: `varying vec2 vUv;\n\n\t\t\t\tuniform sampler2D lastLum;\n\t\t\t\tuniform sampler2D currentLum;\n\t\t\t\tuniform float minLuminance;\n\t\t\t\tuniform float delta;\n\t\t\t\tuniform float tau;\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvec4 lastLum = texture2D( lastLum, vUv, MIP_LEVEL_1X1 );\n\t\t\t\t\tvec4 currentLum = texture2D( currentLum, vUv, MIP_LEVEL_1X1 );\n\n\t\t\t\t\tfloat fLastLum = max( minLuminance, lastLum.r );\n\t\t\t\t\tfloat fCurrentLum = max( minLuminance, currentLum.r );\n\n\t\t\t\t\t//The adaption seems to work better in extreme lighting differences\n\t\t\t\t\t//if the input luminance is squared.\n\t\t\t\t\tfCurrentLum *= fCurrentLum;\n\n\t\t\t\t\t// Adapt the luminance using Pattanaik's technique\n\t\t\t\t\tfloat fAdaptedLum = fLastLum + (fCurrentLum - fLastLum) * (1.0 - exp(-delta * tau));\n\t\t\t\t\t// \"fAdaptedLum = sqrt(fAdaptedLum);\n\t\t\t\t\tgl_FragColor.r = fAdaptedLum;\n\t\t\t\t}`,\n }\n\n this.materialAdaptiveLum = new ShaderMaterial({\n uniforms: UniformsUtils.clone(this.adaptLuminanceShader.uniforms),\n vertexShader: this.adaptLuminanceShader.vertexShader,\n fragmentShader: this.adaptLuminanceShader.fragmentShader,\n defines: Object.assign({}, this.adaptLuminanceShader.defines),\n blending: NoBlending,\n })\n\n this.materialToneMap = new ShaderMaterial({\n uniforms: UniformsUtils.clone(ToneMapShader.uniforms),\n vertexShader: ToneMapShader.vertexShader,\n fragmentShader: ToneMapShader.fragmentShader,\n blending: NoBlending,\n })\n\n this.fsQuad = new FullScreenQuad(null)\n }\n\n render(renderer, writeBuffer, readBuffer, deltaTime /*, maskA
|