Open zhangliang07 opened 1 month ago
This unfortunately is a much more complicated issue than it looks.
The core problem is that ImGui samples due to historic reasons perform alpha blending in Gamma space, which is mathematically incorrect.
Diligent performs blending in linear space, but to make ImGui colors look similar to what everyone expects, most notable, to make color pickers look correctly, it has to perform some shenanigans with colors.
In particular, the colors get alpha-premultiplied, otherwise all text will be broken.
The solution to your problem would've been to set colors to 2.0
, but ImGui clamps color channels to 1.0
.
This unfortunately is a much more complicated issue than it looks. The core problem is that ImGui samples due to historic reasons perform alpha blending in Gamma space, which is mathematically incorrect. Diligent performs blending in linear space, but to make ImGui colors look similar to what everyone expects, most notable, to make color pickers look correctly, it has to perform some shenanigans with colors. In particular, the colors get alpha-premultiplied, otherwise all text will be broken. The solution to your problem would've been to set colors to
2.0
, but ImGui clamps color channels to1.0
.
Thanks for your detailed response very much. I am not familiar with the graphics. You mean that the color in Diligent is correct in mathematics, which the color shown in ImGui is not. I'll have a try to remove the color clamp in ImGui's code. Thanks a lot.
It is not possible to remove color clamp in ImGui because it packs 0.0-1.0 floats into 8 bits. If you want the same color behavior as in ImGui examples, you can create a RGBA8_UNORM swap chain instead of UNORM_SRGB. You can take a look at this example Set
Attribs.SCDesc.RenderTargetFormat = TEX_FORMAT_RGBA8_UNORM;
It is not possible to remove color clamp in ImGui because it packs 0.0-1.0 floats into 8 bits. If you want the same color behavior as in ImGui examples, you can create a RGBA8_UNORM swap chain instead of UNORM_SRGB. You can take a look at this example Set
Attribs.SCDesc.RenderTargetFormat = TEX_FORMAT_RGBA8_UNORM;
It looks like a little difficult for me, but I will have a try of the above method. Thank you so much for your help.
Use the example I sent - this should not be too complicated.
It seems like a problem for a long time, and still exists in recent versions.
The color of the ImGui's windows' background in DiligentCore apps is incorrect, when the background color is set to transparent white, such as this code:
ImGui::GetStyle().Colors[ImGuiCol_WindowBg] = ImVec4(1.0f, 1.0f, 1.0f, 0.5f);
The background color shows a transparent dark gray, but it should be transparent white.
With the same setting, the color is correct in the independent ImGui app without DiligentEngine.
In 2.5.3 the color shows right. This is the environment I used with when the problem occurs:
DiligentCore: v2.5.4~v2.5.6
Integrated ImGui: 1.89.1, 1.91.3
OS: Windows 11 with d3d11, d3d12, opengl, and valkan
I hope it can be fixed because I really need a light translucent style :)
The background color in DiligentEngine:
Hoped background color of ImGui app without DiligentEngine: