How to convert Z depth to horizontal distance in image effect shader?

I have a working image effect shader (in hlsl) that uses z depth for a few different things, but I don’t want the result to tilted with the camera tilt or a straight line. I’m looking for a radius from the camera, ignoring height.

I’m smoothing and blending the depth result so I don’t need it to be extremely precise. I assume this can be done with a projection matrix or camera vector but haven’t been able to get anything to work so I may be wrong?

You need to extract the world position from the camera depth texture.

Wow, thank you so much! This is even better than what I was hoping to do. The only problem was that it was still tilting with the camera. Since you wrote it to work on an object too, I realized it was only wrong on the camera itself and line 43 creating the viewSpaceRay just had to be moved down below the lines flipping the uvs. Going through this code helped me finally understand some concepts I was struggling with, thank you again!

In case anyone stumbles onto this from a google search, some useful links for understanding this stuff:

Oy, the camera texture UV / projecting space flipping stuff is the one thing I can never get right.:stuck_out_tongue:

(fixed the gist too)