<p>Even though you can find multiple slightly different formulations for the perspective matrix on the internet, they all do more or less the same thing. They project everything inside a space with the shape of a truncated pyramid (your view frustum) into a space with the shape of a quad and a defined value range (clip space).</p>
<p>Most differences are related to how you define the shape of your frustum. For example, your first matrix uses a height, a width, and an angle together with z-far and z-near value. The second one uses just an x- and y-FOV and the z-far and z-near values to describe the shape of the frustum. This explains the differences in the upper left section.</p>
<p>So what about the lower right section? One big issue here is, that you can choose to use column or row vectors for your vertices/points. Column vectors are multiplied on the right-hand side and row vectors on the left-hand side. The choice you make determines if you have to transpose (switch columns and rows) your matrix or not. The matrices you presented are just targetting different vector representations. I can't tell you without testing/rereading which one is meant for which representation, but if you transpose one of them, they start looking quite similar.</p>
<p>There are still some other minor differences like varying signs, different factors, or a missing addition.
The derivation of your second matrix can be found <a href="http://www.codinglabs.net/article_world_view_projection_matrix.aspx" rel="nofollow noreferrer">here</a>.
I can't tell you exactly where those small differences in the first matrix come from, but you can find some possible explanations in <a href="https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/building-basic-perspective-projection-matrix" rel="nofollow noreferrer">this link</a> (Have a look into the &quot;Are There Different Ways of Building this Matrix?&quot; section).
Another good read is <a href="http://www.songho.ca/opengl/gl_projectionmatrix.html" rel="nofollow noreferrer">this link here</a>.</p>
<p>Which matrix is &quot;correct&quot; depends on how your Graphic API defines its coordinate systems and it's clip space (For OpenGL - you can take the one from the last link I provided). However, there is no &quot;best&quot; choice because they all do more or less the same. Unless you have no special needs for your program (depth precision) or other fancy ideas I can't think of now, just pick the one suited for your API with the inputs (FOV vs width+height+angle) that you like most and start having fun. ;)</p>

CC BY-SA 4.0
2020-07-02T16:54:34.943Z
if i were to use the secound matrix what should the fovX and fovY be set to to match the standard fov settings
Nixcc
CC BY-SA 4.0
2020-07-02T21:07:54.487Z
Good question, I think 90 degrees for both values is pretty common. This also the value showed in one of the pictures in the second link I provided. However, take this as an orientation and not as a rule. Try some other values and take whatever you think looks best to you. Keep in mind, that different monitors/VR googles might need different settings.
wychmaster
CC BY-SA 4.0
2020-07-02T21:18:27.127Z
Nevermind i found i website for calculating it
https://themetalmuncher.github.io/fov-calc/
Nixcc
CC BY-SA 4.0
2020-07-02T16:41:19.427Z
2020-07-02T16:41:19.427Z
wychmaster
<p>The hand written one must be quite wrong. The <code>-2</code> and <code>Z</code> got messed up. It should be <code>-2 Zfar Znear</code>, not <code>-Zfar...</code> with a Z without dash. In the field above, <code>Zfar</code> is alone, it should be <code>Zfar + Znear</code>.</p>
<p>Apart from these typos I prefer it - it has an aspect ratio and no extra minus signs to flip axes. Well it is column-major, but that is OK.</p>

CC BY-SA 4.0
2023-01-21T21:05:06.080Z
2023-01-21T21:05:06.080Z
neslrac
<p>I've seen two different perspective projection matrices being used but I want to know which one of them is the best. I think that they both output the same but I'm not sure. So if anyone can help me select which one to use I would greatly appreciate it</p>
<p><a href="https://i.sstatic.net/gVMit.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/gVMit.png" alt="perspective projection matrix 1" /></a></p>
<p><a href="https://i.sstatic.net/ycuEv.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ycuEv.png" alt="perspective projection matrix 2" /></a></p>

<matrix><perspective>
Which perspective projection matrix to use
Nixcc
# Which perspective projection matrix to use

(Asked by: username_0 on 2020-07-02)

I've seen two different perspective projection matrices being used but I want to know which one of them is the best. I think that they both output the same but I'm not sure. So if anyone can help me select which one to use I would greatly appreciate it

[![perspective projection matrix 1](https://i.sstatic.net/gVMit.png)](https://i.sstatic.net/gVMit.png)

[![perspective projection matrix 2](https://i.sstatic.net/ycuEv.png)](https://i.sstatic.net/ycuEv.png)

**Tags:** matrix, perspective


---

## 2 answers

### Answer by username_1 on 2020-07-02. Score: 2 | Accepted answer

Even though you can find multiple slightly different formulations for the perspective matrix on the internet, they all do more or less the same thing. They project everything inside a space with the shape of a truncated pyramid (your view frustum) into a space with the shape of a quad and a defined value range (clip space).

Most differences are related to how you define the shape of your frustum. For example, your first matrix uses a height, a width, and an angle together with z-far and z-near value. The second one uses just an x- and y-FOV and the z-far and z-near values to describe the shape of the frustum. This explains the differences in the upper left section.

So what about the lower right section? One big issue here is, that you can choose to use column or row vectors for your vertices/points. Column vectors are multiplied on the right-hand side and row vectors on the left-hand side. The choice you make determines if you have to transpose (switch columns and rows) your matrix or not. The matrices you presented are just targetting different vector representations. I can't tell you without testing/rereading which one is meant for which representation, but if you transpose one of them, they start looking quite similar.

There are still some other minor differences like varying signs, different factors, or a missing addition.
The derivation of your second matrix can be found [here](http://www.codinglabs.net/article_world_view_projection_matrix.aspx).
I can't tell you exactly where those small differences in the first matrix come from, but you can find some possible explanations in [this link](https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/building-basic-perspective-projection-matrix) (Have a look into the "Are There Different Ways of Building this Matrix?" section).
Another good read is [this link here](http://www.songho.ca/opengl/gl_projectionmatrix.html).

Which matrix is "correct" depends on how your Graphic API defines its coordinate systems and it's clip space (For OpenGL - you can take the one from the last link I provided). However, there is no "best" choice because they all do more or less the same. Unless you have no special needs for your program (depth precision) or other fancy ideas I can't think of now, just pick the one suited for your API with the inputs (FOV vs width+height+angle) that you like most and start having fun. ;)

> **Comments:**
> **username_0**: if i were to use the secound matrix what should the fovX and fovY be set to to match the standard fov settings  
> **username_1**: Good question, I think 90 degrees for both values is pretty common. This also the value showed in one of the pictures in the second link I provided. However, take this as an orientation and not as a rule. Try some other values and take whatever you think looks best to you. Keep in mind, that different monitors/VR googles might need different settings.  
> **username_0**: Nevermind i found i website for calculating it https://themetalmuncher.github.io/fov-calc/  

---

### Answer by username_2 on 2023-01-21. Score: 2

The hand written one must be quite wrong. The `-2` and `Z` got messed up. It should be `-2 Zfar Znear`, not `-Zfar...` with a Z without dash. In the field above, `Zfar` is alone, it should be `Zfar + Znear`.

Apart from these typos I prefer it - it has an aspect ratio and no extra minus signs to flip axes. Well it is column-major, but that is OK.


---

