Today we're going to look at various ways of either using textures to make other processes easier, or of making texturing easier. The first thing we're going to look at is bump mapping.
Bump mapping adjusts the way that an object is affected by the scene lighting to change its appearance. It is often used to make objects appear more complicated than they really are, i.e. to create the illusion that there are many more polygons than there are in reality.
Let's try this out by making and applying a bump map. Open up GIMP (either from the Graphics menu, or by using the terminal command "gimp"), and then click on
File → New. We'll use all of the default settings (resolution is 256×256), so just click OK.
A bump map appears completely flat if starting with an image that is all one colour. So that we can make both inwards and outward bumps, let's start with a medium grey. Click on your foreground colour and select a mid grey, then fill the image with it using
"ctrl-," (if it is your background colour you can use
Now draw something on the image. Use whatever brushes you like, or text, or anything else. Some handy GIMP tricks:
When drawing with the pencil, shift-click draws a straight line
Use – to zoom out, and + to zoom in
Click on the active brush (by default a circle, in the bottom right of the main window) to edit the brush attributes
Bear in mind that anything close to grey will not be displaced very much, and colours close to black or white will be displaced a lot. One stipulation: make sure there are some sharp edges in it (i.e., drawn with the pencil or similar). Notice that the image doesn't have to be grey scale, but any colour information will be ignored when applying the bump map.
Now go into Maya, and create a polygon (important that it's polygon) plane with 10 subdivisions in each direction, and shine a single spotlight on it. Create a blinn texture, and play round with the settings a bit. Also, make sure that we can see the specular highlight in a render.
First, just plug it in as a colour map. Make sure it's the correct orientation (rotate the place3dTexture node by 90° in x) and size (use the
Fit to group bbox button).
Disconnect it from the colour map, and we'll plug it in as a bump map. Like we did last week, get a bump map node. Plug the projection into the bumpmap3d node, and the bumpmap3d node into the bump map connection of the blinn.
Do a render now: our flat plane now appears not to be flat, but have lumps in it. The illusion only works so far though: if you look at the plane in profile, the trick doesn't work. Let's have a look at the alternative.
Displacement mapping produces a similar effect to bump mapping, with one subtle difference. Bump mapping cheats, displacement mapping does not. Bump mapping adjusts the lighting to fake a more complicated surface, and thus works well from a distance: when close up, however, the effect is poor (this is especially true when seeing the surface in profile). Displacement mapping, on the other hand, actually creates the extra geometry. Not only can this be a very useful way to model, but it has another advantage: the geometry is only added at render time, so moving around in the viewport is much quicker.
In the hypershade, disconnect the bump map, then MMB-drag
projection1 onto the blinn node and connect it as a displacement map. They won't appear to be connected at first, but if you do a render, you'll see that the displacement map has worked: the surface is perturbed. If you RMB click on the blinn and select
Graph Network from the marking menu, and you'll see the graph expands to include the shading group node. It is not important to know the precise function of this node (more information on it can be found in the help files), but it is important to remember that displacement maps plug into this node and not the material node.
So as you can see, our displacement map has worked, but not perfectly. We need to change some of the settings. Get the attributes of the plane up, and scroll down to the
Displacement Map section. What we have here are the two essential parameters:
Initial Sample Rate and
Extra Sample Rate. In order to figure out how to set these, we'll get a quick preview of our displacement. In the hypershade, plug the projection of our displacement map into the
Color attribute of our blinn node. We will lose the colour of the blinn, but instead see the image as projected (press
Hardware Texturing] if you can't see it).
Now we can think about changing the displacement map parameters. These parameters show the amount of subdivision, so the higher the value, the more accurate the displacement but the slower the render.
The first thing to look for on our object (make sure that the object is selected) is inside each polygonal face, the range of colours (i.e. luminances). The higher the range within a single face, the higher the
Initial Sample Rate needs to be. We have a huge range (plus a very simple scene), so I'm going to go for a very high value (25).
The next thing to look at is how sharp the features are: the sharper the features, the higher the
Extra Sample Rate should be. In this particular image, the features are exceptionally sharp (they go from black to white in the space of a single pixel), so we have to set the
Extra Sample Rate quite high as well (I've set mine to 15).
Now put a nice colour back on it, and try rendering again. You should see that the features are much better defined, at the cost of the rendering time. There will still be jagged edges, but that's because our image has jagged edges in it.
It's a shame, though, that we don't know how much it had to divide our polygons up to get this smooth look. Looking at the poly count HUD, we have 100 polygons before displacement. How many after? Well, Maya gives us a really nice feature which lets us convert our displacement map into a real object, and thus we can see all of the polygons. It's also very straight-forward to carry out: select the plane, and go to
Modify → Convert → Displacement to Polygons. Now you should be able to see the post-displacement polygon mesh in all its glory, all 99,495 faces of it. You'll also still have the original plane, still with the displacement map on. Though it is very useful to be able to convert a displacement map into polygons, bear in mind that one of the reasons for using a displacement map (over modelling the geometry) is to save time in the viewport: it is much quicker to tumble a 100 polygon object than a 100,000 polygon object (turn on the frame rate HUD and you'll see what I mean).
Get a new scene, get a NURBS cylinder, and stretch it out in the y axis. Apply a texture to it with a cylindrical projection (any texture is fine: a simple chequerboard will do), and check that it looks the way it should.
Now try moving the object. Do what you expect? Probably not. That's because it has left its place3dTexture node behind. Clearly this sort of problem is easy to solve: all we have to do is parent the place3dTexture to the object (when it's correctly textured). Easy!
But what if we want to deform the object? Try it now. Apply some sort of deformer to it (I used a bend deformer). Now deform it, and you'll see that the texture "swims" over the object: the texture doesn't move when the object does. This is the downside to 3D textures.
Thankfully, it's easy to solve this. Open up the hypershade, and select the object, then the texture. From the hypershade menus, click on
Edit → Convert to File Texture. Notice that we have a new texture, a much simpler one, and that it is applied to our cylinder. If you try deforming the cylinder now it'll do exactly as you expect (plus it's a whole bundle quicker to see in the viewport).
What this does is converts the whole texture into an image (if you go into the options of the
Convert to File Texture tool, you'll find we can decide what the resolution should be), which is then saved to disc and applied to the object. This is often referred to as "baking" the texture onto the object. It is no longer projected, but rather each area of the texture is placed relative to the object's vertices. When we have complex meshes such as the mesh of a human face, the image generated can look completely bizarre. This is due to the UV mapping, which we'll cover later.
Using this same method, we can do other things to speed up our rendering process. In a new scene, create a plane with several primitives on it. Create a couple of lights, both with depth map shadows on. Now put a texture on the plane (it can just be a single colour, nothing fancy), and get a render view up to monitor things. Again in the hypershade go to
Edit → Convert to File Texture, but this time get the
Bake Shading Group Lighting and
Bake Shadows. Now click
Convert and Close. You'll probably see that there's little difference. Open up the outliner, and delete everything in the scene except for this plane: all of the lights and the primitives. Now render again, and you'll find that the plane looks identical (notice that the specular highlight doesn't move, even when we tumble the camera). This may not seem terribly useful in this circumstance, but when you find you can do it with global illumination and all those things that take forever to render (or at least, using
Lighting/Shading → Batch Bake (mental ray) you can), it becomes quite the most beautiful thing in the world. Use it. Please.
There are times when you want to combine two textures. Maybe you want something inbetween the two, or maybe you want to swap between them smoothly mid-animation. Let's look at ways to do that.
Create an object with a texture. Then disconnect it in the hypershade, and give it a different texture, so you have a hypershade that looks something like mine.
(NB: at this point, if we wanted, we could connect our network so both projections are using the same place3dTexture node. I have chosen not to do this)
In the hypershade, scroll down to
Color Utilities and get a
Blend Colors node. Plug one texture into
color1 of it, the other into
color2, and the output of it into the
color input of the lambert node.
This gives us a weighted average of our two textures: the node has a
Blender attribute that allows us to change the weighting towards
There are other ways to blend textures too. We can multiply them together using a
Multiply Divide node, or we can add them together using a
+/- Average node. We can even do a bit of pseudo-programming: the
Condition node acts like an
Scroll back up, and get a
Layered Texture (from
Other Textures, just below
3D Textures). Layered textures let you use layers in the same way that you might in Photoshop: you can have several different textural layers (e.g. brick, covered with moss, covered with dirt) that the layered texture layer will help you to combine together in virtually any way you can think of. You can plug in as many different textures as you like to a layered texture, and there are many different blend modes to choose from (a lot of which you may be familiar with from Photoshop). Have a play around with the different settings of the node now, see what sort of effects you can come up with.
Finally today, let's have a quick look at UV mapping. In a new scene, create a polygon cube. Say we want to texture this cube to make a die, and we have the net of a die*. Do we have to go into the image, chop the whole image up into individual faces, then stick each image separately onto each face of the cube? No. We use UV mapping.
Give the cube a texture (lambert, blinn, whatever). Then apply the following file to it as a texture:
But rather than using
As Projection, like we've done before, pick
Normal. This puts the whole texture on every face of the object. Clearly this isn't very useful, so we need to adjust the texture to define which bit of the texture is seen on which face of the object. This is done using the UVs.
UVs are texture co-ordinates: they relate a point on the texture in texture space to one of the vertices of a polygonal surface, and thereby provide the information needed to apply textures to the surface. Polygonal surfaces (as well as subdivs) require specific arrangement of the UVs so that textures look correct when applied to the surface material: this arrangement can be done either by projecting a texture, or manually using the
UV Texture Editor.
UV Texture Editor now (it's about halfway down the
Window menu). First thing you should notice is that you can navigate round using the
Alt key as usual. If you zoom out, you'll see that our object has been unfolded, and thus we can assume that outside of the
[1,1] square, the texture is tiled. In our case, we only need any part of the texture to appear on our model once, so we're only going to use the area from 0 – 1. This is generally the best way to work.
On the top row of buttons at the top of the window, there are two particularly useful ones that make our workspace easier to use. In the middle, there's a picture of a face: this button turns the display of the image on and off. Two buttons right, there's a grid icon, which turns the grid on and off. Use both of these freely in order to best see what's going on.
In the marking menu of the cube, select UVs. Now try to arrange the UVs in such a way that they correlate to the images of the faces on the die: e.g., select all UVs and rotate them (bottom left buttons), scale them, etc.
Once you have the UVs looking like those in the image on the right, the die will actually look right. This is because, as we discussed before, the texture tiles outside of the 0 – 1 region. As an exercise, lets put the last square (the one that's currently outside the 0 – 1 region) in the right place.
Select the UVs around the right-most square (you may have to set the masking mode to UV in the UV texture editor too). Now try moving it around: it also moves the right edge of the next square along. We need to be able to split the UVs on the left edge of the right-most square from those on the face next to them. We do this by selecting them and going to
Polygons → Cut UVs (also available from the RMB marking menu).
Now the UVs are split, so that the right-most square is completely separate from the rest. But we still have a problem: each of the UVs that we just cut are now 2 separate UVs, but they are in exactly the same position. How do we distiguish between them? The easiest way to do it is to switch to selecting faces, select the right-most face, then go to
Select → Convert Selection to UVs. We can now move this face completely independently of everything else, and put it over the "2" face of the die texture. We can also, if we wish, combine the UVs that are almost on top of each other by using the
Polygons → Merge UVs menu item.
So this looks good. However, I now want you to embark upon a more difficult example. We should always bevel our polygon objects, so let's do that now. Bevel the object. But lo! Where has our texture gone? When we bevel the object, it screws up the UVs. They seem to disappear completely, it certainly does very strange things. This is why it is not a good idea to do any modelling after you have arranged your UVs nicely.
We can sort out the problem by re-arranging our UVs. Go to
Edit Polygons → Texture and you'll see several different options for mapping our UVs. The best option is to go for
Automatic Mapping. Do this, and see the result: it's not great. You'll have to arrange the UVs in the UV texture editor again to get them looking right. This will be more tricky: don't worry about getting it perfect, just get something workable.
When you've done it, you might like to change the texture: diemap2.png doesn't have the white lines between the colours, so might look better.
From here you can go and make a complete craps table if you like: I've also got a texture of a table which you can use (crapstable.png), and you can put some rigid body dynamics on the dice for some top quality gambling fun.
*It is important to point out that having the texture before doing the UV mapping is not the usual workflow. Usually the UV mapping is done first, and the texture is painted on top of an image of the unwrapped UVs.