Skip to content

Commit

Permalink
WebGPURenderer: Harmonize clear of MRT textures. (#30586)
Browse files Browse the repository at this point in the history
* WebGPURenderer: Harmonize clear of MRT textures.

* E2E: Update screenshots.
  • Loading branch information
Mugen87 authored Feb 23, 2025
1 parent 155d41e commit bcae459
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
Binary file modified examples/screenshots/webgpu_multiple_rendertargets.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion src/renderers/webgl-fallback/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,15 @@ class WebGLBackend extends Backend {

for ( let i = 0; i < descriptor.textures.length; i ++ ) {

gl.clearBufferfv( gl.COLOR, i, [ clearColor.r, clearColor.g, clearColor.b, clearColor.a ] );
if ( i === 0 ) {

gl.clearBufferfv( gl.COLOR, i, [ clearColor.r, clearColor.g, clearColor.b, clearColor.a ] );

} else {

gl.clearBufferfv( gl.COLOR, i, [ 0, 0, 0, 1 ] );

}

}

Expand Down
16 changes: 13 additions & 3 deletions src/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,23 @@ class WebGPUBackend extends Backend {

}

// only apply the user-defined clearValue to the first color attachment like in beginRender()

let clearValue = { r: 0, g: 0, b: 0, a: 1 };

if ( i === 0 && colorAttachmentsConfig.clearValue ) {

clearValue = colorAttachmentsConfig.clearValue;

}

colorAttachments.push( {
view,
depthSlice: sliceIndex,
resolveTarget,
loadOp: GPULoadOp.Load,
storeOp: GPUStoreOp.Store,
...colorAttachmentsConfig
loadOp: colorAttachmentsConfig.loadOP || GPULoadOp.Load,
storeOp: colorAttachmentsConfig.storeOP || GPUStoreOp.Store,
clearValue: clearValue
} );

}
Expand Down

0 comments on commit bcae459

Please sign in to comment.