From 6e47bf9bbc12c496f3d32996506ba6f003cfbd0b Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Tue, 24 Jan 2017 10:19:59 -0500 Subject: [PATCH 1/4] - Added gl_paltonemap_powtable and gl_paltonemap_reverselookup for tweaking palette tonemap generation. --- src/gl/renderer/gl_postprocess.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index 30c0000d3..0c24d89ae 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -81,6 +81,9 @@ CVAR(Float, gl_exposure_min, 0.35f, CVAR_ARCHIVE) CVAR(Float, gl_exposure_base, 0.35f, CVAR_ARCHIVE) CVAR(Float, gl_exposure_speed, 0.05f, CVAR_ARCHIVE) +CVAR(Float, gl_paltonemap_powtable, 1.2f, CVAR_ARCHIVE) +CVAR(Bool, gl_paltonemap_reverselookup, false, CVAR_ARCHIVE) + CUSTOM_CVAR(Int, gl_tonemap, 0, CVAR_ARCHIVE) { if (self < 0 || self > 5) @@ -828,7 +831,7 @@ int FGLRenderer::PTM_BestColor (const uint32 *pal_in, int r, int g, int b, int f if (firstTime) { 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 +840,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; From 494be00ce5155854d6bcc1b8fa236d32433d0952 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Tue, 24 Jan 2017 10:21:02 -0500 Subject: [PATCH 2/4] - Made default values for gl_paltonemap_powtable and gl_paltonemap_reverselookup more "id-like". --- src/gl/renderer/gl_postprocess.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index 0c24d89ae..3329231d8 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -81,8 +81,8 @@ CVAR(Float, gl_exposure_min, 0.35f, CVAR_ARCHIVE) CVAR(Float, gl_exposure_base, 0.35f, CVAR_ARCHIVE) CVAR(Float, gl_exposure_speed, 0.05f, CVAR_ARCHIVE) -CVAR(Float, gl_paltonemap_powtable, 1.2f, CVAR_ARCHIVE) -CVAR(Bool, gl_paltonemap_reverselookup, false, CVAR_ARCHIVE) +CVAR(Float, gl_paltonemap_powtable, 2.0f, CVAR_ARCHIVE) +CVAR(Bool, gl_paltonemap_reverselookup, true, CVAR_ARCHIVE) CUSTOM_CVAR(Int, gl_tonemap, 0, CVAR_ARCHIVE) { From 6263704741710f37088d0cdfadd530b3af234ea3 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Tue, 24 Jan 2017 11:19:01 -0500 Subject: [PATCH 3/4] - Added menu options for pal tonemap tweaks. # Conflicts: # wadsrc/static/language.enu --- wadsrc/static/language.enu | 4 ++++ wadsrc/static/menudef.zz | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/wadsrc/static/language.enu b/wadsrc/static/language.enu index b7558d1b2..ddf23edb9 100644 --- a/wadsrc/static/language.enu +++ b/wadsrc/static/language.enu @@ -2645,6 +2645,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"; @@ -2728,3 +2730,5 @@ OPTVAL_LOW = "Low"; OPTVAL_MEDIUM = "Medium"; OPTVAL_HIGH = "High"; OPTVAL_EXTREME = "Extreme"; +OPTVAL_OBVERSEFIRST = "Obverse"; +OPTVAL_REVERSEFIRST = "Reverse"; 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" } From eb3f83f9084088fbce1e3a993ca0817aa9c9e2b1 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Tue, 24 Jan 2017 11:33:42 -0500 Subject: [PATCH 4/4] - Since tonemap tweaks are on the menu now, make their changes affect instantly. --- src/gl/renderer/gl_postprocess.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index 3329231d8..c504088f4 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -81,9 +81,6 @@ CVAR(Float, gl_exposure_min, 0.35f, CVAR_ARCHIVE) CVAR(Float, gl_exposure_base, 0.35f, CVAR_ARCHIVE) CVAR(Float, gl_exposure_speed, 0.05f, CVAR_ARCHIVE) -CVAR(Float, gl_paltonemap_powtable, 2.0f, CVAR_ARCHIVE) -CVAR(Bool, gl_paltonemap_reverselookup, true, CVAR_ARCHIVE) - CUSTOM_CVAR(Int, gl_tonemap, 0, CVAR_ARCHIVE) { if (self < 0 || self > 5) @@ -136,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) @@ -536,8 +544,11 @@ void FGLRenderer::CreateTonemapPalette() void FGLRenderer::ClearTonemapPalette() { - delete mTonemapPalette; - mTonemapPalette = nullptr; + if (mTonemapPalette) + { + delete mTonemapPalette; + mTonemapPalette = nullptr; + } } //----------------------------------------------------------------------------- @@ -824,12 +835,14 @@ 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, (double)gl_paltonemap_powtable); }