Blender 3D: Noob to Pro/A Glass Material in Cycles
Applicable Blender version: 2.68. |
This tutorial will redo the previous Ray Tracing lesson, this time using Cycles rendering. Start with a copy of the same document you created last time; we will keep the same geometry, but redo all the materials, and then you can compare the final results to see how the different renderers perform.
Open the ray-tracing document. Switch the renderer to Cycles. We previously defined two materials: the world background with the “magic” texture, and the glass for the cubes. So we will need to redo these.
For all but the most basic plain diffuse materials, Cycles requires you to use the Node Editor. You should have done the prior introduction to this; please review that, if not. Cycles material nodes are not the same as Blender Internal material nodes; but the basic mechanics of node editing are the same.
The Magic Sky
editLet’s try fixing the background material first. Go to the World context in the Properties window. It should look something like at right. What happened to all the world settings? Nearly all of them have disappeared!
But see that big “Use Nodes” button? It’s big so that you will find it hard to miss. Click it.
OK! Now there are a few more settings, but still not much. For all the fun stuff, we must go into the Node Editor.
You probably have a Timeline window across the bottom of your Blender screen layout. Change the window type to Node Editor , and increase its height. (Or add a new window if you don’t already have one, and make it a Node Editor.) In its header, next to the menu titles, you should see a group of 3 icons indicating what type of nodes you want to edit: if you hover over them, from left to right, you should see tooltips identifying them as respectively “shader nodes” (i.e. Cycles materials), “compositing nodes” and “texture nodes”. It is the “shader nodes” we want.
Cycles doesn’t use the Texture Node Editor. It may be confusing to see this mode of the Node Editor still available with Cycles chosen as the renderer, but don’t bother using it. All setup of textures in Cycles is done within the Shader/Material Node Editor. |
With shader nodes selected, you will see another pair of icons appear immediately to the right of these three: these indicate whether to edit shader nodes for a selected Object, or for the World. It is the World that we want.
Soon as you select the World shader, the following should appear in the Node Editor window. Note the special “Background” and “World Output” nodes: you must have these in the World shader, but note that “Color” input terminal on the Background node? That’s just itching to have something plugged into it.
Bring up the menu to add a node, with SHIFT + A . Look for the Texture submenu, which should look like at right. Select the “Magic Texture” item.
This will add a new node representing the texture; connect its “Color” output to the “Color” input on the Background node, like at right.
Now if you hit F12 to render, you should see your new magic World background.
Here Comes The Glass
editMake sure the cubes are selected in the 3D view. Go to the Materials context in the Properties window. As before, you will see very few settings, and a big “Use Nodes” button. Click it.
In the Node Editor, remember there are two icons for selecting what type of shader/material nodes to edit, the Object one and the World one? Click the Object one this time.
As before, you will see an initial default node setup, like at right.
This time, there is only one node that needs to be present for the node setup to work correctly, and that is the Material Output node. Click with RMB on the node titled “Diffuse BSDF”, and press DEL to get rid of it.
Now bring up the Add SHIFT + A menu, and this time look for the Shader submenu. We will need three items from here, so add them one at a time:
- A Glossy BSDF to give the shiny surface (note the default Roughness setting in this node is 0.2, set it to zero)
- A Refraction BSDF to give the effect of light refracting through the transparent material, and
- A Mix Shader to combine the two.
Ah, but how do we combine the two? Remember the Fresnel factor we talked about in the Blender Internal tutorial? Well, in Cycles, there’s a node for that!
In the Add SHIFT + A menu, bring up the Input submenu. In there, you will see a Fresnel node type. Add one of these. You will see it starts with a default IOR (Index of Refraction) value of 1.45, which is about right for glass.
Finally, connect together your little collection of nodes like this. See how the Fresnel factor controls the mixing proportion of the Glossy and Refraction shaders? A larger input factor to the Mix shader means a higher proportion of its second (lower) shader input, while a smaller factor gives a higher proportion of its first (upper) shader input. The higher output Fresnel factor corresponds to the regions closer to the edges of the object, where you want more reflection, while the lower value corresponds to the interior regions, where you want more transparency.
And finally finally, hit F12 to see what the result looks like.
Does it look grainy, and not as clear as this? Increase the number of samples in the Sampling panel in the Render context, as you learned to do in the previous tutorial. The picture here was done with 500 samples. |
.
Why not just use the Glass BSDF? You might have seen this in the Add Shader menu, above. However, this doesn’t seem to produce the right effect: it seems little different to the Refraction BSDF, without providing much in the way of glossy reflections. |
Adjustable Refraction
editYou may have noticed that the above collection of nodes includes two different fields labelled “IOR”: the one on the Fresnel node, and the one on the Refraction BSDF. The former governs the transition between transparency and reflectivity, while the latter governs the actual refraction through the material. In the real world, the two would always be the same, since they are the same physical quantity.
With the right IOR, this same node setup can be used to represent other transparent materials. Instead of having to set the value in two places, why not just set it in one?
To do this, add SHIFT + A another node, from the Input submenu, of type Value. This will feed a fixed value that you specify into any number of output terminals. Connect its Value output to the two IOR inputs, on the Fresnel and Refraction BSDF nodes. Here I have set its value to 1.45, which is a suitable value for glass.
A Reusable Custom Shader
editWhat if you wanted to have multiple transparent materials in a document? Would you need to go through all the above setup every single time?
Naturally you wouldn’t. Instead, you can define a custom node group, and insert that into a Node Editor setup wherever you want, as many times as you want.
Start with the node setup as in the previous screen shot. Select RMB the Value node supplying the IOR value, and DEL ete it. Now look at the remaining four nodes, the Fresnel input and the three shader nodes (apart from the material output)? Select these, and only these, in any of the usual ways: press A once or twice to deselect everything, then RMB on the first node and SHIFT + RMB on the rest, or drag a B ox selection around the desired nodes.
Now, with these nodes selected, select “Make Group” from the “Node” menu, or use the keyboard shortcut CTRL + G . Also press N to bring up the Properties shelf at the right side of the Node Editor window. The result should look like at right. Notice a couple of things:
- The greenish background indicates you are editing a node group, not the entire node setup
- The blocks with yellow headers, labelled “Group Input” and “Group Output”: these define the input and output terminals for the entire node group: inputs to the group appear as outputs on the Group Input block, and outputs from the group appear as inputs to the Group Output block. Any terminals within the group not connected to these will not be visible outside the group.
You can press TAB to switch out of editing the node group and back into editing the entire node setup, where you will see your group appear as a single block entitled “NodeGroup”. Try this if you want to have a look, then press TAB to get back into editing the group again, because we haven’t finished setting it up yet.
First of all, we need an input to specify the IOR value. Click on the IOR input terminal on the Fresnel node, and drag to the right edge of the Group Input node. Blender should automatically create an output terminal named “IOR” on the Group Input node, with a wire running to the Fresnel IOR input.
Now click on this Group Input IOR terminal, and drag another wire to the IOR input on the Refraction BSDF node.
Glass often has a colour. This colour affects light passing through the material, while glossy reflections remain uncoloured.
To create a colour input terminal for our node group, just drag from the “Color” input terminal on the Refraction BSDF node to the right edge of the Group Input node; as before, Blender will automatically add a new Group Input terminal and connection.
Now press TAB to finish editing your custom node group. This will take you back to the overall node setup, with your custom node still selected. Its name will be shown in the Properties panel in the Properties shelf at the right; change this from the default “NodeGroup” to something more meaningful, like “Custom Glass”.
And now you can add back the input Value node you deleted, to supply a value to the IOR terminal. And similarly you can add an RGB node to feed into the glass colour. Or, since each value only needs to feed one input terminal, you can type them directly into the unconnected inputs on your Custom Glass node.
And furthermore, your custom node is now present in the Add Group menu, ready for you to insert somewhere else, in this or another node setup.
Note that the node definition itself is not duplicated when you insert another instance of your custom node. Each instance operates on its own separate input values and produces its own corresponding separate output values, but any changes you may subsequently make to the internal definition of the node group will automatically take effect everywhere you’ve already used it.