GLSL by material name?

I’ve been looking at a lot of GLSL examples and am getting close to what I want.

It seems to me that generally there are two approaches to assignment:

1)Assign the python script anywhere in the scene and check an object list and an index list to see where to apply the shader. I hear this is most efficient as the shader is used once per scene or some such.)

2)Assign the python script to each object you want to add the shader to and apply to the specified index. (less efficient because the shader would now be used once per object rather than per scene)

Neither seems ideal to me.

In an iteratative pipeline I want to assign the shaders pretty early. If I merge and split meshes often it’s possible that the material index could change often and it’s a pain to re-order.

as a solution Would it be possible to provide a list of material names rather than object names in the script, get the material name from blender through python and from that work out all the objects and index numbers to apply the shader to?

I’m guessing that the problem may arise when different objects have the same material on different index numbers


Well, imho, I think it would be better to write the code to for the indexing, rather than the last.

You write it just once, and run it whenever.

You say merging and splitting meshes often? are you doing this py? or with the edit add/delete object?

If you know how many times you will do this, you can just set them all up from the start on another layer. Then build the index, using whatever names you have chosen. Do you follow me?

I assume you are using a matrix for the index to save other info too?

Actually, if you do it this way, you can just add the script to each one you need to. LOL, so I think its the second option… going to bed now.

I think you have to go through the object to get to its material etc.

You probably already have this link, but just in case I will post it:

Material indexing with GLSL and especially with Ash’s Videotexplayer often screwed up for me. If anybody has a solution…

In current version of video texture plug-in there is function getMaterialName(object, materialIdx), which returns name of material.
In upcomming version of video texture plug-in is this function changed to materialID(object, materialName), which returns index of material with given name (if object doesn’t have such material, exception is thrown).
I hope this info will be helpful.