4
$\begingroup$

I want to create a driver for a Mix Shader in a Material that is applied to several objects, that is based on a shape key value for the particular mesh.

An example, I have several cylinders that can overheat when compressed, so the value for the shape key "canon fire" would be reference by the driver in Material "Aluminum.Tube": enter image description here

Because the Material is used by several (common) meshes that are each animated "single use", I cannot use a specific object's shape key reference like below as answered here:

enter image description here

Although I see some "Shape Key from Object" that may hint at a solution, although I don't find this node documented.

self.{$current_object}.to_mesh().shape_keys.key_blocks['cannon fire'].value

Is there some way to specify shape key "canon fire" from current object?

The workaround -- if I have several duplicate-linked objects -- is to make a single-user copy of the Material, and edit each to the animation key block for that object.


As @Nathan says, there is no way to reference some current object from material Shader node drivers.

If I have duplicate-linked objects, I'll need to make a Single User copy of the material for those objects and then change the animated Key-set reference name for each.

Me thinks I'll add a suggestion to the rightclickselect community.

$\endgroup$
2
  • 2
    $\begingroup$ I don't think materials are connected to objects; at the time of evaluation of a material, it simply doesn't know what "current object" is. You can still do things like drive object index (which is an integer, but that's not an insurmountable problem) or you can drive a per-object modifier (a driver which might modulate copying a vertex color layer from black to white, from a single vertex, which of course can be read in the material.) To my knowledge, these techniques allow a single material, but still require individual per-object drivers. $\endgroup$
    – Nathan
    Commented Dec 31, 2022 at 21:17
  • 2
    $\begingroup$ Not sure if it helps, but you can create a custom property on each object/mesh and drive that from the shapekey value (using self if you want). Then access the custom prop in the material with an Attribute node. $\endgroup$
    – scurest
    Commented Jan 1, 2023 at 20:47

1 Answer 1

4
$\begingroup$

As mentioned elsewhere, since materials are shared, they can't reference "self" (well they can, but self points to a node tree, not an object).

If you want a setup that you can duplicate with the references to "self" updating, you can leverage the fact modifiers are unique to an object, and so you can use a driver in a geometry nodes modifier, that set a value to an attribute, which is then accessed in a shader:

Now you can duplicate the object and each will have this interaction separate from the rest:

$\endgroup$
5
  • $\begingroup$ It's better to drive a single custom property than a geonode input. It doesn't need to be stored num_verts times. $\endgroup$
    – scurest
    Commented Jan 2, 2023 at 13:59
  • $\begingroup$ @scurest but how will you access it from a shader? Since a material is shared, you can't make a driven field withing a node tree to point to self in this way. $\endgroup$ Commented Jan 2, 2023 at 15:20
  • 1
    $\begingroup$ You can access an object's custom props in the material with an Attribute node set to "Object". Manual. $\endgroup$
    – scurest
    Commented Jan 2, 2023 at 15:58
  • $\begingroup$ @scurest ah, that's indeed better, you should add it as an answer. $\endgroup$ Commented Jan 2, 2023 at 16:52
  • $\begingroup$ A tricky workaround that should be more straightforward, but it works! Me thinks I'll add a suggestion to the rightclickselect community. $\endgroup$
    – james_t
    Commented Jan 2, 2023 at 17:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .