reading for this time news review polygon clipping
play

Reading for This Time News Review: Polygon Clipping CPSC 314 - PowerPoint PPT Presentation

University of British Columbia Reading for This Time News Review: Polygon Clipping CPSC 314 Computer Graphics Project 3 update not just clipping all boundary lines Jan-Apr 2007 FCG Chap 12 Graphics Pipeline Linux executable


  1. University of British Columbia Reading for This Time News Review: Polygon Clipping CPSC 314 Computer Graphics • Project 3 update • not just clipping all boundary lines Jan-Apr 2007 • FCG Chap 12 Graphics Pipeline • Linux executable reposted • may have to introduce new line segments • only 12.1-12.4 Tamara Munzner • template update • download package again OR Hidden Surfaces II • just change line 31 of src/main.cpp from int resolution[2]; to Week 9, Mon Mar 12 int resolution[] = {100,100}; OR http://www.ugrad.cs.ubc.ca/~cs314/Vjan2007 • implement resolution parsing 2 3 4 Review: Sutherland-Hodgeman Clipping Review: Sutherland-Hodgeman Clipping Review: Painter’s Algorithm Review: BSP Trees • for each viewport edge • edge from p[i-1] to p[i] has four cases • draw objects from back to front • preprocess: create binary tree • clip the polygon against the edge equation for new vertex list • decide what to add to output vertex list • problems: no valid visibility order for • recursive spatial partition • after doing all edges, the polygon is fully clipped • intersecting polygons • viewpoint independent inside outside inside outside inside outside inside outside • cycles of non-intersecting polygons possible p[i] p[i-1] p[i] p[i-1] • for each polygon vertex p[i] p[i-1] • decide what to do based on 4 possibilities p[i] p[i-1] • is vertex inside or outside? • is previous vertex inside or outside? p[i] output i output no output i output p[i] output 5 6 7 8 Review: BSP Trees BSP Demo Clarification: BSP Demo • runtime: correctly traversing this tree enumerates objects from back to front • useful demo: • order of insertion can affect half-plane extent • viewpoint dependent: check which side of plane http://symbolcraft.com/graphics/bsp viewpoint is on at each node • draw far, draw object in question, N F draw near 3 Hidden Surface Removal II F F N N 1 5 4 N F F N N F 2 6 8 7 F N F 1 2 N 9 5 9 6 4 3 8 7 9 10 11 12 Summary: BSP Trees The Z-Buffer Algorithm (mid-70’s) The Z-Buffer Algorithm The Z-Buffer Algorithm • pros: • we know how to rasterize polygons into an • what happens if multiple primitives occupy • BSP trees proposed when memory was • simple, elegant scheme image discretized into pixels: the same pixel on the screen? expensive • correct version of painter’s algorithm back-to-front • which is allowed to paint the pixel? rendering approach • first 512x512 framebuffer was >$50,000! • was very popular for video games (but getting less so) • Ed Catmull proposed a radical new • cons: approach called z-buffering • slow to construct tree: O(n log n) to split, sort • the big idea: • splitting increases polygon count: O(n 2 ) worst-case • resolve visibility independently at each • computationally intense preprocessing stage restricts algorithm to static scenes pixel 13 14 15 16

  2. The Z-Buffer Algorithm The Z-Buffer Algorithm Interpolating Z Z-Buffer • augment color framebuffer with Z-buffer or • idea: retain depth after projection transform • barycentric coordinates • store (r,g,b,z) for each pixel depth buffer which stores Z value at each • each vertex maintains z coordinate • interpolate Z like other • typically 8+8+8+24 bits, can be more pixel planar parameters • relative to eye point • at frame beginning, initialize all pixel depths for all i,j { for all i,j { • can do this with canonical viewing volumes Depth[i,j] = MAX_DEPTH Depth[i,j] = MAX_DEPTH to ∞ Image[i,j] = BACKGROUND_COLOUR Image[i,j] = BACKGROUND_COLOUR • when rasterizing, interpolate depth (Z) } } for all polygons P { for all polygons P { across polygon for all pixels in P { for all pixels in P { • check Z-buffer before storing pixel color in if (Z_pixel < Depth[i,j]) { if (Z_pixel < Depth[i,j]) { Image[i,j] = C_pixel Image[i,j] = C_pixel framebuffer and storing depth in Z-buffer Depth[i,j] = Z_pixel Depth[i,j] = Z_pixel • don’t write pixel if its Z value is more distant } } } } than the Z value already stored there } } 17 18 19 20 Depth Test Precision Depth Test Precision Depth Test Precision Z-Buffer Algorithm Questions • therefore, depth-buffer essentially stores 1/z, • low precision can lead to depth fighting for far objects • how much memory does the Z-buffer use? • reminder: projective transformation maps rather than z! • two different depths in eye space get mapped to same eye-space z to generic z -range (NDC) • does the image rendered depend on the depth in framebuffer • issue with integer depth buffers • simple example: drawing order? • which object “wins” depends on drawing order and scan- • high precision for near objects x 1 0 0 0 x   conversion • does the time to render the image depend on               • low precision for far objects • gets worse for larger ratios f:n the drawing order?   y 0 1 0 0 y         • rule of thumb: f:n < 1000 for 24 bit depth buffer T   =   ⋅   z NDC z • how does Z-buffer load scale with visible   NDC  z   0 0 a b   z  • with 16 bits cannot discern millimeter differences in   polygons? with framebuffer resolution?       objects at 1 km distance    1   0 0 1 0   1  −         • demo: a z b ⋅ + b • thus: sjbaker.org/steve/omniv/love_your_z_buffer.html eye z a = = + NDC z z -z - z eye eye eye -n -n -f -f eye 21 22 23 24 Z-Buffer Pros Z-Buffer Cons Z-Buffer Cons Hidden Surface Removal • poor for scenes with high depth complexity • requires lots of memory • simple!!! • two kinds of visibility algorithms • need to render all polygons, even if • (e.g. 1280x1024x32 bits) • easy to implement in hardware • object space methods most are invisible • requires fast memory • hardware support in all graphics cards today • image space methods • Read-Modify-Write in inner loop • polygons can be processed in arbitrary order • hard to simulate translucent polygons • easily handles polygon interpenetration eye eye • we throw away color of polygons behind • enables deferred shading closest one • rasterize shading parameters (e.g., surface • shared edges are handled inconsistently • works if polygons ordered back-to-front normal) and only shade final visible fragments • ordering dependent • extra work throws away much of the speed advantage 25 26 27 28 Object Space Algorithms Image Space Algorithms Projective Rendering Pipeline Rendering Pipeline object world viewing clipping • determine visibility on object or polygon level • perform visibility test for in screen coordinates glVertex3f(x,y,z) glVertex3f(x,y,z) WCS VCS VCS OCS OCS WCS CCS CCS object world viewing • limited to resolution of display • using camera coordinates alter w alter w Model/View Perspective /w /w VCS Geometry Geometry Model/View Perspective OCS WCS WCS VCS OCS glFrustum(...) (...) Lighting glFrustum Lighting Clipping Clipping • Z-buffer: check every pixel independently Transform. Transform. • resolution independent projection projection Database Database Transform. Transform. modeling modeling viewing viewing transformation transformation • performed late in rendering pipeline transformation transformation transformation transformation clipping (4D) • explicitly compute visible portions of polygons glTranslatef(x,y,z) glTranslatef (x,y,z) gluLookAt gluLookAt(...) (...) / w / w CCS CCS normalized glRotatef glRotatef( (th th,x,y,z) ,x,y,z) • early in pipeline perspective perspective device .... .... normalized division division • after clipping NDCS NDCS OCS - object coordinate system screen glutInitWindowSize(w,h) glutInitWindowSize (w,h) device • requires depth-sorting WCS - world coordinate system glViewport(x,y,a,b) glViewport (x,y,a,b) NDCS NDCS SCS SCS device viewport viewport (3D) (2D) VCS - viewing coordinate system DCS DCS • painter’s algorithm transformation transformation CCS - clipping coordinate system device Frame- Frame- Scan Scan Depth Depth • BSP trees Texturing Texturing Blending Blending DCS DCS Conversion buffer buffer Conversion Test Test NDCS - normalized device coordinate system 29 30 31 32 DCS - device coordinate system

Recommend


More recommend