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: Premultiply alpha for clear color. #29103

Merged
merged 2 commits into from
Aug 10, 2024
Merged

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Aug 9, 2024

Related issue: -

Description

Semi transparent clear values do not work as expected with WebGPURenderer.

WebGLRenderer (correct): https://jsfiddle.net/uq8wbo26/1/
WebGPURenderer (incorrect): https://jsfiddle.net/v70u128x/

That's because WebGPURenderer does not premultiply the clear alpha with the clear color. The PR fixes that for both backends.

Copy link

github-actions bot commented Aug 9, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
685.1 kB (169.6 kB) 685.1 kB (169.6 kB) +0 B

🌳 Bundle size after tree-shaking

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

Filesize dev Filesize PR Diff
462 kB (111.4 kB) 462 kB (111.4 kB) +0 B

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Aug 9, 2024

@WestLangley We've used to control this behavior in WebGLRenderer with the premultipliedAlpha renderer parameter.

if ( premultipliedAlpha === true ) {
r *= a; g *= a; b *= a;
}

Do you remember the use case when premultipliedAlpha should set to false when creating WebGLRenderer? WebGPURenderer does not currently not have such a parameter.

@WestLangley
Copy link
Collaborator

Do you remember the use case when premultipliedAlpha should set to false when creating WebGLRenderer?

In the renderer constructor, premultilpiedAlpha: true is a hint to the compositor that the drawing buffer contains RGB values that have been multiplied by alpha.

The three.js NormalBlending function results in a premultiplied buffer, so users should be advised not to change this.

As far as I know, a use case for premultilpiedAlpha: false has not been articulated.

WebGPURenderer does not currently not have such a parameter.

Only indirectly.

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

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Aug 9, 2024

In this case, I'll add a check in WebGPUBackend to only premultiply alpha when the alpha mode is premultiplied.

The WebGL backend does not have an alpha mode so it's always assumed to be premultiplied.

@Mugen87 Mugen87 added this to the r168 milestone Aug 9, 2024
@sunag sunag merged commit 86cfa03 into mrdoob:dev Aug 10, 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.

3 participants