CSCI 480/580 Lecture 14 - In-Class Problems

Two implementation details stand in the way of a fully-working bounding volume hierarchy (BVH) that uses axis-aligned bounding boxes (AABBs) to accelerate ray-scene intersections. First, we need the ability to construct an axis-aligned bounding box from a given object or collection of objects. Secondly, we need to be able to intersect a ray with an AABB.

An axis-aligned bounding box can be described by its minimum and maximum extent in each dimension \(x\), \(y\), and \(z\). So we might store one in a struct such as

struct AABB
  xmin::Float
  xmax::Float
  ymin::Float
  ymax::Float
  zmin::Float
  zmax::Float
  contained_objects::Array
end

Our first set of tasks is to make sure we can compute an AABB for each type of object that our scenes may contain. In our raytracer, these are spheres and triangles. Since we’ll be packing objects into a hierarchy of AABBs, we’ll also need to know how to compute the AABB of a collection of AABBs.

  1. Write pseudocode to construct an AABB for a sphere:

    function sphere_aabb(center::Vec3, radius::Float64)
    
    end
  2. Write pseudocode to construct an AABB for a triangle:

    function tri_aabb(a::Vec3, b::Vec3, c::Vec3)
    
    end
  3. Write pseudocode to construct an AABB that contains a collection of AABBs. As a reminder, the type Array{AABB}, 1} signifies a 1-dimensional Array of type AABB:

    function aabbs_aabb(objs::Array{AABB, 1})
    
    end

At this point, we can use these primitives to construct a hierarchy of bounding boxes using the procedure described in lecture. Then all we need to do is determine whether ray hits an AABB (in which case we need to check whether it hits each of its contained objects) or misses the AABB (in which case we can prune its entire subtree!

Let’s build up to the 3D case by starting simpler. The observation here is that a an axis-aligned 3D cuboid can be expressed as the intersection of three “slabs”, where a “slab” is the region of space between two parallel (axis-aligned, in this case) planes.

  1. Find the range of \(t\) values for which the 3D ray \(\mathbf{p} + t \mathbf{d}\) sits inside the “slab” between the two planes \(x = x_{\min}\) and \(x = x_{\max}\).
  2. Repeat the prior exercise for corresponding \(y\) and \(z\) slabs. From here, we can observe that the ray passes through the box only if it ever sits inside all three slabs at the same time. Devise a scheme for determining whether the ray intersects the box.
  3. Give an approach for determining the coordinates of the point where the ray enters the box.

If you have time, go ahead and sketch out some pseudocode for bounding volume hierarchy construction:

  1. Given a list of objects, each of which is a Triangle or a Sphere, write pseudocode construct a bounding volume hierarchy. At each level of the tree, divide the objects in half by sorting their position (e.g., the point at their center) along a coordinate axis and create a subtree containing each half of the objects. Cycle through the \(x\), \(y\), and \(z\) axes at subsequent levels of the tree.