• Advertisement
Sign in to follow this  

Sky Color using Perez' model

This topic is 4480 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 am trying to implement the sky color model list on page 9 of this paper: http://www.cs.utah.edu/vissim/papers/sunsky/ and also covered in this gamedev thread: http://www.gamedev.net/community/forums/topic.asp?topic_id=100346 However, I'm not sure of the value ranges I should be getting. For the Yxy color, what range should these values be? x = PerezFunction(perez_x, theta, gamma, zenith_x); y = PerezFunction(perez_y, theta, gamma, zenith_y); Y = PerezFunction(perez_Y, theta, gamma, zenith_Y); I then convert to XYZ using the formula given here (which is different to Yanns): http://www.brucelindbloom.com/index.html?ColorCalculator.html xCIE = (x*Y)/y; yCIE = Y; zCIE = ((1-x-y)*Y)/y; I have tried both and am receiving values for x & y between 0-1 and values for Y in the 7,000's upto 20,000's... I then convert to RGB format using the conversion matrix Yann listed: RGB.r = ( 3.240479 * xCIE - 1.537150 * yCIE - 0.498535 * zCIE); RGB.g = (-0.969256 * xCIE + 1.875992 * yCIE + 0.041556 * zCIE); RGB.b = ( 0.055648 * xCIE - 0.204043 * yCIE + 1.057311 * zCIE); and have also tried using the formula given here: http://www.brucelindbloom.com/index.html?ColorCalculator.html RGB.r = pow(( 3.240479 * xCIE - 1.537150 * yCIE - 0.498535 * zCIE), 1/2.2); RGB.g = pow((-0.969256 * xCIE + 1.875992 * yCIE + 0.041556 * zCIE), 1/2.2); RGB.b = pow(( 0.055648 * xCIE - 0.204043 * yCIE + 1.057311 * zCIE), 1/2.2); RGB values for Yann's conversion are huge, around 10,000 and who knows for the other formula.. Any advice on what figures I should be getting would be muchly appreciated. Thanks, Bence.

Share this post


Link to post
Share on other sites
Advertisement
Hi,

Think I had the same problem and found a 'workable' solution from some thread or other that scaled the final rgb values by 1.0/18000. Its an odd number which may simply be abitary, although the comment next to it says '-- Linear CIE XYZ to RGB 19000'?

Anyway give it a go, see if it helps.

Personally I was a bit disappointed with the results, they are close, but it still 'whites out' too much. I suspect I need to do more tweaking of the various properties.

Share this post


Link to post
Share on other sites
You should apply an exposure function to the sky's luminance Y first before convertig the CIE xyY tuble. Something like
Y = 1.0 - exp( -exposure * Y )

might work. I'm using a default exposure value of 0.1.

Additionaly, your conversion from CIE xyY to CIE XYZ looks wrong. Try:
X = (x / y) * Y
Y = Y
Z = ((1.0 - x - y) / y) * Y

Share this post


Link to post
Share on other sites
Yep, thanks for that. I changed the CIE xyY to CIE XYZ to your suggestion, much better :)

Currently I run "1.0 - exp( -exposure * Y )" over the each rgb value after XYZ to RGB conversion and it works alright.

Screenshot (300kb) Early Evening

Screenshot (250kb) Very Early Morning

I have mapped this to a dome but alas, it isn't mapped over the pole but around it. Is this correct or should i be mapping over the pole? Also, see the black color at the bottom, this is happening at the bottom of the dome. Not sure why, it doesn't occur on the other side. Thanks again everyone!




Share this post


Link to post
Share on other sites
Quote:
Original post by Mephiston
Additionaly, your conversion from CIE xyY to CIE XYZ looks wrong. Try:


Actually both sets of equations are the same, just re-arranged, with a little more its possible to simplify it down further, although with todays compilers that may not be necessary.

I tried using the exposure function instead of the linear value I posted before and whilst it reduced the heavy red/orange glow I get at dawn/dusk, it also made anything either side of these times yellow when it should have been black (or dark blue) and in daytime the sky just became almost one tone of bright cyan.

Still the exposure equation might be useful, i'm going to play around with some values and others such as turbidity and see if it can be tweaked.

Sandy:
Can't view those images it requires server authorisation.
Also i've gone with using vertex colours instead of a texture, although using a texture should be no different.

Share this post


Link to post
Share on other sites
Really? Server Authorization, damn Uni... It seems to work from home for me.

I'll try something else:

Free Image Hosting at ImageHosting
Later Afternoon?


Free Image Hosting at ImageHosting
Early Morning


Sorry, I wasn't clear with my last post. I am using vertex colours and not texture maps. It acts a little funny around the poles though, I haven't tesselated my sphere to evenly.

Thanks noisecrime.

Share this post


Link to post
Share on other sites
Quote:
Original post by sandy_bence
Currently I run "1.0 - exp( -exposure * Y )" over the each rgb value after XYZ to RGB conversion and it works alright.


i think you ought to do the exposure function on the luminance values, not the RGB.

Share this post


Link to post
Share on other sites
Quote:
Original post by sandy_bence
Yep, thanks for that. I changed the CIE xyY to CIE XYZ to your suggestion, much better :)


Are you sure there was a difference between your orginal code and the version Mephiston posted? As far as i can tell they are exactly the same so you shouldn't have seen any difference.

Quote:

Currently I run "1.0 - exp( -exposure * Y )" over the each rgb value after XYZ to RGB conversion and it works alright.


After a litle bit of thought I started to get much better results using the exposure function as opposed to simple linear scaling, but it required much smaller values for the exposure value than the 0.1 that Mephiston posted.

Using exposure = 1.0/18000, works very well in reducing the brightness and 'white out' my original version was experiencing, quite a stunning difference actually. The colours are still slightly 'out', but thats due to the perez values needing tweaking.

Thanks for that Mephiston, I'm so glad as i've been working off and on with this for a long time.


Quote:

I have mapped this to a dome but alas, it isn't mapped over the pole but around it. Is this correct or should i be mapping over the pole? Also, see the black color at the bottom, this is happening at the bottom of the dome. Not sure why, it doesn't occur on the other side. Thanks again everyone!


The images look pretty good, hard to comment though as it can depend on the settings you use for turbidity, time of day, long/lat etc.

Not sure I get the problem 'at the poles' mainly cos you've not shown what the problem is, but really there shouldn't be any problem.

As to being dark below the horizon (i assume thats wwhat you mean), remember this is only a simulation of daylight, and below the horizon is going to be at night. This doesn't simply mean it should be black, more that the behaviour is undefined. You need to be careful of this if you try to use it to simulate night time as you can get strange colours coming through.

Share this post


Link to post
Share on other sites
Quote:
Original post by noisecrime
Are you sure there was a difference between your orginal code and the version Mephiston posted? As far as i can tell they are exactly the same so you shouldn't have seen any difference.


Nope, not positive. Might've changed some other settings as well, not really the ideal testing conditions. :/

Quote:
After a litle bit of thought I started to get much better results using the exposure function as opposed to simple linear scaling, but it required much smaller values for the exposure value than the 0.1 that Mephiston posted.

Using exposure = 1.0/18000, works very well in reducing the brightness and 'white out' my original version was experiencing, quite a stunning difference actually. The colours are still slightly 'out', but thats due to the perez values needing tweaking.


Yeah, I use a much smaller exposure value too. 1.0/10000 at the moment, I'll try around yours and see how that goes.

Quote:
The images look pretty good, hard to comment though as it can depend on the settings you use for turbidity, time of day, long/lat etc.


Thanks, I guess. I think there is a problem with my turbidity values though. IT changes the colours dramatically with the slightest change in value. Values from 1.5 to about 3.5 are alright. Out of this range and the colours turn more bright, surreal. Hard to explain without a picture, i'll try get one up soon.

Quote:
Not sure I get the problem 'at the poles' mainly cos you've not shown what the problem is, but really there shouldn't be any problem.


Again, I'll try get a picture.

Quote:
As to being dark below the horizon (i assume thats wwhat you mean), remember this is only a simulation of daylight, and below the horizon is going to be at night. You also need to be careful of this if you try to use it to simulate night time as you can get strange colours coming through.


Yeah, I switch off perez when it is less than 4am and after about 9pm.

Thanks heaps for you help.

Share this post


Link to post
Share on other sites
Quote:
Original post by sandy_bence
Thanks, I guess. I think there is a problem with my turbidity values though. IT changes the colours dramatically with the slightest change in value. Values from 1.5 to about 3.5 are alright. Out of this range and the colours turn more bright, surreal. Hard to explain without a picture, i'll try get one up soon.


I think I know exactly what you mean, i've got a couple of very pychedlic screenshots from oddities that happened during development and appeared related to the turbidity value.

Strangely though this defect appears to have gone away and i'm unsure why or what I changed. Values from 1.0 - 10.0 all work without going surreal, however below 2.0 I get a mainly black sky whilst aproaching 10.0 it starts going sea green.

To be honest whilst its fun and interesting to get this up and running I realised some time back that in most cases you'd proberbly get better results letting artists create texture images and map those to vertex colours (interpolating between images over time). It gives far greater control for weather effect and the like.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement