ITCS 4120-Visible-Surface Detection
ITCS 4120-Visible-Surface Detection
Copyright 2006, Zachary Wartell at University of North Carolina. All rights reserved. Revision 1.3
Textbook: Chapter 9
Zachary Wartell 11/9/2013
Back-Face Culling
Used to remove unseen polygons from convex, closed polyhedron (Cube, Sphere) Does not completely solve hidden surface problem since one polyhedron may obscure another
11/9/2013
N zview xview
zview
PRP
Zachary Wartell
11/9/2013
Depth-Buffer Method
Recall Slide: ITCS 4120-3D Viewing.ppt # 51-53, 3D3D collineation on cube
Zachary Wartell
11/9/2013
Depth-Buffer Algorithm
1. Initialize depth buffer and frame buffer for all pixels (x,y)
depthBuffer(x,y) = 1.0; frameBuffer(x,y)=BackgroundColor
2. Process each polygon face, F, in scene For each projected pixel, P, at location (x,y) in F, calculate the depth z If z < depthBuffer(x,y), compute surface color, C, at the pixel P, so set: depthBuffer(x,y) = z; frameBuffer(x,y)=C Note: After all surfaces are processed, depth buffer contains depth for visible surfaces and frame buffer contains corresponding color values for those surfaces
Zachary Wartell 11/9/2013
Computing z
(x1,y1,z1)
After M3dscr{obliquepers,oblique} you have vertices: {(xi,yi,zi )} (xl,yl,zl) Generally to compute z: Ax By D z C Incremental in x:
(x3,y3,z3)
(xr,yr,zr) (x,y,z)
A( x 1) By D z A/C C
(x2,y2,z2)
Incremental in y:
x x 1/ m So: z z A/ m B C or z z B / C , if m=
Zachary Wartell
11/9/2013
A-Buffer Method
accumulation buffer buffer accumulates multiple pieces of information for each pixel in addition to depth for transparency or anti-aliasing (high-end movies, etc.). A-buffer element stores: Depth Field : real-number Surface Data Field (SDF): stores surface data or pointer
When Depth >= 0: -real-number is depth of surface at pixel -SDF is surface color and pixel coverage percentage
depth 0 RGB & Other Info 48%
Zachary Wartell 11/9/2013
Pixel 44%
A-Buffer Method
When Depth < 0: -SDF is pointer to linked list of elements that store: -RGB intensity
-opacity
-depth -pixel coverage percentage -surface ID -other surface rendering parameters
Depth < 0
Zachary Wartell
11/9/2013
Scan-Line Method
Unlike z-buffer or A-buffer, scan-line method has depth info only for a single scan-line. In order to require one scan-line of depth values, we must group and process all polygons intersecting a given scan-line at the same time before process the next scan-line Build table of edges of all polygons in scene. Maintain active-edgetable as we visit each scan-line in scene. AET now contains edges for all polygons at that scanline. Must maintain flag for each surface to determine whether pixel on scan-line is inside that surface.
scan-line
Zachary Wartell
11/9/2013
Scan Line 2:
(A,D) to (E,H) only inside S1, so color from S1 (E,H) to (B,C) inside S1 and S2 , so compute & test depth In this example we color from S1 (B,C) to (F,G) only inside S2, so color from S2
B E F A S1 S2 C Scan Line 1 Scan Line 2 Scan Line 3
Zachary Wartell
11/9/2013
Zachary Wartell
11/9/2013
Depth-Sorting Method
Painters Algorithm Approach: sorted surfaces by increasing depth may require surface splitting scan-convert surfaces in sorted order (back to front) Use a sequence of sorting steps and tests of increasing computational complexity to handle all possible cases of polygon depth orderings
Zachary Wartell
11/9/2013
zmin2 zmax2
For all Si ,i [2, N] If farthest surface SF has no z overlap render it. (easy case) If there is z overlap with SF, we can still avoid reordering if one of four conditions holds. So we test these conditions
Zachary Wartell 11/9/2013
2)
3)
Sf S2
Sf
S2 z
11/9/2013
Zachary Wartell
11/9/2013
S
If 1-4 fail, we swap Sf and S. Sf
z first swap S S'', but S'' occludes S' so swap S' and S'' to get final order S', S'',S
Zachary Wartell
11/9/2013
Zachary Wartell
11/9/2013
BSP-trees
Binary Space Partition
eyepoint is a relatively easy way to sort the polygons relative to the
11/9/2013
BSP-Tree Example
+Z
C A
+X
-X
11/9/2013
Traversing BSP-Tree
Traverse the BSP tree such that the branch descended first is the side that is away from the eyepoint. This can be determined by substituting the eye point into the plane equation for the polygon at the root. When there is no first branch to descend, or that branch has been completed then render the polygon at this node. After the current node's polygon has been rendered, descend the branch that is closer to the eyepoint.
11/9/2013
E1
F1 C E2 A
F1
E2
D
F2
E1 B
+X EYE 2
-X
11/9/2013
Splitting Triangles
If all our polygons are triangles then we always divide a triangle into more triangles when it is intersected by the plane.
It is possible for the number of triangles to increase exponentially but in practice it is found that the increase may be as small as two fold. A heuristic to help minimize the number of fractures is to enter the triangles into the tree in order from largest to smallest.
11/9/2013
Area-Subdivision Method
Recursively subdivide viewplane into quadrants until: rectangle contains part of 1 projected surface rectangle contains part of no surface rectangle is size of pixel
Zachary Wartell
11/9/2013
Area-Subdivision Method
We need tests that can quickly determine tell if current area is part of one surface or if further subdivision is needed. Four cases for relation between surface and rectangular area:
surrounding surface
overlapping surface
inside surface
outside surface
Zachary Wartell
11/9/2013
Testing Condition 3
sort surfaces on minimum depth from view plane for each surrounding surface for current rectangle compute maximum depth within rectangle subsection If maximum depth of a surrounding surface is closer to view plane than the minimum depths of all other surfaces within the area, condition 3 is achieved (i.e. surrounding surface occludes all others).
zmax
area
z
Zachary Wartell
11/9/2013
Zachary Wartell
11/9/2013
Ray-Casting Method
based geometric optics method that trace rays of light backwards light path tracing compare to depth buffer (surfaces to pixels versus pixel to surfaces) special case of ray-tracing
view plane
pixel
COP
Zachary Wartell
11/9/2013
Octrees
Octree: partitions 3-space by a regular, recursive subdivision of 3-space into axis-aligned boxes 3D objects are stored in the octree node that contains them. Recursively subdivide until each octree node is either empty, a homogeneous volume, or contains single object thats easy to compute visibility (example can use back-face culling alone).
0 7
1 6
0 1 2 3 4 5 6 7
Octrees: Rendering
Given a particular view, the octants can be ordered in view depth order. The order is the same for octants at all levels in the recursive subdivision. For general perspective viewing, traverse the octree in back-to-front order and render contents of each node (nearer objects pixels overwrite farther objects pixels). For parallel projections with view planes parallel to octant faces, render front-to-back using a quadtree subdivision of the display window to record when a object has been drawn onto a region of the window.
view frustum
6 7
3 2
Zachary Wartell
11/9/2013
Zachary Wartell
11/9/2013
Direct approach requires testing each line segment against each surface. Must work with projected coordinates of segment and surface boundaries. Hidden edges can be removed or drawn with dashes
end points inside & behind end points inside & infront end points inside & infront & behind end points outside & behind at boundary end points outside & behind & infront at boundary
Zachary Wartell
11/9/2013
f depth (d )
d is distance of point from view position d max , d min application dependent. Often [0.0,1.0] in normalized coordinates
Color of point is multiplied by fdepth(d) Additionally we could simulate atmospheric effects (smog/haze) where farther pixels are paler in color
Zachary Wartell
11/9/2013
OpenGL Visibility
Back-face removal
glFrontFace(ff); // ff {GL_CW,GL_CCW} glEnable(GL_CULL_FACE); glCullFace(mode); // mode {GL_BACK,GL_FRONT, GL_FRONT_AND_BACK}
Depth-Buffer
- tell GUI library to allocated depth-buffer for graphics windows
- glClear (GL_DEPTH_BUFFER_BIT)
-glEnabled (GL_DEPTH_TEST) -glClearDepth (maxDepth); // maxDepth [0.0,1.0] -glDepthRange (nearNormDepth,farNormDepth) //nearNormDepth [0.0,1.0], farNormDepth [0.0,1.0] -glDepthFunc (testCondition) //testCondition{GL_LESS,GL_GREATER,GL_EQUAL,GL_NOTEQUAL, // GL_LEQUAL,GLGEQUAL,GL_NEVER,GL_ALWAYS}
Zachary Wartell 11/9/2013
Depth-Cueing
glEnable (GL_FOG) glFogi (GL_FOG_MODE,GL_LINEAR) glFogf (GL_FOG_START, minDepth) glFogf (GL_FOG_END, maxDepth)
Zachary Wartell
11/9/2013
Revisions
Revision 1.2 Integrated BSP and Depth Buffer slides from Hodges and Kessler Revision 1.3 - typos
Zachary Wartell
11/9/2013