In this third and final installment of the series, I will demonstrate how to use a series of mask images to apply several different shader setups to different areas of an object in a single material. To recap, in the first part of this series, using a simple cube as an example, I created a greyscale bump map image and used it to bake a normal map using Blender Internal. In the second part I discussed the proper way to apply a normal map in both Blender Internal and Cycles.
Now, using the original bump map image as a starting point, I will create a series of simple black and white images to use as masks for applying several types of materials to various areas of the cube, following the details of the normal map. If you were smart ahead of time and saved a layered GIMP (xcf) or Photoshop (psd) image of the bump map, it’s simply a mater of isolating the elements, turning them white, and making the background black.
The Base Material
The base material is a grey metal texture. To achieve this look, I first add a [tooltip gravity=”n” title=”Input -> Texture Coordinate”]Texture Coordinate[/tooltip] node and an
[tooltip gravity=”n” title=”Texture -> Image Texture”]Image Texture[/tooltip] node then plug the “UV” output socket of the Texture Coordinate node into the “Vector” input socket of the Image Texture node. Then, load in the metal texture image (this texture is from CGTextures.com and can be found here).
Now, I want to mix two shader types for this material: Diffuse and Glossy. First, add the [tooltip gravity=”n” title=”Shader -> Diffuse”]Diffuse[/tooltip] shader node and plug the “Color” output of the Image Texture node into the “Color” input of the Diffuse Shader node. This will apply the metal texture image as the diffuse color of the cube.
For the Glossy shader, I want to color it with the same texture but lighten and de-saturate it first. This is easily achieved by adding a [tooltip gravity=”n” title=”Color -> Mix”]Mix[/tooltip] node, keeping the default type as “Mix” and plugging the “Color” output socket of the Image Texture node into the top “Color1” input socket of the Mix node. Then, set the bottom “Color2” to a gray color (R:0.5, G:0.5, B:0.5) and plug the “Color” output socket of the Mix node into the “Color” input socket of the Glossy node.
To mix these two shader nodes I will add a [tooltip gravity=”n” title=”Shader -> Mix Shader”]Mix Shader[/tooltip] node then plug the “BSDF” output socket of the Glossy node into the top “Shader” input socket of the Mix Shader node and the “BSDF” output socket of the Diffuse node into the bottom “Shader” input socket. I will also use the metal texture image to control the mix factor of these two shader nodes, but I want to have some control over the mixing. For that I will add a [tooltip gravity=”n” title=”Converter -> Color Ramp”]Color Ramp[/tooltip] node then plug the “Color” output of the Image Texture node into the “Fac” input of the Color Ramp node and plug the “Color” output of the Color Ramp node into the “Fac” input of the Mix Shader node (this is mixing data types but for this purpose it will work fine). Finally, plug the “Shader” output of the Mix Shader node into the “Surface” input of the Material Output node.
Note: the normal map is also applied here, for this process see Part 2 of this series. Make sure to plug the “Vector” output socket of the Normal map node into the “Vector” input sockets of all subsequent shader nodes added.
Altering the Color of the Base Material with a Mask Image
The first area of detail on the cube in which I will alter the material is the rough square area on the right-hand side of the cube. For this part, I will simply alter the color of the metal texture in this area. To do this I first create the mask image, using my original bump map as a guide, where the area of the square is pure white and the remaining area is pure black.
Now I will add another Image Texture node, plug the “UV” output socket of the Texture Coordinate node into the “Vector” input socket of the Image Texture node and load in the mask image. Since all I want to do here is tint the metal texture image in this particular are of the cube, there is no need to add a new shader. I can simply alter the image before it plugs into the Diffuse node. To do this I will add a Mix node with the mode set to “Overlay” and drop it in between the “Color” output socket of the Image Texture node and the “Color” input socket of the Diffuse node. Making sure the “Color” output from the Image Texture node is running into the top “Color1” input of the Mix node, I can then change the “Color2” input to whatever color I want to tint the texture.
Adding Emission to the Engraved Lines
The next area of detail I want to focus on is the engraved lines that run along the top and bottom edges of the cube and around the circular details on the left-hand side. I will make these emit a cool sci-fi green light. Again, the first step is to create a mask image to isolate this area of the cube. Using the original bump image this is a simple task.
Since I want this area to be glowing with light, I’ll first add and [tooltip gravity=”n” title=”Shader -> Emission”]Emission[/tooltip] shader node and set the color to a yellow-green and the strength to 1. Also, for the sake of organization, I will group the nodes comprising the metal material by shift-selecting them all and hitting Ctrl+G. Then press Tab to close the Group Node. Next, to mix the node tree to this point with my new Emission node, I’ll add a Mix Shader node and plug the “Shader” output socket of the Group Node into the top “Shader” input of the Mix Shader node and the “Emission” output of the Emission node into the bottom “Shader” input.
Note: there is no “Vector” input on an Emission shader node, so I cannot apply the normal map to this shader.
Now, I want to control the mix factor of my base material and the Emission shader with the mask image. So, I’ll add another Image Texture node, load in the mask image and make sure the “UV” output of the Texture Coordinate node is plugged into the “Vector” input of the new Image Texture node. Then, simply plug the “Color” output socket of the Image Texture node into the “Fac” input socket of the Mix Shader node. (This is again mixing data types, but since the mask image is only black and white there will be no loss of data here.)
Darkening the Vent Holes
I want to fake some depth in the vent on the left-hand side of the cube and I will do that by simply coloring in the holes with pure black. For this and the next part, I will use the same technique that was used above and “daisy-chain” onto the end of the node tree. I will also again group the previous material nodes. First, of course, create the mask image.
Then add a Diffuse shader node (make sure the Normal Map “Vector” is plugged into the Diffuse node “Vector”) and set the color to pure black, add a Mix Shader node and plug in just like before. And, finally, add another Image Texture node, load in the mask image (make sure the “UV” from the Texture Coordinate node is plugged into the “Vector” of the new Image Texture node) and plug the “Color” output socket of the Image Texture node into the “Fac” input of the Mix Shader node.
Making the Text Glass
Lastly, I want to make the text on the top of the cube glass and have light coming from behind it. I’m sure you get the routine by now, so I won’t repeat myself. Just add a Glass shader node and apply the same technique, using a mask image for the Text.
Now, to add the light behind the glass, I will add a plane to the scene and position it inside the cube just under the top side. For visual interest, I prefer the light not be even across the plane, but brighter in the center and fade out to the edges. To do this, UV unwrap the plane, then in GIMP or Photoshop create a grayscale image of a radial gradient – fairly simple.
Then use the following node setup, loading the gradient image into the Image Texture node. The Mix node is used to control the overall brightness without having to edit the image.
The final result:
This technique works well to mix materials following the influence of a normal or bump map. But it can be used in a wide variety of circumstances, anytime you need part of an object to be one material and another part a different material. That’s it for the Normals and Material Masking series, I hope it was helpful and informative.
Some textures used in creating models appearing in imagery on this post are from CGTextures.com, a most excellent source for photo textures.