abs(dot(norm, s)) < 0.05
This problem seems to be unique to you. You seem to have custom preferences on what should cast shadows and what should not, as this is not-at-all standard practice and will definitely cause artifacts with moving suns.
L. Spiro
I think I should ignore this thing (do not lit surfaces which normals are orthogonal to the light). As you said this problem seems unique to me, so yeah I found out that my bias matrix is wrong, instead of this:
0.5 0.0 0.0 0.0
0.0 0.5 0.0 0.0
0.0 0.0 0.5 0.0
0.5 0.5 0.5 1.0
I've had this:
0.5 0.0 0.0 0.5
0.0 0.5 0.0 0.5
0.0 0.0 0.5 0.5
0.0 0.0 0.0 1.0
But after correcting bias matrix everything got screwed up, and now I can think of one problem, matrices multiplication, I think I did it wrong. My program is written in Java and using LWJGL library, there is a matrix class with multiply function and I think I'm multiplying it wrong. By reading shadow mapping tutorial, my light's matrix should be computed like this:
lightMatrix = bias * projection * view * model
Function for multiply looks like this:
public static Matrix4f mul(Matrix4f left, Matrix4f right, Matrix4f dest)
It multiplies right matrix by left matrix and stores to the dest matrix.
For testing purposes I set light projection matrix to perspective, and this is how I multiply them():
Matrix4f.mul(projectionMatrix, biasMatrix, lightViewProjectionMatrix);
Matrix4f.mul(viewMatrix, lightViewProjectionMatrix, lightViewProjectionMatrix);
//After every model transform I send this matrix to the shader:
Matrix4f matrix = new Matrix4f();
Matrix4f.mul(modelMatrix, lightViewProjectionMatrix, matrix);
And the only thing that I get is just black line across the terrain
EDIT: It's not the bias problem, I tried to calculate matrices in vertex shader to make sure bias matrix is correct and results were same.