-
-
Notifications
You must be signed in to change notification settings - Fork 50
Transparent window example #775
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: main
Are you sure you want to change the base?
Conversation
|
If someone wants to test it, here is the |
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.
Note that this file is overwritten using the one from wgpu-native.
The long-term solution would be to contribute this to wgpu-native. A short-term solution could be to add a 3d .h file that we maintain.
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 am not very familiar with Rust, I am just trying to modify it by imitating existing code, 😅 .
I plan to submit the PR to the wgpu-native repo after testing and confirming that this modification is correct.
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.
For the record, this is not Rust, but a C header file.
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.
Yes, what I mean is that it is part of this commit: panxinmiao/wgpu-native@dd0f4d6
|
This is a fun feature, reminds me of shader glass: https://github.com/mausimus/ShaderGlass, not sure how they access the swap chain texture below. side note: I believe transparent canvas works in pyodide already.. Might try that later. |
If I’m not mistaken, the Pyodide environment likely uses an off-screen style rendering setup, where the actual render target is a custom WGPU texture framebuffer rather than a system surface swapchain texture. As a result, transparency should be supported naturally. |
Yeah, it's really just a texture provided by the browser. Which is then composited by the browser with the other content to produce the final browser content. Which is actually stored in a texture, provided by the OS, and which is then composited with the other windows on the desktop, and then rendered to screen :) |
|
I found that when using borderless mode with: glfw.window_hint(glfw.DECORATED, False)the transparent window works perfectly. Video_2025-11-19_164456.mp4However, when the window is decorated, the initial white background issue persists. I’ve tried various approaches, but it seems impossible to resolve so far. Additionally, it seems that the Qt backend does not support transparent windows. canvas.setAttribute(QtCore.Qt.WidgetAttribute.WA_TranslucentBackground, True)Similar to the GLFW case, the initial region shows a white background, but the area after resizing remains non-transparent and appears black instead: Video_2025-11-19_165451.mp4And when I add: canvas.setWindowFlags(QtCore.Qt.FramelessWindowHint)(which I believe corresponds to the application runs but no window content is visible at all. |
I recently revisited the implementation of transparent windows and noticed that in the wgpu documentation
(https://docs.rs/wgpu-types/27.0.1/wgpu_types/instance/struct.Dx12BackendOptions.html
),
the D3D12 backend provides a presentation_system option that allows selecting a SwapchainKind. According to the documentation, using DxgiFromVisual enables transparent window support.
However, wgpu-native does not currently expose this configuration and instead always uses DxgiFromHwnd. I modified the wgpu-native code locally and built a customized version (https://github.com/panxinmiao/wgpu-native/tree/Dx12SwapchainKind) for testing, and the transparent window functionality works correctly.
The only issue is that the initial window content leaves a white background artifact. As shown in the video:
Video_2025-11-18_171932.mp4
After resizing the window, the newly exposed regions become properly transparent, but the original region (the part not affected by resizing) keeps showing a white background.
It seems like the leftover data comes from the system-provided initial window framebuffer, which is outside the control of wgpu. In the wgpu render loop, each frame performs a clear operation (clear_value = (0, 0, 0, 0)), so in theory the entire surface should be cleared, but the initial white region remains unaffected.
I have not yet found a solution to this issue.
Additionally, we may need to consider adding API support for transparent windows and transparent rendering in RenderCanvas and pygfx.
Relaated: pygfx/rendercanvas#29