pixels icon indicating copy to clipboard operation
pixels copied to clipboard

Draw on a transparent window

Open Proxtx opened this issue 3 years ago • 13 comments
trafficstars

I created a transparent window bu as soon as I call the render function the background turns black

Proxtx avatar May 08 '22 15:05 Proxtx

I believe this is https://github.com/gfx-rs/wgpu/issues/687

We have supported the alpha channel since version 0.9.0 in #236 and it was made configurable in #260.

parasyte avatar May 08 '22 17:05 parasyte

so basically it's impossible draw transparent pixels

Proxtx avatar May 08 '22 17:05 Proxtx

No, it is not impossible. Read the linked wgpu thread. It is awaiting a PR to make the composite mode configurable. Once that is released, I can upgrade it and configure the composite mode to fully support alpha blending on all environments.

parasyte avatar May 08 '22 17:05 parasyte

ah so i just have to wait ok....

Proxtx avatar May 08 '22 17:05 Proxtx

Any workarounds?

DevAlone avatar May 23 '22 00:05 DevAlone

The tasks for the wgpu side are described in the linked ticket. We can't do anything here until that is solved. Until these issues are taken care of, transparency in a transparent window may work depending on the exact environment due to various existing bugs in different levels of the graphics stack.

parasyte avatar May 23 '22 02:05 parasyte

Transparent draw works fine here image

winit window builder:

 WindowBuilder::new()
            .with_decorations(false)
            .with_transparent(true)
            ...

pixels clear color:

pixels.set_clear_color(pixels::wgpu::Color::TRANSPARENT);

nathanosoares avatar Jun 08 '22 11:06 nathanosoares

Doing some cleanup on old tickets. This one can probably be closed since the upstream issue has been resolved.

Also, according to the docs, CompositeAlphaMode with support for blending is not guaranteed to be available on every surface. And indeed on Windows 11 I only have CompositeAlphaMode::Opaque available.

parasyte avatar Mar 24 '23 07:03 parasyte

I'm sorry to comment on a closed issue, but has anyone had success getting transparency to work on a Windows system? I haven't had luck getting it to work I'm afraid.

I have tried setting the clear_color to TRANSPARENT and the wgpu issue seems to be closed as though it was resolved.

I also tried a local fork of pixels where I hardcode the alpha_mode to various values. The modes PreMultiplied, PostMultiplied and Inherit all lead to a validation error on Windows.

Caused by:
    Requested alpha mode Inherit is not in the list of supported alpha modes: [Opaque]

This issue appears to be related: https://github.com/gfx-rs/wgpu/issues/5150

Thanks heaps Fotis

fgimian avatar Feb 07 '24 21:02 fgimian

I think what's missing is a way to override the CompositeAlphaMode. As you can see in https://github.com/parasyte/pixels/blob/befb84aea80179377554e22fa9350f02b0b2aad6/src/builder.rs#L322 it always uses the surface's preferred mode. One thing that can be done is adding a builder method to set an override, and as long as the surface is capable of using the override, it should take precedence.

parasyte avatar Feb 07 '24 21:02 parasyte

I also tried a local fork of pixels where I hardcode the alpha_mode to various values. The modes PreMultiplied, PostMultiplied and Inherit all lead to a validation error on Windows.

Ah, yes this is the problem I had when I wrote https://github.com/parasyte/pixels/issues/274#issuecomment-1482344584. Only Opaque is supported on my setup, too.

parasyte avatar Feb 07 '24 21:02 parasyte

Tracking upstream: https://github.com/gfx-rs/wgpu/issues/3486

parasyte avatar Feb 07 '24 21:02 parasyte

I also tried a local fork of pixels where I hardcode the alpha_mode to various values. The modes PreMultiplied, PostMultiplied and Inherit all lead to a validation error on Windows.

Ah, yes this is the problem I had when I wrote #274 (comment). Only Opaque is supported on my setup, too.

Yep, I think that's really the root cause of this one. It likely is more of a wgpu problem, but would be great if we could track it here too.

Thanks so much for the reply and help 😄 Fotis

fgimian avatar Feb 07 '24 21:02 fgimian