diff --git a/source/blender/nodes/composite/nodes/node_composite_map_value.cc b/source/blender/nodes/composite/nodes/node_composite_map_value.cc index 92b8ba0ce8d..f34f4230195 100644 --- a/source/blender/nodes/composite/nodes/node_composite_map_value.cc +++ b/source/blender/nodes/composite/nodes/node_composite_map_value.cc @@ -110,14 +110,81 @@ static ShaderNode *get_compositor_shader_node(DNode node) return new MapValueShaderNode(node); } +template +static float map_value( + const float value, const float offset, const float size, const float min, const float max) +{ + float result = (value + offset) * size; + + if constexpr (UseMin) { + if (result < min) { + result = min; + } + } + + if constexpr (UseMax) { + if (result > max) { + result = max; + } + } + + return result; +} + static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) { - /* Not yet implemented. Return zero. */ - static auto function = mf::build::SI1_SO( - "Map Value", - [](const float /*value*/) -> float { return 0.0f; }, - mf::build::exec_presets::AllSpanOrSingle()); - builder.set_matching_fn(function); + const TexMapping &texture_mapping = node_storage(builder.node()); + const float offset = texture_mapping.loc[0]; + const float size = texture_mapping.size[0]; + const float min = texture_mapping.min[0]; + const float max = texture_mapping.max[0]; + const bool use_min = texture_mapping.flag & TEXMAP_CLIP_MIN; + const bool use_max = texture_mapping.flag & TEXMAP_CLIP_MAX; + + if (use_min) { + if (use_max) { + builder.construct_and_set_matching_fn_cb([=]() { + return mf::build::SI1_SO( + "Map Value With Min With Max", + [=](const float value) -> float { + return map_value(value, offset, size, min, max); + }, + mf::build::exec_presets::AllSpanOrSingle()); + }); + } + else { + builder.construct_and_set_matching_fn_cb([=]() { + return mf::build::SI1_SO( + "Map Value With Min No Max", + [=](const float value) -> float { + return map_value(value, offset, size, min, max); + }, + mf::build::exec_presets::AllSpanOrSingle()); + }); + } + } + else { + if (use_max) { + builder.construct_and_set_matching_fn_cb([=]() { + return mf::build::SI1_SO( + "Map Value No Min With Max", + [=](const float value) -> float { + return map_value(value, offset, size, min, max); + }, + mf::build::exec_presets::AllSpanOrSingle()); + }); + } + else { + builder.construct_and_set_matching_fn_cb([=]() { + return mf::build::SI1_SO( + "Map Value No Min No Max", + [=](const float value) -> float { + return map_value(value, offset, size, min, max); + }, + mf::build::exec_presets::AllSpanOrSingle()); + }); + } + } } } // namespace blender::nodes::node_composite_map_value_cc