Lab 1: Building a Ray Tracer
CS 445: Computer Graphics,
Fall 2008
[next lab][schedule]
Reading
- Chp 4: Mathematics for Modeling, pp. 158-167(top)
- Chp 5: Color and Blending, pp. 180-190
- Chp 6: Lighting and Shading, pp. 213-220
- Ray Tracing(Wikipedia)
- Class Handouts
Goals
- To understand recursive ray tracing
- To understand the phong lighting model.
Description
In this lab, you are to implement a simple ray tracer
based on the discussion in class.
It should should have the following properties:
- You should be able to add multiple objects and lights to the scene.
- Phong lighting and shading.
- Include at least 2 types of objects in addition to spheres (planes, cylinders, cones, etc.)
- Shadows
- The code should be modular; the structure should be easy to figure out. Include the
javadoc.
Directions
Week 1 (due Sept 11):
This week, you are just get the main algorithm working. A sphere is already included. Shading
will be ignored.
- You may start from scratch but I recommend that you download the netbeans project RayTracer08lab. This code will run but it
won't create an image. Begin by reviewing class notes so that you know what all of the parameters mean. Don't
begin coding until you do this!
- The only parts of the code you need to implement this week are 4 methods in the RayTracer.java class:
- calcUVN: calculate the eye coordinate basis vectors
- pixelDir: determine the ray that starts at the camera and goes through a given pixel
- trace: the main loop of the algorithm
- getIntersection: find the closest object to the camera that intersects a given ray.
- The resulting image should be:
- Go into the createScene method in RayTracer and try adding a second sphere with a different size
that partly overlaps the first sphere.
Week 2 (due Sept 18):
This week, you are to get the shading implemented. The parts you need to implement are:
- Material.java: calcColor (note, the uv value is ignored (pass in null).) This is the heart the
shading algorithm. Uses the Phong model.
- RayTracer.java: calcColor - Loops over all the lights and adds together the color contribution from each light source
The code is a bit convoluted - the loop will contain the line something like (null refers to the uv coordinates)
Vec3d col = intersection.shape.mat.calcColor(null, light, lightDir, intersection.normal, viewDir);
- Sphere.java: getNormal - this should be easy for a sphere!
- RayTracer.java: createScene - you need to add a material to each sphere, e.g. to add a blue color to
your sphere s1:
s1.setMat(new Material(Color.blue));
- The resulting image should be:
- Go into the createScene method in RayTracer and try adding a second light at a different location (left image below).
Try changing the light color or the material properties such as or ka, kd, ks and n (right image below).
Week 3 (due Sept 25):
This week, you are to add several more objects such as a plane and cylinder. You are also to add shadows.
Extra Credit
For extra credit, you may choose to implement one or more of the following:
- reflection
- refraction
- 2D image textures
Deliverables
You will have approximately 3 weeks to complete the ray tracer. The schedule of deliverables is as follows:
- Thurs Sept 11: Place your jar file on \\home\enfuzion in the folder cs445Fa08\lab1. Add your initials to the file
name so we know the owner. These will be demo-ed during class on the 11th.
- Thurs Sept 18: Place your jar file on \\home\enfuzion in the folder cs445Fa08\lab1. Add your initials to the file
name so we know the owner. These will be demo-ed during class on the 18th.
- Thurs Sept 25: Complete the project:
- Place your jar file on \\home\enfuzion in the folder cs445fa08\lab1. Add your initials to the file
name so we know the owner. These will be demo-ed during class on the 25th.
- Include javadoc for the code you added.
- Zip together entire project folder (minus the dist folder) and email it to
gorr. Include "CS445 Lab 1" in the subject line.
[top] [schedule]
[home]