For this assignment, you must implement a program that will render spheres using ray tracing. Your input will be a text file containing information about the view, lighting parameters, and objects in the scene. Your output should be an image file in any of the standard formats recognized by ImageMagick. For output, you can either use the ImageMagick libraries used in earlier assignments, or write simple PPM files directly.
Like other input files in this class, empty lines or lines beginning with # should be ignored. The remaining lines of the input file appears in three sections. First is a view specification, consisting of a line giving the camera position (x y z), center of interest (x y z), the view up vector (x y z) and the hither and yon clipping values (hither yon). You may assume a 90 degree perspective view.
The next section is the lighting specification. The first line gives the ambient light intensity and the number of point lights (intensity numlights). For each point light, there is one line giving the light intensity and position (intensity x y z). All lights are white, and specified by intensity only.
The final section gives all of the geometry. For the base assignment, this consists only of spheres. Each sphere is described by one line starting with the word 'sphere', then giving the sphere center, sphere radius, color, diffuse/ambient coefficient, specular coefficient and specular exponent (sphere x y z radius r g b kd ks e).
An input file is provided in ~olano/public/435/assn7/spheres.sph
If you choose to use a PPM format for output, see the man page for 'ppm' for details. The following outlines the code to write a simple PPM file:
unsigned char pixels[HEIGHT][WIDTH];
/* fill in pixel array */
/* to set the red component of pixel x,y to .5, use pixels[y][x] = 255*.5 */
FILE *f = fopen("file.ppm","wb");
fprintf(f, "P6 %d %d %d\n", WIDTH, HEIGHT, 255);
fwrite(pixels, 1, HEIGHT*WIDTH*3, f);
You can use the "convert" program to convert ppm files into most other formats.
For extra credit, implement reflections, refraction, shadows, super-sampled anti-aliasing, or polygon primitives. Each of these features would be worth an additional 10 points. In order to do these, you'll need to modify the file formats. For reflections and refractions, you'll need a coefficient for each primitive. Add these optional coefficients after the specular exponent in the sphere specification. Use a command line argument for super-sampled anti-aliasing (-a #samples) with a default number of samples of one. For polygons, use the polygon format from before with the keyword "polygon" before the number of vertices, extended with ka, kd, ks and e.
This is a big assignment. Start early, or you will probably not finish.
As before, I recommend laying out a plan of attack before coding. It is also worthwhile to get image output working early. Outputting values other than colors at each pixel can be a valuable debugging tool. To assist in your planning, here is an outline of the steps your ray tracing program will need to do:
Turn in this assignment electronically as 'cs435 Proj7' (or after the due date as Proj7late) using the submit mechanism:
submit cs435 Proj7 [files...]
The usual assignment boilerplate applies as always -- submit all files you've created or modified; we must be able to build and run on the GL systems to grade, if you develop elsewhere leave sufficient time to port back; comments are your friend and ours, they're a good idea and they can improve your grade. In either case, you should all files that you created or modified.