Sign in to follow this  
idioglossia

Sky Shader

Recommended Posts

I can't provide a tutorial, but I can describe the workings of a basic sky shader. I'll work in the HSV colour-space because the setting calls for it:

You have, more or less, two stages to worry about.
The first stage is to determine colour of the sky without a sun. The 'ambient' lightness of the sky will be determined by the time of day and the diffuse lightness by the viewing angle. Notice that the darkest point of the sky is usually directly up (the exception being when the sun is nearby). The lightness of the sky, then, can be calculated using
v = scaled_dimensionless_time_of_day * (1 - dot(view, float3(0, 1, 0)));
where 'view' is the view-vector, and 'y is up'. I'd recommend you clamp this value to be positive.
Then, you have the hue to consider. Directly up is more-or-less constantly true-blue. The colour at the horizon depends on the time of day, and it goes roughly, depening on the air quality & humidity, through the rainbow from blue at midday to red at sunrise/sunset. The intermediate hues interpolate between the two. So to calculate a hue value, you could use:
h = dot(view, float3(0, 1, 0)) * 2/3;
This will be a linear rainbow with the cos of the angle, so you'll likely want to raise the dot-product to some power (say 2-16) to bias the 'blueness' so it doesn't look like an everlasting sunset. So something like:
h = (1 - pow(1 - dot(view, float3(0, 1, 0)), 8)) * 2/3;
This looks like it could be optimised somewhat.
How you caluclate the saturation is up to you, but I'd say that the clearer the day, the higher the saturation. You'll also want to tune it according to the rest of your world. It may well change throughout the course of the day, but fixing
s = 0.7
will probably look fine.

The second consideration is positioning of the sun. The closer the viewing angle matches with the sun's direction, the lighter the sky will be at that point:
sun = dot(view, sun_direction)
This will also want to be exponentiated, but less so than the hue (perhaps a factor of 2-4), and clamped to [0,1].

These two colour values will need to be added (after converting HSV to RGB, if you use the formulas above) and clamped again.
This covers the basics - there are many ways to expand on this. I recommend you keep the cloud rendering separate.

Bear in mind that I pulled the theory and forumlas from the top of my head, so my values (or entire train of though) may be off. I'd recommend looking at a tutorial or two to get an idea of potential pitfalls that I won't have forseen before plunging yourself into a coding frenzy.

Regards
Admiral

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi!

@TheAdmiral: Thanks a lot! Was a good starting point for me. Together with the link that Funkymunky provided I should be able to code a nice sky. Thanks again. :)

Share this post


Link to post
Share on other sites
Hi!

@TheAdmiral: Thanks a lot! Was a good starting point for me. Together with the link that Funkymunky provided I should be able to code a nice sky. Thanks again. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this