Homework 3

Assigned: May 1, 2001
Due: 11:59PM, May 8, 2001

For this assignment, you will add a more realistic camera model to lrt. The new camera model will support depth of field, very limited motion blur, and two different kinds of shutters.

Step 0 -- Get new LRT

The new lrt in /usr/class/cs348b/software/lrt/lrt.tar.gz contains all the changes that have been published up to this point, as well as the modifications to the camera framework to make this assignment possible. All of your changes will be made in the file mbdofcamera.cc. In that file, you will see a single function, GenerateRay. You will be required to create a ray given a 5-tuple of sample values. You should familiarize yourself with the function PinholeCamera::GenerateRay in camera.cc to see how this is done for a simple camera with an infinitely small aperture.

Step 1 -- Depth of Field

First, you should add depth of field to lrt. The 5-tuple of samples passed to GenerateRay should be interpreted as follows:

Using sample[0] and sample[1] for the film location, generate a sample on the aperture using the random numbers in sample[2] and sample[3]. Armed with these four numbers (x,y,u,v), you can generate the appropriate ray to trace. Refer to your answer to question 3 of assignment 2 for the mathematics behind this construction.

GenerateRay should return true if the computed ray is valid, and false otherwise.

Setting Depth of Field parameters in RIB

The DepthOfField command sets the parameters necessary to compute depth of field. For more detail, check out the documentation under RenderMan Resources.

The three parameters specified by the DepthOfField command are available as members of the Camera class as FStop, FocalLength, and FocalDistance. You should probably not mess with the FocalLength parameter in the sample file; just adjust the f-stop and focal distance.

Note that you can issue the command

DepthOfField -

Which will set the aperture to RI_INFINITY. If this is the case, the FocalDistance and FocalLength are undefined, and everything will be in focus (i.e., the aperture is a pinhole).

To switch from the default pinhole camera to your fancy camera, put the line:

Option "camera" "type" "mbdof"

at the top of the RIB file. It is important that this line appear before the projection is set, or any other camera options, as it will construct a new camera object, and previous settings will be lost.

Step 2: Motion Blur

The fifth sample parameter is another uniformly distributed random number between 0 and 1, which can be used for sampling a time interval. You will notice that there are two CameraToWorld transformations; these correspond to the camera transformations at time t=0, and t=1.

For this assignment, you may assume that the camera is the only moving object in the scene, and that the camera movement is purely translational.

Setting Motion parameters in RIB

To set the two camera-to-world transformation matrices in RIB, just enclose them in a MotionBegin/MotionEnd pair:

MotionBegin [0 1]
  Translate 0 10 0
  Translate 0 20 0
This needs to appear before the WorldBegin command.

Step 3: Shutter Simulation

Finally, you should simulate the behavior of two different types of shutters: iris shutters and stripe shutters. Andrew Glassner has written an excellent article on shutters. (The article should be available for download from any Stanford computer).

An iris shutter is circular. It starts closed, and opens radially to the full aperture of the lens before closing again. It is closed at t=0, and again at t=1. Obviously, the shutter cannot open and close instantaneously. For this part, you should assume that the radius of the shutter grows from 0 to the full aperture linearly at some rate R, and closes again at the same rate.

For example, if R=10, the iris opens with a linearly growing radius from t=0 until t=1/10. It begins to close (again linearly) at t=9/10. At times when the iris is not fully open, it should be considered to limit the aperture of the lens. Note that it does not make sense for R to be less than 2.

A stripe shutter slides a rectangular window of a certain width across the film plane. The window can move left, right, up, or down. As in the case of the iris shutter, the shutter is closed (i.e., the window is off to one side) at t=0, and it closes again (i.e., the window is at the other side) at t=1. (Note: This is not exactly how this is implemented in real cameras, but it will serve for our purposes. See the Glassner Article for more information).

Shutter notes

The iris shutter should be considered to be located in the lens itself. That is, at any point in time between t=0 and t=1, every point on the film is visible, and only the aperture of the lens is changing. The stripe shutter, on the other hand, is located on the film plane, so it blocks portions of the film at various times. You should NOT reject samples (i.e., return false from GenerateRay) in the stripe shutter, but rather interpret the time variable as specifying the point in the visibility interval of the given pixel. More precisely, each pixel will be visible from some time t=t0 to t=t1. For the stripe shutter, use the time variable to choose a time within this interval. The two shutter types may therefore introduce different kinds of artifacts.

Specifying Shutter parameters in RIB

To specify an iris shutter, put the following line in your RIB file after the specification of the camera type (see above):

Option "camera" "shutter" "iris"

Similarly, you can specify a stripe shutter with:

Option "camera" "shutter" "stripe"

To control the iris open rate, use:

Option "camera" "iris_rate" 10

Note that the numeric value 10 is not quoted as a string. To set the width of the stripe shutter's sliding window, use:

Option "camera" "stripe_width" .1

The stripe width is specified as a number between 0 and 1, representing a percentage of the film extent in the direction of motion. To specify the direction of motion:

Option "camera" "stripe_direction" "down"

Other valid values are "up", "left", and "right".

Determining Shutter parameters in your code

The Camera class has a field called ShutterType, which can be compared to the constants LRT_IRIS and LRT_STRIPE to determine what kind of shutter to simulate.

The Camera class also contains the floats IrisRate and StripeWidth, which correspond directly to the values set in the RIB file.

Finally, the Camera class also has a variable called StripeDirection, which can be compared to the constants LRT_UP, LRT_DOWN, LRT_RIGHT, and (you guessed it), LRT_LEFT to figure out what direction the stripe should be moving.

Fun experiments to try

These experiments are an example of things we will try when grading your assignments, so it would behoove you to experiment with the controls of your camera model, and make sure it behaves the way you think it shoud.

Testing your program

You can run (On Linux) /usr/class/cs348b/bin/humper_lrt, which implements everything you're supposed to do for this assignment. A simple test file can be found in /usr/class/cs348b/ass2/dof.rib. We won't necessarily be comparing your images to ours pixel-for-pixel, but it will provide a reasonable visual comparison.


Turn in your finished homework using the cs348b submit script:
Make sure you hand in all your source code, a Makefile, and a README file.

ALSO: create a web page containing at least three renderings of a single, original scene with varying camera parameters. At least one of the images should clearly show artifacts from a shutter simulation, and be labeled as such. Label each image with the parameters used to create the scene: Motion (if any), f-stop, focal distance, shutter type, shutter parameters, number of samples per pixel. This scene doesn't need to be complex, just a few simple geometric objects arranged in such a way as to show off features of your camera system. If you implement any features above and beyond what's described here, be sure to show them off on your web page. The web page should include the images created, as well as the RIB source that made them. Include a URL to the web page in your README. DO NOT omit this step. Hint: For your final web-page renderings, turn up the number of samples per pixel. You'll be more pleased with the results, and it's worth the wait.

This homework will be graded according to the following system:

Copyright © 2001 Pat Hanrahan