College of Computer and Information Science, Northeastern UniversityOctober 31, 20151 CS G140 Graduate Computer Graphics Prof. Harriet Fell Spring 2009.

Slides:



Advertisements
Similar presentations
Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 7 Scanline algorithm and polygon clipping Taku Komura.
Advertisements

Computer Graphics- SCC 342
William Ribarsky (modified by Amos Johnson) 1 Ray Tracing.
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
Computer Graphics 4: Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling By:Kanwarjeet Singh.
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
Larry F. Hodges (modified by Amos Johnson) 1 Design of Line, Circle & Ellipse Algorithms.
30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
College of Computer and Information Science, Northeastern UniversityApril 17, CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 9.
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
CS 325 Introduction to Computer Graphics 04 / 09 / 2010 Instructor: Michael Eckmann.
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics May 3, 2007.
Ray Casting Ray-Surface Intersections Barycentric Coordinates Reflection and Transmission [Shirley, Ch.9] Ray Tracing Handouts Ray Casting Ray-Surface.
CS 376 Introduction to Computer Graphics 04 / 06 / 2007 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 04 / 2007 Instructor: Michael Eckmann.
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.
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
CGMB 314 Intro to Computer Graphics Fill Area Primitives.
CGMB214: Introduction to Computer Graphics
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
College of Computer and Information Science, Northeastern UniversitySeptember 12, CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture.
WHERE TO DRAW A LINE?? Line drawing is accomplished by calculating intermediate positions along the line path between specified end points. Precise definition.
Scan Conversion Line and Circle
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
CS 325 Introduction to Computer Graphics 04 / 26 / 2010 Instructor: Michael Eckmann.
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
College of Computer and Information Science, Northeastern UniversityOctober 17, CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 5.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
College of Computer and Information Science, Northeastern UniversityMay 27, CS 4300 Computer Graphics Prof. Harriet Fell Fall 2012 Lecture 9 – September.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Basic Ray Tracing CMSC 435/634.
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.
10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Rasterization.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
MIT EECS 6.837, Cutler and Durand 1 Ray Casting II.
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.
Scan Conversion.
More on Ray Tracing Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, April 14, 2004.
CS 325 Introduction to Computer Graphics 04 / 07 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 14 / 2007 Instructor: Michael Eckmann.
Computer Graphics Lecture 08 Taqdees A. Siddiqi Computer Graphics Filled Area Primitives I Lecture 08 Taqdees A. Siddiqi
CS 376 Introduction to Computer Graphics 04 / 18 / 2007 Instructor: Michael Eckmann.
Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Computer Graphics Lecture 06 Circle Drawing Techniques Taqdees A. Siddiqi
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
Primitive graphic objects
Scan Conversion or Rasterization
Computer Graphics Filling.
CS G140 Graduate Computer Graphics
(c) 2002 University of Wisconsin, CS559
Scan Conversion or Rasterization
Prof. Harriet Fell Spring 2007 Lecture 5 – January 17, 2006
Chapter Three Part I Output Primitives CS 380.
Prof. Harriet Fell Spring 2007 Lecture 9 – January 29, 2007
© University of Wisconsin, CS559 Fall 2004
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
Prof. Harriet Fell Fall 2011 Lecture 9 – September 26, 2011
CS 655 – Advanced Computer Graphics
Chapter 3 Graphics Output Primitives
Where We Stand At this point we know how to: Next thing:
Presentation transcript:

College of Computer and Information Science, Northeastern UniversityOctober 31, CS G140 Graduate Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 4 – January 28, 2009

College of Computer and Information Science, Northeastern UniversityOctober 31, Today’s Topics Raster Algorithms  Lines - Section 3.5 in Shirley et al.  Circles  Antialiasing RAY Tracing Continued  Ray-Plane  Ray-Triangle  Ray-Polygon

College of Computer and Information Science, Northeastern UniversityOctober 31, (3,2) (0,0) (0,3) Pixel Coordinates y x x = -0.5 y = 4.5 y = x = 4.5

College of Computer and Information Science, Northeastern UniversityOctober 31, What Makes a Good Line? Not too jaggy Uniform thickness along a line Uniform thickness of lines at different angles Symmetry, Line(P,Q) = Line(Q,P) A good line algorithm should be fast.

College of Computer and Information Science, Northeastern UniversityOctober 31, Line Drawing

College of Computer and Information Science, Northeastern UniversityOctober 31, Line Drawing

College of Computer and Information Science, Northeastern UniversityOctober 31, Which Pixels Should We Color? We could use the equation of the line:  y = mx + b  m = (y 1 – y 0 )/(x 1 – x 0 )  b = y 1 - mx 1 And a loop for x = x 0 to x 1 y = mx + b draw (x, y) This calls for real multiplication for each pixel This only works if x 1  x 2 and |m|  1.

College of Computer and Information Science, Northeastern UniversityOctober 31, Midpoint Algorithm Pitteway 1967 Van Aiken and Nowak 1985 Draws the same pixels as the Bresenham Algorithm Uses integer arithmetic and incremental computation. Draws the thinnest possible line from (x 0, y 0 ) to (x 1, y 1 ) that has no gaps. A diagonal connection between pixels is not a gap.

College of Computer and Information Science, Northeastern UniversityOctober 31, Implicit Equation of a Line (x 0, y 0 ) (x 1, y 1 )f(x,y) = (y 0 – y 1 )x +(x 1 - x 0 )y + x 0 y 1 - x 1 y 0 We will assume x 0  x 1 and that m = (y 1 – y 0 )/(x 1 - x 0 ) is in [0, 1]. f(x,y) = 0 f(x,y) > 0 f(x,y) < 0

College of Computer and Information Science, Northeastern UniversityOctober 31, Basic Form of the Algotithm y = y 0 for x = x 0 to x 1 do draw (x, y) if (some condition) then y = y + 1 Since m  [0, 1], as we move from x to x+1, the y value stays the same or goes up by 1. We want to compute this condition efficiently.

College of Computer and Information Science, Northeastern UniversityOctober 31, Above or Below the Midpoint?

College of Computer and Information Science, Northeastern UniversityOctober 31, Finding the Next Pixel Assume we just drew (x, y). For the next pixel, we must decide between (x+1, y) and (x+1, y+1). The midpoint between the choices is (x+1, y+0.5). If the line passes below (x+1, y+0.5), we draw the bottom pixel. Otherwise, we draw the upper pixel.

College of Computer and Information Science, Northeastern UniversityOctober 31, The Decision Function if f(x+1, y+0.5) < 0 // midpoint below line y = y + 1 f(x,y) = (y 0 – y 1 )x +(x 1 - x 0 )y + x 0 y 1 - x 1 y 0 How do we compute f(x+1, y+0.5) incrementally? using only integer arithmetic?

College of Computer and Information Science, Northeastern UniversityOctober 31, Incremental Computation f(x,y) = (y 0 – y 1 )x +(x 1 - x 0 )y + x 0 y 1 - x 1 y 0 f(x + 1, y) = f(x, y) + (y 0 – y 1 ) f(x + 1, y + 1) = f(x, y) + (y 0 – y 1 ) + (x 1 - x 0 ) y = y 0 d = f(x 0 + 1, y + 0.5) for x = x 0 to x 1 do draw (x, y) if d < 0 then y = y + 1 d = d + (y 0 – y 1 ) + (x 1 - x 0 ) else d = d + + (y 0 – y 1 )

College of Computer and Information Science, Northeastern UniversityOctober 31, Integer Decision Function f(x,y) = (y 0 – y 1 )x +(x 1 - x 0 )y + x 0 y 1 - x 1 y 0 f(x 0 + 1, y ) = (y 0 – y 1 )(x 0 + 1) +(x 1 - x 0 )(y ) + x 0 y 1 - x 1 y 0 2f(x 0 + 1, y ) = 2(y 0 – y 1 )(x 0 + 1) +(x 1 - x 0 )(2y 0 + 1) + 2x 0 y 1 - 2x 1 y 0 2f(x, y)= 0 if (x, y) is on the line. < 0 if (x, y) is below the line. > 0 if (x, y) is above the line.

College of Computer and Information Science, Northeastern UniversityOctober 31, Incremental Computation f(x,y) = (y 0 – y 1 )x +(x 1 - x 0 )y + x 0 y 1 - x 1 y 0 f(x + 1, y) = f(x, y) + (y 0 – y 1 ) f(x + 1, y + 1) = f(x, y) + (y 0 – y 1 ) + (x 1 - x 0 ) y = y 0 d = 2f(x 0 + 1, y + 0.5) for x = x 0 to x 1 do draw (x, y) if d < 0 then y = y + 1 d = d + 2(y 0 – y 1 ) + 2(x 1 - x 0 ) else d = d + + 2(y 0 – y 1 )

College of Computer and Information Science, Northeastern UniversityOctober 31, Midpoint Line Algorithm y = y 0 d = 2(y 0 – y 1 )(x 0 + 1) +(x 1 - x 0 )(2y 0 + 1) + 2x 0 y 1 - 2x 1 y 0 for x = x 0 to x 1 do draw (x, y) if d < 0 then y = y + 1 d = d + 2(y 0 – y 1 ) + 2(x 1 - x 0 ) else d = d + 2(y 0 – y 1 )

College of Computer and Information Science, Northeastern UniversityOctober 31, Some Lines

College of Computer and Information Science, Northeastern UniversityOctober 31, Some Lines Magnified

College of Computer and Information Science, Northeastern UniversityOctober 31, Antialiasing by Downsampling

College of Computer and Information Science, Northeastern UniversityOctober 31, Circles R (0, 0) (x, y) (x+a, y+b) R (a, b)

College of Computer and Information Science, Northeastern UniversityOctober 31, Drawing CirclesDrawing Circles - 1 (0, 0) (x, y) R  x = Rcos(  ) y = Rsin(  ) for  = 0 to 360 do x = Rcos(  ) y = Rsin(  ) draw(x, y)

College of Computer and Information Science, Northeastern UniversityOctober 31, Drawing CirclesDrawing Circles 2 (0, 0) (x, y) R  y 2 + y 2 = R 2 for x = -R to R do y = sqrt( R 2 - x 2 ) draw(x, y) draw(x, -y)

College of Computer and Information Science, Northeastern UniversityOctober 31, Circular Symmetry (0, 0) (x, y) (y, x) (x, -y) (y, -x) (-x, y) (-y, x) (-x, -y) (-y, -x)

College of Computer and Information Science, Northeastern UniversityOctober 31, Midpoint Circle Algorithm IN THE TOP OCTANT: If (x, y) was the last pixel plotted, either (x + 1, y) or (x + 1, y - 1) will be the next pixel. Making a Decision Function: d(x, y) = x 2 + y 2 – R 2 d(x, y) < 0(x, y) is inside the circle. If d(x, y) = 0(x, y) is on the circle. d(x, y) > 0(x, y) is outside the circle.

College of Computer and Information Science, Northeastern UniversityOctober 31, Decision Function Evaluate d at the midpoint of the two possible pixels. d(x + 1, y - ½) = (x + 1) 2 + (y - ½) 2 – R 2 d(x + 1, y - ½) < 0midpoint inside circle choose y If d(x + 1, y - ½) = 0midpoint on circlechoose y d(x + 1, y - ½) > 0midpoint outside circlechoose y - 1

College of Computer and Information Science, Northeastern UniversityOctober 31, Computing D(x,y) Incrementally D(x,y) = d(x + 1, y - ½) = (x + 1) 2 + (y - ½) 2 – R 2 D(x + 1,y) – D(x, y)= (x+2) 2 + (y - ½) 2 – R 2 – ((x + 1) 2 + (y - ½) 2 – R 2 ) =2(x + 1)+ 1 D(x + 1,y - 1) – D(x, y)= (x+2) 2 + (y – 3/2) 2 – R 2 – ((x + 1) 2 + (y - ½) 2 – R 2 ) =2(x+1) + 1 – 2(y – 1) You can also compute the differences incrementally.

College of Computer and Information Science, Northeastern UniversityOctober 31, Time for a Break

College of Computer and Information Science, Northeastern UniversityOctober 31, More Ray-Tracing Ray/Plane Intersection Ray/Triangle Intersection Ray/Polygon Intersection

College of Computer and Information Science, Northeastern UniversityOctober 31, Equation of a Plane N = (A, B, C) P 0 = (a, b, c) (x, y, z) Given a point P 0 on the plane and a normal to the plane N. (x, y, z) is on the plane if and only if (x-a, y-b, z-c)·N = 0. Ax + By + Cz –(Aa + Bb + Cc) = 0 D

College of Computer and Information Science, Northeastern UniversityOctober 31, Ray/Plane Intersection Ax + By + Cz = D P 0 = (x 0, y 0, z 0 ) P 1 = (x 1, y 1, z 1 ) Ray Equation x = x 0 + t(x 1 - x 0 ) y = y 0 + t(y 1 - y 0 ) z = z 0 + t(z 1 - z 0 ) A(x 0 + t(x 1 - x 0 )) + B(y 0 + t(y 1 - y 0 )) + C(z 0 + t(z 1 - z 0 )) = D Solve for t. Find x, y, z.

College of Computer and Information Science, Northeastern UniversityOctober 31, Planes in Your Scenes Planes are specified by  A, B, C, D or by N and P  Color and other coefficients are as for spheres To search for the nearest object, go through all the spheres and planes and find the smallest t. A plane will not be visible if the normal vector (A, B, C) points away from the light.

College of Computer and Information Science, Northeastern UniversityOctober 31, Ray/Triangle Intersection Using the Ray/Plane intersection:  Given the three vertices of the triangle, Find N, the normal to the plane containing the triangle. Use N and one of the triangle vertices to describe the plane, i.e. Find A, B, C, and D. If the Ray intersects the Plane, find the intersection point and its  and . If 0   and 0   and  +   1, the Ray hits the Triangle.

College of Computer and Information Science, Northeastern UniversityOctober 31, Ray/Triangle Intersection Using barycentric coordinates directly: (Shirley pp ) Solve e + td = a +  (b-a) +  (c-a) for t, , and . The x, y, and z components give you 3 linear equations in 3 unknowns. If 0  t  1, the Ray hits the Plane. If 0   and 0   and  +   1, the Ray hits the Triangle. (x e, y e, z e ) (x d, y d, z d ) a b c

College of Computer and Information Science, Northeastern UniversityOctober 31, Ray/Polygon Intersection A polygon is given by n co-planar points. Choose 3 points that are not co-linear to find N. Apply Ray/Plane intersection procedure to find P. Determine whether P lies inside the polygon. P

College of Computer and Information Science, Northeastern UniversityOctober 31, Parity Check Draw a horizontal half-line from P to the right. Count the number of times the half-line crosses an edge. 1in 4out 7in

College of Computer and Information Science, Northeastern UniversityOctober 31, Images with Planes and Polygons

College of Computer and Information Science, Northeastern UniversityOctober 31, Images with Planes and Polygons

College of Computer and Information Science, Northeastern UniversityOctober 31, Scan Line Polygon Fill

College of Computer and Information Science, Northeastern UniversityOctober 31, Polygon Data Structure edges xminymax1/m  168/4  (1, 2) (9, 6) xmin = x value at lowest y ymax = highest y

Polygon Data Structure Edge Table (ET) has a list of edges for each scan line. e1 e2 e3 e4 e5 e6 e7 e8 e9 e10 e  e  e4  e5 6  e3  e7  e  e2  e1  e11 0  e10  e9

College of Computer and Information Science, Northeastern UniversityOctober 31, Preprocessing the edges count twice, once for each edge chop lowest pixel to only count once delete horizontal edges For a closed polygon, there should be an even number of crossings at each scan line. We fill between each successive pair.

Polygon Data Structure after preprocessing Edge Table (ET) has a list of edges for each scan line. e1 e2 e3 e4 e5 e6 e7 e8 e9 e10 e  e  e4  e5 6  e3  e7  e  e2  e1  e11 0  e10  e9 e11 7  e3  e4  e5 6  e7  e8 11  e6 10

College of Computer and Information Science, Northeastern UniversityOctober 31, The Algorithm 1.Start with smallest nonempty y value in ET. 2.Initialize SLB (Scan Line Bucket) to nil. 3.While current y  top y value: a.Merge y bucket from ET into SLB; sort on xmin. b.Fill pixels between rounded pairs of x values in SLB. c.Remove edges from SLB whose ytop = current y. d.Increment xmin by 1/m for edges in SLB. e.Increment y by 1.

Running the Algorithm e2 e3 e4 e5 e6 e7 e8 e9 e10 e ET  e  e3  e4  e5 6  e7  e  e2  e11 0  e10  e9 xminymax1/m e226-2/5 e31/3 121/3 e4412-2/5 e54130 e66 2/313-4/3 e /2 e81082 e91183/8 e /4 e11642/

College of Computer and Information Science, Northeastern UniversityOctober 31, Running the Algorithm e2 e3 e4 e5 e6 e7 e8 e9 e10 e y=0 SCB  114-3/4  1183/8  e9 e /4 11 3/8

College of Computer and Information Science, Northeastern UniversityOctober 31, Running the Algorithm e2 e3 e4 e5 e6 e7 e8 e9 e10 e y=1 SLB  26-2/5  642/3  e11 e2 1 3/5 10 1/44-3/4  11 3/8 83/8  e9 e10 6 2/3 9 1/2 11 6/8

College of Computer and Information Science, Northeastern UniversityOctober 31, Running the Algorithm e2 e3 e4 e5 e6 e7 e8 e9 e10 e y=2 SLB  1 3/56-2/5  6 2/342/3  e11 e2 9 1/24-3/4  11 6/883/8  e9 e /8 8 3/4 7 1/3 1 1/5

College of Computer and Information Science, Northeastern UniversityOctober 31, Running the Algorithm e3 e4 e5 e6 e7 e8 e9 e y=3 SLB  1 1/56-2/5  7 1/342/3  e11 e2 8 3/44-3/4  12 1/883/8  e9 e / /5 e11e2

College of Computer and Information Science, Northeastern UniversityOctober 31, Running the Algorithm e3 e4 e5 e6 e7 e8 e y=4 SLB  4/56-2/5  842/3  e11 e2 84-3/4  12 4/883/8  e9 e10 e11e2 e9 Remove these edges.

College of Computer and Information Science, Northeastern UniversityOctober 31, Running the Algorithm e3 e4 e5 e6 e7 e y=4 SLB  4/56-2/5  e2 12 4/883/8  e9 12 7/8 2/5 e2e11 e10 e9 e11 and e10 are removed.

College of Computer and Information Science, Northeastern UniversityOctober 31, Running the Algorithm e3 e4 e5 e6 e7 e y=5 SLB  2/56-2/5  e2 12 7/883/8  e9 13 2/8 0 e2e11 e10 e9

College of Computer and Information Science, Northeastern UniversityOctober 31, Running the Algorithm e3 e4 e5 e6 e7 e y=6 SLB  06-2/5  e /2  e7 e2e11 e10 e9 Remove this edge  e8 13 2/883/8  e9 9 1/ /8

Running the Algorithm e3 e4 e5 e6 e7 e y=7 SLB  4130  e5 9 1/210-1/2  e7 e2e11 e10 e  e8 13 5/883/8  e9 Add these edges /5  e4 1/3121/3  e3

College of Computer and Information Science, Northeastern UniversityOctober 31, Ray Box Intersection (xl, yl, zl) (x0, y0, z0) + t (xd, yd, zd) (xd, yd, zd) a unit vector (xh, yh, zh) (x0, y0, z0) t1 = (xl - x0) / xd

College of Computer and Information Science, Northeastern UniversityOctober 31, Ray Box Intersection or see Watt pages Box: minimum extent Bl = (xl, yl, zl) maximum extent Bh = (xh, yh, zh) Ray: R0 = (x0, y0, z0), Rd= (xd, yd, zd) ray is R0 + tRd Algorithm : 1.Set tnear = -INFINITY, tfar = +INFINITY 2.For the pair of X planes 1.if zd = 0, the ray is parallel to the planes so:  if x0 xh return FALSE (origin not between planes) 2.else the ray is not parallel to the planes, so calculate intersection distances of planes  t1 = (xl - x0) / xd (time at which ray intersects minimum X plane)  t2 = (xh - x0) / xd (t i me at which ray i ntersects maximum X plane)  if t1 > t2, swap t1 and t2  if t1 > tnear, set tnear = t1  if t2 < tfar, set tfar= t2  if tnear > tfar, box is missed so return FALSE  if tfar < 0, box is behind ray so return FALSE 3.Repeat step 2 for Y, then Z 4.All tests were survived, so return TRUE