forked from blender/blender
MaterialX: split standard_surface into basic nodes #26
@ -51,9 +51,11 @@ class NodeItem {
|
|||||||
MaterialX::OutputPtr output;
|
MaterialX::OutputPtr output;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MaterialX::GraphElement *graph_;
|
MaterialX::GraphElement *graph_ = nullptr;
|
||||||
|
|
||||||
public:
|
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(MaterialX::GraphElement *graph);
|
||||||
~NodeItem() = default;
|
~NodeItem() = default;
|
||||||
|
|
||||||
|
@ -328,18 +328,18 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
|
|
||||||
NodeItem res = empty();
|
NodeItem res = empty();
|
||||||
if (to_type_ == NodeItem::Type::BSDF) {
|
if (to_type_ == NodeItem::Type::BSDF) {
|
||||||
auto inputs = bsdf_inputs();
|
auto in = bsdf_inputs();
|
||||||
|
|
||||||
NodeItem roughness = inputs.find("roughness")->second;
|
NodeItem roughness = in["roughness"];
|
||||||
NodeItem anisotropy = inputs.find("anisotropic")->second;
|
NodeItem anisotropy = in["anisotropic"];
|
||||||
NodeItem rotation = inputs.find("anisotropic_rotation")->second;
|
NodeItem rotation = in["anisotropic_rotation"];
|
||||||
NodeItem base_color = inputs.find("base_color")->second;
|
NodeItem base_color = in["base_color"];
|
||||||
NodeItem specular = inputs.find("specular")->second;
|
NodeItem specular = in["specular"];
|
||||||
NodeItem coat = inputs.find("coat")->second;
|
NodeItem coat = in["coat"];
|
||||||
NodeItem ior = inputs.find("ior")->second;
|
NodeItem ior = in["ior"];
|
||||||
NodeItem normal = inputs.find("normal")->second;
|
NodeItem normal = in["normal"];
|
||||||
NodeItem tangent = inputs.find("tangent")->second;
|
NodeItem tangent = in["tangent"];
|
||||||
NodeItem coat_normal = inputs.find("coat_normal")->second;
|
NodeItem coat_normal = in["coat_normal"];
|
||||||
|
|
||||||
NodeItem n_main_tangent = empty();
|
NodeItem n_main_tangent = empty();
|
||||||
if (tangent && normal) {
|
if (tangent && normal) {
|
||||||
@ -358,13 +358,13 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
NodeItem n_coat_roughness_vector = create_node(
|
NodeItem n_coat_roughness_vector = create_node(
|
||||||
"roughness_anisotropy",
|
"roughness_anisotropy",
|
||||||
NodeItem::Type::Vector2,
|
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 n_coat_bsdf = create_node("dielectric_bsdf",
|
||||||
NodeItem::Type::BSDF,
|
NodeItem::Type::BSDF,
|
||||||
{{"weight", coat},
|
{{"weight", coat},
|
||||||
{"tint", inputs.find("coat_tint")->second},
|
{"tint", in["coat_tint"]},
|
||||||
{"ior", inputs.find("coat_ior")->second},
|
{"ior", in["coat_ior"]},
|
||||||
{"scatter_mode", val(std::string("R"))},
|
{"scatter_mode", val(std::string("R"))},
|
||||||
{"roughness", n_coat_roughness_vector},
|
{"roughness", n_coat_roughness_vector},
|
||||||
{"normal", coat_normal}});
|
{"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_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_extinction_out = n_artistic_ior.add_output("extinction", NodeItem::Type::Color3);
|
||||||
|
|
||||||
NodeItem n_coat_affect_roughness_multiply2 = coat * val(0.0f) *
|
NodeItem n_coat_affect_roughness_multiply2 = coat * val(0.0f) * in["coat_roughness"];
|
||||||
inputs.find("coat_roughness")->second;
|
|
||||||
NodeItem n_coat_affected_roughness = create_node(
|
NodeItem n_coat_affected_roughness = create_node(
|
||||||
"mix",
|
"mix",
|
||||||
NodeItem::Type::Float,
|
NodeItem::Type::Float,
|
||||||
@ -418,7 +417,7 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
NodeItem n_specular_bsdf = create_node("dielectric_bsdf",
|
NodeItem n_specular_bsdf = create_node("dielectric_bsdf",
|
||||||
NodeItem::Type::BSDF,
|
NodeItem::Type::BSDF,
|
||||||
{{"weight", specular},
|
{{"weight", specular},
|
||||||
{"tint", inputs.find("specular_tint")->second},
|
{"tint", in["specular_tint"]},
|
||||||
{"ior", ior},
|
{"ior", ior},
|
||||||
{"scatter_mode", val(std::string("R"))},
|
{"scatter_mode", val(std::string("R"))},
|
||||||
{"roughness", n_main_roughness},
|
{"roughness", n_main_roughness},
|
||||||
@ -456,9 +455,8 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
"subsurface_bsdf",
|
"subsurface_bsdf",
|
||||||
NodeItem::Type::BSDF,
|
NodeItem::Type::BSDF,
|
||||||
{{"color", n_coat_affected_subsurface_color},
|
{{"color", n_coat_affected_subsurface_color},
|
||||||
{"radius",
|
{"radius", in["subsurface_radius"] * in["subsurface_scale"]},
|
||||||
inputs.find("subsurface_radius")->second * inputs.find("subsurface_scale")->second},
|
{"anisotropy", in["subsurface_anisotropy"]},
|
||||||
{"anisotropy", inputs.find("subsurface_anisotropy")->second},
|
|
||||||
{"normal", normal}});
|
{"normal", normal}});
|
||||||
|
|
||||||
NodeItem n_selected_subsurface_bsdf = create_node(
|
NodeItem n_selected_subsurface_bsdf = create_node(
|
||||||
@ -468,9 +466,9 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
|
|
||||||
NodeItem n_sheen_bsdf = create_node("sheen_bsdf",
|
NodeItem n_sheen_bsdf = create_node("sheen_bsdf",
|
||||||
NodeItem::Type::BSDF,
|
NodeItem::Type::BSDF,
|
||||||
{{"weight", inputs.find("sheen")->second},
|
{{"weight", in["sheen"]},
|
||||||
{"color", inputs.find("sheen_tint")->second},
|
{"color", in["sheen_tint"]},
|
||||||
{"roughness", inputs.find("sheen_roughness")->second},
|
{"roughness", in["sheen_roughness"]},
|
||||||
{"normal", normal}});
|
{"normal", normal}});
|
||||||
|
|
||||||
NodeItem n_diffuse_bsdf = create_node("oren_nayar_diffuse_bsdf",
|
NodeItem n_diffuse_bsdf = create_node("oren_nayar_diffuse_bsdf",
|
||||||
@ -480,29 +478,26 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
{"weight", val(1.0f)},
|
{"weight", val(1.0f)},
|
||||||
{"normal", normal}});
|
{"normal", normal}});
|
||||||
|
|
||||||
NodeItem n_subsurface_mix = create_node("mix",
|
NodeItem n_subsurface_mix = create_node(
|
||||||
|
"mix",
|
||||||
NodeItem::Type::BSDF,
|
NodeItem::Type::BSDF,
|
||||||
{{"fg", n_selected_subsurface_bsdf},
|
{{"fg", n_selected_subsurface_bsdf}, {"bg", n_diffuse_bsdf}, {"mix", in["subsurface"]}});
|
||||||
{"bg", n_diffuse_bsdf},
|
|
||||||
{"mix", inputs.find("subsurface")->second}});
|
|
||||||
|
|
||||||
NodeItem n_sheen_layer = create_node(
|
NodeItem n_sheen_layer = create_node(
|
||||||
"layer", NodeItem::Type::BSDF, {{"top", n_sheen_bsdf}, {"base", n_subsurface_mix}});
|
"layer", NodeItem::Type::BSDF, {{"top", n_sheen_bsdf}, {"base", n_subsurface_mix}});
|
||||||
|
|
||||||
NodeItem n_transmission_mix = create_node("mix",
|
NodeItem n_transmission_mix = create_node(
|
||||||
|
"mix",
|
||||||
NodeItem::Type::BSDF,
|
NodeItem::Type::BSDF,
|
||||||
{{"fg", n_transmission_bsdf},
|
{{"fg", n_transmission_bsdf}, {"bg", n_sheen_layer}, {"mix", in["transmission"]}});
|
||||||
{"bg", n_sheen_layer},
|
|
||||||
{"mix", inputs.find("transmission")->second}});
|
|
||||||
|
|
||||||
NodeItem n_specular_layer = create_node(
|
NodeItem n_specular_layer = create_node(
|
||||||
"layer", NodeItem::Type::BSDF, {{"top", n_specular_bsdf}, {"base", n_transmission_mix}});
|
"layer", NodeItem::Type::BSDF, {{"top", n_specular_bsdf}, {"base", n_transmission_mix}});
|
||||||
|
|
||||||
NodeItem n_metalness_mix = create_node("mix",
|
NodeItem n_metalness_mix = create_node(
|
||||||
|
"mix",
|
||||||
NodeItem::Type::BSDF,
|
NodeItem::Type::BSDF,
|
||||||
{{"fg", n_metal_bsdf},
|
{{"fg", n_metal_bsdf}, {"bg", n_specular_layer}, {"mix", in["metallic"]}});
|
||||||
{"bg", n_specular_layer},
|
|
||||||
{"mix", inputs.find("metallic")->second}});
|
|
||||||
|
|
||||||
NodeItem n_thin_film_layer = create_node(
|
NodeItem n_thin_film_layer = create_node(
|
||||||
"layer", NodeItem::Type::BSDF, {{"top", n_thin_film_bsdf}, {"base", n_metalness_mix}});
|
"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 n_coat_attenuation = create_node("mix",
|
||||||
NodeItem::Type::Color3,
|
NodeItem::Type::Color3,
|
||||||
{{"fg", inputs.find("coat_tint")->second},
|
{{"fg", in["coat_tint"]},
|
||||||
{"bg", val(MaterialX::Color3(1.0f, 1.0f, 1.0f))},
|
{"bg", val(MaterialX::Color3(1.0f, 1.0f, 1.0f))},
|
||||||
{"mix", coat}});
|
{"mix", coat}});
|
||||||
|
|
||||||
@ -521,57 +516,54 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
{{"top", n_coat_bsdf}, {"base", n_thin_film_layer * n_coat_attenuation}});
|
{{"top", n_coat_bsdf}, {"base", n_thin_film_layer * n_coat_attenuation}});
|
||||||
}
|
}
|
||||||
else if (to_type_ == NodeItem::Type::EDF) {
|
else if (to_type_ == NodeItem::Type::EDF) {
|
||||||
auto inputs = edf_inputs();
|
auto in = edf_inputs();
|
||||||
|
|
||||||
res = create_node(
|
res = create_node(
|
||||||
"uniform_edf",
|
"uniform_edf", NodeItem::Type::EDF, {{"color", in["emission_color"] * in["emission"]}});
|
||||||
NodeItem::Type::EDF,
|
|
||||||
{{"color", inputs.find("emission_color")->second * inputs.find("emission")->second}});
|
|
||||||
}
|
}
|
||||||
else if (to_type_ == NodeItem::Type::SurfaceShader) {
|
else if (to_type_ == NodeItem::Type::SurfaceShader) {
|
||||||
auto b_inputs = bsdf_inputs();
|
auto in = bsdf_inputs();
|
||||||
auto e_inputs = edf_inputs();
|
auto e_in = edf_inputs();
|
||||||
|
in.insert(e_in.begin(), e_in.end());
|
||||||
|
|
||||||
NodeItem roughness = b_inputs.find("roughness")->second;
|
NodeItem roughness = in["roughness"];
|
||||||
NodeItem base_color = b_inputs.find("base_color")->second;
|
NodeItem base_color = in["base_color"];
|
||||||
NodeItem anisotropic = b_inputs.find("anisotropic")->second;
|
NodeItem anisotropic = in["anisotropic"];
|
||||||
NodeItem rotation = b_inputs.find("anisotropic_rotation")->second;
|
NodeItem rotation = in["anisotropic_rotation"];
|
||||||
|
|
||||||
res = create_node(
|
res = create_node("standard_surface",
|
||||||
"standard_surface",
|
|
||||||
NodeItem::Type::SurfaceShader,
|
NodeItem::Type::SurfaceShader,
|
||||||
{{"base", val(1.0f)},
|
{{"base", val(1.0f)},
|
||||||
{"base_color", base_color},
|
{"base_color", base_color},
|
||||||
{"diffuse_roughness", roughness},
|
{"diffuse_roughness", roughness},
|
||||||
{"metalness", b_inputs.find("metallic")->second},
|
{"metalness", in["metallic"]},
|
||||||
{"specular", b_inputs.find("specular")->second},
|
{"specular", in["specular"]},
|
||||||
{"specular_color", b_inputs.find("specular_tint")->second},
|
{"specular_color", in["specular_tint"]},
|
||||||
{"specular_roughness", roughness},
|
{"specular_roughness", roughness},
|
||||||
{"specular_IOR", b_inputs.find("ior")->second},
|
{"specular_IOR", in["ior"]},
|
||||||
{"specular_anisotropy", anisotropic},
|
{"specular_anisotropy", anisotropic},
|
||||||
{"specular_rotation", rotation},
|
{"specular_rotation", rotation},
|
||||||
{"transmission", b_inputs.find("transmission")->second},
|
{"transmission", in["transmission"]},
|
||||||
{"transmission_color", base_color},
|
{"transmission_color", base_color},
|
||||||
{"transmission_extra_roughness", roughness},
|
{"transmission_extra_roughness", roughness},
|
||||||
{"subsurface", b_inputs.find("subsurface")->second},
|
{"subsurface", in["subsurface"]},
|
||||||
{"subsurface_color", base_color},
|
{"subsurface_color", base_color},
|
||||||
{"subsurface_radius",
|
{"subsurface_radius", in["subsurface_radius"] * in["subsurface_scale"]},
|
||||||
b_inputs.find("subsurface_radius")->second * b_inputs.find("subsurface_scale")->second},
|
{"subsurface_anisotropy", in["subsurface_anisotropy"]},
|
||||||
{"subsurface_anisotropy", b_inputs.find("subsurface_anisotropy")->second},
|
{"sheen", in["sheen"]},
|
||||||
{"sheen", b_inputs.find("sheen")->second},
|
{"sheen_color", in["sheen_tint"]},
|
||||||
{"sheen_color", b_inputs.find("sheen_tint")->second},
|
{"sheen_roughness", in["sheen_roughness"]},
|
||||||
{"sheen_roughness", b_inputs.find("sheen_roughness")->second},
|
{"coat", in["coat"]},
|
||||||
{"coat", b_inputs.find("coat")->second},
|
{"coat_color", in["coat_tint"]},
|
||||||
{"coat_color", b_inputs.find("coat_tint")->second},
|
{"coat_roughness", in["coat_roughness"]},
|
||||||
{"coat_roughness", b_inputs.find("coat_roughness")->second},
|
{"coat_IOR", in["coat_ior"]},
|
||||||
{"coat_IOR", b_inputs.find("coat_ior")->second},
|
|
||||||
{"coat_anisotropy", anisotropic},
|
{"coat_anisotropy", anisotropic},
|
||||||
{"coat_rotation", rotation},
|
{"coat_rotation", rotation},
|
||||||
{"coat_normal", b_inputs.find("coat_normal")->second},
|
{"coat_normal", in["coat_normal"]},
|
||||||
{"emission", e_inputs.find("emission")->second},
|
{"emission", in["emission"]},
|
||||||
{"emission_color", e_inputs.find("emission_color")->second},
|
{"emission_color", in["emission_color"]},
|
||||||
{"normal", b_inputs.find("normal")->second},
|
{"normal", in["normal"]},
|
||||||
{"tangent", b_inputs.find("tangent")->second}});
|
{"tangent", in["tangent"]}});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
BLI_assert_unreachable();
|
BLI_assert_unreachable();
|
||||||
|
Loading…
Reference in New Issue
Block a user