Blender V4.3
node_composite_channel_matte.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
9#include "RNA_access.hh"
10
11#include "UI_interface.hh"
12#include "UI_resources.hh"
13
14#include "GPU_material.hh"
15
16#include "COM_shader_node.hh"
17
19
20/* ******************* Channel Matte Node ********************************* */
21
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 b.add_output<decl::Float>("Matte");
33}
34
35static void node_composit_init_channel_matte(bNodeTree * /*ntree*/, bNode *node)
36{
37 NodeChroma *c = MEM_cnew<NodeChroma>(__func__);
38 node->storage = c;
39 c->t1 = 1.0f;
40 c->t2 = 0.0f;
41 c->t3 = 0.0f;
42 c->fsize = 0.0f;
43 c->fstrength = 0.0f;
44 c->algorithm = 1; /* Max channel limiting. */
45 c->channel = 1; /* Limit by red. */
46 node->custom1 = 1; /* RGB channel. */
47 node->custom2 = 2; /* Green Channel. */
48}
49
51{
52 uiLayout *col, *row;
53
54 uiItemL(layout, IFACE_("Color Space:"), ICON_NONE);
55 row = uiLayoutRow(layout, false);
56 uiItemR(
57 row, ptr, "color_space", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
58
59 col = uiLayoutColumn(layout, false);
60 uiItemL(col, IFACE_("Key Channel:"), ICON_NONE);
61 row = uiLayoutRow(col, false);
62 uiItemR(row,
63 ptr,
64 "matte_channel",
66 nullptr,
67 ICON_NONE);
68
69 col = uiLayoutColumn(layout, false);
70
71 uiItemR(col, ptr, "limit_method", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
72 if (RNA_enum_get(ptr, "limit_method") == 0) {
73 uiItemL(col, IFACE_("Limiting Channel:"), ICON_NONE);
74 row = uiLayoutRow(col, false);
75 uiItemR(row,
76 ptr,
77 "limit_channel",
79 nullptr,
80 ICON_NONE);
81 }
82
83 uiItemR(
84 col, ptr, "limit_max", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
85 uiItemR(
86 col, ptr, "limit_min", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
87}
88
89using namespace blender::realtime_compositor;
90
92 public:
94
95 void compile(GPUMaterial *material) override
96 {
99
100 const float color_space = get_color_space();
101 const float matte_channel = get_matte_channel();
102 float limit_channels[2];
103 get_limit_channels(limit_channels);
104 const float max_limit = get_max_limit();
105 const float min_limit = get_min_limit();
106
107 GPU_stack_link(material,
108 &bnode(),
109 "node_composite_channel_matte",
110 inputs,
111 outputs,
112 GPU_constant(&color_space),
113 GPU_constant(&matte_channel),
114 GPU_constant(limit_channels),
115 GPU_uniform(&max_limit),
116 GPU_uniform(&min_limit));
117 }
118
119 /* 1 -> CMP_NODE_CHANNEL_MATTE_CS_RGB
120 * 2 -> CMP_NODE_CHANNEL_MATTE_CS_HSV
121 * 3 -> CMP_NODE_CHANNEL_MATTE_CS_YUV
122 * 4 -> CMP_NODE_CHANNEL_MATTE_CS_YCC */
124 {
125 return bnode().custom1;
126 }
127
128 /* Get the index of the channel used to generate the matte. */
130 {
131 return bnode().custom2 - 1;
132 }
133
134 /* Get the index of the channel used to compute the limit value. */
136 {
137 return node_storage(bnode()).channel - 1;
138 }
139
140 /* Get the indices of the channels used to compute the limit value. We always assume the limit
141 * algorithm is Max, if it is a single limit channel, store it in both limit channels, because
142 * the maximum of two identical values is the same value. */
143 void get_limit_channels(float limit_channels[2])
144 {
145 if (node_storage(bnode()).algorithm == CMP_NODE_CHANNEL_MATTE_LIMIT_ALGORITHM_MAX) {
146 /* If the algorithm is Max, store the indices of the other two channels other than the matte
147 * channel. */
148 limit_channels[0] = (get_matte_channel() + 1) % 3;
149 limit_channels[1] = (get_matte_channel() + 2) % 3;
150 }
151 else {
152 /* If the algorithm is Single, store the index of the limit channel in both channels. */
153 limit_channels[0] = get_limit_channel();
154 limit_channels[1] = get_limit_channel();
155 }
156 }
157
159 {
160 return node_storage(bnode()).t1;
161 }
162
164 {
165 return node_storage(bnode()).t2;
166 }
167};
168
170{
171 return new ChannelMatteShaderNode(node);
172}
173
174} // namespace blender::nodes::node_composite_channel_matte_cc
175
177{
179
180 static blender::bke::bNodeType ntype;
181
182 cmp_node_type_base(&ntype, CMP_NODE_CHANNEL_MATTE, "Channel Key", NODE_CLASS_MATTE);
183 ntype.declare = file_ns::cmp_node_channel_matte_declare;
184 ntype.draw_buttons = file_ns::node_composit_buts_channel_matte;
185 ntype.flag |= NODE_PREVIEW;
186 ntype.initfunc = file_ns::node_composit_init_channel_matte;
189 ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
190
192}
#define NODE_CLASS_MATTE
Definition BKE_node.hh:411
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1799
#define IFACE_(msgid)
@ NODE_PREVIEW
@ CMP_NODE_CHANNEL_MATTE_LIMIT_ALGORITHM_MAX
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_constant(const float *num)
GPUNodeLink * GPU_uniform(const float *num)
void uiItemL(uiLayout *layout, const char *name, int icon)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
@ UI_ITEM_R_EXPAND
@ UI_ITEM_R_SLIDER
local_group_size(16, 16) .push_constant(Type b
uint col
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void node_composit_buts_channel_matte(uiLayout *layout, bContext *, PointerRNA *ptr)
static void cmp_node_channel_matte_declare(NodeDeclarationBuilder &b)
static void node_composit_init_channel_matte(bNodeTree *, bNode *node)
void register_node_type_cmp_channel_matte()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:46
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:58
int RNA_enum_get(PointerRNA *ptr, const char *name)
int16_t custom1
int16_t custom2
Defines a node type.
Definition BKE_node.hh:218
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
NodeGetCompositorShaderNodeFunction get_compositor_shader_node
Definition BKE_node.hh:328
PointerRNA * ptr
Definition wm_files.cc:4126