CSE681 Lab 1
Winter 2011
due Monday, January 24, by 11:59:59pm
Note:
- We are not going to use OpenInventor this quarter.
This is a change from recent previous 681 classes.
This will change the labs and class notes.
- Professor Shen has some Lab Help pages that you might find useful. However, note that my lab assignments may or may not be the same as Dr. Shen's - so when he refers to something about a specific lab assignment, you need to relate that to my assignment. (But you'll have to ignore the OpenInventor stuff there).
Objective
- In this lab, you will create the basic structure for your ray tracer including the basic ray construction code and ray-sphere intersection code.
However, these can be simplified by using assumptions about the location of the camera and the sphere.
Assignment & Requirements
Write the basic ray tracing geometry code that constructs a ray through each pixel and intersects a sphere of radius 1 centered at the origin.
Color each point by scaling the color red by the z-coordinate of the normal vector.
- Call your program lab1.
- Use whatever classes and program organization you want - but the program should be documented and easily 'readable' by the grader.
- You can refer to the book, the web, other books, etc. to see code fragments for the various tasks you'll have to program - but write your own code.
Questions concerning code will be on the midterm and final.
-
Build a ray tracer that uses a pre-defined camera, intersects a single sphere of radius 1 centered at the origin, shades it according to the normal vector at the intersected point.
- To shade the sphere at a point of intersection:
- At the visible point of intersection, calculate the normal vector (vector from the center of the sphere to the intersection point),
- normalize the normal vector
- Use the z component of the (normalized) normal vector to scale the color of the sphere, clamping it to the ambient value at the low end.
- Default scene consists:
- background color of (0.0 0.6 0.6)
- no lights
- ambient value of 0.2
- one sphere
- at (0,0,0)
- radius of 1
- color of (0.8 0.2 0.2)
- camera
- position at (0.0 0.0 1.5)
- center-of-interest, or lookat point, of (0.0 0.0 0.0)
- half angle of view of 45 degrees
- aspect ratio of 1.0
- hither and yon distances of 0.1 and 100.0
- tilt angle of 0.0 degrees
- resolution of 400 x 400
- When a ray intersects the sphere, compute the intensity of a point on a sphere thusly:
- compute the normalized normal vector of the point on the sphere
- set the intensity to the maximum of the ambient value and the z-component of the normal vector
- Write the image of the ray-traced scene out to a portable pixmap file, called output.ppm. In the PPM file, use 255 as the maximum color component.
- Of course, you can develop your program on any platform you like.
But make sure, before you submit it, that the grader can compile, execute, and view the output under UNIX using the commands shown below.
- Submit the source code for your program.
For example:
submit c681aa lab1 lab1.c makefile
Of course, you can break it up into multiple source files and submit those.
For example:
submit c681aa lab1 main.cpp camera.cpp sphere.cpp light.cpp makefile
- just as long as the grader, under UNIX, can make and execute your program, and then find the output in output.ppm:
make
lab1
convert output.ppm output.jpg
display output.jpg
NOTES
The simple geometric arrangement of the camera and the sphere should help you debug your program.
You should be able to look at pixel values and intersection point values and see if they make sense or not.
For example, at 45 degrees field of view with the observer at z=1.5, the virtual frame buffer should be at z=0.5 and the top of it should be at y=1.0.
Similarly, with a sphere centered at the origin with radius 1, all intersection points should be a distance of 1 away from the origin. The z-coordinate of all normal vectors of all visible points should be positive.
Last updated 1/12/11
681 home page
Rick Parent