Title: 159'235 Graphics
1159.235 Graphics Graphical Programming
- Lecture 26 - Visible Hidden Surface
- Determination
2Hidden Surface Removal
- Inventing renderers led to geometric models, a
call for more realism and therefore lots of
polygons. - All this led to intense interest in finding
efficient algorithms for hidden surface removal. - Some algorithms are more correctly called visible
surface algorithms but the two names are used
interchangeably. - Today well look at several out of many generated
during the period of intense interest (around
late 60s to late 70s).
3Visibility of primitives
- We dont want to waste time rendering primitives
which dont contribute to the final image. - A scene primitive can be invisible for 3 reasons
- Primitive lies outside field of view
- Primitive is back-facing (under certain
conditions) - Primitive is occluded by one or more objects
nearer the viewer - How do we remove these efficiently?
- How do we identify these efficiently?
4The Visibility Problem.
- Two problems remain
- (Clipping we have covered)
- Removal of faces facing away from the viewer.
- Removal of faces obscured by closer objects.
5Visible Surface Algorithms
- Hidden/Visible Surface/Line Elimination/Determinat
ion - Requirements
- Handle diverse set of geometric primitives
- Handle large number of geometric primitives
- Classification Sutherland, Sproull, Schumacher
(1974) - Object Space
- Geometric calculations involving polygons
- Floating point precision Exact
- Often process scene in object order
- Image Space
- Visibility at pixel samples
- Integer precision
- Often process scene in image order
6Back Face Culling
- We saw in modelling, that the vertices of
polyhedra are oriented in an anticlockwise manner
when viewed from outside surface normal N
points out. - Project a polygon.
- Test z component of surface normal. If negative
cull, since normal points away from viewer. - Or if N.V gt 0 we are viewing the back face so
polygon is obscured. - Only works for convex objects without holes, ie.
closed orientable manifolds.
7Back Face Culling
- Back face culling can be applied anywhere in the
pipeline world or eye coords, NDC, image space. - Where is the best point? What portion of the
scene is eliminated, on average? - Depends on application
- If we clip our scene to the view frustrum, then
remove all back-facing polygons are we done? - NO! Most views involve overlapping polygons.
8How de we handle overlapping?
How about drawing the polygons in the right
order so that we get the correct result ( eg.
blue, then green, then peach)? Is it just a
sorting problem ? Yes it is for 2D, but in 3D
we can encounter intersecting polygons or
groups of non-intersecting polygons which form a
cycle where order is impossible (later).
9Simple Z-buffering
- Simple to include in scanline algorithm.
- Interpolate z during scan conversion.
- Maintain a depth (range) image in the frame
buffer (16 or 24 bits common ). - When drawing, compare with the currently stored z
value. - Pixel given intensity of nearest polygon.
10Implementation
- Initialise frame buffer to background colour.
- Initialise depth buffer to z max. value for far
clipping plane, ie. LHCS - Need to calculate value for z for each pixel
- But only for polygons intersecting that pixel.
- Could interpolate from values at vertices.
- Update both frame and depth buffer.
11Determining Depth
- Only one subtraction needed
- Depth coherence.
12Why is z-buffering so popular ?
- Advantage
- Simple to implement in hardware.
- Add additional z interpolator for each primitive.
- Memory for z-buffer is now not expensive
- Diversity of primitives not just polygons.
- Unlimited scene complexity
- Dont need to calculate object-object
intersections. - Disadvantage
- Extra memory and bandwidth
- Waste time drawing hidden objects
- Z-precision Errors
- May have to use point sampling
13Z-compositing
Colour photograph.
Can use depth other than from polygons.
Laser range return.
Reflected laser power
Data courtesy of UNC.
14Ray Casting
- Sometimes referred to as Ray-tracing.
- Involves projecting an imaginary ray from the
centre of projection (the viewers eye) through
the centre of each pixel into the scene.
Scene
Eyepoint
Window
15Computing Ray-Object Intersections
- The heart of ray tracing.
- E.g sphere ( the easiest ! ).
- Expand, substitute for x,y z.
- Gather terms in t.
- Quadratic equation in t.
- Solve for t.
- No roots ray doesnt intersect.
- 1 root ray grazes surface.
- 2 roots ray intersects sphere,
- (entry and exit)
16Ray-Polygon Intersection
- Not so easy !
- Determine whether ray intersects polygons plane.
- Determine whether intersection lies within
polygon. - Easiest to determine (2) with an orthographic
projection onto the nearest axis and the 2D
point-in-polygon test.
z
Ray
x
y
17Ray Casting
- Easy to implement for a variety of primitives
only need a ray-object intersection function. - Pixel adopts colour of nearest intersection.
- Can draw curves and surfaces exactly not just
triangles ! - Can generate new rays inside the scene to
correctly handle visibility with reflections,
refraction etc recursive ray-tracing. - Can be extended to handle global illumination.
- Can perform area-sampling using ray
super-sampling. - But too expensive for real-time applications.
18Examples of Ray-traced images.
19Painters Algorithm (object space)
- Draw surfaces in back to front order nearer
polygons paint over farther ones. - Supports transparency.
- Key issue is order determination.
- Doesnt always work see image at right.
20BSP (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
21BSP Tree
- 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.
22BSP Tree
5
5a
5b
2
- 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.
3
1
4
3
back
front
2
4 5b
front
1
5a
23BSP Tree
- 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.
24BSP Tree
5
2
- 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.
3
1
4
back
5
4
back
Alternate formulation starting at 5
3
front
1
back
2
25Displaying 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.
26BSP 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 dont change very often
in the scene.
27Warnocks Algorithm
- Elegant hybrid of object-space and image-space.
- Uses standard graphics solution- if situation
too complex then subdivide problem. - Start with root window
- If zero or one intersecting, contained or
surrounding polygon then scan convert window - Else subdivide window as quadtree
- Recurse until zero or one polygon, or some set
depth - Depth may be pixel resolution, display nearest
polygon
28Warnocks Example
29Warnock Performance Measure
- Warnocks algorithm
- Screen-space subdivision (screen resolution, r
wh) hybrid object-space image-space algorithm
good for relatively few static primitives,
precise. - Working set size (memory requirement) O(n)
- Storage overhead (over above model) O(n lg r)
- Time to resolve visibility to screen precision
O(nr) - Overdraw (depth complexity how often a typical
pixel is written by rasterization process) none
30BSP Performance Measure
- Tree construction and traversal (object-space
ordering algorithm good for relatively few
static primitives, precise) - Working set size (depends on application) O(1),
O(lg n) - Storage overhead O(n2)
- Time to resolve visibility to screen precision
O(n2) - Overdraw maximum
31Z-buffer Performance
- Brute-force image-space algorithm scores best for
complex scenes not very accurate but is easy to
implement and is very general. - Working set size O(1)
- Storage overhead O(1)
- Time to resolve visibility to screen precision
O(n) - Overdraw maximum
- But even O(n) is now intolerable!
32Example Architectural scenes
Here there can be an enormous amount of occlusion
33Occlusion at various levels
34Cells Portals (object-space)
D
F
- Model scene as a graph
- Nodes Cells (or rooms)
- Edges Portals (or doors)
- Graph gives us
- Potentially visible set
- Superset of visible polygons
- Room to room visibility
- Not a complete solution !
B
C
E
A
G
35Example Application Quake game engine
- Calculates visibility separately for environment
and objects. - Environment
- Use portals to determine potentially visible set
- Use BSP-tree to order polygons front-back.
- Scan-convert polygons maintaining order.
36Example Quake Game Engine
- Scan converting polygons
- Maintain front-back ordering.
- Use visibility mask on scanline.
F
- - Create active edge list for polygons F B.
- - Write in front-back order.
- Mask values once written to buffer.
- Write colour to framebuffer
- - Write z to z-buffer
Scanline
B
37Example Quake Game Engine
- Calculates visibility separately for environment
and objects. - Environment
- Use portals to determine potentially visible set
- Use BSP-tree to order polygons front-back.
- Scan-convert polygons maintaining order.
- Maintain colour and z buffers.
- Objects.
- Use Z-buffer from environment stage.
38Other Applications
- Outdoor environments
- Urban regions, forests, natural scenes in general
- Or very complex assemblies mechanical CAD parts
(Boeing 777 engine block) - Molecular visualization
- Very hard and still not solved problem
39Z-Buffer BSP Not Only Approaches
- Other approaches
- Depth sort Newell, Newell Sancha
- Scan-line algorithms
- Weiler-Atherton subdivision on polygon edges
40Visible Surfaces - Summary
- Visible and Hidden Surfaces
- Z-Buffering
- BSP
- Acknowledgments - thanks to Eric McKenzie,
Edinburgh, from whose Graphics Course some of
these slides were adapted.