I just read an article on http://www.songho.ca which indicates that a projection matrix is defined by:
[2n/(r-l) 0 (r+l)/(r-l) 0 ]
[0 2n/(t-b) (t+b)/(t-b) 0 ]
[0 0 -(f+n)/(f-n) -2*n*f/(f-n) ]
[0 0 -1 0 ]
where:
n: near
f: far
l: left
r: right
t: top
b: bottom
I have also read on http://www.geeks3d.com of an alternate definition given by:
[w 0 0 0]
[0 h 0 0]
[0 0 q -1]
[0 0 qn 0]
where:
w=(2*near)/(width * aspect)
h = 2near/height
q=-(far+near)/(far-near)
qn=-2*(far*near) / (far-near)
Why are there differences in M[0][2] and M[1][2] (excluding one is the transposed of other)? Do they generate the same result? Which one is posible to use in GLSL without any transpose?
The first matrix allows you to arbitrarily position the left, right, top and bottom clip plane positions. The second one always gives you a centred, symmetric frustum, which is kind of limiting. For example when you’re doing stereoscopic rendering you want to slightly shift the left and right plane.
This has nothing to do with GLSL. You can use either. The transpose you’re referring to stems from the way matrices are represented internally in OpenGL and interfaces to the outside world.
Anyway, you should not hardcode matrices into shader source code, but supply them through a Uniform.
Update
OpenGL orders its matrices column major, i.e.