Split doom specific surface data from common/gpu surface data
This commit is contained in:
parent
87eb89ad33
commit
356ad2fe9f
9 changed files with 110 additions and 97 deletions
|
|
@ -64,7 +64,7 @@ LevelMeshSurface* LevelMesh::Trace(const FVector3& start, FVector3 direction, fl
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
hitSurface = GetSurface(Mesh.SurfaceIndexes[hit.triangle]);
|
||||
hitSurface = &Mesh.Surfaces[Mesh.SurfaceIndexes[hit.triangle]];
|
||||
|
||||
int portal = hitSurface->PortalIndex;
|
||||
if (!portal)
|
||||
|
|
@ -91,7 +91,6 @@ LevelMeshSurface* LevelMesh::Trace(const FVector3& start, FVector3 direction, fl
|
|||
LevelMeshTileStats LevelMesh::GatherTilePixelStats()
|
||||
{
|
||||
LevelMeshTileStats stats;
|
||||
int count = GetSurfaceCount();
|
||||
for (const LightmapTile& tile : LightmapTiles)
|
||||
{
|
||||
auto area = tile.AtlasLocation.Area();
|
||||
|
|
@ -125,11 +124,11 @@ void LevelMesh::BuildTileSurfaceLists()
|
|||
{
|
||||
// Plane group surface is to be rendered with
|
||||
TArray<LevelMeshPlaneGroup> PlaneGroups;
|
||||
TArray<int> PlaneGroupIndexes(GetSurfaceCount());
|
||||
TArray<int> PlaneGroupIndexes(Mesh.Surfaces.Size());
|
||||
|
||||
for (int i = 0, count = GetSurfaceCount(); i < count; i++)
|
||||
for (int i = 0, count = Mesh.Surfaces.Size(); i < count; i++)
|
||||
{
|
||||
auto surface = GetSurface(i);
|
||||
auto surface = &Mesh.Surfaces[i];
|
||||
|
||||
// Is this surface in the same plane as an existing plane group?
|
||||
int planeGroupIndex = -1;
|
||||
|
|
@ -172,9 +171,9 @@ void LevelMesh::BuildTileSurfaceLists()
|
|||
for (auto& tile : LightmapTiles)
|
||||
tile.Surfaces.Clear();
|
||||
|
||||
for (int i = 0, count = GetSurfaceCount(); i < count; i++)
|
||||
for (int i = 0, count = Mesh.Surfaces.Size(); i < count; i++)
|
||||
{
|
||||
LevelMeshSurface* targetSurface = GetSurface(i);
|
||||
LevelMeshSurface* targetSurface = &Mesh.Surfaces[i];
|
||||
if (targetSurface->LightmapTileIndex < 0)
|
||||
continue;
|
||||
LightmapTile* tile = &LightmapTiles[targetSurface->LightmapTileIndex];
|
||||
|
|
@ -185,7 +184,7 @@ void LevelMesh::BuildTileSurfaceLists()
|
|||
if (surface != targetSurface && (maxUV.X < 0.0f || maxUV.Y < 0.0f || minUV.X > 1.0f || minUV.Y > 1.0f))
|
||||
continue; // Bounding box not visible
|
||||
|
||||
tile->Surfaces.Push(GetSurfaceIndex(surface));
|
||||
tile->Surfaces.Push((unsigned int)(ptrdiff_t)(surface - Mesh.Surfaces.Data()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -224,9 +223,9 @@ void LevelMesh::PackLightmapAtlas(int lightmapStartIndex)
|
|||
LMTextureCount = (int)packer.getNumPages();
|
||||
|
||||
// Calculate final texture coordinates
|
||||
for (int i = 0, count = GetSurfaceCount(); i < count; i++)
|
||||
for (int i = 0, count = Mesh.Surfaces.Size(); i < count; i++)
|
||||
{
|
||||
auto surface = GetSurface(i);
|
||||
auto surface = &Mesh.Surfaces[i];
|
||||
if (surface->LightmapTileIndex >= 0)
|
||||
{
|
||||
const LightmapTile& tile = LightmapTiles[surface->LightmapTileIndex];
|
||||
|
|
|
|||
|
|
@ -58,10 +58,6 @@ public:
|
|||
LevelMesh();
|
||||
virtual ~LevelMesh() = default;
|
||||
|
||||
virtual LevelMeshSurface* GetSurface(int index) { return nullptr; }
|
||||
virtual unsigned int GetSurfaceIndex(const LevelMeshSurface* surface) const { return 0xffffffff; }
|
||||
virtual int GetSurfaceCount() { return 0; }
|
||||
|
||||
LevelMeshSurface* Trace(const FVector3& start, FVector3 direction, float maxDist);
|
||||
|
||||
LevelMeshTileStats GatherTilePixelStats();
|
||||
|
|
@ -131,6 +127,7 @@ public:
|
|||
AddRange(FreeLists.Surface, { (int)surfaceIndex, 1 });
|
||||
}
|
||||
|
||||
// Data placed in GPU buffers
|
||||
struct
|
||||
{
|
||||
// Vertex data
|
||||
|
|
@ -138,6 +135,7 @@ public:
|
|||
TArray<int> UniformIndexes;
|
||||
|
||||
// Surface info
|
||||
TArray<LevelMeshSurface> Surfaces;
|
||||
TArray<SurfaceUniforms> Uniforms;
|
||||
TArray<FMaterialState> Materials;
|
||||
TArray<int32_t> LightIndexes;
|
||||
|
|
@ -160,6 +158,7 @@ public:
|
|||
int MaxLightIndexes = 0;
|
||||
} Mesh;
|
||||
|
||||
// Ranges in mesh that have changed since last upload
|
||||
struct
|
||||
{
|
||||
TArray<MeshBufferRange> Vertex;
|
||||
|
|
@ -174,6 +173,7 @@ public:
|
|||
TArray<MeshBufferRange> LightIndex;
|
||||
} UploadRanges;
|
||||
|
||||
// Ranges in mesh currently not in use
|
||||
struct
|
||||
{
|
||||
TArray<MeshBufferRange> Vertex;
|
||||
|
|
@ -182,8 +182,10 @@ public:
|
|||
TArray<MeshBufferRange> Surface;
|
||||
} FreeLists;
|
||||
|
||||
// Data structure for doing mesh traces on the CPU
|
||||
std::unique_ptr<TriangleMeshShape> Collision;
|
||||
|
||||
// Draw index ranges for rendering the level mesh
|
||||
TArray<LevelSubmeshDrawRange> DrawList;
|
||||
TArray<LevelSubmeshDrawRange> PortalList;
|
||||
|
||||
|
|
@ -214,7 +216,7 @@ public:
|
|||
ClearRanges(UploadRanges.SurfaceIndex);
|
||||
AddRange(UploadRanges.SurfaceIndex, { 0, (int)Mesh.SurfaceIndexes.Size() });
|
||||
ClearRanges(UploadRanges.Surface);
|
||||
AddRange(UploadRanges.Surface, { 0, GetSurfaceCount() });
|
||||
AddRange(UploadRanges.Surface, { 0, (int)Mesh.Surfaces.Size() });
|
||||
ClearRanges(UploadRanges.UniformIndexes);
|
||||
AddRange(UploadRanges.UniformIndexes, { 0, (int)Mesh.UniformIndexes.Size() });
|
||||
ClearRanges(UploadRanges.Uniforms);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,9 @@ struct LevelMeshSurface
|
|||
|
||||
FGameTexture* Texture = nullptr;
|
||||
float Alpha = 1.0;
|
||||
|
||||
|
||||
int PipelineID = 0;
|
||||
|
||||
bool IsSky = false;
|
||||
int PortalIndex = 0;
|
||||
int SectorGroup = 0;
|
||||
|
|
|
|||
|
|
@ -557,7 +557,7 @@ void VkLevelMeshUploader::UploadSurfaces()
|
|||
SurfaceInfo* surfaces = (SurfaceInfo*)(data + datapos);
|
||||
for (int j = 0, count = range.Size; j < count; j++)
|
||||
{
|
||||
LevelMeshSurface* surface = Mesh->Mesh->GetSurface(range.Offset + j);
|
||||
LevelMeshSurface* surface = &Mesh->Mesh->Mesh.Surfaces[range.Offset + j];
|
||||
|
||||
SurfaceInfo info;
|
||||
info.Normal = FVector3(surface->Plane.X, surface->Plane.Z, surface->Plane.Y);
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ void VkLightmapper::Render()
|
|||
// Paint all surfaces visible in the tile
|
||||
for (int surfaceIndex : targetTile->Surfaces)
|
||||
{
|
||||
LevelMeshSurface* surface = mesh->GetSurface(surfaceIndex);
|
||||
LevelMeshSurface* surface = &mesh->Mesh.Surfaces[surfaceIndex];
|
||||
pc.SurfaceIndex = surfaceIndex;
|
||||
|
||||
VkDrawIndexedIndirectCommand cmd;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue