HiddenSurface Removal: ZBuffer and ListPriority Algorithms PowerPoint PPT Presentation

presentation player overlay
1 / 24
About This Presentation
Transcript and Presenter's Notes

Title: HiddenSurface Removal: ZBuffer and ListPriority Algorithms


1
School of Computing Staffordshire University
3D Computer Graphics
Hidden-Surface RemovalZ-Buffer and
List-Priority Algorithms
Dr. Claude C. Chibelushi
2
Outline
  • Introduction
  • Efficiency Considerations
  • Z-Buffer Algorithm
  • List-Priority Algorithms
  • Depth-sort, Binary space-partitioning
  • Summary

3
Introduction
  • Hidden-surface removal
  • determination of surface visibility
  • also known as visible-surface determination
  • Occluded object points should be hidden
  • show only points nearer to viewer, if
  • opaque surfaces
  • several points along line of sight
  • this requires overlap detection, and comparison
    of distances from viewer (z)

4
Introduction
  • Some difficult cases for hidden-surface removal

Intersecting or cyclically overlapping surfaces
5
Efficiency Considerations
  • Geometric transformations and rasterisation
    require significant processing power
  • Costly operations should be efficient and
    infrequent
  • (ideally) no computation should be wasted on
    occluded surfaces
  • apply frustum and occlusion culling
  • exploit coherence (picture-segment similarities)
  • e.g. reuse of previous results
  • reduce the overdraw problem

6
Z-Buffer Algorithm
  • Also known as depth-buffer algorithm
  • Basic principles
  • surfaces nearer to viewer can occlude farther
    surfaces
  • occlusion leads to surface overlap on view window
  • Implementation sketch
  • compare depth of every point that projects onto
    each view-window pixel
  • display point nearest to viewer

7
Z-Buffer Algorithm
  • Buffer entries for pixel (x, y), if polygons are
    processed in order S2, S3, S1
  • z-buffer z2 overwritten by z1
  • frame-buffer colour for pixel of S2 overwritten
    by pixel of S1

8
Z-Buffer Algorithm
  • Implementation
  • Define two 2-D arrays with same resolution as
    viewport
  • frame buffer
  • to store pixel colour / shade values
  • depth buffer (z-buffer)
  • to store depth values of object points
    corresponding to pixel
  • Scan through pixels for all polygons
  • calculate depth of each point corresponding to
    pixel within projection surface of polygon
  • interpolate vertex depth
  • overwrite buffer entries with colour / shade and
    depth of point if latter is nearer to viewer

9
Z-Buffer Algorithm
  • Implementation ctd.
  • Depth interpolation

10
Z-Buffer Algorithm
  • Implementation ctd.
  • Exploiting coherence
  • use incremental computation
  • add a constant step to z value of previous point
    to obtain z value of current point (for
    increasing y or x)
  • it can be shown that
  • along polygon edge
  • zcurrent zprevious (z1 - z2) / (y1 - y2)
    (along edge between 1 and 2)
  • zcurrent zprevious (z1 - z3) / (y1 - y3)
    (along edge between 1 and 3)
  • along scan line
  • zcurrent zprevious (z5 - z4) / (x5 - x4)
    (along scan line between 4 and 5)

11
Z-Buffer Algorithm
  • Pseudo-code
  • initialize z-buffer and frame buffer with values
    for scene background
  • for each polygon
  • for each scan line (span inside projection of
    polygon)
  • for each pixel
  • compare z-value of object point to z-buffer
    entry for pixel
  • if point is nearer to viewer
  • overwrite z-value in z-buffer
  • calculate pixel colour/shade value
  • overwrite colour/shade value in frame buffer

12
Z-Buffer Algorithm
  • Positives
  • Easy to implement
  • Handles difficult occlusion cases (see slide 4)

13
Z-Buffer Algorithm
  • Negatives
  • Expensive storage requirements
  • 2 buffers
  • but scan-line z-buffer algorithm may be used if
    memory size is limited
  • May calculate shade for occluded pixels
  • overdraw problem
  • Transparent objects require additional processing

14
List-Priority Algorithms
  • Depth-Sort Algorithm
  • Simplified form known as painters algorithm
  • builds up display much like painter might do
  • paints distant objects first
  • paints nearer objects over farther objects
  • painters algorithm
  • order surfaces according to depth from viewer
  • render surfaces back-to-front

15
List-Priority Algorithms
  • Depth-Sort Algorithm
  • Painting sequence

1. paint grass
2. paint road
3. paint police car
4. paint speeding car
16
List-Priority Algorithms
  • Depth-Sort Algorithm implementation
  • Order surfaces according to distance from view
    plane
  • surfaces sorted in order of decreasing depth
  • depth computation calculate average vertex
    depth, or find maximum vertex depth for surface
  • may require splitting surface(s) in case of
    extent overlap
  • Scan convert farther surfaces first, nearer
    surfaces last

17
List-Priority Algorithms
  • Depth-Sort Algorithm
  • May fail if surfaces are not parallel to view
    plane
  • May get stuck in infinite loop
  • circular reshuffling if surfaces alternately
    obstruct each other (see slide 4)
  • possible solution
  • flag pair that has been reordered
  • split surface into two parts on second reordering
    attempt

18
List-Priority Algorithms
  • Depth-Sort Algorithm pseudo-code
  • sort surfaces according to zmax
  • for each surface // in depth order
  • if (no extent overlap with each of other
    surfaces)
  • scan convert current surface
  • else for each surface that overlaps with
    current surface
  • if (reorder(current surface, surface that
    overlaps) true)
  • if (surface pair swapped in earlier pass)
  • split surface that overlaps
  • insert new surfaces into sorted list
  • else swap current surface and surface
    that overlaps
  • tag the swap break

19
List-Priority Algorithms
  • Depth-Sort Algorithm pseudo-code (ctd.)
  • reorder(S / current surface /, S / surface
    that overlaps /)
  • if ( (no overlap between bounding-boxes of S
    and S in x-y plane) OR
  • (S completely behind S relative to viewpoint)
    OR
  • (S completely in front of S relative to
    viewpoint) OR
  • (no overlap between projections of S and S )
    )
  • return false // surface S is behind S,
    hence do not reorder
  • else
  • return true // reorder

20
List-Priority Algorithms
  • Binary Space-Partitioning Algorithm
  • Trades off faster run-time performance for
  • initial storage and computational expense, and
    some geometrical constraints
  • creates binary tree representation of surface
    order (based on depth)
  • reuses same tree for rendering surfaces from any
    viewpoint

21
List-Priority Algorithms
  • Binary Space-Partitioning Algorithm
  • Tree generation procedure
  • choose plane of any surface as scene partition
    (current tree-node)
  • set surfaces in front of (behind) partition plane
    as front (back) children of current node
  • split surface if cut by partition plane
  • apply recursion (see next slide)

22
List-Priority Algorithms
  • Binary Space-Partitioning Algorithm
  • Tree generation procedure (ctd.)
  • Recursion
  • repeat until each region contains single surface
  • partition current node into front and back
    children (with respect to node plane)
  • region corresponding to front children
  • region corresponding to back children

23
List-Priority Algorithms
  • BSP Algorithm example
  • Tree generation

(a)
(b)
Top view of 5 polygons (perpendicular to x,y
plane)
24
List-Priority Algorithms
  • Binary Space-Partitioning Algorithm
  • Display
  • Procedure
  • in-order traversal of BSP tree
  • traversal condition based on position of surface
    relative to viewpoint (in front, or behind?)
  • skip surfaces behind viewer (clipping)
  • Results independent of selection sequence of
    partition planes during tree generation

25
List-Priority Algorithms
  • Binary Space-Partitioning Algorithm
  • Display paint surfaces from back to front
  • tree traversal
  • if viewer is behind current node (surface)
  • display furthest surface in front of plane of
    current node
  • backtrack and display surfaces as one gets closer
    to viewer
  • if viewer is in front of current node (surface)
  • display furthest surface behind plane of current
    node
  • backtrack and display surfaces as one gets closer
    to viewer

26
List-Priority Algorithms
  • BSP Algorithm example
  • Display (see BSP tree on slide 28)

27
List-Priority Algorithms
  • BSP Algorithm example
  • Display (ctd.)

b viewer behind surface f viewer in front of
surface
  • Surface display sequence
  • 1, 2, 3, 4, 5 (without back-face culling and
    clipping)
  • Exercise give display sequence for back-face
    culling clipping BSP

28
List-Priority Algorithms
  • Binary Space-Partitioning Algorithm
  • Limitation generated tree corresponds to given
    relative depth of surfaces, hence
  • universe should be static,
  • or semi-static
  • only allows polygon translation that maintains
    surface-depth order (e.g. in-plane translation)

29
List-Priority Algorithms
  • BSP Algorithm pseudo-code
  • partitionSpace(polygon list) // Generation of
    BSP tree
  • if (list is empty) return null
  • else
  • select any polygon in list as partition plane
  • create front list // containing polygons in
    front of partition plane
  • create back list // containing polygons behind
    partition plane
  • set partition plane polygon as parent node in
    tree
  • load front polygons into front-list child node
    in tree
  • load back polygons into back-list child node in
    tree
  • partitionSpace(front list) partitionSpace(back
    list)
  • // loading into front and back lists may
    require splitting of intersecting polygons
  • return BSP tree

30
List-Priority Algorithms
  • BSP Algorithm pseudo-code (ctd.)
  • traverseTree(node) // Display polygons (tree
    nodes)
  • if (node ! null)
  • if (viewpoint in front of node) // display
    back, current, and front nodes
  • traverseTree(node-gtbackChild)
  • displayPolygon(node-gtpolygon)
  • traverseTree(node-gtfrontChild)
  • else // display front, current, and back
    nodes
  • traverseTree(node-gtfrontChild)
  • displayPolygon(node-gtpolygon)
  • traverseTree(node-gtbackChild)

31
Comparison of Techniques
  • Z-buffer algorithm
  • handles complex geometry and intersections
  • does not require sorting
  • storage (2 buffers) and computational cost
  • not all (unculled) scene occluded segments are
    rendered
  • but suffers from overdraw problem to some extent

32
Comparison of Techniques
  • Painters algorithm
  • sorting may be computationally expensive
  • all unculled scene segments are rendered
  • suffers from overdraw problem
  • does not handle difficult occlusion cases

33
Comparison of Techniques
  • BSP algorithm
  • motion restrictions suitable for static scene,
    or walk-through scenarios
  • high computational and storage overhead in
    tree-generation phase
  • all unculled scene segments are rendered
  • suffers from overdraw problem
  • viewpoint independence

34
Suggested Reading
  • Relevant parts of Ch. 9, 13, D. Hearn, M.P.
    Baker, Computer Graphics, 2nd Ed. in C,
    Prentice-Hall, 1996.
  • Relevant parts of Ch. 14, A. LaMothe, Black Art
    of 3D Game Programming, Waite Group Press, 1995.

35
Summary
  • Hidden-surface removal
  • determination of surface visibility
  • display surfaces by taking occlusion into account
  • common procedure foreground surface overwrites
    background surface
  • can carry high storage and computational cost
  • back-face culling and extent testing can improve
    computational efficiency

36
Summary
  • Wide variety of hidden-surface removal
    techniques, e.g.
  • z-buffer algorithm
  • list-priority algorithms
  • Painters algorithm
  • BSP algorithm
  • Most techniques do not account explicitly for
    view direction
Write a Comment
User Comments (0)
About PowerShow.com