forked from blender/blender
Code improvements + Mix node #30
@ -289,9 +289,11 @@ static void node_shader_update_principled(bNodeTree *ntree, bNode *node)
|
||||
NODE_SHADER_MATERIALX_BEGIN
|
||||
#ifdef WITH_MATERIALX
|
||||
{
|
||||
using InputsType = std::map<std::string, NodeItem>;
|
||||
|
||||
/* NOTE: commented inputs aren't used for node creation. */
|
||||
auto bsdf_inputs = [&]() {
|
||||
return std::map<std::string, NodeItem>{
|
||||
auto bsdf_inputs = [&]() -> InputsType {
|
||||
return {
|
||||
{"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)},
|
||||
@ -320,14 +322,17 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
};
|
||||
};
|
||||
|
||||
auto edf_inputs = [&]() {
|
||||
return std::map<std::string, NodeItem>{
|
||||
auto edf_inputs = [&]() -> InputsType {
|
||||
return {
|
||||
{"emission", get_input_value("Emission Strength", NodeItem::Type::Float)},
|
||||
{"emission_color", get_input_value("Emission", NodeItem::Type::Color3)}};
|
||||
{"emission_color", get_input_value("Emission", NodeItem::Type::Color3)},
|
||||
};
|
||||
};
|
||||
|
||||
NodeItem res = empty();
|
||||
if (to_type_ == NodeItem::Type::BSDF) {
|
||||
|
||||
switch (to_type_) {
|
||||
case NodeItem::Type::BSDF: {
|
||||
auto in = bsdf_inputs();
|
||||
|
||||
NodeItem roughness = in["roughness"];
|
||||
@ -398,10 +403,6 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
NodeItem n_coat_affect_roughness_multiply2 = coat * val(0.0f) * in["coat_roughness"];
|
||||
NodeItem n_coat_affected_roughness = n_coat_affect_roughness_multiply2.mix(roughness,
|
||||
val(1.0f));
|
||||
// NodeItem n_coat_affected_roughness = create_node(
|
||||
// "mix",
|
||||
// NodeItem::Type::Float,
|
||||
// {{"fg", val(1.0f)}, {"bg", roughness}, {"mix", n_coat_affect_roughness_multiply2}});
|
||||
|
||||
NodeItem n_main_roughness = create_node(
|
||||
"roughness_anisotropy",
|
||||
@ -428,12 +429,6 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
|
||||
NodeItem n_coat_affected_transmission_roughness = n_coat_affect_roughness_multiply2.mix(
|
||||
(roughness + roughness).clamp(), val(1.0f));
|
||||
// NodeItem n_coat_affected_transmission_roughness = create_node(
|
||||
// "mix",
|
||||
// NodeItem::Type::Float,
|
||||
// {{"fg", val(1.0f)},
|
||||
// {"bg", (roughness + roughness).clamp(0.0f, 1.0f)},
|
||||
// {"mix", n_coat_affect_roughness_multiply2}});
|
||||
|
||||
NodeItem n_transmission_roughness = create_node(
|
||||
"roughness_anisotropy",
|
||||
@ -463,12 +458,6 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
{"anisotropy", in["subsurface_anisotropy"]},
|
||||
{"normal", normal}});
|
||||
|
||||
NodeItem n_selected_subsurface_bsdf = n_subsurface_bsdf;
|
||||
// NodeItem n_selected_subsurface_bsdf = create_node(
|
||||
// "mix",
|
||||
// NodeItem::Type::BSDF,
|
||||
// {{"fg", n_translucent_bsdf}, {"bg", n_subsurface_bsdf}, {"mix", val(0.0f)}});
|
||||
|
||||
NodeItem n_sheen_bsdf = create_node("sheen_bsdf",
|
||||
NodeItem::Type::BSDF,
|
||||
{{"weight", in["sheen"]},
|
||||
@ -483,29 +472,17 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
{"weight", val(1.0f)},
|
||||
{"normal", normal}});
|
||||
|
||||
NodeItem n_subsurface_mix = in["subsurface"].mix(n_diffuse_bsdf, n_selected_subsurface_bsdf);
|
||||
// NodeItem n_subsurface_mix = create_node(
|
||||
// "mix",
|
||||
// NodeItem::Type::BSDF,
|
||||
// {{"fg", n_selected_subsurface_bsdf}, {"bg", n_diffuse_bsdf}, {"mix", in["subsurface"]}});
|
||||
NodeItem n_subsurface_mix = in["subsurface"].mix(n_diffuse_bsdf, n_subsurface_bsdf);
|
||||
|
||||
NodeItem n_sheen_layer = create_node(
|
||||
"layer", NodeItem::Type::BSDF, {{"top", n_sheen_bsdf}, {"base", n_subsurface_mix}});
|
||||
|
||||
NodeItem n_transmission_mix = in["transmission"].mix(n_sheen_layer, n_transmission_bsdf);
|
||||
// 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 = in["metallic"].mix(n_specular_layer, n_metal_bsdf);
|
||||
// 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}});
|
||||
@ -515,23 +492,21 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
|
||||
NodeItem n_coat_attenuation = coat.mix(val(MaterialX::Color3(1.0f, 1.0f, 1.0f)),
|
||||
in["coat_tint"]);
|
||||
// NodeItem n_coat_attenuation = create_node("mix",
|
||||
// NodeItem::Type::Color3,
|
||||
// {{"fg", in["coat_tint"]},
|
||||
// {"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}});
|
||||
break;
|
||||
}
|
||||
else if (to_type_ == NodeItem::Type::EDF) {
|
||||
auto in = edf_inputs();
|
||||
|
||||
case NodeItem::Type::EDF: {
|
||||
auto in = edf_inputs();
|
||||
res = create_node(
|
||||
"uniform_edf", NodeItem::Type::EDF, {{"color", in["emission_color"] * in["emission"]}});
|
||||
break;
|
||||
}
|
||||
else if (to_type_ == NodeItem::Type::SurfaceShader) {
|
||||
|
||||
case NodeItem::Type::SurfaceShader: {
|
||||
auto in = bsdf_inputs();
|
||||
auto e_in = edf_inputs();
|
||||
in.insert(e_in.begin(), e_in.end());
|
||||
@ -574,11 +549,11 @@ NODE_SHADER_MATERIALX_BEGIN
|
||||
{"emission_color", in["emission_color"]},
|
||||
{"normal", in["normal"]},
|
||||
{"tangent", in["tangent"]}});
|
||||
break;
|
||||
}
|
||||
else {
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user