UNPKG

@babylonjs/core

Version:

Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.

79 lines (78 loc) 3.69 kB
import { FrameGraphTask } from "../../frameGraphTask.js"; import { textureSizeIsObject } from "../../../Materials/Textures/textureCreationOptions.js"; /** * Task which applies a post process. */ export class FrameGraphPostProcessTask extends FrameGraphTask { /** * The draw wrapper used by the post process */ get drawWrapper() { return this._postProcessDrawWrapper; } /** * Constructs a new post process task. * @param name Name of the task. * @param frameGraph The frame graph this task is associated with. * @param postProcess The post process to apply. */ constructor(name, frameGraph, postProcess) { super(name, frameGraph); /** * The sampling mode to use for the source texture. */ this.sourceSamplingMode = 2; this.postProcess = postProcess; this._postProcessDrawWrapper = this.postProcess.drawWrapper; this.outputTexture = this._frameGraph.textureManager.createDanglingHandle(); this.onTexturesAllocatedObservable.add((context) => { context.setTextureSamplingMode(this.sourceTexture, this.sourceSamplingMode); }); } isReady() { return this.postProcess.isReady(); } record(skipCreationOfDisabledPasses = false, additionalExecute, additionalBindings) { if (this.sourceTexture === undefined) { throw new Error(`FrameGraphPostProcessTask "${this.name}": sourceTexture is required`); } const sourceTextureCreationOptions = this._frameGraph.textureManager.getTextureCreationOptions(this.sourceTexture); sourceTextureCreationOptions.options.samples = 1; this._frameGraph.textureManager.resolveDanglingHandle(this.outputTexture, this.targetTexture, this.name, sourceTextureCreationOptions); const sourceSize = !sourceTextureCreationOptions.sizeIsPercentage ? textureSizeIsObject(sourceTextureCreationOptions.size) ? sourceTextureCreationOptions.size : { width: sourceTextureCreationOptions.size, height: sourceTextureCreationOptions.size } : this._frameGraph.textureManager.getAbsoluteDimensions(sourceTextureCreationOptions.size); this._sourceWidth = sourceSize.width; this._sourceHeight = sourceSize.height; const outputTextureDescription = this._frameGraph.textureManager.getTextureDescription(this.outputTexture); this._outputWidth = outputTextureDescription.size.width; this._outputHeight = outputTextureDescription.size.height; const pass = this._frameGraph.addRenderPass(this.name); pass.addDependencies(this.sourceTexture); pass.setRenderTarget(this.outputTexture); pass.setExecuteFunc((context) => { additionalExecute?.(context); context.applyFullScreenEffect(this._postProcessDrawWrapper, () => { context.bindTextureHandle(this._postProcessDrawWrapper.effect, "textureSampler", this.sourceTexture); additionalBindings?.(context); this.postProcess.bind(); }); }); if (!skipCreationOfDisabledPasses) { const passDisabled = this._frameGraph.addRenderPass(this.name + "_disabled", true); passDisabled.addDependencies(this.sourceTexture); passDisabled.setRenderTarget(this.outputTexture); passDisabled.setExecuteFunc((context) => { context.copyTexture(this.sourceTexture); }); } return pass; } dispose() { this.postProcess.dispose(); super.dispose(); } } //# sourceMappingURL=postProcessTask.js.map