Unity中裁剪空间推导(使用FOV来调节)

文章目录


前言

在之前的文章中,我们控制透视相机使用的是SIze。但是,在透视相机中,我们使用的是FOV角度来控制。


一、使用FOV代替之前使用的Size(h)

c o t ( F O V 2 ) = n h 2 = 2 n h cot(\frac{FOV}{2}) = \frac{n}{\frac{h}{2}} = \frac{2n}{h} cot(2FOV)=2hn=h2n

  • OpenGL

    2 n w 0 0 0 0 2 n h 0 0 0 0 n + f n − f 2 n f n − f 0 0 − 1 0 \] \\begin{bmatrix} \\frac{2n}{w} \& 0 \& 0 \& 0 \\\\ 0 \& \\frac{2n}{h} \& 0 \&0\\\\ 0 \& 0 \& \\frac{n+f}{n-f} \&\\frac{2nf}{n-f}\\\\ 0 \& 0 \& -1 \& 0\\\\ \\end{bmatrix} w2n0000h2n0000n−fn+f−100n−f2nf0

    2 n w 0 0 0 0 2 n h 0 0 0 0 n f − n n f f − n 0 0 − 1 0 \] \\begin{bmatrix} \\frac{2n}{w} \& 0 \& 0 \& 0 \\\\ 0 \& \\frac{2n}{h} \& 0 \&0\\\\ 0 \& 0 \& \\frac{n}{f-n} \&\\frac{nf}{f-n}\\\\ 0 \& 0 \& -1 \& 0\\\\ \\end{bmatrix} w2n0000h2n0000f−nn−100f−nnf0

r = w h r = \frac{w}{h} r=hw

r在1920x1080下为1.77

2 n w = 2 n r h = 1 r c o t ( F O V 2 ) \frac{2n}{w} = \frac{2n}{rh} = \frac{1}{r}cot(\frac{FOV}{2}) w2n=rh2n=r1cot(2FOV)

2 n h = c o t ( F O V 2 ) \frac{2n}{h}=cot(\frac{FOV}{2}) h2n=cot(2FOV)

2、替换后

  • OpenGL

    1 r c o t ( F O V 2 ) 0 0 0 0 c o t ( F O V 2 ) 0 0 0 0 n + f n − f 2 n f n − f 0 0 − 1 0 \] \\begin{bmatrix} \\frac{1}{r}cot(\\frac{FOV}{2}) \& 0 \& 0 \& 0 \\\\ 0 \& cot(\\frac{FOV}{2}) \& 0 \&0\\\\ 0 \& 0 \& \\frac{n+f}{n-f} \&\\frac{2nf}{n-f}\\\\ 0 \& 0 \& -1 \& 0\\\\ \\end{bmatrix} r1cot(2FOV)0000cot(2FOV)0000n−fn+f−100n−f2nf0

    1 r c o t ( F O V 2 ) 0 0 0 0 c o t ( F O V 2 ) 0 0 0 0 n f − n n f f − n 0 0 − 1 0 \] \\begin{bmatrix} \\frac{1}{r}cot(\\frac{FOV}{2}) \& 0 \& 0 \& 0 \\\\ 0 \& cot(\\frac{FOV}{2}) \& 0 \&0\\\\ 0 \& 0 \& \\frac{n}{f-n} \&\\frac{nf}{f-n}\\\\ 0 \& 0 \& -1 \& 0\\\\ \\end{bmatrix} r1cot(2FOV)0000cot(2FOV)0000f−nn−100f−nnf0

相关推荐
星火撩猿1 小时前
常见游戏引擎介绍与对比
unity·ue5·游戏引擎·godot
sky_smile_Allen2 小时前
[Unity]-[UI]-[Prefab] 关于Unity UGUI 的布局及组件讲解
ui·unity·游戏引擎
虾球xz4 小时前
游戏引擎学习第244天: 完成异步纹理下载
c++·学习·游戏引擎
太妃糖耶7 小时前
URP-利用矩阵在Shader中实现物体的平移和缩放
unity·矩阵
Magnum Lehar10 小时前
ApophisZerg游戏引擎项目目录展示
人工智能·vscode·编辑器·游戏引擎
Tandy12356_14 小时前
Godot开发2D冒险游戏——第一节:主角登场!
python·游戏引擎·godot
是阿根20 小时前
unity使用iTextSharp生成PDF文件
unity·c#·游戏引擎
岩中竹1 天前
力扣热题100题解(c++)—矩阵
数据结构·c++·程序人生·算法·leetcode·矩阵
byxdaz1 天前
矩阵运算和线性代数操作开源库
矩阵
常城1 天前
Unity中通过TMP使用图片字体
unity·游戏引擎