Implement export of Shader BSDF nodes #13

Merged
Bogdan Nagirniak merged 13 commits from BogdanNagirniak/blender:matx-shader-bsdf-nodes into matx-export-material 2023-09-07 11:22:44 +02:00
7 changed files with 99 additions and 24 deletions
Showing only changes of commit c093aa5203 - Show all commits

View File

@ -8,20 +8,51 @@ namespace blender::nodes::materialx {
NodeItem AddShaderNodeParser::compute_bsdf()
{
/* TODO: implement */
return empty();
NodeItem shader1 = get_input_shader(0, NodeItem::Type::BSDF);
NodeItem shader2 = get_input_shader(1, NodeItem::Type::BSDF);
NodeItem res = empty();
if (shader1 && !shader2) {
res = shader1;
}
else if (!shader1 && shader2) {
res = shader2;
}
else if (shader1 && shader2) {
res = create_node("add", "BSDF");
res.set_input("in1", shader1);
res.set_input("in2", shader2);
}
return res;
}
NodeItem AddShaderNodeParser::compute_edf()
{
/* TODO: implement */
return empty();
NodeItem shader1 = get_input_shader(0, NodeItem::Type::EDF);
NodeItem shader2 = get_input_shader(1, NodeItem::Type::EDF);
NodeItem res = empty();
if (shader1 && !shader2) {
res = shader1;
}
else if (!shader1 && shader2) {
res = shader2;
}
else if (shader1 && shader2) {
res = create_node("add", "EDF");
res.set_input("in1", shader1);
res.set_input("in2", shader2);
}
return res;
}
NodeItem AddShaderNodeParser::compute_surface()
{
/* TODO: implement */
return empty();
NodeItem res = get_input_shader(0, NodeItem::Type::SurfaceShader);
if (!res) {
res = get_input_shader(1, NodeItem::Type::SurfaceShader);
}
return res;
}
} // namespace blender::nodes::materialx

View File

@ -8,19 +8,26 @@ namespace blender::nodes::materialx {
NodeItem BSDFDiffuseNodeParser::compute_bsdf()
{
/* TODO: implement */
return empty();
NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Float);
NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
NodeItem res = create_node("oren_nayar_diffuse_bsdf", "BSDF");
res.set_input("color", color);
res.set_input("roughness", roughness);
if (normal) {
res.set_input("normal", normal);
}
return res;
}
NodeItem BSDFDiffuseNodeParser::compute_edf()
{
/* TODO: implement */
return empty();
}
NodeItem BSDFDiffuseNodeParser::compute_surface()
{
/* TODO: implement */
return empty();
}

View File

@ -8,11 +8,13 @@ namespace blender::nodes::materialx {
NodeItem BSDFPrincipledNodeParser::compute_bsdf()
{
/* TODO: implement */
return empty();
}
NodeItem BSDFPrincipledNodeParser::compute_edf()
{
/* TODO: implement */
return empty();
}

View File

@ -8,19 +8,21 @@ namespace blender::nodes::materialx {
NodeItem EmissionNodeParser::compute_bsdf()
{
/* TODO: implement */
return empty();
}
NodeItem EmissionNodeParser::compute_edf()
{
/* TODO: implement */
return empty();
NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
NodeItem strength = get_input_value("Strength", NodeItem::Type::Float);
NodeItem res = create_node("uniform_edf", "EDF");
res.set_input("color", color * strength);
return res;
}
NodeItem EmissionNodeParser::compute_surface()
{
/* TODO: implement */
return empty();
}

View File

@ -8,20 +8,55 @@ namespace blender::nodes::materialx {
NodeItem MixShaderNodeParser::compute_bsdf()
{
/* TODO: implement */
return empty();
NodeItem fac = get_input_value(0, NodeItem::Type::Float);
NodeItem shader1 = get_input_shader(1, NodeItem::Type::BSDF);
NodeItem shader2 = get_input_shader(2, NodeItem::Type::BSDF);
NodeItem res = empty();
if (shader1 && !shader2) {
res = shader1;
}
else if (!shader1 && shader2) {
res = shader2;
}
else if (shader1 && shader2) {
res = create_node("mix", "BSDF");
res.set_input("fg", shader1);
res.set_input("bg", shader2);
res.set_input("mix", fac);
}
return res;
}
NodeItem MixShaderNodeParser::compute_edf()
{
/* TODO: implement */
return empty();
NodeItem fac = get_input_value(0, NodeItem::Type::Float);
NodeItem shader1 = get_input_shader(1, NodeItem::Type::EDF);
NodeItem shader2 = get_input_shader(2, NodeItem::Type::EDF);
NodeItem res = empty();
if (shader1 && !shader2) {
res = shader1;
}
else if (!shader1 && shader2) {
res = shader2;
}
else if (shader1 && shader2) {
res = create_node("mix", "EDF");
res.set_input("fg", shader1);
res.set_input("bg", shader2);
res.set_input("mix", fac);
}
return res;
}
NodeItem MixShaderNodeParser::compute_surface()
{
/* TODO: implement */
return empty();
NodeItem res = get_input_shader(0, NodeItem::Type::SurfaceShader);
if (!res) {
res = get_input_shader(1, NodeItem::Type::SurfaceShader);
}
return res;
}
} // namespace blender::nodes::materialx

View File

@ -134,8 +134,7 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket, NodeItem::Type to
#define CASE_NODE_TYPE(type, T) \
case type: \
parser = \
std::make_unique<T>(graph_, depsgraph_, material_, from_node, link->fromsock); \
parser = std::make_unique<T>(graph_, depsgraph_, material_, from_node, link->fromsock); \
break;
switch (from_node->typeinfo->type) {
@ -267,7 +266,7 @@ NodeItem ShaderNodeParser::get_input_shader(const bNodeSocket &socket, NodeItem:
#define CASE_SHADER_NODE_TYPE(type, T) \
case type: \
parser = std::make_unique<T>( \
graph_, depsgraph_, material_, from_node, link->fromsock, shader_type); \
graph_, depsgraph_, material_, from_node, link->fromsock, shader_type); \
break;
switch (from_node->typeinfo->type) {

View File

@ -127,5 +127,4 @@ DECLARE_SHADER_NODE_PARSER(EmissionNodeParser)
DECLARE_SHADER_NODE_PARSER(MixShaderNodeParser)
DECLARE_SHADER_NODE_PARSER(SubsurfaceScatteringNodeParser)
} // namespace blender::nodes::materialx