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

ViewportOwned overrides viewport WindowBg alpha #3979

Closed
slotthhy opened this issue Mar 28, 2021 · 3 comments
Closed

ViewportOwned overrides viewport WindowBg alpha #3979

slotthhy opened this issue Mar 28, 2021 · 3 comments

Comments

@slotthhy
Copy link

Version/Branch of Dear ImGui:

Version: 1.82
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_dx11.cpp + imgui_impl_win32.cpp
Compiler: MSVC
Operating System: win10

My Issue/Question:

I've been hacking away at trying to get alpha compositing on viewports working in a custom backend (platform and renderer) for a bit, but I thought I'd try to implement it into the win32 example impl first in order to be able to port it over.

Using the existing ImGui_ImplWin32_EnableAlphaCompositing function, I can set any window to enable alpha compositing. Setting the clear color to the WindowBg style color in the renderer backend and disabling NoRendererClear like in #2766 was all I assumed I'd need past that. However, even if WindowBg alpha was below 255 and that change was reflected in other windows in the main viewport, it would not change the alpha of windows in other viewports. It seems as though this segment

if (window->ViewportOwned)
{
    // No alpha
    bg_col = (bg_col | IM_COL32_A_MASK);
    if (is_docking_transparent_payload)
        window->Viewport->Alpha *= DOCKING_TRANSPARENT_PAYLOAD_ALPHA;
}

prevents WindowBg alpha from ever affecting non main-viewport windows.

I understand alpha compositing is experimental - but I wanted to point this out in case others encounter it or so it does not get overlooked in further implementation.

Screenshots/Video

With the above lines present in imgui.cpp:
image

The same implementation, but with the line bg_col = (bg_col | IM_COL32_A_MASK); commented out:
image

Standalone, minimal, complete and verifiable example:
In imgui_impl_dx11.cpp, in ImGui_ImplDX11_RenderWindow():
Set the clear color
ImVec4 clear_color = ImGui::GetStyle().Colors[ImGuiCol_WindowBg];
in my case, I also had to comment the NoRendererClear check.

In imgui_impl_win32.cpp, in ImGui_Impl32_CreateWindow():
After calling CreateWindowEx, call ImGui_ImplWin32_EnableAlphaCompositing(data->Hwnd);

In this state, if you run the demo, remove a window from the main viewport to create a new viewport, even though we are enabling alpha compositing and clearing our render target with the correct alpha, the window is not transparent when reducing the alpha of WindowBg in the style editor.

Comment out the line mentioned earlier, bg_col = (bg_col | IM_COL32_A_MASK); and run again. The WindowBg alpha value will be reflected as expected in viewport windows.

Thanks!

@ocornut
Copy link
Owner

ocornut commented Mar 29, 2021

Hmm, it feels like you arrived at the same conclusion and change as #2766 which you linked to?
It does

if (!(g.ConfigFlagsCurrFrame & ImGuiConfigFlags_TransparentBackbuffers))
    bg_col = (bg_col | IM_COL32_A_MASK);

@slotthhy
Copy link
Author

You are correct! It seems I missed that since it uses a config flag that hasn't been implemented yet. Hopefully that will be implemented eventually in one way or another. Thank you!

@ocornut
Copy link
Owner

ocornut commented Mar 29, 2021

I'll close this as "sort of duplicate" of #2766 but having the thread linked and index I'll be able to go back to this when we eventually decide of a design. I think we may be able to provide just enough in the core library to facilitate this, even if we don't immediately support all of it in our backends.

@ocornut ocornut closed this as completed Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants