🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Help me to understand BVH

Started by
26 comments, last by trsh 4 years, 4 months ago

@Vilem Otte But the longest axis is that in image (horizontal). The middle is also marked. The problem is that all centroids are on left half (one by a bit). So I don't understand ur solution.

Advertisement

If all centroids are on the left, the average of all those centers is on the left too so some end up right of that..

The point is to take the average of all centroids, not the center of the single bound.

@JoeJ Could you briefly explain SAH?

@JoeJ

JoeJ said:

If all centroids are on the left, the average of all those centers is on the left too so some end up right of that..

The point is to take the average of all centroids, not the center of the single bound.

I dont get your point here. Could you illustrate or show some math?

The math is simply: sum of all orange centers / number of objects

This will create a number at the drawn red line and divide the objects into two groups.

Notice, even if you use only the center of the bounding box, you could still successfully subdivide by putting any 2 bodies on the left and the other two on the right, until a required maximum of bodies per leaf node remains.

SAH = surface area heuristic, tries to minimize the surface area of the bounding boxes. That's good for RT. For a point search or range query minimizing the volume of boxes might work better.
Algorithm is: Sort along longest axis, partition in two halfs, test if putting the dividing object on left / right side improves the heuristic, and continue moving the split until no more improvement can be found.

But those things have high cost on tree building and may not be worth it for dynamic scenes.

Alright … Now, this is going to be a bit image heavy now (but the illustrations might help you out a bit):

Fig. 01 - Your Scene

You start off with a scene.

Fig. 02- Red is axis-aligned bounding box of the scene

Your scene with AABB.

Fig. 03 - Bounding boxes for each primitive in the scene

Then you generate AABBs for each primitive in your scene.

Fig. 04 - Centroid bounds for each primitive

Calculate centroid positions for your primitives.

Fig. 05 - Depending on splitting heuristics calculate proper split position, in this case it is split in the middle of longest axis. It is basically center of the centroids on given axis - this way it is guaranteed we will split some to the left and some to the right (unless we have degenerate triangles)

Fig. 06 - Splitting plane

And build both child nodes:

Fig. 07 - Pink is first child, Yellow is second child. In BVH child nodes can overlap.

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

Thanks guys!

This topic is closed to new replies.

Advertisement