Frustum Culling - Does this sound right?
[Copy of a message I posted on the OpenGL.org forums]
Before I go and turn my pages of hand-written notes into code, can anyone comment on this and let me know if I''m on the right track?
I need to test a bounding box against the current view frustum. I don''t need to differentiate between boxes that are *partially* in the frustum and *totally* in the frustum, they can either be rejected completely or they need further processing. Speed is, of course, of the essence.
So... here''s what I''ve come up with. I know how to code all this, I just want to know if it makes sense to you experts.
- I extract the equations for the 6 planes of the frustum from a concatenation of the current projection and modelview matrices. I only do this if/when the "camera" moves.
- Given a bounding box with 8 vertices, I loop through all 6 planes doing the following:
- Loop through the 8 vertices, calculating the distance of the vertex from the plane. A positive distance means it''s in front of the plane (or outside of the frustum) while a negative value means it''s behind the plane (possibly inside the frustum). If I find a vertex that is behind the plane, then I can refrain from testing the remaining vertices (if any) because at least some part of the bounding box is behind the plane.
- If all 8 vertices are in front of any of the six planes, then I can refrain from testing against the remaining planes because it''s totally outside the frustum.
- If, for each plane, at least one vertex is behind the plane, then some portion of the box is visible and it cannot be rejected.
Does this sound about right?
Testing a bounding sphere would be similar, faster in fact, since I only have to test a single point and compare the distance from the plane to the sphere''s radius.
Toom
Yep, this sounds right. I go for the bounding sphere approach. GeForce cards render faster than CPUs can clip ;-)))
Tim--------------------------glvelocity.gamedev.netwww.gamedev.net/hosted/glvelocity
I''m using an octree to partition space, so testing boxes makes more sense for that. But when I get down to the individual objects I''ll likely use spheres.
Toom
Toom
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement