Saturday, October 1, 2011

From-Scratch Ray Tracer

For my second graphics project I had to write a ray tracer from scratch. I used C++ to do most of the coding with some C spread around. It took a lot of work, especially because I began the project by learning C++ but it turned out excellent. The simple assignment involved ray tracing spheres with diffuse shading only. I also completed the extra credit assignment of tracing arbitrary convex polygons and applying normal interpolation to them (if normals are provided).

 One interesting road-bump I ran into was in shading my spheres. I was getting wacky, psychedelic colors instead of the expected shading.

It turned out the characters I was storing my pixel colors in were overflowing and generating odd color combinations. The cause was my lack of normalizing the vectors in the shading equations. Once I figured this out I was able to get good looking spheres:


Some extra credit images are below. The first is a teapot with smooth shading by normal interpolation. The second is a mountain range with lots of polygons. The mountain took over 10 minutes to render on my school server. All the objects were generated with the spd programs.

No comments:

Post a Comment