MaterialX: add support for nodes #11

Merged
Bogdan Nagirniak merged 17 commits from matx-add-other-nodes into matx-export-material 2023-09-06 10:37:26 +02:00
Showing only changes of commit 8c03750367 - Show all commits

View File

@ -8,54 +8,34 @@ namespace blender::nodes::materialx {
NodeItem BSDFPrincipledNodeParser::compute() NodeItem BSDFPrincipledNodeParser::compute()
{ {
NodeItem zero = value(0.0f);
/* 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 */
NodeItem base_color = get_input_value("Base Color"); NodeItem base_color = get_input_value("Base Color");
NodeItem subsurface = get_input_value("Subsurface"); NodeItem subsurface = get_input_value("Subsurface");
NodeItem subsurface_radius = empty(); NodeItem subsurface_radius = get_input_value("Subsurface Radius");
NodeItem subsurface_color = empty(); NodeItem subsurface_color = get_input_value("Subsurface Color");
if (subsurface != zero) {
subsurface_radius = get_input_value("Subsurface Radius");
subsurface_color = get_input_value("Subsurface Color");
}
NodeItem metallic = get_input_value("Metallic"); NodeItem metallic = get_input_value("Metallic");
NodeItem specular = get_input_value("Specular"); NodeItem specular = get_input_value("Specular");
// NodeItem specular_tint = get_input_value("Specular Tint"); // NodeItem specular_tint = get_input_value("Specular Tint");
NodeItem roughness = get_input_value("Roughness"); NodeItem roughness = get_input_value("Roughness");
NodeItem anisotropic = empty(); /* TODO: use Specular Tint input */
NodeItem anisotropic_rotation = empty(); NodeItem anisotropic = get_input_value("Anisotropic");
if (metallic != zero) { NodeItem anisotropic_rotation = get_input_value("Anisotropic Rotation");
/* TODO: use Specular Tint input */ // anisotropic_rotation = 0.5 - (anisotropic_rotation % 1.0)
anisotropic = get_input_value("Anisotropic");
if (anisotropic != zero) {
anisotropic_rotation = get_input_value("Anisotropic Rotation");
// anisotropic_rotation = 0.5 - (anisotropic_rotation % 1.0)
}
}
NodeItem sheen = get_input_value("Sheen"); NodeItem sheen = get_input_value("Sheen");
// sheen_tint = empty(); // sheen_tint = get_input_value("Sheen Tint");
// if enabled(sheen):
// sheen_tint = get_input_value("Sheen Tint");
NodeItem clearcoat = get_input_value("Clearcoat"); NodeItem clearcoat = get_input_value("Clearcoat");
NodeItem clearcoat_roughness = empty(); NodeItem clearcoat_roughness = get_input_value("Clearcoat Roughness");
if (clearcoat != zero) {
clearcoat_roughness = get_input_value("Clearcoat Roughness");
}
NodeItem ior = get_input_value("IOR"); NodeItem ior = get_input_value("IOR");
NodeItem transmission = get_input_value("Transmission"); NodeItem transmission = get_input_value("Transmission");
NodeItem transmission_roughness = empty(); NodeItem transmission_roughness = get_input_value("Transmission Roughness");
if (transmission != zero) {
transmission_roughness = get_input_value("Transmission Roughness");
}
NodeItem emission = get_input_value("Emission"); NodeItem emission = get_input_value("Emission");
NodeItem emission_strength = get_input_value("Emission Strength"); NodeItem emission_strength = get_input_value("Emission Strength");
@ -72,67 +52,40 @@ 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); res.set_input("tangent", tangent);
} res.set_input("metalness", metallic);
if (tangent) {
res.set_input("tangent", tangent);
}
if (metallic != zero) { res.set_input("specular", specular);
res.set_input("metalness", metallic); res.set_input("specular_color", base_color.to_color3());
} res.set_input("specular_roughness", roughness);
res.set_input("specular_IOR", ior);
res.set_input("specular_anisotropy", anisotropic);
res.set_input("specular_rotation", anisotropic_rotation);
if (specular != zero) { res.set_input("transmission", transmission);
res.set_input("specular", specular); res.set_input("transmission_color", base_color.to_color3());
res.set_input("specular_color", base_color.to_color3()); res.set_input("transmission_extra_roughness", transmission_roughness);
res.set_input("specular_roughness", roughness);
res.set_input("specular_IOR", ior);
if (anisotropic) {
res.set_input("specular_anisotropy", anisotropic);
if (anisotropic_rotation) {
res.set_input("specular_rotation", anisotropic_rotation);
}
}
}
if (transmission != zero) { res.set_input("subsurface", subsurface);
res.set_input("transmission", transmission); res.set_input("subsurface_color", subsurface_color);
res.set_input("transmission_color", base_color.to_color3()); res.set_input("subsurface_radius", subsurface_radius);
res.set_input("transmission_extra_roughness", transmission_roughness); res.set_input("subsurface_anisotropy", anisotropic);
}
if (subsurface != zero) { res.set_input("sheen", sheen);
res.set_input("subsurface", subsurface); res.set_input("sheen_color", base_color.to_color3());
res.set_input("subsurface_color", subsurface_color); res.set_input("sheen_roughness", roughness);
res.set_input("subsurface_radius", subsurface_radius);
if (anisotropic) {
res.set_input("subsurface_anisotropy", anisotropic);
}
}
if (sheen != zero) { res.set_input("coat", clearcoat);
res.set_input("sheen", sheen); res.set_input("coat_color", base_color.to_color3());
res.set_input("sheen_color", base_color.to_color3()); res.set_input("coat_roughness", clearcoat_roughness);
res.set_input("sheen_roughness", roughness); res.set_input("coat_IOR", ior);
} res.set_input("coat_anisotropy", anisotropic);
res.set_input("coat_rotation", anisotropic_rotation);
res.set_input("coat_normal", clearcoat_normal);
if (clearcoat != zero) { res.set_input("emission", emission_strength);
res.set_input("coat", clearcoat); res.set_input("emission_color", emission);
res.set_input("coat_color", base_color.to_color3());
res.set_input("coat_roughness", clearcoat_roughness);
res.set_input("coat_IOR", ior);
if (anisotropic) {
res.set_input("coat_anisotropy", anisotropic);
res.set_input("coat_rotation", anisotropic_rotation);
}
res.set_input("coat_normal", clearcoat_normal);
}
if (emission != zero) {
res.set_input("emission", emission_strength);
res.set_input("emission_color", emission);
}
return res; return res;
} }