D3DXVec3Unproject z value confusion

Started by
4 comments, last by Steven Hansen 18 years, 5 months ago
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!
Advertisement
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.
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?
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.

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.
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.

This topic is closed to new replies.

Advertisement