Sign in to follow this  
Emark

Different colors in fog by using depth?

Recommended Posts

Is it possible to create a fog which uses gradient for its depth colors? Like the farest fog color would be blue, but the nearest fog color would be white, and the middle fog color would be blue-white.

Share this post


Link to post
Share on other sites
colorBack = {0,0,1,1};
colorFront = {1,1,1,1};

finalFogColor = fogDepth*colorFront + (1-fogDepth)*colorBack;

Where fogDepth is the depth of the fog in the range 0,1 this will do a linear interpolation of the two colors white and blue for the fog.It can be done in a shader.

Share this post


Link to post
Share on other sites
and how do i use that ?

this is my fog code:
glFogi(GL_FOG_MODE, GL_EXP);
glFogfv(GL_FOG_COLOR, fogColors[fogid]);
glFogf(GL_FOG_DENSITY, fog_density);
glHint(GL_FOG_HINT, GL_DONT_CARE);
glFogf(GL_FOG_START, 0.4f);
glFogf(GL_FOG_END, 1.0f);


but i can choose only one color for it.

Share this post


Link to post
Share on other sites
I have no idea how you can do it with the fixed function pipeline.
You can completely discard the opengl fog and calculate the vertices colors yourself that way you can color them based on distance to camera or any way you like.
If you are using vertex arrays and using the color arrays too then its easy just calculate the distance to the camera and blend between the fog color and the terrain diffuse color.
But this need to be calculated on the cpu every time the camera moves so its not a good way.
The better solution is to use GLSL and write a shader which does what you want.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this