# How do I create a bounding frustum from a view & projection matrix?

Given a left-handed Projection matrix, a left-handed View matrix, a ViewProj matrix of View * Projection - How do I create a bounding Frustum comprised of near, far, left, right and top, bottom planes?

The only example I could find on Google (Tutorial 16: Frustum Culling) seems to not work; for example, if the math is used as given, the near-plane's distance is a negative. This places the near-plane behind the camera...

• I took a look at how it's done in XNA (where in this example value corresponds to a ViewProjection matrix) and it seems to be possible to extract all the plane information directly from the matrix. I'm too tired to figure it out at the moment though :P – David Gouveia Jun 2 '12 at 5:13

The easiest way I know of is to construct the view frustum in post-projective space (so-called NDC space), where the frustum is a cube, then transform it through the inverse view-projection matrix and construct the planes in world space.

The frustum in NDC space runs from -1 to +1 along the x and y axes, and from -1 to +1 on z if you're in OpenGL, or 0 to 1 on z if you're in D3D. Build the eight corners of this cube (setting w = 1), then multiply them by the inverse view-projection matrix, and divide by w to convert back to regular 3D points.

The result should be the frustum corners in world space, and you can then build the planes by using groups of 3 points and the usual formula for calculating a plane equation from 3 points.

This general technique should work with any kind of view-projection matrix - perspective or orthographic, oblique or straight, any FoV or aspect ratio, etc. There are ways to simplify it by making some assumptions about the form of the matrix, but those tend to break if any of the assumptions are changed.

• Projection matrices appear to be non-invertible. – Narf the Mouse Jun 2 '12 at 4:56
• Never mind; just tired. – Narf the Mouse Jun 2 '12 at 5:05
• @NarftheMouse, the full 4x4 projection matrix should still be invertible. See for instance D3DXMatrixPerspectiveLH; that's perfectly invertible given nonzero values for near, far, etc. – Nathan Reed Jun 2 '12 at 5:08
• Yep; just mistook the math due to tiredness. – Narf the Mouse Jun 2 '12 at 5:14
• Anyway, up-voted and checked the answer box, as I implemented it today and it works. Was pretty sure it would, but wanted to keep it open in case there was a problem. – Narf the Mouse Jun 4 '12 at 22:16