CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions The Midterm Exam was given in class on Thursday, October 23, 2008. 1. [4 pts] Drawing Where? Your instructor says that objects should always be drawn with their natural center at the origin. Why? And if we do this, how do we indicate where an object is to appear in the scene? We draw with the natural center at the origin so that we can easily rotate and scale the object, using rotation and scale transformations, without changing its location. We then position the object using a translation transformation. 2. [7 pts total] Animation & Buffers. When we do real-time animation, we usually do a certain trick with the framebuffer(s). 2a. [5 pts] What is this trick called, and what exactly do we do? (What happens, not what goes in the code.) The trick is called double buffering. We use two framebuffers: the back buffer, which is off-screen, and the front buffer, which is on-screen (visible). We draw into the back buffer. Then, when an animation frame is complete, we swap the buffers, so that the completed frame becomes visible. 2b. [2 pts] What bad thing happens if we do not do this buffer trick? If we do not do this, then the user gets to see partially drawn frames, and the animation appears to flicker. (exam page 2)
3. [12 pts total] Transformations. 3a. [3 pts] In the context of CG, what do we mean by a transformation? A transformation is a mathematical function that maps space to itself. That is, we give it a point in space, and it gives us back a (possibly different) point in space. In computer graphics, transformations are used to position, rotate, scale, and (sometimes) deform objects, to position the camera, and to project the scene onto the viewport. 3b. [9 pts] Finish the list below of kinds of transformations and what they do. One is done; you write three more. Type #1: Translation Effect: Shifts an object s location in space, without affecting size or orientation. Type #2: Rotation Effect: Rotates an object about a line (typically, one passing through the origin), without affecting its size. Type #3: Scale Effect: Expands or contracts an object (typically, about the origin). Generally, we allow scaling the various coordinates (x, y, z) by different factors. Type #4: Perspective projection Effect: Projects the scene onto the viewport in proper perspective (so that more distant objects appear smaller). (exam page 3)
4. [9 pts total] Internal Representations. In the following questions about OpenGL s internal representations, we are talking about the way OpenGL acts like it represents things. 4a. [2 pts] How does OpenGL represent a transformation, internally? OpenGL represents a transformation using a 4 4 matrix. 4b. [2 pts] How does OpenGL represent a point in 3-D space, internally? OpenGL represents a point in 3-D space as a vector with 4 coordinates. 4c. [5 pts] How do we convert to & from the representation in the previous part? Give examples with specific vectors. We convert a 3-D vector to this representation by adding a 4th coordinate whose value is 1. For example, (1, 2, 3) becomes (1, 2, 3, 1). We convert a vector in this representation to a 3-D vector by removing the 4th coordinate and then dividing the other coordinates by it. For example, (1, 2, 3, 4) becomes (1/4, 2/4, 3/4). 5. [4 pts] Display Callback. In a GLUT program, the display function is a callback. What practical effect(s) does this have on the design of a program? Because it is a callback (which is called by GLUT), GLUT gets to decide when drawing occurs. As a result, we should do all drawing in the display function, and no drawing anywhere else, in order that drawing will be done at the proper time. (exam page 4)
6. [7 pts total] Picking. 6a. [2 pts] In the context of this class, what is picking? Picking generally refers to the user choosing an object by clicking the mouse on it. More specifically, when we talk about a picking method, we mean a method for determining which object the user clicked on. 6b. [5 pts] Choose one picking method, and describe how it works. Here are three possibilities. Extent testing. Check the mouse position against the set of pixels used by each object (its extent), in front-to-back order. The first hit is the object selected. Querying the clipper. Reduce the viewport to a single pixel at the mouse position, and query the clipper to see which objects are displayed. The front-most is the object selected. Note: In OpenGL we use selection mode. Reading the framebuffer. Draw the scene with each object in a different color. The color of the pixel at the mouse position indicates which object was selected. 7. [7 pts total] HSR. 7a. [2 pts] What is HSR? HSR stands for Hidden-Surface Removal: ensuring that only visible objects (and portions of objects) appear in an image. 7b. [5 pts] Choose one HSR method, and describe how it works. Here are two possibilities. HSR Using (Reverse) Painter s Algorithm. Draw the primitives making up a scene in back-to-front order (or front-to-back order, never redrawing any pixel). Can use a BSP Tree to determine this order. Z-buffering. Store the depth at each pixel. When a fragment arrives at the framebuffer, check its depth against the stored depth. If less, store its color and depth; otherwise discard the fragment. (exam page 5)
8. [13 pts total] The Rendering Pipeline. 8a. [10 pts] Draw a diagram illustrating the main parts of the graphics rendering pipeline. Indicate at least one operation that occurs in each box, and at least three operations performed on vertices (or groups of vertices). Vertex Operations Rasterization Fragment Operations Model-view transformation Projection transformation Clipping Depth Test The operation occurring in the Rasterization box is rasterization: the generation of fragments from geometry (vertex) data. 8b. [3 pts] We can write two kinds of shaders. Indicate what they are called and where in the pipeline each goes. Vertex shader. Goes inside Vertex Operations box. Replaces the vertex operations before Clipping. Fragment shader. Goes inside Fragment Operations box. Replaces the fragment operations before Depth Test (and the other tests). (exam page 6)
9. [6 pts total] Lambert Cosine. 9a. [2 pts] What is the Lambert cosine? The Lambert cosine is the cosine of the angle between the light-source direction and the surface normal vector. 9b. [2 pts] In practice, how do we compute the Lambert cosine? Hint: We do not actually take the cosine of anything. We compute the Lambert cosine by taking the dot product of the normalized vector indicating the light-source direction with the (normalized) surface normal vector. 9c. [2 pts] How do we use the Lambert cosine? We use the Lambert cosine to compute the intensity of diffuse reflection: Diffuse color = LambertCosine * paintcolor * lightcolor. 10. [6 pts] The Phong Illumination Model. The Phong Illumination Model includes three kinds of lighting/reflection. For each, give its name and a brief description. Type #1: Ambient Description: Light coming from all directions, illuminating every point on a surface equally, regardless of which direction it faces. Type #2: Diffuse Description: Light coming directly from a light source and reflecting equally in all directions. A point facing toward a light source is illuminated in proportion to its Lambert cosine. Type #3: Specular Description: Light coming directly from a light-source and reflecting generally in a mirror-like way. Produces the specular highlight. The brightness of a point is proportional to the cosine of the angle between the reflected light direction and the eye direction, raised to some high-ish power (the shininess). (exam page 7)