Open matt77hias opened 6 years ago
I don't have your answers right now, and perhaps surprisingly I am not the best person to answer. Looking at it from a casual distance, the subtleties and wording involved in srgb/linear space discussions are still mostly confusing to me (even though a few kind people have made an effort to explain things and I've got several e-mail/articles to re-read). Linking this post to #578 for now.
Ok thanks, I will take a look.
As a side note, the two problems that I am facing are:
a*c1^g + (1-a)*c2^g != (a*c1 + (1-a)*c2)^g
(i.e. my linear scene content should be alpha blended with linear ImGui content).I changed the HLSL vertex shader to:
static const char* vertexShader =
"cbuffer vertexBuffer : register(b0) \
{\
float4x4 ProjectionMatrix; \
};\
struct VS_INPUT\
{\
float2 pos : POSITION;\
float4 col : COLOR0;\
float2 uv : TEXCOORD0;\
};\
\
struct PS_INPUT\
{\
float4 pos : SV_POSITION;\
float4 col : COLOR0;\
float2 uv : TEXCOORD0;\
};\
\
PS_INPUT main(VS_INPUT input)\
{\
PS_INPUT output;\
output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\
output.col.xyz = pow(abs(input.col.xyz), 2.2f);\
output.col.w = input.col.w;\
output.uv = input.uv;\
return output;\
}";
and my dithering problem is solved (you cannot see the quantization banding anymore):
It appears that the right solution here is to use SRGB texture view e.g. here: https://github.com/ocornut/imgui/blob/master/examples/imgui_impl_dx11.cpp#L314 The hardware will do sRGB -> linear conversion under the hood and filtering will also be correct.
@DiligentGraphics this would not solve the whole problem as the vertex colors are not part of a texture. Furthermore, (I need to double-check) ImGui uses one font texture that is black and white-ish (i.e. linear black/white = sRGB black/white). Of course if the latter would have some colors in between, an sRGB will be the better fit.
Other related ImGui issue with more detailed info: https://github.com/ocornut/imgui/issues/578#issuecomment-379467586
Based on the vertex structure used,
I assume that
col
represents a color in sRGB color space (i.e. not in linear color space)?Since these vertex structures aren't modified and sent straight to the actual vertex buffer, and since the D3D11 vertex layout is the following:
I assume that the color attribute of a vertex is still expressed in sRGB color space?
Based on the exemplar D3D11 pixel shader used,
I assume all intermediate calculations occur in sRGB color space and sRGB colors are written to a non-sRGB RTV?
If all of the above questions are answered with "yes" and I want to work in a linear color space instead, is it just necessary (and efficient) to:
transform
ImDrawVert
to a custom format instead of usingImDrawVert* vtx_dst = (ImDrawVert*)vtx_resource.pData;
directly;change the vertex input layout to a
DXGI_FORMAT_R32G32B32A32_FLOAT
?