# 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.

## 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 on other sites

Hi there.

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.

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.

-MIGI0027

Edited by Migi0027

##### 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 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 ?

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 13
• 9
• 9
• 15
• ### Forum Statistics

• Total Topics
634078
• Total Posts
3015370
×