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

Material nodes in Cycles


A Cycles material is basically made up of distinct components named shaders. They can be combined to build even more complex surface or volume shaders.

In this recipe, we'll have a look at the basic, necessary steps required to build a basic surface Cycles material, to activate the rendered preview in the 3D window, and to finally render a simple scene.

Getting ready

In the description of the following steps, I'll assume that you are using Blender with the default factory settings. If you aren't, start Blender and just click on the File menu item in the top main header bar to select Load Factory Settings from the pop-up menu, as shown in the following screenshot:

The default Blender interface and the File pop-up menu with the Load Factory Settings item

Now perform the following steps:

  1. In the upper menu bar, switch from Blender Render to Cycles Render (hovering with the mouse on this button shows the engine to use to render a label).

  2. Now split the 3D view into two horizontal rows, and change the upper row to the Node Editor window by selecting the menu item from the Editor Type button in the left corner of the bottom bar of the window. The Node Editor window is, in fact, the window we will use to build our shaders by mixing the nodes (actually, this is not the only way, but we'll see this later).

  3. Put the mouse cursor in the 3D view and add a Plane under the Cube (press Shift + A and navigate to Mesh | Plane). Enter Edit Mode (press Tab), scale it 3.5 times bigger (press S, enter 3.5, and then press Enter) and go out of Edit Mode (press Tab again). Now move the Plane one Blender unit down (press G, then Z, then enter -1, and finally, press Enter).

  4. Go to the little icon (Viewport Shading) showing a sphere in the bottom bar of the 3D view and click on it. A menu showing different options appears (Bounding Box, Wireframe, Solid, Texture, Material and Rendered). Select Rendered from the top of the list (or press the Shift + Z shortcut) and watch your Cube being rendered in real time in the 3D viewport.

  5. Now you can rotate and translate the view or the Cube itself, and the view gets updated in real time (the speed of the update is restricted only by the complexity of the scene and the computing power of your CPU or graphics card).

Let's learn more by performing the following steps:

  1. Select the Lamp item in the Outliner window (by default, it's a Point lamp).

  2. Go to the Object data window under the Properties panel on the right-hand side of the screen.

  3. Under the Nodes tab, click on Use Nodes to activate a node system for the selected light in the scene. This node system is made by an Emission shader connected to a Lamp Output node.

  4. Go to the Strength item, which is set to 100.000 by default, and start increasing the value. As the intensity of the Lamp increases, you will see the Cube and the Plane rendered in the viewport getting brighter, as shown in the following screenshot:

    The Viewport Shading menu with the Rendered item and the Lamp Object data window with the Strength slider

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

How to do it...

We just prepared the scene and took the first look at one of the more appreciated features of Cycles since its first inclusion in Blender—the real-time-rendered preview (which, by the way, is now also available in Blender Internal but seems to work faster in Cycles).

Now let's start with the object's materials:

  1. Select the Cube to assign the shader to by clicking on the item in the Outliner window or right-clicking directly on the object in the Rendered viewport (but be aware that in the Rendered mode, the object selection outline usually around the mesh is not visible because it's obviously not renderable).

  2. Go to the Material window under the Properties panel. The Cube already has a default material assigned (as you can precisely see under the Surface subpanel within the Material window). By the way, you need to click on the Use Nodes button under the Surface subpanel to activate the node system for the material. Instead of this, you can also check the Use Nodes box in the toolbar of the Node Editor window.

  3. As you check the Use Nodes box, the content of the Surface tab changes, showing that a Diffuse BSDF shader has been assigned to the Cube and that, accordingly, two linked nodes have appeared inside the Node Editor window. The Diffuse BSDF shader is already connected to the Surface input socket of a Material Output node.

  4. Put the mouse cursor in the Node Editor window, and by scrolling the mouse wheel, zoom in to the Diffuse BSDF node. Click on the Color rectangle. A color wheel appears, where you can select a new color to change the shader color by clicking on the wheel itself or by inserting the RGB values (note that there is also a color sampler and the alpha channel value, although the latter, in this case, doesn't have any visible effect on the object material's color).

    The color wheel of a Diffuse shader node in the Node Editor window and the Rendered 3D viewport preview

  5. The Cube rendered in the 3D preview changes its material's color in real time. You can even move the cursor in the color wheel and watch the rendered object switching the colors accordingly. Set the object's color to a greenish color by changing its RGB values to 0.430, 0.800, and 0.499, respectively.

  6. Go to the Material window, and under the Surface tab, click on the Surface button, which is showing the Diffuse BSDF item at the moment. From the pop-up menu that appears, select the Glossy BSDF shader item. Now the node changes in the Node Editor window, and so does the Cube's material in the Rendered preview, as shown in the following screenshot:

    Real-time preview of the effect of the Glossy shader node and the Surface subpanel under the Material window

Note that although we just switched a shader node with a different node, the color we set in the former has been kept in the new one. Actually, this happens for all the values that can be kept from a node to a different one.

Now, because a material having a 100 percent matte or reflective surface could hardly exist in the real world, a more accurate basic Cycles material should be made by mixing the Diffuse BSDF and the Glossy BSDF shaders, blended together by a Mix Shader node, which in turn is connected to the Material Output node:

  1. In the Material window, under the Surface tab, click again on the Surface button, which is now showing the Glossy BSDF item, and replace it with a Diffuse BSDF shader.

  2. Put the mouse pointer on the Node Editor window, and by pressing Shift + A, make a pop-up menu appear with several items. Move the mouse pointer on the Shader item. It shows one more pop-up, where all the shader items are collected. Alternatively, press the T key to call the Node Editor tool shelf, where you can find the same shader items under the different tabs.

  3. Select one of these items (in our case, the Glossy BSDF shader node again). The Shader node, which is already selected, is now added to the Node Editor window, although it is not connected to anything yet (in fact, it's not visible in the Material window but only in the Node Editor window).

  4. Again press Shift + A in the Node Editor window, and this time, add a Mix Shader node.

  5. Press G to move the node to the link connecting the Diffuse BSDF node to the Surface input socket of the Material Output node (you'll probably need to first adjust the position of the two nodes to make room between them). The Mix Shader node gets automatically pasted in between, and the Diffuse node output gets connected to the first Shader input socket, as shown in the following screenshot:

    Mix Shader node pasted between a preexisting nodes connection inside the Node Editor window

  6. Click on the green dot output of the Glossy BSDF shader node, and grab the link to the second input socket of the Mix Shader node. Release the mouse button now and see the nodes being connected.

  7. Because the blending Fac (factor) value of the Mix Shader node is set by default to 0.500, the two shader components, Diffuse and Glossy, are now showing on the Cube's surface in equal parts, that is, each component at 50 percent. Click on the Fac slider with the mouse and slide it to 0.000. The Cube's surface now shows only the Diffuse component because the Diffuse BSDF shader is connected to the first Shader input socket, which is corresponding to a value of 0.

  8. Slide the Fac slider value to 1.000 and the surface now shows only the Glossy BSDF shader component, which is, in fact, connected to the second Shader input socket corresponding to a value of 1.

  9. Set the Fac value to 0.800 (keep Ctrl pressed while you are sliding the Fac value to constrain it to 0.100 intervals). The Cube is now reflecting the white Plane on its sides, even though it is blurred, because we have a material that is reflective at 80 percent and matte at 20 percent (the white noise you see in the rendered preview is due to the low sampling we are using at the moment. You will learn more about this later). This is shown in the following screenshot:

    The Rendered preview of the effect of the mixed Diffuse and Glossy shader nodes

  10. Lastly, select the Plane, go to the Material window, and click on the New button to assign a diffuse whitish material.

How it works...

In its minimal form, a Cycles material is made by any one of the node shaders connected to the Surface or the Volume input sockets of the Material Output node. For a new material, the node shader is Diffuse BSDF by default, with the RGB color set to 0.800 and connected to the Surface socket, and the result is a matte whitish material (with the Roughness value at 0.000, actually corresponding to a Lambert shader).

Then the Diffuse BSDF node can be replaced by any other node of the available shader list, for example, by the Glossy BSDF shader as in the former Cube scene, which produced a totally mirrored surface material.

As we have seen, the Node Editor window is not the only way to build the materials. In the Properties panel on the right-hand side of the UI, we have access to the Material window, which is usually divided as follows:

  • The material name, user, and the datablock subpanel.

  • The Preview window.

  • The Surface subpanel, including only the shader nodes added in a vertically ordered column in the Node Editor window, and already connected to each other.

  • The Volume subpanel, with the similar feature as that of the Surface subpanel.

  • The Displacement subpanel.

  • The Settings subpanel, where we can set the object color, the alpha intensity, the specularity color, and the hardness as seen in the viewport in non-rendered mode (Viewport Color, Alpha, Viewport Specular, and Hardness). It also contains the Pass Index value of the material, a Multiple Importance Sample checkbox, the Volume sampling methods, the Interpolation, the Homogeneous item to be activated to accelerate the rendering of volumes, and an option to disable the rendering of the transparent shadows to accelerate the total rendering.

The Material window not only reflects what we do in the Node Editor window and changes accordingly (and vice versa), but can also be used to change the values to easily switch the shaders themselves, and to some extent, to connect them to the other nodes.

The Material and the Node Editor windows are so mutual that there is no prevalence in which window to use to build a material. Both can be used individually or combined, depending on preferences or practical utility. In some cases, it can be very handy to switch a shader from the Surface tab under Material on the right (or a texture from the Texture window as well, but we'll see textures later), leaving all the settings and the links in the node's network untouched.

There is no question, by the way, that the Material window can become pretty complex and confusing as a material network grows more and more in complexity, while the graphic appearance of the Node Editor window shows the same network in a clearer and much more readable way.

There's more...

Looking at the Rendered viewport, you'll notice that the image is now quite noisy and that there are white dots in certain areas of the image. These are the infamous fireflies, caused mainly by transparent, luminescent, or glossy surfaces. Actually, they have been introduced in the rendering of our Cube by the glossy component.

Here is one way to eliminate the fireflies:

  1. Go to the Render window under the Properties panel.

  2. Uncheck both the Reflective and Refractive Caustics items under the Light Path subpanel.

  3. This will immediately eliminate the white noise, but alas! It also eliminates all the caustics (which we would like to keep in the rendering in most cases).

Therefore, a different approach is as follows:

  1. Go to the Render window under the Properties panel. In the Sampling tab, set Samples to 100 for both Preview and Render (they are set to 10 by default).

  2. Set the Clamp Direct and Clamp Indirect values to 1.00 (they are set to 0.00 by default).

  3. Go to the Light Paths tab, re-enable the Reflective and Refractive Caustics items, and then set the Filter Glossy value to 1.00.

  4. The resulting rendered image, as shown in the following screenshot, is now a lot smoother and noise-free, and also keeps the reflected caustics on the Plane:

    Noise-free Rendered preview and settings under the Render window

  5. Save the blend file in an appropriate location on your hard drive with a name such as start_01.blend.

  6. The Samples set to 10 by default are obviously not enough to give a noiseless image, but are good for a fast preview. We could also let the Preview samples remain at the default value and increase only the Render value, to have longer rendering times but a clean image only for the final render (which can be started, as in Blender Internal, by pressing the F12 key).

Using the Clamp value, we can reduce the energy of the light. Internally, Blender converts the image color space to linear, which is from 0 to 1, and then reconverts it to RGB, which is from 0 to 255, for the output. A value of 1.00 in linear space means that all the image values are now included inside a range starting from 0 and arriving to a maximum value of 1, and that values greater than 1 are not possible, thus avoiding the fireflies problem in most cases. Be aware that Clamp values higher than 1.00 might also lower the general lighting intensity of the scene.

The Filter Glossy value is exactly what the name says, a filter that blurs the glossy reflections on the surface to reduce noise.

Remember that even with the same samples, the Rendered preview does not always have a total correspondence to the final render with regards to both noise and the fireflies. This is mainly due to the fact that the preview-rendered 3D window and the final rendered image usually have very different sizes, and artifacts visible in the final rendered image may not show in a smaller preview-rendered window.

See also

As you have seen, the several nodes that can be used to build Cycles shaders have both input and output sockets to the left and to the right of the node interface, respectively, and the color of these sockets is actually indicative of their purpose; green sockets are for shaders, yellow sockets are for colors, gray sockets for values, and blue sockets for vectors.

Each color output socket of one node should be connected with the same color input socket of another node. By the way, connecting differently colored sockets also works quite often; for example, a yellow color output can be connected to a gray value input socket and to a blue vector input.

A general overview of all the Cycles nodes can be found at http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes.