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 premultiplied alpha with clear colors. #29538

Merged
merged 2 commits into from
Oct 2, 2024

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Oct 1, 2024

Fixed #29337

Description

This should fix the clear color differences mentioned in #29337.

There was a bug that premultiplied alpha twice for the WebGL backend. The policy should be:

  • When the clear color from the render context is used, it already has premultiplied alpha added (Background takes care of that).
  • When the original clear color is queried via getClearColor(), alpha has not been premultiplied so far. That must be done if it is used for the actual clear operation.
  • Premultiplied alpha clear colors must always be used with the WebGL backend since it always uses alpha: true for the WebGL rendering context. With WebGPU, premultiplied alpha clear colors are only required when setting alpha: true when creating the renderer.

Copy link

github-actions bot commented Oct 1, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 688.13
170.5
688.13
170.5
+0 B
+0 B
WebGPU 807.15
217.43
807.26
217.48
+109 B
+49 B
WebGPU Nodes 806.66
217.29
806.77
217.34
+109 B
+50 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 462.85
111.78
462.85
111.78
+0 B
+0 B
WebGPU 535.95
144.69
536.06
144.73
+109 B
+39 B
WebGPU Nodes 492.03
134.42
492.14
134.46
+109 B
+37 B

@sunag sunag added this to the r170 milestone Oct 2, 2024
@WestLangley
Copy link
Collaborator

WestLangley commented Oct 2, 2024

In my testing, it seems that both backends render the same with this PR, but the WebGL backend no longer matches WebGLRenderer. Tone mapping disabled for comparison.

#29542 is limiting my ability to fully test this. Proper compositor blending is most easily verified in linear color space.

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Oct 2, 2024

There is definitely a difference when comparing WebGLRenderer with WebGPURenderer since the example uses blending and that is only fully correct in WebGPURenderer. When using sRGB output, WebGLRenderer performs blending in the wrong color space due to the inline encode.

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Oct 2, 2024

I'm going ahead and merge since the WebGL fallback code path is definitely wrong right now.

@Mugen87 Mugen87 merged commit 47fb8fe into mrdoob:dev Oct 2, 2024
12 checks passed
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.

WebGPURenderer with WebGPU Backend: Clear color is not set correctly
3 participants