You are on page 1of 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-Tree M th d BSP T Method Area-Subdivision Method Octree Methods Ray-Casting Ray Casting Method Comparison of Visibility-Detection Methods Wire-Frame Visibility Methods OpenGL Visibility Detection Functions Visibility-Detection
2

01074410 / 13016218 Computer Graphics

Classification of VisibleSurface Detection Algorithms

2 approaches

Object-Space Method

Compares objects and parts of objects to each other within the scene Determine su ace as a whole ee e surface oe Visibility is decided point by point at each pixel position on the projection plane

Image-Space Method

Most visibility-surface algorithms use image-space methods


3

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 is back face if C<=0 l i b kf C 0

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


5

01074410 / 13016218 Computer Graphics

Ex. Back-Face Detection


y N(3,2,6) B(0,3,0) 3x+2y+6z 6 0 3 +2 +6 -6=0 C(0 0 1) C(0,0,1) z
01074410 / 13016218 Computer Graphics

yview

xview zview

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 totally or y partially obscured by other faces For a general scene, back-face removal back face can be expected to eliminate about half of the polygon surfaces in a scene from further visibility tests
7

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.

Process each polygon in a scene


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

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 Depth z of (x+1, y) p ( ,
z = (-Ax-By-D)/C z = [-A(x+1)-By-D]/C, z = z-A/C z = z+(A/m+B)/C z = z+B/C /

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


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

z = [-A(x-1/m)-B(y-1)-D]/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 to the view plane at each position An active list of edges is formed for each scan line

Process pixel position from left to right


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 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, 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

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 Thi method is often referred to painters th d i ft f dt i t algorithm

Each color layer covers up the previous layer


14

01074410 / 13016218 Computer Graphics

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 S zmax S zmax zmin zmax zmin No Depth Overlap x S zmin zmin Depth Overlap x
15

01074410 / 13016218 Computer Graphics

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 edge projections on the view plane do not boundary-edge overlap S is the most distant surface S is scan-converted

If one of these test is true, no reordering for S


01074410 / 13016218 Computer Graphics

16

Depth-Sorting Method (4)


1 2 3

Two surfaces with depth p overlap but no overlap in the x direction

Surface S is completely p y behind the overlapping surface S

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

4
01074410 / 13016218 Computer Graphics

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 S obscures surface 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 behind b hi d or in front of the partitioning plane at i f f h ii i l each step of the space subdivision
19

01074410 / 13016218 Computer Graphics

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 5b 3 1 4

5a

3 1 2 5a 4 5b

01074410 / 13016218 Computer Graphics

21

BSP-Tree Method
5 front 5b 3 1 4 front

5a

3
back

back

4 5b

5a

1
22

01074410 / 13016218 Computer Graphics

BSP-Tree Method
5 front 5b 3 1 4 front

5a

3
back

back

back

5a

5b
23

01074410 / 13016218 Computer Graphics

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 area into smaller and smaller l i t ll d ll rectangular

An easy way is to successively divide the area into i t 4 equal parts at each step l t t h t

Each rectangular contains the projection of part of a single visible surface


24

01074410 / 13016218 Computer Graphics

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 easily y analyzed as belonging to a single surface or reached the resolution limit
25

01074410 / 13016218 Computer Graphics

Area-Subdivision Method (3)

Relationship between a surface and an area of the subdivided view plane

Surrounding surface

Overlapping surface

Completely encloses the area Partly inside and partly outside the area Completely inside the area C l l i id h Completely outside the area

Inside surface

Outside surface

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, overlapping or surrounding Condition 3: An area has one surrounding surface that obscures all other surfaces
27

01074410 / 13016218 Computer Graphics

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 plane i l Use plane equation to calculate depth values at four vertices of the area for all surrounding, inside, overlapping surfaces

Once a surface has been identified as an outside or O f h b id tifi d t id surrounding, it will remain in that category for all subdivisions of the area
28

01074410 / 13016218 Computer Graphics

Area-Subdivision Method (6)

As a variation

Subdivision along surface boundaries instead of dividing them in half

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

01074410 / 13016218 Computer Graphics

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

O l front colors are saved d Only f t l

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 before b f Completely obscured nodes are not traversed Different views of objects, octants are renumbered so that 0,1,2,3 are front nodes
31

01074410 / 13016218 Computer Graphics

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

Depth-sorting or BSP-tree is most efficient Scan-line Scan line or area subdivision is a fast way area-subdivision

Several thousand surfaces

Few thousand surfaces

Scan-line, depth-sorting, or BSP-tree Depth sorting Depth-sorting or Octree Depth-buffer

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

Curved surface representations

low performance with simple scenes but high performance for complex scenes

Octree is fast and simple

Ray-casting or O Octree

Possible to combine and implement different visible-surface detection methods


Only integer additions and subtractions, no sorting or intersection calculations 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 differently from th visible edges diff tl f the i ibl d Methods are also called visible-line detection methods or hidden-line detection methods th d hidd li d t ti 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, its color is multiplied by fdepth(d) pixel

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

You might also like