Sign in to follow this  

Depth in perspective shadowmap

This topic is 4664 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Here's another way to do it. In your vertex shader, transform the position into world space as you're doing now. But instead of sending just the .z and .w components to the pixel shader, send the three-element position. So send your .xyz to your pixel shader.

So in your pixel shader, you now have the position of a particular pixel in world space. You can then compute the distance from the light source (a constant in your pixel shader that is set up by your main applicaiton) to this pixel and store that distance in your shadow map.

neneboricua

Share this post


Link to post
Share on other sites

This topic is 4664 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this