Most of this has already been said but just for completeness:
DistanceToNearestSurface only works if you have ‘Generate Mesh Distance Fields’ project setting enabled (you have to restart editor after changing), and you are on DX11 hardware. This means Geforce 4xx and above, Radeon 6xxx and above.
DistanceToNearestSurface will always return around 0 if sampled on a shadow casting opaque surface, by definition. It’s the distance to the nearest opaque surface. However only static mesh components + foliage + instanced SMC’s actually have distance field reprsentations, so on something like Landscape you should get a non-zero value. On other meshes you have to disable either CastShadows or bAffectDistanceFieldLighting in order to sample the distance values of other meshes.
Going forward we can have landscape affect the global distance field, let me know if that would be useful.
That would be very useful indeed. For example, you could mask crashing waves on ocean planes and in reverse make effects for wet sand, erosion or what have you. Yes, pretty please with sugar and cream and jam and chocolate on top