Blender V4.3
node_composite_chroma_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 <cmath>
10
11#include "BLI_math_rotation.h"
12
13#include "UI_interface.hh"
14#include "UI_resources.hh"
15
16#include "GPU_material.hh"
17
18#include "COM_shader_node.hh"
19
21
22/* ******************* Chroma Key ********************************************************** */
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::Color>("Key Color")
34 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
35 .compositor_domain_priority(1);
36 b.add_output<decl::Color>("Image");
37 b.add_output<decl::Float>("Matte");
38}
39
40static void node_composit_init_chroma_matte(bNodeTree * /*ntree*/, bNode *node)
41{
42 NodeChroma *c = MEM_cnew<NodeChroma>(__func__);
43 node->storage = c;
44 c->t1 = DEG2RADF(30.0f);
45 c->t2 = DEG2RADF(10.0f);
46 c->t3 = 0.0f;
47 c->fsize = 0.0f;
48 c->fstrength = 1.0f;
49}
50
52{
54
55 col = uiLayoutColumn(layout, false);
56 uiItemR(col, ptr, "tolerance", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
57 uiItemR(col, ptr, "threshold", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
58
59 col = uiLayoutColumn(layout, true);
60 /* Removed for now. */
61 // uiItemR(col, ptr, "lift", UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
62 uiItemR(col, ptr, "gain", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
63 /* Removed for now. */
64 // uiItemR(col, ptr, "shadow_adjust", UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
65}
66
67using namespace blender::realtime_compositor;
68
70 public:
72
73 void compile(GPUMaterial *material) override
74 {
77
78 const float acceptance = get_acceptance();
79 const float cutoff = get_cutoff();
80 const float falloff = get_falloff();
81
82 GPU_stack_link(material,
83 &bnode(),
84 "node_composite_chroma_matte",
85 inputs,
86 outputs,
87 GPU_uniform(&acceptance),
88 GPU_uniform(&cutoff),
89 GPU_uniform(&falloff));
90 }
91
93 {
94 return std::tan(node_storage(bnode()).t1 / 2.0f);
95 }
96
97 float get_cutoff()
98 {
99 return node_storage(bnode()).t2;
100 }
101
103 {
104 return node_storage(bnode()).fstrength;
105 }
106};
107
109{
110 return new ChromaMatteShaderNode(node);
111}
112
113} // namespace blender::nodes::node_composite_chroma_matte_cc
114
116{
118
119 static blender::bke::bNodeType ntype;
120
121 cmp_node_type_base(&ntype, CMP_NODE_CHROMA_MATTE, "Chroma Key", NODE_CLASS_MATTE);
122 ntype.declare = file_ns::cmp_node_chroma_matte_declare;
123 ntype.draw_buttons = file_ns::node_composit_buts_chroma_matte;
124 ntype.flag |= NODE_PREVIEW;
125 ntype.initfunc = file_ns::node_composit_init_chroma_matte;
128 ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
129
131}
#define NODE_CLASS_MATTE
Definition BKE_node.hh:411
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1799
#define DEG2RADF(_deg)
@ NODE_PREVIEW
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_uniform(const float *num)
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_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 cmp_node_chroma_matte_declare(NodeDeclarationBuilder &b)
static void node_composit_buts_chroma_matte(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_composit_init_chroma_matte(bNodeTree *, bNode *node)
void register_node_type_cmp_chroma_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
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