Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hidden Surface Removal 1.  Suppose that we have the polyhedron which has 3 totally visible surfaces, 4 totally invisible/hidden surfaces, and 1 partially.

Similar presentations


Presentation on theme: "Hidden Surface Removal 1.  Suppose that we have the polyhedron which has 3 totally visible surfaces, 4 totally invisible/hidden surfaces, and 1 partially."— Presentation transcript:

1 Hidden Surface Removal 1

2  Suppose that we have the polyhedron which has 3 totally visible surfaces, 4 totally invisible/hidden surfaces, and 1 partially visible/hidden surface.  Obviously, invisible/hidden surfaces do not contribute to the final image.  The procedure that distinguishes between visible surfaces from invisible/hidden surfaces is called visible-surface determination, which is often called hidden-surface removal. 2

3 Back Face Culling 3  Performance goals in real-time rendering  frame rate: 60-72 frames/sec?  resolution: 1600x1200?  photorealism (if necessary): undistinguishable from real scene!  Unfortunately, there is no real upper limit on the scene complexity.  We should cull those portions of the scene that are not considered to contribute to the final image, and process only the rest of the scene.  The simplest is back-face culling, which distinguishes between front faces (faces towards the viewer) and back faces (faces away from the viewer). back faces front faces polygon normals

4 Back Face Culling (cont’d)  Back-face culling works as a preprocessing step for hidden surface removal, and is very powerful in that almost half of polygons of an object are discarded as back faces.  Especially, for a single convex polyhedron, the back-face culling does the entire job of hidden-surface removal.  Hidden-surface removal is applied to only the remaining front faces. 4 single convex polyhedron convex, but not a single polyhedron

5 Face Normal  The normal of a triangle is computed as v 1 X v 2 where v 1 is the vector connecting p 1 and p 2, and v 2 connects p 1 and p 3.  If the vertices of every polygon are ordered consistently (CCW or CW), we can make every polygon’s normal point out of the polyhedron. All mesh data used in this class have triangles of CCW vertex ordering. 5 p q r s t 1 = ( p, q, r ) t 2 = ( s, q, p ) t 1 ’s normal = ( q - p )X( r - p ) t 2 ’s normal = ( q - s )X( p - s )

6 Dot Product (revisited) 6 x y c =(1,1) b =(0,1) a =(-1,1) d =(-1,0) a·d = (-1,1)·(-1,0) = 1 > 0 b·d = (0,1)·(-1,0) = 0 c·d = (1,1)·(-1,0) = -1 < 0  Recall the dot product of two vectors v i & v j.  If v iv j = 0, v i & v j are orthogonal/perpendicular.  If v iv j > 0, angle < 90  If v iv j 90  The same applies to 3D.

7 Dot Product for Back Face Culling  Determining if a polygon is a front face or a back face  Generate a vector C connecting COP and a vertex of the polygon.  Take the dot product CN of the vector C and the polygon’s normal N.  If CN > 0, it’s a back face.  If CN < 0, it’s a front face.  If CN = 0, it’s a face that is projected as an edge/silhouette on the screen. 7 C 2 N 2 > 0 C 3 N 3 < 0 COP C1C1 N1N1 N2N2 N3N3 C 1 N 1 = 0 C2C2 C3C3

8 Hidden Surface Removal 8 x=349 y=249 DOP Fig-2 Fig-1  Suppose that we have two triangles in the viewport defined by (x min, y min, width, height) = (0,0,350,250).  Consider a pixel at (241,200).  The above scene should result in Fig-1, not Fig-2.  Note that Fig-1 does correct hidden-surface removal. z=1 Pixel (241,200) at 350  250 resolution viewport. It should be blue.

9 Z-buffer 9 frame buffer z-buffer should be “blue” 250 350 250 350 ?  The most popular hidden-surface removal algorithm uses z-buffer or depth-buffer.  It’s called z-buffer algorithm, where we need z-buffer in addition to the frame buffer. Their sizes are the same. x=349 y=249 DOP z=1 Pixel (241,200) at 350  250 resolution screen. It should be blue.

10 Z-buffer Algorithm  The frame buffer will have a color-value for each pixel.  The z-buffer will have a z-value for each pixel.  The z-buffer is initialized to the z-values of the back plane (in our case, - 1).  Similarly, the frame buffer is initialized to the background color (in our case, white). 10 ……………. : : w w w w ….. : w w w w ….. frame buffer ……………. : : -1 -1 -1 -1.. : -1 -1 -1 -1.. z-buffer ① initial states

11 Z-buffer Algorithm (cont’d)  Select polygons/triangles of a mesh in an arbitrary order.  Project each triangle onto the z=0 plane, and draw it using the scan- line algorithm.  When drawing each polygon, if the polygon point at (x,y) has a bigger z- value than the current value of the z-buffer, the point’s color & z-value replace the old ones in both buffers. 11 x y y=201 y=200 y=199 240 241 242 243 244 240.4 242.6  Let’s take the red triangle.  For example, when processing y=200 scan line, x=[241,242] will be filled.  For the pixel (241,200), its z-value a of the red triangle should be greater than (or equal to) the current z-buffer’s value -1.  So, set frame-buffer[241,200] to red, and set z-buffer[241,200] to a.

12 Z-buffer Algorithm (cont’d) 12 ② When scan line 200 is completed x=241 ……………. : : w w w w ….. : w R R w ….. frame buffer ……………. : : -1 -1 -1 -1.. : -1 0.6 0.5 -1.. z-buffer y=200 x=241 y=200 A point (242,200,0.5) on the red triangle ③ When the red triangle is completely processed ……………. : : w w w w ….. : w R R w ….. R R R R ……………. : : -1 -1 -1 -1.. : -1 0.6 0.5 -1.. : 0.7 0.6 0.5 0.4..

13 Z-buffer Algorithm (cont’d)  When a triangle is completed, arbitrarily select the next triangle and repeat the scan-line algorithm. 13  Let’s now take the blue triangle.  For example, when processing y=200 scan line, x=[*,241] will be filled.  For the pixel (241,200), its z-value b of the blue triangle should be greater than the current z-buffer’s value a.  Then, set frame-buffer[241,200] to blue, and set z-buffer[241,200] to b. pixel (241,200) x y y=201 y=200 y=202 240 241 242 243 244 241.3

14 Z-buffer Algorithm (cont’d)  Note that we will have the same result if we process blue triangle first and then red triangle (unless they are partially transparent). 14 ④ When the blue triangle is completely processed ……………. : : B B w w ….. : B B R w ….. R R R R ……………. : : 0.8 0.7 -1 -1.. : 0.8 0.7 0.5 -1.. : 0.7 0.6 0.5 0.4.. updated! x=241 y=200 x=241 y=200 updated!

15 Depth Computation  A polygon has the plane equation Ax+By+Cz+D=0.  We can compute A, B, C and D from the 3 vertices of the polygon.  (A,B,C) is the plane’s normal vector, and computed using cross product.  The remaining unknown D is obtained by inserting any vertex out of p 1, p 2 and p 3 into Ax+By+Cz+D=0.  The depth value (z-value) at a pixel position (x,y) is computed by inserting (x,y) into the plane equation Ax+By+Cz+D=0. For example, at (x,y)=(241,200), 15 (A,B,C) pixel (241,200)

16 Incremental Depth Computation  Note that the z-buffer testing is integrated into the polygon-filling scan- line algorithm.  In a scan line, the scan-line algorithm processes pixels of the range [x min, x max ] one by one from the left to the right.  Once the z-value z 1 at (x,y) is computed, the z-value z 2 at the next pixel (x+1,y) is computed incrementally using z 1 as follows: 16 z1z1 y x x+1 z1z1 z2z2

17 Discussions on Z-buffer Algorithm  Z-buffer algorithm is the standard algorithm for hidden-surface removal.  Why is the z-buffer algorithm so popular?  simplest among hidden-surface removal algorithms  easy for H/W implementation  compatible with rendering pipeline architecture  etc.  However, the z-buffer algorithm needs a separate memory for the z- buffer. The size of the z-buffer depends on the accuracy to which the depth value of each point (x,y) is to be stored, which is a function of the scene complexity. Suppose that 4 bytes are used for a pixel. Then, it’s as large as the frame buffer!  e.g. 1280  1024  4 > 4MB 17

18 The Paiter’s algorithm Sort the faces list on the basis of the extent.far value paint entire faces, in order from farthest to closest Depth sort, back to front rendering 18

19 Depth Sort If z overlapped X, y overlapped? All the vertices of a face on one side of the plane defined by the other face? If still overlap, Partition!!! 19

20 HSR using Binary-Space Partition Trees BSP the polygons are rearranged into BT and certain faces are split into pieces the tree can traversed in a systematic way to draw the scene with HS properly removed. 20

21 Building a BSP Tree 2D example 3D example 21

22 Traverse the tree If the eye is outside { draw all faces in the inside of F draw F draw all faces in the outside of F } else{ { draw all faces in the outside of F draw F draw all faces in the inside of F } 22

23 A 2D Scene 23

24 A BSP tree 24

25 A 3D Scene and its BSP tree 25

26 Traverse Order 26


Download ppt "Hidden Surface Removal 1.  Suppose that we have the polyhedron which has 3 totally visible surfaces, 4 totally invisible/hidden surfaces, and 1 partially."

Similar presentations


Ads by Google