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

Similar documents
From Ver(ces to Fragments: Rasteriza(on

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline

CS Rasterization. Junqiao Zhao 赵君峤

Rasterization. MIT EECS Frédo Durand and Barb Cutler. MIT EECS 6.837, Cutler and Durand 1

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

Line Drawing. Foundations of Computer Graphics Torsten Möller

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

Chapter 8: Implementation- Clipping and Rasterization

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

Rasterization: Geometric Primitives

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Rendering. A simple X program to illustrate rendering

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

Graphics (Output) Primitives. Chapters 3 & 4

Scan Conversion. Drawing Lines Drawing Circles

Computer Graphics. - Rasterization - Philipp Slusallek

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

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

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

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

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

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

Computer Graphics 7 - Rasterisation

Final projects. Rasterization. The Graphics Pipeline. Illumination (Shading) (Lighting) Viewing Transformation. Rest of semester. This week, with TAs

CPSC / Scan Conversion

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

Chapter - 2: Geometry and Line Generations

Realtime 3D Computer Graphics Virtual Reality

COMP371 COMPUTER GRAPHICS

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

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

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

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

CS 543: Computer Graphics. Rasterization

Topic #1: Rasterization (Scan Conversion)

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

Line Drawing Week 6, Lecture 9

Rendering. A simple X program to illustrate rendering

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

Clipping and Scan Conversion

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

Pipeline implementation II

Overview of Computer Graphics

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

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

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

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

Efficient Plotting Algorithm

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

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

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

Computer Graphics D Graphics Algorithms

Pipeline Operations. CS 4620 Lecture 10

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

Einführung in Visual Computing

Display Technologies: CRTs Raster Displays

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

EF432. Introduction to spagetti and meatballs

1 Introduction to Graphics

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

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

CS452/552; EE465/505. Clipping & Scan Conversion

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

Scan Conversion. Lines and Circles

Rasterization Overview

CSCI 4620/8626. Coordinate Reference Frames

CS 130 Exam I. Fall 2015

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

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

Computer Graphics and GPGPU Programming

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

MET71 COMPUTER AIDED DESIGN

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

Last Time. Why are Shadows Important? Today. Graphics Pipeline. Clipping. Rasterization. Why are Shadows Important?

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

CS 130. Scan Conversion. Raster Graphics

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

Scan Converting Lines

Output Primitives Lecture: 4. Lecture 4

Rasteriza2on and Clipping

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

Chapter 3. Sukhwinder Singh

For Intuition about Scene Lighting. Today. Limitations of Planar Shadows. Cast Shadows on Planar Surfaces. Shadow/View Duality.

Fondamenti di Grafica 3D The Rasterization Pipeline.

CS 130 Final. Fall 2015

Last Time. Reading for Today: Graphics Pipeline. Clipping. Rasterization

CS 112 The Rendering Pipeline. Slide 1

Pipeline and Rasterization. COMP770 Fall 2011

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

UNIT -8 IMPLEMENTATION

Pipeline Operations. CS 4620 Lecture 14

EF432. Introduction to spagetti and meatballs

UNIT 2 GRAPHIC PRIMITIVES

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

Transcription:

From Vertices to Fragments: Rasterization Reading Assignment: Chapter 7 Frame Buffer Special memory where pixel colors are stored. System Bus CPU Main Memory Graphics Card -- Graphics Processing Unit (GPU) -- Frame Buffer

The Graphics Pipeline Modeling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display Modeling Transformations Modeling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping 3D models defined in their own coordinate system (object space) Modeling transforms orient the models within a common coordinate frame (world space) Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display Object space World space

Illumination (Shading) (Lighting) Modeling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Vertices lit (shaded) according to material properties, surface properties (normal) and light sources Local lighting model (Diffuse, Ambient, Phong, etc.) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display Viewing Transformation Modeling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Maps world space to eye space Viewing position is transformed to origin & direction is oriented along some axis (usually z) Clipping Projection (to Screen Space) Eye space Scan Conversion (Rasterization) Visibility / Display World space

Clipping Modeling Transformations Illumination (Shading) Transform to Normalized Device Coordinates (NDC) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display Eye space Portions of the object outside the view volume (view frustum) are removed NDC Projection Modeling Transformations Illumination (Shading) The objects are projected to the 2D image place (screen space) Viewing Transformation (Perspective / Orthographic) Clipping NDC Screen Space Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display

Scan Conversion (Rasterization) Modeling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Rasterizes objects into pixels Interpolate values as we go (color, depth, etc.) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display Visibility / Display Modeling Transformations Illumination (Shading) Each pixel remembers the closest object (depth buffer) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display Almost every step in the graphics pipeline involves a change of coordinate system. Transformations are central to understanding 3D computer graphics.

From Geometry to Display Rasterization How to draw primitives? Convert from geometric definition to pixels Rasterization = selecting the pixels Will be done frequently Must be fast: use integer arithmetic use addition instead of multiplication

Next Line-drawing algorithm naïve algorithm Bresenham algorithm Circle-drawing algorithm naïve algorithm Bresenham algorithm Scan Converting 2D Line Segments Given: Segment endpoints (integers x1, y1; x2, y2) Identify: Set of pixels (x, y) to display for segment (x2, y2) (x1, y1)

Line Rasterization Requirements Transform continuous primitive into discrete samples Uniform thickness & brightness Continuous appearance No gaps (x2, y2) Accuracy Speed (x1, y1) Simple Line Based on slope-intercept algorithm from algebra: y = mx + h Simple approach: h (x 2, y 2 ) increment x, solve for y Floating point arithmetic required (x 1, y 1 )

Naive Line Rasterization Algorithm Simply compute y as a function of x Conceptually: move vertical scan line from x1 to x2 What is the expression of y as function of x? Set pixel (x, round (y)) (x2, y2) y = x x1 y1 + ( y2 y1) x2 x1 = y1 + m( x x1) y (x1, y1) m = dy dx x Efficiency Computing y value is expensive y = y1 + m( x x1) Observe: y += m at each x step (m = dy/dx) y(x+1) y(x) (x1, y1) (x2, y2) y(x+1) y(x) m x x+1 x x+1

Does it Work? It seems to work okay for lines with a slope of 1 or less Doesn t work well for lines with slope greater than 1 lines become more discontinuous in appearance and we must add more than 1 pixel per column to make it work. Solution? - use symmetry. Modify Algorithm per Octant OR, increment along x-axis if dy<dx else increment along y-axis

Bresenham's Algorithm Select pixel vertically closest to line segment intuitive, efficient, pixel center always within 0.5 vertically Same answer as naive approach Bresenham's Algorithm Observation: If we're at pixel P (x p, y p ), the next pixel must be either E (x p +1, y p ) or NE (x p +1, y p +1) Why? P NE E

Bresenham Step Which pixel to choose: E or NE? Error associated with a pixel: NE Error pixel NE E Error pixel E Pick the pixel with error < ½ The sum of the 2 errors is Bresenham Step How to compute the error? Line defined as y = mx + h Vertical distance from line to pixel (x, y): e(x, y) = mx+h-y negative if pixel above L zero on L positive below L L e is called the error function. e<0 e=0 e>0

Bresenham's Algorithm How to compute the error? Error Function: e(x, y) = mx+h-y Initialize error term e = 0 e e On each iteration: update x: update e: if (e 0.5): if (e > 0.5): x' = x+1 e' = e + m y' = y (choose pixel E) y' = y +1 (choose pixel NE) e' = e - 1 Summary of Bresenham Initialize e = 0 for (x = x1; x x2; x++) plot(x,y) update x, y, e NE E Generalize to handle all eight octants using symmetry Still using floating point! e = e + m Can we use only integer arithmetic?

Bresenham with no Floating Point y2 y1 Error function e(x, y) = mx+h-y, m = = x2 x1 At selected pixel (x,y): e(x, y) <= ½ 2mx + 2h 2y 1 <= 0 2x dy + 2h dx 2y dx dx <=0 If e <= 0 stay horizontal If e > 0 move up Update for next pixel: NE E dy dx If stay horizontal: x+=1, e += 2dy If move up: x+=1, y+=1, e += 2(dy dx) Algorithm = single instruction on graphics chips! Line Anti-aliasing Note: brightness can vary with slope What is the maximum variation? How could we compensate for this? Answer: antialiasing 2 * L L

How do we remove aliasing? Solution 1 - Area Sampling: Treat line as a single-pixel wide rectangle Color pixels according to the percentage of each pixel that is covered by the rectangle How do we remove aliasing? Solution 2 Super Sampling: Divide pixel up into sub-pixels : 2x 2, 3x3, 4x4, etc. Pixel color is the average of its sub-pixel colors Easy to implement (in SW and HW). But expensive. No antialiasing Antialiasing (2 2 super-sampling)

OpenGL Antialiasing Can enable separately for points, lines, or polygons For points and lines: glenable(gl_point_smooth); glenable(gl_line_smooth); For triangles: glenable(gl_polygon_smooth); Next: Circle Rasterization

Circle Rasterization Generate pixels for 2nd octant only Slope progresses from 0 1 Analog of Bresenham Segment Algorithm Circle Rasterization: Naïve algorithm Circle equation: x 2 +y 2 -R 2 = 0 Simple algorithm: for x = xmin to xmax y = sqrt(r*r - x*x) draw pixel(x,y) Work by octants and use symmetry

Circle Rasterization: Bresenham Choice between two pixels, E and SE Mid-point algorithm: If the midpoint between pixels is inside the circle, E is closer, draw E If the midpoint is outside, SE is closer, draw SE + + + + E SE R Circle Rasterization: Bresenham In/Out decision function: d(x, y) = x 2 + y 2 R 2 Compute d at midpoint btw E, SE + + + + E SE If the last pixel drawn is (x,y), then E = (x+1, y), and SE = (x+1, y-1). Hence, the midpoint = (x+1, y-1/2). R e(x,y) = (x+1) 2 + (y - 1/2) 2 -R 2 e < 0: draw E e 0: draw SE

Circle Rasterization: Bresenham Error Function: e(x, y) = (x+1) 2 + (y - 1/2) 2 -R 2 + + + + E SE On each iteration: update x: update e: if (e < 0): if (e 0): x' = x + 1 e' = e + 2x + 3 y' = y (choose E) y' = y - 1 (choose SE), e' = e -2y+2 Two multiplications, two additions per pixel Can you do better? R Circle Rasterization: Better Bresenham On each iteration: update x: x' = x + 1 update e: e' = e + 2x + 3 if (e < 0): y' = y (choose E) if (e 0): y' = y - 1 (choose SE), e' = e -2y+2 The error is not linear However, what gets added to the error is Keep Δx and Δy. At each step: Δx+= 2, Δy+= -2 e += Δx, and if y gets decremented, e += Δy 4 additions per pixel

Extensions to Other Functions Midpoint algorithm easy to extend to any curve defined by: f(x,y) = 0 If the curve is polynomial, can be reduced to only additions using n-order differences 2D Scan Conversion Geometric primitive 2D: point, line, polygon, circle... 3D: point, line, polyhedron, sphere... Primitives are continuous; screen is discrete

Use line rasterization Compute the boundary pixels Scan-line Rasterization Compute the boundary pixels Fill the spans Requires some initial setup to prepare

For modern graphics cards Triangles are usually very small Setup cost troublesome Brute force is tractable Modern Rasterization For every triangle ComputeProjection Compute bbox, clip bbox to screen limits For all pixels in bbox If pixel in triangle Framebuffer[x,y]=triangleColor