19 if (type_str ==
"multioutput") {
22 if (type_str ==
"string") {
25 if (type_str ==
"filename") {
28 if (type_str ==
"boolean") {
31 if (type_str ==
"integer") {
34 if (type_str ==
"float") {
37 if (type_str ==
"vector2") {
40 if (type_str ==
"vector3") {
43 if (type_str ==
"vector4") {
46 if (type_str ==
"color3") {
49 if (type_str ==
"color4") {
52 if (type_str ==
"BSDF") {
55 if (type_str ==
"EDF") {
58 if (type_str ==
"displacementshader") {
61 if (type_str ==
"surfaceshader") {
64 if (type_str ==
"material") {
103 return "displacementshader";
105 return "surfaceshader";
121NodeItem::operator bool()
const
141 return arithmetic(other,
"add", [](
float a,
float b) {
return a +
b; });
146 return arithmetic(other,
"subtract", [](
float a,
float b) {
return a -
b; });
151 return val(0.0f) - *
this;
170 return arithmetic(other,
"multiply", [](
float a,
float b) {
return a *
b; });
175 return arithmetic(other,
"divide", [](
float a,
float b) {
return b == 0.0f ? 0.0f : a /
b; });
181 other,
"modulo", [](
float a,
float b) {
return b == 0.0f ? 0.0f : std::fmod(a,
b); });
186 return arithmetic(other,
"power", [](
float a,
float b) {
return std::pow(a,
b); });
200 v =
value->asA<MaterialX::Vector2>()[index];
203 v =
value->asA<MaterialX::Vector3>()[index];
206 v =
value->asA<MaterialX::Vector4>()[index];
209 v =
value->asA<MaterialX::Color3>()[index];
212 v =
value->asA<MaterialX::Color4>()[index];
243 return item1.
value->getValueString() == item2.
value->getValueString();
248 return !(*
this == other);
253 return arithmetic(
"absval", [](
float a) {
return std::abs(a); });
258 return arithmetic(
"floor", [](
float a) {
return std::floor(a); });
263 return arithmetic(
"ceil", [](
float a) {
return std::ceil(a); });
284 return arithmetic(other,
"min", [](
float a,
float b) {
return std::min(a,
b); });
289 return arithmetic(other,
"max", [](
float a,
float b) {
return std::max(a,
b); });
299 f = d.
value->asA<
float>();
303 auto v = d.
value->asA<MaterialX::Vector2>();
308 auto v = d.
value->asA<MaterialX::Vector3>();
309 f =
v[0] +
v[1] +
v[2];
313 auto v = d.
value->asA<MaterialX::Vector4>();
314 f =
v[0] +
v[1] +
v[2] +
v[3];
318 auto v = d.
value->asA<MaterialX::Color3>();
319 f =
v[0] +
v[1] +
v[2];
323 auto v = d.
value->asA<MaterialX::Color4>();
324 f =
v[0] +
v[1] +
v[2] +
v[3];
335 cast_types(item1, item2);
342 return (
val(1.0f) - *
this) * val1 + *
this * val2;
350 return create_node(
"mix", type1, {{
"bg", val1}, {
"fg", val2}, {
"mix", *
this}});
362 return min(max_val).max(min_val);
366 return create_node(
"clamp",
type(), {{
"in", *
this}, {
"low", min_val}, {
"high", max_val}});
397 NodeItem x_axis =
val(MaterialX::Vector3(1.0f, 0.0f, 0.0f));
398 NodeItem y_axis =
val(MaterialX::Vector3(0.0f, 1.0f, 0.0f));
399 NodeItem z_axis =
val(MaterialX::Vector3(0.0f, 0.0f, 1.0f));
409 return to_vector().arithmetic(
"sin", [](
float a) {
return std::sin(a); });
414 return to_vector().arithmetic(
"cos", [](
float a) {
return std::cos(a); });
419 return to_vector().arithmetic(
"tan", [](
float a) {
return std::tan(a); });
424 return to_vector().arithmetic(
"asin", [](
float a) {
return std::asin(a); });
429 return to_vector().arithmetic(
"acos", [](
float a) {
return std::acos(a); });
434 return to_vector().arithmetic(
"atan", [](
float a) {
return std::atan(a); });
439 return to_vector().arithmetic(other,
"atan2", [](
float a,
float b) {
return std::atan2(a,
b); });
445 return (
v.exp() - (-
v).exp()) /
val(2.0f);
451 return (
v.exp() + (-
v).exp()) /
val(2.0f);
459 return (a -
b) / (a +
b);
464 return to_vector().arithmetic(
"ln", [](
float a) {
return std::log(a); });
469 return to_vector().arithmetic(
"sqrt", [](
float a) {
return std::sqrt(a); });
474 return arithmetic(
"sign", [](
float a) {
return a < 0.0f ? -1.0f : (a == 0.0f ? 0.0f : 1.0f); });
479 return to_vector().arithmetic(
"exp", [](
float a) {
return std::exp(a); });
558 "Cannot convert: %s -> %s",
559 type(from_type).c_str(),
629 float v =
value->asA<
float>();
632 res.
value = MaterialX::Value::createValue<MaterialX::Vector2>({
v,
v});
635 res.
value = MaterialX::Value::createValue<MaterialX::Vector3>({
v,
v,
v});
638 res.
value = MaterialX::Value::createValue<MaterialX::Vector4>({
v,
v,
v, 1.0f});
641 res.
value = MaterialX::Value::createValue<MaterialX::Color3>({
v,
v,
v});
644 res.
value = MaterialX::Value::createValue<MaterialX::Color4>({
v,
v,
v, 1.0f});
652 auto v =
value->asA<MaterialX::Vector2>();
655 res.
value = MaterialX::Value::createValue<MaterialX::Vector3>({
v[0],
v[1], 0.0f});
663 auto v =
value->asA<MaterialX::Vector3>();
666 res.
value = MaterialX::Value::createValue<MaterialX::Vector2>({
v[0],
v[1]});
669 res.
value = MaterialX::Value::createValue<MaterialX::Vector4>(
670 {
v[0],
v[1],
v[2], 0.0f});
673 res.
value = MaterialX::Value::createValue<MaterialX::Color3>({
v[0],
v[1],
v[2]});
681 auto v =
value->asA<MaterialX::Vector4>();
684 res.
value = MaterialX::Value::createValue<MaterialX::Vector3>({
v[0],
v[1],
v[2]});
687 res.
value = MaterialX::Value::createValue<MaterialX::Color4>({
v[0],
v[1],
v[2],
v[3]});
695 auto v =
value->asA<MaterialX::Color3>();
698 res.
value = MaterialX::Value::createValue<MaterialX::Vector3>({
v[0],
v[1],
v[2]});
701 res.
value = MaterialX::Value::createValue<MaterialX::Color4>({
v[0],
v[1],
v[2], 1.0f});
709 auto v =
value->asA<MaterialX::Color4>();
712 res.
value = MaterialX::Value::createValue<MaterialX::Vector4>(
713 {
v[0],
v[1],
v[2],
v[3]});
716 res.
value = MaterialX::Value::createValue<MaterialX::Color3>({
v[0],
v[1],
v[2]});
776 auto item2 = else_val;
782 std::function<bool(
float,
float)> func =
nullptr;
783 std::string category;
786 category =
"ifgreater";
787 func = [](
float a,
float b) {
return a >
b; };
790 category =
"ifgreatereq";
791 func = [](
float a,
float b) {
return a >=
b; };
794 category =
"ifequal";
795 func = [](
float a,
float b) {
return a ==
b; };
802 res = func(
value->asA<
float>(), other.
value->asA<
float>()) ? item1 : item2;
806 category,
to_type, {{
"value1", *
this}, {
"value2", other}, {
"in1", item1}, {
"in2", item2}});
840 res.
node = graph_->getDocument()->addNode(category,
name, type_str);
843 res.
node = graph_->addNode(category,
name, type_str);
851 for (
const auto &it :
inputs) {
877 set_input(in_name, item.
value->asA<MaterialX::Vector2>(), item_type);
880 set_input(in_name, item.
value->asA<MaterialX::Vector3>(), item_type);
883 set_input(in_name, item.
value->asA<MaterialX::Vector4>(), item_type);
886 set_input(in_name, item.
value->asA<MaterialX::Color3>(), item_type);
889 set_input(in_name, item.
value->asA<MaterialX::Color4>(), item_type);
895 else if (item.
node) {
897 auto output_name = item.
node->getName() +
"_out";
899 auto output = graph_->getOutput(output_name);
901 output = graph_->addOutput(output_name, item.
node->getType());
908 node->setConnectedNode(in_name, item.
node);
911 else if (item.
input) {
912 node->setAttribute(
"interfacename", item.
input->getName());
915 node->setConnectedOutput(in_name, item.
output);
955 else if (item.
input) {
956 res.
output->setInterfaceName(item.
input->getName());
991NodeItem NodeItem::arithmetic(
const std::string &category, std::function<
float(
float)> func)
const
1000 float v =
value->asA<
float>();
1001 res.value = MaterialX::Value::createValue<float>(func(
v));
1005 auto v =
value->asA<MaterialX::Color3>();
1006 res.value = MaterialX::Value::createValue<MaterialX::Color3>(
1007 {func(
v[0]), func(
v[1]), func(
v[2])});
1011 auto v =
value->asA<MaterialX::Color4>();
1012 res.value = MaterialX::Value::createValue<MaterialX::Color4>(
1013 {func(
v[0]), func(
v[1]), func(
v[2]), func(
v[3])});
1017 auto v =
value->asA<MaterialX::Vector2>();
1018 res.value = MaterialX::Value::createValue<MaterialX::Vector2>({func(
v[0]), func(
v[1])});
1022 auto v =
value->asA<MaterialX::Vector3>();
1023 res.value = MaterialX::Value::createValue<MaterialX::Vector3>(
1024 {func(
v[0]), func(
v[1]), func(
v[2])});
1028 auto v =
value->asA<MaterialX::Vector4>();
1029 res.value = MaterialX::Value::createValue<MaterialX::Vector4>(
1030 {func(
v[0]), func(
v[1]), func(
v[2]), func(
v[3])});
1044 const std::string &category,
1045 std::function<
float(
float,
float)> func,
1056 if (
value && other.value) {
1059 float v1 = item1.value->asA<
float>();
1060 float v2 = item2.value->asA<
float>();
1061 res.value = MaterialX::Value::createValue<float>(func(v1,
v2));
1065 auto v1 = item1.value->asA<MaterialX::Color3>();
1066 auto v2 = item2.value->asA<MaterialX::Color3>();
1067 res.value = MaterialX::Value::createValue<MaterialX::Color3>(
1068 {func(v1[0],
v2[0]), func(v1[1],
v2[1]), func(v1[2],
v2[2])});
1072 auto v1 = item1.value->asA<MaterialX::Color4>();
1073 auto v2 = item2.value->asA<MaterialX::Color4>();
1074 res.value = MaterialX::Value::createValue<MaterialX::Color4>(
1075 {func(v1[0],
v2[0]), func(v1[1],
v2[1]), func(v1[2],
v2[2]), func(v1[3],
v2[3])});
1079 auto v1 = item1.value->asA<MaterialX::Vector2>();
1080 auto v2 = item2.value->asA<MaterialX::Vector2>();
1081 res.value = MaterialX::Value::createValue<MaterialX::Vector2>(
1082 {func(v1[0],
v2[0]), func(v1[1],
v2[1])});
1086 auto v1 = item1.value->asA<MaterialX::Vector3>();
1087 auto v2 = item2.value->asA<MaterialX::Vector3>();
1088 res.value = MaterialX::Value::createValue<MaterialX::Vector3>(
1089 {func(v1[0],
v2[0]), func(v1[1],
v2[1]), func(v1[2],
v2[2])});
1093 auto v1 = item1.value->asA<MaterialX::Vector4>();
1094 auto v2 = item2.value->asA<MaterialX::Vector4>();
1095 res.value = MaterialX::Value::createValue<MaterialX::Vector4>(
1096 {func(v1[0],
v2[0]), func(v1[1],
v2[1]), func(v1[2],
v2[2]), func(v1[3],
v2[3])});
1104#if !(MATERIALX_MAJOR_VERSION <= 1 && MATERIALX_MINOR_VERSION <= 38)
1105 if (category ==
"atan2") {
#define BLI_assert_unreachable()
#define CLOG_DEBUG(clg_ref,...)
#define CLOG_WARN(clg_ref,...)
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
NodeItem operator*(const NodeItem &other) const
NodeItem operator[](int index) const
NodeItem add_output(const std::string &out_name, Type out_type)
NodeItem operator-() const
NodeItem clamp(const NodeItem &min_val, const NodeItem &max_val) const
NodeItem dotproduct(const NodeItem &other) const
MaterialX::InputPtr input
NodeItem max(const NodeItem &other) const
NodeItem val(const T &data) const
void set_input(const std::string &in_name, const T &value, Type in_type)
bool operator!=(const NodeItem &other) const
NodeItem min(const NodeItem &other) const
bool operator==(const NodeItem &other) const
NodeItem atan2(const NodeItem &other) const
NodeItem create_input(const std::string &name, const NodeItem &item) const
MaterialX::OutputPtr output
NodeItem operator+(const NodeItem &other) const
static bool is_arithmetic(Type type)
NodeItem if_else(CompareOp op, const NodeItem &other, const NodeItem &if_val, const NodeItem &else_val) const
NodeItem to_vector() const
NodeItem rotate(const NodeItem &angle, const NodeItem &axis)
MaterialX::ValuePtr value
NodeItem convert(Type to_type) const
NodeItem create_output(const std::string &name, const NodeItem &item) const
NodeItem operator^(const NodeItem &other) const
static bool is_convertible(eNodeSocketDatatype from_type, Type to_type)
NodeItem mix(const NodeItem &val1, const NodeItem &val2) const
static Type type(const std::string &type_str)
NodeItem operator/(const NodeItem &other) const
std::vector< std::pair< std::string, NodeItem > > Inputs
NodeItem normalize() const
NodeItem operator%(const NodeItem &other) const
NodeItem create_node(const std::string &category, Type type) const
CCL_NAMESPACE_BEGIN ccl_device float invert(const float color, const float factor)
static Type to_type(const GPUType type)
struct CLG_LogRef * LOG_IO_MATERIALX
static blender::bke::bNodeSocketTemplate inputs[]
static std::string unique_anonymous_node_name(MaterialX::GraphElement *graph_element)