1
1
Fork 0

Parsing Improvements #14

Merged
Bogdan Nagirniak merged 5 commits from matx-parsing-improvements into matx-export-material 2023-09-07 15:10:17 +02:00
15 changed files with 29 additions and 29 deletions
Showing only changes of commit 902dbd6c65 - Show all commits

View File

@ -16,7 +16,7 @@ NodeItem BSDFDiffuseNodeParser::compute()
NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Float);
NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
NodeItem res = create_node("oren_nayar_diffuse_bsdf", "BSDF");
NodeItem res = create_node("oren_nayar_diffuse_bsdf", shader_type_);
res.set_input("color", color);
res.set_input("roughness", roughness);
if (normal) {

View File

@ -50,7 +50,7 @@ NodeItem BSDFPrincipledNodeParser::compute()
NodeItem tangent = get_input_link("Tangent", NodeItem::Type::Vector3);
/* Creating standard_surface */
NodeItem res = create_node("standard_surface", "surfaceshader");
NodeItem res = create_node("standard_surface", shader_type_);
res.set_input("base", 1.0, "float");
res.set_input("base_color", base_color);
res.set_input("diffuse_roughness", roughness);

View File

@ -15,7 +15,7 @@ NodeItem EmissionNodeParser::compute()
NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
NodeItem strength = get_input_value("Strength", NodeItem::Type::Float);
NodeItem res = create_node("uniform_edf", "EDF");
NodeItem res = create_node("uniform_edf", shader_type_);
res.set_input("color", color * strength);
return res;
}

View File

@ -19,12 +19,12 @@ NodeItem HueSatValNodeParser::compute()
/* Modifier to follow Cycles result */
hue = hue - value(0.5f);
NodeItem combine = create_node("combine3", "vector3");
NodeItem combine = create_node("combine3", NodeItem::Type::Vector3);
combine.set_input("in1", hue);
combine.set_input("in2", saturation);
combine.set_input("in3", val);
NodeItem res = create_node("hsvadjust", "color3");
NodeItem res = create_node("hsvadjust", NodeItem::Type::Color3);
res.set_input("in", color);
res.set_input("amount", combine);
return res;

View File

@ -23,7 +23,7 @@ NodeItem MixShaderNodeParser::compute()
res = shader2 * fac;
}
else if (shader1 && shader2) {
res = create_node("mix", NodeItem::type(shader_type_));
res = create_node("mix", shader_type_);
res.set_input("fg", shader1);
res.set_input("bg", shader2);
res.set_input("mix", fac);

View File

@ -39,10 +39,10 @@ std::string NodeParser::node_name()
std::string(node_->name) + "_" + socket_out_->name);
}
NodeItem NodeParser::create_node(const std::string &mx_category, const std::string &mx_type)
NodeItem NodeParser::create_node(const std::string &mx_category, NodeItem::Type type)
{
NodeItem res = empty();
res.node = graph_->addNode(mx_category, MaterialX::EMPTY_STRING, mx_type);
res.node = graph_->addNode(mx_category, MaterialX::EMPTY_STRING, NodeItem::type(type));
return res;
}

View File

@ -33,7 +33,7 @@ class NodeParser {
protected:
virtual NodeItem compute_full();
virtual std::string node_name();
NodeItem create_node(const std::string &mx_category, const std::string &mx_type);
NodeItem create_node(const std::string &mx_category, NodeItem::Type type);
NodeItem get_input_default(const std::string &name, NodeItem::Type to_type);
NodeItem get_input_default(int index, NodeItem::Type to_type);
NodeItem get_input_link(const std::string &name, NodeItem::Type to_type);

View File

@ -14,7 +14,7 @@ NodeItem NormalMapNodeParser::compute()
NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
NodeItem strength = get_input_value("Strength", NodeItem::Type::Float);
NodeItem res = create_node("normalmap", "vector3");
NodeItem res = create_node("normalmap", NodeItem::Type::Vector3);
res.set_input("in", color);
res.set_input("scale", strength);

View File

@ -20,7 +20,7 @@ NodeItem OutputMaterialNodeParser::compute()
NodeItem bsdf = get_input_shader("Surface", NodeItem::Type::BSDF);
NodeItem edf = get_input_shader("Surface", NodeItem::Type::EDF);
if (bsdf || edf) {
surface = create_node("surface", "surfaceshader");
surface = create_node("surface", NodeItem::Type::SurfaceShader);
if (bsdf) {
surface.set_input("bsdf", bsdf);
}
@ -33,17 +33,17 @@ NodeItem OutputMaterialNodeParser::compute()
}
}
else {
surface = create_node("standard_surface", "surfaceshader");
surface = create_node("standard_surface", NodeItem::Type::SurfaceShader);
surface.set_input("base_color", value(MaterialX::Color3(1.0f, 0.0f, 1.0f)));
}
NodeItem res = create_node("surfacematerial", "material");
NodeItem res = create_node("surfacematerial", shader_type_);
res.set_input("surfaceshader", surface);
return res;
}
NodeItem OutputMaterialNodeParser::compute_default()
{
NodeItem surface = create_node("standard_surface", "surfaceshader");
NodeItem surface = create_node("standard_surface", NodeItem::Type::SurfaceShader);
surface.set_input("base_color",
value(MaterialX::Color3(material_->r, material_->g, material_->b)));
surface.set_input("diffuse_roughness", value(material_->roughness));
@ -56,7 +56,7 @@ NodeItem OutputMaterialNodeParser::compute_default()
surface.set_input("specular_roughness", value(material_->roughness));
}
NodeItem res = create_node("surfacematerial", "material");
NodeItem res = create_node("surfacematerial", shader_type_);
res.node->setName("Material_Default");
res.set_input("surfaceshader", surface);
return res;

View File

@ -18,12 +18,12 @@ NodeItem SeparateColorNodeParser::compute()
case NODE_COMBSEP_COLOR_RGB:
break;
case NODE_COMBSEP_COLOR_HSV:
convert = create_node("rgbtohsv", "color3");
convert = create_node("rgbtohsv", NodeItem::Type::Color3);
convert.set_input("in", color);
break;
case NODE_COMBSEP_COLOR_HSL:
CLOG_WARN(LOG_MATERIALX_SHADER, "Unsupported color model, using HSV instead: %d", mode);
convert = create_node("rgbtohsv", "color3");
convert = create_node("rgbtohsv", NodeItem::Type::Color3);
convert.set_input("in", color);
break;
default:
@ -44,7 +44,7 @@ NodeItem CombineColorNodeParser::compute()
NodeItem blue = get_input_value("Blue", NodeItem::Type::Float);
NodeItem convert = empty();
NodeItem combine = create_node("combine3", "color3");
NodeItem combine = create_node("combine3", NodeItem::Type::Color3);
combine.set_input("in1", red);
combine.set_input("in2", green);
combine.set_input("in3", blue);
@ -53,12 +53,12 @@ NodeItem CombineColorNodeParser::compute()
case NODE_COMBSEP_COLOR_RGB:
break;
case NODE_COMBSEP_COLOR_HSV:
convert = create_node("hsvtorgb", "color3");
convert = create_node("hsvtorgb", NodeItem::Type::Color3);
convert.set_input("in", combine);
break;
case NODE_COMBSEP_COLOR_HSL:
CLOG_WARN(LOG_MATERIALX_SHADER, "Unsupported color model, using HSV instead: %d", mode);
convert = create_node("hsvtorgb", "color3");
convert = create_node("hsvtorgb", NodeItem::Type::Color3);
convert.set_input("in", combine);
break;
default:

View File

@ -18,7 +18,7 @@ NodeItem CombineXYZNodeParser::compute()
NodeItem x = get_input_value("X", NodeItem::Type::Float);
NodeItem y = get_input_value("Y", NodeItem::Type::Float);
NodeItem z = get_input_value("Z", NodeItem::Type::Float);
NodeItem res = create_node("combine3", "vector3");
NodeItem res = create_node("combine3", NodeItem::Type::Vector3);
res.set_input("in1", x);
res.set_input("in2", y);
res.set_input("in3", z);

View File

@ -14,12 +14,12 @@ NodeItem TexCheckerNodeParser::compute()
NodeItem scale = get_input_value("Scale", NodeItem::Type::Float);
if (!vector) {
vector = create_node("texcoord", "vector2");
vector = create_node("texcoord", NodeItem::Type::Vector2);
}
vector = (vector * scale) % value(2.0f);
NodeItem mix = (vector.extract(0).floor() + vector.extract(1).floor())
.if_else(NodeItem::CompareOp::Eq, value(1.0f), value(1.0f), value(0.0f));
NodeItem res = create_node("mix", "color3");
NodeItem res = create_node("mix", NodeItem::Type::Color3);
res.set_input("fg", color1);
res.set_input("bg", color2);
res.set_input("mix", mix);

View File

@ -23,8 +23,8 @@ NodeItem TexEnvironmentNodeParser::compute()
image_path = io::hydra::cache_or_get_image_file(bmain, scene, image, &tex->iuser);
#endif
NodeItem texcoord = create_node("texcoord", "vector2");
NodeItem res = create_node("image", "color3");
NodeItem texcoord = create_node("texcoord", NodeItem::Type::Vector2);
NodeItem res = create_node("image", NodeItem::Type::Color3);
res.set_input("file", image_path, "filename");
res.set_input("texcoord", texcoord);
return res;

View File

@ -23,8 +23,8 @@ NodeItem TexImageNodeParser::compute()
image_path = io::hydra::cache_or_get_image_file(bmain, scene, image, &tex->iuser);
#endif
NodeItem texcoord = create_node("texcoord", "vector2");
NodeItem res = create_node("image", "color3");
NodeItem texcoord = create_node("texcoord", NodeItem::Type::Vector2);
NodeItem res = create_node("image", NodeItem::Type::Color3);
res.set_input("file", image_path, "filename");
res.set_input("texcoord", texcoord);
return res;

View File

@ -16,10 +16,10 @@ NodeItem TexNoiseNodeParser::compute()
detail = value(int(detail.value->asA<float>()));
}
NodeItem position = create_node("position", "vector3");
NodeItem position = create_node("position", NodeItem::Type::Vector3);
position = position * scale;
NodeItem res = create_node("fractal3d", "color3");
NodeItem res = create_node("fractal3d", NodeItem::Type::Color3);
res.set_input("position", position);
res.set_input("octaves", detail);
res.set_input("lacunarity", lacunarity);