Browse Source

Added a front frustum plane which isn't really used for anything yet, but it could be interesting for testing different depth culling approaches.

master
Nico de Poel 3 years ago
parent
commit
1c4bd55cdb
  1. 16
      frustum.c
  2. 1
      frustum.h
  3. 2
      world.c

16
frustum.c

@ -4,7 +4,7 @@
#include <inline_c.h>
static SVECTOR *left, *right, *top, *bottom;
static SVECTOR *left, *right, *top, *bottom, *front;
static INLINE void frustum_buildPlane(MATRIX *rot_matrix, VECTOR *normal, SVECTOR *outPlane)
{
@ -15,7 +15,7 @@ static INLINE void frustum_buildPlane(MATRIX *rot_matrix, VECTOR *normal, SVECTO
void frustum_update(int width, int height)
{
VECTOR l, r, t, b;
VECTOR l, r, t, b, f;
int near;
gte_ReadGeomScreen(&near);
@ -41,6 +41,10 @@ void frustum_update(int width, int height)
t.vy = ONE;
t.vz = -b.vz;
f.vx = 0;
f.vy = ONE;
f.vz = 0;
MATRIX rot_matrix;
RotMatrixQ(&cam_rot, &rot_matrix);
@ -49,11 +53,14 @@ void frustum_update(int width, int height)
right = (SVECTOR*)(scratchpad + sizeof(SVECTOR) * 1);
top = (SVECTOR*)(scratchpad + sizeof(SVECTOR) * 2);
bottom = (SVECTOR*)(scratchpad + sizeof(SVECTOR) * 3);
front = (SVECTOR*)(scratchpad + sizeof(SVECTOR) * 4);
frustum_buildPlane(&rot_matrix, &l, left);
frustum_buildPlane(&rot_matrix, &r, right);
frustum_buildPlane(&rot_matrix, &t, top);
frustum_buildPlane(&rot_matrix, &b, bottom);
frustum_buildPlane(&rot_matrix, &f, front);
front->pad -= near >> 1;
// FntPrint(-1, "l = %d %d, r = %d %d, t = %d %d, b = %d %d\n",
// left.vx, left.pad, right.vx, right.pad, top.vz, top.pad, bottom.vz, bottom.pad);
@ -99,3 +106,8 @@ u_char frustum_boxInside(const SVECTOR *min, const SVECTOR *max)
if (frustum_pointInside_((SVECTOR) { max->vx, max->vy, max->vz })) return 1;
return 0;
}
int frustum_pointDepth(const SVECTOR *point)
{
return m_dot12(front, point) + front->pad;
}

1
frustum.h

@ -5,5 +5,6 @@ void frustum_update(int width, int height);
u_char frustum_pointInside(const SVECTOR *point);
u_char frustum_sphereInside(const SVECTOR *sphere);
u_char frustum_boxInside(const SVECTOR *min, const SVECTOR *max);
int frustum_pointDepth(const SVECTOR *point);
#endif // __FRUSTUM_H__

2
world.c

@ -469,7 +469,7 @@ void world_draw(const world_t *world)
cam_leaf = world_leafAtPoint(world, &cam_pos);
u_char *pvsbuf = scratchpad + 32; // Place the PVS data after the frustum in fast RAM
u_char *pvsbuf = scratchpad + 48; // Place the PVS data after the frustum in fast RAM
u_char *pvs = world_loadVisData(world, cam_leaf, &pvsbuf);
//u_char *pvs = world_noVisData(world, &pvsbuf);

Loading…
Cancel
Save