Jump to content
  • Advertisement
Sign in to follow this  
Volgut

Depth in perspective shadowmap

This topic is 4880 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!