I'm trying to implement shadow mapping on top of the well known Catalin Zima deffered rendering article. When you get to the point where you rendered the shadow map, and are now trying to check whether the distance from the pixel you're looking at is lower than the distance written in the shadow map, what is the formula for getting the correct texture coordinates in the shadow map.
In one sample this is used:
| output.Shadowcoord.x = lightPosition.x / lightPosition.z / 2 + 0.5f; |
| output.Shadowcoord.y = -lightPosition.y / lightPosition.z / 2 + 0.5f; |
The shadow mapping sample uses this:
| float2 ShadowTexCoord = 0.5 * lightingPosition.xy / lightingPosition.w + float2( 0.5, 0.5 ); |
| ShadowTexCoord.y = 1.0f - ShadowTexCoord.y; |
And a render monkey sample uses this:
| float4 sPos = mul(proj_matrix, pos); |
| sPos.z += 10; |
| Out.shadowCrd.x = 0.5 * (sPos.z + sPos.x); |
| Out.shadowCrd.y = 0.5 * (sPos.z - sPos.y); |
| Out.shadowCrd.z = 0; |
| Out.shadowCrd.w = sPos.z; |
The shadow mapping sample and the first sample use an orthographic camera as the light camera, while the render monkey uses a normal fov camera (i think).
How does the type of camera projection affect these shadow coordinates, and what's the math behind this?