Export to MatX various Texture nodes #5

Merged
Bogdan Nagirniak merged 17 commits from matx-add-tex-nodes into matx-export-material 2023-08-31 19:49:26 +02:00
3 changed files with 20 additions and 53 deletions
Showing only changes of commit 9fde492d46 - Show all commits

View File

@ -41,9 +41,8 @@ class NodeParser {
NodeItem empty() const;
template<class T> NodeItem value(const T &data) const;
virtual NodeItem get_input_default(const bNodeSocket &socket);
private:
NodeItem get_input_default(const bNodeSocket &socket);
NodeItem get_input_link(const bNodeSocket &socket);
NodeItem get_input_value(const bNodeSocket &socket);
};
@ -60,24 +59,14 @@ template<class T> NodeItem NodeParser::value(const T &data) const
NodeItem compute() override; \
};
#define DECLARE_PARSER_OVERRIDE(T) \
class T : public NodeParser { \
public: \
using NodeParser::NodeParser; \
NodeItem compute() override; \
\
protected: \
NodeItem get_input_default(const bNodeSocket &socket) override; \
};
DECLARE_PARSER(BSDFPrincipledNodeParser)
DECLARE_PARSER(InvertNodeParser)
DECLARE_PARSER(MathNodeParser)
DECLARE_PARSER(MixRGBNodeParser)
DECLARE_PARSER(OutputMaterialNodeParser)
DECLARE_PARSER(TexImageNodeParser)
DECLARE_PARSER(TexCheckerNodeParser)
DECLARE_PARSER(TexEnvironmentNodeParser)
DECLARE_PARSER_OVERRIDE(TexNoiseNodeParser)
DECLARE_PARSER_OVERRIDE(TexCheckerNodeParser)
DECLARE_PARSER(TexImageNodeParser)
DECLARE_PARSER(TexNoiseNodeParser)
} // namespace blender::nodes::materialx

View File

@ -8,23 +8,13 @@
namespace blender::nodes::materialx {
NodeItem TexCheckerNodeParser::get_input_default(const bNodeSocket &socket)
{
/* Explicit check for Scale socket since MaterialX has scales for X and Y
* axes and Blender only single. */
if (UNLIKELY(STREQ(socket.name, "Scale"))) {
NodeItem res = empty();
float v = socket.default_value_typed<bNodeSocketValueFloat>()->value;
res.value = MaterialX::Value::createValue<MaterialX::Vector2>({v, v});
return res;
}
return NodeParser::get_input_default(socket);
}
NodeItem TexCheckerNodeParser::compute()
{
NodeItem scale = get_input_value("Scale");
if (scale.value && scale.type() == "float") {
float v = scale.value->asA<float>();
scale = value(MaterialX::Vector2(v, v));
}
NodeItem color1 = get_input_value("Color1");
NodeItem color2 = get_input_value("Color2");
@ -32,16 +22,15 @@ NodeItem TexCheckerNodeParser::compute()
NodeItem frequency = create_node("constant", "vector2");
/* Modifier to follow Cycles result. */
NodeItem scale_fitter(graph);
scale_fitter.value = MaterialX::Value::createValue<float>(4.0f);
frequency.set_input("value", scale * scale_fitter);
scale = scale * value(4.0f);
frequency.set_input("value", scale);
NodeItem offset = create_node("constant", "vector2");
offset.set_input("value", empty().val(MaterialX::Vector2({0.0f, 0.0f})));
//NodeItem offset = create_node("constant", "vector2");
//offset.set_input("value", value(MaterialX::Vector2(0.0f, 0.0f)));
NodeItem place2d = create_node("place2d", "vector2");
place2d.set_input("texcoord", texcoord * frequency);
place2d.set_input("offset", offset);
//place2d.set_input("offset", offset);
NodeItem separate = create_node("separate2", "multioutput");
separate.set_input("in", place2d);
@ -50,16 +39,16 @@ NodeItem TexCheckerNodeParser::compute()
NodeItem modulo_x = create_node("modulo", "float");
modulo_x.set_input("in1", separate);
modulo_x.set_input("in2", empty().val(2.0f));
modulo_x.set_input("in2", value(2.0f));
modulo_x.node->setConnectedOutput("in1", separate.node->getOutput("outx"));
NodeItem modulo_y = create_node("modulo", "float");
modulo_y.set_input("in1", separate);
modulo_y.set_input("in2", empty().val(2.0f));
modulo_y.set_input("in2", value(2.0f));
modulo_y.node->setConnectedOutput("in1", separate.node->getOutput("outy"));
NodeItem ifequal = (modulo_x.floor() + modulo_y.floor())
.if_else("==", empty().val(1.0f), empty().val(0.0f), empty().val(1.0f));
NodeItem ifequal =
(modulo_x.floor() + modulo_y.floor()).if_else("==", value(1.0f), value(0.0f), value(1.0f));
NodeItem res = create_node("mix", "color3", false);
res.set_input("fg", color1.to_color3());

View File

@ -8,24 +8,13 @@
namespace blender::nodes::materialx {
NodeItem TexNoiseNodeParser::get_input_default(const bNodeSocket &socket)
{
/* Explicit check for Detail socket since MaterialX expects integer for
* octaves. */
if (UNLIKELY(STREQ(socket.name, "Detail"))) {
NodeItem res = empty();
int v = socket.default_value_typed<bNodeSocketValueFloat>()->value;
res.value = MaterialX::Value::createValue<int>(v);
return res;
}
return NodeParser::get_input_default(socket);
}
NodeItem TexNoiseNodeParser::compute()
{
NodeItem scale = get_input_value("Scale");
NodeItem detail = get_input_value("Detail");
if (detail.value && detail.type() == "float") {
detail = value(int(detail.value->asA<float>()));
}
NodeItem lacunarity = get_input_value("Lacunarity");
NodeItem texcoord = create_node("position", "vector3");