Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not clear when rendering to target in PostProcessEffect #8705

Merged
merged 5 commits into from Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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