From 23deb113991566502d102eb0e435d6fbfc9af8d8 Mon Sep 17 00:00:00 2001 From: RaveYard <29225776+MrRaveYard@users.noreply.github.com> Date: Thu, 31 Aug 2023 22:53:55 +0200 Subject: [PATCH] Merge Surface into hwrenderer::Surface --- .../rendering/hwrenderer/data/hw_levelmesh.h | 64 ++++++++++++------- src/gamedata/r_defs.h | 13 +--- src/maploader/maploader.cpp | 15 +++-- src/rendering/hwrenderer/doom_levelmesh.cpp | 27 ++++---- src/rendering/hwrenderer/doom_levelmesh.h | 46 ++----------- src/rendering/hwrenderer/hw_vertexbuilder.cpp | 2 +- src/rendering/hwrenderer/scene/hw_walls.cpp | 4 +- 7 files changed, 73 insertions(+), 98 deletions(-) diff --git a/src/common/rendering/hwrenderer/data/hw_levelmesh.h b/src/common/rendering/hwrenderer/data/hw_levelmesh.h index 2e9119e82..a15bd95c1 100644 --- a/src/common/rendering/hwrenderer/data/hw_levelmesh.h +++ b/src/common/rendering/hwrenderer/data/hw_levelmesh.h @@ -56,43 +56,59 @@ enum SurfaceType ST_FLOOR }; -class Surface +struct Surface { -public: - // Surface geometry SurfaceType type = ST_UNKNOWN; + int typeIndex; + int numVerts; + unsigned int startVertIndex; + unsigned int startUvIndex; + FVector4 plane; + void* controlSector; // type is sector_t + bool bSky; + + // Lightmap UV information in pixel size + int atlasPageIndex = 0; + int atlasX = 0; + int atlasY = 0; + int texWidth = 0; + int texHeight = 0; + + // + // Required for internal lightmapper: + // + + BBox bounds; + int sampleDimension = 0; + + // Lightmap world coordinates for the texture + FVector3 worldOrigin = { 0.f, 0.f, 0.f }; + FVector3 worldStepX = { 0.f, 0.f, 0.f }; + FVector3 worldStepY = { 0.f, 0.f, 0.f }; + + // Calculate world coordinates to UV coordinates + FVector3 translateWorldToLocal = { 0.f, 0.f, 0.f }; + FVector3 projLocalToU = { 0.f, 0.f, 0.f }; + FVector3 projLocalToV = { 0.f, 0.f, 0.f }; + + // Smoothing group surface is to be rendered with + int smoothingGroupIndex = -1; + + // + // VkLightmap extra stuff that I dislike: + // TArray verts; TArray uvs; - //Plane plane; FVector3 boundsMin, boundsMax; // Touching light sources std::vector LightList; - // Lightmap world coordinates for the texture - FVector3 worldOrigin = { 0.0f, 0.0f, 0.0f }; - FVector3 worldStepX = { 0.0f, 0.0f, 0.0f }; - FVector3 worldStepY = { 0.0f, 0.0f, 0.0f }; - - // Calculate world coordinates to UV coordinates - FVector3 translateWorldToLocal = { 0.0f, 0.0f, 0.0f }; - FVector3 projLocalToU = { 0.0f, 0.0f, 0.0f }; - FVector3 projLocalToV = { 0.0f, 0.0f, 0.0f }; - // Output lightmap for the surface - int texWidth = 0; - int texHeight = 0; std::vector texPixels; - - // Placement in final texture atlas - int atlasPageIndex = -1; - int atlasX = 0; - int atlasY = 0; - - // Smoothing group surface is to be rendered with - int smoothingGroupIndex = -1; }; + struct SmoothingGroup { FVector4 plane = FVector4(0, 0, 1, 0); diff --git a/src/gamedata/r_defs.h b/src/gamedata/r_defs.h index 74858907c..cb5880e9f 100644 --- a/src/gamedata/r_defs.h +++ b/src/gamedata/r_defs.h @@ -41,6 +41,7 @@ #include "p_terrain.h" #include "hwrenderer/data/buffers.h" +#include "hwrenderer/data/hw_levelmesh.h" // Some more or less basic data types // we depend on. @@ -1689,19 +1690,9 @@ struct FMiniBSP // Lightmap data -enum SurfaceType -{ - ST_NULL, - ST_MIDDLEWALL, - ST_UPPERWALL, - ST_LOWERWALL, - ST_CEILING, - ST_FLOOR -}; - struct LightmapSurface { - SurfaceType Type; + hwrenderer::SurfaceType Type; subsector_t *Subsector; side_t *Side; sector_t *ControlSector; diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index 204aa4bc5..8764f1f77 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -3282,16 +3282,17 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position) // //========================================================================== + void MapLoader::SetSubsectorLightmap(const LightmapSurface &surface) { if (!surface.ControlSector) { - int index = surface.Type == ST_CEILING ? 1 : 0; + int index = surface.Type == hwrenderer::ST_CEILING ? 1 : 0; surface.Subsector->lightmap[index][0] = surface; } else { - int index = surface.Type == ST_CEILING ? 0 : 1; + int index = surface.Type == hwrenderer::ST_CEILING ? 0 : 1; const auto &ffloors = surface.Subsector->sector->e->XFloor.ffloors; for (unsigned int i = 0; i < ffloors.Size(); i++) { @@ -3307,16 +3308,16 @@ void MapLoader::SetSideLightmap(const LightmapSurface &surface) { if (!surface.ControlSector) { - if (surface.Type == ST_UPPERWALL) + if (surface.Type == hwrenderer::ST_UPPERSIDE) { surface.Side->lightmap[0] = surface; } - else if (surface.Type == ST_MIDDLEWALL) + else if (surface.Type == hwrenderer::ST_MIDDLESIDE) { surface.Side->lightmap[1] = surface; surface.Side->lightmap[2] = surface; } - else if (surface.Type == ST_LOWERWALL) + else if (surface.Type == hwrenderer::ST_LOWERSIDE) { surface.Side->lightmap[3] = surface; } @@ -3464,7 +3465,7 @@ void MapLoader::BindLightmapSurfacesToGeometry() LightmapSurface l; memset(&l, 0, sizeof(LightmapSurface)); - l.ControlSector = surface.controlSector; + l.ControlSector = (sector_t*)surface.controlSector; l.Type = surface.type; l.LightmapNum = 0; @@ -3472,7 +3473,7 @@ void MapLoader::BindLightmapSurfacesToGeometry() l.LightmapNum = surface.atlasPageIndex; - if (surface.type == ST_FLOOR || surface.type == ST_CEILING) + if (surface.type == hwrenderer::ST_FLOOR || surface.type == hwrenderer::ST_CEILING) { l.Subsector = &Level->subsectors[surface.typeIndex]; if (l.Subsector->firstline && l.Subsector->firstline->sidedef) diff --git a/src/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index e5743ae2e..98c89318d 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.cpp +++ b/src/rendering/hwrenderer/doom_levelmesh.cpp @@ -12,6 +12,9 @@ #include "common/rendering/vulkan/accelstructs/vk_lightmap.h" #include +using hwrenderer::Surface; +using hwrenderer::SurfaceType; + CCMD(dumplevelmesh) { if (level.levelMesh) @@ -36,7 +39,7 @@ DoomLevelMesh::DoomLevelMesh(FLevelLocals &doomMap) for (size_t i = 0; i < Surfaces.Size(); i++) { - const Surface &s = Surfaces[i]; + const auto &s = Surfaces[i]; int numVerts = s.numVerts; unsigned int pos = s.startVertIndex; FVector3* verts = &MeshVertices[pos]; @@ -46,7 +49,7 @@ DoomLevelMesh::DoomLevelMesh(FLevelLocals &doomMap) MeshUVIndex.Push(j); } - if (s.type == ST_FLOOR || s.type == ST_CEILING) + if (s.type == hwrenderer::ST_FLOOR || s.type == hwrenderer::ST_CEILING) { for (int j = 2; j < numVerts; j++) { @@ -59,7 +62,7 @@ DoomLevelMesh::DoomLevelMesh(FLevelLocals &doomMap) } } } - else if (s.type == ST_MIDDLEWALL || s.type == ST_UPPERWALL || s.type == ST_LOWERWALL) + else if (s.type == hwrenderer::ST_MIDDLESIDE || s.type == hwrenderer::ST_UPPERSIDE || s.type == hwrenderer::ST_LOWERSIDE) { if (!IsDegenerate(verts[0], verts[1], verts[2])) { @@ -109,7 +112,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) if (side->linedef->special == Line_Horizon && front != back) { Surface surf; - surf.type = ST_MIDDLEWALL; + surf.type = hwrenderer::ST_MIDDLESIDE; surf.typeIndex = typeIndex; surf.bSky = front->GetTexture(sector_t::floor) == skyflatnum || front->GetTexture(sector_t::ceiling) == skyflatnum; @@ -155,7 +158,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) continue; Surface surf; - surf.type = ST_MIDDLEWALL; + surf.type = hwrenderer::ST_MIDDLESIDE; surf.typeIndex = typeIndex; surf.controlSector = xfloor->model; surf.bSky = false; @@ -216,7 +219,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) MeshVertices.Push(verts[3]); surf.plane = ToPlane(verts[0], verts[1], verts[2]); - surf.type = ST_LOWERWALL; + surf.type = hwrenderer::ST_LOWERSIDE; surf.typeIndex = typeIndex; surf.bSky = false; surf.controlSector = nullptr; @@ -254,7 +257,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) MeshVertices.Push(verts[3]); surf.plane = ToPlane(verts[0], verts[1], verts[2]); - surf.type = ST_UPPERWALL; + surf.type = hwrenderer::ST_UPPERSIDE; surf.typeIndex = typeIndex; surf.bSky = bSky; surf.controlSector = nullptr; @@ -292,7 +295,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) MeshVertices.Push(verts[3]); surf.plane = ToPlane(verts[0], verts[1], verts[2]); - surf.type = ST_MIDDLEWALL; + surf.type = hwrenderer::ST_MIDDLESIDE; surf.typeIndex = typeIndex; surf.controlSector = nullptr; @@ -331,7 +334,7 @@ void DoomLevelMesh::CreateFloorSurface(FLevelLocals &doomMap, subsector_t *sub, verts[j].Z = (float)plane.ZatPoint(verts[j]); } - surf.type = ST_FLOOR; + surf.type = hwrenderer::ST_FLOOR; surf.typeIndex = typeIndex; surf.controlSector = is3DFloor ? sector : nullptr; surf.plane = FVector4(plane.Normal().X, plane.Normal().Y, plane.Normal().Z, plane.D); @@ -370,7 +373,7 @@ void DoomLevelMesh::CreateCeilingSurface(FLevelLocals &doomMap, subsector_t *sub verts[j].Z = (float)plane.ZatPoint(verts[j]); } - surf.type = ST_CEILING; + surf.type = hwrenderer::ST_CEILING; surf.typeIndex = typeIndex; surf.controlSector = is3DFloor ? sector : nullptr; surf.plane = FVector4(plane.Normal().X, plane.Normal().Y, plane.Normal().Z, plane.D); @@ -569,7 +572,7 @@ int DoomLevelMesh::SetupLightmapUvs(int lightmapSize) // Reorder vertices into renderer format for (Surface& surface : Surfaces) { - if (surface.type == ST_FLOOR) + if (surface.type == hwrenderer::ST_FLOOR) { // reverse vertices on floor for (int j = surface.startUvIndex + surface.numVerts - 1, k = surface.startUvIndex; j > k; j--, k++) @@ -577,7 +580,7 @@ int DoomLevelMesh::SetupLightmapUvs(int lightmapSize) std::swap(LightmapUvs[k], LightmapUvs[j]); } } - else if (surface.type != ST_CEILING) // walls + else if (surface.type != hwrenderer::ST_CEILING) // walls { // from 0 1 2 3 // to 0 2 1 3 diff --git a/src/rendering/hwrenderer/doom_levelmesh.h b/src/rendering/hwrenderer/doom_levelmesh.h index 4178d615f..4903e2976 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.h +++ b/src/rendering/hwrenderer/doom_levelmesh.h @@ -12,42 +12,6 @@ typedef dp::rect_pack::RectPacker RectPacker; struct FLevelLocals; -struct Surface -{ - SurfaceType type; - int typeIndex; - int numVerts; - unsigned int startVertIndex; - unsigned int startUvIndex; - FVector4 plane; - sector_t *controlSector; - bool bSky; - - // Lightmap UV information in pixel size - int atlasPageIndex = 0; - int atlasX = 0; - int atlasY = 0; - int texWidth = 0; - int texHeight = 0; - - // - // Required for internal lightmapper: - // - - BBox bounds; - int sampleDimension = 0; - - // Lightmap world coordinates for the texture - FVector3 worldOrigin = { 0.f, 0.f, 0.f }; - FVector3 worldStepX = { 0.f, 0.f, 0.f }; - FVector3 worldStepY = { 0.f, 0.f, 0.f }; - - // Calculate world coordinates to UV coordinates - FVector3 translateWorldToLocal = { 0.f, 0.f, 0.f }; - FVector3 projLocalToU = { 0.f, 0.f, 0.f }; - FVector3 projLocalToV = { 0.f, 0.f, 0.f }; -}; - class DoomLevelMesh : public hwrenderer::LevelMesh { public: @@ -61,11 +25,11 @@ public: return true; int surfaceIndex = MeshSurfaces[hit.triangle]; - const Surface& surface = Surfaces[surfaceIndex]; + const hwrenderer::Surface& surface = Surfaces[surfaceIndex]; return surface.bSky; } - TArray Surfaces; + TArray Surfaces; TArray LightmapUvs; static_assert(alignof(FVector2) == alignof(float[2]) && sizeof(FVector2) == sizeof(float) * 2); @@ -109,10 +73,10 @@ private: }; static PlaneAxis BestAxis(const FVector4& p); - BBox GetBoundsFromSurface(const Surface& surface) const; + BBox GetBoundsFromSurface(const hwrenderer::Surface& surface) const; inline int AllocUvs(int amount) { return LightmapUvs.Reserve(amount * 2); } - void BuildSurfaceParams(int lightMapTextureWidth, int lightMapTextureHeight, Surface& surface); - void FinishSurface(int lightmapTextureWidth, int lightmapTextureHeight, RectPacker& packer, Surface& surface); + void BuildSurfaceParams(int lightMapTextureWidth, int lightMapTextureHeight, hwrenderer::Surface& surface); + void FinishSurface(int lightmapTextureWidth, int lightmapTextureHeight, RectPacker& packer, hwrenderer::Surface& surface); }; diff --git a/src/rendering/hwrenderer/hw_vertexbuilder.cpp b/src/rendering/hwrenderer/hw_vertexbuilder.cpp index 89f5476ad..0b2ad621e 100644 --- a/src/rendering/hwrenderer/hw_vertexbuilder.cpp +++ b/src/rendering/hwrenderer/hw_vertexbuilder.cpp @@ -240,7 +240,7 @@ static int CreateIndexedSectorVerticesLM(FRenderState& renderstate, sector_t* se { subsector_t* sub = sec->subsectors[i]; LightmapSurface* lightmap = &sub->lightmap[h][lightmapIndex]; - if (lightmap->Type != ST_NULL) + if (lightmap->Type != hwrenderer::ST_UNKNOWN) { float* luvs = lightmap->TexCoords; int lindex = lightmap->LightmapNum; diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index 51ccbafb3..761b31b22 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -1016,7 +1016,7 @@ bool HWWall::SetWallCoordinates(seg_t * seg, FTexCoordInfo *tci, float textureto } texcoord* srclightuv; - if (lightmap && lightmap->Type != ST_NULL) + if (lightmap && lightmap->Type != hwrenderer::ST_UNKNOWN) { srclightuv = (texcoord*)lightmap->TexCoords; lindex = (float)lightmap->LightmapNum; @@ -1721,7 +1721,7 @@ void HWWall::BuildFFBlock(HWDrawInfo *di, FRenderState& state, seg_t * seg, F3DF CheckTexturePosition(&tci); texcoord* srclightuv; - if (lightmap && lightmap->Type != ST_NULL) + if (lightmap && lightmap->Type != hwrenderer::ST_UNKNOWN) { srclightuv = (texcoord*)lightmap->TexCoords; lindex = (float)lightmap->LightmapNum;