Cycles Custom Float Node?

Hi All,

I have been playing around with the CustomNodeType template that ships with Blender. I have simplified the code, and attached it in the BLEND file, so the node has only one value, a default_value of a float type. I have modified the poll() function so the node category shows up in the Cycles material menu. I can get my node to appear in the Cycles material node tree but when I connect the value to a known float input it does not work.

For instance, in this image I have a custom node providing the value 0.0 to the roughness of a Glossy shader. The render output should be a perfectly mirrored sphere but instead the Cycles node is ignoring my float input and using the internal roughness value of 1.0 to produce a matte like finish instead.

Does anyone know how to get other node tree types to accept values from custom nodes?


With pynodes you can’t create usable nodes for cycles, BI or compositor (even for something so simple). they are meant to hook up already compiled C code or to give addon’s and external render engines access to blender’s node interface.

Got it, you have to set the default_value directly instead of just calling node.update().

    def update(self):
        #Review linked outputs.
            out = self.outputs["Float"]
            can_continue = True
            can_continue = False
        if can_continue:
            if out.is_linked:
                # I am an ouput node that is linked, try to update my link.
                for o in out.links:
                    if o.is_valid:
                        o.to_socket.node.inputs[].default_value = self.outputs["Float"].default_value   #self.some_value

I have also added in code to handle the update when the frame changes to support animated values.

def pre_frame_change(scene):
    if scene.render.engine == 'CYCLES':
        # Scan materials to see if I have a custom node within any of the trees.
        for m in
            if m.node_tree != None:
                for n in m.node_tree.nodes:
                    if n.bl_idname == 'CustomNodeType':
                        # One of our custom nodes, let's update it.
                        # When we set the value that will trigger an update inside the node.
                        # Even if we change it to the same value it was.
                        v = n.some_value
                        n.some_value = v

I have attached the BLEND file with the example code working.

It looks like custom pynodes can work in any node tree.


27_cycles_custom_node.blend (115 KB)

If I make changes to the script and run the script again, I get an error, how do I fix this?

Thanks for sharing that by the way! it is exactly what I was looking for… Would you mind telling me how I add an input to that node? thanks!