Adding a static fog in the bottom of a terrain

Hi ho, another question.

I’m trying to achieve the effect of a static fog in the bottom of my rocky terrain. It’s used mainly for atmosphere and obscuring some ugly details no one needs to know about. :wink:

Here is the effect I want, done with Unity’s internal fog settings:

alt text

And here is the problem that can’t be fixed with the internal fog.

alt text

The fog retracts as it should. Unfortunately it’s not the effect I want.

I reckon custom shader is the way to do it but unfortunately I don’t have a good grasp on them. Any help (on alternative solutions also) would be much appreciated.

I did a little hack that doesn’t work flawlessly and haunts me in my dreams, but hey, as long as others think it works, eh? I added this to my main camera’s script.

    private float startY = 0;
	private float fogStart = 0;
	private float fogEnd = 0;

	void Awake()
	{
		startY = transform.position.y;
		fogStart = RenderSettings.fogStartDistance;
		fogEnd = RenderSettings.fogEndDistance;
	}

	void Update()
	{
		RenderSettings.fogStartDistance = fogStart + transform.position.y - startY;
		RenderSettings.fogEndDistance = fogEnd + transform.position.y - startY;
	}

I’m still thinking about other possibilities and any further ideas would be much welcome.