-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Implement alpha to coverage (A2C) support. #12970
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
Conversation
[Alpha to coverage] (A2C) replaces alpha blending with a hardware-specific multisample coverage mask when multisample antialiasing is in use. It's a simple form of [order-independent transparency] that relies on MSAA. ["Anti-aliased Alpha Test: The Esoteric Alpha To Coverage"] is a good summary of the motivation for and best practices relating to A2C. This commit implements alpha to coverage support as a new variant for `AlphaMode`. You can supply `AlphaMode::AlphaToCoverage` as the `alpha_mode` field in `StandardMaterial` to use it. When in use, the standard material shader automatically applies the texture filtering method from ["Anti-aliased Alpha Test: The Esoteric Alpha To Coverage"]. Objects with alpha-to-coverage materials are binned in the opaque pass, as they're fully order-independent. The `transparency_3d` example has been updated to feature an object with alpha to coverage. Happily, the example was already using MSAA. [order-independent transparency]: https://en.wikipedia.org/wiki/Order-independent_transparency ["Anti-aliased Alpha Test: The Esoteric Alpha To Coverage"]: https://bgolus.medium.com/anti-aliased-alpha-test-the-esoteric-alpha-to-coverage-8b177335ae4f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MIP-level scaling, which could be a preprocessing thing, can wait I suppose.
The article also mentions an issue with Unity's cascaded shadow mapping that I'm wondering if we are also affected by and need to address. But that can also be done in a follow-up. I would appreciate confirmation of whether it is an issue for us though. :)
@superdump I've changed the logic to fall back to alpha mask with a cutoff of 0.5 if MSAA is off. As for the Unity bug: Translated to Bevy concepts, the Unity issue is that if you use |
In the transparency example, when the alpha blended cube has an alpha of 0 the shadows disappear, but they remain there for the A2C cube. I think that should be handled the same way for both |
@IceSentry The shadow behavior for A2C now matches blend. |
Alright, just one final tiny nitpick, in the example, on the system that updates the alpha of all meshes. There should be a short description of what happens to a2c meshes. It should probably mention the thing you replied to me in discord about the limitation of MSAA samples |
@IceSentry Done. |
Alpha to coverage (A2C) replaces alpha blending with a hardware-specific multisample coverage mask when multisample antialiasing is in use. It's a simple form of order-independent transparency that relies on MSAA. "Anti-aliased Alpha Test: The Esoteric Alpha To Coverage" is a good summary of the motivation for and best practices relating to A2C.
This commit implements alpha to coverage support as a new variant for
AlphaMode
. You can supplyAlphaMode::AlphaToCoverage
as thealpha_mode
field inStandardMaterial
to use it. When in use, the standard material shader automatically applies the texture filtering method from "Anti-aliased Alpha Test: The Esoteric Alpha To Coverage". Objects with alpha-to-coverage materials are binned in the opaque pass, as they're fully order-independent.The
transparency_3d
example has been updated to feature an object with alpha to coverage. Happily, the example was already using MSAA.This is part of #2223, as far as I can tell.
Changelog
Added
AlphaMode
enum now supportsAlphaToCoverage
, to provide limited order-independent transparency when multisample antialiasing is in use.