Eliminating invisible meshes before sending draw calls to the GPU:
Extract the 6 frustum planes (Left, Right, Bottom, Top, Near, Far) from the 4x4 View-Projection Matrix ($M = V \times P$):
// Distance from bounding sphere center to frustum plane
float DistanceToPlane(const Plane& p, const Vector3& center) {
return p.a * center.x + p.b * center.y + p.c * center.z + p.d;
}
bool IsSphereInFrustum(const Vector3& center, float radius, const Plane planes[6]) {
for (int i = 0; i < 6; i++) {
if (DistanceToPlane(planes[i], center) < -radius)
return false; // Completely outside frustum!
}
return true; // Visible!
}Skips 60-80% of world scene objects, saving massive GPU rasterization time!