Sign in to follow this  
Quat

Mie Scattering at Horizon

Recommended Posts

I have a flat terrain heightmap, and I color the skyline using atmospheric scattering methods. With just Rayleigh scattering, my horizon is whitish, which is correct. When I add in Mie scattering, the horizon darkens. I stepped through my code to see why this is happening, and it is because the Mie atmosphere density is "thicker at ground (more thicker than Rayleigh)" and so more light is removed due to the extinction part of the calculations. Mie and Rayleigh particles are combined in the extinction process and so it also affects the rayleigh scattering. I have downloaded an implementation similar to mine and it has the same affect, although they sort of hide it with some geometry at the bottom of the screen to hide the horizon. Anyway, is this a normal side effect of only taking into consideration single scattering instead of multiscattering? I can work around it with some fudge factor scalars to still get pretty results, but I want to make sure I don't have an error.

Share this post


Link to post
Share on other sites
Hello once again, Quat.

The problem you describe is a tipical one when you're developing an atmospheric scattering algorithm and it isn't caused by the fact that you're using single scattering.
Probably your sky is getting darker at the horizon because you have excessive concentration values of molecules or aerosols. You'll have to find a better balance between these two values by trial and error, since this hasn't anything to do with physical accuracy, until you achieve good visual results. Don't worry if you take lots of time until you get a good balance, this is more of an art than a science.

Good luck, and don't forget to post your results when you get them right! ;)

Share this post


Link to post
Share on other sites
Thanks, that is one thing that has really been throwing me off. Some of the papers start off very physics like, but all the implementations I have seen use fudge factors.

Share this post


Link to post
Share on other sites
Lol, yeah, I've been through that also.
Most papers use lots of mathematical and physics garbage, like complex integrals, to make formal descriptions about atmospheric scattering but in practice atmospheric scattering is quite easy to understand after you get it right.
So, the formality of the nasty integrals ends up being unnecessary since they are hard to understand and they aren't all that physically accurate anyway (they just describe an approximation, not the real behaviour of light).

So, one of the main difficulties that people face when implementing atmospheric scattering is that they don't know which unit system or representation they should use to accurately represent things like light radiation, aerosols/molecules densities and other stuff. But there's no use in using accurate unit systems or measures since the algorithm itself is not completely accurate anyway.

But there's one thing that you have to be careful with: although physical accuracy isn't all that important, you do have to represent your colors with High Dynamic Range and apply a tone mapping operator (like the one I told you about in a previous thread) on them to get reallistic results.

Share this post


Link to post
Share on other sites
Quote:

you do have to represent your colors with High Dynamic Range and apply a tone mapping operator (like the one I told you about in a previous thread) on them to get reallistic results.


Yes, I have been using the one in Sean O'Neil's GPU Gems 2 chapter. One thing I am still having trouble with...I am able to get an orangish sunset near the horizon, but I would like to "lift it up a bit". In other words, I would like to get the orangeish sunset without having to be as near to the horizon as I currently do (not just the sun itself but the sky color in general around the horizon). I was able to get it a little bit by modifying H0 in the exp(-h/H0) expression used for the atmosphere density for Rayleigh.

Share this post


Link to post
Share on other sites
Well I'm not sure if that's wrong, the horizon tends to get orange only when the sun is already very near it. But could you post a screenshot showing how near your sun has to be for the horizon to get orange?

Share this post


Link to post
Share on other sites


and here is without the terrain (not sure if it is supposed to be black below the horizon--I'm currently looking into this):



and I want it to be more like this:


Share this post


Link to post
Share on other sites
Your screenshots are looking very good and the horizon is getting reddish at the right sun position, so don't worry about it. The only problem I see is that your Mie scattering is way too intense but if you scale it down with a constant it will look fine.

About the photo you showed, that's an hard sunset to get through the usual atmospheric scattering algorithm since is not a common one, it is very intense and dramatic with a very reddish look not only above the horizon but on the whole sky.
On the other hand, your implementation is generating the orange tone at the right time of day and giving a natural and more common sunset which I personally think it is much more desirable.

Anyway, if you really want to achieve the kind of sunset like the one on the photo you just have to play with your parameters of the Mie and Rayleigh scatterers concentrations. I'm not sure if this will be suficient to achieve the effect but you shouldn't modify your code to get it since your code is already providing very reallistic sunsets.

Share this post


Link to post
Share on other sites
Thanks for your reply. Unfortunately, the boss wants a sunset like in the pic :)

I played with the atmospheric density function (as a function of height) and was able to get the sky to turn orangish earlier (with the sun higher), however that change also affects the sky when it is at other positions, which I didn't like. I may end up adding a weight variable to help control this that is a function of the sun angle with respect to the "up" axis.




Also, does your sky go black below the horizon?


Although not necessary at the moment, I have also seen images of some purple sunsets and some other possible rare situations. The whole physics seems very complicated to come with a general model for all this haha.



[Edited by - Quat on March 17, 2010 11:46:42 AM]

Share this post


Link to post
Share on other sites
Yes, changing the parameters to get the desired sunset will affect the sky for the rest of the day cycle. As you said, perhaps its better if you use a function or something to control the density of the scatterers along the day, which I supose it is not a bad solution anyway since it's probably what happens in reality.

No, my sky doesn't look black below the horizon, it looks red... very red. And that makes sense since the light is traversing huge amounts of air. Perhaps you have a look at your code to see whats wrong. Are you performing any kind of light-ray to earth collision detection?

About the purple sunset, I've never heard of such thing. I belive that photo is manipulated to achieve that color. Many of these photographs of sunsets use HDR tricks to generate "fantasy" looks and so they shouldn't be used as reference.

Share this post


Link to post
Share on other sites
Quote:

Are you performing any kind of light-ray to earth collision detection?


No. And after some further investigation it appears to be related to that. Basically I was seeing atmosphere that should normally be occluded by the earth (terrain was only a couple square kilometers).

Share this post


Link to post
Share on other sites
On the contrary, I would expect a black sky bellow the horizon only if you had used some kind of collision detection of the light with earth. But to be honest, I don't really know how the real world atmosphere would look like bellow the horizon if there was no earth, I supose it would look really red like in my implementation but I'm not sure.
Anyway, you shouldn't worry about it because you only have to generate the sky reallistically above the horizon and you already got that working fine. But if you'd like, post your code or pseudo code here so I can try to find if there's anything wrong.

One more thing, collision of light rays with the earth are only meaningful during the sunset when the sun is already bellow the horizon.

Share this post


Link to post
Share on other sites
Quote:

On the contrary, I would expect a black sky bellow the horizon only if you had used some kind of collision detection of the light with earth. But to be honest, I don't really know how the real world atmosphere would look like bellow the horizon if there was no earth, I supose it would look really red like in my implementation but I'm not sure.


When I step through my code, it goes black because of the extinction is so much. For one thing, cutting through the earth gives a large distance to the atmosphere. Second, when it cuts through the earth the altitude goes negative, which makes the density function exp(-h/H0) large, which means more extinction. I am only modeling single scattering, so things would be very different with multiscattering. But like you say, I do not need to worry about this because my view rays shouldn't be cutting through the earth anyway :)

Quote:

One more thing, collision of light rays with the earth are only meaningful during the sunset when the sun is already bellow the horizon.


That is interesting and I am not modeling that currently. So far I have been pretty happy with my sunsets but I will try this and see if it is worth the extra intersection test. Although it seems like the phase function and the increased distance handle removing the light as the sun dips below the horizon.

Share this post


Link to post
Share on other sites
Hmm, the atmosphere isn't thick enough to extinct all the light so maybe the problem is, like you said, your negative altitude values generating HUGE concentration values of air. I never had that problem because I always perform the calculations above the earth surface which means that the altitude is always (cameraPosition.y+ earthRadius).

About the sunset below horizon, you're having good results probably because the light rays below the horizon suffer huge extinction due to the previous problem, which isn't really accurate. Perhaps you should fix this altitude issue just to be sure that your implementation is accurate and to avoid unexpected beahviour.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this