Volumetric fog

What is the fastest way to do convex volumetric fog brushes in quake style engines?

How does q3 do it’s fogging? Looks to me like billboarded polygons drawn on top on eachother, but I don’t really understand how it works. I’ve done loads of websearches, but not found a method which would be fast and usable.

Indeed is doing “billboards”. Check the content flag of a brush to see if contains fog and after you use the planes of the brush to define gl’s user clipping planes. I did this and worked like a charm.

(you have a texture associated with the brush and that texture has a content flag – CONTENTS_FOG is 64)

Ok, so here is my plan:
-I set fog volume’s planes as clipping planes.
-I calculate the midpoint of the fog volume, and calculate the distance n from midpoint (lets say point A) to most distant vertex in the volume.
-I start moving point B along the vector from camera to A by m units, and while the distance from A to B equals or is smaller than n, I draw a billboarded quad. I keep doing this until distance from A to B is
once again larger than n. (we draw all quads which can intercept the fog volume, no more) Quad size is 2n x 2n to make sure it covers the fog volume in screen space. Quad’s center point is on the vector from camera to A.

Problems(?)
-Can I just repeat above for every visible fog volume in my scene? If not, why?
-6 Maximum clip planes available, so fog volume can only be a cube. Split volumes during map compile or…?
-Fog planes (billboards) are drawn after everything else, so everything should work, except transparent objects in front of / inside of the fog volume. How to fix this, or is it a big problem? Sorting all transparent objects and using clipped fog layers don’t seem to mix well.

Am I going to the right direction? Any ideas / comments are welcome.

I would just draw an alpha-blended poly that has the color of the fog on it, and change the alpha based on fog density and distance from the viewer. Shouldn’t be too hard A game that I like to play a lot, Descent 3, uses this technique (although its triangulation leaves a little to be desired. you may consider using a fog “texture”); the only thing with doing this in a game is for polys that do not define the fog volume. For this, you could set a clipping plane, but you’d be limited to your 6, and clipping planes are usually done at least partially in software. Your best bet would be to clip your fog polygons to your fog volume then, I suppose, but I don’t know how you would go about doing the math. That’s why I haven’t done it myself yet :stuck_out_tongue:

You may want to check my VolumetricFogging demo out. http://esprit.campus.luth.se/~humus/

another (original?) method is based off projected textures

Try use GL_EXT_fog_coords extension for simple volumetric fog.

Originally posted by Serba:
Try use GL_EXT_fog_coords extension for simple volumetric fog.

Great, how?

Read the specs at http://oss.sgi.com/projects/ogl-sample/registry/EXT/fog_coord.txt
You can also find info in OpenGL specifications 1.4

PLEASE!! Of course I have read the specs.

See how I explained my method up there? If you can’t do the same with your method, just don’t post.

Name dropping, like “read opengl 1.4 specs”, “ARB_BOGUS_FOOBAR”, “do it with a texture” and “install directx9” is not useful! Thank you.

Billboarding is really fillrate-intensive. Moreover fog billboarding does not look very good (often you can see the seams) unless you’r in a very special case.

As for the 6 clip planes, note that you can add a clipping volume if you use an alpha texture. If you can use multitexturing, you can add even more clipping volumes.

The GL_EXT_fog_coord is by now the most interesting solution since this extension is almost exclusively designed for volumetric fogging. I can send you (by email) a little program with source code that uses this extension.

>>The GL_EXT_fog_coord is by now the most interesting solution since this extension is almost exclusively designed for volumetric fogging.<<

visually fog_coord gives the worse results of anymethod, in fact i cant see the point of the extension myself.
eg for vol fog normally u want the fog to be thicker away from the camera, unlike normal gl fog fog_coord doesnt take the distance into account!

>>for vol fog normally u want the fog to be thicker away from the camera, unlike normal gl fog fog_coord doesnt take the distance into account!<<
But that’s exactly the point why the extension has been defined : you take full control over the fog contribution. Then imagine any shape for your fog.

The problem is that you need an extra computation for every vertex, which can be pretty intensive. Hopefully you can be assisted with vertex programs.

Is it possible to use the normal opengl fog function when you are in the fog and GL_EXT_fog_coord when you are over it?
I have some problems with this myself.

//Ninja

Gread demos Humus, I’d been unable to run them before because they’re Radeon only.

One suggestion make the audio optional or at least include the OpenAL and ogg-vorbis download links.
http://developer.creative.com/scripts/DC_D&H_Games-Downloads.asp?opt=2
http://www.vorbis.com/download_win.psp

It took me a while to find them, others might not persist.

Quake3 does not do billboarding for fog. Quake3 restricts fog volumes so that only one face of the fog brush is allowed to be visible, and that face has to be axial (ie, its normal has to be parallel to an axis). It then does per-vertex fog calculations for all surfaces in the fog. q3map can automatically tesselate geometry inside fog volumes when generating draw surfaces for the BSP, so that this works adequately and fairly rapidly in practice. Lastly, Q3 can draw a fog shader on the visible face to give it a bit of texture.

If possible Q3 will apply volumetric fog in no extra passes, but to handle the general case it can just draw the triangles another time with the appropriate vertex colors and blend function.

Is it possible to use the normal opengl fog function when you are in the fog and GL_EXT_fog_coord when you are over it?

If you mean :

  • viewpoint in fog -> use standard fog (based on depth)
  • viewpoint outside the fog -> use GL_EXT_fog_coord
    then yes you can do it. You still have to switch to those modes “manually”, though. Moreover it may not look very good if the fog is not “equal” at the point where the transition occurs.

Ok, thanks for your answer, but how do I switch modes?

Regards, Ninja

Nevermind!

Zed, how would you do this with projected textures?

-Ilkka