Allow lm_dynamic to be able to set level-wide in ZDRayInfo

This commit is contained in:
nashmuhandes 2025-06-11 15:24:38 +08:00 committed by Nash Muhandes
commit c40a36ea7c
7 changed files with 33 additions and 2 deletions

View file

@ -120,6 +120,7 @@ public:
float SunIntensity = 1.0f;
bool AmbientOcclusion = true;
bool LightBounce = true;
bool LevelWideLMDynamic = false; // Whole map has dynamic lightmaps enabled via ZDRayInfo (no need to set it per sector)
TArray<LevelMeshPortal> Portals;

View file

@ -482,6 +482,7 @@ public:
uint16_t LightmapSampleDistance = 0;
bool LightBounce = false;
bool AmbientOcclusion = true;
bool LevelWideLMDynamic = false; // Whole map has dynamic lightmaps enabled via ZDRayInfo (no need to set it per sector)
// Portal information.
FDisplacementTable Displacements;

View file

@ -3253,6 +3253,7 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position)
Level->lightmaps = gameinfo.forceEnableLightmaps;
Level->LightBounce = false;
Level->AmbientOcclusion = true;
Level->LevelWideLMDynamic = false;
// note: most of this ordering is important
ForceNodeBuild = gennodes;

View file

@ -852,6 +852,11 @@ public:
Level->AmbientOcclusion = CheckBool(key);
break;
case NAME_lm_dynamic:
CHECK_N(Zd | Zdt)
Level->LevelWideLMDynamic = CheckBool(key);
break;
default:
CHECK_N(Zd | Zdt)
if (0 == strnicmp("user_", key.GetChars(), 5))

View file

@ -22,6 +22,7 @@
#include "vm.h"
#include "p_setup.h"
static void UpdateLightmapTiles();
static int InvalidateLightmap();
static void InvalidateActorLightTraceCache();
@ -74,6 +75,16 @@ static bool RequireLightmap()
return false;
}
// Forces lightmap tiles update
static void UpdateLightmapTiles()
{
for (auto& tile : level.levelMesh->Lightmap.Tiles)
{
if (!tile.NeedsInitialBake)
tile.ReceivedNewLight = true;
}
}
static int InvalidateLightmap()
{
int count = 0;
@ -251,6 +262,7 @@ DoomLevelMesh::DoomLevelMesh(FLevelLocals& doomMap)
Lightmap.SampleDistance = doomMap.LightmapSampleDistance;
LightBounce = doomMap.LightBounce;
AmbientOcclusion = doomMap.AmbientOcclusion;
LevelWideLMDynamic = doomMap.LevelWideLMDynamic;
// HWWall and HWFlat still looks at r_viewpoint when doing calculations,
// but we aren't rendering a specific viewpoint when this function gets called
@ -2717,6 +2729,14 @@ static void InvalidateActorLightTraceCache()
}
}
DEFINE_ACTION_FUNCTION(_Lightmap, Update)
{
PARAM_PROLOGUE;
UpdateLightmapTiles();
InvalidateActorLightTraceCache();
return 0;
}
DEFINE_ACTION_FUNCTION(_Lightmap, Invalidate)
{
PARAM_PROLOGUE;

View file

@ -297,7 +297,7 @@ public:
if (tile->Binding.Type == ST_UPPERSIDE || tile->Binding.Type == ST_MIDDLESIDE || tile->Binding.Type == ST_LOWERSIDE)
{
sector_t* sector = Level->sides[tile->Binding.TypeIndex].sector;
if (sector && (sector->Flags & SECF_LM_DYNAMIC || lm_dynlights))
if (sector && (sector->Flags & SECF_LM_DYNAMIC || lm_dynlights || Level->LevelWideLMDynamic))
{
VisibleTiles.ReceivedNewLight.Push(tile);
}
@ -305,7 +305,7 @@ public:
else if (tile->Binding.Type == ST_CEILING || tile->Binding.Type == ST_FLOOR)
{
sector_t* sector = Level->subsectors[tile->Binding.TypeIndex].sector;
if (sector && (sector->Flags & SECF_LM_DYNAMIC || lm_dynlights))
if (sector && (sector->Flags & SECF_LM_DYNAMIC || lm_dynlights || Level->LevelWideLMDynamic))
{
VisibleTiles.ReceivedNewLight.Push(tile);
}

View file

@ -969,6 +969,9 @@ struct FRailParams
struct Lightmap
{
// Mark lightmap tiles for update. Prefer this over Invalidate() as the latter can crash weak graphics cards.
native static void Update();
// Mark all lightmap surfaces for recalculation. The internal lightmapper will gradually recalculate every single lightmap surface in the level.
native static void Invalidate();