Browse Source

A bit of cleanup ahead of attempting to make textures work

unrollquadloop
Nico de Poel 3 years ago
parent
commit
c8c44b352f
  1. 22
      ps1bsp.h
  2. BIN
      test.ps1bsp
  3. 8
      world.c

22
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;
@ -105,7 +100,8 @@ typedef struct
int type;
int vislist;
// TODO: add bounding box for frustum culing
// TODO: add bounding box for frustum culling (or do we? could save half the number of bounds checks if we only check nodes)
//SVECTOR center;
u_short firstLeafFace;
u_short numLeafFaces;

BIN
test.ps1bsp

8
world.c

@ -225,10 +225,10 @@ static void world_drawface(const world_t *world, const ps1bsp_face_t *face)
{
// Backface culling using the face's plane and center point
// This eliminates the need for normal clipping per polygon
SVECTOR cam_vec, center = face->centerPoint;
cam_vec.vx = center.vx - cam_pos.vx;
cam_vec.vy = center.vy - cam_pos.vy;
cam_vec.vz = center.vz - cam_pos.vz;
SVECTOR cam_vec;
cam_vec.vx = face->center.vx - cam_pos.vx;
cam_vec.vy = face->center.vy - cam_pos.vy;
cam_vec.vz = face->center.vz - cam_pos.vz;
const ps1bsp_plane_t *plane = &world->planes[face->planeId];
// NOTE: this value could be REALLY useful for determining the tessellation subdivisions. It has camera distance *and* angle in it.

Loading…
Cancel
Save