Upload
amelia-willis
View
217
Download
1
Embed Size (px)
Citation preview
10/29/02 (c) 2002 University of Wisconsin, CS559
Today
• Hidden Surface Removal
• Exact Visibility
10/29/02 (c) 2002 University of Wisconsin, CS559
Depth Sorting (Object Precision, in view space)
• An example of a list-priority algorithm• Sort polygons on depth of some point• Render from back to front (modifying order on the fly)
• Rendering: For surface S with greatest depth– If no overlap in depth with other polygons, scan convert
– Else, for overlaps in depth, test for overlaps in the image plane
• If none, scan convert and go to next polygon– If S, S’ overlap in depth and in image plane, swap order and try again
– If S, S’ have been swapped already, split and reinsert
10/29/02 (c) 2002 University of Wisconsin, CS559
Depth Sorting (2)
• Testing for overlaps: Start drawing when first condition is met:– x-extents or y-extents do not overlap
– S is behind the plane of S’
– S’ is in front of the plane of S
– S and S’ do not intersect in the image plane
SS’
S
S’or
z
x
SS’
z
x
SS’
SS’
10/29/02 (c) 2002 University of Wisconsin, CS559
Depth sorting
• Advantages:– Filter anti-aliasing works fine
• Composite in back to front order with a sequence of over operations
– No depth quantization error• Depth comparisons carried out in high-precision view space
• Disadvantages:– Over-rendering– Potentially very large number of splits - (n2) fragments from n
polygons
10/29/02 (c) 2002 University of Wisconsin, CS559
Area Subdivision
• Exploits area coherence: Small areas of an image are likely to be covered by only one polygon
• Three easy cases for determining what’s in front in a given region:1. a polygon is completely in front of
everything else in that region2. no surfaces project to the region3. only one surface is completely inside the
region, overlaps the region, or surrounds the region
10/29/02 (c) 2002 University of Wisconsin, CS559
Warnock’s Area Subdivision(Image Precision)
• Start with whole image• If one of the easy cases is satisfied (previous
slide), draw what’s in front• Otherwise, subdivide the region and recurse• If region is single pixel, choose surface with
smallest depth• Advantages:
– No over-rendering– Anti-aliases well - just recurse deeper to get sub-
pixel information• Disadvantage:
– Tests are quite complex and slow
10/29/02 (c) 2002 University of Wisconsin, CS559
Warnock’s Algorithm• Regions labeled
with case used to classify them:1) One polygon in
front2) Empty3) 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 2 2
2222
2
2
3
3
3
3 33
3
3
3
3
3
333
3
3
1
1 1 11
10/29/02 (c) 2002 University of Wisconsin, CS559
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 algorith
10/29/02 (c) 2002 University of Wisconsin, CS559
BSP-Tree Example
AC
B
2
4
1
3
A
B C
3 2 4 1
-
- -
+
++
10/29/02 (c) 2002 University of Wisconsin, CS559
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
10/29/02 (c) 2002 University of Wisconsin, CS559
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
1
2
3 4
5
6
10/29/02 (c) 2002 University of Wisconsin, CS559
Building Example (1)
1
23b 4b
5
6
1
3a, 4a, 6
2, 3b, 4b, 5
- +
4a3a
10/29/02 (c) 2002 University of Wisconsin, CS559
Building Example (2)
1
23b 4b
5a
6
1
3a, 4a, 6
- +
4a3a
3b, 5b
2
4b, 5a
- +
5b
10/29/02 (c) 2002 University of Wisconsin, CS559
Building Example (3)
1
23b 4b
5a
6
1- +
4a3a
2
4b, 5a
-+
5b
4a, 6
3a+
5b
3b
+
10/29/02 (c) 2002 University of Wisconsin, CS559
Building Example (Done)
1
23b 4b
5a
6
1- +
4a3a
2-
+
5b
3a+
3b
+
4a
6
+
5b
4b
5a
+
10/29/02 (c) 2002 University of Wisconsin, CS559
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
10/29/02 (c) 2002 University of Wisconsin, CS559
BSP-Tree Rendering Example
AC
B
2
4
1
3
A
B C
3 2 4 1
-
- -
+
++
1st
View
2nd3rd 4th
10/29/02 (c) 2002 University of Wisconsin, CS559
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 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
10/29/02 (c) 2002 University of Wisconsin, CS559
Exact Visibility
• An exact visibility algorithm tells you what is visible and only what is visible– No over-rendering– Warnock’s algorithm is an example
• Difficult to achieve efficiently in practice– Small detail objects in an environment make it particularly difficult
• But, in mazes and other simple environments, exact visibility is extremely efficient
10/29/02 (c) 2002 University of Wisconsin, CS559
Cells and Portals
• Assume the world can be broken into cells– Simple shapes– Rooms in a building, for instance
• Define portals to be the transparent boundaries between cells– Doorways between rooms, windows, etc
• In a world like this, can determine exactly which parts of which rooms are visible– Then render visible rooms plus contents
10/29/02 (c) 2002 University of Wisconsin, CS559
Cell and Portal Visibility
• Start in the cell containing the viewer, with the full viewing frustum
• Render the walls of that room and its contents
• Recursively clip the viewing frustum to each portal out of the cell, and call the algorithm on the cell beyond the portal
10/29/02 (c) 2002 University of Wisconsin, CS559
Cell-Portal Example (1)
View
10/29/02 (c) 2002 University of Wisconsin, CS559
Cell-Portal Example (2)
View
10/29/02 (c) 2002 University of Wisconsin, CS559
Cell-Portal Example (3)
View
10/29/02 (c) 2002 University of Wisconsin, CS559
Cell-Portal Example (4)
View
10/29/02 (c) 2002 University of Wisconsin, CS559
Cell-Portal Example (5)
View
10/29/02 (c) 2002 University of Wisconsin, CS559
Cell-Portal Example (6)
View
10/29/02 (c) 2002 University of Wisconsin, CS559
Cell-Portal Operations
• Must clip polygons to the current view frustum (not the original one)– Can be done with additional hardware clipping planes, if you have
them
• Must clip the view frustum to the portal– Easiest to clip portal to frustum, then set frustum to exactly contain
clipped portal
• In Project 2, you implement these things in software, for a 2.5d environment
10/29/02 (c) 2002 University of Wisconsin, CS559
Cell-Portal Properties
• Advantages– Extremely efficient - only looks at cells that are actually visible:
visibility culling
– Easy to modify for approximate visibility - render all of partially visible cells, let depth buffer clean up
– Can handle mirrors as well - flip world about the mirror and pretend mirror is a portal
• Disadvantages– Restricted to environments with good cell/portal structure
10/29/02 (c) 2002 University of Wisconsin, CS559
Rendering a 2.5D Maze (1)
• Assume you are given the following:– Rooms, defined in 2D by the edges that surround
the room
– The height of the ceiling
– Each edge is marked opaque or clear
– For each clear edge, there is a pointer to the thing on the other side
• You know where the viewer is and what the field of view is
– The viewer is given as (cx,cy,cz) position
– The view frustum is given as a direction vector (dx,dy,dz) and an angle for the field of view (cx,cy,cz)
(dx,dy,dz)
10/29/02 (c) 2002 University of Wisconsin, CS559
Rendering a 2.5D Maze (2)
• Work in 2D for the visibility
• Represent the frustum as a left and right clipping line– You don’t have to worry about the top and bottom
– Each clip line starts at the viewer’s position and goes to infinity in the viewing direction
• Write a procedure that clips an edge to the view frustum– This takes a frustum and returns the endpoints of the clipped edge, or
a flag to indicate that the edge is not visible
10/29/02 (c) 2002 University of Wisconsin, CS559
Rendering a 2.5D Maze (3)
• Write a procedure that takes a room and a frustum, and draws the room– Clip each edge to the frustum
– If the edge is visible, draw the wall that the edge represents• Create the 3D wall from the 2d piece of edge
• Project the vertices
• Draw the polygon in 2D
– If the edge is clear, recurse to draw the room through the edge• Use the clipped edge to create a new, clipped frustum
• Call the same procedure with the neighboring room and the clipped frustum
• Draw the floor and ceiling first, because they will be behind everything
10/29/02 (c) 2002 University of Wisconsin, CS559
Where We Stand
• So far we know how to:– Transform between spaces
– Draw polygons
– Decide what’s in front
• Next– Deciding a pixel’s intensity and color
10/29/02 (c) 2002 University of Wisconsin, CS559