Jump to content
  • Advertisement
Sign in to follow this  

Frustum culling with Direct3D

This topic is 4930 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, Does someone know where can i find documentation or source code about frustum culling with direct3d? I know i have to test if bounding boxes of the objects are inside the 6 planes of the frustum but how can i do this?:) Thanks Kev

Share this post

Link to post
Share on other sites
Every bounding box has 8 corners, calculate the distance of each of that corners, if one of them is positive and ohers negative, it means the box is intersecting with the plane. If all are positive it means, the box is on that side of the plane the normal is pointing to. All negative means the other side.
The distance of a point(x,y,z) to a plane is:

a*x + b*y + c*z + d, where (a,b,c) makes up the normal of the plane, which should be normalized, d is the distance of the plane to the origin.

Share this post

Link to post
Share on other sites
Thank you very much, but how can i obtain the 6 planes of the frustum? i remember something about getting them from a matrix...view matrix?...or projection matrix?

Thanks again

Share this post

Link to post
Share on other sites
You need to multiply your view and projection matrices together. Your frustum is just a bunch of planes.

You calculate the normals of those planes like this:

Frust_Left.x = ViewProj._14 + ViewProj._11;
Frust_Left.y = ViewProj._24 + ViewProj._21;
Frust_Left.z = ViewProj._34 + ViewProj._31;

Frust_Right.x = ViewProj._14 - ViewProj._11;
Frust_Right.y = ViewProj._24 - ViewProj._21;
Frust_Right.z = ViewProj._34 - ViewProj._31;

Frust_Top.x = ViewProj._14 - ViewProj._12;
Frust_Top.y = ViewProj._24 - ViewProj._22;
Frust_Top.z = ViewProj._34 - ViewProj._32;

Frust_Bottom.x = ViewProj._14 + ViewProj._12;
Frust_Bottom.y = ViewProj._24 + ViewProj._22;
Frust_Bottom.z = ViewProj._34 + ViewProj._32;

All of these planes have the same position. The position is your camera's positon. You don't really need to calculate the other planes, because they're simply your camera's forward vector multiplied by the near or far distances.

To find if a single point is outside of this frustum, you need to see which side of each plane that point is on. If it is outside of any plane, the point is invisible. Spheres are the same, just add some radius to the distance check. Complex shapes are a bit more of a headache. You have to check to make sure all of the points are outside of one frustum plane.

An easy mistake to make is to assume that if all points are invisible, the object is invisible. But imagine a scenario where the top points are outside of the top plane, and the bottom points are outside of the bottom plane. The center of your object is centered within the camera, and is totally visible. You need to be weary of this when you try to optimize the culling.

edit: The example code I gave was using a DirectX matrix. Sorry. Sometimes I forget which forum I'm in [smile]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!