Using drivers with nodes

There is one moment in node tree, created to separate the sides of the planet model by “day” and “night” – when the position of light source changes its new coordinates every time needs to re-specify manually in Value nodes. It is very inconvenient while setting the scene. To eliminate this fault Blender “drivers” system can be used.

Using drivers in node system
Using drivers in node system

Lets make a simple scene showing the separation of the planet sides. Create a planet (sphere). The light source (plane) locate at 5,0,0. Create a material with “day” and “night” separation, append it to planet.

Scene with planet, separated by "day" and "night"
Scene with planet, separated by “day” and “night”

Simplify nodes tree packing what we do not need during setup into the groups.

  1. Select the desired nodes
    1. ctrl+G
"Mixing Day and Night" and "Day Night Textures" node groups
“Mixing Day and Night” and “Day Night Textures” node groups

There are only Value nodes with the coordinates of the light source outside groups. We will setup drivers to them.

Drivers – a Blender mechanism that uses properties, numbers, transformations, and scripts, to control the values of properties. In simple – drivers proceed dependences some object properties from properties of other objects. In this case we need to associate values from Value nodes in planet material with lighting plane coordinates.

To install driver to the X lighting source coordinate Value node:

  1. Click the right mouse button on the numerical value of Value node for X coordinate
    1. Select Add Driver
Adding driver to Value node
Adding driver to Value node

The value will painted in purple.

  1. Open the Graph Editor
    1. In its menu set Mode to Drivers

If node with driver is selected, the Graph Editor displays the name and path of the controlled value, curve and Drivers tab in the N-bar.

Setting driver
Setting driver

Pay attention to Drivers tab. First we need to configure driver type, regulated with Type parameter. Driver type is a formula that calculates driver output value. There are several variants:

  • Maximum Value
  • Minimum Value
  • Scripted Expression – output value calculates by the expression on the scripting language
  • Sum Values
  • Average Values

These formulas, except Scripted Expression, are needed in order to handle multiple input values by driver. For example, if single object’s position depends on the positions of several other objects. Through a driver that handles multiple input location values, one result can be calculated. A Scripted Expression type you can set to get the output values from scripting language Pithon – this type is used, if other types are not enough.

In our case, we have one input value – X coordinate of the light source. Therefore, we can choose any type of driver, except Scripted Expression. For example – Sum Values. The sum of single number always equal to the same number.

  1. In Graph Editor
    1. In N-panel
      1. Drivers tab
        1. set Type to Sum Values

Next, pay attention to created by default variable named “var”. This variable is the actual input value, which handles by driver. It also has a type:

  • Distance – the distance between two objects
  • Rotation Difference – the difference between the rotation angles of two objects
  • Transform Channel – location data of the object
  • Single Property – value of any object parameter, defined by the scripting language

All types, except Single Property, are used to obtain values that required more often. Like driver type, Single Property can be used to get any value of the object using the Pithon language. In our case we need to get the X coordinate of the light source. Therefore, we select the Transform Channel type.

In the Object/Bone field specify the object – the source of the input value. In our case – a light plane. It is necessary to specify the desired type of coordinate:

  1. In Graph Editor
    1. In N-panel
      1. Drivers tab
        1. “var” variable
          1. Set Type to Transform Channel
          2. In the Object/Bone field specify the light plane
            1. Set Type to X Location
        2. click the Update Dependencies – upgrade the relationship, ie, apply the specified values

Driver that connects the X coordinate of the light source and the Value node for this coordinate in the planet node tree is created and configured. Now if we try to move the light plane by its X coordinate from different sides of the planet, we can see that “day” and “night” textures changes their places.

In the same way we need to create and configure the two other drivers for the two remaining coordinates.

  1. Click the right mouse button on the numerical value of Value node for Y coordinate
    1. Add Driver
    2. Select node
      1. In Graph Editor
        1. In Drivers tab
          1. set Type to Sum Values
          2. For “var” variable
            1. set Type to Transform Channel
            2. In the Object/Bone field specify the light plane
              1. set Type to Y Location
          3. Press the Update Dependencies
  2. Click the right mouse button on the numerical value of Value node for Z coordinate
    1. Add Driver
    2. Select node
      1. In Graph Editor
        1. In Drivers tab
          1. set Type to Sum Values
          2. For “var” variable
            1. set Type to Transform Channel
            2. In the Object/Bone field specify the light plane
              1. set Type to Z Location
          3. Press the Update Dependencies

All three drivers for three coordinates of the light source are configured. Now we can move the light plane to any place – “day” and “night” textures of the planet always will be mapped correctly.

"day" and "night" changing with drivers usage
“day” and “night” changing with drivers usage