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

1 line
20 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"UnrealBloomPass.cjs","sources":["../../src/postprocessing/UnrealBloomPass.js"],"sourcesContent":["import {\n AdditiveBlending,\n Color,\n HalfFloatType,\n MeshBasicMaterial,\n ShaderMaterial,\n UniformsUtils,\n Vector2,\n Vector3,\n WebGLRenderTarget,\n} from 'three'\nimport { Pass, FullScreenQuad } from './Pass'\nimport { CopyShader } from '../shaders/CopyShader'\nimport { LuminosityHighPassShader } from '../shaders/LuminosityHighPassShader'\n\n/**\n * UnrealBloomPass is inspired by the bloom pass of Unreal Engine. It creates a\n * mip map chain of bloom textures and blurs them with different radii. Because\n * of the weighted combination of mips, and because larger blurs are done on\n * higher mips, this effect provides good quality and performance.\n *\n * Reference:\n * - https://docs.unrealengine.com/latest/INT/Engine/Rendering/PostProcessEffects/Bloom/\n */\nconst UnrealBloomPass = /* @__PURE__ */ (() => {\n class UnrealBloomPass extends Pass {\n static BlurDirectionX = new Vector2(1.0, 0.0)\n static BlurDirectionY = new Vector2(0.0, 1.0)\n\n constructor(resolution, strength, radius, threshold) {\n super()\n\n this.strength = strength !== undefined ? strength : 1\n this.radius = radius\n this.threshold = threshold\n this.resolution = resolution !== undefined ? new Vector2(resolution.x, resolution.y) : new Vector2(256, 256)\n\n // create color only once here, reuse it later inside the render function\n this.clearColor = new Color(0, 0, 0)\n\n // render targets\n this.renderTargetsHorizontal = []\n this.renderTargetsVertical = []\n this.nMips = 5\n let resx = Math.round(this.resolution.x / 2)\n let resy = Math.round(this.resolution.y / 2)\n\n this.renderTargetBright = new WebGLRenderTarget(resx, resy, { type: HalfFloatType })\n this.renderTargetBright.texture.name = 'UnrealBloomPass.bright'\n this.renderTargetBright.texture.generateMipmaps = false\n\n for (let i = 0; i < this.nMips; i++) {\n const renderTargetHorizonal = new WebGLRenderTarget(resx, resy, { type: HalfFloatType })\n\n renderTargetHorizonal.texture.name = 'UnrealBloomPass.h' + i\n renderTargetHorizonal.texture.generateMipmaps = false\n\n this.renderTargetsHorizontal.push(renderTargetHorizonal)\n\n const renderTargetVertical = new WebGLRenderTarget(resx, resy, { type: HalfFloatType })\n\n renderTargetVertical.texture.name = 'UnrealBloomPass.v' + i\n renderTargetVertical.texture.generateMipmaps = false\n\n this.renderTargetsVertical.push(renderTargetVertical)\n\n resx = Math.round(resx / 2)\n\n resy = Math.round(resy / 2)\n }\n\n // luminosity high pass material\n\n const highPassShader = LuminosityHighPassShader\n this.highPassUniforms = UniformsUtils.clone(highPassShader.uniforms)\n\n this.highPassUniforms['luminosityThreshold'].value = threshold\n this.highPassUniforms['smoothWidth'].value = 0.01\n\n this.materialHighPassFilter = new ShaderMaterial({\n uniforms: this.highPassUniforms,\n vertexShader: highPassShader.vertexShader,\n fragmentShader: highPassShader.fragmentShader,\n defines: {},\n })\n\n // Gaussian Blur Materials\n this.separableBlurMaterials = []\n const kernelSizeArray = [3, 5, 7, 9, 11]\n resx = Math.round(this.resolution.x / 2)\n resy = Math.round(this.resolution.y / 2)\n\n for (let i = 0; i < this.nMips; i++) {\n this.separableBlurMaterials.push(this.getSeperableBlurMaterial(kernelSizeArray[i]))\n\n this.separableBlurMaterials[i].uniforms['texSize'].value = new Vector2(resx, resy)\n\n resx = Math.round(resx / 2)\n\n resy = Math.round(resy / 2)\n }\n\n // Composite material\n this.compositeMaterial = this.getCompositeMaterial(this.nMips)\n this.compositeMaterial.uniforms['blurTexture1'].value = this.renderTargetsVertical[0].texture\n this.compositeMaterial.uniforms['blurTexture2'].value = this.