PDA

View Full Version : Nice looking fog effect



FlayedOne
07-12-2009, 01:31 PM
Hello,

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:

screenshot (http://www.gamespot.com/pc/sim/freespace2/images/6139782/1/?feature=1&path=2005%2Ffeatures%2Fgreatestgames%2F freespace2%2Ffreespace2_embed001.jpg&caption=%2BHu nting%2Bdown%2Benemy%2Bships%2Bin%2Bthe%2Bmiddle%2 Bof%2Ba%2Bnebula%2Bwas%2Bone%2Bof%2Bthe%2Bmost%2Bu nique%2Baspects%2Bof%2BFreespace%2B2.&cvr=gxK%2F)

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.

increator
07-12-2009, 05:33 PM
According to Google, it seems to be Open Source.
Dunno, try this
http://www.descent2.com/ddn/sources/descent2/

or in general:
http://www.google.com/intl/en/#hl=en&amp...;fp=w37n2H6Quc0 (http://www.google.com/intl/en/#hl=en&lr=&ei=7H9aStCYLIbKnAOprKzdCQ&sa=X&oi=spell &resnum=0&ct=result&cd=1&q=Descent+Freespace+2+sou rce+code&spell=1&fp=w37n2H6Quc0)

MarkS
07-12-2009, 09:18 PM
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".

ZbuffeR
07-12-2009, 11:21 PM
@MarkS : see it in motion before dismissing it.
It looks quite good : http://www.youtube.com/watch?v=EXTEZB2-OE4

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 :
http://www.hard-light.net/wiki/index.php/Getting_started#FreeSpace_2

k_szczech
07-13-2009, 01:25 AM
Yes, these were just billboards - a bunch of quads with some foggy texture painted on them.


The hard part is to allow fluid frame rate despite such overdraw.
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.

FlayedOne
07-13-2009, 02:29 AM
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?

ZbuffeR
07-13-2009, 04:56 AM
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' :)
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 :
http://zurich.disneyresearch.com/~wjarosz/publications/jarosz08radiance.html
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 ?

FlayedOne
07-13-2009, 09:04 AM
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;).

MarkS
07-13-2009, 09:18 AM
@MarkS : see it in motion before dismissing it.
It looks quite good : http://www.youtube.com/watch?v=EXTEZB2-OE4

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

FlayedOne
07-13-2009, 04:45 PM
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 (http://www.easy-share.com/1906741352/SuperNova 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&amp;H(rotate around X),U&amp;J(rotate around Y), and I&amp;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.

FlayedOne
07-14-2009, 07:10 AM
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).

ZbuffeR
07-14-2009, 07:44 AM
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 :
http://developer.download.nvidia.com/SDK/10.5/direct3d/samples.html#SoftParticles
Enemy Territory : Quake Wars have soft particles with opengl.

FlayedOne
07-14-2009, 08:41 AM
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.

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.



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 :
http://developer.download.nvidia.com/SDK/10.5/direct3d/samples.html#SoftParticles
Enemy Territory : Quake Wars have soft particles with opengl.


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

Dark Photon
07-15-2009, 05:44 AM
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"...
Thanks, this looks awesome! I have to try implementing something like this.
There is also a good chapter on this in GPU Gems 3:

* High-Speed, Off-Screen Particles (http://http.developer.nvidia.com/GPUGems3/gpugems3_ch23.html)

MarkS
07-15-2009, 10:52 AM
My Project with fog (http://www.easy-share.com/1906741352/SuperNova v0.10.rar)

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:

FlayedOne
07-15-2009, 12:01 PM
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 (http://www.easy-share.com/1906766338/SuperNova.rar)

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

MarkS
07-16-2009, 05:36 PM
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.

FlayedOne
07-16-2009, 11:38 PM
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 (http://www.easy-share.com/1906791977/SuperNova v0.11 src.rar)

Visual C# Express 2008 (http://www.microsoft.com/express/vcsharp/#webInstall) if you need a C# compiler.

Stephen A
07-16-2009, 11:56 PM
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).

FlayedOne
07-17-2009, 12:13 AM
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;).

Stephen A
07-17-2009, 01:20 AM
Windows.Forms can run cross-platform, too.

I was curious about the project, so I've ported it for you: download here (http://rapidshare.com/files/256747023/SuperNova.zip.html).

I simply switched from Tao.SimpleOpenGlControl to OpenTK.GLControl. Porting the OpenGL calls took a littile time, but the process uncovered several issues (invalid parameters to OpenGL functions - OpenTK catches those automatically). I've also simplified the main loop a little - no need for background threads, you can use Application.Idle (better performance, too).

The only remaining issue is case-sensitivity when loading the bitmaps from disk. Just something to keep in mind on new projects.

Have fun!

FlayedOne
07-17-2009, 02:16 AM
Thank you very much, I seriously don't know what to say :)

Seems, I'll have to take a look at OpenTK ;) Although I'm curious as to what were those incorrect parameters.

That's a really neat trick with the Application.Idle. Really improved performance.

Stephen A
07-17-2009, 06:11 AM
No need to say anything, I had half an hour to burn and was curious to see how feasible a Tao->OpenTK port is (verdict: it really isn't, unless you have written an all-encompassing abstraction layer :) ).

On the other hand, it is actually very easy to move from Tao.SimpleOpenGlControl to OpenTK.GLControl: add the new control, remove the old and add a SwapBuffers() call to the paint event. The rest of the code (e.g. Tao.OpenGl) will continue to work as if nothing's changed, which is very nice for established projects. It seems the compatibility efforts have paid off.