David Luebke12/7/2015 CS 551 / 645: Introductory Computer Graphics Review for Midterm
David Luebke12/7/2015 Administrivia l Hand out assignment 2 l Hand in assignment 3 l Late day policy: –1 late day = due tomorrow at noon –Subsequent late days add 24 hours each –Weekends and holidays count l Compiling with C++ –UNIX C++ compilers: g++ and /bin/CC –I’ll make sure it works before next assignment
David Luebke12/7/2015 Midterm Examination l Midterm is this Thursday (March 9) l Study aids: –This lecture –Earlier lectures (available on course page) –Last semester’s midterm n See n But, its not quite the same material l No calculators! (you won’t need them)
David Luebke12/7/2015 Display Technologies l Cathode Ray Tubes –Earliest, still most common graphical display –Understand the basic mechanism n Vacuum tube, phosphors, electron beam –Pros: bright, fairly high-res, leverages TV tech –Cons: bulky, size-limited, finicky
David Luebke12/7/2015 Display Technologies l Vector versus raster display –Vector: traces lines like an oscilloscope n Pros: bright, crisp, uniform lines n Cons: wireframe only, flicker for complex scenes –Raster: fixed scan pattern for electron beam, intensity controlled by scan-out from frame buffer n Pros: display solid objects, image complexity limited only by framebuffer resolution n Cons: discreet sampling (aliasing), memory cost
David Luebke12/7/2015 Display Technologies l LCDs –Understand the basic mechanism n Polarized light, crystals twist 90º unless excited n Basically a light valve: reflective or transmissive –Pros: light-weight and thin –Cons: expensive, high-power (when backlit), limited in size
David Luebke12/7/2015 Display Technologies l Also know: –Plasma display panels –Digital Micromirror Devices
David Luebke12/7/2015 Framebuffers l Memory array storing image in pixels l Issues: memory speed, size, bus contention l Different types in common use, motivated mainly by memory cost –True-Color: 24 bits, 8 per RGB (or 32 bits with ) –Hi-Color: 16 bits (R = 6, G = 6, B = 4) –Pseudo-Color: 8 bits index into 256-entiry color lookup table (entries typically 24-bits)
David Luebke12/7/2015 Mathematical Foundations l Geometry (2-D, 3-D) l Trigonometry l Vector spaces –Elements: scalars and vectors –Operations: n Addition (identity & inverse) n Scalar multiplication (distributive rule) –Linear combinations, dimension, basis sets –Inner (dot) product, vector (cross) product
David Luebke12/7/2015 Mathematical Foundations l Affine spaces –Elements: points –Operations: n Subtraction (point - point = vector) n Addition (vector + point = point) l Matrices –Linear transforms, vector-matrix multiplication –Matrix-matrix multiplication –Composition of linear transforms = matrix concatenation
David Luebke12/7/2015 The Rendering Pipeline Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering PipelineFramebufferDisplay
David Luebke12/7/2015 The Rendering Pipeline: 3-D Modeling Transforms Scene graph Object geometry Lighting Calculations Viewing Transform Clipping Projection Transform Result: All vertices of scene in shared 3-D “world” coordinate system Vertices shaded according to lighting model Scene vertices in 3-D “view” or “camera” coordinate system Exactly those vertices & portions of polygons in view frustum 2-D screen coordinates of clipped vertices
David Luebke12/7/2015 Geometric Transforms l Modeling transforms: object coordinates world coordinates l Viewing transform: world coordinates eye coordinates –eye coordinates == camera coordinates == view coordinates l Projection transform: eye coordinates 2-D screen coordinates
David Luebke12/7/2015 Geometric Transforms l Understand homogeneous coordinates –[x, y, z, w] T == (x/w, y/w, z/w) –Allows us to capture translation and projection as matrices l Know your 4x4 Euclidean transform matrices: –Translation, scale, rotation about X, Y, Z l Understand rotation about an arbitrary axis l Understand order of composition for matrices –In OpenGL: using column vectors as points order from right to left
David Luebke12/7/2015 Perspective Projection l Geometry of the perspective projection: P (x, y, z)X Z View plane d (0,0,0) x’ = ?
David Luebke12/7/2015 Perspective Projection l Desired result:
David Luebke12/7/2015 Perspective Projection l A matrix that accomplishes this:
David Luebke12/7/2015 Rasterizing Lines l Review McMillan’s great java-enabled lecture l First stab: slope-intercept + symmetry l A case study in optimization –Special case boundary conditions if necessary –Optimize inner loops n Incremental update using DDA (biggest win) n Low-level tricks: integer arithmetic, compare to 0, etc. n Culmination: Bresenham’s algorithm –Be aware of diminishing returns and readability/portability tradeoffs
David Luebke12/7/2015 Rasterizing Triangles l Triangles are nice to deal with because they are always planar and always convex l Triangle rasterization techniques: –REYES: recursive subdivision of primitive –Warnock: recursive subdivision of screen –Edge walking –Edge equations
David Luebke12/7/2015 Rasterizing Triangles l Edge walking: –Draw edges vertically –Fill in horizontal spans for each scanline –Interpolate colors down edges –At each scanline, interpolate edge colors across span –Pros: n Fast: touch only lit pixels, touch pixels only once –Cons: n Finicky: lots of special cases, hard to get just right
David Luebke12/7/2015 Rasterizing Triangles l Edge Equations –Equation of a line defines two half-spaces –Triangle can be represented as intersection of three half-spaces: A 1 x + B 1 y + C 1 < 0 A 2 x + B 2 y + C 2 < 0 A 3 x + B 3 y + C 3 < 0 A 1 x + B 1 y + C 1 > 0 A 3 x + B 3 y + C 3 > 0 A 2 x + B 2 y + C 2 > 0
David Luebke12/7/2015 Rasterizing Triangles l Basic algorithm: –Walk pixels in bounding box –Evaluate three edge equations –If all are greater than zero, shade pixel l Issues: –Computing edge equations: numerical precision –Interpolating parameters (i.e., color): just like another edge equation (why?) l Optimizing the algorithm –Like line rasterization: DDA, early termination, etc.
David Luebke12/7/2015 Rasterizing General Polygons l Parity test: –Starting outside polygon, count edges crossed. –Odd = inside, even = outside l Big cost: testing every edge against every pixel l Solution: the active edge table algorithm –Sort edges by Y –Keep a list of edges that intersect current scanline, sorted by their X-intersection w/ scanline A B C D E F G I H
David Luebke12/7/2015 Clipping Lines l Cohen-Sutherland Algorithm –Clip 2-D line segments to rectangular viewport –Designed for rapid trivial accept & trivial reject ops n 4-bit outcodes divide screen into 9 regions n Bitwise operations determine whether to accept, reject, or intersect with a viewport edge & recurse n May require multiple iterations
David Luebke12/7/2015 Clipping Polygons l Clipping polygons fundamentally more difficult –Polygons can gain or lose edges –Concave polygons can even multiply l Sutherland-Hodgman Algorithm –Simplify by divide-and-conquer: consider each clipping plane individually n Input: polygon as ordered list of vertices n Output: polygon as ordered list of vertices n Lends itself to pipelined hardware implementation
David Luebke12/7/2015 Clipping Polygons l Sutherland-Hodgman Algorithm –Know the details: n Point-plane test n Line-plane intersection n Rules: insideoutside s p p output insideoutside s p no output insideoutside s p i output insideoutside s p i output p output
David Luebke12/7/2015 Clipping in 3-D l Problem: clipping under perspective must happen before homogeneous divide –Solution 1: clip to hither plane in eye coordinates, then multiply by projection matrix, then do homogeneous divide n Better: transform to canonical perspective coordinates to simplify clipping –Solution 2: clip after projection (must clip all 4 homogeneous coordinates) –Solution 3 (ugly but common): clip to hither & yon before projection, clip to 2-D viewport after projection and divide
David Luebke12/7/2015 Color l Rods and cones l Cones and color perception –Metamers –3-D color: X, Y, and Z; CIE color space l Gamma correction
David Luebke12/7/2015 Lighting l Definitions: illumination, lighting, shading l Illumination: –Direct versus indirect –Light properties: geometry, spectrum n Common simplifications: ambient, directional, and point –Surface material: geometry, reflectance, microstructure n Common simplification: Phong lighting Diffuse (Lambertian) reflection: incoming light reflected equally in all directions, proportional to N L Specular reflection: approximate falloff with (V R) n shiny
David Luebke12/7/2015 Lighting l Putting it all together: the Phong lighting model l Note: evaluate per light, per color component Common simplification: constant V (viewer infinitely far away)
David Luebke12/7/2015 Shading l Where to apply lighting calculations? –Once per face: flat shading –Once per vertex, interpolate resulting color: Gouraud shading –Once per pixel, interpolating normal vectors from vertices: Phong shading Flat shadingPhong Shading