1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.

Slides:



Advertisements
Similar presentations
Graphics Primitives: line
Advertisements

CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
From Vertices to Fragments
Computer Graphics 4: Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling By:Kanwarjeet Singh.
Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Different types of Polygons Simple Convex Simple Concave Non-simple : self-intersecting With holes ConvexConcaveSelf-intersecting.
Raster conversion algorithms for line and circle
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.
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics May 3, 2007.
Implementation III Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Graphics Primitives: line. Pixel Position
WHERE TO DRAW A LINE?? Line drawing is accomplished by calculating intermediate positions along the line path between specified end points. Precise definition.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Chapter 7: From Vertices to Fragments Ed Angel Professor of Computer Science, Electrical.
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
Triangle Scan Conversion. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rasterization Rasterization (scan conversion) –Determine which.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
Objectives Introduce basic implementation strategies Clipping Scan conversion.
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.
From Vertices to Fragments II Software College, Shandong University Instructor: Zhou Yuanfeng
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.
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 5E © Addison-Wesley 2009 Week 3 Lecture 1: Implementation Based on Interactive Computer Graphics (Angel) - Chapter.
COMPUTER GRAPHICS Hochiminh city University of Technology Faculty of Computer Science and Engineering CHAPTER 07: Rasterization.
Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.
Implementation II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
In the name of God Computer Graphics. Today Introduction Sampling Graphic Output Primitives 1.Line 2.Circle 3.Curve 4.polygon.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Scan Conversion.
Lecture 13: Raster Graphics and Scan Conversion
Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in.
Computer Graphics CC416 Week 14 Filling Algorithms.
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
Introduction to Polygons
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
University of New Mexico
Implementation III.
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Agenda Polygon Terminology Types of polygons Inside Test
Introduction to Computer Graphics with WebGL
Course code: 10CS65 | Computer Graphics and Visualization
Introduction to Computer Graphics with WebGL
Rasterization and Antialiasing
Agenda Polygon Terminology Types of polygons Inside Test
Lecture 13 Clipping & Scan Conversion
Computer Graphics Implementation III
Rasterization and Antialiasing
Introduction to Computer Graphics with WebGL
Chapter 3 Graphics Output Primitives
Primitive Drawing Algorithm
From Vertices To Fragments
Primitive Drawing Algorithm
Implementation III Ed Angel Professor Emeritus of Computer Science
From Vertex to Fragment
From Vertex to Fragment
Presentation transcript:

1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science Laboratory University of New Mexico

Rasterization Ed Angel Professor Emeritus of Computer Science University of New Mexico

Objectives Survey Line Drawing Algorithms ­How do we calculate the pixels location on a polygon edge… DDA Bresenham’s Algorithm Aliasing and Antialiasing

Rasterization Rasterization (scan conversion) ­Determine which pixels that are inside primitive specified by a set of vertices ­Produces a set of fragments ­Fragments have a location (pixel location) and other attributes such color and texture coordinates that are determined by interpolating values at vertices Pixel colors determined later using color, texture, and other vertex properties

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,ix++) { 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) IF d > 0 use upper pixel d < 0 use lower pixel

12 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Decision Variable Calculations:

Incremental Form More efficient if we look at d k, the value of the decision variable at x = k 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 Single instruction on graphics chips

(Polygon Scan Conversion) Scan Conversion = Fill How to tell inside from outside ­Convex easy ­Nonsimple difficult ­Odd even test Count edge crossings ­Winding number odd-even fill

(Winding Number) Count clockwise encirclements of point Alternate definition of inside: inside if winding number  0 winding number = 2 winding number = 1

Filling in the Frame Buffer Fill at end of pipeline ­Convex Polygons only ­Nonconvex polygons assumed to have been tessellated ­Shades (colors) have been computed for vertices (Gouraud shading) ­Combine with z-buffer algorithm March across scan lines interpolating shades Incremental work small

Using Interpolation span C1C1 C3C3 C2C2 C5C5 C4C4 scan line C 1 C 2 C 3 specified by glColor or by vertex shading C 4 determined by interpolating between C 1 and C 2 C 5 determined by interpolating between C 2 and C 3 interpolate between C 4 and C 5 along span

Flood Fill Fill can be done recursively if we know a seed point located inside (WHITE) Scan convert edges into buffer in edge/inside color (BLACK) flood_fill(int x, int y) { if(read_pixel(x,y)= = WHITE) { write_pixel(x,y,BLACK); flood_fill(x-1, y); flood_fill(x+1, y); flood_fill(x, y+1); flood_fill(x, y-1); }

Scan Line Fill Can also fill by maintaining a data structure of all intersections of polygons with scan lines ­Sort by scan line ­Fill each span vertex order generated by vertex list desired order

Data Structure

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 original antialiased magnified

Polygon Aliasing Aliasing problems can be serious for polygons ­Jaggedness of edges ­Small polygons neglected ­Need compositing so color of one polygon does not totally determine color of pixel All three polygons should contribute to color

24 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Antialiasing Antialiasing by Area Averaging: ­ -aliasing-offon.jpghttp:// -aliasing-offon.jpg Antialiasing by over sampling: ­ MGS/anti-aliasing.jpghttp:// MGS/anti-aliasing.jpg