Animate Mist color

Hey, I searched some time but I didn´t quite find something to match for me.

I´m trying to make a day and night system and I have everything setup, exept the mist.
At night the mist should change to black and at day again to blueish.

I have a property setup which represents the time of day.
My question is:
How can I make the mist change color, and how to change it dynamically depending on the time property.

Hope you can help me out.

Check sdfgeoffs example , realtime mist or something like that in resources,

yeah, I checked it out but i´m too noobish for it. Would be cool if someone could help me customize it to fit for me.

So I set it up exactly like in the Manual but the only thing it does is changing the background color.


ok got it
was interfering with other 2d filters

But now i have a problem animating the values to match my scene.

You can directly change the property values in the object running the script, but it is probably better to use python to allow finer control.
It really isn’t hard. To set the color you can use:


import mist
mist.setColor([0,0,1]) #[r,g,b]

So what are you planning to have drive the mist? What should change it’s color/depth?

I have a property setup which counts from 0-1200. This controls the lamps, skydome and everything else
Now this should also control the mist density/color.
The problem is that 0-1200 is a complete day+night cycle.
So the mist should increase in density till 600 (midnight) and decrease afterwards again.
Same goes to the color which should turn to black till 600 and back to white till 1200.

Hmm. This is going to be a very hacky solution, but I’ll put it out there.
Have an empty called ‘mistdistance’ have it run this script every frame:


import bge
import mist

density = bge.logic.getCurrentController().owner.worldPosition.z
mist.setMistParameters(density)

Now you can animate the mist’s thickness/density by moving the object up and down. (ie using an actual animation)

You could do an empty for color as well:


import bge
import mist

pos = bge.logic.getCurrentController().owner.worldPosition
r = pos.x
g = pos.y
b = pos.z
mist.setMistColor(r,g,b)

Same deal here (run it every frame). Moving the object will change the parameter.

[Note that code is untested. Should work though]

The proper way to do it is to build a mathematical model: draw out the curves you want, and then express them algebraically (eg peicewise function or fourier series). Then you can use the value of the property as an input to the function, and get the color out. But this takes a lot more work.