MaterialX logging #7

Merged
Bogdan Nagirniak merged 3 commits from BogdanNagirniak/blender:matx-logging into matx-export-material 2023-08-31 20:11:18 +02:00
7 changed files with 39 additions and 20 deletions
Showing only changes of commit 978410b94c - Show all commits

View File

@ -1010,7 +1010,7 @@ static void rna_def_render_engine(BlenderRNA *brna)
prop = RNA_def_property(srna, "bl_use_materialx", PROP_BOOLEAN, PROP_NONE); 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_boolean_sdna(prop, nullptr, "type->flag", RE_USE_MATERIALX);
RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL); 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); RNA_define_verify_sdna(true);
} }

View File

@ -24,7 +24,8 @@ set(INC
if(WITH_HYDRA) if(WITH_HYDRA)
list(APPEND INC list(APPEND INC
../../io/usd ../../io/usd
) ../../../../intern/clog
)
add_definitions(-DWITH_HYDRA) add_definitions(-DWITH_HYDRA)
endif() endif()
@ -144,8 +145,6 @@ set(LIB
) )
if(WITH_MATERIALX) if(WITH_MATERIALX)
list(APPEND LIB MaterialXCore)
list(APPEND LIB MaterialXFormat)
list(APPEND SRC list(APPEND SRC
materialx/material.cc materialx/material.cc
materialx/nodes/bsdf_principled.cc materialx/nodes/bsdf_principled.cc
@ -161,6 +160,10 @@ if(WITH_MATERIALX)
materialx/nodes/node_item.h materialx/nodes/node_item.h
materialx/nodes/node_parser.h materialx/nodes/node_parser.h
) )
list(APPEND LIB
MaterialXCore
MaterialXFormat
)
endif() endif()
if(WITH_FREESTYLE) if(WITH_FREESTYLE)

View File

@ -5,13 +5,18 @@
#include "material.h" #include "material.h"
#include "nodes/node_parser.h" #include "nodes/node_parser.h"
#include <MaterialXCore/Node.h>
#include <MaterialXFormat/XmlIo.h> #include <MaterialXFormat/XmlIo.h>
#include "DEG_depsgraph.h"
#include "DNA_material_types.h"
#include "NOD_shader.h" #include "NOD_shader.h"
namespace blender::nodes::materialx { namespace blender::nodes::materialx {
CLG_LOGREF_DECLARE_GLOBAL(LOG_MATERIALX_SHADER, "materialx.shader");
static void export_nodegraph(MaterialX::GraphElement *graph, static void export_nodegraph(MaterialX::GraphElement *graph,
Depsgraph *depsgraph, Depsgraph *depsgraph,
Material *material) Material *material)
@ -48,7 +53,7 @@ MaterialX::DocumentPtr export_to_materialx(Depsgraph *depsgraph, Material *mater
create_standard_surface(doc.get(), material); create_standard_surface(doc.get(), material);
} }
std::string str = MaterialX::writeToXmlString(doc); 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; return doc;
} }

View File

@ -6,11 +6,15 @@
#include <MaterialXCore/Document.h> #include <MaterialXCore/Document.h>
#include "DEG_depsgraph.h" #include "CLG_log.h"
#include "DNA_material_types.h"
struct Depsgraph;
struct Material;
namespace blender::nodes::materialx { namespace blender::nodes::materialx {
extern struct CLG_LogRef *LOG_MATERIALX_SHADER;
MaterialX::DocumentPtr export_to_materialx(Depsgraph *depsgraph, Material *material); MaterialX::DocumentPtr export_to_materialx(Depsgraph *depsgraph, Material *material);
} // namespace blender::nodes::materialx } // namespace blender::nodes::materialx

View File

@ -3,16 +3,14 @@
* SPDX-License-Identifier: GPL-2.0-or-later */ * SPDX-License-Identifier: GPL-2.0-or-later */
#include "node_parser.h" #include "node_parser.h"
#include "../material.h"
namespace blender::nodes::materialx { namespace blender::nodes::materialx {
NodeItem MathNodeParser::compute() NodeItem MathNodeParser::compute()
{ {
/* TODO: finish some math operations */ /* TODO: finish some math operations */
auto op = node->custom1; auto op = node->custom1;
printf("%d\n", int(op));
NodeItem res = empty(); NodeItem res = empty();
/* Single operand operations */ /* Single operand operations */
@ -123,13 +121,13 @@ NodeItem MathNodeParser::compute()
res = x.atan2(y); res = x.atan2(y);
break; break;
case NODE_MATH_SNAP: case NODE_MATH_SNAP:
// res = ; CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break; break;
case NODE_MATH_PINGPONG: case NODE_MATH_PINGPONG:
// res = ; CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break; break;
case NODE_MATH_FLOORED_MODULO: case NODE_MATH_FLOORED_MODULO:
// res = ; CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break; break;
default: { default: {
@ -137,7 +135,7 @@ NodeItem MathNodeParser::compute()
NodeItem z = get_input_value(2); NodeItem z = get_input_value(2);
switch (op) { switch (op) {
case NODE_MATH_WRAP: case NODE_MATH_WRAP:
// res = ; CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break; break;
case NODE_MATH_COMPARE: case NODE_MATH_COMPARE:
res = z.if_else("<", (x - y).abs(), value(1.0f), value(0.0f)); res = z.if_else("<", (x - y).abs(), value(1.0f), value(0.0f));
@ -146,10 +144,10 @@ NodeItem MathNodeParser::compute()
res = x * y + z; res = x * y + z;
break; break;
case NODE_MATH_SMOOTH_MIN: case NODE_MATH_SMOOTH_MIN:
// res = ; CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break; break;
case NODE_MATH_SMOOTH_MAX: case NODE_MATH_SMOOTH_MAX:
// res = ; CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break; break;
default: default:

View File

@ -3,6 +3,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later */ * SPDX-License-Identifier: GPL-2.0-or-later */
#include "node_item.h" #include "node_item.h"
#include "../material.h"
#include "BLI_assert.h" #include "BLI_assert.h"
#include "BLI_utildefines.h" #include "BLI_utildefines.h"
@ -206,6 +207,9 @@ NodeItem NodeItem::dotproduct(const NodeItem &other) const
auto v = value->asA<MaterialX::Vector4>(); auto v = value->asA<MaterialX::Vector4>();
f = v[0] + v[1] + v[2] + v[3]; f = v[0] + v[1] + v[2] + v[3];
} }
else {
BLI_assert_unreachable();
}
d.value = MaterialX::Value::createValue(f); d.value = MaterialX::Value::createValue(f);
} }
return d; return d;
@ -228,6 +232,10 @@ NodeItem NodeItem::if_else(const std::string &condition,
NodeItem res = empty(); NodeItem res = empty();
if (type() != "float" || other.type() != "float") { if (type() != "float" || other.type() != "float") {
CLOG_WARN(LOG_MATERIALX_SHADER,
"Incorrect condition types: %s, %s",
type().c_str(),
other.type().c_str());
return res; return res;
} }

View File

@ -3,8 +3,9 @@
* SPDX-License-Identifier: GPL-2.0-or-later */ * SPDX-License-Identifier: GPL-2.0-or-later */
#include "node_parser.h" #include "node_parser.h"
#include "../material.h"
#include <BKE_node_runtime.hh> #include "BKE_node_runtime.hh"
namespace blender::nodes::materialx { 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])); MaterialX::Color4(v[0], v[1], v[2], v[3]));
} break; } break;
default: { default: {
// TODO log warn CLOG_WARN(LOG_MATERIALX_SHADER, "Unsupported socket type: %d", socket.type);
} }
} }
return res; return res;
@ -127,7 +128,7 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket)
parser = std::make_unique<TexImageNodeParser>(graph, depsgraph, material, in_node); parser = std::make_unique<TexImageNodeParser>(graph, depsgraph, material, in_node);
break; break;
default: default:
// TODO: warning log CLOG_WARN(LOG_MATERIALX_SHADER, "Unsupported node: %s (%d)", in_node->name, in_node->type);
return res; return res;
} }