|
|
@ -68,6 +68,8 @@ int process_faces(const world_t* world, const std::vector<ps1bsp_texture_t>& tex |
|
|
{ |
|
|
{ |
|
|
const face_t* face = &world->faces[faceIdx]; |
|
|
const face_t* face = &world->faces[faceIdx]; |
|
|
const texinfo_t* texinfo = &world->texInfos[face->texinfo_id]; |
|
|
const texinfo_t* texinfo = &world->texInfos[face->texinfo_id]; |
|
|
|
|
|
const miptex_t* miptex = &world->miptexes[texinfo->texture_id]; |
|
|
|
|
|
const plane_t* plane = &world->planes[face->plane_id]; |
|
|
|
|
|
|
|
|
ps1bsp_face_t outFace = { 0 }; |
|
|
ps1bsp_face_t outFace = { 0 }; |
|
|
outFace.planeId = face->plane_id; |
|
|
outFace.planeId = face->plane_id; |
|
|
@ -75,9 +77,11 @@ int process_faces(const world_t* world, const std::vector<ps1bsp_texture_t>& tex |
|
|
outFace.firstFaceVertex = (unsigned short)outFaceVertices.size(); |
|
|
outFace.firstFaceVertex = (unsigned short)outFaceVertices.size(); |
|
|
outFace.textureId = (unsigned char)texinfo->texture_id; |
|
|
outFace.textureId = (unsigned char)texinfo->texture_id; |
|
|
|
|
|
|
|
|
|
|
|
Matrix4x4 textureTrsf = tesselator.buildTextureSpaceTransform(texinfo, miptex, plane); |
|
|
|
|
|
|
|
|
// Traverse the list of face edges to collect all of the face's vertices
|
|
|
// Traverse the list of face edges to collect all of the face's vertices
|
|
|
Vec3 vertexSum; |
|
|
Vec3 vertexSum; |
|
|
BoundBox bounds; |
|
|
|
|
|
|
|
|
FaceBound bounds; |
|
|
for (int edgeListIdx = 0; edgeListIdx < face->ledge_num; ++edgeListIdx) |
|
|
for (int edgeListIdx = 0; edgeListIdx < face->ledge_num; ++edgeListIdx) |
|
|
{ |
|
|
{ |
|
|
int edgeIdx = world->edgeList[face->ledge_id + edgeListIdx]; |
|
|
int edgeIdx = world->edgeList[face->ledge_id + edgeListIdx]; |
|
|
@ -91,9 +95,12 @@ int process_faces(const world_t* world, const std::vector<ps1bsp_texture_t>& tex |
|
|
|
|
|
|
|
|
// Calculate bounding box of this face
|
|
|
// Calculate bounding box of this face
|
|
|
if (edgeListIdx == 0) |
|
|
if (edgeListIdx == 0) |
|
|
bounds.init(vertexPoint); |
|
|
|
|
|
|
|
|
bounds.worldBounds.init(vertexPoint); |
|
|
else |
|
|
else |
|
|
bounds.includePoint(vertexPoint); |
|
|
|
|
|
|
|
|
bounds.worldBounds.includePoint(vertexPoint); |
|
|
|
|
|
|
|
|
|
|
|
Vec3 texturePoint = textureTrsf.TransformPoint(vertexPoint); |
|
|
|
|
|
bounds.addTexturePoint(texturePoint.x, texturePoint.y); |
|
|
|
|
|
|
|
|
// Sum all vertices to calculate an average center point
|
|
|
// Sum all vertices to calculate an average center point
|
|
|
vertexSum = vertexSum + vertexPoint; |
|
|
vertexSum = vertexSum + vertexPoint; |
|
|
@ -163,13 +170,12 @@ int process_faces(const world_t* world, const std::vector<ps1bsp_texture_t>& tex |
|
|
size_t vertIndex = polyVertIter->vertexIndex; |
|
|
size_t vertIndex = polyVertIter->vertexIndex; |
|
|
Vec3 normalizedUV = polyVertIter->normalizedUV; |
|
|
Vec3 normalizedUV = polyVertIter->normalizedUV; |
|
|
|
|
|
|
|
|
Vec3 vertex = tesselator.getVertices()[vertIndex]; |
|
|
|
|
|
|
|
|
|
|
|
ps1bsp_polyvertex_t polyVert = { 0 }; |
|
|
ps1bsp_polyvertex_t polyVert = { 0 }; |
|
|
polyVert.index = (unsigned short)vertIndex; |
|
|
polyVert.index = (unsigned short)vertIndex; |
|
|
polyVert.u = (unsigned char)(normalizedUV.x * (ps1tex.w - 1)) + ps1tex.uoffs; |
|
|
polyVert.u = (unsigned char)(normalizedUV.x * (ps1tex.w - 1)) + ps1tex.uoffs; |
|
|
polyVert.v = (unsigned char)(normalizedUV.y * (ps1tex.h - 1)) + ps1tex.voffs; |
|
|
polyVert.v = (unsigned char)(normalizedUV.y * (ps1tex.h - 1)) + ps1tex.voffs; |
|
|
|
|
|
|
|
|
|
|
|
Vec3 vertex = tesselator.getVertices()[vertIndex]; |
|
|
int light = compute_faceVertex_light5(world, face, faceBounds, vertex); |
|
|
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.
|
|
|
light = (int)((float)light * 1.5f); // Compromise between overbright and non-overbright lighting. Looks good in practice.
|
|
|
if (light > 255) |
|
|
if (light > 255) |
|
|
|