Consider this figure for projection.

enter image description here There are two equations that give value for the xp and yp coordinates:

  • $x_p=x.\frac{(z_{vp}-z_{prp})}{h}+ x_{prp}.\frac{(z-z_{vp})}{h}$ and
  • $y_p=y.\frac{(z_{vp}-z_{prp})}{h}+ y_{prp}.\frac{(z-z_{vp})}{h}$

and then it explains in a paragraph: "Setting up matrix elements for obtaining the homogeneous-coordinate $x_h$ and $y_h$ values in the given equations is straightforward, but we must also structure the matrix to preserve depth (z-value) information. Otherwise, the z coordinates are distorted by the homogeneous-division parameter h. We can do this by setting up the matrix elements for the z transformation so as to normalize the perspective-projection $z_p$ coordinates. There are various ways that we could choose the matrix elements to produce the homogeneous coordinates and the normalized $z_p$ value for spatial position (x, y, z)."

So, I have some questions regarding this:

  • What does it mean to preserve depth(z-values)?
  • What does it mean to normalize the perspective-projection zp coordinates?
  • How to perform this normalization?
  • How does this normalization preserve z-values?

As you can see in the figure above, during a perspective projection, the goal is to essentially "splat" points within the view frustum onto the near frustum plane. That means that the final z coordinate is actually just fixed at $z_{vp}$.

Now, if we did this poorly, we could just map $z$ to $z_{vp}$ directly in our projection matrix by setting the third row of the matrix to $\left[0, 0, \frac{z_{vp}}{z_{prp}}, 0\right]$ and setting the final homogenous coordinate to $1$ (so no divide by $w$ happens at the end). This approach is problematic because squashing all this depth information to $z_{vp}$ loses information and we can no longer do things like a depth test.

This is why, instead of mapping all $z$ values to the same fixed distance from the camera, we opt to map it into a range of $z$ values instead. This is the "normalization" that the text is referring to. Furthermore, we aren't preserving the "values" at all. The wording in the text is confusing, but what we are preserving is the information about what points lie further away from the view origin. When it says that we have a choice about how to do this normalization, well, we can choose to map $z$ into any range that we wish, and in graphics contexts, we normally want something that preserves precision well enough that we can do nice things like get crisp shadows and such.

If you look at standard texts, the $z$ value will be mapped via the matrix row:

$$\left[ 0, 0, \frac{-(f + n)}{f - n}, \frac{-2fn}{f - n} \right]$$

and the $w$ coordinate is mapped to $-z_{prp}$. This should look similar to the other entries that map $x$ and $y$ between the right-left and top-bottom frustum planes respectively. In this case, we're mapping $z_{prp}$ between $n$ and $f$. Now, we have a $z$ coordinate that is mapped in a range such that after the divide-by-$w$ to get back to normal 3-coordinate space from homogeneous space, maps back to $z_{vp}$ as expected, but until that occurs, can be used to perform depth comparisons. The choice of $n$ and $f$ is arbitrary, but too narrow and you end up clipping $z$ values that lie outside the range, and too wide and you lose precision. Some people use a $-\log$ depth computation instead to gain as much precision as possible, but I digress.


Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.