mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 14:51:51 +00:00
- use the exact sRGB->linear transfer function in HDR mode as the 2.2 gamma approximation is visibly inaccurate in this case
This commit is contained in:
parent
81e32ecc72
commit
1973001834
5 changed files with 24 additions and 4 deletions
|
@ -225,11 +225,12 @@ void FGLRenderer::DrawPresentTexture(const IntRect &box, bool applyGamma)
|
|||
{
|
||||
// Full screen exclusive mode treats a rgba16f frame buffer as linear.
|
||||
// It probably will eventually in desktop mode too, but the DWM doesn't seem to support that.
|
||||
mPresentShader->Uniforms->InvGamma *= 2.2f;
|
||||
mPresentShader->Uniforms->HdrMode = 1;
|
||||
mPresentShader->Uniforms->ColorScale = (gl_dither_bpc == -1) ? 1023.0f : (float)((1 << gl_dither_bpc) - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
mPresentShader->Uniforms->HdrMode = 0;
|
||||
mPresentShader->Uniforms->ColorScale = (gl_dither_bpc == -1) ? 255.0f : (float)((1 << gl_dither_bpc) - 1);
|
||||
}
|
||||
mPresentShader->Uniforms->Scale = { screen->mScreenViewport.width / (float)mBuffers->GetWidth(), screen->mScreenViewport.height / (float)mBuffers->GetHeight() };
|
||||
|
|
|
@ -167,6 +167,7 @@ void FGLRenderer::prepareInterleavedPresent(FPresentShaderBase& shader)
|
|||
shader.Uniforms->Saturation = clamp<float>(vid_saturation, -15.0f, 15.0f);
|
||||
shader.Uniforms->GrayFormula = static_cast<int>(gl_satformula);
|
||||
}
|
||||
shader.Uniforms->HdrMode = 0;
|
||||
shader.Uniforms->ColorScale = (gl_dither_bpc == -1) ? 255.0f : (float)((1 << gl_dither_bpc) - 1);
|
||||
shader.Uniforms->Scale = {
|
||||
screen->mScreenViewport.width / (float)mBuffers->GetWidth(),
|
||||
|
|
|
@ -726,7 +726,7 @@ struct PresentUniforms
|
|||
FVector2 Scale;
|
||||
FVector2 Offset;
|
||||
float ColorScale;
|
||||
float Padding;
|
||||
int HdrMode;
|
||||
|
||||
static std::vector<UniformFieldDesc> Desc()
|
||||
{
|
||||
|
@ -741,6 +741,7 @@ struct PresentUniforms
|
|||
{ "UVScale", UniformType::Vec2, offsetof(PresentUniforms, Scale) },
|
||||
{ "UVOffset", UniformType::Vec2, offsetof(PresentUniforms, Offset) },
|
||||
{ "ColorScale", UniformType::Float, offsetof(PresentUniforms, ColorScale) },
|
||||
{ "HdrMode", UniformType::Int, offsetof(PresentUniforms, HdrMode) }
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
@ -200,7 +200,11 @@ void VkPostprocess::DrawPresentTexture(const IntRect &box, bool applyGamma, bool
|
|||
|
||||
if (applyGamma && fb->swapChain->swapChainFormat.colorSpace == VK_COLOR_SPACE_HDR10_ST2084_EXT)
|
||||
{
|
||||
uniforms.InvGamma *= 2.2f;
|
||||
uniforms.HdrMode = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
uniforms.HdrMode = 0;
|
||||
}
|
||||
|
||||
renderstate.Clear();
|
||||
|
|
|
@ -29,7 +29,20 @@ vec4 Dither(vec4 c)
|
|||
return vec4(floor(c.rgb * ColorScale + threshold) / ColorScale, c.a);
|
||||
}
|
||||
|
||||
vec4 sRGBtoLinear(vec4 c)
|
||||
{
|
||||
return vec4(mix(pow((c.rgb + 0.055) / 1.055, vec3(2.4)), c.rgb / 12.92, step(c.rgb, vec3(0.04045))), c.a);
|
||||
}
|
||||
|
||||
vec4 ApplyHdrMode(vec4 c)
|
||||
{
|
||||
if (HdrMode == 0)
|
||||
return c;
|
||||
else
|
||||
return sRGBtoLinear(c);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = Dither(ApplyGamma(texture(InputTexture, UVOffset + TexCoord * UVScale)));
|
||||
FragColor = Dither(ApplyHdrMode(ApplyGamma(texture(InputTexture, UVOffset + TexCoord * UVScale))));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue