Colorizing part of a texture I'm creating a crowd of people in Blender. For now, they all have the same model, and I want to create some variation by changing the colour of their clothing. What I have is a texture, a mask for each piece of clothing, and a randomly chosen colour. What I would like is to be able to use these to create a new texture like so:



Of course I can create each texture by hand, but I'd rather write some script that performs these tasks automatically in Blender. I also want to avoid a directory full of textures, as I can easily create those myself. What would be a good approach for this?

I'm using Blender Internal, and GLSL shading in the viewport. It's important that the viewport also reflects the colour, as I'll be using this in a live demo.

UPDATE: By using material nodes (as suggested by @chebhou) I almost got it working. This is the material node setup now. The material referred to in the "Material" node is actually simply a white textureless material.




The one thing that's left is to ensure that each object has a unique value for the HSV converter inputs. Does anyone have any ideas about this?


UPDATE 2:
Chebhou writes: I have tried to use the driver on the value node but it's not evaluated ( it's just stuck at a certain value) , and i need to make this value specific to each object (there are many objects that use this material but needs to look different )

I'm looking for a way to get an object related value like in cycles :



it would be good also if there is another approach(I can go through the objects and assign this material with different settings but it would be better if it is only one shared )

UPDATE 3:
Sybren writes: What I have so far is working nicely, check the video at  https://www.youtube.com/watch?v=BBlS4PKJhOc

However, it still uses the same values for all objects that use the material :(
this is not a total script but it does the job :


in the default scene (or empty one) create this compositor node setup





you need to run this script just to have random numbers available in the driver :




import bpy
import random

def rand():
    return random.uniform(0,1)

bpy.app.driver_namespace['rand'] = rand



now add a driver for the value nodes with the scripted expression rand()
set the number of frames to render to the number of textures
render the animation and you'll have the output directory full with textures