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

Similar documents
Chapter - 2: Geometry and Line Generations

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

Rendering. A simple X program to illustrate rendering

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

Line Drawing. Foundations of Computer Graphics Torsten Möller

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

Overview of Computer Graphics

From Ver(ces to Fragments: Rasteriza(on

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

Einführung in Visual Computing

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

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

Graphics (Output) Primitives. Chapters 3 & 4

COMP371 COMPUTER GRAPHICS

Scan Conversion. Lines and Circles

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

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

Efficient Plotting Algorithm

CS Rasterization. Junqiao Zhao 赵君峤

Scan Conversion. Drawing Lines Drawing Circles

Chapter 8: Implementation- Clipping and Rasterization

CPSC / Scan Conversion

EF432. Introduction to spagetti and meatballs

1 Introduction to Graphics

Rasterization: Geometric Primitives

Computer Graphics. - Rasterization - Philipp Slusallek

Topic #1: Rasterization (Scan Conversion)

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

EF432. Introduction to spagetti and meatballs

Computer Graphics: 6-Rasterization

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

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

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

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

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

CS 130. Scan Conversion. Raster Graphics

R asterisation. Part I: Simple Lines. Affine transformation. Transform Render. Rasterisation Line Rasterisation 2/16

CS 543: Computer Graphics. Rasterization

Scan Converting Lines

Topic 0. Introduction: What Is Computer Graphics? CSC 418/2504: Computer Graphics EF432. Today s Topics. What is Computer Graphics?

Rendering. A simple X program to illustrate rendering

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

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

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

Computer Graphics Lecture Notes

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

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Computer Graphics Lecture 5

Rasteriza2on and Clipping

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

Line Drawing Week 6, Lecture 9

Computer Graphics D Graphics Algorithms

Pipeline implementation II

Scan Converting Circles

The Traditional Graphics Pipeline

Chapter 3. Sukhwinder Singh

MET71 COMPUTER AIDED DESIGN

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

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

Display Technologies: CRTs Raster Displays

CS488 2D Graphics. Luc RENAMBOT

CS6504 & Computer Graphics Unit I Page 1

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

Realtime 3D Computer Graphics Virtual Reality

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

Raster Scan Displays. Framebuffer (Black and White)

UNIT 2 GRAPHIC PRIMITIVES

The Traditional Graphics Pipeline

MODULE - 4. e-pg Pathshala

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

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

The Traditional Graphics Pipeline

CS 130 Final. Fall 2015

CS 130 Exam I. Fall 2015

Painter s HSR Algorithm

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

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

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

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

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

Computer Graphics D Graphics Algorithms

Solution Notes. COMP 151: Terms Test

Output Primitives Lecture: 4. Lecture 4

Institutionen för systemteknik

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

(Refer Slide Time: 00:03:51)

Pipeline and Rasterization. COMP770 Fall 2011

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

Graphics Hardware and Display Devices

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

CS-184: Computer Graphics. Today. 2D Scan Conversion. Tuesday, October 7, Drawing Lines Drawing Curves Filled Polygons Filling Algorithms

CS-184: Computer Graphics

GRAPHICS OUTPUT PRIMITIVES

Topics. From vertices to fragments

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers

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

CSCI 4620/8626. Coordinate Reference Frames

(Refer Slide Time: 00:02:00)

Rasterization. CS4620 Lecture 13

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

Transcription:

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

Outline : Raster display technology. Basic concepts: pixel, resolution, aspect ratio, dynamic range, image domain, object domain. Rasterization and direct illumination. Graphics primitives and OpenGL. Geometry representations: explicit, parametric and implicit forms. Rasterization algorithms for straight line segments, circles and ellipses. Rasterization algorithms for triangles and polygons. Rasterization versus shading.

Raster display Definition: Discrete grid of elements (frame buffer of pixels). Properties: Shapes drawn by setting the right elements Frame buffer is scanned, one line at a time, to refresh the image (as opposed to vector display) http://en.wikipedia.org/wiki/raster_graphics Difficult to draw smooth lines Displays only a discrete approximation of any shape Refresh of entire frame buffer

Terminology Pixel: Picture Element Smallest accessible element in picture. Usually rectangular or circular. Aspect Ratio: Ratio between physical dimensions of pixel (not necessarily 1). Dynamic Range: Ratio between minimal (not zero!) and maximal light intensity emitted by displayed pixel (black and white, respectively) Resolution: Number of distinguishable rows and columns on a device measured in: Absolute values (nxm) Relative values (e.g., 300 dpi) Usually rectangular or circular. Screen space: Discrete 2D Cartesian coordinate system of screen pixels. Object space: Discrete 3D Cartesian coordinate system of the domain or scene or the objects live in.

SCAN CONVERSION

Scan conversion / rasterization (for direct illumination) Definition: The process of converting geometry into pixels. Final step in pipeline: rasterization (scan conversion) From screen coordinates (float) to pixels (int) Writing pixels into frame buffer. Scan conversion: Figuring out which pixels to turn on. Shading: Determine a color for each filled pixel.

Graphics primitives OpenGL Primitive Taxonomy: Point: POINTS Line: LINES, LINE_STRIP, LINE_LOOP Triangle: TRIANGLES, TRIANGLE_STRIP, TRIANGLE_FAN Polygon: QUADS, QUAD_STRIP, POLYGON Other Primitives: Arc Circle Ellipsis Generic Curves How is each geometric primitive really drawn on screen?

Geometric representations for lines in IR 2 Explicit form: y = f (x) = mx + b Implicit form: f (x, y) = Ax + By + C = 0 Parametric form: x = x(t) = m 0 t + b 0 y = y(t) = m 1 t + b 1

Scan converting lines (x 2, y 2 ) Example: Draw from (x 1,y 1 ) to (x 2,y 2 ) (x 1, y 1 ) Correctness/quality issues: Gaps exist for line with slope m>1 (by varying x) wrong (steeper line) correct

Rasterization rules Line rasterization rules use a diamond test area to determine if a line covers a pixel. https://msdn.microsoft.com/en-us/library/windows/desktop/cc627092%28v=vs.85%29.aspx#line_1

Direct scan conversion Explicit form: y=mx+b, where m=(y i+1 -y i )/(x i+1 -x i )=Δy/Δx and 0 m 1 (1 st, 4 th, 5 th and 8 th octants) What else? Key idea: Increment x from x i to x f and calculate the corresponding value y=mx+b Drawbacks: Gaps when m>1. The solution is to increment y instead of x when m>1. Floating-point computations: floating-point multiplication and addition for every step in x. increments in x (fails when m>1)

Direct scan conversion (cont d) Algorithm (m<1): m=(y f -y i )/(x f -x i ); b=y i -m*x i ; x=xi; y=yi; DrawPixel(x,y); for (x=x i +1; x<=x f ; x++). y=m*x+b; DrawPixel(x,y); increments in x (m<1)

DDA algorithm (Digital Differential Analyser) Explicit form: y=mx+b, where m=(y i+1 -y i )/(x i+1 -x i )=Δy/Δx and 0 m 1 (1 st, 4 th, 5 th and 8 th octants) Key idea: Increment x from x i to x f and calculate the corresponding value y: Current pixel: y i =mx i +b Next pixel: Drawbacks: y i+1 =mx i+1 +b=m(x i +1)+b=y i +m Draw pixel (x i+1,y i+1 ), where y i+1 =ROUND(y i+1 ) Gaps when m>1. In this case, increment y. Floating-point arithmetic: a floating-point addition and a round operation. y i+1 y i x i x i+1 Algorithm (m<1): m=(y f -y i )/(x f -x i ); x=xi; y=yi; DrawPixel(x,y); increments in x (m<1) for (x=x i +1; x<=x f ; x++). y=y+m; DrawPixel(x,y); Note that the explicit form is not used directly!

DDA algorithm (cont d) Algorithm (m>1): m=(y f -y i )/(x f -x i ); x=xi; y=yi; DrawPixel(x,y); for (y=y i +1; y<=y f ; y++). x=x+1/m; DrawPixel(x,y); Why? increments in y (m>1) y i+1 y i x i x i+1 Note that the explicit form is not used directly!

Bresenham algorithm Bresenham, J.E. Algorithm for computer control of a digital plotter, IBM Systems Journal, January 1965, pp. 25-30. Explicit form: y=mx+b, where m=δy/δx and 0 m 1 Key idea: Increment x from x i to x f and calculate the corresponding value y. Current pixel: (x i,y i ) Next pixel: either (x i+1,y i ) or (x i+1,y i+1 ) d 1 =y-y i =mx i+1 +b-y i =m(x i +1)+b-y i y i+1 y i d2 d 1 d 2 =y i+1 -y=y i +1-y=y i +1-m(x i +1)+b x i x i+1 Δd=d 1 -d 2 =2m(x i +1)-2y i +2b-1 If Δd>0 choose higher pixel (x i+1,y i+1 ) If Δd 0 choose lower pixel (x i+1,y i ) Exact y-coordinate value y=y i +d 1 of straight line at x=x i+1

Bresenham algorithm (cont d) Integer arithmetic (?): From triangle similarity, we know that m=δy/δx=d 1 /(x i+1 -x i )=d 1 d 2 =1-d 1 =1-m Hence d 1 -d 2 =2m-1 To take advantage of integer arithmetic, we use the following decision parameter at the first pixel (x i,y i ) to choose which is the next pixel: p i =Δx(d 1 -d 2 )=2Δy-Δx But, in general terms, and using d 1 and d 2 in the previous page, we have: p i =Δx(d 1 -d 2 )=2Δy.x i -2Δx.y i +K, where K is a constant Consequently, the decision parameter at (x i+1,y i+1 ) will be: p i+1 =2Δy.x i+1-2δx.y i+1 +K or p i+1 =p i +2Δy(x i+1 -x i )-2Δx(y i+1 -y i ) (note that x i+1 -x i =1) y i+1 d 2 y i x i x i+1 d 1

Bresenham algorithm (cont d) Algorithm: void Bresenham (int xi, int yi, int xf, int yf) { int x,y,dx,dy,p; x = xi; y = yi; p = 2 * dy - dx; for(x=xi; x<=xf; x++) { DrawPixel (x,y); if (p> 0) { y = y + 1; p = p - 2 * dx; } p= p + 2 * dy; } } y i+1 d 2 y i x i x i+1 d 1

Midpoint algorithm Bresenham, J.E. Algorithm for computer control of a digital plotter, IBM Systems Journal, January 1965, pp. 25-30. Implicit form: f(x,y)=ax+by+c=0 Key idea: Starting from y=mx+b, where m=δy/δx and 0 m 1, we have: f(x,y)=δy.x-δx.y+b.δx=0 with A=Δy, B=-Δx, and C=b.Δx Current pixel: (x i,y i ) Next pixel: either (x i+1,y i ) or (x i+1,y i+1 ) Let the decision parameter p i =f(m P )=f(x i +1,y i +1/2) If p i <0 choose higher pixel (x i+1,y i+1 ) at N If p i 0 choose lower pixel (x i+1,y i ) at E y i N P E x i Current pixel P(x i,y i ) M P http://www.mat.univie.ac.at/~kriegl/skripten/cg/node25.htm l

Midpoint algorithm (cont d) Let us now determine the relation between the function values at consecutive midpoints: Key idea (cont d): p i =f(m P )=f(x i +1,y i +1/2)=A.(x i +1)+B.(y i +1/2)+C If E is chosen: p i+1 =f(m E )=f(x i +2,y i +1/2)=A.(x i +2)+B.(y i +1/2)+C =p i +A=p i +Δy If N is chosen: p i+1 =f(m N )=f(x i +2,y i +3/2)=A.(x i +2)+B.(y i +3/2)+C =p i +A+B=p i +Δy-Δx y i P N E M P M N M E Integer arithmetic (?): x i Initial decision parameter: p i =f(m P )=f(x i +1,y i +1/2)=A.(x i +1)+B.(y i +1/2)+C =f(p)+a+b/2=f(p)+δy-δx/2=δy-δx/2 Multiplying the decision parameter by 2 we realize that we obtain exactly the Bresenham algorithm given before. Current pixel: E (East) or N (Nord-East)

General Bresenham s algorithm for lines To generalize lines with arbitrary slopes: We need to consider symmetry between various octants and quadrants. For m>1, interchange roles of x and y, that is step in y direction, and decide whether the x value is above or below the line. If m>1, and right endpoint is the first point, both x and y decrease. To ensure uniqueness, independent of direction, always choose upper (or lower) point if the line go through the mid-point. y i P N E M P M N M E Handle special cases without invoking the algorithm: horizontal, vertical and diagonal lines x i

Scan converting circles Explicit form: y = f (x) = ± R 2 x 2 Usually, we draw a quarter circle by incrementing x from 0 to R in unit steps and solving for +y for each step. # x = Rcosθ Parametric form: $ % y = Rsinθ Done by stepping the angle from 0 to 90º. Solves the gap problem of explicit form. Implicit form: f (x, y) = x 2 + y 2 R 2 = 0 If f(x,y)=0, then it is on the circle; If f(x,y)>0, then it is outside the circle; If f(x,y)<0, then it is inside the circle. gap problem 8-way symmetry

Midpoint circle algorithm J.E. Bresenham. A linear algorithm for incremental digital display of circular arcs. Communications of the ACM, 20(2):100-106, 1977. Implicit form: f(x,y)=x 2 +y 2 -R 2 =0 Key idea: Current pixel: P(x i,y i ) y i P M P S E M E M S http://www.mat.univie.ac.at/~kriegl/skripten/cg/node25.htm l Next pixel: either (x i+1,y i ) or (x i+1,y i-1 ) Let the decision parameter p i =f(m P )=f(x i +1,y i -1/2) If p i <0 choose higher pixel (x i+1,y i ) at E If p i 0 choose lower pixel (x i+1,y i-1 ) at S x i Current pixel P(x i,y i )

Midpoint circle algorithm (cont d) Let us now determine the relation between the function values at consecutive midpoints: Key idea (cont d): y i P E p i =f(m P )=f(x i +1,y i -1/2)=(x i +1) 2 + (y i -1/2) 2 -R 2 M P S M E If E is chosen: M S p i+1 =f(m E )=f(x i +2,y i -1/2)=(x i +2) 2 +(y i -1/2) 2 -R 2 =p i +(2x i +3) If S is chosen: p i+1 =f(m S )=f(x i +2,y i -3/2)=(x i +2) 2 +(y i -3/2) 2 -R 2 =p i +(2x i -2y i +5) Integer arithmetic: x i Initial decision parameter at (x i,y i )=(0,R): p i =f(m P )=f(x i +1,y i -1/2)=(x i +1) 2 + (y i -1/2) 2 -R 2 =f(p)+2x i -y i +5/4=2x i -y i +5/4=5/4-R 1-R Current pixel: E (East) or S (South-East)

Midpoint circle algorithm (cont d) Algorithm: y i P E void MidPointCircle(int R) { int x=0, y=r, d=1-r; M P S M E M S } DrawPixel(x,y); while (y>x) { if (p< 0) // select E p=p + 2 * x + 3; else // select S } { p = p + 2 * (x - y) + 5; y = y - 1; } x = x + 1; DrawPixel(x,y); x i The algorithm only calculates the pixels on the 2 nd octant. The remaining pixels are found using 8-way-symmetry.

SCAN CONVERSION of TRIANGLES/POLYGONS

Scan converting of polygons Multiple tasks for scan conversion: Filling polygon (inside/outside) Pixel shading (color interpolation) Blending (accumulation, not just writing) Depth values (z-buffer hidden-surface removal) Texture coordinate interpolation (texture mapping) Hardware efficiency critical Many algorithms for filling (inside/outside) Much fewer that handle all tasks well

Review Shading: Determine a color for each filled pixel. Scan conversion: Figuring out which pixels to turn on. Rendering an image of a geometric primitive by setting pixel colors. Example: Filling the inside of a triangle.

Triangle scan conversion Key idea: Color all pixels inside triangle. Inside triangle test: A point is inside a triangle if it is in the positive half-space of all three boundary lines. Triangle vertices are ordered counter-clockwise. Point must be on the left side of every boundary line. Recall that the implicit equation of a line: On the line: Ax+By+C=0 On right: Ax+By+C<0 On left: Ax+By+C>0 void ScanCTriangle(Triangle T, Color rgba) { for each pixel P(x,y) if inside(p,t) setpixel(x,y,rgba) } Boolean inside (Triangle T, Point P) { for each boundary line L of T { float dot = L.A*P.x+L.B*P.y+L.C*P.z; if dot<0.0 return FALSE; } return TRUE; } P

Summary: : Raster display technology. Basic concepts: pixel, resolution, aspect ratio, dynamic range, image domain, object domain. Rasterization and direct illumination. Graphics primitives and OpenGL. Geometry representations: explicit, parametric and implicit forms. Rasterization algorithms for straight line segments, circles and ellipses. Rasterization algorithms for triangles and polygons. Rasterization versus shading.