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
5 changed files with 27 additions and 30 deletions
Showing only changes of commit 9a4ada236d - Show all commits

View File

@ -8,22 +8,7 @@ namespace blender::nodes::materialx {
NodeItem BSDFPrincipledNodeParser::compute() NodeItem BSDFPrincipledNodeParser::compute()
{ {
auto enabled = [](NodeItem &val) -> bool { NodeItem zero = value(0.0f);
if (val.node) {
return true;
}
if (!val.value) {
return false;
}
if (val.value->isA<float>()) {
return val.value->asA<float>() != 0.0f;
}
if (val.value->isA<MaterialX::Color4>()) {
auto c = val.value->asA<MaterialX::Color4>();
return c[0] != 0.0f || c[1] != 0.0f || c[2] != 0.0f;
}
return true;
};
/* Getting required inputs /* Getting required inputs
* Note: if some inputs are not needed they won't be taken */ * Note: if some inputs are not needed they won't be taken */
@ -32,7 +17,7 @@ NodeItem BSDFPrincipledNodeParser::compute()
NodeItem subsurface = get_input_value("Subsurface"); NodeItem subsurface = get_input_value("Subsurface");
NodeItem subsurface_radius = empty(); NodeItem subsurface_radius = empty();
NodeItem subsurface_color = empty(); NodeItem subsurface_color = empty();
if (enabled(subsurface)) { if (subsurface != zero) {
subsurface_radius = get_input_value("Subsurface Radius"); subsurface_radius = get_input_value("Subsurface Radius");
subsurface_color = get_input_value("Subsurface Color"); subsurface_color = get_input_value("Subsurface Color");
} }
@ -44,10 +29,10 @@ NodeItem BSDFPrincipledNodeParser::compute()
NodeItem anisotropic = empty(); NodeItem anisotropic = empty();
NodeItem anisotropic_rotation = empty(); NodeItem anisotropic_rotation = empty();
if (enabled(metallic)) { if (metallic != zero) {
/* TODO: use Specular Tint input */ /* TODO: use Specular Tint input */
anisotropic = get_input_value("Anisotropic"); anisotropic = get_input_value("Anisotropic");
if (enabled(anisotropic)) { if (anisotropic != zero) {
anisotropic_rotation = get_input_value("Anisotropic Rotation"); anisotropic_rotation = get_input_value("Anisotropic Rotation");
// anisotropic_rotation = 0.5 - (anisotropic_rotation % 1.0) // anisotropic_rotation = 0.5 - (anisotropic_rotation % 1.0)
} }
@ -60,7 +45,7 @@ NodeItem BSDFPrincipledNodeParser::compute()
NodeItem clearcoat = get_input_value("Clearcoat"); NodeItem clearcoat = get_input_value("Clearcoat");
NodeItem clearcoat_roughness = empty(); NodeItem clearcoat_roughness = empty();
if (enabled(clearcoat)) { if (clearcoat != zero) {
clearcoat_roughness = get_input_value("Clearcoat Roughness"); clearcoat_roughness = get_input_value("Clearcoat Roughness");
} }
@ -68,7 +53,7 @@ NodeItem BSDFPrincipledNodeParser::compute()
NodeItem transmission = get_input_value("Transmission"); NodeItem transmission = get_input_value("Transmission");
NodeItem transmission_roughness = empty(); NodeItem transmission_roughness = empty();
if (enabled(transmission)) { if (transmission != zero) {
transmission_roughness = get_input_value("Transmission Roughness"); transmission_roughness = get_input_value("Transmission Roughness");
} }
@ -90,11 +75,11 @@ NodeItem BSDFPrincipledNodeParser::compute()
res.set_input("normal", normal); res.set_input("normal", normal);
res.set_input("tangent", tangent); res.set_input("tangent", tangent);
if (enabled(metallic)) { if (metallic != zero) {
res.set_input("metalness", metallic); res.set_input("metalness", metallic);
} }
if (enabled(specular)) { if (specular != zero) {
res.set_input("specular", specular); res.set_input("specular", specular);
res.set_input("specular_color", base_color.to_color3()); res.set_input("specular_color", base_color.to_color3());
res.set_input("specular_roughness", roughness); res.set_input("specular_roughness", roughness);
@ -103,26 +88,26 @@ NodeItem BSDFPrincipledNodeParser::compute()
res.set_input("specular_rotation", anisotropic_rotation); res.set_input("specular_rotation", anisotropic_rotation);
} }
if (enabled(transmission)) { if (transmission != zero) {
res.set_input("transmission", transmission); res.set_input("transmission", transmission);
res.set_input("transmission_color", base_color.to_color3()); res.set_input("transmission_color", base_color.to_color3());
res.set_input("transmission_extra_roughness", transmission_roughness); res.set_input("transmission_extra_roughness", transmission_roughness);
} }
if (enabled(subsurface)) { if (subsurface != zero) {
res.set_input("subsurface", subsurface); res.set_input("subsurface", subsurface);
res.set_input("subsurface_color", subsurface_color); res.set_input("subsurface_color", subsurface_color);
res.set_input("subsurface_radius", subsurface_radius); res.set_input("subsurface_radius", subsurface_radius);
res.set_input("subsurface_anisotropy", anisotropic); res.set_input("subsurface_anisotropy", anisotropic);
} }
if (enabled(sheen)) { if (sheen != zero) {
res.set_input("sheen", sheen); res.set_input("sheen", sheen);
res.set_input("sheen_color", base_color.to_color3()); res.set_input("sheen_color", base_color.to_color3());
res.set_input("sheen_roughness", roughness); res.set_input("sheen_roughness", roughness);
} }
if (enabled(clearcoat)) { if (clearcoat != zero) {
res.set_input("coat", clearcoat); res.set_input("coat", clearcoat);
res.set_input("coat_color", base_color.to_color3()); res.set_input("coat_color", base_color.to_color3());
res.set_input("coat_roughness", clearcoat_roughness); res.set_input("coat_roughness", clearcoat_roughness);
@ -132,7 +117,7 @@ NodeItem BSDFPrincipledNodeParser::compute()
res.set_input("coat_normal", clearcoat_normal); res.set_input("coat_normal", clearcoat_normal);
} }
if (enabled(emission)) { if (emission != zero) {
res.set_input("emission", emission_strength); res.set_input("emission", emission_strength);
res.set_input("emission_color", emission); res.set_input("emission_color", emission);
} }

View File

@ -108,6 +108,11 @@ bool NodeItem::operator==(const NodeItem &other) const
return false; return false;
} }
bool NodeItem::operator!=(const NodeItem &other) const
{
return !(*this == other);
}
NodeItem NodeItem::abs() const NodeItem NodeItem::abs() const
{ {
return arithmetic("absval", [](float a) { return std::fabsf(a); }); return arithmetic("absval", [](float a) { return std::fabsf(a); });

View File

@ -37,6 +37,7 @@ class NodeItem {
NodeItem operator%(const NodeItem &other) const; NodeItem operator%(const NodeItem &other) const;
NodeItem operator^(const NodeItem &other) const; NodeItem operator^(const NodeItem &other) const;
bool operator==(const NodeItem &other) const; bool operator==(const NodeItem &other) const;
bool operator!=(const NodeItem &other) const;
NodeItem abs() const; NodeItem abs() const;
NodeItem floor() const; NodeItem floor() const;

View File

@ -111,7 +111,7 @@ NodeItem NodeParser::get_input_value(const std::string &name)
return res; return res;
} }
NodeItem NodeParser::empty() NodeItem NodeParser::empty() const
{ {
return NodeItem(graph); return NodeItem(graph);
} }

View File

@ -35,9 +35,15 @@ class NodeParser {
NodeItem get_input_default(const std::string &name); NodeItem get_input_default(const std::string &name);
NodeItem get_input_link(const std::string &name); NodeItem get_input_link(const std::string &name);
NodeItem get_input_value(const std::string &name); NodeItem get_input_value(const std::string &name);
NodeItem empty(); NodeItem empty() const;
template<class T> NodeItem value(const T &data) const;
}; };
template<class T> NodeItem NodeParser::value(const T &data) const
{
return empty().val(data);
}
#define DECLARE_PARSER(T) \ #define DECLARE_PARSER(T) \
class T : public NodeParser { \ class T : public NodeParser { \
public: \ public: \