I'm working on implementing directional light and an associated shadowmap.
I'm successfully rendering the shadowmap texture using an orthographic projection. But this is where I'm stuck; in the final render pass, how do I work out the correct texture coordinate from my shadow map to sample? And then, how do I determine whether this object is behind that depth?
What I've tried to do so far:
- Pass the lights View+Projection matrix to the vertex shader for my object
- Multiply the objects vertices in the Vertex Shader by this matrix to pass to the fragment shader
- This gives my fragment shader the location of the vertex when it was drawn to the shadowmap
So, with this I can sample the shadow map?
And this gives me the depth of whatever was drawn there.
But it doesn't tell me whether I'm behind or in front of this depth.