Blender’s Cycles rendering engine includes a nice tool for generating an HDRI sky that will illuminate a scene with a good color approximation of the Earth’s atmosphere. A similar feature in Blender’s internal rendering engine links the appearance of the sky to the direction of a Sun lamp, thus providing an intuitive way to set the properties of the sky directly in the 3D viewport, while maintaining consistency with shadows cast by the sun lamp. Maintaining this consistency mechanically requires a little more thought in Cycles.

I dug around for ages trying to figure out how to get the position of a Sun lamp into the Vector input of a Sky Texture node. It turns out that the Vector input is actually for texture coordinates, not the position of the Sun. It initially appeared that the only way of adjusting the sun position was manually dragging the trackball above the turbidity parameter. The trick is to add a driver to the trackball.

Blender Node Editor

If you’re familiar with Blender’s Drivers, the rest might be obvious. In essence, you add three drivers, one for each axis of the sun’s direction using the world space location of your lamp as an input. The setup is show below. followed by a step-by-step description of the procedure.

Blender Graph Editor

  • Add the driver by right-clicking on the trackball and selecting Add Driver > Manually Create Later.
  • Next switch to the Graph Editor and change the F-Curve dropdown menu to the Drivers selection; you’ll also have to uncheck the filter that narrows the view to the current selection (the button that looks like a mouse cursor).
  • The default driver curve is fine and you can leave it alone.
  • Show the properties shelf in the graph editor (press the N key) and switch to the Drivers tab.
  • Under Type, select ‘sum values’, which will sum all the values of the defined variables.
  • Under the variable definition, select your Sun lamp in the Object field. For the variable’s Type select the X Location, which you want in World Space.
  • Repeat these steps for each of the other axes paying careful attention to match the X position of the lamp to the X Sun Direction channel of the driver, Y for Y, and Z for Z.