Previous | Next --- Slide 49 of 62
Back to Lecture Thumbnails
kayvonf

Question: The purpose of the Z-buffer is to hold the closest visible surface at each output image pixel (surfaces behind this distance are not visible (aka "occluded" from view). Why do you think all modern GPUs use a Z-buffer to compute occlusion? Does this seem like a very brute-force approach since a comparison is performed per-pixel, and not per primitive? Why not just sort all triangles up front and draw them in back-to-front order?

gif

I can think of two possible reasons for favoring the per-fragment z-buffer approach.

  1. It's an easy algorithm! The Z-buffer algorithm is very simple in comparison to the obvious per-triangle algorithm (check whether two triangles intersect, potentially split the triangles if they pass through one another, as in the image above, etc.). For example, it is not obvious how to represent the depth if the triangle is not perpendicular to the camera - would we have a range of depths for triangles, as opposed to a single number; how would these depths be sorted? If the algorithm is simple to implement then it is feasible that it will be reasonable to implement in hardware and moreover it should hopefully use up a relatively small amount of die area.

  2. How many triangles vs. fragments? It isn't necessarily true now and in the future that there will be more fragments than triangles (1). As triangles get smaller the potential benefit of doing per-triangle culling decreases.

(1) http://www.cs.cmu.edu/afs/cs/academic/class/15418-s12/www/lectures/25_micropolygons.pdf

kayvonf

@gif: Good answer. I'd say the primary reasons are simplicity and generality. By general, I mean any primitive that can be turned into fragments can be composited with proper occlusions into the same frame buffer. Imagine if you implemented a fancy scene for determining occlusion for triangles, and then I asked you to add lines, or spheres to your system. Your algorithm would have to change.

The Z-buffer reduces the problem of occlusion to one of generating fragments. Since occlusion tests are always the same (even if supported primitive types change), and the operation is very simple, a hardware accelerated Z-buffer is reasonable brute force, but very fast solution.