# Calculating sun light color from atmospheric scattering

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

## Recommended Posts

Hello, I'm working on an outdoor illumination system that tryies to mimic the illumination caused by the sun and the atmosphere in a reallistic way. I have already a real-time atmospheric scattering shader that generates reallistic sky color and which I also use to generate a skylighting effect (light comming from all directions of the sky), but one puzzling question came up to my head: can I use the same atmospheric scattering algorithm to calculate the color of the sun's direct light? If so, how is it done? I'm a bit confused about the way sun ligth color is affected by the atmosphere. Is the sunlight color the same color we seen when we look at the sun (caused by the atmospheric scattering, mainly by Mie scattering)? Thanks in advance. [Edited by - jcabeleira on February 26, 2010 12:47:53 PM]

##### Share on other sites
Since no one answered my question, I'll ask it in another way:
How can I reallistically calculate the color of direct sunlight for a given time of day?

##### Share on other sites
Eric Bruneton has a homepage with many different papers on realistic rendering, including one on atmospheric scattering. Maybe you can extract some useful information from that.

##### Share on other sites
Thanks, I already knew Eric Bruneton awesome work but unfortunately it doesn't provides me the answer I'm looking for.

In practical terms, could I get an approximate color for the sun's direct light by sampling the sky area that we perceive as the sun? For example, look at this image generated by my atmospheric scattering imlementation:

Illumination from the sun and sky is very complex because light comes from all directions of the sky. But when we look to the sky, the most intense light comes from the area around the sun which is mainly caused by Mie scattering and I supose that this gives the main contribution to the lighting. So when we approximate the sunlight illumination by using directional lights, what we're doing is using the most direct sunlight that comes from the sky, that lighting generated mostly by Mie scattering, as the only source of illumination, right?
So it makes sense that I calculate the sky color by sampling the sky on the area we perceive as the sun, right?

##### Share on other sites
correct lighting always has to be computed over the entire hemisphere. when you only sample the area of the light source, you'll get shadowed surface points when the sun is occluded. however, this is not the case when you sample the hemisphere of all incoming directions.

if I understand you right, you probably need something like this to separate important sampling points from less important sampling points.

nick

##### Share on other sites
Exactly, Nicmenz. I had already considered doing an importance sampling over the entire hemisphere in a very similar fashion like the one you proposed.

Unfortunately in practical terms I need to separate indirect lighting from direct lighting, because of shadows generated by direct lighting (which have to be generated with shadowmaps).
So, currently I'm sampling the sky only to generate reallistic skylighting.

Yes, you can PM me.

##### Share on other sites
Hi jcabeleira,

The irradiance is calculated as the integral over the hemisphere of the point of all incoming light.

E(p, n) = Integral[L(p, omega) * cos(theta)]domega
E represents the irradiance at position p with normal n.
L represents the incoming radiance in that direction.

In an ideal world you could have L be this,

L(p, omega) = SampleSky(omega) * Visibility(p <- omega).

Then you could integrate that across the entire hemisphere and get really great looking lighting but it wouldn't quite be real time.

Ok, so what do we do. We already know the direction of the light so what we want is to find some ambient color(a) and diffuse light color(d) that best represents irradiance. We can use least squares to find it,

Least Squares to minimize:
E(d, a) = Integral(a + d * n.l - Integral(L(p, omega) * cos(theta)ds)^2dN

Well, we need to get rid of the inner integral so the best solution is to project it onto an SH basis. From there you can solve analytically. You can simply use a Monte Carlo integrator to evaluate it once per frame.

You can get the answer by sticking it into Maple. Peter-Pike Sloan has a derivation in his article stupid SH tricks that gives the solution.

The key is you'll need to get rid of that inner integral by projection.

-= Dave

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 26
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633384
• Total Posts
3011595
• ### Who's Online (See full list)

There are no registered users currently online

×