Remove smoothing groups from vk_lightmap and fix some warnings

This commit is contained in:
Magnus Norddahl 2023-09-25 20:35:34 +02:00 committed by Christoph Oelckers
parent 2d37bfe527
commit cfea7404cf
4 changed files with 33 additions and 32 deletions

View file

@ -209,7 +209,6 @@ public:
virtual int AddSurfaceLights(const LevelMeshSurface* surface, LevelMeshLight* list, int listMaxSize) { return 0; } virtual int AddSurfaceLights(const LevelMeshSurface* surface, LevelMeshLight* list, int listMaxSize) { return 0; }
TArray<LevelMeshSmoothingGroup> SmoothingGroups;
TArray<LevelMeshPortal> Portals; TArray<LevelMeshPortal> Portals;
// Lightmap atlas // Lightmap atlas
@ -297,8 +296,11 @@ public:
return hitSurface; // I hit something return hitSurface; // I hit something
} }
protected:
void BuildSmoothingGroups() void BuildSmoothingGroups()
{ {
TArray<LevelMeshSmoothingGroup> SmoothingGroups;
for (int i = 0, count = GetSurfaceCount(); i < count; i++) for (int i = 0, count = GetSurfaceCount(); i < count; i++)
{ {
auto surface = GetSurface(i); auto surface = GetSurface(i);
@ -340,5 +342,27 @@ public:
SmoothingGroups[smoothingGroupIndex].surfaces.push_back(surface); SmoothingGroups[smoothingGroupIndex].surfaces.push_back(surface);
surface->smoothingGroupIndex = smoothingGroupIndex; 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);
} }
}; };

View file

@ -187,19 +187,6 @@ void VkLightmap::Render()
bool buffersFull = false; 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 // Paint all surfaces visible in the tile
for (LevelMeshSurface* surface : targetSurface->tileSurfaces) for (LevelMeshSurface* surface : targetSurface->tileSurfaces)
{ {
@ -529,14 +516,6 @@ void VkLightmap::CopyResult()
fb->GetCommands()->PopGroup(cmdbuffer); 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() void VkLightmap::CreateShaders()
{ {
std::string prefix = "#version 460\r\n"; std::string prefix = "#version 460\r\n";

View file

@ -149,8 +149,6 @@ private:
void CreateDrawIndexedBuffer(); void CreateDrawIndexedBuffer();
void CreateBakeImage(); void CreateBakeImage();
static FVector2 ToUV(const FVector3& vert, const LevelMeshSurface* targetSurface);
static FString LoadPrivateShaderLump(const char* lumpname); static FString LoadPrivateShaderLump(const char* lumpname);
VulkanRenderDevice* fb = nullptr; VulkanRenderDevice* fb = nullptr;

View file

@ -864,20 +864,20 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
auto gameTexture = TexMan.GetGameTexture(texture); auto gameTexture = TexMan.GetGameTexture(texture);
float mid1Top = gameTexture->GetDisplayHeight() / side->textures[side_t::mid].yScale; float mid1Top = (float)(gameTexture->GetDisplayHeight() / side->textures[side_t::mid].yScale);
float mid2Top = gameTexture->GetDisplayHeight() / side->textures[side_t::mid].yScale; float mid2Top = (float)(gameTexture->GetDisplayHeight() / side->textures[side_t::mid].yScale);
float mid1Bottom = 0; float mid1Bottom = 0;
float mid2Bottom = 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) if (side->linedef->flags & ML_DONTPEGBOTTOM)
{ {
yTextureOffset += side->sector->planes[sector_t::floor].TexZ; yTextureOffset += (float)side->sector->planes[sector_t::floor].TexZ;
} }
else 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); 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.bSky = false;
surf.plane = ToPlane(verts[0], verts[1], verts[2], verts[3]); 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) if (side->linedef->sidedef[0] != side)
{ {
@ -1651,8 +1651,8 @@ void DoomLevelMesh::CreateSurfaceTextureUVs(FLevelLocals& doomMap)
auto a = line->v2->fPos() - line->v1->fPos(); auto a = line->v2->fPos() - line->v1->fPos();
for (int i = 0; i < 4; ++i) 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].X = tci.FloatToTexU((float)(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].Y = tci.FloatToTexV((float)(uvs[i].Y * sideHeight + side->textures[side_t::mid].yOffset));
//uvs[i].Y = tci.FloatToTexU(0); //uvs[i].Y = tci.FloatToTexU(0);
//uvs[i].X = uvs[i].X * repeatsU + anchorU / w; //uvs[i].X = uvs[i].X * repeatsU + anchorU / w;
//uvs[i].Y = uvs[i].Y * repeatsV + anchorZ / h; //uvs[i].Y = uvs[i].Y * repeatsV + anchorZ / h;