Einführung in Visual Computing

Similar documents
Graphics Output Primitives

Attributes of Graphics Primitives

Chapter - 2: Geometry and Line Generations

COMP371 COMPUTER GRAPHICS

Unit 2 Output Primitives and their Attributes

Graphics (Output) Primitives. Chapters 3 & 4

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Computer Graphics. Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

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

Rasterization: Geometric Primitives

Computer Graphics. Chapter 4 Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

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

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

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

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

Chapter 8: Implementation- Clipping and Rasterization

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

Pipeline implementation II

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

Topics. From vertices to fragments

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

Computer Graphics. - Rasterization - Philipp Slusallek

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

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

Line Drawing. Foundations of Computer Graphics Torsten Möller

Computer Graphics 7 - Rasterisation

Rasterization. COMP 575/770 Spring 2013

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

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

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

CS Rasterization. Junqiao Zhao 赵君峤

CS 543: Computer Graphics. Rasterization

From Ver(ces to Fragments: Rasteriza(on

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

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

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

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

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

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

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

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

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

Pipeline and Rasterization. COMP770 Fall 2011

Computer Graphics Lecture Notes

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

CS 130 Final. Fall 2015

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

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

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

Werner Purgathofer

CS 325 Computer Graphics

CSCI 4620/8626. Coordinate Reference Frames

Realtime 3D Computer Graphics Virtual Reality

Scan Converting Text. Attributes of Output Primitives. CS 460/560 Computer Graphics. Binghamton University. EngiNet. Thomas J.

Chapter 3. Sukhwinder Singh

Overview of Computer Graphics

Scan Conversion. Drawing Lines Drawing Circles

Rasterization. CS4620 Lecture 13

CHAPTER 1 Graphics Systems and Models 3

RASTERIZING POLYGONS IN IMAGE SPACE

Topic #1: Rasterization (Scan Conversion)

1 Introduction to Graphics

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

Text in OpenGL and Windows. Computer Graphics Attributes. Computer Graphics. Binghamton University. EngiNet. Thomas J. Watson

Rasteriza2on and Clipping

Computer Graphics Geometry and Transform

SE Mock Online Test 1-CG

Shading Techniques Denbigh Starkey

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

Painter s HSR Algorithm

UNIT 2 GRAPHIC PRIMITIVES

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science

CS602 Midterm Subjective Solved with Reference By WELL WISHER (Aqua Leo)

CS488 2D Graphics. Luc RENAMBOT

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

CS6504 & Computer Graphics Unit I Page 1

The Traditional Graphics Pipeline

Computer graphics 2 Marks 1. Define Computer graphics.

Hidden surface removal. Computer Graphics

Rasterization Computer Graphics I Lecture 14. Scan Conversion Antialiasing Compositing [Angel, Ch , ]

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

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

The Traditional Graphics Pipeline

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

Points and lines. x x 1 + y 1. y = mx + b

COMP30019 Graphics and Interaction Rendering pipeline & object modelling

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

Clipping and Scan Conversion

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

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

Graphics and Interaction Rendering pipeline & object modelling

Triangle Rasterization

Einführung in Visual Computing

The Traditional Graphics Pipeline

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

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

CS2401 COMPUTER GRAPHICS ANNA UNIV QUESTION BANK

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

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

Transcription:

Einführung in Visual Computing 186.822 Rasterization Werner Purgathofer

Rasterization in the Rendering Pipeline scene objects in object space transformed vertices in clip space scene in normalized device coordinates Werner raster Purgathofer image in pixel coordinates2 object capture/creation modeling viewing projection vertex stage ( vertex shader ) clipping + homogenization viewport transformation rasterization shading pixel stage ( fragment shader )

Important Graphics Output Primitives in 2D points, lines polygons, circles, ellipses & other curves (also filled) pixel array operations characters in 3D triangles & other polygons free form surfaces + commands for properties: color, texture, Werner Purgathofer / Einf. in Visual Computing 3

Points and Lines point plotting instruction in display list (random scan) entry in frame buffer (raster scan) line drawing instruction in display list (random scan) intermediate discrete pixel positions calculated (raster scan) jaggies, aliasing Werner Purgathofer / Einf. in Visual Computing 4

Lines: Staircase Effect stairstep effect (jaggies) produced when a line is generated as a series of pixel positions Werner Purgathofer / Einf. in Visual Computing 5

Line-Drawing Algorithms line equation: y = m. x + b line path between two points: y 1 m = y 1 y 0 x 1 x 0 y 0 }b x 1 x 0 y 1 y 0 b = y 0 m. x 0 x 0 x 1 Werner Purgathofer / Einf. in Visual Computing 6

DDA Line-Drawing Algorithm line equation: y = m. x + b δy = m. δx for m <1 y 1 y 0 δx m. δx x 0 x 1 Werner Purgathofer / Einf. in Visual Computing 7

DDA Line-Drawing Algorithm line equation: y = m. x + b δy = m. δx for m <1 δy ( δx = m for m >1 ) y 1 y 0 sampling points with distance 1 m DDA (digital differential analyzer) x 0 1 x 1 for δx=1, m <1 : y k+1 = y k + m Werner Purgathofer / Einf. in Visual Computing 8

DDA Algorithm Principle dx = x1 x0; dy = y1 y0; m = dy / dx; x = x0; y = y0; drawpixel (round(x), round(y)); m = y 1 y 0 x 1 x 0 for (k = 0; k < dx; k++) y k+1 = y + k m { x += 1; y += m; drawpixel (round(x), round(y)} for δx=1, m <1 extension to other cases simple Werner Purgathofer / Einf. in Visual Computing 9

Bresenham s Line Algorithm faster than simple DDA incremental integer calculations adaptable to circles, other curves y = m. (x k + 1) + b 13 12 11 decision for every column which of the two candidate pixels is selected 10 10 11 12 13 Werner Purgathofer / Einf. in Visual Computing 10

Bresenham s Line Algorithm y k+2 y k+1 y = mx + b section of the screen grid showing a pixel in column x k on scan line y k that is to be plotted along the path of a line segment with slope 0 < m < 1 y k x k x k+1 x k+2 x k+3 Werner Purgathofer / Einf. in Visual Computing 11

Bresenham s Line Algorithm (1/4) y k+1 y d upper d lower y k x k x k+1

Bresenham s Line Algorithm (1/4) y = m. x k+1 + b = m. (x k + 1) + b y k+1 y y k d upper d lower d lower = y y k = = m. (x k + 1) + b y k d upper = (y k + 1) y = = y k + 1 m. (x k + 1) b d lower d upper = = 2m. (x k + 1) 2y k + 2b 1 x k+1 13

Bresenham s Line Algorithm (2/4) y k+1 y d upper d lower d upper = = 2m. (x k + 1) 2y k + 2b 1 m = y/ x ( x = x 1 x 0, y = y 1 y 0 ) d lower decision parameter: y k p k = x. (d lower d upper ) = 2 y. x k 2 x. y k + c same sign as (d lower d upper ) x k+1 14

Bresenham s Line Algorithm (3/4) current decision value: p k = x. (d lower d upper ) = 2 y. x k 2 x. y k + c next decision value: p k+1 = 2 y. x 2 x. k+1 y + k+1 c + 0 + p k 2 y. x k + 2 x. y k c = = p k + 2 y 2 x. (y k+1 y k ) starting decision value: p 0 = 2 y x Werner Purgathofer / Einf. in Visual Computing 15

Bresenham s Line Algorithm (4/4) 1. store left line endpoint in (x 0,y 0 ) 2. draw pixel (x 0,y 0 ) 3. calculate constants x, y, 2 y, 2 y 2 x, and obtain p 0 = 2 y x 4. at each x k along the line, perform test: if p k <0 then draw pixel (x k +1,y k ); p k+1 = p k + 2 y else draw pixel (x k +1,y k +1); p k+1 = p k + 2 y 2 x 5. perform step 4 ( x 1) times. Werner Purgathofer / Einf. in Visual Computing 16

Bresenham: Example k p k (x k+1,y k+1 ) (20,41) 0-4 (21,41) 1 2 (22,42) 2-12 (23,42) 3-6 (24,42) 4 0 (25,43) 5-14 (26,43) 6-8 (27,43) 7-2 (28,43) 8 4 (29,44) 9-10 (30,44) p 0 = 2 y x 46 x = 10, y = 3 45 44 43 42 41 40 20 21 22 23 24 25 26 27 28 29 30 if p k <0 then draw pixel (x k +1,y k ); p k+1 = p k + 2 y else draw pixel (x k +1,y k +1); p k+1 = p k + 2 y 2 x Werner Purgathofer / Einf. in Visual Computing 17

Attributes of Graphics Output Primitives in 2D points, lines characters in 2D and 3D triangles other polygons ((filled) ellipses and other curves) Werner Purgathofer / Einf. in Visual Computing 18

Points and Line Attributes color type: solid, dashed, dotted, width, line caps, corners pen and brush options Werner Purgathofer / Einf. in Visual Computing 19

Character Attributes text attributes font (e.g. Courier, Arial, Times, Roman, ) proportionally sized vs. fixed space fonts styles (regular, bold, italic, underline, ) size (32 point, 1 point = 1/72 inch) string attributes orientation alignment (left, center, right, justify) horizontal v e r t i c a l Displayed primitives generated by the raster algorithms discussed in Chapter 3 have a jagged, or stairstep, appearance. Displayed primitives generated by the raster algorithms discussed in Chapter 3 have a jagged, or stairstep, appearance. Werner Purgathofer / Einf. in Visual Computing 20 Displayed primitives generated by the raster algorithms discussed in Chapter 3 have a jagged, or stairstep, appearance. Displayed primitives generated by the raster algorithms discussed in Chapter 3 have a jagged, or stairstep, appearance.

Character Primitives font (typeface) design style for (family of) characters Courier, Times, Arial, serif (better readable), sans serif (better legible) definition model Sfzrn Sfzrn bitmap font (simple to define and display), needs more space (font cache) outline font (more costly, less space, geometric transformations) Werner Purgathofer / Einf. in Visual Computing 21

Example: Newspaper Werner Purgathofer / Einf. in Visual Computing 22

Character Generation Examples the letter B represented with an 8x8 bilevel bitmap pattern and with an outline shape defined with straight line and curve segments Werner Purgathofer / Einf. in Visual Computing 23

Area-Fill Attributes (1) fill styles hollow, solid fill, pattern fill fill options edge type, width, color pattern specification through pattern tables tiling (reference point) 4 0 1 2 4 0 1 2 4 1 0 2 4 1 0 2 4 1 0 2 4 0 1 2 4 1 0 2 4 1 0 2 4 1 0 2 4 0 1 2 4 1 0 2 4 1 0 2 4 1 0 2 Werner Purgathofer / Einf. in Visual Computing 24

Area-Fill Attributes (2) combination of fill pattern with background colors and soft fill pattern background or combination of colors antialiasing at object borders xor semitransparent brush simulation example: linear soft-fill replace F... foreground color B...background color P = t F + (1 t) B Werner Purgathofer / Einf. in Visual Computing 25

Triangle and Polygon Attributes color material transparency texture surface details reflexion properties, defined illumination produces effects Werner Purgathofer / Einf. in Visual Computing 26

General Polygon Fill Algorithms triangle rasterization other polygons: what is inside? scan-line fill method flood fill method (α, β,γ) clean borders between adjacent triangles barycentric coordinates Werner Purgathofer / Einf. in Visual Computing 27

General Polygon Fill Algorithms triangle rasterization other polygons: what is inside? scan-line fill method flood fill method interior, exterior for self-intersecting polygons? Werner Purgathofer / Einf. in Visual Computing 28

General Polygon Fill Algorithms triangle rasterization other polygons: what is inside? scan-line fill method flood fill method interior pixels along a scan line passing through a polygon area Werner Purgathofer / Einf. in Visual Computing 29

General Polygon Fill Algorithms triangle rasterization other polygons: what is inside? scan-line fill method flood fill method starting from a seed point: fill until you reach a border Werner Purgathofer / Einf. in Visual Computing 30

Triangles: Barycentric Coordinates notation: (α, β,γ) P 2 (x 2, y 2 ) (0, 0, 1) P 0 (x 0, y 0 ) (1, 0,0) P (, 0.13, 7) 0.60 P = αp 0 + βp 1 + γp 2 triangle = {P α+β+γ=1, 0<α<1, 0<β<1, 0<γ<1} P 1 (x 1, y 1 ) (0, 1, 0) Werner Purgathofer / Einf. in Visual Computing 31

Barycentric Coordinates in 3D notation: (α, β,γ) P 2 (x 2, y 2, z 2 ) (0, 0, 1) P 0 (x 0, y 0, z 0 ) (1, 0,0) P (, 0.13, 7) 0.60 P = αp 0 + βp 1 + γp 2 triangle = {P α+β+γ=1, 0<α<1, 0<β<1, 0<γ<1} P 1 (x 1, y 1, z 1 ) (0, 1, 0) Werner Purgathofer / Einf. in Visual Computing 32

Triangle Rasterization Algorithm for all x for all y /* use a bounding box!*/ {compute (α, β,γ) for (x,y) ; if (0<α<1) <1 and (0<β<1) <1 and (0<γ<1) <1 {c c = αc 00 + βc 11 + γc 22 ; draw pixel (x,y) with color c }} P = αp 0 + βp 1 + γp 2 triangle = {P α+β+γ=1, 0<α<1, 0<β<1, 0<γ<1} interpolates corner values (vertices) linearly inside the triangle (and along edges) Werner Purgathofer / Einf. in Visual Computing 33

Computing (α, β,γ) for P(x,y) line through P 1, P 2 : g 12 (x,y) = a 12 x+b 12 y+c 12 =0 then α = g 12 (x P,y P ) / g 12 (x 0,y 0 ) P 2 (x 2, y 2 ) β,γ analogous P 0 (x 0, y 0 ) P(x P, y P ) (α, β,γ)? g 12 (x,y)=0 P 1 (x 1, y 1 ) P = αp 0 + βp 1 + γp 2 triangle = {P α+β+γ=1, 0<α<1, 0<β<1, 0<γ<1} Werner Purgathofer / Einf. in Visual Computing 34

Barycentric Coordinates Example 1.2-1.4 1.2 1.2-1.2 1.0 1.2-1.0 0.8 1.2-0.8 0.6 1.2-0.6 1.2-1.2-1.2 - P = αp 0 + βp 1 + γp 2 triangle = {P α+β+γ=1, 0<α<1, 0<β<1, 0<γ<1} 1.0-1.2 1.2 1.0-1.0 1.0 1.0-0.8 0.8 1.0-0.6 0.6 1.0-1.0-1.0 1.0-0.8-1.0 1.2 0.8-0.8 1.0 0.8-0.6 0.8 0.8-0.6 0.8-0.8 0.8 0.8-0.6-0.8 1.2 0.6-0.6 1.0 0.6-0.8 0.6-0.6 0.6 0.6 0.6 0.6 0.6 - -0.6 1.2-1.0-0.8 0.6 0.6 0.8 - - 1.2-1.0 0.8 0.6 0.6 0.8 1.0 - - 1.2 1.0 0.8 0.6 0.6 0.8 1.0 1.2 - - 1.2-1.0-0.8-0.6 0.6-0.8-1.0-1.2-1.4 - Werner Purgathofer / Einf. in Visual Computing 35

Avoiding to Draw Borders Twice don t draw the outline of the triangle! result would depend on rendering order Werner Purgathofer / Einf. in Visual Computing 36

Avoiding to Draw Borders Twice don t draw the outline of the triangle! result would depend on rendering order draw only pixels that are inside exact triangle i.e. pixels with α = 0 or β = 0 or γ = 0 are not drawn clean borders between adjacent triangles Werner Purgathofer / Einf. in Visual Computing 37

Pixels exactly on a Border!? holes if both triangles leave pixels away simplest solution: draw both pixels better: arbitrary choice based on some test e.g. only right boundaries Werner Purgathofer / Einf. in Visual Computing 38

What is Inside a Polygon? odd-even rule nonzero-winding- number rule??? Werner Purgathofer / Einf. in Visual Computing 39

Inside-Outside Tests area-filling algorithms interior, exterior for self-intersecting polygons? odd-even rule nonzero-winding-number rule same result for simple polygons Werner Purgathofer / Einf. in Visual Computing 40

What is Inside?: Odd-Even Rule inside/outside switches at every edge straight line to the outside: even number of edge intersections = outside odd number of edge intersections = inside 4 3 2 1 2 1 4 3 2 1 Werner Purgathofer / Einf. in Visual Computing 41 1 3 2 1

What is Inside?: Nonzero Winding Number point is inside if polygon surrounds it straight line to the outside: same number of edges up and down = outside different number of edges up and down = inside Werner Purgathofer / Einf. in Visual Computing 42

Polygon Fill Areas polygon classifications convex: no interior angle > 180 concave: not convex concavity test vector method all vector cross products have the same sign convex rotational method rotate polygon-edges onto x-axis, always same direction convex Werner Purgathofer / Einf. in Visual Computing 43