Lecture 2 October 31, 2005

Similar documents
Lecture 2 March 24, 2004

Computer Graphics, Lecture 2 October 31, Department of Information Technology. - Scientific Computing. Department of Information Technology

Lecture 2 October 29, 2003

COMP371 COMPUTER GRAPHICS

Scan Conversion. Drawing Lines Drawing Circles

Graphics (Output) Primitives. Chapters 3 & 4

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

Computer Graphics. - Rasterization - Philipp Slusallek

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)

From Ver(ces to Fragments: Rasteriza(on

Einführung in Visual Computing

CS 325 Computer Graphics

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Chapter 8: Implementation- Clipping and Rasterization

Rendering. A simple X program to illustrate rendering

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

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

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

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

Pipeline implementation II

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

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

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

UNIT -8 IMPLEMENTATION

CS488 2D Graphics. Luc RENAMBOT

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

CS 543: Computer Graphics. Rasterization

1 Introduction to Graphics

Topic #1: Rasterization (Scan Conversion)

Topics. From vertices to fragments

Computer Graphics 7 - Rasterisation

UNIT 2 GRAPHIC PRIMITIVES

EF432. Introduction to spagetti and meatballs

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

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

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

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

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

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

CS475m - Computer Graphics. Lecture 1 : Rasterization Basics

Realtime 3D Computer Graphics Virtual Reality

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

Rendering. A simple X program to illustrate rendering

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

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

Clipping and Scan Conversion

Display Technologies: CRTs Raster Displays

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

How shapes are represented in 3D Graphics. Aims and objectives By the end of the lecture you will be able to describe

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

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

(Refer Slide Time: 00:02:00)

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

Pipeline and Rasterization. COMP770 Fall 2011

CSCI 4620/8626. Coordinate Reference Frames

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

Real-Time Graphics Architecture

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

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

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

Rasterization: Geometric Primitives

SE Mock Online Test 1-CG

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

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

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

Chapter 3. Sukhwinder Singh

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

Rasterization. CS4620 Lecture 13

Chapter - 2: Geometry and Line Generations

Rasteriza2on and Clipping

Attributes of Graphics Primitives

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

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

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

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

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

CS Rasterization. Junqiao Zhao 赵君峤

Overview of Computer Graphics

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

Computer Graphics and GPGPU Programming

Unit 2 Output Primitives and their Attributes

Computer Graphics Lecture Notes

The Traditional Graphics Pipeline

Aliasing and Antialiasing. ITCS 4120/ Aliasing and Antialiasing

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

RASTERIZING POLYGONS IN IMAGE SPACE

Rasterization, Depth Sorting and Culling

Line Drawing Week 6, Lecture 9

Institutionen för systemteknik

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

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

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

Pipeline Operations. CS 4620 Lecture 10

Graphics Output Primitives

The Traditional Graphics Pipeline

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

Most device that are used to produce images are. dots (pixels) to display the image. This includes CRT monitors, LCDs, laser and dot-matrix

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

Transcription:

What is a frame buffer? Basic rasterization Computer Graphics 1, Fall 2005 Lecture 02 Chapters 7.8-7.10, 7.12, 8.13 A memory array for display Spatial size nxm pixels Use a xy coordinate system Origin in lower-left corner: computer graphics upper-left corner: image analysis From discrete points to discrete lines What is a discrete line segment? Rosenfeld in the 1960 s Scan Conversion Digital Differential Analyzer (DDA) Simplest algorithm for rasterization of line segments All end-points at integer points Based around the computation of the slope Line algorithm 1: DDA Simple, but uses floating point value computations delta_y = Ydifference / Xdifference; y += delta_y; Patrick Karlsson 1

Line algorithm 2 Keep the fraction part of y in a separate variable, Yerror. Start one half up. delta_y = Ydifference / Xdifference; Yerror = 0.5; Yerror += delta_y; if Yerror >= 1 then Yerror--; Bresenham s Algorithm DDA appears efficient. It is coded easily, but requires one floating point addition per generated pixel In 1965, Bresenham derived an algorithm that avoids floating point computations Standard algorithm in HW and SW Line algorithm 3: integer math Multiply Yerror with 2*Xdifference Yerror = 0.5*2*Xdifference; Yerror = Yerror + 2*Ydifference; if Yerror >= 2*Xdifference then Yerror = Yerror - 2*Xdifference; Line algorithm 4 Subtract 2*Xdifference from Yerror Yerror = -Xdifference; Yerror = Yerror + 2*Ydifference; if Yerror >= 0 then Yerror = Yerror - 2*Xdifference; Line algorithm 5: Bresenham Brushing up things a little Using symmetry Yerror = 2*Ydifference Xdifference; StepEast = 2*Ydifference; StepNorthEast = 2*Ydifference - 2*Xdifference; if Yerror <= 0 then Yerror = Yerror + StepEast; else Yerror = Yerror + StepNorthEast; (-x,y) (-x,-y) (-y,x) (-y,-x) (y,x) (y,-x) (x,y) (x,-y) Patrick Karlsson 2

Polygon Scan Conversion There a many methods for rasterizing a polygon The problem of inside-outside testing A flat simple polygon have well-defined interior The fill and sort problem Flood fill Scanline fill Odd-Even fill Defining a polygon A simple flat polygon is an enclosed area with at least 3 vertices (or 3 edges) Convex polygon Concave polygon Complex polygon Order of vertices Inside-outside testing The crossing or the odd-even test is the most common method for performing an inside-outside test. Vertices are counted as one or two crossings depending on the orientation of the adjacent lines. The ordering of the vertices is important! Flood fill Scanline fill Draw one scan-line at a time = Scan conversion Fill from the inside-out. Fill line-by-line, from the bottom to the top. Patrick Karlsson 3

Scan converting convex polygons Sliver Sort the edges, so we know which ones are left / right. Calculate left and right edge for each scan line (y value) and fill between the left and the right edge values. Be careful to only fill pixels inside the polygon, we do not want double edges. Standard is to include the low valued edges (left edge and first scan line) in the polygon. A pixel-perfect scan conversion algorithm Start by splitting the polygon with horizontal lines at each intermediate vertex and calculate the positions of any new vertices. How to calculate the edge values? Bresenham? Requires integer end-points => polygon jumps one pixel at a time when moving. (Solve by using fixed point mathematics.) Here, we will use the simpler DDA algorithm instead. Each part is now a special case of a figure limited by two arbitrary sloped (not horizontal) lines and two horizontal lines. Note! Horizontal edges may have length 0 (zero)! Linear interpolation is a very important tool Flat top and bottom L(a) = (1- a)p 1 +a p 2, where a=[0,1] height: H=Y2-Y1 (X2L,Y2) (X2R,Y2) p 2 =(X2,Y2) slope left/right: SL=(X2L-X1L)/H SR=(X2R-X1R)/H p 1 =(X1,Y1) y(x) = kx + m k = dy/dx= (Y2- Y1) / (X2- X1) m = Y1 (X1L,Y1) (X1R,Y1) In this slide the underlying grid is drawn incorrectly (because Y2-Y2=0). Try to imagine the the object without the grid. Patrick Karlsson 4

Scan converting polygons Scan converting polygons xl=x1l xr=x1r y=ceil(y1) yskip=y-y1 xl+=yskip*sl xr+=yskip*sr (X1L,Y1) yskip while y floor(y2) for x from ceil(xl) to floor(xr) write_pixel(x,y); x++; end for xl+=sl*1 xr+=sr*1 end while (X1L,Y1) Interpolated scan conversion When interpolating colour, think of the colour value as an additional dimension. So instead of drawing polygons in 2D, we draw them in 3D (or rather 5D) where the colour value is the z dimension. Bi-linear interpolation Linear interpolation in two directions. First we interpolate in the y direction, then we interpolate in the x direction. Unique solution for flat objects Interpolate the new variable over the polygon in the same way as before using the colour slope: dc/dy. Interpolate horizontally by adding dc/dx CSL=(C2L-C1L)/H CSR=(C2R-C1R)/H xl=x1l xr=x1r cl=c1l cr=c1r y=ceil(y1) yskip=y-y1 xl+=yskip*sl xr+=yskip*sr cl+=yskip*csl cr+=yskip*csr (X1L,Y1,C1L) yskip while y floor(y2) dcdx=(cr-cl)/(xr-xl) xskip=ceil(xl)-xl c=cl+xskip*dcdx for x from ceil(xl) to floor(xr) write_pixel(x,y,c); x++; c+=dcdx end for xl+=sl*1 xr+=sr*1 cl+=csl*1 cr+=csr*1 end while xskip Patrick Karlsson 5

Anti-aliasing Rasterized line segments and edges of polygons look jagged The phenomenon is called aliasing Anti-aliasing by, e.g., averaging Nyquist s Sampling Theorem In order to accurately reconstruct a signal from a periodically sampled version of it, the sampling frequency must be at least twice the maximum frequency of the signal. Due to limited resolution in the spatial (pixel size) or colour domain, we are forced to undersample. This results in effects called aliasing. Anti-aliasing Line segments To reduce the effect of aliasing various antialiasing techniques can be applied. Some examples are: Low-pass filtering ( poor man s anti-aliasing) Area-sampling (colour proportional to area) Super-sampling (more samples than pixels) Dithering (anti-aliasing in the colour domain) Area-sampling Intensity proportional to the area covered by the object. Simplified area-sampling Simplified version: Intensity proportional to 1 - distance to pixel Patrick Karlsson 6

Super-sampling Anti-aliasing solves the problem of sliver as well as the problem of shared vertices Normal rasterisation, in a frame-buffer of higher resolution than the screen. Average the intensity of the covered sub-pixels when setting the real pixel value. Sliver 13/16 colour + 3/16 white Scissoring 7.6.3 Clipping in the frame buffer When filling polygons, the pixels outside the screen should not be drawn The small starting step we made, yskip, may be of arbitrary size CSL=(C2L-C1L)/H CSR=(C2R-C1R)/H xl=x1l xr=x1r cl=c1l cr=c1r y=max(ceil(y1),miny) yskip=y-y1 Quite easy to insert scissoring into the polygon filling routine xl+=yskip*sl cl+=yskip*csl (X1L,Y1,C1L) yskip Same thing for x. At the top and right side we can just stop. Additional WWW content while y min(floor(y2),maxy) dcdx=(cr-cl)/(xr-xl) xskip=max(ceil(xl)-xl,minx) c=cl+xskip*dcdx for x from ceil(xl) to min(floor(xr),maxx) write_pixel(x,y,c); x+=1 c+=dcdx end for y+=1 xl+=sl*1 xr+=sr*1 cl+=csl*1 cr+=csr*1 end while xskip Derivation of the Bresenham algorithm Interpolated filling Patrick Karlsson 7