diff --git a/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp b/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp index c505640a3..3639d1bd7 100644 --- a/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp +++ b/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp @@ -33,9 +33,12 @@ void VkLightmap::Raytrace(hwrenderer::LevelMesh* level) UpdateAccelStructDescriptors(); // To do: we only need to do this if the accel struct changes. + CreateAtlasImages(); + BeginCommands(); UploadUniforms(); + for (size_t pageIndex = 0; pageIndex < atlasImages.size(); pageIndex++) { RenderAtlasImage(pageIndex); diff --git a/src/common/rendering/vulkan/accelstructs/vk_raytrace.cpp b/src/common/rendering/vulkan/accelstructs/vk_raytrace.cpp index 03b022129..9a7560cc6 100644 --- a/src/common/rendering/vulkan/accelstructs/vk_raytrace.cpp +++ b/src/common/rendering/vulkan/accelstructs/vk_raytrace.cpp @@ -71,6 +71,7 @@ void VkRaytrace::Reset() deletelist->Add(std::move(transferBuffer)); deletelist->Add(std::move(nodesBuffer)); deletelist->Add(std::move(surfaceBuffer)); + deletelist->Add(std::move(surfaceIndexBuffer)); deletelist->Add(std::move(portalBuffer)); deletelist->Add(std::move(blScratchBuffer)); deletelist->Add(std::move(blAccelStructBuffer)); diff --git a/src/common/rendering/vulkan/vk_renderdevice.cpp b/src/common/rendering/vulkan/vk_renderdevice.cpp index e70a19e66..fab7fe2d3 100644 --- a/src/common/rendering/vulkan/vk_renderdevice.cpp +++ b/src/common/rendering/vulkan/vk_renderdevice.cpp @@ -481,8 +481,8 @@ void VulkanRenderDevice::InitLightmap(int LMTextureSize, int LMTextureCount, TAr { Printf("Running VkLightmap.\n"); - VkLightmap lightmap(this); - lightmap.Raytrace(&mesh); + //VkLightmap lightmap(this); + //lightmap.Raytrace(&mesh); Printf("Copying data.\n"); @@ -490,6 +490,10 @@ void VulkanRenderDevice::InitLightmap(int LMTextureSize, int LMTextureCount, TAr auto clamp = [](float a, float min, float max) -> float { return a < min ? min : a > max ? max : a; }; + + std::sort(mesh.surfaces.begin(), mesh.surfaces.end(), [](const std::unique_ptr& a, const std::unique_ptr& b) { return a->texHeight != b->texHeight ? a->texHeight > b->texHeight : a->texWidth > b->texWidth; }); + + RectPacker packer(LMTextureSize, LMTextureSize); for (auto& surface : mesh.surfaces) diff --git a/src/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index 3d1d258dd..bcc48afbc 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.cpp +++ b/src/rendering/hwrenderer/doom_levelmesh.cpp @@ -10,6 +10,7 @@ #include "g_levellocals.h" #include "common/rendering/vulkan/accelstructs/vk_lightmap.h" +#include CCMD(dumplevelmesh) { @@ -511,11 +512,11 @@ int DoomLevelMesh::SetupLightmapUvs(int lightmapSize) hwSurface->boundsMax = surface.bounds.max; hwSurface->boundsMin = surface.bounds.min; - + // hwSurface->LightList = // TODO hwSurface->projLocalToU = surface.projLocalToU; hwSurface->projLocalToV = surface.projLocalToV; - hwSurface->smoothingGroupIndex = -1; + hwSurface->smoothingGroupIndex = 0; hwSurface->texHeight = surface.texHeight; hwSurface->texWidth = surface.texWidth; @@ -524,6 +525,13 @@ int DoomLevelMesh::SetupLightmapUvs(int lightmapSize) hwSurface->texPixels.resize(surface.texWidth * surface.texHeight); + for (auto& pixel : hwSurface->texPixels) + { + pixel.X = floatToHalf(0.0); + pixel.X = floatToHalf(1.0); + pixel.X = floatToHalf(0.0); + } + for (int i = 0; i < surface.numVerts; ++i) { hwSurface->verts.Push(MeshVertices[surface.startVertIndex + i]); @@ -539,6 +547,18 @@ int DoomLevelMesh::SetupLightmapUvs(int lightmapSize) info.Sky = surface.bSky; surfaceInfo.Push(info); + + + } + + { + hwrenderer::SmoothingGroup smoothing; + + for (auto& surface : surfaces) + { + smoothing.surfaces.push_back(surface.get()); + } + smoothingGroups.Push(std::move(smoothing)); } std::sort(sortedSurfaces.begin(), sortedSurfaces.end(), [](Surface* a, Surface* b) { return a->texHeight != b->texHeight ? a->texHeight > b->texHeight : a->texWidth > b->texWidth; });