Blender V5.3
node_texture_hueSatVal.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
9#include "BLI_math_color_c.hh"
10#include "BLI_math_vector_c.hh"
11#include "node_texture_util.hh"
12
13namespace blender {
14
16 {SOCK_FLOAT, N_("Hue"), 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.5f, PROP_NONE},
17 {SOCK_FLOAT, N_("Saturation"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_NONE},
18 {SOCK_FLOAT, N_("Value"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_NONE},
19 {SOCK_FLOAT, N_("Factor"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE},
20 {SOCK_RGBA, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f},
21 {-1, ""},
22};
24 {SOCK_RGBA, N_("Color")},
25 {-1, ""},
26};
27
28static void do_hue_sat_fac(
29 bNode * /*node*/, float *out, float hue, float sat, float val, float *in, float fac)
30{
31 if (fac != 0 && (hue != 0.5f || sat != 1 || val != 1)) {
32 float col[3], hsv[3], mfac = 1.0f - fac;
33
34 rgb_to_hsv(in[0], in[1], in[2], hsv, hsv + 1, hsv + 2);
35 hsv[0] += (hue - 0.5f);
36 if (hsv[0] > 1.0f) {
37 hsv[0] -= 1.0f;
38 }
39 else if (hsv[0] < 0.0f) {
40 hsv[0] += 1.0f;
41 }
42 hsv[1] *= sat;
43 if (hsv[1] > 1.0f) {
44 hsv[1] = 1.0f;
45 }
46 else if (hsv[1] < 0.0f) {
47 hsv[1] = 0.0f;
48 }
49 hsv[2] *= val;
50 if (hsv[2] > 1.0f) {
51 hsv[2] = 1.0f;
52 }
53 else if (hsv[2] < 0.0f) {
54 hsv[2] = 0.0f;
55 }
56 hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col + 1, col + 2);
57
58 out[0] = mfac * in[0] + fac * col[0];
59 out[1] = mfac * in[1] + fac * col[1];
60 out[2] = mfac * in[2] + fac * col[2];
61 }
62 else {
64 }
65}
66
67static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
68{
69 float hue = tex_input_value(in[0], p, thread);
70 float sat = tex_input_value(in[1], p, thread);
71 float val = tex_input_value(in[2], p, thread);
72 float fac = tex_input_value(in[3], p, thread);
73
74 float col[4];
75 tex_input_rgba(col, in[4], p, thread);
76
77 hue += 0.5f; /* [-0.5, 0.5] -> [0, 1] */
78
79 do_hue_sat_fac(node, out, hue, sat, val, col, fac);
80
81 out[3] = col[3];
82}
83
84static void exec(void *data,
85 int /*thread*/,
86 bNode *node,
87 bNodeExecData *execdata,
88 bNodeStack **in,
90{
91 tex_output(node, execdata, in, out[0], &colorfn, static_cast<TexCallData *>(data));
92}
93
95{
96 static bke::bNodeType ntype;
97
98 tex_node_type_base(&ntype, "TextureNodeHueSaturation"_ustr, TEX_NODE_HUE_SAT);
99 ntype.ui_name = "Hue/Saturation/Value";
100 ntype.enum_name_legacy = "HUE_SAT";
104 ntype.exec_fn = exec;
105
107}
108
109} // namespace blender
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:480
#define TEX_NODE_HUE_SAT
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_socket_templates(bNodeType *ntype, bNodeSocketTemplate *inputs, bNodeSocketTemplate *outputs)
Definition node.cc:6134
BMesh Iterators.
void register_node_type_tex_hue_sat()
void hsv_to_rgb(float h, float s, float v, float *r_r, float *r_g, float *r_b)
Definition math_color.cc:25
static void do_hue_sat_fac(bNode *, float *out, float hue, float sat, float val, float *in, float fac)
static void exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
static void colorfn(float *out, TexParams *p, bNode *, bNodeStack **in, short thread)
void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v)
BMesh const char void * data
void tex_output(bNode *node, bNodeExecData *, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
static bke::bNodeSocketTemplate inputs[]
void tex_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
float tex_input_value(bNodeStack *in, TexParams *params, short thread)
static bke::bNodeSocketTemplate outputs[]
MINLINE void copy_v4_v4(float r[4], const float a[4])
static constexpr int _160
Definition BKE_node.hh:246
Compact definition of a node socket.
Definition BKE_node.hh:102
Defines a node type.
Definition BKE_node.hh:265
NodeExecFunction exec_fn
Definition BKE_node.hh:371
const char * enum_name_legacy
Definition BKE_node.hh:274
#define N_(msgid)