Blender V4.5
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 "UI_interface.hh"
16#include "UI_resources.hh"
17
18#include "GPU_material.hh"
19
21
22/* **************** Pre-multiply and Key Alpha Convert ******************** */
23
25
27{
28 b.add_input<decl::Color>("Image")
29 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
30 .compositor_domain_priority(0);
31 b.add_output<decl::Color>("Image");
32}
33
35{
36 layout->prop(ptr, "mapping", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
37}
38
39using namespace blender::compositor;
40
42{
43 return static_cast<CMPNodeAlphaConvertMode>(node.custom1);
44}
45
46static int node_gpu_material(GPUMaterial *material,
47 bNode *node,
48 bNodeExecData * /*execdata*/,
51{
52 switch (get_mode(*node)) {
54 return GPU_stack_link(material, node, "color_alpha_premultiply", inputs, outputs);
56 return GPU_stack_link(material, node, "color_alpha_unpremultiply", inputs, outputs);
57 }
58
59 return false;
60}
61
63{
64 static auto premultiply_function = mf::build::SI1_SO<float4, float4>(
65 "Alpha Convert Premultiply",
66 [](const float4 &color) -> float4 { return float4(color.xyz() * color.w, color.w); },
67 mf::build::exec_presets::AllSpanOrSingle());
68
69 static auto unpremultiply_function = mf::build::SI1_SO<float4, float4>(
70 "Alpha Convert Unpremultiply",
71 [](const float4 &color) -> float4 {
72 if (ELEM(color.w, 0.0f, 1.0f)) {
73 return color;
74 }
75 return float4(color.xyz() / color.w, color.w);
76 },
77 mf::build::exec_presets::AllSpanOrSingle());
78
79 switch (get_mode(builder.node())) {
81 builder.set_matching_fn(premultiply_function);
82 break;
84 builder.set_matching_fn(unpremultiply_function);
85 break;
86 }
87}
88
89} // namespace blender::nodes::node_composite_premulkey_cc
90
92{
94
95 static blender::bke::bNodeType ntype;
96
97 cmp_node_type_base(&ntype, "CompositorNodePremulKey", CMP_NODE_PREMULKEY);
98 ntype.ui_name = "Alpha Convert";
99 ntype.ui_description = "Convert to and from premultiplied (associated) alpha";
100 ntype.enum_name_legacy = "PREMULKEY";
102 ntype.declare = file_ns::cmp_node_premulkey_declare;
103 ntype.draw_buttons = file_ns::node_composit_buts_premulkey;
104 ntype.gpu_fn = file_ns::node_gpu_material;
105 ntype.build_multi_function = file_ns::node_build_multi_function;
106
108}
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:439
#define CMP_NODE_PREMULKEY
#define ELEM(...)
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)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
void set_matching_fn(const mf::MultiFunction *fn)
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
static void cmp_node_premulkey_declare(NodeDeclarationBuilder &b)
static void node_composit_buts_premulkey(uiLayout *layout, bContext *, PointerRNA *ptr)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
static CMPNodeAlphaConvertMode get_mode(const bNode &node)
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[]
int16_t custom1
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
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)
PointerRNA * ptr
Definition wm_files.cc:4226