Only force baking of tiles where the geometry changed

This commit is contained in:
Magnus Norddahl 2025-05-13 01:51:41 +02:00
commit 76fb5901d7
8 changed files with 106 additions and 45 deletions

View file

@ -137,7 +137,7 @@ LevelMeshTileStats LevelMesh::GatherTilePixelStats()
stats.pixels.total += area;
if (tile.NeedsUpdate)
if (tile.NeedsInitialBake)
{
stats.tiles.dirty++;
stats.pixels.dirty += area;
@ -160,7 +160,7 @@ void LevelMesh::PackLightmapAtlas()
tile.AddedThisFrame = false;
if (tile.NeedsUpdate) // false for tiles loaded from lump
if (tile.NeedsInitialBake || tile.GeometryUpdate) // NeedsInitialBake is false for tiles loaded from lump
tile.SetupTileTransform(Lightmap.TextureSize);
sortedTiles.push_back(&tile);

View file

@ -57,8 +57,14 @@ struct LightmapTile
uint16_t SampleDimension = 0;
FVector4 Plane = FVector4(0.0f, 0.0f, 1.0f, 0.0f);
// True if the tile needs to be rendered into the lightmap texture before it can be used
bool NeedsUpdate = true;
// Initial tile for surfaces that can be baked in the background
bool NeedsInitialBake = false;
// This tile MUST be baked before it can be rendered
bool GeometryUpdate = true;
// The light for this tile changed since last bake
bool ReceivedNewLight = true;
// Used to track if tile has already been added to the VisibleTiles list for this scene
int LastSeen = 0;

View file

@ -142,7 +142,7 @@ void VkLightmapper::SelectTiles(const TArray<LightmapTile*>& tiles)
{
LightmapTile* tile = tiles[i];
if (!tile->NeedsUpdate)
if (!tile->ReceivedNewLight)
continue;
// Only grab surfaces until our bake texture is full
@ -158,7 +158,9 @@ void VkLightmapper::SelectTiles(const TArray<LightmapTile*>& tiles)
bakeImage.maxX = std::max<uint16_t>(bakeImage.maxX, uint16_t(result->X + tile->AtlasLocation.Width));
bakeImage.maxY = std::max<uint16_t>(bakeImage.maxY, uint16_t(result->Y + tile->AtlasLocation.Height));
tile->NeedsUpdate = false;
tile->ReceivedNewLight = false;
tile->NeedsInitialBake = false;
tile->GeometryUpdate = false;
}
}
@ -248,7 +250,7 @@ void VkLightmapper::Render()
{
while (i < count)
{
selectedTiles[i].Tile->NeedsUpdate = true;
selectedTiles[i].Tile->ReceivedNewLight = true;
i++;
}
break;