Computer Graphics 7 - Rasterisation

Similar documents
COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

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

Rasterization: Geometric Primitives

Chapter 8: Implementation- Clipping and Rasterization

Einführung in Visual Computing

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

Rasterization. COMP 575/770 Spring 2013

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

Polygon Filling. Can write frame buffer one word at time rather than one bit. 2/3/2000 CS 4/57101 Lecture 6 1

Scan Conversion. Drawing Lines Drawing Circles

Computer Graphics 10 - Shadows

Graphics (Output) Primitives. Chapters 3 & 4

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

Topic #1: Rasterization (Scan Conversion)

Computer Graphics 7 - Texture mapping, bump mapping and antialiasing

COMP371 COMPUTER GRAPHICS

Topics. From vertices to fragments

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

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

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

RASTERIZING POLYGONS IN IMAGE SPACE

Scan Converting Lines

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

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

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

From Ver(ces to Fragments: Rasteriza(on

Triangle Rasterization

Hidden surface removal. Computer Graphics

Rasterizing triangles

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

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

Chapter 3. Sukhwinder Singh

CSE 554 Lecture 7: Deformation II

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

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

Realtime 3D Computer Graphics Virtual Reality

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

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

CS Rasterization. Junqiao Zhao 赵君峤

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

CSCI 4620/8626. Coordinate Reference Frames

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

CHAPTER 2 REVIEW COORDINATE GEOMETRY MATH Warm-Up: See Solved Homework questions. 2.2 Cartesian coordinate system

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

UNIT 2 GRAPHIC PRIMITIVES

Review for Mastery Using Graphs and Tables to Solve Linear Systems

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

CS 410/584, Algorithm Design & Analysis, Lecture Notes 8!

Scan Conversion of Polygons. Dr. Scott Schaefer

CS488 2D Graphics. Luc RENAMBOT

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

The Traditional Graphics Pipeline

Computer Graphics - Week 6

Computer Graphics and GPGPU Programming

Rasteriza2on and Clipping

The Traditional Graphics Pipeline

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

CS 410/584, Algorithm Design & Analysis, Lecture Notes 8

CMSC 435 Introductory Computer Graphics Pipeline. Announcements

9. Visible-Surface Detection Methods

Filled Area Primitives. CEng 477 Introduction to Computer Graphics METU, 2007

Painter s HSR Algorithm

Shading Techniques Denbigh Starkey

Agenda. Polygon Terminology Types of polygons Inside Test Polygon Filling Algorithms. Scan-Line Polygon Fill Algorithm Flood-Fill Algorithm

Computer Graphics. - Rasterization - Philipp Slusallek

Computer Graphics Inf4/MSc. Computer Graphics. Lecture 6 View Projection Taku Komura

Pipeline and Rasterization. COMP770 Fall 2011

Visible Surface Detection Methods

The Traditional Graphics Pipeline

Graphics and Interaction Rendering pipeline & object modelling

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

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

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

CS 130 Exam I. Fall 2015

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

CS 543: Computer Graphics. Rasterization

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

Institutionen för systemteknik

Real-Time Graphics Architecture

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

Werner Purgathofer

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

Polygon Partitioning. Lecture03

Computer Graphics Geometry and Transform

Line Drawing. Foundations of Computer Graphics Torsten Möller

Unit 2 Output Primitives and their Attributes

COMP3421. Particle Systems, Rasterisation

We have already studied equations of the line. There are several forms:

notes13.1inclass May 01, 2015

CPSC / Scan Conversion

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

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

Scan Conversion. Lines and Circles

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

CS 130. Scan Conversion. Raster Graphics

Overview. Pipeline implementation I. Overview. Required Tasks. Preliminaries Clipping. Hidden Surface removal

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

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

Transcription:

Computer Graphics 7 - Rasterisation Tom Thorne Slides courtesy of Taku Komura www.inf.ed.ac.uk/teaching/courses/cg

Overview Line rasterisation Polygon rasterisation Mean value coordinates Decomposing polygons

Rasterisation After projection, polygons are still described in continuous screen coordinates We need to use these polygons to colour in pixels on the screen

Rasterising lines We need to convert a line described in a continuous coordinate system into a set of discrete pixels

Simple line drawing Linear algebra: y = mx + b A very simple approach: Increment x, calculate new y Cast x and y to integers

Simple line drawing For lines where m 1 this seems to work well When m > 1 this doesn t work, the line becomes discontinuous

Symmetry If m 1 increment along the x axis, otherwise when m > 1, increment along y axis This still requires a lot of floating point arithmetic

Midpoint algorithm Iterate over steps, having lit a pixel (x p, y p ) at step p: Check where the line intersects x p+1 Colour in (x p+1, y p ) or (x p+1, y p+1 ) depending on which is closer to the intersection

Testing for the side of a line Assume the line is between (x l, y l ) and (x r, y r ) The slope of the line will be dy dx where dx = x r x l and dy = y r y l If y = mx + c then y = dy dx x + c and so: F (x, y) = ax + by + c = 0 F (x, y) = dy.x dx.y + c = 0

Decision variable Assuming dy dx < 1 using symmetry, evalulate F at point M: d = F (x p + 1, y p + 1 2 ) = a(x p + 1) + b(y p + 1 2 ) + c Then d is a decision variable, if d 0 then E is chosen as the next pixel, otherwise NE is chosen.

Updating the decision variable Then to evaluate d for the next pixel, if we chose E: d = F (x p + 2, y p + 1 2 ) = a(x p + 2) + b(y p + 1 2 ) + c Then since d = a(x p + 1) + b(y p + 1 2 ) + c, d = d + a = d + dy

Updating the decision variable If we chose NE: d = F (x p + 2, y p + 3 2 ) = a(x p + 2) + b(y p + 3 2 ) + c Then since d = a(x p + 1) + b(y p + 1 2 ) + c, d = d + a + b = d + dy dx

Initial value of d The line starts from (x l, y l ), so: d start = F (x l + 1, y l + 1 2 ) = a(x l + 1) + b(y l + 1 2 ) + c = ax l + by l + c + a + b 2 = F (x l, y l ) + a + b 2 But since (x l, y l ) is on the line, F (x l, y l ) = 0, so: d start = dy dx 2 Then to avoid floating point operations, we multiply d by 2.

Decision variables After we multiply by 2, d = 2(ax + by + c). d start = 2dy dx d E = d + 2dy d NE = d + 2dy 2dx Then we only need integer operations

Summary of the mid-point algorithm Start at first endpoint Calculate initial value for d Decide between two next pixels based on decision variable Update the decision based upon which pixel is chosen Iterate

Midpoint algorithm

Overview Line rasterisation Polygon rasterisation Mean value coordinates Decomposing polygons

Scanline algorithm Fill pixels within a polygon scanline by scanline

Scanline algorithm On every scanline: Find intersections of scan line with all edges of the polygon Sort intersections in increasing order of x coordinate Fill in pixels between all pairs of intersections Works with concave polygons

Span extrema Only turn on pixels that have their centre interior to the polygon Otherwise pixels overlap with adjacent polygons This is done by rounding up values on left edges and down on right edges

Scanline algorithm Pros: Simple Cons: Hard to parallelise efficiently Special cases can occur and require exception handling

Barycentric coordinates for triangles Allow us to check whether a pixel is inside or outside a triangle Makes it easy to interpolate attributes between vertices Used in GPUs Easy to parallelise

Barycentric coordinates for triangles Given a 2D triangle with vertices p 0, p 1, p 2. For any point in the plane p: p = p 0 + β(p 1 p 0 ) + γ(p 2 p 0 ) = (1 β γ)p 0 + βp 1 + γp 2 = αp 0 + βp 1 + γp 2 α + β + γ = 1

Barycentric coordinates for triangles The values α, β, γ [0, 1] if and only if p is inside the triangle. α, β, γ are the barycentric coordinates of the point p.

Calculating barycentric coordinates If the triangle is composed of p 0 = (x 0, y 0 ), p 1 = (x 1, y 1 ), p 2 = (x 2, y 2 ), then for a point (x, y): α = f 12(x,y) f 12 (x 0,y 0 ), β = f 20(x,y) f 20 (x 1,y 1 ) γ = f 01(x,y) f 01 (x 2,y 2 ) where f ab = (y a y b )x + (x b x a )y + x a y b x b y a

Bounding box of a triangle We calculate a bounding box around the triangle, by taking the minimum and maximum vertex coordinates in each direction: x min, y min = min(x 0, x 1, x 2 ), min(y 0, y 1, y 2 ) x max, y max = max(x 0, x 1, x 2 ), max(y 0, y 1, y 2 )

Scanning inside the triangle For each pixel in the bounding box, compute the barycentric coordinates Shade the pixel if all three values α, β, γ [0, 1]

Interpolation Barycentric coordinates can be used to interpolate attributes of triangle vertices, for example colour, depth, normal vectors or texture coordinates.

Interpolation of colour Gouraud shading: Calculate colour at vertices and interpolate the colour over the surface

Interpolation of depth When triangles overlap each other, depth needs to be calculated at each pixel in case the intersect Calculate using barycentric coordinates Used in Z-buffering

Exercise What are the barycentric coordinates of A and B? What is the surface depth (Z coordinate) at B γ = (y 0 y 1 )x+(x 1 x 0 )y+x 0 y 1 x 1 y 0 (y 0 y 1 )x 2 +(x 1 x 0 )y 2 +x 0 y 1 x 1 y 0 β = (y 0 y 2 )x+(x 2 x 0 )y+x 0 y 2 x 2 y 0 (y 0 y 2 )x 2 +(x 2 x 0 )y 2 +x 0 y 2 x 2 y 0

Exercise Barycentric coordinates A = ( 1 2, 5 8, 1 8 ) B = ( 1 3, 1 3, 1 3 ) Depth at B = 5 3

Shape editing We can apply the same barycentric coordinates within a triangle when its shape is edited

General polygons Barycentric coordinates for polygons with more vertices: v = i w i p i i w i Barycentric coordinates for 3D meshes: Mean value coordinates Harmonic coordinates (generalised barycentric coordinates)

Shape editing

Mean value coordinates Coordinates that can: smoothly interpolate boundary values works with concave polygons works in 3D w i = tan α i 1/2+tan α i /2 v i v 0

Mean value coordinates Can interpolate convex and concave polygons Smoothly interpolates the interior as well as the exterior

Mean value coordinates Can interpolate convex and concave polygons Smoothly interpolates the interior as well as the exterior

Mean value coordinates Can be computed in 3D Applicable for mesh editing

Overview Line rasterisation Polygon rasterisation Mean value coordinates Decomposing polygons

Polygon decomposition For polygons with more than three vertices, we usually decompose them into triangles

Polygon decomposition Algorithm: Find leftmost vertex and label it A Compose potential triangle out of A and adjacent vertices B and C Check to see if another point of the polygon is inside the triangle ABC If all other points are outside ABC, remove ABC from the polygon and proceed with next leftmost vertex

Polygon decomposition Left most vertex is A Form a triangle between A and the adjacent B and C Check if all other vertices are outside this triangle

Polygon decomposition If a vertex is inside, split the polygon by the inside vertex and point A and continue:

Polygon decomposition The new edge may split the polygon in two. If so recurse over each polygon: Split into ABCDE and AEFGH.

Summary Rasterisation: Line rasterisation, midpoint algorithm Triangle rasterisation, scanline algorithm, barycentric coordinates Mean value coordinates Polygon decomposistion into triangles

References Midpoint and scanline algorithm: Foley Chapter 3.2, 3.5, 3.6 Barycentric coordinates: Shirley Chapter 2.7 Mean value coordinates: Floater, M. S. Mean value coordinates. Computer Aided Geometric Design, 20(1), 19 27, 2003 Ju, T., Schaefer, S., & Warren, J. Mean value coordinates for closed triangular meshes. ACM Transactions on Graphics, 24(3), 561 566, 2005. Polygon decomposition: http://www.siggraph.org/education/materials/ HyperGraph/scanline/outprims/polygon1.htm