8
\$\begingroup\$

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...

\$\endgroup\$
1
  • \$\begingroup\$ 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 \$\endgroup\$ Jun 2, 2012 at 5:13

1 Answer 1

11
\$\begingroup\$

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.

\$\endgroup\$
5
  • \$\begingroup\$ Projection matrices appear to be non-invertible. \$\endgroup\$ Jun 2, 2012 at 4:56
  • \$\begingroup\$ Never mind; just tired. \$\endgroup\$ Jun 2, 2012 at 5:05
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Jun 2, 2012 at 5:08
  • \$\begingroup\$ Yep; just mistook the math due to tiredness. \$\endgroup\$ Jun 2, 2012 at 5:14
  • \$\begingroup\$ 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. \$\endgroup\$ Jun 4, 2012 at 22:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .