From c63fc707a4cbf21d27e8978605db709e09dcf8a5 Mon Sep 17 00:00:00 2001 From: RaveYard <29225776+MrRaveYard@users.noreply.github.com> Date: Thu, 31 Aug 2023 20:06:13 +0200 Subject: [PATCH] WIP fake raytracer output --- .../vulkan/accelstructs/vk_lightmap.cpp | 3 +++ .../vulkan/accelstructs/vk_raytrace.cpp | 1 + .../rendering/vulkan/vk_renderdevice.cpp | 8 +++++-- src/rendering/hwrenderer/doom_levelmesh.cpp | 24 +++++++++++++++++-- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp b/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp index b05a2d7938..0f63512c5c 100644 --- a/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp +++ b/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp @@ -34,9 +34,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 03b0221297..9a7560cc62 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 bc477e7ec1..78455612d3 100644 --- a/src/common/rendering/vulkan/vk_renderdevice.cpp +++ b/src/common/rendering/vulkan/vk_renderdevice.cpp @@ -482,8 +482,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"); @@ -491,6 +491,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 3d1d258dd6..bcc48afbc2 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; });