Bake the lightmap

This commit is contained in:
Magnus Norddahl 2025-01-12 15:24:42 +01:00
commit 303a7c27b0

View file

@ -2,6 +2,7 @@
#include "lightmapcmd.h"
#include "g_levellocals.h"
#include "d_event.h"
#include "v_video.h"
void G_SetMap(const char* mapname, int mode);
void D_SingleTick();
@ -41,8 +42,56 @@ void LightmapBuildCmdlet::OnCommand(FArgs args)
break;
}
Printf("Baking LIGHTMAP lump!\n");
Printf("Current map is %s", level.LevelName.GetChars());
if (!level.levelMesh)
{
Printf("No level mesh. Perhaps your level has no lightmap loaded?\n");
return;
}
if (!level.lightmaps)
{
Printf("Lightmap is not enabled in this level.\n");
}
Printf("Baking lightmaps. Please wait...\n");
uint32_t atlasPixelCount = level.levelMesh->AtlasPixelCount();
auto stats = level.levelMesh->GatherTilePixelStats();
Printf("Surfaces: %u (awaiting updates: %u static, %u dynamic)\n", stats.tiles.total, stats.tiles.dirty, stats.tiles.dirtyDynamic);
Printf("Surface pixel area to update: %u static, %u dynamic\n", stats.pixels.dirty, stats.pixels.dirtyDynamic);
Printf("Surface pixel area: %u\nAtlas pixel area: %u\n", stats.pixels.total, atlasPixelCount);
Printf("Atlas efficiency: %.4f%%\n", float(stats.pixels.total) / float(atlasPixelCount) * 100.0f);
Printf("Baking lightmap. Please wait...\n");
TArray<LightmapTile*> tiles;
while (stats.tiles.dirty > 0)
{
tiles.Clear();
for (auto& e : level.levelMesh->Lightmap.Tiles)
{
if (e.NeedsUpdate && e.AlwaysUpdate == 0)
{
tiles.Push(&e);
if (tiles.Size() == 1001)
break;
}
}
if (tiles.Size() == 0)
break;
screen->BeginFrame();
screen->UpdateLightmaps(tiles);
screen->Update();
}
Printf("Finished baking map.\n");
level.levelMesh->SaveLightmapLump(level);
Printf("Lightmap build complete.\n");
});
}