This is the final homework of Computer Graphics and Animation.
In this homework, based on the ray tracer framework provided by Professor O'Brien, I implemented:
-
ray-surface intersection (triangle surfaces and spheres)
-
Phong shading
-
Shadow
-
Reflection
-
Acceleration data structure (bounding volume hierarchy, using axis-aligned bounding boxes)
The ray tracer takes 3 arguments, 2 required and 1 optional.
Required: a file of Neutral File Format as an input, outputs a file of Portable Pixmap Format.
(e.g. trace input.nff output.ppm)
More information about Neutral File Format can be found at http://www.realtimerendering.com/resources/SPD/NFF.TXT
I used the teapot and the balls as my test cases of shading, shadow, and reflection.
These files can be found at http://www.realtimerendering.com/resources/SPD/
The Bounding Volume Hierarchy reduce the complexity of intersection check from linear to logarithmic. Due to the fact that intersection check is called recursively in the program, the acceleration data structure greatly reduces the rendering time.
Shading + shadow + reflection
Teapot: 433 seconds (before) to 19 seconds (after)
Balls: 975 seconds (before) to 22 seconds (after)
There was a problem that bothered me for a long time when I was implementing the acceleration data structure. My function that constructs a BVH tree did not stop recursion.
It turns out that it is a problem with the Tracer constructor, which is provided in the framework.
Without the commented block of code I added later, the tracer will read the last surface in the input file twice, resulting in two identical surfaces in the scene, and I cannot separate them into different child nodes because they have exactly the same location.
Tracer::Tracer(const std::string &fname) {
std::ifstream in(fname.c_str(), std::ios_base::in);
std::string line;
char ch;
Fill fill;
bool coloredlights = false;
while (in) {
/***************************/
// if (in.eof()) break;
/***************************/
getline(in, line);
} There was a picture rendered not realistically because of an error in calculating reflection, but it was a good-looking one.
This course helped me learned a lot about ray tracing as well as other knowledge of computer graphics.
I will keep working on adding other features in my spare time, such as refraction or filters that can smooth the artifacts when rendering low-poly models.










