Blender  V3.3
node_texture_hueSatVal.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2006 Blender Foundation. All rights reserved. */
3 
8 #include "NOD_texture.h"
9 #include "node_texture_util.h"
10 
12  {SOCK_FLOAT, N_("Hue"), 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.5f, PROP_NONE},
13  {SOCK_FLOAT, N_("Saturation"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_NONE},
14  {SOCK_FLOAT, N_("Value"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_NONE},
15  {SOCK_FLOAT, N_("Factor"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE},
16  {SOCK_RGBA, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f},
17  {-1, ""},
18 };
20  {SOCK_RGBA, N_("Color")},
21  {-1, ""},
22 };
23 
24 static void do_hue_sat_fac(
25  bNode *UNUSED(node), float *out, float hue, float sat, float val, float *in, float fac)
26 {
27  if (fac != 0 && (hue != 0.5f || sat != 1 || val != 1)) {
28  float col[3], hsv[3], mfac = 1.0f - fac;
29 
30  rgb_to_hsv(in[0], in[1], in[2], hsv, hsv + 1, hsv + 2);
31  hsv[0] += (hue - 0.5f);
32  if (hsv[0] > 1.0f) {
33  hsv[0] -= 1.0f;
34  }
35  else if (hsv[0] < 0.0f) {
36  hsv[0] += 1.0f;
37  }
38  hsv[1] *= sat;
39  if (hsv[1] > 1.0f) {
40  hsv[1] = 1.0f;
41  }
42  else if (hsv[1] < 0.0f) {
43  hsv[1] = 0.0f;
44  }
45  hsv[2] *= val;
46  if (hsv[2] > 1.0f) {
47  hsv[2] = 1.0f;
48  }
49  else if (hsv[2] < 0.0f) {
50  hsv[2] = 0.0f;
51  }
52  hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col + 1, col + 2);
53 
54  out[0] = mfac * in[0] + fac * col[0];
55  out[1] = mfac * in[1] + fac * col[1];
56  out[2] = mfac * in[2] + fac * col[2];
57  }
58  else {
59  copy_v4_v4(out, in);
60  }
61 }
62 
63 static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
64 {
65  float hue = tex_input_value(in[0], p, thread);
66  float sat = tex_input_value(in[1], p, thread);
67  float val = tex_input_value(in[2], p, thread);
68  float fac = tex_input_value(in[3], p, thread);
69 
70  float col[4];
71  tex_input_rgba(col, in[4], p, thread);
72 
73  hue += 0.5f; /* [-0.5, 0.5] -> [0, 1] */
74 
75  do_hue_sat_fac(node, out, hue, sat, val, col, fac);
76 
77  out[3] = col[3];
78 }
79 
80 static void exec(void *data,
81  int UNUSED(thread),
82  bNode *node,
83  bNodeExecData *execdata,
84  bNodeStack **in,
85  bNodeStack **out)
86 {
87  tex_output(node, execdata, in, out[0], &colorfn, data);
88 }
89 
91 {
92  static bNodeType ntype;
93 
94  tex_node_type_base(&ntype, TEX_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR);
97  node_type_exec(&ntype, NULL, NULL, exec);
98 
99  nodeRegisterType(&ntype);
100 }
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4358
void node_type_size_preset(struct bNodeType *ntype, eNodeSizePreset size)
Definition: node.cc:4408
#define NODE_CLASS_OP_COLOR
Definition: BKE_node.h:347
void node_type_exec(struct bNodeType *ntype, NodeInitExecFunction init_exec_fn, NodeFreeExecFunction free_exec_fn, NodeExecFunction exec_fn)
Definition: node.cc:4455
#define TEX_NODE_HUE_SAT
Definition: BKE_node.h:1358
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
@ NODE_SIZE_MIDDLE
Definition: BKE_node.h:366
void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v)
Definition: math_color.c:208
void hsv_to_rgb(float h, float s, float v, float *r_r, float *r_g, float *r_b)
Definition: math_color.c:13
MINLINE void copy_v4_v4(float r[4], const float a[4])
#define UNUSED(x)
@ SOCK_FLOAT
@ SOCK_RGBA
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its hue
@ PROP_NONE
Definition: RNA_types.h:126
Definition: thread.h:34
OperationNode * node
uint col
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static bNodeSocketTemplate outputs[]
static void do_hue_sat_fac(bNode *UNUSED(node), float *out, float hue, float sat, float val, float *in, float fac)
static bNodeSocketTemplate inputs[]
static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
void register_node_type_tex_hue_sat(void)
float tex_input_value(bNodeStack *in, TexParams *params, short thread)
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
void tex_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass)
void tex_output(bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
Compact definition of a node socket.
Definition: BKE_node.h:84
Defines a node type.
Definition: BKE_node.h:226
#define N_(msgid)