# how to depth sort a bsp

This topic is 4576 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013710
×