Game Development Reference
In-Depth Information
w = 0
w = n
w = f
z = f
z / w = 1
z = 0
z / w = 0.999
z / w = 0
Figure 3.1. Distribution of z , w ,and z/w .Both z and w are linear in view depth and
differ only by a scale and bias; z/w is highly nonlinear.
the value 0.5 is absolutely not anywhere close to the middle of the frustum. It
is in fact very close to the near plane. The vast majority of the values in the
depth buffer will land somewhere very close to 1. The value in the middle of the
frustum will be something like 0.999. This of course results in a significant loss of
a precision, which is a problem. In the past the solution to this was a W-buffer,
which some hardware supported, offering linear distribution of depth values. The
difference between z and w is not that big, actually; z is essentially w with a
slightly larger scale factor, and z starts at near plane whereas w starts at the eye
position. So both z and w are linear, but it is z/w that is stored in a Z-buffer,
which is not linearly distributed. Refer to Figure 3.1 for a visualization of z , w ,
and z/w .
While z/w has nonlinear distribution of values, it is on the other hand linear
in the gradients pixel-to-pixel in screen space. If you have three neighboring
pixels belonging to the same surface, or coplanar surfaces, you can expect the
difference in depth values from the first pixel to the second to be equal to that of
the second to the third pixel, ignoring precision issues of course. In other words,
the screen-space gradients are constant. This is visualized in Figure 3.2.
Constant gradients are a highly desirable property for the hardware, because
the z/w values can simply be computed at the triangle vertices and then linearly
interpolated across the triangle. In addition to simplifying the rasterizer, this
property also facilitates some newer hardware features such a Z-compression. In
the relatively likely event that some screen-space tile—for instance, 8
×
8pixels—
 
Search Nedrilad ::




Custom Search