Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hidden Surfaces Chapter 10. 2 Department of CSE, CUET Hidden Lines.

Similar presentations


Presentation on theme: "Hidden Surfaces Chapter 10. 2 Department of CSE, CUET Hidden Lines."— Presentation transcript:

1 Hidden Surfaces Chapter 10

2 2 Department of CSE, CUET Hidden Lines

3 3 Department of CSE, CUET Hidden Lines Removed

4 4 Department of CSE, CUET Hidden Surfaces Removed

5 5 Department of CSE, CUET Why? We must determine what is visible within a scene from a chosen viewing position For 3D worlds this is known as visible surface detection or hidden surface elimination

6 6 Department of CSE, CUET Hidden Surface Removal Goal: Determine which surfaces are visible and which ar e not. Z-Buffer is just one of many hidden surface removal algorithms. Other names: Visible-surface detection Hidden-surface elimination Display all visible surfaces, do not display any occluded surfaces. We can categorize into Object-space methods Image-space methods

7 7 Department of CSE, CUET Topics need to be read Back face Culling Hidden Object Removal: Painters Algorithm Z-buffer Scanline subdivision Warnock Atherton-Weiler BSP Tree

8 8 Department of CSE, CUET Two Main Approaches Visible surface detection algorithms are broadly classified as: – Object Space Methods: Compares objects and parts of objects to each other within the scene definition to determine which surfaces are visible – Image Space Methods: Visibility is decided point-by-point at each pixel position on the projection plane Image space methods are by far the more common

9 9 Department of CSE, CUET Two Main Approaches Object Space Method: For each object in the scene do Begin 1. Determine those part of the object whose view is unobstru cted by other parts of it or any other object with respect to the viewing specification. 2. Draw those parts in the object color. End

10 10 Department of CSE, CUET Two Main Approaches Image Space Method: For each pixel in the image do Begin 1. Determine the object closest to the viewer that is pierced by the projector through the pixel 2. Draw the pixel in the object colour. End

11 11 Department of CSE, CUET Visible Surface Detection Object space methods ex: back-face, painters algorithm Image space methods ex: z-buffer, scan-line, subdivision

12 12 Department of CSE, CUET Back-Face Detection In a solid object, there are surfaces which are facing the viewer (front faces) and there are surfaces which are opposite to the viewer (back faces). Each surface has a normal vector. If this vector is pointing in the direction of the center of projection, it is a front face and can be seen by the viewer. If it is pointing away from the center of projection, it is a back face and cannot be seen by the viewer. The test is very simple, if the z component of the normal vector is positive, then, it is a back face. If the z component of the vector is negative, it is a front face.

13 13 Department of CSE, CUET Back-Face Detection zvzv xvxv yvyv V view N=(A,B,C) (x,y,z) is behind the polygon if Ax+By+Cz<0 or A polygon is a backface if V view. N >0 if V view is parallel to z v axis: if C<0 then backface if C=0 then polygon cannot be seen

14 14 Department of CSE, CUET Back-Face Culling Example v = (-1, 0, -1) n 2 = (-3, 1, -2) n 1 · v = (2, 1, 2) · (-1, 0, -1) = -2 – 2 = -4, so n 1 ·v < 0 so n 1 front facing polygon n 1 = (2, 1, 2) n 2 · v = (-3, 1, -2) · (-1, 0, -1) = = 5 so n 2 · v > 0 so n 2 back facing polygon

15 15 Department of CSE, CUET Back-Face Culling If the viewpoint is on the +z axis looking at the origin, we only need check the sign of the z component of the objects normal vector if n z < 0, it is back facing if n z > 0 it is front facing What if n z = 0? the polygon is parallel to the view direction, so we dont see it

16 16 Department of CSE, CUET Z-Buffering Visible Surface Determination Algorithm: Determine which object is visible at each pixel. Order of polygons is not critical. Works for dynamic scenes. Basic idea: Rasterize (scan-convert) each polygon, one at a time Keep track of a z value at each pixel Interpolate z value of vertices during rasterization. Replace pixel with new color if z value is greater. (i.e., if object is closer to eye)

17 17 Department of CSE, CUET Example Goal is to figure out which polygon to draw based on which is in front of what. The algorithm relies on the fact that if a nearer object occupying (x,y) is found, then the depth buffer is overwritten with the rendering information from this nearer surface.

18 18 Department of CSE, CUET Z-buffering Need to maintain: Frame buffer contains colour values for each pixel Z-buffer contains the current value of z for each pixel The two buffers have the same width and height. No object/object intersections. No sorting of objects required. Additional memory is required for the z-buffer. In the early days, this was a problem.

19 19 Department of CSE, CUET Algorithm: 1. Initially each pixel of the z-buffer is set to the maximum depth value (the depth of the back clipping plane). 2. The image buffer is set to the background color. 3. Surfaces are rendered one at a time. 4. For the first surface, the depth value of each pixel is calculated. 5. If this depth value is smaller than the corresponding depth value in the z-buffer (ie. it is closer to the view point), both the depth value in the z-buffer and the color value in the image buffer are replaced by the depth value and the color value of this surface calculated at the pixel position. 6. Repeat step 4 and 5 for the remaining surfaces. 7. After all the surfaces have been processed, each pixel of the image buffer represents the color of a visible surface at that pixel. Z-Buffering: Algorithm

20 20 Department of CSE, CUET Z-Buffering: Algorithm allocate z-buffer; The z-buffer algorithm: compare pixel depth(x,y) against buffer record d[x][y] for (every pixel){ initialize the colour to the background}; for (each facet F){ for (each pixel (x,y) on the facet) if (depth(x,y) < buffer[x][y]){ / / F is closest so far set pixel(x,y) to colour of F; d[x][y] = depth(x,y) }

21 21 Department of CSE, CUET Z-Buffering: Example Scan convert the following two polygons. The number inside the pixel represents its z-value. (0,0) (3,0) (0,3) (0,0)(3,0) (3,3) Does order matter?

22 22 Department of CSE, CUET Z-Buffering: Example = = = =

23 23 Department of CSE, CUET Z-Buffering: Example

24 24 Department of CSE, CUET Z-Buffering: Computing Z How do you compute the z value at a given pixel? Interpolate between vertices z1z1 z2z2 z3z3 y1y1 y2y2 y3y3 ysys zaza zbzb zszs

25 25 Department of CSE, CUET Z-Buffer Advantages Simple to implement in hardware. Memory for z-buffer is now not expensive Diversity of primitives – not just polygons. Unlimited scene complexity Dont need to calculate object-object intersections. – Buffer may be saved with image for re-processing Amenable to scan-line algorithms Can easily resolve visibility cycles

26 26 Department of CSE, CUET Z-Buffer Disadvantages Extra memory and bandwidth Waste time drawing hidden objects Z-precision errors May have to use point sampling Requires a lot of memory – Finite depth precision can cause problems – Spends time while rendering polygons that are not visible – Requires re-calculations when changing the scale Does not do transparency easily Aliasing occurs! Since not all depth questions can be resolved Anti-aliasing solutions non-trivial Shadows are not easy Higher order illumination is hard in general

27 27 Department of CSE, CUET Scan-Line Method An image space method for identifying visible surfaces Computes and compares depth values along the various scan-lines for a scene.

28 28 Department of CSE, CUET Scan-Line Method (cont…) Two important tables are maintained: – The edge table – The surface facet table The edge table contains: – Coordinate end points of reach line in the scene – The inverse slope of each line – Pointers into the surface facet table to connect edges to surfaces The surface facet tables contains: The plane coefficients Surface material properties Other surface data Maybe pointers into the edge table

29 29 Department of CSE, CUET Scan-Line Method (cont…) To facilitate the search for surfaces crossing a given scan-line an active list of edges is formed for each scan-line as it is processed. The active list stores only those edges that cross the scan-line in order of increasing x. Also a flag is set for each surface to indicate whether a position along a scan-line is either inside or outside the surface.

30 30 Department of CSE, CUET Scan-Line Method (cont…) Pixel positions across each scan-line are processed from left to right At the left intersection with a surface the surface flag is turned on At the right intersection point the flag is turned off We only need to perform depth calculations when more than one surface has its flag turned on at a certain scan-line position

31 31 Department of CSE, CUET Scan Line Method Example

32 32 Department of CSE, CUET Scan-Line Method Limitations The scan-line method runs into trouble when surfaces cut through each other or otherwise cyclically overlap Such surfaces need to be divided

33 33 Department of CSE, CUET Scan-Line Method For each scan-line, examine all polygon surface projections intersecting that scan line to determine which are visible. Then enter the surface color of that position in the frame buffer. Edge table: coordinate endpoints of each line inverse slope of each line pointers to surface table Surface table: plane coefficients (A,B,C) surface material properties pointers to edge table yvyv xvxv Image space method

34 34 Department of CSE, CUET Scan-Line Method Algorithm: 1. Form an active edge list that contains only th e edges that cross the current scan line, sorte d in order of increasing x. 2. Define a flag for each surface to indicate whe ther a position along a scan line is inside or o utside the surface. 3. Process pixel positions across each scan line f rom left to right. Locate visible positions of surfaces along the scan line. yvyv xvxv 1 2 3

35 35 Department of CSE, CUET An area-subdivision technique Idea: Divide an area into four equal sub-areas At each stage, the projection of each polygon will do one of four things: 1. Completely surround a particular area 2. Intersect the area 3. Be completely contained in the area 4. Be disjoint to the area Warnocks Algorithm

36 36 Department of CSE, CUET Warnocks Algorithm Disjoint polygons do not influence an area. Parts of an intersecting polygon that lie outside the area do not influence that area At each step, we determine the areas we can color and color them, then subdivide the areas that are ambiguous.

37 37 Department of CSE, CUET Warnocks Algorithm At each stage of the algorithm, examine the areas: 1. If no polygons lie within an area, the area is filled with the bac kground color 2. If only one polygon is in part of the area, the area is first filled with the background color and then the polygon is scan conver ted within the area. 3. If one polygon surrounds the area and it is in front of any othe r polygons, the entire area is filled with the color of the surrou nding polygon. 4. Otherwise, subdivide the area and repeat the above 4 tests.

38 38 Department of CSE, CUET Warnocks Algorithm Initial scene

39 39 Department of CSE, CUET Warnocks Algorithm First subdivision

40 40 Department of CSE, CUET Warnocks Algorithm Second subdivision

41 41 Department of CSE, CUET Warnocks Algorithm Third subdivision

42 42 Department of CSE, CUET Warnocks Algorithm Fourth subdivision

43 43 Department of CSE, CUET Warnocks Algorithm Subdivision continues until: All areas meet one of the four criteria An area is pixel size in this case, the polygon with the closest point at that pixel determines the pixel color

44 44 Department of CSE, CUET

45 45 Department of CSE, CUET

46 46 Department of CSE, CUET

47 47 Department of CSE, CUET

48 48 Department of CSE, CUET

49 49 Department of CSE, CUET 10/29/02 Warnocks Algorithm Regions labeled with case used to classify them: 1) One polygon in front 2) Empty 3) One polygon inside, surr ounding or intersecting Small regions not labeled Note its a rendering algor ithm and a HSR algorithm at the same time Assuming you can draw squares

50 50 Department of CSE, CUET Weiler -Atherton Algorithm Object space Like Warnock Output – polygons of arbitrary accuracy

51 51 Department of CSE, CUET Weiler -Atherton Algorithm Subdivide along polygon boundaries (unlike Warnocks re ctangular boundaries in image space); Algorithm: 1. Sort the polygons based on their minimum z distance 2. Choose the first polygon P in the sorted list 3. Clip all polygons left against P, create two lists: – Inside list: polygon fragments inside P (including P) – Outside list: polygon fragments outside P 4. All polygon fragments on the inside list that are behind P are discarded. If there are polygons on the inside list that are in f ront of P, go back to step 3), use the offending polygons as P 5. Display P and go back to step (2)

52 52 Department of CSE, CUET WA_display( polys : ListOfPolygons) sort_by_minZ( polys ); while ( polys <> NULL) do WA_subdiv( polys->first, polys ) end; WA_subdiv( first : Polygon; polys : ListOfPolygons) inP, outP : ListOfPolygons := NULL; for each P in polys do Clip( P, first->ancestor, inP, outP ); for each P in inP do if P is behind (min z) first then discard P ; for each P in inP do if P is not part of first then WA_subdiv( P, inP ); for each P in inP do display_a_poly( P ); polys := outP ; end; Weiler -Atherton Algorithm

53 53 Department of CSE, CUET 53 Painters Algorithm Object-space algorithm Draw surfaces from back (farthest away) to front (closest) : Sort surfaces/polygons by their depth (z value) Draw objects in order (farthest to closest) Closer objects paint over the top of farther away objects

54 54 Department of CSE, CUET BSP-Trees (Object Precision) Construct a binary space partition tree Tree gives a rendering order A list-priority algorithm Tree splits 3D world with planes The world is broken into convex cells Each cell is the intersection of all the half-spaces of splitting planes on tree path to t he cell Also used to model the shape of objects, and in other visibility algorithms BSP visibility in games does not necessarily refer to this algorithm

55 55 Department of CSE, CUET BSP-Tree Example A C B A B C

56 56 Department of CSE, CUET Building BSP-Trees Choose polygon (arbitrary) Split its cell using plane on which polygon lies May have to chop polygons in two (Clipping!) Continue until each cell contains only one polygon fragment Splitting planes could be chosen in other ways, but there is no efficient optimal algorithm for building BSP trees Optimal means minimum number of polygon fragments in a balanced tree

57 57 Department of CSE, CUET Building Example We will build a BSP tree, in 2D, for a 3 room building Ignoring doors Splitting edge order is shown Back side of edge is side with the number

58 58 Department of CSE, CUET Building Example (1) 1 23b4b a, 4a, 62, 3b, 4b, a 3a

59 59 Department of CSE, CUET Building Example (2) 1 23b4b 5a 6 1 3a, 4a, a 3a 3b, 5b 2 4b, 5a -+ 5b

60 60 Department of CSE, CUET Building Example (3) 1 23b4b 5a a 3a 2 4b, 5a - + 5b 4a, 6 3a + 5b 3b +

61 61 Department of CSE, CUET Building Example (Done) 1 23b4b 5a a 3a b 3a + 3b + 4a 6 + 5b 4b 5a +

62 62 Department of CSE, CUET BSP-Tree Rendering Observation: Things on the opposite side of a splitting plane from the viewpoin t cannot obscure things on the same side as the viewpoint Rendering algorithm is recursive descent of the BSP Tree At each node (for back to front rendering): Recurse down the side of the sub-tree that does not contain the viewpoint Test viewpoint against the split plane to decide which tree Draw the polygon in the splitting plane Paint over whatever has already been drawn Recurse down the side of the tree containing the viewpoint

63 63 Department of CSE, CUET BSP-Tree Rendering Example A C B A B C st View 2nd3rd4th

64 64 Department of CSE, CUET BSP-Tree Rendering (2) Advantages: One tree works for any viewing point Filter anti-aliasing and transparency work Have back to front ordering for compositing Can also render front to back, and avoid drawing back polygon s that cannot contribute to the view User two trees – an extra one that subdivides the window Disadvantages: Can be many small pieces of polygon Over-rendering

65 65 Department of CSE, CUET BSP (Binary Space Partitioning) Tree. One of class of list-priority algorithms – returns ordered list of polygon fragments for specified view point (static pre-processing stage). Choose polygon arbitrarily Divide scene into front (relative to normal) and back half-spaces. Split any polygon lying on both sides. Choose a polygon from each side – split scene again. Recursively divide each side until each node contains only 1 polygon View of scene from above

66 66 Department of CSE, CUET 19/10/2007 BSP Tree. Choose polygon arbitrarily Divide scene into front (relative to normal) and back half-spaces. Split any polygon lying on both sides. Choose a polygon from each side – split scene again. Recursively divide each side until each node contains only 1 polygon a 5b 1 2 5a 4 5b back front

67 67 Department of CSE, CUET Choose polygon arbitrarily Divide scene into front (relative to normal) and back half-spaces. Split any polygon lying on both sides. Choose a polygon from each side – split scene again. Recursively divide each side until each node contains only 1 polygon a 5b 4 5b back front 2 15a front BSP Tree.

68 68 Department of CSE, CUET Choose polygon arbitrarily Divide scene into front (relative to normal) and back half-spaces. Split any polygon lying on both sides. Choose a polygon from each side – split scene again. Recursively divide each side until each node contains only 1 polygon a 5b back front 2 15a front 5b 4 BSP Tree.

69 69 Department of CSE, CUET 19/10/2007 Displaying a BSP tree. Once we have the regions – need priority list BSP tree can be traversed to yield a correct priority list for an arbi trary viewpoint. Start at root polygon. If viewer is in front half-space, draw polygons behind root first, then the ro ot polygon, then polygons in front. If polygon is on edge – either can be used. Recursively descend the tree. If eye is in rear half-space for a polygon – then can back face cull.

70 70 Department of CSE, CUET 19/10/2007 BSP Tree. A lot of computation required at start. Try to split polygons along good dividing plane Intersecting polygon splitting may be costly Cheap to check visibility once tree is set up. Can be used to generate correct visibility for arbitr ary views. Efficient when objects dont change very often in t he scene.

71 71 Department of CSE, CUET 19/10/2007 BSP performance measure Tree construction and traversal (object-space orderi ng algorithm – good for relatively few static primiti ves, precise) Overdraw: maximum Front-to-back traversal is more efficient Record which region has been filled in already Terminate when all regions of the screen is filled in S. Chen and D. Gordon. Front-to-Back Display of BSP Trees. IEEE Co mputer Graphics & Algorithms, pp 79–85. September 1991.

72 72 Department of CSE, CUET Coherence Most methods for visible surface determination take adva ntage of coherence features in the surface: – Object coherence – Face coherence – Edge coherence – Scan-line coherence – Depth coherence – Frame coherence


Download ppt "Hidden Surfaces Chapter 10. 2 Department of CSE, CUET Hidden Lines."

Similar presentations


Ads by Google