imgui icon indicating copy to clipboard operation
imgui copied to clipboard

SRGB framebuffer issue

Open gui2one opened this issue 11 months ago • 1 comments

Config/Build Information (copied from Demo Window)

Dear ImGui 1.87 WIP (18602)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1929
define: _MSVC_LANG=201402
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00100041
 NavEnableKeyboard
 DockingEnable
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1280.00,720.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Version/Branch of Dear ImGui:

Version: 1.87 WIP Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_opengl3.cpp + imgui_impl_glfw.cpp Compiler: MSVC Operating System: Windows10

My Issue/Question:

I am building a small OpenGL Renderer. I struggled a lot with linear/sRGB workflow, and finally settle on using

glEnable(GL_FRAMEBUFFER_SRGB)

witch is apparently pretty much free, and means I don't have to do all the work in fragment shaders. So it's a no brainer. But once in ImGui, the viewport where I renderer my scene is OK, but ImGui colors are too bright.

And trying to enable and disable GL_FRAMEBUFFER_SRGB before and after the ImGui window creation doesn't work. I either have ImGui colors to bright and viewport OK, or ImGui colors OK but viewport too dark;

The scene is rendererd to a framebuffer, which I then display in ImGui window using ImGui::Image() display the scene

Is there a way apply a fragment shader to the image displayed by ImGui::Image ? (to apply a final gamma correction just for the viewport )

Screenshots/Video

ImGui_SRGB_issue2

gui2one avatar Jul 08 '23 13:07 gui2one

Dear ImGui currently doesn't play nice with sRGB backbuffers. https://github.com/ocornut/imgui/issues/578 https://github.com/ocornut/imgui/issues/1724 https://github.com/ocornut/imgui/pull/2943 https://github.com/ocornut/imgui/issues/4890

Unfortunately no consensus has been reached on what the appropriate fix should be.

The maybe-good-enough bandaid fix is to add a sRGB->linear conversion to the end of the pixel shader in the backend to counter-act the implicit linear->sRGB conversion.

PathogenDavid avatar Jul 12 '23 22:07 PathogenDavid