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: enter image description here

Im aiming to achieve this kind of effect: enter image description here

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


3 Answers 3


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): 
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 enter image description here the result is color transition for faces not points :

enter image description here

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)

  • $\begingroup$ 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? $\endgroup$
    – devchimp
    Mar 30, 2015 at 10:28
  • $\begingroup$ 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 $\endgroup$
    – Chebhou
    Mar 30, 2015 at 14:41
  • $\begingroup$ Would it be possible to do this with an image texture instead of a color ramp? $\endgroup$ Apr 19, 2015 at 23:52
  • $\begingroup$ @GiantCowFilms every face has one coordinate (it would be a point on the texture ), still can't get what you mean exactly $\endgroup$
    – Chebhou
    Apr 20, 2015 at 1:28
  • $\begingroup$ I think the choice would be an average of the color of the points at the vertexes... $\endgroup$ Apr 20, 2015 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.

enter image description here

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.

enter image description here

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

  • $\begingroup$ 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? $\endgroup$
    – devchimp
    Mar 30, 2015 at 11:06
  • $\begingroup$ 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. $\endgroup$ Mar 30, 2015 at 13:59
  • $\begingroup$ I've added the .blend $\endgroup$ Mar 30, 2015 at 14:05

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

color ramp set up

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:

enter image description here

  • $\begingroup$ 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 :) $\endgroup$
    – devchimp
    Mar 30, 2015 at 9:06
  • $\begingroup$ 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 ;) $\endgroup$
    – Mr Zak
    Mar 30, 2015 at 12:25
  • $\begingroup$ @MrZak You could have used constant interpolation and saved alot of points $\endgroup$ Jul 10, 2015 at 18:03
  • $\begingroup$ @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. $\endgroup$
    – Mr Zak
    Jul 10, 2015 at 18:49

You must log in to answer this question.

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