You are on page 1of 52

VISIBLESURFACE

DETECTION
The problem of Visibility – Occlusion.
Problem Definition:
Given a set of 3-D surfaces to be
projected onto a 2-D screen, obtain the
nearest surface corresponding to any point
on the screen.

Two types of methods used:

• Object-space methods (Continuous):


Compares parts of objects to each other
to determine which surfaces should be labeled
as visible (use of bounding boxes, and check
limits along each direction).
Order the surfaces being drawn, such
that it provides the correct impression of
depth variations and positions.

Image Space methods (discrete):


Visibility is decided point by point at
each pixel position on the projection plane.
Screen resolution can be a limitation.

Hidden Surface – (a) Surface for


rendering
or
(b) Line drawing
Coherence properties:
• Object Coherence – If one object is
entirely separate from another, do not
compare.

• Face Coherence – smooth variations across a


face; incrementally modify.

• Edge Coherence – Visibility changes if


a edge crosses behind a visible face.

• Implied edge coherence – Line of


intersection of a planar face penetrating
another, can be obtained from two points on
the intersection.
• Scanline coherence – Successive lines have
similar spans.

• Area Coherence – Span of adjacent group


of pixels is often covered by the same
visible face.

• Depth Coherence – Use difference equation


to estimate depths of nearby points on the
same surface.

• Frame Coherence – Pictures of two


successive frames of an animation
sequence are quite similar (small changes
in object and viewpoint).
Different Visible Surface
Detection Methods:

• Back-face Detection
• Depth (Z) buffer method
• Scan-line method
• Depth-sorting method
• Area-subdivision method
• Octree methods
• A-buffer method
• BSP Trees
• Ray casting method

Visible surface techniques are 3D


versions of sorting algorithms
– basically compare depth.
Back face Culling or removal
A Polygon (in 3D) is a back face if:
V.N > 0.

Let V = (0, 0, Vz) and N = Ai + Bj +

Ck. Then V.N = Vz.C;

Let Vz be +ve (view along +ve Z-direction),

Check the sign of C.

Condition of back face is thus:


sgn(C) > 0.
What happens if
V. N = 0 ??
N V

V
How to get normal vector (N) for a
3D surface, polygon ?
R Q

R=PXQ 
P

-R

Order of vertices for calculation


of N – w.r.t the front side of the
surface.

Brighter Darker
Side side
Take the order of vertices to be
counter-clockwise for the brighter side.

Take the case of a cube:

Exterior faces of a cube:


You can choose any two vectors (edges)
to obtain the normal to the surface.

Any risks in such a case, if we randomly


choose any two vectors?
Better Solution to obtain the direction
cosines of N:
n

Assume Yj )(Zi  Z j )


a   (Yi
n vertices 1
in
of the Z j )(Xi  X j ) where j  i 
polygon:
b n (Z i 1
(Xi, Yi, Zi);
c 
i 1 (X i X j )(Yi Yj
i=1,2, i 1
…,n. )

Comp If i  n, j 
n
Yj )(Zi  Z j )
a
i 1 (Yi
n

b   (Z i Z j )(Xi  X j ) where j  i 
in
1
1
X j )(Yi  Y j )
i

c   (XIf
1
i i j1
n,
Take the expression of “c”:
Can you relate that to one property of
the 2-D polygon in X-Y plane?
a, b and c also describe the projection
surface of the polygon on the Y-Z, Z-X
and X-Y planes (or along the X, Y and Z
axis) respectively.
c  (X1X2)(Y1Y2)  (X2X3)(Y2Y3) 
 3XX
(X 1 (Y
1 )(Y
2 Y
3 Y
3 )X
1 ) 2(Y3Y1)X3(Y1Y2)
If A is the total area of the polygon, the
projected areas are:

AYZ = a/2; AXZ = b/2; AXY = c/2;

The surface normal appears to be


pointing outwards. Facing towards the viewer,
the edges of the polygon appears to be drawn
counter-clockwise.
The polygon is a back face, if c > 0

If the view direction is along the –ve Z-


direction, the above condition becomes:
c<0
Drawbacks of back face culling:

• Partially hidden faces cannot be


determined by this method

• Not useful for ray tracing, or


photometry/ radiosity.

However, this is still


useful as a pre-processing
step, as almost 50% of the
surfaces are eliminated.
Depth-buffer
or
Z-buffer
method

COP
Each (X,Y,Z) point on a polygon
surface, corresponds to the orthographic
projection point (X, Y) on the view plane.

At each point (X, Y) on the PP,


object depths are compared by using
the depth(Z) values.
Assume normalized coordinates:

(FCP) Zmax > Z > 0 (BCP), where Zmax = 1.

Two buffer areas are used:

(i) Depth (Z) buffer: To store the depth


values for each (X, Y) position, as
surfaces are processed.

(ii) Refresh Buffer: To store the


intensity
value at each position (X, Y).
Depth-buffer
or
Z-buffer
method

COP
Steps for Processing:
(a) Initialize
depth(X,Y)  Zmax
(X,Y) refresh(X,Y)  I
IB = background B

intensity
(b) For each position on each polygon surface:

(i) Calculate depth Z for each position


(X, Y) on the polygon.

(ii) If Z < depth(X, Y) then

depth (X, Y) = Z;

refresh (X, Y) = Is (X, Y)


Is is the projected intensity value of the
surface at position (X, Y), which has the
minimum value of Z, at the current stage of
iteration.
Equation of thesurface:
AX  BY  CZ D  0;
Calculation of Z:
 AX BY 
Z
D
Equation for Z at the next scan line:
C
Remember scanline/Polyfill algorithm?
Using edge coherence, we get for the next
scanline (Y+1):
X’ = X -1/m;
Y
Y-1

X X+1

Z X −C
Z X 1 
A
; A
B
Z m ;
Z Y 1  Y C
For a vertical edge: Z’ = Z + B/C;
So to implement the algorithm, three
constants are required for each surface:

A
( m B)
B
C , C , C
A

What is the special condition, C = 0?


Using the above three constants, we can
keep calculating the successive depth values
along and for successive scanlines. Similar
approaches can be used for curved surfaces:
Z = f(X, Y).
Z-Buffer Algo:
for all (x,y)
depth(x,y) = -∞ /* Watch this
change */
refresh(x,y) = IB

for each polygon P


for each position (x,y) on polygon P
calculate depth z

if z > depth(x,y) then


1. depth(x,y) = z
2. refresh(x,y) = IP(x,y)

Lets take an example 


Z-values of the 4 4 9 8 7 6 5
coordinates: 4 4 8 7 7 6 5

4 4
4 4
Z-Buffer
values
9 8 9 8
8 7 4 7 8 7 4
4 7 6 5 4
Z-values of the 4 4 9 8 7 6 5
coordinates: 4 4 8 7 7 6 5

9 8
7 8 7 4
7 6 5 4

Z-Buffer
values
IMAGES (after pseudo-texture rendering)
V
V
Case Studies – examples of

Area Sub-division method


(i) (ii)

(iii) (iv)
BSP (Binary Space Partition) trees
P1
P2 C

A
D
P1

B BP F B
FP
FP
BP
P2F P2B
F B B
BSP (Binary Space F
A C B D
Partition) trees
Salient features:

• Identify surfaces that are inside/front


and outside/back w.r.t. the partitioning
plane at each step of the space division,
relative to the viewing direction.

• Start with any plane and find one set


of objects behind and the rest in the
front.

• In the tree, the objects are represented as


terminal nodes with front objects as left
branches and back objects as right
branches.
• BSP tree’s root is a polygon selected
from those to be displayed.

• One polygon each from the root polygon’s


front and back half plane, becomes its front
and back children

• The algorithm terminates when each node


contains only a single polygon.

• Intersection and sorting at object


space/ precision
3
5a 5 2 4
2 5b
5b 5a 1
1
3
4

5a 5
2
3 5b
1 3
4
1 4
2
5b
5a
5
4
5a 5
2
3
5b
1 1
3 2
4

5
2
3
1 3
2 4 4

5a 1 5b
5a
5
2
V
5b 3
1
3 5b
4 2

1 5a 4
Also see:
Other applications:
potential visibility sets;
• Robot navigation
KD trees, R+-trees;
• Collision Detecion
Bounding Volume Hierarchy (BVH)
• GIS
and
Shadow Volume BSP Tree (SVBSP) • Image Registration
Display list of a BSP tree
• BSP tree may be traversed in a “modified in-
order tree” walk to yield a correctly
priority- ordered polygon list for an
arbitrary viewpoint.
• If the viewer is in the root polygon’s front
half space, the algorithm must first display:
1.All polygons in the root’s rear half-
space.
2.Then the root.
3.And finally all polygons in the front
half-space.
• Use back face culling
• Each of the root’s children is
recursively processed.
Disadvantages

– more polygon splitting may occur than


in Painter's algorithm

– appropriate partitioning hyperplane


selection is quite complicated and
difficult

Finding Optimal BSP:

Finding an optimal root node is by testing a small


number of candidates.

The node that results in the smallest number of


nodes in the BSP tree should be chosen
Back-Face
Detection
A point  x, y, z  is behind a polygon surface if Ax  By  Cz  D 
0, where A, B, C and D are the plane parameters of the polygon.
Test is simplified by considering normal of face and viewing
direction.

Vview
N   A, B, C 

A polygon is back face if Vview N  0. In a right-handed


viewing system viewing direction is along negative z axis,

Vview   0, 0, 1 . Then, a polygon is a back face if C 


May 2012
0.
Depth-Buffer
Methods
S3
S2 view plane
S1 yv
xv

 x, y 
zv

Three surfaces overlapping pixel position (x,y) on the view plane. Th


visible surface, S1, has the smallest depth value.

May 2012
Z - Buffer
Algorithm
Initialize each pixel (x, y) of depth buffer and frame buffer (color):

depthBuf  x, y   1.0; // Z is normalized to [0,1.0]

frameBuf  x, y   background color; // initialize to

background for each polygon { // traverse all polygons

for each pixel  x, y  polygon { // rasterization

if (z  x, y   depthBuf  x, y  ) { // check closer

pixel get (compute) color  x, y  ; // compute color

May 2012
of pixel
Efficient Depth
Calculation
Given the depth value in a vertex of a polygon, the depth of any
other point in the plane containing the polygon can be
calculated efficiently (additions only).

Depth is calculated from plane equatuion z    Ax  By  D 

. At rasterization x along scan-line changes by 1. Therefore,

z  x 1   A x 1  By  D C  z  A C, and the ratio


A
May C
2012
BSP-trees
Binary Space Partition is a relatively easy way to sort the polygons
relative to the eyepoint

To Build a BSP Tree


1. Choose a polygon, T, and compute the equation of the plane it defines.

2. Test all the vertices of all the other polygons to determine if they are in front of, behind, or in
the same plane as T. If the plane intersects a polygon, divide the polygon at the plane.

3. Polygons are placed into a binary search tree with T as the root.

4. Call the procedure recursively on the left and right subtree.


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
oint.
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 08/04/15



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 overlapping inside outside


surface surface surface
surface

©Zachary Wartell 08/04/15


Area-Subdivision: Stopping Conditions

• Recursive subdivision can stop when either:


1) a rectangle has all surfaces outside
2)a rectangle has exactly one inside, overlapping, or
surrounding surface
3)a rectangle has one surrounding surface and the
surface occludes all other surfaces in the area
• For efficiency:
– compare rectangle to projected surface bounding
rectangle first.Only perform exact interaction
test if necessary. If single bounding rect.
intersects rectangle, test for exact intersection
and color the framebuffer for the intersection of

You might also like