For this assignment, you must implement a program that will render convex polygons using ray casting. You should read your input from stdin. The input is in NFF format, a simple text format containing information about the view and objects in the scene. Your output should be an image file in PPM format.
Sample NFF format scenes can be generated using a set of programs called the 'Standard Procedural Databases'. A copy of these programs may be found in ~olano/public/spd3.13/. While NFF format is relatively simple, it does contain many features we will not be using in this assignment. You should be able to read any NFF format file (some code to do this is included with SPD, which you are free to use or modify), but ignore anything you do not implement. For the basic assignment, you should at least handle the "v" viewing specification, "b" background color, "f" object material specification (just the r g b color part), and "p" or "pp" polygon specification (you may assume convex polygons and ignore the per-vertex normals given with "pp").
Of the SPD programs, nurbtest, sombrero, teapot and tetra produce scenes using only convex polygons. mount includes a few spheres and sample includes a cone, though both are still interesting without them. The remaining programs are not that interesting without at least some portion of the extra credit: gears includes some concave polygons; balls and shells include many spheres; and jacks, lattice and rings include many spheres and cones.
Since these programs produce their output on stdout and your ray caster takes its input on stdin, you can pipe them together:
teapot | raycast
or, using options to the SPD program to yield a simpler model,
teapot -s 1 | raycast
We are using PPM because it is an exceedingly simple format to write. See the man page for 'ppm' for more details than I provide here.
PPM files can be viewed directly or converted to other image formats for viewing. On the GL systems, you can use "display" to view these files or "convert" convert them into most other image formats.
To create a PPM file, first you should store your image in an array of bytes in y/x/color:
unsigned char pixels[HEIGHT][WIDTH];
When filling in this array, remember that it is in y/x order, not the more familiar x/y order. The final index is the color component, with r=0, g=1 and b=2. Color values range from 0 to 255. For example, this would store a floating point color value of .5 into the green component at x,y:
Once you've filled in the pixels array, actually writing the PPM file is quite simple:
FILE *f = fopen("file.ppm","wb"); fprintf(f, "P6\n%d %d\n%d\n", WIDTH, HEIGHT, 255); fwrite(pixels, 1, HEIGHT*WIDTH*3, f); fclose(f);
Implement one or more of: spheres, concave polygons, and/or cones. Including spheres will be worth up to 10 points of extra credit, concave polygons up to 20 points, and cones up to 30 points; resulting in a possible total of 60 points of extra credit for doing all three. Intersections for spheres and convex polygons are covered in the book. Intersections with cones are not, so part of the extra credit will be figuring out the ray/cone intersection.
Include depth of field as described in section 9.11.3 in the book. You will need to specify the number of samples, aperture size and distance to the focal plane. Take these as optional parameters on the command line, using one sample and zero-size aperture if they are not present (that reduces to standard ray casting). Provide some suggested settings in your readme.txt.
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 casting program will need to do:
Turn in this assignment electronically by checking your source code into your Assn4 CVS directory by 11:59 PM on the day of the deadline. We will use a dated checkout for grading, so you will be graded on whatever has been checked in as of 11:59 PM. Be sure to include a Makefile that will build your project when we run 'make', and a readme.txt file telling us about your assignment. What (if any) help did you receive from books, web sites or people other than the instructor and TA? What extra credit features did you add?
Also submit everything we need to run your submission. Double check the output of cvs update after you submit to make sure you have not forgotten any important source files. Submit your Makefile, any headers and C/C++ files, and any other auxiliary files we might need. Be sure to comment your code! You will not be graded on the presence or quality of your comments, but we will look at your code and anything that helps us understand what you did (or were trying to do) can only help. In any case, your programs are expected to be robust and easy to understand.