I want to add shadow mapping to my realtime renderer. I start with directional lights first.
The algorithm:
- Render the shadow map from the light point of view.
- When shading a worldspace point P it is projected to the light space and the shadow map is sampled to see if it is occluded.
I am stuck at (1). I need to compute the light optimal view projection matrix. It is made of the product of the view and projection matrices. To do so I need to make the light frustrum fit the whole scene.
The scene AABB(min,max) is given as well as the light direction.
To summarize the matrices i need are:
a) The light View matrix.
Typically computed by DirectX::XMMatrixLookAtRH or glm::lookAtRH.
What should be the parameters EyePosition, FocusPosition and UpDirection?
b) The light projection matrix.
Since it is a directional light this should be an orthographic projection.
Typically computed by DirectX::XMMatrixOrthographicOffCenterRH or glm::orthoRH
What would be the parameters ViewLeft, ViewRight, ViewBottom, ViewTop, NearZ, farZ?
c) The light view projection matrix.
Product of (a) and (b)
If too far would get something like this. I lose precision
If too close i lose information

