Home Game Development Blender Cycles: Lighting and Rendering Cookbook - Second Edition

Blender Cycles: Lighting and Rendering Cookbook - Second Edition

By Bernardo Iraci , Ton Roosendaal
books-svg-icon Book
eBook $32.99 $22.99
Print $54.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $32.99 $22.99
Print $54.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Key Holder and Wallet Studio Shot
About this book
Blender provides a broad spectrum of modeling, texturing, lighting, animation and video post-processing functionality in one package. It provides cross-platform interoperability, extensibility and a tightly integrated workflow. Blender is one of the most popular Open Source 3D graphics applications in the world. Modern GPUs (Graphics Processing Unit) have some limitations for rendering complex scenes. This is mainly because of limited memory, and interactivity issues when the same graphics card is also used for displaying and rendering frames. This is where Cycles rendering engine comes into play. Cycles is bundled as an add-on with Blender. Some of the features of Cycles is its quality, speed and having integrated industry standard libraries. This book will show you how to carry out your first steps in Cycles - a brand new rendering engine for Blender. In a gradual and logical way, you will learn how to create complex shaders and lighting setups to face any kind of situation that you may find in Computer Graphics. This book provides information on how to setup your first application in Cycles. You will start by adding lights, materials, and textures to your scene. When it's time for the final render, you will see how to setup Cycles in the best way. You will learn about a wide variety of materials, lighting, techniques, tips, and tricks to get the best out of Cycles. Further on in the book, you will get to know about animation and still shots, and learn how to create advanced materials for realistic rendering, as well cartoon style shaders. This cookbook contains a wide range of different scenes, proposed in a structured and progressive order. During this journey, you will get involved in the concepts behind every step you take in order to really master what you learn.
Publication date:
December 2013
Publisher
Packt
Pages
274
ISBN
9781782164609

 

Chapter 1. Key Holder and Wallet Studio Shot

In this first chapter we will learn how to set up Cycles. Then, we will create our first materials and lights in Cycles. We will cover the following topics:

  • Setting up Cycles for the first run

  • Creating a three-point light setup in Cycles using mesh emitters

  • Learning environment lighting

  • Using the Glossy shader to create a clean metal material

  • Adding realism to the keys with a bump texture

  • Creating a rubber shader for the key holder

  • Adding color to the key holder

  • Creating a leather material for the wallet

  • Using the Cycles camera's depth of field

  • Setting the Cycles render parameters

 

Introduction


Here we are at the beginning of our journey. In a short time we are going to set up our first Cycles scene. We will start with some basic lighting and materials, but at the end of this chapter we will have already learned a good amount of knowledge, which we will use to proceed with the other chapters and the creation of more and more complex things in Cycles.

 

Setting up Cycles for the first run


In this recipe we will see how to set up Cycles for the first run.

Getting ready

Let's open Blender and set Cycles as the rendering engine. If you are using the CPU to render, you are pretty much ready to go. If you want to use your video card, we need to change a couple of settings.

How to do it…

  1. Let's go to File | User Preferences.... As an alternative you can use the hotkey Ctrl + Alt + U.

  2. Let's start by going to the System tab and in the lower-left corner you will see the Compute Device setting area.

  3. As default it is set to None, but to use your Compute Unified Device Architecture (CUDA) device, you need to click on the CUDA button. From the drop-down menu, select your device (or devices if you have more than one card installed in your computer).

  4. At this point you may want to save the settings. To do this, click on the Save User Settings button in the lower-left corner so that Blender remembers these settings at the next startup.

    Tip

    If you are working with Blender 2.66 or newer, the user settings and the startup scene are kept separate. If on the other hand you are using an older version, clicking the Save User Settings button will also save the scene that you have in the viewport at the moment, and it will become the startup scene of Blender. To save the startup scene in version 2.66 or newer, go to File | Save Startup File.

  5. Now let's close the Blender User Preferences window and go to the Render menu bar item. From there go to the render menu and change the Device from CPU to GPU Compute.

  6. Let's open up the keys_Empty.blend file. If we did everything correctly from the previous section, the video card settings should have remained as we set them a while ago.

    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.

  7. As you can see the interface is a bit different from the default one. This is because to set up Cycles materials, we will need a node editor always open. Moreover, Cycles has a new great feature that will help us while setting up our scenes—the interactive viewport.

  8. When the interactive viewport is on, we will see our render running in real time in the viewport; in the meantime, we can set up our lights and material.

  9. This is why I like to have a small viewport always set on camera view to check out the scene in real time. As the rendering is quite a heavy process, if we don't have a really powerful hardware (such as a dual-video card machine), it is good to keep this window comparatively small, in order not to over charge the system.

  10. We will use the main viewport to select and move objects around in the scene, as this operation is not so easy from the real-time viewport.

  11. Of course the interface setup really depends on personal tastes, so feel free to change it as you like. For the sake of simplicity in this book, when explaining some passage I will refer to the interface setup you will find in the various chapter's scenes.

  12. Well, I think that now we are really ready to set up our first Cycles scene!

 

Creating a three-point light setup in Cycles using mesh emitters


For our first lighting setup we will look at one of the most important and common ways of lighting: the three-point light setup. As the name suggests, this consists of three lights—the key light, the rim light, and the fill light. With different positions, colors, and intensities we can create a huge variety of moods for our image and this is why every artist should know how to set up this kind of lighting. Let's get started!

Getting ready

From the smaller viewport header, select the Display mode and from the drop-down menu, click on the Rendered mode.

Here you have it! The awesome real-time viewport. Now the scene is quite empty, so it is not so heavy and Blender should still be quite responsive. Anyway, it is up to the artist to decide when to turn the real-time viewport off if it becomes too heavy.

Tip

When we activate the real-time viewport, in the upper part of it we can see some technical info. The last one on the right is Path Tracing Samples x/x. The more samples you have, the more precise and less noisy the viewport will be. If you want to increase the samples for the viewport, go to the render settings section and under the Sampling panel, change the Preview value. Just keep in mind that higher samples also mean higher render time!

How to do it...

These are steps that we need to follow to create a three-point lighting setup:

  1. Right now, the scene is quite dark and boring. So, let's add some light to start. Add a plane, add a material to it from the material menu, and name it Key_Light. While the node editor will be needed for the biggest part of materials, for the really basic ones it is still possible to use the old materials menu. So from the Surface panel, click on the Surface drop-down menu and select Emission. Note that a new shader node has been added in the node editor.

  2. If you still have the real-time viewport active, you will see that the plane is emitting light. Place the light a bit above our scene and let's take some time to familiarize with it. As we said in the introduction, Cycles is able to calculate lights in a quite accurate way. Indeed, mesh lights will behave like it does in reality.

  3. This means that increasing the surface of the emitter will increase the amount of light in the scene. At the same time, the shadows will become more blurred. On the other hand, a smaller surface will be weaker but will cast much sharper shadows.

  4. For the mesh emitters the only possible setting is in the materials menu (or in the node editor) and is Strength. Let's give this light an emitting power of 10 and then place it a bit on the right and a bit higher than the camera, and make it face towards the center of the scene. Now set the scale to 3.

  5. Let's copy the plane, place it on the left side of the scene, and scale it up to a value of 16. Our target is to make the shadows of this light much smoother, this being a fill light. The problem is that now its light is way too strong. By clicking on the button with the number 2 on it, which is right next to the material name, duplicate the material and name it Fill_Light and set the intensity of this material to 1. To make the scene a bit more interesting, we can add a touch of blue to the color of the light. Something like R: 0.600, G: 0.800, B: 0.800 should be fine.

  6. Now let's duplicate the emitting plane again and move it behind the objects facing towards the camera and leave the scale as it is. Again we will have to duplicate the material and name it Rim_Light . Change the color to a really subtle yellow. Set the RGB value to 0.800, 0.770, 0.600. This small color temperature contrast will help make the scene more interesting.

  7. There is just a small problem now. We can see our rim light in the camera, and this is not exactly what we want in a studio shot. Luckily, even if Cycles is a realistic engine, there is still a lot of room for tricks! With the rim light selected, go to the object menu and down to the Ray Visibility panel. Here uncheck the Camera checkbox and our rim light will be gone from the real-time viewport!

  8. That's it for our three-point light setup! In the end, our scene should look more or less like this:

How it works...

As we said at the beginning of this recipe, the three-point light setup is one of the most important setups to master and one of the most commonly used. We are now going to see the concepts behind it in depth.

Key Light

This is the dominant light in the scene. This light plays the main role in determining the mood of an image and in shaping the form of subjects. It is also responsible for most of the shadows. With that said, the key light is not always the brightest one in the scene. More often than not the rim light is the brightest. On the other hand, the key light must always be brighter than the fill light. This light is usually positioned about 30 to 60 degrees to the front and to the right-hand side of the object. This is not a rule, however.

Fill Light

As the name suggests, this light fills in the shadow areas. As we said before, it is always of lesser visual intensity than the key light. The fill light is also really soft. This is because it is used to control the contrast of the image. A stronger fill light will result in a less-contrasted (and so with less visual tension) image, while a weaker fill light will leave the image with a higher contrast (and thus a more dramatic and visually tense image). In the real world, the fill light is always generated by the reflected or scattered light from where it takes its soft look. The fill light is usually positioned across from the key light, in order to better fill the shadows left by the latter. Still it should cast its light from the camera side.

Rim Light

This light is also called Backlight and its primary function is to make the subject stand out from the background. It creates a thin line of light around the shape of the subject that helps to enhance the illusion of depth and emphasize the subject. This light is positioned behind the subject, more or less opposite to the camera point of view.

The three-point light setup became so popular thanks to its versatility. Playing with the intensities, colors, and position of the lights will greatly change the mood of the image, from a happy fairy look to a dark and sinister one. A good technique is to find references from images, for example, movies, and try to recreate the look of that image. You can be sure that in almost any of the movies out there, the lighting of the subjects was done with a three-point setup.

In this link Ben Simonds will explains a lot of tips and tricks with the three-point light setup, including how to give different moods:

http://bensimonds.com/2010/06/03/lighting-tips-from-the-masters/

 

Learning environment lighting


Even if we already set up a proper three-point light system, a real studio shot usually has some more elements around the scene that will contribute to the reflections on the object.

Getting ready

To recreate the environment that will contribute to the lighting and the reflections, it won't be necessary to model a whole scene. Instead, we can use an image to fake the environment around the scene and give our objects something to reflect.

How to do it...

To create the environment lighting, we will be following these steps:

  1. Let's go to the World node editor and add the following three nodes:

    • Texture Coordinate

    • Environment Texture (Add | Texture)

    • Mapping (Add | Vector)

  2. The environment texture is the kind of texture that we always have to use for a World BSDF (Bidirectional Scattering Distribution Function). The Mapping node is really useful. It allows us to move, rotate, and scale an image on a surface or, as for this situation, on the environment. Let's plug the Generated output socket of the Texture Coordinate node in the Vector input of the Mapping node and the output of the latter in the Vector input of the Environment Texture node. Finally, as we would do for a normal shader, let's plug the texture in the Color input of the Background node.

  3. Now the sky will have a purple color. That's because we still haven't loaded any image in the Texture node. Let's do it now, and from the browser, load the studio019.hdr file. Here we go! Now the environment will resemble the look of a real photographic studio. You can move around in the scene in the perspective mode, or look through the camera and the picture will move accordingly.

  4. All we have to do now is to set the Z rotation in the Mapping node to -90 degrees in order to place the image accordingly to our scene. Finally, let's set the intensity of the Background node to 0.6.

To see the final effect, remember to activate the layer with the lights and deactivate the Clay material overwrite option from the Render menu.

Here is how the World node setup should looks like:

How it works...

Let's have a brief look at the environment lighting system built in Cycles in a more general way. As for the materials, we have two ways of setting it up. We can use the menu as it works for Blender Internal (BI) or we can use the node editor.

Of course, the node editor will give us more versatility for the creation of the environment. Anyway, before we can use it, there is one thing to do. Let's go to the World menu and on the Surface panel click on the Use Nodes button. Now we are ready to move to the node editor and start playing with the environment.

In the lower header of the node editor, click on the World icon (it is the same icon of the World menu). What you should see is a Background node plugged inside a World Output node. The concept behind the environment is exactly the same as for the Shader node system. Here, things are a bit more straightforward as the only shader node which we have to worry about is the Background one. For the rest, it works exactly in the same way.

To familiarize with the environment lighting, let's switch off the layer with the mesh lights for a moment. Also, to speed up the scene rendering, we will use a clay material for the whole scene. Don't worry, we won't be changing materials one after another. It is enough to go to the Render menu, and from the Layers panel, select the material Clay inside the material space. This is just a gray diffuse material that I included in the file. All the materials we created are still where we left them, but for now every object of the scene will render with the Clay material. To come back to the original situation, it will be enough to erase the material from where we just placed it.

Now, let's activate the real-time viewport. Remember that Cycles have Global Illumination (GI). This means that the environment will always influence the scene. Of course we also have the possibility to deactivate it, but this is an important concept to keep in mind. If we set the color to pure black, as there are no lights, the scene will look pitch black. As we make the color lighter, we will start to see things in our scene. As it is now, which is a plain color, the environment works as a constant source of light which is uniformly distributed around our scene. It will not cast shadows, but we will be able to see the occlusion of the objects. In a moment, we will see that it is possible to make the environment non-uniform, in order to resemble the different kind of places or lighting or whatever we want, without physically having them in the scene.

In the World menu, right below the Surface panel, there is the Ambient Occlusion panel. In Cycles, the ambient occlusion works only in the Add mode. By activating it, you will see that the occluded areas of the scene look much brighter. We can adjust the intensity and the distance at which the AO affects the objects of the scene. For this particular scene, we will not be using the AO, so switch it off for now.

Even below the Settings panel there is the Multiple Importance Sample checkbox. I quote from the Cycles manual:

"By default, lighting from the world is computed solely with indirect light sampling. However for more complex environment maps this can be too noisy, as sampling the BSDF may not easily find the highlights in the environment map image. By enabling this option, the world background will be sampled as a lamp, with lighter parts automatically given more samples."

So, this option will help us reduce the noise when dealing with complex images used as environments. The map resolution will increase the accuracy of the MIS, but also increase the render times and memory used.

There's more...

At the beginning of this chapter, we talked about Bidirectional Scattering Distribution Function (BSDF from now on). We will have a lot to do with this from the next recipe, so it is time to have a better understanding of what it is. Said in a really simple way, it represents a big part of the shaders present in Cycles. As the name suggests, it is the function used by Cycles to distribute the light when a surface is lit. So, when we apply a BSDF to an object, the light will be distributed following the function of the BSDF we used, depending on the one we use. As we will see, there are several BSDFs, such as Diffuse, Glossy, Glass, and others. Each one of these is a different light distribution function, which imitates real-life materials. With each chapter of the book, we will see in depth each BSDF present in Cycles and learn to use it at its best.

It is important to say that there is also a second kind of scattering function called Bidirectional Surface Scattering Reflectance Distribution Function (BSSRDF). This is another kind of function which is used for some particular shader, for example, the subsurface scattering which we will see for the first time in Chapter 3, Creating an Interior Scene.

See also

 

Using the Glossy shader to create a clean metal material


Now that the lighting is ready, we need to add some material to the objects of our scene. Let's start with the key.

Getting ready

Select the key from the scene, add a new material and name it Key. Even if the key material alone will be quite simple, this time we are going to use the node editor in order to set it up.

By default when we add a new material, Cycles will add a Diffuse shader node and of course, the material output. For the key metal we will also need this node, so let's leave it where it is. Moreover, we are going to need a glossy shader in order to add reflections to the key surface.

How to do it...

These are the steps to create the materials of this recipe:

  1. To add a new node, we need to keep the cursor on the node editor and press Shift + A to make the Add menu appear. Now let's go to Shader | Glossy BSDF. A new Shader node will appear where your cursor stands.

  2. Now we need to mix the Diffuse BSDF and the Glossy BSDF nodes. To do this, we can use the Mix Shader node. You will find it again in the Add menu, Shader section. Now let's take the output from the Diffuse BSDF node and plug it into the first Shader input of the Mix Shader node, and the output of the Glossy BSDF node into the second Shader input of the Mix Shader node. As a last thing, take the output of the Mix Shader node and plug it into the Surface input of the Material Output node.

  3. In the real-time viewport you should already see that the key is looking much better than with the plain white material it had before. Anyway, we need to make a couple of tweaks to make it look as it really should.

  4. First of all we need to change the mix factor in the Mix Shader node. Let's change the face value to 0.800. In this way 80 percent of the output will come from the lower shader input, where we connected the Glossy BSDF node. Now the key should have stronger reflections on the surface.

  5. Anyway if we observe a real key, we will notice that reflections are quite sharp when objects are close to the surface, while they get a bit blurred as the distance increases. Our key right now has definitely too blurred reflections, and to make them sharper, we need to change the Roughness value of the Glossy BSDF node. Set it to 0.060 and now we can see that the reflection of the close objects are much sharper.

  6. The last thing to do is to change the diffuse color to a gray one (set RGB values as 0.200, 0.200, 0.200).

The final node setup should look like the following screenshot:

And that's it! We just created our first Cycles material!

How it works...

In this first material we are mixing two different BSDFs to obtain the desired result. While the Glossy BSDF is important to get reflections on the surface of the key, it is also true that the metal of which the key is made of does not behave as a mirror. This means that even if it is strongly influenced by the colors and lights around it, in most cases it will maintain its grayish color. This is why we mixed the Glossy BSDF with a bit of Diffuse BSDF. The Diffuse BSDF is useful to give a plain color to a surface. It will still be influenced by surrounding objects and lights, but it will help the surface to maintain its gray color in most environment situations.

There's more...

You will see the BSDF acronym next to every shader node in Cycles. Applying a shader to a material will change the way in which the lights interact with the surface of that material. Each different shader node contains a different BSDF.

 

Adding realism to the keys with a bump texture


In this recipe we will learn how to use bump maps to distort the surface of an object or at least create the illusion of it.

Getting ready

Now the surface of our key is reacting in a realistic way to light, but it is still missing something. Every real key has got some word or pattern on it. To obtain this effect, we are going to add a bump texture at the key material in order to add these details on the surface.

How to do it...

These are the steps we are going to follow to create the bump for our material:

  1. Let's go to our node editor and add a new node. To do this press Shift + A and go to Inputs | Texture Coordinate. This node will allow us to tell Cycles what kind of coordinate we want to use for the textures of our material. Now we need to add an Image Texture node. We will find it in the Textures section of the Add menu. Before we start to link the nodes, we need the last one. From the Vector section of the Add menu, add a Bump node.

  2. Now let's link the UV output from the Texture Coordinate node to the Vector input of the Image Texture node and the Color output of the latter to the Height input of the Bump node. As a last linking we need to put the Normal output of the Bump node into the Normal input of both the Diffuse BSDF and Glossy BSDF nodes. We are almost ready, as we just need to add the image that we want to use as a bump map. To do this we need to click on the open image icon in the Image Texture node. From the file browser go to the Chapter01/Blend/Textures folder and open the Key_Bump.png image.

  3. That's it! Looking at the real-time viewport we can see the bump map doing its work on the key surface. Without changing anything of the mesh geometry we can see really fine details, affecting the way the light reacts on the surface of the key.

  4. There is one last thing to change. The strength of the bump node is definitely too much. To adjust this, let's change the Strength value of the Bump node to 0.030.

The final node setup of the key material will look like the following screenshot:

How it works...

We used the Texture Coordinate node to tell the Image Texture node where to place the image on the surface of our key. Then with the Bump node we converted the black and white image information into vector information which is readable by the BDSFs.

When we use a bump map, Cycles will treat the surface as it would be lower in correspondence to the black areas of the image and higher in correspondence to the white ones. Of course all the grayscale in the middle will give information about the position of the surface. Taking this information in account, the BDSFs will calculate the behavior of the light bouncing on the surface of the object.

There's more...

A bump map is a black and white image which contains information about the shape of the surface of an object. It is used to add details to a mesh without actually changing the geometry of it. This means that during the rendering process, Cycles will take to account the information taken from the bump map and make the light react accordingly even if the surface is actually flat. A bump map will not change the silhouette of the object, it will just fake the details on the surface. To actually change the geometry we need to use displacement, but we will cover this technique later on in the book, in Chapter 8, Creating a Car Animation, in the Creating the materials for the exterior environment recipe.

 

Creating a rubber shader for the key holder


Now we will create a material for the key holder. It will be a soft rubber material and something completely different from the metal of the key.

Getting ready

Before we start to create the material we need to add it to the mesh. Let's select the key holder mesh, add a new material to it, and name it KeyHolder.

How to do it...

These are the steps we are going to take to create the rubber material:

  1. Now, erase the Diffuse BSDF node from the node editor as we will not use it. Instead, we will be using the combination of Translucent BSDF and Glass BDSF nodes. Add them from the Shader section of the Add menu. Also add a Mix Shader node and link the Translucent BSDF node to the first Shader input and the Glossy BSDF one to the second Shader input of the Mix Shader node. Also set the Fac value to 0.100.

  2. As you can see in the viewport, the key holder now has a white milky material, with the light scattering inside itself. Anyway, to give it a rubber-like look we need to tweak the Glass BSDF node a bit.

  3. Let's change the Roughness value of Glass BSDF to 0.500. Doing so, we will make both the refractions and the reflections generated by this BSDF quite blurry, to resemble the look of a piece of rubber. Also set the Glass BSDF color to pure white.

  4. The last thing we need to do is to set the correct IOR value for the rubber. On the Internet you can easily find information about the IOR (Index of Refraction) of different materials. Rubber for instance has an IOR of 1.5191. Let's set the IOR value in Glass BSDF to 1.5191.

Here is how the final node setup will look like in the following screenshot:

How it works...

A rubber material needs the light to be scattered inside itself. Moreover, it will have a slight amount of reflection on its surface and refractions within its volume.

With the Translucent BSDF node we make the light scatter through the key holder. As we need a touch of reflections and refractions, we will use a small amount of the Glass BSDF node. As both reflections and refractions are quite blurry for a piece of rubber, we increased the roughness value of the Glass BSDF node.

The color of the Glass BSDF node is really important. As we will see, especially in the next chapter, really small changes make a big difference. In order to not make a glass look dark and almost dirty the color needs to be pure white. Even a slightly darker color will not make the glass look good.

There's more...

The Translucent BSDF allows the light to pass through the object and get scattered within. The surface, as in the Diffuse BSDF, is without reflections. On the other hand, a Glass BSDF, as the name tells us, is a shader used to recreate glass materials. While for the Translucent BSDF we can just choose the color, and for the glass we can change the glossiness of the refractions and the IOR. This last value represents the ratio between the speed at which the light travels in vacuum compared to the speed in the object. This is the reason why when we look through a piece of glass we see things distorted. Moreover, the Glass shader generates not only refractions, but also reflections on the surface of the object.

 

Adding color to the key holder


In this recipe we will learn how to use a color texture inside a material. We will also learn a really interesting technique to make the material more realistic and "live".

Getting ready

As you will have probably noticed our key holder has the shape of the Blender logo. Of course we cannot have just the shape, we need to add proper colorization!

How to do it...

To effectively use a color texture, we need to follow these steps:

  1. First of all let's add the colors of the Blender logo to it. In the node editor add a new Image Texture node and a Texture Coordinate node. Also, for these textures we will use the UV coordinates.

  2. Now link the Color output of the Image Texture node to the Color input of the Translucent BSDF node. It is already much better! Now we have a nice Blender logo! Some could say that we could even stop here, but let's tweak this material even further.

  3. It would be nice to have a bit of dirt in the occluded parts of the the key holder. To obtain this kind of effect, we will be using vertex paint.

  4. First of all let's paint the vertices of our key holder. From the lower header of the viewport, select from the Mode menu, Vertex Paint. Now our key holder will have a shadeless white color in the viewport. From the lower viewport header, in the Paint menu select Dirty Vertex Color. Looking at the viewport we can now see that the color of the key holder has changed. This function will give a black and white color to the surface of the object following things such as occlusion and topology. We could say that our key holder is a bit dirty, and this is what we wanted.

  5. Let's see how we can use this color in our material. Go back to object mode. If we go to the Object Data menu, we will see that in the Vertex Color panel a new entry has been added. This is the color information we created a while ago. Change the name to KeyHolderDirt, and copy it (you can use Ctrl + C as in the desktop environment). Now let's go to the node editor and add an Attribute node. We can find this inside the Input section of the Add menu. Now paste within the Attribute node field the name of the vertex color with Ctrl + V and we are ready to go. The Color output of this node will now work as a texture with the information of the vertex Color.

  6. Now let's add a Mix Color node, which can be found in the Color section of the Add menu. Take the output of the Image Texture node which was plugged in to the Translucent BSDF color input and plug it into the first Color socket of the Color Mix node. In the second socket we will plug the Color output of the Attribute node. Finally, let's change the mixing mode of the Mix node to Multiply, change the factor to 0.300, and plug the Color output to the Translucent node's Color input.

  7. As a last touch, let's add a Gamma node (go to Add | Color) and place it between the Mix node's Color output and the Translucent BSDF node's Color input. We will use this node to lighten the overall color a bit as now it is too dark. Change the Gamma value to 0.600.

  8. Our rubber key holder is ready!

This is how the final node setup should look like, in the following screenshot:

Before we move on to the next recipe, let's add a fast material to both the chain and the keyring. It can be the same material for both. Add a new material and name it KeyHolderChain. Now let's move for a while to the key material. In the node editor select just the two BSDFs and the relative Mix node and press Ctrl + C. Now go again to the KeyHolderChain material and in the node editor erase the default Diffuse BSDF node. Press Ctrl + V and the node that we copied before will be pasted into the node editor. We will just have to link the Mix output to the Material output and we are ready to go.

How it works...

The first part of the creation of this material follows a workflow that we already saw in the previous recipes. However, we mixed two new BSDFs. While we will have a whole chapter to talk about the Glass BSDF, let's have a look at how the Translucent BSDF works.

As we saw, a BSDF is useful to scatter light within an object. The amount of light scattered by the object depends on the color we set in the node. A totally white color will give the highest amount of light scattered through the object, while a black color means no light scattered at all.

When we used the texture and the vertex color as the input for the Translucent BSDF node's color, we not only changed the amount of light scattered, but we also changed the color of the light that scattered through the key holder.

Another important thing we learned in this material is that BSDFs have to be mixed in a different way than colors. While for BSDF we need a Mix Shader node, for the colors we have to use a normal Mix node, exactly like the one that we use in the compositing node editor. You can easily see the difference of the two nodes by the colors of the inputs and outputs. Moreover, the Color Mix node has several ways of mixing the colors.

There's more...

Vertex painting is a technique used in computer graphics to assign color information directly on the vertices of a mesh. It can be used simply to give color over a surface or as a map to achieve different effects when setting up, for instance, a material.

Tip

When you are creating a complex material, it is a good idea to check some passages with a much simpler setup. For example, if we need to check the color of some texture or the effect given by some node, we can use a temporary diffuse node. Plugging, for instance, a texture inside the color input of a Diffuse BSDF and the diffuse output directly in the Material Output node will give us a good idea of what is going on.

See also

 

Creating a leather material for the wallet


Now let's see how we can create a material for a wallet. We want to recreate a smooth, worn eco leather.

Getting ready

First of all we need to add a new material to the wallet. Let's select the wallet mesh, add a new material to it, and name it Wallet.

How to do it…

To create the leather material, we will be following these steps:

  1. Now in the node editor add a Glossy BSDF node and mix it with the default Diffuse BSDF node using a Mix Shader node. Set the mix factor to 0.300 and the Glossy BSDF node's Roughness value to 0.100. Still not so great looking... is it? Let's make this material look a bit better! To do so we are going to use a combination of image textures and procedural textures.

  2. First of all let's add our Texture Coordinate node (Add | Input). Then we need to add a procedural texture. From the Texture section of the Add menu, click on Noise Texture. Link the Vector input to the Generated output of the Texture Coordinate node.

  3. For this material we just need to set the Distortion to 1.000, while for the other values the default settings of the Noise Texture node will be good for our needs, so we can leave them as they are. If you want to see how this texture looks, remember that you can use a Diffuse BSDF node.

  4. We will now be using a second procedural texture to recreate the smaller imperfections of the leather. It will again be a noise texture type. So let's duplicate the one we just created using Shift + D. In this one we need to set the scale to 100.000, while we will set Details and Distortion to 5.000.

  5. Now we need to mix the two procedural textures with a Mix node in mix mode, with a Fac of 0.050. We will be needing the black and white info of the textures, so we need to use the Fac output of the procedural textures, not the Color one. The Noise Texture node with the lower scale value (Scale 5.000) have to be plugged in the first socket, while the Noise Texture node with the higher scale vale (Scale 100.000) in the second socket.

  6. As we will see, this node setup will soon start to be a little bit crowded. It is a good thing to keep things organized, so let's name some nodes. Press the N key to bring out the properties panel. When you have a node selected in this panel, you will get some info and some settings about the node. With the last-created Mix node selected, write PROCEDURAL in the label space. Looking at the node, we can see that now it will not have Mix written on it anymore, but the name we just gave it. Note that you can also change other settings such as the name and the color of the node.

  7. Now let's add an Image Texture node and from the browser, select the scratches.jpeg image. This time as the texture coordinate we will use UV .

  8. To recreate the leather, we will be using another Image Texture node as well. Let's duplicate the previous Image Texture node and press the X button on the node to erase the path and load instead the image called stains.jpeg. Also for this texture we want to use UV coordinates.

  9. As we did for the procedural textures, let's mix these two Image Texture nodes. Plug them into a Mix node, scratches.jpeg in the second socket and stains.jpeg in the first one, Mix mode, Fac 0.20. As we also want to use the black and white information from the image textures, we need to convert them. To do this from the Convertor section of the Add menu, click on RGB to BW and link the Color output of the Image Texture nodes to the input of the node we just added. Let's label this Mix node Images.

  10. Now we want to mix the procedural texture and the image texture. To do this we will again use a Mix node. Plug the Mix node labeled Proc in the first socket and the one labeled Images in the second. For this particular situation we want to change the Mix mode to Add and set the Fac value to 1.000. Let's label the node GlossyCOLOR. Now let's plug the output of this Mix node to the Color input of the Glossy BSDF node. If we change the Diffuse BSDF node's color to a brownish color (RGB 0.150, 0.075, 0.030), we will see that now the wallet material starts to resemble leather, but the reflections are way too strong. To fix this, we need to darken the color of the Glossy BSDF node. Let's add a Gamma node between the GlossyCOLOR Mix node and the Glossy BSDF node and set the value to 1.750. The reflections now will be much weaker. Anyway, the material is still looking really flat and boring.

  11. To give some interesting variation to the surface, we will use the same color we are using for the Glossy BSDF node's color as a bump. Let's add a Bump node (Add | Vector), plug the GlossyCOLOR Mix node into the Height input, and the Vector input of both the Diffuse BSDF and the Glossy BSDF nodes into the Normal output of the Bump node. Now the surface is starting to be more interesting. All we need to do is set the strength to -0.030 .

  12. Let's give a final touch to this leather. We want to have more glossiness variation between the worn and the lesser worn parts of the wallet. Add another Diffuse BSDF node and set the color to RGB 0.500, 0.400, 0.250. This will be the color of the scratches and worn areas. Now let's add a Mix Shader node and plug in the second Shader socket BSDF output of the Diffuse BSDF node and in the first Shader socket plug in the mix between the other Diffuse BSDF and Glossy BSDF nodes BSDF outputs. This time we will not set manually the Fac value. Instead let's plug in it the output of the GlossyCOLOR Mix node. Finally plug the output of the Mix Shader node into the Material Output node and we are ready to go!

Here is how the final node setup will look like, in the following screenshot:

For the stitches it is enough to use a diffuse material with an RGB value of 0.650, 0.400, 0.250. We will name the material Stitches .

How it works...

In this leather material we can really start to see the power of nodes. First we created the map of the color by mixing different procedural and image textures. Then we used the very same node group, or part of them for the bump input and to mix two different BSDFs.

When we converted the two image textures to black and white color information, we were able to use it as a factor input for the last Mix node, telling Cycles how much we wanted of each one of the BSDF inputs. Precisely, black areas received influence from the first socket (the leather) and white areas from the second one (the material inside the scratches).

In this situation the scratches material was made using just a Diffuse BSDF node, but we could have created another big and really complex node setup if needed. As anticipated in the introduction, this kind of operation can be done in reality any number of times we want, making the possibilities virtually endless.

There's more...

A procedural texture is a computer-generated image that tries to resemble different natural patterns using functions, for instance, fractal noise and turbulence. These functions try in a different way to represent the "randomness" of nature. Procedural textures are set with different numerical values and can be seamlessly mapped over surfaces, even without the usage of UV maps.

 

Using the Cycles camera's depth of field


Creating images using a 3D program is often all about imitating reality. When we take a picture, something that often occurs is that some of the objects are out of focus. Such an effect is called depth of field (DOF) and is what we are going to recreate in this recipe.

Getting ready

Our first scene in Cycles is almost ready. However, we can still do a couple of things to make it look even more realistic. We will now see how to add a nice DOF effect.

How to do it...

To recreate the DOF effect in Cycles, let's follow these steps:

  1. Let's jump in now to our scene in Blender and select the camera. First of all we need to set the point in the scene where we want to keep the focus. To do this we need to select the camera and go to the Object Data menu (the one with the little camera icon).

  2. From here we need to activate the Limits option in the Display panel. In the viewport we will see that the camera now has a line going towards where it is looking and a yellow cross at the beginning. This cross represents the focus point.

  3. To set the focus point where we want it, we need to change the Distance value in the Depth of Field panel. We want the keyholder to be the focus point of the scene, so let's set the Distance value to 16. The yellow cross will now be placed over the key holder.

  4. For the DOF intensity, let's use Radius with a value of 0.0500. We do not want an effect that is too strong. For this particular scene we will simulate a round iris so that the default values are ok. Now we have a nice DOF effect in our scene that helps add realism to it. This is how the camera settings should look like if we did everything correctly in the following screenshot:

How it works...

With Blender Internal, the only way of adding this kind of effect is in compositing. Even if this method is still possible—also in Cycles—we now have another way of achieving the DOF effect.

Cycles has a DOF system built inside the camera. This means that now we dispose of a real ray-traced DOF effect which is much more accurate than the previous one. It is necessary to remind you that this new method also has some drawbacks. For instance, we will be dealing with render passes, and we will see that DOF generates a big amount of noise around edges, which can make it difficult sometimes to composite the scene. Another drawback is that once we render the image, we will not be able to change the DOF until we render the image again. This can be a problem especially for animations.

Anyway, apart from these two aspects the method of achieving DOF is fast and the final quality is really high.

There's more...

Another method of setting the focus point is to use an object. Right above the Distance value there is a field where you can put the name of the object on which you want to set the focus. The yellow cross will now automatically follow this object. It is important to remember that this doesn't mean that the camera will follow this object, just the distance of the focus.

On the left of where we set the distance value for the focus of the camera, there are the settings for the DOF. We can use two methods to set the intensity of the DOF: Radius and F/stop (focus stop). Bigger values for the radius will mean stronger DOF. On the contrary, with the focus stop method we need to lower the value to have a stronger DOF.

Right under the intensity value there are the iris settings, which will determine the shape and rotation of the bokeh effect. We can decide what shape and rotation the latter will have. If we want to have a circle iris it is enough to leave the Blade value to 0.

 

Setting the Cycles render parameters


In this recipe we are going to learn how to set the parameters for the final render. We will learn how to make our image noise-free and how to set the parameters in order to optimize our render times as best as we can, without losing quality.

Getting ready

We are getting closer to the conclusion of our first scene in Cycles. It may sound strange but even if we have already set up materials, lighting, and DOF, we still didn't actually render anything yet by pressing the render button. We only looked at the scene through the real-time viewport! So we can see how powerful the Cycles real-time viewport is. But the time for the final render has come, so it's time to talk about render settings.

How to do it…

I thought that a description of each render setting would be better than a mere list of the values I used in this scene. In this way, we can understand better how and why we are doing something like this. Anyway, the following is a screenshot of the render settings used for this render:

How it works...

Let's jump to the Render panel. Many of the settings are the same as they were in BI, so we will skip the Dimensions, Stamp, and Output panels. We already saw in the first part of the chapter how to set up the settings concerning the device to use, CPU or GPU.

Let's have a look instead at the Sampling panel. Here lies some really important settings for our render. On the right we can read Samples. Every time a light path in the scene hits a surface, Cycles will compute a new sample for that pixel. The higher the number of samples, the less noise the render will have. The setting of this value will depend on the scene. In general, we will need to keep increasing it till the noise disappears, or at least will be at an acceptable level.

We can see that there is a Render and a Preview value. The first is the number of samples that Cycles will compute for the final render, while the second represents how many samples will be computed in the real-time viewport. Let's set the Render value to 750 for this scene.

Note

The seed value is really important for animation as it will avoid the noise to be static. We will talk again about this in Chapter 7, Car Rendering in Cycles.

The clamp value is a setting that will help us reduce fireflies in our scene. A firefly, also known as burned pixels, is a mistake made by the engine while calculating areas with strong light. They will appear as white pixels with totally crazy RGB values.

There are many ways to avoid fireflies, but the fireflies will still occur from time to time. Clamp will help us reduce them at the cost of the accuracy of the scene. This setting will indeed clamp out the highlights over a certain value to avoid getting burned pixels. Anyway, if set a value too high, clamp can also cut out some highlights that we would like to have in the scene. Leaving this value as 0 will disable clamping, while low values will mean stronger clamping of light and higher value will mean less clamping. Usually it is not good to go below values like 3, as by doing so it may compromise the lighting of the scene. For this particular scene we won't be needing clamp anyway, so we can leave the value to 0.

We will learn in the next part of this chapter about the non-progressive integrator.

Now let's move to the Light Paths panel. Here we will find the settings about the precision of the rendering. As for the samples, it is good that the settings will change depending on the scene. Each setting that you see represent the number of light path bounces that we want to have in the scene. In general, the higher the number of bounces the more precise the render will be, but it will also increase both render time and noise. It is important to find the right balance. The number of bounces needed depends on the level of complexity of the materials in the scene. For instance, a complex glass material could require a high-transparency bounces number in order to render correctly.

We also have the possibility of switching off shadows and/or caustics computation. While it is really hard to find a scene where shadows are not needed, if not in particular situations, we will see especially in Chapter 2, Creating Different Glass Materials in Cycles, that sometimes caustics can generate a lot of noise, and it is a good idea to turn them off, especially because it is possible to fake them.

Finally, the Filter Glossy value can help us reduce noise on glossy surfaces in some situations. Of course nothing comes for free and as for the clamp, filter glossy will decrease the accuracy of the image. For this reason it is better to use it only if strictly necessary.

You will also see at the top of this panel a cascade menu with a couple of presets. You can also add your own presets, but as I said every scene is a story on its own.

In general, it is quite hard to find scenes that will require bounce numbers higher than 16 (and 8 for the min values). This is a quite safe area that will be capable of rendering the majority of scenes without any lack in quality and precision. On the other hand, it could also be too much for other scenes. However, a method that I like to use is to set the Full Global Illumination preset and make a render. Then I will start to lower down each value until I see that there is a little change in the image. It is important to check areas with transparencies, reflections, and caustics, as they are the first to change depending on the settings.

Moving down we have the settings regarding Motion Blur, which we will see in depth in Chapter 7, Car Rendering in Cycles.

In the Film panel, we can find settings regarding the exposure, the Anti-Aliasing algorithm, and the option to make the background transparent. Making the background transparent will preserve any lighting or reflections coming from it. It will just be rendered as an alpha channel.

Another important panel is Performance. Here we can find some settings which, if correctly set up, can speed up our render times. First of all let's talk about tiles. To save up memory and take advantage of multithreading, Cycles will divide the render into smaller tiles. Here it is very important what we use to render. In case of GPU the tile size should be bigger, around 256 x 256. On the other hand, when using a CPU we should make tiles smaller. Depending on the number of cores we have, good values are 32 x 32 or 64 x 64. Anyway, you will have to test it and see which is the best setting for your computer. Keep in mind that this setting can really change render times. We can also decide in what order we want the tiles to be rendered.

The Progressive Refine option will render the image in a single big tile. The render will be slower, but it can be stopped when we believe the noise level is acceptable and we can see the overall look of the image from the beginning.

The Save Buffer option will allow Cycles to write some information on the hard drive instead of the RAM. This will allow us to save some memory and could come in very handy in some big scene especially when using the GPU for the rendering.

On the right side of the panel, we will find options concerning the Acceleration Structure. When Cycles starts the render, a bounding volume hierarchy (BVH) of the scene will be built. Without going too deeply into technical details, BVH can be defined as the geometrical structure of the scene. Even when we will be using GPU to render, this operation will be computed by CPU and there are some different ways BVH can be built.

First of all, we can decide between a static or dynamic BVH build. The first one will require a complete reconstruction of the BVH for each rendering, but the sampling phase of the render will be faster. On the other hand, the dynamic one will allow faster BVH updates at the cost of sampling speed.

The Spatial Split option works in a similar way. When this option is activated, the BVH building will be slower, but the sampling will be faster.

Another interesting option is Cache BVH. This option will allow Cycles to cache the BVH on the RAM so that it will not need to compute it again for the next render. It is important to keep in mind anyway that this will work only if no mesh in the scene is deformed. A good kind of scene to use this option is when the only thing which is animated is the camera.

Tip

A good thing to keep in mind is that Blender has a really good tips pop-up system to help understand the settings. Just hover the cursor over an option or a button and after a while, a pop up with a brief description will pop up.

This is the conclusion of the first chapter. If you encountered any difficulty in following some part of the recipes, you will find a ready version of the scene in the blend folder named keys.blend which is available in the code bundle of this book.

About the Authors
  • Bernardo Iraci

    Bernardo Iraci was born in Livorno, Italy in 1985. He followed a standard education career until he graduated in Economics in 2009. He always had a great passion for computers, especially gaming. During the latter part of his studies, he also developed a passion for 3D graphics, and this soon became the main focus of his career. It was at this time that he came to understand that his passion was the most important thing to pursue, more important than even attending university. Even though Bernardo later participated in various online courses teaching the different aspects of computer graphics, he has been largely self-taught. In 2010, he moved to Warsaw, Poland, where he was finally able to start working full-time in computer graphics as a 3D generalist in the field of movies VFX and advertisments. He also started work as a freelancer. Bernardo constantly works to improve his skills and knowledge about computer graphics and thinks that this is the only way to keep pace with this field. When he is not busy with graphics, he likes to travel, watch movies, and play the guitar.

    Browse publications by this author
  • Ton Roosendaal
Latest Reviews (4 reviews total)
leicht verständlich, gut zum Selbststudium
While the book itself isn't really for the sole beginners despite the author claiming otherwise it is still worth every penny and it contains abundance of useful information, tips and tricks that both intermediate and advanced users would find really helpful and essential for their workflow rendering in Cycles.
There is some great information in this book, but the many errors in the text make this a nightmare to use as a how-to book. I eventually gave up in frustration. It could be a helpful book, but it needs some serious proofreading and re-editing. I started to send some of the errors into the errata page but quickly realized it was turning into a full-time job. I couldn't recommend this book to anyone who wasn't already a complete expert in Blender, but then of course you wouldn't need the book anyway.
Blender Cycles: Lighting and Rendering Cookbook - Second Edition
Unlock this book and the full library FREE for 7 days
Start now