Blender V4.3
node_texture_separate_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 "BLI_listbase.h"
10#include "BLI_math_color.h"
11#include "NOD_texture.h"
12#include "node_texture_util.hh"
13#include "node_util.hh"
14#include <cmath>
15
17 {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
18 {-1, ""},
19};
21 {SOCK_FLOAT, N_("Red")},
22 {SOCK_FLOAT, N_("Green")},
23 {SOCK_FLOAT, N_("Blue")},
24 {SOCK_FLOAT, N_("Alpha")},
25 {-1, ""},
26};
27
28static void apply_color_space(float *out, NodeCombSepColorMode type)
29{
30 switch (type) {
32 /* Pass */
33 break;
34 }
36 rgb_to_hsv_v(out, out);
37 break;
38 }
40 rgb_to_hsl_v(out, out);
41 break;
42 }
43 default: {
45 break;
46 }
47 }
48}
49
50static void valuefn_r(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
51{
52 tex_input_rgba(out, in[0], p, thread);
53 apply_color_space(out, (NodeCombSepColorMode)node->custom1);
54 *out = out[0];
55}
56
57static void valuefn_g(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
58{
59 tex_input_rgba(out, in[0], p, thread);
60 apply_color_space(out, (NodeCombSepColorMode)node->custom1);
61 *out = out[1];
62}
63
64static void valuefn_b(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
65{
66 tex_input_rgba(out, in[0], p, thread);
67 apply_color_space(out, (NodeCombSepColorMode)node->custom1);
68 *out = out[2];
69}
70
71static void valuefn_a(float *out, TexParams *p, bNode * /*node*/, bNodeStack **in, short thread)
72{
73 tex_input_rgba(out, in[0], p, thread);
74 *out = out[3];
75}
76
77static void update(bNodeTree * /*ntree*/, bNode *node)
78{
79 node_combsep_color_label(&node->outputs, (NodeCombSepColorMode)node->custom1);
80}
81
82static void exec(void *data,
83 int /*thread*/,
84 bNode *node,
85 bNodeExecData *execdata,
86 bNodeStack **in,
87 bNodeStack **out)
88{
89 TexCallData *tex_call_data = static_cast<TexCallData *>(data);
90 tex_output(node, execdata, in, out[0], &valuefn_r, tex_call_data);
91 tex_output(node, execdata, in, out[1], &valuefn_g, tex_call_data);
92 tex_output(node, execdata, in, out[2], &valuefn_b, tex_call_data);
93 tex_output(node, execdata, in, out[3], &valuefn_a, tex_call_data);
94}
95
97{
98 static blender::bke::bNodeType ntype;
99
100 tex_node_type_base(&ntype, TEX_NODE_SEPARATE_COLOR, "Separate Color", NODE_CLASS_OP_COLOR);
101 blender::bke::node_type_socket_templates(&ntype, inputs, outputs);
102 ntype.exec_fn = exec;
103 ntype.updatefunc = update;
104
106}
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:406
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
void rgb_to_hsl_v(const float rgb[3], float r_hsl[3])
@ SOCK_FLOAT
@ SOCK_RGBA
NodeCombSepColorMode
@ NODE_COMBSEP_COLOR_RGB
@ NODE_COMBSEP_COLOR_HSV
@ NODE_COMBSEP_COLOR_HSL
void node_type_socket_templates(bNodeType *ntype, bNodeSocketTemplate *inputs, bNodeSocketTemplate *outputs)
Definition node.cc:4570
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void update(bNodeTree *, bNode *node)
static void apply_color_space(float *out, NodeCombSepColorMode type)
static void valuefn_b(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
void register_node_type_tex_separate_color()
static void exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static void valuefn_r(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
static void valuefn_a(float *out, TexParams *p, bNode *, bNodeStack **in, short thread)
static void valuefn_g(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
void tex_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
void tex_output(bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
void node_combsep_color_label(const ListBase *sockets, NodeCombSepColorMode mode)
Definition node_util.cc:242
Compact definition of a node socket.
Definition BKE_node.hh:103
Defines a node type.
Definition BKE_node.hh:218
NodeExecFunction exec_fn
Definition BKE_node.hh:316
void(* updatefunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:257
#define N_(msgid)