Monday, April 16, 2007

Ray Tracer

I am currently working on a ray tracer in my spare time. Eventually, it will create really pretty 3D pictures. But that is still a ways off. Before I get ahead of myself, I decided to undertake this project to keep my skills sharp. A ray tracer is relatively simple, well, at least conceptually. Converting it to a working application is another matter.

I started with a simple blank file named raytrace.cpp. I was determined to do everything from scratch, using no existing libraries. The first task was to create a simple blank image. Sounds easy, and it is. I decided to use the PPM file format, which is a simple pixel map file simile similar to a Windows .bmp file, but the file format is dead simple. I did not save an image from this stage of the application, it was a simple black image, completely unremarkable in every way. :)

Stage two, that is shoot out rays from camera and color object in the scene with an arbitrary color, was a bit more difficult. Being that I am not a graphics programmer, and my last math class was about 5 years ago, I had to relearn the basic concepts of vectors, rays, points, spheres matrix transforms and trig. Once I had the basics after about a week of reading in my spare time, I then had to translate that into code. At this stage the project consists of 14 files and about 350 lines of code, 550 if you include my comments. I finally got this stage kind of working last night at about 4:30 AM. With a single sphere in the scene, the current state of the project is:
The next stages are to add more spheres to the scene and add shading, then I will begin bouncing the rays and adding light sources. Stay tuned...

-Michael

No comments: