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

1 line
6.0 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"BokehPass.cjs","sources":["../../src/postprocessing/BokehPass.ts"],"sourcesContent":["/**\n * Depth-of-field post-process with bokeh shader\n */\n\nimport { Pass, FullScreenQuad } from './Pass'\nimport {\n Color,\n MeshDepthMaterial,\n NearestFilter,\n NoBlending,\n PerspectiveCamera,\n RGBADepthPacking,\n Scene,\n ShaderMaterial,\n UniformsUtils,\n WebGLRenderer,\n WebGLRenderTarget,\n} from 'three'\nimport { BokehShader } from '../shaders/BokehShader'\n\ntype BokehPassParams = {\n focus?: number\n aspect?: number\n aperture?: number\n maxblur?: number\n width?: number\n height?: number\n}\n\nclass BokehPass extends Pass {\n public scene: Scene\n public camera: PerspectiveCamera\n public renderTargetDepth: WebGLRenderTarget\n public materialDepth: MeshDepthMaterial\n public materialBokeh: ShaderMaterial\n public fsQuad: FullScreenQuad\n\n private _oldClearColor: Color\n\n public uniforms\n\n constructor(scene: Scene, camera: PerspectiveCamera, params: BokehPassParams) {\n super()\n this.scene = scene\n this.camera = camera\n const focus = params.focus !== undefined ? params.focus : 1.0\n const aspect = params.aspect !== undefined ? params.aspect : camera.aspect\n const aperture = params.aperture !== undefined ? params.aperture : 0.025\n const maxblur = params.maxblur !== undefined ? params.maxblur : 1.0 // render targets\n\n const width = params.width || window.innerWidth || 1\n const height = params.height || window.innerHeight || 1\n this.renderTargetDepth = new WebGLRenderTarget(width, height, {\n minFilter: NearestFilter,\n magFilter: NearestFilter,\n })\n this.renderTargetDepth.texture.name = 'BokehPass.depth' // depth material\n\n this.materialDepth = new MeshDepthMaterial()\n this.materialDepth.depthPacking = RGBADepthPacking\n this.materialDepth.blending = NoBlending // bokeh material\n\n if (BokehShader === undefined) {\n console.error('BokehPass relies on BokehShader')\n }\n\n const bokehShader = BokehShader\n const bokehUniforms = UniformsUtils.clone(bokehShader.uniforms)\n bokehUniforms['tDepth'].value = this.renderTargetDepth.texture\n bokehUniforms['focus'].value = focus\n bokehUniforms['aspect'].value = aspect\n bokehUniforms['aperture'].value = aperture\n bokehUniforms['maxblur'].value = maxblur\n bokehUniforms['nearClip'].value = camera.near\n bokehUniforms['farClip'].value = camera.far\n this.materialBokeh = new ShaderMaterial({\n defines: Object.assign({}, bokehShader.defines),\n uniforms: bokehUniforms,\n vertexShader: bokehShader.vertexShader,\n fragmentShader: bokehShader.fragmentShader,\n })\n this.uniforms = bokehUniforms\n this.needsSwap = false\n this.fsQuad = new FullScreenQuad(this.materialBokeh)\n this._oldClearColor = new Color()\n }\n\n public render(\n renderer: WebGLRenderer,\n writeBuffer: WebGLRenderTarget,\n readBuffer: WebGLRenderTarget,\n /*, deltaTime, maskActive */\n ): void {\n // Render depth into texture\n this.scene.overrideMaterial = this.materialDepth\n renderer.getClearColor(this._oldClearColor)\n const oldClearAlpha = renderer.getClearAlpha()\n const oldAutoClear = renderer.autoClear\n renderer.autoClear = false\n renderer.setClearColor(0xffffff)\n renderer.setClearAlpha(1.0)\n renderer.setRenderTarget(this.renderTargetDepth)\n renderer.clear()\n renderer.render(this.scene, this.camera) // Render bokeh composite\n\n this.uniforms['tColor'].value = readBuffer.texture\n this.uniforms['nearClip'].value = this.camera.near\n this.uniforms['farClip'].value = this.camera.far\n\n if (this.renderToScreen) {\n renderer.setRenderTarget(null)\n this.fsQuad.render(renderer)\n } else {\n renderer.setRenderTarget(writeBuffer)\n renderer.clear()\n this.fsQuad.render(renderer)\n }\n\n this.scene.overrideMaterial = null\n renderer.setClearColor(this._oldClearColor)\n renderer.setClearAlpha(oldClearAlpha)\n rendere