Blender V4.5
node_composite_antialiasing.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
8
9#include "UI_interface.hh"
10#include "UI_resources.hh"
11
12#include "COM_algorithm_smaa.hh"
13#include "COM_node_operation.hh"
14
16
17/* **************** Anti-Aliasing (SMAA 1x) ******************** */
18
20
22{
23 b.add_input<decl::Color>("Image")
24 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
25 .compositor_domain_priority(0);
26 b.add_input<decl::Float>("Threshold")
27 .default_value(0.2f)
29 .min(0.0f)
30 .max(1.0f)
31 .description(
32 "Specifies the threshold or sensitivity to edges. Lowering this value you will be able "
33 "to detect more edges at the expense of performance")
34 .compositor_expects_single_value();
35 b.add_input<decl::Float>("Contrast Limit")
36 .default_value(2.0f)
37 .min(0.0f)
39 "If there is an neighbor edge that has a Contrast Limit times bigger contrast than "
40 "current edge, current edge will be discarded. This allows to eliminate spurious "
41 "crossing edges")
42 .compositor_expects_single_value();
43 b.add_input<decl::Float>("Corner Rounding")
44 .default_value(0.25f)
46 .min(0.0f)
47 .max(1.0f)
48 .description("Specifies how much sharp corners will be rounded")
49 .compositor_expects_single_value();
50
51 b.add_output<decl::Color>("Image");
52}
53
54using namespace blender::compositor;
55
57 public:
59
60 void execute() override
61 {
62 smaa(this->context(),
63 this->get_input("Image"),
64 this->get_result("Image"),
65 this->get_threshold(),
67 this->get_corner_rounding());
68 }
69
70 /* We encode the threshold in the [0, 1] range, while the SMAA algorithm expects it in the
71 * [0, 0.5] range. */
73 {
74 return math::clamp(this->get_input("Threshold").get_single_value_default(0.2f), 0.0f, 1.0f) /
75 2.0f;
76 }
77
79 {
80 return math::max(0.0f, this->get_input("Contrast Limit").get_single_value_default(2.0f));
81 }
82
83 /* We encode the corner rounding factor in the float [0, 1] range, while the SMAA algorithm
84 * expects it in the integer [0, 100] range. */
86 {
87 return int(math::clamp(this->get_input("Corner Rounding").get_single_value_default(0.25f),
88 0.0f,
89 1.0f) *
90 100.0f);
91 }
92};
93
95{
96 return new AntiAliasingOperation(context, node);
97}
98
99} // namespace blender::nodes::node_composite_antialiasing_cc
100
102{
104
105 static blender::bke::bNodeType ntype;
106
107 cmp_node_type_base(&ntype, "CompositorNodeAntiAliasing", CMP_NODE_ANTIALIASING);
108 ntype.ui_name = "Anti-Aliasing";
109 ntype.ui_description = "Smooth away jagged edges";
110 ntype.enum_name_legacy = "ANTIALIASING";
112 ntype.declare = file_ns::cmp_node_antialiasing_declare;
113 ntype.flag |= NODE_PREVIEW;
114 blender::bke::node_type_size(ntype, 170, 140, 200);
115 ntype.get_compositor_operation = file_ns::get_compositor_operation;
116
118}
#define NODE_CLASS_OP_FILTER
Definition BKE_node.hh:437
#define CMP_NODE_ANTIALIASING
@ NODE_PREVIEW
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_FACTOR
Definition RNA_types.hh:239
NodeOperation(Context &context, DNode node)
Result & get_result(StringRef identifier)
Definition operation.cc:39
Result & get_input(StringRef identifier) const
Definition operation.cc:138
void node_type_size(bNodeType &ntype, int width, int minwidth, int maxwidth)
Definition node.cc:5573
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
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:1646
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, DNode node)
static void cmp_node_antialiasing_declare(NodeDeclarationBuilder &b)
static void register_node_type_cmp_antialiasing()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:336
const char * enum_name_legacy
Definition BKE_node.hh:235
NodeDeclareFunction declare
Definition BKE_node.hh:355