Nice looking fog effect


I’m not sure where to post it, so I’m sorry if that’s a wrong place.

Some of you may have played the game “Descent Freespace 2”. Although it’s a pretty old game, it contained one of the best fog effects I’ve seen:


I tried to find out how it was implemented, but failed(I know that the engine used OpenGL). Does any of you know how to achieve something similar? Or maybe you could point me in the direction of other good fog effects?

Thanks in advance.

According to Google, it seems to be Open Source.
Dunno, try this

or in general:…;fp=w37n2H6Quc0

This looks to me to be something far more simple than fog. It looks like a full-screen pic of fog rendered on top with blending. It is too “perfect”.

@MarkS : see it in motion before dismissing it.
It looks quite good :

The technique seem to be large “foggy” billboards, that fades out when coming closer to the craft. The hard part is to allow fluid frame rate despite such overdraw.

The source code seem to be maintained around here :

Yes, these were just billboards - a bunch of quads with some foggy texture painted on them.

That fog texture is so smooth one could simply render fog billboards to texture that’s 2x or even 4x smaller than screen (I’d go for 4x). Then just use that texture on everything you draw with alpha channel computed from distance.

Inaccurate and fake but it would be hard to notice any difference.

Thanks for replies. I should’ve mentioned, that I know about it being open source, but had trouble finding a working download with it. I finally found it though. After having looked through the source, it seems that the algorith goes like this:

-pre render foggy textures depending on the players rotation
-clip objects that are not visible/switch them to less detailed versions with less polys(engines trait - less visible<=>less polys model version)
-render two quads of foggy texture in front of the player, which get closer depending on the speed, with alpha somehow calculated(I can’t figure that one out… maybe depending on Z-buffer?)
-if one of the quads went beyond the visibility point(too close), dispose of it, and create a new one further.

I might have overlooked something, or understood it wrong though… Is such algorithm even feasible? Are those quads the “billboards” you were talking about?

@k_szczech - by everything you mean adding a new texture to all objects?

What alghorithms should be used to get a good, realistic-looking fog effect?

Of course it is feasible, you have the working code right under your eyes …

In that context yes, those quads are billboards…

What algorithms should be used to get a good, realistic-looking fog effect?

It mostly depends on what you mean by ‘realistic’ :slight_smile:
Most realistic fog techniques are the same as volume rendering (ie. like medical images).
Then if you want nice god rays in the participating media, you need to shoot extra rays from everywhere is all directions, beautifull but very costly :
Then some fluid simulation for the fog buffs, etc.

Or use some cheating methods, like this one in Freespace2 which looks surprisingly good.

Can you share what sort of realism you want to achieve ? On real time framerate ?

Thanks for your help, and for the link. This radiance caching looks awesome.

I’ll try to code something similar to this, and will see how it looks.

I really don’t know. I’m creating some kind of real time 3D “Engine”, pretty much just for fun, and to learn OpenGL while I’m at it, so I guess I don’t need the very best algorithms. Since I’m neither a profesional, nor am I going to spend half my life on trying to get my applications to work at acceptable speed, I was thinking about some cheated methods, similar to the Freespace one;).

Thanks, again for your help;).

WOW! The effect is amazing no matter how it’s done.

Here is what I managed to achieve if anyone is interested. Unfortunately it probably requires .NET 3.5 to run. It’s a bit less random then Freespace’s one(I can’t be bothered to create bigger,more diverse textures) though.

[My Project with fog]( v0.10.rar)

0.11 version uses 20 layers of fog, while the 0.10 version uses 10. You can move the camera with W(forward),S(backward), Y&H(rotate around X),U&J(rotate around Y), and I&K(rotate around Z, partially unimplemented). For best effect, set fog end to ~30 in the ‘graphics->settings’ menu. The problem is, I can hear my GPUs radiator when running the 0.11:P. The fog looks decent even with 2-3 layers, as long as there are no other objects around. Unfortunately 2-3 layers fog looks damn ugly when the billboards intersect with objects. I guess that’s why Freespace 2 took place in space:P.

I’m sorry for a double post, but I have another question, and can no longer edit my last one.

After some tweaking, I got the fog(Freespace like) to look pretty nicely(at least IMO:P ), but I’ve encountered a problem. When lights are in the area, the fog gets lit up just as it should, but only if I’m facing the light. Is there a way of defining 2 normals for the fog billboards? Or maybe telling Open GL to light this one object from two sides? I found the GL_LIGHT_TWO_SIDES property, of a light model, but it seems to only either work for all models, or not at all(switching it on and off during fog rendering doesn’t seem to have any effect).

I would advise to just disable GL lighting for the fog billboards. or you can do something fancy with glsl shaders, but fixed path is quite limited for non-standard lighting.

Unfortunately 2-3 layers fog looks damn ugly when the billboards intersect with objects. I guess that’s why Freespace 2 took place in space:P.

There are ways to fade parts of the billboards depending on the depth difference, so that intersections are much less obvious. It is called “soft particles”, there is a D3D example here but same principles applies with opengl :
Enemy Territory : Quake Wars have soft particles with opengl.

Disabling lightning disables a pretty cool effect that specular lights create, so I’m trying to avoid this. I know nothing about shaders, but it seems I’ll have to give them a go…

In the worst case, I can always render billboards twice with different normals, and lower alpha:P.

Thanks, this looks awesome! I have to try implementing something like this.


Thanks, this looks awesome! I have to try implementing something like this. [/QUOTE]
There is also a good chapter on this in GPU Gems 3:

Is there a trick to getting this to run? I have a dual-boot system with both XP 32-bit and Windows 7 64-bit, both of which have .NET 3.5 SP1 installed. I cannot run your app on either OS. :confused:

Oh damn, of course I forgot to copy referenced dll’s. Updated working version here: link

@Dark Photon - thanks for the link, I’m getting right to reading;)

Are you using GL 3.x by any chance? I see spinning cubes, but no texturing and no fog. Clicking on any of the menus freezes the app and I have to force it to quit. I’m really curious how you did this and I’d like to see the results. I need something similar for a project.

Hmmm… that’s strange, works fine on both my notebook and PC…No 3.x OpenGl here, it uses the default 2.1 context.
Then there probably is only one way:

[source download]( v0.11 src.rar)

Visual C# Express 2008 if you need a C# compiler.

Please include the necessary dlls for the project: Tao.Platform.Windows and Tao.OpenGl.

Also, the dependency on Tao.Platform.Windows means that the project won’t run on Linux/Mac OS. (You are using .Net so it’s trivial to make it cross-platform).

They are included. And they should be in a folder they are referenced to, unless I screwed something up again…

You’re definitely right, but since I’m working on a new project right now, I don’t think, I’ll go back and make a discarded one cross-platform. This, and Windows Forms are so convenient;).