Hello,
Im currently in the process of implementing shadow mapping on my engine, im using a deferred renderer for now and works just fine, my main issue comes to implementing directional lights.
I've managed to setup a ortographic matrix and multiply it with a view matrix to obtain a camera who can render the scene and draw proper shadows, the problem arises in the fact that not the entire geometry is covered in the camera range.
The solution i've read is to create the camera based on the user-controlled camera frustum, however, i do not quite understand how the ortho projection works, mainly what each parameter means, right now im using a function who takes 4 parameters, this is the code (im using the irrlicht math library for my engine as i was used to it already).
template <class T>
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixOrthoLH(
float widthOfViewVolume, float heightOfViewVolume, float zNear, float zFar)
{
AX_ASSERT_IF(widthOfViewVolume==0.f); //divide by zero
AX_ASSERT_IF(heightOfViewVolume==0.f); //divide by zero
AX_ASSERT_IF(zNear==zFar); //divide by zero
M[0] = (T)(2/widthOfViewVolume);
M[1] = 0;
M[2] = 0;
M[3] = 0;
M[4] = 0;
M[5] = (T)(2/heightOfViewVolume);
M[6] = 0;
M[7] = 0;
M[8] = 0;
M[9] = 0;
M[10] = (T)(1/(zFar-zNear));
M[11] = 0;
M[12] = 0;
M[13] = 0;
M[14] = (T)(zNear/(zNear-zFar));
M[15] = 1;
#if defined ( USE_MATRIX_TEST )
definitelyIdentityMatrix=false;
#endif
return *this;
}
I dont know what exactly each parameter means when it comes to projection, i'm also not quite sure if i need a view matrix to create the light camera, maybe someone can help me with this.
Thanks!