Depth logarithm inversion

Hello to the group,

I have implemented logarithmic depth in the vertex shader like the one shown below:

gl_Position.z = 2.0*log(gl_Position.w/near)/log(far/near) - 1;

gl_Position.z *= gl_Position.w;

In a random fragment shader I’m reading the depth buffer which has the log value and I would like to convert this to the corresponding scene depth in world coordinates so that i can compare for example sphere casting depth with the newly converted depth value. How can I make this conversion?