[Solved] Unity Orthographic Projection Wrong?

When I create an orthographic projection;

float l, r, b, t, n, f;
l = -1;
r = 1;
b = -1;
t = 1;
n = 1f;
f = 10;
Matrix4x4 orthoMatrix = Matrix4x4.Ortho (l, r, b, t, n, f);

I get back the below matrix;

{
    1.00000    0.00000    0.00000    0.00000
    0.00000    1.00000    0.00000    0.00000
    0.00000    0.00000    -0.22222    -1.22222
    0.00000    0.00000    0.00000    1.00000
}

Which is as I expect, apart from the third element in the last column. According to every source I can find, this shouldn’t be negative, but positive (e.g. from Wikipedia);

Why do unity’s orthographic projection matrices have that element negative?

I’m assuming this is the article:

Note this statement, just before the formula:

It appears the coordinate space they’re working in is rendering with ‘forward’ being the ‘-z’ axis. Unity uses the ‘+z’ axis as forward.

The 4th column, 3rd row, of the projection matrix is the ‘z’ translation when projecting. So all they’ve done is flipped that value, which is the difference in their forwards.

1 Like

Thanks lordofduct for pointing that out - it makes perfect sense! Appreciate your fast reply :slight_smile: