Blender V5.0
node_composite_premulkey.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 "STRAIGHT_TO_PREMULTIPLIED",
24 0,
25 N_("To Premultiplied"),
26 N_("Convert straight to premultiplied")},
28 "PREMULTIPLIED_TO_STRAIGHT",
29 0,
30 N_("To Straight"),
31 N_("Convert premultiplied to straight")},
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::Menu>("Type")
45 .static_items(type_items)
47}
48
49using namespace blender::compositor;
50
51static int node_gpu_material(GPUMaterial *material,
52 bNode *node,
53 bNodeExecData * /*execdata*/,
56{
57 return GPU_stack_link(material, node, "node_composite_convert_alpha", inputs, outputs);
58}
59
61{
62 static auto function = mf::build::SI2_SO<float4, MenuValue, float4>(
63 "Alpha Convert",
64 [](const float4 color, const MenuValue type) -> float4 {
65 switch (CMPNodeAlphaConvertMode(type.value)) {
67 return float4(color.xyz() * color.w, color.w);
69 return color.w == 0.0f ? color : float4(color.xyz() / color.w, color.w);
70 }
71 return color;
72 },
73 mf::build::exec_presets::AllSpanOrSingle());
74 builder.set_matching_fn(function);
75}
76
77} // namespace blender::nodes::node_composite_premulkey_cc
78
80{
82
83 static blender::bke::bNodeType ntype;
84
85 cmp_node_type_base(&ntype, "CompositorNodePremulKey", CMP_NODE_PREMULKEY);
86 ntype.ui_name = "Alpha Convert";
87 ntype.ui_description = "Convert to and from premultiplied (associated) alpha";
88 ntype.enum_name_legacy = "PREMULKEY";
90 ntype.declare = file_ns::cmp_node_premulkey_declare;
91 ntype.gpu_fn = file_ns::node_gpu_material;
92 ntype.build_multi_function = file_ns::node_build_multi_function;
93
95}
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:453
#define CMP_NODE_PREMULKEY
CMPNodeAlphaConvertMode
@ CMP_NODE_ALPHA_CONVERT_UNPREMULTIPLY
@ CMP_NODE_ALPHA_CONVERT_PREMULTIPLY
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 node_register_type(bNodeType &ntype)
Definition node.cc:2416
static void cmp_node_premulkey_declare(NodeDeclarationBuilder &b)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
VecBase< float, 4 > float4
static void register_node_type_cmp_premulkey()
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[]
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
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)