Visible Surface Detection VSD

Document Sample
Visible Surface Detection VSD Powered By Docstoc
					Visible Surface Detection
 Sometimes also called Hidden
 Line Hidden Surface Removal
       Viewing process so far
• defining a view system     • 3D clipping (in principle,
• projection on to a view-     polygon clipping)
  (projection) plane         • transform the
• a view volume is             parallelepiped to a unit
  defined from projection      cube with normalized
• close the view volume        coordinates
• transform the closed
  pyramid to a
  parallelepiped (in case
  of perspective proj.)
             Intro to VSD
In principle, VSD is equal to HLHSR
No best algorithm exists!
Sorting and coherence are important
Classification of algorithms:
1) object-space methods
    * use object definitions directly
2) image-space methods (most common)
    * use the projected object images
    * pixel by pixel decisions
 Back-face detection/removal
A first general step in the VSD process to detect
  and remove back-faces
The process (also called culling) involves:
• Identifying back-faces of a polyhedron
• An initial step of the process of identifying
  visible surfaces
• Comparing the outgoing surface normal from
  each polygon and compare it with the viewing
Typically, if viewing in the negative z-axis
  direction and using a right-handed system,
      if C≤0 (C the z coefficient in the
      plane equation) then the polygon is
For all non-overlapping convex objects
  (polyhedrons), all hidden surfaces are
Generally, about half of the hidden surfaces are
  eliminated in this step.
Assume a slice through an object where N1-N6
  are the surface normals of the bounding
  polygons (left-handed system!)
     Three VSD techniques
• Depth-Buffer method (Z-buffer method)
  – image space method
• Scan-Line method
  – image space method
• Depth-Sorting method
  – object space method
      Depth-Buffer method
• Normalized projection coordinates,
• Right-handed system (looking in the
  negative z-axis direction)
• Polygon surfaces
• Only non-transparent (solid) objects
  Depth-Buffer method,cont’d
Two buffers are needed representing all
  pixel positions:
• a depth buffer keeping the (current) z-
  value (depth) of each pixel
• a refresh buffer, typically the frame
  buffer, keeping the (current) intensity
  value of each pixel
  Depth-Buffer method,cont’d
• the refresh buffer is initiated with the
  background color
• the depth buffer is initiated with z=0
  (corresponds to the background depth)
  Depth-Buffer method,cont’d
Each object is processed at a time, each
  projected polygon surface of an object is
  processed (scan-converted along scan-lines)
  separately, one point (pixel) at a time.
A pixel is written in the refresh buffer only if its
  depth position is nearer than the currently
  registered value for that position in the depth
Depth-Buffer method,cont’d
  Depth-Buffer method,cont’d
Basic algorithm part for testing a pixel,
 (x,y,z), in a projected polygon with a
 given intensity, color:
     if z > depthbuffer(x,y) then
  Depth-Buffer method,cont’d
After all objects with their projected
  polygon surfaces have been scan-
  converted in this way, the correct image
  is in the refresh buffer
Time-consuming (problem in real-time
  applications) and memory demanding
  (less of a problem today)
  Depth-Buffer method,cont’d
Important to make use of coherence
  properties when testing all the points in
  the scan-conversion of polygons
Instead of explicitly calculating the depth
  (z-) value for each point direct from the
  plane equation for the polygon, some
  kind of recursive process for getting the
  depth values would help a lot
  Depth-Buffer method,cont’d
Assume plane equation:
  Ax + By + Cz + D = 0
Then, the depth in (x1,y1):
  z1 = (-Ax1 - By1 -D)/C
Next point on the same scan-line is (x1+1,y1)
  with depth:
  z2 = [-A(x1+1) - By1 -D]/C
This gives: z2 = z1 - A/C, where A/C is constant
  for the whole polygon!
  Depth-Buffer method,cont’d
Similar when changing scan-line (assume
  down the left side of the polygon with an
  edge slope m):
  z1 = (-Ax1 - By1 - D)/C and
  z2 = [-A(x1 - 1/m) - B(y1 - 1) - D]/C
that gives: z2 = z1 + (A/m + B)/C
  (if vertical edge, then z2 = z1 + B/C)
          A-buffer method
• an extension of the depth-buffer method
• can also deal with transparent objects
• needs to accumulate several intensity
  values in each position
• each position references a linked list of
• the final pixel color will be completed as
  a combination of different surface data
        Scan-Line method
An extension of the Scan-Line algorithm
 for polygon filling in 2D
For each scan-line, all polygon
 intersections are examined to decide
 which one is the visible one (i.e. the one
 with the least depth)
The record structure for edges in the 2D
 case then need to be extended
    Scan-Line method,cont’d
Edge record:          Polygon record:
• endpoint coord’s    • plane equation
• slope inverse       • surface properties,
                        e.g. intensity
• polygon reference
                      • flag (false before
                        each new scan-line;
                        true when scanning
                        inside the polygon
                      • reference to edges
    Scan-Line method,cont’d
For each scan-line, an active list of edge
 records is sorted on increasing x
 coordinates; the list is maintained and
 updated in the same way as for 2D
    Scan-Line method,cont’d
On a new scan-line, for each edge record, the
  following is done:
• the flag related to the polygon, to which the
  edge belongs, is inverted, i.e. set to true on
  entrance of the polygon and set to false when
  leaving the polygon
• for the point determined by the x-value of the
  edge record and the scan-line (y-value), a
  depth comparision is done between those
  polygons having a true flag
    Scan-Line method,cont’d
• current intensity is defined by the
  polygon with the least depth
• print pixels on the scan-line by using the
  current intensity until the x-value of the
  next edge record is encountered in the
    Scan-Line method,cont’d
To determine the depth: use the plane equation
   for the polygon
If no true flag, print the background intensity
If only one active polygon, print the intensity of it
Coherence: intensity is preserved from one
   scan-line to the next as long as the active list
   is the same
Scan-Line method,cont’d
    Scan-Line method,cont’d
The method works correctly with any number of
  overlapping polygon surfaces only if surfaces
  do not cut through or otherwise cyclically
  overlap each other
       Depth-Sorting method
Also called Painter’s algorithm
Assume viewing in the positive z-direction (left-
  handed system)
Main idea: The polygons are sorted in priority
  order (high z-value => low priority), and they
  are written in the refresh buffer (frame buffer)
  in reverse priority order.
  Polygon parts that are hidden will sooner or
  later be overwritten
 Depth-Sorting method,cont’d
The priority order is initially based on z-
  max for each polygon.
Much work to examine overlappings in
  different respects.
In the (projected) xy-plane, use a
  rectangle to bound the projection of a
  polygon => much easier examination
 Depth-Sorting method,cont’d
1) first, sort the polygons in order of
   decreasing zmax
2) Then, compare the first polygon, P, in the
   list with the rest of the polygons whether
   there are any overlaps*) in depth. If so,
   reorder the polygons in the list so that P is
   exchanged with an overlapped polygon, say
   Q. Repeat this step with the new list.
 Depth-Sorting method,cont’d
3) When the first polygon in the list is not
   overlapping , scan convert (i.e. write)
   the polygon in the refresh (frame)
   buffer and remove it from the list
4) Repeat from step 2) until the list is
 Depth-Sorting method,cont’d
*) A polygon P is not overlapping a
    polygon Q if any of the following tests
    is positive:
1) No overlapping in depth (zQmax<zPmin)
2) The bounding rectangles in the xy-
    plane do not overlap
3) All vertices in P are lying behind the
    plane defined by Q
 Depth-Sorting method,cont’d
1) No overlapping in
   depth (zQmax<zPmin)
 Depth-Sorting method,cont’d
2) The bounding rectangles in the xy-plane do not
 Depth-Sorting method,cont’d
3) All vertices in P are
   lying behind the
   plane defined by Q
 Depth-Sorting method,cont’d
4) All vertices in Q are lying in front of the
   plane defined by P
5) The projection of the two polygons on to the
   projection plane do not overlap
The tests are listed in order of increasing
   complexity, and the first test that is true
   means that P and Q are changing places in
   the list and step 2) is repeated
 Depth-Sorting method,cont’d
4) All vertices in Q
   are lying in front of
   the plane defined
   by P
Depth-Sorting method,example
Depth-Sorting example,cont’d
The initial polygon list is:
One correct order in which the polygons
 are written:
No guarantee for an unambigous priority
     Depth-Sorting problems
Similar problems as for the Scan-Line method
  can also occur here. If two (or more) surfaces
  obscure each other, we can come into infinite
  loops. The solution is again to split polygons
  Comparing the three methods
Depth-Buffer is the most general method and
  clearly the best when the image complexity
Depth-Sorting is best when there are only a
  limited number of objects (polygons)
Obscuring problems with Depth-Sorting and
  Scan-Line (needs extra processing)
Scan-Line can take advantage of the hardware
  refresh cycles, but generally only second best

Shared By: