Make doom specific surface fields private to doom
This commit is contained in:
parent
4336f0e58d
commit
7bc52386f9
7 changed files with 97 additions and 99 deletions
|
|
@ -29,20 +29,8 @@ public:
|
|||
int SectorGroup;
|
||||
};
|
||||
|
||||
enum LevelMeshSurfaceType
|
||||
{
|
||||
ST_UNKNOWN,
|
||||
ST_MIDDLESIDE,
|
||||
ST_UPPERSIDE,
|
||||
ST_LOWERSIDE,
|
||||
ST_CEILING,
|
||||
ST_FLOOR
|
||||
};
|
||||
|
||||
struct LevelMeshSurface
|
||||
{
|
||||
LevelMeshSurfaceType Type = ST_UNKNOWN;
|
||||
int typeIndex;
|
||||
int numVerts;
|
||||
unsigned int startVertIndex;
|
||||
unsigned int startUvIndex;
|
||||
|
|
@ -51,12 +39,15 @@ struct LevelMeshSurface
|
|||
FVector4 plane;
|
||||
bool bSky;
|
||||
|
||||
// Lightmap UV information in pixel size
|
||||
int atlasPageIndex = 0;
|
||||
int atlasX = 0;
|
||||
int atlasY = 0;
|
||||
int texWidth = 0;
|
||||
int texHeight = 0;
|
||||
// Surface location in lightmap texture
|
||||
struct
|
||||
{
|
||||
int X = 0;
|
||||
int Y = 0;
|
||||
int Width = 0;
|
||||
int Height = 0;
|
||||
int ArrayIndex = 0;
|
||||
} AtlasTile;
|
||||
|
||||
// True if the surface needs to be rendered into the lightmap texture before it can be used
|
||||
bool needsUpdate = true;
|
||||
|
|
@ -88,7 +79,7 @@ struct LevelMeshSurface
|
|||
//
|
||||
// Utility/Info
|
||||
//
|
||||
inline uint32_t Area() const { return texWidth * texHeight; }
|
||||
inline uint32_t Area() const { return AtlasTile.Width * AtlasTile.Height; }
|
||||
|
||||
int LightListPos = -1;
|
||||
int LightListCount = 0;
|
||||
|
|
@ -336,8 +327,8 @@ private:
|
|||
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);
|
||||
float u = (1.0f + (localPos | targetSurface->projLocalToU)) / (targetSurface->AtlasTile.Width + 2);
|
||||
float v = (1.0f + (localPos | targetSurface->projLocalToV)) / (targetSurface->AtlasTile.Height + 2);
|
||||
return FVector2(u, v);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ void VkLightmap::SelectSurfaces(const TArray<LevelMeshSurface*>& surfaces)
|
|||
continue;
|
||||
|
||||
// Only grab surfaces until our bake texture is full
|
||||
auto result = packer.insert(surface->texWidth + 2, surface->texHeight + 2);
|
||||
auto result = packer.insert(surface->AtlasTile.Width + 2, surface->AtlasTile.Height + 2);
|
||||
if (result.pageIndex == 0)
|
||||
{
|
||||
SelectedSurface selected;
|
||||
|
|
@ -127,8 +127,8 @@ void VkLightmap::SelectSurfaces(const TArray<LevelMeshSurface*>& surfaces)
|
|||
selected.Y = result.pos.y + 1;
|
||||
selectedSurfaces.Push(selected);
|
||||
|
||||
bakeImage.maxX = std::max<uint16_t>(bakeImage.maxX, uint16_t(selected.X + surface->texWidth + spacing));
|
||||
bakeImage.maxY = std::max<uint16_t>(bakeImage.maxY, uint16_t(selected.Y + surface->texHeight + spacing));
|
||||
bakeImage.maxX = std::max<uint16_t>(bakeImage.maxX, uint16_t(selected.X + surface->AtlasTile.Width + spacing));
|
||||
bakeImage.maxY = std::max<uint16_t>(bakeImage.maxY, uint16_t(selected.Y + surface->AtlasTile.Height + spacing));
|
||||
|
||||
surface->needsUpdate = false;
|
||||
}
|
||||
|
|
@ -167,19 +167,13 @@ void VkLightmap::Render()
|
|||
auto& selectedSurface = selectedSurfaces[i];
|
||||
LevelMeshSurface* targetSurface = selectedSurface.Surface;
|
||||
|
||||
/*if (targetSurface->LightList.empty() && (targetSurface->plane.XYZ() | mesh->SunDirection) < 0.0f) // No lights, no sun
|
||||
{
|
||||
selectedSurface.Rendered = true;
|
||||
continue;
|
||||
}*/
|
||||
|
||||
LightmapRaytracePC pc;
|
||||
pc.TileX = (float)selectedSurface.X;
|
||||
pc.TileY = (float)selectedSurface.Y;
|
||||
pc.SurfaceIndex = mesh->StaticMesh->GetSurfaceIndex(targetSurface);
|
||||
pc.TextureSize = (float)bakeImageSize;
|
||||
pc.TileWidth = (float)targetSurface->texWidth;
|
||||
pc.TileHeight = (float)targetSurface->texHeight;
|
||||
pc.TileWidth = (float)targetSurface->AtlasTile.Width;
|
||||
pc.TileHeight = (float)targetSurface->AtlasTile.Height;
|
||||
pc.WorldToLocal = targetSurface->translateWorldToLocal;
|
||||
pc.ProjLocalToU = targetSurface->projLocalToU;
|
||||
pc.ProjLocalToV = targetSurface->projLocalToV;
|
||||
|
|
@ -392,7 +386,7 @@ void VkLightmap::CopyResult()
|
|||
auto& selected = selectedSurfaces[i];
|
||||
if (selected.Rendered)
|
||||
{
|
||||
unsigned int pageIndex = (unsigned int)selected.Surface->atlasPageIndex;
|
||||
unsigned int pageIndex = (unsigned int)selected.Surface->AtlasTile.ArrayIndex;
|
||||
if (pageIndex >= copylists.Size())
|
||||
{
|
||||
copylists.Resize(pageIndex + 1);
|
||||
|
|
@ -471,10 +465,10 @@ void VkLightmap::CopyResult()
|
|||
CopyTileInfo* copyinfo = ©tiles.Tiles[pos++];
|
||||
copyinfo->SrcPosX = selected->X;
|
||||
copyinfo->SrcPosY = selected->Y;
|
||||
copyinfo->DestPosX = surface->atlasX;
|
||||
copyinfo->DestPosY = surface->atlasY;
|
||||
copyinfo->TileWidth = surface->texWidth;
|
||||
copyinfo->TileHeight = surface->texHeight;
|
||||
copyinfo->DestPosX = surface->AtlasTile.X;
|
||||
copyinfo->DestPosY = surface->AtlasTile.Y;
|
||||
copyinfo->TileWidth = surface->AtlasTile.Width;
|
||||
copyinfo->TileHeight = surface->AtlasTile.Height;
|
||||
}
|
||||
|
||||
// Draw the tiles. One instance per tile.
|
||||
|
|
|
|||
|
|
@ -3093,13 +3093,13 @@ bool MapLoader::LoadLightmap(MapData* map)
|
|||
|
||||
if (surface.Type > ST_UNKNOWN && surface.Type <= ST_FLOOR)
|
||||
{
|
||||
if (auto list = surfaceGroups[surface.Type - 1].CheckKey(surface.typeIndex))
|
||||
if (auto list = surfaceGroups[surface.Type - 1].CheckKey(surface.TypeIndex))
|
||||
{
|
||||
list->Push(&surface);
|
||||
}
|
||||
else
|
||||
{
|
||||
surfaceGroups[surface.Type - 1].InsertNew(surface.typeIndex).Push(&surface);
|
||||
surfaceGroups[surface.Type - 1].InsertNew(surface.TypeIndex).Push(&surface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3143,7 +3143,7 @@ bool MapLoader::LoadLightmap(MapData* map)
|
|||
|
||||
auto levelSurface = &submesh->Surfaces[i];
|
||||
|
||||
if (levelSurface->Type != surface.type || levelSurface->typeIndex != surface.typeIndex || levelSurface->ControlSector != controlSector)
|
||||
if (levelSurface->Type != surface.type || levelSurface->TypeIndex != surface.typeIndex || levelSurface->ControlSector != controlSector)
|
||||
{
|
||||
auto internalIndex = findSurfaceIndex(surface.type, surface.typeIndex, controlSector);
|
||||
|
||||
|
|
@ -3173,8 +3173,8 @@ bool MapLoader::LoadLightmap(MapData* map)
|
|||
}
|
||||
else
|
||||
{
|
||||
levelSurface->texWidth = surface.width;
|
||||
levelSurface->texHeight = surface.height;
|
||||
levelSurface->AtlasTile.Width = surface.width;
|
||||
levelSurface->AtlasTile.Height = surface.height;
|
||||
|
||||
surface.targetSurface = levelSurface;
|
||||
detectedSurfaces.Insert(levelSurface, 1);
|
||||
|
|
@ -3217,9 +3217,9 @@ bool MapLoader::LoadLightmap(MapData* map)
|
|||
#if 0 // debug surface mapping
|
||||
for (auto& surface : submesh->Surfaces)
|
||||
{
|
||||
int dstX = surface.atlasX;
|
||||
int dstY = surface.atlasY;
|
||||
int dstPage = surface.atlasPageIndex;
|
||||
int dstX = surface.AtlasTile.X;
|
||||
int dstY = surface.AtlasTile.Y;
|
||||
int dstPage = surface.AtlasTile.ArrayIndex;
|
||||
|
||||
// copy pixels
|
||||
uint16_t* dst = &submesh->LMTextureData[dstPage * textureSize * textureSize * 3];
|
||||
|
|
@ -3228,9 +3228,9 @@ bool MapLoader::LoadLightmap(MapData* map)
|
|||
|
||||
if (auto ptr = detectedSurfaces.CheckKey(&surface))
|
||||
{
|
||||
for (int y = 0; y < surface.texHeight; ++y)
|
||||
for (int y = 0; y < surface.AtlasTile.Height; ++y)
|
||||
{
|
||||
for (int x = 0; x < surface.texWidth; ++x)
|
||||
for (int x = 0; x < surface.AtlasTile.Width; ++x)
|
||||
{
|
||||
uint32_t dstIndex = uint32_t(dstX + x + (dstY + y) * textureSize) * 3;
|
||||
|
||||
|
|
@ -3242,9 +3242,9 @@ bool MapLoader::LoadLightmap(MapData* map)
|
|||
}
|
||||
else
|
||||
{
|
||||
for (int y = 0; y < surface.texHeight; ++y)
|
||||
for (int y = 0; y < surface.AtlasTile.Height; ++y)
|
||||
{
|
||||
for (int x = 0; x < surface.texWidth; ++x)
|
||||
for (int x = 0; x < surface.AtlasTile.Width; ++x)
|
||||
{
|
||||
uint32_t dstIndex = uint32_t(dstX + x + (dstY + y) * textureSize) * 3;
|
||||
|
||||
|
|
@ -3268,9 +3268,9 @@ bool MapLoader::LoadLightmap(MapData* map)
|
|||
// calculate pixel positions
|
||||
const uint32_t srcPixelOffset = surface.pixelsOffset;
|
||||
|
||||
const int dstX = realSurface.atlasX;
|
||||
const int dstY = realSurface.atlasY;
|
||||
const int dstPage = realSurface.atlasPageIndex;
|
||||
const int dstX = realSurface.AtlasTile.X;
|
||||
const int dstY = realSurface.AtlasTile.Y;
|
||||
const int dstPage = realSurface.AtlasTile.ArrayIndex;
|
||||
|
||||
// Sanity checks
|
||||
if (dstX < 0 || dstY < 0 || dstX + surface.width > textureSize || dstY + surface.height > textureSize || dstPage >= submesh->LMTextureCount)
|
||||
|
|
@ -3284,12 +3284,12 @@ bool MapLoader::LoadLightmap(MapData* map)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (realSurface.texWidth != surface.width || realSurface.texHeight != surface.height)
|
||||
if (realSurface.AtlasTile.Width != surface.width || realSurface.AtlasTile.Height != surface.height)
|
||||
{
|
||||
errors = true;
|
||||
if (developer >= 1)
|
||||
{
|
||||
Printf("Surface size mismatch: Attempting to remap %dx%d to %dx%d pixel area.\n", surface.width, surface.height, realSurface.texWidth, realSurface.texHeight);
|
||||
Printf("Surface size mismatch: Attempting to remap %dx%d to %dx%d pixel area.\n", surface.width, surface.height, realSurface.AtlasTile.Width, realSurface.AtlasTile.Height);
|
||||
}
|
||||
realSurface.needsUpdate = true;
|
||||
continue;
|
||||
|
|
@ -3300,7 +3300,7 @@ bool MapLoader::LoadLightmap(MapData* map)
|
|||
Printf("Mapping lightmap surface pixels[%u] (count: %u) -> ((x:%d, y:%d), (x2:%d, y2:%d), page:%d) area: %u\n",
|
||||
srcPixelOffset, surface.width * surface.height * 3,
|
||||
dstX, dstY,
|
||||
dstX + realSurface.texWidth, dstY + realSurface.texHeight,
|
||||
dstX + realSurface.AtlasTile.Width, dstY + realSurface.AtlasTile.Height,
|
||||
dstPage,
|
||||
realSurface.Area() * 3);
|
||||
}
|
||||
|
|
@ -3309,14 +3309,14 @@ bool MapLoader::LoadLightmap(MapData* map)
|
|||
uint32_t srcIndex = 0;
|
||||
uint16_t* src = &textureData[srcPixelOffset];
|
||||
|
||||
uint16_t* dst = &submesh->LMTextureData[realSurface.atlasPageIndex * textureSize * textureSize * 3];
|
||||
uint16_t* dst = &submesh->LMTextureData[realSurface.AtlasTile.ArrayIndex * textureSize * textureSize * 3];
|
||||
|
||||
int endY = realSurface.atlasY + realSurface.texHeight;
|
||||
int endX = realSurface.atlasX + realSurface.texWidth;
|
||||
int endY = realSurface.AtlasTile.Y + realSurface.AtlasTile.Height;
|
||||
int endX = realSurface.AtlasTile.X + realSurface.AtlasTile.Width;
|
||||
|
||||
for (int y = realSurface.atlasY; y < endY; ++y)
|
||||
for (int y = realSurface.AtlasTile.Y; y < endY; ++y)
|
||||
{
|
||||
for (int x = realSurface.atlasX; x < endX; ++x)
|
||||
for (int x = realSurface.AtlasTile.X; x < endX; ++x)
|
||||
{
|
||||
uint32_t dstIndex = uint32_t(x + (y * textureSize)) * 3;
|
||||
|
||||
|
|
@ -3341,12 +3341,12 @@ bool MapLoader::LoadLightmap(MapData* map)
|
|||
|
||||
if (developer >= 5)
|
||||
{
|
||||
Printf("Old UV: %.6f %.6f (w:%d, h:%d) (x:%d, y:%d), Lump UVs %.3f %.3f\n", UVs[i].X, UVs[i].Y, realSurface.texWidth, realSurface.texHeight, realSurface.atlasX, realSurface.atlasY, newUVs[i].X, newUVs[i].Y);
|
||||
Printf("Old UV: %.6f %.6f (w:%d, h:%d) (x:%d, y:%d), Lump UVs %.3f %.3f\n", UVs[i].X, UVs[i].Y, realSurface.AtlasTile.Width, realSurface.AtlasTile.Height, realSurface.AtlasTile.X, realSurface.AtlasTile.Y, newUVs[i].X, newUVs[i].Y);
|
||||
}
|
||||
|
||||
// Finish surface
|
||||
UVs[i].X = (newUVs[i].X + realSurface.atlasX) / textureSize;
|
||||
UVs[i].Y = (newUVs[i].Y + realSurface.atlasY) / textureSize;
|
||||
UVs[i].X = (newUVs[i].X + realSurface.AtlasTile.X) / textureSize;
|
||||
UVs[i].Y = (newUVs[i].Y + realSurface.AtlasTile.Y) / textureSize;
|
||||
|
||||
if (developer >= 5)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -82,9 +82,9 @@ void PrintSurfaceInfo(const DoomLevelMeshSurface* surface)
|
|||
|
||||
auto gameTexture = TexMan.GameByIndex(surface->texture.GetIndex());
|
||||
|
||||
Printf("Surface %d (%p)\n Type: %d, TypeIndex: %d, ControlSector: %d\n", level.levelMesh->StaticMesh->GetSurfaceIndex(surface), surface, surface->Type, surface->typeIndex, surface->ControlSector ? surface->ControlSector->Index() : -1);
|
||||
Printf(" Atlas page: %d, x:%d, y:%d\n", surface->atlasPageIndex, surface->atlasX, surface->atlasY);
|
||||
Printf(" Pixels: %dx%d (area: %d)\n", surface->texWidth, surface->texHeight, surface->Area());
|
||||
Printf("Surface %d (%p)\n Type: %d, TypeIndex: %d, ControlSector: %d\n", level.levelMesh->StaticMesh->GetSurfaceIndex(surface), surface, surface->Type, surface->TypeIndex, surface->ControlSector ? surface->ControlSector->Index() : -1);
|
||||
Printf(" Atlas page: %d, x:%d, y:%d\n", surface->AtlasTile.ArrayIndex, surface->AtlasTile.X, surface->AtlasTile.Y);
|
||||
Printf(" Pixels: %dx%d (area: %d)\n", surface->AtlasTile.Width, surface->AtlasTile.Height, surface->Area());
|
||||
Printf(" Sample dimension: %d\n", surface->sampleDimension);
|
||||
Printf(" Needs update?: %d\n", surface->needsUpdate);
|
||||
Printf(" Sector group: %d\n", surface->sectorGroup);
|
||||
|
|
@ -485,7 +485,7 @@ void DoomLevelSubmesh::BindLightmapSurfacesToGeometry(FLevelLocals& doomMap)
|
|||
// You have no idea how long this took me to figure out...
|
||||
|
||||
// Reorder vertices into renderer format
|
||||
for (LevelMeshSurface& surface : Surfaces)
|
||||
for (DoomLevelMeshSurface& surface : Surfaces)
|
||||
{
|
||||
if (surface.Type == ST_FLOOR)
|
||||
{
|
||||
|
|
@ -542,14 +542,14 @@ void DoomLevelSubmesh::BindLightmapSurfacesToGeometry(FLevelLocals& doomMap)
|
|||
|
||||
if (surface.Type == ST_FLOOR || surface.Type == ST_CEILING)
|
||||
{
|
||||
surface.Subsector = &doomMap.subsectors[surface.typeIndex];
|
||||
surface.Subsector = &doomMap.subsectors[surface.TypeIndex];
|
||||
if (surface.Subsector->firstline && surface.Subsector->firstline->sidedef)
|
||||
surface.Subsector->firstline->sidedef->sector->HasLightmaps = true;
|
||||
SetSubsectorLightmap(&surface);
|
||||
}
|
||||
else
|
||||
{
|
||||
surface.Side = &doomMap.sides[surface.typeIndex];
|
||||
surface.Side = &doomMap.sides[surface.TypeIndex];
|
||||
SetSideLightmap(&surface);
|
||||
}
|
||||
}
|
||||
|
|
@ -640,7 +640,7 @@ void DoomLevelSubmesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
|
|||
|
||||
DoomLevelMeshSurface surf;
|
||||
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.sampleDimension = side->textures[side_t::mid].LightmapSampleDistance;
|
||||
|
||||
|
|
@ -674,7 +674,7 @@ void DoomLevelSubmesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
|
|||
{
|
||||
DoomLevelMeshSurface surf;
|
||||
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.sampleDimension = side->textures[side_t::mid].LightmapSampleDistance;
|
||||
|
||||
|
|
@ -730,7 +730,7 @@ void DoomLevelSubmesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
|
|||
|
||||
surf.plane = ToPlane(verts[0], verts[1], verts[2], verts[3]);
|
||||
surf.Type = ST_MIDDLESIDE;
|
||||
surf.typeIndex = typeIndex;
|
||||
surf.TypeIndex = typeIndex;
|
||||
surf.sampleDimension = side->textures[side_t::mid].LightmapSampleDistance;
|
||||
surf.ControlSector = nullptr;
|
||||
surf.sectorGroup = sectorGroup[front->Index()];
|
||||
|
|
@ -806,7 +806,7 @@ void DoomLevelSubmesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
|
|||
MeshVertices.Push(verts[3] + offset);
|
||||
|
||||
surf.Type = ST_MIDDLESIDE;
|
||||
surf.typeIndex = typeIndex;
|
||||
surf.TypeIndex = typeIndex;
|
||||
surf.sampleDimension = side->textures[side_t::mid].LightmapSampleDistance;
|
||||
surf.ControlSector = nullptr;
|
||||
surf.sectorGroup = sectorGroup[front->Index()];
|
||||
|
|
@ -837,7 +837,7 @@ void DoomLevelSubmesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
|
|||
|
||||
DoomLevelMeshSurface surf;
|
||||
surf.Type = ST_MIDDLESIDE;
|
||||
surf.typeIndex = typeIndex;
|
||||
surf.TypeIndex = typeIndex;
|
||||
surf.ControlSector = xfloor->model;
|
||||
surf.bSky = false;
|
||||
surf.sampleDimension = side->textures[side_t::mid].LightmapSampleDistance;
|
||||
|
|
@ -906,7 +906,7 @@ void DoomLevelSubmesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
|
|||
|
||||
surf.plane = ToPlane(verts[0], verts[1], verts[2], verts[3]);
|
||||
surf.Type = ST_LOWERSIDE;
|
||||
surf.typeIndex = typeIndex;
|
||||
surf.TypeIndex = typeIndex;
|
||||
surf.bSky = false;
|
||||
surf.sampleDimension = side->textures[side_t::bottom].LightmapSampleDistance;
|
||||
surf.ControlSector = nullptr;
|
||||
|
|
@ -949,7 +949,7 @@ void DoomLevelSubmesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
|
|||
|
||||
surf.plane = ToPlane(verts[0], verts[1], verts[2], verts[3]);
|
||||
surf.Type = ST_UPPERSIDE;
|
||||
surf.typeIndex = typeIndex;
|
||||
surf.TypeIndex = typeIndex;
|
||||
surf.bSky = bSky;
|
||||
surf.sampleDimension = side->textures[side_t::top].LightmapSampleDistance;
|
||||
surf.ControlSector = nullptr;
|
||||
|
|
@ -1009,7 +1009,7 @@ void DoomLevelSubmesh::CreateFloorSurface(FLevelLocals &doomMap, subsector_t *su
|
|||
}
|
||||
|
||||
surf.Type = ST_FLOOR;
|
||||
surf.typeIndex = typeIndex;
|
||||
surf.TypeIndex = typeIndex;
|
||||
surf.sampleDimension = (controlSector ? controlSector : sector)->planes[sector_t::floor].LightmapSampleDistance;
|
||||
surf.ControlSector = controlSector;
|
||||
surf.plane = FVector4((float)plane.Normal().X, (float)plane.Normal().Y, (float)plane.Normal().Z, -(float)plane.D);
|
||||
|
|
@ -1062,7 +1062,7 @@ void DoomLevelSubmesh::CreateCeilingSurface(FLevelLocals& doomMap, subsector_t*
|
|||
}
|
||||
|
||||
surf.Type = ST_CEILING;
|
||||
surf.typeIndex = typeIndex;
|
||||
surf.TypeIndex = typeIndex;
|
||||
surf.sampleDimension = (controlSector ? controlSector : sector)->planes[sector_t::ceiling].LightmapSampleDistance;
|
||||
surf.ControlSector = controlSector;
|
||||
surf.plane = FVector4((float)plane.Normal().X, (float)plane.Normal().Y, (float)plane.Normal().Z, -(float)plane.D);
|
||||
|
|
@ -1164,7 +1164,7 @@ void DoomLevelSubmesh::DumpMesh(const FString& objFilename, const FString& mtlFi
|
|||
}
|
||||
}
|
||||
|
||||
auto name = [](LevelMeshSurfaceType type) -> const char* {
|
||||
auto name = [](DoomLevelMeshSurfaceType type) -> const char* {
|
||||
switch (type)
|
||||
{
|
||||
case ST_CEILING:
|
||||
|
|
@ -1210,12 +1210,12 @@ void DoomLevelSubmesh::DumpMesh(const FString& objFilename, const FString& mtlFi
|
|||
else
|
||||
{
|
||||
const auto& surface = Surfaces[index];
|
||||
fprintf(f, "o Surface[%d] %s %d%s\n", index, name(surface.Type), surface.typeIndex, surface.bSky ? " sky" : "");
|
||||
fprintf(f, "usemtl lightmap%d\n", surface.atlasPageIndex);
|
||||
fprintf(f, "o Surface[%d] %s %d%s\n", index, name(surface.Type), surface.TypeIndex, surface.bSky ? " sky" : "");
|
||||
fprintf(f, "usemtl lightmap%d\n", surface.AtlasTile.ArrayIndex);
|
||||
|
||||
if (surface.atlasPageIndex > highestUsedAtlasPage)
|
||||
if (surface.AtlasTile.ArrayIndex > highestUsedAtlasPage)
|
||||
{
|
||||
highestUsedAtlasPage = surface.atlasPageIndex;
|
||||
highestUsedAtlasPage = surface.AtlasTile.ArrayIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1277,7 +1277,7 @@ void DoomLevelSubmesh::PackLightmapAtlas()
|
|||
sortedSurfaces.push_back(&surface);
|
||||
}
|
||||
|
||||
std::sort(sortedSurfaces.begin(), sortedSurfaces.end(), [](LevelMeshSurface* a, LevelMeshSurface* b) { return a->texHeight != b->texHeight ? a->texHeight > b->texHeight : a->texWidth > b->texWidth; });
|
||||
std::sort(sortedSurfaces.begin(), sortedSurfaces.end(), [](LevelMeshSurface* a, LevelMeshSurface* b) { return a->AtlasTile.Height != b->AtlasTile.Height ? a->AtlasTile.Height > b->AtlasTile.Height : a->AtlasTile.Width > b->AtlasTile.Width; });
|
||||
|
||||
RectPacker packer(LMTextureSize, LMTextureSize, RectPacker::Spacing(0));
|
||||
|
||||
|
|
@ -1291,12 +1291,12 @@ void DoomLevelSubmesh::PackLightmapAtlas()
|
|||
|
||||
void DoomLevelSubmesh::FinishSurface(int lightmapTextureWidth, int lightmapTextureHeight, RectPacker& packer, LevelMeshSurface& surface)
|
||||
{
|
||||
int sampleWidth = surface.texWidth;
|
||||
int sampleHeight = surface.texHeight;
|
||||
int sampleWidth = surface.AtlasTile.Width;
|
||||
int sampleHeight = surface.AtlasTile.Height;
|
||||
|
||||
auto result = packer.insert(sampleWidth, sampleHeight);
|
||||
int x = result.pos.x, y = result.pos.y;
|
||||
surface.atlasPageIndex = (int)result.pageIndex;
|
||||
surface.AtlasTile.ArrayIndex = (int)result.pageIndex;
|
||||
|
||||
// calculate final texture coordinates
|
||||
for (int i = 0; i < (int)surface.numVerts; i++)
|
||||
|
|
@ -1307,8 +1307,8 @@ void DoomLevelSubmesh::FinishSurface(int lightmapTextureWidth, int lightmapTextu
|
|||
v = (v + y) / (float)lightmapTextureHeight;
|
||||
}
|
||||
|
||||
surface.atlasX = x;
|
||||
surface.atlasY = y;
|
||||
surface.AtlasTile.X = x;
|
||||
surface.AtlasTile.Y = y;
|
||||
}
|
||||
|
||||
BBox DoomLevelSubmesh::GetBoundsFromSurface(const LevelMeshSurface& surface) const
|
||||
|
|
@ -1465,8 +1465,8 @@ void DoomLevelSubmesh::BuildSurfaceParams(int lightMapTextureWidth, int lightMap
|
|||
tCoords[i][axis] -= d;
|
||||
}
|
||||
|
||||
surface.texWidth = width;
|
||||
surface.texHeight = height;
|
||||
surface.AtlasTile.Width = width;
|
||||
surface.AtlasTile.Height = height;
|
||||
}
|
||||
|
||||
// hw_flats.cpp
|
||||
|
|
@ -1480,13 +1480,13 @@ void DoomLevelSubmesh::CreateSurfaceTextureUVs(FLevelLocals& doomMap)
|
|||
auto toUv = [](const DoomLevelMeshSurface* targetSurface, FVector3 vert) {
|
||||
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);
|
||||
float u = (1.0f + (localPos | targetSurface->projLocalToU)) / (targetSurface->AtlasTile.Width + 2);
|
||||
float v = (1.0f + (localPos | targetSurface->projLocalToV)) / (targetSurface->AtlasTile.Height + 2);
|
||||
|
||||
return FVector2(u, 1.0f - v);
|
||||
};
|
||||
|
||||
auto texPosition = [](LevelMeshSurfaceType surfaceType) {
|
||||
auto texPosition = [](DoomLevelMeshSurfaceType surfaceType) {
|
||||
switch (surfaceType)
|
||||
{
|
||||
case ST_UPPERSIDE:
|
||||
|
|
@ -1513,7 +1513,7 @@ void DoomLevelSubmesh::CreateSurfaceTextureUVs(FLevelLocals& doomMap)
|
|||
if (surface.Type == ST_FLOOR || surface.Type == ST_CEILING)
|
||||
{
|
||||
auto ceiling = surface.Type == ST_FLOOR ? sector_t::floor : sector_t::ceiling;
|
||||
auto mat = GetPlaneTextureRotationMatrix(gtxt, doomMap.subsectors[surface.typeIndex].sector, ceiling);
|
||||
auto mat = GetPlaneTextureRotationMatrix(gtxt, doomMap.subsectors[surface.TypeIndex].sector, ceiling);
|
||||
|
||||
for (int i = 0; i < surface.numVerts; ++i)
|
||||
{
|
||||
|
|
@ -1535,7 +1535,7 @@ void DoomLevelSubmesh::CreateSurfaceTextureUVs(FLevelLocals& doomMap)
|
|||
}
|
||||
|
||||
// shift the uv based on the surface type and anchor
|
||||
/*const*/ auto* side = &doomMap.sides[surface.typeIndex];
|
||||
/*const*/ auto* side = &doomMap.sides[surface.TypeIndex];
|
||||
const auto* line = side->linedef;
|
||||
const auto* sector = side->sector;
|
||||
const auto* otherSector = line->frontsector == sector ? line->backsector : line->frontsector;
|
||||
|
|
|
|||
|
|
@ -14,8 +14,21 @@ typedef dp::rect_pack::RectPacker<int> RectPacker;
|
|||
|
||||
struct FLevelLocals;
|
||||
|
||||
enum DoomLevelMeshSurfaceType
|
||||
{
|
||||
ST_UNKNOWN,
|
||||
ST_MIDDLESIDE,
|
||||
ST_UPPERSIDE,
|
||||
ST_LOWERSIDE,
|
||||
ST_CEILING,
|
||||
ST_FLOOR
|
||||
};
|
||||
|
||||
struct DoomLevelMeshSurface : public LevelMeshSurface
|
||||
{
|
||||
DoomLevelMeshSurfaceType Type = ST_UNKNOWN;
|
||||
int TypeIndex;
|
||||
|
||||
subsector_t* Subsector = nullptr;
|
||||
side_t* Side = nullptr;
|
||||
sector_t* ControlSector = nullptr;
|
||||
|
|
|
|||
|
|
@ -247,7 +247,7 @@ static int CreateIndexedSectorVerticesLM(FRenderState& renderstate, sector_t* se
|
|||
if (lightmap && lightmap->Type != ST_UNKNOWN) // lightmap may be missing if the subsector is degenerate triangle
|
||||
{
|
||||
float* luvs = lightmap->TexCoords;
|
||||
int lindex = lightmap->atlasPageIndex;
|
||||
int lindex = lightmap->AtlasTile.ArrayIndex;
|
||||
for (unsigned int j = 0; j < sub->numlines; j++)
|
||||
{
|
||||
SetFlatVertex(vbo_shadowdata[vi + pos], sub->firstline[j].v1, plane, luvs[j * 2], luvs[j * 2 + 1], lindex);
|
||||
|
|
|
|||
|
|
@ -1019,7 +1019,7 @@ bool HWWall::SetWallCoordinates(seg_t * seg, FTexCoordInfo *tci, float textureto
|
|||
if (lightmap && lightmap->Type != ST_UNKNOWN)
|
||||
{
|
||||
srclightuv = (texcoord*)lightmap->TexCoords;
|
||||
lindex = (float)lightmap->atlasPageIndex;
|
||||
lindex = (float)lightmap->AtlasTile.ArrayIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1734,7 +1734,7 @@ void HWWall::BuildFFBlock(HWDrawInfo *di, FRenderState& state, seg_t * seg, F3DF
|
|||
if (lightmap && lightmap->Type != ST_UNKNOWN)
|
||||
{
|
||||
srclightuv = (texcoord*)lightmap->TexCoords;
|
||||
lindex = (float)lightmap->atlasPageIndex;
|
||||
lindex = (float)lightmap->AtlasTile.ArrayIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue