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

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

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

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

COMP371 COMPUTER GRAPHICS

Clipping and Scan Conversion

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

Image Processing. Blending. Blending in OpenGL. Image Compositing. Blending Errors. Antialiasing Revisited Computer Graphics I Lecture 15

Image Processing Computer Graphics I Lecture 15

Pipeline implementation II

Topics. From vertices to fragments

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

Image Processing. CSCI 420 Computer Graphics Lecture 22

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

Image Processing. Alpha Channel. Blending. Image Compositing. Blending Errors. Blending in OpenGL

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

CS 432 Interactive Computer Graphics

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

The Traditional Graphics Pipeline

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

Pixels and Buffers. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

CHAPTER 1 Graphics Systems and Models 3

The Traditional Graphics Pipeline

Einführung in Visual Computing

Realtime 3D Computer Graphics Virtual Reality

Computer Graphics. - Rasterization - Philipp Slusallek

Scan Conversion. Drawing Lines Drawing Circles

Computer Graphics I Lecture 11

The Traditional Graphics Pipeline

Computer Graphics. Three-Dimensional Graphics VI. Guoying Zhao 1 / 73

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

CS 4731/543: Computer Graphics Lecture 7 (Part I): Raster Graphics: Polygons & Antialiasing. Emmanuel Agu

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

CS 543: Computer Graphics. Rasterization

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

Topic #1: Rasterization (Scan Conversion)

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

From Ver(ces to Fragments: Rasteriza(on

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

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

Visualization Computer Graphics I Lecture 20

Height Fields and Contours Scalar Fields Volume Rendering Vector Fields [Angel Ch. 12] April 23, 2002 Frank Pfenning Carnegie Mellon University

Pipeline Operations. CS 4620 Lecture 10

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

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

Scan line algorithm. Jacobs University Visualization and Computer Graphics Lab : Graphics and Visualization 272

Buffers, Textures, Compositing, and Blending. Overview. Buffers. David Carr Virtual Environments, Fundamentals Spring 2005 Based on Slides by E.

Announcements. Written Assignment 2 out (due March 8) Computer Graphics

Pipeline Operations. CS 4620 Lecture 14

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

CS4620/5620: Lecture 14 Pipeline

Painter s HSR Algorithm

Computer Graphics CS 543 Lecture 11 (Part 1) Polygon Filling & Antialiasing

Discrete Techniques. 11 th Week, Define a buffer by its spatial resolution (n m) and its depth (or precision) k, the number of

? Which intermediate. Recall: Line drawing algorithm. Programmer specifies (x,y) of end pixels Need algorithm to determine pixels on line path

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

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

Computer Graphics Geometry and Transform

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

Review Computer Graphics I Lecture 23

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

EF432. Introduction to spagetti and meatballs

COMP3421. Particle Systems, Rasterisation

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

Clipping. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

More Visible Surface Detection. CS116B Chris Pollett Mar. 16, 2005.

Reading. 18. Projections and Z-buffers. Required: Watt, Section , 6.3, 6.6 (esp. intro and subsections 1, 4, and 8 10), Further reading:

CS559: Computer Graphics. Lecture 12: Antialiasing & Visibility Li Zhang Spring 2008

The Rasterization Pipeline

Interactive Computer Graphics A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL

9. Illumination and Shading

11/1/13. Visualization. Scientific Visualization. Types of Data. Height Field. Contour Curves. Meshes

Visualization. CSCI 420 Computer Graphics Lecture 26

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

6.837 Introduction to Computer Graphics Assignment 5: OpenGL and Solid Textures Due Wednesday October 22, 2003 at 11:59pm

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

RASTERIZING POLYGONS IN IMAGE SPACE

EF432. Introduction to spagetti and meatballs

Graphics (Output) Primitives. Chapters 3 & 4

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

Topics and things to know about them:

Lecture 13: Reyes Architecture and Implementation. Kayvon Fatahalian CMU : Graphics and Imaging Architectures (Fall 2011)

Computer Graphics 7 - Rasterisation

Input Nodes. Surface Input. Surface Input Nodal Motion Nodal Displacement Instance Generator Light Flocking

CS451Real-time Rendering Pipeline

Rasterization: Geometric Primitives

Computer Graphics. Bing-Yu Chen National Taiwan University

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

CS Rasterization. Junqiao Zhao 赵君峤

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

Rasterization, Depth Sorting and Culling

Chapter IV Fragment Processing and Output Merging. 3D Graphics for Game Programming

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

Graphics and Interaction Rendering pipeline & object modelling

Chapter 8: Implementation- Clipping and Rasterization

TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students)

Real-Time Graphics Architecture

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

Transcription:

15-462 Computer Graphics I Lecture 14 Rasterization March 13, 2003 Frank Pfenning Carnegie Mellon University http://www.cs.cmu.edu/~fp/courses/graphics/ Scan Conversion Antialiasing Compositing [Angel, Ch. 7.9-7.11, 8.9-8.12]

Rasterization Final step in pipeline: rasterization (scan conv.) From screen coordinates (float) to pixels (int) Writing pixels into frame buffer Separate z-buffer, display, shading, blending Concentrate on primitives: Lines Polygons 03/13/2003 15-462 Graphics I 2

DDA Algorithm DDA ( Digital Differential Analyzer ) Represent Assume 0 m 1 Exploit symmetry Distinguish special cases 03/13/2003 15-462 Graphics I 3

DDA Loop Assume write_pixel(int x, int y, int value) For (ix = x1; ix <= x2; ix++) { y += m; write_pixel(ix, round(y), color); } Slope restriction needed Easy to interpolate colors 03/13/2003 15-462 Graphics I 4

Bresenham s Algorithm I Eliminate floating point addition from DDA Assume again 0 m 1 Assume pixel centers halfway between ints 03/13/2003 15-462 Graphics I 5

Bresenham s Algorithm II Decision variable a b If a b > 0 choose lower pixel If a b 0 choose higher pixel Goal: avoid explicit computation of a b Step 1: re-scale d = (x 2 x 1 )(a b) = x(a b) d is always integer 03/13/2003 15-462 Graphics I 6

Bresenham s Algorithm III Compute d at step k +1 from d at step k! Case: j did not change (d k > 0) a decreases by m, b increases by m (a b) decreases by 2m = 2( y/ x) x(a-b) decreases by 2 y 03/13/2003 15-462 Graphics I 7

Bresenham s Algorithm IV Case: j did change (d k 0) a decreases by m-1, b increases by m-1 (a b) decreases by 2m 2 = 2( y/ x 1) x(a-b) decreases by 2( y - x) 03/13/2003 15-462 Graphics I 8

Bresenham s Algorithm V So d k+1 = d k 2 y if d k > 0 And d k+1 = d k 2( y x) if d k 0 Final (efficient) implementation: void draw_line(int x1, int y1, int x2, int y2) { int x, y = y0; int dx = 2*(x2-x1), dy = 2*(y2-y1); int dydx = dy-dx, D = (dy-dx)/2; } for (x = x1 ; x <= x2 ; x++) { write_pixel(x, y, color); if (D > 0) D -= dy; else {y++; D -= dydx;} } 03/13/2003 15-462 Graphics I 9

Bresenham s Algorithm VI Need different cases to handle other m Highly efficient Easy to implement in hardware and software Widely used 03/13/2003 15-462 Graphics I 10

Outline Scan Conversion for Lines Scan Conversion for Polygons Antialiasing Compositing 03/13/2003 15-462 Graphics I 11

Scan Conversion 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 03/13/2003 15-462 Graphics I 12

Filling Convex Polygons Find top and bottom vertices List edges along left and right sides For each scan line from top to bottom Find left and right endpoints of span, xl and xr Fill pixels between xl and xr Can use Bresenham s alg. to update xl and xr xl xr 03/13/2003 15-462 Graphics I 13

Other Operations Pixel shading (Gouraud) Bilinear interpolation of vertex colors Depth values (z-buffer) Bilinear interpolation of vertex depth Read, and write only if visible Preserve depth (final orthographic projection) Texture coordinates u and v Rational linear interpolation to avoid distortion u(x,y) = (Ax+By+C)/(Dx+Ey+F) similarly for v(x,y) Two divisions per pixel for texture mapping Due to perspective transformation 03/13/2003 15-462 Graphics I 14

Concave Polygons: Odd-Even Test Approach 1: odd-even test For each scan line Find all scan line/polygon intersections Sort them left to right Fill the interior spans between intersections Parity rule: inside after an odd number of crossings 03/13/2003 15-462 Graphics I 15

Concave Polygons: Winding Rule Approach 2: winding rule Orient the lines in polygon For each scan line Winding number = right-hdd left-hdd crossings Interior if winding number non-zero Different only for self-intersecting polygons 1 2 1 1 1 1 Even-odd rule Winding rule 03/13/2003 15-462 Graphics I 16

Concave Polygons: Tessellation Approach 3: divide non-convex, non-flat, or non-simple polygons into triangles OpenGL specification Need accept only simple, flat, convex polygons Tessellate explicitly with tessellator objects Implicitly if you are lucky GeForce3 scan converts only triangles 03/13/2003 15-462 Graphics I 17

Boundary Cases Boundaries and special cases require care Cracks between polygons Parity bugs: fill to infinity Intersections on pixel: set at beginning, not end Shared vertices: count y min for parity, not y max Horizontal edges: don t change parity parity change no parity change set pixel don t set pixel 03/13/2003 15-462 Graphics I 18

Edge/Scan Line Intersections Brute force: calculate intersections explicitly Incremental method (Bresenham s algorithm) Caching intersection information Edge table with edges sorted by y min Active edges, sorted by x-intersection, left to right Process image from smallest y min up 03/13/2003 15-462 Graphics I 19

Flood Fill Draw outline of polygon Color seed Color surrounding pixels and recurse Must be able to test boundary and duplication More appropriate for drawing than rendering 03/13/2003 15-462 Graphics I 20

Outline Scan Conversion for Lines Scan Conversion for Polygons Antialiasing Compositing 03/13/2003 15-462 Graphics I 21

Aliasing Artefacts created during scan conversion Inevitable (going from continuous to discrete) Aliasing (name from digital signal processing): we sample a continues image at grid points Effect Jagged edges Moire patterns Moire pattern from sandlotscience.com 03/13/2003 15-462 Graphics I 22

More Aliasing 03/13/2003 15-462 Graphics I 23

Antialiasing for Line Segments Use area averaging at boundary (c) is aliased, magnified (d) is antialiased, magnified Warning: these images are sampled on screen! 03/13/2003 15-462 Graphics I 24

Antialiasing by Supersampling Mostly for off-line rendering (e.g., ray tracing) Render, say, 3x3 grid of mini-pixels Average results using a filter Can be done adaptively Stop if colors are similar Subdivide at discontinuities 03/13/2003 15-462 Graphics I 25

Supersampling Example Other improvements Stochastic sampling (avoiding repetition) Jittering (perturb a regular grid) 03/13/2003 15-462 Graphics I 26

Pixel-Sharing Polygons Another aliasing error Assign color based on area-weighted average Interaction with depth information Use accumulation buffer or α-blending 03/13/2003 15-462 Graphics I 27

Temporal Aliasing Sampling rate is frame rate (30 Hz for video) Example: spokes of wagon wheel in movie Possible to supersample and average Fast-moving objects are blurred Happens automatically in video and movies Exposure time (shutter speed) Memory persistence (video camera) Effect is motion blur 03/13/2003 15-462 Graphics I 28

Motion Blur Achieve by stochastic sampling in time Still-frame motion blur, but smooth animation 03/13/2003 15-462 Graphics I 29

Motion Blur Example T. Porter, Pixar, 1984 16 samples/pixel 03/13/2003 15-462 Graphics I 30

Outline Scan Conversion for Polygons Antialiasing Compositing 03/13/2003 15-462 Graphics I 31

Accumulation Buffer OpenGL mechanism for supersampling or jitter Accumulation buffer parallel to frame buffer Superimpose images from frame buffer Copy back into frame buffer for display glclear(gl_accum_buffer_bit); for (i = 0; i < num_images; i++) { glclear(gl_color_buffer_bit, GL_DEPTH_BUFFER_BIT); display_image(i); glaccum(gl_accum, 1.0/(float)num_images); } glaccum(gl_return, 1.0); 03/13/2003 15-462 Graphics I 32

Filtering and Convolution Image transformation at pixel level Represent N M image as matrix A = [a ik ] Process each color component separately Linear filter produces matrix B = [b ik ] with B is the result of convolving A with filter H Represent H by n m convolution matrix 03/13/2003 15-462 Graphics I 33

Filters for Antialiasing Averaging pixels with neighbors For antialiasing: weigh center more heavily 03/13/2003 15-462 Graphics I 34

Filter for Depth-of-Field Simulate camera depth-of-field Keep plane z = z f in focus Keep near and far planes unchanged Move viewer by x Compute x min, x max, y min, y max for new frustum 03/13/2003 15-462 Graphics I 35

Depth-of-Field Jitter Compute Blend the two images in accumulation buffer 03/13/2003 15-462 Graphics I 36

Blending Frame buffer Simple color model: R, G, B; 8 bits each α-channel A, another 8 bits Alpha determines opacity, pixel-by-pixel α = 1: opaque α = 0: transparent Blend translucent objects during rendering Achieve other effects (e.g., shadows) 03/13/2003 15-462 Graphics I 37

Image Compositing Compositing operation Source: s = [s r s g s b s a ] Destination: d = [d r d g d b d a ] b = [b r b g b b b a ] source blending factors c = [c r c g c b c a ] destination blending factors d = [b r s r + c r d r b g s g + c g d g b b s b + c b d b b a s a + c a d a ] Overlay n images with equal weight Set α-value for each pixel in each image to 1/n Source blending factor is α Destination blending factor is 1 03/13/2003 15-462 Graphics I 38

Blending in OpenGL Enable blending glenable(gl_blend); Set up source and destination factors glblendfund(source_factor, dest_factor); Source and destination choices GL_ONE, GL_ZERO GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA 03/13/2003 15-462 Graphics I 39

Blending Errors Operations are not commutative Operations are not idempotent Interaction with hidden-surface removal Polygon behind opaque one should be culled Translucent in front of others should be composited Solution: make z-buffer read-only for translucent polygons with gldepthmask(gl_false); 03/13/2003 15-462 Graphics I 40

Antialiasing Revisited Single-polygon case first Set α-value of each pixel to covered fraction Use destination factor of 1 α Use source factor of α This will blend background with foreground Overlaps can lead to blending errors 03/13/2003 15-462 Graphics I 41

Antialiasing with Multiple Polygons Initially, background color C 0, α 0 = 0 Render first polygon; color C 1 fraction α 1 C d = (1 α 1 )C 0 + α 1 C 1 α d = α 1 Render second polygon; assume fraction α 2 If no overlap (a), then C d = (1 α 2 )C d + α 2 C 2 α d = α 1 + α 2 03/13/2003 15-462 Graphics I 42

Antialiasing with Overlap Now assume overlap (b) Average overlap is α 1 α 2 So α d = α 1 + α 2 α 1 α 2 Make front/back decision for color as usual 03/13/2003 15-462 Graphics I 43

Antialiasing in OpenGL Avoid explicit α-calculation in program Enable both smoothing and blending glenable(gl_point_smooth); glenable(gl_line_smooth); glenable(gl_blend); glblendfunc(gl_src_alpha, GL_ONE_MINUS_SRC_ALPHA); 03/13/2003 15-462 Graphics I 44

Depth Cueing and Fog Another application of blending Use distance-dependent (z) blending Linear dependence: depth cueing effect Exponential dependence: fog effect This is not a physically-based model GLfloat fcolor[4] = {...}; glenable(gl_fog); glfogf(gl_fog_mode; GL_EXP); glfogf(gl_fog_density, 0.5); glfogfv(gl_fog_color, fcolor); [Example: Fog Tutor] 03/13/2003 15-462 Graphics I 45

Summary Scan Conversion for Polygons Basic scan line algorithm Convex vs concave Odd-even and winding rules, tessellation Antialiasing (spatial and temporal) Area averaging Supersampling Stochastic sampling Compositing Accumulation buffer Blending and α-values 03/13/2003 15-462 Graphics I 46

Preview Assignment 5 due in one week Assignment 6 out in one week Next topics: More on image processing and pixel operations Ray tracing 03/13/2003 15-462 Graphics I 47