C481 B581 Computer Graphics
Dana Vrajitoru

Hidden Surfaces

Determine which parts of the scene are seen by the viewer (camera) and which are not. Allows the user to create a mental 3D spatial representation of the 2D image.

For an object, determine the point of view and orientation
 

For several objects, determine their position with respect to each other:
 


Depth Comparison

If two points P1(x1, y1, z1) and P2(x2, y2, z2) result in the same projection, compare the distance between each of them and If we project on the 0xy plane, we just have to compare z1 and z2: the point with smaller depth is visible.

Detection algorithms:

General Idea

Back-Face Detection

An object-space method.

Consider the normal to a surface N and the view vector V. If angle(V, N) < 90, then the face is a back face.

In the case where the projection is on the (0xy) plane, if the z component of the normal, Nz > 0, then the face is hidden.

Only works if the object is closed. Can be used to preprocess the scene.
 

Z-Buffer Algorithm

An image-space method.

For each pixel (x,y) in the projection plane, keep the value of the closest z value that has been drawn on it.

1. Initialize the projection area to a background color.
2. Initialize the z-buffer to a maximal number (back clipping plane).
3. Scan-convert one polygon (triangle) at a time. For each converted point, compare its z with the value stored for that pixel in the z-buffer. If the new value is smaller, draw the point.
 

A-Buffer Algorithm

Similar to the z-buffer method, only considers transparency.

For each pixel record all the scan-converted points, with depth and opacity parameter.

Compute the color of the pixel based on all this information.

color(P) = a2 * color(P2) + (1-a2) (a1*color(P1) + (1-a1) (a3*color(P3) + (1-a3)*background))
= 0.8 c2 + 0.2 (0.3 c1 + 0.7 (0.5 c3 + 0.5 bcgr)
= 0.8 c2 + 0.06 c1 +  0.065 c3 + 0.065 bcgr


Hidden Surfaces in OpenGL

Enable the z-buffer:
glEnable(GL_DEPTH_TEST);

Disable the z-buffer:
glDisable(GL_DEPTH_TEST);

Clear the z-buffer:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);