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

相关推荐
_风华ts4 小时前
虚幻引擎RPC
rpc·游戏引擎·虚幻
垂葛酒肝汤7 小时前
放置挂机游戏的离线和在线收益unity实现
游戏·unity·c#
孟无岐7 小时前
【Laya】Base64Tool 编码工具类使用说明
typescript·游戏引擎·游戏程序·laya
康de哥8 小时前
在OpenCode中配置unity3d-mcp
unity·glm-4.7·minimax m2.1·opencode·unity3d-mcp
Howrun7778 小时前
虚幻引擎_动画蓝图/混合空间/状态机_超详细教学
游戏引擎·虚幻
在路上看风景9 小时前
1.5 AssetDataBase
unity
qianbo_insist10 小时前
unity 无头模式启动
unity·游戏引擎
郝学胜-神的一滴11 小时前
深入解析Mipmap层级判定原理:从理论到实践
c++·unity·godot·游戏程序·图形渲染·unreal engine
weixin_4093831211 小时前
cocos shader闪光
游戏引擎·cocos2d
Howrun77711 小时前
虚幻引擎_用户小控件_准星
c++·游戏引擎·虚幻