Page MenuHome

PyDrivers in Cycles node value fields do not evaluate automatically
Closed, ArchivedPublic


Mac OS 10.6.8 2.16 GHz Intel Core 2 Duo Radeon X1600

blender-2.67-r57600-OSX-10.6-i386 (and r57661); 32-bit.

For motivation and intent, please see

For bug itself, please see attached .png screenshot.


1.- I have only one scene, and to it I have attached a Custom Property
    with name=ArchiDraft and value=1.0

2.- In a Cycles Value node, I have the PyDriver expression <blockquote><i>[0].ArchiDraft </i></blockquote>3.- I have Run the lines<blockquote><i>import bpy
bpy.types.Scene.ArchiDraft = bpy.props.FloatProperty()</i></blockquote>&#x2003; &#x2003; Thanks to that,
&#x2003; &#x2003; the Graph Editor acknowledges the aforementioned expression as valid.

4.- Even though the Properties panel has ArchiDraft set to 1.0
&#x2003; &#x2003; the Graph Editor evaluates it to 0.000

5.- The Cycles Value node, which holds the <i>[0].ArchiDraft</i>
&#x2003; &#x2003; expression, apparently evaluates it to 0.500 ;
&#x2003; &#x2003; in reality, that number is just the initial default,
&#x2003; &#x2003; which has not been updated.

6.- My intent is to drop the PyDriver expression into a Fac field of a Mix node;
&#x2003; &#x2003; thus far, however, if I do that, the Node editor accepts it,
&#x2003; &#x2003; but the Graph Editor does not acknowledge it at all.

7.- I can drop the exact same expression into e.g.
&#x2003; &#x2003; an object’s Z rotation field, and then everything works as expected:
&#x2003; &#x2003; thank you, gurus, and congratulations!


To Do

Event Timeline

Regarding 1) and 2), there's a difference between properties like bpy.props.FloatProperty that you can declare to exist on all Scenes, or just properties created on a single scene. Your driver expression can work without bpy.props.FloatProperty like this:[0]['ArchiDraft'][0]['ArchiDraft']

Interesting; thank you!

But, doesn't that mean that Cycles will trigger a character string search
for every sample of every pixel it is trying to render?

OK, having the Custom Property ArchiDraft=1.0 in the Properties panel,
linked to the scene, but without first executing

import bpy
bpy.types.Scene.ArchiDraft = bpy.props.FloatProperty()

I entered[0]['ArchiDraft']
as PyDriver into the Fac field of a Mix node, and found that

(a) The Graph Editor acknowledges it and does not complain. However:

(b) The Graph Editor evaluates the expression to 0.000 and the Node Editor to 0.500 (i.e. the default),
even though the Properties panel acknowledges 1.000

(c) The same occurs if I drop the expression into a Value node.

Thank you for your patience!

Drivers are not evaluated per pixel or sample, they are evaluated once before rendering. So performance overhead is negligible. Also Python will do a character string search in both cases anyway (well actually accelerated with hash table).

I didn't check on the other issues yet.

...Drivers are not evaluated per pixel or sample, they are evaluated once before rendering...

Is that true even for noise.random() ?

I once used noise.random() to select shapekeys on a curl
that was duplifaced over a scalp, and one could see
that neighboring duplis were not identical.

By the way, congratulations on that Toon BSDF, and THANK you for the Size and Smooth parameters!
I think I'm falling in love, as in, going to use it even for realistic renders, e.g. hair.

As for speed, 100% CPU, it just blows my hat off!

I'm sad to say: the problem here is the depgraph :(

In theory, what you should do is:
1) make a driver variable "var"
2) link it to the Scene
3) set ArchiDraft or ['ArchiDraft'] as the path (depending on RNA or custom property)
4) use "var" as the driver expression

This does not work because of the limited depgraph, which does not evaluate drivers based on scene dependencies. The only reliable driver target atm are Objects - so if this is feasible, use an Object instead of Scene for the property!

Another option is to make an update callback for your property, then you don't need drivers in the first place.

In any case, it's a known ToDo, sorry. Hopefully the depgraph overhaul will fix it.

Wonderful to “hear” from you!

There’s a lot of buzz on regarding Dependency Graph improvements,
including a GSoC13 project:
so I’ll try to internalize what you are suggesting to me for now, and—
may the Force be with you!