Skip to content

Commit

Permalink
[Fix] Projection matrix for Vulkan and DX12
Browse files Browse the repository at this point in the history
  • Loading branch information
mrouffet committed Feb 17, 2024
1 parent fcf0a54 commit 3021c8d
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions Include/SA/Maths/Matrix/Matrix4.inl
Original file line number Diff line number Diff line change
Expand Up @@ -557,26 +557,28 @@ namespace SA

if (_bInvertedZ)
{
//const T A = _near / (_far - _near);
//const T B = (_far * _near) / (_far - _near);
// Sources: https://github.com/sebbbi/rust_test/commit/d64119ce22a6a4972e97b8566e3bbd221123fcbb

return Mat4(
_aspect / focalLength, 0, 0, 0,
0, T(1) / focalLength, 0, 0,
0, 0, 0, (_far - _near) / (_far * _near) /* 1 / B */,
0, 0, -1, (_far - _near) / (_far * _far - _far) /* A / B */
focalLength / _aspect, 0, 0, 0,
0, focalLength, 0, 0,
0, 0, -_near / (_far - _near), (_far * _near) / (_far - _near),
0, 0, 1, 0
);

}
else
{
// GLM implementation.
/**
* Vulkan/DX12 matrix
* Sources: https://youtu.be/U0_ONQQ5ZNM
* https://computergraphics.stackexchange.com/questions/12448/vulkan-perspective-matrix-vs-opengl-perspective-matrix
*/

return Mat4(
focalLength / _aspect, 0, 0, 0,
0, focalLength, 0, 0,
0, 0, -(_far + _near) / (_far - _near), -(2 * _far * _near) / (_far - _near),
0, 0, -1, 0
0, 0, _far / (_far - _near), -(_far * _near) / (_far - _near),
0, 0, 1, 0
);
}
}
Expand Down

0 comments on commit 3021c8d

Please sign in to comment.