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

Similar documents
Rasterization: Geometric Primitives

From Ver(ces to Fragments: Rasteriza(on

Line Drawing Week 6, Lecture 9

Scan Converting Lines

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

Scan Conversion. Drawing Lines Drawing Circles

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

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

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

Computer Graphics. - Rasterization - Philipp Slusallek

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

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

CS 543: Computer Graphics. Rasterization

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

Chapter 8: Implementation- Clipping and Rasterization

Topic #1: Rasterization (Scan Conversion)

Chapter - 2: Geometry and Line Generations

Line Drawing. Foundations of Computer Graphics Torsten Möller

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

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

Painter s HSR Algorithm

1 Introduction to Graphics

Einführung in Visual Computing

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

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

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

Pipeline implementation II

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

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

Computer Graphics D Graphics Algorithms

Computer Graphics 7 - Rasterisation

CPSC / Scan Conversion

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

Unit 2 Output Primitives and their Attributes

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

CS Rasterization. Junqiao Zhao 赵君峤

Clipping and Scan Conversion

Pipeline and Rasterization. COMP770 Fall 2011

Rendering. A simple X program to illustrate rendering

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

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

CS 130. Scan Conversion. Raster Graphics

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

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

Rasterization. COMP 575/770 Spring 2013

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

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

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

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

Rasterization. CS4620 Lecture 13

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

COMP371 COMPUTER GRAPHICS

CS488 2D Graphics. Luc RENAMBOT

(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?

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

Computer Graphics D Graphics Algorithms

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

CSCI 4620/8626. Coordinate Reference Frames

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

Rendering. A simple X program to illustrate rendering

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

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

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

Scan Conversion. Lines and Circles

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

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

This library uses only GL functions but contains code for creating common objects and simplifying viewing.

Graphics (Output) Primitives. Chapters 3 & 4

Realtime 3D Computer Graphics Virtual Reality

Efficient Plotting Algorithm

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

UNIT -8 IMPLEMENTATION

Display Technologies: CRTs Raster Displays

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Computer Graphics

Topics. From vertices to fragments

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

Chapter 1. Linear Equations and Straight Lines. 2 of 71. Copyright 2014, 2010, 2007 Pearson Education, Inc.

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

An Improved Algorithm for Scan-converting a Line

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

Sec 4.1 Coordinates and Scatter Plots. Coordinate Plane: Formed by two real number lines that intersect at a right angle.

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

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

Chapter 3. Sukhwinder Singh

UNIT 2 GRAPHIC PRIMITIVES

Prof. Feng Liu. Fall /25/2018

Raster Scan Displays. Framebuffer (Black and White)

Section 1.1 The Distance and Midpoint Formulas

Last class. A vertex (w x, w y, w z, w) - clipping is in the - windowing and viewport normalized view volume if: - scan conversion/ rasterization

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

Shading Techniques Denbigh Starkey

Computer Graphics and GPGPU Programming

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

(Refer Slide Time: 9:36)

CS 4300 Computer Graphics. Prof. Harriet Fell Fall 2012 Lecture 5 September 13, 2012

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Section 18-1: Graphical Representation of Linear Equations and Functions

Math-2. Lesson 3-1. Equations of Lines

Overview of Computer Graphics

Transcription:

Rasterization, or What is glbegin(gl_lines) really doing? Course web page: http://goo.gl/eb3aa February 23, 2012 Lecture 4

Outline Rasterizing lines DDA/parametric algorithm Midpoint/Bresenham s algorithm Rasterizing polygons/triangles

Rasterization: What is it? How to go from floating-point coords of geometric primitives vertices to integer coordinates of pixels on screen Geometric primitives Points: Round vertex location in screen coordinates Lines: Can do this for endpoints, but what about in between? Polygons: How to fill area bounded by edges? from Angel

Rasterizing Lines: Goals Draw pixels as close to the ideal line as possible Use the minimum number of pixels without leaving any gaps Do it efficiently Extras Handle different line styles Width Stippling (dotted and dashed lines) Join styles for connected lines Minimize aliasing ( jaggies )

DDA/Parametric Line Drawing DDA stands for Digital Differential Analyzer, the name of a class of old machines used for plotting functions Slope-intercept form of a line: y = mx + b m = dy/dx b is where the line intersects the Y axis DDA s basic idea: If we increment the x coordinate by 1 pixel at each step, the slope of the line tells us how to much increment y per step I.e., m = dy/dx, so for dx = 1, dy = m This only works if m <= 1 otherwise there are gaps Solution: Reverse axes and step in Y direction. Since now dy = 1, we get dx = 1/m from Angel

DDA/Parametric Line Drawing DDA stands for Digital Differential Analyzer, the name of a class of old machines used for plotting functions Slope-intercept form of a line: y = mx + b m = dy/dx b is where the line intersects the Y axis DDA s basic idea: If we increment the x coordinate by 1 pixel at each step, the slope of the line tells us how to much increment y per step I.e., m = dy/dx, so for dx = 1, dy = m This only works if m <= 1 otherwise there are gaps Solution: Reverse axes and step in Y direction. Since now dy = 1, we get dx = 1/m from Angel

DDA: Algorithm 1. Given endpoints (x 0, y 0 ), (x 1, y 1 ) Integer coordinates: Round if endpoints were originally real-valued Assume (x 0, y 0 ) is to the left of (x 1, y 1 ): Swap if they aren t 2. Then we can compute slope: m = dy/dx = (y 1 - y 0 ) / (x 1 - x 0 ) 3. Iterate If m <= 1: Iterate integer x from x 0 to x 1, incrementing by 1 each step Initialize real y = y 0 At each step, y += m, and plot point (x, round(y)) Else m > 1: Iterate integer y from y 0 to y 1, incrementing (or decrementing) by 1 Initialize real x = x 0 At each step, x += 1/m, and plot (round(x), y)

Midpoint/Bresenham s line drawing DDA is somewhat slow Floating-point calculations, rounding are relatively expensive Big idea: Avoid rounding, do everything with integer arithmetic for speed Assume slope between 0 and 1 Again, handle lines with other slopes by using symmetry

Midpoint line drawing: Line equation Recall that the slope-intercept form of the line is y = (dy/dx)x + b Multiplying through by dx, we can rearrange this in implicit form: F(x, y) = dy x - dx y + dx b = 0 F is: Zero for points on the line Positive for points below the line (to (right if slope > 1) Negative for points above the line (left if slope > 1) Examples: (0, 1), (1, 0), etc. 9x - 2y = 0 2x - 9y = 0 from Angel

Midpoint line drawing: The Decision Given our assumptions about the slope, after drawing (x, y) the only choice for the next pixel is between the upper pixel U = (x+1, y+1) and the lower one L = (x+1, y) We want to draw the one closest to the line U L from Hill

Midpoint line drawing: Midpoint decision After drawing (x, y), in order to choose the next pixel to draw we consider the midpoint M = (x+1, y+0.5) If it s on the line, then U and L are equidistant from the line If it s below the line, pixel U is closer to the line than pixel L If it s above the line, then L is closer than U M from Hill

Midpoint line drawing: Midpoint decision So F is a decision function about which pixel to draw: If F(M) = F(x+1, y+0.5) > 0 (M below the line), pick U If F(M) = F(x+1, y+0.5) <= 0 (M above or on line), pick L from Hill

Midpoint line drawing: Implementation Key efficiency insight: F does not have to be fully evaluated every step Suppose we do the full evaluation once and get F(x+1, y+0.5) If we choose L, next midpoint to evaluate M ' is at F(x+2, y+0.5) If we choose U, next midpoint M '' would be at F(x+2, y+1.5) from Hill

Midpoint line drawing: Implementation Key efficiency insight: F does not have to be fully evaluated every step Suppose we do the full evaluation once and get F(x+1, y+0.5) If we choose L, next midpoint to evaluate M ' is at F(x+2, y+0.5) If we choose U, next midpoint M '' would be at F(x+2, y+1.5) from Hill

Midpoint line drawing: Implementation Key efficiency insight: F does not have to be fully evaluated every step Suppose we do the full evaluation once and get F(x+1, y+0.5) If we choose L, next midpoint to evaluate M ' is at F(x+2, y+0.5) If we choose U, next midpoint M '' would be at F(x+2, y+1.5) from Hill

Midpoint line drawing: Implementation Expanding these out using F(x, y) = dy x dx y + dx b : F M = F(x + 1, y + 0.5) = dy(x + 1) - dx(y + 0.5) + dx b F M ' = F(x + 2, y + 0.5) = dy(x + 2) - dx(y + 0.5) + dx b F M '' = F(x + 2, y + 1.5) = dy(x + 2) - dx(y + 1.5) + dx b Note that F M ' - F M = dy and F M '' - F M = dy - dx So depending on whether we choose L or U, we just have to add dy or dy - dx, respectively, to the old value of F in order to get the new value from Hill

Midpoint line drawing: Algorithm To initialize, we do a full calculation of F at the first midpoint next to the left line endpoint: F(x 0 + 1, y 0 + 0.5) = dy(x 0 + 1) - dx(y 0 + 0.5) + dx b = dy x 0 - dx y 0 + dx b + dy - 0.5 dx = F(x 0, y 0 ) + dy - 0.5 dx But F(x 0, y 0 ) = 0 since it s on the line, so our first F = dy - 0.5 dx Only the sign matters for the decision, so to make it an integer value we multiply by 2 to get 2F = 2 dy - dx To update, keep current values for x and y and a running total for F: When L is chosen: F += 2dy and x++ When U is chosen: F += 2(dy - dx) and x++, y++

Line drawing speed 100,000 random lines in 500 x 500 window (average of 5 runs) DDA: 6.8 seconds Midpoint: 2.5 seconds OpenGL using GL_LINES (in software): 1.6 seconds

Extensions How to draw thick (>1 pixel wide) lines? Nested Bresenham s (perpendicular to main line at each step, or series of parallel lines) Stippled/dashed lines Add state (pen up/down) inside loop

Polygon Rasterization Given a set of vertices, want to fill the interior Basic procedure: Iterate over scan lines between top and bottom vertex For each scan line, find all intersections with polygon edges odd- Sort intersections by x-value and fill pixel runs between even pairs of intersections from Hill

Polygon Rasterization: Notes Refinements Maintain correct parity by discarding intersections with upper endpoint of any edge Avoid double-drawing at border of abutting polygons (bad if blending/ XOR ing): Left/bottom ownership Draw pixel on left edge of run but not right Discard intersections with any horizontal edges Efficiency Avoid checking intersections with all poly edges for each scanline by keeping an active edge list from Hill

Rasterizing triangles Special case of polygon rasterization Exactly two active edges at all times One method: Fill scanline table between top and bottom vertex with leftmost and rightmost side by using DDA or midpoint algorithm to follow edges Traverse table scanline by scanline, fill run from left to right