CGII-Visibility

advertisement
Computer Graphics 2
Lecture 8:
Visibility
Pr. Min Chen
Dr. Benjamin Mora
Benjamin Mora
1
University of Wales
Swansea
Main techniques for visibility
• Historical Techniques.
• Z-buffer techniques.
– Used Much.
– Basis for current hardware-accelerated
Technologies.
• Ray-Tracing.
– See Next Lecture!
Benjamin Mora
2
University of Wales
Swansea
Content
• Painter & Priority Lists Algorithms.
• Cells and Portals.
• Area subdivision algorithms.
– Warnock and Weiler Atherton algorithms.
• Scan line algorithms.
• The z-buffer algorithm.
• Extensions.
– Culling.
– Hidden Surface Removal
• Hierarchical Occlusion maps.
• Hierarchical z.
– Depth peeling.
– Soft Shadows.
– Shadow mapping.
Benjamin Mora
3
University of Wales
Swansea
Old Techniques
Benjamin Mora
4
University of Wales
Swansea
Painter’s Algorithm
• Painter’s Algorithm:
– Only if graphics primitives can be separated by planes.
• Primitive can be projected from the farthest one to the closest
(Back-to-Front) without any need to find the closest intersection.
• All the primitives being on the same side of the viewpoint (A) will
be intersected first, so a Front-to-back analysis is more efficient.
(A)
(B)
Benjamin Mora
5
University of Wales
Swansea
Priority List/BSP Trees (Fuch)
1
2
1
2
3
5
5
4
4
3
Benjamin Mora
6
University of Wales
Swansea
Priority List/BSP Trees (Fuch)
• Proposed by Henry Fuch (1980).
• By preprocessing the scene and creating a binary
space subdivision, primitives can then be projected
in a visibility order.
• Handles Transparency correctly.
• In practice, constructing a Binary Space Partitioning
tree is difficult!
Benjamin Mora
7
University of Wales
Swansea
Cells and Portals
• In architectural scenes, rooms are usually
not visible from other rooms.
• Used in 3D games (with Z-buffering).
• A visibility graph is usually associated to the
scene.
A
A
B
F
C
E
C
F
E
B
D
D
Benjamin Mora
8
University of Wales
Swansea
Cells and Portals
• However:
– Do not work with scenes like forest, clouds,…
– Needs to pre-compute the graph.
• Dynamic scenes are an issue.
– Sorting out visibility inside the cells is still required.
• Sometime a method that can compute visibility in
real-time (on-the-fly) is needed.
– Z-Buffer/Hierarchical Z-buffer.
– Hierarchical Occlusions Maps.
– Occlusion queries.
Benjamin Mora
9
University of Wales
Swansea
Area Subdivision Algorithms
• Warnock Algorithm (1969).
– Not really used anymore.
– Hierarchical method.
– Quadtree structure.
– Assumes no overlapping
– Visibility is computed
on a per-block basis.
http://www.evl.uic.edu/aej/488/diagrams/areasub.gif
Benjamin Mora
10
University of Wales
Swansea
Area Subdivision Algorithms
• Weiler-Atherton algorithm
– Kevin Weiler, Peter Atherton, “Hidden surface
removal using polygon area sorting”, Siggraph
1977.
– Works on 3D primitives instead of using screen
space subdivisions.
– Maintains a list of clipped (visible) polygons.
• Every time a new polygon is processed, clipping with
all the (visible) polygons is performed and a new list of
polygons is generated.
• Once all the polygons processed, the clipped parts
can be used for the final image.
Benjamin Mora
11
University of Wales
Swansea
Area Subdivision Algorithms
• Weiler Atherton algorithm.
– Provides a general clipping algorithm for
concave polygons.
Subject Polygon
Clip Polygon
– Other algorithm for clipping: SutherlandHodgman algorithm.
Benjamin Mora
12
University of Wales
Swansea
Scanline (Watkins 70)
• Watkins, G.S. A real-time visible surface
algorithm. UTEC-CSc-70-101, Computer
Science Dept., Univ. of Utah, June 1970.
• Principles similar to Weiler Atherton
algorithm, but uses 1D clipping (line) only.
– Maintains a list of clipped lines for every row.
• Scan-line term used for rasterization
algorithms.
Benjamin Mora
13
University of Wales
Swansea
Scanline (Watkins 70)
Image
Triangle #2
Scan Line y
Primitive list
p1 p32
Row y
p1
p2
p3
p3 p4
p4 p2
p4
Triangle #1
Benjamin Mora
14
University of Wales
Swansea
Possible Issues with these algorithms
• Could be too complex (e.g., 2D clipping).
– Lead to several cases and bugs in
implementations.
• Not fast enough.
– E.g. clipping.
• Hardly parallelizable.
– Not suitable to hardware acceleration.
Benjamin Mora
15
University of Wales
Swansea
The Z-Buffer
Benjamin Mora
16
University of Wales
Swansea
Z-Buffer test
• Example:
Final image
Benjamin Mora
Final z-buffer
17
University of Wales
Swansea
Z-Buffer test
• Used by current hardware technology.
• Primitives can be sent to the graphics hardware in
any order, thanks to the z-buffer test that will keep
the closest fragments.
• A z value is stored for every pixel (z-buffer).
• Algorithm for a given pixel:
If the rasterized z-value is less than the current z-value
Then replace the previous color and z-value by the new ones
Benjamin Mora
18
University of Wales
Swansea
Z-Buffer test
• A scan line algorithm can be used to find all the
pixels on the projection of a single triangle.
• Lines are filled with colors if the pixels pass the ztest.
Row y
Row y+1
Row y+2
Benjamin Mora
19
University of Wales
Swansea
Extensions to these
techniques
Benjamin Mora
20
University of Wales
Swansea
Culling
• Why ?
– To avoid processing geometry that does not need to be
processed.
– Useful when having millions (or billions) of triangles.
– Can be done at the triangle or pixel level.
• View Frustum Culling.
• Back Face Culling.
• Occlusion Culling.
Benjamin Mora
21
University of Wales
Swansea
Culling
• View Frustum Culling.
– Primitives outside of the view frustum discarded.
– Implemented on graphics cards.
Viewing pyramid
Viewpoint
Visible Triangle
Culled triangles
Benjamin Mora
22
University of Wales
Swansea
Culling
• Can be accelerated (software) by grouping
triangle and computing the frustum
intersection only for the bounding box.
Frustum
Don’t need to
process these
triangles.
Bounding Box
Benjamin Mora
23
University of Wales
Swansea
Culling
#1
• Back Face Culling.
– If the viewpoint is fronting the
backface, then the triangle is not
processed.
#3
#2
Projected Triangle
(Visible)
#1
– Hardware accelerated
– Can be enabled/disabled.
#2
#3
Wrong vertex order
– Orientation given by the order of
projected vertices.
Benjamin Mora
24
(Triangle is culled)
University of Wales
Swansea
Occlusion Culling
• A set of algorithms to avoid processing
hidden geometry/surfaces
– Hierarchical Occlusion Maps.
– Hierarchical z-buffer.
– Occlusion queries.
Benjamin Mora
25
University of Wales
Swansea
Hierarchical Occlusion Maps
• Proposed by Zhang et al.
Hansong Zhang, Dinesh Manocha, Tom Hudson Kenneth E. Hoff III.
Visibility Culling using Hierarchical Occlusion Maps. Siggraph 1997.
• Similar to Hierarchical z.
• Only occlusion is stored here.
Benjamin Mora
26
University of Wales
Swansea
Hierarchical Occlusion Maps
• Triangles are initially grouped into separate regions
of space such as bounding boxes, grids or trees.
• This data structure is traversed in a front to back
order.
– The visibility of the region is given by the HOM.
– If region is visible, then its content (i.e., triangles) must be
projected.
– During projection, the content of the different maps is
updated every time a pixel becomes opaque.
• Not used by current hardware.
– Hierarchical-z instead
Benjamin Mora
27
University of Wales
Swansea
Hierarchical Z-buffer
• Proposed by Greene et al.
Ned Greene, Michael Kass and Gavin Miller. Hierarchical Z-Buffer Visibility.
Siggraph 1993.
• A hierarchical z-max pyramid is constructed
above the z-buffer.
• Every time a z value is updated, the
hierarchy is updated.
8
6
5
4
2
Benjamin Mora
3
5
7
6
2
5
4
2
9
1
3
2
8
6 9
7 4
28
8
9
University of Wales
Swansea
Hierarchical Z-buffer
• Current ATI and NVidia graphics card
implement a limited z-hierarchy.
• Efficient when objects are projected in a
front-to-back way.
• ATI Hyper-Z III:
http://graphics.tomshardware.com/graphic/20020718/radeon9700-08.html
Benjamin Mora
29
University of Wales
Swansea
Occlusion Queries
• New Graphics Hardware allows counting the
number of fragments that pass the z-test.
• 3 steps:
– Lock the z-buffer and frame buffer (impossible to
modify the content of these buffers).
– Render a bounding box.
• If no pixel has passed the z-test, then the region
inside the BB is not visible.
– Unlock the Z-buffer and Frame-Buffer.
Benjamin Mora
30
University of Wales
Swansea
Occlusion Queries
• Can take advantage of fast z tests.
• Efficient only if the BB contains many primitives.
• Must wait for the answer.
– The program should do something before testing the
answer.
– Occlusions should be chained in order to avoid an empty
graphics pipeline.
Benjamin Mora
31
University of Wales
Swansea
Depth Peeling
From
Interactive Order-Independent Transparency
Cass Everitt
NVIDIA OpenGL Applications Engineering
Benjamin Mora
32
University of Wales
Swansea
Depth Peeling
From
Interactive Order-Independent Transparency
Cass Everitt
NVIDIA OpenGL Applications Engineering
Benjamin Mora
33
University of Wales
Swansea
Depth Peeling
• Z-buffer based visibility only allows finding
the nearest elements of the scene.
– Transparency cannot correctly be handled.
• Solution: use a multipass algorithm to find
the second nearest surface, third nearest
surface, and etc… for every pixel
– At the end, combine the different images in a
front-to-back-order.
Benjamin Mora
34
University of Wales
Swansea
Download