diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index b8553bde1c..a53067d8be 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -306,13 +306,13 @@ void FGLRenderer::CopyToBackbuffer(const GL_IRECT *bounds, bool applyGamma) mPresentShader->InputTexture.Set(0); if (!applyGamma || framebuffer->IsHWGammaActive()) { - mPresentShader->Gamma.Set(1.0f); + mPresentShader->InvGamma.Set(1.0f); mPresentShader->Contrast.Set(1.0f); mPresentShader->Brightness.Set(0.0f); } else { - mPresentShader->Gamma.Set(clamp(Gamma, 0.1f, 4.f)); + mPresentShader->InvGamma.Set(1.0f / clamp(Gamma, 0.1f, 4.f)); mPresentShader->Contrast.Set(clamp(vid_contrast, 0.1f, 3.f)); mPresentShader->Brightness.Set(clamp(vid_brightness, -0.8f, 0.8f)); } diff --git a/src/gl/shaders/gl_presentshader.cpp b/src/gl/shaders/gl_presentshader.cpp index e40aa7a2c0..426253639d 100644 --- a/src/gl/shaders/gl_presentshader.cpp +++ b/src/gl/shaders/gl_presentshader.cpp @@ -60,7 +60,7 @@ void FPresentShader::Bind() mShader.SetAttribLocation(0, "PositionInProjection"); mShader.SetAttribLocation(1, "UV"); InputTexture.Init(mShader, "InputTexture"); - Gamma.Init(mShader, "Gamma"); + InvGamma.Init(mShader, "InvGamma"); Contrast.Init(mShader, "Contrast"); Brightness.Init(mShader, "Brightness"); Scale.Init(mShader, "UVScale"); diff --git a/src/gl/shaders/gl_presentshader.h b/src/gl/shaders/gl_presentshader.h index 513af41ccf..b54fa2e36e 100644 --- a/src/gl/shaders/gl_presentshader.h +++ b/src/gl/shaders/gl_presentshader.h @@ -9,7 +9,7 @@ public: void Bind(); FBufferedUniform1i InputTexture; - FBufferedUniform1f Gamma; + FBufferedUniform1f InvGamma; FBufferedUniform1f Contrast; FBufferedUniform1f Brightness; FBufferedUniform2f Scale; diff --git a/wadsrc/static/shaders/glsl/present.fp b/wadsrc/static/shaders/glsl/present.fp index 4a3f418404..53fc007b67 100644 --- a/wadsrc/static/shaders/glsl/present.fp +++ b/wadsrc/static/shaders/glsl/present.fp @@ -3,14 +3,14 @@ in vec2 TexCoord; out vec4 FragColor; uniform sampler2D InputTexture; -uniform float Gamma; +uniform float InvGamma; uniform float Contrast; uniform float Brightness; vec4 ApplyGamma(vec4 c) { - vec3 val = c.rgb * Contrast - (Contrast - 1.0) * 0.5; - val = pow(val, vec3(1.0 / Gamma)); + vec3 val = max(c.rgb * Contrast - (Contrast - 1.0) * 0.5, vec3(0.0)); + val = pow(val, vec3(InvGamma)); val += Brightness * 0.5; return vec4(val, c.a); }