Jump to content
• Advertisement

# D3DXVec3Unproject z value confusion

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

##### Share on other sites
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.

#### Share this 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

##### Share on other sites
Quote:
 Original post by Steven HansenLet 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.

#### Share this post

##### Share on other sites
Quote:
Original post by Coder
Quote:
 Original post by Steven HansenLet 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

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

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

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

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633735
• Total Posts
3013593
×

## 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!