# Is there a smart way to apply a better transition between colours while maintaining one solid colour per face?

I recently started using blender for a project. I have tried using a color ramp with a transition between the 4 colours, but the result is too smooth when applied:

Im aiming to achieve this kind of effect:

Is there a way, or is it the long winded way?

The following script reads the face position normalize it and assign it to the vertex color of this face ( new group named 'face_pos' will be created ) :

import bpy

obj = bpy.context.object
obj_data = obj.data
group_name = 'face_pos'
#check for existing group with the same name
if None == obj_data.vertex_colors.get(group_name):
obj_data.vertex_colors.new(name=group_name)
color_map =  obj_data.vertex_colors[group_name]

#collect dimension info
dim = obj.dimensions
min_x = -1*min([p.center[0] for p in obj_data.polygons])
min_y = -1*min([p.center[1] for p in obj_data.polygons])
min_z = -1*min([p.center[2] for p in obj_data.polygons])

for poly in obj_data.polygons:
pos = poly.center
color = ((pos[0]+min_x)/dim[0], (pos[1]+min_y)/dim[1], (pos[2]+min_z)/dim[2])
for loop_ind in poly.loop_indices:
color_map.data[loop_ind].color = color


we wont apply this vertex color but instead we use it as a face position input in the material nodes using the Attribute node and the vertex color name , then we manipulate this information to create the desired effect

material node the result is color transition for faces not points :

This solution maybe a bit complicated but it introduce a trick for accessing other properties in cycles(this is not like drivers since it updates per point not frame)

• I copied your script and saved as 'face_pos.py', I then installed from File > User Preferences > Install From File. I followed the node layout exactly but it only renders the first colour in the colour map. I've never dabbled with scripts before, but is there a step ive missed or something I may not have done? – devchimp Mar 30 '15 at 10:28
• copy and past in blender text editor select your object and click Run_Script in the text editor you will see new vertex_color_group you can go to vertex_color_paint mode to see the colors the rest is as in the answer – Chebhou Mar 30 '15 at 14:41
• Would it be possible to do this with an image texture instead of a color ramp? – GiantCowFilms Apr 19 '15 at 23:52
• @GiantCowFilms every face has one coordinate (it would be a point on the texture ), still can't get what you mean exactly – Chebhou Apr 20 '15 at 1:28
• I think the choice would be an average of the color of the points at the vertexes... – GiantCowFilms Apr 20 '15 at 1:50

if you select all of the faces in Edit mode and then use Alt+e to access the Extrude options menu->Individual.

Press the Esc key to cancel the movement.

Next, press Ctrl + i to invert the selection

Press x to access the Delete menu and select 'Faces'.

Now you should be left with only the extruded faces and they should be all separate components.

OPTIONAL:Personally, I would bake these results to a UV map probably using the 'Lightmap Pack'setting.
This way, the individual faces can be re-joined after baking. This helps keep the Outliner clean. The 3D Viewport should also run much faster when many Objects are joined together into one.

Make sure that everything is selected and press p to access 'Separate->By Loose Parts'.

Now enter Object Mode and make sure that all the separate pieces are selected then use the shortcut Ctrl+Shift+Alt+c to access the 'Set Origin' Menu. Choose the option 'Origin To Center Of Mass' and now the model is ready.

The 'Node: Input -> Object Info -> Random' is key here. This is why the faces are all separate objects. Random greyscale values will be assigned to each separate model and this can be used to modulate the colors ramp so the color transition is a bit more scattered.

Here is a simple node setup that uses the random node to change the relative brightness of triangles.

This next node setup uses a second color ramp combined using the Linear Light Blend mode, many of the other blend modes give interesting effects as well. This setup also uses a noise texture to modulate how the main colors transition across the model.

Here's the .blend file http://www.pasteall.org/blend/35306

• I followed your instructions and copied the node modules and layout to my material exactly, however when it comes to render it comes out solid pink (the first colour in my gradient) any ideas? – devchimp Mar 30 '15 at 11:06
• My apologies. I didn't think to mention that that color ramps and mapping nodes are very touchy here. The model scale has a big impact on which numbers should be chosen. Usually I just move the sliders around quickly until I find the range I am looking for and then I hold down Shift and also sometimes Alt to fine-tune the numbers. – MarcClintDion Mar 30 '15 at 13:59
• I've added the .blend – MarcClintDion Mar 30 '15 at 14:05

I think you might want to set up Color Ramp node like that:

In this case, color transition will be a lot more sharper. To control the sharpness you can drag the control points in and out or change the Interpolation type (it's better than using default Linear one in this case, because it provides still smooth but more visible transitions, imo).

If rendered, objects might look like that:

• This is about as far as I got before posting the question, should have been a bit clearer, but thanks for the input all the same :) – devchimp Mar 30 '15 at 9:06
• Well, you have much better answers on your question already so mine is here only because I didn't think it's more complicated task and haven't delete it ;) – Mr Zak Mar 30 '15 at 12:25
• @MrZak You could have used constant interpolation and saved alot of points – GiantCowFilms Jul 10 '15 at 18:03
• @GiantCowFilms as I've got OP this approach isn't good enough at all because he needed much more than this solution could provide. I simply misread his question. – Mr Zak Jul 10 '15 at 18:49