University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Rasterization Week 6,

Slides:



Advertisements
Similar presentations
Computer Graphics- SCC 342
Advertisements

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 Lighting/Shading III Week.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Color Week 5, Fri Feb.
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 2008 Tamara Munzner Lighting/Shading III Week.
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.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Vision/Color II, Virtual.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Lighting/Shading II Week.
Graphics Programming: Polygon Filling
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Lighting/Shading II Week.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Scan Conversion Week 6, Mon 6 Oct 2003 recap: Bresenham line algorithm scan.
Scan Conversion Week 6, Wed 8 Oct 2003
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Color 2 Week 10, Fri 7 Nov 2003.
1 Project 2: Navigation five ways to navigate Absolute Rotate/Translate Keyboard Absolute Lookat Keyboard move wrt global coordinate system Relative Rolling.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Shading Week 5, Wed 1 Oct 2003 recap: lighting shading.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Lighting and Shading Week.
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Lighting/Shading II Week.
Polygon Shading. Assigning color to a shape to make graphical scenes look realistic, or artistic, or whatever effect we’re attempting to achieve But first.
Polygon Scan Conversion and Z-Buffering
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.
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.
Graphics Graphics Korea University cgvr.korea.ac.kr Raster Graphics 고려대학교 컴퓨터 그래픽스 연구실.
Computer Science 631 Lecture 7: Colorspace, local operations
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.
CS 480/680 Computer Graphics Implementation III Dr. Frederick C Harris, Jr. Fall 2011.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Lighting/Shading III Week.
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.
University of British Columbia CPSC 314 Computer Graphics May-June 2005 Tamara Munzner Rasterization, Interpolation,
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.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Rasterization.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
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.
David Luebke 1 2/5/2016 Color CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
David Luebke2/23/2016 CS 551 / 645: Introductory Computer Graphics Color Continued Clipping in 3D.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Rasterization II Week.
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 I, Fall Programming with OpenGL Part 2: Complete Programs.
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.
CS 551 / 645: Introductory Computer Graphics
Computer Graphics Filling.
(c) 2002 University of Wisconsin, CS559
University of New Mexico
Implementation III.
Introduction to Computer Graphics with WebGL
Computer Graphics Filling & Color.
Rasterization, Interpolation, Vision/Color Week 2, Thu May 19
Lighting/Shading III Week 7, Wed Mar 3
Lecture 13 Clipping & Scan Conversion
Computer Graphics Implementation III
Rasterization Week 6, Mon Feb 12
Primitive Drawing Algorithm
Primitive Drawing Algorithm
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 2005 Tamara Munzner Rasterization Week 6, Mon Feb 7

2 News midterm review Wednesday plus Kangaroo Hall of Fame midterm Friday (be on time!) covering through lighting/shading not color or rasterization homework 1 solutions out no more late homework accepted program 2 writeup out due Thu Feb 24

3 Program 2: Terrain Navigation make bumpy terrain 100x100 rectangular grid vertex height varies randomly by 20% vertex color varies randomly switch between per-face, per-vertex normals explicitly draw normals (hedgehog mode) lighting and shading headlamp, plus at least one fixed light switch between smooth and flat shading

4 Navigating two flying modes: absolute and relative absolute keyboard keys to increment/decrement x/y/z position of eye, lookat, up vectors relative mouse drags incremental wrt current camera position forward/backward motion roll, pitch, and yaw angles

5 Hint: Incremental Motion motion is wrt current camera coords maintaining cumulative angles wrt world coords would be difficult computation in coord system used to draw previous frame is simple OpenGL modelview matrix has the info! but multiplying by new matrix gives p’=CIp you want to do p’=ICp trick: dump out modelview matrix wipe the stack with glIdentity apply incremental update matrix apply current camera coord matrix

6 Reading Color (reading from Friday) FCG Chap 17 Human Vision (pp ) FCG Chap 18 Color (pp ) until Section 18.9 Tone Mapping FCG Sec 3.2 Gamma Correction FCG Sec 3.3 RGB Color Rasterization FCG Chap 3 Raster Algorithms (pp 49-67) FCG Section 2.11 Barycentric Coordinates

7 FCG Errata p 54 triangle at bottom of figure shouldn’t have black outline p 63 The test if numbers a [x] and b [y] have the same sign can be implemented as the test ab [xy] > 0.

8 Font Correction: Lighting in OpenGL glLightfv(GL_LIGHT0, GL_AMBIENT, amb_light_rgba ); glLightfv(GL_LIGHT0, GL_DIFFUSE, dif_light_rgba ); glLightfv(GL_LIGHT0, GL_SPECULAR, spec_light_rgba ); glLightfv(GL_LIGHT0, GL_POSITION, position); glEnable(GL_LIGHT0); glMaterialfv( GL_FRONT, GL_AMBIENT, ambient_rgba ); glMaterialfv( GL_FRONT, GL_DIFFUSE, diffuse_rgba ); glMaterialfv( GL_FRONT, GL_SPECULAR, specular_rgba ); glMaterialfv( GL_FRONT, GL_SHININESS, n ); warning: glMaterial is expensive and tricky use cheap and simple glColor when possible see OpenGL Pitfall #14 from Kilgard’s list

9 Correction/Review: Computing Normals per-vertex normals by interpolating per-facet normals OpenGL supports both computing normal for a polygon three points form two vectors cross: normal of plane direction normalize: make unit length which side of plane is up? counterclockwise point order convention c b a b-c a-b (a-b) x (b-c)

10 Review: Trichromacy and Metamers three types of cones color is combination of cone stimuli metamer: identically perceived color caused by very different spectra

11 Review: Color Constancy

12 Review: Measured vs. CIE Color Spaces measured basis monochromatic lights physical observations negative lobes transformed basis “imaginary” lights all positive, unit area Y is luminance

13 Review: Device Color Gamuts compare gamuts on CIE chromaticity diagram gamut mapping

14 Review: RGB Color Space define colors with (r, g, b) amounts of red, green, and blue used by OpenGL RGB color cube sits within CIE color space subset of perceivable colors

15 Review: HSV Color Space hue: dominant wavelength, “color” saturation: how far from grey value/brightness: how far from black/white

16 Review: YIQ Color Space YIQ is the color model used for color TV in America. Y is brightness, I & Q are color same Y as CIE, backwards compatibility with black and white TV blue is more compressed

17 Review: Gamma Correction  DS   D   OS 

18 Rasterization

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

20 Scan Conversion given vertices in DCS, fill in the pixels start with lines

21 Lines

Basic Line Drawing assume, slope how can we do this quickly? goals integer coordinates thinnest line with no gaps

23 Midpoint Algorithm moving incrementally along x direction draw at current y value, or move up 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: top pixel above: bottom pixel [demo]

24 m e y+e+m e+m y+e y y+1 xx+1 Making It Fast maintain error value test if (y+e+m) < y+.5 e+m <.5 if top pixel picked e = y+e+m-y = e+m if bottom pixel picked e = y+e+m-(y+1) = e+m-1 convert to use only integer arithmetic (remember m=dy/dx) test: multiply by 2*dx. then check if (2*e*dx+dy) < dx top: multiply by dx. then e*dx = e*dx+dy bottom: multiple by dx. then e*dx = e*dx+dy-1 E= e*dx

25 Bresenham Line Drawing Algorithm all integer arithmetic y=y0; e=0; for (x=x0; x <= x1; x++) { draw(x,y); if (2(e+dy) < dx) { e = e+dy; } else { y=y+1; e=e+dy-dx; }}

26 Bresenham Line Drawing Algorithm all integer arithmetic more speedups left shift for multiply by two avoid extra calculations y=y0; e=0; for (x=x0; x <= x1; x++) { draw(x,y); if (2(e+dy) < dx) { e = e+dy; } else { y=y+1; e=e+dy-dx; }} y=y0; eps=0 for ( int x = x0; x = dx ){ y++; eps -= dx; } }

27 Polygons

28 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

29 Triangulation convex polygons easily triangulated concave polygons present a challenge

30 OpenGL Triangulation simple convex polygons break into triangles, trivial glBegin(GL_POLYGON)... glEnd() concave or non-simple polygons break into triangles, more effort 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 scan conversion implicit test

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

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

34 Flood Fill draw edges run: drawbacks?

35 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!

36 Scanline Algorithms scanline: a line of pixels in an image

=0 P Scanline Algorithms set pixels inside polygon boundary along horizontal lines one pixel apart use bounding box to speed up

38 Edge Walking basic idea: draw edges vertically interpolate colors down edges fill in horizontal spans for each scanline at each scanline, interpolate edge colors across span

39 moving slivers shared edge ordering Triangle Rasterization Issues

40 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

41 General Polygon Rasterization consider the following polygon: how do we know whether a given pixel on the scanline is inside or outside the polygon? A B C D E F

42 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);

43 Interpolation

44 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

45 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

46 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

47 3. Barycentric Coordinates weighted combination of vertices (1,0,0) (0,1,0) (0,0,1) “convex combination of points” of points”

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

49 Computing Barycentric Coords similarly b 1 : b 2 P2P2P2P2 P3P3P3P3 P1P1P1P1 PLPLPLPL PRPRPRPR P d 2 : d 1

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

51 Computing Barycentric Coords thus

52 Computing Barycentric Coords can verify barycentric properties