The way it works is quite simple, since it relies on the texture slots list. The textures within the lists simply stack on top of the others. Basically, the first texture in the list is applied as if it was the very first layer of texture. The second texture in the list is applied over the previous one ; if it is 100% opaque, then the first texture would be completely hidden by the first one. The same applies for the third, the fourth and so on, for each of the textures in the slots list.

Of course, you can make use of transparent or semi-transparent textures, in the upper layers of textures, so that they would show at least parts of the underlying textures. But dealing this with Alpha properties of textures can get nasty and cumbersome. Here comes the Stencil.

1. Using a stencil with textures

By using stencils, you won't have to care of the transparency of any individual texture anymore. You will just have to specify a bottom texture, a top texture, and then a stencil texture that will convey all the transparency information and indicate to the renderer how the two different textures are to be mixed over the textured surface.

The process is quite simple. Let's suppose you start with a newly added plane object. In the Material menu, add a new material using the New button.

Capture-01.png
Rename it a convenient way, for example Outdoor_Ground.

Capture-02.pngWe can now proceed with the real magic.

1.1 Adding the "bottom" texture, the first layer

Shift now to the Texture menu. The texture list of available slots should be available.

Capture-03.png

Important note
The first slot available is for the first layer over the surface. This means that it is the bottom texture. This may be confusing, as in the slots list, the upper texture would be the bottom one, and the more down one would be the op one. Keeping this in mind will make things less confuse.

Select the first slot (the one at the top of the list) and use the New button to assign a new texture to it. You can also use the texture browser button to select among a list of pre-existing textures already available in the scene. Let's name the texture Ground, and in the dropdown menu Type, select Image or Movie. In this exemple, I chose a texture from the Blender Texture Disc that is now in the Public Domain.

Capture-04.png

Of course, you could use any other type of texture. In any case, be sure that the Mapping and Influence panels are set properly for your surface model, especially if it is uv-mapped.

1.2 Adding the "top" texture, the second layer

Now select the second texture slot. Do the same as previously, in order to add another texture to the material. For the example's sake, name it Grass and set it also to the Image or Movie type of texture. Most of the time, the Mapping panel would be set the same as previously, but this is not mandatory, as you are perfectly allowed to use an uvmapped image with a procedural texture, for example.

Capture-05.png

1.3 Setting the stencil texture

You can now select the third texture slot for the last part of this tutorial, and a third texture named Stencil, for example. The stencil works on the basis of the Grey value of any picture: black value will show the bottom texture (e.g., the first layer) while white value will show the top texture (e.g., the second layer). Obviously, intermediate colors will mix the two textures according to the grey value: dark pixels will tend to display the bottom texture predominanty, for instance, while light pixels would display the top texture.

Bitmap or procedural?

As for stencil, once again, the use of uvmapped images will provide a very powerful control over the blending of the layered texutres, but a procedural stencil would enable very quick-and-dirty but interesting results over the textured surface. It most probably depends on the distance to the camera of the textured object and its own complexity. On primitives and simple objects, procedural or even blend texture types are very convenient.

Capture-06.png

While you would have to set the Mapping panel as you see fit, a special attention should be deserved to the Influence panel.

  • At first, you have to deactivate the Color influence over the Diffuse of the shader. Otherwise, you would have your grey-based texture that would override the two other textures on the surface of the object.
  • You then have to convert the RGB space values of the texture to Grey space values. This is done by checking the RGB to Intensity option.
  • Finally, you also have to state that this texture is to be used as a stencil. This is obviously done by checking the Stencil option.

Capture-07.png

1.4 Sorting the texture slots

Of course, if you make a render right now, you would see no stencil magic at work, only the top texture covering uniformly all the surface of the object. This is because the location of the stencil in the stencil slots does matter.

Capture-08.png

Back to the list of texture slots, select the Stencil texture and use the up and down arrow buttons on the side of the list to relocate it between the Ground and Grass textures.

stack-02.png

That's it!

2. Using a stencil with node materials

In this mini-tutorial, we will see how to mix two existing materials (coming along with its own complex texture setup, perhaps also involving stencils). Once again, the Mapping of the texture is not our primary focus, so you can use any Projection type (Flat, TubeCube, Sphere) or any Coordinates system (UV...).

2.1 The raw materials

For the purpose of this tutorial, once again I rely on the Blender Texture Disc discussed before. I selected the two following materials:

  • orange
  • redapple

and appended them into my test scene using Shift+F1. I also created a third material, named Stencil, that would be my stencil material. Basicly, it has an Image or Movie texture type applied to it, with Generated coordinates, and Sphere projection. The image is black and white: a checker also issued from the Blender Texture Disc, but any grey toned texture would have been suitable also. In case of a RGB texture, remember to check the RGB to Intensity option in the Influence panel.

nodes-02.png

2.2 The Material Node editor

With the object to be shaded selected, change the Screen layout to Compositing. The Node Editor is then the main view.

  1. In the Material menu, click on the New button to link a brand new material to the selected object. Rename it a convenient way, like Node_Material.
  2. In the header of the Node Editor, activate the Material Nodes icon and check the Use Nodes option. The default nodes settings pop up on screen.
    Capture-09.png
  3. Use the Add > Input entry of the menu to add a second Material node (or use Shift+A to call the floating menu). Repeat one more time, in order to have 3 Material nodes available.

    Remark:
    If you have a node selected, the newly added node will automatically be linked back to it through the most logical socket. To unlink two nodes, just click on the entrance socket of the node newly added.

  4. Now add, a Mix node (Add > Color > Mix).
  5. Sort the nodes network: put the 3 Material nodes on the far left end, the Mix node somewhere in the middle, and the original Output node of the far right end. As for the connexions, complete the network like this:
    • The Color output of the first Material node to the Color1 entrance of the Mix node
    • The Color output of the second Material node to the Color2 entrance of the Mix node
    • The Color output of the third Material node to the Fac entrance of the Mix node
    • The Color output of the Mix node to the Color entrance of the Output node
    Capture-10.png
  6. Assign the materials:
    • The orange material to the first Material node, which will provide the bottom (1st layer) material
    • The redapple material to the second Material node, which will provide the top (2nd layer) material
    • The Stencil material to the third Material node, which will provide the blending of the two materials: white is opaque and will show the top material, while black is transparent and will show the bottom material
    Capture-11.png

The only thing left is to do a render of your scene to enjoy stencils with Material nodes. I'm quite sure you will have quite a lot of creative ideas on how to use stencils in your scenes, from now on!

nodes-01.png


Article written on February the 27th, 2005.
Updated on July the 8th, 2010 for Blender 2.50 Alpha 2. Comments re-initialized.