1

I know how to share a material among different objects, customizing it by using the ObjectInfo node. I want do something similar but replacing the ObjectInfo node with a custom property (different for each object, and animated with an F-Curve) that the material can automatically read as input.

How could I do this? Adding a custom property to the object? How would I access it from nodes? Could the ObjectInfo node be enhanced to support this custom property (as well as random, object index, location, material index)?

Dazotaro
  • 901
  • 1
  • 9
  • 20
  • 1
    Does this help? https://blender.stackexchange.com/questions/40634/use-custom-properties-variable-values-in-the-node-editor – Ray Mairlot May 08 '19 at 17:28
  • 1
    What kind of property do you need? Integer, float, vector? – Jaroslav Jerryno Novotny May 08 '19 at 18:15
  • I need a float, in the range [0.0, 1.0]. The following answer would work, but I was hoping for an easier way (e.g. augmenting the ObjectInfo node with a custom property). https://blender.stackexchange.com/questions/72101/capture-object-properties-to-use-in-a-cycles-material – Dazotaro May 08 '19 at 18:21
  • @RayMairlot That link does solve my problem using drivers. Thanks for your help. – Dazotaro May 08 '19 at 18:33
  • You could hack the Object ID property, the maximum is 32767 so that would give you 1 / 32767 = 0.00003 precision in [0,1] range. For real floats you can use vertex colors, but that is bigger workaround. The ultimate would be to script your own cycles node, but you would have to distribute that as an addon to everywhere you want it to work. It's also a lot more work. – Jaroslav Jerryno Novotny May 08 '19 at 18:34
  • Are you sure that those drivers solve your problem? The driver will have the same value for every object the material is applied to. The driver lives inside the material, not on the object. – Jaroslav Jerryno Novotny May 08 '19 at 18:36
  • @JaroslavJerrynoNovotny But the driver will drive the value node using each object's custom property, won't it? – Dazotaro May 08 '19 at 18:40
  • @JaroslavJerrynoNovotny Do you have an example on how to hack the object id property? Also, two objects could end up with the same id; wouldn't that be a problem? – Dazotaro May 08 '19 at 18:41
  • @JaroslavJerrynoNovotny You are right about the driver not being a valid approach. I would need to duplicate the material so the value node's driver can use different objects as targets. – Dazotaro May 08 '19 at 18:47

1 Answers1

3

There are not that many options how to input unique data of each object into a shader node tree.

There are vertex colors, hacking UV coordinates as numerical input, and outputs of Object Info node. There is also an option of scripting a custom Cycles node.

Because you need float in range <0, 1>, using the Object Index seems feasible. It's an integer with max value of 32767, which scaled into 0-1 range gives you 1/32767 of precision (0.00003), which is not bad. This is how you'd use it inside your material:

enter image description here

This is the property to animate for each object:

enter image description here

Just multiply your value with 32767 and round it.

Jaroslav Jerryno Novotny
  • 51,077
  • 7
  • 129
  • 218