This assignment will build your assignment 2 ray tracing code (or mine, if your's was not working) adding a kd-tree acceleration structure to make the ray tracing faster.
A kd-tree is a BSP tree where all of the planes are axis-aligned, so each split is either along the X axis, Y axis, or Z axis. At each node in the tree, any object that intersects the splitting plane for that node will be stored in the node (not divided in two, as we did with the polygonal BSP). Any object entirely on the negative side of the plane will be in the left subtree. Any object entirely on the positive side of the plane will be in the right subtree.
With axis aligned planes, you don't need to use dot products to compute point-plane distances, you can just subtract the x, y, or z coordinates. For example, for a sphere of radius r with center (xc, yc, zc) and an X splitting plane through x=xp, you can tell if a sphere intersects a plane if abs(xc-xp) < r. If the distance is greater than the radius, then the sign of xc-xp tells you which subtree to use.
Unless you are doing the extra credit, use a longest-axis splitting heuristic. For all primitives in a node, find the minimum and maximum x, y, and z, and split in half along the axis with the greatest range. For spheres, these ranges are:
During ray traversal, start by testing any object in the root, then the child containing the ray start point, then its child, until you have tested objects all the way down to the leaf containing the ray origin. If you have found an intersection in that node, stop. If not, find the next leaf node the ray will enter, being sure to test any untested objects in parents of that leaf node. Continue until you find an intersection or leave the root. This will save time both by only testing leaf cells along the path of the ray, not ones the ray cannot hit. Also, as soon as you find an intersection in the region contained in a leaf node, you can stop, without having to test additional intersections along the path of the ray.
Students taking this class as CMSC 435 need only handle spheres (ignore any non-sphere objects). Students taking the class as CMSC 634 should handle cones as well.
For up to 20 points of extra credit, use the Surface Area Heuristic for tree construction instead of the longest axis heuristic. For the surface area heuristic, you consider each node to bound a rectangular volume of space. The root node bounds a volume given by the minimum and maximum x, y, and z of all of the objects. At each possible split, you choose the one with the minimum cost, with a cost function that counts the objects that cross the splitting plane plus a fraction of the objects in each subtree, weighted by the ratio of the surface area nodes:
For split plane location, consider the extreme points of each object (e.g. x-r or x+r of each sphere in the node for splits in the x direction)
What to turn in
Turn in this assignment electronically by pushing your source code to your class git repository by 11:59 PM on the day of the deadline and tagging the commit
assn6. Do your development in the
trace directory, continuing to modify the code there. It is not necessary to make a copy, we will use your git tag to grade the right version.
Also include an
assn6.txt file telling us about your assignment. Include your name and campus ID at the top of this file. Do not forget to tell us what (if any) help you received from books, web sites or people other than the instructor and TA.
Check in along the way with useful checkin messages. We will be looking at your development process, so a complete and perfectly working assignment submitted in a single checkin one minute before the deadline will NOT get full credit. Individual checkins of complete files one at a time just before the deadline will also NOT get full credit. Do be sure to check in all of your source code, CMakeLists.txt, and updated .gitignore file, but no build files, log files, generated images, zip files, libraries, or other non-code content.