From 666a99f204d4d34780a569107060b0207656cb86 Mon Sep 17 00:00:00 2001 From: Professor Hastig Date: Tue, 4 Jul 2023 09:57:19 +0200 Subject: [PATCH] lightmode refactor * make all legacy light modes except 'Doom' MAPINFO only. A CVAR still exists for testing but its value won't be saved to the config. * user can only select between "performance', 'software' and 'vanilla'. 'performance' is the old 'Doom' mode which is still needed to speed things up on low end hardware. * MAPINFO can not enforce any of the two software light modes, as low end users require the option to change this to the 'performance' setting. Selecting one will always revert to the user's light mode selection. --- src/am_map.cpp | 8 +++-- .../rendering/hwrenderer/data/hw_cvars.h | 1 - src/g_level.cpp | 30 +++++++++++++------ src/g_levellocals.h | 3 +- src/gameconfigfile.cpp | 9 ++++++ src/gamedata/g_mapinfo.cpp | 3 +- .../hwrenderer/scene/hw_drawinfo.cpp | 5 ++-- src/version.h | 2 +- 8 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index dd3d93423..8510eafa1 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -2012,6 +2012,9 @@ void DAutomap::drawSubsectors() PalEntry flatcolor; mpoint_t originpt; + auto lm = getRealLightmode(Level, false); + bool softlightramp = !V_IsHardwareRenderer() || lm == ELightMode::Doom || lm == ELightMode::DoomDark; + auto &subsectors = Level->subsectors; for (unsigned i = 0; i < subsectors.Size(); ++i) { @@ -2186,15 +2189,14 @@ void DAutomap::drawSubsectors() // Why the +12? I wish I knew, but experimentation indicates it // is necessary in order to best reproduce Doom's original lighting. double fadelevel; - - if (!V_IsHardwareRenderer() || primaryLevel->lightMode == ELightMode::DoomDark || primaryLevel->lightMode == ELightMode::Doom || primaryLevel->lightMode == ELightMode::ZDoomSoftware || primaryLevel->lightMode == ELightMode::DoomSoftware) + if (softlightramp) { double map = (NUMCOLORMAPS * 2.) - ((floorlight + 12) * (NUMCOLORMAPS / 128.)); fadelevel = clamp((map - 12) / NUMCOLORMAPS, 0.0, 1.0); } else { - // The hardware renderer's light modes 0, 1 and 4 use a linear light scale which must be used here as well. Otherwise the automap gets too dark. + // for the hardware renderer's light modes that use a linear light scale this must do the same. Otherwise the automap gets too dark. fadelevel = 1. - clamp(floorlight, 0, 255) / 255.f; } diff --git a/src/common/rendering/hwrenderer/data/hw_cvars.h b/src/common/rendering/hwrenderer/data/hw_cvars.h index 0b9d8f09b..cf2364979 100644 --- a/src/common/rendering/hwrenderer/data/hw_cvars.h +++ b/src/common/rendering/hwrenderer/data/hw_cvars.h @@ -18,7 +18,6 @@ EXTERN_CVAR (Bool, gl_light_shadowmap); EXTERN_CVAR (Int, gl_shadowmap_quality); EXTERN_CVAR(Int, gl_fogmode) -EXTERN_CVAR(Int, gl_lightmode) EXTERN_CVAR(Bool,gl_mirror_envmap) EXTERN_CVAR(Bool,gl_mirrors) diff --git a/src/g_level.cpp b/src/g_level.cpp index dda4651e6..5985ab374 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -146,17 +146,30 @@ CUSTOM_CVAR(Bool, gl_notexturefill, false, CVAR_NOINITCALL) } } -CUSTOM_CVAR(Int, gl_lightmode, 3, CVAR_ARCHIVE | CVAR_NOINITCALL) +CUSTOM_CVAR(Int, gl_maplightmode, -1, CVAR_NOINITCALL) // this is just for testing. -1 means 'inactive' { - int newself = self; - if (newself > 8) newself = 16; // use 8 and 16 for software lighting to avoid conflicts with the bit mask ( in hindsight a bad idea.) - else if (newself > 5) newself = 8; - else if (newself < 0) newself = 0; - if (self != newself) self = newself; - else for (auto Level : AllLevels()) + if (self > 5 || self < -1) self = -1; +} + +CUSTOM_CVAR(Int, gl_lightmode, 1, CVAR_ARCHIVE | CVAR_NOINITCALL) +{ + if (self < 0 || self > 2) self = 2; +} + +ELightMode getRealLightmode(FLevelLocals* Level, bool for3d) +{ + auto lightmode = Level->info->lightmode; + if (lightmode == ELightMode::NotSet) { - if ((Level->info == nullptr || Level->info->lightmode == ELightMode::NotSet)) Level->lightMode = (ELightMode)*self; + if (gl_maplightmode != -1) Level->info->lightmode == (ELightMode)*gl_maplightmode; + else Level->info->lightmode = ELightMode::Doom; } + if (lightmode == ELightMode::Doom && for3d) + { + if (gl_lightmode == 1) lightmode = ELightMode::ZDoomSoftware; + else if (gl_lightmode == 2) lightmode = ELightMode::DoomSoftware; + } + return lightmode; } CVAR(Int, sv_alwaystally, 0, CVAR_SERVERINFO) @@ -1864,7 +1877,6 @@ void FLevelLocals::Init() DefaultEnvironment = info->DefaultEnvironment; - lightMode = info->lightmode == ELightMode::NotSet? (ELightMode)*gl_lightmode : info->lightmode; brightfog = info->brightfog < 0? gl_brightfog : !!info->brightfog; lightadditivesurfaces = info->lightadditivesurfaces < 0 ? gl_lightadditivesurfaces : !!info->lightadditivesurfaces; notexturefill = info->notexturefill < 0 ? gl_notexturefill : !!info->notexturefill; diff --git a/src/g_levellocals.h b/src/g_levellocals.h index 04ec8c6d9..b50b19fe4 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -683,7 +683,6 @@ public: float MusicVolume; // Hardware render stuff that can either be set via CVAR or MAPINFO - ELightMode lightMode; bool brightfog; bool lightadditivesurfaces; bool notexturefill; @@ -883,3 +882,5 @@ inline TArrayView AllLevels() { return TArrayView(&primaryLevel, 1); } + +ELightMode getRealLightmode(FLevelLocals* Level, bool for3d); diff --git a/src/gameconfigfile.cpp b/src/gameconfigfile.cpp index 6c9c88410..5a801bff3 100644 --- a/src/gameconfigfile.cpp +++ b/src/gameconfigfile.cpp @@ -607,6 +607,15 @@ void FGameConfigFile::DoGlobalSetup () var->SetGenericRep(v, CVAR_Float); } } + if (last < 225) + { + if (const auto var = FindCVar("gl_lightmode", NULL)) + { + UCVarValue v = var->GetGenericRep(CVAR_Int); + v.Int /= 8; // all legacy modes map to 0, ZDoom software to 1 and Vanilla software to 2. + var->SetGenericRep(v, CVAR_Int); + } + } } } } diff --git a/src/gamedata/g_mapinfo.cpp b/src/gamedata/g_mapinfo.cpp index a5b0bfb1c..78ffb15a1 100644 --- a/src/gamedata/g_mapinfo.cpp +++ b/src/gamedata/g_mapinfo.cpp @@ -1521,7 +1521,8 @@ DEFINE_MAP_OPTION(lightmode, false) parse.ParseAssign(); parse.sc.MustGetNumber(); - if ((parse.sc.Number >= 0 && parse.sc.Number <= 4) || parse.sc.Number == 8 || parse.sc.Number == 16) + if (parse.sc.Number == 8 || parse.sc.Number == 16) info->lightmode = ELightMode::NotSet; + else if (parse.sc.Number >= 0 && parse.sc.Number <= 5) { info->lightmode = ELightMode(parse.sc.Number); } diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp index 613132ebe..2275d9a11 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp @@ -139,7 +139,8 @@ void HWDrawInfo::StartScene(FRenderViewpoint &parentvp, HWViewpointUniforms *uni mClipper = &staticClipper; Viewpoint = parentvp; - lightmode = Level->lightMode; + lightmode = getRealLightmode(Level, true); + if (uniforms) { VPUniforms = *uniforms; @@ -153,7 +154,7 @@ void HWDrawInfo::StartScene(FRenderViewpoint &parentvp, HWViewpointUniforms *uni VPUniforms.mViewMatrix.loadIdentity(); VPUniforms.mNormalViewMatrix.loadIdentity(); VPUniforms.mViewHeight = viewheight; - if (gl_lightmode == 5) + if (lightmode == ELightMode::Build) { VPUniforms.mGlobVis = 1 / 64.f; VPUniforms.mPalLightLevels = 32 | (static_cast(gl_fogmode) << 8) | ((int)lightmode << 16); diff --git a/src/version.h b/src/version.h index d6649ee22..e995dad82 100644 --- a/src/version.h +++ b/src/version.h @@ -65,7 +65,7 @@ const char *GetVersionString(); // Version stored in the ini's [LastRun] section. // Bump it if you made some configuration change that you want to // be able to migrate in FGameConfigFile::DoGlobalSetup(). -#define LASTRUNVERSION "224" +#define LASTRUNVERSION "225" // Protocol version used in demos. // Bump it if you change existing DEM_ commands or add new ones.