From cfea7404cf90d1dea29cf4bfe3aa51d2ec6c93d2 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Mon, 25 Sep 2023 20:35:34 +0200 Subject: [PATCH] Remove smoothing groups from vk_lightmap and fix some warnings --- .../rendering/hwrenderer/data/hw_levelmesh.h | 26 ++++++++++++++++++- .../vulkan/accelstructs/vk_lightmap.cpp | 21 --------------- .../vulkan/accelstructs/vk_lightmap.h | 2 -- src/rendering/hwrenderer/doom_levelmesh.cpp | 16 ++++++------ 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/common/rendering/hwrenderer/data/hw_levelmesh.h b/src/common/rendering/hwrenderer/data/hw_levelmesh.h index e00bdfe304..1fce1faed0 100644 --- a/src/common/rendering/hwrenderer/data/hw_levelmesh.h +++ b/src/common/rendering/hwrenderer/data/hw_levelmesh.h @@ -209,7 +209,6 @@ public: virtual int AddSurfaceLights(const LevelMeshSurface* surface, LevelMeshLight* list, int listMaxSize) { return 0; } - TArray SmoothingGroups; TArray Portals; // Lightmap atlas @@ -297,8 +296,11 @@ public: return hitSurface; // I hit something } +protected: void BuildSmoothingGroups() { + TArray SmoothingGroups; + for (int i = 0, count = GetSurfaceCount(); i < count; i++) { auto surface = GetSurface(i); @@ -340,5 +342,27 @@ public: SmoothingGroups[smoothingGroupIndex].surfaces.push_back(surface); surface->smoothingGroupIndex = smoothingGroupIndex; } + + for (int i = 0, count = GetSurfaceCount(); i < count; i++) + { + auto targetSurface = GetSurface(i); + for (LevelMeshSurface* surface : SmoothingGroups[targetSurface->smoothingGroupIndex].surfaces) + { + FVector2 minUV = ToUV(surface->bounds.min, targetSurface); + FVector2 maxUV = ToUV(surface->bounds.max, targetSurface); + if (surface != targetSurface && (maxUV.X < 0.0f || maxUV.Y < 0.0f || minUV.X > 1.0f || minUV.Y > 1.0f)) + continue; // Bounding box not visible + + targetSurface->tileSurfaces.Push(surface); + } + } + } + + FVector2 ToUV(const FVector3& vert, const LevelMeshSurface* targetSurface) + { + FVector3 localPos = vert - targetSurface->translateWorldToLocal; + float u = (1.0f + (localPos | targetSurface->projLocalToU)) / (targetSurface->texWidth + 2); + float v = (1.0f + (localPos | targetSurface->projLocalToV)) / (targetSurface->texHeight + 2); + return FVector2(u, v); } }; diff --git a/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp b/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp index 5d9bbd160d..afe5a30105 100644 --- a/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp +++ b/src/common/rendering/vulkan/accelstructs/vk_lightmap.cpp @@ -187,19 +187,6 @@ void VkLightmap::Render() bool buffersFull = false; - if (targetSurface->tileSurfaces.Size() == 0) // To do: move this to where we set up the smoothing groups as we don't need the groups after this step - { - for (LevelMeshSurface* surface : mesh->SmoothingGroups[targetSurface->smoothingGroupIndex].surfaces) - { - FVector2 minUV = ToUV(surface->bounds.min, targetSurface); - FVector2 maxUV = ToUV(surface->bounds.max, targetSurface); - if (surface != targetSurface && (maxUV.X < 0.0f || maxUV.Y < 0.0f || minUV.X > 1.0f || minUV.Y > 1.0f)) - continue; // Bounding box not visible - - targetSurface->tileSurfaces.Push(surface); - } - } - // Paint all surfaces visible in the tile for (LevelMeshSurface* surface : targetSurface->tileSurfaces) { @@ -529,14 +516,6 @@ void VkLightmap::CopyResult() fb->GetCommands()->PopGroup(cmdbuffer); } -FVector2 VkLightmap::ToUV(const FVector3& vert, const LevelMeshSurface* targetSurface) -{ - FVector3 localPos = vert - targetSurface->translateWorldToLocal; - float u = (1.0f + (localPos | targetSurface->projLocalToU)) / (targetSurface->texWidth + 2); - float v = (1.0f + (localPos | targetSurface->projLocalToV)) / (targetSurface->texHeight + 2); - return FVector2(u, v); -} - void VkLightmap::CreateShaders() { std::string prefix = "#version 460\r\n"; diff --git a/src/common/rendering/vulkan/accelstructs/vk_lightmap.h b/src/common/rendering/vulkan/accelstructs/vk_lightmap.h index b8e5d7b26e..c10d14836a 100644 --- a/src/common/rendering/vulkan/accelstructs/vk_lightmap.h +++ b/src/common/rendering/vulkan/accelstructs/vk_lightmap.h @@ -149,8 +149,6 @@ private: void CreateDrawIndexedBuffer(); void CreateBakeImage(); - static FVector2 ToUV(const FVector3& vert, const LevelMeshSurface* targetSurface); - static FString LoadPrivateShaderLump(const char* lumpname); VulkanRenderDevice* fb = nullptr; diff --git a/src/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index 4bcbdb3706..8b040ff6c1 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.cpp +++ b/src/rendering/hwrenderer/doom_levelmesh.cpp @@ -864,20 +864,20 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) auto gameTexture = TexMan.GetGameTexture(texture); - float mid1Top = gameTexture->GetDisplayHeight() / side->textures[side_t::mid].yScale; - float mid2Top = gameTexture->GetDisplayHeight() / side->textures[side_t::mid].yScale; + float mid1Top = (float)(gameTexture->GetDisplayHeight() / side->textures[side_t::mid].yScale); + float mid2Top = (float)(gameTexture->GetDisplayHeight() / side->textures[side_t::mid].yScale); float mid1Bottom = 0; float mid2Bottom = 0; - float yTextureOffset = side->textures[side_t::mid].yOffset / gameTexture->GetScaleY(); + float yTextureOffset = (float)(side->textures[side_t::mid].yOffset / gameTexture->GetScaleY()); if (side->linedef->flags & ML_DONTPEGBOTTOM) { - yTextureOffset += side->sector->planes[sector_t::floor].TexZ; + yTextureOffset += (float)side->sector->planes[sector_t::floor].TexZ; } else { - yTextureOffset += side->sector->planes[sector_t::ceiling].TexZ - gameTexture->GetDisplayHeight() / side->textures[side_t::mid].yScale; + yTextureOffset += (float)(side->sector->planes[sector_t::ceiling].TexZ - gameTexture->GetDisplayHeight() / side->textures[side_t::mid].yScale); } verts[0].Z = min(max(yTextureOffset + mid1Bottom, v1Bottom), v1Top); @@ -891,7 +891,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) surf.bSky = false; surf.plane = ToPlane(verts[0], verts[1], verts[2], verts[3]); - auto offset = FVector3(surf.plane.XYZ()) * 0.05; // for better accuracy when raytracing mid-textures from each side + FVector3 offset = surf.plane.XYZ() * 0.05f; // for better accuracy when raytracing mid-textures from each side if (side->linedef->sidedef[0] != side) { @@ -1651,8 +1651,8 @@ void DoomLevelMesh::CreateSurfaceTextureUVs(FLevelLocals& doomMap) auto a = line->v2->fPos() - line->v1->fPos(); for (int i = 0; i < 4; ++i) { - uvs[i].X = tci.FloatToTexU(uvs[i].X * a.Length() + side->textures[side_t::mid].xOffset); - uvs[i].Y = tci.FloatToTexV(uvs[i].Y * sideHeight + side->textures[side_t::mid].yOffset); + uvs[i].X = tci.FloatToTexU((float)(uvs[i].X * a.Length() + side->textures[side_t::mid].xOffset)); + uvs[i].Y = tci.FloatToTexV((float)(uvs[i].Y * sideHeight + side->textures[side_t::mid].yOffset)); //uvs[i].Y = tci.FloatToTexU(0); //uvs[i].X = uvs[i].X * repeatsU + anchorU / w; //uvs[i].Y = uvs[i].Y * repeatsV + anchorZ / h;