Here is a picture:
And there is a working demo:
The idea is to use functionality of clipping planes, with some modifications of the code for clipping Now it’s not clipping, but interpolation between values of 0 and the depth of fog, using distance from a point to the plane.
Looks fine when the camera is above the plane, but when it goes down below, then you can see what’s the trick.
The example that doesn’t break functionality of clipping planes: