Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


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.

  • You cannot reply to this topic
6 replies to this topic

#1 wngabh11   Members   -  Reputation: 128

Like
0Likes
Like

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.



Sponsor:

#2 Bacterius   Crossbones+   -  Reputation: 9043

Like
1Likes
Like

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.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#3 wngabh11   Members   -  Reputation: 128

Like
0Likes
Like

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.



#4 L. Spiro   Crossbones+   -  Reputation: 13928

Like
0Likes
Like

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
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#5 Tasty Texel   Members   -  Reputation: 1330

Like
1Likes
Like

Posted 04 February 2013 - 08:24 PM

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



#6 Bacterius   Crossbones+   -  Reputation: 9043

Like
1Likes
Like

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.


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#7 L. Spiro   Crossbones+   -  Reputation: 13928

Like
0Likes
Like

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.

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums




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.



PARTNERS