diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index 30c0000d3..c504088f4 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -133,6 +133,17 @@ CUSTOM_CVAR(Float, gl_ssao_exponent, 1.8f, 0) if (self < 0.1f) self = 0.1f; } +CUSTOM_CVAR(Float, gl_paltonemap_powtable, 2.0f, CVAR_ARCHIVE | CVAR_NOINITCALL) +{ + GLRenderer->ClearTonemapPalette(); +} + +CUSTOM_CVAR(Bool, gl_paltonemap_reverselookup, true, CVAR_ARCHIVE | CVAR_NOINITCALL) +{ + GLRenderer->ClearTonemapPalette(); +} + + EXTERN_CVAR(Float, vid_brightness) EXTERN_CVAR(Float, vid_contrast) @@ -533,8 +544,11 @@ void FGLRenderer::CreateTonemapPalette() void FGLRenderer::ClearTonemapPalette() { - delete mTonemapPalette; - mTonemapPalette = nullptr; + if (mTonemapPalette) + { + delete mTonemapPalette; + mTonemapPalette = nullptr; + } } //----------------------------------------------------------------------------- @@ -821,14 +835,16 @@ int FGLRenderer::PTM_BestColor (const uint32 *pal_in, int r, int g, int b, int f const PalEntry *pal = (const PalEntry *)pal_in; static double powtable[256]; static bool firstTime = true; + static float trackpowtable = 0.; double fbestdist, fdist; int bestcolor; - if (firstTime) + if (firstTime || trackpowtable != gl_paltonemap_powtable) { + trackpowtable = gl_paltonemap_powtable; firstTime = false; - for (int x = 0; x < 256; x++) powtable[x] = pow((double)x/255,1.2); + for (int x = 0; x < 256; x++) powtable[x] = pow((double)x/255, (double)gl_paltonemap_powtable); } for (int color = first; color < num; color++) @@ -837,9 +853,9 @@ int FGLRenderer::PTM_BestColor (const uint32 *pal_in, int r, int g, int b, int f double y = powtable[abs(g-pal[color].g)]; double z = powtable[abs(b-pal[color].b)]; fdist = x + y + z; - if (color == first || fdist < fbestdist) + if (color == first || ((gl_paltonemap_reverselookup)?(fdist <= fbestdist):(fdist < fbestdist))) { - if (fdist == 0) + if (fdist == 0 && !gl_paltonemap_reverselookup) return color; fbestdist = fdist; diff --git a/wadsrc/static/language.enu b/wadsrc/static/language.enu index ae500c152..3ed8ffa77 100644 --- a/wadsrc/static/language.enu +++ b/wadsrc/static/language.enu @@ -2662,6 +2662,8 @@ GLPREFMNU_LENS = "Lens distortion effect"; GLPREFMNU_SSAO = "Ambient occlusion quality"; GLPREFMNU_SSAO_PORTALS = "Portals with AO"; GLPREFMNU_FXAA = "FXAA Quality"; +GLPREFMNU_PALTONEMAPORDER = "Tonemap Palette Order"; +GLPREFMNU_PALTONEMAPPOWER = "Tonemap Palette Exponent"; // Option Values OPTVAL_SMART = "Smart"; @@ -2745,6 +2747,8 @@ OPTVAL_LOW = "Low"; OPTVAL_MEDIUM = "Medium"; OPTVAL_HIGH = "High"; OPTVAL_EXTREME = "Extreme"; +OPTVAL_OBVERSEFIRST = "Obverse"; +OPTVAL_REVERSEFIRST = "Reverse"; // QZDoom exclusive: diff --git a/wadsrc/static/menudef.zz b/wadsrc/static/menudef.zz index 599c28a2d..f683f2e0d 100644 --- a/wadsrc/static/menudef.zz +++ b/wadsrc/static/menudef.zz @@ -1,3 +1,9 @@ +OptionValue "LookupOrder" +{ + 0, "$OPTVAL_OBVERSEFIRST" + 1, "$OPTVAL_REVERSEFIRST" +} + OptionValue "SpriteclipModes" { 0, "$OPTVAL_NEVER" @@ -249,4 +255,7 @@ OptionMenu "GLPrefOptions" Option "$GLPREFMNU_SSAO", gl_ssao, "SSAOModes" Slider "$GLPREFMNU_SSAO_PORTALS", gl_ssao_portals, 0.0, 4.0, 1.0, 0 Option "$GLPREFMNU_FXAA", gl_fxaa, "FXAAQuality" + StaticText " " + Slider "$GLPREFMNU_PALTONEMAPPOWER", gl_paltonemap_powtable, 0.2, 3.0, 0.1, 0 + Option "$GLPREFMNU_PALTONEMAPORDER", gl_paltonemap_reverselookup, "LookupOrder" }