Blender V5.0
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_resources.hh"
10
11#include "COM_algorithm_smaa.hh"
12#include "COM_node_operation.hh"
13
15
16/* **************** Anti-Aliasing (SMAA 1x) ******************** */
17
19
21{
22 b.use_custom_socket_order();
23 b.allow_any_socket_order();
24 b.add_input<decl::Color>("Image")
25 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
26 .hide_value()
27 .structure_type(StructureType::Dynamic);
28 b.add_output<decl::Color>("Image").structure_type(StructureType::Dynamic).align_with_previous();
29
30 b.add_input<decl::Float>("Threshold")
31 .default_value(0.2f)
33 .min(0.0f)
34 .max(1.0f)
35 .description(
36 "Specifies the threshold or sensitivity to edges. Lowering this value you will be able "
37 "to detect more edges at the expense of performance");
38 b.add_input<decl::Float>("Contrast Limit")
39 .default_value(2.0f)
40 .min(0.0f)
42 "If there is an neighbor edge that has a Contrast Limit times bigger contrast than "
43 "current edge, current edge will be discarded. This allows to eliminate spurious "
44 "crossing edges");
45 b.add_input<decl::Float>("Corner Rounding")
46 .default_value(0.25f)
48 .min(0.0f)
49 .max(1.0f)
50 .description("Specifies how much sharp corners will be rounded");
51}
52
53using namespace blender::compositor;
54
56 public:
58
59 void execute() override
60 {
61 smaa(this->context(),
62 this->get_input("Image"),
63 this->get_result("Image"),
64 this->get_threshold(),
66 this->get_corner_rounding());
67 }
68
69 /* We encode the threshold in the [0, 1] range, while the SMAA algorithm expects it in the
70 * [0, 0.5] range. */
72 {
73 return math::clamp(this->get_input("Threshold").get_single_value_default(0.2f), 0.0f, 1.0f) /
74 2.0f;
75 }
76
78 {
79 return math::max(0.0f, this->get_input("Contrast Limit").get_single_value_default(2.0f));
80 }
81
82 /* We encode the corner rounding factor in the float [0, 1] range, while the SMAA algorithm
83 * expects it in the integer [0, 100] range. */
85 {
86 return int(math::clamp(this->get_input("Corner Rounding").get_single_value_default(0.25f),
87 0.0f,
88 1.0f) *
89 100.0f);
90 }
91};
92
94{
95 return new AntiAliasingOperation(context, node);
96}
97
98} // namespace blender::nodes::node_composite_antialiasing_cc
99
101{
103
104 static blender::bke::bNodeType ntype;
105
106 cmp_node_type_base(&ntype, "CompositorNodeAntiAliasing", CMP_NODE_ANTIALIASING);
107 ntype.ui_name = "Anti-Aliasing";
108 ntype.ui_description = "Smooth away jagged edges";
109 ntype.enum_name_legacy = "ANTIALIASING";
111 ntype.declare = file_ns::cmp_node_antialiasing_declare;
112 ntype.flag |= NODE_PREVIEW;
113 blender::bke::node_type_size(ntype, 175, 140, 200);
114 ntype.get_compositor_operation = file_ns::get_compositor_operation;
115
117}
#define NODE_CLASS_OP_FILTER
Definition BKE_node.hh:451
#define CMP_NODE_ANTIALIASING
@ NODE_PREVIEW
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_FACTOR
Definition RNA_types.hh:251
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:5384
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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:238
std::string ui_description
Definition BKE_node.hh:244
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:348
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362