-
Notifications
You must be signed in to change notification settings - Fork 943
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
Window alpha transparency support #687
Comments
…fixes iced-rs#272 wgpu would currently ignore the alpha: gfx-rs/wgpu#687 glow (and naively patched wgpu) requires premultiplied alpha, so if you don't multiply the RGB by the A right now, the semi-transparent color would be wrong (too bright). winit with_transparent doesn't seem necessary.
I would be fine with exposing the composite alpha mode |
As in the whole Swapchain creation is public API so this affects |
Is there an alternative to telling users what modes are available, and letting them select one? As for webgpu-headers - you are right, we'll need to expose it there as well, just like we expose the present modes. cc @Kangz |
I was thinking "pick the most common mode and handle conversions" but yeah, exposing everything to the user would be much easier. |
Can we have a brief investigation of what the compositing modes are and how they translate to the various APIs? I worry for example that on macOS the compositing mode might be a part of the CALayer so we'd be mutating that. Also are there any guarantees that we can support all compositing modes on all platforms, or does for example Vulkan give little guarantees so we need to have queries in webgpu.h for it? |
Agreed, would be great to have it!
Pretty sure we are already mutating
No |
…fixes iced-rs#272 wgpu would currently ignore the alpha: gfx-rs/wgpu#687 glow (and naively patched wgpu) requires premultiplied alpha, so if you don't multiply the RGB by the A right now, the semi-transparent color would be wrong (too bright). winit with_transparent doesn't seem necessary.
…fixes iced-rs#272 wgpu would currently ignore the alpha: gfx-rs/wgpu#687 glow (and naively patched wgpu) requires premultiplied alpha, so if you don't multiply the RGB by the A right now, the semi-transparent color would be wrong (too bright). winit with_transparent doesn't seem necessary.
…fixes iced-rs#272 wgpu would currently ignore the alpha: gfx-rs/wgpu#687 glow (and naively patched wgpu) requires premultiplied alpha, so if you don't multiply the RGB by the A right now, the semi-transparent color would be wrong (too bright). winit with_transparent doesn't seem necessary.
…fixes iced-rs#272 wgpu would currently ignore the alpha: gfx-rs/wgpu#687 glow (and naively patched wgpu) requires premultiplied alpha, so if you don't multiply the RGB by the A right now, the semi-transparent color would be wrong (too bright). winit with_transparent doesn't seem necessary.
Any updates on this? |
@atsuzaki I don't think anyone has been looking into this yet (unless @myfreeweb has a branch somewhere?), but please feel free to start looking into it if you'd like. An investigation into how to handle this on each backend and/or prototyping the changes with one or more backends would be great. |
I just have a hardcoded premultiplied mode, nothing smarter, no API or anything |
I've made a similar change with the let window = WindowBuilder::new()
.with_title("Rust by Example: WGPU!")
.with_decorations(false)
.with_transparent(true)
.build(&event_loop)
.unwrap(); color_states: &[
wgpu::ColorStateDescriptor {
format: sc_desc.format,
color_blend: wgpu::BlendDescriptor {
src_factor: wgpu::BlendFactor::SrcAlpha,
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
operation: wgpu::BlendOperation::Add
},
alpha_blend: wgpu::BlendDescriptor {
src_factor: wgpu::BlendFactor::One,
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
operation: wgpu::BlendOperation::Add
},
//color_blend: wgpu::BlendDescriptor::REPLACE,
//alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL
}
] let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[
wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color {
r: 0.005,
g: 0.005,
b: 0.01,
a: 0.5
}),
store: true
}
}
],
depth_stencil_attachment: None
}); config.composite_alpha_mode = hal::window::CompositeAlphaMode::PREMULTIPLIED; |
gfx-rs Metal backend needs to handle this better, I guess. |
@nyxtom Metal transparency support is coming in gfx-rs/gfx#3561 |
Transparent windows don't work for me either. Using Linux and Xorg. I ran the Vulkan validation layers and see the error below. My GPU is an RTX 2080 Ti, and transparent windows work with OpenGL things. Seems a little weird that the only supported mode on my GPU is
|
3561: [metal] use metal-rs github, implement transparency r=kvark a=kvark Adds an ability to make surfaces transparent on Metal. Related to gfx-rs/wgpu#687 (comment) Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
Still interested in a solution to this |
just wanted to express interest too. just like ryanw, transparency doesn't work for me either on linux/X11 with 1070Ti. |
just checking, but is this repo still the main one? i heard the repos were moved around. i will go make a new issue for transparency, if there's a new repo somewhere. |
just bumping here as its been a few months. but transparency in windows 10 is working. tested on
and wgpu master branch by just changing clear color to [0.0, 0.0, 0.0, 0.0] in the Load operation, and creating winit window with transparency enabled and making sure to have blend state to ALPHA_BLENDING. bunny mark example |
I might have realized this too late. but is there actually a point in exposing CompositeAlphaMode ? |
@coderedart is this Vulkan or D3D12? Have you only tested on nvidia GPUs? If this is Vulkan, something in your stack definitely violates the spec:
this clearly says that in opaque mode, there MUST NOT be any transparency. It works correctly on Mesa — |
I am making an egui app and used transparency on both windows and linux (1070ti) without any issues. I just cloned and ran the hello-triangle example from wgpu repo by just changing the clear color and enabling the transparency option for window, and it works perfectly.
as mentioned previously, i only have opaque bit mentioned in driver, so i thought vulkan drivers don't really care about niche things like this. and wgpu source definitely sets the opaque bit. I will check on windows with dx backend and report back. SECOND EDIT: in all these cases, i just changed the window builder to use transparency and renderpass clear color to transparent contant. didn't touch any other code, and just ran |
Yep, so D3D12 seems to be working correctly. (@coderedart could you please confirm that you get transparency on DX12 if you change the Looking at open source WSI implementations:
Conclusion: the opaque bit actually works correctly on Wayland and macOS (MoltenVK), and the similar bit seems to work on D3D12, but many other Vulkan implementations ignore it and INCORRECTLY let transparency work with |
none of the pre/post composite modes work on windows dx12 backend. and all of them work with transparency on vulkan backend (but i do get validation errors saying only opaque bit is supported, and i'm using unsupported bit with pre or post multiplied). the dx12 backend just crashes
OS:
nvidia driver version: 511.23 I have no idea if there's a dx12 equivalent of vulkaninfo which i can use to check supported CompositeModes. I hope mesa don't fix the bug xD this issue has been here for a long time, and if they fix it (especially as nvidia doesn't expose any other composite modes), there's no way to get transparency for vulkan now. I gotta go back to opengl 😭 |
No, the temporary way to get transparency for now is to just patch wgpu like I've been doing, and the real way is to make wgpu expose |
Thank you so much for investigating this and filing an upstream issue, @unrelentingtech ! Looking forward to hear from Mesa folks on it. |
@kvark in any case the "driver bug" is only that some drivers allow transparency when they shouldn't, it's not that big of a deal, just something to understand when people are saying "transparency already works". The original issue here is still that wgpu should give us access to this setting. |
Yes, I think we are aligned here. Just need a PR. |
hey folks! How's the progress on this topic? |
I think this can be closed. we now have |
Fixed by #2836 |
Two things I don't understand about the solution #2836:
The status quo seems like a half-solution:
|
@dhardy could you open a new issue with your thoughts to improve the status quo? |
…, fixes #272 wgpu would currently ignore the alpha: gfx-rs/wgpu#687 glow (and naively patched wgpu) requires premultiplied alpha, so if you don't multiply the RGB by the A right now, the semi-transparent color would be wrong (too bright). winit with_transparent doesn't seem necessary.
Is your feature request related to a problem? Please describe.
Currently, windows are hardcoded to be opaque:
so the
a
inwgpu::RenderPassColorAttachmentDescriptor
clear_color
doesn't do anything.Describe the solution you'd like
There should be support for the transparent modes. In particular, premultiplied mode should be handled, as it's the only one supported at least on my machine (using Mesa RADV driver for Radeon).
Additional context
Hardcoding
::PREMULTIPLIED
makes transparency work, but I actually have to multiply the colors by the alpha:The text was updated successfully, but these errors were encountered: