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.89k stars 1.19k forks source link

Bounds3::Intersect returns wrong answer when boxes do not overlap #288

Closed jesperdj closed 4 years ago

jesperdj commented 4 years ago

Paragraph 2.6 about bounding boxes:

The Bounds3::Intersect method calculates the intersection of two bounding boxes by taking the max of the minimums, and the min of the maximums (page 78). Figure 2.9 illustrates it in 2D. The two points are passed to the constructor that takes two points (page 77).

The combination of the Intersect method and the constructor gives the wrong result when the boxes do not overlap.

Look at this example, where we have a red and a blue box that do not overlap. The two circled points are the points that the Intersect method calculates.

pbrt-intersect-bug-1

Now, the constructor shuffles the coordinates around to make sure that pMin.x <= pMax.x && pMin.y <= pMax.y && pMin.z <= pMax.z. Because of this, the end result is that the shaded area is returned as the intersection:

pbrt-intersect-bug-2

Which is incorrect, because this is an area that's outside of both the red and blue box, and is not the intersection.

jesperdj commented 4 years ago

I see this was already fixed in this commit: https://github.com/mmp/pbrt-v3/commit/3d6f3ddf4742b4da836191826b58929a76bd99fe#diff-15e0d60d770e3e10971c974901304ebd