Jump to content
  • Advertisement
Sign in to follow this  
Milleniumas

Frustum Culling, need help !

This topic is 4264 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 have encountered with a problem of frustum culling. I have created frustum culling and AABB checking if it's in the plane. But the problem is, that it checks only the first Object, and other are auto not renderring. Well the code speaks itself. The cull is a boolean and it return true or false; for(int i = 0; i<3; i++) { if(Camera->cull(Model->minBounds,Model->maxBounds)) { Model->Render(); } else { font->DrawTextA(NULL,"Culling",7,&rect,DT_WORDBREAK,D3DCOLOR_RGBA(255,0,0,255)); } }

Share this post


Link to post
Share on other sites
Advertisement
How do you know the others aren't rendering? If you take out the call to Camera->Cull() do all the objects render? Is the single object that renders the first object in the list? Is it the only one intersecting a frustum plane, or not intersecting any plane? Can we see your cull() function implementation? Are the minBounds and maxBounds valid? Have you tried outputing them to the debug output via OutputDebugString() or through some logging function? Can you tell if the "Culling" text is drawn 3 times? As it is, it'll all be drawn in the same place, so you won't be able to see if there's one string there or more. Could there be any problem with the Render() function for the other 2 models? Are they set up correctly?

It's impossible to tell without more information...

Share this post


Link to post
Share on other sites
I can see that the others are not rendering. If The first box is outside the frustum then the others are not rendering. Object rendering is correct if I render whitout frustum. Maybe it's becouse the cull, couse when the first box outside, then it return false for all other.

void ModelX::Render()
{
p_lpd3d9->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW);
SetPosition(Position);

for(DWORD i = 0; i<numMaterials; i++)
{
p_lpd3d9->SetMaterial(&MaterialList);
p_lpd3d9->SetTexture(0,TextureList);
OptModel->DrawSubset(i);
}

p_lpd3d9->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);
BBox->DrawSubset(0);
p_lpd3d9->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
p_lpd3d9->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
}



bool Camera::cull(const D3DXVECTOR3 &aabbMin, const D3DXVECTOR3 &aabbMax)
{
for(int i=0; i<6; i++)
{
if(m_FrustrumPlane.m_normal.x*aabbMin.x + m_FrustrumPlane.m_normal.y*aabbMin.y + m_FrustrumPlane.m_normal.z*aabbMin.z + m_FrustrumPlane.m_distance >= 0) continue;
if(m_FrustrumPlane.m_normal.x*aabbMax.x + m_FrustrumPlane.m_normal.y*aabbMin.y + m_FrustrumPlane.m_normal.z*aabbMin.z + m_FrustrumPlane.m_distance >= 0) continue;
if(m_FrustrumPlane.m_normal.x*aabbMin.x + m_FrustrumPlane.m_normal.y*aabbMax.y + m_FrustrumPlane.m_normal.z*aabbMin.z + m_FrustrumPlane.m_distance >= 0) continue;
if(m_FrustrumPlane.m_normal.x*aabbMax.x + m_FrustrumPlane.m_normal.y*aabbMax.y + m_FrustrumPlane.m_normal.z*aabbMin.z + m_FrustrumPlane.m_distance >= 0) continue;
if(m_FrustrumPlane.m_normal.x*aabbMin.x + m_FrustrumPlane.m_normal.y*aabbMin.y + m_FrustrumPlane.m_normal.z*aabbMax.z + m_FrustrumPlane.m_distance >= 0) continue;
if(m_FrustrumPlane.m_normal.x*aabbMax.x + m_FrustrumPlane.m_normal.y*aabbMin.y + m_FrustrumPlane.m_normal.z*aabbMax.z + m_FrustrumPlane.m_distance >= 0) continue;
if(m_FrustrumPlane.m_normal.x*aabbMin.x + m_FrustrumPlane.m_normal.y*aabbMax.y + m_FrustrumPlane.m_normal.z*aabbMax.z + m_FrustrumPlane.m_distance >= 0) continue;
if(m_FrustrumPlane.m_normal.x*aabbMax.x + m_FrustrumPlane.m_normal.y*aabbMax.y + m_FrustrumPlane.m_normal.z*aabbMax.z + m_FrustrumPlane.m_distance >= 0) continue;
return false;
}

return true;
}

Share this post


Link to post
Share on other sites
1) check if you frustrum planes is correct (normals if normalized and see outside the frustrum)
2) create small test. As i understood Model[0] is rendered but Model[1] and Model[2] are not. So change Model[0] and Model[1] and try again.

Share this post


Link to post
Share on other sites
I think It checks only the first object in the list for frustum. If the first object is outside the frustum then it is not rendering the first object and so do two others. However if first object is inside the frustum then all three objects are rendered. Maybe I am not checking the objects frustum correctly? Any ideas how to solve?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!