## Assignment 2

 Handed out: Tuesday, February 13, 1996 Due: 5pm, Tuesday, February 27, 1996

One of the cleverest new techniques in computer graphics is the ability to simulate looking around a 3d scene in real time by reprojecting panoramic views of the environment. The best example of this technique is the system from Apple called QuickTimeVR. The system allows the user to look freely in any direction from a fixed viewpoint. The input to the viewer is a full surround panoramic photographic that captures the entire environment. The environment may be either created by a computer, or captured from a set of photographs.

Your assignment is to build such a viewer. As you will see this involves writing a simple texture mapped polygon scan converter. To help concentrate your efforts on the most important and interesting aspects of this assignment, we will provide you with an example viewer, and a set of interesting environments. Your job will be to write the critical inner-most loop of this program---the polygon scan converter with texture mapping.

The key design decision in this system is the representation of the environment surrounding the vantage point. In this assignment we will use a cubical environment map. In this representation, a cube is centered at the vantage point and images of the surrounding environment as seen from the vantage point are stored on each of the 6 faces of the cube. From this information any possible view of the environment from that vantage point may be synthesized. The viewer program takes as input the 6 images, one for each face, and then allows the user to pan and tilt their head to look in any direction. Each face of the cubical environment map is then projected onto the display surface given the current orientation, and is drawn into the framebuffer as a texture mapped polygon.

Since we have not covered the mathematics of many of the 3D geometric operations yet (although we will soon), we will provide a outer shell program that handles the user interface, the orientation of the user's head, the projection of the cube faces onto an image plane, and the clipping of the cube faces to the near Z plane. Your job will be to write a single procedure that takes as input the 2D projection of the three vertices of a triangle, and draws that triangle into the image buffer using a texture map.

As with the first assignment, the class web pages contain detailed instructions on how to submit your assignment. Unlike the first assignment, you will be submitting only one source file. If you are writing your code in C, you should submit `rasterize.c`; if you are writing your code in C++, you should submit `rasterize.cc` or `rasterize.C`. The rest of the files you use should be identical to the ones from the example program, and thus need no submitting. Submission should take place using submit, the assignment 2 CS248 submission script.

Your grade will be based on the following criteria: 80% for implementing the functionality that we request, and 20% for tuning the code. The criteria for tuning the code will be based on your code's speed divided by our code's speed. If your code runs at half our code's speed, you get 10%. Thus, you can get extra credit if your code runs faster than ours (good luck though). We will dock up to 10% if your submission cannot be recompiled and executed. We suggest you attack the assignment as follows:

Step 1.

Play with our version of the viewer. Type
`/usr/class/cs248/assignments/assignment2/sample_viewer -h`
to see the documentation for the viewer. Try each of the options; these will help you get familiar with the debugging facilities built into the viewer. Test out various environment maps.

Step 2.

`/usr/class/cs248/assignments/assignment2/README.starting`

Or else look at the online version of Assignment2 Getting Started.

Look at `render.h`. This file defines the interface that must be implemented by you.

Step 3.

Write `RasterizeXor()`, which takes three vertices and rasterizes it by xor'ing current color with each pixel it coveres in the image buffer. You will have to implement scissoring of X & Y, and rasterization. The point of xor'ing is that if a pixel gets hit twice, it will be turned off. This will help you get meshing correct (i.e., adjacent triangles should not both rasterize the same pixel). Make sure you look at the `-rasfile` option and the `-clear` option in viewer for making your life easier.

Grading for this section will be as follows:  5 A triangle shows up on the screen. 5 The triangle does xor'ing of the pixels. 5 The triangle is clipped correctly. 5 You rasterize only pixels within the triangle. 5 You mesh triangles correctly. 5 Performance. 30

Step 4.

Write `RasterizePointSample()`, which takes three vertices and rasterizes it by looking up the nearest texel in texture and putting it in the image buffer. You will have to implement texture coordinate interpolation. Make sure you look at the `-neverrefine` and `-map` options for this section.

Grading for this section will be as follows:  15 A textured triangle shows up on the screen. 5 The texture is perspective corrected. 5 The boundary pixels of a textured triangle are sampled correctly 5 The boundaries of two cube faces meet correctly. 10 Performance. 40

Step 5.

Write `RasterizeBilinear()`, which takes three vertices and rasterizes it by looking up the four nearest texels in the texture, doing a bilinear interpolation on it, and putting it in the image buffer. You will have to implement bilinear interpolation. Make sure you look at the `-alwaysrefine` and `-map` options for this section.

Grading for this section will be as follows:  10 A smoothly textured triangle shows up on the screen. 5 Smoothness is achieved through bilinear interpolation. 5 The boundary pixels of a textured triangle are sampled correctly. 5 The image doesn't shift when bilinear interpolation is done. 5 Performance. 30

hanrahan@cs.stanford.edu