Skip to content

Commit

Permalink
WebGPURenderer: Premultiply alpha for clear color. (#29103)
Browse files Browse the repository at this point in the history
* WebGPURenderer: Premultiply alpha for clear color.

* WebGPUBackend: Honor `alpha` paramter when configuring clear values.
  • Loading branch information
Mugen87 committed Aug 10, 2024
1 parent 5cdfd25 commit 86cfa03
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/renderers/webgl-fallback/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,12 @@ class WebGLBackend extends Backend {

const clearColor = descriptor.clearColorValue || this.getClearColor();

// premultiply alpha

clearColor.r *= clearColor.a;
clearColor.g *= clearColor.a;
clearColor.b *= clearColor.a;

if ( depth ) this.state.setDepthMask( true );

if ( descriptor.textures === null ) {
Expand Down
14 changes: 13 additions & 1 deletion src/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,19 @@ class WebGPUBackend extends Backend {

const clearColor = this.getClearColor();

clearValue = { r: clearColor.r, g: clearColor.g, b: clearColor.b, a: clearColor.a };
if ( this.renderer.alpha === true ) {

// premultiply alpha

const a = clearColor.a;

clearValue = { r: clearColor.r * a, g: clearColor.g * a, b: clearColor.b * a, a: a };

} else {

clearValue = { r: clearColor.r, g: clearColor.g, b: clearColor.b, a: clearColor.a };

}

}

Expand Down

0 comments on commit 86cfa03

Please sign in to comment.