Archived

This topic is now archived and is closed to further replies.

volumetric fog (FlyFire)

This topic is 6673 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Only idea - i have not tried it yet.
Implement it as vertex fog
F(x, y, z) - integrated by z axis fog function,
for each lighted vertex V.color = alpha*V.color +
(1-alpha)*F(x,y,z). You should render background fog
also... may be render F(x,y,z) into billboard
grid vertices ?

Share this post


Link to post
Share on other sites
hmm, i don't know much about this, though i've looked for stuff on it in the past. i guess there
isn't a whole lot out there on the subject. all i can tell you is that i think, if implemented in
realtime, the stencil buffer is used....

-Nick

Share this post


Link to post
Share on other sites
I'll have an article on this topic within a week or
two.

The program will use vertex based multi-pass
blending. (Only one pass for the fog, but it can be
layered on top of other passes). I believe this is
how quake3 does it. It's a good solution for decent
quality, flexibility and speed.

The article will discuss a few other ways of doing it.
particle-based
3d-textures

I hope to expand it to more advanced algorithms,

including animated procedural fog.

I'll post something here when I get it done.

Scott Franke [druid-]
sfranke@usc.edu
druid-'s GLJournal

Share this post


Link to post
Share on other sites
It's a second pass with gouroud shaded polygons.
Doubling the number of polygons, but it could be worse.

You'll notice that having fog in scene will slow down
the Unreal engine quite a bit (check the fps on the
opening shot). I'm not sure what technique they used,
but I'm trying to find out.

Nick:
I'm not familiar with any volumetric fog techniques
that use the stencil buffer. Do you have an example
of one?

Share this post


Link to post
Share on other sites
Another idea - for fog with cylindrical symmetry
u can precalculate a set of map (it will be one -
parametrical) and between the map use linear
blending; the corresponding (to From ->To vectors) map
applied to object either as second texture or as
quad + stencil (here is a stencil buffer)template.

Share this post


Link to post
Share on other sites
Another idea - for fog with cylindrical symmetry
u can precalculate a set of map (it will be one -
parametrical) and between the map use linear
blending; the corresponding (to From ->To vectors) map
applied to object either as second texture or as
quad + stencil (here is a stencil buffer)template.

Share this post


Link to post
Share on other sites
You can try this...

Get the source code, take out the part that renders
the texture (it's bilinear filtered, which is slow as
hell in software). Then try turning down the
tesselation level. It's in the tessBox function -
lines 391-3 in scene.c. It's 8 right now, start at
one and go up if it runs decently.

Share this post


Link to post
Share on other sites
Since i don't have VC installed, so i can't recompile
your example. i'll belive your words.

I have read your article. The only thing i can suggest
is to make some kind of terms glossary for the words
like "The actual volumetric fog computations is a _line
integral_ through 3D space, which integrates a _spatial
lighting function_"
or strips and fans.
Some of them is not clear for me (and, i think, other
people too, who just starting to go into 3d secrets and
tricks).

P.S. Doom doesn't use BSP Trees (introduction - line
13) Hope this is just mistake

Share this post


Link to post
Share on other sites
Well, I'll consider making those changes myself and
posting a low-end version. I'll also consider putting
together a glossary for my web page with those terms
and any others people ask about. That's a good idea.

Doom does use BSP trees actually. Download the source
and see for yourself. Just because it's a 2d bsp
doesn't mean it's not a bsp.

look at :
r_bsp.c & r_bsp.h

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi all,

Yesterday I was thinking about a way to do volumetric fog. And i have some ideas for it.

Most of the time people use 'fog spheres' to do volumetric fog. Because I worked with people who worked very close to the development of Unreal I know that Unreal does fogging also probably using fogspheres.

You need to create a texture (the way Unreal does)and map that on the world with a special blendmode. The texture contains the fogsphere texture and is view dependent. So you have to recalc/upload the texture every time the viewport changes. And since texture uploading on hardware is not really fast this slows down Unreal pretty much. (Unreal's bottleneck were also the enormous texture uploads)

Basicly the intensity of the fog is calculated like this:
density * (fogEnd - fogStart)
If we use a sphere with a constant radius, it is quite simple. It doesnt matter how you view the sphere but it will always result in a texture which is intense in the center and fading to the borders. Like a phongmap sometimes used in fast environment mapping.
Now you need to calculate the density. Maybe you can base that on the distance to the center of the sphere or whatever.

After you created the right texture you will also need to map it on the world. I haven't really thought about this yet. At the moment I'm just thinking about about the generation of the volumetric fogsphere texture.

Well, this were some idea's of me. I hope other people can work this idea out to a working volumetric fog model.

- John van der Burg
Programmer of Oxygen3D http://www.mysticgd.com

Share this post


Link to post
Share on other sites
I get your idea about fog-spheres and i think i know how to basicly implement it. Also i found one good looking fog phere in Unreal. But how to be with ground fogging?
For example, fog over a water surface, like in the starting intro in Unreal?
Place many fog spheres? That seems to be very slow and will not looking good.

FlyFire/CodeX
http://codexorg.webjump.com

Share this post


Link to post
Share on other sites
Hi !

I can simply answer your question. Spherical Volumetric Fog is done by calculating the distance between two intersection points of a sphere. These intersection points are computed by casting a ray from a vertex to the camera, when the ray hits the sphere you get two (or one if a tangent by the way) intersection points. Calculating the distance is used to calculate the fogging of the vertex.

But this is not the only way to do fogging. Basically as said before everything comes down to calculate two intersection points (where the ray enters and leaves the fog). But you can calculate the two intersectíon points with spheres, boxes, 3D Meshes and so on. Spheres are normally used because calculating intersection points is very easy and quite fast. In order to do ground fog, just use a box which starts and is some value high. That's it. Calculate the intersection points with the box and do the rest the same as with spheres.
You can also do that with 3D Meshes, but then calculating intersection points get's quite slow and complicated.

I don't know if Unreal is able to use different Volumes than spheres, but basically this is a way to do very, very nice ground fog.

I will soon post an article (give me 3 or 4 days) which will very detailed explain, how it works, the basics and how to do it in a program. There will also be Source Code and an executable. It will explain spherical fog, but you will also see a few ideas how to do it with other volumes.

When my article is up, I will post it here.

Bye now,

Phillip Schuster

Share this post


Link to post
Share on other sites
I think if we will use spheres, updating lightmaps will be quite fast. Because sphere always result on a polygon highlight in center that fades to borders, we can store initual fog density and then just calculate new one at the center and at the border, and then fade it using simple quadratic equation.
This idea is still not clear for me, but i think this might be fast.

Also, make vertex fog is easy, but how to be with lightmaps fog? (foggin every pixel). At /opengl i found some words about space tesselation, but i didn't get how to do this.

Thanx,
FlyFire
http://codexorg.webjump.com

Share this post


Link to post
Share on other sites
In the little volumetric fog article I wrote a while back, I used axis aligned boxes (not neccessarily square). This makes calculating the intersection trivial. My density calculations treat the box as it if was an ellipsoid (linear or quadratic fall-off along each axis from the center).

Don't feel restricted to using only spheres for your fog volumes. You can generalize the intersection algorithm to work with ellipsoids fairly easily.

------------------
Scott Franke [druid-]
sfranke@usc.edu
druid-'s GL Journal
http://www.gamedev.net/opengl

Share this post


Link to post
Share on other sites
True volumetric fog involves solving the line integral between the camera and the surface on which you want the fog projected. The line integral is essentially a sum of the density of the fog over a large number of tiny steps which, taken as a whole, add up to the distance from the camera to the surface.

Volumetric fog can be approximated by calculating the fog color at each vertex of the tris over which the fog will be projected and interpolating the values in between vertices. OpenGL has an extension to specify fog colors for a vertex (much like texture coordinates).

For those mathematically inclined, the line integral is much like integrating f(x)dx, except dx is now a vector and x is a point in space. Or something like that. This stuff is usually covered in an advanced calculus course in college.

Share this post


Link to post
Share on other sites
Hi !!

I have an example and a very (64 KB) article about volumetric fog done a few days ago.

Go to www.voodoospotlight.com/devknowledge/index.html

There you will find the article, an executable showing my algo and full source-code. You will need Power Render to recompile, however it's understandable even if you never heard about Power Render before.

Just check it out. I got a lot of positive feedback on my article. I think all answers here are covered in my article.

Phillip Schuster

Share this post


Link to post
Share on other sites