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

Similar documents
Lecture 2 March 24, 2004

Lecture 2 October 31, 2005

Lecture 2 October 29, 2003

COMP371 COMPUTER GRAPHICS

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

Computer Graphics. - Rasterization - Philipp Slusallek

From Ver(ces to Fragments: Rasteriza(on

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)

Rendering. A simple X program to illustrate rendering

Scan Conversion. Drawing Lines Drawing Circles

Einführung in Visual Computing

Chapter 8: Implementation- Clipping and Rasterization

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

Graphics (Output) Primitives. Chapters 3 & 4

Pipeline implementation II

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

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

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

Clipping and Scan Conversion

Rendering. A simple X program to illustrate rendering

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

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

EF432. Introduction to spagetti and meatballs

Realtime 3D Computer Graphics Virtual Reality

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

CS488 2D Graphics. Luc RENAMBOT

Computer Graphics 7 - Rasterisation

UNIT 2 GRAPHIC PRIMITIVES

Topics. From vertices to fragments

Rasterization: Geometric Primitives

CS475m - Computer Graphics. Lecture 1 : Rasterization Basics

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

UNIT -8 IMPLEMENTATION

CS 543: Computer Graphics. Rasterization

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

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

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

Overview of 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

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

SE Mock Online Test 1-CG

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 : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling

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

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

Chapter - 2: Geometry and Line Generations

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

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

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

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

Topic #1: Rasterization (Scan Conversion)

1 Introduction to Graphics

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

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

Computer Graphics Lecture Notes

Display Technologies: CRTs Raster Displays

CS Rasterization. Junqiao Zhao 赵君峤

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

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

Chapter 3. Sukhwinder Singh

Unit 2 Output Primitives and their Attributes

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

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

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

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

Rasteriza2on and Clipping

CS 325 Computer Graphics

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

Painter s HSR Algorithm

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

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

Computer Graphics D Graphics Algorithms

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

Computer Graphics. Chapter 4 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

Raster Scan Displays. Framebuffer (Black and White)

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

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

Pipeline and Rasterization. COMP770 Fall 2011

Line Drawing. Foundations of Computer Graphics Torsten Möller

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

Rasterization. CS4620 Lecture 13

Scan Converting Circles

Computer Graphics and GPGPU Programming

CSCI 4620/8626. Coordinate Reference Frames

Real-Time Graphics Architecture

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

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

(Refer Slide Time: 00:02:00)

Rasterization, Depth Sorting and Culling

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

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

The Traditional Graphics Pipeline

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

RASTERIZING POLYGONS IN IMAGE SPACE

EF432. Introduction to spagetti and meatballs

Line Drawing Week 6, Lecture 9

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

Transcription:

Computer Graphics, Lecture 2 October 31, 2006 Frame buffer Basic Basic rasterization Computer Graphics 1, Fall 2006 Lecture 2 Chapter 7.8-7.10, 7.12, 8.13 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 7.8 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; Ingela Nyström 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--; 7.9 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 Line algorithm 4 Subtract 2*Xdifference from Yerror Yerror = 0.5*2*Xdifference; Yerror += 2*Ydifference; if Yerror >= 2*Xdifference then Yerror -= 2*Xdifference; Yerror = -Xdifference; Yerror += 2*Ydifference; if Yerror >= 0 then 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 += StepEast; else Yerror += StepNorthEast; (-x,y) (-x,-y) (-y,x) (-y,-x) (y,x) (y,-x) (x,y) (x,-y) Ingela Nyström 2

7.10 Scan Conversion of Polygons Defining a polygon Many methods for rasterizing polygons: Inside-outside testing Concave polygons Fill and sort Flood fill Scan lines 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, i.e., scan conversion Flood-fill: Rasterize the edges of the polygon Find seed-point inside Recursively fill neighbours until edges are reached Ingela Nyström 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 (X2L,Y2) (X2R,Y2) p 2 =(X2,Y2) height: H=Y2-Y1 p 1 =(X1,Y1) y(x) = kx + m k = dy/dx= (Y2- Y1) / (X2- X1) m = Y1 slope left/right: SL=(X2L-X1L)/H SR=(X2R-X1R)/H (X1L,Y1) (X1R,Y1) Ingela Nyström 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 Bi-linear interpolation 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. 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 dy Interpolate horizontally by adding dc/dx 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 Ingela Nyström 5

7.12 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 under-sample. This results in effects called aliasing. Anti-aliasing To reduce the effect of aliasing various anti-aliasing techniques can be applied: 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) Line segments Area-sampling Intensity proportional to the area covered by the object Simplified area-sampling Intensity proportional to 1 - distance to pixel Ingela Nyström 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 CSL=(C2L-C1L)/H CSR=(C2R-C1R)/H xl=x1l xr=x1r cl=c1l cr=c1r y=max(ceil(y1),miny) yskip=y-y1 The small starting step we made, yskip,, may be of arbitrary size 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 material 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 Useful in computer exercise 1 Ingela Nyström 7