From c2901404d5fe4d55c4b3ef2522220446be12ed25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Thu, 12 Dec 2024 19:50:21 -0300 Subject: [PATCH] ensure non-dynamic tiles are baked first --- .../hwrenderer/scene/hw_drawinfo.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp index 22c172cfa..133789533 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp @@ -687,16 +687,31 @@ void HWDrawInfo::UpdateLightmaps() { if (!outer && VisibleTiles.Size() < unsigned(lm_background_updates)) { + int unbaked = 0; + int dynamic = 0; + for (auto& e : level.levelMesh->Lightmap.Tiles) { if (e.NeedsUpdate) { + if(e.AlwaysUpdate == 0) unbaked++; + if(e.AlwaysUpdate != 0) dynamic++; + VisibleTiles.Push(&e); - if (VisibleTiles.Size() >= unsigned(lm_background_updates)) - break; + if((!dynamic && (VisibleTiles.Size() >= unsigned(lm_background_updates))) || unbaked >= unsigned(lm_background_updates)) break; } } + + if(unbaked && dynamic) + { + std::sort(VisibleTiles.begin(), VisibleTiles.end(), [](LightmapTile *a, LightmapTile *b){return (!!a->AlwaysUpdate) < (!!b->AlwaysUpdate);}); + } + + if(VisibleTiles.Size() > unsigned(lm_background_updates)) + { + VisibleTiles.Resize(lm_background_updates); + } } screen->UpdateLightmaps(VisibleTiles); }