mmp / pbrt-v3

Source code for pbrt, the renderer described in the third edition of "Physically Based Rendering: From Theory To Implementation", by Matt Pharr, Wenzel Jakob, and Greg Humphreys.
http://pbrt.org
BSD 2-Clause "Simplified" License
4.86k stars 1.18k forks source link

A question regarding the stack size during bvh traversal #239

Closed harrytodorov closed 5 years ago

harrytodorov commented 5 years ago

I was reading through the source code to traverse a bvh tree, when I stumbled upon the fixed stack you're using here. Is there an explanation for it?

My intuition is that you bound it to the maximum depth for a bvh tree you could have? When traversing a bvh tree of depth 64 and you reach a leaf node, at most you would have 64 - 1 elements in the stack.

harrytodorov commented 5 years ago

I was reading through the source code to traverse a bvh tree, when I stumbled upon the fixed stack you're using here. Is there an explanation for it?

My intuition is that you bound it to the maximum depth for a bvh tree you could have? When traversing a bvh tree of depth 64 and you reach a leaf node, at most you would have 64 - 1 elements in the stack.

Ok, I've just read the chapter for traversing a kd-tree and you state it there as well. It's bound to the tree's maximum depth. Nevertheless, it would be good for a future pedantic reader to be pointed to this piece of information :)

mmp commented 5 years ago

I've made a note to add a sentence about that in the next edition. Thanks!