Browse Source

Added check to backface culling to see if the face is behind the camera.

This will be required if we ditch depth-based culling in favor of leaf-based depth.
Also makes for a nice speed boost in some scenarios already.
unrollquadloop
Nico de Poel 3 years ago
parent
commit
b1e568e5c3
  1. 1
      common.h
  2. 4
      input.c
  3. 1
      main.c
  4. 6
      world.c

1
common.h

@ -22,6 +22,7 @@ typedef struct _STVECTOR {
extern VECTOR cam_pos;
extern SVECTOR cam_rot;
extern SVECTOR cam_dir;
extern u_short cam_leaf;
extern u_short quake_clut;

4
input.c

@ -34,6 +34,10 @@ void input_process()
MATRIX cam_mtx;
RotMatrixQ(&cam_rot, &cam_mtx);
cam_dir.vx = cam_mtx.m[0][1];
cam_dir.vy = cam_mtx.m[1][1];
cam_dir.vz = cam_mtx.m[2][1];
int deltaTime = time_getDeltaTime();
int moveInterval = (moveSpeed * deltaTime) >> 12;
int rotInterval = (moveSpeed * deltaTime) >> 12;

1
main.c

@ -11,6 +11,7 @@ extern u_long bsp_test[];
VECTOR cam_pos = { 2176, 1152, 272 }; // START
//VECTOR cam_pos = { 1920, -1408, 352 }; // E1M1
SVECTOR cam_rot = { 0, 0, 0 };
SVECTOR cam_dir = { 0, ONE, 0 };
u_short cam_leaf = 0;
world_t world;

6
world.c

@ -77,7 +77,13 @@ static INLINE char world_cull_backface(const world_t *world, const ps1bsp_face_t
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;
// Check if the face is behind the camera
short camDot = m_dot12s(cam_vec, cam_dir);
if (camDot < 0)
return 1;
// Check if the face's plane points towards the camera
const ps1bsp_plane_t *plane = &world->planes[face->planeId];
*dot = world_planeDot(&cam_vec, plane);
return ((*dot >= 0) ^ face->side);

Loading…
Cancel
Save