Jump to content
  • Advertisement
Sign in to follow this  

Frustum culling problems

This topic is 4792 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

I've looked around for some nice frustum culling code in c++/d3d but the one I found don't work very well.. I've read threads here and in other places but couldn't find good code to extract the view frustum planes. I took code from http://www.toymaker.info/Games/html/direct3d_faq.html#D3D6 and the code uses a combined matrix of the view and projection matrix. I'm a bit confused by the distance to plane variables which seemes to be 0.0 most of the time :) what happens is that almost everything get culled, but in certain angles of my camera some objects will be visible :) Any ideas on how to fix this? My projection matrix is set up like this D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, fAspect, 0.5f, 1000.0f ); m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); and the view matrix updates with the inverse to world matrix of the camera. I'm using world space AABB to cull objects. Help plz :)

Share this post

Link to post
Share on other sites
The plane distances should not all be zero, and if the camera is moving around rarely should any of them be zero. You might post your extraction code - it sounds like there's an error in there somewhere.

Share this post

Link to post
Share on other sites
Well.. whenever my camera moves I update the planes with the new view-matrix
and for some reason the distances becomes 0.0, at least on the left, right and
the bottom clip-planes.

void FrustumCuller::UpdatePlanes(const D3DXMATRIX &matView)
// Get combined matrix
D3DXMATRIXA16 matComb;
D3DXMatrixMultiply(&matComb, &matView, &m_matProj);

// Left clipping plane
m_frustumPlanes[0].m_normal.x = matComb._14 + matComb._11;
m_frustumPlanes[0].m_normal.y = matComb._24 + matComb._21;
m_frustumPlanes[0].m_normal.z = matComb._34 + matComb._31;
m_frustumPlanes[0].m_distance = matComb._44 + matComb._41;

// Right clipping plane
m_frustumPlanes[1].m_normal.x = matComb._14 - matComb._11;
m_frustumPlanes[1].m_normal.y = matComb._24 - matComb._21;
m_frustumPlanes[1].m_normal.z = matComb._34 - matComb._31;
m_frustumPlanes[1].m_distance = matComb._44 - matComb._41;

// Top clipping plane
m_frustumPlanes[2].m_normal.x = matComb._14 - matComb._12;
m_frustumPlanes[2].m_normal.y = matComb._24 - matComb._22;
m_frustumPlanes[2].m_normal.z = matComb._34 - matComb._32;
m_frustumPlanes[2].m_distance = matComb._44 - matComb._42;

// Bottom clipping plane
m_frustumPlanes[3].m_normal.x = matComb._14 + matComb._12;
m_frustumPlanes[3].m_normal.y = matComb._24 + matComb._22;
m_frustumPlanes[3].m_normal.z = matComb._34 + matComb._32;
m_frustumPlanes[3].m_distance = matComb._44 + matComb._42;

// Near clipping plane
m_frustumPlanes[4].m_normal.x = matComb._13;
m_frustumPlanes[4].m_normal.y = matComb._23;
m_frustumPlanes[4].m_normal.z = matComb._33;
m_frustumPlanes[4].m_distance = matComb._43;

// Far clipping plane
m_frustumPlanes[5].m_normal.x = matComb._14 - matComb._13;
m_frustumPlanes[5].m_normal.y = matComb._24 - matComb._23;
m_frustumPlanes[5].m_normal.z = matComb._34 - matComb._33;
m_frustumPlanes[5].m_distance = matComb._44 - matComb._43;

Share this post

Link to post
Share on other sites
The extraction code looks correct. Distances of zero for the side, top and bottom planes suggests an identity view matrix. Are you sure the view and projection matrices are both correct?

Share this post

Link to post
Share on other sites
There was something very strange about the distance values.. but after adding and removing a variable to the FrustumPlane class and rebuilding the solution the problem was gone?! =)

While debugging, setting the distance to something like 8.3 - 7.9 would result in 0.0 ...

And found that the normals pointed in the wrong direction.. also, the distance had the wrong sign :)

that explains why it culled about every object! :)

// Left clipping plane
m_frustumPlanes[0].m_normal.x = -(matComb._14 + matComb._11);
m_frustumPlanes[0].m_normal.y = -(matComb._24 + matComb._21);
m_frustumPlanes[0].m_normal.z = -(matComb._34 + matComb._31);
m_frustumPlanes[0].m_distance = -(matComb._44 + matComb._41);

note the -( ... )


So it seemes to work!! .. great!..

Now I have to do some serious vertex shading transformations to speed up to drawing of up to 7000 objects per frame :9

Thx for your replies

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!