Skip to content

Fixing windows transparent background - #4835

Open
Supergames207 wants to merge 3 commits into
rust-windowing:masterfrom
Supergames207:master
Open

Supergames207 wants to merge 3 commits into
rust-windowing:masterfrom
Supergames207:master

Conversation

@Supergames207

Copy link
Copy Markdown

When working with transparent apps on windows, a white rectangule could show up. Same issue as n1ght-hunter@06bf39c

  • Tested on all platforms changed (only windows)
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality

When working with transparent apps it could cause a white rectangule to show up. Same issue as n1ght-hunter@06bf39c
@Murmele

Murmele commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Hi, how did you reproduce it? If I use the popup example and colorize the window I see it transparent:
grafik

@Supergames207

Supergames207 commented Nov 12, 2026 •

Copy link
Copy Markdown
Author

@Murmele First of all thank you for taking your time.
I'm using winit and wgpu (DX12 adapter) on windows and the background isn't getting cleaned.
It actually works while vscode is opened but once I switch windows a gross white rectangle appears

image

I'm creating the window with impl ApplicationHandler for App {

fn resumed(&mut self, event_loop: &ActiveEventLoop) {
		// let monitor = event_loop.primary_monitor().expect("Couldn't get primary monitor");

		let mut window_attributes = Window::default_attributes();
		// window_attributes = window_attributes.with_fullscreen(Some(winit::window::Fullscreen::Borderless(None)));
		window_attributes = window_attributes.with_transparent(true).with_title("WgpuTest").with_decorations(false);
		window_attributes = window_attributes.with_window_level(WindowLevel::AlwaysOnTop);
		window_attributes = window_attributes.with_maximized(true);
		
		let window = event_loop.create_window(window_attributes).expect("Couldn't create window");
		
		let cursor_hittest = window.set_cursor_hittest(false);

		if let Err(error) = cursor_hittest{
			panic!("Couldn't set cursor hittest to false. Error : {:?}", error)
		}

		let arch = Arc::new(window);
		
		let state = pollster::block_on(State::new(arch.clone(), event_loop.owned_display_handle(), self.proxy.clone()));

		self.state = Some(state);

	}

This part will be about the wgpu side. I set the alpha_mode to config.alpha_mode = wgpu::CompositeAlphaMode::PreMultiplied; then everyframe I supossedly clean the background with

let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
                label: Some("main pass"),
                color_attachments: &[Some(wgpu::RenderPassColorAttachment {
                    view: &view,
                    depth_slice: None,
                    resolve_target: None,
                    ops: wgpu::Operations {
                        load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT),
                        store: wgpu::StoreOp::Store,
                    },
                })],
                ..Default::default()
            });

and then apply a shader to 2 triangles that cover up the whole scene.
The important thing is that when I set each fragment's transparency to either 1 or 0 the white rectangle isn't visible but if it's somewhere in the middle it appears quite grossly. This repo shows the same issue, https://github.com/n1ght-hunter/wgpu-transparency, this was actually where I got the solution but they couldn't merge it onto the winit so I thought I could try

@Murmele

Murmele commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

@Murmele First of all thank you for taking your time. I'm using winit and wgpu (DX12 adapter) on windows and the background isn't getting cleaned. It actually works while vscode is opened but once I switch windows a gross white rectangle appears
image

I'm creating the window with impl ApplicationHandler for App {

fn resumed(&mut self, event_loop: &ActiveEventLoop) {
		// let monitor = event_loop.primary_monitor().expect("Couldn't get primary monitor");

		let mut window_attributes = Window::default_attributes();
		// window_attributes = window_attributes.with_fullscreen(Some(winit::window::Fullscreen::Borderless(None)));
		window_attributes = window_attributes.with_transparent(true).with_title("WgpuTest").with_decorations(false);
		window_attributes = window_attributes.with_window_level(WindowLevel::AlwaysOnTop);
		window_attributes = window_attributes.with_maximized(true);
		
		let window = event_loop.create_window(window_attributes).expect("Couldn't create window");
		
		let cursor_hittest = window.set_cursor_hittest(false);

		if let Err(error) = cursor_hittest{
			panic!("Couldn't set cursor hittest to false. Error : {:?}", error)
		}

		let arch = Arc::new(window);
		
		let state = pollster::block_on(State::new(arch.clone(), event_loop.owned_display_handle(), self.proxy.clone()));

		self.state = Some(state);

	}

This part will be about the wgpu side. I set the alpha_mode to config.alpha_mode = wgpu::CompositeAlphaMode::PreMultiplied; then everyframe I supossedly clean the background with

let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
                label: Some("main pass"),
                color_attachments: &[Some(wgpu::RenderPassColorAttachment {
                    view: &view,
                    depth_slice: None,
                    resolve_target: None,
                    ops: wgpu::Operations {
                        load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT),
                        store: wgpu::StoreOp::Store,
                    },
                })],
                ..Default::default()
            });

and then apply a shader to 2 triangles that cover up the whole scene. The important thing is that when I set each fragment's transparency to either 1 or 0 the white rectangle isn't visible but if it's somewhere in the middle it appears quite grossly. This repo shows the same issue, https://github.com/n1ght-hunter/wgpu-transparency, this was actually where I got the solution but they couldn't merge it onto the winit so I thought I could try

Thanks for clarifying. On my side the softrenderer is used and because of that it might not happen. Can you fix the ci?

@Supergames207

Copy link
Copy Markdown
Author

@Murmele I think I fixed it, I'm quite new to this so I don't really know. There are some failed checks but I don't see any problem, they passed before?

@Murmele

Murmele commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

@Murmele I think I fixed it, I'm quite new to this so I don't really know. There are some failed checks but I don't see any problem, they passed before?

@Supergames207 thanks for fixing. The windows build seems not to be related to your PR. @ogoffart could you retrigger?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants