# Converting depth buffer values in GLSL shader...

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

## 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 on other sites
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 - ndistance = n + (depthvalue*depthrange)
I might be wrong, but that should work.

Cheers,
-G

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 14
• 9
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
632915
• Total Posts
3009194
• ### Who's Online (See full list)

There are no registered users currently online

×