Blender
V5.0
source
blender
nodes
composite
nodes
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
9
#include "
BLI_math_vector_types.hh
"
10
11
#include "
FN_multi_function_builder.hh
"
12
13
#include "
NOD_multi_function.hh
"
14
15
#include "
GPU_material.hh
"
16
17
#include "
node_composite_util.hh
"
18
19
namespace
blender::nodes::node_composite_premulkey_cc
{
20
21
static
const
EnumPropertyItem
type_items
[] = {
22
{
CMP_NODE_ALPHA_CONVERT_PREMULTIPLY
,
23
"STRAIGHT_TO_PREMULTIPLIED"
,
24
0,
25
N_
(
"To Premultiplied"
),
26
N_
(
"Convert straight to premultiplied"
)},
27
{
CMP_NODE_ALPHA_CONVERT_UNPREMULTIPLY
,
28
"PREMULTIPLIED_TO_STRAIGHT"
,
29
0,
30
N_
(
"To Straight"
),
31
N_
(
"Convert premultiplied to straight"
)},
32
{0,
nullptr
, 0,
nullptr
,
nullptr
},
33
};
34
35
static
void
cmp_node_premulkey_declare
(
NodeDeclarationBuilder
&
b
)
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"
)
44
.default_value(
CMP_NODE_ALPHA_CONVERT_PREMULTIPLY
)
45
.static_items(
type_items
)
46
.
optional_label
();
47
}
48
49
using namespace
blender::compositor
;
50
51
static
int
node_gpu_material
(
GPUMaterial
*material,
52
bNode
*node,
53
bNodeExecData
*
/*execdata*/
,
54
GPUNodeStack
*
inputs
,
55
GPUNodeStack
*
outputs
)
56
{
57
return
GPU_stack_link
(material, node,
"node_composite_convert_alpha"
,
inputs
,
outputs
);
58
}
59
60
static
void
node_build_multi_function
(
blender::nodes::NodeMultiFunctionBuilder
&builder)
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
)) {
66
case
CMP_NODE_ALPHA_CONVERT_PREMULTIPLY
:
67
return
float4
(
color
.xyz() *
color
.w,
color
.w);
68
case
CMP_NODE_ALPHA_CONVERT_UNPREMULTIPLY
:
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
79
static
void
register_node_type_cmp_premulkey
()
80
{
81
namespace
file_ns =
blender::nodes::node_composite_premulkey_cc
;
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"
;
89
ntype.
nclass
=
NODE_CLASS_CONVERTER
;
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
94
blender::bke::node_register_type
(ntype);
95
}
96
NOD_REGISTER_NODE
(
register_node_type_cmp_premulkey
)
NODE_CLASS_CONVERTER
#define NODE_CLASS_CONVERTER
Definition
BKE_node.hh:453
CMP_NODE_PREMULKEY
#define CMP_NODE_PREMULKEY
Definition
BKE_node_legacy_types.hh:205
BLI_math_vector_types.hh
CMPNodeAlphaConvertMode
CMPNodeAlphaConvertMode
Definition
DNA_node_types.h:3074
CMP_NODE_ALPHA_CONVERT_UNPREMULTIPLY
@ CMP_NODE_ALPHA_CONVERT_UNPREMULTIPLY
Definition
DNA_node_types.h:3076
CMP_NODE_ALPHA_CONVERT_PREMULTIPLY
@ CMP_NODE_ALPHA_CONVERT_PREMULTIPLY
Definition
DNA_node_types.h:3075
FN_multi_function_builder.hh
GPU_material.hh
GPU_stack_link
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
Definition
gpu_node_graph.cc:851
NOD_multi_function.hh
NOD_REGISTER_NODE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
Definition
NOD_register.hh:34
blender::nodes::NodeDeclarationBuilder
Definition
NOD_node_declaration.hh:664
blender::nodes::NodeMultiFunctionBuilder
Definition
NOD_multi_function.hh:18
blender::nodes::NodeMultiFunctionBuilder::set_matching_fn
void set_matching_fn(const mf::MultiFunction *fn)
Definition
NOD_multi_function.hh:99
blender::nodes::SocketDeclaration::optional_label
bool optional_label
Definition
NOD_node_declaration.hh:222
blender::nodes::decl::Color
Definition
NOD_socket_declarations.hh:139
blender::nodes::decl::Menu
Definition
NOD_socket_declarations.hh:230
b
b
Definition
compositor_morphological_distance_infos.hh:24
blender::bke::node_register_type
void node_register_type(bNodeType &ntype)
Definition
node.cc:2416
blender::color
Definition
BLI_color.hh:32
blender::compositor
Definition
BKE_node.hh:77
blender::nodes::node_composite_premulkey_cc
Definition
node_composite_premulkey.cc:19
blender::nodes::node_composite_premulkey_cc::cmp_node_premulkey_declare
static void cmp_node_premulkey_declare(NodeDeclarationBuilder &b)
Definition
node_composite_premulkey.cc:35
blender::nodes::node_composite_premulkey_cc::type_items
static const EnumPropertyItem type_items[]
Definition
node_composite_premulkey.cc:21
blender::nodes::node_composite_premulkey_cc::node_gpu_material
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
Definition
node_composite_premulkey.cc:51
blender::nodes::node_composite_premulkey_cc::node_build_multi_function
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
Definition
node_composite_premulkey.cc:60
blender::float4
VecBase< float, 4 > float4
Definition
BLI_math_vector_types.hh:620
register_node_type_cmp_premulkey
static void register_node_type_cmp_premulkey()
Definition
node_composite_premulkey.cc:79
cmp_node_type_base
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Definition
node_composite_util.cc:33
node_composite_util.hh
outputs
static blender::bke::bNodeSocketTemplate outputs[]
Definition
node_texture_at.cc:16
inputs
static blender::bke::bNodeSocketTemplate inputs[]
Definition
node_texture_at.cc:11
EnumPropertyItem
Definition
RNA_types.hh:648
GPUMaterial
Definition
gpu/intern/gpu_material.cc:63
GPUNodeStack
Definition
GPU_material.hh:295
bNodeExecData
Definition
node_util.hh:22
bNode
Definition
DNA_node_types.h:422
blender::bke::bNodeType
Defines a node type.
Definition
BKE_node.hh:238
blender::bke::bNodeType::ui_description
std::string ui_description
Definition
BKE_node.hh:244
blender::bke::bNodeType::ui_name
std::string ui_name
Definition
BKE_node.hh:243
blender::bke::bNodeType::gpu_fn
NodeGPUExecFunction gpu_fn
Definition
BKE_node.hh:342
blender::bke::bNodeType::build_multi_function
NodeMultiFunctionBuildFunction build_multi_function
Definition
BKE_node.hh:351
blender::bke::bNodeType::nclass
short nclass
Definition
BKE_node.hh:251
blender::bke::bNodeType::enum_name_legacy
const char * enum_name_legacy
Definition
BKE_node.hh:247
blender::bke::bNodeType::declare
NodeDeclareFunction declare
Definition
BKE_node.hh:362
blender::nodes::MenuValue
Definition
NOD_menu_value.hh:16
blender::nodes::MenuValue::value
int value
Definition
NOD_menu_value.hh:17
N_
#define N_(msgid)
Definition
versioning_userdef.cc:63
Generated on
for Blender by
doxygen
1.16.1