forked from blender/blender
Implement type conversion for NodeItem #9
@ -109,10 +109,10 @@ NodeItem MathNodeParser::compute()
|
||||
res = x.max(y);
|
||||
break;
|
||||
case NODE_MATH_LESS_THAN:
|
||||
res = x.if_else(NodeItem::IfType::Less, y, value(1.0f), value(0.0f));
|
||||
res = x.if_else(NodeItem::CompareOp::Less, y, value(1.0f), value(0.0f));
|
||||
break;
|
||||
case NODE_MATH_GREATER_THAN:
|
||||
res = x.if_else(NodeItem::IfType::Greater, y, value(1.0f), value(0.0f));
|
||||
res = x.if_else(NodeItem::CompareOp::Greater, y, value(1.0f), value(0.0f));
|
||||
break;
|
||||
case NODE_MATH_MODULO:
|
||||
res = x % y;
|
||||
@ -138,7 +138,7 @@ NodeItem MathNodeParser::compute()
|
||||
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
|
||||
break;
|
||||
case NODE_MATH_COMPARE:
|
||||
res = z.if_else(NodeItem::IfType::Less, (x - y).abs(), value(1.0f), value(0.0f));
|
||||
res = z.if_else(NodeItem::CompareOp::Less, (x - y).abs(), value(1.0f), value(0.0f));
|
||||
break;
|
||||
case NODE_MATH_MULTIPLY_ADD:
|
||||
res = x * y + z;
|
||||
|
@ -416,18 +416,18 @@ NodeItem NodeItem::convert(Type to_type) const
|
||||
return res;
|
||||
}
|
||||
|
||||
NodeItem NodeItem::if_else(IfType condition,
|
||||
NodeItem NodeItem::if_else(CompareOp op,
|
||||
const NodeItem &other,
|
||||
const NodeItem &if_val,
|
||||
const NodeItem &else_val) const
|
||||
{
|
||||
switch (condition) {
|
||||
case IfType::Less:
|
||||
return other.if_else(IfType::Greater, *this, else_val, if_val);
|
||||
case IfType::LessEq:
|
||||
return other.if_else(IfType::GreaterEq, *this, else_val, if_val);
|
||||
case IfType::NotEq:
|
||||
return if_else(IfType::Eq, other, else_val, if_val);
|
||||
switch (op) {
|
||||
case CompareOp::Less:
|
||||
return other.if_else(CompareOp::Greater, *this, else_val, if_val);
|
||||
case CompareOp::LessEq:
|
||||
return other.if_else(CompareOp::GreaterEq, *this, else_val, if_val);
|
||||
case CompareOp::NotEq:
|
||||
return if_else(CompareOp::Eq, other, else_val, if_val);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -446,16 +446,16 @@ NodeItem NodeItem::if_else(IfType condition,
|
||||
|
||||
std::function<bool(float, float)> func = nullptr;
|
||||
std::string mx_category;
|
||||
switch (condition) {
|
||||
case IfType::Greater:
|
||||
switch (op) {
|
||||
case CompareOp::Greater:
|
||||
mx_category = "ifgreater";
|
||||
func = [](float a, float b) { return a > b; };
|
||||
break;
|
||||
case IfType::GreaterEq:
|
||||
case CompareOp::GreaterEq:
|
||||
mx_category = "ifgreatereq";
|
||||
func = [](float a, float b) { return a >= b; };
|
||||
break;
|
||||
case IfType::Eq:
|
||||
case CompareOp::Eq:
|
||||
mx_category = "ifequal";
|
||||
func = [](float a, float b) { return a == b; };
|
||||
break;
|
||||
@ -685,6 +685,8 @@ NodeItem NodeItem::arithmetic(const std::string &category, std::function<float(f
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* TODO: Some of math functions (sin, cos, ...) doesn't work with Color types,
|
||||
* we have to convert to Vector */
|
||||
res.node = graph_->addNode(category, MaterialX::EMPTY_STRING, type(tp));
|
||||
res.set_input("in", *this);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class NodeItem {
|
||||
Color3,
|
||||
Color4
|
||||
};
|
||||
enum class IfType { Less = 0, LessEq, Eq, GreaterEq, Greater, NotEq };
|
||||
enum class CompareOp { Less = 0, LessEq, Eq, GreaterEq, Greater, NotEq };
|
||||
|
||||
public:
|
||||
MaterialX::ValuePtr value;
|
||||
@ -72,7 +72,7 @@ class NodeItem {
|
||||
NodeItem sign() const;
|
||||
NodeItem exp() const;
|
||||
NodeItem convert(Type to_type) const;
|
||||
NodeItem if_else(IfType condition,
|
||||
NodeItem if_else(CompareOp op,
|
||||
const NodeItem &other,
|
||||
const NodeItem &if_val,
|
||||
const NodeItem &else_val) const;
|
||||
|
@ -32,7 +32,7 @@ NodeItem TexCheckerNodeParser::compute()
|
||||
modulo_y.set_input("in2", value(2.0f));
|
||||
|
||||
NodeItem ifequal = (modulo_x.floor() + modulo_y.floor())
|
||||
.if_else(NodeItem::IfType::Eq, value(1.0f), value(0.0f), value(1.0f));
|
||||
.if_else(NodeItem::CompareOp::Eq, value(1.0f), value(0.0f), value(1.0f));
|
||||
|
||||
NodeItem res = create_node("mix", "color3");
|
||||
res.set_input("bg", color1, NodeItem::Type::Color3);
|
||||
|
Loading…
Reference in New Issue
Block a user