This technique allows you to draw wireframe objects with the hidden lines removed, or drawn in a style different from the ones that are visible. This technique can clarify complex line drawings of objects, and improve their appearance [27] [4].
The algorithm assumes that the object is composed of polygons. The algorithm first renders the polygons of the objects, then the edges themselves, which make up the line drawing. During the first pass, only the depth buffer is updated. During the second pass, the depth buffer only allows edges that are not obscured by the objects polygons to be rendered.
Here's the algorithm in detail:
In order to improve the appearance of the edges (which may show depth buffer aliasing artifacts), use polygon offset or stencil decaling techniques to draw the polygon edges. The following technique works well, although its not completely general. Use the stencil buffer to mask where all the lines, both hidden and visible, are. Then use the stencil function to prevent the polygon rendering from updating the depth buffer where the stencil values have been set. When the visible lines are rendered, there is no depth value conflict, since the polygons never touched those pixels.
Here's the modified algorithm:
The only problem with this algorithm is if the hidden and visible lines aren't all the same color, or interpolate colors between endpoints. In this case, it's possible for a hidden and visible line to overlap, in which case the most recent line will be the one that is drawn.
Instead of removing hidden lines, sometimes it's desirable to render them with a different color or pattern. This can be done with a modification of the algorithm:
In this technique, all the edges are drawn twice; first with the hidden line pattern, then with the visible one. Rendering the object as polygons updates the depth buffer, preventing the second pass of line drawing from effecting the hidden lines.