Assignment: ray casting (updated with submission link)


Assignment 2

Basic modeling, ray casting, interpolation and local lighting
Due: by class time October 9 at this link. (updated: with previous link)

Goal:

In this assignment you will practice the ray casting, viewing, interpolation and lighting concepts that we have discussed. You will compare these to the OpenGL equivalent.

Basic grading:

The components of this assignment will be graded as follows:
  • 10% Properly turned in assignment
  • 15% Using OpenGL, parse and render just the vertices described in an obj file, in white
  • 15% Using ray casting, render the vertices of the same model using ray casting, in white
  • 10% Using OpenGL, parse and render the complete triangles described in the obj file, in white
  • 20% Using ray casting, render the complete triangles described in the same obj file, in white
  • 10% Using OpenGL, render the complete triangles described in the obj file, with Blinn-Phong illumination and Gouraud shading
  • 20% 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:

As in the previous assignment, you should display two images in sequence. Pressing the space bar moves between these. The first shows OpenGL, and should be rendered similarly to your triangle rendering from the first assignment. The second shows your ray casting, and should be rendered ultimately with techniques similar to your pixel rendering from the first assignment. You do not need to animate anything in this assignment. As you progress through the assignment, you can use any improved OpenGL image to replace the previous (e.g. don't show parts 1, 3 and 5, just 5); and any improved ray casting image to replace the previous.

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.

Part 0: Properly turned in assignment

Turn in both an executable and source. Your assignment should run without any missing libraries, and compile without any missing references. Submit 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.

Part 1: Using OpenGL, render just the vertices in white

Your program should read in the file input.obj. Your parser should not halt if it doesn't recognize a line, instead it should ignore it. You can ignore triangles, colors and normals for this part of the assignment. You should see only the model vertices in white.

Part 2: Using ray casting, render just the vertices in white

Now use ray casting to render the same vertices. You don't need to worry about interpolating along the viewing window or calculating intersections for this part, simply trace rays from the eye through each vertex, then interpolate X and Y along the ray using depth to find the pixel location. Your ray casted and openGL images should look the same.

Part 3: Using OpenGL, render the complete triangles

You can no longer ignore the triangles for this part. Render the triangles contained in the obj file in white. All triangle edges and interiors should now be white.

Part 4: Using ray casting, render the 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. The images from this and the previous part should look the same, though there may be small differences in rounding at edges.

Part 5: Using OpenGL, render lit triangles

You can now no longer ignore colors and normals, and need to worry about depth. Turn on depth buffering, local Blinn-Phong lighting, Gouraud shading. You should see the same triangles you rendered before, but with the same sort of lighting and shading you saw on the first assignment's triangle, with every triangle fragment having a slightly different color. You should also see occlusion.

Part 6: 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
  • 5% detect shadows during ray casting
  • 10% add coherent specular reflections during ray casting
  • 10% add refractions 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.

Extra credit: Add coherent specular reflections

When performing lighting during ray casting, shoot an additional ray in the reflected direction to obtain some additional color, and add it to the local color. No need to recurse; just obtain immediate reflections. This should only affect the last part of your assignment.

Extra credit: Add refraction

When performing lighting during ray casting, shoot an additional ray in the refracted direction to obtain additional color, and add it to the local color. No need to recurse. This should affect only the last part of your assignment.