Einführung inEinführung inVisual ComputingVisual Computing
186.822
Visible Surface DetectionVisible Surface Detection
Werner Purgathofer
Visibility in the Rendering Pipeline
scene objects in object spaceobject capture/creation
modelingviewing vertex stage
( vertex shader“)g
projection(„vertex shader )
transformed vertices in clip spaceclipping + homogenization
transformed vertices in clip space
scene in normalized device coordinates
viewport transformation
rasterizationshading pixel stage
Werner Purgathofer 1raster image in pixel coordinates
shading p g(„fragment shader“)
3D Display: Wireframe Display
© ZwCAD Software Co.,Ltd
Werner Purgathofer / Computergraphik 1 2
3D Display: Depth Cueing
?= or ?
intensity decreases with i i di tincreasing distance
Werner Purgathofer / Computergraphik 1 3
3D Display: Visibility
visible line and surface identification
= or !
© ZwCAD Software Co.,Ltd
Werner Purgathofer / Computergraphik 1 4
3D Display: Visibility
© Snaptu
Werner Purgathofer / Computergraphik 1 5
3D Display: Depth Cueing + Visibility
only visible linesintensity decreasesintensity decreases with increasing distance
© Gerschon Elber
Werner Purgathofer / Computergraphik 1 6
3D Display: Shaded Display
shading + depth cueing:
Werner Purgathofer / Computergraphik 1 7
Visible-Surface Detection
identifying visible parts of a scene (also hidden-surface elimination)( )type of algorithm depends on:
complexity of scenecomplexity of scenetype of objectsavailable equipmentavailable equipmentstatic or animated displays
object space methodsobject-space methodsobjects compared to each other
i th dimage space methodspoint by point at each pixel location
Werner Purgathofer / Computergraphik 1 8
often sorting and coherence used
Visible-Surface Detection Methods
the following algorithms are examples for different classes of methodsdifferent classes of methods
back-face detectiondepth buffer methodscan-line methodscan line methoddepth-sorting methodarea-subdivision methodoctree methodsray-casting method
Werner Purgathofer / Computergraphik 1 9
Back-Face Detection (1)
surfaces (polygons) with a surface normal pointing away from the eye cannot be visiblepointing away from the eye cannot be visible (back faces)
eliminate them before visibility algorithm !
viewing di ti direction
Werner Purgathofer / Computergraphik 1 10
can be eliminated:
Back-Face Detection (2)
eliminating back faces of closed polyhedraview point (x y z) “inside” a polygon surface ifview point (x,y,z) inside a polygon surface if
Ax + By + Cz + D < 0or polygon with normal N=(A, B, C) is a back face if 0NVface if 0NVview
N = (A B C)N = (A, B, C)
VviewVview
Werner Purgathofer / Computergraphik 1 11
Back-Face Detection (3)
object description in viewing coordinates V (0 0 V )Vview=(0,0,Vz) CVNVview z
sufficient condition: if C 0 then back-face
N = (A B C)yv
zv N = (A, B, C)
Vviewx Vviewxv
Werner Purgathofer / Computergraphik 1 12
Back-Face Detection (4)
complete visibility test for non-overlapping convex polyhedraconvex polyhedra
face partially hidden by other faces
preprocessing step for other objects: about 50% of surfaces eliminated
Werner Purgathofer / Computergraphik 1 13
Depth-Buffer Method (1)
z-buffer methodimage-space methodimage space methodhardware implementationno sorting!no sorting!
Werner Purgathofer / Computergraphik 1 14
Depth-Buffer Method (2)
two buffersdepth buffer (distance information)depth buffer (distance information)refresh buffer (intensity information)
size corresponds to screen resolution(for every pixel: r, g, b, z)
draw something =• compare z with z in buffer• if z closer to viewer• then draw and update z in buffer• else nothing!
Werner Purgathofer / Computergraphik 1 15
• else nothing!
Depth-Buffer Algorithm Example
polygons with corresponding .8 .7corresponding z-values .3 .3
.3 .3
.8 .7
.7 .6 .6 .56 5
.44
back-
.3 .3 .6 .5 .4
imagebackground
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1depth-buffer .3 .3
.8 .7
.7 .6 .3 .7 .6.6.8 .7
.3-1 -1 -1 -1-1 -1 -1 -1
-1 -1 -1 -1-1 -1
-1 -1-1
-1 -1
Werner Purgathofer / Computergraphik 1 16
.3 .3 .3 .3 .6 .5 .4 .3-1 -1 -1 -1 -1 -1 -1 -1
Depth-Buffer Algorithm
for all (x,y)depthBuff(x,y) = -1frameBuff(x,y) = backgroundColorframeBuff(x,y) backgroundColor
for each polygon Pf h iti ( ) l Pfor each position (x,y) on polygon Pcalculate depth zif z > depthBuff(x,y) thendepthBuff(x,y) = zdept u ( ,y)frameBuff(x,y) = surfColor(x,y)
Werner Purgathofer / Computergraphik 1 17
Depth-Buffer: Incremental z-Values
depth at (x,y): z =AxByD
C
depth at (x+1 y):
C
z’ =A(x+1)ByD = z Adepth at (x+1,y): z = C = z
CAx B(y 1) D B
depth at (x,y-1): z” =AxB(y1)D
C = z CB
constants !
Werner Purgathofer / Computergraphik 1 18
Depth-Buffer: y-Coordinate Intervals
determine y-coordinate extents of polygon P
Werner Purgathofer / Computergraphik 1 19
Depth-Buffer: Values down an Edge
z =AxByD
CC
z’ =A(x1/m)B(y1)D
Cx’ = x 1/m
’ 1 z Cy’ = y 1
= z C
A/m + BC
constant !constant !
Werner Purgathofer / Computergraphik 1 20
Scan-Line Method
image-space methodextension of scan line algorithm forextension of scan-line algorithm for polygon filling
Werner Purgathofer / Computergraphik 1 21
Scan-Line Method: Edge & Polygon Tables
edge table (all edges, y-sorted)coordinate endpointsinverse slopepointers into polygon table
polygon table (all polygons)coefficients of plane equationp qintensity information(pointers into edge table)(po te s to edge tab e)
Werner Purgathofer / Computergraphik 1 22
Scan-Line Method: Active Edge List
active edge list (all edges crossing current scanline x sorted flag)current scanline, x-sorted, flag)
Werner Purgathofer / Computergraphik 1 23
Scan-Line Method Example
Edge T. 2,3,1,5,1,1,2,2,5,4,3,3,4,4 Poly.T. , , t d / t l
23
act.edges / act.poly.3,2
1 1
31 51,5,2,1,3,1 , ,
12 1
2 4 2,2,5,3,1,5 , ,
5
23
35
3,3,1,5 ,
3 1 Werner Purgathofer / Computergraphik 1 24
44
3,1
Scan-Line Method Details
coherence between adjacent scan linesincremental calculationsincremental calculationsactive edge list very similar(easy sorting, avoid depth calculations)( y g, p )
intersecting or cyclically overlapping surfaces!
Werner Purgathofer / Computergraphik 1 25
Depth-Sorting Method: Overview
surfaces sorted in order of decreasing depth (viewing in z direction)(viewing in z-direction)
“approximate”-sorting using smallest z-value (greatest depth)fine-tuning to get correct depth orderg g p
surfaces scan converted in orderti b th i i d bj tsorting both in image and object space
scan conversion in image spacescan conversion in image spacealso called “painter’s algorithm”
Werner Purgathofer / Computergraphik 1 26
Depth-Sorting Method: Sorting (1)
surface S with greatest depth is compared to all other surfaces S’compared to all other surfaces S
no depth overlap ordering correctdepth overlap do further tests in
zminS
increasing order of complexity zmaxof complexity max
z´min S´
z´max2 surfaces with no d th l
Werner Purgathofer / Computergraphik 1 27
viewing direction xz
depth overlap
Depth-Sorting Method: Sorting (2)
ordering correct ifbounding rectangles in xy plane do notbounding rectangles in xy-plane do not overlapcheck x-,y-direction separately
viewing direction
S´2 surfaces with depth
overlap but no overlap S
S´
overlap but no overlap in the x-direction
Werner Purgathofer / Computergraphik 1 28
xmin xmax x´min x´maxxz
Depth-Sorting Method: Sorting (3)
ordering correct ifS completely behind S’S completely behind S’substitute vertices of S into equation of S’
overlap in x- and z-directionS
viewing directionS is completely
behind (“inside”) S´behind ( inside )the overlapping S’
S
Werner Purgathofer / Computergraphik 1 29
xz
Depth-Sorting Method: Sorting (4)
ordering correct ifS’ completely in front of SS’ completely in front of Ssubstitute vertices of S’ into equation of S
overlap in x- and z-direction
SS is not completely
viewing direction
S is not completely behind (“inside”) the
overlapping S’S´
overlapping S’
Werner Purgathofer / Computergraphik 1 30
xz
Depth-Sorting Method: Sorting (4)
ordering correct ifS’ completely in front of SS’ completely in front of Ssubstitute vertices of S’ into equation of S
Soverlapping S’ is l t l i f t viewing
directioncompletely in front
(“outside”) of S, but S i t l t l
S´is not completely
behind S’
Werner Purgathofer / Computergraphik 1 31
xz
Depth-Sorting Method: Sorting (5)
ordering correct ifprojections of S S’ in xy plane don’t overlapprojections of S,S’ in xy-plane don’t overlap
surfaces with overlapping bounding rectangles
Werner Purgathofer / Computergraphik 1 32
surfaces with overlapping bounding rectangles
Depth-Sorting Method: Sorting (6)
all five tests fail ordering probably wrongordering probably wronginterchange surfaces S, S’repeat process for reordered surfacesrepeat process for reordered surfaces
SSS´
viewing direction
S´S”
S
xzxz
Werner Purgathofer / Computergraphik 1 33
sorted surface list: S, S’, S” should be reordered: S’, S”, S
surface S has greater depth but obscures S’
Depth-Sorting: Special Cases
avoiding infinite loops due to cyclic overlapreordered surfaces S’ are flaggedreordered surfaces S’ are flaggedif S’ would have to be reordered again
divide S’ into two parts
Werner Purgathofer / Computergraphik 1 34
Area-Subdivision Method (1)
image-space methodarea coherence exploitedarea coherence exploitedviewing area subdivided until visibility d i idecision very easy
Werner Purgathofer / Computergraphik 1 35
Area-Subdivision Method (2)
relationship polygon rectangular view area
inside f
outside f
surrounding f
overlapping f surface surfacesurface surface
only these four possibilities
Werner Purgathofer / Computergraphik 1 36
only these four possibilities
Area-Subdivision Method (3)
all surfaces are outside of viewing areathree easy visibility decisions
all surfaces are outside of viewing areachecking bounding rectangles
only one inside overlapping oronly one inside, overlapping, or surrounding surface is in the area
bounding rectangles for initial checkbounding rectangles for initial checkone surrounding surface obscures all other surfaces within the viewing areasu aces e e g a ea
minimum depth ordering
Werner Purgathofer / Computergraphik 1 37
Area-Subdivision Method (4)
a surrounding obscuring surfacesurfaces ordered according to minimum depthsurfaces ordered according to minimum depthmaximum depth of surrounding surface closest to view plane?test is conservativetest is conservative
viewing direction
zmax
zmin
x
surroundingsurface
Werner Purgathofer / Computergraphik 1 38
xz area
Area-Subdivision Method (5)
if all three tests fail do subdivisionsubdivide area into four equal subareassubdivide area into four equal subareasoutside and surrounding surfaces will remain in this status for all subareassome inside and overlapping surfaces will besome inside and overlapping surfaces will be eliminated
no f rther s bdi ision possible (pi elno further subdivision possible (pixel resolution reached)
sort surfaces and take intensity of nearest surface
Werner Purgathofer / Computergraphik 1 39
su ace
Area-Subdivision Method Example
1 21 23 4
Werner Purgathofer / Computergraphik 1 40
Octree Methods
recursive traversal of octreetraversal order depends on processingtraversal order depends on processing direction
front-to-back: pixel(x y) written oncepixel(x,y) written oncecompletely obscured
d t t dnodes are not traversedback-to-front:
painter’s algorithm viewing direction
Werner Purgathofer / Computergraphik 1 41
Octree Methods
recursive traversal of octreetraversal order depends on processingtraversal order depends on processing direction
viewingfront-to-back:
pixel(x y) written once
viewing direction
pixel(x,y) written oncecompletely obscured
d t t dnodes are not traversedback-to-front:
painter’s algorithm
Werner Purgathofer / Computergraphik 1 42
Ray-Casting Method (1)
line-of-sight of each pixel is intersected with all surfacesall surfacestake closest intersected surface
closest intersectionviewing
Werner Purgathofer / Computergraphik 1 43
intersectionpoint
viewing direction
Ray-Casting Method (2)
based on geometric optics, tracing paths of light rayslight raysbackward tracing of light rayssuitable for complex, curved surfacesspecial case of ray tracing algorithmsspecial case of ray-tracing algorithmsefficient ray-surface intersection techniques necessary
intersection pointintersection pointnormal vector
Werner Purgathofer / Computergraphik 1 44