Sign in to follow this  

D3DXVec3Unproject z value confusion

This topic is 4420 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 am trying to understand this method a little better, but the documentation is quite terse. For parameter2 (screen 3d coordinate), exactly how does the z component figure in? Value of 0 gives near-plane and 1 gives far-plane, but what about intermediate values? I tried z=0.5 and got a resulting depth very close to the near-plane! Does anyone understand why? Or am I using the function wrong if I get values like that? I really don't need a generic picker - I want to take screen coords, and center an object there, but at a specific depth (in world-space). Calling D3DXVec3Unproject twice, finding the difference, normalizing the result and then multiplying by the desired depth seems a bit wasteful if I could just use the correct value of z for the unproject call in the first place. Thanks!

Share this post


Link to post
Share on other sites
Quote:

I tried z=0.5 and got a resulting depth very close to the near-plane! Does anyone understand why?

This is due to the fact that the z values in the depth buffer aren't linear. Meaning that they do not go from 0 - 1 linearly.

Keep well.

Share this post


Link to post
Share on other sites
Quote:
Original post by Armadon
Quote:

I tried z=0.5 and got a resulting depth very close to the near-plane! Does anyone understand why?

This is due to the fact that the z values in the depth buffer aren't linear. Meaning that they do not go from 0 - 1 linearly.
Keep well.


Let me rephrase. What does the z value mean in this context? 0 is near, 1 is far, 0.5 is what?

Share this post


Link to post
Share on other sites
Quote:
Original post by Coder
Quote:
Original post by Steven Hansen
Let me rephrase. What does the z value mean in this context? 0 is near, 1 is far, 0.5 is what?

Somewhere in-between. Check Learning to love your Z-buffer.


That is a cool link, and I understand a bit better what happens in the z-buffer. So is this a result of the matrices being used for projection and view, or is it an artificial introduction by the depth buffer implementation? If it is the former, that would explain why the D3DXVec3Unproject works the way it does.

Share this post


Link to post
Share on other sites
I thought about the zbuffer thing for a while, and came to the experimental conclusion that D3DXVec3Unproject doesn't treat the z value in the same way. Experimentally 0.999 was coming out as 500 when the depth varied in [1, 1000]. The zbuffer wouldn't be THAT heavily adjusted to the front, with only 0.001 of the values available for the entire second half of the field of depth.

So, while zbuffer is interesting, I still don't know what z values between 0 and 1 indicate in the D3DXVec3Unproject function. Any other ideas? Thanks.

Share this post


Link to post
Share on other sites

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