Skip to content

Commit 6f6913c

Browse files
committed
Rework material system material and surface generation
1 parent 7160194 commit 6f6913c

File tree

12 files changed

+352
-584
lines changed

12 files changed

+352
-584
lines changed

src/engine/renderer/GeometryOptimiser.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ void MergeDuplicateVertices( bspSurface_t** rendererSurfaces, int numSurfaces, s
356356
}
357357
} */
358358

359-
std::vector<MaterialSurface> OptimiseMapGeometryMaterial( world_t* world, int numSurfaces ) {
359+
std::vector<MaterialSurface> OptimiseMapGeometryMaterial( world_t* world, bspSurface_t** rendererSurfaces, int numSurfaces ) {
360360
std::vector<MaterialSurface> materialSurfaces;
361361
materialSurfaces.reserve( numSurfaces );
362362

@@ -366,23 +366,44 @@ std::vector<MaterialSurface> OptimiseMapGeometryMaterial( world_t* world, int nu
366366
// std::unordered_map<TriEdge, TriIndex> triEdges;
367367

368368
int surfaceIndex = 0;
369-
for ( int k = 0; k < world->numSurfaces; k++ ) {
370-
bspSurface_t* surface = &world->surfaces[k];
369+
vec3_t worldBounds[2] = {};
370+
for ( int i = 0; i < numSurfaces; i++ ) {
371+
bspSurface_t* surface = rendererSurfaces[i];
372+
373+
if ( surface->BSPModel ) {
374+
// Not implemented yet
375+
continue;
376+
}
371377

372378
MaterialSurface srf {};
373379

374380
srf.shader = surface->shader;
375381
srf.bspSurface = true;
382+
srf.lightMapNum = surface->lightmapNum;
376383
srf.fog = surface->fogIndex;
384+
srf.portalNum = surface->portalNum;
377385

378386
srf.firstIndex = ( ( srfGeneric_t* ) surface->data )->firstIndex;
379-
srf.count = ( ( srfGeneric_t* ) surface->data )->numTriangles;
387+
srf.count = ( ( srfGeneric_t* ) surface->data )->numTriangles * 3;
380388
srf.verts = ( ( srfGeneric_t* ) surface->data )->verts;
381389
srf.tris = ( ( srfGeneric_t* ) surface->data )->triangles;
382390

391+
VectorCopy( ( ( srfGeneric_t* ) surface->data )->origin, srf.origin );
392+
srf.radius = ( ( srfGeneric_t* ) surface->data )->radius;
393+
394+
BoundsAdd( worldBounds[0], worldBounds[1],
395+
( ( srfGeneric_t* ) surface->data )->bounds[0], ( ( srfGeneric_t* ) surface->data )->bounds[1] );
396+
397+
materialSystem.GenerateMaterial( &srf );
398+
383399
materialSurfaces.emplace_back( srf );
384400
surfaceIndex++;
385401
}
386402

403+
materialSystem.GenerateWorldMaterialsBuffer();
404+
materialSystem.GeneratePortalBoundingSpheres();
405+
materialSystem.SetWorldBounds( worldBounds );
406+
materialSystem.GenerateWorldCommandBuffer( materialSurfaces );
407+
387408
return materialSurfaces;
388409
}

src/engine/renderer/GeometryOptimiser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,6 @@ void OptimiseMapGeometryCore( world_t* world, bspSurface_t** rendererSurfaces, i
106106
void MergeLeafSurfacesCore( world_t* world, bspSurface_t** rendererSurfaces, int numSurfaces );
107107
void MergeDuplicateVertices( bspSurface_t** rendererSurfaces, int numSurfaces, srfVert_t* vertices, int numVerticesIn,
108108
glIndex_t* indices, int numIndicesIn, int& numVerticesOut, int& numIndicesOut );
109-
std::vector<MaterialSurface> OptimiseMapGeometryMaterial( world_t* world, int numSurfaces );
109+
std::vector<MaterialSurface> OptimiseMapGeometryMaterial( world_t* world, bspSurface_t** rendererSurfaces, int numSurfaces );
110110

111111
#endif // GEOMETRY_OPTIMISER_H

0 commit comments

Comments
 (0)