Browse Source

A bit of cleanup ahead of attempting to make textures work

master
Nico de Poel 3 years ago
parent
commit
1882d246b9
  1. 23
      main.cpp
  2. 19
      ps1bsp.h

23
main.cpp

@ -318,9 +318,9 @@ int process_faces(const world_t* world)
// export_lightmap(world, face, bounds, faceIdx);
outFace.numFaceVertices = (unsigned short)(outFaceVertices.size() - outFace.firstFaceVertex);
outFace.centerPoint = convertWorldPosition(vertexSum / outFace.numFaceVertices);
outFace.center = convertWorldPosition(vertexSum / outFace.numFaceVertices);
float area = computeFaceArea(world, face);
outFace.centerPoint.pad = (short)(sqrt(area));
outFace.center.pad = (short)(sqrt(area));
outFaces.push_back(outFace);
}
@ -335,28 +335,9 @@ int process_faces(const world_t* world)
{
ps1bsp_facevertex_t& faceVertex = outFaceVertices[outFace.firstFaceVertex + faceVertIdx];
faceVertex.light = compute_faceVertex_light2(world, face, faceVertex.index, faceBounds, vertexFaces);
if (face->lightmap >= 0)
{
ps1bsp_vertex_t& vertex = outVertices[faceVertex.index];
*(unsigned short*)(&vertex.baseLight) += faceVertex.light;
vertex.r++;
}
}
}
// Average the lightmap values for each vertex
for (auto iter = outVertices.begin(); iter != outVertices.end(); ++iter)
{
unsigned char count = (*iter).r;
if (count == 0)
continue;
unsigned short accumulate = *(unsigned short*)(&(*iter).baseLight);
(*iter).baseLight = accumulate / count;
(*iter).r = 0;
}
// Convert planes
std::vector<ps1bsp_plane_t> outPlanes;
for (int planeIdx = 0; planeIdx < world->numPlanes; ++planeIdx)

19
ps1bsp.h

@ -46,27 +46,22 @@ typedef struct
unsigned short nextframe; // If non-zero, the texture is animated and this points to the next texture in the sequence
} ps1bsp_texture_t;
// This matches the SVECTOR data type, using the extra padding to store vertex color data.
// The full range and precision required cannot be stored in just shorts, so we make use of a floating origin stored in the BSP leafs.
// With this the higher-order bits of each vertex position are calculated into the model-view matrix, giving good precision for polygons near the camera.
// This matches the SVECTOR data type; we can use the extra padding to store some more data.
typedef struct
{
short x;
short y;
short z;
unsigned char baseLight, finalLight; // Used for gouraud shading based on static lightmap data
// Sampled color value from the face texture, for untextured gouraud shaded drawing
unsigned char a : 1; // 0 = opaque, 1 = semi-transparent
unsigned char r : 5;
unsigned char g : 5;
unsigned char b : 5;
short pad;
} ps1bsp_vertex_t;
typedef struct
{
unsigned short index;
unsigned short light;
// TODO: add texture uv's
// TODO: add sampled texture color * light, for untextured gouraud shaded drawing at range
} ps1bsp_facevertex_t;
typedef struct
@ -77,7 +72,7 @@ typedef struct
unsigned short firstFaceVertex;
unsigned short numFaceVertices;
SVECTOR centerPoint;
SVECTOR center;
u_long drawFrame; // Which frame was this face last drawn on? Used to check if this face should be drawn.
} ps1bsp_face_t;
@ -94,7 +89,7 @@ typedef struct
int planeId;
short children[2];
// TODO: add bounding box for frustum culling
// TODO: add bounding box for frustum culling (or bounding sphere, might be cheaper)
u_short firstFace;
u_short numFaces;

Loading…
Cancel
Save