To main page | 3dengine.org

Hidden Objects


Hidden objects typically refers to the objects that are behind some other object in the current view. (It may also refer to objects, that are hidden right now because of some other condition)

How OpenGL draws triangles/objects

The OpenGL approach to hidden object (actually hidden pixels) is depth-testing in the screen space. The point being drawn is transformed to screen space coordinates, and then it's screen space z-coordinate is tested against the z-coordinate in the current buffer. Whether the point would be drawn is decided by depth function currently in use. Typically it's GL_LESS, which means point would be drawn only if it's z-coordinate is LESS than the z-coordinate of point in buffer.

So let's say the buffer contains some plane, that is far away, and it's screen space z-coordinate is 0.8. Of course you specify world space x,y,z coordinates, that are translated internally by OpenGL to screen space. Now you try to draw one plane that is further away with z-coordinate of 0.9 and one that is closer with z=0.1 . OpenGL call will test each point during the rasterization process with depth function and draw the pixels of closer (z=0.1) plane and discard pixels of the farther (z=0.9) plane.

The idea of comparing each pixel to each other means that it's costly process. There are more effective algorithms to determine whether object is visible and should the programmer even start the drawing process for some object. However the GPU usually consist of many parallel processing units, which mean that tens of thousands of pixels are drawn and tested simultaneously, therefore those algorithms, which are typically done on CPU should be very-very effective, since modern CPUs have only 1 to 4 parallel processing units and usually only one of them is active; parallel programming isn't easy on CPU yet.

Other algortihms

Effective algorithms:
* Occlusion culling

Ineffective algorithms (nowadays), but still those should be studied for general expansion of your knowledge:
* Hidden lines removal

GPU will also do the frustum culling without any special programming required.