Visibility - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

Visibility

Description:

Render the polygons in that order, deepest one first ... Composite in back to front order with a sequence of over operations. No depth quantization error ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 37
Provided by: xiaoyu1
Category:
Tags: visibility

less

Transcript and Presenter's Notes

Title: Visibility


1
Visibility
2
Visibility Problem
  • Given a set of polygons, which is visible at
    each pixel? Also called hidden surface removal.
    In many cases, however, rather than solving the
    direct problem of determining what is visible, we
    will instead address the converse problem of
    eliminating those primitives that are invisible
  • In many complex worlds, few things are visible
  • How much of the real world can you see at any
    moment?
  • primitives outside of the viewing frustum
  • back-facing primitives on a closed, convex object
  • primitives occluded by other objects closer to
    the camera

3
Outside the Field-of-View
  • Clipping, as we discussed before, addresses the
    problem of removing the objects outside of the
    field of view.
  • Frustum clipping removes portions of objects
    that are partially inside of and partially
    outside of the field of view.

4
Visibility Algorithms
  • Very large number of different algorithms known.
    Two main classes
  • Object space algorithms computations that
    decompose polygons in world to solve
  • Image space algorithms computations at the pixel
    level
  • Issues
  • Efficiency it is slow to overwrite pixels, or
    scan convert things that cannot be seen
  • Accuracy - answer should be right, and behave
    well when the viewpoint moves
  • Complexity - Must have technology that handles
    large, complex scenes. Object precision
    visibility may generate many small pieces of
    polygon

5
General Approaches
  • Object-Based Approach
  • for (each object in the world)
  • determine unobstructed object parts
  • draw the parts in the appropriate color
  • Image-Based Approach
  • for (each pixel in the image)
  • determine the closest object for that pixel
  • draw the pixel in the color of the closest
    object

6
Back Face Culling
  • if an object is closed (having a well defined
    inside and outside) then some parts of the outer
    surface must be blocked by other parts of the
    same surface.

7
Removing Back-Faces
  • For each polygonal face of a closed object, we
    assume an outward pointing normal can be
    computed. If this normal is directed away from
    the viewpoint. That is, if its dot product with a
    vector directed towards the viewer is negative,
    then the face can be immediately discarded from
    consideration.
  • On average this quick test can eliminate about
    one half of the faces from further consideration.
  • Note that V is vector from point on polygon to
    eye. You cannot use the one view direction for
    all polygons.

8
Culling Plane-Test
  • This is equivalent to test which side of the
    polygon plane the eye lies in. Remove faces that
    have the eye in their negative half-space. This
    requires computing a plane equation for each face
    considered.
  • We still need to compute the normal (How?). But,
    we don't have to normalize it. How do we go
    about computing a value for d?

9
Culling Plane-Test
  • Once we have the plane equation, we substitute
    the coordinate of the viewing point (the eye
    coordinate in our viewing matrix). If it is
    negative, then the surface is back-facing.

10
Canonical Space
  • Its very convenient to do back-face removal in
    the projected canonical space because all views
    are orthographic.
  • You need only look at the sign of the z component
    of the face normal. If nz lt 0, it can be removed.

11
OpenGL Specifications
  • glEnable(GL_CULL_FACE)
  • glCullFace(GLenum mode)
  • GL_FRONT
  • GL_BACK
  • GL_FRONT_AND_BACK
  • Need to order triangle vertices in right order
    (CCW). Why?

12
Handling Occlusion
  • For most interesting scenes and viewpoints, some
    polygons will overlap somehow, we must determine
    which portion of each polygon is rendered in the
    final image.

13
A Painter's Algorithm
  • The painter's algorithm, sometimes called
    depth-sorting, gets its name from the process
    which an artist renders a scene using oil paints.
  • First, the artist will paint the background
    colors of the sky and ground.
  • Next, the most distant objects are painted,
  • then the nearer objects, and so forth.
  • Algorithm
  • First, the list of surfaces are sorted according
    to their distance from the viewpoint.
  • Render the polygons in that order, deepest one
    first
  • The first issue is which depth-value do you sort
    by? In general a primitive is not entirely at a
    single depth. (centeroid ?).

14
Problems with Painters
  • The painter's algorithm works great... unless one
    of the following happens
  • Big triangles and little triangles. This problem
    can usually be resolved using further tests.
  • Another problem occurs when the triangle from a
    model interpenetrate as shown below. This problem
    is a lot more difficult to handle. generally it
    requires that primitive be subdivided (which
    requires clipping).

15
Depth Sorting Simple Cases
  • Testing for overlaps Start drawing when first
    condition is met
  • x-extents or z-extents do not overlap
  • S is behind the plane of S
  • S is in front of the plane of S
  • S and S do not intersect in the image plane

S
S
S
or
S
z
S
S
x
z
S
S
x
S
S
16
Depth Sorting General Algorithm
  • Sort polygons on depth of some point
  • Render from back to front (modifying order on the
    fly)
  • Rendering For surface S with greatest depth
  • If no overlap in depth with other polygons, scan
    convert
  • Else, for overlaps in depth, test for overlaps in
    the image plane
  • If none, scan convert and go to next polygon
  • If S, S overlap in depth and in image plane,
    swap order and try again
  • If S, S have been swapped already, split and
    reinsert

17
Depth sorting
  • Advantages
  • Handles transparent image compositing
  • Composite in back to front order with a sequence
    of over operations
  • No depth quantization error
  • Depth comparisons carried out in high-precision
    view space
  • Disadvantages
  • Over-rendering
  • Potentially very large number of splits - ?(n2)
    fragments from n polygons

18
The Z-buffer (Image Precision)
  • For each pixel on screen, have at least two
    buffers
  • Color buffer stores the current color of each
    pixel
  • The thing to ultimately display
  • Z-Buffer stores at each pixel the depth of the
    nearest thing seen so far
  • Also called the depth buffer
  • Initialize this buffer to a value corresponding
    to the furthest point (e.g. z1.0)
  • As a polygon is filled in, compute the depth
    value of each pixel that is to be filled
  • if depth lt z-buffer depth, fill in pixel color
    and new depth
  • else disregard

19
The Z-buffer (2)
  • Advantages
  • Simple and now ubiquitous in hardware
  • A z-buffer is part of what makes a graphics card
    3D
  • Computing the required depth values is simple
  • Disadvantages
  • Over-renders - worthless for very large
    collections of polygons
  • Depth quantization errors can be annoying
  • Cant easily do transparency (Requires keeping
    information about partially covered polygons)

20
OpenGL Depth Buffer
  • OpenGL defines a depth buffer as its visibility
    algorithm
  • The enable depth testing glEnable(GL_DEPTH_TEST)
  • To clear the depth buffer glClear(GL_DEPTH_BUFFER
    _BIT)
  • To clear color and depth glClear(GL_COLOR_BUFFER_
    BITGL_DEPTH_BUFFER_BIT)
  • The number of bits used for the depth values can
    be specified (windowing system dependent, and
    hardware may impose limits based on available
    memory)
  • The comparison function can be specified
    glDepthFunc()
  • Possible functions Always, Never, lt, lt, , !,
    gt, gt
  • Default glDepthFunc(GL_LESS)

21
Plane Power
  • Intersections
  • Objects on opposite sides of a plane cannot
    intersect.
  • Visibility
  • objects on same side as viewer are "closer" than
    objects on opposite side
  • use visibility order with Painters Algorithm

22
Binary Spatial Partitions (BSP)
  • Inter-object Trees
  • generalizes binary search trees to dimensions gt 1
  • compare to hyerplanes instead of points

23
Intra-Object Trees
24
BSP-Trees (Object Precision)
  • Construct a binary space partition tree
  • Tree gives a rendering order
  • A list-priority algorithm
  • Tree splits 3D world with planes
  • The world is broken into convex cells
  • Each cell is the intersection of all the
    half-spaces of splitting planes on tree path to
    the cell
  • Also used to model the shape of objects, and in
    other visibility algorithms
  • Often used in game development

25
Constructing a BSP Tree
  • The Binary Space Partitioning (BSP) algorithm
  • 1. Select a partitioning plane/facet.
  • 2. Partition the remaining planes/facets
    according to the side of the partitioning plane
    that they fall on ( or -).
  • 3. Repeat with each of the two new sets.
  • Partitioning requires testing all facets in the
    active set to find if they lie
  • entirely on the positive side of the partition
    plane,
  • entirely on the negative side,
  • or if they cross it. In the case of a crossing
    facet we clip it into two halves.

26
BSP-Tree Example
A
A
C
4
-
3

B
C
-
B
-


1
3
2
4
1
2
27
Building Example
  • We will build a BSP tree, in 2D, for a 3 room
    building
  • Ignoring doors
  • Splitting edge order is shown
  • Back side of edge is side with the number

5
2
3
4
1
6
28
Building Example (1)
5
1

-
3a, 4a, 6
2, 3b, 4b, 5
2
3b
4b
1
4a
3a
6
29
Building Example (2)
5a
5b
1

-
3a, 4a, 6
2
-

2
3b
4b
3b, 5b
4b, 5a
1
4a
3a
6
30
Building Example (3)
5a
5b
1

-
2
3a
-


2
3b
4b
4b, 5a
4a, 6
3b

5b
1
4a
3a
6
31
Building Example (Done)
5a
5b
1

-
2
3a
-


2
3b
4b
3b
4a
4b



6
5b
5a
1
4a
3a
6
32
Computing Visibility with BSP trees
  • Starting from the root of the tree.
  • 1. Classify viewpoint as being in the positive or
    negative half-space of our plane
  • 2. Call this routine with the opposite half-space
  • 3. Draw the current partitioning plane
  • 4. Call this routine with the same half-space
  • Intuitively, at each partition, we first draw the
    stuff further away than the current plane, then
    we draw the current plane, and then we draw the
    closer stuff. BSP traversal is called a "hidden
    surface elimination" algorithm, but it doesn't
    really "eliminate" anything it simply orders the
    drawing of primitive in a back-to-front order
    like the Painter's algorithm.

33
BSP-Tree Rendering Example
A
A
C
4
-

3
C
B
-
-


B
1
3
2
4
1
2
1st
2nd
3rd
4th
34
BSP tree rendering Example
5a
5b
1

-
2
3a
-


2
3b
4b
3b
4a
4b



6
5b
5a
1
4a
3a
6
35
BSP-Tree Rendering (2)
  • Advantages
  • One tree works for any viewing point
  • transparency works
  • Have back to front ordering for compositing
  • Can also render front to back, and avoid drawing
    back polygons that cannot contribute to the view
  • Disadvantages
  • Can be many small pieces of polygon
  • Over-rendering

36
View Frustum Culling
Hierarchical view frustum culling based on
BSP(Binary Space Partitioning) Tree
Write a Comment
User Comments (0)
About PowerShow.com