Advertisement Jump to content
Sign in to follow this  
noatom

Why do frustum culling in world space?

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

Some people suggested to do the culling in world space,but i don't understand a thing.

 

Say you load a car model,and you want to create an AABB. There is a problem,because the car will ALWAYS be in model space,since its vertices get in world space only when they are in the gpu pipeline(hence setting the world matrix for each mesh).

 

Another problem... if you do the culling in model space: say you make the car's size 5x bigger,and that normally,the car wouldn't fit in the current frustum,but since its 5x bigger,it now does. But,since the worldmatrix(and the scaling),is applied to the mesh ONLY in the gpu pipeline,you will create an AABB for the normal car(not 5x bigger),and the car will be reject for drawing!

 

Could someone explain how everything should be handled?

 

Share this post


Link to post
Share on other sites
Advertisement

Hi there. smile.png

 

Why do the culling in world space? Well first of all you usually don't check if the mesh (all vertices...) are in the frustrum, instead what is normally done is that either a bounding sphere or a bounding box is created for the mesh, with origin and radius/bounds.

 

vfboxsphere.gif

 

A simple algo for a bounding sphere: (PS. Bugs might be present, please say if they are )

Vector3 center(0,0,0);
float r = 0;

for all vertices
{
    center += vertices[i].pos;
}

center /= vertices.size();
center += meshPosition.xyz;

for all vertices
{
    float length = getLength(vertices[i].pos, center);

    if (r < length) r = length
}

// Plus do some extra calculations for when scaling

Then you'd check if the frustum collides with (example) this bounding sphere, if it does, render it! If not, then don't.

 

EDIT: And if your mesh is translated then simply recalculate the origin, and if scaled, change the radius (optimizations can be made)

 

Hope this might prove useful. smile.png

-MIGI0027

Edited by Migi0027

Share this post


Link to post
Share on other sites

"And if your mesh is translated then simply recalculate the origin, and if scaled, change the radius (optimizations can be made)" that's the answer.

Share this post


Link to post
Share on other sites

The same model matrix used to transform the vertices on the GPU side is the same model matrix that should be used to transform the model bounding box. This matrix is already available CPU side. There is not stipulation that the matrix used to transform the model vertices in the vertex shader can only be use for that purpose. Its uploaded as a vertex shader input for that reason, but if its available why not use it ?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!