High-performance view frustum implementation for efficient 3D culling operations.
The Frustum class represents a truncated pyramid defined by six planes, commonly used for view frustum culling in 3D rendering pipelines. It provides optimized methods for testing whether geometric primitives are inside, outside, or intersecting the frustum.
Key features:
- Memory-efficient representation (six planes)
- Optimized intersection tests with common primitives (points, AABBs, spheres)
- Multiple construction methods (from projection matrix, from individual planes)
- Fixed-point arithmetic for consistent behavior across platforms
- Specialized fast-rejection tests for performance-critical rendering paths
Frustum planes:
- Near: Close clipping plane (minimum Z distance)
- Far: Distance clipping plane (maximum Z distance)
- Left/Right: Horizontal bounds of the view
- Top/Bottom: Vertical bounds of the view
Coordinate system:
- Uses a right-handed coordinate system where:
- +X is right
- +Y is up
- -Z is forward (into the screen)
All plane normals point inward toward the frustum interior, so an object is inside the frustum if it's on the positive side of all planes. This convention simplifies containment tests and is consistent with standard graphics literature.
Performance optimizations:
- Tests are ordered to maximize early rejection
- AABB tests use optimized corner selection based on plane normals
- Sphere tests use squared distances to avoid square root calculations
Common applications:
- View frustum culling in rendering pipelines
- Portal culling for indoor environments
- Occlusion culling pre-processing
- Visibility determination for LOD systems
- Note
- For optimal culling performance, consider using a spatial partitioning structure (octree, BVH) in conjunction with frustum culling to minimize the number of individual object tests.
- See also
- Plane For the underlying plane implementation
-
AABB For axis-aligned bounding box intersection tests
-
Sphere For sphere intersection tests
|
| Frustum (const Angle &verticalFov, const Fxp &aspectRatio, const Fxp &nearDist, const Fxp &farDist) |
| Constructs a view frustum.
|
|
bool | Contains (const AABB &aabb) const |
| Tests if an AABB intersects the frustum.
|
|
bool | Contains (const Sphere &sphere) const |
| Tests if a sphere intersects the frustum.
|
|
bool | Contains (const Vector3D &point) const |
| Tests if a point is inside the frustum.
|
|
void | Update (const Matrix43 &viewMatrix) |
| Updates frustum planes based on view matrix.
|
|