Browse Source

Geometry, textures and lighting now all working correctly.

Ditched the concept of surface vertices, as UVs cannot be shared between polygons.
unrollquadloop
Nico de Poel 3 years ago
parent
commit
3b5a59dae6
  1. 5
      ps1bsp.h
  2. BIN
      test.ps1bsp
  3. 64
      world.c
  4. 6
      world.h

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.

BIN
test.ps1bsp

64
world.c

@ -41,8 +41,8 @@ void world_load(const u_long *data, world_t *world)
LOAD_CHUNK(ps1bsp_texture_t, world->textures, world->numTextures, bytes, header->textures);
LOAD_CHUNK(ps1bsp_vertex_t, world->vertices, world->numVertices, bytes, header->vertices);
LOAD_CHUNK(ps1bsp_surfvertex_t, world->surfVertices, world->numSurfVertices, bytes, header->surfVertices);
LOAD_CHUNK(ps1bsp_polygon_t, world->polygons, world->numPolygons, bytes, header->polygons);
LOAD_CHUNK(ps1bsp_polyvertex_t, world->polyVertices, world->numPolyVertices, bytes, header->polyVertices);
LOAD_CHUNK(ps1bsp_face_t, world->faces, world->numFaces, bytes, header->faces);
LOAD_CHUNK(ps1bsp_facevertex_t, world->faceVertices, world->numFaceVertices, bytes, header->faceVertices);
LOAD_CHUNK(ps1bsp_plane_t, world->planes, world->numPlanes, bytes, header->planes);
@ -313,13 +313,13 @@ static void world_drawface(const world_t *world, const ps1bsp_face_t *face)
const ps1bsp_polygon_t* poly = &world->polygons[face->firstPolygon];
for (u_char polyIdx = 0; polyIdx < face->numPolygons; ++polyIdx, ++poly)
{
ps1bsp_surfvertex_t *surfVertex = &world->surfVertices[poly->firstPolyVertex];
ps1bsp_polyvertex_t *polyVertex = &world->polyVertices[poly->firstPolyVertex];
SVECTOR *curVert = verts;
for (u_char vertIdx = 0; vertIdx < poly->numPolyVertices; ++vertIdx, ++surfVertex, ++curVert)
for (u_char vertIdx = 0; vertIdx < poly->numPolyVertices; ++vertIdx, ++polyVertex, ++curVert)
{
const ps1bsp_vertex_t *vert = &world->vertices[surfVertex->index];
const ps1bsp_vertex_t *vert = &world->vertices[polyVertex->index];
*curVert = *((SVECTOR*)vert);
curVert->pad = surfVertex->light;
curVert->pad = polyVertex->light;
}
if (poly->numPolyVertices == 3)
@ -336,62 +336,20 @@ static void world_drawface(const world_t *world, const ps1bsp_face_t *face)
const ps1bsp_polygon_t* poly = &world->polygons[face->firstPolygon];
for (u_char polyIdx = 0; polyIdx < face->numPolygons; ++polyIdx, ++poly)
{
ps1bsp_surfvertex_t *surfVertex = &world->surfVertices[poly->firstPolyVertex];
ps1bsp_polyvertex_t *polyVertex = &world->polyVertices[poly->firstPolyVertex];
STVECTOR *curVert = verts;
for (u_char vertIdx = 0; vertIdx < poly->numPolyVertices; ++vertIdx, ++surfVertex, ++curVert)
for (u_char vertIdx = 0; vertIdx < poly->numPolyVertices; ++vertIdx, ++polyVertex, ++curVert)
{
const ps1bsp_vertex_t *vert = &world->vertices[surfVertex->index];
const ps1bsp_vertex_t *vert = &world->vertices[polyVertex->index];
*((SVECTOR*)curVert) = *((SVECTOR*)vert);
curVert->u = (u_short)surfVertex->u;
curVert->v = (u_short)surfVertex->v;
curVert->pad = surfVertex->light;
curVert->u = (u_short)polyVertex->u;
curVert->v = (u_short)polyVertex->v;
curVert->pad = polyVertex->light;
}
draw_quad_strip_tex(verts, poly->numPolyVertices, faceTexture->tpage);
}
}
// if (!enableTexturing)
// {
// // Draw untextured, vertex colored polygons
// SVECTOR *vecs = (SVECTOR*)(scratchpad + 256);
// // Copy this face's vertices into scratch RAM for fast reuse
// // TODO: this is the main performance bottleneck right now!
// ps1bsp_facevertex_t *faceVertex = &world->faceVertices[face->firstFaceVertex];
// SVECTOR *curVec = vecs;
// for (int vertIdx = 0; vertIdx < face->numFaceVertices; ++vertIdx, ++faceVertex, ++curVec)
// {
// const ps1bsp_vertex_t *vert = &world->vertices[faceVertex->index];
// *curVec = *((SVECTOR*)vert);
// curVec->pad = faceVertex->light;
// }
// if (face->numFaceVertices == 3) // Special case: draw single triangles using the simplest method
// draw_triangle_fan(vecs, 3);
// else
// draw_quad_strip(vecs, face->numFaceVertices);
// }
// else
// {
// // Draw textured, vertex colored polygons
// STVECTOR *vecs = (STVECTOR*)(scratchpad + 256);
// // Copy this face's vertices into scratch RAM for fast reuse
// ps1bsp_facevertex_t *faceVertex = &world->faceVertices[face->firstFaceVertex];
// ps1bsp_texture_t *faceTexture = &world->textures[face->textureId];
// STVECTOR *curVec = vecs;
// for (int vertIdx = 0; vertIdx < face->numFaceVertices; ++vertIdx, ++faceVertex, ++curVec)
// {
// const ps1bsp_vertex_t *vert = &world->vertices[faceVertex->index];
// *((SVECTOR*)curVec) = *((SVECTOR*)vert);
// curVec->u = (u_short)faceVertex->u;
// curVec->v = (u_short)faceVertex->v;
// curVec->pad = faceVertex->light;
// }
// draw_quad_strip_tex(vecs, face->numFaceVertices, faceTexture->tpage);
// }
}
static void world_drawnode(const world_t *world, short nodeIdx, u_char *pvs)

6
world.h

@ -11,12 +11,12 @@ typedef struct
u_short numVertices;
ps1bsp_vertex_t *vertices;
u_short numSurfVertices;
ps1bsp_surfvertex_t *surfVertices;
u_short numPolygons;
ps1bsp_polygon_t *polygons;
u_short numPolyVertices;
ps1bsp_polyvertex_t *polyVertices;
u_short numFaces;
ps1bsp_face_t *faces;

Loading…
Cancel
Save