Jump to content
  • Advertisement
Sign in to follow this  
averisk

OpenGL 'Select buffer' returns weird, non-linear depth values

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

I'm using the standard way of picking objects using opengl (ie. glSelectBuffer, gluPickMatrix, glLoadName, etc. ) and this works, at least in terms of actually finding the selected object. And now I'm trying to use the depth values in some other calculations, but I can't get the right numbers out of it. According to MSDN: "Returned depth values are mapped such that the largest unsigned integer value corresponds to window coordinate depth 1.0, and zero corresponds to window coordinate depth 0.0." So I take the depth value, divide by max int, and print the number, and this basically works. Depth value of 0 refers to the near clip plane and depth value of 1 refers to the far clip plane (like MSDN says), but the numbers in between are not linear, they rapidly approach 1 as my object gets closer to the near clip plane and slowly trails back to zero as it moves away (exponential maybe?) Anyway, I could always get the depth value myself, but the application is pretty performance heavy already, so I'm looking for ways around this. Anyone know why the values are like this? Thanks for your time

Share this post


Link to post
Share on other sites
Advertisement
The Z-buffer usually is non-linear so your buffer read works well. If you want a linear buffer use a W-buffer instead. The usual Z-buffer behaviour is such that near objects are depth-tested with greater accuracy because artifacts would be more disturbing. See here for a detailed explanation. Here too.

Greetz,

Illco

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!