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

WebGPURenderer: Fix clear alpha in WebGLBackend #30329

Merged

Conversation

RenaudRohlinger
Copy link
Collaborator

Description

This PR addresses an issue where the renderer's clear method does not properly clear the alpha channel when autoClear is set to false. Additionally, the viewport and scissor logic in the WebGLBackend has been refactored to align with best practices, reducing unnecessary WebGL bindings.

This contribution is funded by Utsubo

Copy link

github-actions bot commented Jan 15, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 339.53
79.09
339.53
79.09
+0 B
+0 B
WebGPU 491.02
136.44
491.65
136.62
+633 B
+170 B
WebGPU Nodes 490.49
136.34
491.12
136.5
+633 B
+168 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 465.39
112.16
465.39
112.16
+0 B
+0 B
WebGPU 561.56
152.15
562.2
152.31
+637 B
+168 B
WebGPU Nodes 516.95
141.72
517.58
141.88
+637 B
+167 B

@Mugen87 Mugen87 added this to the r173 milestone Jan 15, 2025
@sunag sunag merged commit a13e4b0 into mrdoob:dev Jan 16, 2025
12 checks passed
@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 4, 2025

@RenaudRohlinger There seems to be a minor issue with the clearColorValue. Everything works great if you use the default setup but if you set renderer.outputColorSpace to THREE.LinearSRGBColorSpace, a runtime error occurs:

three.webgpu.js:49759 Uncaught TypeError: Cannot set properties of null (setting 'clearColorValue')
at WebGPURenderer.clear (three.webgpu.js:49759:33)
at _display/:67:10

Live example: https://jsfiddle.net/obvwkyne/1/

The linear-srgb workflow skips the internal render target so the clear targets the canvas (default) framebuffer. Consequently, there is no renderTarget set which means renderContext ends up null.

It does work with r172 though: https://jsfiddle.net/obvwkyne/2/

@RenaudRohlinger
Copy link
Collaborator Author

Should we just wrap this line with the !== null then @Mugen87?

if ( renderContext !== null ) {
  renderContext.clearColorValue = this._clearColor;
}

I would guess this PR was a fix for renderTarget and the issue it covers didn't concerned no renderTarget.

@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 4, 2025

That sounds good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants