-
Notifications
You must be signed in to change notification settings - Fork 68
Add AlphaMode and transparency
#321
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
base: madsmtm/stride
Are you sure you want to change the base?
Conversation
| /// - macOS/iOS: Supported, but currently doesn't work with additive values (maybe only as the | ||
| /// root layer?). Make sure that components are `<= alpha` if you want to be cross-platform. |
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.
It looks like this currently:
I suspect that this may be an intentional limitation of transparency in the "root" / that goes through the top-level layer, perhaps as a form of security measure to avoid users reading contents of contents below the window in a shader or smth? But I'll need to investigate this further, might be possible to fix with IOSurface.
| /// The non-alpha channels are not expected to already be multiplied by the alpha channel; | ||
| /// instead, the compositor will multiply the non-alpha channels by the alpha channel during | ||
| /// compositing. | ||
| /// | ||
| /// Also known as "straight alpha". | ||
| /// | ||
| /// ## Platform Dependent Behavior | ||
| /// | ||
| /// - Web and macOS/iOS: Supported. | ||
| /// - Android, KMS/DRM, Orbital, Windows, X11: Not yet supported. | ||
| #[doc(alias = "Straight")] | ||
| #[doc(alias = "Unassociated")] | ||
| Postmultiplied, |
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.
What should we call this? Wikipedia uses "straight", wgpu uses PostMultiplied.
| /// root layer?). Make sure that components are `<= alpha` if you want to be cross-platform. | ||
| /// - Android, Orbital, Web, Windows and X11: Not yet supported. | ||
| #[doc(alias = "Associated")] | ||
| Premultiplied, |
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.
I elected to call this Premultiplied instead of PreMultiplied (not camel casing), because most of the references I could find on the interwebs seemed to prefer to write it in one word instead of hyphenating as "pre-multiplied".
b636a35 to
21e4a90
Compare
ebf31d1 to
4dd27ed
Compare
4dd27ed to
304f431
Compare
Add:
This fixes #17 and prepares for #98 / #317.
As noted in the transparency issue, it is important to make a distinction between straight and premultiplied alpha. The former can be easier to work with, but the latter is often what's actually supported by compositors.
One mode that is a bit odd here is
Opaque, but it's necessary for the Web backend, because that platform doesn't support zero-copy RGBX, the alpha channel is always read (at least from what I could figure out). Adding this mode (and requiring that alpha channel to be 255) fixes #207.The implementation of these modes for each platform is as follows (I have tested all these):
Opaque,Ignored,PremultipliedandPostmultipliedenabled.Premultipliedclamps the additive variants, but this might change with theIOSurfaceimpl.Opaque,Ignored,Premultiplied.OpaqueandPostmultiplied.Premultipliedcan be supported in the future withImageBitmapIIUC.Premultiplied, but I couldn't get it to work properly, so only did part of it, I'm not too familiar with Windows. I suspect it might also need something like fixed window transparency winit#2503.Premultipliedcould be supported.We could fairly easily implement a conversion step to support postmultiplied alpha when premultiplied is supported by the backend, but I'd like to migrate towards a more efficient design where each backend always do zero-copying, so I haven't done that.
Expected behaviour
I've created an example
transparency.rs, which renders a few different shades of orange and yellow. The expected result are as follows:Opaque/IgnoredPremultipliedPostmultiplied