Trying to figure out the sun_direction vector
If there is anybody who knows how to get the right vector for the sun direction please let me know.
if i look in the documentation it should be in
nodes[“Sky Texture”].sun_direction and be saved in 3 vectors
but if i check the console it only shows me one vector
from -1 to 1.
I dont get it

also you can not access the sun_direction via nodes.
the vector you can plug in is only the position, rotation and scale for the whole sky texture.
if you rotate it it will change the rotation / sun position but it will not change the color.

it would make more sense if the vector would change the sun direction instead of turning the horizon upside down.

what i wanted to do is to connect the Sun_direction (object) to the Sun_direction (Sky texture)
like it is in Blender internal when you turn on sky and atmosphere.
but in cycles it doesnt work that way

i was trying to connect it via drivers and it works (a little) but the sky texture doesnt respond as expected.

any help would be nice!

The easy way, find the values in the matrix!
Run script!

import bpy

if bpy.context.object.type == “LAMP”:
if == “SUN”:
lampob = bpy.context.object
lamp =“Sun”, “SUN”)
lampob =“SunRig”, lamp)
mw = [i[:] for i in bpy.context.object.matrix_world[:]]
skynodes = [node for node in[:] if node.type == “TEX_SKY”]
if len(skynodes) < 1:
shader =“ShaderNodeTexSky”)
bgnode = [node for node in[:] if node.type == “BACKGROUND”][0][‘Color’], bgnode.inputs[‘Color’])
shader = skynodes[0]
shader.sun_direction[0] = mw[0][2]
shader.sun_direction[1] = mw[1][2]
shader.sun_direction[2] = mw[2][2]

print(“The world have not nodes!”)

The easiest way to do what you want is toinstall the ‘Sun Position’ addon located here:…/3D_interaction/Sun_Position
It allows you to bind Cycles’ sky texture to a sun lamp and/or objects and animate the whole
thing by applying keyframing to the UI values.

Additionally, the nodes[“Sky Texture”].sun_direction vector is correct as it is a normalized 3D vector.
Based on a ‘unit sphere’, the vector is meant to indicate direction. To project a sun object 20 units
into Blender’s world space, you need only to multiply the sun_direction vector by a radius value,
i.e., object_location = sun_direction * 20.

Following is a simple test that should be run from the python console. It allows you
to place a sphere in the same direction as the sun in the sky texture. Here’s the setup:
| 1. Select Cycles as the renderer.
| 2. Make sure a Sky Texture exists called ‘Sky Texture’ in the World panel.
| 3. Move your camera to the world center, location (0,0,0).
| 4. After running the code below, do the following:
| a. right click on the camera to select it,
| b. then <Shift> right-click on the sphere that was created.
| c. Next, press <Ctrl>T and select ‘Track to constraint’.
| This will keep the camera pointing towards the sphere to
| verify the sun position from the viewport.
| 5. At this point you can keep running the set_sun_position function
| from the console changing any of the values to update the texture rotation
| and the object location.

import bpy
import math

def degToRad(angleDeg):
    return (pi * angleDeg / 180.0)

def set_sun_position(elevation, azimuth, radius):
    sd =['World'].node_tree.nodes['Sky Texture'].sun_direction
    theta = pi / 2 - degToRad(elevation)
    phi = degToRad(-azimuth)
    sd.x = sin(phi) * sin(-theta)
    sd.y = sin(theta) * cos(phi)
    sd.z = cos(theta)
    return sd * radius
bpy.ops.mesh.primitive_uv_sphere_add(segments=32, ring_count=16, size=1.0, location=(10, 0, 0))
obj = bpy.context.active_object

# Set sun elevation to 30 degrees and azimuth 90 with sun object at
# a distance of 20 blender units from the world center.
obj.location = set_sun_position(30, 90, 20)