Need help with creating a fog material.

Since I don’t really like the way how the default height fog works in UE4, I’ve decided to make mine own one. I’m using UDK for creating experimental materials such as this one, since it has much faster shader compiler (believe me, the material below works the exact same way as it does in UE4). After some work, I’ve managed to create this material:

This is how I expected it to work. The fog was made in Photoshop and the tower was outlined using fresnel for a better look:

But this is what I’ve got:

As you can see, this fog effect looks good only when the object is close, and the more far away the object is, the worse and worse the effect looks. It’s all caused because the divide number isn’t increasing when the distance gets larger. It can be seen by this picture of the sky. I’ve added the wireframe for a cleaner look:

I do believe that it can be fixed by increasing the divide node’s number that’s connected to the subtract node, but I don’t exactly know how to do this. I’ve tried to use distance node, but I couldn’t figure out what to do next. I honestly will be very thankful if someone will help me with this.

P.S. It also would be incredible if it would be possible to do by not using nodes such as “PixelDepth” or something, since they require transparent materials.