KD Tree delima!!!
#21
Posted 15 July 2012 - 06:12 PM
Actually you can speed up SAH Kd-tree builder with few tricks, and it can even generate trees in realtime - like adding threading support and pre-sorting bounding edges, and so on... for me optimizing it further is mostly "try & fail" with profiler.
Though if you really need more speed, you can use idea of "Binned SAH building" that is used in BVHs or BIHs and adapt it to Kd-trees - I haven't tried it yet at Kd-trees (only at BVHs and QBVHs), but there is paper from Saarland http://graphics.cg.u...-GPU-kdTree.pdf describing a bit about Binning SAH Kd-tree building (on Gpu - but actually Gpu and Cpu doesn't differ that much and I think that getting idea from this is not that hard)
So there is actually quite huge research how to find best splitting plane. Anyway if you're not targeting ray tracing - but physics, consider median splitting instead of SAH - it's almost instant to build (especially with pre-sorting the primitives), because it actually splits geometry to two halves, which might be better suited for physics (and maybe even for frustum testing - but one would need to profile this).
If you don't know how to speed up application, go "roarrrrrr!", hit the compiler with the club and use -O3 :D
#22
Posted 15 July 2012 - 08:12 PM
#23
Posted 15 July 2012 - 09:45 PM
Kd-trees are winning a lot when you're tracing random rays through hierarchy (e.g. path tracing) or generally incoherent rays... on the other hand they're losing a bit when testing against packets (because they're not well suited for packet tracing), although note that packet tracing is definitely not a way to go...
BVHs are quite good for coherent rays (but they're winning by just a few percents over decent Kd-trees), and overally their tree quality is worse (because doing full SAH on them is way slower than doing it on Kd-trees).
So actually Kd-trees produce better quality trees well suited for incoherent rays, random rays and good for packets (they're losing just a little).
BIHs are a mix between Kd-trees and BVH - you build them as BVH thus getting faster build times, but traversing them as packet-friendly Kd-trees - thus being very good for ray packets. On the other hand BIHs are outperformed by Kd-trees when your rays are a bit incoherent (they're losing even with reflective surfaces, not even mentioning path tracing).
What is quite a concurrent for Kd-trees is actually QBVH - tetrary BVH. It gives quite good results even for incoherent rays, they're a lot faster to build (although they're still just approximating SAH with binning - we can do the same for Kd-trees and they're not winning that much in building times).
So it really depends - even basic grid or nested grid is usable acceleration structure ... somewhere. Actually SAH Kd-trees have one huge advantage - they give very good quality for almost any kind of scene (where BVH or QBVH dies on long thin triangles - Kd-trees can handle them, even triangle fans can be handled when giving correct numbers to SAH computation).
If you don't know how to speed up application, go "roarrrrrr!", hit the compiler with the club and use -O3 :D
#24
Posted 15 July 2012 - 10:21 PM
#25
Posted 23 July 2012 - 11:49 PM
#26
Posted 24 July 2012 - 12:34 AM
#27
Posted 24 July 2012 - 01:30 AM
MaxDepth = int(8 + 1.3 * log2(PolyCount));
and for the min poly per leaf I use...
log2(PolyCount)
So for a 900k poly, it gives me a depth of about 33 and 19 or so poly min per leaf. Is that too much you think?
#28
Posted 24 July 2012 - 03:41 AM
For 900K triangles with 20 triangles per leaf node, that's 45K leaf nodes, so 90K nodes altogether. At 8 bytes per node, that's only ~700KB of memory. Hmm...did you by any chance confuse 700KB for 700MB?
#29
Posted 24 July 2012 - 04:04 AM
I just loaded a 310,000 poly model, and that created 211,881 nodes and that took about 300MB (not KB).
#30
Posted 24 July 2012 - 05:56 AM
#31
Posted 24 July 2012 - 12:08 PM
#32
Posted 24 July 2012 - 05:01 PM
I'm not asking you because I want to play a guessing game; you should instrument your code and find out where the memory is going!
#33
Posted 24 July 2012 - 08:57 PM
Sample scene - Sponza Atrium
One of the worst scenes for either Kd-trees or BVHs, so you'll get really bad trees (plenty of useless nodes) for it! Although this is actually the point why we test on it. I strongly recommend trying Sponza...
Ray tracer - old GPU ray tracer, mono-tracing in OpenCL application, no actual optimization (just for general testing of tree quality) - e.g. simple ray tracing algorithm. So this one is just brain-dead simple implementation of ray tracer. Wald triangles used, I think...
Total Triangle Count - 67462 tris
Criteria: SAH Splitting, Primitive criteria = 64, Sah intersect cost = 80, Sah traversal cost = 1, Sah empty bonus = 0.5
Created 6081 nodes
Size of nodes = 48648 bytes (less than 50 KiB)
Size of all Kd-tree data = 512696 bytes (0.5 MiB)
Building done in 906 ms (1 core building algorithm posted here)
Average performance = 6.32 MRays/s
Criteria: SAH Splitting, Primitive criteria = 16 (e.g. if there is 16 or less triangles, create node), Sah intersect cost = 80, Sah traversal cost = 1, Sah empty bonus = 0.5
Created 114775 nodes
Size of nodes = 918200 bytes (e.g. less than 1 MiB)
Size of all Kd-tree data = 3606472 bytes (e.g. a bit more than 3 MiB)
Building done in 1401 ms (1 core building algorithm posted here)
Average performance = 7.46 MRays/s
Criteria: SAH Splitting, Primitive criteria = 4, Sah intersect cost = 80, Sah traversal cost = 1, Sah empty bonus = 0.5
Created 5626177 nodes
Size of all nodes = 45009416 bytes (e.g. 45 MiB)
Size of all Kd-tree data = 112243156 bytes (e.g.112 MiB)
Building done in 6848 ms (1 core building algorithm posted here)
Average performance = 3.72 MRays/s
If you don't know how to speed up application, go "roarrrrrr!", hit the compiler with the club and use -O3 :D
#34
Posted 24 July 2012 - 09:22 PM
#35
Posted 24 July 2012 - 10:22 PM
#36
Posted 24 July 2012 - 10:29 PM
227,500 triangles
depth = 18
min tri per node = 31
30MB total size for the tree
Seems to work fine for the Sponza, but on others, it just doesn't. at all.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












