Sign in to follow this  

Frustum culling problem

This topic is 4197 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 use sphere tree in my project and now I want to use frustum culling with the spheres. However I got strange results. Half of a scene is invisible though it should appear on the screen. I've already figured out it's a problem of culling algoritm not tree itself. That's how I do frustum calculations:
D3DXMATRIXA16 matVP;
D3DXMatrixMultiply(&matVP, &matView, &matProj);

// Left plane
m_plFrustum[0].a=matVP._14+matVP._11;
m_plFrustum[0].b=matVP._24+matVP._21;
m_plFrustum[0].c=matVP._34+matVP._31;
m_plFrustum[0].d=matVP._44+matVP._41;

// Right
m_plFrustum[1].a=matVP._14-matVP._11;
m_plFrustum[1].b=matVP._24-matVP._21;
m_plFrustum[1].c=matVP._34-matVP._31;
m_plFrustum[1].d=matVP._44-matVP._41;

// Top
m_plFrustum[2].a=matVP._14-matVP._12;
m_plFrustum[2].b=matVP._24-matVP._22;
m_plFrustum[2].c=matVP._34-matVP._32;
m_plFrustum[2].d=matVP._44-matVP._42;

// Bottom
m_plFrustum[3].a=matVP._14+matVP._12;
m_plFrustum[3].b=matVP._24+matVP._22;
m_plFrustum[3].c=matVP._34+matVP._32;
m_plFrustum[3].d=matVP._44+matVP._42;

// Front
m_plFrustum[4].a=matVP._14+matVP._13;
m_plFrustum[4].b=matVP._24+matVP._23;
m_plFrustum[4].c=matVP._34+matVP._33;
m_plFrustum[4].d=matVP._44+matVP._43;

// Back
m_plFrustum[5].a=matVP._14-matVP._13;
m_plFrustum[5].b=matVP._24-matVP._23;
m_plFrustum[5].c=matVP._34-matVP._33;
m_plFrustum[5].d=matVP._44-matVP._43;

// Normalize planes
for(int i=0; i<6; ++i)
	D3DXPlaneNormalize(&m_plFrustum[i], &m_plFrustum[i]);
Having frustum calculated, I perform a visibility test:
float fDistance;			// Calculated distance

// Test against a plane
for(int i=0; i<6; ++i)
{
   fDistance=D3DXPlaneDotCoord(&m_plFrustum[i], &pos);
			
   if(fDistance<-r)
	return VS_OUTSIDE;

   if((float)fabs(fDistance)<r)
	return VS_PARTIAL;
}
pos is sphere's centre position and r is its radius. What's wrong with that?

Share this post


Link to post
Share on other sites
i have a feeling you are creating your planes wrong...or atleast one of them wrong


D3DXMATRIX viewProjection = view * proj;
D3DMATRIX vp = (D3DMATRIX)viewProjection;

//left plane
frustum[0].a = vp._14 + vp._11;
frustum[0].b = vp._24 + vp._21;
frustum[0].c = vp._34 + vp._31;
frustum[0].d = vp._44 + vp._41;

//right plane
frustum[1].a = vp._14 - vp._11;
frustum[1].b = vp._24 - vp._21;
frustum[1].c = vp._34 - vp._31;
frustum[1].d = vp._44 - vp._41;

//top plane
frustum[2].a = vp._14 - vp._12;
frustum[2].b = vp._24 - vp._22;
frustum[2].c = vp._34 - vp._32;
frustum[2].d = vp._44 - vp._42;

//top plane
frustum[3].a = vp._14 + vp._12;
frustum[3].b = vp._24 + vp._22;
frustum[3].c = vp._34 + vp._32;
frustum[3].d = vp._44 + vp._42;

//near plane
frustum[4].a = vp._13;
frustum[4].b = vp._23;
frustum[4].c = vp._33;
frustum[4].d = vp._43;

//far plane
frustum[5].a = vp._14 - vp._13;
frustum[5].b = vp._24 - vp._23;
frustum[5].c = vp._34 - vp._33;
frustum[5].d = vp._44 - vp._43;

for(int i = 0; i &lt; 4; i++)
{
D3DXPlaneNormalize(&frustum[i],&frustum[i]);
}



it looks liek its your near plane....try changing that and if its still messed up let me know

mike

Share this post


Link to post
Share on other sites

This topic is 4197 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this