Jump to content
  • Advertisement
Sign in to follow this  
Waaayoff

[DX11] How to read a value from the depth buffer?

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

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

I want to read the value from the depth buffer corresponding to the position of the mouse but i'm not sure how...

[/font]

Share this post


Link to post
Share on other sites
Advertisement
You need a 1x1 pixel staging buffer with the same color system as the depth buffer

* Convert the mouse position to pixels if needed
* Use CopySubresourceRegion to copy one pixel from the depth buffer to the staging buffer
* Map the staging buffer
* Read the data from the staging buffer
* Unmap the staging buffer
* Convert the depth value from ZW scale to linear depth using 2 values from the camera's projection matrix
Linear = ProjectionMatrix._43 / (ZWDepth - ProjectionMatrix._33)

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.

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!