Browse Source

Retired the concept of surface vertices, as UVs can in fact not be shared between polygons.

I may revisit this idea when trying to compress data size, as lighting data can be shared between poly vertices.
master
Nico de Poel 3 years ago
parent
commit
4655246b69
  1. 20
      main.cpp
  2. 5
      ps1bsp.h

20
main.cpp

@ -137,7 +137,7 @@ int process_faces(const world_t* world, const std::vector<ps1bsp_texture_t>& tex
outFaces.push_back(outFace);
}
std::vector<ps1bsp_surfvertex_t> outSurfVertices;
std::vector<ps1bsp_polyvertex_t> outPolyVertices;
std::vector<ps1bsp_polygon_t> outPolygons;
// Iterate over all faces again; now that we know the bounds of each face, we can calculate lighting for all of them
@ -156,7 +156,7 @@ int process_faces(const world_t* world, const std::vector<ps1bsp_texture_t>& tex
for (auto polyIter = polygons.begin(); polyIter != polygons.end(); ++polyIter)
{
ps1bsp_polygon_t outPoly = { 0 };
outPoly.firstPolyVertex = (unsigned short)outSurfVertices.size();
outPoly.firstPolyVertex = (unsigned short)outPolyVertices.size();
for (auto polyVertIter = polyIter->polyVertices.begin(); polyVertIter != polyIter->polyVertices.end(); ++polyVertIter)
{
@ -165,21 +165,21 @@ int process_faces(const world_t* world, const std::vector<ps1bsp_texture_t>& tex
Vec3 vertex = tesselator.getVertices()[vertIndex];
ps1bsp_surfvertex_t surfVert = { 0 };
surfVert.index = (unsigned short)vertIndex;
surfVert.u = (unsigned char)(normalizedUV.x * (ps1tex.w - 1)) + ps1tex.uoffs;
surfVert.v = (unsigned char)(normalizedUV.y * (ps1tex.h - 1)) + ps1tex.voffs;
ps1bsp_polyvertex_t polyVert = { 0 };
polyVert.index = (unsigned short)vertIndex;
polyVert.u = (unsigned char)(normalizedUV.x * (ps1tex.w - 1)) + ps1tex.uoffs;
polyVert.v = (unsigned char)(normalizedUV.y * (ps1tex.h - 1)) + ps1tex.voffs;
int light = compute_faceVertex_light5(world, face, faceBounds, vertex);
light = (int)((float)light * 1.5f); // Compromise between overbright and non-overbright lighting. Looks good in practice.
if (light > 255)
light = 255;
surfVert.light = (unsigned short)light;
outSurfVertices.push_back(surfVert);
polyVert.light = (unsigned short)light;
outPolyVertices.push_back(polyVert);
}
outPoly.numPolyVertices = (unsigned short)(outSurfVertices.size() - outPoly.firstPolyVertex);
outPoly.numPolyVertices = (unsigned short)(outPolyVertices.size() - outPoly.firstPolyVertex);
outPolygons.push_back(outPoly);
}
@ -265,8 +265,8 @@ int process_faces(const world_t* world, const std::vector<ps1bsp_texture_t>& tex
// Write collected data to file and update header info
writeMapData(textures, outHeader.textures, fbsp);
writeMapData(outVertices, outHeader.vertices, fbsp);
writeMapData(outSurfVertices, outHeader.surfVertices, fbsp);
writeMapData(outPolygons, outHeader.polygons, fbsp);
writeMapData(outPolyVertices, outHeader.polyVertices, fbsp);
writeMapData(outFaces, outHeader.faces, fbsp);
writeMapData(outFaceVertices, outHeader.faceVertices, fbsp);
writeMapData(outPlanes, outHeader.planes, fbsp);

5
ps1bsp.h

@ -30,7 +30,6 @@ typedef struct
ps1bsp_dentry_t textures;
ps1bsp_dentry_t vertices;
ps1bsp_dentry_t surfVertices;
ps1bsp_dentry_t polygons;
ps1bsp_dentry_t polyVertices;
ps1bsp_dentry_t faces;
@ -57,13 +56,13 @@ typedef struct
short pad;
} ps1bsp_vertex_t;
// Texture UV and lighting data for a vertex on a particular surface. Can be shared between multiple polygons on the same surface.
// Texture UV and lighting data for a vertex on a particular polygon.
typedef struct
{
unsigned short index;
unsigned short light; // Can be made into u_char if we need to store more data; currently u_short for 32-bit alignment purposes
unsigned short u, v; // Can be made into u_char if we need to store more data; currently u_short for 32-bit alignment purposes
} ps1bsp_surfvertex_t;
} ps1bsp_polyvertex_t;
// Faces are broken up into one or more polygons, each of which can be drawn as a quad/triangle strip with a single texture.
// This ahead-of-time tesselation is done to deal with the fact that the PS1 can't do texture wrapping, meaning tiling textures have to be broken up into separate polygons.

Loading…
Cancel
Save