mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-22 12:11:25 +00:00
Use UVs from the lightmap
This commit is contained in:
parent
00bd608dc5
commit
dec222c9fe
3 changed files with 50 additions and 30 deletions
|
@ -87,7 +87,6 @@ struct LevelMeshSurface
|
|||
// VkLightmap extra stuff that I dislike:
|
||||
//
|
||||
TArray<FVector3> verts;
|
||||
TArray<FVector2> uvs;
|
||||
|
||||
// Touching light sources
|
||||
std::vector<const LevelMeshLight*> LightList;
|
||||
|
|
|
@ -3157,7 +3157,7 @@ void MapLoader::LoadLightmap(MapData* map)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (developer >= 4)
|
||||
if (developer >= 5)
|
||||
{
|
||||
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,
|
||||
|
@ -3188,6 +3188,32 @@ void MapLoader::LoadLightmap(MapData* map)
|
|||
}
|
||||
}
|
||||
|
||||
// Use UVs from the lightmap
|
||||
for (auto& surface : zdraySurfaces)
|
||||
{
|
||||
auto& realSurface = Level->levelMesh->Surfaces[findSurfaceIndex(surface.type, surface.typeIndex, getControlSector(surface.controlSector))];
|
||||
|
||||
auto* UVs = &Level->levelMesh->LightmapUvs[realSurface.startUvIndex];
|
||||
auto* newUVs = &zdrayUvs[surface.uvOffset];
|
||||
|
||||
for (uint32_t i = 0; i < surface.uvCount; ++i)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
// Finish surface
|
||||
UVs[i].X = (newUVs[i].X + realSurface.atlasX) / textureSize;
|
||||
UVs[i].Y = (newUVs[i].Y + realSurface.atlasY) / textureSize;
|
||||
|
||||
if (developer >= 5)
|
||||
{
|
||||
Printf("New UV: %.6f %.6f\n", UVs[i].X, UVs[i].Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (developer >= 3)
|
||||
{
|
||||
int loadedSurfaces = 0;
|
||||
|
|
|
@ -97,7 +97,7 @@ CCMD(surfaceinfo)
|
|||
}
|
||||
|
||||
auto posXYZ = FVector3(pov->Pos());
|
||||
posXYZ.Z = players[consoleplayer].viewz;
|
||||
posXYZ.Z = float(players[consoleplayer].viewz);
|
||||
auto angle = pov->Angles.Yaw;
|
||||
auto pitch = pov->Angles.Pitch;
|
||||
|
||||
|
@ -401,6 +401,28 @@ void DoomLevelMesh::UpdateLightLists()
|
|||
|
||||
void DoomLevelMesh::BindLightmapSurfacesToGeometry(FLevelLocals& doomMap)
|
||||
{
|
||||
// You have no idea how long this took me to figure out...
|
||||
|
||||
// Reorder vertices into renderer format
|
||||
for (LevelMeshSurface& surface : Surfaces)
|
||||
{
|
||||
if (surface.Type == ST_FLOOR)
|
||||
{
|
||||
// reverse vertices on floor
|
||||
for (int j = surface.startUvIndex + surface.numVerts - 1, k = surface.startUvIndex; j > k; j--, k++)
|
||||
{
|
||||
std::swap(LightmapUvs[k], LightmapUvs[j]);
|
||||
}
|
||||
}
|
||||
else if (surface.Type != ST_CEILING) // walls
|
||||
{
|
||||
// from 0 1 2 3
|
||||
// to 0 2 1 3
|
||||
std::swap(LightmapUvs[surface.startUvIndex + 1], LightmapUvs[surface.startUvIndex + 2]);
|
||||
std::swap(LightmapUvs[surface.startUvIndex + 2], LightmapUvs[surface.startUvIndex + 3]);
|
||||
}
|
||||
}
|
||||
|
||||
// Allocate room for all surfaces
|
||||
|
||||
unsigned int allSurfaces = 0;
|
||||
|
@ -1064,11 +1086,6 @@ void DoomLevelMesh::SetupLightmapUvs()
|
|||
{
|
||||
surface.verts.Push(MeshVertices[surface.startVertIndex + i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < surface.numVerts; ++i)
|
||||
{
|
||||
surface.uvs.Push(LightmapUvs[surface.startUvIndex + i]);
|
||||
}
|
||||
}
|
||||
|
||||
BuildSmoothingGroups();
|
||||
|
@ -1082,28 +1099,6 @@ void DoomLevelMesh::SetupLightmapUvs()
|
|||
FinishSurface(LMTextureSize, LMTextureSize, packer, *surf);
|
||||
}
|
||||
|
||||
// You have no idea how long this took me to figure out...
|
||||
|
||||
// Reorder vertices into renderer format
|
||||
for (LevelMeshSurface& surface : Surfaces)
|
||||
{
|
||||
if (surface.Type == ST_FLOOR)
|
||||
{
|
||||
// reverse vertices on floor
|
||||
for (int j = surface.startUvIndex + surface.numVerts - 1, k = surface.startUvIndex; j > k; j--, k++)
|
||||
{
|
||||
std::swap(LightmapUvs[k], LightmapUvs[j]);
|
||||
}
|
||||
}
|
||||
else if (surface.Type != ST_CEILING) // walls
|
||||
{
|
||||
// from 0 1 2 3
|
||||
// to 0 2 1 3
|
||||
std::swap(LightmapUvs[surface.startUvIndex + 1], LightmapUvs[surface.startUvIndex + 2]);
|
||||
std::swap(LightmapUvs[surface.startUvIndex + 2], LightmapUvs[surface.startUvIndex + 3]);
|
||||
}
|
||||
}
|
||||
|
||||
LMTextureCount = (int)packer.getNumPages();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue