5
$\begingroup$

More generally, using the Blackbody node as an example, how can I access the current numerical values of inputs, parameters/settings and outputs of cycles nodes, through the api or by other means?

In this particular case I want to compare the conversion values calculated by the Blackbody node with other color temperature -> RGB algorithms. But I'm interested in the more general situation. If this is not possible, shouldn't it be, and will it be in the future?

$\endgroup$
2
$\begingroup$

Example for the compositor node which is present by default:

import bpy

scene = bpy.context.scene
scene.use_nodes = True

nt = scene.node_tree

#get the node
node = nt.nodes['Composite']

#access by string key in 2.69
input = node.inputs['Alpha'].default_value = 0.5

#older versions of blender might require
#access by index
for index, input in enumerate(node.inputs):
    if input.name == "Alpha":
        print(index)
        break

#link    
output = nt.nodes['Render Layers'].outputs['Alpha']
nt.links.new(input, output)

You can hover over the input with python tooltips enabled: hover python tooltip

Using python it is only possible to setup the tree and its parameters.

Via OSL you can implement your own shaders. Enable Open Shading Language in the render menu, add a script node and see Text Editor -> Templates -> Open Shading Language

Template Temperature To RGB

shader temperature_to_rgb(
    float Kelvin = 1200.0,
    output color Color = 0.8)
{   
    /* Kelvin to RGB */
    Color = blackbody(Kelvin);
}

As you can see blackbody is an inbuilt function of the standard library.

$\endgroup$
5
  • $\begingroup$ Perhaps I'm missing something, but I thought the OP was asking how to view the values of a node socket? $\endgroup$
    – gandalf3
    Feb 22 '14 at 0:29
  • $\begingroup$ Thanks for this. I had more or less figured out this much. By "using python it is only possible to setup the tree and its parameters" I take it that accessing the actual current values of nodes (e.g. the RGB values from the Blackbody node output) is not possible. Why isn't this data exposed to python? $\endgroup$
    – xerula
    Feb 22 '14 at 0:31
  • $\begingroup$ Because python is quite slow. As written above you can write and use your own OSL shaders in cycles. $\endgroup$ Feb 22 '14 at 11:50
  • $\begingroup$ OK, thanks. It surprises me that "too slow" is a reason for not being able to simply read off the current values of a node output of something like the blackbody node, which apparently just does some straightforward math / lookup. But I have further questions about the behavior of the blackbody node and will ask about this separately. $\endgroup$
    – xerula
    Feb 22 '14 at 17:32
  • $\begingroup$ I might be completely wrong, but perhaps the reason for this is the RGB values of the blackbody node are actually computed by cycles at rendertime? $\endgroup$
    – gandalf3
    Feb 27 '14 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.