MaterialX: add support for Vector nodes #27

Merged
Bogdan Nagirniak merged 13 commits from Vasyl-Pidhirskyi/blender:BLEN-525 into matx-export-material 2023-09-22 10:03:45 +02:00
Showing only changes of commit 67cf3b35ea - Show all commits

View File

@ -212,6 +212,78 @@ static void node_shader_update_vector_rotate(bNodeTree *ntree, bNode *node)
ntree, sock_angle, !ELEM(node->custom1, NODE_VECTOR_ROTATE_TYPE_EULER_XYZ)); ntree, sock_angle, !ELEM(node->custom1, NODE_VECTOR_ROTATE_TYPE_EULER_XYZ));
} }
NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX
{
/* NOTE: This node doesn't have an implementation in MaterialX.*/
NodeItem res = create_node("rotate3d", NodeItem::Type::Vector3);
MaterialX::Vector3 axis_vector;
NodeItem angle = empty();
NodeItem center = get_input_value("Center", NodeItem::Type::Vector3) *
val(MaterialX::Vector3(1.0f, 1.0f, -1.0f));
NodeItem vector = get_input_link("Vector", NodeItem::Type::Vector3) - center;
const int mode = node_->custom1;
const int invert = node_->custom2 ? -1.0f : 1.0f;
switch (mode) {
case NODE_VECTOR_ROTATE_TYPE_EULER_XYZ:
angle = get_input_value("Rotation", NodeItem::Type::Vector3);
if (angle == 0.0) {
return vector;
}
angle = (angle / val(float(M_PI))) * val(180.0f);
for (int i = node_->custom2 ? 2 : 0; node_->custom2 ? i >= 0 : i <= 2; node_->custom2 ? i-- : i++) {
axis_vector = MaterialX::Vector3(0.0f, 0.0f, 0.0f);
int inv = invert;
if (i == 2) {
inv *= -1.0f;
}
axis_vector[i] = inv;
NodeItem res_rot = create_node("rotate3d", NodeItem::Type::Vector3);
res_rot.set_input("in", vector);
res_rot.set_input("amount", angle.extract(i));
res_rot.set_input("axis", val(axis_vector));
vector = res_rot;
}
res = vector;
break;
default: {
angle = get_input_value("Angle", NodeItem::Type::Float);
if (angle == 0.0) {
return vector;
}
angle = (angle / val(float(M_PI))) * val(180.0f);
NodeItem axis = empty();
if (node_->custom2) {
angle = angle * val(-1.0f);
}
switch (mode) {
case NODE_VECTOR_ROTATE_TYPE_AXIS:
axis = get_input_value("Axis", NodeItem::Type::Vector3);
axis = axis * val(MaterialX::Vector3(1.0f, 1.0f, -1.0f));
break;
case NODE_VECTOR_ROTATE_TYPE_AXIS_X:
axis = val(MaterialX::Vector3(1.0f, 0.0f, 0.0f));
break;
case NODE_VECTOR_ROTATE_TYPE_AXIS_Y:
axis = val(MaterialX::Vector3(0.0f, 1.0f, 0.0f));
break;
case NODE_VECTOR_ROTATE_TYPE_AXIS_Z:
axis = val(MaterialX::Vector3(0.0f, 0.0f, -1.0f));
break;
}
res.set_input("in", vector);
res.set_input("amount", angle);
res.set_input("axis", axis);
}
}
return res + center;
}
#endif
NODE_SHADER_MATERIALX_END
} // namespace blender::nodes::node_shader_vector_rotate_cc } // namespace blender::nodes::node_shader_vector_rotate_cc
void register_node_type_sh_vector_rotate() void register_node_type_sh_vector_rotate()
@ -226,6 +298,7 @@ void register_node_type_sh_vector_rotate()
ntype.gpu_fn = file_ns::gpu_shader_vector_rotate; ntype.gpu_fn = file_ns::gpu_shader_vector_rotate;
ntype.updatefunc = file_ns::node_shader_update_vector_rotate; ntype.updatefunc = file_ns::node_shader_update_vector_rotate;
ntype.build_multi_function = file_ns::sh_node_vector_rotate_build_multi_function; ntype.build_multi_function = file_ns::sh_node_vector_rotate_build_multi_function;
ntype.materialx_fn = file_ns::node_shader_materialx;
nodeRegisterType(&ntype); nodeRegisterType(&ntype);
} }