MaterialX: add support for nodes #11

Merged
Bogdan Nagirniak merged 17 commits from matx-add-other-nodes into matx-export-material 2023-09-06 10:37:26 +02:00
4 changed files with 127 additions and 0 deletions
Showing only changes of commit 7cdf99e7cb - Show all commits

View File

@ -160,6 +160,7 @@ if(WITH_MATERIALX)
materialx/nodes/tex_environment.cc materialx/nodes/tex_environment.cc
materialx/nodes/tex_noise.cc materialx/nodes/tex_noise.cc
materialx/nodes/tex_checker.cc materialx/nodes/tex_checker.cc
materialx/nodes/vector_math.cc
materialx/material.h materialx/material.h
materialx/nodes/node_item.h materialx/nodes/node_item.h

View File

@ -142,6 +142,9 @@ NodeItem NodeParser::get_input_link(const bNodeSocket &socket)
case SH_NODE_TEX_CHECKER: case SH_NODE_TEX_CHECKER:
parser = std::make_unique<TexCheckerNodeParser>(graph, depsgraph, material, in_node); parser = std::make_unique<TexCheckerNodeParser>(graph, depsgraph, material, in_node);
break; break;
case SH_NODE_VECTOR_MATH:
parser = std::make_unique<VectorMathNodeParser>(graph, depsgraph, material, in_node);
break;
default: default:
CLOG_WARN(LOG_MATERIALX_SHADER, "Unsupported node: %s (%d)", in_node->name, in_node->type); CLOG_WARN(LOG_MATERIALX_SHADER, "Unsupported node: %s (%d)", in_node->name, in_node->type);
return res; return res;

View File

@ -70,5 +70,6 @@ DECLARE_PARSER(TexCheckerNodeParser)
DECLARE_PARSER(TexEnvironmentNodeParser) DECLARE_PARSER(TexEnvironmentNodeParser)
DECLARE_PARSER(TexImageNodeParser) DECLARE_PARSER(TexImageNodeParser)
DECLARE_PARSER(TexNoiseNodeParser) DECLARE_PARSER(TexNoiseNodeParser)
DECLARE_PARSER(VectorMathNodeParser)
} // namespace blender::nodes::materialx } // namespace blender::nodes::materialx

View File

@ -0,0 +1,122 @@
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "node_parser.h"
#include "../material.h"
namespace blender::nodes::materialx {
NodeItem VectorMathNodeParser::compute()
{
/* TODO: finish some math operations */
auto op = node->custom1;
NodeItem res = empty();
/* Single operand operations */
NodeItem x = get_input_value(0);
switch (op) {
case NODE_VECTOR_MATH_SINE:
res = x.sin();
break;
case NODE_VECTOR_MATH_COSINE:
res = x.cos();
break;
case NODE_VECTOR_MATH_TANGENT:
res = x.tan();
break;
case NODE_VECTOR_MATH_ABSOLUTE:
res = x.abs();
break;
case NODE_VECTOR_MATH_FLOOR:
res = x.floor();
break;
case NODE_VECTOR_MATH_CEIL:
res = x.ceil();
break;
case NODE_VECTOR_MATH_FRACTION:
res = x % value(1.0f);
break;
case NODE_VECTOR_MATH_LENGTH:
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break;
case NODE_VECTOR_MATH_NORMALIZE:
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break;
default: {
/* 2-operand operations */
NodeItem y = get_input_value(1);
switch (op) {
case NODE_VECTOR_MATH_ADD:
res = x + y;
break;
case NODE_VECTOR_MATH_SUBTRACT:
res = x - y;
break;
case NODE_VECTOR_MATH_MULTIPLY:
res = x * y;
break;
case NODE_VECTOR_MATH_DIVIDE:
res = x / y;
break;
case NODE_VECTOR_MATH_MINIMUM:
res = x.min(y);
break;
case NODE_VECTOR_MATH_MAXIMUM:
res = x.max(y);
break;
case NODE_VECTOR_MATH_MODULO:
res = x % y;
break;
case NODE_VECTOR_MATH_SNAP:
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break;
case NODE_VECTOR_MATH_CROSS_PRODUCT:
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break;
case NODE_VECTOR_MATH_DOT_PRODUCT:
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break;
case NODE_VECTOR_MATH_PROJECT:
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break;
case NODE_VECTOR_MATH_REFLECT:
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break;
case NODE_VECTOR_MATH_DISTANCE:
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break;
case NODE_VECTOR_MATH_SCALE:
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break;
default: {
/* 3-operand operations */
NodeItem z = get_input_value(2);
switch (op) {
case NODE_VECTOR_MATH_MULTIPLY_ADD:
res = x * y + z;
break;
case NODE_VECTOR_MATH_REFRACT:
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break;
case NODE_VECTOR_MATH_FACEFORWARD:
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break;
case NODE_VECTOR_MATH_WRAP:
CLOG_WARN(LOG_MATERIALX_SHADER, "Unimplemented math operation %d", op);
break;
default:
BLI_assert_unreachable();
}
}
}
}
}
return res;
}
} // namespace blender::nodes::materialx