Can't use driver on Cycles shader

Hello Blender artists!

I’m trying to manipulate a Cycles mix shader’s “Fac” value using a driver.
I cannot get it to work for some reason. Setting up drivers for transformations of an object works without problems, but when I use the exact same type of driver (which should work since it works on the transformations) it doesn’t do anything on the “Fac” value.

To demonstrate my problem I have attached a file.
There’s a cube whose z-Position is driven by dragging the bone up and down and also the “Fac” value should be influenced the same way, but nothing does happen.

When I turn on the debugging info it constantly shows me a “value” of 0, although at the same bone position in the transformations driver it shows me some other value as soon as I move the bone.

Does anybody know if I’m doing something wrong?

Thank you!

MD

Attachments

CyclesDriver.blend (486 KB)

Hi

Maybe try a handler instead.


import bpy

def setFac(scene):
    # test with adding 0.01 use bone loc or whatever.

    bpy.data.materials['Material.001'].node_tree.nodes['Mix Shader'].inputs['Fac'].default_value += 0.01
    
bpy.app.handlers.frame_change_pre.append(setFac)

Hi batFINGER,

thanks for looking into this.
Only, I’m afraid I do not quite understand what a handler is and what I am supposed to do with your code snippet. Do I need to run it somewhere inside of Blender? And if so, where and how?

Also, why doesn’t it work in the first place? Is it me doing something wrong or is this a bug in Blender?

Thanks!

MD

Paste the script into the text editor, right click, choose run script. The example i posted is a pre frame change handler, ie it runs the code on a frame change event before the new settings take place. A render handler may be more appropriate in this case. http://www.blender.org/documentation/blender_python_api_2_62_release/bpy.app.handlers.html?highlight=handlers#bpy.app.handlers

Also, why doesn’t it work in the first place? Is it me doing something wrong or is this a bug in Blender?

Thanks!

MD

My guess, and it’s a guess, is that the node tree isn’t part of the dependency tree that is calculated to see what is being driven by what. Eg you get a cyclic dependency error if you try and drive object a with b and b with a at the same time. Wether this is an oversight or bug, or by design I’m not sure.

Ok, I got the script to work and it increases the driver value on a frame change. I am not quite sure how to use it in my setup now actually, but luckily I found a workaround for my situation which doesn’t even use any drivers at all.

Thanks again for helping me.

As for the “bug or not”: I have no idea about these things, but I would guess it’s actually a bug, otherwise why would they offer you the possibility to even add a driver for these nodes if you cannot use them at all? Do you think it is something I should report?

MD

http://projects.blender.org/tracker/index.php?func=detail&aid=31834&group_id=9&atid=498

I also submitted this bug. It’s VERY important to the project I’m working on right now.
However, it looks like Aligorith has fixed it. Time to get the latest SVN version and start testing!

Just for people stumbling into this.

Usually people want to have a cycles shader change based upon frame index
What you can do is set a value node to 0 on frame zero press i on the value area
Then go to the last render frame, notice frame number, put it in the value press i again.
Next goto graph editor for this value and change the curve shape to linear

Result a value that shows frame numbers