Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics

Similar documents
Scan Conversion. Drawing Lines Drawing Circles

Topic #1: Rasterization (Scan Conversion)

Fall CSCI 420: Computer Graphics. 7.1 Rasterization. Hao Li.

Rasterization, or What is glbegin(gl_lines) really doing?

COMP371 COMPUTER GRAPHICS

CSCI 420 Computer Graphics Lecture 14. Rasterization. Scan Conversion Antialiasing [Angel Ch. 6] Jernej Barbic University of Southern California

Rasterization. Rasterization (scan conversion) Digital Differential Analyzer (DDA) Rasterizing a line. Digital Differential Analyzer (DDA)

Rasterization: Geometric Primitives

From Ver(ces to Fragments: Rasteriza(on

Chapter 8: Implementation- Clipping and Rasterization

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

Computer Graphics. - Rasterization - Philipp Slusallek

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Polygon Filling. Can write frame buffer one word at time rather than one bit. 2/3/2000 CS 4/57101 Lecture 6 1

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

Tópicos de Computação Gráfica Topics in Computer Graphics 10509: Doutoramento em Engenharia Informática. Chap. 2 Rasterization.

Computer Graphics (CS 543) Lecture 10: Rasterization and Antialiasing

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

Computer Graphics D Graphics Algorithms

2D Image Synthesis. 2D image synthesis. Raster graphics systems. Modeling transformation. Vectorization. u x u y 0. o x o y 1

Incremental Form. Idea. More efficient if we look at d k, the value of the decision variable at x = k

Pipeline implementation II

Line Drawing Week 6, Lecture 9

Line Drawing. Foundations of Computer Graphics Torsten Möller

Einführung in Visual Computing

Department of Computer Sciences Graphics Fall 2003 (Lecture 2) Pixels

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline

Output Primitives Lecture: 3. Lecture 3. Output Primitives. Assuming we have a raster display, a picture is completely specified by:

Chapter 3. Sukhwinder Singh

EF432. Introduction to spagetti and meatballs

CPSC / Scan Conversion

(Refer Slide Time: 00:02:00)

Output Primitives. Dr. S.M. Malaek. Assistant: M. Younesi

Implementation III. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

UNIT -8 IMPLEMENTATION

Painter s HSR Algorithm

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller

Computer Graphics 7 - Rasterisation

1 Introduction to Graphics

Scan Conversion. CMP 477 Computer Graphics S. A. Arekete

Graphics (Output) Primitives. Chapters 3 & 4

Rasterization Computer Graphics I Lecture 14. Scan Conversion Antialiasing Compositing [Angel, Ch , ]

Rendering. A simple X program to illustrate rendering

Computer Graphics D Graphics Algorithms

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

2D Graphics Primitives II. Additional issues in scan converting lines. 1)Endpoint order. Want algorithms to draw the same pixels for each line

CS 543: Computer Graphics. Rasterization

The Traditional Graphics Pipeline

Scan Converting Lines

CS488 2D Graphics. Luc RENAMBOT

Clipping and Scan Conversion

Computer Graphics and GPGPU Programming

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Raster Displays and Scan Conversion. Computer Graphics, CSCD18 Fall 2008 Instructor: Leonid Sigal

Scan Converting Circles

UNIT 2 GRAPHIC PRIMITIVES

Display Technologies: CRTs Raster Displays

Topics. From vertices to fragments

Unit 2 Output Primitives and their Attributes

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

Realtime 3D Computer Graphics Virtual Reality

Chapter - 2: Geometry and Line Generations

R asterisation. Part I: Simple Lines. Affine transformation. Transform Render. Rasterisation Line Rasterisation 2/16

Computer Graphics. Lecture 2. Doç. Dr. Mehmet Gokturk

Visible Surface Detection Methods

RASTERIZING POLYGONS IN IMAGE SPACE

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

Rasteriza2on and Clipping

Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling

CSCI 4620/8626. Coordinate Reference Frames

CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE

Cs602-computer graphics MCQS MIDTERM EXAMINATION SOLVED BY ~ LIBRIANSMINE ~

CS 130. Scan Conversion. Raster Graphics

Computer Graphics. Bing-Yu Chen National Taiwan University The University of Tokyo

Computer Graphics. Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

Scan Conversion. Lines and Circles

Raster Scan Displays. Framebuffer (Black and White)

Computer Graphics. Bing-Yu Chen National Taiwan University

0. Introduction: What is Computer Graphics? 1. Basics of scan conversion (line drawing) 2. Representing 2D curves

Agenda. Polygon Terminology Types of polygons Inside Test Polygon Filling Algorithms. Scan-Line Polygon Fill Algorithm Flood-Fill Algorithm

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Clipping. Concepts, Algorithms for line clipping. 1 of 16. Andries van Dam. Clipping - 10/12/17

Graphics Output Primitives

EF432. Introduction to spagetti and meatballs

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

Topic 0. Introduction: What Is Computer Graphics? CSC 418/2504: Computer Graphics EF432. Today s Topics. What is Computer Graphics?

CS Rasterization. Junqiao Zhao 赵君峤

Rendering. A simple X program to illustrate rendering

Output Primitives Lecture: 4. Lecture 4

Computer Graphics. Chapter 4 Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

Werner Purgathofer

? Which intermediate. Recall: Line drawing algorithm. Programmer specifies (x,y) of end pixels Need algorithm to determine pixels on line path

Graphics System. Processor. Output Display. Input Devices. Frame Buffer. Memory. Array of pixels. Resolution: # of pixels Depth: # of bits/pixel

Overview of Computer Graphics

In today s lecture we ll have a look at: A simple technique The mid-point circle algorithm

Visible-Surface Detection Methods. Chapter? Intro. to Computer Graphics Spring 2008, Y. G. Shin

(Refer Slide Time: 00:03:51)

CS602 MCQ,s for midterm paper with reference solved by Shahid

CS602 Midterm Subjective Solved with Reference By WELL WISHER (Aqua Leo)

Transcription:

Announcements Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class 1

Scan Conversion Overview of Rendering Scan Conversion Drawing Lines Drawing Polygons Watt 6.4 (Rasterization) 11/1/02

Rendering: creating images of our 3d models Why is this hard? Must determine what s visible Must simulate how light flows through the environment Different approaches Painter s Algorithm and Z-Buffer Algorithm (OpenGL): draw objects one by one (scan conversion to determine which pixels to write) Ray Tracing: shoot rays out from light source/viewer Radiosity: subdivide surfaces with mesh, solve linear system We will start with low-level, scan conversion, then move to raytracing and radiosity 3

Scan Conversion or Rasterization Ideal Picture Raster Representation Scan Conversion: Process of converting ideal to raster 4

Scan Conversion Algorithms A discrete set of pixels can only approximate a continuous geometric object This means that scan conversion usually introduces error Properties of good scan conversion algorithms: They should be as accurate as possible They should be as fast Challenges Modify all the right pixels Modify only the right pixels Calculate their values correctly Do it quickly So, start with a correct algorithm and optimize it 5

Line Drawing, Cases by Octant Lines come with different slopes, algorithm varies according to which octant (45 degree sector) it lies in. We will talk about one octant only; the algorithms generalize to the other octants easily. The algorithms for drawing lines need to step along one pixel at a time in the fast direction, but which direction this is depends on the slope of the line We also have to worry about reversed end point order (drawing from large to small X, for example). We ll assume slope is between 0 and 1 6

A Really Simple Line Algorithm Equation for a line: y(x) = mx + b Fill in one pixel per column So, just evaluate for each x This requires a choice of quadrant, so x steps evenly Certainly correct, but slow: integer add, cast to float, floating multiply and add, plus round every step. void line (int x0, int y0, int x1, int y1){ float m = whatever; float b = whatever; int x; for(x=x0;x<=x1;x++) { float y= m*x + b; draw_pixel(x,round(y)); } } 7

Lines: DDA Algorithm Optimize the previous to remove multiply from inner loop. If we know y(x), we can calculate y(x+1): y(x+1) = mx + m + b = y(x) + m void line (int x0, int y0, int x1, int y1){ float y = y0; float m = (y1 - y0)/ (float) (x1 - x0); int x; for(x=x0;x<=x1;x++) { draw_pixel(x,round(y)); y += m; } } This is called Differential Digital Analyzer (DDA) because it is solving the very simple differential equation dy/dx = m Problem: Floating-point add and rounds are expensive 8

What do we get from this algorithm? Why did we limit the slope of the line? So we can have this rather than that 9

Bresenham s Algorithm This does the right thing (same as DDA) at a cost of only 2 or 3 integer adds per point. (assumes sorted endpoints, 0<slope<1) void draw_line(int x0, int y0, int x1, int y1) { int x, y = y0; int dx = 2*(x1-x0), dy = 2*(y1-y0); int dydx = dy-dx, F = (dy-dx)/2; } for (x=x0 ; x<=x1 ; x++) { draw_pixel(x, y); if (F<0) F += dy; else {y++; F += dydx;} } F is a decision variable do you increment y on this iteration or not? Why does this work? 10

Implicit Function for a Line Line L from [x 0, y 0 ] to [x 1, y 1 ]. P 0 = [x 0, y 0 ], P 1 = [x 1, y 1 ]. dx = x 1 x 0, dy = y 1 y 0 N = [dy, dx] implicit function : F(P) = 2N (P P 0 ) F = 0 P is on L P P 0 P 1 F > 0 N F < 0 Why the factor of 2? Because we re going to divide by 2 later. 11

(x,y) Line Drawing: Which Pixel is Next? Go here next? (x + 1, y + 1) (x + 1, y) Or here next? Assume: 0<slope<1 sorted endpoints, x 0 <x 1 At each step: Current point is (x,y) Next point is pixel (x+1,?) that s closest to the actual line Do we increment x and y or only x? Use the implicit function to decide! 12

Use the Implicit Function Idea: Test the half-way point (x+1, y+1/2) (x + 1, y + 1) (x,y) (x + 1, y) F(( x + 1, y + 1 2)) > 0? yes : increment x and y no : increment x 13

Trick: Incrementally Update F F(P) = 2N (P P 0 ) F(P + )=2N (P+ P 0 ) =F(P)+2N Computing F(P) requires a dot product: 2 multiplications and 1 add But computing F(P+ ) requires only 1 add The 2N term is constant - it only needs to be calculated once is [1,0] or [1,1] x is incremented, y might or might not be 14

F = [1,0] or [1,1] F 0 0 = = F = F = F = F where so F or F( P F( P F 0 0 0 + [1,1/ ) + + 2N N = [ dy, dx] = F( P ) + + 2dy 2]) N [2,1] 2dy dx + 2dy 2dx Decision Variable F Initialize x, y, F Loop until end of line: drawpixel(x,y) increment x if F>0, increment y increment F according to whether is [1,0] or [1,1] (x,y) (x + 1, y + 1) (x + 1, y) 15

Bresenham Line Algorithm Code Snippet Again this does the right thing (same as DDA) at a cost of only 2 or 3 integer adds per point. (assumes sorted endpoints, 0<slope<1) void draw_line(int x0, int y0, int x1, int y1) { int x, y = y0; int dx = 2*(x1-x0), dy = 2*(y1-y0); int dydx = dy-dx, F = (dy-dx)/2; } for (x=x0; x<=x1; x++) { draw_pixel(x, y); if (F<0) F += dy; else {y++; F += dydx;} } 16

Bresenham Algorithm for Circles Same approach as line algorithm use a decision variable formula derived for a circle (F = x² + y² - r²) Eightfold symmetry only compute the points for one octant - use sign flips to give the rest Extends to general conics (ellipses...) 17

Bresenham Circle Algorithm /* this draws a circle by calculating in one octant */ /* and re-using the resulting point 8 times */ void draw_circle(int radius) { int x = 0, y = radius; int d = 1-radius; while (y>x) { if (d<0) /* select East point next */ d += 2*x + 3; else { /* select South-East point next */ d += 2*(x-y) + 5; y--; } x++; draw_8_pts(x,y); /* draws point in each octant */ } } 18

Scan Converting Filled, Convex Polygons: Basic Approach Find top and bottom vertices Make list of edges along left and right sides For each scanline from top to bottom There s a single span to fill Find left & right endpoints of span, xl & xr Fill pixels inbetween xl & xr Can use Bresenham s algorithm to update xl & xr as you step from line to line If you don t do all of the above carefully, cracks or overlaps between abutting polygons result! xl xr 19

Scan Converting Filled, Concave Polygons: Basic Approach For each scanline Find all the scanline/polygon intersections Sort them left to right Fill the interior spans between intersections Parity Rule: odd ones are interior, even are exterior 20

Inside/Outside Rules This even-odd rule is not the only option. An alternative would be the winding rule: Pick a line to infinity (like the preceding part of the scan line) Add up right-handed minus left-handed crossings non-zero result means it s interior Only matters for self-intersecting primitives 1 1 2 1 1 1 Even-odd rule Winding rule 21

Span Filling Given a sorted list of scanline intersections (X1,X2,...,Xn) Initialize: start at ceiling(x1), set parity = 1 (inside) While x < Xn» if (parity == 1), pixel = fillcolor»x=x+1» if you've passed an intersection, parity =(1-parity) Span X 1 X 2 X 3 X 4 22

Special Cases For an integer intersection - exactly on a pixel set the pixel if it's the beginning of a span, not if it's the end Shared vertices (possible grazing contact) count ymin for parity, not ymax Horizontal edges don t change parity no parity change no parity change set pixel don t set pixel parity change why be so careful? 23

Special Cases 2 Q: Where did these inside/outside rules come from? A: Somebody made them up. You can resolve the special cases any way you want, as long as it s consistent: Avoid drawing a pixel twice if the same edge is used for two adjacent polygons. (It s slightly slower, and leads to errors in XOR mode) Degenerate or horizontal edges should not leave seams. Make sure inside regions stay inside (and vice versa) for small shifts of the polygon 24

Computing Edge/Scanline Intersections How to compute intersection points (X1,..., Xn)? Brute force method Calculate intersection of each scanline with each edge Better method Exploit coherence between scanlines» intersections do not change much between scanlines Cache the intersection information in a table Edge Table with all edges sorted by ymin Active Edge Table containing the edges that intersect the current scanline, sorted by x-intersection, left to right Process the image from the smallest ymin up When you run out of edges you re done 25

Caching Edge/Scanline Intersections Cache the intersection information in a table Edge Table (ET) with all edges sorted by ymin Active Edge Table (AET) containing» the edges that intersect the current scanline» their points of intersection» sorted by x-intersection, left to right BA y max x 1/m A B C D E AE BA, BC DC, DE Edge Table (ET) BA, AE, DE BA, DE BA, DE BA, DE BA, DE BA, BC, DC, DE BA, BC, DC, DE BA, BC, DC, DE BA, BC, DC, DE BA, BC, DC, DE DC, DE DC, DE Active Edge Table (AET) 26