Rasterization. COMP 575/770 Spring 2013

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

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

Rasterization. CS4620 Lecture 13

Pipeline and Rasterization. COMP770 Fall 2011

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

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

CS4620/5620: Lecture 14 Pipeline

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

Einführung in Visual Computing

Realtime 3D Computer Graphics Virtual Reality

Pipeline Operations. CS 4620 Lecture 14

Rasterization: Geometric Primitives

Computer Graphics 7 - Rasterisation

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

Line Drawing. Foundations of Computer Graphics Torsten Möller

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

Scan Converting Lines

Line Drawing Week 6, Lecture 9

Chapter 8: Implementation- Clipping and Rasterization

Graphics Pipeline 2D Geometric Transformations

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

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

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

CS 130 Exam I. Fall 2015

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

CSE 167: Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

CS 130 Exam I. Fall 2015

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

Topics. From vertices to fragments

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

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

CS 543: Computer Graphics. Rasterization

CS 130 Final. Fall 2015

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

RASTERIZING POLYGONS IN IMAGE SPACE

Introduction Rasterization Z-buffering Shading. Graphics 2012/2013, 4th quarter. Lecture 09: graphics pipeline (rasterization and shading)

CSE 167: Introduction to Computer Graphics Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

CS 4620 Final Exam. (a) Is a circle C 0 continuous?

Chapter - 2: Geometry and Line Generations

Institutionen för systemteknik

1 Introduction to Graphics

Pipeline implementation II

Graphics (Output) Primitives. Chapters 3 & 4

Triangle Rasterization

CS 130. Scan Conversion. Raster Graphics

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

Clipping and Scan Conversion

CS488 2D Graphics. Luc RENAMBOT

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

Computer Graphics. - Rasterization - Philipp Slusallek

Geometric Primitives. Chapter 5

The Traditional Graphics Pipeline

Pipeline Operations. CS 4620 Lecture 10

The Traditional Graphics Pipeline

Painter s HSR Algorithm

Computer Graphics and GPGPU Programming

The Traditional Graphics Pipeline

COMP371 COMPUTER GRAPHICS

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

Drawing Fast The Graphics Pipeline

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

Werner Purgathofer

Topic #1: Rasterization (Scan Conversion)

CMSC 435 Introductory Computer Graphics Pipeline. Announcements

- Rasterization. Geometry. Scan Conversion. Rasterization

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

Triangle Fast Scan-Conversion Algorithm Report

Display Technologies: CRTs Raster Displays

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination

Scanline Rendering 2 1/42

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

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination (Total: 100 marks)

From Ver(ces to Fragments: Rasteriza(on

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

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

Transforms. COMP 575/770 Spring 2013

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

CS 381 Computer Graphics, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Tuesday, October 16, 2012.

Real-Time Graphics Architecture

E.Order of Operations

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

Rasterization. Computer Graphics Fabio Pellacini and Steve Marschner

CS452/552; EE465/505. Geometry Transformations

Drawing Fast The Graphics Pipeline

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

CS Rasterization. Junqiao Zhao 赵君峤

Review for Mastery Using Graphs and Tables to Solve Linear Systems

CS 4620 Program 3: Pipeline

UNIT -8 IMPLEMENTATION

9.1 Linear Inequalities in Two Variables Date: 2. Decide whether to use a solid line or dotted line:

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

The Rasterization Pipeline

CPSC / Scan Conversion

Graphics Hardware and Display Devices

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

COMP 175 COMPUTER GRAPHICS. Ray Casting. COMP 175: Computer Graphics April 26, Erik Anderson 09 Ray Casting

Standard Graphics Pipeline

Computing Visibility. Backface Culling for General Visibility. One More Trick with Planes. BSP Trees Ray Casting Depth Buffering Quiz

Transcription:

Rasterization COMP 575/770 Spring 2013

The Rasterization Pipeline you are here APPLICATION COMMAND STREAM 3D transformations; shading VERTEX PROCESSING TRANSFORMED GEOMETRY conversion of primitives to pixels RASTERIZATION FRAGMENTS blending, compositing, shading user sees this FRAGMENT PROCESSING FRAMEBUFFER IMAGE DISPLAY

Rasterization 1. Project a primitive onto the screen 2. Find which pixels lie inside the projection 3. Interpolate attributes at each pixel These are quantities that help in shading 4. Perform shading

Outline Overview Line Rasterization

Rasterizing Lines Most pixels won t lie on the line! Approximate line using thin rectangle

Rasterizing Lines Mark all pixels inside the thin rectangle? Problem: Sometimes marks adjacent pixels

Rasterizing Lines

Midpoint Algorithm Mark only one pixel per column The closest one Basically, line width defined parallel to pixel grid

Midpoint Algorithm

Midpoint Algorithm Slope-intercept form of line equation: y = mx + b We assume m (0,1] There are three other analogous cases: m (, 1] m ( 1,0] m (1, )

Midpoint Algorithm Evaluate line equation per column Endpoints at x 0 < x 1 for x = ceil(x 0 ) to floor(x 1 ) y = m*x + b mark(x, round(y)) end y = 1.91 + 0.37 x

Midpoint Algorithm Evaluate line equation per column Endpoints at x 0 < x 1 x = ceil(x 0 ) while x < floor(x 1 ) y = m*x + b mark(x, round(y)) x += 1 end y = 1.91 + 0.37 x

Optimized Midpoint Algorithm Two slow operations: Multiply: y = m*x + b Round: mark(x, round(y)) y varies predictably: y x + 1 = m x + 1 + b = y x + m x = ceil(x 0 ) y = m*x + b while x < floor(x 1 ) mark(x, round(y)) x += 1 y += m end

Optimized Midpoint Algorithm Only two options when moving to next column Which does line pass closer to? d = m x + 1 + b y If d > 0.5, line is closer to NE Otherwise, closer to E

Optimized Midpoint Algorithm Incrementally update d If we choose E: Increment d by m If we choose NE: Increment d by m 1 Approach also called digital differential analyzer (DDA) d = m x + 1 + b y

Optimized Midpoint Algorithm x = ceil(x 0 ) y = round(m*x + b) d = m*(x+1) + b - y while x < floor(x 1 ) if d > 0.5 y += 1 d -= 1 end x += 1 d += m mark(x, y) end

Outline Overview Line Rasterization Line Attributes

Attribute Interpolation Attributes are often attached to vertices/endpoints E.g., color of hair drawn using lines Want color to vary smoothly along line segments Linear interpolation: f x = 1 α y 0 + αy 1 α = x x 0 x 1 x 0 α is the fraction of distance from (x 0, y 0 ) to (x 1, y 1 )

Attribute Interpolation Suppose endpoint attributes are A 0 and A 1 A x = A 0 + α(a 1 A 0 ) Since α is linear in x, can write an incremental expression

Outline Overview Line Rasterization Line Attributes Triangle Rasterization

Triangle Rasterization The most common primitive in most applications Can represent any object using many triangles A triangle always projects to a triangle Triangle represented by 3 vertices a = (x a, y a ), b = (x b, y b ), and c = x c, y c Need to figure out which pixels are inside the triangle

Bounding Rectangle Smallest rectangular portion of screen which contains triangle No pixels outside it could possibly be in the triangle x min = floor(min(x a, x b, x c )) x max = ceil(max(x a, x b, x c )) y min = floor(min(y a, y b, y c )) y max = ceil(max(y a, y b, y c ))

Triangle Rasterization x min = floor(min(x a, x b, x c )) x max = ceil(max(x a, x b, x c )) y min = floor(min(y a, y b, y c )) y max = ceil(max(y a, y b, y c )) for y = y min to y max for x = x min to x max if (x, y) is in triangle mark(x, y) end end end

Barycentric Coordinates A triangle is a convex shape Any point in the triangle is a convex combination of the triangle s vertices: Subject to: p = αa + βb + γc α + β + γ = 1

Barycentric Coordinates α, β, γ are called the barycentric coordinates of p p lies inside the triangle if α 0, β 0, and γ 0 Alternatively: β 0, γ 0, and β + γ 1 Main goal: determine β, γ

Barycentric Coordinates Rewriting: p = a + β b a + γ c a We ve seen this sort of thing before! (β, γ) are coordinates of p in a different frame: a is the origin (b a) and (c a) are the axes

Barycentric Coordinates

Barycentric Coordinates Construct the frame-to-canonical matrix: b a c a a 0 0 1 Invert to get the canonical-to-frame matrix: β γ 1 = F β γ 1 = x y 1 β γ 1 = F 1 x y 1 = b a c a a 0 0 1 1 x y 1

Barycentric Coordinates The final answer is: β = γ = y a y c x + x c x a y + x a y c x c y a y a y c x b + x c x a y b + x a y c x c y a y a y b x + x b x a y + x a y b x b y a y a y b x c + x b x a y c + x a y b x b y a α = 1 β γ

Triangle Rasterization x min = floor(min(x a, x b, x c )) x max = ceil(max(x a, x b, x c )) y min = floor(min(y a, y b, y c )) y max = ceil(max(y a, y b, y c )) for y = y min to y max for x = x min to x max compute, given x, y if > 0 and > 0 and + < 1 mark(x, y) end end end

Optimized Triangle Rasterization β, γ are linear functions of x, y: β = γ = y a y c x + x c x a y + x a y c x c y a y a y c x b + x c x a y b + x a y c x c y a y a y b x + x b x a y + x a y b x b y a y a y b x c + x b x a y c + x a y b x b y a Rewriting: α = 1 β γ β x, y γ x, y = β 0 + β x x + β y y = γ 0 + γ x x + γ y y

Optimized Triangle Rasterization This gives the following recurrences: β x + 1, y β x, y β x, y + 1 β x, y γ x + 1, y γ x, y γ x, y + 1 γ x, y = β x = β y = γ x = γ y So now we can write an incremental algorithm!

Optimized Triangle Rasterization compute x min, x max, y min, y max compute, given x min, y min n = (x max x min ) + 1 for y = y min to y max for x = x min to x max if > 0 and > 0 and + < 1 mark(x, y) end += x += x end += y n* x += y n* x end

Outline Overview Line Rasterization Line Attributes Triangle Rasterization Triangle Attributes

Attribute Interpolation Given attributes A a, A b, A c at vertices a, b, c Attribute at p = (x, y): A x, y = A a + β A b A a + γ A c A a β, γ are just the barycentric coordinates

Attribute Interpolation Easy to incorporate into incremental algorithm Also called Gouraud interpolation Just one way of doing interpolation

Shared Edges Some pixels may lie exactly on an edge shared by two triangles What color to assign them? More than one way to do this

Shared Edges Pixel (x, y) is on an edge if: β = 0 or γ = 0 or β + γ = 1 Ignore pixels on an edge when on top row or last column in a row OpenGL/Direct3D convention http://msdn.microsoft.com/en-us/library/windows/desktop/bb147314(v=vs.85).aspx

Outline Overview Line Rasterization Line Attributes Triangle Rasterization Triangle Attributes Clipping

Clipping Rasterizer assumes triangle s pixels are on-screen Bad things happen if triangle crosses near plane After applying perspective matrix, need to clip against canonical view volume Clip triangle against planes x, y, z = ±1

Clipping 4 cases, based on which/how many vertices are inside the clipping plane: All inside: retain triangle as-is All outside: don t draw triangle One inside, two outside: one clipped triangle Two inside, one outside: two clipped triangles