Finished copying over the base ray tracing algorithm.