CS Rasterization. Junqiao Zhao 赵君峤

Similar documents
From Ver(ces to Fragments: Rasteriza(on

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

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

Pipeline implementation II

Rasterization: Geometric Primitives

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

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

Rasterization. CS4620 Lecture 13

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

Rendering. A simple X program to illustrate rendering

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

Chapter - 2: Geometry and Line Generations

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

The Traditional Graphics Pipeline

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

Einführung in Visual Computing

Line Drawing. Foundations of Computer Graphics Torsten Möller

The Traditional Graphics Pipeline

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

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

The Traditional Graphics Pipeline

COMP371 COMPUTER GRAPHICS

Rendering. A simple X program to illustrate rendering

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

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

Pipeline and Rasterization. COMP770 Fall 2011

Rasterization and Graphics Hardware. Not just about fancy 3D! Rendering/Rasterization. The simplest case: Points. When do we care?

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

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

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

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

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

2D and 3D Viewing Basics

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Efficient Plotting Algorithm

Overview of Computer Graphics

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

Scan Conversion. Drawing Lines Drawing Circles

Painter s HSR Algorithm

Line Drawing Week 6, Lecture 9

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

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

Last time? Rasterization. Scan Conversion (Rasterization) High-level concepts for Visibility / Display. Today

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

1 Introduction to Graphics

Chapter 8: Implementation- Clipping and Rasterization

Display Technologies: CRTs Raster Displays

Rendering approaches. 1.image-oriented. 2.object-oriented. foreach pixel... 3D rendering pipeline. foreach object...

Topics. From vertices to fragments

Realtime 3D Computer Graphics Virtual Reality

CS Surface Rendering

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

CS 4300 Computer Graphics. Prof. Harriet Fell Fall 2012 Lecture 5 September 13, 2012

Computer Graphics. - Rasterization - Philipp Slusallek

Graphics System. Processor. Output Display. Input Devices. Frame Buffer. Memory. Array of pixels. Resolution: # of pixels Depth: # of bits/pixel

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

From 3D World to 2D Screen. Hendrik Speleers

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

Computer Graphics. Lecture 2. Doç. Dr. Mehmet Gokturk

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

Topic #1: Rasterization (Scan Conversion)

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

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

Computer Graphics 7 - Rasterisation

Pipeline Operations. CS 4620 Lecture 10

CS 543: Computer Graphics. Rasterization

CS 450: COMPUTER GRAPHICS RASTERIZING LINES SPRING 2016 DR. MICHAEL J. REALE

Computer Graphics D Graphics Algorithms

Graphics Systems and Models

Scan Converting Lines

Scan Converting Circles

CS130 : Computer Graphics Lecture 2: Graphics Pipeline. Tamar Shinar Computer Science & Engineering UC Riverside

Rasterization. MIT EECS Frédo Durand and Barb Cutler. MIT EECS 6.837, Cutler and Durand 1

Computer Graphics Lecture Notes

CS-321 Thursday 12 September 2002 Quiz (3 pts.) What is the purpose of a control grid in a cathode ray tube (CRT)?

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

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

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

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

CS 130. Scan Conversion. Raster Graphics

CPSC / Scan Conversion

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

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

CS 130 Final. Fall 2015

Clipping and Scan Conversion

An Improved Algorithm for Scan-converting a Line

EF432. Introduction to spagetti and meatballs

Computer Graphics Lecture 5

UNIT -8 IMPLEMENTATION

CS6504 & Computer Graphics Unit I Page 1

VTU QUESTION PAPER SOLUTION UNIT -1 INTRODUCTION

Rasterization. COMP 575/770 Spring 2013

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

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

Final projects. Rasterization. The Graphics Pipeline. Illumination (Shading) (Lighting) Viewing Transformation. Rest of semester. This week, with TAs

MODULE - 4. e-pg Pathshala

Transcription:

CS10101001 Rasterization Junqiao Zhao 赵君峤 Department of Computer Science and Technology College of Electronics and Information Engineering Tongji University

Vector Graphics Algebraic equations describe shapes. Can render type and large areas of color with relatively small file sizes Can be reduced/enlarged with no loss of quality Cannot show continuous tone images (photographs, color blends) Examples: Plotters, Oscilloscopes, Illustrator, Flash, PDF

Raster Graphics Pixel-based / Bit-mapped graphics Grid of pixels Size of grid = resolution of image Poor scalability : zoom in - loss of quality (jagged look) Best for large photographic images Modification at pixel level - texture mapping, blending, alpha channels, antialiasing, etc. Examples : CRT, LCD, Dot-matrix printers Adobe Photoshop, BMP

Pipeline We are here! (2013 Steve Marschner)

The Display Hardware Cathode Ray Tube (CRT) (Wikipedia)

The Display Hardware Liquid-crystal display (LCD) (Website)

Frame Buffer Model Raster Display: 2D array of picture elements (pixels) Fragments have a location (pixel location) and other attributes such color and texture coordinates that are determined by interpolating values at vertices Pixel colors determined later using color, texture, and other vertex properties (Durand and Cutler MIT )

Rasterization Geometric primitives (point, line, polygon, circle, polyhedron, sphere... ) Primitives are continuous; screen is discrete Scan Conversion: algorithms for efficient generation of the samples comprising this approximation (Durand and Cutler MIT )

Rasterization Rasterization = Scan Conversion = Converting a continuous object such as a line or a circle into discrete pixels.

Rasterization First job: enumerate the pixels covered by a primitive simple, aliased definition: pixels whose centers fall inside Second job: interpolate values across the primitive e.g. colors computed at vertices e.g. normals at vertices

Primitives to be Rasterized Points Line segments and chains of connected line segments Triangles And that s all! Curves? Approximate them with chains of line segments Polygons? Break them up into triangles Curved regions? Approximate them with triangles Trend has been toward minimal primitives simple, uniform, repetitive: good for parallelism

Rasterize Points How? Rules (Microsoft Dx11)

Rasterize Lines Given: Segment endpoints (integers x1, y1; x2, y2) Identify: Set of pixels (x, y) to display for segment (Durand and Cutler MIT )

Requirements Transform continuous primitive into discrete samples Uniform thickness & brightness Continuous appearance No gaps Accuracy Speed

Comparison

(Durand and Cutler MIT ) Think about? Assume: m = dy dx, 0 < m < 1 x2 > x1 One pixel per column Fewer -> disconnected More -> thick

Think about? Note: brightness can vary with slope What is the maximum variation? How can we compensate for this? Antialiasing (Durand and Cutler MIT )

The naive method Simply compute y as a function of x Conceptually: move vertical scan line from x1 to x2 Δx = 1 What is the expression of y as function of x? Set pixel (x, round (y(x))) y = y1 + m x x1 m = dy dx (Durand and Cutler MIT )

Improvement Computing y value is expensive y i = y1 + m x i x1 m = dy dx Observe: y i = y1 + m x i x1 y i+1 = y1 + m x i + Δx x1 = y i + mδx In each step, y += m, x += 1! (Durand and Cutler MIT )

DDA (Digital Difference Analyzer) Select pixel vertically closest to line segment intuitive, efficient, pixel center always within 0.5 vertically (Durand and Cutler MIT )

DDA pseudo code For(x=x1; x<=x2,x++) { y+=m; SetPixel(x, round(y)); }

How to solve general cases? Previously, we assumed x2 < x1, 0 < m < 1 E.g. When x2 < x1? when m > 1? (Eg Angel)

Use Symmetry For m > 1, swap role of x and y For each y, plot closest x x i+1 = x i + 1 m (Eg Angel)

DDA pseudo code dx = x2-x1;dy = y2-y1; If dx > dy then step = dx else step = dy; For(i=0; i<step,i++) { } x+=dx/steps; y+=dy/steps; SetPixel(round(x), round(y));

Bresenham s algorithm The short comings of DDA Floating point arithmetic Round operation Observe again: If we're at pixel P(x p, y p ), the next pixel must be either E (x p + 1, y p ) or NE (x p + 1, y p + 1) Why? (Durand and Cutler MIT )

Candidate Pixels y = mx + b candidates last pixel Note that line could have passed through any part of this pixel

Candidate Pixels y = mx + b j + 3 2 candidates j + 1 2 last pixel i + 1 2 i + 3 2 Note that line could have passed through any part of this pixel

The decision function y = mx + b j + 3 2 j + 1 2 i + 1 2 i + 3 2

The decision function j + 3 2 j + 1 2 a b y = mx + b i + 1 2 i + 3 2

The decision parameter If a < b Then upper pixel If a > b Then lower pixel y k + 1 y k a b a = (y k +1) y = y k + 1 m x k + 1 b b = y y k = m x k + 1 + b y k let d = Δx a b = 2Δy x k 2Δx y k + c x k x k + 1 d is an integer d < 0 use upper pixel d > 0 use lower pixel

Bresenham s algorithm (mid-point) Further observation: d k = 2Δy x k 2Δx y k + c d k+1 = 2Δy x k+1 2Δx y k+1 + c d k+1 d k = 2Δy (x k+1 x k ) 2Δx (y k+1 y k ) Here: x k+1 x k = 1, if 0 < m < 1 y k+1 y k = 0 or 1, depending on the sign of d k d 0 = 2Δy Δx

Bresenham s algorithm Given x 1, y 1, x 2, y 2 Calculate Δx, Δy d 0 = 2Δy Δx SetPixel(x 0, y 0 ) At each x k, k starts from k=0, do Δx 1 steps If d k <0, SetPixel(x k +1, y k ) and d k+1 = d k + 2Δy If d k >0, SetPixel(x k +1, y k +1) and d k+1 = d k + 2Δy 2Δx

Mid-point algorithm Similar to Bresenham s But can be extended! y k + 1 y = mx + b y k Mid-point x k x k + 1

Curve Take Circle as an example Generate pixels for 1/8 octant only Slope progresses from 0 1 Analog of Bresenham s Algorithm (Durand and Cutler MIT )

y k y k -1 Mid-point x 2 + y 2 = r 2 x k x k + 1

Midpoint Circle Algorithm Decision Function: d k = D x k + 1, y k 0.5 = (x k +1) 2 + (y k 0.5) 2 r 2 If d k < 0, the mid point is inside the circle, choose upper If d k > 0, the mid point is outside the circle,choose lower If d k = 0, the mid point is on the circle,choose lower

Midpoint Circle Algorithm Observation d k+1 = D x k+1 + 1, y k+1 0.5 = (x k +1 + 1) 2 + (y k+1 + 0.5) 2 r 2 2 d k+1 = d k + 2 x k + 1 + y k+1 y 2 k y k+1 y k + 1 y k+1 is either y k or y k 1, depending on the sign of d k On each iteration: x += 1 d k += 2x k+1 + 1 if d k < 0 d k += 2x k+1 + 1 2y k+1 if d k > 0

References Ed Angel, CS/EECE 433 Computer Graphics, University of New Mexico Cutler and Durand, MIT EECS 6.837 Steve Marschner, CS4620/5620 Computer Graphics, Cornell Tom Thorne, COMPUTER GRAPHICS, The University of Edinburgh Elif Tosun, Computer Graphics, The University of New York

Questions?