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

Similar documents
1 Introduction to Graphics

Prof. Feng Liu. Fall /25/2018

Rasterization: Geometric Primitives

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

CS 450: COMPUTER GRAPHICS RASTERIZING LINES SPRING 2016 DR. MICHAEL J. REALE

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

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

From Ver(ces to Fragments: Rasteriza(on

GRAPHICS OUTPUT PRIMITIVES

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

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

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

Rendering. A simple X program to illustrate rendering

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

Scan Converting Lines

Chapter 8: Implementation- Clipping and Rasterization

Line Drawing Week 6, Lecture 9

Lecture 6 of 41. Scan Conversion 1 of 2: Midpoint Algorithm for Lines and Ellipses

Lecture 6 of 41. Scan Conversion 1 of 2: Midpoint Algorithm for Lines and Ellipses

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

UNIT -8 IMPLEMENTATION

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

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

Scan Conversion. Drawing Lines Drawing Circles

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

CS 543: Computer Graphics. Rasterization

EF432. Introduction to spagetti and meatballs

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

Painter s HSR Algorithm

Realtime 3D Computer Graphics Virtual Reality

Graphics (Output) Primitives. Chapters 3 & 4

Rendering. A simple X program to illustrate rendering

Graphics Output Primitives

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

CSC Computer Graphics

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

Topic #1: Rasterization (Scan Conversion)

Shading Techniques Denbigh Starkey

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

(Refer Slide Time: 00:02:00)

OUTPUT PRIMITIVES. CEng 477 Introduction to Computer Graphics METU, 2007

CS Rasterization. Junqiao Zhao 赵君峤

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

Rasterization. CS4620/5620: Lecture 12. Announcements. Turn in HW 1. PPA 1 out. Friday lecture. History of graphics PPA 1 in 4621.

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

Pipeline implementation II

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

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

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

Computer Graphics. Modelling in 2D. 2D primitives. Lines and Polylines. OpenGL polygon primitives. Special polygons

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

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

Line Drawing. Foundations of Computer Graphics Torsten Möller

COMP371 COMPUTER GRAPHICS

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

Chapter - 2: Geometry and Line Generations

CS488 2D Graphics. Luc RENAMBOT

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

(Refer Slide Time: 00:03:51)

Rasterization and Graphics Hardware. Not just about fancy 3D! Rendering/Rasterization. The simplest case: Points. When do we care?

CPSC / Scan Conversion

(Refer Slide Time: 9:36)

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

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

Computer Graphics. - Rasterization - Philipp Slusallek

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

EF432. Introduction to spagetti and meatballs

Display Technologies: CRTs Raster Displays

UNIT 2 GRAPHIC PRIMITIVES

Last time? Rasterization. Scan Conversion (Rasterization) High-level concepts for Visibility / Display. Today

Chapter 3. Sukhwinder Singh

Institutionen för systemteknik

COMP3421. Particle Systems, Rasterisation

Rendering approaches. 1.image-oriented. 2.object-oriented. foreach pixel... 3D rendering pipeline. foreach object...

(Refer Slide Time: 00:02:02)

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

Rasteriza2on and Clipping

Rendering. Basic Math Review. Rasterizing Lines and Polygons Hidden Surface Remove Multi-pass Rendering with Accumulation Buffers.

Points and lines. x x 1 + y 1. y = mx + b

Pipeline and Rasterization. COMP770 Fall 2011

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

Topics. From vertices to fragments

Rasterization. CS4620 Lecture 13

Computer Graphics D Graphics Algorithms

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

Computer Graphics. Lecture 3 Graphics Output Primitives. Somsak Walairacht, Computer Engineering, KMITL

Efficient Plotting Algorithm

Rasterization. CS 4620 Lecture Kavita Bala w/ prior instructor Steve Marschner. Cornell CS4620 Fall 2015 Lecture 16

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

CS 130 Final. Fall 2015

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

Rasterization. COMP 575/770 Spring 2013

Surface shading: lights and rasterization. Computer Graphics CSE 167 Lecture 6

RASTERIZING POLYGONS IN IMAGE SPACE

CS 4731/543: Computer Graphics Lecture 7 (Part I): Raster Graphics: Polygons & Antialiasing. Emmanuel Agu

Einführung in Visual Computing

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

CS 428: Fall Introduction to. Polygon rendering: additional topics. Andrew Nealen, Rutgers, /14/2009 1

Lecture 2 October 31, 2005

Transcription:

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

Rater Displays Screen is represented by 2D array of locations called piels y

Rater Displays Screen is represented by 2D array of locations called piels At each piel 2 N intensities/colors can be generated Grayscale 2 8 = 256 Color (2 8 + 2 8 + 2 8 ) y

Rater Displays Screen is represented by 2D array of locations called piels At each piel 2 N intensities/colors can be generated Grayscale 2 8 = 256 Color (2 8 + 2 8 + 2 8 ) Colors are stored in a frame buffer physical memory on a graphics card Primitive operations setpiel (,y,c) getpiel (,y) y

Scan Conversion Convert basic CG objects (2D) into corresponding pielmap representation Since objects are often specified using real valued mathematical primitives (e.g. lines, circles, arcs, etc.), often an approimation to object Continuous line Digital line (8,6) y y (1,5)

Scan Conversion for Lines Set piels to desired line color to approimate the line from (, y ) to ( 1, y 1 ) Goals Accuracy: piels should approimate the line as closely as possible Speed: line drawing should be as efficient as possible Visual quality: uniform brightness Usability: independent of point order, independent of the slope

Equation of the Line y = m + Points that are on the line must satisfy equation above (where m = slope, b = y-intercept) y y 1 m b = = = = y m m y 1 1 1 + + y b m b y = m( + y ) y b Continuous line Continuous line ( 1,y 1 ) (,y) m (,y ) This is the form we ll prefer to use for this lecture

Line Drawing: Basic Idea We need to determine the piels that lie closest to the mathematical line Digital line Simple Algorithm 1. Draw piel at line start

Line Drawing: Basic Idea We need to determine the piels that lie closest to the mathematical line Digital line Simple Algorithm 1. Draw piel at line start 2. Increment piel position by 1

Line Drawing: Basic Idea We need to determine the piels that lie closest to the mathematical line Digital line Simple Algorithm? 1. Draw piel at line start 2. Increment piel position by 1 3. Determine the y position of the piel lying closest to the line

Line Drawing: Basic Algoruithm We need to determine the piels that lie closest to the mathematical line Digital line Simple Algorithm? compute m for (=, <= 1, ++) y = m (- ) + y setpiel (, round(y), c) end y is real if m is real Problem: What if points are given in the wrong order? Solution: Detect ( 1 < ) and switch order of points

Line Drawing: Basic Algorithm Let s test with m = 1 Simple Algorithm compute m for (=, <= 1, ++) y = m (- ) + y setpiel (, round(y), c) end

Line Drawing: Basic Algorithm Let s test with m = 1/2 Simple Algorithm compute m for (=, <= 1, ++) y = m (- ) + y setpiel (, round(y), c) end

Line Drawing: Basic Algorithm Let s test with m = 2 Simple Algorithm compute m for (=, <= 1, ++) y = m (- ) + y setpiel (, round(y), c) end Problem: When m > 1 Solution: Loop over y instead of when m > 1

Line Drawing: Basic Algorithm Let s test with m = 2 Simple Algorithm (etended) compute m if (m <= 1) for ( =, <= 1, ++) y = m (- ) + y setpiel (, round(y), c) end else for (y = y, y <= y 1, y++) = (y-y )/m + setpiel (round(), y, c) end end

Line Drawing: Basic Algorithm Key disadvantage: inefficiency relies on floating-point operations to compute piel positions floating-point operations are slow Alternative: Bresnham s Algorithm Incremental integer approach

Bresenham s Algorithm Incremental approach: assume piel ( i, y i ) is on how do we tell which piel to turn on net? y i +1 Line point @ i+1 : Q = m ( i + 1 ) + y Basic Idea 1. Test if Q < is above or bellow M y i i i +1 Midpoint: M = ( i +1, y i +.5) (also known as Midpoint Algorithm)

Bresenham s Algorithm Incremental approach: assume piel ( i, y i ) is on how do we tell which piel to turn on net? y i +1 Line point @ i+1 : Q = m ( i + 1 ) + y Basic Idea 1. Test if Q < is above or bellow M 2. If Q bellow M turn on ( i+1, y i ) y i i i +1 Midpoint: M = ( i +1, y i +.5) (also known as Midpoint Algorithm)

Bresenham s Algorithm Incremental approach: assume piel ( i, y i ) is on how do we tell which piel to turn on net? y i +1 Line point @ i+1 : Q = m ( i + 1 ) + y Basic Idea 1. Test if Q < is above or bellow M 2. If Q bellow M turn on ( i+1, y i ) 3. If Q above M turn on ( i+1, y i+1 ) y i i i +1 Midpoint: M = ( i +1, y i +.5) (also known as Midpoint Algorithm)

Bresenham s Algorithm Incremental approach: assume piel ( i, y i ) is on how do we tell which piel to turn on net? y i +1 Line point @ i+1 : Q = m ( i + 1 ) + y Basic Idea 1. Test if Q < is above or bellow M 2. If Q bellow M turn on ( i+1, y i ) 3. If Q above M turn on ( i+1, y i+1 ) y i 4. Repeat above steps for the newly draw point i i +1 Midpoint: M = ( i +1, y i +.5) Steps guarantee that closest piel to line is always chosen (also known as Midpoint Algorithm)

Bresenham s Algorithm Incremental approach: assume piel ( i, y i ) is on how do we tell which piel to turn on net? Line point @ i+1 : Q = m ( i + 1 ) + y Basic Idea How do we decide if Q is above or bellow M? y i +1 Look at the implicit function of the line f(,y) y i i i +1 Midpoint: M = ( i +1, y i +.5)

Implicit function of the line 1 1 W y y H = = H W m ) ( ) ( Wy H Wy y W H y + = + = ) ( y m y + = ) ( ) ( ), ( y W y H y f + = = ) ( 2 ) ( 2 ), ( y W y H y f = = If f(,y) = then (,y) on the line If f(,y) < then (,y) above line Eercise for home, show that indeed If f(,y) > then (,y) bellow line

Bresenham s Algorithm Incremental approach: assume piel ( i, y i ) is on how do we tell which piel to turn on net? Line point @ i+1 : Q = y = m ( i + 1 ) + y Basic Idea How do we decide if Q is above or bellow M? y i +1 y i i i +1 Look at the implicit function of the line f(,y) @ the midpoint If f( i +1, y i +.5) < then j = i +1 y j = y i If f( i +1, y i +.5) < then j = i +1 Midpoint: y j = y i +1 M = ( i +1, y i +.5)

Now, why did we multiply by 2? ) ( 2 ) ( 2 ), ( y W y H y f = = ).5 ( 2 ) 1 ( 2.5) 1, ( y W y H y f i i i i + + = = + + Now this computation can be done in terms of integers

Now, why did we multiply by 2? f (, y) = = 2H( ) 2W( y y ) f ( i + 1, y i +.5) = = 2H( i + 1 ) 2W( y i +.5 y ) Note, that we only need to keep track of f(,y) at the mid points, which can be done efficiently incrementally f ( + 1, y) = f (, y) + 2H f ( + 1, y + 1) = f (, y) + 2( H W)

Now, why did we multiply by 2? f (, y) = = 2H( ) 2W( y y ) f ( i + 1, y i +.5) = = 2H( i + 1 ) 2W( y i +.5 y ) Note, that we only need to keep track of f(,y) at the mid points, which can be done efficiently incrementally Very Efficient f ( + 1, y) = f (, y) + 2H f ( + 1, y + 1) = f (, y) + 2( H W)

Bresenham s Algorithm y = y H = y 1 y W = 1 f = 2H W for ( =, <= 1, ++) setpiel (, y, c) if (f <) f += 2H else y++ f += 2(H-W) end end Note, initially f(,y )=, so first test is @ f( +1, y +.5) f ( // y stays the same // y increases + 1, y +.5) = 2H( + 1 2W( y = 2H W ) +.5 y )

Bresenham s Algorithm Limitations: same as the basic line drawing, the Bresenham s algorithm in the last slide only works for m < 1 and has to be altered for a more general cases To make it general need to (as in the basic line drawing algorithm) Switch order of points if necessary Iterate over y if m > 1

Aliasing An unfortunate artifact of the line scan conversion discussed is that lines have jaggy appearance This phenomenon is called aliasing

Anti-aliasing Main idea: rather than just drawing in s and 1 s, use in-between values in neighborhood of the mathematical line Aliased line Anti-aliased line

Anti-aliasing Comparison

Polygon Filling Scan Conversion Goal: find piels that occupy inside of the polygon and fill them with a given color Polygon Filling 2 3 P = ( 1, 2, 3, 4, 5) 5 1 4

Polygon Filling Idea Goal: find piels that occupy inside of the polygon and fill them with a given color Polygon Filling 2 3 Simple Idea For each horizontal scanline L L 5 1 4

Polygon Filling Idea Goal: find piels that occupy inside of the polygon and fill them with a given color L Polygon Filling 2 3 Simple Idea For each horizontal scanline L 1. Find intersection of L with P (store in active edge list AEL) 5 1 4

Polygon Filling Idea Goal: find piels that occupy inside of the polygon and fill them with a given color Polygon Filling 2 3 L 1 2 5 Simple Idea For each horizontal scanline L 1. Find intersection of L with P (store in active edge list AEL) 2. Sort intersections by increasing value of 1 4

Polygon Filling Idea Goal: find piels that occupy inside of the polygon and fill them with a given color Polygon Filling 2 3 L 1 2 5 1 4 Simple Idea For each horizontal scanline L 1. Find intersection of L with P (store in active edge list AEL) 2. Sort intersections by increasing value of 3. Fill piels between pairs of intersections

Polygon Filling Algorithm Algorithm Active Edge List (AEL) y=n... for each edge [(, y ), ( 1,y 1 )] in P =; compute m for (y=y, y<=y 1, y++) = + 1/m place (round(), y) in AEL end end Does this remind you of anything? y= 1 2 3

Polygon Filling Special Cases A B C Intersections: one @ A two @ B one @ C A B C D Intersections: one @ A two @ B one @ C one @ D

Polygon Filling Special Cases A B C Intersections: one @ A two @ B one @ C works!!! A B C D problem!!! Intersections: one @ A two @ B one @ C one @ D

Polygon Filling Handling Special Cases All problems can be handled by 2 simple rules only rasterize edges (not intersections) Ignore horizontal edges

Clipping Clipping: used to determine which parts of the line/polygon lie inside viewing window allows efficient rendering and rastering (W R, W T ) (W L, W B )

Clipping Algorithm Every line segment of the polygon is either trivially inside (both endpoints lie inside the window) trivially outside (both endpoints lie outside of one of the half-spaces that define the window) candidate for clipping (W R, W T ) (W L, W B )

Clipping Algorithm Every line segment of the polygon is either trivially inside (both endpoints lie inside the window) Keep trivially outside (both endpoints lie outside of one of the half-spaces that define the window) candidate for clipping (W R, W T ) Remove (W L, W B )

Clipping Algorithm Every line segment of the polygon is either trivially inside (both endpoints lie inside the window) Keep trivially outside (both endpoints lie outside of one of the half-spaces that define the window) candidate for clipping Find the intersection with the window (if eists) Disregard irrelevant part of the segment Remove