 |
Lab 1: Building a Recursive Ray Tracer
CS 445: Computer Graphics,
Fall 2012
|
Due Dates:
- Part 1: 5pm, Tuesday, Sept 11
- Part 2: 5pm, Tuesday, Sept 18
- Part 3: 5pm, Tuesday, Sept 25
Goals
- To understand recursive ray tracing.
- To learn the basic components of a graphics system.
- To understand the phong lighting model.
Summary Description
In this lab, you are to implement a simple ray tracer
based on the discussion in class.
- Week 1: It should be able to display several sphere objects which are flat shaded.
- Week 2: It uses the Phong lighting.
- Week 3: It implements shadows.
- Week 3: It implements reflections (using recursion).
- Week 3: It should contain at least 2 types of objects in addition to spheres (planes, cylinders, cones, etc.)
- Week 3: It should be able to rotate and move the camera.
- (Optional) It should have procedural and/or image based Textures
Resources
Part 1: Due Sept 11
This week, you are just get the main algorithm working. A sphere is already included. Shading
will be ignored.
- Download the skeleton code here. It should run but will display a black window.
- In class, we will carefull go over the code. Make sure you understand what each class does before you
continue. A summary of the classes can be found here.
- Do the following:
- Add a Camera class. Camera.h is already provided. You need to add Camera.cpp. Assume the image is stored as
a 1D array of GLFloat elements.
- Complete the implementation of the two functions in RenderEngin.cpp: render_scene and trace_ray.
The resulting image should look something like:
Part 1
Demonstrate your program in lab no later 5pm on Tues, Sept 11. No need to turn anything in (yet).
This week, you are to get the shading implemented. Do the following:
- Complete the Material class so that it includes reflection coefficients (ka, kd, ks),
colors (ambient, diffuse, specular), and specularity (for specular component). The methods
to include are constructors, destructor, assignment operator, setters/getters.
- Add a PointLight class which includes a color, location, and intensity. The methods
to include are constructors, destructor, assignment operator, setters/getters. In addition,
it is useful to have a method that calculates the direction from hit point to this light, where
the hit point is passed in as a parameter.
- In the build method in World, you will need to add PointLights to the scene and also add Materials to the shapes. You also need
to make sure that the ShadeRec object that is passed back from the shape's hit method, includes a link to the shape's shader.
- Modify RenderEngine::trace_ray and RenderEngine::calc_shade to determine the Phong lighting equation for the closest hit point.
The resulting image should look something like:
Part 2: Basic Phong Lighting
Demonstrate your program in lab no later 5pm on Tues, Sept 18. No need to turn anything in (yet).
This week, you should:
- Make sure that the CalcUVN method works in the Camera class. Use it to change the orientation of the camera. Also
try moving the location of the camera.
- Add several more objects such as a plane and cylinder. Try different locations and orientations of the objects to make sure
the intersection calculation is working properly.
- Add shadows. To do this, do the following:
- For convenience, add a method to the PointLight class which calculates the shadow ray from hit point to the light.
- add the method:
bool RenderEngine::inShadow(Vector3D hit_point, PointLight* light) // called from calc_shade.
Look at the Ray Trace Notes if you don't remember what this method is supposed to do.
- Once you feel the shadows are implemented properly, move your objects and (multiple) lights around to make
sure that the shadows work under different conditions.
- Add reflections. This is done using recursion in the trace_ray method using the variable "depth" to control the number of
recursions. You will need to calculate the reflected ray at the intersection. Do the following
- Add a reflection coefficient (kr) to the Material class.
- add the method:
RGBColor RenderEngine::calc_reflected(const Ray& ray, ShadeRec& sr, int rayDepth) // called from trace_ray
- Once you feel the reflections are implemented properly, move your objects and lights around to make
sure that the reflections work under different conditions. Change the depth value to get multiple levels of reflections.
The resulting image should look something like:
Part 3: Shadows only |
Shadows and Reflections |
Tilted Camera |
Demonstrate your program in lab no later 5pm on Tues, Sept 25. Generate several images showing the different shapes you have
implemented with shadows and reflections. Include at least 1 image showing that you can move and reorient your camera. Zip these images together with your code and submit via WISE.