I'm fairly new to Blender. I have a Cycles material in Blender 2.79. I'm using an Attribute node with COLOR_0 to get the vertex color and multiplying that into the material color. But if a particular mesh doesn't have the COLOR_0 attribute, it comes through black. Is there a node that can act as a switch based on presence of an attribute?


One way is to define a material where it will use a node comparing value of vertex colors for a factor defining what socket of the next node will be used.

enter image description here

There are 2 cubes and 2 different materials on them (for demonstration purposes). Both cubes have vertex color layer called "Col" (default name).

The color is fed to the Math node set to Less Than which compares values on the input to its second socket (which is 0.001, almost black, color will be black if no vertex color data is present).

Then the output of that is used as a factor for the MixRGB node - the output is either 0 or 1. If factor is 0 bottom input of the MixRGB node is used, If it's 1 - then the top one.

The cube on the right has Attribute node with vertex color layer written wrongly - "Col1" and blue color is used instead of default black. You can setup any color in the bottom input of the MixRGB node.

| improve this answer | |
  • $\begingroup$ I guess that works as long as the vertex color is not black! I don't know how the Attribute node is implemented, but it would be great if it could have an extra "default" input that would be used if the attribute was not present. Or a second output, a boolean. $\endgroup$ – GaryO Apr 14 '18 at 13:31
  • $\begingroup$ @GaryO the method shown above works fine and is intended to work when vertex colors are black. Though the node setup in the answer assumes value for the Math node set to Less Than should be 0.001 or any other infinitely small value (i.e not 0). To workaround that use Math > Greater Than mode and put vertex colors into the bottom socket of the MixRGB node as here i.stack.imgur.com/2xRMR.gif. Making Attribute or any node having another input/output is impossible without rewriting Blender source code. $\endgroup$ – R El Clein Apr 14 '18 at 19:04
  • $\begingroup$ @R El Clein, it almost works. But if you have a whole face painted black, it gets the alternate color. It only works most of the time because with only one black vertex, the actual color is never totally black. See the green triangle face at pasteboard.co/HgD2ddm.png $\endgroup$ – GaryO Apr 14 '18 at 21:09
  • $\begingroup$ A true solution would have to detect the presence of the attribute. This seems like a bug to me; I'll submit it. $\endgroup$ – GaryO Apr 14 '18 at 21:12
  • 1
    $\begingroup$ @GaryO in this case this is not a bug, but a feature request as this is a missing feature while everything already present works properly. $\endgroup$ – R El Clein Apr 14 '18 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.