Jump to content

  • Log In with Google      Sign In   
  • Create Account

Frustum culling using a KD-tree


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 french_hustler   Members   -  Reputation: 384

Like
0Likes
Like

Posted 07 June 2013 - 04:22 PM

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.



Sponsor:

#2 eppo   Crossbones+   -  Reputation: 2621

Like
0Likes
Like

Posted 08 June 2013 - 05:12 AM

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.



#3 french_hustler   Members   -  Reputation: 384

Like
1Likes
Like

Posted 10 June 2013 - 11:03 AM

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.



#4 Bacterius   Crossbones+   -  Reputation: 9282

Like
1Likes
Like

Posted 10 June 2013 - 11:32 PM

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.

Edited by Bacterius, 10 June 2013 - 11:34 PM.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#5 french_hustler   Members   -  Reputation: 384

Like
0Likes
Like

Posted 14 June 2013 - 03:04 PM

Makes more sense... Thank you Bacterius.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS