Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 5 Hidden Surface Removal and Rasterization Taku Komura.

  • Published on
    01-Apr-2015

  • View
    214

  • Download
    1

Transcript

  • Slide 1

Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 5 Hidden Surface Removal and Rasterization Taku Komura Slide 2 Computer Graphics Inf4/MSc 2 Hidden surface removal Drawing polygonal faces on screen consumes CPU cycles Illumination We cannot see every surface in scene We don t want to waste time rendering primitives which don t contribute to the final image. Slide 3 Computer Graphics Inf4/MSc 3 Visibility (hidden surface removal) A correct rendering requires correct visibility calculations Correct visibility when multiple opaque polygons cover the same screen space, only the closest one is visible (remove the other hidden surfaces) wrong visibility correct visibility Slide 4 Computer Graphics Inf4/MSc 4 Visibility of primitives A scene primitive can be invisible for 3 reasons: Primitive lies outside field of view Primitive is back-facing Primitive is occluded by one or more objects nearer the viewer Slide 5 Computer Graphics Inf4/MSc 5 Visible surface algorithms. Definitions: Object space techniques: applied before vertices are mapped to pixels Back face culling, Painters algorithm, BSP trees Image space techniques: applied while the vertices are rasterized Z-buffering Slide 6 Computer Graphics Inf4/MSc 6 Back face culling. The vertices of polyhedra are oriented in an anticlockwise manner when viewed from outside surface normal N points out. Project a polygon. Test z component of surface normal. If negative cull, since normal points away from viewer. Or if N. V > 0 we are viewing the back face so polygon is obscured. Slide 7 Computer Graphics Inf4/MSc 7 Painters algorithm (object space). Draw surfaces in back to front order nearer polygons paint over farther ones. Supports transparency. Key issue is order determination. Doesnt always work see image at right. Slide 8 Computer Graphics Inf4/MSc BSP (Binary Space Partitioning) Tree. One of class of list-priority algorithms returns ordered list of polygon fragments for specified view point (static pre-processing stage). Choose polygon arbitrarily Divide scene into front (relative to normal) and back half-spaces. Split any polygon lying on both sides. Choose a polygon from each side split scene again. Recursively divide each side until each node contains only 1 polygon. 3 4 1 2 5 View of scene from above Slide 9 Computer Graphics Inf4/MSc 19/10/2007 Lecture 9 9 BSP Tree. Choose polygon arbitrarily Divide scene into front (relative to normal) and back half-spaces. Split any polygon lying on both sides. Choose a polygon from each side split scene again. Recursively divide each side until each node contains only 1 polygon. 3 3 4 1 2 5 5a 5b 1 2 5a 4 5b back front Slide 10 Computer Graphics Inf4/MSc BSP Tree. Choose polygon arbitrarily Divide scene into front (relative to normal) and back half-spaces. Split any polygon lying on both sides. Choose a polygon from each side split scene again. Recursively divide each side until each node contains only 1 polygon. 3 3 4 1 2 5 5a 5b 4 5b back front 2 15a front Slide 11 Computer Graphics Inf4/MSc BSP Tree. Choose polygon arbitrarily Divide scene into front (relative to normal) and back half-spaces. Split any polygon lying on both sides. Choose a polygon from each side split scene again. Recursively divide each side until each node contains only 1 polygon. 3 3 4 1 2 5 5a 5b back front 2 15a front 5b 4 Slide 12 Computer Graphics Inf4/MSc 19/10/2007 Lecture 9 12 Displaying a BSP tree. Once we have the regions need priority list BSP tree can be traversed to yield a correct priority list for an arbitrary viewpoint. Start at root polygon. If viewer is in front half-space, draw polygons behind root first, then the root polygon, then polygons in front. If polygon is on edge either can be used. Recursively descend the tree. If eye is in rear half-space for a polygon then can back face cull. Slide 13 Computer Graphics Inf4/MSc 19/10/2007 Lecture 9 13 BSP Tree. A lot of computation required at start. Try to split polygons along good dividing plane Intersecting polygon splitting may be costly Cheap to check visibility once tree is set up. Can be used to generate correct visibility for arbitrary views. Efficient when objects dont change very often in the scene. Slide 14 Computer Graphics Inf4/MSc 19/10/2007 Lecture 9 14 BSP performance measure Tree construction and traversal (object-space ordering algorithm good for relatively few static primitives, precise) Overdraw: maximum Front-to-back traversal is more efficient Record which region has been filled in already Terminate when all regions of the screen is filled in S. Chen and D. Gordon. Front-to-Back Display of BSP Trees. IEEE Computer Graphics & Algorithms, pp 7985. September 1991. Slide 15 Computer Graphics Inf4/MSc 15 Z-buffering : image space approach Basic Z-buffer idea: rasterize every input polygon For every pixel in the polygon interior, calculate its corresponding z value (by interpolation) Track depth values of closest polygon (smallest z) so far Paint the pixel with the color of the polygon whose z value is the closest to the eye. Slide 16 Computer Graphics Inf4/MSc 16 Slide 17 Computer Graphics Inf4/MSc 17 Slide 18 Computer Graphics Inf4/MSc 18 Slide 19 Computer Graphics Inf4/MSc 19 Slide 20 Computer Graphics Inf4/MSc 20 Implementation. Initialise frame buffer to background colour. Initialise depth buffer to z = max. value for far clipping plane For each triangle Calculate value for z for each pixel inside Update both frame and depth buffer Slide 21 Computer Graphics Inf4/MSc Filling in Triangles Scan line algorithm Filling in the triangle by drawing horizontal lines from top to bottom Barycentric coordinates Checking whether a pixel is inside / outside the triangle Slide 22 Computer Graphics Inf4/MSc 22 Triangle Rasterization Consider a 2D triangle with vertices p0, p1, p2. Let p be any point in the plane. We can always find a, b, c such that We will have if and only if p is inside the triangle. We call the barycentric coordinates of p. Slide 23 Computer Graphics Inf4/MSc 23 Computing the baricentric coordinates of the interior pixels (,,) : barycentric coordinates Only if 0

Recommended

View more >