#### Archived

This topic is now archived and is closed to further replies.

# Equation to calculate RGB of daytime->night time

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

## Recommended Posts

I have a time value that can go up to 360. once It reaches 360 it resets to 0 I am trying to make realistic sky effects and was wondering how to caculate the RGB values for each point of time. eg, morning it would be orange yellow, noon would be blue, dsuk orange yellow, night black. And was wondering if anyone knows of something such as this?

##### Share on other sites
Well, it all has to do with the refraction of the sun''s electromagnetic waves through the atmosphere at different times of the day. So, I suppose you can find an equation for calculating what wavelength of light an observer would see at different times of the day.

But that''s kinda difficult I would simply go with a model that interpolates between the different times of the day. For example, you know it''s orange/reddish in the morning and goes toward blue in the afternoon. So maybe you could interpolate between orange and blue from the morning to the afternoon, and then back down to orange in the evening. Ideally you''d want more than three known points, so maybe spend some time outside observing sky colors at different times of day?

Just some suggestions.

##### Share on other sites
well anything easy would be nice lol

##### Share on other sites
The colors would also differ according to longitude and season...will you model summer in the arctics
- I''d go with some simple interpolation.

##### Share on other sites
lol.. not lookning for something that complicated just something siimple to change its colors

##### Share on other sites
I''d suggest using a sin cos function somewhat like this:
pseudocode:angle = 2*PI*time/360; // your time was from 0 to 360 rightblue = cos(angle) * MaxBlueValue;red  = sin(angle) * MaxRedValue;// then taking care of brightnessAmountOfLight = (before 0800) ? pitchblack : brightlight; //  - or something

Actually, I think you should have a different colormodel than the RGB one to do this correctly. You should probably tamper with gamma and cromatica and stuff... try to google for different colormodels, converting between them would probably not be to hard...

##### Share on other sites
"A survey of the modelling and rendering of the earth''s atmosphere"

Slides (should get you started)
Full paper (ACM Digital Lib account required)

Even if you don''t have an account, the list of references should give you a few keyword to plug into google

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan

##### Share on other sites
Actually this paper: "A practical analytic model for daylight" is simpler and matches your need better. Additionally, it's freely available

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan

[edited by - Fruny on April 10, 2004 4:52:05 AM]

##### Share on other sites
pseudocode:angle = 2*PI*time/360; // your time was from 0 to 360 rightblue = cos(angle) * MaxBlueValue;red = sin(angle) * MaxRedValue;

this works very well however.

how to account for green?

[edited by - DevLiquidKnight on April 10, 2004 8:34:36 PM]

##### Share on other sites
If you don''t feel like implementing the skylight models in the paper Fruny suggested, you could always interpolate between the colors that you''ve chosen for each time of day; between morning (6 AM) and noon (12 PM), interpolate between yellow orange and blue. I don''t think this looks very realistic, but whatever floats your boat.

• 9
• 13
• 41
• 15
• 14