diff --git a/src/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index 2df459bba..8e2a7399a 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.cpp +++ b/src/rendering/hwrenderer/doom_levelmesh.cpp @@ -15,6 +15,8 @@ #include "hwrenderer/scene/hw_flatdispatcher.h" #include +#include "vm.h" + static bool RequireLevelMesh() { if (level.levelMesh) @@ -36,6 +38,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; @@ -71,13 +87,8 @@ CCMD(invalidatelightmap) { if (!RequireLightmap()) return; - int count = 0; - for (auto& tile : level.levelMesh->LightmapTiles) - { - if (!tile.NeedsUpdate) - ++count; - tile.NeedsUpdate = true; - } + int count = InvalidateLightmap(); + Printf("Marked %d out of %d tiles for update.\n", count, level.levelMesh->LightmapTiles.Size()); } @@ -1176,3 +1187,43 @@ void DoomLevelMesh::CreatePortals(FLevelLocals& doomMap) } } } + +// struct lightmap + +DEFINE_ACTION_FUNCTION(_Lightmap, Invalidate) +{ + PARAM_PROLOGUE; + InvalidateLightmap(); + 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()) + { + 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); + + auto vec = FVector3(float(x), float(y), float(z)); + level.SunColor = vec; + level.levelMesh->SunColor = vec; + return 0; +} \ No newline at end of file diff --git a/wadsrc/static/zscript/doombase.zs b/wadsrc/static/zscript/doombase.zs index 479f802a2..836851b4e 100644 --- a/wadsrc/static/zscript/doombase.zs +++ b/wadsrc/static/zscript/doombase.zs @@ -807,3 +807,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); +}; \ No newline at end of file