Implement export of Math node. Continue other arithmetic support for NodeItem #6

Merged
Bogdan Nagirniak merged 9 commits from BogdanNagirniak/blender:matx-arithmetic into matx-export-material 2023-08-31 12:35:55 +02:00
3 changed files with 32 additions and 14 deletions
Showing only changes of commit e1e66e4a1d - Show all commits

View File

@ -8,6 +8,8 @@ namespace blender::nodes::materialx {
NodeItem MathNodeParser::compute()
{
/* TODO: finish some math operations */
auto op = node->custom1;
printf("%d\n", int(op));
@ -76,6 +78,9 @@ NodeItem MathNodeParser::compute()
case NODE_MATH_TANH:
res = x.tanh();
break;
case NODE_MATH_TRUNC:
res = x.sign() * x.abs().floor();
break;
default: {
/* 2-operand operations */
@ -117,17 +122,14 @@ NodeItem MathNodeParser::compute()
case NODE_MATH_ARCTAN2:
res = x.atan2(y);
break;
case NODE_MATH_TRUNC:
//res = x.atan2(y);
break;
case NODE_MATH_SNAP:
//res = x.atan2(y);
// res = ;
break;
case NODE_MATH_PINGPONG:
//res = x.atan2(y);
// res = ;
break;
case NODE_MATH_FLOORED_MODULO:
//res = x.atan2(y);
// res = ;
break;
default: {
@ -135,27 +137,26 @@ NodeItem MathNodeParser::compute()
NodeItem z = get_input_value(2);
switch (op) {
case NODE_MATH_WRAP:
//res = x * y + z;
// res = ;
break;
case NODE_MATH_COMPARE:
//res = x * y + z;
res = z.if_else("<", (x - y).abs(), value(1.0f), value(0.0f));
break;
case NODE_MATH_MULTIPLY_ADD:
res = x * y + z;
break;
case NODE_MATH_SMOOTH_MIN:
//res = x * y + z;
// res = ;
break;
case NODE_MATH_SMOOTH_MAX:
//res = x * y + z;
// res = ;
break;
default:
/* TODO: log unsupported operation*/
BLI_assert_unreachable();
}
}
}
}
}

View File

@ -75,6 +75,11 @@ NodeItem NodeItem::operator-(const NodeItem &other) const
return arithmetic(other, "subtract", [](float a, float b) { return a - b; });
}
NodeItem NodeItem::operator-() const
{
return val(0.0f) - *this;
}
NodeItem NodeItem::operator*(const NodeItem &other) const
{
return arithmetic(other, "multiply", [](float a, float b) { return a * b; });
@ -177,6 +182,17 @@ NodeItem NodeItem::if_else(const std::string &condition,
const NodeItem &if_val,
const NodeItem &else_val) const
{
/* TODO: if_else() doesn't work correctly. Here is description
* Node: <ifgreater>
* Output the value of in1 if value1>value2, or the value of in2 if value1<=value2.
<nodedef name="ND_ifgreater_color3" node="ifgreater" nodegroup="conditional">
<input name="value1" type="float" value="1.0" />
<input name="value2" type="float" value="0.0" />
<input name="in1" type="color3" value="0.0, 0.0, 0.0" />
<input name="in2" type="color3" value="0.0, 0.0, 0.0" />
<output name="out" type="color3" defaultinput="in1" />
</nodedef>
*/
if (condition == "<") {
return other.if_else(">", *this, else_val, if_val);
}
@ -264,12 +280,12 @@ NodeItem NodeItem::atan2(const NodeItem &other) const
NodeItem NodeItem::sinh() const
{
return exp() - (val(0.0f) - *this).exp()) / val(2.0f);
return (exp() - (-*this).exp()) / val(2.0f);
}
NodeItem NodeItem::cosh() const
{
return exp() - (val(0.0f) - *this).exp()) / val(2.0f);
return (exp() - (-*this).exp()) / val(2.0f);
}
NodeItem NodeItem::tanh() const

View File

@ -32,6 +32,7 @@ class NodeItem {
operator bool() const;
NodeItem operator+(const NodeItem &other) const;
NodeItem operator-(const NodeItem &other) const;
NodeItem operator-() const;
NodeItem operator*(const NodeItem &other) const;
NodeItem operator/(const NodeItem &other) const;
NodeItem operator%(const NodeItem &other) const;