3
$\begingroup$

I am using black & white vertex colors to drive some of the shading on a character model's surface material (cycles), and found that the colors were the opposite of what I needed.

I wound up just swapping the colors on the material's Color Mix node, but now I am wondering: is there any way in blender to invert a model's vertex colors?

EDIT: To clarify, I was wondering if there was any built-in method to directly modify vertex colors. IE: without using python code or the invert node.

$\endgroup$

2 Answers 2

3
$\begingroup$

You can invert the colors of a vertex paint with python. The algorithm to invert the color is as follows:

new_color = 1.0 - current_color

Here is the code to invert the color of a vertex paint. Note that you should substitute the name Cube to the name of your mesh. Same goes for the vertex paint layer Col.

import bpy
import random

# get and store the object in object mode
obj = bpy.data.objects["Cube"]
mesh = obj.data

# set active vertex paint layer
color_layer = mesh.vertex_colors["Col"]

v = 0  # current vertex in loop

# iterate over the verices and invert their color
for poly in mesh.polygons:
    for idx in poly.loop_indices:
        col = [(1 - color_layer.data[v].color[i]) for i in range(3)]
        color_layer.data[v].color = col
        v += 1

# We have to refresh Vertex Paint mode to see the changes
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='VERTEX_PAINT')

Final Result

enter image description here

The advantage of this method is that you do not have to constantly invert at rendertime.

$\endgroup$
1
  • $\begingroup$ why the downvote? $\endgroup$
    – Vader
    Dec 27, 2014 at 15:20
1
$\begingroup$

Perhaps you are looking for the Color Invert node.

The top half of the following image shows the vertex colors plugged straight into the models color. The bottom half shows the Color Invert node inserted between the Attribute node and the final color.

enter image description here

$\endgroup$
1
  • $\begingroup$ As I stated before, I was just swapping the color values in the mix node, which was the same effect. I was asking about how to invert the color values directly, rather than just using a node to transform them. $\endgroup$ Dec 27, 2014 at 3:47

You must log in to answer this question.

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