Merge Surface into hwrenderer::Surface

This commit is contained in:
RaveYard 2023-08-31 22:53:55 +02:00 committed by Christoph Oelckers
parent fc2704b902
commit 6de6ae28e9
7 changed files with 73 additions and 98 deletions

View file

@ -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<FVector3> verts;
TArray<FVector2> uvs;
//Plane plane;
FVector3 boundsMin, boundsMax;
// Touching light sources
std::vector<ThingLight*> 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<FVector3> 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);

View file

@ -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;

View file

@ -3277,16 +3277,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++)
{
@ -3302,16 +3303,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;
}
@ -3459,7 +3460,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;
@ -3467,7 +3468,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)

View file

@ -12,6 +12,9 @@
#include "common/rendering/vulkan/accelstructs/vk_lightmap.h"
#include <vulkan/accelstructs/halffloat.h>
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

View file

@ -12,42 +12,6 @@ typedef dp::rect_pack::RectPacker<int> 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<Surface> Surfaces;
TArray<hwrenderer::Surface> Surfaces;
TArray<FVector2> 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);
};

View file

@ -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;

View file

@ -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;