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

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

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

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

CS 543: Computer Graphics. Rasterization

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

CS 563 Advanced Topics in Computer Graphics Lecture 2: Bare-Bones Raytracer. by Emmanuel Agu

Painter s HSR Algorithm

COMP371 COMPUTER GRAPHICS

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

1 Introduction to Graphics

Computer Graphics (CS 543) Lecture 9 (Part 2): Clipping. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

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

Graphics (Output) Primitives. Chapters 3 & 4

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

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)

Computer Graphics. - Rasterization - Philipp Slusallek

Raster Scan Displays. Framebuffer (Black and White)

Chapter 8: Implementation- Clipping and Rasterization

Rasterization: Geometric Primitives

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

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

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

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

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

Pipeline implementation II

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

From Ver(ces to Fragments: Rasteriza(on

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

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

Reading on the Accumulation Buffer: Motion Blur, Anti-Aliasing, and Depth of Field

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

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

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

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

COMP3421. Particle Systems, Rasterisation

CS 325 Computer Graphics

Scan Conversion. Drawing Lines Drawing Circles

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

Chapter - 2: Geometry and Line Generations

Attributes of Graphics Primitives

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

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

Computer Graphics Geometry and Transform

(Refer Slide Time: 00:02:00)

Computer Graphics (CS 543) Lecture 10 (Part 1): 3D Clipping. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Lecture 6 of 41. Scan Conversion 1 of 2: Midpoint Algorithm for Lines and Ellipses

Lecture 6 of 41. Scan Conversion 1 of 2: Midpoint Algorithm for Lines and Ellipses

UNIT 2 GRAPHIC PRIMITIVES

Scan Converting Lines

Computer Graphics (4731) Lecture 4: 2D Graphics Systems (Drawing Polylines, tiling, & Aspect Ratio)

Topics. From vertices to fragments

CS488 2D Graphics. Luc RENAMBOT

EF432. Introduction to spagetti and meatballs

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

Scan Conversion of Polygons. Dr. Scott Schaefer

Rendering. A simple X program to illustrate rendering

Computer Graphics Lecture Notes

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

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

Line Drawing. Foundations of Computer Graphics Torsten Möller

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

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

Shading Techniques Denbigh Starkey

Einführung in Visual Computing

Chapter 3. Sukhwinder Singh

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

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

Computer Graphics (CS 543) Lecture 4a: Introduction to Transformations

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

Computer Graphics (CS 4731) Lecture 16: Lighting, Shading and Materials (Part 1)

Lecture 2: Digital Drawing. Computer Graphics and Imaging UC Berkeley CS184/284

Computer Graphics (CS 543) Lecture 10: Soft Shadows (Maps and Volumes), Normal and Bump Mapping

Institutionen för systemteknik

Computer Graphics (CS 543) Lecture 7b: Intro to lighting, Shading and Materials + Phong Lighting Model

CS 130 Exam I. Fall 2015

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

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

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

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

Line Drawing Week 6, Lecture 9

CS 130 Exam I. Fall 2015

Display Technologies: CRTs Raster Displays

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

Topic #1: Rasterization (Scan Conversion)

Computer Graphics. Rendering. by Brian Wyvill University of Calgary. cpsc/enel P 1

Unit 2 Output Primitives and their Attributes

More on Coordinate Systems. Coordinate Systems (3) Coordinate Systems (2) Coordinate Systems (5) Coordinate Systems (4) 9/15/2011

EF432. Introduction to spagetti and meatballs

Overview of Computer Graphics

Computer Graphics (CS 543) Lecture 13b Ray Tracing (Part 1) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

CS 130 Final. Fall 2015

Computer Graphics CS 543 Lecture 13a Curves, Tesselation/Geometry Shaders & Level of Detail

UNIT -8 IMPLEMENTATION

CS354 Computer Graphics Sampling and Aliasing

I Internal Examination (Model Paper) B.Tech III Year VI semester, Computer Science & Engineering

Computer Graphics (CS 543) Lecture 8a: Per-Vertex lighting, Shading and Per-Fragment lighting

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

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

Computer Graphics Geometry and Transform

Transcription:

Recall: Line drawing algorithm Programmer specifies (x,y) of end pixels Need algorithm to determine pixels on line path 8 7 6 5 4 3 2 1 (3,2) (9,6) Line: (3,2) -> (9,6)? Which intermediate pixels to turn on? 0 1 2 3 4 5 6 7 8 9 10 11 12

Bresenham s Line-Drawing Algorithm Problem: Given endpoints (Ax, Ay) and (Bx, By) of line, determine intervening pixels First make two simplifying assumptions (remove later): (Ax < Bx) and (0 < m < 1) Define Width W = Bx Ax Height H = By - Ay (Bx,By) H (Ax,Ay) W

Bresenham s Line-Drawing Algorithm (Bx,By) H W (Ax,Ay) Based on assumptions (Ax < Bx) and (0 < m < 1) W, H are +ve H < W Increment x by +1, y incr by +1 or stays same Midpoint algorithm determines which happens

Bresenham s Line-Drawing Algorithm What Pixels to turn on or off? Consider pixel midpoint M(Mx, My) = (x + 1, y + ½) Build equation of actual line, compare to midpoint (x1,y1) M(Mx,My) Case a: If midpoint (red dot) is below line, Shade upper pixel, (x + 1, y + 1) (x1,y1) (x0, y0) Case b: If midpoint (red dot) is above line, Shade lower pixel, (x + 1, y)

Build Equation of the Line Using similar triangles: (x,y) (Bx,By) H y x Ay Ax H W (Ax,Ay) W H(x Ax) = W(y Ay) -W(y Ay) + H(x Ax) = 0 Above is equation of line from (Ax, Ay) to (Bx, By) Thus, any point (x,y) that lies on ideal line makes eqn = 0 Double expression (to avoid floats later), and call it F(x,y) F(x,y) = -2W(y Ay) + 2H(x Ax)

Bresenham s Line-Drawing Algorithm So, F(x,y) = -2W(y Ay) + 2H(x Ax) Algorithm, If: F(x, y) < 0, (x, y) above line F(x, y) > 0, (x, y) below line Hint: F(x, y) = 0 is on line Increase y keeping x constant, F(x, y) becomes more negative

Bresenham s Line-Drawing Algorithm Example: to find line segment between (3, 7) and (9, 11) F(x,y) = -2W(y Ay) + 2H(x Ax) = (-12)(y 7) + (8)(x 3) For points on line. E.g. (7, 29/3), F(x, y) = 0 A = (4, 4) lies below line since F = 44 B = (5, 9) lies above line since F = -8 (5,9) (4,4)

Bresenham s Line-Drawing Algorithm What Pixels to turn on or off? Consider pixel midpoint M(Mx, My) = (x0 + 1, Y0 + ½) (x1,y1) M(Mx,My) (x1,y1) Case a: If M below actual line F(Mx, My) < 0 shade upper pixel (x + 1, y + 1) (x0, y0) Case b: If M above actual line F(Mx,My) > 0 shade lower pixel (x + 1, y)

Can compute F(x,y) incrementally Initially, midpoint M = (Ax + 1, Ay + ½) F(Mx, My) = -2W(y Ay) + 2H(x Ax) i.e. F(Ax + 1, Ay + ½) = 2H W Can compute F(x,y) for next midpoint incrementally If we increment to (x + 1, y), compute new F(Mx,My) F(Mx, My) += 2H (Ax + 2, Ay + ½) i.e. F(Ax + 2, Ay + ½) - F(Ax + 1, Ay + ½) = 2H (Ax + 1, Ay + ½)

Can compute F(x,y) incrementally If we increment to (x +1, y + 1) F(Mx, My) += 2(H W) i.e. F(Ax + 2, Ay + 3/2) - F(Ax + 1, Ay + ½) = 2(H W) (Ax + 2, Ay + 3/2) (Ax + 1, Ay + ½)

Bresenham s Line-Drawing Algorithm Bresenham(IntPoint a, InPoint b) { // restriction: a.x < b.x and 0 < H/W < 1 int y = a.y, W = b.x a.x, H = b.y a.y; int F = 2 * H W; // current error term for(int x = a.x; x <= b.x; x++) { setpixel at (x, y); // to desired color value if F < 0 // y stays same F = F + 2H; else{ Y++, F = F + 2(H W) // increment y } } } Recall: F is equation of line

Bresenham s Line-Drawing Algorithm Final words: we developed algorithm with restrictions 0 < m < 1 and Ax < Bx Can add code to remove restrictions When Ax > Bx (swap and draw) Lines having m > 1 (interchange x with y) Lines with m < 0 (step x++, decrement y not incr) Horizontal and vertical lines (pretest a.x = b.x and skip tests)

Computer Graphics CS 4731 Lecture 23 Polygon Filling & Antialiasing Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI)

Defining and Filling Regions of Pixels Methods of defining region Pixel-defined: specifies pixels in color or geometric range Symbolic: provides property pixels in region must have Examples of symbolic: Closeness to some pixel Within circle of radius R Within a specified polygon

Pixel-Defined Regions Definition: Region R is the set of all pixels having color C that are connected to a given pixel S 4-adjacent: pixels that lie next to each other horizontally or vertically, NOT diagonally 8-adjacent: pixels that lie next to each other horizontally, vertically OR diagonally 4-connected: if there is unbroken path of 4-adjacent pixels connecting them 8-connected: unbroken path of 8-adjacent pixels connecting them

Recursive Flood-Fill Algorithm Recursive algorithm Starts from initial pixel of color, intcolor Recursively set 4-connected neighbors to newcolor Flood-Fill: floods region with newcolor Basic idea: start at seed pixel (x, y) If (x, y) has color intcolor, change it to newcolor Do same recursively for all 4 neighbors (x, y+1) (x-1, y (x, y) (x, y-1) (x+1, y)

Recursive Flood-Fill Algorithm Note: getpixel(x,y) used to interrogate pixel color at (x, y) void floodfill(short x, short y, short intcolor) { if(getpixel(x, y) == intcolor) { setpixel(x, y); floodfill(x 1, y, intcolor); // left pixel floodfill(x + 1, y, intcolor); // right pixel floodfill(x, y + 1, intcolor); // down pixel floodfill(x, y 1, intcolor); // up pixel } } (x, y+1) (x-1, y (x, y) (x, y-1) (x+1, y)

Recursive Flood-Fill Algorithm Recursive flood-fill is blind Some pixels retested several times Region coherence is likelihood that an interior pixel mostly likely adjacent to another interior pixel Coherence can be used to improve algorithm performance A run: group of adjacent pixels lying on same scanline Fill runs(adjacent, on same scan line) of pixels

Region Filling Using Coherence Example: start at s, initial seed Push address of seed pixel onto stack while(stack is not empty) { Pop stack to provide next seed Fill in run defined by seed Pseudocode: In row above find reachable interior runs Push address of their rightmost pixels Do same for row below current run } Note: algorithm most efficient if there is span coherence (pixels on scanline have same value) and scan-line coherence (consecutive scanlines similar)

Filling Polygon-Defined Regions Problem: Region defined polygon with vertices Pi = (Xi, Yi), for i = 1 N, specifying sequence of P s vertices P1 P2 P7 P3 P5 P6 P4

Filling Polygon-Defined Regions Solution: Progress through frame buffer scan line by scan line, filling in appropriate portions of each line Filled portions defined by intersection of scan line and polygon edges Runs lying between edges inside P are filled Pseudocode: for(each scan Line L) { Find intersections of L with all edges of P Sort the intersections by increasing x-value Fill pixel runs between all pairs of intersections }

Filling Polygon-Defined Regions Example: scan line y = 3 intersects 4 edges e3, e4, e5, e6 Sort x values of intersections and fill runs in pairs Note: at each intersection, inside-outside (parity), or vice versa P1 P2 P7 P3 e6 e3 3 P6 e5 P5 e4 P4

Data Structure

Filling Polygon-Defined Regions Problem: What if two polygons A, B share an edge? Algorithm behavior could result in: setting edge first in one color and the another Drawing edge twice too bright Make Rule: when two polygons share edge, each polygon owns its left and bottom edges E.g. below draw shared edge with color of polygon B A B

Filling Polygon-Defined Regions Problem: How to handle cases where scan line intersects with polygon endpoints to avoid wrong parity? Solution: Discard intersections with horizontal edges and with upper endpoint of any edge See 0 See 0 See 2 See 1 See 0 See 2 See 1

Antialiasing Raster displays have pixels as rectangles Aliasing: Discrete nature of pixels introduces jaggies

Antialiasing Aliasing effects: Distant objects may disappear entirely Objects can blink on and off in animations Antialiasing techniques involve some form of blurring to reduce contrast, smoothen image Three antialiasing techniques: Prefiltering Postfiltering Supersampling

Prefiltering Basic idea: compute area of polygon coverage use proportional intensity value Example: if polygon covers ¼ of the pixel Pixel color = ¼ polygon color + ¾ adjacent region color Cons: computing polygon coverage can be time consuming

Supersampling Assumes we can compute color of any location (x,y) on screen Sample (x,y) in fractional (e.g. ½) increments, average samples Example: Double sampling = increments of ½ = 9 color values averaged for each pixel Average 9 (x, y) values to find pixel color

Postfiltering Supersampling weights all samples equally Post-filtering: use unequal weighting of samples Compute pixel value as weighted average Samples close to pixel center given more weight Sample weighting 1/16 1/16 1/16 1/16 1/2 1/16 1/16 1/16 1/16

Antialiasing in OpenGL Many alternatives Simplest: accumulation buffer Accumulation buffer: extra storage, similar to frame buffer Samples are accumulated When all slightly perturbed samples are done, copy results to frame buffer and draw

Antialiasing in OpenGL First initialize: glutinitdisplaymode(glut_single GLUT_RGB GLUT_ACCUM GLUT_DEPTH); Zero out accumulation buffer glclear(glut_accum_buffer_bit); Add samples to accumulation buffer using glaccum( )

Antialiasing in OpenGL Sample code jitter[] stores randomized slight displacements of camera, factor, f controls amount of overall sliding glclear(gl_accum_buffer_bit); for(int i=0;i < 8; i++) { cam.slide(f*jitter[i].x, f*jitter[i].y, 0); display( ); glaccum(gl_accum, 1/8.0); jitter.h } -0.3348, 0.4353 glaccum(gl_return, 1.0); 0.2864, -0.3934

References Angel and Shreiner, Interactive Computer Graphics, 6 th edition Hill and Kelley, Computer Graphics using OpenGL, 3 rd edition, Chapter 9