T1 AABB Box (MS1)

We have learned in semester 1 that hierarchical spatial data structures such as AABB, Octree, Bounding Sphere Volumes can be used to accelerate ray-object intersection. This can be used for picking as well as for ray tracing.

In this tutorial, Professor Shirley used the simplest one - AABB, as we did in semester 1 for picking.

We have learned that for Ray-AABB intersection, we are using the slab algorithm.

Add a new public method expand() for class interval in interval.h

class interval {
  public:
    // ...

    // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    // merge two intervals into one
    interval(const interval& a, const interval& b) {
        // Create the interval tightly enclosing the two input intervals.
        min = a.min <= b.min ? a.min : b.min;
        max = a.max >= b.max ? a.max : b.max;
    }
    // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    
    // ...
    
    // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    interval expand(double delta) const {
        auto padding = delta/2;
        return interval(min - padding, max + padding);
    }
    // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    
    // ...
};

Add a new aabb class for the axis aligned bounding box

create aabb.h and put the following code into it.

The aabb is defined by three intervals along the x, y, z direction.

The most important method, hit(), implemented the slab algorithm.

(t_exit is ray_t.max, t_enter iray_t.min)

Add a bounding_box virtual interface in hittable

Revise sphere.h to add the bounding box

add a bbox private member in class sphere, revise the construtor and add a get method (returning bbox).

Note: Don't use static_center if you skipped motion blur. Please see the following code.

Creating Bounding Box for List of Objects

hittable_list.h

Add a private bbox member for hittable_list.

Revise add() to update the bbox when adding new objects.

Add a get method to return the bbox.

Add a bvh_node class

create bvh.h, write class bvh_node to inherit from the hittable abstract class

add random_int() in rtweekend.h

Revise main.cpp

add bvh. to main.cpp

change the scene to a simple two sphere scene

set the image resolution to a low resolution for fast testing

Build and Run

Build and run you programme, if successful, you are going to see an image similar to the following

Note: I did do Gamma correct so my image may look darker.

Last updated