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

[Merged by Bors] - use blendstate blend for alphamode::blend #7899

Closed
wants to merge 1 commit into from

Conversation

robtfm
Copy link
Contributor

@robtfm robtfm commented Mar 4, 2023

Objective

revert combining pipelines for AlphaMode::Blend and AlphaMode::Premultiplied & Add

the recent blend state pr changed AlphaMode::Blend to use a blend state of Blend::PREMULTIPLIED_ALPHA_BLENDING, and recovered the original behaviour by multiplying colour by alpha in the standard material's fragment shader.

this had some advantages (specifically it means more material instances can be batched together in future), but this also means that custom materials that specify AlphaMode::Blend now get a premultiplied blend state, so they must also multiply colour by alpha.

Solution

revert that combination to preserve 0.9 behaviour for custom materials with AlphaMode::Blend.

@cart cart added this to the 0.10 milestone Mar 4, 2023
Copy link
Contributor

@coreh coreh left a comment

Choose a reason for hiding this comment

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

Ouch, yeah, I hadn't considered this would subtly break existing custom shaders. 😕

Was going to also remind to update the release notes as part of this review, but I see that @cart has already removed the section about the shared blend state 👍

#endif // ALPHA_MASK

#ifdef BLEND_PREMULTIPLIED_ALPHA
#else // BLEND_PREMULTIPLIED_ALPHA || BLEND_ALPHA
let alpha_mode = material.flags & STANDARD_MATERIAL_FLAGS_ALPHA_MODE_RESERVED_BITS;
if (alpha_mode == STANDARD_MATERIAL_FLAGS_ALPHA_MODE_BLEND || alpha_mode == STANDARD_MATERIAL_FLAGS_ALPHA_MODE_ADD)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm I think this will needleslly run in BLEND_MULTIPLY, maybe we can guard it with a #ifndef BLEND_MULTIPLY?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think it's ok as is, since if we have BLEND_MULTIPLY, which implies we have !BLEND_PREMULTIPLIED_ALPHA && !BLEND_ALPHA && !ALPHA_MASK, then EMPTY_PREPASS_ALPHA_DISCARD gets defined and this whole containing block is skipped.

i think this set of defs could use a bit of a rationalization at some point though, it seems complex for what it's actually doing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah. Probably better to do that after 0.10 is out to avoid subtly breaking anything.

I wanna try adding a dither-based alpha mode that renders “transparency” in the opaque pass (would go well with TAA) so maybe that could be a good time to do that

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen labels Mar 4, 2023
Copy link
Contributor

@superdump superdump left a comment

Choose a reason for hiding this comment

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

bors r+

bors bot pushed a commit that referenced this pull request Mar 5, 2023
# Objective

revert combining pipelines for AlphaMode::Blend and AlphaMode::Premultiplied & Add

the recent blend state pr changed `AlphaMode::Blend` to use a blend state of `Blend::PREMULTIPLIED_ALPHA_BLENDING`, and recovered the original behaviour by multiplying colour by alpha in the standard material's fragment shader. 

this had some advantages (specifically it means more material instances can be batched together in future), but this also means that custom materials that specify `AlphaMode::Blend` now get a premultiplied blend state, so they must also multiply colour by alpha.

## Solution

revert that combination to preserve 0.9 behaviour for custom materials with AlphaMode::Blend.
@bors bors bot changed the title use blendstate blend for alphamode::blend [Merged by Bors] - use blendstate blend for alphamode::blend Mar 5, 2023
@bors bors bot closed this Mar 5, 2023
Shfty pushed a commit to shfty-rust/bevy that referenced this pull request Mar 19, 2023
# Objective

revert combining pipelines for AlphaMode::Blend and AlphaMode::Premultiplied & Add

the recent blend state pr changed `AlphaMode::Blend` to use a blend state of `Blend::PREMULTIPLIED_ALPHA_BLENDING`, and recovered the original behaviour by multiplying colour by alpha in the standard material's fragment shader. 

this had some advantages (specifically it means more material instances can be batched together in future), but this also means that custom materials that specify `AlphaMode::Blend` now get a premultiplied blend state, so they must also multiply colour by alpha.

## Solution

revert that combination to preserve 0.9 behaviour for custom materials with AlphaMode::Blend.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants