Skip to content

Commit

Permalink
WebGPURenderer: Fix alpha canvas in WebGPU (mrdoob#27442)
Browse files Browse the repository at this point in the history
* fix alpha background in webgpu

* fix whitespace
  • Loading branch information
RenaudRohlinger authored and AdaRoseCannon committed Jan 15, 2024
1 parent c9701e9 commit 4c482a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion examples/jsm/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Renderer {

const {
logarithmicDepthBuffer = false,
alpha = true
} = parameters;

// public
Expand All @@ -43,6 +44,8 @@ class Renderer {
this.autoClearDepth = true;
this.autoClearStencil = true;

this.alpha = alpha;

this.logarithmicDepthBuffer = logarithmicDepthBuffer;

this.outputColorSpace = SRGBColorSpace;
Expand Down Expand Up @@ -85,7 +88,10 @@ class Renderer {
this._opaqueSort = null;
this._transparentSort = null;

this._clearColor = new Color4( 0x000000 );

const alphaClear = this.alpha === true ? 0 : 1;

this._clearColor = new Color4( 0, 0, 0, alphaClear );
this._clearDepth = 1;
this._clearStencil = 0;

Expand Down
5 changes: 4 additions & 1 deletion examples/jsm/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class WebGPUBackend extends Backend {
this.isWebGPUBackend = true;

// some parameters require default values other than "undefined"
this.parameters.alpha = ( parameters.alpha === undefined ) ? true : parameters.alpha;

this.parameters.antialias = ( parameters.antialias === true );

Expand Down Expand Up @@ -114,11 +115,13 @@ class WebGPUBackend extends Backend {
this.device = device;
this.context = context;

const alphaMode = parameters.alpha ? 'premultiplied' : 'opaque';

this.context.configure( {
device: this.device,
format: GPUTextureFormat.BGRA8Unorm,
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
alphaMode: 'premultiplied'
alphaMode: alphaMode
} );

this.updateSize();
Expand Down

0 comments on commit 4c482a4

Please sign in to comment.