forked from blender/blender
MaterialX: add support for Vector nodes #27
@ -74,6 +74,73 @@ static void node_shader_update_mapping(bNodeTree *ntree, bNode *node)
|
||||
ntree, sock, ELEM(node->custom1, NODE_MAPPING_TYPE_POINT, NODE_MAPPING_TYPE_TEXTURE));
|
||||
}
|
||||
|
||||
NODE_SHADER_MATERIALX_BEGIN
|
||||
#ifdef WITH_MATERIALX
|
||||
{
|
||||
NodeItem res = create_node("rotate3d", NodeItem::Type::Vector3);
|
||||
NodeItem location = get_input_value("Location", NodeItem::Type::Vector3);
|
||||
NodeItem scale = get_input_value("Scale", NodeItem::Type::Vector3);
|
||||
NodeItem vector = get_input_link("Vector", NodeItem::Type::Vector3);
|
||||
NodeItem angle = (get_input_value("Rotation", NodeItem::Type::Vector3) / val(float(M_PI))) * val(180.0f);
|
||||
MaterialX::Vector3 axis_vector;
|
||||
NodeItem in = empty();
|
||||
const int mode = node_->custom1;
|
||||
|
||||
switch (mode) {
|
||||
case NODE_MAPPING_TYPE_POINT:
|
||||
in = vector * scale;
|
||||
break;
|
||||
|
||||
case NODE_MAPPING_TYPE_TEXTURE:
|
||||
in = vector - location;
|
||||
break;
|
||||
|
||||
case NODE_MAPPING_TYPE_VECTOR:
|
||||
in = vector * scale;
|
||||
break;
|
||||
|
||||
case NODE_MAPPING_TYPE_NORMAL:
|
||||
in = vector / scale;
|
||||
break;
|
||||
}
|
||||
|
||||
bool tex = mode == NODE_MAPPING_TYPE_TEXTURE;
|
||||
float inv = tex ? -1.0 : 1.0;
|
||||
for (int i = tex ? 2 : 0; tex ? i >= 0 : i <= 2; tex ? i-- : i++) {
|
||||
axis_vector = MaterialX::Vector3(0.0f, 0.0f, 0.0f);
|
||||
axis_vector[i] = inv;
|
||||
if (i == 2) { // invert Z axis to get the same result as Cycles
|
||||
inv *= -1.0f;
|
||||
}
|
||||
axis_vector[i] = inv;
|
||||
NodeItem res_rot = create_node("rotate3d", NodeItem::Type::Vector3);
|
||||
res_rot.set_input("in", in);
|
||||
res_rot.set_input("amount", angle.extract(i));
|
||||
res_rot.set_input("axis", val(axis_vector));
|
||||
in = res_rot;
|
||||
res = in;
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case NODE_MAPPING_TYPE_POINT:
|
||||
res = res + location;
|
||||
break;
|
||||
|
||||
case NODE_MAPPING_TYPE_TEXTURE:
|
||||
res = res / scale;
|
||||
break;
|
||||
|
||||
case NODE_MAPPING_TYPE_NORMAL:
|
||||
NodeItem normalize = create_node("normalize", NodeItem::Type::Vector3);
|
||||
normalize.set_input("in", res);
|
||||
res = normalize;
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
NODE_SHADER_MATERIALX_END
|
||||
|
||||
} // namespace blender::nodes::node_shader_mapping_cc
|
||||
|
||||
void register_node_type_sh_mapping()
|
||||
@ -87,6 +154,7 @@ void register_node_type_sh_mapping()
|
||||
ntype.draw_buttons = file_ns::node_shader_buts_mapping;
|
||||
ntype.gpu_fn = file_ns::gpu_shader_mapping;
|
||||
ntype.updatefunc = file_ns::node_shader_update_mapping;
|
||||
ntype.materialx_fn = file_ns::node_shader_materialx;
|
||||
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user