Blender V5.0
node_composite_setalpha.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
8
10
12
13#include "NOD_multi_function.hh"
14
15#include "GPU_material.hh"
16
18
20
21static const EnumPropertyItem type_items[] = {
23 "APPLY",
24 0,
25 N_("Apply Mask"),
26 N_("Multiply the input image's RGBA channels by the alpha input value")},
28 "REPLACE_ALPHA",
29 0,
30 N_("Replace Alpha"),
31 N_("Replace the input image's alpha channel by the alpha input value")},
32 {0, nullptr, 0, nullptr, nullptr},
33};
34
36{
37 b.use_custom_socket_order();
38 b.allow_any_socket_order();
39 b.is_function_node();
40 b.add_input<decl::Color>("Image").default_value({1.0f, 1.0f, 1.0f, 1.0f}).hide_value();
41 b.add_output<decl::Color>("Image").align_with_previous();
42
43 b.add_input<decl::Float>("Alpha").default_value(1.0f).min(0.0f).max(1.0f);
44 b.add_input<decl::Menu>("Type")
45 .default_value(CMP_NODE_SETALPHA_MODE_APPLY)
46 .static_items(type_items)
48}
49
50static void node_composit_init_setalpha(bNodeTree * /*ntree*/, bNode *node)
51{
52 /* Unused, but allocated for forward compatibility. */
53 NodeSetAlpha *settings = MEM_callocN<NodeSetAlpha>(__func__);
54 node->storage = settings;
55}
56
57using namespace blender::compositor;
58
59static int node_gpu_material(GPUMaterial *material,
60 bNode *node,
61 bNodeExecData * /*execdata*/,
64{
65 return GPU_stack_link(material, node, "node_composite_set_alpha", inputs, outputs);
66}
67
69{
70 static auto function = mf::build::SI3_SO<float4, float, MenuValue, float4>(
71 "Set Alpha",
72 [](const float4 &color, const float alpha, const MenuValue type) -> float4 {
73 switch (CMPNodeSetAlphaMode(type.value)) {
75 return color * alpha;
77 return float4(color.xyz(), alpha);
78 }
79 return color;
80 },
81 mf::build::exec_presets::AllSpanOrSingle());
82
83 builder.set_matching_fn(function);
84}
85
86} // namespace blender::nodes::node_composite_setalpha_cc
87
89{
91
92 static blender::bke::bNodeType ntype;
93
94 cmp_node_type_base(&ntype, "CompositorNodeSetAlpha", CMP_NODE_SETALPHA);
95 ntype.ui_name = "Set Alpha";
96 ntype.ui_description = "Add an alpha channel to an image";
97 ntype.enum_name_legacy = "SETALPHA";
99 ntype.declare = file_ns::cmp_node_setalpha_declare;
100 ntype.initfunc = file_ns::node_composit_init_setalpha;
103 ntype.gpu_fn = file_ns::node_gpu_material;
104 ntype.build_multi_function = file_ns::node_build_multi_function;
105
107}
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:453
#define CMP_NODE_SETALPHA
CMPNodeSetAlphaMode
@ CMP_NODE_SETALPHA_MODE_REPLACE_ALPHA
@ CMP_NODE_SETALPHA_MODE_APPLY
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 * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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:5414
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static void node_composit_init_setalpha(bNodeTree *, bNode *node)
static void cmp_node_setalpha_declare(NodeDeclarationBuilder &b)
VecBase< float, 4 > float4
static void register_node_type_cmp_setalpha()
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[]
void node_free_standard_storage(bNode *node)
Definition node_util.cc:42
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:54
void * storage
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:342
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:351
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362
#define N_(msgid)