Jump to content
  • Advertisement
Sign in to follow this  
Emark

Different colors in fog by using depth?

This topic is 3671 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
oh well, i just started OGL and dunno anything about shaders... are the shaders fast in drawing? as fast as the default fog system?

Share this post


Link to post
Share on other sites
If you're just starting with OpenGL then shaders may be a little advanced for you. However if you're really insistent then I can recommend this book as a good guide to GLSL shaders in OpenGL.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!