MaterialX: split standard_surface into basic nodes #26

Merged
Bogdan Nagirniak merged 11 commits from matx-principlebsdf-split into matx-export-material 2023-09-21 10:58:14 +02:00
2 changed files with 233 additions and 189 deletions
Showing only changes of commit 4a2633b85d - Show all commits

View File

@ -287,11 +287,6 @@ static void node_shader_update_principled(bNodeTree *ntree, bNode *node)
NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX
{
if (to_type_ != NodeItem::Type::SurfaceShader) {
/* TODO: implement for BSDF and EDF */
return empty();
}
NodeItem base_color = get_input_value("Base Color", NodeItem::Type::Color3);
NodeItem subsurface = get_input_value("Subsurface", NodeItem::Type::Float);
@ -330,6 +325,8 @@ NODE_SHADER_MATERIALX_BEGIN
subsurface_radius = subsurface_radius * subsurface_scale;
NodeItem res = empty();
if (to_type_ == NodeItem::Type::BSDF) {
NodeItem n_main_tangent = empty();
if (tangent) {
NodeItem n_tangent_rotate = create_node("rotate3d", NodeItem::Type::Vector3);
@ -344,7 +341,8 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem::CompareOp::Greater, val(0.0f), n_tangent_rotate_normalize, tangent);
}
NodeItem n_coat_roughness_vector = create_node("roughness_anisotropy", NodeItem::Type::Vector2);
NodeItem n_coat_roughness_vector = create_node("roughness_anisotropy",
NodeItem::Type::Vector2);
n_coat_roughness_vector.set_input("roughness", roughness);
n_coat_roughness_vector.set_input("anisotropy", anisotropic);
@ -423,7 +421,8 @@ NODE_SHADER_MATERIALX_BEGIN
(roughness + roughness).clamp(0.0f, 1.0f));
n_coat_affected_transmission_roughness.set_input("mix", n_coat_affect_roughness_multiply2);
NodeItem n_transmission_roughness = create_node("roughness_anisotropy", NodeItem::Type::Vector2);
NodeItem n_transmission_roughness = create_node("roughness_anisotropy",
NodeItem::Type::Vector2);
n_transmission_roughness.set_input("roughness", n_coat_affected_transmission_roughness);
n_transmission_roughness.set_input("anisotropy", anisotropic);
@ -505,22 +504,67 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem n_opacity_luminance = create_node("luminance", NodeItem::Type::Color3);
n_opacity_luminance.set_input("in", val(MaterialX::Color3(1.0f, 1.0f, 1.0f)));
NodeItem n_emission_edf = create_node("uniform_edf", NodeItem::Type::EDF);
n_emission_edf.set_input("color", emission * emission_strength);
NodeItem n_coat_attenuation = create_node("mix", NodeItem::Type::Color3);
n_coat_attenuation.set_input("fg", base_color);
n_coat_attenuation.set_input("bg", val(MaterialX::Color3(1.0f, 1.0f, 1.0f)));
n_coat_attenuation.set_input("mix", coat);
NodeItem n_coat_layer = create_node("layer", NodeItem::Type::BSDF);
n_coat_layer.set_input("top", n_coat_bsdf);
n_coat_layer.set_input("base", n_thin_film_layer * n_coat_attenuation);
res = create_node("layer", NodeItem::Type::BSDF);
res.set_input("top", n_coat_bsdf);
res.set_input("base", n_thin_film_layer * n_coat_attenuation);
NodeItem res = create_node("surface", NodeItem::Type::SurfaceShader);
res.set_input("bsdf", n_coat_layer);
res.set_input("edf", n_emission_edf);
res.set_input("opacity", n_opacity_luminance.extract(0));
return res;
}
else if (to_type_ == NodeItem::Type::EDF) {
res = create_node("uniform_edf", NodeItem::Type::EDF);
res.set_input("color", emission * emission_strength);
DagerD marked this conversation as resolved Outdated

This node is created in MaterialOutput.
Should be:

if (to_type_ == NodeItem::Type::BSDF) {
<calculate and return only BSDF part>
....
return n_coat_layer; // probably n_coat_layer * n_opacity_luminance
}
else if (to_type_ == NodeItem::Type::EDF) {
<calculate and return only EDF part>
...
return n_emission_edf; // probably n_emission_edf * n_opacity_luminance
}
else if (to_type_ == NodeItem::Type::SurfaceShader) {
<previous implementation>
}
This node is created in MaterialOutput. Should be: ``` if (to_type_ == NodeItem::Type::BSDF) { <calculate and return only BSDF part> .... return n_coat_layer; // probably n_coat_layer * n_opacity_luminance } else if (to_type_ == NodeItem::Type::EDF) { <calculate and return only EDF part> ... return n_emission_edf; // probably n_emission_edf * n_opacity_luminance } else if (to_type_ == NodeItem::Type::SurfaceShader) { <previous implementation> } ```
}
else if (to_type_ == NodeItem::Type::SurfaceShader) {
res = create_node("standard_surface", NodeItem::Type::SurfaceShader);
res.set_input("base", val(1.0f));
res.set_input("base_color", base_color);
res.set_input("diffuse_roughness", roughness);
if (normal) {
res.set_input("normal", normal);
}
if (tangent) {
res.set_input("tangent", tangent);
}
res.set_input("metalness", metallic);
res.set_input("specular", specular);
res.set_input("specular_color", base_color);
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);
res.set_input("transmission", transmission);
res.set_input("transmission_color", base_color);
res.set_input("transmission_extra_roughness", roughness);
res.set_input("subsurface", subsurface);
res.set_input("subsurface_color", base_color);
res.set_input("subsurface_radius", subsurface_radius);
res.set_input("subsurface_anisotropy", anisotropic);
res.set_input("sheen", sheen);
res.set_input("sheen_color", base_color);
res.set_input("sheen_roughness", roughness);
res.set_input("coat", coat);
res.set_input("coat_color", base_color);
res.set_input("coat_roughness", coat_roughness);
res.set_input("coat_IOR", ior);
res.set_input("coat_anisotropy", anisotropic);
res.set_input("coat_rotation", anisotropic_rotation);
if (coat_normal) {
res.set_input("coat_normal", coat_normal);
}
res.set_input("emission", emission_strength);
res.set_input("emission_color", emission);
}
return res;
}

View File

@ -42,8 +42,8 @@ NODE_SHADER_MATERIALX_BEGIN
}
else if (shader1 && shader2) {
res = create_node("mix", to_type_);
res.set_input("fg", shader1);
res.set_input("bg", shader2);
res.set_input("fg", shader2);
res.set_input("bg", shader1);
res.set_input("mix", fac);
}
break;