Blender V5.3
node_composite_set_alpha.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
8
10
11#include "GPU_material.hh"
12
13#include "COM_result.hh"
14
16
18
19static const EnumPropertyItem type_items[] = {
21 "APPLY",
22 0,
23 N_("Apply Mask"),
24 N_("Multiply the input image's RGBA channels by the alpha input value")},
26 "REPLACE_ALPHA",
27 0,
28 N_("Replace Alpha"),
29 N_("Replace the input image's alpha channel by the alpha input value")},
30 {0, nullptr, 0, nullptr, nullptr},
31};
32
34{
35 b.use_custom_socket_order();
36 b.allow_any_socket_order();
37 b.is_function_node();
38 b.add_input<decl::Color>("Image"_ustr).default_value({1.0f, 1.0f, 1.0f, 1.0f}).hide_value();
39 b.add_output<decl::Color>("Image"_ustr).align_with_previous();
40
41 b.add_input<decl::Float>("Alpha"_ustr).default_value(1.0f).min(0.0f).max(1.0f);
42 b.add_input<decl::Menu>("Type"_ustr)
43 .default_value(CMP_NODE_SETALPHA_MODE_APPLY)
44 .static_items(type_items)
46}
47
48static void node_init(bNodeTree * /*ntree*/, bNode *node)
49{
50 /* Unused, but allocated for forward compatibility. */
51 NodeSetAlpha *settings = MEM_new<NodeSetAlpha>(__func__);
52 node->storage = settings;
53}
54
55using namespace blender::compositor;
56
57static int node_gpu_material(GPUMaterial *material,
58 bNode *node,
59 bNodeExecData * /*execdata*/,
60 GPUNodeStack *inputs,
61 GPUNodeStack *outputs)
62{
63 return GPU_stack_link(material, node, "node_composite_set_alpha", inputs, outputs);
64}
65
66static float4 set_alpha(const float4 &color, const float alpha, const MenuValue &type)
67{
68 switch (CMPNodeSetAlphaMode(type.value)) {
70 return color * alpha;
72 return float4(color.xyz(), alpha);
73 }
74 return color;
75}
76
78
80{
81 static auto function = mf::build::SI3_SO<Color, float, MenuValue, Color>(
82 "Set Alpha",
83 [](const Color &color, const float alpha, const MenuValue &type) -> Color {
84 return Color(set_alpha(float4(color), alpha, type));
85 },
86 mf::build::exec_presets::AllSpanOrSingle());
87
88 builder.set_matching_fn(function);
89}
90
91static void node_register()
92{
93 static bke::bNodeType ntype;
94
95 cmp_node_type_base(&ntype, "CompositorNodeSetAlpha"_ustr, CMP_NODE_SETALPHA);
96 ntype.ui_name = "Set Alpha";
97 ntype.ui_description = "Add an alpha channel to an image";
98 ntype.enum_name_legacy = "SETALPHA";
100 ntype.declare = node_declare;
101 ntype.initfunc = node_init;
106
108}
110
111} // namespace blender::nodes::node_composite_set_alpha_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define CMP_NODE_SETALPHA
#define NOD_REGISTER_NODE(REGISTER_FUNC)
void set_matching_fn(const mf::MultiFunction *fn)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:6166
ColorSceneLinear4f< eAlpha::Premultiplied > Color
Definition COM_result.hh:96
static void node_build_multi_function(nodes::NodeMultiFunctionBuilder &builder)
static float4 set_alpha(const float4 &color, const float alpha, const MenuValue &type)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static void node_declare(NodeDeclarationBuilder &b)
static void node_init(bNodeTree *, bNode *node)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ CMP_NODE_SETALPHA_MODE_REPLACE_ALPHA
@ CMP_NODE_SETALPHA_MODE_APPLY
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:382
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
#define N_(msgid)