From 72491049e0b371dff959e567ac88ca6dc733c2c7 Mon Sep 17 00:00:00 2001 From: raa-eruanna Date: Wed, 21 Sep 2016 15:08:53 -0400 Subject: [PATCH] Changes to the contrast/brightness/gamma formula for both hardware and shader gamma correction. Mainly makes a correction with the shader version where contrast/brightness being negative values would clip them inappropriately. --- src/gl/system/gl_framebuffer.cpp | 2 +- wadsrc/static/shaders/glsl/present.fp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 07d8abaef..1ca2f7edd 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -250,8 +250,8 @@ void OpenGLFrameBuffer::DoSetGamma() for (int i = 0; i < 256; i++) { double val = i * contrast - (contrast - 1) * 127; - if(gamma != 1) val = pow(val, invgamma) / norm; val += bright * 128; + if(gamma != 1) val = pow(val, invgamma) / norm; gammaTable[i] = gammaTable[i + 256] = gammaTable[i + 512] = (WORD)clamp(val*256, 0, 0xffff); } diff --git a/wadsrc/static/shaders/glsl/present.fp b/wadsrc/static/shaders/glsl/present.fp index 53fc007b6..4f5c7cffa 100644 --- a/wadsrc/static/shaders/glsl/present.fp +++ b/wadsrc/static/shaders/glsl/present.fp @@ -9,9 +9,9 @@ uniform float Brightness; vec4 ApplyGamma(vec4 c) { - vec3 val = max(c.rgb * Contrast - (Contrast - 1.0) * 0.5, vec3(0.0)); - val = pow(val, vec3(InvGamma)); + vec3 val = c.rgb * Contrast - (Contrast - 1.0) * 0.5; val += Brightness * 0.5; + val = pow(val, vec3(InvGamma)); return vec4(val, c.a); }