You are on page 1of 38

Hidden Surfaces

Introduction

• Suppose we are looking at some object A & then some


other object say B comes in between our eyes & object
A, then in that case we are not able to see the object A
fully or partially.
• The surfaces that are blocked or hidden from view must
be removed in order to construct a realistic view of 3D
scene.
• So the object B should be displayed with only three of
the six faces.
• The identification & removing of these surfaces is called
as hidden surface problem
Example
Approaches

• There are 2 fundamental approaches to the problem.

– Object space
– Image space
Object space

• Object space algorithms do their work by comparing


the objects & parts of the objects to each other
within the scene definition to determine which
surface is visible &which is not.

• Pseudo code…
– for each object in the scene
• determine which parts of object are visible
• draw these parts in the appropriate color
Image space

• Image space algorithms do their work as the objects


are being converted to pixels in the frame buffer. The
resolution of the display device is important here as
this is done on a pixel by pixel basis.

• Pseudo code…
– for each pixel in the frame buffer
• determine which polygon is closest to the
viewer at that pixel location

• color the pixel with the color of that


polygon at that location
Algorithms

1. Object Space Techniques: Applied before vertices are


mapped to pixels

a) Back Face Removal(Detection) Algorithm,


b) Painter’s Algorithm
c) BSP trees Algorithm
d) Area Subdivision (Warnock’s) Algorithm

2. Image Space Techniques: Applied while the vertices are


rasterized
1. Z-buffering algorithm
Back Face Removal
• Object surfaces that are oriented away from the viewer
are called back faces.
• The back faces of a cube are completely blocked by the
cube itself & hidden from view.
• Therefore we can identify & remove these back faces.
• We know that the equation of plane is given by
Ax + By + Cz + D = 0
• In object space method, the identification of back faces is
based on above equation.
• If a point (x,y,z) satisfyies the equation then the point
(x,y,z) is lying on the plane.
• If Ax + By + Cz + D < 0, it means (x,y,z) lies on negative
side.
• If Ax + By + Cz + D > 0, it means (x,y,z) lies on positive side
Depth comparision Algorithms

• Suppose there are two points A(x1,y1,z1) & B(x2,y2,z2).


• Now we want to know which point is getting hidden out of A & B.
• In other words whether A is hiding B or vice versa.
• For this we have to apply two steps-
1. If both point A & B are not lying on the same projection line then no
point hides another (both points are co-linear).So both points will
be displayed.
2. If both points A & B are lying on same projection line,then either
one of these two points get hidden by other.So only one point will
be displayed.
• So we have to identify which point have to displayed(what will be
the name of that point)
• So we have to use third third parameter i.e. z co-ordinate.This z co-
ordinate is nothing but the depth.
• If z co-ordinate of A is smaller than Z co-ordinate B then point B
hides point A.
Example
Example
Painters algorithm (Depth Sort)

1. Painters algorithm is called Depth sort algorithm.


2. It works similar to a painter’s painting process.
3. Polygons are sorted based on their depth from the viewer.
4. Frame buffer is set to background color.
5. The polygon which is far from viewer is drawn first, then next
and so on.
6. It means more distance polygons are painted first and nearer
distance polygons are painted over more distance polygons,
partially or totally hiding them from view.
Example
• Painter algorithm uses a technique called as minimax
test or boxing test.
• From this test we can immediately sorts which
polygon are overlapping & which not overlapping.
• The minimax test says that , if we place both the
polygons in two different boxes & if these boxes are
not overlapping, then it means the polygons within
these boxes are not overlapping.
Example
Example
Example

Sort objects in depth order


Draw all from Back-to-Front (far-to-near)
Area Subdivision (Warnock’s) Algorithm

• It uses Divide and Conquer approach to remove hidden surfaces.

• It starts with the total view.

• Tests are applied to decide whether scene can be displayed or scene is


complex and we should subdivide the total area into smaller
rectangles.
• These tests are then applied to each smaller area, subdividing these if
the tests indicate that visibility of single surface is still uncertain.
• This subdivision process is continued until the subdivided area can be
easily analyzed or they are reduced to the size of single pixel.
Area Subdivision
Four Tests

• Tests : To determine the visibility of single surface(polygon)


within a specified area
• How tests are carried out ?: by giving the relationship of a
display area and a polygon.

1. Surrounding Polygon: Polygon completely encloses the area


2. Intersecting polygon: polygon that is partly inside and partly
outside the area.
3. Contained Polygon: polygon is completely inside the area.
4. Disjoint Polygon: polygon is completely outside the area.
Four Tests : Warnock’s Algorithm
These tests are carried out : by giving the relationship of a
display area and a polygon.

surround intersect contained disjoint


Actions after Test
1. If all the polygons are disjoint from the area, then the
background color is displayed in the area.

2. If there is only one intersecting or only one contained polygon


, then the area is first filled with the background color and
then part of the polygon contained in the area is filled with
the color of polygon.

3. If there is a single surrounding polygon, but no intersecting or


contained polygon then area is filled with the color of the
surrounding polygon.

4. If there are more than one polygon intersecting , contained in,


or surrounding the area then we have to do some more
processing.
Warnock’s Algorithm
Warnock’s Algorithm STEPS

• Recursion

• Starts from the entire display area

• We check for the four cases. If none holds, we subdivide


the area, otherwise, we stop and perform the action
associated with the case

• The recursion stops when you are at the pixel level


BSP (Binary Space Partitioning) Tree.

• This algorithms – returns ordered list of polygon


fragments for specified view point (static pre-
processing stage).

• It is a two step procedure


1. Construction of BSP tree
2. Displaying BSP tree
BSP (Binary Space Partitioning) Tree.

Step 1 :
•Choose a polygon arbitrarily from scene.
5

•Divide scene into front (relative to normal)


and back half-spaces. 2

•Split any polygon lying on both sides.


3
1 4
•Choose a polygon from each side – split
scene again.

•Recursively divide each side until each node


contains only 1 polygon. View of scene from above
BSP Tree.
5
5a
5b
•Choose polygon arbitrarily (eg here 3) 2

•Divide scene into front (relative to 3


normal) and back half-spaces. 1 4

•Split any polygon lying on both sides.

•Choose a polygon from each side – split


scene again.
front 3 back
•Recursively divide each side until each
node contains only 1 polygon. 1 4
2 5b
5a
BSP Tree. 5

5a
2 5b
•Choose polygon arbitrarily (here 2)

•Divide scene into front (relative to normal) 3


1 4
and back half-spaces.

•Split any polygon lying on both sides.

•Choose a polygon from each side – split


scene again.
front 3 back
•Recursively divide each side until each node 2 4
contains only 1 polygon. front
5b
5a 1
BSP Tree. 5
5a
2 5b
•Choose polygon arbitrarily (here 4)
3
•Divide scene into front (relative to normal) 1 4
and back half-spaces.

•Split any polygon lying on both sides.

•Choose a polygon from each side – split scene


again. 3
front back
•Recursively divide each side until each node 2 4
front
contains only 1 polygon.
5a 1 5b
Step 2: Displaying a BSP tree.

• Once we have the regions – need priority list(means order of display)


• BSP tree can be traversed to yield a correct priority list for an arbitrary viewpoint.
• The relation between root and view point is considered. The relation is to traverse BSP tree
in inorder way.(LNR)
• Start at root polygon.
– If viewer is in front half-space, draw polygons behind root first, then the root polygon,
then polygons in front.
– If polygon is on edge – either can be used.

Back Back
Front Front Viewpoint

Viewpoint
Z-Buffer

In this method two buffers are required.

1) A depth buffer( Z-buffer) : It is used to store the depth


value for each (x,y) position as surface are processed.

2) Refresh Buffer(Frame Buffer):


It is used to store the intensity value for each position.
Z-buffering : image space approach

Basic Z-buffer idea:


• Here we are sorting the polygon based on their position
the space. (Position of a polygon is given by its z value.)

• Frame buffer is used to store the images which we want to


display on the screen. It stores the x, and y values of an
image.

• Z-buffer is used to keep track of z-values ie depth values of


closest polygon (smallest z) so far.

• Paint the pixel with the color of the polygon whose z value
is the closest to the eye.
Z-Buffer (steps)

1. Initialise frame buffer to background colour.


2. Initialise depth buffer(z-buffer) to z = infinity (Min value)
3. Scan convert each polygon in arbitrary order.
4. For each pixel (x,y) in the polygon, calculate the depth z(x,y) at that
pixel.
5. Compare the depth z(x,y) with the value stored in the z-buffer at that
location, Zbuffer(x,y)
6. Update both frame and Z- buffer :
a) Case 1: z(x,y) < Zbuffer(x,y) : (current polygon lies in front) then
the new z-value is stored in Z-buffer and corresponding intensity
value is stored in frame buffer.
b) Case 2:: z(x,y) > Zbuffer(x,y) : (current polygon lies behind some
polygon ) Do nothing
Advantages & Disadvantages

• Advantages :
1. It is easy to implement
2. As it processes one object at a time , the
number of objects can be large.

• Disadvantages
1. It requires lots of memory as we are storing
each pixels z-value.
2. It is time consuming as we are comparing
each and every pixel

You might also like