how to change ( decrease ) fog ( fogginess ) with altitude ( height )?


Fog is a nice feature but, I've noticed that it is dependent only on distance. I'd like to make it dependent on altitude also.

Please take a look at these images: {

var image1: image

var image2: image



Now, if you look closely, you'll see that things are foggier as they are closer to the ground. Areas that are at higher altitudes are less foggy and that's why sometimes, in nature, we can see the sky even when it's foggy. Because there are less water particles above us than in front of us. So they block visibility less vertically and more horizontally.

I wanted to look at the ways I could make a script for a fog that would do this. basically, there would be three additional parameters: lowerLimit, upperLimit and verticalFalloff.

But first I wanted to check with experienced programmers as would this even be possible? I've only started scripting a few weeks ago and although I'm learning pretty fast, I'm still bad at doing scripts from ground-up without some examples that are at least similar.

I've also found this: but as far as I understand, it's applied to individual objects. Also I don't yet understand where to put that code :) and if I could use it with any kind of material.

That's it, thanx.

As I have found the answer to this question, I will answer it myself so that anyone wondering the same thing can quickly get the answer.

There is now an image effect in Unity which does vertical fog.