Project 3 Help Session
This session is to help you get started with the third project: a raytracer.
Starting the Project
After copying the files from course web page,
the ray trace program can be run by typing double clicking the .dsw
project file and building the project in MSVC. This raytracer reads files
with the .out file extension. Load a scene such as
simple.out and hit the render button to see how the basic program works.
Note that the size of the render window is adjustable. The smaller your
window, the quicker the scene will render. The sphere and box in the scene
should appear as flat disks when rendered, since the routines that compute the
color of each pixel have been gutted for your educational benefit.
Useful Files
This program has quite a few source files associated with it, but don't be
alarmed, because most of your of your work on this project will be
concentrated in only a few files. In fact, all of the required extensions
require modifying only the Shade() function in Raytrace.cpp.
Here are a list of some of the most important of the files:
Raytrace.{cpp,h}
Here's where all the required extensions will be added.
Intersect.{cpp,h}
These routines cast rays and determine intersection points
with various objects. To add a more general type of
refraction, you will need to edit these files.
SceneIO.{cpp,h}
These files define the scene. You shouldn't have to make
changes here.
Shade() Function
The function in which you will implement all the required extensions is the
Shade function in Raytrace.c:
Void
Shade(SceneIO *scene, int level, float weight, Vector3f P, Vector3f N,
Vector3f I, struct IsectType *intersect, Vector3f color,
RTParameters* g_params);
This function calculates the color of an intersection point of a ray that
is cast into the scene.
- scene contains information about the lights and objects
- level indicates the current level of recursion
- weight is a term used with the recursive reflection and
transmission rays
- P is the intersection point with an object
- N is the normal to the surface at the point P
- I is the incident ray from the point P
- intersect contains information about the intersection point
Note: When calculating refraction, prevIndex
indicates the index of refraction in the medium the ray
is coming from and nextIndex the index of refraction
in the medium the ray is entering
- color is the color of the object at the intersection point
which you will be calculating
- g_params is the struct which contains the information for the
recursion.
MaterialIO
The struct MaterialIO contains information about the properties of an
intersection point on an object. The comments following the elements of
the struct contain the symbols used in the Phong shading model presented
in class.
typedef struct MaterialIO
{
Color3f diffColor; /* Diffuse color: kd */
Color3f ambColor; /* Ambient color: ka */
Color3f specColor; /* Specular color: ks */
Color3f emissColor; /* Emissive color- do not need for assignment */
float shininess; /* Shininess: ns */
float ktran; /* Transparency: ktran */
} MaterialIO;
Ray
This struct contains the information about the ray cast by the intersection
routine.
typedef struct Ray
{
Point3f P; /* point of origin of the ray */
Point3f D; /* direction ray is traveling */
} Ray;
RTParameters
This struct contains information used for recursion.
typedef struct RTParameters
{
float rayeps; /* epsilon value for ray intersections */
float minweight; /* min weight to keep tracing a ray -
Note: this may be used to implement one of the whistles */
float maxlevel; /* max number of tracing levels -
Note: max level can be 4 for the basic assignment */
} RTParameters;
Additional Information
- When you are viewing scenes rendered with your solution,
the scenes may appear washed out. Scale the factors
in your code until the ray traced image looks roughly
similar to the sample images given by running the
solutions. (However the images don't have to be an exact match in
color. Just make sure that the shadows, reflections and tranmissions are
falling in the right places).
- For (semi-)transparent surfaces, you should probably multiply
the diffuse and ambient terms by (1-ktran). Otherwise,
the diffuse and transmitted rays will add up and the
surface will become washed out.
- For the basic assignment (without any bells or whistles for
refraction), the refractive index may be set to 1.5.
- For ns, use shininess*128 (where shininess is the scene's
shininess output between 0 and 1.)
- For attenuation of light sources, use the attenuation equation
presented in class with a =.01, b = .1, and c = .25. If
your results don't look satisfactory, feel free to play with
this parameter. Note: Secondary rays (reflected and
transmitted) are not attenuated.
- Happy Raytracing
Send questions or comments about the help session and handouts to Doug
(dougz@cs) or Michael(maucoin@cs).