From bfd4f7cbbb592d3261a430b4eeca445f8f105acb Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 13 Jul 2021 11:54:25 +0200 Subject: [PATCH] - added map option to disable shadowmaps. Prompted by 'Hurt' which has > 4000 lights and runs into both performance issues and unpredictable light selection for the limited amount of shadowmap slots. # Conflicts: # src/gamedata/g_mapinfo.h --- src/common/rendering/hwrenderer/data/hw_shadowmap.cpp | 4 ++-- src/gamedata/g_mapinfo.cpp | 6 ++++-- src/gamedata/g_mapinfo.h | 1 + src/rendering/hwrenderer/hw_dynlightdata.cpp | 3 +-- src/rendering/hwrenderer/hw_entrypoint.cpp | 8 +++++++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/common/rendering/hwrenderer/data/hw_shadowmap.cpp b/src/common/rendering/hwrenderer/data/hw_shadowmap.cpp index cb5630594a..f3e37ed614 100644 --- a/src/common/rendering/hwrenderer/data/hw_shadowmap.cpp +++ b/src/common/rendering/hwrenderer/data/hw_shadowmap.cpp @@ -85,7 +85,7 @@ CUSTOM_CVAR(Int, gl_shadowmap_quality, 512, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) bool IShadowMap::ShadowTest(const DVector3 &lpos, const DVector3 &pos) { - if (mAABBTree && gl_light_shadowmap) + if (mAABBTree) return mAABBTree->RayTest(lpos, pos) >= 1.0f; else return true; @@ -98,7 +98,7 @@ bool IShadowMap::PerformUpdate() LightsProcessed = 0; LightsShadowmapped = 0; - if (gl_light_shadowmap && (screen->hwcaps & RFL_SHADER_STORAGE_BUFFER) && CollectLights != nullptr) + if (CollectLights != nullptr) { UpdateCycles.Clock(); UploadAABBTree(); diff --git a/src/gamedata/g_mapinfo.cpp b/src/gamedata/g_mapinfo.cpp index fd7b795279..bfffad7c9c 100644 --- a/src/gamedata/g_mapinfo.cpp +++ b/src/gamedata/g_mapinfo.cpp @@ -1652,8 +1652,10 @@ MapFlagHandlers[] = { "nolightfade", MITYPE_SETFLAG3, LEVEL3_NOLIGHTFADE, 0 }, { "nocoloredspritelighting", MITYPE_SETFLAG3, LEVEL3_NOCOLOREDSPRITELIGHTING, 0 }, { "forceworldpanning", MITYPE_SETFLAG3, LEVEL3_FORCEWORLDPANNING, 0 }, - { "propermonsterfallingdamage", MITYPE_SETFLAG3, LEVEL3_PROPERMONSTERFALLINGDAMAGE, 0 }, - { "enableskyboxao", MITYPE_SETFLAG3, LEVEL3_SKYBOXAO, 0 }, + { "propermonsterfallingdamage", MITYPE_SETFLAG3, LEVEL3_PROPERMONSTERFALLINGDAMAGE, 0 }, + { "disableshadowmap", MITYPE_SETFLAG3, LEVEL3_NOSHADOWMAP, 0 }, + { "enableshadowmap", MITYPE_CLRFLAG3, LEVEL3_NOSHADOWMAP, 0 }, + { "enableskyboxao", MITYPE_SETFLAG3, LEVEL3_SKYBOXAO, 0 }, { "disableskyboxao", MITYPE_CLRFLAG3, LEVEL3_SKYBOXAO, 0 }, { "nobotnodes", MITYPE_IGNORE, 0, 0 }, // Skulltag option: nobotnodes { "compat_shorttex", MITYPE_COMPATFLAG, COMPATF_SHORTTEX, 0 }, diff --git a/src/gamedata/g_mapinfo.h b/src/gamedata/g_mapinfo.h index e96b1c4581..e150762914 100644 --- a/src/gamedata/g_mapinfo.h +++ b/src/gamedata/g_mapinfo.h @@ -252,6 +252,7 @@ enum ELevelFlags : unsigned int LEVEL3_HIDEAUTHORNAME = 0x00000100, LEVEL3_PROPERMONSTERFALLINGDAMAGE = 0x00000200, // Properly apply falling damage to the monsters LEVEL3_SKYBOXAO = 0x00000400, // Apply SSAO to sector skies + LEVEL3_NOSHADOWMAP = 0x00010000, // disables shadowmaps for a given level. }; diff --git a/src/rendering/hwrenderer/hw_dynlightdata.cpp b/src/rendering/hwrenderer/hw_dynlightdata.cpp index dddc9ad4df..f65b031726 100644 --- a/src/rendering/hwrenderer/hw_dynlightdata.cpp +++ b/src/rendering/hwrenderer/hw_dynlightdata.cpp @@ -107,10 +107,9 @@ void AddLightToList(FDynLightData &dld, int group, FDynamicLight * light, bool f } float shadowIndex; - if (gl_light_shadowmap) + if (gl_light_shadowmap) // note: with gl_light_shadowmap switched off, we cannot rely on properly set indices anymore. { shadowIndex = light->mShadowmapIndex + 1.0f; - } else shadowIndex = 1025.f; // Store attenuate flag in the sign bit of the float. diff --git a/src/rendering/hwrenderer/hw_entrypoint.cpp b/src/rendering/hwrenderer/hw_entrypoint.cpp index 5485cedc08..1845f051c5 100644 --- a/src/rendering/hwrenderer/hw_entrypoint.cpp +++ b/src/rendering/hwrenderer/hw_entrypoint.cpp @@ -107,7 +107,7 @@ sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bou R_SetupFrame(mainvp, r_viewwindow, camera); - if (mainview && toscreen) + if (mainview && toscreen && !(camera->Level->flags3 & LEVEL3_NOSHADOWMAP) && gl_light_shadowmap && (screen->hwcaps & RFL_SHADER_STORAGE_BUFFER)) { screen->SetAABBTree(camera->Level->aabbTree); screen->mShadowMap.SetCollectLights([=] { @@ -115,6 +115,12 @@ sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bou }); screen->UpdateShadowMap(); } + else + { + // null all references to the level if we do not need a shadowmap. This will shortcut all internal calculations without further checks. + screen->SetAABBTree(nullptr); + screen->mShadowMap.SetCollectLights(nullptr); + } // Update the attenuation flag of all light defaults for each viewpoint. // This function will only do something if the setting differs.