6
$\begingroup$

I need a number of shading properties that are unique per object, so I can control the strength of a couple of effects in the shader. The color property in the Object info node is a perfect example of what I'm looking for, but I need a few more properties than just the color.

Is there any way to access custom properties, or something equivalent, in a similar manner? And preferably in a way so that objects that don't have that custom property added don't break the shader?

$\endgroup$

1 Answer 1

8
$\begingroup$

Tested with blender 3.0 (should probably work with any version with shader nodes added).

  1. Add custom property of required type to your objects.

Object custom property

I want to set colors by myColor property (use gear icon to setup property).

Color property type

First object color

Second object color

  1. Use Input/Attribute node in the shared material. Set type to Object and use your property name.

Shader nodes

Objects without this property will read the default value of the corresponding type (zeros or black color).

$\endgroup$
4
  • 1
    $\begingroup$ Is there a way to use a custom property for the material to do the same? $\endgroup$
    – james_t
    Apr 28, 2022 at 18:48
  • 1
    $\begingroup$ @james_t I don't know about custom properties via blender's UI, but properties added via python very much so, but also in python, by using the property's update callback. I've made extensive use of this here: github.com/taniwha/io_object_mu/tree/master/shader $\endgroup$
    – taniwha
    Jun 8, 2022 at 14:18
  • $\begingroup$ I have confirmed that this works for properties (even nested) added via python scripts: if you know the property "path", it's just a matter of continuing from the object (eg, muproperties.layer where muproperties is a property group added to the object via python, and layer is a sub-property in that group). $\endgroup$
    – taniwha
    Jun 8, 2022 at 14:22
  • $\begingroup$ Fantastic, thank you! This seems to be the best way to switch textures on an object during animation. And yet I haven't seen it described in any tutorials. I wonder if I'm missing something? But it works perfectly! $\endgroup$ Sep 12, 2022 at 7:23

You must log in to answer this question.

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