3D math question

How to calculate the distance between the pixel that cast shadow and the shaded pixel?

As I understand all shadow casting pixels are in shadowmap and we need to somehow combine light’s position, camera’s projection coord and the value of shadowmap in certain x,y to obtain its world position. How to do that?