Realtime 3D Computer Graphics Virtual Reality

Similar documents
Topics. From vertices to fragments

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

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

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

From Vertices To Fragments-1

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

Clipping and Scan Conversion

Pipeline implementation II

Rasterization, Depth Sorting and Culling

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

3D Rendering Pipeline (for direct illumination)

Chapter 8: Implementation- Clipping and Rasterization

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

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

Introduction to Computer Graphics 5. Clipping

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

CS4620/5620: Lecture 14 Pipeline

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

COMP371 COMPUTER GRAPHICS

Rasterization. COMP 575/770 Spring 2013

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

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

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

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

Line Drawing. Foundations of Computer Graphics Torsten Möller

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

Examples. Clipping. The Rendering Pipeline. View Frustum. Normalization. How it is done. Types of operations. Removing what is not seen on the screen

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

From Ver(ces to Fragments: Rasteriza(on

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

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Clipping. Concepts, Algorithms for line clipping. 1 of 16. Andries van Dam. Clipping - 10/12/17

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

Computer Graphics. - Rasterization - Philipp Slusallek

Last class. A vertex (w x, w y, w z, w) - clipping is in the - windowing and viewport normalized view volume if: - scan conversion/ rasterization

Computer Graphics. - Clipping - Philipp Slusallek & Stefan Lemme

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

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

The Traditional Graphics Pipeline

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

CHAPTER 1 Graphics Systems and Models 3

Topic #1: Rasterization (Scan Conversion)

CS 130. Scan Conversion. Raster Graphics

The Traditional Graphics Pipeline

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

CSCI 4620/8626. Computer Graphics Clipping Algorithms (Chapter 8-5 )

CS602 Midterm Subjective Solved with Reference By WELL WISHER (Aqua Leo)

Rasterization: Geometric Primitives

Rasterization. CS4620 Lecture 13

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

Einführung in Visual Computing

Graphics (Output) Primitives. Chapters 3 & 4

The Traditional Graphics Pipeline

From 3D World to 2D Screen. Hendrik Speleers

Computer Graphics and GPGPU Programming

Rasterization Overview

Painter s HSR Algorithm

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

EF432. Introduction to spagetti and meatballs

RASTERIZING POLYGONS IN IMAGE SPACE

1 Introduction to Graphics

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

This library uses only GL functions but contains code for creating common objects and simplifying viewing.

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

CSE 167: Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Hidden Surface Removal

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

CSCI 4620/8626. Coordinate Reference Frames

UNIT -8 IMPLEMENTATION

Drawing Fast The Graphics Pipeline

CS Rasterization. Junqiao Zhao 赵君峤

Pipeline and Rasterization. COMP770 Fall 2011

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

Two-Dimensional Viewing. Chapter 6

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

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

Sung-Eui Yoon ( 윤성의 )

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

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

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

Scan Conversion. Drawing Lines Drawing Circles

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

Clipping & Culling. Lecture 11 Spring Trivial Rejection Outcode Clipping Plane-at-a-time Clipping Backface Culling

CHAPTER 2 REVIEW COORDINATE GEOMETRY MATH Warm-Up: See Solved Homework questions. 2.2 Cartesian coordinate system

Lecture 7 of 41. Viewing 4 of 4: Culling and Clipping Lab 1b: Flash Intro

QUESTION BANK 10CS65 : COMPUTER GRAPHICS AND VISUALIZATION

Institutionen för systemteknik

CS 543: Computer Graphics. Rasterization

EF432. Introduction to spagetti and meatballs

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

CS 130 Final. Fall 2015

Graphics and Interaction Rendering pipeline & object modelling

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

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

Page 1. Area-Subdivision Algorithms z-buffer Algorithm List Priority Algorithms BSP (Binary Space Partitioning Tree) Scan-line Algorithms

Computer Graphics Geometry and Transform

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

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

Clipping Algorithms; 8-5. Computer Graphics. Spring CS4815

Transcription:

Realtime 3D Computer Graphics Virtual Reality From Vertices to Fragments Overview Overall goal recapitulation: Input: World description, e.g., set of vertices and states for objects, attributes, camera, Output: Array of colored pixels in framebuffer. After transformation and projection (with possible normalization) we have to 1. decide visibility of objects: which objects will be seen due to frustum and output window: Culling: in object or world space Clipping: in canonical view or image space which objects will be in front of others (depth-sorting): Occlusion culling, depth sort: in object or world space z-buffer algorithm, w-buffer algorithm: in canonical view or image space 2. draw the remaining primitives; map from continuous space to discrete space Scan conversion, rasterization Two different possibilities: for(each_object) render(object); //see right for(each_pixel) assign_a_color(pixel);

Tasks Modelling Geometry processing Which objects appear on the screen Assign color shades to vertices Primitive assembly and clipping Perspective division Rasterization Maps from NDC* to window coords (see right): Lines: Which fragments should be used to approximate Polygons: Which pixels are inside Assign color to fragments Fragment processing Combine with image path (texturing) Blending Anti-aliasing x = x v y = y v z = z v v min v min v min x + 1.0 + 2.0 y + 1.0 + y 2.0 z + 1.0 + zv 2.0 ( x x ) v max v min ( y ) v max v min ( z ) max v min *NDC: All vertices lie in the cube with w a w, a { x, y, z} Realtime 3D Computer Graphics Virtual Reality Clipping

Clipping 2D against clipping window 3D against clipping volume Easy for line segments/polygons Hard for curves and text Convert to lines and polygons first Clipping 2D Line Segments: Brute force approach: compute intersections with all sides of clipping window Inefficient: one division per intersection Line processing Lines: Most common 2D primitive - done 100s or 1000s of times each frame, even 3D wireframes are eventually 2D lines! Lines are compatible with vector displays but nowadays most displays are raster displays. Any render stage before viz might need discretization. Optimized algorithms contain numerous tricks/techniques that help in designing more advanced algorithms for line processing. Polynomial Evaluator Per Vertex Operations & Primitive Assembly in OpenGL CPU Display List Rasterization Per Fragment Operations Frame Buffer Pixel Operations Texture Memory

Line Requirements Must compute integer coordinates of pixels which lie on or near a line or circle. Pixel level algorithms are invoked hundreds or thousands of times when an image is created or modified must be fast! Lines must create visually satisfactory images. Lines should appear straight Lines should terminate accurately Lines should have constant density Line algorithm should always be defined. Basic Math Review Point-slope formula for a Line: Given two points (x 1,y 1 ), (x 2, y 2 ) Consider a third point on the line: p = (x,y) Slope = (y 2 -y 1 )/(x 2 -x 1 ) = (y - y 1 )/(x - x 1 ) Solving For y y = [(y 2 -y 1 )/(x 2 -x 1 )]*(x-x 1 )+ y 1 or, plug in the point (0, b) to get the Slope-intercept form: y = mx + b Length of line segment between p 1 and p 2 : 2 2 l = ( x2 x1) + ( y2 y1) Midpoint of a line segment between p 1 and p 3 : p 2 = ( (x 1 +x 3 )/2, (y 1 +y 3 )/2 ) Two lines are perpendicular iff 1) m 1 = -1/m 2 2) Cosine of the angle between them is 0. Parametric form Given points p 1 = (x 1, y 1 ) and p 2 = (x 2, y 2 ) 6 5 4 3 2 x = x 1 + α(x 2 -x 1 ), y = y 1 + α(y 2 -y 1 ) p(α)=(1- α)p 1 + αp 2 α is called the parameter. When α = 0 we get (x 1,y 1 ), α = 1 we get (x 2,y 2 ) As 0 < α < 1 we get all the other points on the line segment between (x 1,y 1 ) and (x 2,y 2 ). Cartesian Coordinate System 1 p 1 = (x 1,y 1 ) p2 = (x 2,y 2 ) 1 2 3 4 5 6 slope = rise run = y 2 -y 1 x 2 -x 1 p = (x,y)

Cohen-Sutherland Algorithm Idea: Eliminate as many cases as possible without computing intersections Start with four lines that determine the sides of the clipping window Assign binary opcodes for the 9 regions for fast processing: b 0 b 1 b 2 b 3 Computation of outcode requires at most 4 subtractions: b 0 = 1 if y > y max, 0 otherwise b 1 = 1 if y < y min, 0 otherwise b 2 = 1 if x > x max, 0 otherwise b 3 = 1 if x < x min, 0 otherwise GH = [0001,1000] IJ = [0001,1000] AB = [0000,0000] CD = [0000,0010] EF = [0010,0010] Cohen-Sutherland Algorithm Compute opcodes for each line segment s. Given: line segment by two opcodes o 1 (s), o 2 (s). procedure cs-clip(segment s){ if (o1(s) OR o2(s) = 0) raterize(s); else if (o1(s) AND o2(s)!= 0) reject(s); else cs-clip( clipseg (s) ); } function clipseg (s){ // Line can be determined by opcode line l = find_line_by_opcode (s); return shortenseg (s,l); } GH = [0001,1000] IJ = [0001,1000] AB = [0000,0000] CD = [0000,0010] EF = [0010,0010]

Cohen-Sutherland Efficiency: Often, clipping window is small relative to the size of the entire data base Most segments are outside one or more window sides and can be eliminated based on their outcodes Inefficiency when code has to be reexecuted for line segments that must be shortened in more than one step 3D-extension Use 6-bit outcodes: When needed, clip line segment against planes: Liang-Barsky Clipping Consider the parametric form of a line segment p 2 p(α) = (1-α)p 1 + αp 2 1 α 0 p 1 Distinguish between cases based on ordering of the values of α where the line determined by the line segment crosses the lines that determine the window In (a): 1 > α 4 > α 3 > α 2 > α 1 > 0 Intersect right, top, left, bottom: shorten In (b): 1 > α 4 > α 2 > α 3 > α 1 > 0 Intersect right, left, top, bottom: reject

Liang-Barsky Clipping 1. Avoid computing intersection as long as possible. 2. Rejection can be done on ordering. ymax y1 3. Using parametric form, it follows: α = (similar for the other 3 sides) y2 y1 This can be rewritten as: α = ( y2 y1) = α y = ymax y1 = y Restate decisions in terms of ymax, y avoid floating-point execution during decision until intersection is actually required. Advantages: Can accept/reject as easily as with Cohen- Sutherland Using values of α, we do not have to use algorithm recursively as with C- S Extends to 3D max Clipping and Normalization General clipping in 3D requires intersection of line segments against arbitrary plane (Example: oblique view): n ( po a = n ( p 2 p ) 1 p ) 1 Normalization is part of viewing (pre clipping)but after normalization, we clip against sides of right parallelepiped Typical intersection calculation now requires only a floating point subtraction, e.g. is x > xmax? top view before normalization after normalization

Polygon Clipping Not as simple as line segment clipping Clipping a line segment yields at most one line segment Clipping a polygon can yield multiple polygons However, clipping a convex polygon can yield at most one other polygon One strategy is to replace nonconvex (concave) polygons with a set of triangular polygons (a tessellation) Also makes fill easier (e.g., tessellation code available in GLU library) Clipping pipeline Consider line segment clipping as a process that takes in two vertices and produces either no vertices or the vertices of a clipped line segment: Clipping against window sides is independent of other sides Place independent clippers in a pipeline:

Pipeline Clipping of Polygons Three dimensions: add front and back clippers Strategy used in SGI Geometry Engine Small increase in latency Clipping Bounding Boxes Rather than doing clipping on a complex polygon, we can use an axis-aligned bounding box or extent Smallest rectangle aligned with axes that encloses the polygon Simple to compute: max and min of x and y Can usually determine accept/reject based only on bounding box reject requires detailed clipping accept

Realtime 3D Computer Graphics Virtual Reality Rasterization Scan conversion Rasterization Rasterization (scan conversion) Determine which pixels that are inside primitive specified by a set of vertices Produces a set of fragments 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

Scan Conversion of Line Segments Start with segment in window coordinates with integer values for endpoints Assume implementation has a write_pixel function y = mx + h Digital Differential Analyzer DDA was a mechanical device for numerical solution of differential equations Line y=mx+ h satisfies differential equation dy/dx = m = y/ x = y 2 -y 1 /x 2 -x 1 Along scan line x = 1 For(x=x1; x<=x2,ix++) { y+=m; write_pixel(x, round(y), line_color) } y m = x Problem DDA = for each x plot pixel at closest y Problems for steep lines Solution: Using symmetry Use for 1 m 0 For m > 1, swap role of x and y For each y, plot closest x

Simple DDA Line Algorithm void DDA(int X1,Y1,X2,Y2) { int Length, I; float X,Y,Xinc,Yinc; Length = ABS(X2 - X1); if (ABS(Y2 - Y1) > Length) Length = ABS(Y2-Y1); Xinc = (X2 - X1)/Length; Yinc = (Y2 - Y1)/Length; } X = X1; Y = Y1; while(x<x2){ write_pixel(round(x),round(y); line_color); X = X + Xinc; Y = Y + Yinc; } DDA creates good lines but it is too time consuming due to the round r function and long operations on real values. DDA Example Compute which pixels should be turned on to represent the line from (6,9) to (11,12). Length =? Xinc =? Yinc =? 13 12 11 10 9 6 7 8 9 10 11 12 13

DDA Example Line from (6,9) to (11,12). Length := Max of (ABS(11-6), ABS(12-9)) = 5 Xinc := 1 Yinc := 0.6 Values computed are: (6, 9) (7, 9.6) (8, 10.2) (9, 10.8) (10, 11.4) (11, 12) 13 12 11 10 9 6 7 8 9 10 11 12 13 Bresenham s Algorithm DDA requires one floating point addition per step We can eliminate all fp through Bresenham s algorithm Consider only 1 m 0 Other cases by symmetry Assume pixel centers are at half integers If we start at a pixel that has been written, there are only two candidates for the next pixel to be written into the frame buffer

Idea 1 m 0 candidates last pixel Note that line could have passed through any part of this pixel Decision variable: d = x(a-b) d is an integer d < 0 use upper pixel d > 0 use lower pixel