The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

Similar documents
Pipeline and Rasterization. COMP770 Fall 2011

Rasterization. CS4620 Lecture 13

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

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

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

Rasterization. COMP 575/770 Spring 2013

Rasterization. Computer Graphics Fabio Pellacini and Steve Marschner

CS4620/5620: Lecture 14 Pipeline

Graphics Pipeline 2D Geometric Transformations

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

CS Rasterization. Junqiao Zhao 赵君峤

CS 130 Final. Fall 2015

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

Rasterization: Geometric Primitives

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

Computer Graphics. - Rasterization - Philipp Slusallek

Einführung in Visual Computing

Line Drawing. Foundations of Computer Graphics Torsten Möller

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

From Ver(ces to Fragments: Rasteriza(on

Line Drawing Week 6, Lecture 9

CS 543: Computer Graphics. Rasterization

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

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

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

Pipeline Operations. CS 4620 Lecture 10

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

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

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

Realtime 3D Computer Graphics Virtual Reality

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

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

Pipeline Operations. CS 4620 Lecture 14

Pipeline implementation II

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

Scan Conversion. Drawing Lines Drawing Circles

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

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

Drawing Fast The Graphics Pipeline

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

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

COMP371 COMPUTER GRAPHICS

Chapter 8: Implementation- Clipping and Rasterization

The Graphics Pipeline

Topic #1: Rasterization (Scan Conversion)

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

Math background. 2D Geometric Transformations. Implicit representations. Explicit representations. Read: CS 4620 Lecture 6

- Rasterization. Geometry. Scan Conversion. Rasterization

CHAPTER 1 Graphics Systems and Models 3

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

Intro to OpenGL II. Don Fussell Computer Science Department The University of Texas at Austin

Institutionen för systemteknik

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

Topics. From vertices to fragments

E.Order of Operations

Real-Time Graphics Architecture

Drawing Fast The Graphics Pipeline

Rendering. A simple X program to illustrate rendering

Introduction to Visualization and Computer Graphics

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

Computer Graphics Fundamentals. Jon Macey

CS 130 Exam I. Fall 2015

UNIT -8 IMPLEMENTATION

CPSC / Scan Conversion

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

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

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

Drawing Fast The Graphics Pipeline

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

CS 112 The Rendering Pipeline. Slide 1

Triangle Rasterization

A New Line Drawing Algorithm Based on Sample Rate Conversion

Computer Graphics Geometry and Transform

CSCI 4620/8626. Coordinate Reference Frames

Scan Converting Lines

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

For this assignment, you are to implement three line drawers and a polygon drawer.

The Traditional Graphics Pipeline

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

Spring 2009 Prof. Hyesoon Kim

Raster Scan Displays. Framebuffer (Black and White)

Graphics (Output) Primitives. Chapters 3 & 4

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

CS559: Computer Graphics. Lecture 12: Antialiasing & Visibility Li Zhang Spring 2008

Computer Graphics and GPGPU Programming

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

The Traditional Graphics Pipeline

Clipping and Scan Conversion

Last Time: Acceleration Data Structures for Ray Tracing. Schedule. Today. Shadows & Light Sources. Shadows

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Rendering. A simple X program to illustrate rendering

CS 130 Exam I. Fall 2015

Real-Time Graphics Architecture

The Traditional Graphics Pipeline

The Rasterization Pipeline

1 Introduction to Graphics

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

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

Transcription:

The graphics pipeline Pipeline and Rasterization CS4620 Lecture 9 The standard approach to object-order graphics Many versions exist software, e.g. Pixar s REYES architecture many options for quality and flexibility hardware, e.g. graphics cards in PCs amazing performance: millions of triangles per frame We ll focus on an abstract version of hardware pipeline Pipeline because of the many stages very parallelizable leads to remarkable performance of graphics cards (many times the flops of the CPU at ~1/5 the clock speed) 1 2 Pipeline you are here 3D transformations; shading conversion of primitives to pixels blending, compositing, shading user sees this APPLICATION COMMAND STREAM VERTEX PROCESSING TRANSFORMED GEOMETRY RASTERIZATION FRAGMENTS FRAGMENT PROCESSING FRAMEBUFFER IMAGE DISPLAY Primitives Points Line segments and chains of connected line segments Triangles And that s all! Curves? Approximate them with chains of line segments Polygons? Break them up into triangles Curved regions? Approximate them with triangles Trend has been toward minimal primitives simple, uniform, repetitive: good for parallelism 3 4

Rasterization First job: enumerate the pixels covered by a primitive simple, aliased definition: pixels whose centers fall inside Second job: interpolate values across the primitive e.g. colors computed at vertices e.g. normals at vertices will see applications later on Rasterizing lines Define line as a rectangle Specify by two endpoints Ideal image: black inside, white outside 5 6 Rasterizing lines Define line as a rectangle Specify by two endpoints Ideal image: black inside, white outside Point sampling Approximate rectangle by drawing all pixels whose centers fall within the line Problem: sometimes turns on adjacent pixels 6 7

Point sampling Approximate rectangle by drawing all pixels whose centers fall within the line Problem: sometimes turns on adjacent pixels Point sampling in action 7 8 Bresenham lines (midpoint alg.) Point sampling unit width rectangle leads to uneven line width Define line width parallel to pixel grid That is, turn on the single nearest pixel in each column Note that 45º lines are now thinner Bresenham lines (midpoint alg.) Point sampling unit width rectangle leads to uneven line width Define line width parallel to pixel grid That is, turn on the single nearest pixel in each column Note that 45º lines are now thinner 9 9

Bresenham lines (midpoint alg.) Point sampling unit width rectangle leads to uneven line width Define line width parallel to pixel grid That is, turn on the single nearest pixel in each column Note that 45º lines are now thinner Midpoint algorithm in action 9 10 Algorithms for drawing lines Optimizing line drawing line equation: y = b + m x Simple algorithm: evaluate line equation per column W.l.o.g. x 0 < x 1 ; 0! m! 1 for x = ceil(x0) to floor(x1) y = b + m*x output(x, round(y)) y = 1.91 + 0.37 x Multiplying and rounding is slow At each pixel the only options are E and NE d = m(x + 1) + b y d > 0.5 decides between E and NE 11 12

Optimizing line drawing d = m(x + 1) + b y Only need to update d for integer steps in x and y Do that with addition Known as DDA (digital differential analyzer) Midpoint line algorithm x = ceil(x0) y = round(m*x + b) d = m*(x + 1) + b y while x < floor(x1) if d > 0.5 y += 1 d = 1 x += 1 d += m output(x, y) 13 14 Linear interpolation Linear interpolation We often attach attributes to vertices e.g. computed diffuse color of a hair being drawn using lines want color to vary smoothly along a chain of line segments Recall basic definition 1D: f(x) = (1!) y 0 + " y 1 where! = (x x 0 ) / (x 1 x 0 ) In the 2D case of a line segment, alpha is just the fraction of the distance from (x 0, y 0 ) to (x 1, y 1 ) Pixels are not exactly on the line Define 2D function by projection on line this is linear in 2D therefore can use DDA to interpolate 15 16

Linear interpolation Pixels are not exactly on the line Define 2D function by projection on line this is linear in 2D therefore can use DDA to interpolate Linear interpolation Pixels are not exactly on the line Define 2D function by projection on line this is linear in 2D therefore can use DDA to interpolate 16 16 Alternate interpretation Alternate interpretation We are updating d and! as we step from pixel to pixel d tells us how far from the line we are! tells us how far along the line we are So d and! are coordinates in a coordinate system oriented to the line View loop as visiting all pixels the line passes through Interpolate d and! for each pixel Only output frag. if pixel is in band This makes linear interpolation the primary operation 17 18

Pixel-walk line rasterization x = ceil(x0) y = round(m*x + b) d = m*x + b y while x < floor(x1) if d > 0.5 y += 1; d = 1; else x += 1; d += m; if 0.5 < d! 0.5 output(x, y) Rasterizing triangles The most common case in most applications with good antialiasing can be the only case some systems render a line as two skinny triangles Triangle represented by three vertices Simple way to think of algorithm follows the pixel-walk interpretation of line rasterization walk from pixel to pixel over (at least) the polygon s area evaluate linear functions as you go use those functions to decide which pixels are inside 19 20 Rasterizing triangles Rasterizing triangles Input: three 2D points (the triangle s vertices in pixel space) (x 0, y 0 ); (x 1, y 1 ); (x 2, y 2 ) parameter values at each vertex q 00,, q 0n ; q 10,, q 1n ; q 20,, q 2n Output: a list of fragments, each with the integer pixel coordinates (x, y) interpolated parameter values q 0,, q n Summary 1" evaluation of linear functions on pixel grid 2" functions defined by parameter values at vertices 3" using extra parameters to determine fragment set 21 22

Incremental linear evaluation A linear (affine, really) function on the plane is: Linear functions are efficient to evaluate on a grid: Incremental linear evaluation lineval(xl, xh, yl, yh, cx, cy, ck) { // setup qrow = cx*xl + cy*yl + ck; // traversal for y = yl to yh { qpix = qrow; for x = xl to xh { output(x, y, qpix); qpix += cx; qrow += cy; c x =.005; c y =.005; c k = 0 (image size 100x100) 23 24 Rasterizing triangles Summary 1" evaluation of linear functions on pixel grid 2" functions defined by parameter values at vertices 3" using extra parameters to determine fragment set Defining parameter functions To interpolate parameters across a triangle we need to find the c x, c y, and c k that define the (unique) linear function that matches the given values at all 3 vertices this is 3 constraints on 3 unknown coefficients: (each states that the function agrees with the given value at one vertex) leading to a 3x3 matrix equation for the coefficients: (singular iff triangle is degenerate) 25 26

Defining parameter functions Defining parameter functions More efficient version: shift origin to (x 0, y 0 ) q(x, y) = c x (x x 0 ) + c y (y y 0 ) + q 0 q(x 1, y 1 ) = c x (x 1 x 0 ) + c y (y 1 y 0 ) + q 0 = q 1 q(x 2, y 2 ) = c x (x 2 x 0 ) + c y (y 2 y 0 ) + q 0 = q 2 now this is a 2x2 linear system (since q 0 falls out): solve using Cramer s rule (see Shirley): lininterp(xl, xh, yl, yh, x0, y0, q0, x1, y1, q1, x2, y2, q2) { // setup det = (x1-x0)*(y2-y0) - (x2-x0)*(y1-y0); cx = ((q1-q0)*(y2-y0) - (q2-q0)*(y1-y0)) / det; cy = ((q2-q0)*(x1-x0) - (q1-q0)*(x2-x0)) / det; qrow = cx*(xl-x0) + cy*(yl-y0) + q0; // traversal (same as before) for y = yl to yh { qpix = qrow; for x = xl to xh { output(x, y, qpix); qpix += cx; qrow += cy; q = 0 q = 1 q = 0 27 28 Interpolating several parameters Rasterizing triangles lininterp(xl, xh, yl, yh, n, x0, y0, q0[], x1, y1, q1[], x2, y2, q2[]) { // setup for k = 0 to n-1 // compute cx[k], cy[k], qrow[k] // from q0[k], q1[k], q2[k] // traversal for y = yl to yh { for k = 1 to n, qpix[k] = qrow[k]; for x = xl to xh { output(x, y, qpix); for k = 1 to n, qpix[k] += cx[k]; for k = 1 to n, qrow[k] += cy[k]; Summary 1" evaluation of linear functions on pixel grid 2" functions defined by parameter values at vertices 3" using extra parameters to determine fragment set 29 30

Clipping to the triangle Interpolate three barycentric coordinates across the plane each barycentric coord is 1 at one vert. and 0 at the other two Output fragments only when all three are > 0. Barycentric coordinates A coordinate system for triangles algebraic viewpoint: geometric viewpoint (areas): Triangle interior test: [Shirley 2000] 31 32 Barycentric coordinates A coordinate system for triangles geometric viewpoint: distances Barycentric coordinates Linear viewpoint: basis for the plane linear viewpoint: basis of edges in this view, the triangle interior test is just [Shirley 2000] 33 34

Walking edge equations We need to update values of the three edge equations with single-pixel steps in x and y Edge equation already in form of dot product components of vector are the increments Pixel-walk (Pineda) rasterization Conservatively visit a superset of the pixels you want Interpolate linear functions Use those functions to determine when to emit a fragment 35 36 Rasterizing triangles Exercise caution with rounding and arbitrary decisions need to visit these pixels once but it s important not to visit them twice! Clipping Rasterizer tends to assume triangles are on screen particularly problematic to have triangles crossing the plane z = 0 After projection, before perspective divide clip against the planes x, y, z = 1, 1 (6 planes) primitive operation: clip triangle against axis-aligned plane 37 38

Clipping a triangle against a plane 4 cases, based on sidedness of vertices all in (keep) all out (discard) one in, two out (one clipped triangle) two in, one out (two clipped triangles) 39