Triangle Rasterization

Similar documents
Hidden surface removal. Computer Graphics

Scan Converting Triangles

Ray tracing. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 3/19/07 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Visibility: Z Buffering

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

CS4620/5620: Lecture 14 Pipeline

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

CS 498 VR. Lecture 18-4/4/18. go.illinois.edu/vrlect18

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

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

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination

Topic #1: Rasterization (Scan Conversion)

Visible-Surface Detection Methods. Chapter? Intro. to Computer Graphics Spring 2008, Y. G. Shin

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

Graphics and Interaction Rendering pipeline & object modelling

COMP30019 Graphics and Interaction Rendering pipeline & object modelling

Lecture outline. COMP30019 Graphics and Interaction Rendering pipeline & object modelling. Introduction to modelling

Rasterization Overview

Clipping & Culling. Lecture 11 Spring Trivial Rejection Outcode Clipping Plane-at-a-time Clipping Backface Culling

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

Computer Graphics. Lecture 9 Hidden Surface Removal. Taku Komura

CS 112 The Rendering Pipeline. Slide 1

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

Drawing Fast The Graphics Pipeline

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

CS 248 Assignment 2 Polygon Scan Converter. CS248 Presented by Abe Davis Stanford University October 17, 2008

MIT EECS 6.837, Teller and Durand 1

Parallel Triangle Rendering on a Modern GPU

Rendering If we have a precise computer representation of the 3D world, how realistic are the 2D images we can generate? What are the best way to mode

Class of Algorithms. Visible Surface Determination. Back Face Culling Test. Back Face Culling: Object Space v. Back Face Culling: Object Space.

Drawing Fast The Graphics Pipeline

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

Fondamenti di Grafica 3D The Rasterization Pipeline.

Visible Surface Detection. (Chapt. 15 in FVD, Chapt. 13 in Hearn & Baker)

CS 248 Assignment 2 Polygon Scan Conversion. CS248 Presented by Michael Green Stanford University October 20, 2004

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

Projection Matrix Tricks. Eric Lengyel

Real-Time Graphics Architecture

Sung-Eui Yoon ( 윤성의 )

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

9. Visible-Surface Detection Methods

Chapter 8: Implementation- Clipping and Rasterization

Computer Graphics 7 - Rasterisation

Adaptive Point Cloud Rendering

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

Pipeline Operations. CS 4620 Lecture 10

Two basic types: image-precision and object-precision. Image-precision For each pixel, determine which object is visable Requires np operations

Perspective Mappings. Contents

Rasterizing triangles

Next-Generation Graphics on Larrabee. Tim Foley Intel Corp

Shadows in the graphics pipeline

Lecture notes: Object modeling

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

The Graphics Pipeline. Interactive Computer Graphics. The Graphics Pipeline. The Graphics Pipeline. The Graphics Pipeline: Clipping

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

CS 130 Final. Fall 2015

Rasterization. COMP 575/770 Spring 2013

Einführung in Visual Computing

Drawing Fast The Graphics Pipeline

INTRODUCTION TO COMPUTER GRAPHICS. It looks like a matrix Sort of. Viewing III. Projection in Practice. Bin Sheng 10/11/ / 52

The Traditional Graphics Pipeline

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

Identifying those parts of a scene that are visible from a chosen viewing position, and only process (scan convert) those parts

CSL 859: Advanced Computer Graphics. Dept of Computer Sc. & Engg. IIT Delhi

Hidden-Surface Removal.

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

The Traditional Graphics Pipeline

Performance OpenGL Programming (for whatever reason)

The Traditional Graphics Pipeline

Topics. From vertices to fragments

Page 1. Area-Subdivision Algorithms z-buffer Algorithm List Priority Algorithms BSP (Binary Space Partitioning Tree) Scan-line Algorithms

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

Computer Graphics. Bing-Yu Chen National Taiwan University The University of Tokyo

CSE528 Computer Graphics: Theory, Algorithms, and Applications

CS130 : Computer Graphics Lecture 2: Graphics Pipeline. Tamar Shinar Computer Science & Engineering UC Riverside

VISIBILITY & CULLING. Don t draw what you can t see. Thomas Larsson, Afshin Ameri DVA338, Spring 2018, MDH

INTRODUCTION TO COMPUTER GRAPHICS. cs123. It looks like a matrix Sort of. Viewing III. Projection in Practice 1 / 52

CS488 2D Graphics. Luc RENAMBOT

Visibility and Occlusion Culling

Culling. Computer Graphics CSE 167 Lecture 12

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Computer Graphics Shadow Algorithms

CSE 167: Introduction to Computer Graphics Lecture #10: View Frustum Culling

Volume Shadows Tutorial Nuclear / the Lab

Project 1, 467. (Note: This is not a graphics class. It is ok if your rendering has some flaws, like those gaps in the teapot image above ;-)

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

Lecture 4: Visibility. (coverage and occlusion using rasterization and the Z-buffer) Visual Computing Systems CMU , Fall 2014

Real-Time Shadows. Last Time? Textures can Alias. Schedule. Questions? Quiz 1: Tuesday October 26 th, in class (1 week from today!

Shadow Rendering EDA101 Advanced Shading and Rendering

RASTERIZING POLYGONS IN IMAGE SPACE

Motivation. Culling Don t draw what you can t see! What can t we see? Low-level Culling

Computer Graphics. - Rasterization - Philipp Slusallek

Advanced 3D-Data Structures

4: Polygons and pixels

Graphics Hardware and Display Devices

Computer Graphics. Bing-Yu Chen National Taiwan University

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

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Transcription:

Triangle Rasterization Computer Graphics COMP 770 (236) Spring 2007 Instructor: Brandon Lloyd 2/07/07 1

From last time Lines and planes Culling View frustum culling Back-face culling Occlusion culling Hierarchical culling Clipping 2/07/07 2

Topics for today Quick review of coordinate systems Motivation What is rasterization? Why triangles? Rasterization Scan-line Edge equations Interpolation Beyond triangles 2/07/07 3

Coordinate systems model world eye clip NDC window M Modelview matrix V P Divide by w Viewport transformation 2/07/07 4

Primitive rasterization Rasterization converts vertex representation to pixel representation Coverage determination Computes which pixels (samples) belong to an ideal analytical primitive Parameter interpolation Computes parameters at covered pixels from parameters associated with primitive vertices Coverage is a 2-D sampling problem Possible coverage criteria: distance of the primitive to sample point (often used with lines) Percent coverage of a pixel (used to be popular) Sample is inside the primitive (assuming it is closed) 2/07/07 5

Why triangles? Triangles are simple minimal representation for a surface element (3 points or 3 edge equations) triangles are linear (makes computations easier) v 2 e e 1 0 T = (v,v,v ) 0 1 2 T = (e,e,e ) 0 1 2 v 1 v 0 e 2 2/07/07 6

Why triangles? Triangles are convex What does it mean to be a convex? An object is convex if and only if any line segment connecting two points on its boundary is contained entirely within the object or one of its boundaries. Why is convexity important? Regardless of a triangle s orientation on the screen a given scan line will contain only a single segment or span of that triangle. 2/07/07 7

Why triangles? Arbitrary polygons can be decomposed into triangles Decomposing a convex n-sided polygon is trivial Suppose the polygon has ordered vertices {v 0, v 1,... v n } It can be decomposed into triangles {(v 0,v 1,v 2 ), {v 0,v 2,v 3 ), (v 0,v i,v i+1 ),... (v 0,v n-1,v n )}. Decomposing a non-convex polygon is non-trivial sometimes have to introduce new vertices 2/07/07 8

Why triangles? Triangles can approximate any 2-dimensional shape (or 3D surface) Polygons are a locally linear (planar) approximation. Improve the quality of fit by increasing the number edges or faces. 2/07/07 9

Scanline triangle rasterizer Walk along edges one scanline at a time Rasterize spans between edges 2/07/07 10

Scanline triangle rasterizer Walk along edges one scanline at a time Rasterize spans between edges 2/07/07 11

Scanline triangle rasterizer Walk along edges one scanline at a time Rasterize spans between edges 2/07/07 12

Scanline triangle rasterizer Walk along edges one scanline at a time Rasterize spans between edges 2/07/07 13

Scanline triangle rasterizer Walk along edges one scanline at a time Rasterize spans between edges 2/07/07 14

Scanline triangle rasterizer Walk along edges one scanline at a time Rasterize spans between edges 2/07/07 15

Fractional offsets offset from edge to pixel center Straightforward to interpolate values (e.g. colors) along the edges, but must be careful when offsetting from the edge to the pixel s center. 2/07/07 16

Scanline rasterizing entire scenes Sort all edges by start scanline into the Inactive Edge Table (IET) Move edges intersected by current scanline from IET to Active Edge Table (AET) Compute spans between active edges Sort spans by starting x Rasterize visible span segments Remove edges from AET when they no longer intersect the current scanline processed active inactive current scanline scanline depth spans spans 2/07/07 17

Scanline rasterization Advantages: Can be made quite fast Low memory usage for smallish scenes Don t need full 2D z-buffer (can use 1D z-buffer on the scanline) Disadvantages: Doesn t scale well to large scenes Have to worry about fractional offsets Lots of special cases 2/07/07 18

Rasterizing with edge equations Compute edge equations from vertices Compute interpolation equations from vertex parameters Traverse pixels evaluating the edge equations Draw pixels for which all edge equations are positive Interpolate parameters at pixels 2/07/07 19

Edge equation coefficients The cross product between 2 homogeneous points generates the line between them v 0 e v 1 e = v v 0 1 = [x y 1] [x y 1] t 0 0 1 1 = [(y y ) (x x ) (x y x y )] 0 1 1 0 0 1 1 0 A B C t E(x, y) = Ax + By + C A pixel at (x,y) is inside an edge if E(x,y)>0 2/07/07 20

Numerical precision Subtraction of two nearly equal floating point numbers results in catastophic cancellation which leaves only a few significant bits 1.234 10 1.233 10 = 1.000 10 When x 0 y 1 x 1 y 0 computing C = x 0 y 1 x 1 y 0 can result in loss of precision Reformulate C coefficent: 3 3 0 A(x0 + x 1) + B(y 0 + y 1) C = 2 2/07/07 21

Triangle area x0 x1 x2 1 Area = 2 det y0 y1 y 2 1 1 1 = ((xy xy) (xy xy) + (xy xy)) 1 2 1 2 2 1 0 2 2 0 0 1 1 0 = (C + C + C ) 1 2 0 1 2 Area = 0 means that the triangle is not visible Area < 0 means the triangle is back facing: Reject triangle if performing back-face culling Otherwise, flip edge equations by multiplying by -1 2/07/07 22

Shared edges Suppose two triangles share an edge. Which covers the pixel when the edge passes through the sample (E(x,y)=0)? Both pixel color becomes dependent on order of triangle rendering creates problems when rendering transparent objects - double hitting Neither Missing pixels create holes in otherwise solid surface We need a consistent tie-breaker! triangle 1 triangle 2 2/07/07 23

Shared edges A common tie-breaker: A> 0 if A 0 bool t = B > 0 otherwise (A,B) triangle 1 triangle 2 Coverage determination becomes if( E(x,y) >0 (E(x,y)==0 && t)) pixel is covered 2/07/07 24

Shared vertices Use inclusion direction as a tie breaker. Any direction can be used Snap vertices to subpixel grid and displace so that no vertex can be at the pixel center 2/07/07 25

Other benefits of snapping to subpixel grid Simplicity can use fixed-point arithmetic can be used (integer operations) Robustness With sufficient bits, edge equations and areas can be computed exactly Quality Smoother animation than if we snapped to the pixel grid 2/07/07 26

Interpolating parameters Specify a parameter, say redness (r) at each vertex of the triangle. Linear interpolation creates a planar function y x r(x,y) = Ax + By + C 2/07/07 27

Solving for interpolation equation Given the redness of the three vertices, we can set up the following linear system: with the solution: x x x r r r A B C y y y 1 1 1 [ ] = [ ] 0 1 2 0 1 2 r r r 0 1 2 [ A B C ] = [ r r r ] r r r 0 1 2 (y1 y 2) (x2 x 1) (x1y2 x2y 1) (y0 y 2) (x2 x 0) (x0y2 x2y 0) (y0 y 1) (x1 x 0) (x0y1 x1y 0) x0 x1 x2 det y0 y1 y 2 1 1 1 2/07/07 28

Interpolation equation The parameter plane equation is just a linear combination of the edge equations e 1 A B C r r r e 2area e [ ] = [ ] r r r 0 1 2 1 Extra work to interpolate a parameter: Transform parameter vector Compute one interpolation equation per pixel per parameter 0 2 2/07/07 29

Z-Buffering When rendering multiple triangles we need to determine which triangles are visible Use z-buffer to resolve visibility stores the depth `at each pixel Initialize z-buffer to 1 Post-perspective z values lie between 0 and 1 Linearly interpolate depth (z tri ) across triangles Why can we do this? If z tri (x,y) < zbuffer[x][y] write to pixel at (x,y) zbuffer[x][y] = z tri (x,y) image from wikipedia.com 2/07/07 30

Traversing pixels Free to traverse pixels how we please Edge and interpolation equations can be computed at any point Try to minimize work Restrict traversal to primitive bounding box Zig-zag traversal avoids empty pixels Hierarchical traversal - Knock out tiles of pixels (say 4x4) at a time - Test corners of tiles against equations - Test individual pixels of tiles not entirely inside or outside 2/07/07 31

Incremental update of linear equations Some computation can be saved by updating the edge and interpolation equations incrementally: E(x, y) = Ax + By + C E(x +, y) = A(x + ) + By + C = E(x, y) + A E(x, y + ) = Ax + B(y + ) + C = E(x, y) + B Equations can be updated with a single addition! 2/07/07 32

Triangle setup Compute edge equations 3 cross products Compute triangle area A few additions Cull zero area and back-facing triangles and/or flip edge equations Compute interpolation equations Matrix/vector product per parameter 2/07/07 33

A Post-Triangle World? Are triangles really the best rendering primitive? 100,000,000 primitives 2,000,000 pixels 5 primitives/pixel (Assuming that primitives are uniformly distributed over screen and only 10% are visible.) Cost to render a single triangle specify 3 vertices compute 3 edge equations evaluate equations one Models of this magnitude are being built today. The leading and most ambitious work in this area is Stanford's "Digital Michelangelo Project". 2/07/07 34

Point-cloud rendering Points have been proposed as a rendering primitive to address this problem. Key Attibutes: Hierarchy Incremental refinement Compact representation (differental encoding) 130,712 Splats, 132 ms 259,975 Splats, 215 ms 1,017,149 Splats, 722 ms 14,835,967 Splats, 8308 ms 2/07/07 35

Next time Texture mapping Barycentric coodinates Perspective-correct interpolation Texture filtering 2/07/07 36