MaterialX logging #7

Merged
Bogdan Nagirniak merged 3 commits from BogdanNagirniak/blender:matx-logging into matx-export-material 2023-08-31 20:11:18 +02:00
2 changed files with 27 additions and 18 deletions
Showing only changes of commit 5779298f55 - Show all commits

View File

@ -72,8 +72,12 @@ NodeItem BSDFPrincipledNodeParser::compute()
res.set_input("base", 1.0, "float"); res.set_input("base", 1.0, "float");
res.set_input("base_color", base_color.to_color3()); res.set_input("base_color", base_color.to_color3());
res.set_input("diffuse_roughness", roughness); res.set_input("diffuse_roughness", roughness);
if (normal) {
res.set_input("normal", normal); res.set_input("normal", normal);
}
if (tangent) {
res.set_input("tangent", tangent); res.set_input("tangent", tangent);
}
if (metallic != zero) { if (metallic != zero) {
res.set_input("metalness", metallic); res.set_input("metalness", metallic);
@ -84,9 +88,11 @@ NodeItem BSDFPrincipledNodeParser::compute()
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);
res.set_input("specular_IOR", ior); res.set_input("specular_IOR", ior);
if (anisotropic) {
res.set_input("specular_anisotropy", anisotropic); res.set_input("specular_anisotropy", anisotropic);
res.set_input("specular_rotation", anisotropic_rotation); res.set_input("specular_rotation", anisotropic_rotation);
} }
}
if (transmission != zero) { if (transmission != zero) {
res.set_input("transmission", transmission); res.set_input("transmission", transmission);
@ -98,8 +104,10 @@ NodeItem BSDFPrincipledNodeParser::compute()
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);
if (anisotropic) {
res.set_input("subsurface_anisotropy", anisotropic); res.set_input("subsurface_anisotropy", anisotropic);
} }
}
if (sheen != zero) { if (sheen != zero) {
res.set_input("sheen", sheen); res.set_input("sheen", sheen);
@ -112,8 +120,10 @@ NodeItem BSDFPrincipledNodeParser::compute()
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);
res.set_input("coat_IOR", ior); res.set_input("coat_IOR", ior);
if (anisotropic) {
res.set_input("coat_anisotropy", anisotropic); res.set_input("coat_anisotropy", anisotropic);
res.set_input("coat_rotation", anisotropic_rotation); res.set_input("coat_rotation", anisotropic_rotation);
}
res.set_input("coat_normal", clearcoat_normal); res.set_input("coat_normal", clearcoat_normal);
} }

View File

@ -25,6 +25,9 @@ void NodeItem::set_input(const std::string &name, const NodeItem &item)
else if (item.node) { else if (item.node) {
set_input(name, item.node); set_input(name, item.node);
} }
else {
CLOG_WARN(LOG_MATERIALX_SHADER, "Empty item to input: %s", name.c_str());
}
} }
void NodeItem::set_input(const std::string &name, const MaterialX::ValuePtr value) void NodeItem::set_input(const std::string &name, const MaterialX::ValuePtr value)
@ -232,10 +235,6 @@ NodeItem NodeItem::if_else(const std::string &condition,
NodeItem res = empty(); NodeItem res = empty();
if (type() != "float" || other.type() != "float") { if (type() != "float" || other.type() != "float") {
CLOG_WARN(LOG_MATERIALX_SHADER,
"Incorrect condition types: %s, %s",
type().c_str(),
other.type().c_str());
return res; return res;
} }
@ -365,27 +364,27 @@ NodeItem NodeItem::exp() const
NodeItem NodeItem::to_color3() const NodeItem NodeItem::to_color3() const
{ {
std::string t = type(); std::string mx_type = type();
NodeItem res = empty(); NodeItem res = empty();
if (value) { if (value) {
MaterialX::Color3 c; MaterialX::Color3 c;
if (t == "float") { if (mx_type == "float") {
float v = value->asA<float>(); float v = value->asA<float>();
c = {v, v, v}; c = {v, v, v};
} }
else if (t == "color3") { else if (mx_type == "color3") {
auto v = value->asA<MaterialX::Color3>(); auto v = value->asA<MaterialX::Color3>();
c = {v[0], v[1], v[2]}; c = {v[0], v[1], v[2]};
} }
else if (t == "color4") { else if (mx_type == "color4") {
auto v = value->asA<MaterialX::Color4>(); auto v = value->asA<MaterialX::Color4>();
c = {v[0], v[1], v[2]}; c = {v[0], v[1], v[2]};
} }
else if (t == "vector3") { else if (mx_type == "vector3") {
auto v = value->asA<MaterialX::Vector3>(); auto v = value->asA<MaterialX::Vector3>();
c = {v[0], v[1], v[2]}; c = {v[0], v[1], v[2]};
} }
else if (t == "vector4") { else if (mx_type == "vector4") {
auto v = value->asA<MaterialX::Vector4>(); auto v = value->asA<MaterialX::Vector4>();
c = {v[0], v[1], v[2]}; c = {v[0], v[1], v[2]};
} }
@ -395,7 +394,7 @@ NodeItem NodeItem::to_color3() const
res.value = MaterialX::Value::createValue<MaterialX::Color3>(c); res.value = MaterialX::Value::createValue<MaterialX::Color3>(c);
} }
else if (node) { else if (node) {
if (t != "color3") { if (mx_type != "color3") {
return res; return res;
} }
res.node = node; res.node = node;