• Advertisement

Archived

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

Equation to calculate RGB of daytime->night time

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 right
blue = cos(angle) * MaxBlueValue;
red = sin(angle) * MaxRedValue;
// then taking care of brightness
AmountOfLight = (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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
quote:
Original post by DevLiquidKnight
how to account for green?


That code only interpolates between red and no red values, blue and no blue...
You will probably also have to change the general amount of light, ie you would interpolate from darkgray to lightgray (dawn til dusk and back) and then add the blue and red value to that shade of gray... or something...

I would have a look at different colormodels such as HSV, CMYK and such. It would probably be easier to interpolate between light and dark in the CMYK or HSV model and then make a conversion to RGB. Shouldnt be hard, just a few lines of code when you find the right recepie.

If you want things to look realistic (good) I would really have a look at those papers though.


[edited by - JOL on April 11, 2004 9:23:38 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
http://www.vterrain.org/Atmosphere/index.html

Share this post


Link to post
Share on other sites

  • Advertisement