• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# real and complex fog representatin

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

### #1wngabh11  Members

Posted 02 February 2013 - 09:07 PM

There are some easy algorithms or formulars to simulate fog effect.

such as:

Linear fog adds a linear amount of fog based on the distance you are viewing the object from:

Linear Fog = (FogEnd - ViewpointDistance) / (FogEnd - FogStart)

Exponential fog adds exponentially more fog the further away an object is inside the fog:

Exponential Fog = 1.0 / 2.71828 power (ViewpointDistance * FogDensity)

Exponential 2 fog adds even more exponential fog than the previous equation giving a very thick fog appearance:

Exponential Fog 2 = 1.0 / 2.71828 power ((ViewpointDistance * FogDensity) * (ViewpointDistance * FogDensity))

All three equations produce a fog factor. To apply that fog factor to the model's texture and produce a final pixel color value we use the following equation:

Fog Color = FogFactor * TextureColor + (1.0 - FogFactor) * FogColor

For this tutorial we will generate the fog factor in the vertex shader and then calculate the final fog color in the pixel shader.

but the effect generated is not satisfying, for i think the scattaring effects must be considered. I know some indoor single scattaring formulars, but outdoor effect are different from that indoor.

DO anyone know if there are any complex method to simulate very real fog effect or if there are any physics based equations to simulate it?

And i prefer physics method.

Thanks.

### #2Bacterius  Members

Posted 03 February 2013 - 12:01 AM

Sure. Let K be your extinction coefficient, S your scattering coefficient, P(theta) your scattering phase function. Then the probability that a light ray travelling a distance d in an isotropic, homogeneous medium is scattered is:

K e^(-Kd)

And the ray is scattered with intensity (S / K) P(theta) in direction theta with respect to the incident direction. You can use any normalized phase function for P.

You can also sample the first probability distribution function to sample the average distance travelled by the ray. To do this, first obtain the CDF from the PDF:

PDF = K e^(-Kd)

CDF = integral of PDF = 1 - e^(-Kd)

-Kd = log(1 - CDF)

d = -log(1 - CDF) / K

(this is called inverse transform sampling)

Now select a uniform random number between 0 and 1 for your CDF variable, and compute d, the distance, and you're done. Depending on your extinction coefficient (the higher, the thicker the fog) most light rays will get scattered after only travelling a few metres in the medium, try graphing the last formula with respect to the CDF variable for various values of K and see at what distance most light rays will get scattered. Note K = 0 corresponds to a non-absorbing, non-scattering medium and is, in fact, a special case (the math sort of works out, with the distance travelled always being infinity, even though the PDF and CDF are invalid, but you'll want to handle it properly in your code, obviously)

After being scattered, you need to recurse until the ray is absorbed or otherwise interrupted if you want a correct solution. For extremely thick fog, this will take forever.

All that said, good luck implementing a truly physically based global scattering method in a realtime application. You may prefer to consider cheaper, approximate alternatives, especially since you can usually use a screen-space solution for fog and haze (as outdoor scattering is predominantly forward scattering).

Edited by Bacterius, 03 February 2013 - 12:10 AM.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

### #3wngabh11  Members

Posted 03 February 2013 - 05:21 AM

THanks for your help. I have understood what you say.

Do you know Tyndall effect? For example, in the forest, there will be some 'god' light when sun light is across the leaves of the tree. We can use some techniques, such as billboard, to show this effect, but we can also use analytical methods to implement it.

Take the indoor situation as an example, due to the effect i said above, if there is a lamp or some other types of source light there, there may be glow effect, shadows, god light( depends on the type of light ). If I use the way this link, www.cs.berkeley.edu/~ravir/papers/singlescat/scattering.pdf, introduced, i just simulate the equation in this paper instead of post processing methods to generate the vivid effects. I implemented this algorithem before and I think it is much better than post processing methods to show the effect. Another article in the book shaderX 7, called 'a hybrid method for interactive shadows in homogeneous media', impressed me a lot. the author uses a method which I think is closer to physical simulation and the effects are very excellent.

At the outdoor situation, I also hope to implement these effects, such as glow, just based on such kinds of equations. When deciding the color of each pixel, I can use more complex model(BRDF) instead of the producting of two vectors(N * L). I can add Ambient Occlusion instead of simple shadow map. It goes without saying that shadow map is needed. However, if I want to implement the glow effect, what I know is just post processing the render target. Besides, I think the method you said cannot let the fog have the color caused by scattaring. As a result, the translucent feature is displayed, but the fog color is monochromatic. So, I don't know how to combine the affect of ambience which makes the fog has color with the thickness of fog. The shortcoming of the link paper is that it is just suitable for point light rather than sun light.

### #4L. Spiro  Members

Posted 04 February 2013 - 06:23 PM

Sure.

Do you have any papers on this? I saw one a while back and for the life of me I can’t find it again.
I remember it had pictures of a pot on a table in what looked like possibly an Egyptian tomb or maybe sponza. I believe it was an efficient real-time physically based participating medium research paper.

L. Spiro

### #5Tasty Texel  Members

Posted 04 February 2013 - 08:24 PM

Mhmm, perhaps this one: http://www.cs.berkeley.edu/~ravir/papers/singlescat/scattering.pdf ?

### #6Bacterius  Members

Posted 04 February 2013 - 10:12 PM

Sure.

Do you have any papers on this? I saw one a while back and for the life of me I can’t find it again.
I remember it had pictures of a pot on a table in what looked like possibly an Egyptian tomb or maybe sponza. I believe it was an efficient real-time physically based participating medium research paper.

L. Spiro

As well as the paper cited by Bummel, there's this paper: "Rendering Participating Media with Bidirectional Path Tracing", which briefly discusses the physical theory in the first few pages then goes on to show how to implement it with BDPT.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

### #7L. Spiro  Members

Posted 04 February 2013 - 11:27 PM

Thank you. The link from Bummel is for what I was looking but yours will also be useful.

L. Spiro

Edited by L. Spiro, 04 February 2013 - 11:56 PM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.