reading for this time news review clipping
play

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

University of British Columbia Reading for This Time News Review: Clipping CPSC 314 Computer Graphics Project 3 update analytically calculating the portions of Jan-Apr 2007 FCG Chap 12 Graphics Pipeline primitives within the


  1. University of British Columbia Reading for This Time News Review: Clipping CPSC 314 Computer Graphics • Project 3 update • analytically calculating the portions of Jan-Apr 2007 • FCG Chap 12 Graphics Pipeline primitives within the viewport • Linux executable reposted • only 12.1-12.4 Tamara Munzner • FCG Chap 8 Hidden Surfaces • template update • download package again OR Clipping II, Hidden Surfaces I • just change line 31 of src/main.cpp from int resolution[2]; to Week 8, Fri Mar 9 int resolution[] = {100,100}; OR http://www.ugrad.cs.ubc.ca/~cs314/Vjan2007 • implement resolution parsing 2 3 4 Review: Clipping Lines To Viewport Review: Cohen-Sutherland Line Clipping Polygon Clipping • combining trivial accepts/rejects • outcodes • objective • trivially accept lines with both endpoints inside all edges • 4 flags encoding position of a point relative to • 2D: clip polygon against rectangular window of the viewport top, bottom, left, and right boundary • or general convex polygons • trivially reject lines with both endpoints outside the same edge of the viewport • extensions for non-convex or general polygons Clipping II • otherwise, reduce to trivial cases by splitting into two • OC(p1)== 0 && 1010 1010 1000 1000 1001 1001 • 3D: clip polygon against parallelpiped segments y=y y= y max OC(p2)==0 max p3 p3 p1 p1 • trivial accept 0010 0010 0000 0000 0001 0001 • (OC(p1) & p2 p2 OC(p2))!= 0 y=y y= y min min 0110 0100 0101 0110 0100 0101 • trivial reject x=x x max x=x x= x min x= min max 5 6 7 8 Polygon Clipping Why Is Clipping Hard? Why Is Clipping Hard? Polygon Clipping • what happens to a triangle during clipping? • not just clipping all boundary lines • a really tough case: • classes of polygons • some possible outcomes: • may have to introduce new line segments • triangles • convex • concave • holes and self-intersection triangle to quad triangle to triangle triangle to 5-gon • how many sides can result from a triangle? • seven concave polygon to multiple polygons 9 10 11 12 Sutherland-Hodgeman Clipping Sutherland-Hodgeman Clipping Sutherland-Hodgeman Clipping Sutherland-Hodgeman Clipping • basic idea: • basic idea: • basic idea: • basic idea: • consider each edge of the viewport individually • consider each edge of the viewport individually • consider each edge of the viewport individually • consider each edge of the viewport individually • clip the polygon against the edge equation • clip the polygon against the edge equation • clip the polygon against the edge equation • clip the polygon against the edge equation • after doing all edges, the polygon is fully clipped • after doing all edges, the polygon is fully clipped • after doing all edges, the polygon is fully clipped • after doing all edges, the polygon is fully clipped 13 14 15 16

  2. Sutherland-Hodgeman Clipping Sutherland-Hodgeman Clipping Sutherland-Hodgeman Clipping Sutherland-Hodgeman Clipping • basic idea: • basic idea: • basic idea: • basic idea: • consider each edge of the viewport individually • consider each edge of the viewport individually • consider each edge of the viewport individually • consider each edge of the viewport individually • clip the polygon against the edge equation • clip the polygon against the edge equation • clip the polygon against the edge equation • clip the polygon against the edge equation • after doing all edges, the polygon is fully clipped • after doing all edges, the polygon is fully clipped • after doing all edges, the polygon is fully clipped • after doing all edges, the polygon is fully clipped 17 18 19 20 Sutherland-Hodgeman Clipping Sutherland-Hodgeman Algorithm Clipping Against One Edge Clipping Against One Edge • basic idea: • input/output for whole algorithm • p[i] inside: 2 cases • p[i] outside: 2 cases • consider each edge of the viewport individually • input: list of polygon vertices in order • clip the polygon against the edge equation • output: list of clipped polygon vertices consisting of old vertices (maybe) and new vertices (maybe) • after doing all edges, the polygon is fully clipped inside inside outside outside inside inside outside outside inside inside outside outside inside inside outside outside • input/output for each step p[i-1] p[i-1] p[i] p[i] p[i-1] p[i-1] • input: list of vertices • output: list of vertices, possibly with changes • basic routine p[i-1] p[i-1] p p p p • go around polygon one vertex at a time p[i] p[i] • decide what to do based on 4 possibilities p[i] p[i] p[i-1] p[i-1] • is vertex inside or outside? p[i] p[i] • is previous vertex inside or outside? output: p[i] p[i] output: p, p, p[i] p[i] output: p p output: nothing output: output: output: output: nothing 21 22 23 24 Clipping Against One Edge Sutherland-Hodgeman Example Sutherland-Hodgeman Discussion clipPolygonToEdge( p[n], edge ) { • similar to Cohen/Sutherland line clipping for( i= 0 ; i< n ; i++ ) { • inside/outside tests: outcodes if( p[i] inside edge ) { inside inside outside • intersection of line segment with edge: outside if( p[i-1] inside edge ) output p[i]; // p[-1]= p[n-1] window-edge coordinates p7 p7 else { p6 p6 p5 p5 • clipping against individual edges independent p= intersect( p[i-1], p[i], edge ); output p, p[i]; Hidden Surface Removal p3 p3 } p4 p4 • great for hardware (pipelining) } else { // p[i] is outside edge • all vertices required in memory at same time p2 p2 p0 p0 if( p[i-1] inside edge ) { • not so good, but unavoidable p= intersect(p[i-1], p[I], edge ); output p; • another reason for using triangles only in p1 p1 } hardware rendering } } 25 26 27 28 Occlusion Painter’s Algorithm Painter’s Algorithm: Problems Analytic Visibility Algorithms • early visibility algorithms computed the set of visible • for most interesting scenes, some polygons • simple: render the polygons from back to • intersecting polygons present a problem polygon fragments directly, then rendered the overlap front, “painting over” previous polygons • even non-intersecting polygons can form a fragments to a display: cycle with no valid visibility order: • to render the correct image, we need to • draw blue, then green, then orange determine which polygons occlude which • will this work in the general case? 29 30 31 32

  3. Analytic Visibility Algorithms Analytic Visibility Algorithms Binary Space Partition Trees (1979) Creating BSP Trees: Objects • what is the minimum worst-case cost of • so, for about a decade (late 60s to late 70s) • BSP Tree: partition space with binary tree of computing the fragments for a scene there was intense interest in finding efficient planes composed of n polygons? algorithms for hidden surface removal • idea: divide space recursively into half-spaces by choosing splitting planes that separate • answer: • we’ll talk about one: objects in scene O( n 2 ) • Binary Space Partition (BSP) Trees • preprocessing: create binary tree of planes • runtime: correctly traversing this tree enumerates objects from back to front 33 34 35 36 Creating BSP Trees: Objects Creating BSP Trees: Objects Creating BSP Trees: Objects Creating BSP Trees: Objects 37 38 39 40 Splitting Objects Traversing BSP Trees Traversing BSP Trees BSP Trees : Viewpoint A • tree creation independent of viewpoint • no bunnies were harmed in previous query: given a viewpoint, produce an ordered list of (possibly • preprocessing step split) objects from back to front: example • tree traversal uses viewpoint • but what if a splitting plane passes through renderBSP(BSPtree *T) • runtime, happens for many different viewpoints BSPtree *near, *far; an object? • each plane divides world into near and far if ( eye on left side of T->plane ) • for given viewpoint, decide which side is near and • split the object; give half to each node near = T->left; far = T->right; which is far else • check which side of plane viewpoint is on independently for each tree vertex near = T->right; far = T->left; Ouch • tree traversal differs depending on viewpoint! renderBSP(far); • recursive algorithm if ( T is a leaf node ) • recurse on far side renderObject(T) • draw object renderBSP(near); • recurse on near side 41 42 43 44 BSP Trees : Viewpoint A BSP Trees : Viewpoint A BSP Trees : Viewpoint A BSP Trees : Viewpoint A N F N N N N F F F F F F F F F N N N N N F F N F N N ν decide independently at each tree vertex ν not just left or right child! 45 46 47 48

Recommend


More recommend