Blender V5.0
node_composite_posterize.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_math_base.hh"
10#include "BLI_math_vector.hh"
12
14
15#include "NOD_multi_function.hh"
16
17#include "GPU_material.hh"
18
20
21/* **************** Posterize ******************** */
22
24
26{
27 b.use_custom_socket_order();
28 b.allow_any_socket_order();
29 b.is_function_node();
30 b.add_input<decl::Color>("Image").default_value({1.0f, 1.0f, 1.0f, 1.0f}).hide_value();
31 b.add_output<decl::Color>("Image").align_with_previous();
32
33 b.add_input<decl::Float>("Steps").default_value(8.0f).min(2.0f).max(1024.0f);
34}
35
36using namespace blender::compositor;
37
38static int node_gpu_material(GPUMaterial *material,
39 bNode *node,
40 bNodeExecData * /*execdata*/,
43{
44 return GPU_stack_link(material, node, "node_composite_posterize", inputs, outputs);
45}
46
48{
49 static auto function = mf::build::SI2_SO<float4, float, float4>(
50 "Posterize",
51 [](const float4 &color, const float steps) -> float4 {
52 const float sanitized_steps = math::clamp(steps, 2.0f, 1024.0f);
53 return float4(math::floor(color.xyz() * sanitized_steps) / sanitized_steps, color.w);
54 },
55 mf::build::exec_presets::SomeSpanOrSingle<0>());
56 builder.set_matching_fn(function);
57}
58
59} // namespace blender::nodes::node_composite_posterize_cc
60
62{
64
65 static blender::bke::bNodeType ntype;
66
67 cmp_node_type_base(&ntype, "CompositorNodePosterize", CMP_NODE_POSTERIZE);
68 ntype.ui_name = "Posterize";
69 ntype.ui_description =
70 "Reduce number of colors in an image, converting smooth gradients into sharp transitions";
71 ntype.enum_name_legacy = "POSTERIZE";
73 ntype.declare = file_ns::cmp_node_posterize_declare;
74 ntype.gpu_fn = file_ns::node_gpu_material;
75 ntype.build_multi_function = file_ns::node_build_multi_function;
76
78}
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:449
#define CMP_NODE_POSTERIZE
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
void set_matching_fn(const mf::MultiFunction *fn)
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
T clamp(const T &a, const T &min, const T &max)
T floor(const T &a)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
static void cmp_node_posterize_declare(NodeDeclarationBuilder &b)
VecBase< float, 4 > float4
static void register_node_type_cmp_posterize()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
static blender::bke::bNodeSocketTemplate outputs[]
static blender::bke::bNodeSocketTemplate inputs[]
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:342
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:351
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362