Monday, December 21, 2009

Crystal Ball Animation

Join my Blender 3D forum, where you can network with other Blender friends and get your Blender 3D questions answered.

In my tutorial on world background colors, we saw how to change the background color, produce a gradient from one color to another as a background to the scene, and how to map the colors to the world horizon and zenith.

Blender also lets you use an entire image, such as a sky image, as a background. In addition, if you turn on Ray Mirror reflection, which I discussed in my Ray Mirror tutorial, you can make objects in your scene reflect the background image so that it appears to exist inside the image generated world. What's interesting is that no lamps are required for this effect. All the light comes from the image itself. This general class of techniques is called Global Illumination, or GI. You can see the dramatic effects of GI in movies such as Avatar, where an entire world is created as the characters fly around inside it. Even though we'll do this on a smaller scale, the principle is the same.

Here are the steps:

1) We'll prepare our fake world first. Start with the default scene. Delete the default cube (Right click, press the Del key, press Enter to confirm). Select the lamp and delete it the same way. We're going to create a UV Sphere and have it reflect the background. Add a UV Sphere (Space - Add - Mesh - UVSphere). Scale it up 2 times (S - 2 - Enter).

We're also going to add a Track To constraint on the camera. Press the Home key to include all the objects in the scene. Select the camera. Press the Object buttons (F7), then the Constraints button. Select the Track To constraint and make the object the Sphere. Set Fw to -Z and Up to Y. Our scene is very simple: the UVSphere and the camera.

2) Now let's place an image in the background. Actually, any image will do. As we will see, the higher the image resolution, the more realistic the effect. We'll start with a JPEG of the sky. I downloaded an evening sky jpeg from, a good place if you're looking for sky images. You can google Free Sky Images for more.

To make the image the scene background, select F5 for the shading buttons. Click the globe icon for the World buttons. Press the texture button (F6). Make sure that the World texture is selected. Select the top texture channel, click Add New, and from the Texture Type dropdown, select Image. Click Load Image, and load your chosen JPEG. Go back to the World Buttons. In the Preview panel, press Real. In the Texture and Input panel, change the setting to AngMap (Angular Map) to make map to the entire background. In the Map To panel, change the setting to Hori (for Horizon) from the default of Blend. Press F12 to render. The sky renders in the background.

3) This is a start, but we can do better. You can control the size of the background image. From the Texture and Input buttons, increase SizeX and SizeY to 3 to zoom in on the image. Press F12 to render. We get some of the ground as well, if we move the camera so that it can see the ground. One problem is that this JPEG isn't set up to show the entire 360 degree world. The best way is to use an image, called an HDR Image, for High Definition Range, which has a high enough resolution to show the entire 360 degrees of the world we want to simulate. Sometimes they're called Light Probes. If you do a Google Search on Free HDR images, you'll find many HDR images that you can use, not only of the sky, but of buildings, landscapes, mountains, canyons, and so on. I'm using an HDR image of Galileo's tomb in Florence, Italy, from the Light Probe Image Gallery. Google Light Probe Image Gallery to download this and many others. Look for files with the HDR extension. To use this image, go to the World buttons, and then the Texture button. Delete the first image by pressing the X key. Then I click the Load Image button and load the HDR image. In the Texture and Input buttons, set SizeX and SizeY back to 1. Press F12 to render. The new HDR image renders in the background.

4) A really interesting effect can be produced by having our UV Sphere reflect the image, like a crystal ball. To enable this effect, select the Sphere, go to the Shading Buttons (F5),and choose the default material (Material). Go to the Mirror Trans tab. Turn on the Ray Mirror button and set Ray Mirror to 1, which is 100% Ray Mirror. Check out my Ray Mirror tutorial for other effects. For this demo, the ball is getting all of its image information from the HDR image. Press F12 to render. If we reposition the camera somewhere else, we see a different part of the image, just as if the ball was inside the image.

5) Let's get a panoramic view of our world by animating the camera around the sphere. I discussed this technique in my Blender camera positioning tutorial.

Clear rotation (Alt-R) and location (Alt-G) on the camera. Press Shift C. Add Bezier circle. Scale it 4 times. Go to Edit Buttons. Press CurvePath to make the Bezier circle a path. Then select the Camera. Delete the track To constraint. Add the Follow Path constraint, making the object CurveCircle, the default name for the Bezier circle. Set Fw to -Z and Up to Y. Add the Track To constraint back. Set the Object to Sphere and Fw to -Z and Up to Y. Press Shift-Alt-A to animate. The camera follows the sphere along the circular path. To animate this, go to the Scene buttons (F10), set the end frame to, say, 100, change the output directory to where you want the video file to end up, set the video type (I like AVI compressed, but MOV for quicktime works as well). I'll pause the video while the animation renders. Here's the result: a camera flyaround inside the image.

6) Suppose you want to eliminate the background and just have the sphere reflect the world. Here's how to do it. Go to the World buttons by pressing F5 (Shading), then the World button. Change the window to the Node Editor. Click on the Face Icon (for Composite Nodes), then press Use Nodes. You get the RenderLayer input (our scene), as well as a Composite Node output node (the composite result). Add a Mix Node (Space - Add - Color - Mix). Connect the Image socket of the RenderLayer node to the input Image socket of the Mix node. Connect the Alpha socket of the RenderLayer node to the Fac socket of the Mix Node. Connect the output Image Socket of the Mix node to the Image socket of the Composite node. The background has disappeared, replaced by the color of the first Image socket of the Mix node. You can change the color to anything you want. Make it red, for example. To render the effect, go to the Scene buttons (F10), press the Do Composite button, and press F12 to render. You can redo the animation without the background if you like.

As you can see, you can create your own little Avatar like world in Blender. I hope this gives you some ideas for your own creativity. Be sure to press the Subscribe button in YouTube so you won't miss any of my other tutorials. Happy Blendering!