Creating materials with nodes
It's now time to discover the material creation process with Cycles. In this section, we are going to create the basic shaders that are composed of our previously painted textures. The shaders won't be at their final stage here. Later, we are going to improve them with normal maps.
Creating the materials of the house, the rocks, and the tree
Let's start with the wall shader of the house:
- We will first select the corresponding object.
- We are going to duplicate the clay shader that we had added in order to test our lighting in the previous section. As you can see, it is used by 68 objects in the scene. If you click on the 68 button on the right-hand side of the material name in the material tab of the Properties editor, you will duplicate the shader and make it unique. At this time, we can now rename it as
HouseWall
. - We are now going to switch to the Node Editor in order to have more control on our shader. In fact, we can do everything in the Properties editor, but it will be quite hard to manage with a complex shader. So open a new editor and change it to a Node Editor.
- As you can see, we already have Diffuse BSDF plugged into the Surface input of the Material Output node.
- A diffuse shader has no shine on it. It looks flat. In real life, every surface is at least a little specular, so we are going to mix our diffuse shader with another shader that will bring us the shiny effect. To do this, we will first add a Glossy BSDF shader (press Shift + A and select Shader | Glossy BSDF) and place it under the diffuse shader. Don't connect it for the moment.
- In order to mix the two shaders together, we will use a Mix Shader node (Shift + A and select Shader | Mix Shader). As you can see, this node has two shader inputs. Plug the BSDF output (green dot) of the diffuse shader to the first shader input of the Mix shader, and the BSDF output of the Glossy shader to the second shader input of the Mix shader. Now plug the Mix shader output to the surface input of the Material Output node. As you can see, both shaders have been mixed together. You can now use the Factor slider in order to choose which one is predominating. If you put a value of 0, you will only use the shader connected to the first input (the diffuse), and if you put a value of 1, you will only use the shader connected to the second input (the glossy one).
- The blend between these shaders is not going to look right with any value, so we are going to connect a Fresnel node to the fac input (press Shift + A and select Input | Fresnel).
Note
About the Fac input
The role of the fac input is to control how both shaders will be mixed. Usually, the Fac input needs to be fed with black and white information where the amount of black tells us how much the first shader will be used, and the amount of white tells us how much the second shader will be used for the final output.
- We can now change the value of the Fresnel to 1.4.
Note
About the Fresnel
The Fresnel node will produce a black and white texture according to the volume of the geometry. It will be calculated according to the light ray's incidence. We usually use a Fresnel node in order to catch the highlights better. You can use a pretty interesting add-on called node wrangler that allows you to quickly see the result of each node without shadows. In order to use it, right-click on the node you want to see while pressing Ctrl and Shift.
- We will now change the glossy color to a yellowish tint. Don't forget to turn on real-time shading in order to have a preview of what this will look like in the render. You can also drag a rectangle to the zone you want to preview with the Shift + B shortcut while being in camera view. If you want to remove the rectangle zone, drag a new zone to the outer zone of the camera in the camera view.
The last thing we will do with this material for now is plug it into our texture:
- We will add a new Image Texture node (press Shift + A and select Texture | Image Texture).
- We will need to connect the Color output of this node to the Diffuse BSDF color input.
- It's also a good idea to add a Texture Coordinate (press Shift + A and select Input | Texture Coordinate) node and plug the UV slot to the Vector input of the Image Texture node.
By default, the Vector inputs are set to be UV, but with this node, we can clearly see the mapping method used for the textures.
- We can now select one of the roofs and change its clay shader to the one we created because the roof shader will be nearly the same. Now, in order to break the link between the roof and the wall shader, we can press the button with the number of objects that share the same material in order to copy the material.
- We will rename this shader to
HouseRoof1
. - The only thing we need to do for now is to change the texture of the Image Texture node to the corresponding roof texture.
- We can now select all the objects that need to share the same material (the other blue roofs), and finally, we select the roof that has the shader that we want to share, press Ctrl + L, and select Material.
- We will now repeat the process of creating a new material by copying it from the previous one, changing its name and texture information, and linking it to its corresponding objects.
We will now have a shader on the rocks, the tree, and all the different objects that make up the house. The only shader that will be different is the one on the top window. It needs to emit light. In order to do this, we will copy the previous material, delete the diffuse, glossy, and mix shader (X or Delete), replace them with an Emission shader (press Shift + A and select Shader | Emission), and plug the window texture to this. Now the top light is going to emit light! You can tweak the emission value if you want more light. As you can see, we need to do this for the other windows as well, but in the case of the other windows, we can't do this simply because they are not planes and their color information is located on the wall texture. That's why we need to paint a mask.
Adding a mask for the windows
We are now going to improve our wall material by creating a mask that will separate the windows that are shining from the rest. These windows are going to be painted white and the rest will be black. So when we plug the mask in the Fac input of a Mix material node, we will be able to choose an emission shader for the white parts.
- We are going to paint our map in the Blender Internal context. Note that we can actually use the Texture Paint mode while being in Cycles, but this implies that we add and select a texture node that uses the texture that we want to paint.
- So we will select the wall object, and in the UV Image editor, we will create a new 1024 x 1014 black texture. Usually, masks don't need large resolutions.
- Now in pure white paint the windows that shine (the light yellow ones on the color map).
- Let's go back to our wall material and add a mix shader just before the output node. If you want to save time, you can drag the node on the connection line of the previous Mix shader and the Output node. This will automatically do the connections for you.
- The first shader input is already used by our old Mix shader. Now we are going to add a new Texture node with our mask and plug its output to the Fac input of our new Mix shader.
- The second shader input will be fed with an Emission shader (press Shift + A and select Shader | Emission). In the Color input of this node, we will plug our color map (the same as in Diffuse shader).
- Now we can increase the strength of the Emission shader to 2.0. As you can see, now our shining windows (and only them) emit light!
Using procedural textures
One thing that could be very interesting when creating materials is generating their textures procedurally. In this render, we are going to replace the hand-painted ground by a procedural material. This is done as follows:
- We will select the cliff and create a new material for it.
- The next thing is to add a Diffuse BSDF node. The color input of this diffuse material will be fed with a mix of procedural textures.
- Let's add a Noise texture node (Shift + A and select Textures | Noise) and duplicate it (Shift + D). The first one will have a scale of 2.0, and the second one will have a scale of 10.0. Our goal is to have a mix of both levels of noise. Both of them will use the Tiled UV layer, so add a UV Map node (press Shift + A and select Input | UV Map), select the correct map, and feed the Vector input of the noise textures with the UV Map node output.
- As these nodes are textures and not shaders, we aren't going to use the Mix Shader node but the MixRGB node instead. So we will add one of these nodes (press Shift + A and select Color | MixRGB), and feed the inputs with their noise Fac output. Don't use the color output as we want a black and white mix here. Remember that you can always test your results with the Node Wrangler add-on (press Shift + Ctrl and right-click on any node).
- We are now going to mix this result with a Musgrave node (press Shift + A and select Texture | Musgrave). We also need the Tiled UV for the vector input. We will set the Scale to 20.0, the Detail to 3.5, and the Dimension to 1.7. Its effect will be pronounced in the final result, so we are going to mix it with white. To do this, we will add the MixRGB node and plug the first color input with the Fac output of the Musgrave Texture. The second color slot can be changed to white. We are going to change the Fac slider of the MixRBG node to 0.98; this will make Musgrave very subtle.
- We can now mix our noises and the Musgrave results together with one more MixRGB node.
- If we plug this directly to the color input of the diffuse, we will get a black and white result. In order to introduce color, we will need another MixRGB node, but instead of feeding the color inputs we are going to plug our texture in the Fac input and choose two brownish colors. Now we can plug the result to the color input of the Diffuse shader.
- Lastly, we can plug the black and white texture to the displacement input of the Material output node. In order to raise the displacement effect, we can place a Math node in-between (press Shift + A and select Converter | Math). We can change its operation to Multiply and use a 3.5 value.
Making and applying normal maps in Cycles
As we saw it previously with the alien character, normal map allows us to simulate a relief on a 3D mesh very efficiently. It would be good to generate a few of them in order to add some relief to our scene. We will explore a method to easily generate normal maps from tiled, hand-painted textures:
- We will open a new Blender scene.
- We will delete the cube (X) and then we will add a plane in the middle of the scene (press Shift + A and select Mesh | Plane) that we name as Plane-1.
- We will split the screen in two parts to open the UV/Image Editor at the right-hand side.
- We will add a Multires modifier to our plane and a Displace modifier. We will place the Multires modifier above the Displace modifier.
- In the Texture tab, we will create a new texture by pressing New, and then we will load the tiled texture of wood, that is, WoodTilePlank.png.
- We will check that the texture is loaded in the Displace modifier.
- In the Multires modifier, we will check the Simple mode, and we will click on subdivide until we get to level 8. The more the mesh is subdivided, the more the Displace effect is accurate, but we must pay attention to the RAM of the computer.
- We will modify Strength to 0.25. This can vary depending on the texture. We must avoid important deformations on the mesh.
- We will duplicate the plane (Shift + D), and then we will delete the modifiers of this new plane that we name as Plane-2.
- We will select all the faces (A) of Plane-2 in the Edit Mode, and we will do an unwrap (U | Unwrap) with a square shape taking all the UV surfaces. Then, we will add a new image. In the UVMap Editor, we will click on New Image (Image | New Image). We will name it as WoodTilePlank_NM.png.
- We will move Plane-2 to the same height as Plane-1.
- Enter the top view (the 7 numpad key) for a better view of the mesh.
If the Displace doesn't give exactly the effect we want, we can make a few modifications with the Sculpt mode after applying the displace modifier by pushing on Apply. This is what we will do with the rock and the tile roof textures.
We can now bake a normal map as follows:
- We will need to click on the Smooth Shading button, otherwise we will see the polygons on our bake.
- Then, we will have to first select Plane-1 (RMB) and then Plane-2 (press Shift and the RMB). This becomes the active object.
- Now, in the Properties editor, under the Render section, we will expand the Bake subpanel.
- The first option to choose is what type of map (or texture) we want to bake. So, in the Bake Mode drop-down menu, we will select Normal Map.
- The next thing we'll have to check is the Selected to Active option that tells Blender to bake from the sculpture to the active object (our low poly plane).
- Now you can click the Bake button. Don't forget to save your map (select Image | Save As Image or press F3), or it will be lost!
We will use the same process of Normal Map creation for every tiled texture. Once this is done, we can return to our shaders and apply our normal maps.
We will start with the House-Rock shader, which is very simple for the moment:
- We will add a Glossy node (Shift + A) and navigate to Shader | Glossy BSDF, which we will mix with diffuse using a Mix Shader (Shift + A and select Shader | Mix Shader). To better visualize the normal maps, we will need glossiness.
- We will add Fresnel (Shift + A and navigate to Input | Fresnel) that we will position in the FAC input socket of the Mix Shader node. We will put a IOR value of 1.4.
- We will add a Normal Map node (Shift + A and select Vector | Normal Map) with a Strength value of 1.0 and connect its output to the Normal input socket of the Diffuse and Glossy shaders.
- We will duplicate an Image Texture node (Shift + D), and we will open the normal map texture named Roch-Tilling-NM.png file. We must switch the Color Data option of this second Image Texture to Non-Color Data. The data should not be interpreted as color data but as normal direction data.
- We will add a UV Map node (Shift + A) and navigate to Input | Glossy UV Map. Then we will change the UVLayer to Tiled. You will recall that the rocks have two UV layers, so we must select one.
We can apply this process for almost every shader using hand-painted tiled textures, except the brick walls in our case. It is a special case that requires that we bake the normal map on a larger map with a little modification of painting in order to hide the bricks behind the windows.