Blender V4.5
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.add_input<decl::Color>("Image")
28 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
29 .compositor_domain_priority(0);
30 b.add_input<decl::Float>("Steps")
31 .default_value(8.0f)
32 .min(2.0f)
33 .max(1024.0f)
35 b.add_output<decl::Color>("Image");
36}
37
38using namespace blender::compositor;
39
40static int node_gpu_material(GPUMaterial *material,
41 bNode *node,
42 bNodeExecData * /*execdata*/,
45{
46 return GPU_stack_link(material, node, "node_composite_posterize", inputs, outputs);
47}
48
50{
51 static auto function = mf::build::SI2_SO<float4, float, float4>(
52 "Posterize",
53 [](const float4 &color, const float steps) -> float4 {
54 const float sanitized_steps = math::clamp(steps, 2.0f, 1024.0f);
55 return float4(math::floor(color.xyz() * sanitized_steps) / sanitized_steps, color.w);
56 },
57 mf::build::exec_presets::SomeSpanOrSingle<0>());
58 builder.set_matching_fn(function);
59}
60
61} // namespace blender::nodes::node_composite_posterize_cc
62
64{
66
67 static blender::bke::bNodeType ntype;
68
69 cmp_node_type_base(&ntype, "CompositorNodePosterize", CMP_NODE_POSTERIZE);
70 ntype.ui_name = "Posterize";
71 ntype.ui_description =
72 "Reduce number of colors in an image, converting smooth gradients into sharp transitions";
73 ntype.enum_name_legacy = "POSTERIZE";
75 ntype.declare = file_ns::cmp_node_posterize_declare;
76 ntype.gpu_fn = file_ns::node_gpu_material;
77 ntype.build_multi_function = file_ns::node_build_multi_function;
78
80}
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:435
#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:2748
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[]
static const int steps
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:330
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:344
const char * enum_name_legacy
Definition BKE_node.hh:235
NodeDeclareFunction declare
Definition BKE_node.hh:355