Hi, I'm trying to implement cascaded shadow maps in my Direct3D project and I've been struggling with this issue for a few days now. What I'm trying to do is calculate the current view frustum splits in world space by manually constructing frustum splits in NDC space and transforming them with the current inverse viewprojection matrix. I've managed to create the frustums in NDC space, using these values for the first frustum;
/// NDC Frustum points (xyzw)
LTN:-1.000000 1.000000 0.100000 1.000000
RTN: 1.000000 1.000000 0.100000 1.000000
LBN:-1.000000 -1.000000 0.100000 1.000000
RBN: 1.000000 -1.000000 0.100000 1.000000
LTF:-1.000000 1.000000 0.215443 1.000000
RTF: 1.000000 1.000000 0.215443 1.000000
LBF:-1.000000 -1.000000 0.215443 1.000000
RBF: 1.000000 -1.000000 0.215443 1.000000
LTN means LeftTopNear, LBF means LeftBottomFar and so on. The data for the second and third frustum are similar, but with the different z-values for the far planes (0.464159 for the second frustum and 1.0 for the last one)
Here's the code that is supposed to transform and normalize the frustum points:
/// m_viewProjection verified to be correct
XMMATRIX invViewProjection = XMMatrixInverse(nullptr, m_viewProjection);
/// GFX_SHADOW_CASCADE_COUNT is set to 3
for (unsigned short i = 0; i < Config::GFX_SHADOW_CASCADE_COUNT; i++)
{
for (int j = 0; j < 8; j++)
{
m_frustumsWorld[i].point[j] = XMVector4Transform(m_frustumsNDC[i].point[j], invViewProjection);
m_frustumsWorld[i].point[j] /= m_frustumsWorld[i].point[j].m128_f32[3];
}
}
The problem seems to occur when I do the transform. The last frustum (with NDC z-far distance of 1.0) seems to get transformed right with a world z-value corresponding to 100% of the max view distance, but the other two doesn't. Their transformed values puts them extremly close to the camera, not ~21% and ~46% of the max view distance which is what I'm looking for. I've spent days trying to figure out whats wrong appreciate any help I can get!