Skip to content

Commit

Permalink
Do not clear when rendering to target in PostProcessEffect (#8705)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixpalmer committed Mar 27, 2024
1 parent 51a3a3c commit db26ab6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions modules/core/src/effects/post-process-effect.ts
Expand Up @@ -38,12 +38,14 @@ export default class PostProcessEffect<ShaderPassT extends ShaderPass> implement

for (let index = 0; index < passes.length; index++) {
const isLastPass = index === passes.length - 1;
if (target !== undefined && isLastPass) {
const renderToTarget = target !== undefined && isLastPass;
if (renderToTarget) {
outputBuffer = target;
}
const clearCanvas = !renderToTarget || Boolean(params.clearCanvas);
const moduleSettings = {};
moduleSettings[this.module.name] = this.props;
passes[index].render({inputBuffer, outputBuffer, moduleSettings});
passes[index].render({clearCanvas, inputBuffer, outputBuffer, moduleSettings});

const switchBuffer = outputBuffer as Framebuffer;
outputBuffer = inputBuffer;
Expand Down
1 change: 1 addition & 0 deletions modules/core/src/lib/deck-renderer.ts
Expand Up @@ -84,6 +84,7 @@ export default class DeckRenderer {
const outputBuffer = this.lastPostProcessEffect ? this.renderBuffers[0] : renderOpts.target;
if (this.lastPostProcessEffect) {
renderOpts.clearColor = [0, 0, 0, 0];
renderOpts.clearCanvas = true;
}
const renderStats = layerPass.render({...renderOpts, target: outputBuffer});

Expand Down
5 changes: 3 additions & 2 deletions modules/core/src/passes/screen-pass.ts
Expand Up @@ -13,6 +13,7 @@ type ScreenPassProps = {
};

type ScreenPassRenderOptions = {
clearCanvas?: boolean;
inputBuffer: Framebuffer;
outputBuffer: Framebuffer | null;
moduleSettings: any;
Expand Down Expand Up @@ -47,15 +48,15 @@ export default class ScreenPass extends Pass {
* @param outputBuffer - Frame buffer that serves as the output render target
*/
protected _renderPass(device: Device, options: ScreenPassRenderOptions) {
const {inputBuffer, outputBuffer} = options;
const {clearCanvas, inputBuffer, outputBuffer} = options;
const texSize = [inputBuffer.width, inputBuffer.height];
this.model.shaderInputs.setProps(options.moduleSettings);
this.model.setBindings({texSrc: inputBuffer.colorAttachments[0]});
this.model.setUniforms({texSize});
const renderPass = this.device.beginRenderPass({
framebuffer: outputBuffer,
parameters: {viewport: [0, 0, ...texSize]},
clearColor: [0, 0, 0, 0],
clearColor: clearCanvas ? [0, 0, 0, 0] : false,
clearDepth: 1
});

Expand Down

0 comments on commit db26ab6

Please sign in to comment.