Creating node groups

Single nodes (shaders, textures, input, or whatever) can be grouped together, and this is probably one of the best ways to organize our workflow.

Thanks to node groups, it's easy to store complex materials in ready-to-use libraries. It's possible to share or reuse them in other files, and they can also be used to build handy shader interfaces for easier tweaking of material properties.

Getting ready

Start Blender and open the 9931OS_02_interface.blend file.

How to do it...

Let's go to the Node Editor window directly:

  1. Now box-select (place the mouse cursor in the Node Editor window, press B, and click and drag a box to include the nodes you want to select) the Diffuse BSDF and the Glossy BSDF nodes, as shown in this screenshot:
    How to do it...

    Box-selecting two nodes

  2. Press Ctrl + G on the keyboard. The background of Node Editor changes, showing that now we are in Edit Mode inside a group. In fact, there are two selected nodes with a Group Input node and a Group Output node. Also, the Surface subpanel under the Material window has changed, and in the Node Editor in the Properties panel, a new Interface tab has appeared, as shown in the following screenshot:
    How to do it...

    The appearance of the just created and open for editing node group inside the Node Editor window

  3. Because the two shaders were already connected to Mix Shader (which, in this case, we left out of the group on purpose), both the Diffuse BSDF and the Glossy BSDF outputs are now connected to two BSDF sockets automatically created on the Group Output node.
  4. As for every Edit Mode in Blender, by pressing the Tab key, we go out of Edit Mode, closing the node group, as shown in this screenshot:
    How to do it...

    The closed node group

    The node group is still showing the two BSDF outputs (actually connected to the input sockets of the Mix Shader node), the name data block, and the fake user button (F). This last one is the same as in Blender Internal. It prevents the user count from ever becoming zero, and therefore prevents the deletion of any non-assigned material. When you save the file and/or close Blender by assigning the fake user to a non-assigned material, you are sure that it will not be deleted. This is particularly handy when you are building a material library.

  5. Now click on the name data block of the node group and change the default name, NodeGroup, to something else. I wrote BasicShader.
  6. Press Tab and go to Edit Mode again. Click on the only empty socket in the Group Input node and drag a link to the Color input socket of the Diffuse BSDF node. The empty socket now connected to the Diffuse BSDF node has changed and is now indicated as Color. Moreover, a new empty socket has appeared on the Group Input node, as shown in the following screenshot:
    How to do it...

    Editing the node group by connecting inner sockets to expose them

  7. Repeat the previous step for the new empty input socket and connect it to the Color input socket of the Glossy BSDF node. Again, a new empty socket has appeared, ready to be connected to something else.
  8. Now look at the Properties panel to the right. The Interface subpanel is reflecting what we are doing in the Node Editor. In fact, in the little Input window, there are two Color sockets, and we can double-click to rename them (Color1 and Color2 in our case). To remove a socket, just click on the name in the Properties panel, and then click on the X icon in the bottom Name slot, as shown in this screenshot:
    How to do it...

    Renaming and ordering the new input sockets through the Interface subpanel in the Properties side-panel

  9. Repeat the process to create input sockets for other properties of the Diffuse BSDF and Glossy BSDF nodes. Then press Tab to exit Edit Mode, which is also shown in the following screenshot for your reference:
    How to do it...

    The appearance of the inner connections in the open node group and as exposed input sockets in the closed node group

    Here, we get a simple interface for the BasicShader node group, and as you can see in the following screenshot, the exposed values can be tweaked. Also, the properties are driven by textures exactly as in other nodes:

    How to do it...

    The BasicShader node group put to use

  10. Press Tab again to go back to Edit Mode. Move the mouse cursor into the node and press Shift + A to add a Mix Shader node to the group (press Shift + A and navigate to Shader | Mix Shader).
  11. Connect the Diffuse BSDF and the Glossy BSDF shaders to the new Mix Shader node and its output to one of the BSDF sockets. Delete the other node by clicking on the X icon in the Properties panel. Connect the empty socket of the Group Input node to the Fac input socket of the Mix Shader node, as shown in this screenshot:
    How to do it...

    Adding a Mix Shader node inside the node group and one more exposed socket

  12. Exit Edit Mode and select the outer Mix Shader node. Press Alt + D (this shortcut removes a node from a network, leaving the connection untouched) to disconnect it and then delete it, or simply press Ctrl + X to delete it, leaving the connection untouched. This is shown in the following screenshot:
    How to do it...

    The final interface of the BasicShader node group

How it works...

I think you get the picture. Basically, almost any input or output socket of the nodes wrapped inside a group can be connected to the outside of the node group to be tweaked.

The good thing about a node group is that you can make instances of that node (by pressing Shift + D). Note that when you modify the inner structure of a node group, the modifications get reflected in all the group instances, but the outer (exposed) values on the node group interface are local for each instance and can be individually tweaked.

Every newly created node group is available in both the Add menu (press Shift + A) and in the slots in the Material window of the Properties panel, under the item Group, to be added on the fly to the network.

To remove a node group, select it and press Alt + G. This will break the node envelope but keep the content intact and still connected.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.75.117