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 79 additions and 85 deletions
Showing only changes of commit 0201383a4c - Show all commits

View File

@ -51,9 +51,11 @@ class NodeItem {
MaterialX::OutputPtr output;
private:
MaterialX::GraphElement *graph_;
MaterialX::GraphElement *graph_ = nullptr;
public:
/* Default constructor added to allow easy work with std::map. Don't use this constructor to create NodeItem. */
NodeItem() = default;
NodeItem(MaterialX::GraphElement *graph);
~NodeItem() = default;

View File

@ -328,18 +328,18 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem res = empty();
if (to_type_ == NodeItem::Type::BSDF) {
auto inputs = bsdf_inputs();
auto in = bsdf_inputs();
NodeItem roughness = inputs.find("roughness")->second;
NodeItem anisotropy = inputs.find("anisotropic")->second;
NodeItem rotation = inputs.find("anisotropic_rotation")->second;
NodeItem base_color = inputs.find("base_color")->second;
NodeItem specular = inputs.find("specular")->second;
NodeItem coat = inputs.find("coat")->second;
NodeItem ior = inputs.find("ior")->second;
NodeItem normal = inputs.find("normal")->second;
NodeItem tangent = inputs.find("tangent")->second;
NodeItem coat_normal = inputs.find("coat_normal")->second;
NodeItem roughness = in["roughness"];
NodeItem anisotropy = in["anisotropic"];
NodeItem rotation = in["anisotropic_rotation"];
NodeItem base_color = in["base_color"];
NodeItem specular = in["specular"];
NodeItem coat = in["coat"];
DagerD marked this conversation as resolved Outdated

Rewrite create_node() with inputs parameter inside function.

Rewrite `create_node()` with `inputs` parameter inside function.
NodeItem ior = in["ior"];
NodeItem normal = in["normal"];
NodeItem tangent = in["tangent"];
NodeItem coat_normal = in["coat_normal"];
NodeItem n_main_tangent = empty();
if (tangent && normal) {
@ -358,13 +358,13 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem n_coat_roughness_vector = create_node(
"roughness_anisotropy",
NodeItem::Type::Vector2,
{{"roughness", inputs.find("coat_roughness")->second}, {"anisotropy", anisotropy}});
{{"roughness", in["coat_roughness"]}, {"anisotropy", anisotropy}});
NodeItem n_coat_bsdf = create_node("dielectric_bsdf",
NodeItem::Type::BSDF,
{{"weight", coat},
{"tint", inputs.find("coat_tint")->second},
{"ior", inputs.find("coat_ior")->second},
{"tint", in["coat_tint"]},
{"ior", in["coat_ior"]},
{"scatter_mode", val(std::string("R"))},
{"roughness", n_coat_roughness_vector},
{"normal", coat_normal}});
@ -395,8 +395,7 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem n_ior_out = n_artistic_ior.add_output("ior", NodeItem::Type::Color3);
NodeItem n_extinction_out = n_artistic_ior.add_output("extinction", NodeItem::Type::Color3);
NodeItem n_coat_affect_roughness_multiply2 = coat * val(0.0f) *
inputs.find("coat_roughness")->second;
NodeItem n_coat_affect_roughness_multiply2 = coat * val(0.0f) * in["coat_roughness"];
NodeItem n_coat_affected_roughness = create_node(
"mix",
NodeItem::Type::Float,
@ -418,7 +417,7 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem n_specular_bsdf = create_node("dielectric_bsdf",
NodeItem::Type::BSDF,
{{"weight", specular},
{"tint", inputs.find("specular_tint")->second},
{"tint", in["specular_tint"]},
{"ior", ior},
{"scatter_mode", val(std::string("R"))},
{"roughness", n_main_roughness},
@ -456,9 +455,8 @@ NODE_SHADER_MATERIALX_BEGIN
"subsurface_bsdf",
NodeItem::Type::BSDF,
{{"color", n_coat_affected_subsurface_color},
{"radius",
inputs.find("subsurface_radius")->second * inputs.find("subsurface_scale")->second},
{"anisotropy", inputs.find("subsurface_anisotropy")->second},
{"radius", in["subsurface_radius"] * in["subsurface_scale"]},
{"anisotropy", in["subsurface_anisotropy"]},
{"normal", normal}});
NodeItem n_selected_subsurface_bsdf = create_node(
@ -468,9 +466,9 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem n_sheen_bsdf = create_node("sheen_bsdf",
NodeItem::Type::BSDF,
{{"weight", inputs.find("sheen")->second},
{"color", inputs.find("sheen_tint")->second},
{"roughness", inputs.find("sheen_roughness")->second},
{{"weight", in["sheen"]},
{"color", in["sheen_tint"]},
{"roughness", in["sheen_roughness"]},
{"normal", normal}});
NodeItem n_diffuse_bsdf = create_node("oren_nayar_diffuse_bsdf",
@ -480,29 +478,26 @@ NODE_SHADER_MATERIALX_BEGIN
{"weight", val(1.0f)},
{"normal", normal}});
NodeItem n_subsurface_mix = create_node("mix",
NodeItem::Type::BSDF,
{{"fg", n_selected_subsurface_bsdf},
{"bg", n_diffuse_bsdf},
{"mix", inputs.find("subsurface")->second}});
NodeItem n_subsurface_mix = create_node(
"mix",
NodeItem::Type::BSDF,
{{"fg", n_selected_subsurface_bsdf}, {"bg", n_diffuse_bsdf}, {"mix", in["subsurface"]}});
NodeItem n_sheen_layer = create_node(
"layer", NodeItem::Type::BSDF, {{"top", n_sheen_bsdf}, {"base", n_subsurface_mix}});
NodeItem n_transmission_mix = create_node("mix",
NodeItem::Type::BSDF,
{{"fg", n_transmission_bsdf},
{"bg", n_sheen_layer},
{"mix", inputs.find("transmission")->second}});
NodeItem n_transmission_mix = create_node(
"mix",
NodeItem::Type::BSDF,
{{"fg", n_transmission_bsdf}, {"bg", n_sheen_layer}, {"mix", in["transmission"]}});
NodeItem n_specular_layer = create_node(
"layer", NodeItem::Type::BSDF, {{"top", n_specular_bsdf}, {"base", n_transmission_mix}});
NodeItem n_metalness_mix = create_node("mix",
NodeItem::Type::BSDF,
{{"fg", n_metal_bsdf},
{"bg", n_specular_layer},
{"mix", inputs.find("metallic")->second}});
NodeItem n_metalness_mix = create_node(
"mix",
NodeItem::Type::BSDF,
{{"fg", n_metal_bsdf}, {"bg", n_specular_layer}, {"mix", in["metallic"]}});
NodeItem n_thin_film_layer = create_node(
"layer", NodeItem::Type::BSDF, {{"top", n_thin_film_bsdf}, {"base", n_metalness_mix}});
@ -512,7 +507,7 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem n_coat_attenuation = create_node("mix",
NodeItem::Type::Color3,
{{"fg", inputs.find("coat_tint")->second},
{{"fg", in["coat_tint"]},
{"bg", val(MaterialX::Color3(1.0f, 1.0f, 1.0f))},
{"mix", coat}});
@ -521,57 +516,54 @@ NODE_SHADER_MATERIALX_BEGIN
{{"top", n_coat_bsdf}, {"base", n_thin_film_layer * n_coat_attenuation}});
}
else if (to_type_ == NodeItem::Type::EDF) {
auto inputs = edf_inputs();
auto in = edf_inputs();
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> } ```
res = create_node(
"uniform_edf",
NodeItem::Type::EDF,
{{"color", inputs.find("emission_color")->second * inputs.find("emission")->second}});
"uniform_edf", NodeItem::Type::EDF, {{"color", in["emission_color"] * in["emission"]}});
}
else if (to_type_ == NodeItem::Type::SurfaceShader) {
auto b_inputs = bsdf_inputs();
auto e_inputs = edf_inputs();
auto in = bsdf_inputs();
auto e_in = edf_inputs();
in.insert(e_in.begin(), e_in.end());
NodeItem roughness = b_inputs.find("roughness")->second;
NodeItem base_color = b_inputs.find("base_color")->second;
NodeItem anisotropic = b_inputs.find("anisotropic")->second;
NodeItem rotation = b_inputs.find("anisotropic_rotation")->second;
NodeItem roughness = in["roughness"];
NodeItem base_color = in["base_color"];
NodeItem anisotropic = in["anisotropic"];
NodeItem rotation = in["anisotropic_rotation"];
res = create_node(
"standard_surface",
NodeItem::Type::SurfaceShader,
{{"base", val(1.0f)},
{"base_color", base_color},
{"diffuse_roughness", roughness},
{"metalness", b_inputs.find("metallic")->second},
{"specular", b_inputs.find("specular")->second},
{"specular_color", b_inputs.find("specular_tint")->second},
{"specular_roughness", roughness},
{"specular_IOR", b_inputs.find("ior")->second},
{"specular_anisotropy", anisotropic},
{"specular_rotation", rotation},
{"transmission", b_inputs.find("transmission")->second},
{"transmission_color", base_color},
{"transmission_extra_roughness", roughness},
{"subsurface", b_inputs.find("subsurface")->second},
{"subsurface_color", base_color},
{"subsurface_radius",
b_inputs.find("subsurface_radius")->second * b_inputs.find("subsurface_scale")->second},
{"subsurface_anisotropy", b_inputs.find("subsurface_anisotropy")->second},
{"sheen", b_inputs.find("sheen")->second},
{"sheen_color", b_inputs.find("sheen_tint")->second},
{"sheen_roughness", b_inputs.find("sheen_roughness")->second},
{"coat", b_inputs.find("coat")->second},
{"coat_color", b_inputs.find("coat_tint")->second},
{"coat_roughness", b_inputs.find("coat_roughness")->second},
{"coat_IOR", b_inputs.find("coat_ior")->second},
{"coat_anisotropy", anisotropic},
{"coat_rotation", rotation},
{"coat_normal", b_inputs.find("coat_normal")->second},
{"emission", e_inputs.find("emission")->second},
{"emission_color", e_inputs.find("emission_color")->second},
{"normal", b_inputs.find("normal")->second},
{"tangent", b_inputs.find("tangent")->second}});
res = create_node("standard_surface",
NodeItem::Type::SurfaceShader,
{{"base", val(1.0f)},
{"base_color", base_color},
{"diffuse_roughness", roughness},
{"metalness", in["metallic"]},
{"specular", in["specular"]},
{"specular_color", in["specular_tint"]},
{"specular_roughness", roughness},
{"specular_IOR", in["ior"]},
{"specular_anisotropy", anisotropic},
{"specular_rotation", rotation},
{"transmission", in["transmission"]},
{"transmission_color", base_color},
{"transmission_extra_roughness", roughness},
{"subsurface", in["subsurface"]},
{"subsurface_color", base_color},
{"subsurface_radius", in["subsurface_radius"] * in["subsurface_scale"]},
{"subsurface_anisotropy", in["subsurface_anisotropy"]},
{"sheen", in["sheen"]},
{"sheen_color", in["sheen_tint"]},
{"sheen_roughness", in["sheen_roughness"]},
{"coat", in["coat"]},
{"coat_color", in["coat_tint"]},
{"coat_roughness", in["coat_roughness"]},
{"coat_IOR", in["coat_ior"]},
{"coat_anisotropy", anisotropic},
{"coat_rotation", rotation},
{"coat_normal", in["coat_normal"]},
{"emission", in["emission"]},
{"emission_color", in["emission_color"]},
{"normal", in["normal"]},
{"tangent", in["tangent"]}});
}
else {
BLI_assert_unreachable();