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.87k stars 1.18k forks source link

An implementation question regarding the construction of a BVH #232

Closed harrytodorov closed 5 years ago

harrytodorov commented 5 years ago

Going through the building of a BVH, I stumbled upon this line, which was a bit unclear for me. Why would you use a for-loop just add 1 element?

mmp commented 5 years ago

Normally, you wouldn't. :-)

In this case it's an artifact of pbrt being a literate program; this code fragment is reused in both places leaf nodes are created (the one-primitive case and in the multi-primitive cases.) That way, we don't have to repeatedly implement the little bit of functionality to grab the primitive number, index into the primitives array, etc...