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

Fix window holes behind transparent objects #1021

Merged
merged 1 commit into from
Sep 4, 2021

Conversation

akhilman
Copy link
Contributor

@akhilman akhilman commented Sep 2, 2021

Without this change, the transparent objects composed over the opaque
background creates the transparency of the entire window through which
the desktop wallpaper could be seen.
This problem manifested itself with glow backend and wayland compositor
(gnome).

This patch completely eliminates this problem. With it, the final image
produced by glow backend corresponds to the image produced by the wgpu
backend.

Fixes #1018

Without this change, the transparent objects composed over the opaque
background creates the transparency of the entire window through which
the desktop wallpaper could be seen.
This problem manifested itself with glow backend and wayland compositor
(gnome).

This patch completely eliminates this problem. With it, the final image
produced by glow backend corresponds to the image produced by the wgpu
backend.

Fixes iced-rs#1018
@akhilman
Copy link
Contributor Author

akhilman commented Sep 2, 2021

The glBlendFunc sets same function for all channels including alpha. Suppose we have glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA), background colour (1.0, 1.0, 1.0, 1.0) as (R. G, B, A) and foreground colour (0,5, 0,5, 0,5, 0,5). For all channels we will have 0.5 * 0.5 + 1.0 * (1.0 - 0.5) which equals to 0.75. So overall composition is transparent and we have hole in the window.

With glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA) function for alpha channel will be 0.5 * 1.0 + 1.0 * (1.0 - 0.5) which equals to 1.0, so overall composition is opaque.

@hecrj hecrj added the bug Something isn't working label Sep 4, 2021
@hecrj hecrj added this to the 0.4.0 milestone Sep 4, 2021
Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

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

Good catch!

I noticed transparent colors not completely matching when comparing backends and couldn't exactly pin-point why. Thank you! 🎉

@hecrj hecrj merged commit 589f68d into iced-rs:master Sep 4, 2021
@oknozor
Copy link
Contributor

oknozor commented Oct 13, 2021

I just tested this on latest master :
image
I think this also closes #1021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Glow canvas handles transparency differently from wgpu
3 participants