Blender V4.3
node_shader_sepcomb_color.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "node_shader_util.hh"
10#include "node_util.hh"
11
12#include "UI_interface.hh"
13#include "UI_resources.hh"
14
15static void node_combsep_color_init(bNodeTree * /*tree*/, bNode *node)
16{
17 NodeCombSepColor *data = MEM_cnew<NodeCombSepColor>(__func__);
18 data->mode = NODE_COMBSEP_COLOR_RGB;
19 node->storage = data;
20}
21
22/* **************** SEPARATE COLOR ******************** */
23
25
27
29{
30 b.add_input<decl::Color>("Color").default_value({0.8f, 0.8f, 0.8f, 1.0f});
31 b.add_output<decl::Float>("Red");
32 b.add_output<decl::Float>("Green");
33 b.add_output<decl::Float>("Blue");
34}
35
36static void node_sepcolor_update(bNodeTree * /*ntree*/, bNode *node)
37{
38 const NodeCombSepColor &storage = node_storage(*node);
39 node_combsep_color_label(&node->outputs, (NodeCombSepColorMode)storage.mode);
40}
41
42static const char *gpu_shader_get_name(int mode)
43{
44 switch (mode) {
46 return "separate_color_rgb";
48 return "separate_color_hsv";
50 return "separate_color_hsl";
51 }
52
53 return nullptr;
54}
55
57 bNode *node,
58 bNodeExecData * /*execdata*/,
59 GPUNodeStack *in,
60 GPUNodeStack *out)
61{
62 const NodeCombSepColor &storage = node_storage(*node);
63 const char *name = gpu_shader_get_name(storage.mode);
64 if (name != nullptr) {
65 return GPU_stack_link(mat, node, name, in, out);
66 }
67
68 return 0;
69}
70
72#ifdef WITH_MATERIALX
73{
74 int mode = static_cast<NodeCombSepColor *>(node_->storage)->mode;
75 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
76
77 NodeItem convert = empty();
78 switch (mode) {
80 convert = color;
81 break;
84 /* NOTE: HSL is unsupported color model, using HSV instead */
85 convert = create_node("rgbtohsv", NodeItem::Type::Color3, {{"in", color}});
86 break;
87 default:
89 }
90
91 int index = STREQ(socket_out_->name, "Red") ? 0 : STREQ(socket_out_->name, "Green") ? 1 : 2;
92 return convert[index];
93}
94#endif
96
97} // namespace blender::nodes::node_shader_separate_color_cc
98
100{
102
103 static blender::bke::bNodeType ntype;
104
106 ntype.declare = file_ns::sh_node_sepcolor_declare;
107 ntype.updatefunc = file_ns::node_sepcolor_update;
110 &ntype, "NodeCombSepColor", node_free_standard_storage, node_copy_standard_storage);
111 ntype.gpu_fn = file_ns::gpu_shader_sepcolor;
112 ntype.materialx_fn = file_ns::node_shader_materialx;
113
115}
116
117/* **************** COMBINE COLOR ******************** */
118
120
122
124{
125 b.add_input<decl::Float>("Red").default_value(0.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
126 b.add_input<decl::Float>("Green").default_value(0.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
127 b.add_input<decl::Float>("Blue").default_value(0.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
128 b.add_output<decl::Color>("Color");
129}
130
131static void node_combcolor_update(bNodeTree * /*ntree*/, bNode *node)
132{
133 const NodeCombSepColor &storage = node_storage(*node);
134 node_combsep_color_label(&node->inputs, (NodeCombSepColorMode)storage.mode);
135}
136
137static const char *gpu_shader_get_name(int mode)
138{
139 switch (mode) {
141 return "combine_color_rgb";
143 return "combine_color_hsv";
145 return "combine_color_hsl";
146 }
147
148 return nullptr;
149}
150
152 bNode *node,
153 bNodeExecData * /*execdata*/,
154 GPUNodeStack *in,
155 GPUNodeStack *out)
156{
157 const NodeCombSepColor &storage = node_storage(*node);
158 const char *name = gpu_shader_get_name(storage.mode);
159 if (name != nullptr) {
160 return GPU_stack_link(mat, node, name, in, out);
161 }
162
163 return 0;
164}
165
167#ifdef WITH_MATERIALX
168{
169 int mode = static_cast<NodeCombSepColor *>(node_->storage)->mode;
170 NodeItem red = get_input_value("Red", NodeItem::Type::Float);
171 NodeItem green = get_input_value("Green", NodeItem::Type::Float);
172 NodeItem blue = get_input_value("Blue", NodeItem::Type::Float);
173
174 NodeItem combine = create_node("combine3", NodeItem::Type::Color3);
175 combine.set_input("in1", red);
176 combine.set_input("in2", green);
177 combine.set_input("in3", blue);
178
179 NodeItem res = empty();
180 switch (mode) {
182 res = combine;
183 break;
186 /* NOTE: HSL is unsupported color model, using HSV instead */
187 res = create_node("hsvtorgb", NodeItem::Type::Color3);
188 res.set_input("in", combine);
189 break;
190 default:
192 }
193 return res;
194}
195#endif
197
198} // namespace blender::nodes::node_shader_combine_color_cc
199
201{
203
204 static blender::bke::bNodeType ntype;
205
207 ntype.declare = file_ns::sh_node_combcolor_declare;
208 ntype.updatefunc = file_ns::node_combcolor_update;
211 &ntype, "NodeCombSepColor", node_free_standard_storage, node_copy_standard_storage);
212 ntype.gpu_fn = file_ns::gpu_shader_combcolor;
213 ntype.materialx_fn = file_ns::node_shader_materialx;
214
216}
#define SH_NODE_COMBINE_COLOR
Definition BKE_node.hh:994
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:410
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1799
#define SH_NODE_SEPARATE_COLOR
Definition BKE_node.hh:995
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
#define STREQ(a, b)
NodeCombSepColorMode
@ NODE_COMBSEP_COLOR_RGB
@ NODE_COMBSEP_COLOR_HSV
@ NODE_COMBSEP_COLOR_HSL
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a producing a negative Combine Generate a color from its red
@ PROP_FACTOR
Definition RNA_types.hh:154
local_group_size(16, 16) .push_constant(Type b
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
void convert(SignedNormalized< StorageType > &dst, const F32 &src)
static void node_combcolor_update(bNodeTree *, bNode *node)
static void sh_node_combcolor_declare(NodeDeclarationBuilder &b)
static int gpu_shader_combcolor(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_sepcolor_update(bNodeTree *, bNode *node)
static int gpu_shader_sepcolor(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void sh_node_sepcolor_declare(NodeDeclarationBuilder &b)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_sepcolor()
static void node_combsep_color_init(bNodeTree *, bNode *node)
void register_node_type_sh_combcolor()
void sh_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
void node_combsep_color_label(const ListBase *sockets, NodeCombSepColorMode mode)
Definition node_util.cc:242
Defines a node type.
Definition BKE_node.hh:218
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:320
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:318
NodeDeclareFunction declare
Definition BKE_node.hh:347
void(* updatefunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:257