I've recently implemented shadow maps on my project. However, I'd like to add a feature that allows the light direction to be dynamically changed, so that the terrain can be viewed using different light angles. Unfortunately I'm struggling to understand how to do this, as I'm not sure how to 'fake' the position of the light to create a depth texture from.
Essentially, I want to mimic the sun and I'm having trouble getting my head around the fact that directional lights do not have a position, so how can I create a fake position to render the shadows from, while still keeping my scene in view of the orthographic projection.
I'm currently setting up my lights matrices in this way:
mPosition = XMFLOAT3(-30.0f, 30.0f, -30.0f); //Bottom left corner mProjMatrix = XMMatrixOrthographicLH(400.0f, 120.0f, 1.0f, 1200.0f); XMFLOAT3 la3 = XMFLOAT3(126.0f, 0.0f, 126.0f); //Look at center XMFLOAT3 up3 = XMFLOAT3(0.0f, 1.0f, 0.0f); XMVECTOR eye = XMLoadFloat3(&mPosition), la = XMLoadFloat3(&la3), up = XMLoadFloat3(&up3); mViewMatrix = XMMatrixLookAtLH(eye, la, up); mViewProjMatrix = XMMatrixMultiply(mViewMatrix, mProjMatrix);
And you can find the pixel shader I use here.
Thank you very much for your time