CPSC 324, Fall 2002
Lab 9: Blender Textures
THIS LAB IS MOSTLY ABOUT USING TEXTURES in Blender, after a short detour to discuss some new aspects of Blender materials. At the end of the lab, you'll find sections on lighting and on running Blender in the background. This material is for your information, and you are not responsible for knowing it.
Exercises: For this lab, you should create two images. For the first image, you should apply textures to the objects in the file objects.blend. The objective is to show a variety of texture effects. For each object, explain what textures you have applied. In at least a few cases, you should apply more than one texture to the same object. For the second image, you should design your own scene that uses textures, including at least one image texture. If you prefer to do an animation for the second image, you can. Put one frame from the animation on your Web page, along with a link to animation file itself. (Do NOT put a huge animated GIF on your web page!) This lab will count for 12 points.
Now that we know more about materials, you might take another look at Blender's material buttons. In the following illustration, I've set up a partly transparent blue sphere with green specular reflections:
Transparency is controlled by the "Alpha" slider, with the default value of 1.0 meaning fully opaque. To set the specular color, I clicked the "Spec: button in the middle of the picture. The default "Color" button is for setting the ambient and diffuse color and the "Mir" color is for use with environments, which we haven't covered yet. Because I'm using transparency, I've clicked on the "ZTransp" option on the right of the picture. This is essential if you want transparency to look right. The "Emit" slider adds some emissive color to the object, while the "Amb" slider affect the degree to which it reflects ambient light. I've changed the preview on the left to show a sphere by clicking the little sphere icon just above the preview area. If you want an object with no specular hilites, turn down the "Spec" slider to zero. The "Hard" button controls the size or sharpness of specular hilites.
If you click the "Halo" button, as I've done in the image below, you get a whole new set of options. A halo is a special type of material that can only be applied to mesh objects (and to particle systems, which are also tied to meshes). When a halo material is applied to a mesh object, the object itself is no longer drawn. Instead a so-called halo appears at each vertex of the object. In the image at the right, I've applied a halo material to a 16-vertex mesh circle. The material settings that I used are shown below. A default halo is simply a ball of light, but you can add "Lines" and "Rings", as I've done here. You can control the basic halo color and the colors of the lines and rings separately, and you can set the number of lines and rings. The "Star" option changes the shape of the basic halo. If you turn on "Halo Tex", then any texture that is applied to the object is applied to each individual halo, which can be a very neat effect. If "Halo Tex" is off, then the texture just makes the color vary from one halo to another.
Textures in Blender
The term "texture" does not just refer to a variation in color from one point to another. It refers to a variety of effects that influence the appearance of a surface, including the diffuse color, the specular color, the emissive color, the transparency, and the direction of the normal vector. Here is a sample image that uses many of these effects. By the end of the lab, you should understand everything that is done here except for the reflection of the eggs in the table. (That uses an environment map, which will be covered in the next lab.) The source file for this image is eggs.blend.
Textures are complicated, and there are a lot of control buttons that affect them. These controls are divided between the Material Buttons and the Texture Buttons. In general, the Texture Buttons control the properties of the texture itself, while the Material Buttons control how the texture is applied to the material. An object can have more than one texture. In blender, a material can have up to eight textures, which are applied to the material one after the other. Of course, using more than one texture only makes sense if you use the extra textures to blend with the material in some way rather than to replace it.
To add a texture to an object, that object must first have a material -- even if you intend to completely cover the material color with a texture. (In fact, an image texture usually replaces only the diffuse/ambient color of the material, leaving the specular color intact.) You have already seen how to add a texture: After adding the material to the object, go the Texture Buttons and select one of the texture types along the top of Texture Buttons Window. But what if you want more than one texture? Just next to the texture preview area is a column of buttons. Each of these buttons represents one of eight possible textures to be applied to the material. When you add the first texture, the name of the texture goes in the first button. If you want to add another texture, just click the next button in the column, and then you can add the second texture just as you did the first.
We have not yet looked at Image textures. When you add an Image texture, you have to choose an image file. Just click the "Load Image" button to select the image file that you want to use. The image that you select will be applied to the surface of the object. You can use just about any type of image file. You will find a few sample images that you can use as textures in the folder named textures.
To control how a texture is applied to a material, you have to go back to the Material Buttons. There are a lot of options. The whole right side of the Material Buttons Window is devoted to this. Let's take a look at it:
I don't understand all of these controls, but I will describe the ones that I do understand.
Along the top are eight buttons representing the eight possible textures. Select the texture that you want to work on here. The preview at the left of the Material Buttons Window ordinarily shows the effect of applying all the textures to the material. If you click the "SepT" toggle on, the preview will show only the selected texture. This can make it easier to adjust the controls.
The group of buttons that starts "UV", "Object",... controls how texture coordinates are computed. The default selection, "Orco", uses the "original coordinates" from the object that is being textured. That is, it will base the texture coordinates on the (x,y,z) coordinates of the object in its own modeling coordinate system. This is the most common option. The other aren't so useful. For example, the "Glob" option uses global (x,y,z) coordinates. That is, the texture is fixed in space and as the object moves it will slide through the fixed texture. Later, we will see that the "Refl" option is used for environment maps.
The four buttons labeled "Flat", "Cube", "Tube", and "Sphere" determine how a 2D image texture is projected onto an object. That is, how are the three texture coordinates transformed into (s,t) coordinates on the image. The "Sphere" projection is useful for applying specially prepared files to mesh spheres. For example, the image shown, earth_sphere.jpg, will give a very realistic looking globe if it is applied to a mesh sphere using the "Sphere" projection option. (Just don't forget to apply "Set Smooth" to the sphere.)
The "ofsX", "ofsY", and "ofsZ" buttons are used to set a texture transformation. These buttons apply offsets to the three texture coordinates, which will slide the texture along the surface of the object. Similarly, "sizeX", "sizeY", and "sizeZ" apply scaling to the texture coordinates. Note that scaling the texture by a factor of K will make the texture K times smaller on the object. (You can, by the way, animate the texture transformation values to give textures that move or change size.)
The color sliders in the middle set the color that is used for blending by intensity textures such as marble and clouds. The intensity of the texture at a point determines how much of this color is blended into the original color of the material. The "Neg" button in the intensity texture reverses black/white in the intensity texture. So, for example, if you have a marble texture with narrow white stripes on a green background, you can use "Neg" to change it to narrow green stripes on a white background.
In the next column, the buttons labeled "Col", "Nor", etc, determine which aspect of the material is affected by the texture. The default is "Col", which means that the diffuse color of the material is affected. "Nor" means that normal vectors are affected. That is, the direction of the normal is changed, based on the intensity of the texture. A texture used in this way is referred to as a bump map because it can give the illusion of bumps on the surface. "Csp" is the specular color. "Cmir" is used for environment maps. "Ref", "Spec", "Hard", "Alpha", and "Emit" affect the corresponding values of the material. (These values are the same ones that are controlled by the sliders at the bottom left of the Material Buttons.) Some of these buttons are three-position toggles. The toggle can be on, off, or negative. For example, a positive "Nor" toggle makes the surface look like it has bumps, then a negative "Nor" will make it look like it has depressions. Note that you can choose to apply the texture to several different aspects of the material at the same time.
Once you know which aspect of the material is to be affected by the texture, you still have to say how it will be affected. The next set of four buttons, on the middle right, determine whether the texture value is Mixed, Multiplied, Added, or Subtracted. (Not all of these make sense in all contexts.) Finally, there are three sliders on the lower right that determine the degree to which the material is affected. If the texture is affecting the color, the "Col" slider says how much of the texture color is mixed into the material color. If this slider is 1.000 (the default), then the texture color completely replaces the material color or previous texture. For smaller values, the texture color is blended. For example, this can make an image texture look partially transparent. The "Nor" slider controls the extent to which the texture affects the normal vector. This slider has an effect only if the texture is set to affect the normal vector. The "Var" slider determines the extent to which the texture affects a value such as "Alpha" or "Emit", and it has an effect only when the texture is set to affect such a value.
For this lab, you have to apply a variety of textures to objects. You can use the objects in the sample file, objects.blend. Open this file now. It contains a scene that renders as the image shown to the right. The wooden floor is really an image texture applied to a mesh plane, with all the default settings. As a first exercise in image textures, you should add an image texture to the plane at the back of the scene. First, select this plane and add a material. Then go to the Texture Buttons, add a new texture, and select "Image" as the type of texture. You'll see a variety of controls for image textures. The most important of these are the "Load Image" button and the text field next to it that shows the name of the image file. Currently, the file name is empty. Click the "Load Image" button. You will get a file-open window where you can select the image. Navigate to the textures folder. You will see a preview of all the images in the directory. Select "stone.jpg" by clicking on it with middle mouse button.
If you render the image, you'll see the stone texture on the plane. However, it looks too "stretched out" to me. To fix this, apply a texture transform: Go the Materials button. Enter 3.000 as the value of "sizeX" and 2.00 as the value of "sizeY". This will make the texture repeat 3 times in the horizontal direction on the plane and 2 times in the vertical direction. The rendered image should look better now. If you would like to "tint" the stone texture by blending in some color, set a color for the material and set the "Col" slider in the bottom right of the Material Buttons to a value less than one. This will make the stone texture blend with the material color.
To help you to understand the variety of things that you can do with textures, I will explain how I textured each of the eggs in the image at the top of this page:
- The paisley egg has a simple image texture, paisley.rgb, applied. The texture projection was set to "Cube".
- The purple egg has a bump map applied to a purple material. The bump map is actually a "Stucci" texture. To get a bump map, I turned off the "Col" toggle and turned on the "Nor" toggle in the group of buttons at the upper right of the material buttons. I set "sizeX", "sizeY", and "sizeZ" to 3 to get smaller bumps. And I set the "Nor" slider at the bottom right to 3.252 to get deeper bumps. (You can apply image textures as bump maps! Try applying the image bricks2.rgb to the "Nor" channel of a material, or try applying it to both "Col" and "Nor".)
- The marble egg uses a very light green material color and two marble textures. (This gives a more natural marbled appearance.) The first texture is a medium green with fairly wide stripes. It has the "Sharp" option set in the Texture Buttons. The second texture is a very dark green, and it shows up as dark, narrow lines in the middle of the medium green stripes. For this one, I turned on the "Sharper" option in the Texture Buttons. I also turned on the "Neg" option above the texture color sliders in the Material Buttons. Without this option, I would have had very wide dark bands with narrow light-colored lines.
- The wooden egg also has two textures. The first is a standard "Wood" texture which combines a brown texture color with a yellowish material color. However, I wanted to add some "grain" to the wood. For this I added a second texture, of type "Clouds". The texture color for the Clouds texture is a dark brown. I set "sizeX" for this texture to 9.40 so that the clouds would be collapsed into thin vertical stripes. I set the "Col" slider, at the bottom right, to 0.608 to reduce the effect of the Clouds texture on the material.
- On the far right is a partly transparent egg with a sphere inside it. The inside sphere has an image texture, sky.rgb. The egg has a red material color and a Marble texture. However, I set the texture to affect the "Alpha" of the material, rather than the "Col". I also had to change the mode of the texture from "Mix" to "Mul". That is, the alpha value of the material is multiplied by the texture intensity: where the texture is white, the material becomes transparent; where the texture is black, the material is unaffected. I set the "Var" slider to 0.818 to reduce the effect of the texture, so that no part of the egg becomes completely transparent. To make the egg actually be see-through, I also had to turn on the "ZTransp" toggle in the middle of the Material buttons.
- In the background is a blue egg with a marble texture. In this case, I set the texture to affect the "Emit" of the material rather than the "Col", so it looks like there are some glowing stripes on the egg. Since emissive color does not actually give off light that affects other objects, I also added a blue light inside the egg. You can see the glow from this light on some of the other eggs.
As a final example, consider this animated globe of the planet Mars. I made this by applying the file mars_sphere.jpg to a mesh sphere. There is a subtle point that is hard to see in this animation. Compare the two images below, where I have simply mapped Mars onto a Mesh plane. The first image just uses an image texture. The second image actually uses two textures. The first texture is just the image of Mars. The second texture is a bump map that gives an illusion of surface topography. The bump map is defined by a second image, mars_bumpmap_sphere.jpg. This is a gray-scale image where the brightness corresponds to the surface elevation on Mars. I added this as an image texture, and set it to apply to the "Nor" channel rather than to the "Col" channel. In fact, I had to set the "Nor" button to its negative position to get bumps rather than depressions.
I got the bump map, along with the maps of Earth and Mars, from http://gw.marketingden.com/planets/planets.html. You might want to look at their Earth page, which describes how various images could be combined to produce a realistic-looking image of the Earth. (By the way, their images are quite large. I downloaded the smallest versions and still decided to scale them down by 50% for use in this lab.) For more maps of the earth, you could try http://www.vterrain.org/Imagery/whole_earth.html
Setting up nice lighting for a scene is an important part of modeling that we haven't really covered yet. Lighting a 3D graphics scene is similar to lighting a physical movie set or stage, so some of the techniques that are used for lighting on the stage are relevant here. There are some standard techniques for placing lights. Here is how this is described in The Blender Book, by Carsten Wartmann:
Traditional films or TV productions frequently use a lighting scheme called a three-point system. This scheme typically has one key light that simulates natural light in the scene... In general, this light source is situated 30 to 45 degrees away from the axis between the camera and the filmed object and is also raised 30 to 45 degrees from the axis.
Fill light is commonly used to soften the shadows created by the primary light source. Fill light is less bright than the primary light, and is diffused to avoid throwing hard shadows. If the fill light is too strong, the scene will appear flat with minimal contrast. The fill light is commonly placed at the same level as the camera...
The back light... is placed outside the camera's view, where it illuminates from behind and over the filmed object to emphasize the object's contours and to set it off from the background. The back light must not shine directly into the camera objective.
I tried to do something like this in the scene in objects.blend. Keeping in mind the fact that in blender only spot lights can cast shadows, I used a spotlight as the key light. The other two lights are regular lamps (that is, point light sources).
When you use a spotlight in blender, remember to turn on the "Shadows" toggle in the Display Buttons. Otherwise, the shadows won't be rendered. When you have a spotlight in a blender 3D window, you see a line running down the center of the spotlight's cone. This line shows the range of distances from the light in which shadows will be cast. You can get sharper shadows by shortening this distance, since a shorter distance makes better use of the memory that blender uses for calculating shadows. The extent of this line is controlled by the "ClipSta" and "ClipEnd" buttons in the Lamp Buttons.
You can turn on a "Halo" effect for a spotlight. This is supposed to simulate what happens when light rays are made visible by dust, smoke, or mist in the air. The intensity of the effect is determined by the "HaloInt" button. You can also add a texture to a light. The right side of the Lamp Buttons is used to control how the texture is applied to the light. It is similar to the texture control in the Material Buttons. Try it, for example, with a "stainedGlass" image texture.
FYI: Running blender in the Background
If you are writing a big blender animation that will take a long time to render, you might want to run it in the background on one of the cslab computers. Please do not do this on math.hws.edu, since that computer is busy being a server. Even on the cslab machines, please do the rendering in "nice" mode so it will not interfere too much with foreground tasks.
An easy way to run something in background while you are not logged in is to use the "at" command. This command lets you enter a list of commands to be executed at a specified time. To run some commands at 3:00 AM, just say: at 3:00 AM and then type the commands in the same way you would enter them to run them directly. Hit CTRL-D to end the list of commands. If you want to start running the commands immediately, you can say: at now
Your account is set up with a CPU time limit of ten minutes, so that a process will be killed after it uses 10 minutes of processing time. However, it is possible to remove this limit. The command to do this is ulimit -t unlimited.
To render a blender animation in the background, with no graphical interface, set everything up in your blender file to the point where you are ready to click the ANIM button to render the animation. Make sure the file name, number of frames, and output format are correct! Instead of clicking ANIM, save the blender file. Let's say it's called "anim.blend". Quit blender. Then enter the "at" command with the time when you want to run the job. When "at" prompts you for commands, enter:ulimit -t unlimited nice blender -b anim.blend -a >CTRL-D<
Replace "anim.blend" with your actual file name. Later, you can use the "top" command to check if the job is running.
David Eck, November 2002