Frustum culling using a KD-tree

Started by
3 comments, last by french_hustler 10 years, 10 months ago

Hello all,

I just finished a ray-tracing class and have become more familiar with kd-trees. We used a kd-tree to acquire the nearest neighbours for a photon mapping technique. I have read from many places that a kd-tree can be used for frustum culling and am trying to understand how this is done.

Say I use a kd-tree implementation similar to the ANN library (http://www.cs.umd.edu/~mount/ANN/). With such library, you provide it your points and you can query for the N nearest neighbours about a specific point or do a search for the neigbours within a radius at a specific point. The thing is, how is such a structure useful for frustum culling? The KD-tree stores points and can acquire nearest neighbours.... To do frustum culling, wouldn't you have to store AABB bounds with each node of the tree and do some sort of intersection with the frustum while traversing the tree structure? Wouldn't that step away from the purpose of a kd-tree which is to efficiently acquire near neighbors for a given data set of k dimensions?

ANN uses "indices" to a vector of points. So technically, I could somehow store AABB's in another vector with respective indices and pass the center point of each AABB to create the kd-tree. But I still fail to see how that would help.... I'm assuming that the traversal logic would have to be much different than for looking for nearest neighbors.

I'm not sure if the above makes any sense, but in the end, I'd appreciate if someone could point me in the right direction to understand how a kd-tree can help with frustum culling.

Thank you.

Advertisement

To do frustum culling, wouldn't you have to store AABB bounds with each node of the tree and do some sort of intersection with the frustum while traversing the tree structure?

Are the trees in the ANN library in some way different from basic kd-trees? Otherwise keeping track of nodes'/cells' AABBs shouldn't be too hard. You can test those boxes directly against the frustum using basic frustum culling methods. For example a box can be clipped whenever all its corners/vertices fall outside one of the frustum's faces. (transform points into projection space and test against w, or do a halfspace test against the six faces of the frustum.) The same for the individual points stored in the tree.

If you don't know the AABBs you can cull one side of a split whenever all the eight corners of the frustum fall on the opposite side of the split's hyperplane.

Hey, thanks for the reply. I am still confused angry.png .

Say I build the kd-tree from scratch. I have N entities each with their own AABB bound. Would I construct the kd-tree using the position of the entities? Or should each point of the bounding boxes be used? To me, a BVH makes much more sense for frustum culling as the nodes represent an AABB. Same goes for structures like octrees for example. Each node represents an "area" in space. With a kd-tree a node represents a split in one dimension.

My take on it is that there are two "types" of kd-trees, one which stores points and another which stores volumes (AABB's, probably). On the former, you do nearest-neighbour searches (kNN search) and on the latter, you do ray-AABB traversals (which probably become ray-triangle queries). You've grasped the first type.

Now the second type uses splits in three dimensions, but the meaning is different from just storing a point, it instead says "in this node, there are no AABB's left (or right) of this split in the given dimension". What this means is that in your traversal code, you only need to examine at most one side of the split.

Take a look at http://www.flipcode.com/archives/Raytracing_Topics_Techniques-Part_7_Kd-Trees_and_More_Speed.shtml which I found is a decent introduction.

Dunno how that would be useful for frustum culling, though. kd-trees are generally used with raytracers which implicitly do not require frustum culling.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Makes more sense... Thank you Bacterius.

This topic is closed to new replies.

Advertisement