Blender  V2.93
node_shader_hueSatVal.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2006 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "node_shader_util.h"
25 
26 /* **************** Hue Saturation ******************** */
28  {SOCK_FLOAT, N_("Hue"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE},
29  {SOCK_FLOAT, N_("Saturation"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_NONE},
30  {SOCK_FLOAT, N_("Value"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_NONE},
31  {SOCK_FLOAT, N_("Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
32  {SOCK_RGBA, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f},
33  {-1, ""},
34 };
36  {SOCK_RGBA, N_("Color")},
37  {-1, ""},
38 };
39 
40 /* note: it would be possible to use CMP version for both nodes */
41 static void do_hue_sat_fac(
42  bNode *UNUSED(node), float *out, float hue, float sat, float val, const float in[4], float fac)
43 {
44  if (fac != 0.0f && (hue != 0.5f || sat != 1.0f || val != 1.0f)) {
45  float col[3], hsv[3], mfac = 1.0f - fac;
46 
47  rgb_to_hsv(in[0], in[1], in[2], hsv, hsv + 1, hsv + 2);
48  hsv[0] = fmodf(hsv[0] + hue + 0.5f, 1.0f);
49  hsv[1] = clamp_f(hsv[1] * sat, 0.0f, 1.0f);
50  hsv[2] *= val;
51  hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col + 1, col + 2);
52 
53  out[0] = mfac * in[0] + fac * col[0];
54  out[1] = mfac * in[1] + fac * col[1];
55  out[2] = mfac * in[2] + fac * col[2];
56  }
57  else {
58  copy_v4_v4(out, in);
59  }
60 }
61 
63  int UNUSED(thread),
64  bNode *node,
65  bNodeExecData *UNUSED(execdata),
66  bNodeStack **in,
67  bNodeStack **out)
68 {
69  float hue, sat, val, fac;
70  float col[4];
71  nodestack_get_vec(&hue, SOCK_FLOAT, in[0]);
72  nodestack_get_vec(&sat, SOCK_FLOAT, in[1]);
73  nodestack_get_vec(&val, SOCK_FLOAT, in[2]);
74  nodestack_get_vec(&fac, SOCK_FLOAT, in[3]);
76  do_hue_sat_fac(node, out[0]->vec, hue, sat, val, col, fac);
77 }
78 
80  bNode *node,
81  bNodeExecData *UNUSED(execdata),
82  GPUNodeStack *in,
83  GPUNodeStack *out)
84 {
85  return GPU_stack_link(mat, node, "hue_sat", in, out);
86 }
87 
89 {
90  static bNodeType ntype;
91 
92  sh_node_type_base(&ntype, SH_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR, 0);
97 
98  nodeRegisterType(&ntype);
99 }
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4645
#define SH_NODE_HUE_SAT
Definition: BKE_node.h:992
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
void node_type_size_preset(struct bNodeType *ntype, eNodeSizePreset size)
Definition: node.cc:4577
#define NODE_CLASS_OP_COLOR
Definition: BKE_node.h:336
void node_type_exec(struct bNodeType *ntype, NodeInitExecFunction init_exec_fn, NodeFreeExecFunction free_exec_fn, NodeExecFunction exec_fn)
Definition: node.cc:4635
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
@ NODE_SIZE_MIDDLE
Definition: BKE_node.h:372
MINLINE float clamp_f(float value, float min, float max)
void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v)
Definition: math_color.c:229
void hsv_to_rgb(float h, float s, float v, float *r_r, float *r_g, float *r_b)
Definition: math_color.c:31
MINLINE void copy_v4_v4(float r[4], const float a[4])
#define UNUSED(x)
#define N_(msgid)
@ SOCK_FLOAT
@ SOCK_RGBA
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ PROP_NONE
Definition: RNA_types.h:113
@ PROP_FACTOR
Definition: RNA_types.h:131
OperationNode * node
uint col
#define fmodf(x, y)
static int gpu_shader_hue_sat(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static bNodeSocketTemplate sh_node_hue_sat_out[]
static void do_hue_sat_fac(bNode *UNUSED(node), float *out, float hue, float sat, float val, const float in[4], float fac)
static bNodeSocketTemplate sh_node_hue_sat_in[]
static void node_shader_exec_hue_sat(void *UNUSED(data), int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out)
void register_node_type_sh_hue_sat(void)
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag)
void nodestack_get_vec(float *in, short type_in, bNodeStack *ns)
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221