From ed418d5dcf73d5eff8b143807c5a5e746e3a800d Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 4 Apr 2024 18:59:45 +0200 Subject: [PATCH] disable colourcube cause of visual discrepentcies (temporary) --- src/doomdef.h | 3 +- src/hardware/hw_main.c | 3 +- src/hardware/hw_md2.c | 3 +- src/m_menu.c | 31 +++++++++-- src/screen.c | 3 +- src/v_video.c | 117 ++++++++++++++++++++++++++++++++++++++++- src/v_video.h | 7 ++- 7 files changed, 156 insertions(+), 11 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index 208b6cc69..01237401a 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -559,7 +559,8 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; // Compile them at your own risk! /// Undefine to use the new method of Gamma correction see colour cube in v_video.c -#define BACKWARDSCOMPATCORRECTION +#define OLDGAMMA +//#define BACKWARDSCOMPATCORRECTION /// Allows the use of devmode in multiplayer. AKA "fishcake" //#define NETGAME_DEVMODE diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index ff7f2a207..7aebf5854 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -496,13 +496,14 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col // Clamp the light level, since it can sometimes go out of the 0-255 range from animations light_level = min(max(light_level, cv_secbright.value), 255); - +#ifndef OLDGAMMA // in palette rendering mode, this is not needed since it properly takes the changes to the palette itself if (!HWR_ShouldUsePaletteRendering()) { V_CubeApply(&tint_color.s.red, &tint_color.s.green, &tint_color.s.blue); V_CubeApply(&fade_color.s.red, &fade_color.s.green, &fade_color.s.blue); } +#endif Surface->PolyColor.rgba = poly_color.rgba; Surface->TintColor.rgba = tint_color.rgba; Surface->FadeColor.rgba = fade_color.rgba; diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 5818f01b2..6e1dc17e2 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -402,7 +402,7 @@ static void md2_loadTexture(md2_t *model) grpatch->height = (INT16)h; grpatch->mipmap->width = (UINT16)w; grpatch->mipmap->height = (UINT16)h; - +#ifndef OLDGAMMA // for palette rendering, color cube is applied in post-processing instead of here if (!HWR_ShouldUsePaletteRendering()) { @@ -417,6 +417,7 @@ static void md2_loadTexture(md2_t *model) image++; } } +#endif } HWD.pfnSetTexture(grpatch->mipmap); HWR_UnlockCachedPatch(grpatch); diff --git a/src/m_menu.c b/src/m_menu.c index b672357a1..6b32839d0 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -321,7 +321,11 @@ static void M_ChangeControl(INT32 choice); static void M_ResetControls(INT32 choice); // Video & Sound +#ifdef OLDGAMMA +menu_t OP_VideoOptionsDef, OP_VideoModeDef, OP_ExpOptionsDef; +#else menu_t OP_VideoOptionsDef, OP_VideoModeDef, OP_ExpOptionsDef, OP_ColorOptionsDef; +#endif #ifdef HWRENDER menu_t OP_OpenGLOptionsDef; #endif @@ -419,7 +423,9 @@ static void M_DrawControl(void); static void M_DrawVideoMenu(void); static void M_DrawHUDOptions(void); static void M_DrawVideoMode(void); +#ifndef OLDGAMMA static void M_DrawColorMenu(void); +#endif static void M_DrawMonitorToggles(void); static void M_DrawMPMainMenu(void); #ifndef NONET @@ -1327,6 +1333,15 @@ static const char* OP_MouseTooltips[] = static menuitem_t OP_VideoOptionsMenu[] = { +#ifdef OLDGAMMA + {IT_STRING | IT_CALL, NULL, "Set Resolution...", M_VideoModeMenu, 20}, +#if defined (__unix__) || defined (UNIXCOMMON) || defined (HAVE_SDL) + {IT_STRING|IT_CVAR, NULL, "Fullscreen", &cv_fullscreen, 30}, +#endif + + {IT_STRING | IT_CVAR | IT_CV_SLIDER, + NULL, "Gamma", &cv_globalgamma, 40}, +#else {IT_STRING | IT_CALL, NULL, "Set Resolution...", M_VideoModeMenu, 10}, #if defined (__unix__) || defined (UNIXCOMMON) || defined (HAVE_SDL) {IT_STRING|IT_CVAR, NULL, "Fullscreen", &cv_fullscreen, 20}, @@ -1338,7 +1353,7 @@ static menuitem_t OP_VideoOptionsMenu[] = NULL, "Saturation", &cv_globalsaturation , 40}, {IT_SUBMENU|IT_STRING, NULL, "Advanced Color Settings...", &OP_ColorOptionsDef, 50}, - +#endif // OLDGAMMA {IT_STRING | IT_CVAR, NULL, "Draw Distance", &cv_drawdist, 65}, {IT_STRING | IT_CVAR, NULL, "Weather Draw Distance",&cv_drawdist_precip, 75}, {IT_STRING | IT_CVAR, NULL, "Field of View", &cv_fov, 95}, @@ -1362,8 +1377,10 @@ static const char* OP_VideoTooltips[] = "Enable fullscreen.", #endif "Gamma (brightness) of the game.", +#ifndef OLDGAMMA "Saturation of the game.", "Advanced color settings of the game.", +#endif "How far away objects are drawn.", "How far away weather is drawn.", "Player field of view.", @@ -1386,8 +1403,10 @@ enum op_video_fullscreen, #endif op_video_gamma, +#ifndef OLDGAMMA op_video_sat, op_video_color, +#endif op_video_dd, op_video_wdd, op_video_fov, @@ -1407,6 +1426,7 @@ static menuitem_t OP_VideoModeMenu[] = {IT_KEYHANDLER | IT_NOTHING, NULL, "", M_HandleVideoMode, '\0'}, // dummy menuitem for the control func }; +#ifndef OLDGAMMA static menuitem_t OP_ColorOptionsMenu[] = { {IT_STRING | IT_CALL, NULL, "Reset all", M_ResetCvars, 0}, @@ -1447,6 +1467,7 @@ static menuitem_t OP_ColorOptionsMenu[] = {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Saturation", &cv_msaturation, 145}, {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Brightness", &cv_mgamma, 150}, }; +#endif static menuitem_t OP_ExpOptionsMenu[] = { @@ -2837,7 +2858,7 @@ menu_t OP_VideoModeDef = NULL, {NULL} }; - +#ifndef OLDGAMMA menu_t OP_ColorOptionsDef = { "M_VIDEO", @@ -2850,7 +2871,7 @@ menu_t OP_ColorOptionsDef = NULL, {NULL} }; - +#endif menu_t OP_SoundOptionsDef = { "M_SOUND", @@ -12724,7 +12745,7 @@ static void M_DrawVideoMode(void) V_DrawScaledPatch(i - 8, j, 0, W_CachePatchName("M_CURSOR", PU_CACHE)); } - +#ifndef OLDGAMMA // Just M_DrawGenericScrollMenu but showing a backing behind the headers. static void M_DrawColorMenu(void) { @@ -12835,7 +12856,7 @@ static void M_DrawColorMenu(void) V_DrawScaledPatch(currentMenu->x - 24, cursory, 0, W_CachePatchName("M_CURSOR", PU_CACHE)); } - +#endif // special menuitem key handler for video mode list static void M_HandleVideoMode(INT32 ch) diff --git a/src/screen.c b/src/screen.c index e5c1ebff4..d9c21fc4f 100644 --- a/src/screen.c +++ b/src/screen.c @@ -195,6 +195,7 @@ void SCR_Startup(void) CV_RegisterVar(&cv_constextsize); CV_RegisterVar(&cv_globalgamma); +#ifndef OLDGAMMA CV_RegisterVar(&cv_globalsaturation); CV_RegisterVar(&cv_rhue); @@ -217,7 +218,7 @@ void SCR_Startup(void) CV_RegisterVar(&cv_csaturation); CV_RegisterVar(&cv_bsaturation); CV_RegisterVar(&cv_msaturation); - +#endif V_SetPalette(0); } diff --git a/src/v_video.c b/src/v_video.c index 180424934..85eb29345 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -46,6 +46,11 @@ consvar_t cv_ticrate = {"showfps", "No", CV_SAVE, fps_cons_t, NULL, 0, NULL, NUL static void CV_palette_OnChange(void); +#ifdef OLDGAMMA +static CV_PossibleValue_t gamma_cons_t[] = {{0, "MIN"}, {4, "MAX"}, {0, NULL}}; +consvar_t cv_globalgamma = {"gamma", "0", CV_SAVE|CV_CALL, gamma_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; + +#else static CV_PossibleValue_t gamma_cons_t[] = {{-15, "MIN"}, {5, "MAX"}, {0, NULL}}; consvar_t cv_globalgamma = {"gamma", "0", CV_SAVE|CV_CALL, gamma_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; @@ -75,6 +80,7 @@ consvar_t cv_gsaturation = {"gsaturation", "10", CV_SAVE|CV_CALL, saturation_con consvar_t cv_csaturation = {"csaturation", "10", CV_SAVE|CV_CALL, saturation_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_bsaturation = {"bsaturation", "10", CV_SAVE|CV_CALL, saturation_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_msaturation = {"msaturation", "10", CV_SAVE|CV_CALL, saturation_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +#endif consvar_t cv_allcaps = {"allcaps", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -89,6 +95,113 @@ consvar_t cv_menucaps = {"menucaps", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NUL // local copy of the palette for V_GetColor() RGBA_t *pLocalPalette = NULL; +#ifdef OLDGAMMA +const UINT8 gammatable[5][256] = +{ + {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16, + 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32, + 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48, + 49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64, + 65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80, + 81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96, + 97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112, + 113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128, + 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, + 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, + 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, + 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, + 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, + 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, + 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239, + 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255}, + + {2,4,5,7,8,10,11,12,14,15,16,18,19,20,21,23,24,25,26,27,29,30,31, + 32,33,34,36,37,38,39,40,41,42,44,45,46,47,48,49,50,51,52,54,55, + 56,57,58,59,60,61,62,63,64,65,66,67,69,70,71,72,73,74,75,76,77, + 78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98, + 99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114, + 115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,129, + 130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145, + 146,147,148,148,149,150,151,152,153,154,155,156,157,158,159,160, + 161,162,163,163,164,165,166,167,168,169,170,171,172,173,174,175, + 175,176,177,178,179,180,181,182,183,184,185,186,186,187,188,189, + 190,191,192,193,194,195,196,196,197,198,199,200,201,202,203,204, + 205,205,206,207,208,209,210,211,212,213,214,214,215,216,217,218, + 219,220,221,222,222,223,224,225,226,227,228,229,230,230,231,232, + 233,234,235,236,237,237,238,239,240,241,242,243,244,245,245,246, + 247,248,249,250,251,252,252,253,254,255}, + + {4,7,9,11,13,15,17,19,21,22,24,26,27,29,30,32,33,35,36,38,39,40,42, + 43,45,46,47,48,50,51,52,54,55,56,57,59,60,61,62,63,65,66,67,68,69, + 70,72,73,74,75,76,77,78,79,80,82,83,84,85,86,87,88,89,90,91,92,93, + 94,95,96,97,98,100,101,102,103,104,105,106,107,108,109,110,111,112, + 113,114,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128, + 129,130,131,132,133,133,134,135,136,137,138,139,140,141,142,143,144, + 144,145,146,147,148,149,150,151,152,153,153,154,155,156,157,158,159, + 160,160,161,162,163,164,165,166,166,167,168,169,170,171,172,172,173, + 174,175,176,177,178,178,179,180,181,182,183,183,184,185,186,187,188, + 188,189,190,191,192,193,193,194,195,196,197,197,198,199,200,201,201, + 202,203,204,205,206,206,207,208,209,210,210,211,212,213,213,214,215, + 216,217,217,218,219,220,221,221,222,223,224,224,225,226,227,228,228, + 229,230,231,231,232,233,234,235,235,236,237,238,238,239,240,241,241, + 242,243,244,244,245,246,247,247,248,249,250,251,251,252,253,254,254, + 255}, + + {8,12,16,19,22,24,27,29,31,34,36,38,40,41,43,45,47,49,50,52,53,55, + 57,58,60,61,63,64,65,67,68,70,71,72,74,75,76,77,79,80,81,82,84,85, + 86,87,88,90,91,92,93,94,95,96,98,99,100,101,102,103,104,105,106,107, + 108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124, + 125,126,127,128,129,130,131,132,133,134,135,135,136,137,138,139,140, + 141,142,143,143,144,145,146,147,148,149,150,150,151,152,153,154,155, + 155,156,157,158,159,160,160,161,162,163,164,165,165,166,167,168,169, + 169,170,171,172,173,173,174,175,176,176,177,178,179,180,180,181,182, + 183,183,184,185,186,186,187,188,189,189,190,191,192,192,193,194,195, + 195,196,197,197,198,199,200,200,201,202,202,203,204,205,205,206,207, + 207,208,209,210,210,211,212,212,213,214,214,215,216,216,217,218,219, + 219,220,221,221,222,223,223,224,225,225,226,227,227,228,229,229,230, + 231,231,232,233,233,234,235,235,236,237,237,238,238,239,240,240,241, + 242,242,243,244,244,245,246,246,247,247,248,249,249,250,251,251,252, + 253,253,254,254,255}, + + {16,23,28,32,36,39,42,45,48,50,53,55,57,60,62,64,66,68,69,71,73,75,76, + 78,80,81,83,84,86,87,89,90,92,93,94,96,97,98,100,101,102,103,105,106, + 107,108,109,110,112,113,114,115,116,117,118,119,120,121,122,123,124, + 125,126,128,128,129,130,131,132,133,134,135,136,137,138,139,140,141, + 142,143,143,144,145,146,147,148,149,150,150,151,152,153,154,155,155, + 156,157,158,159,159,160,161,162,163,163,164,165,166,166,167,168,169, + 169,170,171,172,172,173,174,175,175,176,177,177,178,179,180,180,181, + 182,182,183,184,184,185,186,187,187,188,189,189,190,191,191,192,193, + 193,194,195,195,196,196,197,198,198,199,200,200,201,202,202,203,203, + 204,205,205,206,207,207,208,208,209,210,210,211,211,212,213,213,214, + 214,215,216,216,217,217,218,219,219,220,220,221,221,222,223,223,224, + 224,225,225,226,227,227,228,228,229,229,230,230,231,232,232,233,233, + 234,234,235,235,236,236,237,237,238,239,239,240,240,241,241,242,242, + 243,243,244,244,245,245,246,246,247,247,248,248,249,249,250,250,251, + 251,252,252,253,254,254,255,255} +}; + +// keep a copy of the palette so that we can get the RGB value for a color index at any time. +static void LoadPalette(const char *lumpname) +{ + const UINT8 *usegamma = gammatable[cv_globalgamma.value]; + lumpnum_t lumpnum = W_GetNumForName(lumpname); + size_t i, palsize = W_LumpLength(lumpnum)/3; + UINT8 *pal; + + Z_Free(pLocalPalette); + + pLocalPalette = Z_Malloc(sizeof (*pLocalPalette)*palsize, PU_STATIC, NULL); + + pal = W_CacheLumpNum(lumpnum, PU_CACHE); + for (i = 0; i < palsize; i++) + { + pLocalPalette[i].s.red = usegamma[*pal++]; + pLocalPalette[i].s.green = usegamma[*pal++]; + pLocalPalette[i].s.blue = usegamma[*pal++]; + pLocalPalette[i].s.alpha = 0xFF; + } +} +#else /* The following was an extremely helpful resource when developing my Colour Cube LUT. http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter24.html @@ -313,11 +426,12 @@ const UINT8 correctiontable[256] = // keep a copy of the palette so that we can get the RGB value for a color index at any time. static void LoadPalette(const char *lumpname) { - Cubeapply = InitCube(); lumpnum_t lumpnum = W_GetNumForName(lumpname); size_t i, palsize = W_LumpLength(lumpnum)/3; UINT8 *pal; + Cubeapply = InitCube(); + Z_Free(pLocalPalette); pLocalPalette = Z_Malloc(sizeof (*pLocalPalette)*palsize, PU_STATIC, NULL); @@ -381,6 +495,7 @@ void V_CubeApply(UINT8 *red, UINT8 *green, UINT8 *blue) *green = (UINT8)(working[0][1]); *blue = (UINT8)(working[0][2]); } +#endif //ifdef OLDGAMMA const char *R_GetPalname(UINT16 num) { diff --git a/src/v_video.h b/src/v_video.h index 77f628efb..42df40279 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -27,12 +27,15 @@ extern UINT8 *screens[5]; +#ifdef OLDGAMMA +extern consvar_t cv_ticrate, cv_accuratefps, cv_allcaps, cv_constextsize, cv_menucaps, cv_globalgamma; +#else extern consvar_t cv_ticrate, cv_accuratefps, cv_allcaps, cv_constextsize, cv_menucaps,\ cv_globalgamma, cv_globalsaturation,\ cv_rhue, cv_yhue, cv_ghue, cv_chue, cv_bhue, cv_mhue,\ cv_rgamma, cv_ygamma, cv_ggamma, cv_cgamma, cv_bgamma, cv_mgamma, \ cv_rsaturation, cv_ysaturation, cv_gsaturation, cv_csaturation, cv_bsaturation, cv_msaturation; - +#endif // Allocates buffer screens, call before R_Init. void V_Init(void); @@ -63,7 +66,9 @@ extern UINT8 hudtrans; extern INT32 V_LocalTransFlag(void); +#ifndef OLDGAMMA void V_CubeApply(UINT8 *red, UINT8 *green, UINT8 *blue); +#endif // Retrieve the ARGB value from a palette color index #define V_GetColor(color) (pLocalPalette[color&0xFF])