Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MapInfo/ZScript Lightmap Control #71

Merged
merged 6 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/gamedata/gi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, defaultdropstyle)
DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, normforwardmove)
DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, normsidemove)
DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, mHideParTimes)
DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, forceEnableLightmaps)
DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, defaultSunColor)
DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, defaultSunDirection)
DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, defaultLightmapSampleDistance)

const char *GameNames[17] =
{
Expand Down Expand Up @@ -209,6 +213,19 @@ const char* GameInfoBorders[] =
gameinfo.key[1] = sc.Float; \
}

#define GAMEINFOKEY_THREEDOUBLES(key, variable) \
else if(nextKey.CompareNoCase(variable) == 0) \
{ \
sc.MustGetValue(true); \
gameinfo.key[0] = sc.Float; \
sc.MustGetToken(','); \
sc.MustGetValue(true); \
gameinfo.key[1] = sc.Float; \
sc.MustGetToken(','); \
sc.MustGetValue(true); \
gameinfo.key[2] = sc.Float; \
}

#define GAMEINFOKEY_COLOR(key, variable) \
else if(nextKey.CompareNoCase(variable) == 0) \
{ \
Expand Down Expand Up @@ -464,7 +481,9 @@ void FMapInfoParser::ParseGameInfo()
GAMEINFOKEY_TWODOUBLES(normsidemove, "normsidemove")
GAMEINFOKEY_BOOL(nomergepickupmsg, "nomergepickupmsg")
GAMEINFOKEY_BOOL(mHideParTimes, "hidepartimes")

GAMEINFOKEY_BOOL(forceEnableLightmaps, "forceenablelightmaps")
GAMEINFOKEY_THREEDOUBLES(defaultSunColor, "defaultsuncolor")
GAMEINFOKEY_THREEDOUBLES(defaultSunDirection, "defaultSunDirection")
else
{
DPrintf(DMSG_ERROR, "Unknown GAMEINFO key \"%s\" found in %s:%i\n", nextKey.GetChars(), sc.ScriptName.GetChars(), sc.Line);
Expand Down
4 changes: 4 additions & 0 deletions src/gamedata/gi.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ struct gameinfo_t
bool nomergepickupmsg;
bool mHideParTimes;
CutsceneDef IntroScene;
bool forceEnableLightmaps = false;
FVector3 defaultSunColor = FVector3(1.f, 1.f, 1.f);
FVector3 defaultSunDirection = FVector3(0.45f, 0.3f, 0.9f);
int defaultLightmapSampleDistance = 16;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the merge conflicts 🙏 We're using a default value of 8 now, to match UDB's default, plus 16 is a little too blurry to be usable...


const char *GetFinalePage(unsigned int num) const;
};
Expand Down
8 changes: 4 additions & 4 deletions src/maploader/maploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3200,10 +3200,10 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position)
const int *oldvertextable = nullptr;

// Reset defaults for lightmapping
Level->SunColor = FVector3(1.f, 1.f, 1.f);
Level->SunDirection = FVector3(0.45f, 0.3f, 0.9f);
Level->LightmapSampleDistance = 8;
Level->lightmaps = false;
Level->SunColor = gameinfo.defaultSunColor;
Level->SunDirection = gameinfo.defaultSunDirection;
Level->LightmapSampleDistance = gameinfo.defaultLightmapSampleDistance;
Level->lightmaps = gameinfo.forceEnableLightmaps;

// note: most of this ordering is important
ForceNodeBuild = gennodes;
Expand Down
7 changes: 6 additions & 1 deletion src/p_saveg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,9 @@ void FLevelLocals::Serialize(FSerializer &arc, bool hubload)
("scrolls", Scrolls)
("automap", automap)
("interpolator", interpolator)
("frozenstate", frozenstate);
("frozenstate", frozenstate)
("suncolor", SunColor)
("sundirection", SunDirection);


// Hub transitions must keep the current total time
Expand All @@ -1027,6 +1029,9 @@ void FLevelLocals::Serialize(FSerializer &arc, bool hubload)
{
InitSkyMap(this);
AirControlChanged();

levelMesh->SunColor = SunColor;
levelMesh->SunDirection = SunDirection;
}

Behaviors.SerializeModuleStates(arc);
Expand Down
5 changes: 5 additions & 0 deletions src/playsim/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,11 @@ class AActor final : public DThinker
DVector3 Pos = DVector3(-12345678.0, -12345678.0, -12345678.0);
uint64_t Bits = 0;
} StaticLightsTraceCache;

void InvalidateLightTraceCache()
{
StaticLightsTraceCache.Pos.X = -1e80;
}
};

class FActorIterator
Expand Down
73 changes: 72 additions & 1 deletion src/rendering/hwrenderer/doom_levelmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "hwrenderer/scene/hw_flatdispatcher.h"
#include <unordered_map>

#include "vm.h"

static bool RequireLevelMesh()
{
if (level.levelMesh)
Expand All @@ -38,6 +40,20 @@ static bool RequireLightmap()
return false;
}

static int InvalidateLightmap()
{
int count = 0;

for (auto& tile : level.levelMesh->LightmapTiles)
{
if (!tile.NeedsUpdate)
++count;
tile.NeedsUpdate = true;
}

return count;
}

ADD_STAT(lightmap)
{
FString out;
Expand Down Expand Up @@ -84,7 +100,7 @@ CCMD(invalidatelightmap)
{
if (!RequireLightmap()) return;

int count = 0;
int count = InvalidateLightmap();
for (auto& tile : level.levelMesh->Lightmap.Tiles)
{
if (!tile.NeedsUpdate)
Expand Down Expand Up @@ -2198,3 +2214,58 @@ FString DoomLevelMesh::GetMapFilename(FLevelLocals& doomMap)
FString fullpath = folder + filename;
return fullpath;
}

// struct lightmap

static void InvalidateActorLightTraceCache()
{
auto it = level.GetThinkerIterator<AActor>();
AActor* ac;
while ((ac = it.Next()))
{
ac->InvalidateLightTraceCache();
}
}

DEFINE_ACTION_FUNCTION(_Lightmap, Invalidate)
{
PARAM_PROLOGUE;
InvalidateLightmap();
InvalidateActorLightTraceCache();
return 0;
}

DEFINE_ACTION_FUNCTION(_Lightmap, SetSunDirection)
{
PARAM_PROLOGUE;
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_FLOAT(z);

auto vec = FVector3(float(x), float(y), float(z));

if (!vec.isZero() && level.levelMesh)
{
vec.MakeUnit();
level.SunDirection = vec;
level.levelMesh->SunDirection = vec;
}
return 0;
}

DEFINE_ACTION_FUNCTION(_Lightmap, SetSunColor)
{
PARAM_PROLOGUE;
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_FLOAT(z);

if (level.levelMesh)
{
auto vec = FVector3(float(x), float(y), float(z));
level.SunColor = vec;
level.levelMesh->SunColor = vec;
}
return 0;
}

19 changes: 19 additions & 0 deletions wadsrc/static/zscript/doombase.zs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ extend struct GameInfoStruct
native double normforwardmove[2];
native double normsidemove[2];
native bool mHideParTimes;
native bool forceEnableLightmaps;
native FVector3 defaultSunColor;
native FVector3 defaultSunDirection;
native int defaultLightmapSampleDistance;
}

extend class Object
Expand Down Expand Up @@ -806,3 +810,18 @@ struct FRailParams
native int SpiralOffset;
native int limit;
}; // [RH] Shoot a railgun


struct Lightmap
{
// Mark all lightmap surfaces for recalculation. The internal lightmapper will gradually recalculate every single lightmap surface in the level.
native static void Invalidate();

// Set direction of the light towards the sun.
// Calling this does NOT recalculate the lightmap.
native static void SetSunDirection(Vector3 dir);

// Can go above 1.0 (call Invalidate())
// Calling this does NOT recalculate the lightmap.
native static void SetSunColor(Vector3 color);
};
Loading