CPSC 324: Computer Graphics
Sixth Lab
April 17, 2001

Today's lab is mostly about textures, with a little extra information thrown in about lighting and spotlights. For your lab report, you should produce one or more images that use a variety of textures and texture effects. You can use the sample blender file, objects.blend, as a starting point if you like. In addition to this, make a scene from scratch that uses a spotlight with visible shadows. Your scene should use either an environment map or a spotlight with either a halo effect or a texture or both.

The "cpsc324" folder on the "N" drive contains the sample file objects.blend. It also contains a directory named "textures" which holds some image textures that you can use in the lab. You will find copies of the same stuff on the math server in the directory /home/cs324/blender.


Textures in Blender

Blender uses the term "texture" to refer to a variety of effects that influence the appearance of a surface, including 2D image textures, 3D procedural textures, bump maps, and environment maps. Here is a sample image that uses all of these effects. The source file for this image is eggs.blend.

Textures Eggs

I will tell you how I made each of the eggs, but first, let's look at some of blender's control buttons for texturing. Since textures are so complicated, there are a lot of them, and they 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. 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 texture 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 color of the material, leaving the specular color intact.) After adding the material to the object, go the Texture Buttons. You'll see a list of texture types along the top of Texture Buttons Window. Select one of these by clicking on it. A new set of buttons for controlling that type of texture will appear. There is a square area at the left end of the buttons window that shows a preview of the texture. Just to the right of this 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. To add a second texture, click the second button and then click one of the texture types to add the texture. If you want to change the settings for one of several textures, just click the corresponding button to see its settings. Remember that textures will be applied to the material in the order that they are listed.

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:

Texture Controls

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 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 "Sphe" 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 "ofsX", "ofsY", and "ofsZ" buttons are used to set a texture transformation. These buttons apply offsets to the three texture coordinates. Similarly, "sizeX", "sizeY", and "sizeZ" apply scaling to the texture coordinates. Remember 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 grow.)

The color sliders in the middle set the color that is used for blending by intensity textures such as marble an 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.

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, so you get the effect of a bump map. I think "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. Also, note that you can choose to apply the texture to several aspects of the material.

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 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 which 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. For smaller values, the texture color is blended with the material color. The "Nor" slider controls the extend 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, if you like, 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 directory N:\cpsc324\textures. 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 Easter eggs in the image at the top of this page:


Lighting

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.

I've had a lot of trouble aiming a spotlight. An easy way to do this is to make it track an object. You can use an object in the scene or an empty object introduced just for this purpose. This can make it particularly easy to keep the spotlight pointed at a moving object during an animation. (Recall how to set up tracking: Select the spotlight by right-clicking it. Add the object that it will track to the selection by shift-right-clicking it. Hit CTRL-T and confirm that you want to set up tracking. Select the spotlight again and hit ALT-R. Confirm that you want to clear the light's rotation. It should now point directly at the object that it is tracking.)


Environment Maps

Reflect in a sphere Environment maps are used to simulate reflection of the scene in a shiny object. Blender does environment mapping by making six images of the scene -- one view in each direction from the position of a specified reference object. These scenes are then used as a texture on the reflective object. In the image at the right, an environment map is applied to the sphere. In the textured eggs image at the top of this page, an environment map is applied to the plane on which the eggs are standing. Environment maps are computed automatically in blender, once the parameters are set up. If you are doing an animation, you can even have blender compute a new environment map for each scene.

I have only been able to get good environment maps on spheres and planes. Here are the steps for adding an environment map to a sphere:

  1. Select the sphere, make sure it has a material, go to the Texture Buttons, add a new texture to the sphere, and set the type of the texture to "EnvMap". You will see the Environment Map controls, which are shown below.
  2. In the button labeled "Ob:", enter the name of the sphere. (You can get this name from the header in the Edit Buttons, as usual.)
  3. Move the sphere to a different layer. (Select the sphere, hit the "M" key, and select the layer you want to move it to.) In the environment map controls, under "Don't render layer", click on the layer that now contains the sphere. This is so that the sphere itself won't appear in the environment map. In the 3D window header, turn on the layer that contains the sphere if it isn't already on (by shift-clicking on the corresponding little button).
  4. In the environment map controls, you will probably want to increase the "CubeRes" to 250 or more. This determines the size of the images created for the environment map. If it's too small, the reflection will be blurry.
  5. You have to go back to the Material Buttons and make some changes. Change the texture coordinates from the default "Orco" to "Refl". For the texture mode, turn off the default "Col" and turn on "Cmir". If you render now, the sphere should look like a perfectly reflective mirror.
  6. You can add a color tint to the reflection by setting the "Cmir" color at the left end of the Material Buttons. To blend the environment map into the sphere's material, rather than replacing it, you can turn down the value on the "Col" slider at the bottom right of the Material Buttons.
  7. If you edit the scene, a new environment map will not be computed automatically. To force a new computation, go to the Texture Buttons and click the "Free Data" button in the environment map controls. To automatically recompute an environment map for each frame of an animation, click the "Anim" button.

Environment Map Controls

The procedure for environment mapping a plane is the same, except for step two. You have to be really careful about the reference object used for a planar reflection. The reference object must mirror the portion of the camera, reflected through the plane. (Think of it like this: what the camera sees reflected in the plane should be the same as what the reference object sees directly.) To set up the reference object for reflection in a plane, do the following:

Then, continue with step (3) above. (You still have to move the plane to a different layer and set the environment map to not render that layer.)


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 in, say, 2 minutes, you can say:  at now + 2 minutes 

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! 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, April 2001