/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
 *
 * SPDX-License-Identifier: Apache-2.0 */

#include "stdcycles.h"

shader node_vertex_color(string bump_offset = "center",
                         string layer_name = "",
                         output color Color = 0.0,
                         output float Alpha = 0.0)
{
  float vertex_color[4];
  string vertex_color_layer;

  if (layer_name == "") {
    vertex_color_layer = "geom:vertex_color";
  }
  else {
    vertex_color_layer = layer_name;
  }

  if (getattribute(vertex_color_layer, vertex_color)) {
    Color = color(vertex_color[0], vertex_color[1], vertex_color[2]);
    Alpha = vertex_color[3];

    if (bump_offset == "dx") {
      Color += Dx(Color);
      Alpha += Dx(Alpha);
    }
    else if (bump_offset == "dy") {
      Color += Dy(Color);
      Alpha += Dy(Alpha);
    }
  }
  else {
    warning("%s", "Invalid attribute.");
  }
}
