Compositor: Implemenet Posterize node for new CPU compositor

Reference #125968.
This commit is contained in:
Omar Emara
2024-10-23 13:24:54 +03:00
parent 471c30fdd9
commit 8a02a5de56
2 changed files with 8 additions and 4 deletions

View File

@@ -4,6 +4,6 @@
void node_composite_posterize(vec4 color, float steps, out vec4 result)
{
steps = clamp(steps, 2.0, 1024.0);
result = vec4(floor(color.rgb * steps) / steps, color.a);
float sanitized_steps = clamp(steps, 2.0, 1024.0);
result = vec4(floor(color.rgb * sanitized_steps) / sanitized_steps, color.a);
}

View File

@@ -6,6 +6,8 @@
* \ingroup cmpnodes
*/
#include "BLI_math_base.hh"
#include "BLI_math_vector.hh"
#include "BLI_math_vector_types.hh"
#include "FN_multi_function_builder.hh"
@@ -57,10 +59,12 @@ static ShaderNode *get_compositor_shader_node(DNode node)
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
{
/* Not yet implemented. Return zero. */
static auto function = mf::build::SI2_SO<float4, float, float4>(
"Posterize",
[](const float4 & /*color*/, const float /*steps*/) -> float4 { return float4(0.0f); },
[](const float4 &color, const float steps) -> float4 {
const float sanitized_steps = math::clamp(steps, 2.0f, 1024.0f);
return float4(math::floor(color.xyz() * sanitized_steps) / sanitized_steps, color.w);
},
mf::build::exec_presets::SomeSpanOrSingle<0>());
builder.set_matching_fn(function);
}