Sign in to follow this  
ehmdjii

how to depth sort a bsp

Recommended Posts

hello, i hear a lot that a bsp tree is the best choice for a datastructure for a scenegraph implementation (is this still true?), mainly because it is pretty easy to do depth-sorting. now how is depth-sorting done in a bsp-tree. no real code please ;) just the algorithm, described in some words. thanks a lot! PS: is depth-sorting still a must, to do correct alpha-testing, or are there other methods?

Share this post


Link to post
Share on other sites
For alpha, depth sorting is a must (if you want pixel-perfect blending).

Binary space partition tree is pretty simple. As the name includes, there is always "two spaces" : the front and the back (or left and right). As you know the every bsp node is defined by a plane so it is easy to find out which triangles are in front of the plane and which are on the back side.

In order to get the correct sorting information from BSP you'll need to know the location of the camera.

By evaluating the BSP tree recursively you can produce the correct drawing order.

The logic goes something like this:

For each node you must find out an answer to a question

"which side of the tree must I render first?"

So if you camera is in front of the node plane, logically, first you'll need to draw the nodes behind the current node. Then the node itself and then the other side.

So :

If this node has no front or back nodes, draw this and return.

If camera is in front of the node, then draw the nodes behind, then the current node, and then the nodes in front.

Else if camera is behind of the node, draw the nodes in front of the node, then the current node and then the nodes in behind.


--

I hope I got it right. It's been a while that I did any BSP stuff.

I am 100% sure that BSP isn't the most efficient way of drawing things. It works best with lowpoly stuff, and perhaps shouldn't be applied anywhere else than arranging translucent objects.

Best regards

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this