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
  • DirectX
    [ 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

1、我们可以把矩阵中使用到 h(高) 和 w(宽) 的部分使用比值替换掉。

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
  • DirectX
    [ 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
相关推荐
lovingyk1 小时前
Unity VRoid+Blender+Unity 3D人物模型导入使用
unity
软件黑马王子3 小时前
Unity游戏制作中的C#基础(3)加减乘除算术操作符,比较运算符,逻辑与,或运算符
开发语言·unity·c#
阿正的梦工坊7 小时前
PyTorch下三角矩阵生成函数torch.tril的深度解析
人工智能·pytorch·矩阵
[奋斗不止]8 小时前
Unity打包APK报错 using a newer Android Gradle plugin to use compileSdk = 35
unity·unity apk 报错
虾球xz11 小时前
游戏引擎学习第119天
学习·游戏引擎
lovingyk15 小时前
Unity 脚本控制3D人物模型的BlendShape
unity
晴空了无痕18 小时前
现代任务调度系统架构深度解析——以TaskSchedulerController为核心的弹性任务管理方案
unity·系统架构·游戏引擎
虾球xz1 天前
游戏引擎学习第118天
学习·游戏引擎
软件黑马王子1 天前
Unity游戏制作中的C#基础(6)方法和类的知识点深度剖析
开发语言·游戏·unity·c#
不吃斋的和尚1 天前
Unity中一个节点实现植物动态(Shader)
unity·游戏引擎