Jump to content
  • Advertisement
Sign in to follow this  
Master of Riddles

Frustum culling problem

This topic is 4486 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, &m_plFrustum);
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, &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
Advertisement
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,&frustum);
}



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
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!