University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Clipping II, Hidden Surfaces.

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
Advertisements

Rezanje črt in poligonov. World window & viewport window viewport screen window world window.
10/10/02 (c) 2002 University of Wisconsin, CS 559 Last Time Finished viewing: Now you know how to: –Define a region of space that you wish to view – the.
David Luebke5/11/2015 CS 551 / 645: Introductory Computer Graphics David Luebke
CS 551 / 645: Introductory Computer Graphics Visible Surface Determination.
Visibility in Computer Graphics Toni Sellarès Unversitat de Girona
CS 551 / 645: Introductory Computer Graphics Clipping Lines and Polygons.
Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)
Computer Graphics Viewing.
Viewing & Clipping In 2D. 2 of 44 Contents Windowing Concepts Clipping –Introduction –Brute Force –Cohen-Sutherland Clipping Algorithm Area Clipping –Sutherland-Hodgman.
CS 445 / 645: Introductory Computer Graphics
UBI 516 Advanced Computer Graphics
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Clipping Week 8, Wed Mar.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Interpolation Clipping.
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
1 Dr. Scott Schaefer Hidden Surfaces. 2/62 Hidden Surfaces.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Advanced Rendering II,
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Advanced Rendering III,
Hidden Surface Elimination Wen-Chieh (Steve) Lin Institute of Multimedia Engineering I-Chen Lin’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals.
Texturing, Clipping Week 9, Mon 27 Oct 2003
1 CSCE 441: Computer Graphics Hidden Surface Removal (Cont.) Jinxiang Chai.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Visibility II Week 7,
1 Clipping and Hidden Surfaces CS-184: Computer Graphics Prof. James O’Brien.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Hidden Surfaces II Week.
Vertices and Fragments III Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
Spatial Data Structure: Quadtree, Octree,and BSP tree Mengxia Zhu Fall 2007.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Visibility Week 9, Fri 31 Oct 2003.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Visibility Week 7, Wed.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Visibility: Z Buffering Week 10, Mon 3 Nov 2003.
Graphics Pipeline Clipping CMSC 435/634. Graphics Pipeline Object-order approach to rendering Sequence of operations – Vertex processing – Transforms.
Hidden Surface Removal
2-Dimension Viewing and Clipping
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Clipping II, Hidden Surfaces.
10/29/02 (c) 2002 University of Wisconsin, CS559 Today Hidden Surface Removal Exact Visibility.
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by David Luebke)
CS-378: Game Technology Lecture #2.2: Clipping and Hidden Surfaces Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney,
Windows, Viewports, and Clipping
1Computer Graphics Implementation II Lecture 16 John Shearer Culture Lab – space 2
Implementation II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Binary Space Partitioning Trees Ray Casting Depth Buffering
Implementation II.
Computer Graphics Zhen Jiang West Chester University.
David Luebke 1 12/8/2015 Visibility CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
Computer Graphics I, Fall 2010 Implementation II.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
01/28/09Dinesh Manocha, COMP770 Visibility Computations Visible Surface Determination Visibility Culling.
Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 5 Hidden Surface Removal and Rasterization Taku Komura.
Hidden Surfaces University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner.
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
CS 445 / 645 Introduction to Computer Graphics Lecture 21 Visibility Visibility.
Computer Graphics Clipping.
Computer Graphics Implementation II
CS 551 / 645: Introductory Computer Graphics
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Hidden Surfaces Dr. Scott Schaefer.
Graphics Pipeline Clipping
CSCE 441: Computer Graphics Hidden Surface Removal
Implementation II Ed Angel Professor Emeritus of Computer Science
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Visibility: Z Buffering Week 10, Mon 3 Nov 2003
Hidden Surfaces II Week 9, Mon Mar 15
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
© University of Wisconsin, CS559 Fall 2004
Introduction to Computer Graphics with WebGL
Clipping Polygons Dr. Scott Schaefer.
Clipping University of British Columbia CPSC 314 Computer Graphics
Implementation II Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Clipping II, Hidden Surfaces I Week 8, Fri Mar 9

2 Reading for This Time FCG Chap 12 Graphics Pipeline only FCG Chap 8 Hidden Surfaces

3 News Project 3 update Linux executable reposted template update download package again OR just change line 31 of src/main.cpp from int resolution[2]; to int resolution[] = {100,100}; OR implement resolution parsing

4 Review: Clipping analytically calculating the portions of primitives within the viewport

5 Review: Clipping Lines To Viewport combining trivial accepts/rejects trivially accept lines with both endpoints inside all edges of the viewport trivially reject lines with both endpoints outside the same edge of the viewport otherwise, reduce to trivial cases by splitting into two segments

6 Review: Cohen-Sutherland Line Clipping outcodes 4 flags encoding position of a point relative to top, bottom, left, and right boundary x=x min x=x max y=y min y=y max p1 p2 p3 OC(p1)== 0 && OC(p2)==0 trivial accept (OC(p1) & OC(p2))!= 0 trivial reject

7 Clipping II

8 Polygon Clipping objective 2D: clip polygon against rectangular window or general convex polygons extensions for non-convex or general polygons 3D: clip polygon against parallelpiped

9 Polygon Clipping not just clipping all boundary lines may have to introduce new line segments

10 what happens to a triangle during clipping? some possible outcomes: how many sides can result from a triangle? seven triangle to triangle Why Is Clipping Hard? triangle to quad triangle to 5-gon

11 a really tough case: Why Is Clipping Hard? concave polygon to multiple polygons

12 Polygon Clipping classes of polygons triangles convex concave holes and self-intersection

13 Sutherland-Hodgeman Clipping basic idea: consider each edge of the viewport individually clip the polygon against the edge equation after doing all edges, the polygon is fully clipped

14 Sutherland-Hodgeman Clipping basic idea: consider each edge of the viewport individually clip the polygon against the edge equation after doing all edges, the polygon is fully clipped

15 Sutherland-Hodgeman Clipping basic idea: consider each edge of the viewport individually clip the polygon against the edge equation after doing all edges, the polygon is fully clipped

16 Sutherland-Hodgeman Clipping basic idea: consider each edge of the viewport individually clip the polygon against the edge equation after doing all edges, the polygon is fully clipped

17 Sutherland-Hodgeman Clipping basic idea: consider each edge of the viewport individually clip the polygon against the edge equation after doing all edges, the polygon is fully clipped

18 Sutherland-Hodgeman Clipping basic idea: consider each edge of the viewport individually clip the polygon against the edge equation after doing all edges, the polygon is fully clipped

19 Sutherland-Hodgeman Clipping basic idea: consider each edge of the viewport individually clip the polygon against the edge equation after doing all edges, the polygon is fully clipped

20 Sutherland-Hodgeman Clipping basic idea: consider each edge of the viewport individually clip the polygon against the edge equation after doing all edges, the polygon is fully clipped

21 Sutherland-Hodgeman Clipping basic idea: consider each edge of the viewport individually clip the polygon against the edge equation after doing all edges, the polygon is fully clipped

22 Sutherland-Hodgeman Algorithm input/output for whole algorithm input: list of polygon vertices in order output: list of clipped polygon vertices consisting of old vertices (maybe) and new vertices (maybe) input/output for each step input: list of vertices output: list of vertices, possibly with changes basic routine go around polygon one vertex at a time decide what to do based on 4 possibilities is vertex inside or outside? is previous vertex inside or outside?

23 Clipping Against One Edge p[i] inside: 2 cases outsideinsideinsideoutside p[i] p[i-1] output: p[i] p[i] p[i-1] p output: p, p[i]

24 Clipping Against One Edge p[i] outside: 2 cases p[i] p[i-1] output: p p[i] p[i-1] p output: nothing outsideinsideinsideoutside

25 Clipping Against One Edge clipPolygonToEdge( p[n], edge ) { for( i= 0 ; i< n ; i++ ) { if( p[i] inside edge ) { if( p[i-1] inside edge ) output p[i]; // p[-1]= p[n-1] else { p= intersect( p[i-1], p[i], edge ); output p, p[i]; } } else { // p[i] is outside edge if( p[i-1] inside edge ) { p= intersect(p[i-1], p[I], edge ); output p; }

26 Sutherland-Hodgeman Example inside outside p0 p1 p2 p3 p4 p5 p7 p6

27 Sutherland-Hodgeman Discussion similar to Cohen/Sutherland line clipping inside/outside tests: outcodes intersection of line segment with edge: window-edge coordinates clipping against individual edges independent great for hardware (pipelining) all vertices required in memory at same time not so good, but unavoidable another reason for using triangles only in hardware rendering

28 Hidden Surface Removal

29 Occlusion for most interesting scenes, some polygons overlap to render the correct image, we need to determine which polygons occlude which

30 Painter’s Algorithm simple: render the polygons from back to front, “painting over” previous polygons draw blue, then green, then orange will this work in the general case?

31 Painter’s Algorithm: Problems intersecting polygons present a problem even non-intersecting polygons can form a cycle with no valid visibility order:

32 Analytic Visibility Algorithms early visibility algorithms computed the set of visible polygon fragments directly, then rendered the fragments to a display:

33 Analytic Visibility Algorithms what is the minimum worst-case cost of computing the fragments for a scene composed of n polygons? answer: O(n 2 )

34 Analytic Visibility Algorithms so, for about a decade (late 60s to late 70s) there was intense interest in finding efficient algorithms for hidden surface removal we’ll talk about one: Binary Space Partition (BSP) Trees

35 Binary Space Partition Trees (1979) BSP Tree: partition space with binary tree of planes idea: divide space recursively into half-spaces by choosing splitting planes that separate objects in scene preprocessing: create binary tree of planes runtime: correctly traversing this tree enumerates objects from back to front

36 Creating BSP Trees: Objects

37 Creating BSP Trees: Objects

38 Creating BSP Trees: Objects

39 Creating BSP Trees: Objects

40 Creating BSP Trees: Objects

41 Splitting Objects no bunnies were harmed in previous example but what if a splitting plane passes through an object? split the object; give half to each node Ouch

42 Traversing BSP Trees tree creation independent of viewpoint preprocessing step tree traversal uses viewpoint runtime, happens for many different viewpoints each plane divides world into near and far for given viewpoint, decide which side is near and which is far check which side of plane viewpoint is on independently for each tree vertex tree traversal differs depending on viewpoint! recursive algorithm recurse on far side draw object recurse on near side

43 Traversing BSP Trees renderBSP(BSPtree *T) BSPtree *near, *far; if (eye on left side of T->plane) near = T->left; far = T->right; else near = T->right; far = T->left; renderBSP(far); if (T is a leaf node) renderObject(T) renderBSP(near); query: given a viewpoint, produce an ordered list of (possibly split) objects from back to front:

44 BSP Trees : Viewpoint A

45 BSP Trees : Viewpoint A F N F N

46 BSP Trees : Viewpoint A F N F N F N decide independently at each tree vertex not just left or right child!

47 BSP Trees : Viewpoint A F N F N NF F N

48 BSP Trees : Viewpoint A F N F N NF F N

49 BSP Trees : Viewpoint A F N F N F N NF 1 1

50 BSP Trees : Viewpoint A F N F N F N FNNF

51 BSP Trees : Viewpoint A F N F N F N FN NF NF

52 BSP Trees : Viewpoint A F N F N F N FN NF NF

53 BSP Trees : Viewpoint A F N F N F N FN NF NF

54 BSP Trees : Viewpoint A F N F N FN NF NF F N 12 34

55 BSP Trees : Viewpoint A F N F N FN NF NF F N

56 BSP Trees : Viewpoint A F N F N FN NF NF F N FN F N

57 BSP Trees : Viewpoint B N F F N F N FN FN F N F N NF

58 BSP Trees : Viewpoint B N F F N F N FN FN F N F N NF

59 BSP Tree Traversal: Polygons split along the plane defined by any polygon from scene classify all polygons into positive or negative half-space of the plane if a polygon intersects plane, split polygon into two and classify them both recurse down the negative half-space recurse down the positive half-space

60 BSP Demo useful demo:

61 Summary: BSP Trees pros: simple, elegant scheme correct version of painter’s algorithm back-to-front rendering approach was very popular for video games (but getting less so) cons: slow to construct tree: O(n log n) to split, sort splitting increases polygon count: O(n 2 ) worst-case computationally intense preprocessing stage restricts algorithm to static scenes