Browse Source

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
master
Nico de Poel 3 years ago
parent
commit
2626b9c67f
  1. 37
      lighting.cpp
  2. 1
      lighting.h
  3. 11
      main.cpp

37
lighting.cpp

@ -40,44 +40,23 @@ void export_lightmap(const world_t* world, const face_t* face, const FaceBound&
if (face->lightmap < 0) if (face->lightmap < 0)
return; 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]; 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; FILE* flm;
fopen_s(&flm, path, "wb"); fopen_s(&flm, path, "wb");
if (!flm) if (!flm)
return; return;
const unsigned char* lightmap = &world->lightmap[face->lightmap];
for (int y = 0; y < height; ++y) for (int y = 0; y < height; ++y)
{ {
fwrite(&lightmap[y * width], sizeof(unsigned char), width, flm); fwrite(&lightmap[y * width], sizeof(unsigned char), width, flm);

1
lighting.h

@ -18,7 +18,6 @@ struct Surface
struct FaceBound struct FaceBound
{ {
BoundBox worldBounds;
Matrix4x4 textureTransform; Matrix4x4 textureTransform;
BoundBox textureBounds; BoundBox textureBounds;
Matrix4x4 lightmapTransform; Matrix4x4 lightmapTransform;

11
main.cpp

@ -100,12 +100,7 @@ int process_faces(const world_t* world, const TextureList& textures)
const vertex_t* vertex = &world->vertices[vertIndex]; const vertex_t* vertex = &world->vertices[vertIndex];
Vec3 vertexPoint = vertex->toVec(); 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); Vec3 texturePoint = bounds.textureTransform.TransformPoint(vertexPoint);
bounds.addTexturePoint(texturePoint.x, texturePoint.y); 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 // Sum all vertices to calculate an average center point
vertexSum = vertexSum + vertexPoint; vertexSum = vertexSum + vertexPoint;
ps1bsp_facevertex_t faceVertex = { 0 };
faceVertex.index = (unsigned short)tesselator.addVertex(vertexPoint);
outFaceVertices.push_back(faceVertex);
} }
faceBounds[face] = bounds; faceBounds[face] = bounds;

Loading…
Cancel
Save