Volgut March 09, 2005, 08:53 AM 

Hello,
Currently I'm working on shadows and I have one problem with perspective shadowmaps. I'm rendering my scene from light position to special depth texture. I would like to have linear distance from light to all objects (pixels). In vertex shader I'm transforming my vertex position to world space and then I'm sending .z and .w components to pixel shader. In pixel shader I'm computing distance by dividing .z/.w. And here is my problem. For orthogonal projection .w is always 1, so my distance is linear. But not for perspective projection. I was trying to compute distance in that way: dist=(.z/.w)*(.z/.w), but it's still incorrect. And here is my question  what I have to do to calculate linear distance in perspective projection?
Thanks, regards Tomasz Przechodzki
