{"version":3,"file":"TAARenderPass.cjs","sources":["../../src/postprocessing/TAARenderPass.js"],"sourcesContent":["import { HalfFloatType, WebGLRenderTarget } from 'three'\nimport { SSAARenderPass } from './SSAARenderPass'\n\n/**\n *\n * Temporal Anti-Aliasing Render Pass\n *\n * When there is no motion in the scene, the TAA render pass accumulates jittered camera samples across frames to create a high quality anti-aliased result.\n *\n * References:\n *\n * TODO: Add support for motion vector pas so that accumulation of samples across frames can occur on dynamics scenes.\n *\n */\n\nclass TAARenderPass extends SSAARenderPass {\n constructor(scene, camera, clearColor, clearAlpha) {\n super(scene, camera, clearColor, clearAlpha)\n\n this.sampleLevel = 0\n this.accumulate = false\n this.accumulateIndex = -1\n }\n\n render(renderer, writeBuffer, readBuffer, deltaTime) {\n if (this.accumulate === false) {\n super.render(renderer, writeBuffer, readBuffer, deltaTime)\n\n this.accumulateIndex = -1\n return\n }\n\n const jitterOffsets = _JitterVectors[5]\n\n if (this.sampleRenderTarget === undefined) {\n this.sampleRenderTarget = new WebGLRenderTarget(readBuffer.width, readBuffer.height, { type: HalfFloatType })\n this.sampleRenderTarget.texture.name = 'TAARenderPass.sample'\n }\n\n if (this.holdRenderTarget === undefined) {\n this.holdRenderTarget = new WebGLRenderTarget(readBuffer.width, readBuffer.height, { type: HalfFloatType })\n this.holdRenderTarget.texture.name = 'TAARenderPass.hold'\n }\n\n if (this.accumulateIndex === -1) {\n super.render(renderer, this.holdRenderTarget, readBuffer, deltaTime)\n\n this.accumulateIndex = 0\n }\n\n const autoClear = renderer.autoClear\n renderer.autoClear = false\n\n renderer.getClearColor(this._oldClearColor)\n const oldClearAlpha = renderer.getClearAlpha()\n\n const sampleWeight = 1.0 / jitterOffsets.length\n\n if (this.accumulateIndex >= 0 && this.accumulateIndex < jitterOffsets.length) {\n this.copyUniforms['opacity'].value = sampleWeight\n this.copyUniforms['tDiffuse'].value = writeBuffer.texture\n\n // render the scene multiple times, each slightly jitter offset from the last and accumulate the results.\n const numSamplesPerFrame = Math.pow(2, this.sampleLevel)\n for (let i = 0; i < numSamplesPerFrame; i++) {\n const j = this.accumulateIndex\n const jitterOffset = jitterOffsets[j]\n\n if (this.camera.setViewOffset) {\n this.camera.setViewOffset(\n readBuffer.width,\n readBuffer.height,\n jitterOffset[0] * 0.0625,\n jitterOffset[1] * 0.0625, // 0.0625 = 1 / 16\n readBuffer.width,\n readBuffer.height,\n )\n }\n\n renderer.setRenderTarget(writeBuffer)\n renderer.setClearColor(this.clearColor, this.clearAlpha)\n renderer.clear()\n renderer.render(this.scene, this.camera)\n\n renderer.setRenderTarget(this.sampleRenderTarget)\n if (this.accumulateIndex === 0) {\n renderer.setClearColor(0x000000, 0.0)\n renderer.clear()\n }\n\n this.fsQuad.render(renderer)\n\n this.accumulateIndex++\n\n if (this.accumulateIndex >= jitterOffsets.length) break\n }\n\n if (this.camera.clearViewOffset) this.camera.clearViewOffset()\n }\n\n renderer.setClearColor(this.clearColor, this.clearAlpha)\n const accumulationWeight = this.accumulateIndex * sampleWeight\n\n if (accumulationWeight > 0) {\n this.copyUniforms['opacity'].value = 1.0\n this.copyUniforms['tDiffuse'].value = this.sampleRenderTarget.texture\n renderer.setRenderTarget(writeBuffer)\n renderer.clear()\n this.fsQuad.render(renderer)\n }\n\n if (accumulationWeight < 1.0) {\n this.copyUniforms['opacity'].value = 1.0 - accumulationWeight\n this.copyUniforms['tDiffuse'].value = this.holdRenderTarget.texture\n renderer.setRenderTarget(writeBuffer)\n this.fsQuad.render(renderer)\n }\n\n renderer.autoClear = autoClear\n renderer.setClearColor(this._oldClearColor, oldClearAlpha)\n }\n\n dispose() {\n super.dispose()\n\n if (this.sampleRenderTarget !== undefined) this.sampleRenderTarget.dispose()\n if (this.holdRenderTarget !== undefined) this.holdRenderTarget.dispose()\n }\n}\n\n// prettier-ignore\nconst _JitterVectors = [\n\t[\n\t\t[ 0, 0 ]\n\t],\n\t[\n\t\t[ 4, 4 ], [ - 4, - 4 ]\n\t],\n\t[\n\t\t[ - 2, - 6 ], [ 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