Skip to content
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

Re-enable per-pixel transparency support on Linux, macOS, and Windows. #65283

Merged
merged 1 commit into from
Sep 3, 2022

Conversation

bruvzg
Copy link
Member

@bruvzg bruvzg commented Sep 3, 2022

Seems like new Vulkan drivers have support for transparency, so it can be re-enabled.

So far I have tested it on Windows (with NVIDIA RTX 2070 Super), Linux (Fedora 36, NVIDIA RTX 2070 Super) and M1 mac.

To use:

  • Enable display/window/per_pixel_transparency/allowed in the project settings.
  • Disable viewport background get_viewport().transparent_bg = true.
  • Set transparent flag for a window DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_TRANSPARENT, true, window_id).

Transparency for the splash screen will probably require some additional changes.

Fixes #50626

@TokisanGames
Copy link
Contributor

Would this help anything listed in this issue #63675?

@fire
Copy link
Member

fire commented Sep 3, 2022

Wanted to repost that @you-win depends on this transparent desktop windows feature for https://github.com/virtual-puppet-project/vpuppr

@bruvzg

This comment was marked as outdated.

@bruvzg bruvzg marked this pull request as ready for review September 3, 2022 16:28
@bruvzg bruvzg requested review from a team as code owners September 3, 2022 16:28
@bruvzg
Copy link
Member Author

bruvzg commented Sep 3, 2022

Would this help anything listed in this issue #63675?

Actually, it's completely unrelated, so ignore my previous comment, I was looking at a wrong tab. This is for enabling semi-transparent windows, it's not affecting rendering in any way.

@akien-mga akien-mga merged commit 042050a into godotengine:master Sep 3, 2022
@akien-mga akien-mga modified the milestones: 4.x, 4.0 Sep 3, 2022
@akien-mga
Copy link
Member

Thanks!

@MarianoGnu
Copy link
Contributor

MarianoGnu commented Apr 13, 2023

I tested the example project, turned out it had the transparent_background flag disabled and made me think the movie maker was working wrong, but it indeed recorded with transparent background. However the window itself does not show with transparent background and renders the skybox when running, this behavior is quite unexpected

EDIT: i am updating my gpu drivers right now, uldate later

@Calinou
Copy link
Member

Calinou commented Apr 13, 2023

I tested the example project, turned out it had the transparent_background flag disabled and made me think the movie maker was working wrong, but it indeed recorded with transparent background. However the window itself does not show with transparent background and renders the skybox when running, this behavior is quite unexpected

Which operating system are you using? On Linux, you must have composting enabled in your window manager for transparency to be visible. This is the case by default on most desktop environments, but not always – especially on "lightweight" ones such as Xfce or LXQt.

@MarianoGnu
Copy link
Contributor

MarianoGnu commented Apr 13, 2023

I just updated my nvidia drivers to confirm it is not a driver issue, the problem still persists
System Information:
Godot Engine v4.0.2.stable.official.7a0977ce2 - https://godotengine.org
Vulkan API 1.3.236 - Forward+ - Using Vulkan Device #1: NVIDIA - NVIDIA GeForce RTX 3060 Laptop GPU
Windows 11 Home, 64 bits

@Calinou
Copy link
Member

Calinou commented Apr 13, 2023

I wonder if the fact this is hybrid graphics (NVIDIA Optimus) causes an issue with per-pixel transparency. Try updating the Intel integrated graphics' drivers as well (from Intel, not your laptop OEM or Windows Update).

@MarianoGnu
Copy link
Contributor

I disabled the nvidia drivers from Device manager to force the use of Intel GPU (without updating it), as result, i have per pixel transparency, but not as expected, instead environment is half transparent
image

@MarianoGnu
Copy link
Contributor

Changing the environment to use clear color instead of skubox seems to work for the usecase of the test example, except it affects lighting a lot, in my personal project i intend to use an skybox for affecting lighting on 3D world
image

@MarianoGnu
Copy link
Contributor

MarianoGnu commented Apr 13, 2023

when using a non fully black color as clear color the issue appears again, it seems windows is using grayscale for transparency instead of alpha, or maybe is using AGBR instead of RGBA format

image

@GK-GreyGhost
Copy link
Contributor

GK-GreyGhost commented Apr 17, 2023

I'm running into the problem even with a fully black clear color, its seems the godot window blend mode is some sort of additive blend? if the window behind godot is black it becomes opaque, 50% gray is transparent and white almost completely disappears
image
this image is a default cube in godot in front of affinity designer (graphics editing program) showing a black page with a gray and white stripe. happy to upload a video if needed

edit: going to investigate the source tomorrow starting with VkCompositeAlphaFlagBitsKHR

Windows 10, Godot 4.0.2

@Calinou
Copy link
Member

Calinou commented Apr 17, 2023

as result, i have per pixel transparency, but not as expected, instead environment is half transparent

This is because Godot uses premultiplied alpha for transparent windows. Fully transparent pixels use additive blending, fully opaque pixels use "mix" blending. This means that fully transparent non-black pixels will be visible, but with additive blending.

Premultiplied alpha should be preferred over straight alpha, as it allows for antialiased borders to look correct. (You can check this by having an unshaded white cube in a transparent window, then moving this transparent window on a white background. Make sure to enable MSAA to some degree.)

@GK-GreyGhost
Copy link
Contributor

Thank you @Calinou, that solved it for me, 1 material in the scene was "corrupting" everything else by having subsurface scattering turned on

image
image

I think this is a bug? if not could we add a warning? "SSS causes scene to use additive blending with per-pixel transparency enabled"

@Calinou
Copy link
Member

Calinou commented Apr 17, 2023

@GK-GreyGhost The SSS issue may be a bug. Please open an issue with a minimal reproduction project attached.

@GK-GreyGhost
Copy link
Contributor

@Calinou copy that, I will shortly, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Per-pixel transparency missing in Godot 4.0/master
7 participants