by Spike » Thu Apr 19, 2018 9:53 pm
toneddu2000, you're actually looking for two projection matricies.
the one used to render the shadowmap needs to transform from camera space to clip space.
the one used to read the shadowmap needs to transform again from camera space, but this time to the texture coords (with depth).
clip space in opengl ranges from -1 on the left, bottom, and nearest part of the screen, to 1 on the right, top, and furthest part of the screen.
on the other hand, texture coords range from 0 to 1, as does the 'red' component of the shadowmap texture (aka the depth).
sampling from a 2d shadow sampler can be done with a 3d texcoord - the 3rd coord being a reference value to compare the texture against. This gives slightly smoother results. the alternative is to treat it as a regular texture and do the compare yourself, which may be needed with gles2, but mneh.
so the first matrix is a standard ortho matrix, while the second one can be generated from the first by multiplying it against a bias matrix, but if you care about precision you'd get more precise results by calculating it directly.
and don't forget the divide-by-w thing, though I don't recall it actually being needed with ortho matricies.
.