Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hidden Surface Removal. 2 Goal: Determine which surfaces are visible and which are not. Z-Buffer is just one of many hidden surface removal algorithms.

Similar presentations


Presentation on theme: "Hidden Surface Removal. 2 Goal: Determine which surfaces are visible and which are not. Z-Buffer is just one of many hidden surface removal algorithms."— Presentation transcript:

1 Hidden Surface Removal

2 2 Goal: Determine which surfaces are visible and which are 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

3 3 Hidden Surface Elimination Object space algorithms: determine which objects are in front of others Resize doesn’t require recalculation Works for static scenes May be difficult to determine Image space algorithms: determine which object is visible at each pixel Resize requires recalculation Works for dynamic scenes

4 4 Don’t draw surfaces facing away from viewpoint: Assumes objects are solid polyhedra Usually combined with additional methods Compute polygon normal n: Assume counter-clockwise vertex order For a triangle (a, b, c): n = (b – a)  (c – a) Compute vector from viewpoint to any point p on polygon v: Facing away (don’t draw) if n and v are pointed in opposite directions  dot product n · v > 0 Back-Face Culling a b c n x y z

5 5 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) = 3 + 2 = 5 so n 2 · v > 0 so n 2 back facing polygon

6 6 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 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 don’t see it

7 7 Painter’s Algorithm(depth sorting algm) 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

8 8 List Priority Algorithms A visibility ordering is placed on the objects Objects are rendered back to front based on that ordering Problems: overlapping polygons x z

9 9 Depth Sort Algorithm An extension to the painter’s algorithm Performs a similar algorithm but attempts to resolve overlapping polygons Algorithm: Sort objects by their minimum z value (farthest from the viewer) Resolve any ambiguities caused by overlapping polygons, splitting polygons if necessary Scan convert polygons in ascending order of their z values (back to front)

10 10 Depth-Sort Algorithm Depth-Sort test for overlapping polygons: Let P be the most distant polygon in the sorted list. Before scan converting P, we must make sure it does not overlap another polygon and obscure it For each polygon Q that P might obscure, we make the following tests. As soon as one succeeds, there is no overlap, so we quit: 1.Are their x extents non-overlapping? 2.Are their y extents non-overlapping? 3.Is P entirely on the other side of Q’s plane from the viewpoint? 4.Is Q entirely on the same side of P’s plane as the viewpoint? 5.Are their projections onto the (x, y) plane non- overlapping?

11 11 Test 3 succeeds: Test 3 fails, test 4 succeeds: z Q P Depth-Sort Algorithm z Q P x x

12 12 Depth-Sort Algorithm If all 5 tests fail, assume that P obscures Q, reverse their roles, and repeat steps 3 and 4 If these tests also fail, one of the polygons must be split into multiple polygons and the tests run again.

13 13 Binary Space Partition (BSP) Tree Recursively subdivide space to determine depth order: Think of scene as clusters of objects Find plane that separates two clusters An object on same side of the plane as the viewpoint can obscure, but cannot be obscured by, an object on the other side. Recursively subdivide clusters by finding appropriate planes Store subdivision (space-partioning) planes in a binary tree Node: stores a polygon and a space partioning plane Left child: subtree of objects on negative side of plane Right child: subtree of objects on positive side of plane

14 14 Binary Space Partition (BSP) Tree Very efficient for static scenes New viewpoints calculated quickly Invented by Henry Fuchs and others. Fuchs is a professor at UNC. Used in first-person shooters. Used in Doom.

15 15 BSP Trees: Basic Idea – + In the plane (= 0) Behind the plane (– side) eye t2t2 t1t1 In front of the plane (+ side)

16 16 BSP Trees: Basic Idea (cont.) Assume (for now) the polygons do not cross the plane. Let f (p) be the implicit equation of a plane evaluated at p. if f t1 (eye) < 0 draw t 1 draw t 2 else draw t 2 draw t 1 – + In the plane Behind the plane eye t2t2 t1t1

17 17 BSP Algorithm BSP Tree: partitions space into positive and negative sides Node: polygon and a space partioning plane Left (right) child: subtree of objects on negative (positive) side of plane Use a modified in-order traversal to draw the scene: Start at root Compute which side of node’s plane eye is on Recursively scan convert polygons on opposite side from eye Scan convert node’s polygon Recursively scan convert polygons on same side as eye 1 2 3 Root polygon + – 4 + – eye

18 18 BSP Algorithm (cont.) 1 2 3 Root polygon + – 4 + – eye draw(tree, eye){ if tree.empty() return; if tree.f plane (eye) < 0 draw(tree.plus, eye); rasterize(tree.triangle); draw(tree.minus, eye) else draw(tree.minus, eye); rasterize(tree.triangle); draw(tree.plus, eye); } 1 32 –+ 4 + Resulting drawing order: 2, 4, 1, 3

19 19 BSP Tree Algorithm 1.Select a polygon and make it the root 2.Partition space into two half-spaces determined by the normal of the root polygon 3.If a polygon is intersected by the plane, split the polygon into two polygons, one in each half space 4.Select one polygon in the root’s front and one in the root’s back and assign them as children of the root 5.Recursively subdivide space depending on each of the children generated from step 4. 6.Stop when a sub-space contains a single polygon

20 20 BSP Tree example Initial Scene: 1 2 3 4 5

21 21 BSP Tree example Select polygon 3 as the root 1 2 3 4 5 1 2 4a 4b 5 3 4a 4b front back

22 22 BSP Tree example Select polygons 2 and 4b as the next nodes 1 2 3 4 5 1b 4a 3 4b 2 1a 5 1b 1a front back

23 23 BSP Tree example Select polygon 1b as the next node 1 2 3 4 5 3 4a 4b 2 1a 5 1b 1a 1b 4a front back

24 24 BSP Tree Once the tree is built, you can scan convert The viewpoint will be in one of the subspaces To scan convert properly: Recursively scan convert all polygons in the root’s subspace that doesn’t contain the viewpoint Then scan convert the root Then recursively scan convert the subspace that contains the viewpoint

25 25 BSP Tree example Suppose the viewpoint is as shown: Since the eye is in front of 3, scan convert the polygons in back of 3 first 3 4b 2 1a 5 1b 4a front back 1 2 3 4 5 4a 4b 1b 1a eye

26 26 BSP Tree example The eye is behind 4b, so scan convert the polygons in front of 4b first (there are none) Then scan convert 4b, then scan convert the polygons in back of 4b (5) 1 2 3 4 5 4a 4b 1b 1a 3 4b 2 1a 5 1b 4a front back eye

27 27 BSP Tree example Next scan convert 3 Then scan convert the polygons in front of 3 3 4b 2 1a 5 1b 4a front back 1 2 3 4 5 4a 4b 1b 1a eye

28 28 BSP Tree example The eyepoint is behind 2, so scan convert the polygons in front of 2 first 3 4b 2 1a 5 1b 4a front back 1 2 3 4 5 4a 4b 1b 1a eye

29 29 BSP Tree example The eyepoint is behind 1b, so scan convert the polygons in front of 1b first (none) Then scan convert 1b, then the polygons behind 1b (4a) 3 4b 2 1a 5 1b 4a front back 1 2 3 4 5 4a 4b 1b 1a eye

30 30 BSP Tree example Then scan convert 2 Then scan convert the polygons behind 2 (1a) 3 4b 2 1a 5 1b 4a front back 1 2 3 4 5 4a 4b 1b 1a eye

31 31 BSP Tree example So, the final ordering is: 4b, 5, 3, 1b, 4a, 2, 1a 3 4b 2 1a 5 1b 4a front back 1 2 3 4 5 4a 4b 1b 1a eye

32 32 Cutting Triangles Must maintain same vertex ordering to keep the same normal! t 1 =(a, b, A) t 2 = (b, B, A) t 3 = (A, B, c) b a A B c t1t1 t2t2 t3t3 Plane a b B c A If triangle intersects plane  Split

33 33 Cutting Triangles (cont.) Assume we’ve c isolated on one side of plane and that f plane (c) > 0, then: Add t 1 and t 2 to negative subtree: minus.add(t 1 ) minus.add(t 2 ) Add t 3 to positive subtree: plus.add(t 3 ) t 1 =(a, b, A) t 2 = (b, B, A) t 3 = (A, B, c) –+ b a A B c t1t1 t2t2 t3t3 Plane

34 34 Cutting Triangles (cont.) How do we find A and B? A: intersection of line between a and c with the plane f plane Use parametric form of line: p(t) = a + t(c – a) Plug p into the plane equation for the triangle: f plane (p) = (n · p) + D = n · (a + t(c – a)) + D Solve for t and plug back into p(t) to get A Repeat for B a b B c A We use same formula in ray tracing!!

35 35 Z-Buffering Image precision algorithm: Determine which object is visible at each pixel Order of polygons not critical Works for dynamic scenes Takes more memory Basic idea: Rasterize (scan-convert) each polygon Keep track of a z value at each pixel Interpolate z value of polygon vertices during rasterization Replace pixel with new color if z value is smaller (i.e., if object is closer to eye)

36 36 Scan Line Algorithms Image precision Similar to the ideas behind polygon scan conversion, except now we are dealing with multiple polygons Need to determine, for each pixel, which object is visible at that pixel The approach we will present is the “Watkins Algorithm”

37 37 Watkins Algorithm Similar to the edge table idea used in polygon scan conversion Create an Edge Table (ET) Entries in the edge table have the following format: X is the x coordinate of the endpoint with the smaller y coordinate Y max is the y coordinate of the endpoint with the greatest Y value dx is the x increment used in going from one scan line to the next ID is the polygon to which this edge belongs XY max dxIDnext

38 38 Watkins Algorithm - cont Edges are sorted by smallest Y value and placed in buckets accordingly We also need a Polygon Table (PT) that contains information about the polygons Entries in the polygon table have the following format: ID is the id of this polygon Plane Coefs are the coefficients of the plane in which this polygon lies Shading info is the color or shading info to be used in the scan conversion of the polygon In/Out flag - a boolean flag to be used in scan conversion IDPlane CoefsShading InfoIn/Out Flag

39 39 Watkins Algorithm - cont In addition to the ET and PT, we keep an Active Edge Table (AET), similar to the one used in single polygon scan conversion Process scan line by scan line, left to right Initially all polygon In/Out flags are FALSE When a scan line intersects and edge, that polygon’s In/Out flag is set to TRUE.

40 40 Watkins Algorithm - cont If two or more In/Out flags are TRUE, use the plane equations for the polygons to determine which intersected polygon is in front Y = the current scan line X = the intersection point between the scan line and the edges Z is computed using the plane equations If we have non-penetrating polygons, shade with one polygon’s color until the next edge intersection, then update accordingly.

41 41 Watkins Algorithm - cont What about penetrating polygons? Break them into sub-polygons and scan convert the sub-polygons Y1Y1 Y2Y2 Y3Y3

42 42 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 Warnock’s Algorithm

43 43 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.

44 44 Warnock’s Algorithm At each stage of the algorithm, examine the areas: 1.If no polygons lie within an area, the area is filled with the background 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 converted within the area. 3.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. 4.Otherwise, subdivide the area and repeat the above 4 tests.

45 45 Warnock’s Algorithm Initial scene

46 46 Warnock’s Algorithm First subdivision

47 47 Warnock’s Algorithm Second subdivision

48 48 Warnock’s Algorithm Third subdivision

49 49 Warnock’s Algorithm Fourth subdivision

50 50 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

51 51 Visible Surface Ray Tracing From the center of projection, send a ray through each pixel The color of the pixel is determined by the first object intersected by the ray Eye Image plane


Download ppt "Hidden Surface Removal. 2 Goal: Determine which surfaces are visible and which are not. Z-Buffer is just one of many hidden surface removal algorithms."

Similar presentations


Ads by Google