From 150be12da154c1d8c24d4fcca1a2f7eaa19f5ecb Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Fri, 12 Feb 2016 23:26:36 +0000 Subject: [PATCH] Contrast support with a "contrast" cvar, behaving the same as MarkV's. It may be a useful alternative to the existing gamma control for laptops in a bright environment, etc. (raising contrast gives less of a gray/washed out look than raising gamma, but as a disadvantage, colours near white get clipped to white.) It's also implemented for both GLSL and SDL gamma ramps, but only if USE_GAMMA_RAMPS is set to 1. Since USE_GAMMA_RAMPS is 0, currently it only works with GLSL. git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1290 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/gl_rmain.c | 7 ++++++- Quake/gl_vidsdl.c | 5 ++++- Quake/menu.c | 12 ++++++++++++ Quake/view.h | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Quake/gl_rmain.c b/Quake/gl_rmain.c index c517ec73..78d6828a 100644 --- a/Quake/gl_rmain.c +++ b/Quake/gl_rmain.c @@ -124,6 +124,7 @@ static int r_gamma_texture_width, r_gamma_texture_height; // uniforms used in gamma shader static GLuint gammaLoc; +static GLuint contrastLoc; static GLuint textureLoc; /* @@ -158,9 +159,11 @@ static void GLSLGamma_CreateShaders (void) "\n" "uniform sampler2D GammaTexture;\n" "uniform float GammaValue;\n" + "uniform float ContrastValue;\n" "\n" "void main(void) {\n" " vec4 frag = texture2D(GammaTexture, gl_TexCoord[0].xy);\n" + " frag.rgb = frag.rgb * ContrastValue;\n" " gl_FragColor = vec4(pow(frag.rgb, vec3(GammaValue)), 1.0);\n" "}\n"; @@ -171,6 +174,7 @@ static void GLSLGamma_CreateShaders (void) // get uniform locations gammaLoc = GL_GetUniformLocation (&r_gamma_program, "GammaValue"); + contrastLoc = GL_GetUniformLocation (&r_gamma_program, "ContrastValue"); textureLoc = GL_GetUniformLocation (&r_gamma_program, "GammaTexture"); } @@ -186,7 +190,7 @@ void GLSLGamma_GammaCorrect (void) if (!gl_glsl_gamma_able) return; - if (vid_gamma.value == 1) + if (vid_gamma.value == 1 && vid_contrast.value == 1) return; // create render-to-texture texture if needed @@ -227,6 +231,7 @@ void GLSLGamma_GammaCorrect (void) // draw the texture back to the framebuffer with a fragment shader GL_UseProgramFunc (r_gamma_program); GL_Uniform1fFunc (gammaLoc, vid_gamma.value); + GL_Uniform1fFunc (contrastLoc, q_min(2.0, q_max(1.0, vid_contrast.value))); GL_Uniform1iFunc (textureLoc, 0); // use texture unit 0 glDisable (GL_ALPHA_TEST); diff --git a/Quake/gl_vidsdl.c b/Quake/gl_vidsdl.c index d711a04c..b03d0878 100644 --- a/Quake/gl_vidsdl.c +++ b/Quake/gl_vidsdl.c @@ -152,6 +152,7 @@ static cvar_t vid_desktopfullscreen = {"vid_desktopfullscreen", "0", CVAR_ARCHIV //johnfitz cvar_t vid_gamma = {"gamma", "1", CVAR_ARCHIVE}; //johnfitz -- moved here from view.c +cvar_t vid_contrast = {"contrast", "1", CVAR_ARCHIVE}; //QuakeSpasm, MarkV //========================================================================== // @@ -271,7 +272,7 @@ static void VID_Gamma_f (cvar_t *var) for (i = 0; i < 256; i++) { vid_gamma_red[i] = - CLAMP(0, (int) (255 * pow((i + 0.5)/255.5, var->value) + 0.5), 255) << 8; + CLAMP(0, (int) ((255 * pow((i + 0.5)/255.5, vid_gamma.value) + 0.5) * vid_contrast.value), 255) << 8; vid_gamma_green[i] = vid_gamma_red[i]; vid_gamma_blue[i] = vid_gamma_red[i]; } @@ -287,7 +288,9 @@ VID_Gamma_Init -- call on init static void VID_Gamma_Init (void) { Cvar_RegisterVariable (&vid_gamma); + Cvar_RegisterVariable (&vid_contrast); Cvar_SetCallback (&vid_gamma, VID_Gamma_f); + Cvar_SetCallback (&vid_contrast, VID_Gamma_f); if (gl_glsl_gamma_able) return; diff --git a/Quake/menu.c b/Quake/menu.c index c9fd7244..21aa4b90 100644 --- a/Quake/menu.c +++ b/Quake/menu.c @@ -965,6 +965,7 @@ enum OPT_SCALE, OPT_SCRSIZE, OPT_GAMMA, + OPT_CONTRAST, OPT_MOUSESPEED, OPT_SBALPHA, OPT_SNDVOL, @@ -1024,6 +1025,12 @@ void M_AdjustSliders (int dir) else if (f > 1) f = 1; Cvar_SetValue ("gamma", f); break; + case OPT_CONTRAST: // contrast + f = vid_contrast.value + dir * 0.1; + if (f < 1) f = 1; + else if (f > 2) f = 2; + Cvar_SetValue ("contrast", f); + break; case OPT_MOUSESPEED: // mouse speed f = sensitivity.value + dir * 0.5; if (f > 11) f = 11; @@ -1151,6 +1158,11 @@ void M_Options_Draw (void) r = (1.0 - vid_gamma.value) / 0.5; M_DrawSlider (220, 32 + 8*OPT_GAMMA, r); + // OPT_CONTRAST: + M_Print (16, 32 + 8*OPT_CONTRAST, " Contrast"); + r = vid_contrast.value - 1.0; + M_DrawSlider (220, 32 + 8*OPT_CONTRAST, r); + // OPT_MOUSESPEED: M_Print (16, 32 + 8*OPT_MOUSESPEED, " Mouse Speed"); r = (sensitivity.value - 1)/10; diff --git a/Quake/view.h b/Quake/view.h index 48827dfd..af0cdf1d 100644 --- a/Quake/view.h +++ b/Quake/view.h @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define _QUAKE_VIEW_H extern cvar_t vid_gamma; +extern cvar_t vid_contrast; extern float v_blend[4];