iced icon indicating copy to clipboard operation
iced copied to clipboard

Transparency doesnt work with wgpu backend

Open oknozor opened this issue 5 years ago • 9 comments

Seems transparency does not work on wgpu, is this normal ? I would happily use glow, but fonts are a bit aliased. Is there a workaround this ?

  • features = ["wgpu", "default_system_font", "debug", "palette" ]

screenshot-2020-11-05-T17-06-13-0100

  • features = ["glow", "glow_default_system_font", "debug", "palette" ]

screenshot-2020-11-05-T17-05-54-0100

oknozor avatar Nov 05 '20 16:11 oknozor

See https://github.com/hecrj/iced/pull/371 / https://github.com/gfx-rs/wgpu/issues/687

tl;dr for now wgpu hardcodes opaque mode, so it needs to be patched. You can use my fork:

[patch.crates-io]
# patch: transparency (config.composite_alpha_mode = hal::window::CompositeAlphaMode::PREMULTIPLIED)
wgpu-core  = { git = "https://github.com/myfreeweb/wgpu", branch = "v0.6-alpha" }
wgpu-types = { git = "https://github.com/myfreeweb/wgpu", branch = "v0.6-alpha" }

valpackett avatar Nov 07 '20 21:11 valpackett

See #371 / gfx-rs/wgpu#687

tl;dr for now wgpu hardcodes opaque mode, so it needs to be patched. You can use my fork:

[patch.crates-io]
# patch: transparency (config.composite_alpha_mode = hal::window::CompositeAlphaMode::PREMULTIPLIED)
wgpu-core  = { git = "https://github.com/myfreeweb/wgpu", branch = "v0.6-alpha" }
wgpu-types = { git = "https://github.com/myfreeweb/wgpu", branch = "v0.6-alpha" }

I've followed this & used your fork, modified the examples, but the transparency still seems not working on macOS 11.0.1 Big Sur:

diff --git a/Cargo.toml b/Cargo.toml
index 6221ae4..6bbfb22 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -100,3 +100,8 @@ iced_web = { version = "0.3", path = "web" }
 [package.metadata.docs.rs]
 rustdoc-args = ["--cfg", "docsrs"]
 features = ["image", "svg", "canvas"]
+
+[patch.crates-io]
+# patch: transparency (config.composite_alpha_mode = hal::window::CompositeAlphaMode::PREMULTIPLIED)
+wgpu-core  = { git = "https://github.com/myfreeweb/wgpu", branch = "v0.6-alpha" }
+wgpu-types = { git = "https://github.com/myfreeweb/wgpu", branch = "v0.6-alpha" }
\ No newline at end of file
diff --git a/examples/clock/Cargo.toml b/examples/clock/Cargo.toml
index c6e3237..b2a819a 100644
--- a/examples/clock/Cargo.toml
+++ b/examples/clock/Cargo.toml
@@ -7,4 +7,4 @@ publish = false
 
 [dependencies]
 iced = { path = "../..", features = ["canvas", "tokio", "debug"] }
-chrono = "0.4"
+chrono = "0.4"
\ No newline at end of file
diff --git a/examples/clock/src/main.rs b/examples/clock/src/main.rs
index b317ac0..3a52ff2 100644
--- a/examples/clock/src/main.rs
+++ b/examples/clock/src/main.rs
@@ -1,3 +1,5 @@
+
 use iced::{
     canvas::{self, Cache, Canvas, Cursor, Geometry, LineCap, Path, Stroke},
     executor, time, Application, Color, Command, Container, Element, Length,
@@ -6,6 +8,11 @@ use iced::{
 
 pub fn main() -> iced::Result {
     Clock::run(Settings {
+	window: iced::window::Settings{
+	    decorations: false,
+	    transparent: true,
+	    ..iced::window::Settings::default()
+	},
         antialiasing: true,
         ..Settings::default()
     })
@@ -32,7 +39,7 @@ impl Application for Clock {
                 now: chrono::Local::now(),
                 clock: Default::default(),
             },
-            Command::none(),
+            Command::none()
         )
     }
 
@@ -55,6 +62,10 @@ impl Application for Clock {
         Command::none()
     }
 
+    fn background_color(&self) -> Color {
+	Color::TRANSPARENT
+    }
+

image

But switching to glow works:

diff --git a/examples/clock/Cargo.toml b/examples/clock/Cargo.toml
index c6e3237..fce87f2 100644
--- a/examples/clock/Cargo.toml
+++ b/examples/clock/Cargo.toml
@@ -6,5 +6,5 @@ edition = "2018"
 publish = false
 
 [dependencies]
-iced = { path = "../..", features = ["canvas", "tokio", "debug"] }
-chrono = "0.4"
+iced = { path = "../..", features = ["glow", "glow_canvas", "tokio", "debug"] }
+chrono = "0.4"

image

code-monad avatar Dec 10 '20 10:12 code-monad

Is this still an issue in the latest versions of wgpu?

hecrj avatar Jan 19 '22 11:01 hecrj

Yes, you can see that https://github.com/gfx-rs/wgpu/issues/687 is still open. I still use a forked wgpu with a one-line patch for this.

valpackett avatar Jan 19 '22 13:01 valpackett

I'm still having this same issue on macOS with the latest iced and wgpu, although it looks like wgpu merged that PR. Any advice on a fix / workaround?

Thanks!

LoganWalls avatar May 03 '23 21:05 LoganWalls

Up! Same here

vaaleyard avatar Jun 09 '23 14:06 vaaleyard

I believe I'm hitting this as well - here is a small sample project:

  • https://github.com/leoshimo/commandbar_iced/blob/38c05acf51a8534cce524b45b19b8c572cbc5054/src/main.rs

I've set application + children to have transparent background, but seeing a black box being rendered: Screenshot 2023-08-15 at 2 39 26 PM

UPDATE(8/15): Rolled back to see if Iced 0.9.0 works - same issue. UPDATE(8/16): I was able to avoid window transparency altogether by taking a different approach - project has been updated to use new approach, but updated the URL above as viable sample code that illustrates issue.

leoshimo avatar Aug 15 '23 18:08 leoshimo

Just another data point, on my system transparency works for WGPU_BACKEND=gl but not WGPU_BACKEND=vulkan.

matze avatar Sep 12 '23 21:09 matze

It seems the linked PR has been closed, so perhaps a fix can be merged ?

davawen avatar Nov 03 '23 22:11 davawen