0
$\begingroup$

Lets say i got a node and i want to change the color of that node with another node using drivers

enter image description here

something like this, so if i have my RGB node color set to white, it changes the Diffuse node to white too, if its red it changes to red etc. the goal is to make this possible with drivers only, i tried driving the Diffuse node to be controlled by the RGB node's RNA path but it didnt really work, it seems it can only control the driver with a value node or similar but it wont work with RGB nodes or color information. how can i make this to work?

$\endgroup$
5
  • 1
    $\begingroup$ Any reason why you can't just connect the nodes? The driver variable must be Single Property set to point to a material, and the Python path to the red channel of the RGB node is: node_tree.nodes["RGB"].outputs["Color"].default_value[0] (change the last [0] to [1] or [2] or [3] for g, b, a respectively) But it will be a dependency cycle if it drives something in the same material, so it's not functional in the example you've given. $\endgroup$ Aug 19 '19 at 20:02
  • $\begingroup$ oofies well.... this is related to my previous question about blender 2.8's workbench viewport displaying the solid color instead of the material color as it did back in 2.79 viewport. so i figured i could change the solid color of an object by driving it with nodes. also you mentioned "in the same material" does that mean this is doable by creating a second material? $\endgroup$
    – Zophiekat
    Aug 19 '19 at 21:20
  • $\begingroup$ The solid color and the material color might work, they aren't nodes. I think it might work with a second material, but you'll need a separate driver for r, g, and b colors. Dependency cycles occur because of user error or missing depsgraph checks... so if you're really passionate about this you might try reporting a bug or asking a question on devtalk. It might be that the devs can tweak a few lines of code and make it possible. $\endgroup$ Aug 19 '19 at 21:27
  • $\begingroup$ A second material seems to work! i couldnt solve my main problem though but at least im happy to know this small experiment worked $\endgroup$
    – Zophiekat
    Aug 19 '19 at 22:37
  • $\begingroup$ Blender 2.81 will support color properties on objects, according to the [ developer's meeting notes](devtalk.blender.org/t/19-august-2019/8888) from this week. It may yet be possible to do what you want in the future. $\endgroup$ Aug 20 '19 at 16:36
1
$\begingroup$

I was looking for this as well, but you can actually do it, just not Quite in the same way, and it's Way too much work. I'm writting a request to just open this up in nodes instead, but wanted to see if there was another way to do it.

So add the driver to the viewport display. Create an rgb node. Right click and copy the full path (you'll only use half of it)

in the drivers editor, select R diffuse color. expression is just var change input variable to single property, named var change the prop: to material and select the material (it's ok that it's the same material, so you don't need to create an extra one) For the path paste your path, but delete everything before node-tree... should look something like this: node_tree.nodes["RGB"].outputs[0].default_value[0]

Notice you'll have to add the [0] at the end. That tells it to use only the first value of RGBA. You should see the red value match now. Move on to G and change that number to [1], and so on. You can skip Alpha though, no point in matching 1.0 with 1.0 right? But up to you.

Now with all that, I'm hoping they can add viewport display options as input nodes to the material output node as an option. Because it would be a Heck of a lot easier to just connect them.

$\endgroup$
2
  • $\begingroup$ wow i forgot about this question lol, basically yes, this is what i ended up doing. adding some drivers to the viewport color, it isnt quite accurate but it gives a tolerable result. though, in my testing, i noticed that if you do this multiple times it will start to lag your scene. i honestly wouldnt recommend doing this at larger scales $\endgroup$
    – Zophiekat
    Jun 16 at 0:28
  • $\begingroup$ Yeah, I learned the hard way that even incredibly basic drivers can cause scenes to be incredibly slow. I'm guessing the way they are run aren't optimized....maybe at all. Example: I've got a scene with 2.5m verts on 500 objects parented to an empty. Playback is smooth. Add a single driver to Any of the children, and playback fps drops. This applies even if you only add a single keyframe. $\endgroup$ Oct 19 at 17:53
0
$\begingroup$

I thought I'd leave this here in case others follow this breadcrumb. I could find no docs or examples on this so it was made by trial and error.

Here is how I delete and remake a color driver in a world node tree RGB node using python.

I have a custom object properties named "Sky" as a color.

to define a color custom property, use this syntax in the Property Value field on a color named "Sky":

[1.0, 1.0, 1.0, 1.0]

here's the logic to then clear and rebuild the driver in python.

world_nodes = bpy.context.scene.world 
if world_nodes:
    sky_color = color_swatch_object["Sky"]
    background_node = world_nodes.node_tree.nodes.get('Background')
    colorNode = background_node.inputs[0].links[0].from_node
    if sky_color:
        try:
            colorNode.outputs[0].driver_remove("default_value")[0] 
            colorNode.outputs[0].driver_remove("default_value")[1] 
            colorNode.outputs[0].driver_remove("default_value")[2] 
        except:
            pass

        colorDriverRed = colorNode.outputs[0].driver_add("default_value")[0] 
        colorDriverGreen = colorNode.outputs[0].driver_add("default_value")[1] 
        colorDriverBlue = colorNode.outputs[0].driver_add("default_value")[2] 

        colorDriverRed.driver.type = 'SUM'
        newVar = colorDriverRed.driver.variables.new()
        newVar.name = "Sky"
        newVar.type = 'SINGLE_PROP'
        newVar.targets[0].id = color_swatch_object
        newVar.targets[0].data_path = '["Sky"][0]' 

        colorDriverGreen.driver.type = 'SUM'
        newVar = colorDriverGreen.driver.variables.new()
        newVar.name = "Sky"
        newVar.type = 'SINGLE_PROP'
        newVar.targets[0].id = color_swatch_object
        newVar.targets[0].data_path = '["Sky"][1]' 

        colorDriverBlue.driver.type = 'SUM'
        newVar = colorDriverBlue.driver.variables.new()
        newVar.name = "Sky"
        newVar.type = 'SINGLE_PROP'
        newVar.targets[0].id = color_swatch_object
        newVar.targets[0].data_path = '["Sky"][2]' 
$\endgroup$

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.