Compositor: Implement Map Value node for new CPU compositor
Reference #125968.
This commit is contained in:
@@ -110,14 +110,81 @@ static ShaderNode *get_compositor_shader_node(DNode node)
|
||||
return new MapValueShaderNode(node);
|
||||
}
|
||||
|
||||
template<bool UseMin, bool UseMax>
|
||||
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<float, float>(
|
||||
"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<float, float>(
|
||||
"Map Value With Min With Max",
|
||||
[=](const float value) -> float {
|
||||
return map_value<true, true>(value, offset, size, min, max);
|
||||
},
|
||||
mf::build::exec_presets::AllSpanOrSingle());
|
||||
});
|
||||
}
|
||||
else {
|
||||
builder.construct_and_set_matching_fn_cb([=]() {
|
||||
return mf::build::SI1_SO<float, float>(
|
||||
"Map Value With Min No Max",
|
||||
[=](const float value) -> float {
|
||||
return map_value<true, false>(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<float, float>(
|
||||
"Map Value No Min With Max",
|
||||
[=](const float value) -> float {
|
||||
return map_value<false, true>(value, offset, size, min, max);
|
||||
},
|
||||
mf::build::exec_presets::AllSpanOrSingle());
|
||||
});
|
||||
}
|
||||
else {
|
||||
builder.construct_and_set_matching_fn_cb([=]() {
|
||||
return mf::build::SI1_SO<float, float>(
|
||||
"Map Value No Min No Max",
|
||||
[=](const float value) -> float {
|
||||
return map_value<false, false>(value, offset, size, min, max);
|
||||
},
|
||||
mf::build::exec_presets::AllSpanOrSingle());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace blender::nodes::node_composite_map_value_cc
|
||||
|
||||
Reference in New Issue
Block a user