- Home /
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. ;)
Here is the effect I want, done with Unity's internal fog settings:
![alt text](/storage/temp/12882-fog+example.png)
And here is the problem that can't be fixed with the internal fog.
![alt text](/storage/temp/12883-fog+example2.png)
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.
Answer by D4rt · Jul 07, 2013 at 03:34 PM
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.
With properly constraining the x and y movement I've managed to make this look quite nice and robust. I guess I'll have to go with this until I have access to Unity Pro and the Global Fog.