diff --git a/source/blender/makesrna/intern/rna_render.cc b/source/blender/makesrna/intern/rna_render.cc index 75efabbb1a5..c681bd398a5 100644 --- a/source/blender/makesrna/intern/rna_render.cc +++ b/source/blender/makesrna/intern/rna_render.cc @@ -1010,7 +1010,7 @@ static void rna_def_render_engine(BlenderRNA *brna) prop = RNA_def_property(srna, "bl_use_materialx", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, nullptr, "type->flag", RE_USE_MATERIALX); RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL); - RNA_def_property_ui_text(prop, "Use Material", "Use MaterialX for exporting materials to Hydra"); + RNA_def_property_ui_text(prop, "Use MaterialX", "Use MaterialX for exporting materials to Hydra"); RNA_define_verify_sdna(true); } diff --git a/source/blender/nodes/shader/CMakeLists.txt b/source/blender/nodes/shader/CMakeLists.txt index 991128fec7f..1dec91b8b3a 100644 --- a/source/blender/nodes/shader/CMakeLists.txt +++ b/source/blender/nodes/shader/CMakeLists.txt @@ -24,7 +24,8 @@ set(INC if(WITH_HYDRA) list(APPEND INC ../../io/usd - ) + ../../../../intern/clog +) add_definitions(-DWITH_HYDRA) endif() @@ -144,8 +145,6 @@ set(LIB ) if(WITH_MATERIALX) - list(APPEND LIB MaterialXCore) - list(APPEND LIB MaterialXFormat) list(APPEND SRC materialx/material.cc materialx/nodes/bsdf_principled.cc @@ -164,6 +163,10 @@ if(WITH_MATERIALX) materialx/nodes/node_item.h materialx/nodes/node_parser.h ) + list(APPEND LIB + MaterialXCore + MaterialXFormat + ) endif() if(WITH_FREESTYLE) diff --git a/source/blender/nodes/shader/materialx/material.cc b/source/blender/nodes/shader/materialx/material.cc index 5fec3563571..502ea74f5fd 100644 --- a/source/blender/nodes/shader/materialx/material.cc +++ b/source/blender/nodes/shader/materialx/material.cc @@ -5,13 +5,18 @@ #include "material.h" #include "nodes/node_parser.h" -#include #include +#include "DEG_depsgraph.h" + +#include "DNA_material_types.h" + #include "NOD_shader.h" namespace blender::nodes::materialx { +CLG_LOGREF_DECLARE_GLOBAL(LOG_MATERIALX_SHADER, "materialx.shader"); + static void export_nodegraph(MaterialX::GraphElement *graph, Depsgraph *depsgraph, Material *material) @@ -48,7 +53,7 @@ MaterialX::DocumentPtr export_to_materialx(Depsgraph *depsgraph, Material *mater create_standard_surface(doc.get(), material); } std::string str = MaterialX::writeToXmlString(doc); - printf("\nMaterial: %s\n%s\n", material->id.name, str.c_str()); + CLOG_INFO(LOG_MATERIALX_SHADER, 1, "Material: %s\n%s", material->id.name, str.c_str()); return doc; } diff --git a/source/blender/nodes/shader/materialx/material.h b/source/blender/nodes/shader/materialx/material.h index 1784c42349b..b32f3ff2962 100644 --- a/source/blender/nodes/shader/materialx/material.h +++ b/source/blender/nodes/shader/materialx/material.h @@ -6,11 +6,15 @@ #include -#include "DEG_depsgraph.h" -#include "DNA_material_types.h" +#include "CLG_log.h" + +struct Depsgraph; +struct Material; namespace blender::nodes::materialx { +extern struct CLG_LogRef *LOG_MATERIALX_SHADER; + MaterialX::DocumentPtr export_to_materialx(Depsgraph *depsgraph, Material *material); } // namespace blender::nodes::materialx diff --git a/source/blender/nodes/shader/materialx/nodes/bsdf_principled.cc b/source/blender/nodes/shader/materialx/nodes/bsdf_principled.cc index a87a0782881..5a5e9f7c053 100644 --- a/source/blender/nodes/shader/materialx/nodes/bsdf_principled.cc +++ b/source/blender/nodes/shader/materialx/nodes/bsdf_principled.cc @@ -72,8 +72,12 @@ NodeItem BSDFPrincipledNodeParser::compute() res.set_input("base", 1.0, "float"); res.set_input("base_color", base_color.to_color3()); res.set_input("diffuse_roughness", roughness); - res.set_input("normal", normal); - res.set_input("tangent", tangent); + if (normal) { + res.set_input("normal", normal); + } + if (tangent) { + res.set_input("tangent", tangent); + } if (metallic != zero) { res.set_input("metalness", metallic); @@ -84,8 +88,10 @@ NodeItem BSDFPrincipledNodeParser::compute() res.set_input("specular_color", base_color.to_color3()); res.set_input("specular_roughness", roughness); res.set_input("specular_IOR", ior); - res.set_input("specular_anisotropy", anisotropic); - res.set_input("specular_rotation", anisotropic_rotation); + if (anisotropic) { + res.set_input("specular_anisotropy", anisotropic); + res.set_input("specular_rotation", anisotropic_rotation); + } } if (transmission != zero) { @@ -98,7 +104,9 @@ NodeItem BSDFPrincipledNodeParser::compute() res.set_input("subsurface", subsurface); res.set_input("subsurface_color", subsurface_color); res.set_input("subsurface_radius", subsurface_radius); - res.set_input("subsurface_anisotropy", anisotropic); + if (anisotropic) { + res.set_input("subsurface_anisotropy", anisotropic); + } } if (sheen != zero) { @@ -112,8 +120,10 @@ NodeItem BSDFPrincipledNodeParser::compute() res.set_input("coat_color", base_color.to_color3()); res.set_input("coat_roughness", clearcoat_roughness); res.set_input("coat_IOR", ior); - res.set_input("coat_anisotropy", anisotropic); - res.set_input("coat_rotation", anisotropic_rotation); + if (anisotropic) { + res.set_input("coat_anisotropy", anisotropic); + res.set_input("coat_rotation", anisotropic_rotation); + } res.set_input("coat_normal", clearcoat_normal); } diff --git a/source/blender/nodes/shader/materialx/nodes/math.cc b/source/blender/nodes/shader/materialx/nodes/math.cc index 9fce9a7457d..8787bf2ca39 100644 --- a/source/blender/nodes/shader/materialx/nodes/math.cc +++ b/source/blender/nodes/shader/materialx/nodes/math.cc @@ -3,16 +3,14 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ #include "node_parser.h" +#include "../material.h" namespace blender::nodes::materialx { NodeItem MathNodeParser::compute() { /* TODO: finish some math operations */ - auto op = node->custom1; - printf("%d\n", int(op)); - NodeItem res = empty(); /* Single operand operations */ @@ -123,13 +121,13 @@ NodeItem MathNodeParser::compute() res = x.atan2(y); break; case NODE_MATH_SNAP: - // res = ; + CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op); break; case NODE_MATH_PINGPONG: - // res = ; + CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op); break; case NODE_MATH_FLOORED_MODULO: - // res = ; + CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op); break; default: { @@ -137,7 +135,7 @@ NodeItem MathNodeParser::compute() NodeItem z = get_input_value(2); switch (op) { case NODE_MATH_WRAP: - // res = ; + CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op); break; case NODE_MATH_COMPARE: res = z.if_else("<", (x - y).abs(), value(1.0f), value(0.0f)); @@ -146,10 +144,10 @@ NodeItem MathNodeParser::compute() res = x * y + z; break; case NODE_MATH_SMOOTH_MIN: - // res = ; + CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op); break; case NODE_MATH_SMOOTH_MAX: - // res = ; + CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op); break; default: diff --git a/source/blender/nodes/shader/materialx/nodes/node_item.cc b/source/blender/nodes/shader/materialx/nodes/node_item.cc index b5b85fb6eea..f3cf3779058 100644 --- a/source/blender/nodes/shader/materialx/nodes/node_item.cc +++ b/source/blender/nodes/shader/materialx/nodes/node_item.cc @@ -3,6 +3,7 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ #include "node_item.h" +#include "../material.h" #include "BLI_assert.h" #include "BLI_utildefines.h" @@ -26,6 +27,9 @@ void NodeItem::set_input(const std::string &name, else if (item.node) { set_input(name, item.node, output_name); } + else { + CLOG_WARN(LOG_MATERIALX_SHADER, "Empty item to input: %s", name.c_str()); + } } void NodeItem::set_input(const std::string &name, const MaterialX::ValuePtr value) @@ -218,6 +222,9 @@ NodeItem NodeItem::dotproduct(const NodeItem &other) const auto v = value->asA(); f = v[0] + v[1] + v[2] + v[3]; } + else { + BLI_assert_unreachable(); + } d.value = MaterialX::Value::createValue(f); } return d; @@ -369,27 +376,27 @@ NodeItem NodeItem::exp() const NodeItem NodeItem::to_color3() const { - std::string t = type(); + std::string mx_type = type(); NodeItem res = empty(); if (value) { MaterialX::Color3 c; - if (t == "float") { + if (mx_type == "float") { float v = value->asA(); c = {v, v, v}; } - else if (t == "color3") { + else if (mx_type == "color3") { auto v = value->asA(); c = {v[0], v[1], v[2]}; } - else if (t == "color4") { + else if (mx_type == "color4") { auto v = value->asA(); c = {v[0], v[1], v[2]}; } - else if (t == "vector3") { + else if (mx_type == "vector3") { auto v = value->asA(); c = {v[0], v[1], v[2]}; } - else if (t == "vector4") { + else if (mx_type == "vector4") { auto v = value->asA(); c = {v[0], v[1], v[2]}; } @@ -399,7 +406,7 @@ NodeItem NodeItem::to_color3() const res.value = MaterialX::Value::createValue(c); } else if (node) { - if (t != "color3") { + if (mx_type != "color3") { return res; } res.node = node; diff --git a/source/blender/nodes/shader/materialx/nodes/node_parser.cc b/source/blender/nodes/shader/materialx/nodes/node_parser.cc index edbdffd6f09..2c8974406d9 100644 --- a/source/blender/nodes/shader/materialx/nodes/node_parser.cc +++ b/source/blender/nodes/shader/materialx/nodes/node_parser.cc @@ -3,8 +3,9 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ #include "node_parser.h" +#include "../material.h" -#include +#include "BKE_node_runtime.hh" namespace blender::nodes::materialx { @@ -82,7 +83,7 @@ NodeItem NodeParser::get_input_default(const bNodeSocket &socket) MaterialX::Color4(v[0], v[1], v[2], v[3])); } break; default: { - // TODO log warn + CLOG_WARN(LOG_MATERIALX_SHADER, "Unsupported socket type: %d", socket.type); } } return res; @@ -136,7 +137,7 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket) parser = std::make_unique(graph, depsgraph, material, in_node); break; default: - // TODO: warning log + CLOG_WARN(LOG_MATERIALX_SHADER, "Unsupported node: %s (%d)", in_node->name, in_node->type); return res; }