NVIDIAGameWorks / Falcor

Real-Time Rendering Framework
https://developer.nvidia.com/falcor
Other
2.72k stars 497 forks source link

AABB::overlaps false negative for edge cases #435

Open jallmenroeder opened 6 months ago

jallmenroeder commented 6 months ago

The AABB::overlaps function misses overlaps when one of the AABBs is 0 in one dimension. Example:

AABB a(float3(-1, -1, -1), float3(1, 1, 1));
AABB b(float3(-1, -1, 0), float3(1, 1, 0));
assert(a.overlaps(b));

Since the overlaps function relies on the volume of the intersection of the two AABBs, which is 0 in this case, the assert fails. This can happen in practice, if you have an axis aligned triangle, create its AABB and use it to "early out" of an intersection test.

One solution could be to only check if the intersection AABB is valid.

/// Returns true if the two AABBs have any overlap.
bool overlaps(AABB b)
{
    b.intersection(*this);
    return b.valid();
}

However, this would return true for "touching" AABBs. Depending on the definition of "overlaps", this might be a problem.

Would love to hear your thoughts on that.