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

## 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 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 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 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_Left.Normalize();Frust_Right.x = ViewProj._14 - ViewProj._11;Frust_Right.y = ViewProj._24 - ViewProj._21;Frust_Right.z = ViewProj._34 - ViewProj._31;Frust_Right.Normalize();Frust_Top.x = ViewProj._14 - ViewProj._12;Frust_Top.y = ViewProj._24 - ViewProj._22;Frust_Top.z = ViewProj._34 - ViewProj._32;Frust_Top.Normalize();Frust_Bottom.x = ViewProj._14 + ViewProj._12;Frust_Bottom.y = ViewProj._24 + ViewProj._22;Frust_Bottom.z = ViewProj._34 + ViewProj._32;Frust_Bottom.Normalize();

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]

1. 1
Rutin
31
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633313
• Total Posts
3011321
• ### Who's Online (See full list)

There are no registered users currently online

×