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

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

Realtime 3D Computer Graphics Virtual Reality

Hidden surface removal. Computer Graphics

9. Visible-Surface Detection Methods

Chapter 8: Implementation- Clipping and Rasterization

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

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

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

Topic #1: Rasterization (Scan Conversion)

Computer Graphics. Lecture 9 Hidden Surface Removal. Taku Komura

CS 325 Computer Graphics

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

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Visibility: Z Buffering

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

CS 543: Computer Graphics. Rasterization

Intro to Modeling Modeling in 3D

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

COMP371 COMPUTER GRAPHICS

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

Hidden Surface Removal

CSE528 Computer Graphics: Theory, Algorithms, and Applications

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

4.5 VISIBLE SURFACE DETECTION METHODES

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

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

8. Hidden Surface Elimination

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Einführung in Visual Computing

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

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

Graphics (Output) Primitives. Chapters 3 & 4

CEng 477 Introduction to Computer Graphics Fall 2007

1 Introduction to Graphics

Werner Purgathofer

The Traditional Graphics Pipeline

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

Ray tracing. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 3/19/07 1

Visible Surface Detection Methods

Scan Conversion. Drawing Lines Drawing Circles

RASTERIZING POLYGONS IN IMAGE SPACE

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

Unit 2 Output Primitives and their Attributes

(Refer Slide Time 05:03 min)

Computer Graphics. Bing-Yu Chen National Taiwan University

Overview of Computer Graphics

CS559: Computer Graphics. Lecture 12: Antialiasing & Visibility Li Zhang Spring 2008

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

The Traditional Graphics Pipeline

Class of Algorithms. Visible Surface Determination. Back Face Culling Test. Back Face Culling: Object Space v. Back Face Culling: Object Space.

Identifying those parts of a scene that are visible from a chosen viewing position, and only process (scan convert) those parts

Computer Graphics - Week 6

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

The Traditional Graphics Pipeline

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination

CS 130. Scan Conversion. Raster Graphics

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

From Ver(ces to Fragments: Rasteriza(on

UNIT 2 GRAPHIC PRIMITIVES

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

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

CSC Computer Graphics

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

Computer Graphics. - Rasterization - Philipp Slusallek

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

Introduction Rasterization Z-buffering Shading. Graphics 2012/2013, 4th quarter. Lecture 09: graphics pipeline (rasterization and shading)

The Graphics Pipeline. Interactive Computer Graphics. The Graphics Pipeline. The Graphics Pipeline. The Graphics Pipeline: Clipping

8. Hidden Surface Elimination

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination (Total: 100 marks)

Sung-Eui Yoon ( 윤성의 )

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

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

Rasterization: Geometric Primitives

Lecture 4. Viewing, Projection and Viewport Transformations

Two basic types: image-precision and object-precision. Image-precision For each pixel, determine which object is visable Requires np operations

RASTERISED RENDERING

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

Introduction to Visualization and Computer Graphics

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

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

CS 130 Exam I. Fall 2015

Painter s HSR Algorithm

Computer Graphics Lecture Notes

Computer Graphics. Rendering. by Brian Wyvill University of Calgary. cpsc/enel P 1

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

Topic 12: Texture Mapping. Motivation Sources of texture Texture coordinates Bump mapping, mip-mapping & env mapping

Hidden Surfaces II. Week 9, Mon Mar 15

Rasterization, Depth Sorting and Culling

Pipeline Operations. CS 4620 Lecture 10

Topic 11: Texture Mapping 11/13/2017. Texture sources: Solid textures. Texture sources: Synthesized

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

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

Topics. From vertices to fragments

Graphics and Interaction Rendering pipeline & object modelling

Computer Graphics II

EF432. Introduction to spagetti and meatballs

2D Graphics Primitives II. Additional issues in scan converting lines. 1)Endpoint order. Want algorithms to draw the same pixels for each line

From Vertices To Fragments-1

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

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

Transcription:

Rendering Rasterizing Lines and Polygons Hidden Surface Remove Multi-pass Rendering with Accumulation Buffers Basic Math Review Slope-Intercept Formula For Lines Given a third point on the line: P = (X,Y) Slope = (Y - Y1)/(X - X1) = (Y2 - Y1)/(X2 - X1) Solve for Y Y = [(Y2-Y1)/(X2-X1)]X + [-(Y2-Y1)/(X2-X1)]X1 + Y1 or Y = mx + b 6 5 4 3 2 1 P = (X,Y) P2 = (X2,Y2) P1 = (X1,Y1) 1 2 3 4 5 6 RISE Y2-Y1 SLOPE = = RUN X2-X1 CS4451 Fall 2002 1

Basic Math Review: Other Helpful Formulas Length of line segment between P1 and P2: L = [ (X2-X1)2 + (Y2-Y1)2 ] Midpoint of a line segment between P1 and P3: P2 = ( (X1+X3)/2, (Y1+Y3)/2 ) Two lines are perpendicular iff: M1 = -1/M2 Basic Math Review: Parametric Form of a 2D Line Given points P1 = (X1, Y1) and P2 = (X2, Y2) X = X1 + t(x2-x1) Y = Y1 + t(y2-y1) When t = 0 we get (X1,Y1) t = 1 we get (X2,Y2) As 0 < t < 1, we get all points between (X1,Y1) and (X2,Y2) CS4451 Fall 2002 2

Basic Line Algorithm Must: 1. Compute integer coordinates of pixels which lie on or near a line. 2. Be efficient. 3. Create visually satisfactory images. Lines should appear straight Lines should terminate accurately Lines should have constant density Line density should be independent of line length and angle 4. Always be defined. Simple DDA Line Algorithm {Based on the parametric equation of a line} Procedure DDA(X1,Y1,X2,Y2 :Integer); Var Length, I :Integer; X,Y,Xinc,Yinc :Real; Begin Length := ABS(X2 - X1); If ABS(Y2 - Y1) > Length Then Length := ABS(Y2-Y1); Xinc := (X2 - X1)/Length; Yinc := (Y2 - Y1)/Length; X := X1; Y := Y1; For I := 0 To Length Do Begin Plot(Round(X), Round(Y)); X := X + Xinc; Y := Y + Yinc End {For} End; {DDA} Creates good lines, but problems... CS4451 Fall 2002 3

DDA Example Render the 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) 1 3 1 2 1 1 1 0 9 6 7 8 9 1 0 1 1 1 2 1 3 Fast Lines Using The Midpoint Method Assumptions: line between points (0,0) and (a,b) with slope 0 m 1 i.e. lies in first octant: +y -x +x Recall: y = mx + B (m is the slope, B is the y-intercept) m = b/a and B = 0 y = (b/a)x + 0 f(x,y) = bx - ay = 0 -y CS4451 Fall 2002 4

Fast Lines (cont.) Two choices for next pixel (T or S), want the pixel closer to line! Assume distance between pixel centers is 1 Midpoint is (xi + 1,yi + 1/2) T = (x i + 1, y i + 1) (x i + 1, y i + 1/2 + e) e (x i +1,y i + 1/2) P = (x i, y i ) S = (x i + 1, y i ) e is difference between midpoint and where line crosses between S and T If e is positive, line crosses above the midpoint and is closer to T If e is negative, line crosses below the midpoint and is closer to S don t need exact value of e Fast Lines: The Decision Variable f(xi+1,yi+ 1/2 + e) = b(xi+1) - a(yi+ 1/2 + e) = b(xi + 1) - a(yi + 1/2) -ae = f(xi + 1, yi + 1/2) - ae = 0 Let di = f(xi + 1, yi + 1/2) = ae; di is known as the decision variable. Since a 0, di has the same sign as e. Algorithm: If di 0 then Choose T = (xi + 1, yi + 1) as next point di+1 = f(xi+1 + 1, yi+1 + 1/2) = f(xi +1+1, yi +1+1/2) = b(xi +1+1) - a(yi +1+1/2) = f(xi + 1, yi + 1/2) + b - a = di + b - a else Choose S = (xi + 1, yi) as next point di+1 = f(xi+1 + 1, yi+1 + 1/2) = f(xi +1+1,yi +1/2) = b(xi +1+1) - a(yi +1/2) = f(xi + 1, yi + 1/2) + b = di + b CS4451 Fall 2002 5

Fast Line Algorithm Calculate initial value for d 0 directly from f(x,y) at (0,0): d 0 = f(0 + 1, 0 + 1/2) = b(1) - a(1/2) = b - a/2 Algorithm for a line from (0,0) to (a,b) in the first octant is: x := 0; y := 0; d := b - a/2; For i := 0 to a do Begin Plot(x,y); End Else Begin End x := x + 1; d := d + b If d 0 Then Begin x := x + 1; y := y + 1; d := d + b - a End The only non-integer value is a/2. How can we get rid of it? Bresenham s Line Algorithm Generalize for lines beginning at points other than (0,0) Begin {Bresenham for lines with slope between 0 and 1} a := ABS(xend - xstart); b := ABS(yend - ystart); d := 2*b - a; Incr1 := 2*(b-a); For I := 0 to a Do Begin Plot(x,y); Incr2 := 2*b; x := x + 1; If xstart > xend Then Begin If d 0 Then Begin x := xend; y := y + 1; y := yend d := d + incr1 End End Else Begin Else x := xstart; d := d + incr2 y := ystart End {For Loop} End; End; {Bresenham} CS4451 Fall 2002 6

Optimizations Detect cycles in the decision variable correspond to a repeated pattern of pixel choices Save pattern, reuse if a cycle is detected 1 6 1 5 1 4 1 3 1 2 1 1 1 0 9 6 7 8 9 1 0 1 1 1 2 13 14 15 16 17 di= 2-6 6-2 10 2-6 6-2 10 Polygons Polygon: many-sided planar figure of vertices and edges Vertices: represented by points (x,y) Edges: represented as line segments between two points, (x i,y i ) and (x i+1,y i+1 ) (x1,y1) E1 (x2,y2) P = { (x i, y i ) } i=1,n E3 E2 (x3,y3) CS4451 Fall 2002 7

Convex and Concave Polygons Convex Polygon: Given P1, P2 inside polygon All P = up1 + (1-u)P2, u in [0,1] is inside polygon Concave = not convex! How do we know a point is "inside" a polygon? P is inside a polygon iff a scanline intersects the polygon edges an odd number of times moving from P in either direction 1 2 3 4 Problem when scan line crosses a vertex: Does the vertex count as two points? Or should it count as one point? CS4451 Fall 2002 8

Max-Min Test Vertex = local max or min Count it twice, else count it once. or or Count twice Count once Filling Polygons Fill polygon 1 scanline at a time Set pixels inside polygon on each scanline to the appropriate value Look only for those pixels at which changes occur CS4451 Fall 2002 9

Scan-Line Algorithm For each scan-line: 1. Find intersections of scan line with all edges 2. Sort intersections by increasing x-coordinate 3. Fill all pixels between pairs of intersections 8 For scan-line number 7 the sorted list of x-coordinates is (1,3,7,9) 6 4 2 How do we know a point is "inside" a polygon? Possible Problems Horizontal edges Ignore Vertices If local max or min, count twice, else count once (Implemented by shortening one edge by one pixel) Calculating intersections is slow CS4451 Fall 2002 10

Edge Coherence Observations: Not all edges intersect each scanline If edge intersected in scanline i, will probably be intersected by scanline i+l Consider scanline s, the line y = s s = mx s + b x s = (s-b)/m For scanline s + 1, x s +1 = (s+1 - b)/m = x s + 1/m Processing Polygons Polygon edges sorted according to minimum Y Scan lines processed in increasing (decreasing) Y order When current scan line reaches edge, it becomes active When current scan line passes edge, it becomes inactive Active Edges Not yet active edges Finished edge Ignored horizontal edge Active edges sorted according to increasing X Fill the scan line between alternating edge intersections CS4451 Fall 2002 11

Fill Patterns: Simple textures Defined as a 0-based, m x n array Pixel (x,y) is assigned the value found in: pattern((x mod m), (y mod n)) Pattern Pattern filled polygon Halftoning Mimic greyscale on bitmapped displays Tradeoff resolution (addressability) for range of intensities Patterns should be designed to avoid being noticed CS4451 Fall 2002 12

Dithering Another way to mimic grey on bit-mapped displays Ordered dither: turn pixel on or off at (x,y) based on desired intensity I(x,y) at that point an (n by n) dither matrix Dn Each integer 0 to n2-1 appears once in the matrix Dn e.g. D4 0 8 2 10 12 4 14 6 3 11 1 9 15 7 13 5 let i = x MOD 4, j = y MOD 4 if I(x,y) > D4(i, j) then (x,y) is turned on; otherwise it is not Antialiasing Aliasing caused by finite addressability of CRT Approximation of lines with discrete points can result in a staircase appearance or "Jaggies" Desired line Aliased rendering of the line CS4451 Fall 2002 13

Antialiasing - Solutions Aliasing can be smoothed out by using higher addressability. Problem: addressability usually fixed Solution: intensity is variable, so use it two adjacent pixels can give impression of point part way between perceived location of point dependent upon ratio of intensities An antialiased line has virtual pixels located at the proper addresses Antialiased Bresenham Lines Use the distance (e = di/a) value to determine pixel intensities. Three possible cases for the Bresenham algorithm: e > 0 0 > e > -0.5 e < -0.5 e A B C A = 0.5 + e B = 1 - abs(e+0.5) C = 0 What about color? e A B C A = 0.5 + e B = 1 - abs(e+0.5) C = 0 A B e C A = 0 B = 1 - abs(e+0.5) C = -0.5 - e CS4451 Fall 2002 14

Antialiasing Polygons Polygon edges suffer from aliasing as lines Similar method can be used on the scan line fill X i X i+1 X j X j+1 If odd intersection between two pixels Xi < X < Xi+1 pixel Xi is assigned the intensity (Xi+1 -X) pixel Xi+1 is assigned intensity 1.0 At even intersection, reverse is true Hidden Surface Elimination (Visible Surface Determination) CS4451 Fall 2002 15

Approaches 1. Back-Face Removal 2. z-buffer (Depth-Buffer) 3. Depth-Sort 4. BSP-Tree 5. Scanline Algorithm (see book) 1) Back-Face Removal (Culling) Remove unseen polygons from convex, closed polyhedron (Cube, Sphere) Does not completely solve problem One polyhedron may obscure another CS4451 Fall 2002 16

P5 P8 Back Face Algorithm P1 P6 P4 P7 Idea. For each polygon: If surface normal faces toward eye, keep If surface normal faces away from eye, toss P2 P3 Adopt convention for vertex order ie. assume counter-clockwise w.r.t. front (P1, P2, P3, P4) Compute N Back Face Algorithm Look at surface normal In World Coordinates If A xe + B ye + C ze + D < 0 The polygon is a backface. After Normalizing/Perspective Projection? What is (xe, ye, ze)? CS4451 Fall 2002 17

2) z-buffer (Depth-Buffer) Look at each pixel Pixel shows closest object in world We have all info to compute z(x,y) Which Z? Recall canonical view volumes: Y axis +1 Front Clipping Plane y=-z Back Clipping Plane z=-1-1 -Z +1 Y axis -1 -Z -1 y=z -1 CS4451 Fall 2002 18

Computing Pixel z-values Perspective projection gives z-values for vertices of polygons. To find the z- values for the boundary and interior pixels you do a linear interpolation (x1,y1,z1) (x3,y3,z3) (x2,y2,z2) Vertically: zi+1 = zi + zv, zv = (z1-z3)/(y1-y3) Horizontally: zi+1 = zi + zh, zh = (z1-z3)/(x1-x3) z-buffer Algorithm Initialize: Each z-buffer location Max z value Each frame buffer loc. background color For each polygon: Compute z(x,y), depth at the pixel (x,y) If z(x,y) < z buffer value at pixel (x,y) then z buffer(x,y) z(x,y) pixel(x,y) color of polygon at (x,y) CS4451 Fall 2002 19

z-buffer Advantages Linear performance Polygons may be processed in any order Hardware implementation very fast Disadvantages Lots of memory (nowadays so what?) Problems with linear interpolation under perspective Modifications needed for antialiasing, transparency, translucency effects 3) Depth Sort Sort polygons by distance Paint in back-to-front order Problems? CS4451 Fall 2002 20

4) Binary Space Paritition (BSP) Trees Easy way to sort the polygons relative to eye-point To Build a BSP Tree 1. Choose a polygon, T, and compute the equation of the plane it defines. 2. Test all the vertices of all the other polygons to determine if they are in front of, behind, or in the same plane as T. If the plane intersects a polygon, divide the polygon at the plane. 3. Polygons are placed into a binary search tree with T as the root. 4. Call the procedure recursively on the left and right subtree. BSP Tree Example F +Z D C A E B +X -X CS4451 Fall 2002 21

Traversing the BSP-Tree Traverse the BSP tree such that the branch decended first is the side that is away from the eyepoint. This can be determined by substituting the eye point into the plane equation for the polygon at the root. When there is no first branch to descend, or that branch has been completed then render the polygon at this node. After the current node's polygon has been rendered, descend the branch that is closer to the eyepoint. Traversing the BSP Tree Example F2 +Z D EYE 1 B A C F1 C A E2 E1 F1 E2 D F2 E1 B +X -X EYE 2 CS4451 Fall 2002 22

Splitting Triangles If all our polygons are triangles when we always divide a triangle into more triangles when it is intersected by the plane. Possible for the number of triangles to increase exponentially but in practice it is found that the increase may be as small as two fold A heuristic to help minimize the number of fractures is to enter the triangles into the tree in order from largest to smallest. Accumulation Buffers Multi-pass rendering For anitaliasing, depth of field, soft shadows, motion blur Render scene multiple times, different params Viewpoint (antialiasing, depth of field) Time (motion blur) Light position (soft shadows) Accumulate rendered images into accum buffer Using ops such as + and * to add with weight CS4451 Fall 2002 23