# Problem with frustum culling

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

## Recommended Posts

The story:

I load terrain,and split it into 17x17 vertices meshes,and create AABBs for those meshes.When the time to draw comes,I see if those AABBs are in the camera's frustum,and if they are,they are drawn,if not,they're not.

But I am having some problems if I look down.You can see for yourself:

That little triangle at the bottom is the skybox(so the user sees through the terrain!) that proves that parts of the terrain are being culled,when they shouldn't.

If I move the camera just a little bit it goes away,but others appear(mostly when I look down)

I use a near plane of 0.1f and a far plane of 5000.0f;

The code:

void frustum_extraction(){
D3DXPLANE* m_Frustum = new D3DXPLANE[6];

// Build a combined view & projection matrix
D3DXMATRIX m = GetViewMatrix() * GetProjMatrix();

// Left clipping plane
m_Frustum[0].a = -(m._14 + m._11);
m_Frustum[0].b = -(m._24 + m._21);
m_Frustum[0].c = -(m._34 + m._31);
m_Frustum[0].d = -(m._44 + m._41);

// Right clipping plane
m_Frustum[1].a = -(m._14 - m._11);
m_Frustum[1].b = -(m._24 - m._21);
m_Frustum[1].c = -(m._34 - m._31);
m_Frustum[1].d = -(m._44 - m._41);

// Top clipping plane
m_Frustum[2].a = -(m._14 - m._12);
m_Frustum[2].b = -(m._24 - m._22);
m_Frustum[2].c = -(m._34 - m._32);
m_Frustum[2].d = -(m._44 - m._42);

// Bottom clipping plane
m_Frustum[3].a = -(m._14 + m._12);
m_Frustum[3].b = -(m._24 + m._22);
m_Frustum[3].c = -(m._34 + m._32);
m_Frustum[3].d = -(m._44 + m._42);

// Near clipping plane
m_Frustum[4].a = -(m._13);
m_Frustum[4].b = -(m._23);
m_Frustum[4].c = -(m._33);
m_Frustum[4].d = -(m._43);

// Far clipping plane
m_Frustum[5].a = -(m._14 - m._13);
m_Frustum[5].b = -(m._24 - m._23);
m_Frustum[5].c = -(m._34 - m._33);
m_Frustum[5].d = -(m._44 - m._43);

// Normalize the m_Frustum
for (ULONG i = 0; i < 6; i++) D3DXPlaneNormalize(&m_Frustum[i], &m_Frustum[i]);

}

void check_ifInFrustum(){
D3DXVECTOR3 NearPoint, FarPoint, Normal;
ULONG i;
D3DXVECTOR3 Min = mesh->BoundsMin;
D3DXVECTOR3 Max = mesh->BoundsMax;

// Loop through all the planes
for (i = 0; i < 6; i++)
{
// Store the plane normal
Normal = D3DXVECTOR3(m_Frustum[i].a, m_Frustum[i].b, m_Frustum[i].c);

if (Normal.x > 0.0f)
{
if (Normal.y > 0.0f)
{
if (Normal.z > 0.0f)
{
NearPoint.x = Min.x; NearPoint.y = Min.y; NearPoint.z = Min.z;

} // End if Normal.z > 0
else
{
NearPoint.x = Min.x; NearPoint.y = Min.y; NearPoint.z = Max.z;

} // End if Normal.z <= 0

} // End if Normal.y > 0
else
{
if (Normal.z > 0.0f)
{
NearPoint.x = Min.x; NearPoint.y = Max.y; NearPoint.z = Min.z;

} // End if Normal.z > 0
else
{
NearPoint.x = Min.x; NearPoint.y = Max.y; NearPoint.z = Max.z;

} // End if Normal.z <= 0

} // End if Normal.y <= 0

} // End if Normal.x > 0
else
{
if (Normal.y > 0.0f)
{
if (Normal.z > 0.0f)
{
NearPoint.x = Max.x; NearPoint.y = Min.y; NearPoint.z = Min.z;

} // End if Normal.z > 0
else
{
NearPoint.x = Max.x; NearPoint.y = Min.y; NearPoint.z = Max.z;

} // End if Normal.z <= 0

} // End if Normal.y > 0
else
{
if (Normal.z > 0.0f)
{
NearPoint.x = Max.x; NearPoint.y = Max.y; NearPoint.z = Min.z;

} // End if Normal.z > 0
else
{
NearPoint.x = Max.x; NearPoint.y = Max.y; NearPoint.z = Max.z;

} // End if Normal.z <= 0

} // End if Normal.y <= 0

} // End if Normal.x <= 0

// Near extreme point is outside, and thus the
// AABB is totally outside the frustum ?
if (D3DXVec3Dot(&Normal, &NearPoint) + m_Frustum[i].d > 0.0f) return false;

} // Next Plane

// Is within the frustum
return true;
}


Any ideeas how to fix it?

Edited by noatom

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 9
• 15
• 9
• 11