Objectives Introduce basic implementation strategies Clipping Scan conversion.

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
Advertisements

From Vertices to Fragments
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
1 Clipping. 2 Transformation Sequence X Y Z X Y Z X Y Z X Y Z Object Coords. Eye Coords. Clip Coords. Normalized Device Coords. Screen Coords. Implementation:
Two-Dimensional Viewing Jehee Lee Seoul National University.
Computer Graphics Viewing.
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
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.
Implementation Dr. Amy Zhang. Reading 2  Hill, Chapters  Hill, Chapter 10.
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Implementation III Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
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,
Graphics Pipeline Clipping CMSC 435/634. Graphics Pipeline Object-order approach to rendering Sequence of operations – Vertex processing – Transforms.
Objectives Review some advanced topics, including Review some advanced topics, including Chapter 8: Implementation Chapter 8: Implementation Chapter 9:
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Chapter 7: From Vertices to Fragments Ed Angel Professor of Computer Science, Electrical.
Triangle Scan Conversion. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rasterization Rasterization (scan conversion) –Determine which.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
22 Implementation Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Many changes – Jeff.
From Vertices to Fragments Chapter 7. Part I Objectives Introduce basic implementation strategies Introduce basic implementation strategies Clipping Clipping.
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
1Computer Graphics Implementation III Lecture 17 John Shearer Culture Lab – space 2
Introduction to Computer Graphics with WebGL
CS 480/680 Computer Graphics Implementation III Dr. Frederick C Harris, Jr. Fall 2011.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Week 3 Lecture 1: Implementation Based on Interactive Computer Graphics (Angel) - Chapter.
CSE Real Time Rendering Week 9. Post Geometry Shaders Courtesy: E. Angel and D. Shreiner – Interactive Computer Graphics 6E © Addison-Wesley 2012.
COMPUTER GRAPHICS Hochiminh city University of Technology Faculty of Computer Science and Engineering CHAPTER 07: Rasterization.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Implementation of a Renderer Consider Programs are processd by the system line & polygon, outside the view volume Efficiently Understanding of the implementation.
Computer Graphics I, Fall 2010 Implementation II.
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
Lecture 9 From Vertices to Fragments. Objectives Introduce basic implementation strategies Clipping Rasterization hidden-surface removal.
Computer Graphics I, Fall 2010 Scan conversion algorithms.
Chapter 71 Computer Graphics - Chapter 7 From Vertices to Fragments Objectives are: How your program are processed by the system that you are using, Learning.
Computer Graphics Implementation II
Introduction to Computer Graphics with WebGL
Computer Graphics CC416 Week 13 Clipping.
Transformations contd.
Computer Graphics Shading in OpenGL
University of New Mexico
Implementation III.
Implementation I Ed Angel
Graphics Pipeline Clipping
Introduction to Computer Graphics with WebGL
Computer Graphics : Viewing In 2D
Implementation II Ed Angel Professor Emeritus of Computer Science
Course code: 10CS65 | Computer Graphics and Visualization
Rasterization and Antialiasing
Lecture 13 Clipping & Scan Conversion
Computer Graphics Implementation III
Rasterization and Antialiasing
Introduction to Computer Graphics with WebGL
From Vertices To Fragments
Clipping Clipping Sutherland-Hodgman Clipping
Clipping University of British Columbia CPSC 314 Computer Graphics
Implementation I Ed Angel Professor Emeritus of Computer Science
Implementation III Ed Angel Professor Emeritus of Computer Science
Implementation II Ed Angel Professor Emeritus of Computer Science
From Vertex to Fragment
From Vertex to Fragment
Presentation transcript:

Objectives Introduce basic implementation strategies Clipping Scan conversion

Major tasks (1) Modeling: results in sets of vertices that specify a group of geometric objects supported by the rest of the system ­E.g. GL_POLYGON in OpenGL ­Modeler is usually an application program that may be interactive

Major tasks (2) Geometry Processing: works with vertices involves a number of transformations

Modeling transformations Viewing transformation Projection transformation Clipping Perspective division NDC to viewport (window coordinates) 3D WORLD 3D World 3D camera 3D clip 3D NDC 2D window (with depth) “Normalized View Volume”

Projection Transformation OpenGL transforms vertices by a projection transformation to a normalized view volume (cube centered at origin, with side length 2). These coordinates are referred to as normalized device coordinates No matter how the viewing volume was specified by the user (e.g. glOrtho or gluPerspective)

Perspective Projection z y Z=-near Z=-far z y (far) -1(near) Viewing frustum Normalized view volume viewer

Normalized Device Coordinates (x,y) coordinates indicate the projected point on the final viewing window. ­Orthogonal projection of the distorted shape in the normalized volume is equivalent to perspective projection of the original shape z coordinate is used for depth ­There is a reversal of z coordinates: the points closest to the viewer have smaller z coordinates ­Z coordinates went through a nonlinear shortening, however relative order of z coordinates are maintained—that is sufficient for hidden surface removal

Why normalization? To simplify clipping ­Now primitives are clipped with respect to the same shape! ­In fact, clipping takes place before the perspective division (division by w): still an axis aligned rectangular box. To avoid division operation for parts that are not going to be visible in the window at the end! Clip coordinates

Clipping 2D against clipping window 3D against clipping volume Easy for line segments polygons Hard for curves and text ­Convert to lines and polygons first

Clipping 2D Line Segments Brute force approach: compute intersections with all sides of clipping window ­Inefficient: one division per intersection

Cohen-Sutherland Algorithm Idea: eliminate as many cases as possible without computing intersections Start with four lines that determine the sides of the clipping window x = x max x = x min y = y max y = y min

The Cases Case 1: both endpoints of line segment inside all four lines ­Draw (accept) line segment as is Case 2: both endpoints outside all lines and on same side of a line ­Discard (reject) the line segment x = x max x = x min y = y max y = y min

The Cases Case 3: One endpoint inside, one outside ­Must do at least one intersection Case 4: Both outside ­May have part inside ­Must do at least one intersection x = x max x = x min y = y max

Defining Outcodes For each endpoint, define an outcode Outcodes divide space into 9 regions Computation of outcode requires at most 4 subtractions b0b1b2b3b0b1b2b3 b 0 = 1 if y > y max, 0 otherwise b 1 = 1 if y < y min, 0 otherwise b 2 = 1 if x > x max, 0 otherwise b 3 = 1 if x < x min, 0 otherwise

Using Outcodes Consider the 5 cases below AB: outcode(A) = outcode(B) = 0 ­Accept line segment

Using Outcodes CD: outcode (C) = 0, outcode(D)  0 ­Compute intersection ­Location of 1 in outcode(D) determines which edge to intersect with ­Note if there were a segment from A to a point in a region with 2 ones in outcode, we might have to do two intersections

Using Outcodes EF: outcode(E) logically ANDed with outcode(F) (bitwise)  0 ­Both outcodes have a 1 bit in the same place ­Line segment is outside of corresponding side of clipping window ­reject

Using Outcodes GH and IJ: same outcodes, neither zero but logical AND yields zero Shorten line segment by intersecting with one of sides of window Compute outcode of intersection (new endpoint of shortened line segment) Reexecute algorithm

Efficiency In many applications, the clipping window is small relative to the size of the whole data base ­Most line segments are outside one or more side of the window and can be eliminated based on their outcodes Inefficiency when code has to be reexecuted for line segments that must be shortened in more than one step

Cohen Sutherland in 3D Use 6-bit outcodes When needed, clip line segment against planes

Liang-Barsky Clipping Consider the parametric form of a line segment (works in both 2- and 3-dimensions) We can distinguish between the cases by looking at the ordering of the values of  where the line determined by the line segment crosses the lines that determine the window p(  ) = (1-  )p 1 +  p 2 1  0 p1p1 p2p2

Liang-Barsky Clipping In (a):  4 >  3 >  2 >  1 ­Intersect right, top, left, bottom: shorten In (b):  4 >  2 >  3 >  1 ­Intersect right, left, top, bottom: reject

Liang-Barsky Clipping Efficient implementation requires avoiding computing intersections until they are needed. We also want to avoid divisions when possible.

Liang-Barsky Clipping The intersection with top line (y= ymax) is at Rewrite equation as It is possible to restate all the rules in terms of

Liang-Barsky Clipping Many lines can be rejected before all 4 intersections are known. ­E.g. if, reject

Liang-Barsky Clipping Can accept/reject as easily as with Cohen-Sutherland Using values of , we do not have to use algorithm recursively as with C-S Extends to 3D ­We are now clipping lines against planes (six of them)

Plane-Line Intersections

Plane-line intersection The above equation requires six multiplications and divisions! However, the normalized viewing volume has axis aligned planes ­Reduces to a single division just like in 2D. E.g.

Polygon Clipping Not as simple as line segment clipping ­Clipping a line segment yields at most one line segment ­Clipping a polygon can yield multiple polygons However, clipping a convex polygon can yield at most one other polygon

Tessellation and Convexity Either do not allow nonconvex polygons or replace nonconvex (concave) polygons with a set of triangular polygons (a tessellation)

Clipping as a Black Box Can consider line segment clipping as a process that takes in two vertices and produces either no vertices or the vertices of a clipped line segment

Pipeline Clipping of Line Segments Clipping against each side of window is independent of other sides ­Can use four independent clippers in a pipeline

Pipeline Clipping of Polygons Clip edges of polygons successively Three dimensions: add front and back clippers Strategy used in SGI Geometry Engine Small increase in latency

Therefore clipped polygon is P, Q, R, S. Clipping to One Boundary Consider each polygon edge in turn Four cases: ­ENTER: ­STAY IN: ­LEAVE: ­STAY OUT: inside P Q Output P, Q R Output R S Output S (no output)

Clipping Example Works for more nonconvex shapes. Input Case Output 1 start - 2 stay in 2 3 leave A 4 stay out - 5 enter B, 5 6 leave C 7 stay out - 1 enter D, 1 2 A B 5 C D A D C B inside

Bounding Boxes Rather than doing clipping on a complex polygon, we can use an axis-aligned bounding box or extent ­Smallest rectangle aligned with axes that encloses the polygon ­Simple to compute: max and min of x and y

Bounding boxes Can usually determine accept/reject based only on bounding box reject accept requires detailed clipping

Rasterization Rasterization (scan conversion) ­Shade pixels that are inside an object specified by a set of vertices Line segments Polygons: scan conversion = fill Shades determined by color, texture, shading model Here we study algorithms for determining the correct pixels starting with the vertices

Scan Conversion of Line Segments Start with line segment in window coordinates with integer values for endpoints Assume implementation has a write_pixel function y = mx + h

DDA Algorithm Digital Differential Analyzer ­DDA was a mechanical device for numerical solution of differential equations ­Line y=mx+ h satisfies differential equation dy/dx = m =  y/  x = y 2 -y 1 /x 2 -x 1 Along scan line  x = 1 For(x=x1; x<=x2, x++) { y+=m; write_pixel(x, round(y), line_color) }

Problem DDA = for each x plot pixel at closest y ­Problems for steep lines

Using Symmetry Use for 1  m  0 For m > 1, swap role of x and y ­For each y, plot closest x

Bresenham’s Algorithm DDA requires one floating point addition per step We can eliminate all fp through Bresenham’s algorithm Consider only 1  m  0 ­Other cases by symmetry Assume pixel centers are at half integers If we start at a pixel that has been written, there are only two candidates for the next pixel to be written into the frame buffer

Candidate Pixels 1  m  0 last pixel candidates Note that line could have passed through any part of this pixel

Decision Variable - d =  x(b-a) d is an integer d > 0 use upper pixel d < 0 use lower pixel

Incremental Form To compute d k+1 ­More efficient if we use d k, the value of the decision variable at x = x k a b

Incremental Form a b Constant (c )

Incremental Form a b Either 0 or 1 depending on the sign of dk

Incremental Form d k+1 = d k +2  y, if d k < 0 d k+1 = d k +2(  y-  x), otherwise For each x, we need do only an integer addition and a test

Bresenham’s Algorithm (1) Input the two line endpoints and store the left endpoint in(x1, y1) (2)set the color for posiiton(x1,y2) and plot the first point (3) calculate constants  y,  x, 2(  y-  x) (4)calculate d1 = 2  y-  x (5) At each xk, starting at k=1 do if dk < 0, plot (xk +1, yk) d k+1 = d k +2  y, Else plot(xk+1, yk+1) d k+1 = d k +2(  y-  x)

Example Endpoints (20,10) and (30,18)  x=10,  y=8, d1=6 2  y-2  x=-4, 2  y=16

Example Endpoints (20,10) and (30,18)  x=10,  y=8, d1=6 2  y-2  x=-4, 2  y=16

(x1,y1)=(20,10) P1=6 Next pixel (x2,y2): (21,11) P2=6-4=2

(x2,y2)=(21,11) P2=2 Next pixel (x3,y3): (22,12) P3=2-4=-2

(x3,y3)=(22,12) P3=-2 Next pixel (x4,y4): (23,12) P4=-2+16=14

(x4,y4)=(23,12) P4=14 Next pixel (x5,y5): (24,13) P5=14-4=10

Aliasing Ideal rasterized line should be 1 pixel wide Choosing best y for each x (or visa versa) produces aliased raster lines

Antialiasing by Area Averaging Color multiple pixels for each x depending on coverage by ideal line originalantialiased magnified