Create DoomLevelMeshSurface

This commit is contained in:
Magnus Norddahl 2023-09-02 13:24:04 +02:00 committed by Christoph Oelckers
parent fd7e0d986f
commit dd07316072
6 changed files with 43 additions and 29 deletions

View file

@ -43,7 +43,6 @@ struct LevelMeshSurface
unsigned int startVertIndex; unsigned int startVertIndex;
unsigned int startUvIndex; unsigned int startUvIndex;
FVector4 plane; FVector4 plane;
void* controlSector; // type is sector_t
bool bSky; bool bSky;
// Lightmap UV information in pixel size // Lightmap UV information in pixel size
@ -167,7 +166,8 @@ public:
std::unique_ptr<TriangleMeshShape> Collision; std::unique_ptr<TriangleMeshShape> Collision;
TArray<LevelMeshSurface> Surfaces; virtual LevelMeshSurface* GetSurface(int index) { return nullptr; }
virtual int GetSurfaceCount() { return 0; }
TArray<LevelMeshSmoothingGroup> SmoothingGroups; // TODO fill TArray<LevelMeshSmoothingGroup> SmoothingGroups; // TODO fill
TArray<LevelMeshPortal> Portals; // TODO fill TArray<LevelMeshPortal> Portals; // TODO fill

View file

@ -103,9 +103,9 @@ void VkLightmap::RenderAtlasImage(size_t pageIndex)
}; };
beginPass(); beginPass();
for (unsigned int i = 0; i < mesh->Surfaces.Size(); i++) for (int i = 0, count = mesh->GetSurfaceCount(); i < count; i++)
{ {
LevelMeshSurface* targetSurface = &mesh->Surfaces[i]; LevelMeshSurface* targetSurface = mesh->GetSurface(i);
if (targetSurface->lightmapperAtlasPage != pageIndex) if (targetSurface->lightmapperAtlasPage != pageIndex)
continue; continue;
@ -204,9 +204,9 @@ void VkLightmap::CreateAtlasImages()
const int spacing = 3; // Note: the spacing is here to avoid that the resolve sampler finds data from other surface tiles const int spacing = 3; // Note: the spacing is here to avoid that the resolve sampler finds data from other surface tiles
RectPacker packer(atlasImageSize, atlasImageSize, RectPacker::Spacing(spacing)); RectPacker packer(atlasImageSize, atlasImageSize, RectPacker::Spacing(spacing));
for (unsigned int i = 0; i < mesh->Surfaces.Size(); i++) for (int i = 0, count = mesh->GetSurfaceCount(); i < count; i++)
{ {
LevelMeshSurface* surface = &mesh->Surfaces[i]; LevelMeshSurface* surface = mesh->GetSurface(i);
auto result = packer.insert(surface->texWidth + 2, surface->texHeight + 2); auto result = packer.insert(surface->texWidth + 2, surface->texHeight + 2);
surface->lightmapperAtlasX = result.pos.x + 1; surface->lightmapperAtlasX = result.pos.x + 1;
@ -313,9 +313,9 @@ void VkLightmap::DownloadAtlasImage(size_t pageIndex)
hvec4* pixels = (hvec4*)atlasImages[pageIndex].Transfer->Map(0, atlasImageSize * atlasImageSize * sizeof(hvec4)); hvec4* pixels = (hvec4*)atlasImages[pageIndex].Transfer->Map(0, atlasImageSize * atlasImageSize * sizeof(hvec4));
for (unsigned int i = 0; i < mesh->Surfaces.Size(); i++) for (int i = 0, count = mesh->GetSurfaceCount(); i < count; i++)
{ {
LevelMeshSurface* surface = &mesh->Surfaces[i]; LevelMeshSurface* surface = mesh->GetSurface(i);
if (surface->lightmapperAtlasPage != pageIndex) if (surface->lightmapperAtlasPage != pageIndex)
continue; continue;

View file

@ -115,13 +115,15 @@ void VkRaytrace::CreateBuffers()
} }
TArray<SurfaceInfo> surfaceInfo; TArray<SurfaceInfo> surfaceInfo;
for (auto& surface : Mesh->Surfaces) for (int i = 0, count = Mesh->GetSurfaceCount(); i < count; i++)
{ {
LevelMeshSurface* surface = Mesh->GetSurface(i);
SurfaceInfo info; SurfaceInfo info;
info.Normal = surface.plane.XYZ(); info.Normal = surface->plane.XYZ();
info.PortalIndex = 0; info.PortalIndex = 0;
info.SamplingDistance = (float)surface.sampleDimension; info.SamplingDistance = (float)surface->sampleDimension;
info.Sky = surface.bSky; info.Sky = surface->bSky;
surfaceInfo.Push(info); surfaceInfo.Push(info);
} }

View file

@ -537,7 +537,7 @@ void VulkanRenderDevice::SetLevelMesh(LevelMesh* mesh)
mRaytrace->SetLevelMesh(mesh); mRaytrace->SetLevelMesh(mesh);
static LevelMesh* lastMesh = nullptr; // Temp hack; Since this function is called every frame we only want to do this once static LevelMesh* lastMesh = nullptr; // Temp hack; Since this function is called every frame we only want to do this once
if (lastMesh != mesh && mesh->Surfaces.Size() > 0) if (lastMesh != mesh && mesh->GetSurfaceCount() > 0)
{ {
lastMesh = mesh; lastMesh = mesh;
@ -561,23 +561,25 @@ void VulkanRenderDevice::SetLevelMesh(LevelMesh* mesh)
TArray<uint16_t> LMTextureData; TArray<uint16_t> LMTextureData;
LMTextureData.Resize(mesh->LMTextureSize * mesh->LMTextureSize * mesh->LMTextureCount * 3); LMTextureData.Resize(mesh->LMTextureSize * mesh->LMTextureSize * mesh->LMTextureCount * 3);
for (auto& surface : mesh->Surfaces) for (int i = 0, count = mesh->GetSurfaceCount(); i < count; i++)
{ {
uint16_t* currentTexture = LMTextureData.Data() + (mesh->LMTextureSize * mesh->LMTextureSize * 3) * surface.atlasPageIndex; LevelMeshSurface* surface = mesh->GetSurface(i);
FVector3* colorSamples = surface.texPixels.data(); uint16_t* currentTexture = LMTextureData.Data() + (mesh->LMTextureSize * mesh->LMTextureSize * 3) * surface->atlasPageIndex;
FVector3* colorSamples = surface->texPixels.data();
// store results to lightmap texture // store results to lightmap texture
for (int i = 0; i < surface.texHeight; i++) for (int i = 0; i < surface->texHeight; i++)
{ {
for (int j = 0; j < surface.texWidth; j++) for (int j = 0; j < surface->texWidth; j++)
{ {
// get texture offset // get texture offset
int offs = ((mesh->LMTextureSize * (i + surface.atlasY)) + surface.atlasX) * 3; int offs = ((mesh->LMTextureSize * (i + surface->atlasY)) + surface->atlasX) * 3;
// convert RGB to bytes // convert RGB to bytes
currentTexture[offs + j * 3 + 0] = floatToHalf(clamp(colorSamples[i * surface.texWidth + j].X, 0.0f, 65000.0f)); currentTexture[offs + j * 3 + 0] = floatToHalf(clamp(colorSamples[i * surface->texWidth + j].X, 0.0f, 65000.0f));
currentTexture[offs + j * 3 + 1] = floatToHalf(clamp(colorSamples[i * surface.texWidth + j].Y, 0.0f, 65000.0f)); currentTexture[offs + j * 3 + 1] = floatToHalf(clamp(colorSamples[i * surface->texWidth + j].Y, 0.0f, 65000.0f));
currentTexture[offs + j * 3 + 2] = floatToHalf(clamp(colorSamples[i * surface.texWidth + j].Z, 0.0f, 65000.0f)); currentTexture[offs + j * 3 + 2] = floatToHalf(clamp(colorSamples[i * surface->texWidth + j].Z, 0.0f, 65000.0f));
} }
} }
} }

View file

@ -230,7 +230,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
// line_horizont consumes everything // line_horizont consumes everything
if (side->linedef->special == Line_Horizon && front != back) if (side->linedef->special == Line_Horizon && front != back)
{ {
LevelMeshSurface surf; DoomLevelMeshSurface surf;
surf.type = ST_MIDDLESIDE; surf.type = ST_MIDDLESIDE;
surf.typeIndex = typeIndex; surf.typeIndex = typeIndex;
surf.bSky = front->GetTexture(sector_t::floor) == skyflatnum || front->GetTexture(sector_t::ceiling) == skyflatnum; surf.bSky = front->GetTexture(sector_t::floor) == skyflatnum || front->GetTexture(sector_t::ceiling) == skyflatnum;
@ -276,7 +276,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
if (bothSides) if (bothSides)
continue; continue;
LevelMeshSurface surf; DoomLevelMeshSurface surf;
surf.type = ST_MIDDLESIDE; surf.type = ST_MIDDLESIDE;
surf.typeIndex = typeIndex; surf.typeIndex = typeIndex;
surf.controlSector = xfloor->model; surf.controlSector = xfloor->model;
@ -318,7 +318,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
{ {
if (IsBottomSideVisible(side)) if (IsBottomSideVisible(side))
{ {
LevelMeshSurface surf; DoomLevelMeshSurface surf;
FVector3 verts[4]; FVector3 verts[4];
verts[0].X = verts[2].X = v1.X; verts[0].X = verts[2].X = v1.X;
@ -356,7 +356,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
bool bSky = IsTopSideSky(front, back, side); bool bSky = IsTopSideSky(front, back, side);
if (bSky || IsTopSideVisible(side)) if (bSky || IsTopSideVisible(side))
{ {
LevelMeshSurface surf; DoomLevelMeshSurface surf;
FVector3 verts[4]; FVector3 verts[4];
verts[0].X = verts[2].X = v1.X; verts[0].X = verts[2].X = v1.X;
@ -392,7 +392,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
// middle seg // middle seg
if (back == nullptr) if (back == nullptr)
{ {
LevelMeshSurface surf; DoomLevelMeshSurface surf;
surf.bSky = false; surf.bSky = false;
FVector3 verts[4]; FVector3 verts[4];
@ -424,7 +424,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
void DoomLevelMesh::CreateFloorSurface(FLevelLocals &doomMap, subsector_t *sub, sector_t *sector, int typeIndex, bool is3DFloor) void DoomLevelMesh::CreateFloorSurface(FLevelLocals &doomMap, subsector_t *sub, sector_t *sector, int typeIndex, bool is3DFloor)
{ {
LevelMeshSurface surf; DoomLevelMeshSurface surf;
surf.bSky = IsSkySector(sector, sector_t::floor); surf.bSky = IsSkySector(sector, sector_t::floor);
secplane_t plane; secplane_t plane;
@ -463,7 +463,7 @@ void DoomLevelMesh::CreateFloorSurface(FLevelLocals &doomMap, subsector_t *sub,
void DoomLevelMesh::CreateCeilingSurface(FLevelLocals &doomMap, subsector_t *sub, sector_t *sector, int typeIndex, bool is3DFloor) void DoomLevelMesh::CreateCeilingSurface(FLevelLocals &doomMap, subsector_t *sub, sector_t *sector, int typeIndex, bool is3DFloor)
{ {
LevelMeshSurface surf; DoomLevelMeshSurface surf;
surf.bSky = IsSkySector(sector, sector_t::ceiling); surf.bSky = IsSkySector(sector, sector_t::ceiling);
secplane_t plane; secplane_t plane;

View file

@ -12,6 +12,11 @@ typedef dp::rect_pack::RectPacker<int> RectPacker;
struct FLevelLocals; struct FLevelLocals;
struct DoomLevelMeshSurface : public LevelMeshSurface
{
sector_t* controlSector;
};
class DoomLevelMesh : public LevelMesh class DoomLevelMesh : public LevelMesh
{ {
public: public:
@ -28,6 +33,11 @@ public:
return Surfaces[surfaceIndex].bSky; return Surfaces[surfaceIndex].bSky;
} }
LevelMeshSurface* GetSurface(int index) override { return &Surfaces[index]; }
int GetSurfaceCount() override { return Surfaces.Size(); }
TArray<DoomLevelMeshSurface> Surfaces;
TArray<FVector2> LightmapUvs; TArray<FVector2> LightmapUvs;
static_assert(alignof(FVector2) == alignof(float[2]) && sizeof(FVector2) == sizeof(float) * 2); static_assert(alignof(FVector2) == alignof(float[2]) && sizeof(FVector2) == sizeof(float) * 2);