Browse Source

Added box-frustum test code, used to experiment with more accurate per-leaf bounding box frustum culling.

Not really worth it as it only makes things slower in the end.
unrollquadloop
Nico de Poel 3 years ago
parent
commit
5e738340b8
  1. 22
      frustum.c
  2. 1
      frustum.h
  3. 8
      ps1bsp.h
  4. BIN
      test.ps1bsp
  5. 2
      world.c

22
frustum.c

@ -53,6 +53,15 @@ void frustum_update(int width, int height)
// left.vx, left.pad, right.vx, right.pad, top.vz, top.pad, bottom.vz, bottom.pad);
}
static INLINE u_char frustum_pointInside_(const SVECTOR p)
{
if (m_dot12(left, p) + left.pad < 0) return 0;
if (m_dot12(right, p) + right.pad < 0) return 0;
if (m_dot12(top, p) + top.pad < 0) return 0;
if (m_dot12(bottom, p) + bottom.pad < 0) return 0;
return 1;
}
u_char frustum_pointInside(const SVECTOR *point)
{
if (m_dot12(left, *point) + left.pad < 0) return 0;
@ -71,3 +80,16 @@ u_char frustum_sphereInside(const SVECTOR *sphere)
if (m_dot12(bottom, *sphere) + bottom.pad < radius) return 0;
return 1;
}
u_char frustum_boxInside(const SVECTOR *min, const SVECTOR *max)
{
if (frustum_pointInside_((SVECTOR) { min->vx, min->vy, min->vz })) return 1;
if (frustum_pointInside_((SVECTOR) { min->vx, min->vy, max->vz })) return 1;
if (frustum_pointInside_((SVECTOR) { min->vx, max->vy, min->vz })) return 1;
if (frustum_pointInside_((SVECTOR) { min->vx, max->vy, max->vz })) return 1;
if (frustum_pointInside_((SVECTOR) { max->vx, min->vy, min->vz })) return 1;
if (frustum_pointInside_((SVECTOR) { max->vx, min->vy, max->vz })) return 1;
if (frustum_pointInside_((SVECTOR) { max->vx, max->vy, min->vz })) return 1;
if (frustum_pointInside_((SVECTOR) { max->vx, max->vy, max->vz })) return 1;
return 0;
}

1
frustum.h

@ -4,5 +4,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);
#endif // __FRUSTUM_H__

8
ps1bsp.h

@ -138,18 +138,18 @@ typedef struct
SVECTOR boundingSphere;
} ps1bsp_node_t;
typedef struct
typedef struct ps1bsp_leaf_s
{
int type;
short type;
int vislist;
SVECTOR boundingSphere;
SVECTOR mins, maxs;
u_short firstLeafFace;
u_short numLeafFaces;
// Run-time data
u_short nextLeaf; // For chaining leafs in drawing order
struct ps1bsp_leaf_s *nextLeaf; // For chaining leafs in drawing order
u_short leafDepth; // At what depth the leaf's faces should be placed in the ordering table
} ps1bsp_leaf_t;

BIN
test.ps1bsp

2
world.c

@ -200,7 +200,7 @@ static void world_drawnode(const world_t *world, short nodeIdx, u_char *pvs)
return;
const ps1bsp_leaf_t *leaf = &world->leaves[~nodeIdx];
// if (!frustum_sphereInside(&leaf->boundingSphere)) // TODO: not sure if it's actually faster to do all these additional frustum checks
// if (!frustum_boxInside(&leaf->mins, &leaf->maxs)) // TODO: these additional frustum checks actually make things slower, probably not worth it
// return;
u_long frameNum = time_getFrameNumber();

Loading…
Cancel
Save