godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.91k stars 21.14k forks source link

Small transparency(?) issue on the corners of tooltips. #65231

Closed Mickeon closed 2 years ago

Mickeon commented 2 years ago

Godot version

v4.0.alpha.custom_build [c6fd311da]

System information

Windows 10

Issue description

This is very minor but now I can't un-see it. image image

They bear the same colour as the Default Clear Color:

image

Of note is that, this is probably because popups are set up to be is slightly transparent (notice the colour hue shift in the image above).

Steps to reproduce

Hover on anything that would display a tooltip,

Minimal reproduction project

No need.

Calinou commented 2 years ago

Windows can't have per-pixel transparency anymore in 4.0, so the only way to fix this is to make corners for tooltips non-rounded (like https://github.com/godotengine/godot/pull/59045).

Mickeon commented 2 years ago

Would it ever be possible to bring per-pixel transparency back or is it a massive performance or maintenance burden?

RedMser commented 2 years ago

Would it ever be possible to bring per-pixel transparency back

@Mickeon I managed to make a custom build that got it working for me, but I can imagine there's some reasons why it's not implemented this way in master.

I would make a PR for it if I understood the implications better 👀

Mickeon commented 2 years ago

That's actually pretty cool, in theory.

To quote Calinou from the mentioned PR:

PopupMenus use separate windows by default in the editor, and windows no longer support per-pixel transparency for now in 4.0. Even if per-pixel transparency was reimplemented, we can't assume that it'll always work in practice (e.g. when compositing is disabled).

So the end of that sentence may be reason for it? I mean, it wouldn't hurt to make a PR and waiting for an explanation at the very least, but at the same time, a solution may need to be found for systems that do not support it...

Calinou commented 2 years ago

I remember @bruvzg saying that per-pixel transparency is currently impossible to implement in Vulkan due to missing extensions, but it can be done with the OpenGL backend.

bruvzg commented 2 years ago

Well it was a long time ago, and at least MoltenVK on macOS does support it now, so it should be re-evaluated:

For OpenGL: support was re-implemented with OpenGL backend to macOS display server, I'm not sure if it was for other platforms (X11 seems to have at least some part of it, and Windows seems to be missing all the transparency related code).

Here's a patch to enable transparency support (on macOS works with both Vulkan and OpenGL, not tested on other platforms):

diff --git a/drivers/vulkan/vulkan_context.cpp b/drivers/vulkan/vulkan_context.cpp
index b52179b4f3..99ef57abae 100644
--- a/drivers/vulkan/vulkan_context.cpp
+++ b/drivers/vulkan/vulkan_context.cpp
@@ -1706,10 +1706,10 @@ Error VulkanContext::_update_swap_chain(Window *window) {
    // Find a supported composite alpha mode - one of these is guaranteed to be set.
    VkCompositeAlphaFlagBitsKHR compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
    VkCompositeAlphaFlagBitsKHR compositeAlphaFlags[4] = {
-       VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
        VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR,
        VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR,
        VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR,
+       VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
    };
    for (uint32_t i = 0; i < ARRAY_SIZE(compositeAlphaFlags); i++) {
        if (surfCapabilities.supportedCompositeAlpha & compositeAlphaFlags[i]) {
diff --git a/main/main.cpp b/main/main.cpp
index a0d2f594ac..d37c2610b3 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -1557,10 +1557,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
    OS::get_singleton()->_allow_hidpi = GLOBAL_DEF("display/window/dpi/allow_hidpi", true);

    // FIXME: Restore support.
-#if 0
-   //OS::get_singleton()->_allow_layered = GLOBAL_DEF("display/window/per_pixel_transparency/allowed", false);
-   video_mode.layered = GLOBAL_DEF("display/window/per_pixel_transparency/enabled", false);
-#endif
+   OS::get_singleton()->_allow_layered = GLOBAL_DEF("display/window/per_pixel_transparency/allowed", false);

    if (editor || project_manager) {
        // The editor and project manager always detect and use hiDPI if needed

In the case of Vulkan, it depends on a driver supporting any alpha composition mode other than VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR.