### Re: XNA Framework Infinite projection matrix

Jon Watte

You can absolutely make a transformation matrix where the far plane is at infinity. This is very useful when using Z fail stencil shadows, because you don't need to write specific capping code, as all vertices that meet at infinity automatically generate a closed mesh. NVIDIA has a whitepaper about it (called something like "robust stencil shadows.")

I'm not sure that the calculation of Q is correct; I seem to recall it should be (f+n)/(f-n) but I could be wrong.

To make infinity come out to 1.0 in the perspective division, you need to make it so that W is always higher than Z, but gets asymptotically closer as distance increases. You also want Z to be 0 at the near clip plane. I believe a matrix something like this might work:

xFactor 0 0 0

0 yFactor 0 0

0 0 -1 -1

0 0 -n 0

I could have gotten it wrong, but this seems to generate a Z value that starts out at 0 at the near plane, and gets closer to 1 the closer you get to infinity (after perspective division).

(This matrix is for row vectors on the left, which is the DirectX convention)