|
Quick And Dirty: Realistic Skies with Sky Spheres
by Mike Kost
Introduction
Although it is possible to create amazing sunsets and sunrises with
media, it's dreadfully painful. Povray takes a long time to render it,
and it may not be worth it. Fortunately, sky spheres come to the
rescue. This latest Quick & Dirty tutorial illustrates how to
create a noteworthy sky using Gimp 2.2 and Povray 3.6.
Quick Reading
Can't fly into the wild blue yonder without some book learning first. A
little background material will help nicely:
Sky Sphere Structure
The sky_sphere directive provides a great way to add background to a
scene. The sky sphere color gets used when Povray rays never collide
with an object. A simple sky sphere structure is shown below:
sky_sphere {
pigment {
<function>
color_map {
[0.0 <color>]
...
[1.0 <color>]
}
}
}
Each sky_sphere contains a pigment. The pigment is almost always a
color_map of some kind. The real magic in creating a great sky is
generating the color map.
Also important is the function used with the color map. Sky
spheres are typically shown using a function of 'gradient y'. This
works but has problems. If you get a peak of the sky below y=0, the
color_map will wrap as shown below.

Two preferrable alternatives are shown below, each with "better"
behavior

|
|

|
function { abs(y) }
|
|
function { max(min(y,1),0) }
|
We prefer using the second alternative, and all the sky spheres in this
article do so.
Preparing The Image
To generate that amazing color map, it helps to start with a picture
from the
real world. I took this picture with my digital camera on an otherwise
uneventful flight from Chicago to Austin.

To get the image down to something workable, open it up in the Gimp and
crop it [1] to a workable section of sky.

Having cropped the image, flip it 180 degrees by using
Image->Transform->Flip Vertically. This gives the image below.

Althought it seems goofy, it's easier to work with the sky upside-down.
Just believe for the moment - it'll be explained in a minute. Having
gotten this far, I suggest saving off the small section of sky so that
it's easy to refer to.
First Sampling Pass
From here, engage the Color Picker tool [2] and zoom
in real close (say 800%). We're going to be looking at individual
pixels and it helps to be able to find them.

This is where the tedious work begins. To get a good sky_sphere, we'll
slowly
iterate through the section of sky and pick colors to place in the
color_map. Every pixel has an X and Y value. Y increases as you move
down the image and X increases as you move to the right of the image.
This is why the image is flipped - Povray thinks increasing Y is up
while Gimp thinks increasing Y is down. By inverting the image, we keep
the ground level (Y = 0) low and the sky (Y = a lot) high.
The sky segment is 270 pixels tall, numbered 0 - 269. When creating
sky_spheres, start by picking the first pixel (Y = 0), the last pixel
(Y = 269 in this case), and then filling in about every 20 or so.

Now, stepping through approximately every 20 pixels, we get the color
map entries below.
[ 0/269 color rgb <120/255, 79/255, 51/255>]
[ 20/269 color rgb <255/255,246/255,203/255>]
[ 40/269 color rgb <236/255,223/255,214/255>]
[ 60/269 color rgb <166/255,176/255,201/255>]
[ 80/269 color rgb <103/255,127/255,171/255>]
[100/269 color rgb < 66/255, 97/255,143/255>]
[120/269 color rgb < 47/255, 75/255,122/255>]
[140/269 color rgb < 37/255, 60/255,102/255>]
[160/269 color rgb < 32/255, 51/255, 84/255>]
[180/269 color rgb < 27/255, 42/255, 71/255>]
[200/269 color rgb < 25/255, 36/255, 58/255>]
[220/269 color rgb < 22/255, 31/255, 48/255>]
[240/269 color rgb < 18/255, 27/255, 42/255>]
[260/269 color rgb < 15/255, 21/255, 33/255>]
[269/269 color rgb < 15/255, 21/255, 33/255>]
Taking this and rendering it in Povray gives the image below

Second Sampling Pass
Looking at the first rendering, there's some things that aren't right.
The horizon doesn't capture the yellowish sunset glow and the blue has
obvious bands to it. To fix this, look through the first pass color
map, and find regions where the color changes a lot between entries.
Sample new pixels to fill in the gaps. A second pass is shown below
with the new color_map entries marked.
[ 0/269 color rgb <120/255, 79/255, 51/255>]
[ 1/269 color rgb <141/255, 83/255, 46/255>] // New
[ 2/269 color rgb <177/255, 86/255, 41/255>] // New
[ 3/269 color rgb <235/255,128/255, 72/255>] // New
[ 5/269 color rgb <255/255,159/255, 72/255>] // New
[ 10/269 color rgb <255/255,218/255,112/255>] // New
[ 20/269 color rgb <255/255,246/255,203/255>]
[ 30/269 color rgb <255/255,240/255,219/255>] // New
[ 40/269 color rgb <236/255,223/255,214/255>]
[ 50/269 color rgb <205/255,204/255,212/255>] // New
[ 60/269 color rgb <166/255,176/255,201/255>]
[ 70/269 color rgb <129/255,149/255,182/255>] // New
[ 80/269 color rgb <103/255,127/255,171/255>]
[ 90/269 color rgb < 79/255,110/255,154/255>] // New
[100/269 color rgb < 66/255, 97/255,143/255>]
[110/269 color rgb < 52/255, 84/255,131/255>] // New
[120/269 color rgb < 47/255, 75/255,122/255>]
[140/269 color rgb < 37/255, 60/255,102/255>]
[160/269 color rgb < 32/255, 51/255, 84/255>]
[180/269 color rgb < 27/255, 42/255, 71/255>]
[200/269 color rgb < 25/255, 36/255, 58/255>]
[220/269 color rgb < 22/255, 31/255, 48/255>]
[240/269 color rgb < 18/255, 27/255, 42/255>]
[260/269 color rgb < 15/255, 21/255, 33/255>]
[269/269 color rgb < 15/255, 21/255, 33/255>]
Rendering again, we get this second and better scene. The image on the
right shows the difference between the first and second
renderings [3].

Third Sampling Pass
To get a little bit better matching with the original image, we did one
more pass through. Most of the focus was placed on filling in the
regions with large changes in the blue component. Again, the new color
map entries are marked.
[ 0/269 color rgb <120/255, 79/255, 51/255>]
[ 1/269 color rgb <141/255, 83/255, 46/255>]
[ 2/269 color rgb <177/255, 86/255, 41/255>]
[ 3/269 color rgb <235/255,128/255, 72/255>]
[ 5/269 color rgb <255/255,159/255, 72/255>]
[ 8/269 color rgb <255/255,203/255, 94/255>] // New
[ 10/269 color rgb <255/255,218/255,112/255>]
[ 13/269 color rgb <255/255,233/255,148/255>] // New
[ 15/269 color rgb <251/255,241/255,172/255>] // New
[ 20/269 color rgb <255/255,246/255,203/255>]
[ 30/269 color rgb <255/255,240/255,219/255>]
[ 40/269 color rgb <236/255,223/255,214/255>]
[ 50/269 color rgb <205/255,204/255,212/255>]
[ 55/269 color rgb <185/255,190/255,209/255>] // New
[ 60/269 color rgb <166/255,176/255,201/255>]
[ 65/269 color rgb <149/255,163/255,190/255>] // New
[ 70/269 color rgb <129/255,149/255,182/255>]
[ 80/269 color rgb <103/255,127/255,171/255>]
[ 90/269 color rgb < 79/255,110/255,154/255>]
[100/269 color rgb < 66/255, 97/255,143/255>]
[110/269 color rgb < 52/255, 84/255,131/255>]
[120/269 color rgb < 47/255, 75/255,122/255>]
[140/269 color rgb < 37/255, 60/255,102/255>]
[160/269 color rgb < 32/255, 51/255, 84/255>]
[180/269 color rgb < 27/255, 42/255, 71/255>]
[200/269 color rgb < 25/255, 36/255, 58/255>]
[220/269 color rgb < 22/255, 31/255, 48/255>]
[240/269 color rgb < 18/255, 27/255, 42/255>]
[260/269 color rgb < 15/255, 21/255, 33/255>]
[269/269 color rgb < 15/255, 21/255, 33/255>]
The result is rendered one more time and differenced against the second
pass color map. Much better.

Final Sky Sphere
For a final rendering, add some water to reflect the sky. The final
image is below. The water is a plane texture is from Christoph
Horrman's "Realistic
Water with POV-Ray" tutorial.

Want To Know More?
As with many other topics, there's very little on the 'net on sky
spheres. If you know of a sky sphere tutorial, please e-mail it in to contact@povray.tashcorp.net.
Notes And Disclaimers
[1] - I've assumed you can get around in the Gimp. If
you're wondering what cropping is, try cgo:GIMP
Lite Quickies, Crop.
[2] - As before, if you're unfamiliar with the color
picker, try The GIMP
Documentation: Color Picker Tool.
[3] - To difference two images in Linux, run
'composite -compose difference image1.png image2.png out.png'
from the
command line. This uses ImageMagick.
Published: 01/03/06
Last Edited: 01/03/06
Copyright (C) 2006 Mike
Kost
|
|