For this MP, you will be implementing a basic Ray Tracer. You will be given a scene description consisting of basic objects such as spheres and planes, and you will render this scene using ray tracing. Your final picture will be complete with effects such as shadows, reflections, and specular highlights.
Upon completion of this MP, you should be able to do the following things:
Read Chapter 14, sections 1 through 6, in the required text for this class - ``Computer Graphics, C Version, 2nd Edition'' by Hearn & Baker. It discusses the basic illumination models, shading, and ray tracing.
Before you begin coding, figure out the different parts that make up your ray tracing algorithm. For example, you will have to figure out how to determine intersection with a sphere and a plane, how to calculate a reflection vector, etc.
This is your last MP, and it will take you longer than any of the other MPs in this class. You have about 2-1/2 weeks to do it, and you will probably need all of that time to complete it. If you wait until the last minute to start programming, you will not finish. You have been warned.
You are to write a program that ray traces a scene. Since ray tracing is a slow process, you are required to implement only one input to the program - type ``Q'' to quit. The rest of this section describes the scene, and implementation specifics.
When the user types the letter ``q'' or ``Q'', the program should exit.
The description of the scene you are to render is as follows.
Below is an example of this scene rendered with a basic ray tracing algorithm. Notice the shadows cast by the two spheres, the specular highlights of the light on the spheres, and the reflection of each sphere in the other sphere.
![]() |
You may use any ray tracing method you wish, as long as you implement ambient, diffuse, and specular lighting, shadows, and reflections. Since the scene described above is very specific, you can make your ray tracer specific to this scene only. It does not need to be general to handle other scenes.
One thing you should realize, however, is that there are many ray tracing programs out there on the internet, and we are aware of most of them. If you get caught copying code directly from these programs into your MP, you will receive a zero for the MP.
select the center of projection (eyepoint) and window on view plane; for each scan line in image for each pixel in scan line { determine the ray from the center of projection through the pixel; pixel_color = RayTrace(ray,1); draw pixel_color at current pixel position; } PIXELCOLOR RayTrace(RAYTYPE ray; INT depth) { determine the closest_object_hit by ray; if (hit_object) { compute surface_normal at intersection_point; return RayShade(closest_object_hit, ray, intersection_point, surface_normal, depth); } else return background_color; } PIXELCOLOR RayShade(OBJECT closest_object_hit, RAYTYPE ray, POINTTYPE intersection_point, VECTORTYPE surface_normal, INT depth) { /* local variables */ COLORTYPE color; /* Color of the ray */ RAYTYPE rRay, tRay, sRay; /* Reflected, refracted, and shadow rays */ COLORTYPE rColor, tColor; /* Reflected and refracted ray colors */ color = ambient_color; /* Always add ambient_color component */ sRay = ray to light from intersection_point; if ((surface_normal DOT direction_to_light) > 0) { Check to see if closest_object_hit has no objects between it and the light; if there are no such objects, add the diffuse and specular components to color. } if (depth < MAXDEPTH) { if (object is reflective) { rRay = ray in reflection direction from intersection_point; rColor = RayTrace(rRay, depth+1); scale rColor by reflection coefficient and add to color; } if (object is refractive) { rRay = ray in refraction direction througn intersection_point; rColor = RayTrace(rRay, depth+1); add rColor to color; } } return color; }
Those graduate students enrolled for 1 unit of credit, and undergrad students registered for honors credit, must also implement the following additional functionality.
You must add a third sphere of radius 1.0 to your scene, with its center located at (-2.0,-2.0,1.0). However, this sphere must be made of glass (transparent), with a index of refraction of 1.5. You can make this sphere any color you want, but it must allow light to pass through so you can see objects on the other side.
Below is an example of this scene rendered with a ray tracer. Notice how the image in the glass sphere is upside-down due to refraction.
![]() |
You may treat this sphere as the other spheres when dealing with shadows. In other words, you do not need to worry about the special shadow generated by this third sphere, or how the light penetrates the glass sphere to generate highlights on the square grid. (In the image above, the shadow generated by the glass sphere has been made slightly lighter by handling it as a special case.)
For this final MPs, we will be using the electronic handin program. Once you have completed your program, logon or telnet to one of the Sun Sparc machines (``handin'' does not work on the WindowsNT machines) and hand in your source code by typing ``handin cs318 mp6 mp6.c''. (For more information on handing in your code, consult the class web page at http://www-courses.cs.uiuc.edu/~cs318/handin.html.) This will send your program to the class directory for grading.
Do not submit your executable program. Also, put all your source code in one file. You must hand in your source code file before 10:00am of the due date, as handin will not accept late assignments. Make sure your name, login, MP#, and date appear at the top of your code listing. See the class web page for a sample file header.
If your program does not run as required, you will be given at most 50% of the total points for the MP. You are responsible for making sure your program compiles on the WindowsNT machines using the makewin batch file.
Late assignments will not be accepted. If you are having problems beyond your control, you must let a TA know at least 24 hours before the due date to arrange for a possible extension. There will be no exceptions!