home   drawings   cartoons   stories   waffles   projects   virtual worlds   files   blog

Backgrounds

When making my worlds I often add a nice background of a sky with clouds. To do this, I use an old, but amazing program named POV-Ray (or povray). It is free, and like VRML, it uses text files to create its scenes. It is a raytracing program. That is, it traces the paths rays of light take to reveal a scene. (Actually, for the sake of efficiency, it traces the rays backward — from your eyes back into the scene, calculating only the light you'll see.)

Here is an example of a very simple scene written in POV-Ray's scene description language.

// Persistence Of Vision raytracer version 2.0 sample file.

#include "colors.inc"

camera {
   location  <0, 20,-100>
   direction <0,  0,   1>
   up        <0,  1,   0>
   right   <4/3,  0,   0>
}

plane { y, -10
   pigment {White}
   finish {ambient 0.2 diffuse 0.8}
}

sphere { <0, 25, 0>, 40
   pigment {Red}
   finish {
      ambient 0.15
      diffuse 0.75
      phong 1
      phong_size 100
   }
}

light_source {<100, 120, -40> colour White}

If you save that text file as "simple.pov" and run POV-Ray on it:
povray simple.pov
you should get this image:

Most 3D programs let us apply textures to the surface of objects using pictures, but in addition to that capability, POV-Ray has a lot of what are known as "procedural textures" built into it, letting us use wonderfully natural-looking textures on things, such as wood grain, granite, marble, cloud-like textures and others. For my cloudy skies I tend to use the "bozo" texture a lot.

Here is a very simple, but dramatic cloudy sky using one of POV-Ray's predefined cloud textures (S_Cloud1) on its sky_sphere object.

// POV-Ray v 3.1

global_settings { assumed_gamma 2.2 }

#include "shapes.inc"
#include "colors.inc"
#include "textures.inc"   
#include "skies.inc"

camera {
   location <0, 0, 0>
   direction <0, 0, 1>
   up <0.0, 1.0, 0.0>
   right <4/3, 0.0, 0.0>
   look_at <0.0, 30.0, 200.0>
}

light_source { <100, 100, -50> White }

sky_sphere { S_Cloud1 }

POV-Ray should render it to produce this:

I like to add fog to the bottom. Add this to the scene:

fog{
    color red 0.84375 green 0.74609375 blue 0.84375
    fog_type 2
    fog_alt 0.35
    fog_offset 0
    distance 100
    turbulence <.15, .15, .15>
    omega 0.35
    lambda 1.25
    octaves 5
}

Then retrace it with POV-Ray to get this:

Much nicer.

One of my favorite cloudy sky backgrounds uses layers of clouds to give the impression of them having volume. I won't display the text of it here because it is too long, but you can download it and read it at your leisure: my_shadow_clouds.pov.

When rendered with POV-Ray, it looks like this:

These images are okay, but how do I use them in VRML worlds?

I use a special POV-Ray script that was created by someone named Armagon way back in 1998. It is called BackgroundMaker.pov

If you take a look at that file you'll find it sets the camera to have a 90° view angle and repeatedly turns to point in 6 different directions to create images that are the 6 faces of a cube, as viewed from inside. This is great, because VRML has a special background node that lets us surround our world with 6 images as faces of a cube positioned at infinity.

Render this sequence using a slightly different invocation of POV-Ray. Try this:

povray +KFF6 +W512 +H512 +FN BackgroundMaker.pov

This runs POV-Ray as if it was going to make an animation. "+KFF6" sets the clock (K) running, rendering a frame for every tick, the final frame (FF) being the 6th one.

The width (+W) and height (+H) are both set to 512 pixels here, though for more detail 1024x1024 can be good. It is best to keep these to powers of two (4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048...) when making textures for VRML. Larger images can slow the VRML viewer significantly, and start to make movement in less powerful computers jumpy.

POV-Ray can't render to jpeg files so I tell it to produce png files (+FN). When they're destined for the internet I use ImageMagick to convert them to jpeg files, which have a much smaller filesize for the same image size.
mogrify -format jpg -quality 90 *.png

Using these 6 images inside a VRML world is easy, though there is a slight wrinkle. POV-Ray's forward is backward for VRML, and rotations are reversed too, which has the effect of messing things up, so even though POV-Ray will render the images as front, left, right, back, down, and up, you need to use the images in VRML as back, left, right, front, down, and up. Like this:

#VRML V2.0 utf8

NavigationInfo {
	type ["FLY"]
}

Background {
	backUrl "BackgroundMaker1.png"
	leftUrl "BackgroundMaker2.png"
	rightUrl "BackgroundMaker3.png"
	frontUrl "BackgroundMaker4.png"
	bottomUrl "BackgroundMaker5.png"
	topUrl "BackgroundMaker6.png"
}

That will look like this:

Should be displaying my dayClouds VRML world here
If instead you're seeing this text, you need a more modern web browser.

Drag your mouse around the background to rotate the view.
Roll the mouse wheel, or on a touch screen drag 2 fingers, to look up or down.
Right-click, or long-tap to get the menu if you want to choose full-screen view.
The ESC key escapes from full-screen, or on a touch-screen long-tap brings up the menu again then choose to end full-screen mode.


Here are a few more of my POV-Ray background scenes in VRML for your enjoyment:


My clouds made to appear to have volume in a fine blue sky.


Morning sky with fog below.


Morning sky with a metallic sea below.


Night sky with clouds and a light mist below.


Foggy sunset with rising full moon.


So now you know how to make interesting backgrounds for your VRML worlds using POV-Ray.