# 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 :(

• You could try texture node's, instead of a script – someonewithpc Mar 14 '15 at 23:24
• According to the manual, texture nodes don't work in the viewport, so that's not an option for me. – dr. Sybren Mar 15 '15 at 11:27
• @Sybren so you want the texture to be generated (during display) without using nodes and could be displayed in the viewport? – Chebhou Mar 16 '15 at 9:44
• well, texture nodes don't work in the viewport, so that's why I don't want texture nodes. It has to work in the viewport too. – dr. Sybren Mar 16 '15 at 13:04

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

• Thanks for your answer. It seems useful, but I was trying to avoid having a directory full of textures, and do the shading in Blender itself. – dr. Sybren Mar 16 '15 at 8:08
• what about material nodes with the same setup – Chebhou Mar 16 '15 at 10:00
• It took a while to figure out how to hook them up, but it works, thanks. Now there's one thing left, and that's assigning the colour values. I've updated my post to reflect this (also includes a screenshot of the node setup). – dr. Sybren Mar 16 '15 at 13:26
• @Sybren is it okay to have a different materials for each object ? – Chebhou Mar 16 '15 at 14:20
• I'm experimenting with this now. I can use mat.node_tree.nodes['colourizer'].inputs['H'].default_value = random.uniform(0, 1) to get a random hue. This can be done for each material, and I can clone materials for each object. It would be sweet though if I could use a single material that picks up properties from the object it's applied to. – dr. Sybren Mar 16 '15 at 15:06