Download presentation

Presentation is loading. Please wait.

1
Hidden Surfaces Chapter 10

2
Hidden Lines

3
Hidden Lines Removed

4
**Hidden Surfaces Removed**

5
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
**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
**Topics need to be read Back face Culling**

Hidden Object Removal: Painters Algorithm Z-buffer Scanline subdivision Warnock Atherton-Weiler BSP Tree

8
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
**Two Main Approaches Object Space Method:**

For each object in the scene do Begin 1. Determine those part of the object whose view is unobstructed 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
**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
**Visible Surface Detection**

Object space methods ex: back-face, painters algorithm Image space methods ex: z-buffer, scan-line, subdivision

12
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
**Back-Face Detection (x,y,z) is behind the polygon if Ax+By+Cz<0 or**

A polygon is a backface if Vview . N >0 if Vview is parallel to zv axis: if C<0 then backface if C=0 then polygon cannot be seen yv xv N=(A,B,C) zv Vview

14
**Back-Face Culling Example**

n1·v = (2, 1, 2) · (-1, 0, -1) = -2 – 2 = -4, so n1·v < 0 so n1 front facing polygon n2 = (-3, 1, -2) n1 = (2, 1, 2) n2 ·v = (-3, 1, -2) · (-1, 0, -1) = = 5 so n2 · v > 0 so n2 back facing polygon v = (-1, 0, -1)

15
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 object’s normal vector if nz < 0, it is back facing if nz > 0 it is front facing What if nz = 0? the polygon is parallel to the view direction, so we don’t see it

16
**Z-Buffering Basic idea: 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
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
**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
**Z-Buffering: 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.

20
**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
**Z-Buffering: Example Scan convert the following two polygons.**

The number inside the pixel represents its z-value. (3,3) -1 -3 -2 -5 -4 -7 -6 (0,3) -1 -2 -3 -4 -5 -6 -7 (0,0) (0,0) (3,0) (3,0) Does order matter?

22
**Z-Buffering: Example - -5 -7 -6 - -5 -7 -6 + = + = + = + = - - -**

-1 -3 -2 -5 -4 -7 -6 -1 - -1 -2 -3 -4 -5 -6 -7 - -1 -2 -3 -4 -5 -6 -7 -1 -3 -2 -5 -4 -7 -6 -2 -3 + = + = -3 -4 -4 -5 - -1 -3 -2 -5 -4 -7 -6 -1 -2 -3 -4 -5 -6 -7 - -1 -3 -2 -5 -4 -7 -6 - -1 -3 -2 -5 -4 -7 -6 -1 -2 -3 + = + = -3 -4 -4 -5

23
Z-Buffering: Example

24
**Z-Buffering: Computing Z**

How do you compute the z value at a given pixel? Interpolate between vertices z1 y1 za zb ys zs y2 z2 y3 z3

25
**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 Don’t 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
**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
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
**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
**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
**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
**Scan Line Method Example**

32
**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
**Scan-Line Method Image space 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 yv xv Image space method

34
**Scan-Line Method Algorithm:**

1. Form an active edge list that contains only the edges that cross the current scan line, sorted in order of increasing x. 2. Define a flag for each surface to indicate whether a position along a scan line is inside or outside the surface. 3. Process pixel positions across each scan line from left to right. Locate visible positions of surfaces along the scan line. yv 1 2 3 xv

35
**Warnock’s Algorithm 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: Completely surround a particular area Intersect the area Be completely contained in the area Be disjoint to the area

36
**Warnock’s 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
**Warnock’s Algorithm At each stage of the algorithm, examine the areas:**

If no polygons lie within an area, the area is filled with the background color 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 converted within the area. If one polygon surrounds the area and it is in front of any other polygons, the entire area is filled with the color of the surrounding polygon. Otherwise, subdivide the area and repeat the above 4 tests.

38
Warnock’s Algorithm Initial scene

39
Warnock’s Algorithm First subdivision

40
Warnock’s Algorithm Second subdivision

41
Warnock’s Algorithm Third subdivision

42
Warnock’s Algorithm Fourth subdivision

43
**Warnock’s 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

49
**Warnock’s Algorithm 10/29/02**

Regions labeled with case used to classify them: One polygon in front Empty One polygon inside, surrounding or intersecting Small regions not labeled Note it’s a rendering algorithm and a HSR algorithm at the same time Assuming you can draw squares 2 3 2 2 3 3 3 2 3 3 3 1 3 1 1 1 1 3 3 3 3 3 2 3 3 3 2 2 2 2 10/29/02

50
**Weiler -Atherton Algorithm**

Object space Like Warnock Output – polygons of arbitrary accuracy

51
**Weiler -Atherton Algorithm**

Subdivide along polygon boundaries (unlike Warnock’s rectangular boundaries in image space); Algorithm: Sort the polygons based on their minimum z distance Choose the first polygon P in the sorted list Clip all polygons left against P, create two lists: Inside list: polygon fragments inside P (including P) Outside list: polygon fragments outside P All polygon fragments on the inside list that are behind P are discarded. If there are polygons on the inside list that are in front of P, go back to step 3), use the ’offending’ polygons as P Display P and go back to step (2)

52
**Weiler -Atherton Algorithm**

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;

53
**Painter’s 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
**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 the 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
BSP-Tree Example A A C 4 3 - + B C - B + - + 1 3 2 4 1 2

56
**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
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 5 2 3 4 1 6

58
Building Example (1) 5 1 - + 3a, 4a, 6 2, 3b, 4b, 5 3b 2 4b 1 4a 3a 6

59
**Building Example (2) 5b 5a 3b 2 4b 1 4a 3a 6 1 - + 3a, 4a, 6 2 - +**

60
**Building Example (3) 5b 5a 3b 2 4b 1 4a 3a 6 1 - + 2 3a - + + 4a, 6**

61
**Building Example (Done)**

1 - + 2 3a - + + 3b 2 4b 4a 4b 3b + + + 6 5a 5b 1 4a 3a 6

62
BSP-Tree Rendering Observation: Things on the opposite side of a splitting plane from the viewpoint 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
**BSP-Tree Rendering Example**

C 4 3 - + B C - B + - + 1 3 2 4 1 2 3rd 4th 1st 2nd View

64
**BSP-Tree Rendering (2) Advantages: Disadvantages:**

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 polygons 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
**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. 5 2 3 1 4 View of scene from above

66
**BSP Tree. Choose polygon arbitrarily**

3 4 1 2 5 5a 5b back front 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. 19/10/2007

67
**BSP Tree. Choose polygon arbitrarily**

5 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. 5a 5b 2 3 1 4 3 front back 2 4 5b front 5a 1

68
**BSP Tree. Choose polygon arbitrarily**

3 4 1 2 5 5a 5b back front 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.

69
**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 arbitrary viewpoint. Start at root polygon. If viewer is in front half-space, draw polygons behind root first, then the root 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. 19/10/2007

70
**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 arbitrary views. Efficient when objects don’t change very often in the scene. 19/10/2007

71
**BSP performance measure**

Tree construction and traversal (object-space ordering algorithm – good for relatively few static primitives, 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 Computer Graphics & Algorithms, pp 79–85. September 1991. 19/10/2007

72
Coherence • Most methods for visible surface determination take advantage of coherence features in the surface: – Object coherence – Face coherence – Edge coherence – Scan-line coherence – Depth coherence – Frame coherence

Similar presentations

OK

10/29/02 (c) 2002 University of Wisconsin, CS559 Today Hidden Surface Removal Exact Visibility.

10/29/02 (c) 2002 University of Wisconsin, CS559 Today Hidden Surface Removal Exact Visibility.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on electricity generation in india Haptic communication ppt on paper Ppt on marketing mix product Ppt on indian army weapons images Ppt on 2nd world war records Ppt on regional trade agreements in asia Ppt on autonomous car Ppt on sports day logo Ppt on topography of pakistan Free download ppt on railway reservation system