Actually, that was a lie. It is, in fact, not remotely done. Which is good, since you can read about the steps being taken to correct the fact that it is not done.
In this entry Michael explains the z-buffer. Let me take a crack at the same thing, because I enjoy doing it…
So you’re there, rendering polygons, and you want to make sure that stuff in the background is properly obscured by the things in front of it. In the old days, it was a lot like painting with oil-based paints. You had to paint the far away details first, and gradually layer on things closer and closer to the viewer, covering up the stuff you painted before.
Of course, we’re talking about computer rendering here, so we’re trying to make a new painting 30 times a second. (Eat your heart out, Bob Ross.) The problem with drawing the world back-to-front, is that players insist on always moving around all the time. This means that you have to keep re-calculating the distances to all of the stuff to be rendered and then re-sorting them. That’s expensive even today, and back in the (very) early 90’s, computers had even less CPU time to waste on this sort of business.
Enter the z-buffer. (Sometimes called the depth buffer, because programmers are never happy until they have eleven different names for everything.) Imagine that we have two canvases. One is the rendering buffer, where we will paint our picture.
The other is the z-buffer, where we will record how far away things are. Now, the z-buffer is never shown to the user, but you can think of it as a grayscale image.
Every time we draw a pixel in the render buffer, we draw a pixel in the z-buffer as well, recording how far away that pixel is. In our example, farther = brighter. If we ever run into a situation where we would be drawing a brighter pixel over a darker one in the z-buffer, then we skip drawing it and neither the z-buffer or the render buffer are changed.
Once the painting is done, you wipe the z-buffer clean and start over.
But that only solves half of your problems. If you want to draw transparent stuff (like windows) then you need both a z-buffer and sorting to make it look right. Check out the Let’s Code entry to read the rest of that puzzle.
Diablo III Retrospective
We were so upset by the server problems and real money auction that we overlooked just how terrible everything else is.
So what happens when a SOFTWARE engineer tries to review hardware? This. This happens.
PC Hardware is Toast
This is why shopping for graphics cards is so stupid and miserable.
Please Help I Can’t Stop Playing Cities: Skylines
What makes this borderline indie title so much better than the AAA juggernauts that came before?
The Mistakes DOOM Didn't Make
How did this game avoid all the usual stupidity that ruins remakes of classic titles?