Blender V5.3
node_composite_anti_aliasing.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2017 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
7
9
11
13{
14 b.use_custom_socket_order();
15 b.allow_any_socket_order();
16 b.add_input<decl::Color>("Image"_ustr)
17 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
18 .hide_value()
19 .structure_type(StructureType::Dynamic);
20 b.add_output<decl::Color>("Image"_ustr)
21 .structure_type(StructureType::Dynamic)
22 .align_with_previous();
23
24 b.add_input<decl::Float>("Threshold"_ustr)
25 .default_value(0.2f)
27 .min(0.0f)
28 .max(1.0f)
29 .description(
30 "Specifies the threshold or sensitivity to edges. Lowering this value you will be able "
31 "to detect more edges at the expense of performance");
32 b.add_input<decl::Float>("Contrast Limit"_ustr)
33 .default_value(2.0f)
34 .min(0.0f)
36 "If there is an neighbor edge that has a Contrast Limit times bigger contrast than "
37 "current edge, current edge will be discarded. This allows to eliminate spurious "
38 "crossing edges");
39 b.add_input<decl::Float>("Corner Rounding"_ustr)
40 .default_value(0.25f)
42 .min(0.0f)
43 .max(1.0f)
44 .description("Specifies how much sharp corners will be rounded");
45}
46
47using namespace blender::compositor;
48
50 public:
52
53 void execute() override
54 {
55 smaa(this->context(),
56 this->get_input("Image"),
57 this->get_result("Image"),
58 this->get_threshold(),
60 this->get_corner_rounding());
61 }
62
63 /* We encode the threshold in the [0, 1] range, while the SMAA algorithm expects it in the
64 * [0, 0.5] range. */
66 {
67 return math::clamp(
68 this->get_input("Threshold").get_single_value_default<float>(), 0.0f, 1.0f) /
69 2.0f;
70 }
71
73 {
74 return math::max(0.0f, this->get_input("Contrast Limit").get_single_value_default<float>());
75 }
76
77 /* We encode the corner rounding factor in the float [0, 1] range, while the SMAA algorithm
78 * expects it in the integer [0, 100] range. */
80 {
81 return int(math::clamp(this->get_input("Corner Rounding").get_single_value_default<float>(),
82 0.0f,
83 1.0f) *
84 100.0f);
85 }
86};
87
89{
90 return new AntiAliasingOperation(context, node);
91}
92
93static void node_register()
94{
95 static bke::bNodeType ntype;
96
97 cmp_node_type_base(&ntype, "CompositorNodeAntiAliasing"_ustr, CMP_NODE_ANTIALIASING);
98 ntype.ui_name = "Anti-Aliasing";
99 ntype.ui_description = "Smooth away jagged edges";
100 ntype.enum_name_legacy = "ANTIALIASING";
102 ntype.declare = node_declare;
103 ntype.flag |= NODE_PREVIEW;
106
108}
110
111} // namespace blender::nodes::node_composite_anti_aliasing_cc
#define NODE_CLASS_OP_FILTER
Definition BKE_node.hh:482
#define CMP_NODE_ANTIALIASING
#define NOD_REGISTER_NODE(REGISTER_FUNC)
NodeOperation(Context &context, const bNode &node)
Result & get_result(StringRef identifier)
Definition operation.cc:40
Context & context() const
Definition operation.cc:57
Result & get_input(StringRef identifier) const
Definition operation.cc:35
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void smaa(Context &context, const Result &input, Result &output, const float threshold=0.1f, const float local_contrast_adaptation_factor=2.0f, const int corner_rounding=25)
Definition smaa.cc:1693
T clamp(const T &a, const T &min, const T &max)
T max(const T &a, const T &b)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
@ PROP_FACTOR
Definition RNA_types.hh:308
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
static constexpr int _180
Definition BKE_node.hh:247
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:379
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393