3
$\begingroup$

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:

My intended colour change

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.

Material node setup

  • 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 :

enter image description here

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

$\endgroup$
4
  • $\begingroup$ You could try texture node's, instead of a script $\endgroup$ Mar 14, 2015 at 23:24
  • $\begingroup$ According to the manual, texture nodes don't work in the viewport, so that's not an option for me. $\endgroup$
    – dr. Sybren
    Mar 15, 2015 at 11:27
  • $\begingroup$ @Sybren so you want the texture to be generated (during display) without using nodes and could be displayed in the viewport? $\endgroup$
    – Chebhou
    Mar 16, 2015 at 9:44
  • $\begingroup$ 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. $\endgroup$
    – dr. Sybren
    Mar 16, 2015 at 13:04

1 Answer 1

3
$\begingroup$

this is not a total script but it does the job :

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

enter image description here

  • 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

enter image description here

$\endgroup$
5
  • $\begingroup$ 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. $\endgroup$
    – dr. Sybren
    Mar 16, 2015 at 8:08
  • $\begingroup$ what about material nodes with the same setup $\endgroup$
    – Chebhou
    Mar 16, 2015 at 10:00
  • $\begingroup$ 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). $\endgroup$
    – dr. Sybren
    Mar 16, 2015 at 13:26
  • $\begingroup$ @Sybren is it okay to have a different materials for each object ? $\endgroup$
    – Chebhou
    Mar 16, 2015 at 14:20
  • $\begingroup$ 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. $\endgroup$
    – dr. Sybren
    Mar 16, 2015 at 15:06

You must log in to answer this question.

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