Topic #1: Rasterization (Scan Conversion)

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

Scan Conversion. Drawing Lines Drawing Circles

Rasterization: Geometric Primitives

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

Chapter 8: Implementation- Clipping and Rasterization

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

Painter s HSR Algorithm

Line Drawing Week 6, Lecture 9

Scan Converting Lines

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

COMP371 COMPUTER GRAPHICS

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

From Ver(ces to Fragments: Rasteriza(on

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

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

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

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

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline

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

Pipeline implementation II

1 Introduction to Graphics

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

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

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

Computer Graphics. - Rasterization - Philipp Slusallek

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Graphics (Output) Primitives. Chapters 3 & 4

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

The Traditional Graphics Pipeline

Visible Surface Detection Methods

Computer Graphics 7 - Rasterisation

Projection and viewing. Computer Graphics CSE 167 Lecture 4

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

Triangle Rasterization

CEng 477 Introduction to Computer Graphics Fall 2007

Topics. From vertices to fragments

Werner Purgathofer

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

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

Clipping and Scan Conversion

Realtime 3D Computer Graphics Virtual Reality

Computer Graphics and GPGPU Programming

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

Raster Scan Displays. Framebuffer (Black and White)

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

EF432. Introduction to spagetti and meatballs

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

Hidden Surface Removal

Visibility: Z Buffering

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

CS488 2D Graphics. Luc RENAMBOT

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

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

CSCI 4620/8626. Coordinate Reference Frames

Line Drawing. Foundations of Computer Graphics Torsten Möller

CS 543: Computer Graphics. Rasterization

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

Drawing Fast The Graphics Pipeline

Computer Graphics - Week 6

Chapter - 2: Geometry and Line Generations

CS4620/5620: Lecture 14 Pipeline

Einführung in Visual Computing

Rendering. Basic Math Review. Rasterizing Lines and Polygons Hidden Surface Remove Multi-pass Rendering with Accumulation Buffers.

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

Chapter 3. Sukhwinder Singh

9. Visible-Surface Detection Methods

Rendering. A simple X program to illustrate rendering

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

CPSC / Scan Conversion

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

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

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

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

Unit 2 Output Primitives and their Attributes

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

Computer Graphics II

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

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

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

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

Shadows in the graphics pipeline

Pipeline Operations. CS 4620 Lecture 10

Shading Techniques Denbigh Starkey

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

CS 130. Scan Conversion. Raster Graphics

CS475m - Computer Graphics. Lecture 1 : Rasterization Basics

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

Drawing the Visible Objects

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

Computer Graphics. Bing-Yu Chen National Taiwan University

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

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

CSE528 Computer Graphics: Theory, Algorithms, and Applications

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

Computer Graphics. Lecture 9 Hidden Surface Removal. Taku Komura

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

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

Transcription:

Topic #1: Rasterization (Scan Conversion) We will generally model objects with geometric primitives points, lines, and polygons For display, we need to convert them to pixels for points it s obvious but we ll need some algorithms for lines and polygons

General Comments on Rasterization Moving from continuous geometry to discrete pixels is inexact we re attempting to approximate the primitive with pixels thus a certain amount of error is being introduced Goal #1: Accuracy construct good approximations (i.e., low error) this can be hard because there may be many tricky cases Goal #2: Efficiency this process is going to happen a lot imagine we need to draw 10 million polygons/second one near-universal strategy: implement this stuff in hardware

Line Rasterization We have a 2-D line segment inside the viewport it s been projected & clipped To simplify discussion, assume slope is between 0 and 1 other cases are symmetric Our goal, fill in pixels on line actually, most nearly on as measured at pixel centers 0 m 1

First Cut: Very Simple Line Algorithm Compute equation of line y y= mx+ b where m= x Now, start at the leftmost point and walk to the right in other words, increment x by 1 at each step for each x, compute y with equation need to round y to integral coordinate for instance, can use rint(y) or floor(y + 0.5) fill in pixel (x, y) This is a correct algorithm, but it is inefficient requires floating point multiply/add/round for each pixel column Fortunately, we can easily do better

A More Efficient Incremental Algorithm What does the slope of a line mean? it s the change in y for a unit change in x this is exactly what we need to know! yx ( +1 ) = mx ( +1 ) + b= ( mx+ b) + m= yx ( ) + m Again, let s start at leftmost point and walk to the right increment x by 1 at each step increment y by m at each step fill in pixel (x, round(y)) This has a fancy name: Digital Differential Analyzer (DDA) Obviously better than our first try, but still rather inefficient we re still doing floating point add/round per pixel column

Bresenham s Algorithm (Midpoint Algorithm) We ll switch to the implicit form of the line equation p 1 x1 = y 1 y F( p) =2n ( p p0 ) =0 where n= x x = x x and y= y y 1 0 1 0 p 0 x0 = y 0 For the next pixel, we either increment x or both x, y we want to pick the one closest to the line can do this with our line equation above ( x+1, y+1) ( x, y) ( x+1, y)

Selecting the Next Pixel F ( p) =0 ( x+1, y+ 1 ) 2 We test the midpoint evaluate F at midpoint >0 means it s below line 0 means it s on or above line This tells us which pixel is closer and hence which one to pick >0 increment x and y 0 increment x only

The Key Insight We can incrementalize this test of F F( p+ d) =2n ( p+ d p0 ) 1 1 where d = or = F( p) +2n d 0 1 note that the dot product can be precomputed incremental update of F requires a single integer addition! So, we initially compute F at the beginning at each step, we use F to pick how to increment (x,y) hence it is called the decision variable and it also tells us how to increment F If F >0 ( xy, ) ( x+1, y+1) F F +2 y 2 x If F 0 ( xy, ) ( x+1, y) F F +2 y

Bresenham s Line Algorithm in C void line(int x0, int y0, int x1, int y1) { int x = x0, y = y0; int dx = x1-x0, dy = y1-y0; int F = 2*dy-dx int incx = 2*dy, incxy = 2*(dy-dx); } for(x=x0; x<=x1; x++) { write_pixel(x, y); if( F<=0 ) { F += incx; } else { F += incxy; y++; } }

Bresenham s (Midpoint) Algorithm for Circles Can use the same methodology for drawing circles write the implicit equation of the circle 2 2 2 F( x, y) = x + y r =0 derive decision variable scheme exploit 8-way symmetry only need to compute 1 octant And it even generalizes to other conic sections ellipses, parabolas, hyperbolas See textbook for algorithm details

Polygon Rasterization We want to fill every pixel covered by the polygon And we need to be really careful! suppose we have two adjacent polygons we don t want any overlap or any cracks visit every covered pixel exactly once

What s the Inside of a Polygon? This is not obvious when the polygon intersects itself over time, people came up with some arbitrary definitions Definition #1: Odd even rule pass horizontal line through shape; points with odd # crossings are in this is the one generally used for polygon rasterization

What s the Inside of a Polygon? Definition #1: Odd even rule pass horizontal line through shape; points with odd # crossings are in Definition #2: Winding rule walk around entire polygon; add up # of times you encircle a point clockwise (+1) or counter-clockwise (-1) fill points with non-zero winding number 1 1 2 1 1 1

Scan Converting Polygons Loop over all scanlines covered by polygon find points of intersection, from left to right fill all the interior spans these are the odd spans as per the odd even rule Some special cases to watch out for horizontal edges grazing vertices

Efficiently Tracking Scanline Intersections We could do something simple, but inefficient directly compute intersection of every scanline with every edge But we can do better by exploiting coherence of scanlines Create an Edge Table with all edges sorted by ymin Maintain Active Edge Table to hold list of edges intersecting current scanline sorted left to right If we process the polygon from ymin to ymax add edge to AET at its ymin value remove edge at its ymax value when the AET is empty, we re done can use something like Bresenham s line algorithm to efficiently track x-coordinate of intersections

Topic #2: Visible Surface Determination Rasterization will convert are primitives to pixels in the image but we need to make sure we don t draw occluded objects For each pixel, what is the nearest object in the scene? this is the only thing we need to draw at this pixel provided the object isn t transparent we need to determine the visible surface

Painter s Algorithm Developed thousands of years ago probably by cave dwellers Draws every object in depth order from back to front near objects overwrite far objects What could be simpler? Painter s Algorithm: sort objects back to front loop over objects rasterize current object write pixels first second third

But the Catch is in the Depth Sorting What do we sort by? minimum z value no maximum z value no in fact, there s no single z value we can sort by Worse yet, depth ordering of objects can be cyclic may need to split polygons to break cycles

Looking at Painter s Algorithm It has some nice strengths the principle is very simple handles transparent objects nicely just composite new pixels with what s already there But it also has some noticeable weaknesses general sorting is a little expensive worse than O(n) need to do splitting for depth cycles, interpenetration, and what if the objects aren t planar polygons?

Scanline Visibility Looks a lot like polygon rasterization maintains active object table looks at one scanline at a time no need to store entire image nice if memory is scarce Scanline Algorithm: sort objects by ymin loop over scanlines update active object list sort active objects by x loop over x values find closest active object write pixel

The Z-Buffer Algorithm Create new frame buffer channel a depth component to go with our RGBα channels Records depth of pixel contents overwrite pixel it s farther away This used to look pretty wasteful say 24 bits * number of pixels doubles size of framebuffer but memory is cheap now Now most common method especially for hardware design Z-Buffer Algorithm: allocate z-buffer initialize values to infinity loop over all objects rasterize current object for each covered pixel (x,y) if z(x,y) < zbuffer(x,y) zbuffer(x,y) = z(x,y) write pixel OpenGL glenable(gl_depth_test)

Looking at the Z-Buffer Algorithm It has some attractive strengths it s very simple, and easy to implement in hardware can easily accommodate any primitive you can rasterize not just planar polygons But it does have a few problems it doesn t handle transparency well needs intelligent selection of znear & zfar clipping planes z-buffers typically use integer depth values fixed bit precision mapped to range znear..zfar

Making Z-Buffers Efficient When we rasterize a polygon, we need z value at each pixel we could just compute it at every pixel but this is pretty expensive Can use the same incrementalization trick as in rasterization the projected polygon satisfies some plane equation ax + by + cz + d =0 we could compute the depth as d ax by z = c but taking account of coherence a z = x for fixed values of y c

Ray Casting This is a very general algorithm works with any primitive we can write intersection tests for but it s hard to make it run fast We ll come back to this idea later can use it for much more than visibility testing shadows, refractive objects, reflections, motion blur, Ray Casting: loop over every pixel (x,y) shoot ray from eye through (x,y) intersect with all surfaces find first intersection point write pixel