Code improvements + Mix node #30

Merged
Bogdan Nagirniak merged 18 commits from BogdanNagirniak/blender:matx-code-improvements into matx-export-material 2023-09-22 18:23:13 +02:00
2 changed files with 46 additions and 5 deletions
Showing only changes of commit e90a7fa7f7 - Show all commits

View File

@ -318,9 +318,7 @@ NodeItem NodeItem::dotproduct(const NodeItem &other) const
NodeItem NodeItem::mix(const NodeItem &val1, const NodeItem &val2) const
{
BLI_assert(type() == Type::Float);
if (value && val1.value && val2.value) {
if ((value && val1.value && val2.value) || type() != Type::Float) {
return (val(1.0f) - *this) * val1 + *this * val2;
}

View File

@ -546,8 +546,51 @@ static void sh_node_mix_build_multi_function(NodeMultiFunctionBuilder &builder)
NODE_SHADER_MATERIALX_BEGIN
#ifdef WITH_MATERIALX
{
/* TODO: Implement */
return empty();
const NodeShaderMix *data = (NodeShaderMix *)node_->storage;
NodeItem factor = empty();
NodeItem value1 = empty();
NodeItem value2 = empty();
switch (data->data_type) {
case SOCK_FLOAT:
factor = get_input_value(0, NodeItem::Type::Float);
value1 = get_input_value(2, NodeItem::Type::Float);
value2 = get_input_value(3, NodeItem::Type::Float);
break;
case SOCK_VECTOR:
if (data->factor_mode == NODE_MIX_MODE_UNIFORM) {
factor = get_input_value(0, NodeItem::Type::Float);
}
else {
factor = get_input_value(1, NodeItem::Type::Vector3);
}
value1 = get_input_value(4, NodeItem::Type::Vector3);
value2 = get_input_value(5, NodeItem::Type::Vector3);
break;
case SOCK_RGBA:
factor = get_input_value(0, NodeItem::Type::Float);
value1 = get_input_value(6, NodeItem::Type::Color4);
value2 = get_input_value(7, NodeItem::Type::Color4);
break;
default:
BLI_assert_unreachable();
}
if (data->clamp_factor) {
factor = factor.clamp();
}
NodeItem res = factor.mix(value1, value2);
if (data->data_type == SOCK_RGBA) {
/* TODO: Apply data->blend_type */
if (data->clamp_result) {
res = res.clamp();
}
}
return res;
}
#endif
NODE_SHADER_MATERIALX_END