How to make your own SkyBox with a digital camera

Download and install hugin software (it's free) from

http://hugin.sourceforge.net/download/

Use a tripod to take pictures all around, first directly in front, then down near the base of the tripod, just without the legs, and step back and take an image of where the tripod was from near where the tripod was holding the camera. Then starting with the view just above the legs of the tripod, take a series of images, overlapping the center of each image with the edge of the next, in a complete circle. Then tilt the camera upwards so that the top of the previous picture is in the center of the view and repeat. Continue until the camera points directly upwards to the sky. You should have all directions covered.

If there is something interesting passing by as you take pictures, you may choose to snap an image of it out of sequence, but then use the following sequence of images to link back to where you left off. In this manner, most images will be adjacent spatially to images that are adjacent sequentially. This will allow you to process smaller groups of images, like 20 at a time instead of about 100 all at once.

Start Hugin

Select Images and drop your images into Hugin's image list

Select the first 20 images, #1-#20, and Create control points

Repeat for #10-#30, #20-#40, … until control points have been created for all images.

Then if the first and last images overlap, select the last 10 and first 10 images together and repeat one more time.

(Occasionally no control points will be found for an image. If this happens, the next step will fail, but you can either remove the image from this list, or manually add control points under Control Points)

Click Assistant → Align

Go do something else while you wait for it to finish.

The stitched image may look like this.

There are a lot of interesting projections available. You can make planetoids, and other neat effects... but you need an Equirectangular projection to make a sky box.

Select Projection → Equirectangular

Then Move/Drag

Adjust Yaw/Pitch/Roll or use your mouse to adjust the image. The Straighten button may help.

Change the overall brightness with EV. (Sometimes it is helpful to create several copies of the image with different EV values, optimized for the sky, the land, and perhaps the shadow areas, to be combined with an image editing program such as GNU Image Manipulation Program as separate layers. To do that, finish the process of creating a panorama with these settings, and repeat with different settings to make lighter or darker images.)

You may save the project at this time.

After saving the project, you may return to make adjustments later.

Now it's time to create the panorama inane.

Close this window and select Assistant → Create Panorama.

Take a break while you wait a long time. Perhaps you go to the beach or take another set of pictures for your next skycube while you wait.

When it's complete, you can close Hugin and find your TIF image where you saved it.

Create a file called sky.pto containing the following text, but change the h6203and w12406 to the actual height and width of beach.tif

p n"TIFF_m" v90 h1024 w1024

i n"beach.tif" f4 v360 y-90 p0 h6203 w12406 i n"beach.tif" f4 v360 y90 p0 h6203 w12406 i n"beach.tif" f4 v360 y0 p-90 h6203 w12406 i n"beach.tif" f4 v360 y0 p90 h6203 w12406 i n"beach.tif" f4 v360 y0 p0 h6203 w12406 i n"beach.tif" f4 v360 y180 p0 h6203 w12406 v

Save it in the same folder as beach.tif, then on the command line in that folder,

`locate -l 1 \*/nona` -o face sky.pto

(note that the quotes are backward - alternatively you could make sure nona is in the path and call

nona -o face sky.pto

which is what you must do on Windows anyway since it lacks locate and backquote processing)

Before you can use these files with JReality, you need to convert them to jpg format. Open them with an editor and save them in jpg format.

final Viewer viewer = JRViewer.display(scene);
SceneGraphComponent root = viewer.getSceneRoot();
CubeMap cube = TextureUtility.createReflectionMap(
        root.getAppearance(),
        "polygonShader",
        "face",
        new String[] {"0000","0001","0002","0003","0004","0005"},
        ".jpg");
ImageData[] sides = TextureUtility.getCubeMapImages(cube);
TextureUtility.createSkyBox(root.getAppearance(),sides);

Pasted Graphic 22.png

The view in JReality appears mirrored with left and right reversed like this.

If you do this often, you can create a shell script to automatically convert equirectangular projections from Hugin into sequences of .jpg sky box images.

The script below is for OSX, with imagemagick installed in /sw/bin

grep "\.tif$" <<<$1
if [ $? != 0 ]; then
   echo >&2  A .tif image file must be selected.
   echo >&2  It should be an equiectangular projection. 
   exit 1
fi
/sw/bin/identify $1 | /sw/bin/awk '-F(+| |x)' '{print \
"p n\"TIFF_m\" v90 w1024 h1024"\
"\ni n\""$1"\" f4 v360 y-90 p0 h"$4" w"$3\
"\ni n\""$1"\" f4 v360 y90  p0 h"$4" w"$3\
"\ni n\""$1"\" f4 v360 y0 p-90 h"$4" w"$3\
"\ni n\""$1"\" f4 v360 y0  p90 h"$4" w"$3\
"\ni n\""$1"\" f4 v360 y0   p0 h"$4" w"$3\
"\ni n\""$1"\" f4 v360 y180 p0 h"$4" w"$3\
"\nv"}' >cube.pto
echo Wait...
/Applications/Hugin/Hugin.app/Contents/MacOS/nona -o face cube.pto
echo converting...
/sw/bin/mogrify -format jpg face000?.tif
rm face000?.tif cube.pto
echo Done.
And to make the images appear correctly instead of mirrored, you can avoid an extra transform matrix in JReality with this:
grep "\.tif$" <<<$1
if [ $? != 0 ]; then
   echo >&2  A .tif image file must be selected.
   echo >&2  It should be an equiectangular projection. 
   exit 1
fi
/sw/bin/identify $1 | /sw/bin/awk '-F(+| |x)' '{print \
"p n\"TIFF_m\" v90 w1024 h1024"\
"\ni n\""$1"\" f4 v360 y90  p0 h"$4" w"$3\
"\ni n\""$1"\" f4 v360 y-90 p0 h"$4" w"$3\
"\ni n\""$1"\" f4 v360 y0 p-90 h"$4" w"$3\
"\ni n\""$1"\" f4 v360 y0  p90 h"$4" w"$3\
"\ni n\""$1"\" f4 v360 y0   p0 h"$4" w"$3\
"\ni n\""$1"\" f4 v360 y180 p0 h"$4" w"$3\
"\nv"}' >cube.pto
echo Wait...
/Applications/Hugin/Hugin.app/Contents/MacOS/nona -o face cube.pto
echo converting...
/sw/bin/mogrify -flop -format jpg face000?.tif
rm face000?.tif cube.pto
echo Done.

Using TextureUtility.createCubeMap instead of TextureUtility.createReflectionMap does not change the reflection. It only changes the texture, as shown. It does not correct for the mirrored image effect. In the script above, it is corrected by mirroring the images with -flop, and swapping the 1st two (left and right) images.

Here is the finished product as it appears in JReality.

Now you have a sky cube for your JReality 3D environment! But that's not all... You can get creative with ideas like mapping your skycube image onto an inflatable origami ball (using the original script without the mirroring correction), or project images onto four walls of your room and paint it as a mural!