summit/frontend/node_modules/three-stdlib/postprocessing/BloomPass.cjs.map

1 line
6.3 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"BloomPass.cjs","sources":["../../src/postprocessing/BloomPass.ts"],"sourcesContent":["import { Pass, FullScreenQuad } from './Pass'\nimport {\n AdditiveBlending,\n IUniform,\n ShaderMaterial,\n UniformsUtils,\n Vector2,\n WebGLRenderer,\n WebGLRenderTarget,\n} from 'three'\nimport { ConvolutionShader } from '../shaders/ConvolutionShader'\n\nclass BloomPass extends Pass {\n public renderTargetX: WebGLRenderTarget\n public renderTargetY: WebGLRenderTarget\n public materialCombine: ShaderMaterial\n public materialConvolution: ShaderMaterial\n public fsQuad: FullScreenQuad\n public combineUniforms: Record<keyof typeof CombineShader['uniforms'], IUniform<any>>\n public convolutionUniforms: Record<keyof typeof ConvolutionShader['uniforms'], IUniform<any>>\n\n public blurX = new Vector2(0.001953125, 0.0)\n public blurY = new Vector2(0.0, 0.001953125)\n\n constructor(strength = 1, kernelSize = 25, sigma = 4, resolution = 256) {\n super() // render targets\n\n this.renderTargetX = new WebGLRenderTarget(resolution, resolution)\n this.renderTargetX.texture.name = 'BloomPass.x'\n this.renderTargetY = new WebGLRenderTarget(resolution, resolution)\n this.renderTargetY.texture.name = 'BloomPass.y' // combine material\n\n this.combineUniforms = UniformsUtils.clone(CombineShader.uniforms)\n this.combineUniforms['strength'].value = strength\n this.materialCombine = new ShaderMaterial({\n uniforms: this.combineUniforms,\n vertexShader: CombineShader.vertexShader,\n fragmentShader: CombineShader.fragmentShader,\n blending: AdditiveBlending,\n transparent: true,\n }) // convolution material\n\n if (ConvolutionShader === undefined) console.error('BloomPass relies on ConvolutionShader')\n const convolutionShader = ConvolutionShader\n this.convolutionUniforms = UniformsUtils.clone(convolutionShader.uniforms)\n this.convolutionUniforms['uImageIncrement'].value = this.blurX\n this.convolutionUniforms['cKernel'].value = ConvolutionShader.buildKernel(sigma)\n this.materialConvolution = new ShaderMaterial({\n uniforms: this.convolutionUniforms,\n vertexShader: convolutionShader.vertexShader,\n fragmentShader: convolutionShader.fragmentShader,\n defines: {\n KERNEL_SIZE_FLOAT: kernelSize.toFixed(1),\n KERNEL_SIZE_INT: kernelSize.toFixed(0),\n },\n })\n this.needsSwap = false\n this.fsQuad = new FullScreenQuad(this.materialConvolution)\n }\n\n public render(\n renderer: WebGLRenderer,\n writeBuffer: WebGLRenderTarget,\n readBuffer: WebGLRenderTarget,\n deltaTime: number,\n maskActive: boolean,\n ): void {\n if (maskActive) renderer.state.buffers.stencil.setTest(false) // Render quad with blured scene into texture (convolution pass 1)\n\n this.fsQuad.material = this.materialConvolution\n this.convolutionUniforms['tDiffuse'].value = readBuffer.texture\n this.convolutionUniforms['uImageIncrement'].value = this.blurX\n renderer.setRenderTarget(this.renderTargetX)\n renderer.clear()\n this.fsQuad.render(renderer) // Render quad with blured scene into texture (convolution pass 2)\n\n this.convolutionUniforms['tDiffuse'].value = this.renderTargetX.texture\n this.convolutionUniforms['uImageIncrement'].value = this.blurY\n renderer.setRenderTarget(this.renderTargetY)\n renderer.clear()\n this.fsQuad.render(renderer) // Render original scene with superimposed blur to texture\n\n this.fsQuad.material = this.materialCombine\n this.combineUniforms['tDiffuse'].value = this.renderTargetY.texture\n if (maskActive) renderer.state.buffers.stencil.setTest(true)\n renderer.setRenderTarget(readBuffer)\n if (this.clear) renderer.clear()\n this.fsQuad.render(renderer)\n }\n}\n\nconst CombineShader = {\n uniforms: {\n tDiffuse: {\n value: null,\n },\n strength: {\n value: 1.0,\n },\n },\n vertexShader:\n /* glsl */\n `\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewM