Lecture 2 March 24, 2004

Similar documents
Lecture 2 October 31, 2005

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

Lecture 2 October 29, 2003

COMP371 COMPUTER GRAPHICS

From Ver(ces to Fragments: Rasteriza(on

Scan Conversion. Drawing Lines Drawing Circles

Computer Graphics. - Rasterization - Philipp Slusallek

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

Graphics (Output) Primitives. Chapters 3 & 4

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)

Rendering. A simple X program to illustrate rendering

Chapter 8: Implementation- Clipping and Rasterization

Pipeline implementation II

Einführung in Visual Computing

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

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

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

UNIT -8 IMPLEMENTATION

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

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

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

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

EF432. Introduction to spagetti and meatballs

Realtime 3D Computer Graphics Virtual Reality

CS475m - Computer Graphics. Lecture 1 : Rasterization Basics

CS488 2D Graphics. Luc RENAMBOT

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

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

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

CS 543: Computer Graphics. Rasterization

CS 325 Computer Graphics

Clipping and Scan Conversion

Topics. From vertices to fragments

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

Rendering. A simple X program to illustrate rendering

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

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

1 Introduction to Graphics

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

UNIT 2 GRAPHIC PRIMITIVES

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

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

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

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

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

Rasterization: Geometric Primitives

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

Overview of Computer Graphics

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

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

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

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

Display Technologies: CRTs Raster Displays

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

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

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

Computer Graphics 7 - Rasterisation

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

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

Topic #1: Rasterization (Scan Conversion)

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

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

SE Mock Online Test 1-CG

CSCI 4620/8626. Coordinate Reference Frames

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

The Traditional Graphics Pipeline

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

Pipeline and Rasterization. COMP770 Fall 2011

Aliasing and Antialiasing. ITCS 4120/ Aliasing and Antialiasing

CS Rasterization. Junqiao Zhao 赵君峤

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

Rasterization. CS4620 Lecture 13

Real-Time Graphics Architecture

RASTERIZING POLYGONS IN IMAGE SPACE

Rasterization, Depth Sorting and Culling

Computer Graphics Lecture Notes

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

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

Chapter - 2: Geometry and Line Generations

Line Drawing Week 6, Lecture 9

Graphics and Interaction Rendering pipeline & object modelling

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

(Refer Slide Time: 00:02:00)

Rasteriza2on and Clipping

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

Chapter 3. Sukhwinder Singh

Institutionen för systemteknik

The Traditional Graphics Pipeline

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

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

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

EF432. Introduction to spagetti and meatballs

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

Introduction to Computer Graphics (CS602) Lecture 05 Line Drawing Techniques

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

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

Painter s HSR Algorithm

Line Drawing. Foundations of Computer Graphics Torsten Möller

Computer Graphics and GPGPU Programming

Transcription:

Frame buffer Basic rasterization Computer Graphics 1, Spring 2004 Lecture 2 Chapter 8.9-8.12 Array for display n x m pixels x-y coordinate system Origin in lower-left corner: computer graphics upper-left corner: image analysis Drawing lines Discrete line segments Rosenfeld in the 1960 s 8.9 Scan Conversion Digital Differential Analyzer (DDA) Simplest algorithm for rasterization of line segments End-points at integer points Compute 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--; 8.10 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

8.11 Scan Conversion of Polygons Many methods for rasterizing polygons Inside-outside testing Concave polygons Fill and sort Flood fill Scan lines Defining a polygon A 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 Filling polygons Filling polygons Draw one scan-line at a time = scan conversion 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 Linear interpolation Flat top and bottom p(a) = (1- a)p 1 +a p 2 p 1 =(X1,Y1) p 2 =(X2,Y2) y(x) = kx + m k = dy/dx= (Y2- Y1) / (X2- X1) m = Y1 height: H=Y2-Y1 slope left/right: SL=(X2L-X1L)/H SR=(X2R-X1R)/H (X2L,Y2) (X1L,Y1) (X2R,Y2) (X1R,Y1) 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

8.11 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 8.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