From 2626b9c67f98d10fc87abb16314da37bd8eeefd0 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sun, 12 Feb 2023 13:18:47 +0100 Subject: [PATCH] A bit of cleanup: - Ditching the face vertex thing since we're not likely to use the low-quality render path in practice, and this saves a ton on extra vertex data - No need to build a world-space bounding box per face anymore --- lighting.cpp | 37 ++++++++----------------------------- lighting.h | 1 - main.cpp | 11 +---------- 3 files changed, 9 insertions(+), 40 deletions(-) diff --git a/lighting.cpp b/lighting.cpp index 1019ed8..cbfc833 100644 --- a/lighting.cpp +++ b/lighting.cpp @@ -40,44 +40,23 @@ void export_lightmap(const world_t* world, const face_t* face, const FaceBound& if (face->lightmap < 0) return; - const unsigned char* lightmap = &world->lightmap[face->lightmap]; - const plane_t* plane = &world->planes[face->plane_id]; + Vec3 minBounds = (bounds.lightmapBounds.min / 16).floor(); + Vec3 maxBounds = (bounds.lightmapBounds.max / 16).ceil(); - int width, height; - switch (plane->type) - { - case 0: - case 3: - // Towards X - width = (int)(ceil(bounds.worldBounds.max.y / 16) - floor(bounds.worldBounds.min.y / 16)); - height = (int)(ceil(bounds.worldBounds.max.z / 16) - floor(bounds.worldBounds.min.z / 16)); - break; - case 1: - case 4: - // Towards Y - width = (int)(ceil(bounds.worldBounds.max.x / 16) - floor(bounds.worldBounds.min.x / 16)); - height = (int)(ceil(bounds.worldBounds.max.z / 16) - floor(bounds.worldBounds.min.z / 16)); - break; - case 2: - case 5: - // Towards Z - width = (int)(ceil(bounds.worldBounds.max.x / 16) - floor(bounds.worldBounds.min.x / 16)); - height = (int)(ceil(bounds.worldBounds.max.y / 16) - floor(bounds.worldBounds.min.y / 16)); - break; - default: - printf("Error: unknown plane type %d\n", plane->type); - return; - } + int width = ((int)maxBounds.x - (int)minBounds.x) * 16; // extents[0] + int height = ((int)maxBounds.y - (int)minBounds.y) * 16; // extents[1] - width += 1; + width = (width >> 4) + 1; + height = (height >> 4) + 1; char path[_MAX_PATH]; - sprintf_s(path, _MAX_PATH, "lightmap_face%d_e%d_PT%d_%dx%d.raw", faceIdx, face->ledge_num, plane->type, width, height); + sprintf_s(path, _MAX_PATH, "lightmap_face%d_e%d_%dx%d.raw", faceIdx, face->ledge_num, width, height); FILE* flm; fopen_s(&flm, path, "wb"); if (!flm) return; + const unsigned char* lightmap = &world->lightmap[face->lightmap]; for (int y = 0; y < height; ++y) { fwrite(&lightmap[y * width], sizeof(unsigned char), width, flm); diff --git a/lighting.h b/lighting.h index 5cf2bf8..e0b3dcc 100644 --- a/lighting.h +++ b/lighting.h @@ -18,7 +18,6 @@ struct Surface struct FaceBound { - BoundBox worldBounds; Matrix4x4 textureTransform; BoundBox textureBounds; Matrix4x4 lightmapTransform; diff --git a/main.cpp b/main.cpp index de6545d..9461681 100644 --- a/main.cpp +++ b/main.cpp @@ -100,12 +100,7 @@ int process_faces(const world_t* world, const TextureList& textures) const vertex_t* vertex = &world->vertices[vertIndex]; Vec3 vertexPoint = vertex->toVec(); - // Calculate bounding box of this face - if (edgeListIdx == 0) - bounds.worldBounds.init(vertexPoint); - else - bounds.worldBounds.includePoint(vertexPoint); - + // Calculate bounding boxes of this face Vec3 texturePoint = bounds.textureTransform.TransformPoint(vertexPoint); bounds.addTexturePoint(texturePoint.x, texturePoint.y); @@ -114,10 +109,6 @@ int process_faces(const world_t* world, const TextureList& textures) // Sum all vertices to calculate an average center point vertexSum = vertexSum + vertexPoint; - - ps1bsp_facevertex_t faceVertex = { 0 }; - faceVertex.index = (unsigned short)tesselator.addVertex(vertexPoint); - outFaceVertices.push_back(faceVertex); } faceBounds[face] = bounds;