Can anyone please tell me what is the general formula to implement the Perspective Projection Matrix? I'm trying to implement a way to generate this matrix in order to use it for a game engine I'm working on.
Asked
Active
Viewed 2,791 times
0
-
there are more than one type of perspective matrix out there ... I am used to this one [depth buffer got by glReadPixels is always 1](https://stackoverflow.com/a/51130948/2521214) look for `glPerspective` – Spektre Nov 11 '18 at 05:04
-
@Spektre I gave it a look but I'm still having a hard time figuring things out. But clarify this to me, a Perspective Projection Matrix isn't the product between a perspective matrix and a projection matrix? Or there's something else to it? – Pmsmm Nov 12 '18 at 01:24
-
1Yes you're right but the projection matrix to which you are multiplying the perspective matrix is usually unit matrix unless you want to simulate some special behavior. My matrix just preserve aspect ratio and re-map the z to logarithmic values (like `gluPerspective` would do) – Spektre Nov 12 '18 at 07:18
-
I think I'm getting it, I'll try to do some further research but thanks for the help. – Pmsmm Nov 12 '18 at 19:56
1 Answers
5
Ok so basically with some help from @spektre and a friend of mine I was able to figure out how to really do this. Pretty much the formula I used was this:
So pretty much what you need to make this matrix is a function that receives 4 arguments which are the following:
- zFar
- zNear
- Aspect Ratio
- Field of View
If you want to know more about these fields and the matrix itself my advice is to head over to WebGL 3D Perspective to actually see this working.

Pmsmm
- 352
- 5
- 17