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

UnrealBloomPass: Use premultipliedAlpha. #26185

Closed
wants to merge 2 commits into from
Closed

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Jun 3, 2023

Related issue: #26179

Description

UnrealBloomPass has to set the premultipliedAlpha flag to true for its CopyShader pass similar to SSAARenderPass since both use AdditiveBlending (so a built-in blending function where premultipliedAlpha applies).

This PR mitigates the bloom effect so it is required to increase the bloom strength to achieve a comparable result like before. So this change has to be noted in the migration guide.

@Mugen87 Mugen87 marked this pull request as ready for review June 3, 2023 08:21
@Mugen87 Mugen87 added this to the r154 milestone Jun 3, 2023
@Mugen87 Mugen87 requested a review from WestLangley June 3, 2023 08:25
@@ -130,6 +130,7 @@ class UnrealBloomPass extends Pass {
vertexShader: copyShader.vertexShader,
fragmentShader: copyShader.fragmentShader,
blending: AdditiveBlending,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A so-called materialCopy that does additive blending is not copying. I think that is poorly-named.

Do you still think premultipliedAlpha is correct? I find trying to track the logic of the code in this file a bit daunting...

If you are not sure, I wonder if changing the behavior for users is worth it?

//

On a related note, I think the existing example has too much bloom effect, and looks better with this one-line change. IMO, there would be no need to change the parameters to try to match the previous look.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A so-called materialCopy that does additive blending is not copying. I think that is poorly-named.

Agreed. E.g. materialBlend sounds more appropriate.

Do you still think premultipliedAlpha is correct?

Yes. The pass additively blends over the input. Considering how CopyPass is implemented, premultipliedAlpha should be set to true.

If you are not sure, I wonder if changing the behavior for users is worth it?

Let me think about this. That is a valid point since even without the change the effect looks "right".

On a related note, I think the existing example has too much bloom effect, and looks better with this one-line change. IMO, there would be no need to change the parameters to try to match the previous look.

Yeah, I think I got a little bit excited when UnrealBloomPass finally produces a correctly tone-mapped result in the right color space so I couldn't have enough bloom 😅 . I'm fine with turning it down a bit.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering how CopyPass is implemented, premultipliedAlpha should be set to true.

We should set .premultipliedAlpha to true only if the shader outputs premultiplied RGB values. So, the question is: does it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so. The opacity scales all color components, not just alpha.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This effect was not written to properly accommodate the premultiplied output from RenderPass.

Given this PR causes breakage for users, and given the change here sill leaves inconsistencies in the code, I'd suggest doing nothing for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

, and given the change here sill leaves inconsistencies in the code

On what inconsistencies are you referring to? Is there something else to fix?

Copy link
Collaborator Author

@Mugen87 Mugen87 Jun 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I agree the breakage isn't worth the overall change. If someone reports a bug related to blending that can be fixed by setting the premultipliedAlpha to true, we can reconsider the PR.

Copy link
Collaborator Author

@Mugen87 Mugen87 Jun 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When implementing the fiddle for #24703 (comment), I've noticed that the bloom is too strong given standard values like 1 for bloom strength. It seems enabling premultipliedAlpha as suggested in the PR produces a more consistent results.

@Mugen87 Mugen87 closed this Jun 4, 2023
@Mugen87 Mugen87 removed this from the r154 milestone Jun 4, 2023
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.

None yet

2 participants