University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Interpolation Clipping.

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
Advertisements

Rezanje črt in poligonov. World window & viewport window viewport screen window world window.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
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.
CS 551 / 645: Introductory Computer Graphics Clipping Lines and Polygons.
CS 445 / 645 Introduction to Computer Graphics Lecture 9 Clipping Clipping.
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)
Two-Dimensional Viewing Jehee Lee Seoul National University.
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.
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Clipping Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009.
University of British Columbia CPSC 314 Computer Graphics May-June 2005 Tamara Munzner Compositing, Clipping,
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 2007 Tamara Munzner Clipping II, Hidden Surfaces.
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
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,
Texturing, Clipping Week 9, Mon 27 Oct 2003
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Clipping.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Visibility Week 7, Wed.
Graphics Pipeline Clipping CMSC 435/634. Graphics Pipeline Object-order approach to rendering Sequence of operations – Vertex processing – Transforms.
2/26/04© University of Wisconsin, CS559 Spring 2004 Last Time General Orthographic Viewing –Specifying cameras in world coordinates –Building world  view.
UBI 516 Advanced Computer Graphics Two Dimensional Viewing ( Chapter 6 ) Aydın Öztürk Two Dimensional.
2-Dimension Viewing and Clipping
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Clipping II, Hidden Surfaces.
CS 551 / 645: Introductory Computer Graphics
Objectives Introduce basic implementation strategies Clipping Scan conversion.
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by David Luebke)
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
CSE Real Time Rendering Week 9. Post Geometry Shaders Courtesy: E. Angel and D. Shreiner – Interactive Computer Graphics 6E © Addison-Wesley 2012.
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.
Implementation II.
1 Visiblity: Culling and Clipping Computer Graphics COMP 770 (236) Spring 2009 January 21 & 26: 2009.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Rasterization.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Scan Conversion Week 5, Fri 3 Oct 2003 recap: shading scan conversion: lines.
1 Computer Graphics Clipping Fall FCC Line Clipping What happens when one or both endpoints of a line segment are not inside the specified drawing.
Computer Graphics Lecture 20 Fasih ur Rehman. Last Class Clipping – What is clipping – Why we do clipping – How clipping is done.
Computer Graphics I, Fall 2010 Implementation II.
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
Clipping Primitives. Clipping line Clipping rectangle: – x min to x max – y min to y max A point (x,y) lies within a clip rectangle and thus displayed.
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Rasterization II Week.
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
Lecture 9 From Vertices to Fragments. Objectives Introduce basic implementation strategies Clipping Rasterization hidden-surface removal.
Computer Graphics Clipping.
Computer Graphics CC416 Week 13 Clipping.
Transformations contd.
CS 551 / 645: Introductory Computer Graphics
Computer Graphics Shading in OpenGL
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Concepts, algorithms for clipping
Graphics Pipeline Clipping
WINDOWING AND CLIPPING
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
WINDOWING AND CLIPPING
Lecture 13 Clipping & Scan Conversion
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Clipping Polygons Dr. Scott Schaefer.
Clipping University of British Columbia CPSC 314 Computer Graphics
Presentation transcript:

University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Interpolation Clipping Week 7, Mon Feb 21

2 News grades for p1, h2 posted

3 Interpolation

4 Scan Conversion done how to determine pixels covered by a primitive next how to assign pixel colors interpolation of colors across triangles interpolation of other properties

5 Interpolation During Scan Conversion interpolate values between vertices z values r,g,b colour components use for Gouraud shading u,v texture coordinates surface normals equivalent methods (for triangles) bilinear interpolation barycentric coordinates

6 Bilinear Interpolation interpolate quantity along L and R edges, as a function of y then interpolate quantity as a function of x y P(x,y) P1P1P1P1 P2P2P2P2 P3P3P3P3 PLPLPLPL PRPRPRPR

7 Barycentric Coordinates weighted combination of vertices (1,0,0) (0,1,0) (0,0,1) “convex combination of points” of points”

8 P2P2P2P2 P3P3P3P3 P1P1P1P1 PLPLPLPL PRPRPRPR P d 2 : d 1 Computing Barycentric Coordinates for point P on scanline

9 Computing Barycentric Coordinates similarly b 1 : b 2 P2P2P2P2 P3P3P3P3 P1P1P1P1 PLPLPLPL PRPRPRPR P d 2 : d 1

10 b 1 : b 2 P2P2P2P2 P3P3P3P3 P1P1P1P1 PLPLPLPL PRPRPRPR P d 2 : d 1 c 1 : c 2 Computing Barycentric Coordinates combining gives

11 Computing Barycentric Coordinates thus

12 Computing Barycentric Coordinates can verify barycentric properties

13 Clipping

14 Reading FCG Chapter 11 pp only: clipping

15 Rendering Pipeline GeometryDatabaseGeometryDatabase Model/ViewTransform.Model/ViewTransform. LightingLightingPerspectiveTransform.PerspectiveTransform. ClippingClipping ScanConversionScanConversion DepthTestDepthTest TexturingTexturing BlendingBlending Frame-bufferFrame-buffer

16 Next Topic: Clipping we’ve been assuming that all primitives (lines, triangles, polygons) lie entirely within the viewport in general, this assumption will not hold:

17 Clipping analytically calculating the portions of primitives within the viewport

18 Why Clip? bad idea to rasterize outside of framebuffer bounds also, don’t waste time scan converting pixels outside window could be billions of pixels for very close objects!

19 Line Clipping 2D determine portion of line inside an axis-aligned rectangle (screen or window) 3D determine portion of line inside axis-aligned parallelpiped (viewing frustum in NDC) simple extension to 2D algorithms

20 Clipping naïve approach to clipping lines: for each line segment for each edge of viewport find intersection point pick “nearest” point if anything is left, draw it what do we mean by “nearest”? how can we optimize this? A B C D

21 Trivial Accepts big optimization: trivial accept/rejects Q: how can we quickly determine whether a line segment is entirely inside the viewport? A: test both endpoints

22 Trivial Rejects Q: how can we know a line is outside viewport? A: if both endpoints on wrong side of same edge, can trivially reject line

23 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

24 Cohen-Sutherland Line Clipping outcodes 4 flags encoding position of a point relative to top, bottom, left, and right boundary OC( p1 )=0010 OC( p2 )=0000 OC( p3 )=1001 x=x min x=x max y=y min y=y max p1 p2 p3

25 Cohen-Sutherland Line Clipping assign outcode to each vertex of line to test line segment: ( p1,p2 ) trivial cases OC( p1 )== 0 && OC( p2 )==0 both points inside window, thus line segment completely visible (trivial accept) (OC( p1 ) & OC( p2 ))!= 0 there is (at least) one boundary for which both points are outside (same flag set in both outcodes) thus line segment completely outside window (trivial reject)

26 Cohen-Sutherland Line Clipping if line cannot be trivially accepted or rejected, subdivide so that one or both segments can be discarded pick an edge that the line crosses (how?) intersect line with edge (how?) discard portion on wrong side of edge and assign outcode to new vertex apply trivial accept/reject tests; repeat if necessary

27 Cohen-Sutherland Line Clipping if line cannot be trivially accepted or rejected, subdivide so that one or both segments can be discarded pick an edge that the line crosses check against edges in same order each time for example: top, bottom, right, left A B D E C

28 Cohen-Sutherland Line Clipping intersect line with edge (how?) A B D E C

29 discard portion on wrong side of edge and assign outcode to new vertex apply trivial accept/reject tests and repeat if necessary Cohen-Sutherland Line Clipping A B D C

30 Viewport Intersection Code (x 1, y 1 ), (x 2, y 2 ) intersect vertical edge at x right y intersect = y 1 + m(x right – x 1 ) m=(y 2 -y 1 )/(x 2 -x 1 ) (x 1, y 1 ), (x 2, y 2 ) intersect horiz edge at y bottom x intersect = x 1 + (y bottom – y 1 )/m m=(y 2 -y 1 )/(x 2 -x 1 ) (x 2, y 2 ) (x 1, y 1 ) x right (x 2, y 2 ) (x 1, y 1 ) y bottom

31 Cohen-Sutherland Discussion use opcodes to quickly eliminate/include lines best algorithm when trivial accepts/rejects are common must compute viewport clipping of remaining lines non-trivial clipping cost redundant clipping of some lines more efficient algorithms exist

32 Line Clipping in 3D approach clip against parallelpiped in NDC after perspective transform means that clipping volume always the same xmin=ymin= -1, xmax=ymax= 1 in OpenGL boundary lines become boundary planes but outcodes still work the same way additional front and back clipping plane zmin = -1, zmax = 1 in OpenGL

33 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

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

35 what happens to a triangle during clipping? possible outcomes: triangle  triangle Why Is Clipping Hard? triangle  quad triangle  5-gon how many sides can a clipped triangle have?

36 How Many Sides? seven…

37 a really tough case: Why Is Clipping Hard?

38 a really tough case: Why Is Clipping Hard? concave polygon  multiple polygons

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

40 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

41 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

42 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

43 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

44 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

45 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

46 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

47 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

48 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

49 Sutherland-Hodgeman Algorithm input/output for algorithm input: list of polygon vertices in order output: list of clipped poygon vertices consisting of old vertices (maybe) and new vertices (maybe) 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?

50 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]

51 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

52 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; }

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

54 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

55 Sutherland/Hodgeman Discussion for rendering pipeline: re-triangulate resulting polygon (can be done for every individual clipping edge)