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
Showing only changes of commit 7a2d2ae8e6 - Show all commits

View File

@ -289,99 +289,60 @@ static void node_shader_update_principled(bNodeTree *ntree, bNode *node)
NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX
{
/* NOTE: commented inputs aren't used for node creation. */
auto bsdf_inputs = [&]() {
NodeItem base_color = get_input_value("Base Color", NodeItem::Type::Color3);
NodeItem subsurface = get_input_value("Subsurface", NodeItem::Type::Float);
NodeItem subsurface_radius = get_input_value("Subsurface Radius", NodeItem::Type::Vector3);
NodeItem subsurface_scale = get_input_value("Subsurface Scale", NodeItem::Type::Float);
NodeItem metallic = get_input_value("Metallic", NodeItem::Type::Float);
NodeItem specular = get_input_value("Specular", NodeItem::Type::Float);
// NodeItem specular_tint = get_input_value("Specular Tint");
NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Float);
/* TODO: use Specular Tint input */
NodeItem anisotropic = get_input_value("Anisotropic", NodeItem::Type::Float);
NodeItem anisotropic_rotation = get_input_value("Anisotropic Rotation", NodeItem::Type::Float);
// anisotropic_rotation = 0.5 - (anisotropic_rotation % 1.0)
NodeItem sheen = get_input_value("Sheen", NodeItem::Type::Float);
// sheen_tint = get_input_value("Sheen Tint");
NodeItem coat = get_input_value("Coat", NodeItem::Type::Float);
NodeItem coat_roughness = get_input_value("Coat Roughness", NodeItem::Type::Float);
NodeItem ior = get_input_value("IOR", NodeItem::Type::Float);
NodeItem transmission = get_input_value("Transmission", NodeItem::Type::Float);
NodeItem alpha = get_input_value("Alpha", NodeItem::Type::Float);
// transparency = 1.0 - alpha
NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
NodeItem coat_normal = get_input_link("Coat Normal", NodeItem::Type::Vector3);
NodeItem tangent = get_input_link("Tangent", NodeItem::Type::Vector3);
subsurface_radius = subsurface_radius * subsurface_scale;
return std::map<std::string, NodeItem>{
{"base", val(1.0f)},
{"base_color", base_color},
{"diffuse_roughness", roughness},
{"normal", normal},
{"tangent", tangent},
{"metalness", metallic},
{"specular", specular},
{"specular_color", base_color},
{"specular_roughness", roughness},
{"specular_IOR", ior},
{"specular_anisotropy", anisotropic},
{"specular_rotation", anisotropic_rotation},
{"transmission", transmission},
{"transmission_color", base_color},
{"transmission_extra_roughness", roughness},
{"subsurface", subsurface},
{"subsurface_color", base_color},
{"subsurface_radius", subsurface_radius},
{"subsurface_anisotropy", anisotropic},
{"sheen", sheen},
{"sheen_color", base_color},
{"sheen_roughness", roughness},
{"coat", coat},
{"coat_color", base_color},
{"coat_roughness", coat_roughness},
{"coat_IOR", ior},
{"coat_anisotropy", anisotropic},
{"coat_rotation", anisotropic_rotation},
{"coat_normal", coat_normal},
{"base_color", get_input_value("Base Color", NodeItem::Type::Color3)},
{"subsurface", get_input_value("Subsurface", NodeItem::Type::Float)},
{"subsurface_scale", get_input_value("Subsurface Scale", NodeItem::Type::Float)},
{"subsurface_radius", get_input_value("Subsurface Radius", NodeItem::Type::Vector3)},
//{"subsurface_ior", get_input_value("Subsurface IOR", NodeItem::Type::Vector3)},
{"subsurface_anisotropy", get_input_value("Subsurface Anisotropy", NodeItem::Type::Float)},
{"metallic", get_input_value("Metallic", NodeItem::Type::Float)},
{"specular", get_input_value("Specular", NodeItem::Type::Float)},
{"specular_tint", get_input_value("Specular Tint", NodeItem::Type::Color3)},
{"roughness", get_input_value("Roughness", NodeItem::Type::Float)},
{"anisotropic", get_input_value("Anisotropic", NodeItem::Type::Float)},
{"anisotropic_rotation", get_input_value("Anisotropic Rotation", NodeItem::Type::Float)},
{"sheen", get_input_value("Sheen", NodeItem::Type::Float)},
{"sheen_roughness", get_input_value("Sheen Roughness", NodeItem::Type::Float)},
{"sheen_tint", get_input_value("Sheen Tint", NodeItem::Type::Color3)},
{"coat", get_input_value("Coat", NodeItem::Type::Float)},
{"coat_roughness", get_input_value("Coat Roughness", NodeItem::Type::Float)},
{"coat_ior", get_input_value("Coat IOR", NodeItem::Type::Float)},
{"coat_tint", get_input_value("Coat Tint", NodeItem::Type::Color3)},
{"ior", get_input_value("IOR", NodeItem::Type::Float)},
{"transmission", get_input_value("Transmission", NodeItem::Type::Float)},
//{"alpha", get_input_value("Alpha", NodeItem::Type::Float)},
{"normal", get_input_link("Normal", NodeItem::Type::Vector3)},
{"coat_normal", get_input_link("Coat Normal", NodeItem::Type::Vector3)},
{"tangent", get_input_link("Tangent", NodeItem::Type::Vector3)},
};
};
auto edf_inputs = [&]() {
NodeItem emission = get_input_value("Emission", NodeItem::Type::Color3);
NodeItem emission_strength = get_input_value("Emission Strength", NodeItem::Type::Float);
return std::map<std::string, NodeItem>{{"emission", emission_strength},
{"emission_color", emission}};
return std::map<std::string, NodeItem>{
{"emission", get_input_value("Emission Strength", NodeItem::Type::Float)},
{"emission_color", get_input_value("Emission", NodeItem::Type::Color3)}};
};
NodeItem res = empty();
if (to_type_ == NodeItem::Type::BSDF) {
auto inputs = bsdf_inputs();
NodeItem roughness = inputs.find("diffuse_roughness")->second;
NodeItem anisotropy = inputs.find("specular_anisotropy")->second;
NodeItem rotation = inputs.find("specular_rotation")->second;
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("specular_IOR")->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 n_main_tangent = empty();
if (tangent) {
if (tangent && normal) {
NodeItem n_tangent_rotate = create_node(
"rotate3d",
NodeItem::Type::Vector3,
@ -397,22 +358,22 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem n_coat_roughness_vector = create_node(
"roughness_anisotropy",
NodeItem::Type::Vector2,
{{"roughness", roughness}, {"anisotropy", anisotropy}});
{{"roughness", inputs.find("coat_roughness")->second}, {"anisotropy", anisotropy}});
NodeItem n_coat_bsdf = create_node("dielectric_bsdf",
NodeItem::Type::BSDF,
{{"weight", coat},
{"tint", val(MaterialX::Color3(1.0f, 1.0f, 1.0f))},
{"ior", ior},
{"tint", inputs.find("coat_tint")->second},
{"ior", inputs.find("coat_ior")->second},
{"scatter_mode", val(std::string("R"))},
{"roughness", n_coat_roughness_vector},
{"normal", normal}});
{"normal", coat_normal}});
if (tangent) {
if (tangent && coat_normal) {
NodeItem n_coat_tangent_rotate = create_node(
"rotate3d",
NodeItem::Type::Vector3,
{{"in", tangent}, {"amount", rotation * val(360.0f)}, {"axis", normal}});
{{"in", tangent}, {"amount", rotation * val(360.0f)}, {"axis", coat_normal}});
NodeItem n_coat_tangent_rotate_normalize = create_node(
"normalize", NodeItem::Type::Vector3, {{"in", n_coat_tangent_rotate}});
@ -434,7 +395,8 @@ 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) * roughness;
NodeItem n_coat_affect_roughness_multiply2 = coat * val(0.0f) *
inputs.find("coat_roughness")->second;
NodeItem n_coat_affected_roughness = create_node(
"mix",
NodeItem::Type::Float,
@ -456,7 +418,7 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem n_specular_bsdf = create_node("dielectric_bsdf",
NodeItem::Type::BSDF,
{{"weight", specular},
{"tint", base_color},
{"tint", inputs.find("specular_tint")->second},
{"ior", ior},
{"scatter_mode", val(std::string("R"))},
{"roughness", n_main_roughness},
@ -490,12 +452,14 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem::Type::BSDF,
{{"color", n_coat_affected_subsurface_color}, {"normal", normal}});
NodeItem n_subsurface_bsdf = create_node("subsurface_bsdf",
NodeItem::Type::BSDF,
{{"color", n_coat_affected_subsurface_color},
{"radius", inputs.find("subsurface_radius")->second},
{"anisotropy", anisotropy},
{"normal", normal}});
NodeItem n_subsurface_bsdf = create_node(
"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},
{"normal", normal}});
NodeItem n_selected_subsurface_bsdf = create_node(
"mix",
@ -505,8 +469,8 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem n_sheen_bsdf = create_node("sheen_bsdf",
NodeItem::Type::BSDF,
{{"weight", inputs.find("sheen")->second},
{"color", base_color},
{"roughness", roughness},
{"color", inputs.find("sheen_tint")->second},
{"roughness", inputs.find("sheen_roughness")->second},
{"normal", normal}});
NodeItem n_diffuse_bsdf = create_node("oren_nayar_diffuse_bsdf",
@ -538,7 +502,7 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem::Type::BSDF,
{{"fg", n_metal_bsdf},
{"bg", n_specular_layer},
{"mix", inputs.find("metalness")->second}});
{"mix", inputs.find("metallic")->second}});
NodeItem n_thin_film_layer = create_node(
"layer", NodeItem::Type::BSDF, {{"top", n_thin_film_bsdf}, {"base", n_metalness_mix}});
@ -546,16 +510,15 @@ NODE_SHADER_MATERIALX_BEGIN
NodeItem n_opacity_luminance = create_node(
"luminance", NodeItem::Type::Color3, {{"in", val(MaterialX::Color3(1.0f, 1.0f, 1.0f))}});
NodeItem n_coat_attenuation = create_node(
"mix",
NodeItem::Type::Color3,
{{"fg", base_color}, {"bg", val(MaterialX::Color3(1.0f, 1.0f, 1.0f))}, {"mix", coat}});
NodeItem n_coat_attenuation = create_node("mix",
NodeItem::Type::Color3,
{{"fg", inputs.find("coat_tint")->second},
{"bg", val(MaterialX::Color3(1.0f, 1.0f, 1.0f))},
{"mix", coat}});
res = create_node("layer",
NodeItem::Type::BSDF,
{{"top", n_coat_bsdf}, {"base", n_thin_film_layer * n_coat_attenuation}});
return res;
}
else if (to_type_ == NodeItem::Type::EDF) {
auto inputs = edf_inputs();
@ -569,45 +532,49 @@ NODE_SHADER_MATERIALX_BEGIN
auto b_inputs = bsdf_inputs();
auto e_inputs = edf_inputs();
NodeItem roughness = b_inputs.find("diffuse_roughness")->second;
NodeItem roughness = b_inputs.find("roughness")->second;
NodeItem base_color = b_inputs.find("base_color")->second;
NodeItem anisotropic = b_inputs.find("specular_anisotropy")->second;
NodeItem ior = b_inputs.find("specular_IOR")->second;
NodeItem rotation = b_inputs.find("specular_rotation")->second;
NodeItem anisotropic = b_inputs.find("anisotropic")->second;
NodeItem rotation = b_inputs.find("anisotropic_rotation")->second;
res = create_node("standard_surface",
NodeItem::Type::SurfaceShader,
{{"base", val(1.0f)},
{"base_color", base_color},
{"diffuse_roughness", roughness},
{"metalness", b_inputs.find("metalness")->second},
{"specular", b_inputs.find("specular")->second},
{"specular_color", base_color},
{"specular_roughness", roughness},
{"specular_IOR", ior},
{"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},
{"subsurface_anisotropy", anisotropic},
{"sheen", b_inputs.find("sheen")->second},
{"sheen_color", base_color},
{"sheen_roughness", roughness},
{"coat", b_inputs.find("coat")->second},
{"coat_color", base_color},
{"coat_roughness", b_inputs.find("coat_roughness")->second},
{"coat_IOR", ior},
{"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", 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}});
}
else {
BLI_assert_unreachable();
}
return res;