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

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

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

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

CS 543: Computer Graphics. Rasterization

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

COMP371 COMPUTER GRAPHICS

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

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.

Graphics (Output) Primitives. Chapters 3 & 4

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

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

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

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

Chapter 8: Implementation- Clipping and Rasterization

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

Raster Scan Displays. Framebuffer (Black and White)

CS 325 Computer Graphics

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

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

Chapter 3. Sukhwinder Singh

Scan Conversion of Polygons. Dr. Scott Schaefer

Painter s HSR Algorithm

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

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

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

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

Computer Graphics Geometry and Transform

Pipeline implementation II

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

1 Introduction to Graphics

Attributes of Graphics Primitives

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

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

(Refer Slide Time: 00:02:00)

Computer Graphics. - Rasterization - Philipp Slusallek

Identifying those parts of a scene that are visible from a chosen viewing position, and only process (scan convert) those parts

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

In today s lecture we ll have a look at: A simple technique The mid-point circle algorithm

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

From Ver(ces to Fragments: Rasteriza(on

EF432. Introduction to spagetti and meatballs

CS354 Computer Graphics Sampling and Aliasing

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

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

Computer Graphics Lecture Notes

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

COMP3421. Particle Systems, Rasterisation

Einführung in Visual Computing

VERTICAL SCAN-CONVERSION FOR FILLING PURPOSES

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

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

Scan Conversion. Drawing Lines Drawing Circles

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

CSC Computer Graphics

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

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

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

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

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

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

Computer Graphics Geometry and Transform

CS 248 Assignment 2 Polygon Scan Conversion. CS248 Presented by Michael Green Stanford University October 20, 2004

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

CS488 2D Graphics. Luc RENAMBOT

Sampling and Monte-Carlo Integration

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

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

CS 248 Assignment 2 Polygon Scan Converter. CS248 Presented by Abe Davis Stanford University October 17, 2008

Topics. From vertices to fragments

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

The Traditional Graphics Pipeline

EF432. Introduction to spagetti and meatballs

CSCI 4620/8626. Primitives and Attributes

8. Hidden Surface Elimination

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

CS 428: Fall Introduction to. Polygon rendering: additional topics. Andrew Nealen, Rutgers, /14/2009 1

Video of BALSA Scanline Poly Fill Algorithm Animator CS 460. Computer Graphics. Scanline Polygon Fill Algorithm

SE Mock Online Test 1-CG

UNIT 2 GRAPHIC PRIMITIVES

Visible Surface Detection Methods

The Traditional Graphics Pipeline

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

4.5 VISIBLE SURFACE DETECTION METHODES

POLYGON FILLING ALGORITHM

For this assignment, you are to implement three line drawers and a polygon drawer.

Display Technologies: CRTs Raster Displays

Topic #1: Rasterization (Scan Conversion)

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

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

CS602 MCQ,s for midterm paper with reference solved by Shahid

Lecture 2 October 31, 2005

Lecture 3: Art Gallery Problems and Polygon Triangulation

Shading Techniques Denbigh Starkey

UNIT -8 IMPLEMENTATION

The Traditional Graphics Pipeline

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

Transcription:

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

So Far Raster graphics: Line drawing algorithms (simple, Bresenham s) Today: Defining and filling regions Polygon drawing and filling Antialiasing

Defining and Filling Regions of Pixels First, understand how to define and fill any defined regions Next, how to fill regions bounded by a polygon

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

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); // fill up } }

Recursive Flood-Fill Algorithm This version defines region using intcolor Can also have version defining region by boundary Recursive flood-fill is somewhat blind and some pixels may be retested several times before algorithm terminates 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 is a group of adjacent pixels lying on same Exploit runs(adjacent, on same scan line) of pixels

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

Filling Polygon-Defined Regions Problem: Region defined by Polygon P 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

Filling Polygon-Defined Regions 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

Filling Polygon-Defined Regions 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 Read: Hill: 9.7.1, pg 481

Filling Polygon-Defined Regions 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 Hill: 9.7.1, pg. 482

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 use ¼ polygon color add it to ¾ of adjacent region color Cons: computing pixel coverage can be time consuming

Supersampling Useful if we can compute color of any (x,y) value on the screen Increase frequency of sampling Instead of (x,y) samples in increments of 1 Sample (x,y) in fractional (e.g. ½) increments Find average of samples Example: Double sampling = increments of ½ = 9 color values averaged for each pixel Average 9 (x, y) values to find pixel color

Postfiltering Supersampling uses average Gives all samples equal importance Post-filtering: use weighting (different levels of importance) 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], f*jitter[i].y, 0); display( ); glaccum(gl_accum, 1/8.0); } glaccum(gl_return, 1.0); jitter.h -0.3348, 0.4353 0.2864, -0.3934

References Hill, chapter 9