mmp / pbrt-v4

Source code to pbrt, the ray tracer described in the forthcoming 4th edition of the "Physically Based Rendering: From Theory to Implementation" book.
https://pbrt.org
Apache License 2.0
2.8k stars 429 forks source link

remove redundant mid calculations in bvh construction #334

Closed SethPyle376 closed 1 year ago

SethPyle376 commented 1 year ago

Mid is pre-calculated to the same value here for a couple of these split methods :)

mmp commented 1 year ago

Ah, this is a tricky one! The first one, in line 254, is necessary since the case statement above it doesn't always break at the end; it may fall through, and when it does, it will have modified mid, so it needs to be re-set.

You are correct about the second one being redundant, but that's an artifact of pbrt's literate program heritage; the code there is reusing the "Partition primitives into equally sized subsets" fragment. So in return for making the book slightly shorter through reusing that fragment, we get a redundancy in the C++ code. I prefer to leave this as is, just to keep the code in sync with the book.

Keep 'em coming if you see anything else fishy though!

SethPyle376 commented 1 year ago

Ah I see, thanks for the explanation!