From f8dbfa56370f06123ab6d61e1bf70a868e110339 Mon Sep 17 00:00:00 2001 From: divverent Date: Tue, 29 Jan 2008 11:39:41 +0000 Subject: [PATCH] v_contrastboost, and support for the color control functions to fill the gamma table. Goal: remove USECONTRASTBOOST and USEGAMMA in the postprocess shader, replace it by USEGAMMARAMP, and let vid_shared build the gamma tables even if hw gamma is off when glsl needs them... then add a cvar r_glsl_hwgamma that lets glsl take over gamma ramp handling git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8040 d7cf8633-e32d-0410-b094-e92efae38249 --- palette.c | 16 +++++++++++----- palette.h | 4 ++-- vid_shared.c | 18 +++++++++++------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/palette.c b/palette.c index 85cd474f..86ffa5a4 100644 --- a/palette.c +++ b/palette.c @@ -169,30 +169,36 @@ void Palette_SetupSpecialPalettes(void) palette_bgra_font[0] = 0; } -void BuildGammaTable8(float prescale, float gamma, float scale, float base, unsigned char *out, int rampsize) +void BuildGammaTable8(float prescale, float gamma, float scale, float base, float contrastboost, unsigned char *out, int rampsize) { int i, adjusted; double invgamma; + double t; invgamma = 1.0 / gamma; prescale /= (double) (rampsize - 1); for (i = 0;i < rampsize;i++) { - adjusted = (int) (255.0 * (pow((double) i * prescale, invgamma) * scale + base) + 0.5); + t = i * prescale; + t = contrastboost * t / ((contrastboost - 1) * t + 1); + adjusted = (int) (255.0 * (pow(t, invgamma) * scale + base) + 0.5); out[i] = bound(0, adjusted, 255); } } -void BuildGammaTable16(float prescale, float gamma, float scale, float base, unsigned short *out, int rampsize) +void BuildGammaTable16(float prescale, float gamma, float scale, float base, float contrastboost, unsigned short *out, int rampsize) { int i, adjusted; double invgamma; + double t; invgamma = 1.0 / gamma; prescale /= (double) (rampsize - 1); for (i = 0;i < rampsize;i++) { - adjusted = (int) (65535.0 * (pow((double) i * prescale, invgamma) * scale + base) + 0.5); + t = i * prescale; + t = contrastboost * t / ((contrastboost - 1) * t + 1); + adjusted = (int) (65535.0 * (pow(t, invgamma) * scale + base) + 0.5); out[i] = bound(0, adjusted, 65535); } } @@ -239,7 +245,7 @@ void Palette_Load(void) scale = bound(0.01, scale, 10.0); base = bound(0, base, 0.95); - BuildGammaTable8(1.0f, gamma, scale, base, texturegammaramp, 256); + BuildGammaTable8(1.0f, gamma, scale, base, 1, texturegammaramp, 256); palfile = (unsigned char *)FS_LoadFile ("gfx/palette.lmp", tempmempool, false, &filesize); if (palfile && filesize >= 768) diff --git a/palette.h b/palette.h index 11058772..e534b9c5 100644 --- a/palette.h +++ b/palette.h @@ -21,8 +21,8 @@ extern unsigned int palette_bgra_transparent[256]; extern unsigned int palette_bgra_embeddedpic[256]; // used by hardware gamma functions in vid_* files -void BuildGammaTable8(float prescale, float gamma, float scale, float base, unsigned char *out, int rampsize); -void BuildGammaTable16(float prescale, float gamma, float scale, float base, unsigned short *out, int rampsize); +void BuildGammaTable8(float prescale, float gamma, float scale, float base, float contrastboost, unsigned char *out, int rampsize); +void BuildGammaTable16(float prescale, float gamma, float scale, float base, float contrastboost, unsigned short *out, int rampsize); void Palette_Init(void); diff --git a/vid_shared.c b/vid_shared.c index eae2789e..2d1a4b77 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -99,6 +99,7 @@ cvar_t vid_resizable = {CVAR_SAVE, "vid_resizable", "0", "0: window not resizabl cvar_t v_gamma = {CVAR_SAVE, "v_gamma", "1", "inverse gamma correction value, a brightness effect that does not affect white or black, and tends to make the image grey and dull"}; cvar_t v_contrast = {CVAR_SAVE, "v_contrast", "1", "brightness of white (values above 1 give a brighter image with increased color saturation, unlike v_gamma)"}; cvar_t v_brightness = {CVAR_SAVE, "v_brightness", "0", "brightness of black, useful for monitors that are too dark"}; +cvar_t v_contrastboost = {CVAR_SAVE, "v_contrastboost", "1", "by how much to multiply the contrast in dark areas (1 is no change)"}; cvar_t v_color_enable = {CVAR_SAVE, "v_color_enable", "0", "enables black-grey-white color correction curve controls"}; cvar_t v_color_black_r = {CVAR_SAVE, "v_color_black_r", "0", "desired color of black"}; cvar_t v_color_black_g = {CVAR_SAVE, "v_color_black_g", "0", "desired color of black"}; @@ -821,7 +822,7 @@ void Force_CenterView_f (void) } static int gamma_forcenextframe = false; -static float cachegamma, cachebrightness, cachecontrast, cacheblack[3], cachegrey[3], cachewhite[3]; +static float cachegamma, cachebrightness, cachecontrast, cacheblack[3], cachegrey[3], cachewhite[3], cachecontrastboost; static int cachecolorenable, cachehwgamma; void VID_UpdateGamma(qboolean force, int rampsize) { @@ -838,6 +839,7 @@ void VID_UpdateGamma(qboolean force, int rampsize) BOUNDCVAR(v_gamma, 0.1, 5); BOUNDCVAR(v_contrast, 1, 5); BOUNDCVAR(v_brightness, 0, 0.8); + BOUNDCVAR(v_contrastboost, 0.0625, 16); BOUNDCVAR(v_color_black_r, 0, 0.8); BOUNDCVAR(v_color_black_g, 0, 0.8); BOUNDCVAR(v_color_black_b, 0, 0.8); @@ -856,6 +858,7 @@ void VID_UpdateGamma(qboolean force, int rampsize) GAMMACHECK(cachegamma , v_gamma.value); GAMMACHECK(cachecontrast , v_contrast.value); GAMMACHECK(cachebrightness , v_brightness.value); + GAMMACHECK(cachecontrastboost, v_contrastboost.value); GAMMACHECK(cachecolorenable, v_color_enable.integer); GAMMACHECK(cacheblack[0] , v_color_black_r.value); GAMMACHECK(cacheblack[1] , v_color_black_g.value); @@ -891,15 +894,15 @@ void VID_UpdateGamma(qboolean force, int rampsize) if (cachecolorenable) { - BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[0]), cachewhite[0], cacheblack[0], vid_gammaramps, rampsize); - BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[1]), cachewhite[1], cacheblack[1], vid_gammaramps + vid_gammarampsize, rampsize); - BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[2]), cachewhite[2], cacheblack[2], vid_gammaramps + vid_gammarampsize*2, rampsize); + BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[0]), cachewhite[0], cacheblack[0], cachecontrastboost, vid_gammaramps, rampsize); + BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[1]), cachewhite[1], cacheblack[1], cachecontrastboost, vid_gammaramps + vid_gammarampsize, rampsize); + BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[2]), cachewhite[2], cacheblack[2], cachecontrastboost, vid_gammaramps + vid_gammarampsize*2, rampsize); } else { - BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps, rampsize); - BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps + vid_gammarampsize, rampsize); - BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps + vid_gammarampsize*2, rampsize); + BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, vid_gammaramps, rampsize); + BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, vid_gammaramps + vid_gammarampsize, rampsize); + BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, cachecontrastboost, vid_gammaramps + vid_gammarampsize*2, rampsize); } // LordHavoc: this code came from Ben Winslow and Zinx Verituse, I have @@ -979,6 +982,7 @@ void VID_Shared_Init(void) Cvar_RegisterVariable(&vid_hardwaregammasupported); Cvar_RegisterVariable(&v_gamma); Cvar_RegisterVariable(&v_brightness); + Cvar_RegisterVariable(&v_contrastboost); Cvar_RegisterVariable(&v_contrast); Cvar_RegisterVariable(&v_color_enable); -- 2.39.2