Fog too "dense"?

Hi all, I don’t know why I can’t totally see the background even I have the following code setting (density = 0 already)

float g_FogDensity = 0.0f;
float fogColor[4] = {1.0f,1.0f,1.0f,1.0f};
glFogfv(GL_FOG_COLOR, fogColor);
glFogf(GL_FOG_DENSITY, g_FogDensity);
glFogf(GL_FOG_START, 0);
glFogf(GL_FOG_END, 400.0f);

Basically, what I want to do is to apply a distance-based fog to limit the vision of the player so that when he view the distant object, he can just see it to a certain extent (but never not now, which totally can’t see the skybox…)

Problem picture

Thx a lot


Fog density only affects the exponential fog modes. If you use linear fog, the fog’s strength is determined by the FOG_START and FOR_END parameters.

If you don’t want fog for certain elements, it’s best just to disable it before drawing them. If you want the fog to stop getting stronger at a certain distance, you’re going to have to set it up yourself using glFogCoord.


Fixed function fog is computed in eye space (after the modelview matrix, but before the projection matrix).
A definitive answer to your problem requires knowing “how far away” your most distant geometry is - or rather should be, if you’re culling objects based on distance. If it’s 400 units (in eye space), then you should be close to the right setup.

Also note that if the projection matrix is set up with a far plane at, say, 100 units, most of your fog will just be clipped away. So your fog end distance should be less than your far plane distance. This doesn’t seem to be the issue in your case, but keep it in mind.

Regarding your screenshot, I assume the white background is your skybox, completely blended into the fog?
Most fog effects in commercial games aren’t applied to the skybox at all, only to ‘ground’ geometry. So you’d disable fogging before rendering the skybox and reenable it afterwards.