Fog Question..

This is not about JOGL per say, but more of just an OpenGL question and I don’t know of any forums that deal primarily with OpenGL, so if someone can answer this anyway…

I am trying to apply fog to a simple 3D object (cube). In all the examples I have come accross, in order for the fog to look right, you have to make the background color the same color as the fog. This seems strange. If I leave the background color black (or whatever color aside from the gray fog color) the object gets “fogged” but the “world” is not.

Am I doing something wrong? Is there something more I need to do? It seems strange to me because you won’t always have a single background color in a scene.

Thanks.

Nope, you’re doing it exactly right. You have to set your background color to match your fog color.

Is there any explination of this somewhere? What happens if your scene has terrain, mountains, a sky, some trees, etc, etc. And you need some fog. There is no single “background color”. Or is the background color the color before you added everything?

Fog, lighting, etc only affect vertex colors. Because there are no vertex colors in a “clear” background, there is no color to affect.

I think what you need is volumetric fog. That effect is more like real fog, but it is much more complicated to implement… Volumetric fog is the fog that doesn’t apear all over the scee, but on some part of your virtual world.

Normal OpenGL fog just applies fog color to objects in different alpha values. Alpha value is bigger on close objects and smaller on distant objects, so if the object if far enough fog color will completely cover it.
If all of your scene is filled with objects or terein surface you should get desired result, if not, you should set same color on backround and fog.

You can find a simple tutorial on volumetric fog here.
I know of another technique described here, but it’s rather convoluted, using the stencil buffer and multiple passes. I wouldn’t go that route, but it’s always nice to see different implementations.