Download presentation
Presentation is loading. Please wait.
1
1 CSCE 441: Computer Graphics Hidden Surface Removal (Cont.) Jinxiang Chai
2
2 Outline Backface Culling Painter’s algorithm BSP Z-buffer Scan line Ray casting Reading: section 9-1 to 9-11, 9-14,9-15
3
3 Review: Backface Culling view direction, draw polygon
4
4 Review: Painter’s Example z = 0.7 z = 0.3 z = 0.1 Sort by depth: Green rect Red circle Blue tri z = 0
5
5 Review: Painter’s Algorithm 1. Sort all objects’ z min and z max 2. If an object is uninterrupted (its z min and z max are adjacent in the sorted list), it is fine 3. If 2 objects DO overlap 3.1 Check if they overlap in x - If not, they are fine 3.2 Check if they overlap in y - If not, they are fine - If yes, need to split one
6
6 5-2 2 7-2 Review: Building a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 b b b b bf f f
7
7 Rendering with a BSP Tree How to traverse the tree Draw “back” polygons Draw “on” polygons Draw “front” polygons 1 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b
8
8 5-2 2 7-2 1 Different View Points? 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 b b b b bf f f Do we need to build a new tree? V0V0
9
9 5-2 2 7-2 1 Different View Points? 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 b b b b bf f f Do we need to build a new tree? - No, we use the same tree if objects are static
10
10 5-2 2 7-2 1 Different View Points? 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 b b b b bf f f Do we need to build a new tree? - No, we use the same tree if objects are static How can we traverse the tree? V0V0
11
11 Rendering with a BSP Tree If eye is in front of plane Draw “back” polygons Draw “on” polygons Draw “front” polygons If eye is behind plane Draw “front” polygons Draw “on” polygons Draw “back” polygons Else eye is on plane Draw “front” polygons Draw “back” polygons 1 2 3 45 6 7 + - 6,7 5 bf 1,2,3,4 V0V0 V new
12
12 Rendering with a BSP Tree If eye is in front of plane Draw “back” polygons Draw “on” polygons Draw “front” polygons If eye is behind plane Draw “front” polygons Draw “on” polygons Draw “back” polygons Else eye is on plane Draw “front” polygons Draw “back” polygons 1 2 3 45 6 7 + - 6,7 5 bf 1,2,3,4 V0V0 V new
13
13 Rendering with a BSP Tree If eye is in front of plane Draw “back” polygons Draw “on” polygons Draw “front” polygons If eye is behind plane Draw “front” polygons Draw “on” polygons Draw “back” polygons Else eye is on plane Draw “front” polygons Draw “back” polygons 1 2 3 45 6 7 + - 6,7 5 bf 1,2,3,4 V new V0V0
14
14 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b + - V0V0 V new 1
15
15 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b V0V0 V new 1
16
16 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b + - V0V0 V new 1
17
17 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b + - V0V0 V new 1
18
18 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1->2 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b + - V0V0 V new 1
19
19 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1->2->(7-1) 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b + - V0V0 V new 1
20
20 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1->2->(7-1)->4 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b + - V0V0 V new 1
21
21 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1->2->(7-1)->4->(5-1) 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b + - V0V0 V new 1
22
22 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1->2->(7-1)->4->(5-1)->3 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b V0V0 V new 1
23
23 1 Different View Points? 12 3 4 6 7-2 7-1 5-2 5-1 Traversal order: 1->2->(7-1)->4->(5-1)->3->(7-2)->(5-2)->6 7-1 bf 3 f 4 f 5-2 2 7-2 5-1 6 b b b b V0V0 V new 1
24
24 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? b b bf f f b b
25
25 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? b b bf f f b b + - 1
26
26 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? b b bf f f b b + - 1->?
27
27 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? b b bf f f b b 1->? + -
28
28 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? b b bf f f b b 1->? + -
29
29 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? b b bf f f b b 1->? + -
30
30 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? b b bf f f b b 1->6 + -
31
31 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? b b bf f f b b 1->6->?
32
32 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? 1->6->5-2 b b bf f f b b
33
33 5-2 2 7-2 Rendering with a BSP Tree 12 3 4 6 5-1 3 7-1 4 6 1 7-2 7-1 5-2 5-1 Traversal order? 1->6->(5-2)->(7-2)->3->4->(5-1)->(7-1)->2 b b bf f f b b
34
34 Summary: BSP Trees Pros: Simple, elegant scheme No depth comparisons needed Polygons split and ordered automatically Works for moving cameras Only writes to framebuffer (i.e., painters algorithm)
35
35 Summary: BSP Trees Cons: Computationally intense preprocess stage restricts algorithm to static scenes Splitting increases polygon count Redraws same pixel many times Choosing splitting plane not an exact science Not suitable for moving objects
36
36 Outline Backface Culling Painter’s algorithm BSP Z-buffer Scan line Ray casting Reading: section 9-1 to 9-11, 9-14,9-15
37
37 Depth (“Z”) Buffer Simple modification to scan-conversion Maintain a separate buffer storing the closest “z” value for each pixel—depth buffer Only draw pixel if depth value is closer than stored “z” value Update buffer with closest depth value
38
38 Z-Buffering Example z = 0.7 z = 0.3 z = 0.1 z = 1.0 z = 0.3 z = 1.0 z = 0.3 z = 0.1 z = 1.0 z = 0.7 z = 0.3 z = 0.1 NOTE: Can draw these shapes in any order
39
39 How to Calculate “z”? Update “z” values using scan line conversion algorithm
40
40 How to Calculate “z”? Update “z” values using scan line conversion algorithm Plane equation: Ax+By+Cz+D=0
41
41 How to Calculate “z”? Update “z” values using scan line conversion algorithm Plane equation: Ax+By+Cz+D=0
42
42 How to Calculate “z”? Update “z” values using scan line conversion algorithm Plane equation: Ax+By+Cz+D=0
43
43 How to Calculate “z”? Update “z” values using scan line conversion algorithm Plane equation: Ax+By+Cz+D=0
44
44 How to Calculate “z”? Update “z” values using scan line conversion algorithm Plane equation: Ax+By+Cz+D=0
45
45 How to Calculate “z”? Update “z” values using scan line conversion algorithm Plane equation: Ax+By+Cz+D=0 What’s the x,y,z value for this pixel?
46
46 How to Calculate “z”? Update “z” values using scan line conversion algorithm Plane equation: Ax+By+Cz+D=0 What’s the x k+1,y k+1,z k+1 values for the next horizontal pixel?
47
47 Depth (“Z”) Buffer Advantages Always works. The nearest object always determines the color of a pixel Polygon drawn in any order Commonly in hardware Disadvantages Needs a whole extra buffer Requires extra storage space (How big?) Still lots of overdraw
48
48 Depth (“Z”) Buffer Advantages Always works. The nearest object always determines the color of a pixel Polygon drawn in any order Commonly in hardware Disadvantages Needs a whole extra buffer Requires extra storage space (How big?) (1k*1k*24bits) Still lots of overdraw
49
49 Scan Line Algorithm Scan line algorithm for polygon drawing - how can we modify it for hidden surface removals? Scan line
50
50 Scan Line Algorithm Assume for each line of screen, we have scan-lines for all polygons intersecting that line For each polygon, keep track of extents of scan line Whenever the x-extents of two scan lines overlap, determine ordering of two polygons
51
51 Scan Line Algorithm Scan line algorithm with depth information z=0.1 z=0.3 z=0.2 z=0.5 z=0.4 Scan line
52
52 Scan Line Algorithm Scan line algorithm with depth information z=0.1 z=0.3 z=0.2 z=0.5 z=0.4 Z=0.18Z=0.38 Z=0.5 Scan line Scan line spans
53
53 Scan Line Algorithm How can we determine overlapping regions? - for each scan line, label the pixel “inside” or “outside”
54
54 Scan Line Algorithm How can we determine overlapping regions? - for each scan line, label the pixel “inside” or “outside” - Multiple “inside” are overlapping regions. No overlapping regions!
55
55 Scan Line Algorithm How can we determine overlapping regions? - for each scan line, label the pixel “inside” or “outside” - Multiple “inside” are overlapping regions. One overlapping region!
56
56 Scan Line Algorithm How can we determine overlapping regions? - for each scan line, label the pixel “inside” or “outside” - Multiple “inside” are overlapping regions. One overlapping region! Calculate and compare depth values in overlapping regions
57
57 Scan Line Algorithm
58
58 Scan Line Algorithm
59
59 Scan Line Algorithm Calculate and compare depth values in overlapping regions
60
60 Scan Line Algorithm Advantages Takes advantage of coherence resulting in fast algorithm Does not require as much storage as depth buffer Only draw visible pixels Commonly in software Disadvantages More complex algorithm Requires all polygons sent to renderer before drawing
61
61 Ray Casting For each pixel enter P ij - Send a ray from eye point, c, through p ij into scene - Intersect ray with each object - Select the nearest intersection
62
62 Ray Casting Implementation - Might parameterize each ray as - Each object O k returns t k >0 such that first intersection with o k occurs at r(t k )
63
63 Ray Casting Implementation - Might parameterize each ray as - Each object O k returns t k >0 such that first intersection with o k occurs at r(t k ) - Q: given the set {t k }, what is the first intersection point?
64
64 Ray Casting Implementation - Might parameterize each ray as - Each object O k returns t k >0 such that first intersection with o k occurs at r(t k ) - Q: given the set {t k }, what is the first intersection point?
65
65 Ray Casting Ray casting properties: - process pixels one at a time - draw each visible pixel once - efficient algorithm needed for ray-object intersection - may (not) use pixel coherence - simple but generally not used
66
66 Hidden Surface removal: opengl Backface culling - glEnable(GL_CULL_FACE), glDisable(GL_CULL_FACE) - glCullFace(GL_BACK) view direction, cull polygon
67
67 Z-buffer: opengl In opengl, depth values are normalized to [0.0,1.0] - Specify depth-buffer operations glutInitDisplayMode // with argument GLUT_DEPTH - Specify initial depth-buffer value glClear(GL_DEPTH_BUFFER_BIT) // initialize depth-buffer values to 1.0 glClearDepth (depth) // specify an initial depth-buffer value - Activate depth-testing operations glEnable (GL_DEPTH_TEST)
68
68 Summary Backface Culling Painter’s algorithm BSP Z-buffer Scan line Ray casting Reading: section 9-1 to 9-11,9-14,9-15
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.