mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-03-09 19:50:57 +00:00
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
This commit is contained in:
parent
ebd73d2a3c
commit
150be12da1
4 changed files with 23 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
12
Quake/menu.c
12
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;
|
||||
|
|
|
@ -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];
|
||||
|
||||
|
|
Loading…
Reference in a new issue