diff --git a/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp b/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp index a2d84d07e1..feea2d2477 100644 --- a/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp +++ b/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp @@ -54,7 +54,6 @@ void VkLightmap::Raytrace(LevelMesh* level, const TArray& sur { bool newLevel = (mesh != level); mesh = level; - if (newLevel) { UpdateAccelStructDescriptors(); @@ -63,62 +62,65 @@ void VkLightmap::Raytrace(LevelMesh* level, const TArray& sur lightmapRaytraceLast.Reset(); } - lightmapRaytrace.active = true; - lightmapRaytraceLast.active = true; + if (surfaces.Size()) + { + lightmapRaytrace.active = true; + lightmapRaytraceLast.active = true; - lightmapRaytrace.Clock(); - lightmapRaytraceLast.ResetAndClock(); + lightmapRaytrace.Clock(); + lightmapRaytraceLast.ResetAndClock(); - CreateAtlasImages(surfaces); + CreateAtlasImages(surfaces); #if 0 // SmoothGroups - TArray allSurfaces; + TArray allSurfaces; - std::set s; + std::set s; - for (auto& surface : surfaceIndices) - { - s.insert(mesh->GetSurface(surface)->smoothingGroupIndex); - } - - for (int i = 0, count = level->GetSurfaceCount(); i < count; ++i) - { - auto surface = level->GetSurface(i); - - if (s.find(surface->smoothingGroupIndex) != s.end()) + for (auto& surface : surfaceIndices) { - allSurfaces.Push(i); - surface->needsUpdate = false; + s.insert(mesh->GetSurface(surface)->smoothingGroupIndex); + } + + for (int i = 0, count = level->GetSurfaceCount(); i < count; ++i) + { + auto surface = level->GetSurface(i); + + if (s.find(surface->smoothingGroupIndex) != s.end()) + { + allSurfaces.Push(i); + surface->needsUpdate = false; + } } - } #else - const auto& allSurfaces = surfaces; + const auto& allSurfaces = surfaces; #endif - UploadUniforms(); + UploadUniforms(); - lastSurfaceCount = allSurfaces.Size(); + lastSurfaceCount = allSurfaces.Size(); - for (size_t pageIndex = 0; pageIndex < atlasImages.size(); pageIndex++) - { - if (atlasImages[pageIndex].pageMaxX && atlasImages[pageIndex].pageMaxY) + for (size_t pageIndex = 0; pageIndex < atlasImages.size(); pageIndex++) { - RenderAtlasImage(pageIndex, allSurfaces); + if (atlasImages[pageIndex].pageMaxX && atlasImages[pageIndex].pageMaxY) + { + RenderAtlasImage(pageIndex, allSurfaces); + } } - } - for (size_t pageIndex = 0; pageIndex < atlasImages.size(); pageIndex++) - { - if (atlasImages[pageIndex].pageMaxX && atlasImages[pageIndex].pageMaxY) + for (size_t pageIndex = 0; pageIndex < atlasImages.size(); pageIndex++) { - ResolveAtlasImage(pageIndex); - BlurAtlasImage(pageIndex); - CopyAtlasImageResult(pageIndex, allSurfaces); + if (atlasImages[pageIndex].pageMaxX && atlasImages[pageIndex].pageMaxY) + { + ResolveAtlasImage(pageIndex); + BlurAtlasImage(pageIndex); + CopyAtlasImageResult(pageIndex, allSurfaces); + } } - } - lightmapRaytrace.Unclock(); - lightmapRaytraceLast.Unclock(); + lightmapRaytrace.Unclock(); + lightmapRaytraceLast.Unclock(); + } } void VkLightmap::RenderAtlasImage(size_t pageIndex, const TArray& surfaces) @@ -272,7 +274,7 @@ void VkLightmap::CreateAtlasImages(const TArray& surfaces) LevelMeshSurface* surface = surfaces[i]; //for (int i = 0, count = mesh->GetSurfaceCount(); i < count; i++) //{ - //LevelMeshSurface* surface = mesh->GetSurface(i); + // LevelMeshSurface* surface = mesh->GetSurface(i); auto result = packer.insert(surface->texWidth + 2, surface->texHeight + 2); surface->lightmapperAtlasX = result.pos.x + 1; diff --git a/src/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index 17069cf9d0..97e16b37e8 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.cpp +++ b/src/rendering/hwrenderer/doom_levelmesh.cpp @@ -369,8 +369,6 @@ void DoomLevelMesh::BindLightmapSurfacesToGeometry(FLevelLocals& doomMap) { surface.TexCoords = (float*)&LightmapUvs[surface.startUvIndex]; - surface.LightmapNum = surface.atlasPageIndex; - if (surface.Type == ST_FLOOR || surface.Type == ST_CEILING) { surface.Subsector = &doomMap.subsectors[surface.typeIndex]; diff --git a/src/rendering/hwrenderer/doom_levelmesh.h b/src/rendering/hwrenderer/doom_levelmesh.h index d1e8216084..e9a9aa7fbe 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.h +++ b/src/rendering/hwrenderer/doom_levelmesh.h @@ -16,10 +16,9 @@ struct FLevelLocals; struct DoomLevelMeshSurface : public LevelMeshSurface { - subsector_t* Subsector; - side_t* Side; - sector_t* ControlSector; - uint32_t LightmapNum; // To do: same as atlasPageIndex. Delete one of them! + subsector_t* Subsector = nullptr; + side_t* Side = nullptr; + sector_t* ControlSector = nullptr; float* TexCoords; }; diff --git a/src/rendering/hwrenderer/hw_vertexbuilder.cpp b/src/rendering/hwrenderer/hw_vertexbuilder.cpp index 359c8a77bc..9c6e5d4a22 100644 --- a/src/rendering/hwrenderer/hw_vertexbuilder.cpp +++ b/src/rendering/hwrenderer/hw_vertexbuilder.cpp @@ -243,7 +243,7 @@ static int CreateIndexedSectorVerticesLM(FRenderState& renderstate, sector_t* se if (lightmap && lightmap->Type != ST_UNKNOWN) // lightmap may be missing if the subsector is degenerate triangle { float* luvs = lightmap->TexCoords; - int lindex = lightmap->LightmapNum; + int lindex = lightmap->atlasPageIndex; for (unsigned int j = 0; j < sub->numlines; j++) { SetFlatVertex(vbo_shadowdata[vi + pos], sub->firstline[j].v1, plane, luvs[j * 2], luvs[j * 2 + 1], lindex); diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index c4686a58e8..7b5b868b3c 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -1019,7 +1019,7 @@ bool HWWall::SetWallCoordinates(seg_t * seg, FTexCoordInfo *tci, float textureto if (lightmap && lightmap->Type != ST_UNKNOWN) { srclightuv = (texcoord*)lightmap->TexCoords; - lindex = (float)lightmap->LightmapNum; + lindex = (float)lightmap->atlasPageIndex; } else { @@ -1725,7 +1725,7 @@ void HWWall::BuildFFBlock(HWDrawInfo *di, FRenderState& state, seg_t * seg, F3DF if (lightmap && lightmap->Type != ST_UNKNOWN) { srclightuv = (texcoord*)lightmap->TexCoords; - lindex = (float)lightmap->LightmapNum; + lindex = (float)lightmap->atlasPageIndex; } else {