Book Image

Blender Cycles: Materials and Textures Cookbook, Third Edition

By : Enrico Valenza
Book Image

Blender Cycles: Materials and Textures Cookbook, Third Edition

By: Enrico Valenza

Overview of this book

Table of Contents (17 chapters)
Blender Cycles: Materials and Textures Cookbook Third Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Procedural textures in Cycles


In this recipe, we'll see several kinds of textures available in Cycles, and learn how to use them with the shaders.

Similar to Blender Internal, we can use both procedural textures and image textures in Cycles. However, the Cycles procedural textures are not exactly the same as in Blender Internal. Some textures are missing because they have been replaced by an improved version (for example, the Clouds procedural texture has been replaced by particular settings of the Noise procedural texture), and a few textures are new and exclusive to Cycles.

Getting ready

We have already seen a simple construction of a basic Cycles material by mixing the diffuse and the glossy (specular) components of a surface. Now let's take a look at the textures we can use in Cycles to further refine a material.

Because Cycles has a node-based system for materials, textures are not added in their slot under a tab as they are in Blender Internal. They get added in the Node Editor window, and are directly connected to the input socket of the shaders or other kinds of nodes. This gives a lot more flexibility to the material creation process because a texture can be used to drive several options inside the material network.

Let's see how they work:

  1. Starting from the previously saved start_01.blend blend file, where we already set a simple scene with a Cube on a Plane and a basic material, select the Cube and go to the Object modifiers window inside the Properties panel to the right of the UI.

  2. Assign to the Cube a Subdivision Surface modifier, set the Subdivisions level to 4 for both View and Render, and check the Optimal Display item.

  3. Go to the Tool tab at the left of the 3D window, navigate to Edit | Shading, and set the subdivided Cube (let's call it Spheroid from now on) to Smooth.

  4. Just to make things clearer, click on the color box of the Glossy BSDF shader to change it to a purple color (RGB set to 0.800, 0.233, and 0.388, respectively). Note that only the glossy reflection part on the Spheroid is now purple, whereas the rest of the surface, which is the diffuse component, is still greenish.

  5. Save the blend file and name it start_02.blend. The effect visible in the real-time Rendered preview is as follows:

    The Rendered preview of the effect of two differently colored Diffuse and Glossy components on the Spheroid

How to do it...

Perform the following steps to add a procedural texture to the object:

  1. Put the mouse pointer in the Node Editor window and press Shift + A.

  2. In the contextual pop-up menu, go to the Texture item, just under Shader, and click on Wave Texture to add the texture node to the Node Editor window.

  3. Grab and connect the yellow Color output socket of the texture to the yellow input socket of the Diffuse shader, the socket close to the Color rectangle that we formerly set as a greenish color, as shown in this screenshot:

    The Rendered preview of the effect of a Wave texture assigned as color to the diffuse component of the material

  4. In the Wave Texture node, change the Scale value to 8.500, Distortion to 12.000, Detail to a maximum value of 16.000, and the Detail Scale value to 6.000.

  5. Now disconnect the texture color output from the Diffuse node and connect it to the color input socket of the Glossy shader, as shown in the following screenshot:

    The effect of the Wave Texture assigned as color to the Glossy component of the material

  6. Disconnect the texture color output from the Glossy shader. Grab and connect the texture node's Fac output to the Roughness input socket of the Glossy BSDF shader, as shown in this screenshot:

    The effect of the Wave Texture assigned as Roughness factor to the Glossy component of the material

  7. Disconnect the texture color output from the Roughness input socket of the Glossy BSDF shader. Move the Wave Texture node to the left and add a Bump node (Shift + A and navigate to Vector | Bump). Connect the Fac output of the Wave Texture node to the Height input node of the Bump node, and the Normal output of the Bump node to the Normal input socket of both the Diffuse and the Glossy nodes. Set the Strength to 0.300. Here is a screenshot showing the effect of the Wave Texture node as bump:

    The effect of the Wave Texture Fac output as Bump for both the components of the material

  8. Save the file.

  9. Delete the Wave Texture node (X key), press Shift + A with the mouse pointer in the Node Editor window, and add a Checker Texture node.

  10. Connect the Fac output of the Checker Texture node to the Fac input socket of the Mix Shader node and to the Height input socket of the Bump node, as shown in the following screenshot:

    The effect of a Checker Texture used as bump and especially as blending factor to mix the two components of the material

  11. Save the file as start_03.blend.

How it works...

From step 1 to 3, the changes are immediately visible in the Rendered viewport. At the moment, the Wave Texture node color output is connected to the color input of the Diffuse BSDF shader node, and the Spheroid looks as if it's painted in a series of black and white bands. Actually, the black and white bands of the texture node override the green color of the diffuse component of the shader, while keeping the material's pink glossy component unaltered.

In step 5, we did exactly the opposite. We disconnected the texture output from the Diffuse shader to connect it to the Glossy shader color input. Now we have the diffuse greenish color back and the pink has been overridden, while the reflection component is visible only inside the white bands of the wave texture.

In step 6, in addition to the color output, every texture node also has a Fac (factor) output socket, outputting gray-scale linear values. When connected to the Roughness input socket of the Glossy shader, the texture output works as a factor for its reflectivity. The Spheroid keeps its colors and gets the specular component only in the white areas on the surface (that is, white bands represent total reflection and black bands represent no reflection).

In step 10, the Checker Texture node's Fac output connected to the Fac input socket of the Mix Shader node works as a mask, or a stencil, based on the black and white values of the output. The numeric slider for the mixing factor on the Mix Shader node has disappeared because now we are using the black and white linear values of the Checker Texture output as a factor to mixing the Diffuse and Glossy components. Therefore, these components appear on the Spheroid surface according to the black and white quads of the checker.

Every texture node has several setting options. All of them have in common the Scale value to set the size of the procedural. The other settings change according to the type of texture.

The Fac output of the texture node can be used to feed the Height input socket of the Bump node (actually, the Color output also works quite well here). Hence, the Normal output of the Bump node can be connected to the Normal input sockets of each shader node, giving a per node bump effect. So, the bump can have an effect only on the diffuse component, or only on the glossy component, or on both, and so on.

Let's create an example of Wave and Voronoi textures:

  1. Re-open the start_02.blend file.

  2. Add a Voronoi Texture node (press Shift + A and navigate to Texture | Voronoi Texture) and a new Bump node (press Shift + A and navigate to Vector | Bump).

  3. Connect the Fac output of the Voronoi Texture node to the Height socket of the new Bump node, and connect the latter to the Normal input socket of the Glossy BSDF shader node. Set its Strength value to 0.650 and the Voronoi scale to 6.000.

  4. Save the file as start_02bis.blend.

    Two different procedural textures, a Wave and a Voronoi, used as bumps for the two components to have a per shader effect

In this case, we have two different bump types, affecting the diffuse and the glossy components independently, and building an effect of a layered bump.

There's more...

At this point, you could wonder: "Okay, we just mapped textures on the Spheroid, but what's the projection mode of these mappings?"

Good question! By default, if the projection mode is not specified and if the object doesn't have any UV coordinates, the mapping is Generated, which is the equivalent of the Original Coordinates mode (now renamed Generated as well) in Blender Internal.

But what if you want to specify a mapping method? Then follow these steps:

  1. Press Shift + A with the mouse pointer in the Node Editor window again, go to the Input item, and select the Texture Coordinate item, which is a node with several mapping modes and their respective output sockets.

  2. Try to connect the several outputs to the Vector input (the blue socket on the left-hand side of the node), which can be found from Checker Texture, to see the texture mapping on the Spheroid change in real time, as shown in the following screenshot:

    The Object output of the Texture Coordinate node connected to the Vector input of the Texture node

By the way, I'd like to point your attention to the UV coordinates output. Connect the link to the texture's vector socket, and you will see the mapping on the Spheroid disappear. Why is this so? Because we haven't assigned any UV coordinates to our Spheroid yet.

Go to the UV Maps tab in the Object data window, under the Properties panel on the right, and click on the + sign. This just adds a one-to-one Reset UV projection UV layer to the object, which means that every face of the mesh is covering the whole area of the UV/Image Editor window. Remember that although the Cube looks like a Spheroid now, this is only due to the effect of the assigned Subdivision Surface modifier. The UV coordinates work at the lowest level of subdivision, which is still a six-faced Cube.

A second option is to place the proper seams on the Cube's edges and directly unwrap the object in the UV/Image Editor window, as demonstrated in the following steps:

  1. Press Tab to go to Edit Mode, select the appropriate edges, press Ctrl + E, and in the Edges pop-up menu, select the Mark Seam item.

  2. Now press A to select all the vertices (if deselected), press U, and choose an unwrapping method from the UV Mapping pop-up menu (Smart UV Project and Cube Projection don't even need the seams). Then go out of Edit Mode to update the Rendered preview.

The Texture Coordinate node is not mandatory to map an image texture on an unwrapped object; in such a case, Cycles will automatically use the (first) available UV coordinates to map the image map anyway.

Often, the only Texture Coordinate node is not enough. What we need now is a way to offset, rotate, and scale this texture on the surface:

  1. First delete the Bump node, then select the Texture Coordinate node, and drag it to the left of the window as far as suffices to make room for a new node. In the Add menu, go to Vector and choose Mapping.

  2. Grab the Mapping node in the middle of the link that connects the Texture Coordinate node to the Checker Texture node. It will be automatically pasted between them, as shown in the following screenshot:

    The Mapping node pasted between Texture Coordinate and the Texture nodes

  3. Now start playing with the values inside the Mapping node. For example, set the Z Rotation value to 45°, set the X Scale value to 2.000, and then slide the X Location value, while seeing, in the Rendered viewport, how the texture changes orientation and dimension and actually slide along the x axis.

  4. Save the blend file as start_04.blend.

The Min and Max buttons on the bottom of the Mapping node are used to clip the extension of the texture mapping. Check both Min and Max to prevent the texture from being repeated n times on the surface, and it will be shown only once. A minimum value of 0.000 and a maximum value of 1.000 give a correspondence of one-to-one to the mapped image. You can tweak these values to limit or extend the clipping. This is useful to map decals, logos, or labels, for example, on an object and avoid repetition.

See also

In Cycles, it is possible to use normal maps by adding the Normal Map node (by navigating to Add | Vector | Normal Map) and connecting its output to the Normal input socket of the shader nodes.

To see an example of a Normal Map node used in a Cycles material, go to Chapter 8, Creating Organic Materials, of this cookbook and look at the bark_seamless material of the Creating trees shaders – the bark recipe.

Here is a link to the official documentation talking about the Normal Map node:

http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/More