Heightmap gradient based on distance from ground plane

I would like to achieve an depth-map, or gradient effect based on distance (Z value) from the ground (XY plane).

Basically exactly like fog or Z-buffer depth, but not tied in any way to camera. Whatever the camera position is, gradient remains the same. For example, all pixels that are at z=0 are black and all pixels at z = 100 are white. Everything in between has greyscale value.

In this video, near the end, at 8:38 mark is exactly the effect I’m looking for: