Jump to content
  • Advertisement
Sign in to follow this  
hayden

Converting depth buffer values in GLSL shader...

This topic is 3663 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

Hi everyone, i need to convert the values of a depth map, range of 0 - 1, to the actual distance from the camera. I'm using a method released in a computer graphics paper: ////////////////////////////////////////////// P33 = (f + n)/(n − f) P34 = (−2 f × n)/(f − n) z = −P34/(depthValue + P33) being n and f the near and far clipping plane, respectively. ////////////////////////////////////////////// But none of this is giving me right results... I have n=1 and f=50, with depthValue (depthbuffer) in a range between zero and one. Then mathematically i'm not getting this right, the results are all negative and not the real distance from the camera. Is anybody here who has done this kind of depth conversion? Or, at least, can give me any hint or somewhere (link) to research a bit better? I know i can't figure something important, but don't know what :S Thanks for your time :) Hayden

Share this post


Link to post
Share on other sites
Advertisement
You're right; this doesn't seem to work mathematically. I'm getting things in the range -1.5 to -3.0.

Can't one just go:
depthrange = f - n
distance = n + (depthvalue*depthrange)
I might be wrong, but that should work.

Cheers,
-G

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!