projectMatrix

第一步

第二步

转到NDC:

因为目前只有 \(-1 \le y' \le 1\),对于 \(x'\)可以除与\(r\)
所以:

\[x' = \frac{x}{rz \tan(\alpha/2)} \tag{eq. 5.1} \]

\[y' = \frac{y}{z \tan(\alpha/2)} \]

matrix

我们可以使用matrix表示,但是上面 \({eq. 5.1}\)不是线性的。需要矩阵(线性表示)表示的话,需要除于\(z\)才能满足线性.所以要将\(z\)放到\(w\)位置上:

因为上面那个式子带有了\(z\)所以不是线性的.我们下面详细讲解:

输入一个三维点 \((x,y,z)\),我们写成4维 \((x,y,z,1)\),然后与矩阵相乘:

\[(x, y, z, 1) \cdot P = (x', y', z', w') \]

这个是严格的线性变换,我们设计矩阵\(P\)的核心诡计:让输出的\(w'\)刚好等于原始输入的\(z\),把需要用来做除法的深度值存起来。后面在最终结果最后取出这个\(w'\)进行除法。

\[P= \begin{bmatrix} \dfrac{1}{r\tan(\alpha/2)} & 0 & 0 & 0 \\ 0 & \dfrac{1}{\tan(\alpha/2)} & 0 & 0 \\ 0 & 0 & A & 1 \\ 0 & 0 & B & 0 \end{bmatrix} \]

把一个点带入:

\[[x,y,z,1] \begin{bmatrix} \dfrac{1}{r\tan(\alpha/2)} & 0 & 0 & 0 \\ 0 & \dfrac{1}{\tan(\alpha/2)} & 0 & 0 \\ 0 & 0 & A & 1 \\ 0 & 0 & B & 0 \end{bmatrix} = \left[ \frac{x}{r\tan(\alpha/2)},\; \frac{y}{\tan(\alpha/2)},\; Az+B,\; z \right] \tag{eq. 5.2} \]

After multiplying by the projection matrix (the linear part), we complete the
transformation by dividing each coordinate by \(w = z\) (the nonlinear part):

\[\left[ \frac{x}{r\tan(\alpha/2)},\; \frac{y}{\tan(\alpha/2)},\; Az+B,\; z \right] \xrightarrow{\text{divide by } w} \left[ \frac{x}{rz\tan(\alpha/2)},\; \frac{y}{z\tan(\alpha/2)},\; A+\frac{B}{z},\; 1 \right] \tag{eq. 5.3} \]

归一化 z

这个时候三维模型被投影到了二维平面上了,看来是完成了三维到二维的投影,应该算是完了.但是有时候需要深度信息.

Therefore, we must construct an order preserving function \(g(z)\) that maps the interval \([n, f]\) onto \([0, 1]\)

Equation 5.3, that the \(z\)-coordinate undergoes the transformation:

\[g(z) = A + \frac{B}{z} \]

We now need to choose \(A\) and \(B\) subject to the constraints:

Condition 1: \(g(n) = A + B/n = 0\) (the near plane gets mapped to zero)

Condition 2: \(g(f) = A + B/f = 1\) (the far plane gets mapped to one)

Solving condition 1 for \(B\) yields: \(B = -An\). Substituting this into condition 2 and solving for \(A\) gives:

\[A + \frac{-An}{f} = 1 \]

\[\frac{Af - An}{f} = 1 \]

\[Af - An = f \]

\[A = \frac{f}{f-n} \]

Therefore,

\[g(z) = \frac{f}{f-n} - \frac{nf}{(f-n)z} \]

最后得出的矩阵:

\[P= \begin{bmatrix} \dfrac{1}{r\tan(\alpha/2)} & 0 & 0 & 0 \\ 0 & \dfrac{1}{\tan(\alpha/2)} & 0 & 0 \\ 0 & 0 & \dfrac{f}{f-n} & 1 \\ 0 & 0 & \dfrac{-nf}{f-n} & 0 \end{bmatrix} \]

posted on 2026-07-17 16:24  Ultraman_X  阅读(5)  评论(0)    收藏  举报

导航