Painter s HSR Algorithm

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

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

CS 543: Computer Graphics. Rasterization

CS Computer Graphics: Hidden Surface Removal

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

Rasterization: Geometric Primitives

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

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

From Ver(ces to Fragments: Rasteriza(on

Topic #1: Rasterization (Scan Conversion)

Computer Graphics. Bing-Yu Chen National Taiwan University The University of Tokyo

Chapter - 2: Geometry and Line Generations

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

CS 498 VR. Lecture 18-4/4/18. go.illinois.edu/vrlect18

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

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

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

1 Introduction to Graphics

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

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

Computer Graphics. Bing-Yu Chen National Taiwan University

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

Line Drawing. Foundations of Computer Graphics Torsten Möller

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

Overview. Pipeline implementation I. Overview. Required Tasks. Preliminaries Clipping. Hidden Surface removal

Pipeline Operations. CS 4620 Lecture 10

Computer Graphics. - Rasterization - Philipp Slusallek

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

CS Rasterization. Junqiao Zhao 赵君峤

Computer Graphics (CS 543) Lecture 10: Soft Shadows (Maps and Volumes), Normal and Bump Mapping

CSE328 Fundamentals of Computer Graphics: Concepts, Theory, Algorithms, and Applications

Chapter 8: Implementation- Clipping and Rasterization

Line Drawing Week 6, Lecture 9

Realtime 3D Computer Graphics Virtual Reality

CSE528 Computer Graphics: Theory, Algorithms, and Applications

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

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

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

Scan Converting Lines

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

CS 563 Advanced Topics in Computer Graphics Lecture 2: Bare-Bones Raytracer. by Emmanuel Agu

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

Einführung in Visual Computing

CS4620/5620: Lecture 14 Pipeline

COMP371 COMPUTER GRAPHICS

Pipeline Operations. CS 4620 Lecture 14

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

Rendering. A simple X program to illustrate rendering

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

CEng 477 Introduction to Computer Graphics Fall 2007

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

Recall: Indexing into Cube Map

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

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

Clipping and Scan Conversion

UNIT -8 IMPLEMENTATION

Topics. From vertices to fragments

Shading Techniques Denbigh Starkey

Computer Graphics. Lecture 9 Hidden Surface Removal. Taku Komura

CS 130 Exam I. Fall 2015

Hidden surface removal. Computer Graphics

Rendering. A simple X program to illustrate rendering

Computer Graphics (CS 543) Lecture 13b Ray Tracing (Part 1) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Computer Graphics CS 543 Lecture 13a Curves, Tesselation/Geometry Shaders & Level of Detail

Efficient Plotting Algorithm

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

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Scan Conversion. Drawing Lines Drawing Circles

Visibility and Occlusion Culling

Visible Surface Detection. (Chapt. 15 in FVD, Chapt. 13 in Hearn & Baker)

The Traditional Graphics Pipeline

Visible-Surface Detection Methods. Chapter? Intro. to Computer Graphics Spring 2008, Y. G. Shin

Clipping. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Rasterization. COMP 575/770 Spring 2013

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

From 3D World to 2D Screen. Hendrik Speleers

VISIBILITY & CULLING. Don t draw what you can t see. Thomas Larsson, Afshin Ameri DVA338, Spring 2018, MDH

CS488 2D Graphics. Luc RENAMBOT

Computing Visibility. Backface Culling for General Visibility. One More Trick with Planes. BSP Trees Ray Casting Depth Buffering Quiz

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Computer Graphics

RASTERIZING POLYGONS IN IMAGE SPACE

The Traditional Graphics Pipeline

Display Technologies: CRTs Raster Displays

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

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

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

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

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

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

Computer Graphics (CS 543) Lecture 8a: Per-Vertex lighting, Shading and Per-Fragment lighting

CSE 167: Introduction to Computer Graphics Lecture #9: Visibility. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2018

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

Werner Purgathofer

The Traditional Graphics Pipeline

RASTERISED RENDERING

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

Transcription:

Painter s HSR Algorithm Render polygons farthest to nearest Similar to painter layers oil paint Viewer sees B behind A Render B then A

Depth Sort Requires sorting polygons (based on depth) O(n log n) complexity to sort n polygon depths Not every polygon is clearly in front or behind other polygons Polygons sorted by distance from COP

Easy Cases Case a: A lies behind all polygons Case b: Polygons overlap in z but not in x or y

Hard Cases cyclic overlap Overlap in (x,y) and z ranges penetration

Back Face Culling Back faces: faces of opaque object that are pointing away from viewer Back face culling: do not draw back faces (saves resources) Back face How to detect back faces?

Back Face Culling Goal: Test if a face F is is backface How? Form vectors View vector, V Normal N to face F N N V Backface test: F is backface if N.V < 0 why??

Back Face Culling: Draw mesh front faces void drawfrontfaces( ) { for(int f = 0;f < numfaces; f++) { if(isbackface(f,.) continue; gldrawarrays(gl_polygon, 0, N); } if N.V < 0

View-Frustum Culling o o Goal: Remove objects outside view frustum Done by 3D clipping algorithm (e.g. Liang-Barsky) Clipped Not Clipped

Ray Tracing Ray tracing is another image space method Ray tracing: Cast a ray from eye through each pixel into world. Ray tracing algorithm figures out: what object seen in direction through given pixel? Topic of grad class

Combined z-buffer and Gouraud Shading (Hill) Can combine shading and hsr through scan line algorithm for(int y = ybott; y <= ytop; y++) // for each scan line { for(each polygon){ find xleft and xright find dleft, dright, and dinc find colorleft and colorright, and colorinc for(int x = xleft, c = colorleft, d = dleft; x <= xright; x++, c+= colorinc, d+= dinc) if(d < d[x][y]) { put c into the pixel at (x, y) d[x][y] = d; // update closest depth } } ytop y4 ys ybott color3 color4 color2 color1 xleft xright

Computer Graphics (CS 4731) Lecture 22: Rasterization: Line Drawing Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI)

Fragments Rasterization Rasterization generates set of fragments Implemented by graphics hardware Rasterization algorithms for primitives (e.g lines, circles, triangles, polygons) Rasterization: Determine Pixels (fragments) each primitive covers

Line drawing algorithm Programmer specifies (x,y) of end pixels Need algorithm to determine pixels on line path 8 7 6 5 4 3 2 1 (3,2) (9,6) Line: (3,2) -> (9,6)? Which intermediate pixels to turn on? 0 1 2 3 4 5 6 7 8 9 10 11 12

Line drawing algorithm Pixel (x,y) values constrained to integer values Computed intermediate values may be floats Rounding may be required. E.g. (10.48, 20.51) rounded to (10, 21) Rounded pixel value is off actual line path (jaggy!!) Sloped lines end up having jaggies Vertical, horizontal lines, no jaggies

Line Drawing Algorithm Slope-intercept line equation y = mx + b Given 2 end points (x0,y0), (x1, y1), how to compute m and b? m dy dx y1 x1 y0 x0 y0 m* x0 b b y0 m* x0 (x1,y1) dy (x0,y0) dx

Line Drawing Algorithm Numerical example of finding slope m: (Ax, Ay) = (23, 41), (Bx, By) = (125, 96) (125,96) dy (23,41) dx m By Bx Ay Ax 96 41 125 23 55 102 0.5392

Digital Differential Analyzer (DDA): Line Drawing Algorithm Consider slope of line, m: m>1 (x1,y1) m=1 (x0,y0) dx dy m<1 o Step through line, starting at (x0,y0) o Case a: (m < 1) x incrementing faster o Step in x=1 increments, compute y (a fraction) and round o Case b: (m > 1) y incrementing faster o Step in y=1 increments, compute x (a fraction) and round

DDA Line Drawing Algorithm (Case a: m < 1) m y y x k1 y y x k k1 k1 m y x k k y k1 1 y (x1,y1) k x = x0 y = y0 Illuminate pixel (x, round(y)) x = x + 1 y = y + m Illuminate pixel (x, round(y)) x = x + 1 y = y + m Illuminate pixel (x, round(y)) Until x == x1 (x0, y0) Example, if first end point is (0,0) Example, if m = 0.2 Step 1: x = 1, y = 0.2 => shade (1,0) Step 2: x = 2, y = 0.4 => shade (2, 0) Step 3: x= 3, y = 0.6 => shade (3, 1) etc

DDA Line Drawing Algorithm (Case b: m > 1) m y x y x k 1 k 1 y x k k x k 1 1 x k x = x0 y = y0 Illuminate pixel (round(x), y) x k 1 x k 1 m y = y + 1 x = x + 1/m Illuminate pixel (round(x), y) (x1,y1) y = y + 1 x = x + 1 /m Illuminate pixel (round(x), y) Until y == y1 (x0,y0) Example, if first end point is (0,0) if 1/m = 0.2 Step 1: y = 1, x = 0.2 => shade (0,1) Step 2: y = 2, x = 0.4 => shade (0, 2) Step 3: y= 3, x = 0.6 => shade (1, 3) etc

DDA Line Drawing Algorithm Pseudocode compute m; if m < 1: { float y = y0; // initial value for(int x = x0; x <= x1; x++, y += m) setpixel(x, round(y)); } else // m > 1 { float x = x0; // initial value for(int y = y0; y <= y1; y++, x += 1/m) setpixel(round(x), y); } Note: setpixel(x, y) writes current color into pixel in column x and row y in frame buffer

Line Drawing Algorithm Drawbacks DDA is the simplest line drawing algorithm Not very efficient Round operation is expensive Optimized algorithms typically used. Integer DDA E.g.Bresenham algorithm Bresenham algorithm Incremental algorithm: current value uses previous value Integers only: avoid floating point arithmetic Several versions of algorithm: we ll describe midpoint version of algorithm

References Angel and Shreiner, Interactive Computer Graphics, 6 th edition Hill and Kelley, Computer Graphics using OpenGL, 3 rd edition, Chapter 9