University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Rasterization.

Slides:



Advertisements
Similar presentations
Computer Graphics- SCC 342
Advertisements

CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
CP411 polygon Lecture 6 1. Scan conversion algorithm for circle 2. Draw polygons 3. Antialiasing.
Different types of Polygons Simple Convex Simple Concave Non-simple : self-intersecting With holes ConvexConcaveSelf-intersecting.
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.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Lighting/Shading I Week.
Implementation Dr. Amy Zhang. Reading 2  Hill, Chapters  Hill, Chapter 10.
Implementation III Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Graphics Programming: Polygon Filling
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Rasterization Week 6,
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Scan Conversion Week 6, Mon 6 Oct 2003 recap: Bresenham line algorithm scan.
CS 454 Computer graphics Polygon Filling
Scan Conversion Week 6, Wed 8 Oct 2003
Rasterization Foley, Ch: 3. Pixels are represented as disjoint circles centered on uniform grid Each (x,y) of the grid has a pixel Y X (1,1) (1,2) (0,0)
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
TOPIC 4 PART III FILL AREA PRIMITIVES POLYGON FILL AREAS CGMB214: Introduction to Computer Graphics.
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
CGMB 314 Intro to Computer Graphics Fill Area Primitives.
Basics of Rendering Pipeline Based Rendering –Objects in the scene are rendered in a sequence of steps that form the Rendering Pipeline. Ray-Tracing –A.
Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.
CS 551 / 645: Introductory Computer Graphics
3/4/04© University of Wisconsin, CS559 Spring 2004 Last Time Clipping Lines –Cohen-Sutherland: The use of outcodes and early reject/accept tests –Liang-Barsky:
CS 445 / 645 Introduction to Computer Graphics Lecture 8 Triangle Rasterization Lecture 8 Triangle Rasterization.
Rasterization Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by David Luebke)
Triangle Scan Conversion. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rasterization Rasterization (scan conversion) –Determine which.
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
College of Computer and Information Science, Northeastern UniversityOctober 12, CS G140 Graduate Computer Graphics Prof. Harriet Fell Spring 2006.
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 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CAP4730: Computational Structures in Computer Graphics
Drawing Triangles CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Lighting/Shading I Week.
Introduction to Computer Graphics CS 445 / 645 Lecture 9 Chapter 4: Rasterization L. McMillan MIT notes (Fall ’98)
10/15/02 (c) 2002 University of Wisconsin, CS559 Who Am I? Prof Stephen Chenney These notes will be online after the lecture – in fact they’re online already.
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
Computer Graphics Filling. Filling Polygons So we can figure out how to draw lines and circles How do we go about drawing polygons? We use an incremental.
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
MIT EECS 6.837, Durand and Cutler The Graphics Pipeline: Line Clipping & Line Rasterization.
Lecture 15: Raster Graphics and Scan Conversion
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Rasterization II Week.
Lecture 13: Raster Graphics and Scan Conversion
Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in.
Vision/Color II, Rasterization Week 6, Mon Feb 8
Computer Graphics CC416 Week 14 Filling Algorithms.
Computer Graphics Lecture 08 Taqdees A. Siddiqi Computer Graphics Filled Area Primitives I Lecture 08 Taqdees A. Siddiqi
Computer Graphics I, Fall 2010 Scan conversion algorithms.
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
Computer Graphics Filling.
CS G140 Graduate Computer Graphics
Polygons.
(c) 2002 University of Wisconsin, CS559
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
University of New Mexico
Implementation III.
Introduction to Computer Graphics with WebGL
© University of Wisconsin, CS559 Fall 2004
Agenda Polygon Terminology Types of polygons Inside Test
Agenda Polygon Terminology Types of polygons Inside Test
Lecture 13 Clipping & Scan Conversion
Computer Graphics Implementation III
Rasterization Week 6, Mon Feb 12
Clipping University of British Columbia CPSC 314 Computer Graphics
Implementation III Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Rasterization

2 Reading for This Module FCG Chap 3 Raster Algorithms (through 3.2) Section 2.7 Triangles Section 8.1 Rasterization (through 8.1.2)

3 Rasterization

4 Rendering Pipeline Geometry Database Geometry Database Model/View Transform. Model/View Transform. Lighting Perspective Transform. Perspective Transform. Clipping Scan Conversion Scan Conversion Depth Test Depth Test Texturing Blending Frame- buffer Frame- buffer

5 Scan Conversion - Rasterization convert continuous rendering primitives into discrete fragments/pixels lines midpoint/Bresenham triangles flood fill scanline implicit formulation interpolation

6 Scan Conversion given vertices in DCS, fill in the pixels display coordinates required to provide scale for discretization [demo]

Basic Line Drawing assume, slope one octant, other cases symmetric how can we do this more quickly? goals integer coordinates thinnest line with no gaps

8 Midpoint Algorithm we're moving horizontally along x direction (first octant) only two choices: draw at current y value, or move up vertically to y+1? check if midpoint between two possible pixel centers above or below line candidates top pixel: (x+1,y+1) bottom pixel: (x+1, y) midpoint: (x+1, y+.5) check if midpoint above or below line below: pick top pixel above: pick bottom pixel other octants: different tests octant II: y loop, check x left/right above: bottom pixel below: top pixel

9 Midpoint Algorithm we're moving horizontally along x direction (first octant) only two choices: draw at current y value, or move up vertically to y+1? check if midpoint between two possible pixel centers above or below line candidates top pixel: (x+1,y+1) bottom pixel: (x+1, y) midpoint: (x+1, y+.5) check if midpoint above or below line below: pick top pixel above: pick bottom pixel key idea behind Bresenham reuse computation from previous step integer arithmetic by doubling values [demo] above: bottom pixel below: top pixel

Bresenham, Detailed Derivation Goal: function F tells us if line is above or below some point F(x,y) = 0 on line F(x,y) < 0 when line under point F(x,y) > 0 when line over point 10

Using F with Midpoints: Initial 11 (x0,y0) (x1,y1) (x0+1,y0+.5) (x0+2,y0+.5) (x0+4,y0+1.5)(x0+3,y0+1.5) dy dx

Incremental F: Initial 12 Initial difference in F: 2*dy-dx (x0,y0) (x1,y1) (x0+1,y0+.5) (x0+2,y0+.5) (x0+4,y0+1.5)(x0+3,y0+1.5) dy dx

Using F with Midpoints: No Y Change 13 (x0,y0) (x1,y1) (x0+1,y0+.5) (x0+2,y0+.5) (x0+4,y0+1.5)(x0+3,y0+1.5) dy dx

Incremental F: No Y Change 14 (x0,y0) (x1,y1) (x0+1,y0+.5) (x0+2,y0+.5) (x0+4,y0+1.5)(x0+3,y0+1.5) dy dx Next difference in F: 2*dy (no change in y for pixel)

Using F with Midpoints: Y Increased 15 (x0,y0) (x1,y1) (x0+1,y0+.5) (x0+2,y0+.5) (x0+4,y0+1.5)(x0+3,y0+1.5) dy dx

Incremental F: Y Increased 16 (x0,y0) (x1,y1) (x0+1,y0+.5) (x0+2,y0+.5) (x0+4,y0+1.5)(x0+3,y0+1.5) dy dx Next difference in F: 2*dy-2*dx (when pixel at y+1)

17 y=y0; dx = x1-x0; dy = y1-y0; d = 2*dy-dx; incKeepY = 2*dy; incIncreaseY = 2*dy-2*dx; for (x=x0; x <= x1; x++) { draw(x,y); if (d>0) then { y = y + 1; d += incIncreaseY; } else { d += incKeepY; } Bresenham: Reuse Computation, Integer Only

18 Rasterizing Polygons/Triangles basic surface representation in rendering why? lowest common denominator can approximate any surface with arbitrary accuracy all polygons can be broken up into triangles guaranteed to be: planar triangles - convex simple to render can implement in hardware

19 Triangulating Polygons simple convex polygons trivial to break into triangles pick one vertex, draw lines to all others not immediately adjacent OpenGL supports automatically glBegin(GL_POLYGON)... glEnd() concave or non-simple polygons more effort to break into triangles simple approach may not work OpenGL can support at extra cost gluNewTess(), gluTessCallback(),...

Problem input: closed 2D polygon problem: fill its interior with specified color on graphics display assumptions simple - no self intersections simply connected solutions flood fill edge walking

21 P Flood Fill simple algorithm draw edges of polygon use flood-fill to draw interior

22 Flood Fill start with seed point recursively set all neighbors until boundary is hit

23 Flood Fill draw edges run: drawbacks?

24 Flood Fill Drawbacks pixels visited up to 4 times to check if already set need per-pixel flag indicating if set already must clear for every polygon!

25 Scanline Algorithms scanline: a line of pixels in an image set pixels inside polygon boundary along horizontal lines one pixel apart vertically =0 P

26 General Polygon Rasterization how do we know whether given pixel on scanline is inside or outside polygon? A B C D E F

27 General Polygon Rasterization idea: use a parity test for each scanline edgeCnt = 0; for each pixel on scanline (l to r) if (oldpixel->newpixel crosses edge) edgeCnt ++; // draw the pixel if edgeCnt odd if (edgeCnt % 2) setPixel(pixel);

Making It Fast: Bounding Box smaller set of candidate pixels loop over xmin, xmax and ymin,ymax instead of all x, all y

29 moving slivers shared edge ordering Triangle Rasterization Issues

30 Triangle Rasterization Issues exactly which pixels should be lit? pixels with centers inside triangle edges what about pixels exactly on edge? draw them: order of triangles matters (it shouldn’t) don’t draw them: gaps possible between triangles need a consistent (if arbitrary) rule example: draw pixels on left or top edge, but not on right or bottom edge example: check if triangle on same side of edge as offscreen point

31 Interpolation

32 Interpolation During Scan Conversion drawing pixels in polygon requires interpolating many values between vertices r,g,b colour components use for shading z values u,v texture coordinates surface normals equivalent methods (for triangles) bilinear interpolation barycentric coordinates

33 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

34 Barycentric Coordinates non-orthogonal coordinate system based on triangle itself origin: P 1, basis vectors: (P 2 -P 1 ) and (P 3 -P 1 ) P = P 1 +  (P 2 -P 1 )+  (P 3 -P 1 )    

35 Barycentric Coordinates           

36 Barycentric Coordinates non-orthogonal coordinate system based on triangle itself origin: P 1, basis vectors: (P 2 -P 1 ) and (P 3 -P 1 ) P = P 1 +  (P 2 -P 1 )+  (P 3 -P 1 ) P = (1-  P 1 +  P 2 +  P 3 P =  P 1 +  P 2 +  P 3  

37 Using Barycentric Coordinates weighted combination of vertices smooth mixing speedup compute once per triangle (  ) = (1,0,0) (0,1,0) (0,0,1) “convex combination of points” of points” for points inside triangle

38 P2P2P2P2 P3P3P3P3 P1P1P1P1 PLPLPLPL PRPRPRPR P d 2 : d 1 Deriving Barycentric From Bilinear from bilinear interpolation of point P on scanline

39 Deriving Barycentric From Bilineaer similarly b 1 : b 2 P2P2P2P2 P3P3P3P3 P1P1P1P1 PLPLPLPL PRPRPRPR P d 2 : d 1

40 b 1 : b 2 P2P2P2P2 P3P3P3P3 P1P1P1P1 PLPLPLPL PRPRPRPR P d 2 : d 1 c 1 : c 2 Deriving Barycentric From Bilinear combining gives

41 Deriving Barycentric From Bilinear thus P =  P 1 +  P 2 +  P 3 with can verify barycentric properties

42 Computing Barycentric Coordinates 2D triangle area half of parallelogram area from cross product A =  P1 +  P2 +  P3  P1 /A  P2 /A  P3 /A (  ) = (1,0,0) (0,1,0) (0,0,1)