Code improvements + Mix node #30

Merged
Bogdan Nagirniak merged 18 commits from BogdanNagirniak/blender:matx-code-improvements into matx-export-material 2023-09-22 18:23:13 +02:00
Showing only changes of commit 834ee030b6 - Show all commits

View File

@ -360,62 +360,68 @@ NodeItem NodeItem::clamp(float min_val, float max_val) const
NodeItem NodeItem::sin() const
{
return arithmetic("sin", [](float a) { return std::sinf(a); });
return to_vector().arithmetic("sin", [](float a) { return std::sinf(a); });
}
NodeItem NodeItem::cos() const
{
return arithmetic("cos", [](float a) { return std::cosf(a); });
return to_vector().arithmetic("cos", [](float a) { return std::cosf(a); });
}
NodeItem NodeItem::tan() const
{
return arithmetic("tan", [](float a) { return std::tanf(a); });
return to_vector().arithmetic("tan", [](float a) { return std::tanf(a); });
}
NodeItem NodeItem::asin() const
{
return arithmetic("asin", [](float a) { return std::asinf(a); });
return to_vector().arithmetic("asin", [](float a) { return std::asinf(a); });
}
NodeItem NodeItem::acos() const
{
return arithmetic("acos", [](float a) { return std::acosf(a); });
return to_vector().arithmetic("acos", [](float a) { return std::acosf(a); });
}
NodeItem NodeItem::atan() const
{
return arithmetic("atan", [](float a) { return std::atanf(a); });
return to_vector().arithmetic("atan", [](float a) { return std::atanf(a); });
}
NodeItem NodeItem::atan2(const NodeItem &other) const
{
return arithmetic(other, "atan2", [](float a, float b) { return std::atan2f(a, b); });
return to_vector().arithmetic(
other, "atan2", [](float a, float b) { return std::atan2f(a, b); });
}
NodeItem NodeItem::sinh() const
{
return (exp() - (-*this).exp()) / val(2.0f);
NodeItem v = to_vector();
return (v.exp() - (-v).exp()) / val(2.0f);
}
NodeItem NodeItem::cosh() const
{
return (exp() - (-*this).exp()) / val(2.0f);
NodeItem v = to_vector();
return (v.exp() + (-v).exp()) / val(2.0f);
}
NodeItem NodeItem::tanh() const
{
return sinh() / cosh();
NodeItem v = to_vector();
NodeItem a = v.exp();
NodeItem b = (-v).exp();
return (a - b) / (a + b);
}
NodeItem NodeItem::ln() const
{
return arithmetic("ln", [](float a) { return std::logf(a); });
return to_vector().arithmetic("ln", [](float a) { return std::logf(a); });
}
NodeItem NodeItem::sqrt() const
{
return arithmetic("sqrt", [](float a) { return std::sqrtf(a); });
return to_vector().arithmetic("sqrt", [](float a) { return std::sqrtf(a); });
}
NodeItem NodeItem::sign() const
@ -425,7 +431,7 @@ NodeItem NodeItem::sign() const
NodeItem NodeItem::exp() const
{
return arithmetic("exp", [](float a) { return std::expf(a); });
return to_vector().arithmetic("exp", [](float a) { return std::expf(a); });
}
NodeItem NodeItem::convert(Type to_type) const
@ -898,13 +904,7 @@ NodeItem NodeItem::arithmetic(const std::string &category, std::function<float(f
}
}
else {
NodeItem v = *this;
if (ELEM(category, "sin", "cos", "tan", "asin", "acos", "atan2", "sqrt", "ln", "exp"))
{
/* These functions haven't implementation in MaterialX, converting to Vector types */
v = v.to_vector();
}
res = create_node(category, type, {{"in", v}});
res = create_node(category, type, {{"in", *this}});
}
return res;
}