Volumetric fog problems......,


Well, i have implemented some volumetric fog effects in my engine, and i have some problems, that after some time thinking, i dont have a solution for it…, maybe you guys can help, give me some sugestions.
Essentialy, in the editor, a draw a cube and assign that cube as fog! Then when i’m building my data, i detect if that triangle is inside the fog volume, if it is a mark it as being inside a fog.
Then, at runtime, when i detect a face that is inside a fog volume, i use the glFogCoordEXT to assign the fog the the face.
This works fine, if the faces all have the same height, if i have a face with an Y value of 10, and another one with 2 , the fog won’t look ok…, any way to assing a value to the glFogCoordEXT so that faces with diferent heights look ok ?
The other problem is with models.
Take a look at :

With a model, i can’t assing the fog this way…, so, how can i make the model look ok?

thanks for any help/suggestions


Volumetric fog is not that simple as marking the face as fogged or not.

glForCoordEXT is a per-vertex state, so you can set different fog values for each of the vertices of the face (and OpenGL will shade the face with smooth gouraud shading).

This way, you must calculate the distance traveled inside the fog volume, using the line that goes from the eye to the vertex.

The general idea is:
-calc the intersections of the line of sight and the fog volume
-with that, calc the distance traveled by the line inside the fog.
-use that distance as a parameter in a fog formula of yours (maybe taking into account other factors like fog density, height, etc), in order to get the amount of fog the vertex should get.
-after you have done this for all vertices, draw the triangles with one glFogCoordEXT per vertex using the fog amount value calculated before.

The back portals of the fog sector, which are not filled by polys can only (I mean, you can do it like this) be blended over the scene behind, means, you have a portal that is marked as a exit and entry point of the fog. If the portal is visible from the exit point (Actually I mean, when you are inside the fog sector), you calculate the fog color for the vertices of the portal in a only distance dependant way and render it over the scene behind. The vertices inside the fog volume get fogged accordingly. If it is visible from the entry point (you stand in front of the fog sector), you need to cut the view-line by the portal plane to get the actual fog colors. Means it will be good if you have only small portals which lead into the fog volume (large exiting portals wouldn’t be too bad (but for overdraw), but they are entry portals seen from the other side… ).

If you however have some camera script running and know the sides from which the camera will view the fog portals, you can make the ones that exit the fog sector make very large, if your engine isn’t fillrate limited already.