Jump to content
  • Advertisement
Sign in to follow this  
giant

OpenGL Fog Filling in Entire Screen

This topic is 4094 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

Hi I'm having an issue with adding OpenGL fog to my 3D Engine. I am following lesson 16 from nehe and when I build and compile the source code all works fine. As you may know the Fog code is quiet small, so I have added it to the initialization part of my Engine.
GLuint filter;				         // Which Filter To Use
GLuint fogMode[]= { GL_EXP, GL_EXP2, GL_LINEAR };      // Types Of Fog
GLfloat fogColor[4]= {0.5f, 0.5f, 0.5f, 1.0f};	// Fog Color
..
..
..
..
..
glFogi(GL_FOG_MODE, fogMode[0]);		// Fog Mode
glFogfv(GL_FOG_COLOR, fogColor);		// Set Fog Color
glFogf(GL_FOG_DENSITY, 0.35f);		// How Dense Will The Fog Be
glHint(GL_FOG_HINT, GL_DONT_CARE);		// Fog Hint Value
glFogf(GL_FOG_START, 1.0f);			// Fog Start Depth
glFogf(GL_FOG_END, 50.0f);			// Fog End Depth
glEnable(GL_FOG);				// Enables GL_FOG


Now the entire screen is filled with the color of the fog. If I switch to wireframe rendering I can see that the terrain/water and mesh are rendered, but they are all grey. My ideal goal is to have fog under the water to add more realism with depth. In essence I want to have a cube of fog. This sounds like volumetric fog to me. I have tried to do this using the extension glFogCoordfEXT but this also fills the screen with the fog color when used in my engine, but this works correctly in the sample program. To solve these issues have tried to comment out as much as possible, but the problem still persists. Any other information I can think of which I wouldnt believe would cause a problem but might help I am using glew32.dll I am using VBO's whereas the sample programs render vertex by vertex Thanks

Share this post


Link to post
Share on other sites
Advertisement
is either
glFogf(GL_FOG_DENSITY, 0.35f); with GL_EXP, GL_EXP2

or

glFogf(GL_FOG_START, 1.0f); with GL_LINEAR
glFogf(GL_FOG_END, 50.0f);

ie not both

but for what u want youre best ignoring glfog altogether (incl glFogCoordfEXT)
+ look into methods of doing vol fog, theres prolly at least 5 methods u can achieve what u want depending on wether or not u want to use glsl etc

Share this post


Link to post
Share on other sites
Hi zedz

Thanks for your reply. Im glad to hear that my guess that I needed volumetric fog was correct. I have looked on gamedev and the following links

Volumetric Fog
Spherical Volume Fog

are pretty old and do not show any practical implementation, and elsewhere I look though google everything seems to use glFogCoordfEXT() which you advise against.

Do you have any links to good Volumetric Fog tutorials/implemtations from which I might learn, or if you have the knowledge would you mind dispencing some here.

Thanks
Ciarán

Share this post


Link to post
Share on other sites
heres an old demo of mine
http://www.zedzeek.com/APPS/volumetric%20fog.rar
mouse button to move camera

i believe each vertice in the fog(underwater) i measure the dist to the camera, + then set the fog amount based on that,
youll prolly want something like the following for the final shading
color = texture * (1-fogamount) + fogamount*fogcolor

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!