Hidden Surfaces. Chapter 10. Hidden Lines. Hidden Lines Removed. Hidden Surfaces Removed. Why?. We must determine what is visible within a scene from a chosen viewing position For 3D worlds this is known as visible surface detection or hidden surface elimination. Hidden Surface Removal.
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Hidden Surfaces
Chapter 10
We must determine what is visible within a scene from a chosen viewing position
For 3D worlds this is known as visible surface detection or hidden surface elimination
Visible surface detection algorithms are broadly classified as:
Image space methods are by far the more common
For each object in the scene do
Begin
1. Determine those part of the object whose view is unobstructed by other parts of it or
any other object with respect to the viewing specification.
2. Draw those parts in the object color.
End
For each pixel in the image do
Begin
1. Determine the object closest to the viewer that is pierced by the projector through the pixel
2. Draw the pixel in the object colour.
End
Object space methods ex: backface, painters algorithm
Image space methods ex: zbuffer, scanline, subdivision
Each surface has a normal vector. If this vector is pointing in the direction of the center of projection, it is a front face and can be seen by the viewer. If it is pointing away from the center of projection, it is a back face and cannot be seen by the viewer.
The test is very simple, if the z component of the normal vector is positive, then, it is a back face. If the z component of the vector is negative, it is a front face.
(x,y,z) is behind the polygon if Ax+By+Cz<0
or
A polygon is a backface if
Vview . N >0
if Vview is parallel to zv axis:
if C<0 then backface
if C=0 then polygon cannot be seen
yv
xv
N=(A,B,C)
zv
Vview
n1·v = (2, 1, 2) · (1, 0, 1)
= 2 – 2 = 4,
so n1·v < 0
so n1front facing polygon
n2 = (3, 1, 2)
n1 = (2, 1, 2)
n2 ·v = (3, 1, 2) · (1, 0, 1)
= 3 + 2 = 5
so n2 · v > 0
so n2 back facing polygon
v = (1, 0, 1)
If the viewpoint is on the +z axis looking at the origin, we only need check the sign of the z component of the object’s normal vector
if nz < 0, it is back facing
if nz > 0 it is front facing
What if nz = 0?
the polygon is parallel to the view direction, so we don’t see it
Visible Surface Determination Algorithm:
Determine which object is visible at each pixel.
Order of polygons is not critical.
Works for dynamic scenes.
Basic idea:
Rasterize (scanconvert) each polygon, one at a time
Keep track of a z value at each pixel
Interpolate z value of vertices during rasterization.
Replace pixel with new color if z value is greater. (i.e., if object is closer to eye)
Goal is to figure out which polygon to draw based on which is in front of what. The algorithm relies on the fact that if a nearer object occupying (x,y) is found, then the depth buffer is overwritten with the rendering information from this nearer surface.
Need to maintain:
Frame buffer
contains colour values for each pixel
Zbuffer
contains the current value of z for each pixel
The two buffers have the same width and height.
No object/object intersections.
No sorting of objects required.
Additional memory is required for the zbuffer.
In the early days, this was a problem.
ZBuffering: Algorithm
allocate zbuffer;
The zbuffer algorithm:
compare pixel depth(x,y) against buffer record d[x][y]
for (every pixel){ initialize the colour to the background};
for (each facet F){
for (each pixel (x,y) on the facet)
if (depth(x,y) < buffer[x][y]){ / / F is closest so far
set pixel(x,y) to colour of F;
d[x][y] = depth(x,y)
}
}
}
1
2
3
1
3
4
5
3
2
4
5
6
7
5
4
3
7
6
5
4
Scan convert the following two polygons.
The number inside the pixel represents its zvalue.
(3,3)
(0,3)
(0,0)
(3,0)
(0,0)
(3,0)
Does order matter?
































































































1
1
1
1
1
1
1
2
2
2
3
3
3
1
1
1
3
3
2
2
2
2
3
3
3
3
3
4
4
4
5
5
5
3
3
3
2
2
2
5
5
4
4
3
3
3
3
4
4
4
4
4
5
5
5
6
6
6
7
7
7
5
5
5
4
4
4
3
3
3
7
7
6
6
5
5
4
4
4
4
5
5
7
7
7
6
6
6
5
5
5
4
4
4
=
+
+
=
+
=
+
=
ZBuffering: Example
How do you compute the z value at a given pixel?
Interpolate between vertices
z1
y1
za
zb
ys
zs
y2
z2
y3
z3
An image space method for identifying visible surfaces Computes and compares depth values along the various scanlines for a scene.
Two important tables are maintained:
The edge table contains:
The surface facet tables contains:
The scanline method runs into trouble when surfaces cut through each other or otherwise cyclically overlap
Such surfaces need to be divided
For each scanline, examine all polygon surface projections intersecting that scan line to determine which are visible. Then enter the surface color of that position in the frame buffer.
Edge table:
Surface table:
yv
xv
Image space method
Algorithm:
1. Form an active edge list that contains only the edges that cross the current scan line, sorted in order of increasing x.
2. Define a flag for each surface to indicate whether a position along a scan line is inside or outside the surface.
3. Process pixel positions across each scan line from left to right. Locate visible positions of surfaces along the scan line.
yv
1
2
3
xv
An areasubdivision technique
Idea:
Divide an area into four equal subareas
At each stage, the projection of each polygon will do one of four things:
Completely surround a particular area
Intersect the area
Be completely contained in the area
Be disjoint to the area
Disjoint polygons do not influence an area.
Parts of an intersecting polygon that lie outside the area do not influence that area
At each step, we determine the areas we can color and color them, then subdivide the areas that are ambiguous.
At each stage of the algorithm, examine the areas:
If no polygons lie within an area, the area is filled with the background color
If only one polygon is in part of the area, the area is first filled with the background color and then the polygon is scan converted within the area.
If one polygon surrounds the area and it is in front of any other polygons, the entire area is filled with the color of the surrounding polygon.
Otherwise, subdivide the area and repeat the above 4 tests.
Initial scene
First subdivision
Second subdivision
Third subdivision
Fourth subdivision
Subdivision continues until:
All areas meet one of the four criteria
An area is pixel size
in this case, the polygon with the closest point at that pixel determines the pixel color
2
3
2
2
3
3
3
2
3
3
3
1
3
1
3
1
1
1
3
3
3
3
2
3
3
3
2
2
2
2
Weiler Atherton Algorithm
Weiler Atherton Algorithm
WA_display(polys : ListOfPolygons)
sort_by_minZ(polys);while (polys <> NULL) doWA_subdiv(polys>first, polys)end;
WA_subdiv(first: Polygon; polys: ListOfPolygons)
inP, outP : ListOfPolygons := NULL;
for each P in polys do Clip(P, first>ancestor, inP, outP);
for each P in inP do if P is behind (min z)first then discard P;
for each P in inP doif P is not part of first then WA_subdiv(P, inP);
for each P in inP do display_a_poly(P);
polys := outP;
end;
Objectspace algorithm
Draw surfaces from back (farthest away) to front (closest):
Sort surfaces/polygons by their depth (z value)
Draw objects in order (farthest to closest)
Closer objects paint over the top of farther away objects
A
A
C
4

3
+
C
B

B
+

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

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

3a, 4a, 6
2

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

2
3a

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

2
3a

+
+
3b
2
4b
4a
4b
3b
+
+
+
6
5a
5b
1
4a
3a
6
A
A
C
4

+
3
C
B

+

+
B
1
3
2
4
1
2
3rd
4th
1st
2nd
View
5
2
3
1
4
View of scene from above
5
5a
5b
2
3
1
4
3
back
front
1
2
5a
4
5b
5
5a
5b
2
3
1
4
3
back
front
2
4
5b
front
5a
1
5
5a
5b
2
3
1
4
3
back
front
2
4
front
5a
1
5b
• Most methods for visible surface determination take advantage of coherence