Blender V4.5
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 "UI_interface.hh"
16#include "UI_resources.hh"
17
18#include "GPU_material.hh"
19
21
22/* **************** SET ALPHA ******************** */
23
25
27
29{
30 b.add_input<decl::Color>("Image")
31 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
32 .compositor_domain_priority(0);
33 b.add_input<decl::Float>("Alpha")
34 .default_value(1.0f)
35 .min(0.0f)
36 .max(1.0f)
37 .compositor_domain_priority(1);
38 b.add_output<decl::Color>("Image");
39}
40
41static void node_composit_init_setalpha(bNodeTree * /*ntree*/, bNode *node)
42{
43 NodeSetAlpha *settings = MEM_callocN<NodeSetAlpha>(__func__);
44 node->storage = settings;
46}
47
49{
50 layout->prop(ptr, "mode", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
51}
52
53using namespace blender::compositor;
54
56{
57 return static_cast<CMPNodeSetAlphaMode>(node_storage(node).mode);
58}
59
60static int node_gpu_material(GPUMaterial *material,
61 bNode *node,
62 bNodeExecData * /*execdata*/,
65{
66 switch (get_mode(*node)) {
68 return GPU_stack_link(material, node, "node_composite_set_alpha_apply", inputs, outputs);
70 return GPU_stack_link(material, node, "node_composite_set_alpha_replace", inputs, outputs);
71 }
72
73 return false;
74}
75
77{
78 static auto apply_function = mf::build::SI2_SO<float4, float, float4>(
79 "Set Alpha Apply",
80 [](const float4 &color, const float alpha) -> float4 { return color * alpha; },
81 mf::build::exec_presets::AllSpanOrSingle());
82
83 static auto replace_function = mf::build::SI2_SO<float4, float, float4>(
84 "Set Alpha Replace",
85 [](const float4 &color, const float alpha) -> float4 { return float4(color.xyz(), alpha); },
86 mf::build::exec_presets::AllSpanOrSingle());
87
88 switch (get_mode(builder.node())) {
90 builder.set_matching_fn(apply_function);
91 break;
93 builder.set_matching_fn(replace_function);
94 break;
95 }
96}
97
98} // namespace blender::nodes::node_composite_setalpha_cc
99
101{
103
104 static blender::bke::bNodeType ntype;
105
106 cmp_node_type_base(&ntype, "CompositorNodeSetAlpha", CMP_NODE_SETALPHA);
107 ntype.ui_name = "Set Alpha";
108 ntype.ui_description = "Add an alpha channel to an image";
109 ntype.enum_name_legacy = "SETALPHA";
111 ntype.declare = file_ns::cmp_node_setalpha_declare;
112 ntype.draw_buttons = file_ns::node_composit_buts_set_alpha;
113 ntype.initfunc = file_ns::node_composit_init_setalpha;
116 ntype.gpu_fn = file_ns::node_gpu_material;
117 ntype.build_multi_function = file_ns::node_build_multi_function;
118
120}
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:439
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1215
#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)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
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:2748
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:5603
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 node_composit_buts_set_alpha(uiLayout *layout, bContext *, PointerRNA *ptr)
static void cmp_node_setalpha_declare(NodeDeclarationBuilder &b)
static CMPNodeSetAlphaMode get_mode(const bNode &node)
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
#define min(a, b)
Definition sort.cc:36
void * storage
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:277
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:330
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:344
const char * enum_name_legacy
Definition BKE_node.hh:235
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:355
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
max
Definition text_draw.cc:251
PointerRNA * ptr
Definition wm_files.cc:4226