Assignment: viewing, interpolation and ray casting

Assignment 1
Note: Based on original assignment from CG Class Fall 2012

Due: end of day, October 1


In this assignment you will practice the ray casting, viewing, and interpolation that we have discussed.

Basic grading:

The components of this assignment will be graded as follows:
  • 10% Properly turned in assignment
  • 40% Using ray casting, render the complete triangles described in the obj file, in white
  • 50% Using ray casting, render the complete triangles described in the obj file, with Blinn-Phong illumination and Phong shading
  • Participation credit: You can receive participation credit (outside of this assignment) for posting your release, good or bad, on the class forum!

General notes:

Obj is a 3D modeling format in widespread use, originally designed for the Alias\Modeling software, now Maya. You can find details on obj in our course wiki, including format, sites with free models, and parsing code that you should feel free to use. You will not need parse the complete obj format for this assignment: only those parts that describe triangles and the vertices they contain, as well as vertex locations, colors and normals. If you wish to build your own models, you can download Maya and Max for free. Both can output directly to obj, and you can read and edit obj easily in any editor. Here is a simple example obj file describing a cube, here is its material.
All vertex locations should be described in world coordinates, meaning they do not require any transformation. Locate the eye at (0 0 -2), with a view up vector of [0 1 0] and a look at vector of [0 0 1]. Locate the front clipping plane a distance of 1 from the eye, and the back clipping plane a distance of 3. You may assume that the viewing window is a 2x2 square centered on the front clipping plane, and aligned with world the coordinate axes. With this scheme, you can ensure that everything in the world is in view if it is located in a 2x2x2 box centered at the origin. Use perspective projection. Put a white (1,1,1) light at location (0,5,0).
You may make your interface window only 256x256 in size. This will speed testing of your ray casting. We will test your program with the test cube, as well as several other obj files, some of which you can find here, others which you cannot.
We are providing a shell in which you can build your code. It shows how you should draw a pixel (using OpenGL in a slightly unusual way), and if you press the space bar, it will switch between pixel rendering and OpenGL rasterized render of the obj file. You should use space bar to switch between ray casting and a purely OpenGL rasterized render of the obj file in your program. Note that while your ray casted locations should match the OpenGL image, your colors will not exactly: the OpenGL render uses interpolated Gouraud shading, while your ray caster is using Phong shading, that is per pixel lighting.

Part 0: Properly turned in assignment

Submit the following files:
  • raycast.exe, a Windows 7 executable of your finished assignment
  • all associated source code files (these can be called anything you want)
  • a readme.txt file if there is any configurable behavior
  • if you wish to claim any extra credit, list those claims in the readme file, along with any needed details
Please DO NOT submit any supplemental development files, in particular Developer Studio solution or project files. The size of these files will quickly exceed the available space in the submit locker.
There is an important requirement that your assignment must satisfy.
  • Your program must be compiled to run on a Windows 7 PC equipped with OpenGL, GLUT, and the standard Visual Studio runtime libraries. If we cannot run your program, we will not be able to mark it.

Part 1: Using ray casting, render complete triangles

Use ray casting to render triangles, not just vertices. Now to trace each ray, you will have to locate each pixel with a BILERP through the viewing window. Also, you will have to perform an intersection to see if there are any triangles behind the pixel. Feel free to use intersection code you find on the net (though you should cite it). You needn't do any depth testing however, since everything is still white.

Part 2: Using ray casting, render lit triangles

Now you will have to examine the depth of each intersection, and if it is the frontmost, perform a local lighting calculation. To perform that lighting calculation, you may either perform an edge based interpolation of the normals as we discussed in class, or use the barycentric weights you generated in the intersection test for that triangle. Don't forget to normalize the resulting vectors, and recalculate the local light vector! The result will be Phong, not Gouraud shading, so you should see an image showing triangles with the same outline and occlusion as the previous part (subject to edge rounding), but slightly smoother and better looking colors.

Participation credit:

Please remember that you can get participation credit outside this assignment for posting your imagery, good or bad, on the course forum or Voicethread.

Extra credit grading:

Extra credit opportunities include the following, with others possible with instructor approval:
  • 5% support arbitrarily sized images (and interface windows)
  • 5% support multiple obj files and arbitrary modeling coordinates
  • 5% support arbitrary viewing setups
  • 5% support off-axis and rectangular projections
  • 5% support multiple lights at arbitrary locations
  • 10% detect shadows during ray casting

Extra credit: Arbitrarily sized images and interface windows

Read in an additional window.txt file that one line, lists the width and height of the interface window. Size your interface window to match, and change your ray casting interpolation to match. This should effect every part of your assignment.

Extra credit: Multiple obj files and arbitrary modeling coordinates

Read in an additional world.txt file that on each line, references an obj file and its associated modeling transform. Read in, transform and display all the named obj files before rendering them. This should affect every part of your assignment.

Extra credit: Support arbitrary viewing setups

Read in an additional view.txt file that lists the eye's location, the view up, and the look at vectors, each on a different line. Reorient the window to be normal to the look at vector (in OpenGL this will happen automatically, but not in ray casting). Render the scene with these viewing parameters. Note that with bad viewing parameters, you will not see the model. This should affect every part of your assignment.

Extra credit: Support off-axis and rectangular projections

Read in an additional project.txt file that lists the viewing window's top, right, bottom and left Y, X, Y, and X coordinates (four numbers) on one line. Adjust your ray casting interpolation to these new coordinates. Render the scene with these new projection parameters. Note that if you also perform the arbitrary viewing extra credit, these coordinates may not be in world space! Also with bad projection parameters, you will not see the model. This should affect every part of your assignment.

Extra credit: Multiple and arbitrarily located lights

Read in an additional lights.txt file that on each line, describes the location and color of a light (use one triple for a light's color, with its ambient, diffuse and specular colors the same). Render the scene with these lights. In ray casting, you will have to sum the colors all the lights. This should affect the last two parts of your assignment.

Extra credit: Detect shadows during ray casting

When performing lighting during ray casting, shoot an additional ray toward the light to decide if only ambient light reaches the intersection. If you also support multiple lights, make sure to shoot a ray at each light! This should only affect the last part of your assignment.