computer graphics computer graphics
TRANSCRIPT
Computer GraphicsComputer Graphics
Chapter 9Visible Surface Detection MethodsVisible Surface Detection Methods
Somsak Walairacht, Computer Engineering, KMITL
Outline Classification of Visible-Surface Detection Algorithms Back-Face Detection Depth-Buffer Method A-Buffer Method Scan-Line Method Depth-Sorting Method
BSP T M th d BSP-Tree Method Area-Subdivision Method Octree Methods
Ray Casting Method Ray-Casting Method Comparison of Visibility-Detection Methods Wire-Frame Visibility Methods OpenGL Visibility-Detection Functions
01074410 / 13016218 Computer Graphics 2
OpenGL Visibility Detection Functions
Classification of Visible-Surface Detection Algorithms
2 approaches Object-Space Method
Compares objects and parts of objects to each other within the scene
Determine surface as a wholee e e su ace as a o e
Image-Space Method Visibility is decided point by point at each pixel position
on the projection planeon the projection plane
Most visibility-surface algorithms use image-space methods
01074410 / 13016218 Computer Graphics 3
Back-Face Detection A fast and simple object-space method Find the faces on the backs of polyhedral and discard them A point is behind a polygon surface if
Ax + By + Cz + D < 0 Back-face test by considering the direction of the normal vector
for a polygon surfaceA polygon is a back face if A polygon is a back face if
Vview . N > 0
01074410 / 13016218 Computer Graphics 4
Back-Face Detection (2) Right-handed viewing system If object is converted to projection coordinates and
viewing direction is parallel to z axisviewing direction is parallel to zv axis, Only consider the z component of the normal vector N N = (A, B, C)
A l i b k f if C 0 A polygon is back face if C<=0
01074410 / 13016218 Computer Graphics 5
Similarly, left-handed system, back face if C >= 0
Ex. Back-Face Detection
y xviewyview
zview
B(0,3,0)
3 +2 +6 6 0
view
N(3,2,6)
C(0 0 1)
3x+2y+6z -6=0
xz
A(2,0,0)C(0,0,1)
01074410 / 13016218 Computer Graphics 6
z
Back-Face Detection (3) Complete visibility test for nonoverlapping
convex polyhedra
For concave polygon, more test must be carried out to determine whether there are additional faces that are totally or ypartially obscured by other faces
For a general scene, back-face removal For a general scene, back face removal can be expected to eliminate about half of the polygon surfaces in a scene from further visibility tests
01074410 / 13016218 Computer Graphics 7
Depth-Buffer Method Image-space approach
Compares surface depth values throughout avalues throughout a scene from each pixel position on the projection planeplane
Also called the z-buffer method Depth is measured along
the z-axis
01074410 / 13016218 Computer Graphics 8
Depth-Buffer Method (2) 2 buffer areas are required
A depth buffer Stores depth values for each (x, y) position
Frame buffer (Refresh buffer) Frame buffer (Refresh buffer) Stores the surface-color values for each pixel position
Calculated depth is compared with the stored value, if it is less than value in the depth buffer, the new value is stored
Algorithm1. Initialize the depth and frame buffer
depthBuff(x, y) = 1.0, frameBuff(x, y) = backgndColor2. Process each polygon in a scene2. Process each polygon in a scene
For each projected (x, y) pixel, calculate the depth z If z < depthBuff(x, y), compute the surface color
depthBuff(x, y) = z, frameBuff(x, y) = surfColor(x, y)
01074410 / 13016218 Computer Graphics 9
Depth-Buffer Method (3) Calculate the depth of any point on the plane containing the polygon A surface position (x, y) from plane equation
z = (-Ax-By-D)/C Depth z’ of (x+1, y) p ( , y)
z’ = [-A(x+1)-By-D]/C, z’ = z-A/C Depth z’ of (x-1/m, y-1)
z’ = [-A(x-1/m)-B(y-1)-D]/C, z’ = z+(A/m+B)/C Depth z’ of (x, y-1)
’ [ ( ) ]/ ’ /z’ = [-Ax-B(y-1)-D]/C, z’ = z+B/C
01074410 / 13016218 Computer Graphics 10
Scan-Line Method Image-space method Across each scan line, depth calculations are
performed to determine which surface is nearest toperformed to determine which surface is nearest to the view plane at each position
An active list of edges is formed for each scan line Contains only edges that cross the current scan lineContains only edges that cross the current scan line Sorting in order of increasing x A flag for each surface to indicate whether a position along
scan line is inside or outside the surface Process pixel position from left to right
At left intersection, flag is on At right intersection, flag is off
01074410 / 13016218 Computer Graphics 11
Scan-Line Method (2) Scan line 1, active edges:
AB,BC,EH,FG AB-BC, flag S1 on EH-FG, flag S2 on EH FG, flag S2 on
Scan line 2, active edges: AD,EH,BC,FG AD-EH flag S1 on AD EH, flag S1 on EH-BC, flag S1,S2 on
Calculate depth After BC, flag S1 off Flag S2 on until FG
Scan line 3 is same as scan line 2 Coherence along scan lines Same active edges list
01074410 / 13016218 Computer Graphics 12
Same active edges list
Depth-Sorting Method
Using both image-space and object-space operations
Basic functions Surfaces are sorted in order of decreasing depth Surface are scan-converted in order, starting with
the surface of greatest depth
Thi th d i ft f d t i t ’ This method is often referred to painter’s algorithm
Each color layer covers up the previous layer
01074410 / 13016218 Computer Graphics 14
Each color layer covers up the previous layer
Depth-Sorting Method (2) Compare surfaces whether there are any depth overlaps No overlaps, each surface is processed in depth order until all
have been scan-converted If depth overlap is detected, need addition comparisons to
determinez z
Szmax
S
S’z’max
zmax
S’z’max
z’min
zmin S’
z’min
zmin
01074410 / 13016218 Computer Graphics 15
x xNo Depth Overlap Depth Overlap
Depth-Sorting Method (3) Tests for each surface that has a depth overlap with S
1. The bounding rectangles (coordinate extents) in xy directions do not overlapdo not overlap
2. Surface S completely behind the overlapping surface3. The overlapping surface is completely in front of S4 The boundary-edge projections on the view plane do not4. The boundary edge projections on the view plane do not
overlap If one of these test is true, no reordering for S
S is the most distant surface S is the most distant surface S is scan-converted
01074410 / 13016218 Computer Graphics 16
Depth-Sorting Method (4)
12 3
Two surfaces with depth Surface S is completely Overlapping surface S’ is poverlap but no overlap in the x direction
p ybehind the overlapping surface S’
pp gcompletely in front of surface S, but S is not completely behind S’
Two polygon surfaces with overlapping bounding
4
01074410 / 13016218 Computer Graphics 17
rectangles in the xy plane
Depth-Sorting Method (5)
Should all four tests fail for an overlapping surface S’ Interchange surfaces S and S’ in the sorted list
Surface S extends to a greater depth, but it obscures surface S’
Three surfaces that have been entered into the sorted surface list in the
01074410 / 13016218 Computer Graphics 18
obscures surface Sorder S, S’, S’’ should be reordered as S’, S’’, S
BSP-Tree Method
Painting surfaces into frame buffer from back to front – painter’s algorithm
Useful when the view reference point changes, but the objects in a scene are at fixed positions
Visibility testing involves identifying surfaces b hi d i f f h i i i lbehind or in front of the partitioning plane at each step of the space subdivision
01074410 / 13016218 Computer Graphics 19
BSP-Tree Method When BSP tree is complete, process the tree from the
right nodes to the left nodes
01074410 / 13016218 Computer Graphics 20
BSP-Tree Method
5 32
5a5
5b
3front back
13 4
5b2
front back
45b
15a
01074410 / 13016218 Computer Graphics 22
BSP-Tree Method
5 32
5a5
5b
3front back
13 2
front back4
back
415a 5b
01074410 / 13016218 Computer Graphics 23
Area-Subdivision Method Image-space method Take advantage of coherence, by locating
projection areas that represent part of aprojection areas that represent part of a single surface
By successively dividing the total view-l i t ll d llplane area into smaller and smaller
rectangular An easy way is to successively divide the area
i t 4 l t t h tinto 4 equal parts at each step Each rectangular contains the projection of
part of a single visible surface
01074410 / 13016218 Computer Graphics 24
Area-Subdivision Method (2)
First, test if the view is sufficiently complexp Yes, subdivide it
Test to each smaller areas, subdividing , gif a single surface is still uncertain
Continue until subdivisions are easily yanalyzed as belonging to a single surface or reached the resolution limit
01074410 / 13016218 Computer Graphics 25
Area-Subdivision Method (3) Relationship between a surface and an area of the subdivided
view plane Surrounding surface
Completely encloses the area Completely encloses the area Overlapping surface
Partly inside and partly outside the area Inside surface
C l l i id h Completely inside the area Outside surface
Completely outside the area
01074410 / 13016218 Computer Graphics 26
Area-Subdivision Method (4)
Test for determining surface visibility within a rectangular area
No further subdivisions if one of the following conditions is true Condition 1: All surfaces are outside the area Condition 2: An area has only one inside,
overlapping or surroundingoverlapping, or surrounding Condition 3: An area has one surrounding surface
that obscures all other surfaces
01074410 / 13016218 Computer Graphics 27
Area-Subdivision Method (5) Condition 1 test by comparing coordinate extents of
each surfaceCondition 2 usually require intersection tests Condition 2 usually require intersection tests
Condition 3 test by sorting surfaces according to minimum depth from
i lview plane Use plane equation to calculate depth values at four vertices
of the area for all surrounding, inside, overlapping surfacesO f h b id tifi d t id Once a surface has been identified as an outside or surrounding, it will remain in that category for all subdivisions of the area
01074410 / 13016218 Computer Graphics 28
Area-Subdivision Method (6)
As a variation Subdivision along surface Subdivision along surface
boundaries instead of dividing them in half
In general fewer In general, fewer subdivisions are required, but more processing is p gneeded to subdivide and to analyze the relation of surfaces
01074410 / 13016218 Computer Graphics 29
surfaces
Octree Method
When an octree representation is used, visibility testing is done by searching octree nodes in a front-to-back order
Front octants 0,1,2,3 are visible Rear octants 4 5 6 7 are hidden by the front Rear octants 4,5,6,7 are hidden by the front When a color value is encountered, it is
saved only if no previously saved valueO l f t l d Only front colors are saved
01074410 / 13016218 Computer Graphics 30
Octree Method (2) Visibility testing is carried out
with recursive processing of octree nodes and create quadtree representation
Depth-first traversal of the octree, octant 0 is visited b fbefore
Completely obscured nodes are not traversed
Different views of objects, octants are renumbered so that 0,1,2,3 are front nodes
01074410 / 13016218 Computer Graphics 31
Ray-Casting Method Along the line of sight, can determined
which objects intersect this line Method is based on geometric-optics g p
methods, which trace the parts of light rays Trace the light-ray paths backward from the
pixels through the scene Effective method for scenes with curved
surfaces, particularly, spheres Ray casting is a special case of ray-tracing
algorithmsalgorithms Only follow a ray out from each pixel to the
nearest object
01074410 / 13016218 Computer Graphics 32
Comparison of Visibility-Detection Methods Surfaces are widely distributed
Very little depth overlap, few surfaces Depth-sorting or BSP-tree is most efficient
Few overlaps, small number of surfacesScan line or area subdivision is a fast way Scan-line or area-subdivision is a fast way
Several thousand surfaces Scan-line, depth-sorting, or BSP-tree
Few thousand surfaces Depth-sorting or Octree Depth sorting or Octree
Nearly constant with processing time, and independent to number of surfaces Depth-buffer
low performance with simple scenes but high performance for complex scenes Curved surface representations
O Ray-casting or Octree Octree is fast and simple
Only integer additions and subtractions, no sorting or intersection calculations Possible to combine and implement different visible-surface detection methods
Implemented in hardware
01074410 / 13016218 Computer Graphics 33
Implemented in hardware Parallel processing
Wire-Frame Visibility Methods
Apply depth cueing Displayed intensity of a line is a function of its
distance from the viewer
Hidden edges are eliminated or displayed diff tl f th i ibl ddifferently from the visible edges
Methods are also called visible-line detection th d hidd li d t ti th dmethods or hidden-line detection methods
01074410 / 13016218 Computer Graphics 34
Wire-Frame Surface-Visibility Algorithms Compare edge position with the positions of the surfaces in a
scene Same methods used in line-clipping algorithms
Compare edge and surface depth values Compare edge and surface depth values If both projected edge endpoints are behind the surface, edge is
hidden Calculate intersection positions and determine the depth values at
those intersection pointsthose intersection points
01074410 / 13016218 Computer Graphics 35
Wire-frame Depth-Cueing Algorithm Displaying visibility information by vary the
brightness of objects as a function of distance form the viewing positionform the viewing position
Fdepth = (dmax–d) / (dmax–dmin)where d is the distance of a point form the viewing
positionp dmin, dmax can be set to the normalized depth
range 0.0~1.0 Each pixel its color is multiplied by f (d) Each pixel, its color is multiplied by fdepth(d)
Nearer points are displayed with higher intensities Points at maximum depth have intensity = 0
01074410 / 13016218 Computer Graphics 36