Get depth in unreal units from reverse z depth buffer

Hi everyone,

I am currently writing a compute shader that is going to be used in a post-process and I would like to retrieve the view space depth in unreal units (cm). My initial plan was to use ConvertFromDeviceZ from Common.usf; I noticed however that this does not generate the expected values.

My testscene is a default UE4 scene with a camera placed at 0.5 meter (50cm) and 1 meter (100cm) of an object.
I then output ConvertFromDeviceZ(PostprocessInput1[ PixelPos ].x) * 0.01 in the red channel of my render target where the depthbuffer is bound as PostprocessInput1. The expected values are 0.5 and 1.0 however the return values are a lot higher.

I believe that the issue lies with the reverse z projection but I have not yet been able to find the curve that is being used to generate the z buffer.

I would love to know how I could correctly un-project the depth samples from the reverse z projected depth buffer.

Thanks in advance!

Juul

1 Like