I am rendering shadow maps to cubemaps (just rendering raw depth buffer) then projecting them to the scene to do omni-directional shadow mapping.
The cubemap is sampled by the light direction vector on each fragment:
float3 lightvector = pos3D.xyz-lightPos.xyz; float shadowmap = xTextureSh.Sample(Sampler,lightvector).r;
If I compare the shadowmap value to the lightvector length which is the distance from the fragment to the light, I get wrong results because that distance is in world space units, whereas the shadowmap values are not, they are normalized values.
My question is, how could I normalize the length of the light vector the same way the shadow map is normalized? I don't access the shadow view matrix in the fragment shader to do a W division on it, because I would need to send 6 matrices there and I switched to cubemaps exactly to avoid that. I do know hovewer the far clip distance to the shadow cameras, if it counts.
Previously I tried to multiply the shadow map value with the camera far clip distance reading this presentation (on the 30th page), but had no luck. What am I missing?