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 5926f1ce84 - Show all commits

View File

@ -137,6 +137,61 @@ static int gpu_shader_vect_transform(GPUMaterial *mat,
return true; return true;
} }
NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX
{
/* NOTE: SHD_VECT_TRANSFORM_SPACE_CAMERA don't have an implementation in MaterialX.*/
NodeItem res = empty();
std::string name = socket_out_->name;
NodeShaderVectTransform *nodeprop = (NodeShaderVectTransform *)node_->storage;
std::string fromspace = "world";
std::string tospace = "world";
NodeItem vector = get_input_value("Vector", NodeItem::Type::Vector3);
switch (nodeprop->convert_from) {
Vasyl-Pidhirskyi marked this conversation as resolved
Review

Here and other places:

default:
	BLI_assert_unreachable();
Here and other places: ``` default: BLI_assert_unreachable(); ```
case SHD_VECT_TRANSFORM_SPACE_WORLD:
fromspace = "world";
break;
case SHD_VECT_TRANSFORM_SPACE_OBJECT:
fromspace = "object";
break;
case SHD_VECT_TRANSFORM_SPACE_CAMERA:
return vector;
}
switch (nodeprop->convert_to) {
case SHD_VECT_TRANSFORM_SPACE_WORLD:
tospace = "world";
break;
case SHD_VECT_TRANSFORM_SPACE_OBJECT:
tospace = "object";
break;
case SHD_VECT_TRANSFORM_SPACE_CAMERA:
return vector;
}
if (fromspace == tospace) {
return vector;
}
switch (nodeprop->type) {
case SHD_VECT_TRANSFORM_TYPE_POINT:
res = create_node("transformpoint", NodeItem::Type::Vector3);
break;
case SHD_VECT_TRANSFORM_TYPE_NORMAL:
res = create_node("transformnormal", NodeItem::Type::Vector3);
break;
case SHD_VECT_TRANSFORM_TYPE_VECTOR:
res = create_node("transformvector", NodeItem::Type::Vector3);
break;
}
res.set_input("in", vector);
res.set_input("fromspace", val(fromspace));
res.set_input("tospace", val(tospace));
return res;
}
#endif
NODE_SHADER_MATERIALX_END
} // namespace blender::nodes::node_shader_vector_transform_cc } // namespace blender::nodes::node_shader_vector_transform_cc
void register_node_type_sh_vect_transform() void register_node_type_sh_vect_transform()
@ -152,6 +207,7 @@ void register_node_type_sh_vect_transform()
node_type_storage( node_type_storage(
&ntype, "NodeShaderVectTransform", node_free_standard_storage, node_copy_standard_storage); &ntype, "NodeShaderVectTransform", node_free_standard_storage, node_copy_standard_storage);
ntype.gpu_fn = file_ns::gpu_shader_vect_transform; ntype.gpu_fn = file_ns::gpu_shader_vect_transform;
ntype.materialx_fn = file_ns::node_shader_materialx;
nodeRegisterType(&ntype); nodeRegisterType(&ntype);
} }