Sie sind auf Seite 1von 38

Computer Graphics

Chapter 9
Visible 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
BSP-Tree
M
Method
th d
Area-Subdivision Method
Octree Methods
Ray Casting Method
Ray-Casting
Comparison of Visibility-Detection Methods
Wire-Frame Visibility Methods
OpenGL Visibility
Visibility-Detection
Detection Functions

01074410 / 13016218 Computer Graphics

Classification of VisibleSurface Detection Algorithms

2 approaches

Object-Space Method

Image-Space Method

Compares objects and parts of objects to each other


within the scene
Determine
ee
e su
surface
ace as a whole
oe
Visibility is decided point by point at each pixel position
on the projection plane

Most visibility-surface algorithms use image-space


methods

01074410 / 13016218 Computer Graphics

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 surface
A polygon is a back face if
Vview . N > 0

01074410 / 13016218 Computer Graphics

Back-Face Detection (2)

Right-handed viewing system


If object is converted to projection coordinates and
viewing direction is parallel to zv axis,
axis

Only consider the z component of the normal vector N


N = (A, B, C)

A polygon
l
is
i back
b k face
f
if C<=0
C 0

Similarly, left-handed system, back face if C >= 0

01074410 / 13016218 Computer Graphics

Ex. Back-Face Detection


yview

xview
zview

N(3,2,6)

B(0,3,0)
3 +2 +6 -6=0
3x+2y+6z
6 0

C(0 0 1)
C(0,0,1)
z
01074410 / 13016218 Computer Graphics

A(2,0,0)
x
6

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 totallyy or
partially obscured by other faces
For a general scene, back-face
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

Depth-Buffer Method

Image-space approach

Compares surface depth


values throughout a
scene from each pixel
position on the projection
plane

Also called the z-buffer


method

Depth is measured along


the z-axis

01074410 / 13016218 Computer Graphics

Depth-Buffer Method (2)

2 buffer areas are required

A depth buffer

Frame buffer (Refresh buffer)

Stores depth values for each (x, y) position


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
Algorithm
1.

Initialize the depth and frame buffer

2.

depthBuff(x, y) = 1.0, frameBuff(x, y) = backgndColor

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

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
p z of (x+1,
(
, y)

z = [-A(x+1)-By-D]/C,

z = z-A/C

z = [-A(x-1/m)-B(y-1)-D]/C,

z = z+(A/m+B)/C

z = [-Ax-B(y-1)-D]/C,
[
( ) ]/

z = z+B/C
/

Depth z of (x-1/m, y-1)


Depth z of (x, y-1)

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 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 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,
EH
FG, flag S2 on

Scan line 2, active edges:


AD,EH,BC,FG

AD EH, flag S1 on
AD-EH
EH-BC, flag S1,S2 on

Scan line 3 is same as scan line 2

01074410 / 13016218 Computer Graphics

Calculate depth
After BC, flag S1 off
Flag S2 on until FG

Coherence along scan lines


Same active edges list

12

Scan-Line Method (3)

01074410 / 13016218 Computer Graphics

13

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

This method
Thi
th d is
i often
ft referred
f
d to
t painters
i t
algorithm

Each color layer covers up the previous layer

01074410 / 13016218 Computer Graphics

14

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
determine
z
zmax

z
zmax

S
zmax

zmin
zmax

zmin

zmin

zmin
No Depth Overlap

01074410 / 13016218 Computer Graphics

Depth Overlap

x
15

Depth-Sorting Method (3)

Tests for each surface that has a depth overlap with S


1.
2.
3.
4
4.

The bounding rectangles (coordinate extents) in xy directions


do not overlap
Surface S completely behind the overlapping surface
The overlapping surface is completely in front of S
The boundary
boundary-edge
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 scan-converted

01074410 / 13016218 Computer Graphics

16

Depth-Sorting Method (4)


1

Two surfaces with depth


p
overlap but no overlap in
the x direction

4
01074410 / 13016218 Computer Graphics

Surface S is completely
p
y
behind the overlapping
surface S

Overlapping
pp g surface S is
completely in front of
surface S, but S is not
completely behind S

Two polygon surfaces with


overlapping bounding
rectangles in the xy plane
17

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
S
01074410 / 13016218 Computer Graphics

Three surfaces that have


been entered into the
sorted surface list in the
order S, S, S should be
reordered as S, S, S

18

BSP-Tree Method

Painting surfaces into frame buffer from back


to front painters 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 or in
behind
i front
f
off the
h partitioning
i i i plane
l
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

5a

5
5b

3
1
4

01074410 / 13016218 Computer Graphics

1
2
5a

4
5b

21

BSP-Tree Method

5a

back

front
5b

3
front

1
4

01074410 / 13016218 Computer Graphics

5a

back

4
5b

1
22

BSP-Tree Method

5a

back

front
5b

3
front

1
4

01074410 / 13016218 Computer Graphics

5a

back

back

5b
23

Area-Subdivision Method

Image-space method
Take advantage of coherence, by locating
projection areas that represent part of a
single surface
By successively dividing the total viewplane
l
area into
i t smaller
ll and
d smaller
ll
rectangular

An easy way is to successively divide the area


i t 4 equall parts
into
t att each
h step
t

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


p
complex

Yes, subdivide it

Test to each smaller areas,, subdividing


g
if a single surface is still uncertain
Continue until subdivisions are easilyy
analyzed 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

Overlapping surface

Partly inside and partly outside the area

Inside surface

Completely encloses the area

C
Completely
l l inside
i id the
h 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 surrounding
overlapping,
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 surface
Condition 2 usually require intersection tests
Condition 3

test by sorting surfaces according to minimum depth from


view
i
plane
l
Use plane equation to calculate depth values at four vertices
of the area for all surrounding, inside, overlapping surfaces

Once a surface
O
f
has
h been
b
identified
id tifi d as an outside
t id 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


boundaries instead of dividing
them in half

In general,
general fewer
subdivisions are required,
but more p
processing
g is
needed to subdivide and to
analyze the relation of
surfaces

01074410 / 13016218 Computer Graphics

29

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
4 5 6 7 are hidden by the front
When a color value is encountered, it is
saved only if no previously saved value

O l front
f t colors
l
d
Only
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 f
before
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
algorithms

Only follow a ray out from each pixel to the


nearest object

01074410 / 13016218 Computer Graphics

32

Comparison of VisibilityDetection Methods

Surfaces are widely distributed

Very little depth overlap, few surfaces

Few overlaps, small number of surfaces

Scan-line, depth-sorting, or BSP-tree

Few thousand surfaces

Depth-sorting
Depth
sorting or Octree

Nearly constant with processing time, and independent to number of surfaces

Depth-buffer

Ray-casting or Octree
O

Octree is fast and simple

low performance with simple scenes but high performance for complex scenes

Curved surface representations

Scan line or area


Scan-line
area-subdivision
subdivision is a fast way

Several thousand surfaces

Depth-sorting or BSP-tree is most efficient

Only integer additions and subtractions, no sorting or intersection calculations

Possible to combine and implement different visible-surface detection methods

Implemented in hardware
Parallel processing

01074410 / 13016218 Computer Graphics

33

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
differently
tl from
f
th
the visible
i ibl edges
d
Methods are also called visible-line detection
methods
th d or hidden-line
hidd li detection
d t ti methods
th d

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

If both projected edge endpoints are behind the surface, edge is


hidden
Calculate intersection positions and determine the depth values at
those 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 position
Fdepth = (dmaxd) / (dmaxdmin)
where d is the distance of a point form the viewing
p
position

dmin, dmax can be set to the normalized depth


range 0.0~1.0
Each pixel,
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

OpenGL Visibility-Detection
Functions

01074410 / 13016218 Computer Graphics

37

End of Chapter 9

01074410 / 13016218 Computer Graphics

38

Das könnte Ihnen auch gefallen