CS 4204: Computer Graphics


Announcements & syllabus


Programming assignments




Programming Assignment 3: Basic Ray-Tracing


You will write a simple ray tracing program. Your program should produce images that exhibit diffuse reflection (using Lambert's law and ambient light), specular reflection, and shadows. The program should be able to render spheres and polygons.

Due Date

The assignment is due on Monday, April 7 at 11:59 PM. The standard late policy for programs is in effect.

Required Features

  • The program should be written in C/C++ using openGL and GLUT. However, note that very few features of openGL/GLUT will be used. You will only use GLUT to create an interface window, and use openGL to draw 2D pixels within that window. Your program will do all the necessary calculations to determine the color of each pixel in the window.
  • The program should take a single command-line argument - the name of the input file (see the next bullet).
  • The scene will be specified in a file as follows (this is for your information only; you will be given code to parse this file):
    • VIEW z-position
    • LIGHT x y z red green blue
    • SPHERE x y z radius red green blue
    • POLY #vertices x1 y1 z1 x2 y2 z2 x3 y3 z3 ... red green blue
  • There will be a limited number of objects (given by constants in the provided skeleton code) specified in the file. You will be given routines that read this file and place the information into data structures.
  • For the view, assume that the eyepoint is on the positive z-axis, looking back toward the origin (in the negative z-direction). The window is centered at the origin and is 2x2 (-1.0, -1.0) to (1.0, 1.0). The view should be a standard perspective projection.
  • You will be provided with the following files:
    • read_input.c: Routines to read the input file
    • ray_trace.h: Globals and data structures
    • ray_trace.c: Some skeleton code
    • P3_input: a directory containing sample input files on which your program will be partially graded
    • All of these files are available in this zip archive.
  • Your job is to fill in the functions that calculate intersections between rays and objects, and that determine the illumination (color) at each pixel.
  • You are required to include the ability to render spheres and polygons correctly, including ambient, diffuse, and specular illumination, and shadows caused by objects occluding the light source from a particular point.
  • Test your program on scenes containing up to two light sources, up to three spheres, and up to two polygons. Your program will be graded on whether it runs and renders objects (40%), whether the illumination and shadowing "look good" (40%) and on documentation (20%). "Looking good" is obviously a subjective measure, but we will be looking for even shading, correct shadows, appropriate ambient lighting, good choices for the diffuse coefficient and specular values, etc.
  • Ray-tracing programs can have long execution times. You may wish to debug your program using a lower resolution (small screen window to which you are mapping your 2x2 view window) for faster execution times (since you will be calculating the values of each pixel of the interface window).
  • This PDF file has sample images for scenes 1, 2, and 3 (spheres only, as well as spheres and polygons).

Optional Features (for up to 10 bonus points)

  • Provide an interface allowing the user to change the values of the illumination model constants and re-render the scene.
  • Provide an interface allowing the user to change the material properties of individual objects in the scene.
  • Render the same scene using openGL 3D graphics and lighting in a separate window for comparison purposes.
  • Make some objects partially transparent.
  • Add an acceleration algorithm to speed up the intersection calculations. See the instructor if interested in this option.


Turn in your program via email to the TA. You may either submit a single source file or a ZIP archive of several source/header files. You may also optionally include a plain text README file if you wish.