From Vertices to Fragments II Software College, Shandong University Instructor: Zhou Yuanfeng

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
Advertisements

Visible-Surface Detection(identification)
From Vertices to Fragments
Collisions and Intersections When objects move, test for collision. When projecting surfaces, check for intersections. (Many slides adapted from Amitabh.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
03/12/02 (c) 2002 University of Wisconsin, CS559 Last Time Some Visibility (Hidden Surface Removal) algorithms –Painter’s Draw in some order Things drawn.
Graphics Graphics Korea University cgvr.korea.ac.kr 1 Hidden Surface Removal 고려대학교 컴퓨터 그래픽스 연구실.
Part I: Basics of Computer Graphics
Different types of Polygons Simple Convex Simple Concave Non-simple : self-intersecting With holes ConvexConcaveSelf-intersecting.
Implementation Dr. Amy Zhang. Reading 2  Hill, Chapters  Hill, Chapter 10.
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
1 Dr. Scott Schaefer Hidden Surfaces. 2/62 Hidden Surfaces.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Implementation III Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Hidden Surface Elimination Wen-Chieh (Steve) Lin Institute of Multimedia Engineering I-Chen Lin’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals.
1 CSCE 441: Computer Graphics Hidden Surface Removal (Cont.) Jinxiang Chai.
1 Clipping and Hidden Surfaces CS-184: Computer Graphics Prof. James O’Brien.
Vertices and Fragments III Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
Spatial Data Structure: Quadtree, Octree,and BSP tree Mengxia Zhu Fall 2007.
Hidden Surface Removal
Graphics Pipeline Hidden Surfaces CMSC 435/634. Visibility We can convert simple primitives to pixels Which primitives (or parts of primitives) should.
Graphics Pipeline Hidden Surface CMSC 435/634. Visibility We can convert simple primitives to pixels/fragments How do we know which primitives (or which.
10/29/02 (c) 2002 University of Wisconsin, CS559 Today Hidden Surface Removal Exact Visibility.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Chapter 7: From Vertices to Fragments Ed Angel Professor of Computer Science, Electrical.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
From Vertices to Fragments Chapter 7. Part I Objectives Introduce basic implementation strategies Introduce basic implementation strategies Clipping Clipping.
CSC418 Computer Graphics n BSP tree n Z-Buffer n A-buffer n Scanline.
1Computer Graphics Implementation III Lecture 17 John Shearer Culture Lab – space 2
Introduction to Computer Graphics with WebGL
CS 480/680 Computer Graphics Implementation III Dr. Frederick C Harris, Jr. Fall 2011.
Visible-Surface Detection Jehee Lee Seoul National University.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Week 3 Lecture 1: Implementation Based on Interactive Computer Graphics (Angel) - Chapter.
Hidden Surface Removal 1.  Suppose that we have the polyhedron which has 3 totally visible surfaces, 4 totally invisible/hidden surfaces, and 1 partially.
CS-378: Game Technology Lecture #2.2: Clipping and Hidden Surfaces Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney,
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1Computer Graphics Implementation II Lecture 16 John Shearer Culture Lab – space 2
Implementation II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann.
Hidden Surface Removal
Implementation II.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Where We Stand At this point we know how to: –Convert points from local to window coordinates –Clip polygons and lines to the view volume –Determine which.
Computer Graphics Filling. Filling Polygons So we can figure out how to draw lines and circles How do we go about drawing polygons? We use an incremental.
Computer Graphics I, Fall 2010 Implementation II.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
01/28/09Dinesh Manocha, COMP770 Visibility Computations Visible Surface Determination Visibility Culling.
Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 5 Hidden Surface Removal and Rasterization Taku Komura.
COMPUTER GRAPHICS CS 482 – FALL 2015 NOVEMBER 10, 2015 VISIBILITY CULLING HIDDEN SURFACES ANTIALIASING HALFTONING.
Computer Graphics CC416 Week 14 Filling Algorithms.
Computer Graphics I, Fall 2010 Scan conversion algorithms.
Computer Graphics Implementation II
Computer Graphics Filling.
Solid Area Scan Conversion or Visible Surface Detection
Introduction to Polygons
University of New Mexico
Implementation III.
Introduction to Computer Graphics with WebGL
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
Implementation II Ed Angel Professor Emeritus of Computer Science
Course code: 10CS65 | Computer Graphics and Visualization
Rasterization and Antialiasing
Computer Graphics Implementation III
Rasterization and Antialiasing
Introduction to Computer Graphics with WebGL
From Vertices To Fragments
Implementation III Ed Angel Professor Emeritus of Computer Science
Implementation II Ed Angel Professor Emeritus of Computer Science
From Vertex to Fragment
From Vertex to Fragment
Presentation transcript:

From Vertices to Fragments II Software College, Shandong University Instructor: Zhou Yuanfeng

Review Cyrus-Beck clipping algorithm; Liang-Barsky clipping algorithm; Sutherland-Hodgman polygon clipping; DDA line algorithm; Bresenham’s line algorithm;

3 Objectives Rasterization: Polygon scan conversion algorithm; Hidden surface removal Aliasing

4 Polygon Scan Conversion Scan Conversion = Fill How to tell inside from outside ­Convex easy ­Nonsimple difficult ­Odd even test Count edge crossings ­Winding number odd-even fill

5 Winding Number Count clockwise encirclements of point Alternate definition of inside: inside if winding number  0 winding number = 2 winding number = 1

OpenGL & Concave Polygon OpenGL can only fill convex polygon correctly 6

OpenGL & Concave Polygon // create tessellator GLUtesselator *tess = gluNewTess(); // describe non-convex polygon gluTessBeginPolygon(tess, user_data); // first contour gluTessBeginContour(tess); gluTessVertex(tess, coords[0], vertex_data);... gluTessEndContour(tess);... gluTessEndPolygon(tess); // delete tessellator after processing gluDeleteTess(tess); 7

Constrained Delaunay Triangulation 8

9 Filling in the Frame Buffer Fill at end of pipeline ­Convex Polygons only ­Nonconvex polygons assumed to have been tessellated ­Shades (colors) have been computed for vertices (Gouraud shading) ­Combine with z-buffer algorithm March across scan lines interpolating shades Incremental work small

10 Using Interpolation span C1C1 C3C3 C2C2 C5C5 C4C4 scan line C 1 C 2 C 3 specified by glColor or by vertex shading C 4 determined by interpolating between C 1 and C 2 C 5 determined by interpolating between C 2 and C 3 interpolate between C 4 and C 5 along span

11 Flood Fill Fill can be done recursively if we know a seed point located inside (WHITE) Scan convert edges into buffer in edge/inside color (BLACK) flood_fill(int x, int y) { if(read_pixel(x,y)= = WHITE) { write_pixel(x,y,BLACK); flood_fill(x-1, y); flood_fill(x+1, y); flood_fill(x, y+1); flood_fill(x, y-1); } } //4 directions

Flood Fill 12 //8 directions

Flood Fill with Scan Line Stack

14 Scan Line Fill Can also fill by maintaining a data structure of all intersections of polygons with scan lines ­Sort by scan line ­Fill each span vertex order generated by vertex list desired order

Singularities 15

16 Data Structure

Scan line filling For each scan line: 1.Find the intersections of the scan line with all edges of the polygon; 2.Sort the intersections by increasing x- coordinate; 3.Fill in all pixels between pairs of intersections. Problem: Calculating intersections is slow. Solution: Incremental computation / coherence 17

Coherence of Region 18 Trapezoid: inside and outside

Coherence of Scan Line e is an integer; ≥e ≥ Intersections number is even; are inside; 19 inside

Coherence of Edge Intersection points of d is l e and l d The number of l e = l d and are on the same edge 20 e d y 63 y 24

Coherence of Edge Observation: Not all edges intersect each scanline. Many edges intersected by scanline i will also be intersected by scanline i+1 Formula for scanline s is y = s, for an edge is y = mx + b Their intersection is s = mx s + b --> x s = (s-b)/m For scanline s + 1, x s+1 = (s+1 - b)/m = x s + 1/m Incremental calculation: x s+1 = x s + 1/m 21

Data Structure 22 Edge index table ET Active Edge List AEL Node: y max The max coord y; x The bottom x coord of edge in ET, the intersection x of edge and scan line in AEL. Δx 1/m next the next node Where is the end of one edge while scanning Initial x Current scan line and edge intersection When y=y+1, x=x+1/m Next edge

Data Structure ET 23 y

Data Structure AEL 24 AEL is the edges list which intersect with current scan line, the next intersection can be computed by: Active Edge List -5/3 5 7 AEL e0e0 e5e AEL at y=2 scan line -5/3 5 5 AEL e0e0 e5e AEL at y=3 scan line 2 y max x 1/m Edge list is ordered according x increasing

Algorithm Construct the Edge Table (ET); Active Edge List (AEL) = null; for y = Ymin to Ymax Merge-sort ET[y] into AEL by x value Fill between pairs of x in AEL for each edge in AEL if edge.ymax = y remove edge from AEL else edge.x = edge.x + dx/dy sort AEL by x value end scan_fill 25

26 Hidden Surface Removal Object-space approach: use pairwise testing between polygons (objects space) Worst case complexity O(n 2 ) for n polygons partially obscuringcan draw independently

27 Image Space Approach Look at each projector ( nm for an n x m frame buffer) and find closest of k polygons Complexity O (nmk) Ray tracing z-buffer Fast but with low paint quality

28 Painter’s Algorithm Render polygons a back to front order so that polygons behind others are simply painted over B behind A as seen by viewer Fill B then A

29 Depth Sort Requires ordering of polygons first ­O(n log n) calculation for ordering ­Not every polygon is either in front or behind all other polygons Order polygons and deal with easy cases first, harder later Polygons sorted by distance from COP

30 Easy Cases (1) A lies behind all other polygons ­Can render (2) Polygons overlap in z but not in either x or y ­Can render independently

31 Hard Cases (3) Overlap in all directions but can one is fully on one side of the other cyclic overlap penetration (4)

32 Back-Face Removal (Culling)  face is visible iff 90    -90 equivalently cos   0 or v n  0 plane of face has form ax + by +cz +d =0 but after normalization n = ( ) T need only test the sign of c In OpenGL we can simply enable culling but may not work correctly if we have nonconvex objects

33 z-Buffer Algorithm Use a buffer called the z or depth buffer to store the depth of the closest object at each pixel found so far As we render each polygon, compare the depth of each pixel to depth in z buffer If less, place shade of pixel in color buffer and update z buffer

z-Buffer Algorithm 34

z-Buffer Algorithm 35

Example 36

Example 37

Example 38

39 Efficiency If we work scan line by scan line as we move across a scan line, the depth changes satisfy a  x+b  y+c  z=0 Along scan line  y = 0  z = -  x In screen space  x = 1

40 Scan-Line Algorithm Can combine shading and hsr through scan line algorithm scan line i: no need for depth information, can only be in no or one polygon scan line j: need depth information only when in more than one polygon

z-Buffer Scan-Line 41

42 Implementation Need a data structure to store ­Flag for each polygon (inside/outside) ­Incremental structure for scan lines that stores which edges are encountered ­Parameters for planes for intersections

43 Visibility Testing In many real-time applications, such as games, we want to eliminate as many objects as possible within the application ­Reduce burden on pipeline ­Reduce traffic on bus Partition space with Binary Spatial Partition (BSP) Tree

44 Simple Example consider 6 parallel polygons top view The plane of A separates B and C from D, E and F

45 BSP Tree Can continue recursively ­Plane of C separates B from A ­Plane of D separates E and F Can put this information in a BSP tree ­Use for visibility and occlusion testing

BSP Tree 46

BSP Algorithm Choose a polygon P from the list. Make a node N in the BSP tree, and add P to the list of polygons at that node. For each other polygon in the list: If that polygon is wholly in front of the plane containing P, move that polygon to the list of nodes in front of P. If that polygon is wholly behind the plane containing P, move that polygon to the list of nodes behind P. If that polygon is intersected by the plane containing P, split it into two polygons and move them to the respective lists of polygons behind and in front of P. If that polygon lies in the plane containing P, add it to the list of polygons at node N. Apply this algorithm to the list of polygons in front of P. Apply this algorithm to the list of polygons behind P. 47

48 BSP display Type Tree Tree* front; Face face; Tree *back; End Algorithm DrawBSP(Tree T; point: w) //w 为视点 If T is null then return; endif If w is in front of T.face then DrawBSP(T.back,w); Draw(T.face,w); DrawBSP(T.front,w); Else // w is behind or on T.face DrawBSP(T.front,w); Draw(T.face,w); DrawBSP(T. back,w); Endif end

49 Aliasing Ideal rasterized line should be 1 pixel wide Choosing best y for each x (or visa versa) produces aliased raster lines

50 Antialiasing by Area Averaging Color multiple pixels for each x depending on coverage by ideal line original antialiased magnified

51 Polygon Aliasing Aliasing problems can be serious for polygons ­Jaggedness of edges ­Small polygons neglected ­Need compositing so color of one polygon does not totally determine color of pixel All three polygons should contribute to color

Time-domain aliasing Adding ray tracing line from one pixel; 52