CPSC 1020.004 Computer Science II

CPSC 1020.004
Computer Science II
Assigned: Apr. 1, 2015
Due: 11:59pm, Thurs., Apr. 21, 2015
Programming Assignment 05 - C++ Diffuse (and more) Raytracer
(Grading: 7% of total grade)
For this program, the ONLY authorized source of assistance is the instructor or the lab instructors
(not your friends, your friends’ friends, your parents, your parents’ friends, or anyone else).
Overview
This assignment has two major parts: (1) Complete the diffuse illumination raytracer in C++ and
(2) Extend this raytracer to include new features of your choice.
Part 1: Diffuse Illumination
For this assignment, you will augment your ambient raytracer to also work with diffuse illumination.
This will still be a hybrid of C/C++, although any new classes that you implement should be
in C++. However, should reuse your main.c, and in particular your image.c, rayfuns.c, and
raytrace.c will still be C files. You are welcome to incorporate your new C++ vector class that
you’ve worked on in the labs, but this change is not required. To get started:
• Create a new directory called prog05:
$> mkdir prog05
• Change directories into the new one you just created:
$> cd prog05
• Copy the files from my webpage. You can either do this from a browser, or try using curl:
$> curl -O http://people.cs.clemson.edu/~levinej/courses/1020/progs/prog05.part1.tar.gz
Untar this file (tar xvzf prog05.part1.tar.gz). You should see a list the seven scene files,
with associated log and sample ppm images.
• After that, copy the appropriate .cpp, .c, and .h files from your past assignments and/or
labs. You should also use the same makefile which generates an executable called ray.
You will complete the following tasks for this assignment:
1. Create light.cpp based on the declaration in ray.h. First, implement the light t constructor
as well as light t::printer() and light list print(). You might want to take advantage of
the parser for loading the light in the constructor, but you could also implement this differently.
Implement all accessor functions for light t as well.
2. Modify your model.cpp to support initializing lights (in the constructor), reading lights from
scene files (in model load entities()), and printing lists (by calling light list print() in
model t::print()).
3. After completing these two steps, stop and debug. You want to ensure that for the test files we’ve
provided you are correctly reading all entities, including the lights. Note that your material.cpp
code should already support loading diffuse colors—you should not have had to make modifications.
4. Modify raytrace.c to by adding the add illumination() function as described in the notes.
5. Modify image.c, making any necessary changes to ray trace() so that it calls add illumination()
and correctly handles the diffuse coloring of pixels.
CPSC 1020.004, Computer Science II, Joshua A. Levine (1 of 4)
6. Modify light.cpp to implement light t::illuminate().
7. Test all on of the seven scenes, start with scene 1.
It is very likely you will need to have optional debug code that will allow you to print:
• the vector from the hitpoint to the light
• the cosine of the angle
• the distance from the hitpoint to the light
• the diffuse reflectivity of the material
• the occlusion data, such as:
#ifdef DBG_OCCLUDE
fprintf(stderr, "%-10s occ by %-10s at (%4.1lf, %4.1lf, %4.1lf)
(%4.1lf, %4.1lf, %4.1f \n",
light->name, obj->objname,
hitobj->last_hit[0], hitobj->last_hit[1], hitobj->last_hit[2],
obj->last_hit[0], obj->last_hit[1], obj->last_hit[2]);
#endif
Once you feel confident that you have successfully added that functionality, you can move on with
the remainder of this assignment.
Part 2: Extended Raytracer
Within your prog05 directory, we’ll download some additional scenes to test.
• Create a new directory called part2:
$> mkdir part2
• Change directories into the new one you just created:
$> cd part2
• Copy the files from my webpage. You can either do this from a browser, or try using curl:
$> curl -O http://people.cs.clemson.edu/~levinej/courses/1020/progs/prog05.part2.tar.gz
Untar this file (tar xvzf prog05.part2.tar.gz). You should see a list the many subdirectories, each of which contains additional scene files, with associated log and sample ppm
images:
aa
images
spec
tplane
fplane
proj
spotlight
trans
glint
revsurf
texplane
Your task is to select some of these new features to support, and, using the notes, implement the
necessary components to support them. Your ray.h should already include the appropriate class
definitions, but you may need to modify them too.
Coding Requirements
For this assignment, you should make sure the follow the programming assignment requirements
outlined in prog01. In addition, I would like you to submit a plaintext file called README. This
file should include your name, your email, and the date. In this file, you should include a description
of what you have coded, and some instructions that show how you compiled and tested it. It must
also provide a description of the features you implemented and any difficulties you encountered.
CPSC 1020.004, Computer Science II, Joshua A. Levine (2 of 4)
Compiling Your Program
Your program should compile correctly when you (or I) enter the command:
$> make
This should make an executable called ray. Be sure to include a target that allows you to run make
clean as well.
Testing Your Program
As in prog04, you should test your program on all seven sample scenes. You are welcome to try
out any other scenes that you’ve previously used as well. Be sure to document which scenes you
tested in your README.
The general form of the command for testing is
$>./ray scene#.txt img#.ppm 2>s#.log
Replacing “#” with the appropriate scene number. Where appropriate, you should also use scene
files in the part2 subdirectory, e.g.:
$>./ray part2/aa/aademo.txt aademo.ppm 2>aademo.log
Grading
Implementing all components in Part 1 will count for 70% of your grade. Including a mymodel.txt
that shows off a new scene of your own design is worth 10% of your grade. Finally, each component
that you correctly implement from Part 2 is worth an additional 5%. The full list of possibilities
includes:
1. Triangles (if you had not already implemented)
2. Procedural planes (if you had not already implemented)
3. Tiled planes (using the new, generalized format with arbitrary orientation)
4. Finite planes
5. Spotlights
6. Specular reflection
7. Specular glints
8. Transparency
9. Anti-aliasing
10. Textured planes
11. Surfaces of revolution
Thus, the maximum possible score on this assignment is above 100%.
CPSC 1020.004, Computer Science II, Joshua A. Levine (3 of 4)
Submission
(Please read all of these instructions carefully.)
Please take extra care to make sure that your homework compiles on the School of Computing’s
Ubuntu Linux cluster—testing on your own home machine, even if it runs the same OS, may not
be sufficient. Instructions are in the syllabus as to how to get an account. Remember:
both a working build script and README must be provided
Consequently, to receive any credit whatsoever this code must compile on the cluster, even if it does
not accomplish all of the tasks of the assignment. You will receive a grade of zero if you submit
code that does not compile.
Submit using the handin procedure online at https://handin.cs.clemson.edu/. You are
welcome to use the commandline interface, but the web interface is sufficient. The assignment
number is prog05.
Finally, since we are using multiple files, please only submit a single file which has aggregated
everything. Including everything needed to build and run the program in a single archive. Be sure
to include your mymodel.txt as well. To tar up all files, while in your prog05 directory type:
$> tar czvf [username] prog05.tar.gz *
where [username] is your Clemson id (please remove the brackets []). For example, mine would be
levinej prog05.tgz. Please make sure you run make clean before generating the .tar.gz file,
so as to remove all extra files that are generated when you compile your code.
CPSC 1020.004, Computer Science II, Joshua A. Levine (4 of 4)