反向Z深度缓冲投影矩阵计算

时间:2017-09-03 16:54:46

标签: c++ matrix

有人可以向我解释如何计算适合反向Z深度缓冲的投影矩阵吗?

我知道我必须将近平面映射到1并将远平面映射到0但我真的无法得到一个有效的矩阵。

这是我用来计算“普通”投影矩阵(工作)的代码:

float fovYRad = DegToRad(fov * 0.5f);
float tanHalfFovy = tanf(fovYRad);
float aspect = width / height;

m[0] = 1.0f / tanHalfFovy;  m[1] = 0.0f;                    m[2] = 0.0f;                                    m[3] = 0.0f;
m[4] = 0.0f;                m[5] = aspect / tanHalfFovy;    m[6] = 0.0f;                                    m[7] = 0.0f;
m[8] = 0.0f;                m[9] = 0.0f;                    m[10] = (zNear + zFar) / (zNear - zFar);        m[11] = -1.0f;
m[12] = 0.0f;               m[13] = 0.0f;                   m[14] = (2.0f * zNear * zFar) / (zNear - zFar); m[15] = 0.0f;

这是我尝试计算反向Z投影矩阵(不工作):

float fovYRad = DegToRad(fov * 0.5f);
float tanHalfFovy = tanf(fovYRad);
float aspect = width / height;

m[0] = 1.0f / tanHalfFovy;  m[1] = 0.0f;                    m[2] = 0.0f;                                m[3] = 0.0f;
m[4] = 0.0f;                m[5] = aspect / tanHalfFovy;    m[6] = 0.0f;                                m[7] = 0.0f;
m[8] = 0.0f;                m[9] = 0.0f;                    m[10] = zNear / (zFar - zNear);             m[11] = -1.0f;
m[12] = 0.0f;               m[13] = 0.0f;                   m[14] = (zNear * zFar) / (zFar - zNear);    m[15] = 0.0f;

0 个答案:

没有答案