Aquacolor

Aquacolor



一些几何数学基础(3)

Gumdrop · 2025-06-23 · 31浏览 · 未分类



过程

  1. Viewing变换:按顺序作model(相机位置信息=>空间移动到以相机为原点)、view(相机方向信息=>空间旋转到相机镜头向-z,镜头上方向+y)、projection变换(视角、长宽比、远近平面信息=>视锥变换为$[-1,1]^3$的立方体)。
    1. projection变换包含perspective peojection变换(挤压frustom到cubiod)、平移变换(平移cubiod中心到原点)、标准化变换(伸缩cubiod到cononical);后两步合称orthographic projection变换。
    2. Viewing变换即MVP。
  2. Viewport变换:伸缩cononical到其长宽与screen的分辨率匹配且恢复原深度,平移cubiod到正交投影变换前的cubiod深度且左下角为原点。
  3. Rasterize光栅化:凸包(有简单做法)、深度插值(前文)、深度测试(后文)、反走样(抗锯齿,有简单做法)……

如何进行深度测试?

循环网格面,先对每个三角形网格面做凸包。

对凸包内所有点测试是否在该三角形内部。

进行深度插值,判断该点是否被其他三角形覆盖(深度大),以选择像素颜色。

在判断过程中维护了一个zbuffer和一个framebuffer。zbuffer生命周期应该在开始渲染三角形之前,初始值为最远;在每帧渲染结束后清除。

变换矩阵

2025-06-23T14:57:26.png

$$ \begin{pmatrix} 1 & 0 & 0 & \cfrac{\mathrm{Width}}{2} \\ 0 & 1 & 0 & \cfrac{\mathrm{Height}}{2} \\ 0 & 0 & 1 & \cfrac{n+f}{2} \\ 0 & 0 & 0 & 1 \end{pmatrix}\begin{pmatrix} \cfrac{\mathrm{Width}}{2} & 0 & 0 & 0 \\ 0 & \cfrac{\mathrm{Height}}{2} & 0 & 0 \\ 0 & 0 & \cfrac{n-f}{2} & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} $$ $$ \begin{pmatrix} \cfrac{1}{n\tan\cfrac{\theta}{2}} & 0 & 0 & 0 \\ 0 & \cfrac{1}{\alpha \times n\tan\cfrac{\theta}{2}} & 0 & 0 \\ 0 & 0 & \cfrac{2}{n-f} & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & -\cfrac{n+f}{2} \\ 0 & 0 & 0 & 1 \end{pmatrix}\begin{pmatrix} n & 0 & 0 & 0 \\ 0 & n & 0 & 0 \\ 0 & 0 & n+f & -nf \\ 0 & 0 & 1 & 0 \end{pmatrix} $$ $$ \begin{pmatrix} x_{\hat{g}\times\hat{t}} & x_{\hat{t}} & x_{-\hat{g}} & 0 \\ y_{\hat{g}\times\hat{t}} & y_{\hat{t}} & y_{-\hat{g}} & 0 \\ z_{\hat{g}\times\hat{t}} & z_{\hat{t}} & z_{-\hat{g}} & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}^T\begin{pmatrix} 1 & 0 & 0 & x_{-\vec{e}} \\ 0 & 1 & 0 & y_{-\vec{e}} \\ 0 & 0 & 1 & z_{-\vec{e}} \\ 0 & 0 & 0 & 1 \end{pmatrix} $$

透视投影矩阵的几何意义

$$ M_{persp}\begin{pmatrix} x \\ y \\ z \\ 1 \\ \end{pmatrix}=\begin{pmatrix} nx \\ ny \\ (n+f)z-nf \\ z \\ \end{pmatrix}\xlongequal{\text{Homogeneous division}}\begin{pmatrix} \cfrac{n}{z}x \\ \cfrac{n}{z}y \\ (n+f)-\cfrac{nf}{z} \\ 1 \\ \end{pmatrix} $$

考虑在xOy平面上投影,则相当于对平面空间做伸缩,比例$\dfrac{n}{z}$,越远则压缩越严重。

考虑每个平面变换前后的深度变化,有(实在描述不出):

geogebra-export.png



©

comment 评论区

添加新评论

face表情



  • ©2026 bilibili.com

textsms
内容不能为空
昵称不能为空
email
邮件地址格式错误
web
beach_access
验证码不能为空
keyboard发表评论


star_outline 咱快来抢个沙发吧!




©2026 Aquacolor

Theme Romanticism2.2 by Akashi
Powered by Typecho