# Building a Shader Switch | How to get custom values from individual objects?

I'm trying to build a shader-switch to easily switch the texture out of a set of ten different images. I want to use a single material for a set of picture frames. This is what I've got so far:

The node-group switches ten inputs using an input value between 0 and 1.

Problem: I can't change the input in the shader-node-editor, because all of my object would be updated. I can use the object-info-node to drive the channel with the random value, but this way I don't have control about the image.

There are already a lot of discussions about this topic, but most of the answers suggest to use drivers. In my case I have multiple objects. So I can't use one driver.

My idea is to read a custom property. A value between 0 an 1. But how can I access such a value in the node editor without using drivers.

Is there a way to use "self" in the driver menu? What kind of object is "self" in a shader-context? Can I somehow reference a custom property this way?

See this comment: Drivers: How to access "self"?

Do you have any tips? Thanks in advance!

• I don't think it helps here, but on the issue of what self is, I found this answer from @batFINGER very helpful. – Robin Betts Jul 17 '19 at 12:48
• Have a look here blender.stackexchange.com/questions/40634/… – lemon Jul 17 '19 at 12:59
• Here, you could use the 'Object Index' field of the Object Info node, which refers to the Pass Index of the object. That can be set per-object. You might have to divide it by 10, or whatever, to work with your switch node. (oops, @Martin Z has just shown you how) – Robin Betts Jul 17 '19 at 13:02

You do not need a custom property. You can use Object Index:

It might also be anoying to go through all the objects and assign different numbers to each, so you could use a very simple Python script to do that for all objects that you have seleceted:

 import bpy

for i,o in enumerate(bpy.context.selected_objects):
o.pass_index = i


Add something to i if you wish to start counting from a higher number if you have some indices set already.

• I find it strange it's called "pass index" in the property editor if this is what it does – John Dvorak Jul 17 '19 at 13:02
• I think it's weird as well. Could be called Object ID or something like that. – Martynas Žiemys Jul 17 '19 at 13:19
• The hover tip says it's the "index number for the "Object Index" render pass". Yeah. – John Dvorak Jul 17 '19 at 13:23
• Thanks a lot. That did the trick. Are there any use cases for the pass index? When do you use it? – Christopher Baumeister Jul 17 '19 at 14:33
• I haven't seen how it is in 2.80 yet and have never used it in my workflows, but in 2.79 it was possible to override all materials by one material per render pass, so this is a way to change materials by object or even by material index - this is the only case I can think of to use material index output in the Object Info node, because outside a material that overrides all other materials having material index accessible from inside the same material would be a bit pointless... – Martynas Žiemys Jul 17 '19 at 14:43