# Calculate light color from light direction and Nishita's sky model

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

## Recommended Posts

Hello everyone!

I recently implemented an atmosphere renderer using Nishita's method as depicted in this blog. Everything looks gorgeous but there is one thing, which puzzles me.

The colors of the environment are all calculated just fine but I always assume, that the sun's color is pure white. This works fine as long as it is day but during sunsets or sunrises my color assumption leads to bright white objects while the sky is red.

So I need to adjust the sun color in respect to the position of the sun.

Can I somehow use Nishita's atmospheric scattering algorithm to calculate the light color? Or are there other, fast methods to calculate a realistic light color?

##### Share on other sites

Proper solution would raymarch from each shaded position to edge of atmosphere and calculate how much is left from pure white light. To approximate this you can just raymarch from sea level(or camera level) to edge of atmosphere and use that value for everywhere. But do not feed this value to sky model but just for direct lighting.

##### Share on other sites

As far as i remeber, CryTek(wich used Nishita's model aswell) just averaged pixels at horizon level and used that as the sun color. So i assume that works quite well(did for them)

Else you would have to get the average color of the complete sky hemisphere

##### Share on other sites

Else you would have to get the average color of the complete sky hemisphere

That's not particularly hard to do either: you render the sky to a cube-map, and then use that to lookup the light colour based on the light direction.

This is roughly the same process used for light probes in modern engines.

##### Share on other sites

Else you would have to get the average color of the complete sky hemisphere

But that would give average skylight color which would be quite blue. Sun color is what is left from white light after transmittance and absorption.

##### Share on other sites

As far as i remeber, CryTek(wich used Nishita's model aswell) just averaged pixels at horizon level and used that as the sun color. So i assume that works quite well(did for them)

Else you would have to get the average color of the complete sky hemisphere

We actually only used the average for fog/scattering, not for the sun color. :)

##### Share on other sites

Buuut it should work for sun color aswell :D

What i've done in the past was(used gpu Gems2 approach) use mie coefficents(the 1/wavelength^4 was rayleigh i think) and some sort of mie phase function and averaged some rays around the sunlight direction.

Worked okayish and the blue tone was only noticeable on the clouds.

Other than that, depending on how realistic it should be, you could compute it for a ray towards the sun and desaturate it based dot(sundir,up) with some smoothstep function.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634059
• Total Posts
3015292
×