Line Rasterization and Antialiasing

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

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

Laboratory Exercise 8

Rasterization, Depth Sorting and Culling

From Ver(ces to Fragments: Rasteriza(on

CS475m - Computer Graphics. Lecture 1 : Rasterization Basics

EECS150 - Digital Design Lecture 12 - Video Interfacing. MIPS150 Video Subsystem

EECS150 - Digital Design Lecture 15 - Video

EECS150 - Digital Design Lecture 15 - Project Description, Part 5

MAZE A SIMPLE GPU WITH EMBEDDED VIDEO GAME. Designed by:

Laboratory Exercise 5

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

Pipeline implementation II

Einführung in Visual Computing

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

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

CS Rasterization. Junqiao Zhao 赵君峤

Line Drawing. Foundations of Computer Graphics Torsten Möller

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

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

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

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

Chapter 8: Implementation- Clipping and Rasterization

Display Technologies: CRTs Raster Displays

Efficient Plotting Algorithm

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

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

Realtime 3D Computer Graphics Virtual Reality

Bresenham s Line Algorithm in Hardware

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

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

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

CS 543: Computer Graphics. Rasterization

UNIT -8 IMPLEMENTATION

Rendering. A simple X program to illustrate rendering

Overview of Computer Graphics

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

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

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

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

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

COMP3421. Particle Systems, Rasterisation

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

Computer Graphics - Week 6

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Topic #1: Rasterization (Scan Conversion)

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

CSCI 4620/8626. Coordinate Reference Frames

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

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

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

Chapter - 2: Geometry and Line Generations

Output Primitives Lecture: 4. Lecture 4

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

Computer Graphics Lecture 5

Scan Conversion. Lines and Circles

Scan Conversion. Drawing Lines Drawing Circles

OUTPUT PRIMITIVES. CEng 477 Introduction to Computer Graphics METU, 2007

COMP371 COMPUTER GRAPHICS

Graphics (Output) Primitives. Chapters 3 & 4

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

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

E.Order of Operations

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

CS 4620 Final Exam. (a) Is a circle C 0 continuous?

Z- Buffer Store the depth for each pixel on the screen and compare stored value with depth of new pixel being drawn.

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

Computer Graphics and GPGPU Programming

1 Introduction to Graphics

Time: 3 hours Max. Marks: 80. Note: Answer FIVE full questions, choosing one full question from each module.

Scan Converting Lines

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers

Lossy Coding 2 JPEG. Perceptual Image Coding. Discrete Cosine Transform JPEG. CS559 Lecture 9 JPEG, Raster Algorithms

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

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

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY CS2401 COMPUTER GRAPHICS QUESTION BANK

MET71 COMPUTER AIDED DESIGN

From 3D World to 2D Screen. Hendrik Speleers

The Traditional Graphics Pipeline

Computer Graphics. - Rasterization - Philipp Slusallek

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. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

A New Line Drawing Algorithm Based on Sample Rate Conversion

Rasterizing triangles

An Improved Algorithm for Scan-converting a Line

Rasteriza2on and Clipping

The Traditional Graphics Pipeline

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

CS 130 Exam I. Fall 2015

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

Rendering. A simple X program to illustrate rendering

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

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

Lecture 4. Animation: Procedure and Case Studies

CS488 2D Graphics. Luc RENAMBOT

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

1 Some easy lines (2, 17) (10, 17) (18, 2) (18, 14) (1, 5) (8, 12) Check with a ruler. Are your lines straight?

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

UNIT 2 GRAPHIC PRIMITIVES

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

Transcription:

Katarina Mitchell, James Rich and Michael Bullis CprE 480x Final Project Line Rasterization and Antialiasing Rubric Code Modified and Added OpenGL Additions New types in SGP_config In utils/include/sgp.h In utils/src/simplegl/glwrapper.c Line Rasterization using Bresenham Algorithm Bresenham Algorithm Line Rasterization with Antialiasing using Gupta-Sproull Algorithm Gupta-Sproull Algorithm Variant Flow through LineRast Resources

Rubric Attributes Unsatisfactory Satisfactory Beyond Satisfactory Hardware Line Rasterization & Aliasing Rasterize an aliased line (Bresenham) [50] Use algorithm for antialiasing (Gupta- Sproull) [100] Further optimize the Gupta-Sproull algorithm implementation [150] OpenGL Integration Basic GL_LINES functionality implemented. [25] Support for GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP [50] Support for line color interpolation and gllinewidth [75] Demo and Report Demo and report partially completed [25] Full demo, report includes description of all major components [50] Full demo, report also includes detailed figures and testing results [75] Code Modified and Added 1. OpenGL a. GL_LINES, GL_LINE_LOOP & GL_LINE_STRIP all implemented in original code as well as Enable/Disable antialiasing i. utils/src/simplegl/glwrapper ii. utils/src/simplegl/gl.h (gl_lines, gl_line_loop, gl_line_strip are opcodes x0001-3) iii. GL_LINE_SMOOTH within glenable/gldisable (GL_LINE_SMOOTH opcode x0b20) 2. Assembly a. GL_LINES, GL_LINE_LOOP & GL_LINE_STRIP all handled in original code 3. VertexOps a. Added logic to the clipping component to remove lines outside of the viewport 4. RasterOps a. Added the LineRast component and necessary signals. b. Added a link between the host bus and the LineRast component. 5. LineRast a. Added two separate algorithms, Bresenham Line Rasterization algorithm and Gupta-Sproull Antialiasing Line Rasterization Algorithm.

OpenGL Additions New types in SGP_config

In utils/src/simplegl/glwrapper.c we had to modify the glenable and gldisable methods to send a packet to the rasterops module whenever a glenable(gl_line_smooth) or gldisable(gl_line_smooth) call is made. The rasterops module will then receive this with its host bus interface and forward this onto our line rasterization unit. type line_array_t is array(1 downto 0) of vertexattr_t; type line_t is record vertex : line_array_t; valid : std_logic; smooth : std_logic; end record; In utils/include/sgp.h #define SMOOTH_ENABLE 0x400 #define SMOOTH_DISABLE 0x800 In utils/src/simplegl/glwrapper.c glenable if(cap == GL_LINE_SMOOTH) sendpacket( RASTEROPS SMOOTH_ENABLE NUMPACKETS(0),0); gldisable if(cap == GL_LINE_SMOOTH) sendpacket( RASTEROPS SMOOTH_DISABLE NUMPACKETS(0),0); Line Rasterization using Bresenham Algorithm For the case when antialiasing is disabled, the linerast module uses a variation of the Bresenham algorithm to rasterize lines. The algorithm is fairly fast and requires only one division per line to be rasterized. All other calculations are simple additions or subtractions. The basic idea of the Bresenham algorithm is to start at the left side of the line to be rasterized and increment x as you continue on. The y direction is only changed when the error (or slope) indicates.

The algorithm starts by reading in a line, identifying the slope and swapping the x-values with the y-values if the slope is too steep (if Δy > Δx). The reason we need to swap the x-values with the y-values for a line with a steep slope is because we are using Δy/Δx to calculate our error. This is the distance the rasterized fragment will move away from the true line during each iteration when we increment our x-value. If the error gets too large, then it means that the y- value is too far away from the true line we are trying to draw. When the total error exceeds 0.5, the y-value is incremented or decremented by 1 (depending on orientation) and 1 is subtracted from the total error. If we do not swap the x-values and y-values for a vertical line, then our deltae (Δy/Δx) is infinite. This means as soon as we increment our x-value, our error will jump to infinity, and we cannot recover from this. Secondly, all lines are drawn from left to right. If the first point on the line is to the right of the second point, the values are swapped. Bresenham Algorithm from Wikipedia: function line(x0, x1, y0, y1) boolean steep := abs(y1 - y0) > abs(x1 - x0) if steep then swap(x0, y0) swap(x1, y1) if x0 > x1 then swap(x0, x1) swap(y0, y1) int deltax := x1 - x0 int deltay := abs(y1 - y0) real error := 0 real deltaerr := deltay / deltax int ystep int y := y0 if y0 < y1 then ystep := 1 else ystep := -1 for x from x0 to x1 if steep then plot(y,x) else plot(x,y) error := error + deltaerr

if error 0.5 then y := y + ystep error := error - 1.0 Line Rasterization with Antialiasing using Gupta- Sproull Algorithm For the case when antialiasing is enabled, the linerast module uses a variation of the Gupta- Sproull algorithm to rasterize antialiased lines. The algorithm draws lines that are three pixels wide and defines the color of each pixel depending on how far away the pixel is from the true line. The original algorithm relies on table lookups to convert from the distance to coverage however, we attempted to simplify the process by making pixel coverage a function of the distance from the true line. In order to alter each pixels coverage, we remove the alpha values of the color provided and set it according to the pixel s distance from the true line. In the case where the distance (e) is 0, the alpha value is set to its highest value, 255 (complete opaque). The larger distance gets, the smaller the alpha value becomes, making those pixels which are further from the true line more transparent. The alpha values are set as follows: alpha = 255 - (e << 1) Gupta-Sproull Algorithm Variant from http://courses.engr.illinois.edu: void AALine(int x0, int y0, int x1, int y1) int addr = (y0*640+x0)*4; int dx = x1-x0; int dy = y1-y0; /* By switching to (u,v), we combine all eight octants */ if (abs(dx) > abs(dy))

/* Note: If this were actual C, these integers would be lost * at the closing brace. That's not what I mean to do. Do what * I mean. */ int du = abs(dx); int dv = abs(dy); int u = x1; int v = y1; int uincr = 4; int vincr = 640*4; if (dx < 0) uincr = -uincr; if (dy < 0) vincr = -vincr; else int du = abs(dy); int dv = abs(dx); int u = y1; int v = x1; int uincr = 640*4; int vincr = 4; if (dy < 0) uincr = -uincr; if (dx < 0) vincr = -vincr; int uend = u + 2 * du; int d = (2 * dv) - du; /* Initial value as in Bresenham's */ int incrs = 2 * dv; /* Δd for straight increments */ int incrd = 2 * (dv - du); /* Δd for diagonal increments */ int twovdu = 0; /* Numerator of distance; starts at 0 */ double invd = 1.0 / (2.0*sqrt(du*du + dv*dv)); /* Precomputed inverse denominator */ double invd2du = 2.0 * (du*invd); /* Precomputed constant */ do /* Note: this pseudocode doesn't ensure that the address is * valid, or that it even represents a pixel on the same side of * the screen as the adjacent pixel */ DrawPixelD(addr, twovdu*invd); DrawPixelD(addr + vincr, invd2du - twovdu*invd); DrawPixelD(addr - vincr, invd2du + twovdu*invd); if (d < 0) /* choose straight (u direction) */ twovdu = d + du; d = d + incrs; else /* choose diagonal (u+v direction) */ twovdu = d - du; d = d + incrd; v = v+1; addr = addr + vincr; u = u+1;

addr = addr+uincr; while (u < uend);

Flow through LineRast :

Resources http://en.wikipedia.org/wiki/bresenham%27s_line_algorithm - Bresenham Algorithm http://courses.engr.illinois.edu/ece390/archive/archive-f2000/mp/mp4/anti.html -Gupta Sproull Algorithm