mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-15 17:11:24 +00:00
- use the exact sRGB->linear transfer function in HDR mode as the 2.2 gamma approximation is visibly inaccurate in this case
# Conflicts: # src/rendering/gl/renderer/gl_postprocess.cpp # src/rendering/gl/renderer/gl_stereo3d.cpp # src/rendering/hwrenderer/postprocessing/hw_postprocess.h # src/rendering/vulkan/renderer/vk_postprocess.cpp # wadsrc/static/shaders/glsl/present.fp # Conflicts: # src/gl/renderer/gl_postprocess.cpp # src/gl/stereo3d/gl_interleaved3d.cpp # src/hwrenderer/postprocessing/hw_presentshader.h
This commit is contained in:
parent
11faa63009
commit
98607f594e
5 changed files with 20 additions and 3 deletions
|
@ -900,12 +900,12 @@ void FGLRenderer::DrawPresentTexture(const GL_IRECT &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.
|
||||
invgamma *= 2.2f;
|
||||
mPresentShader->InvGamma.Set(invgamma);
|
||||
mPresentShader->HdrMode.Set(1);
|
||||
mPresentShader->ColorScale.Set(static_cast<float>((gl_dither_bpc == -1) ? 1023.0f : (float)((1 << gl_dither_bpc) - 1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
mPresentShader->HdrMode.Set(0);
|
||||
mPresentShader->ColorScale.Set(static_cast<float>((gl_dither_bpc == -1) ? 255.0f : (float)((1 << gl_dither_bpc) - 1)));
|
||||
}
|
||||
mPresentShader->Scale.Set(mScreenViewport.width / (float)mBuffers->GetWidth(), mScreenViewport.height / (float)mBuffers->GetHeight());
|
||||
|
|
|
@ -50,6 +50,7 @@ void FPresentShaderBase::Init(const char * vtx_shader_name, const char * program
|
|||
GrayFormula.Init(mShader, "GrayFormula");
|
||||
Scale.Init(mShader, "UVScale");
|
||||
ColorScale.Init(mShader, "ColorScale");
|
||||
HdrMode.Init(mShader, "HdrMode");
|
||||
}
|
||||
|
||||
void FPresentShader::Bind()
|
||||
|
|
|
@ -16,6 +16,7 @@ public:
|
|||
FBufferedUniform1i GrayFormula;
|
||||
FBufferedUniform2f Scale;
|
||||
FBufferedUniform1f ColorScale;
|
||||
FBufferedUniform1i HdrMode;
|
||||
|
||||
protected:
|
||||
virtual void Init(const char * vtx_shader_name, const char * program_name);
|
||||
|
|
|
@ -113,6 +113,7 @@ static void prepareInterleavedPresent(FPresentStereoShaderBase& shader)
|
|||
shader.Saturation.Set(clamp<float>(vid_saturation, -15.0f, 15.0f));
|
||||
shader.GrayFormula.Set(static_cast<int>(gl_satformula));
|
||||
}
|
||||
shader.HdrMode.Set(0);
|
||||
shader.ColorScale.Set(static_cast<float>((gl_dither_bpc == -1) ? 255.0f : (float)((1 << gl_dither_bpc) - 1)));
|
||||
shader.Scale.Set(
|
||||
GLRenderer->mScreenViewport.width / (float)GLRenderer->mBuffers->GetWidth(),
|
||||
|
|
|
@ -10,6 +10,7 @@ uniform float Saturation;
|
|||
uniform int GrayFormula;
|
||||
layout(binding=1) uniform sampler2D DitherTexture;
|
||||
uniform float ColorScale;
|
||||
uniform int HdrMode;
|
||||
|
||||
vec4 ApplyGamma(vec4 c)
|
||||
{
|
||||
|
@ -35,7 +36,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, TexCoord)));
|
||||
FragColor = Dither(ApplyHdrMode(ApplyGamma(texture(InputTexture, TexCoord))));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue