Blender V4.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.h"
10#include "BLI_math_vector.h"
11#include "node_texture_util.hh"
12
14 {SOCK_FLOAT, N_("Hue"), 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.5f, PROP_NONE},
15 {SOCK_FLOAT, N_("Saturation"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_NONE},
16 {SOCK_FLOAT, N_("Value"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_NONE},
17 {SOCK_FLOAT, N_("Factor"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE},
18 {SOCK_RGBA, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f},
19 {-1, ""},
20};
22 {SOCK_RGBA, N_("Color")},
23 {-1, ""},
24};
25
26static void do_hue_sat_fac(
27 bNode * /*node*/, float *out, float hue, float sat, float val, float *in, float fac)
28{
29 if (fac != 0 && (hue != 0.5f || sat != 1 || val != 1)) {
30 float col[3], hsv[3], mfac = 1.0f - fac;
31
32 rgb_to_hsv(in[0], in[1], in[2], hsv, hsv + 1, hsv + 2);
33 hsv[0] += (hue - 0.5f);
34 if (hsv[0] > 1.0f) {
35 hsv[0] -= 1.0f;
36 }
37 else if (hsv[0] < 0.0f) {
38 hsv[0] += 1.0f;
39 }
40 hsv[1] *= sat;
41 if (hsv[1] > 1.0f) {
42 hsv[1] = 1.0f;
43 }
44 else if (hsv[1] < 0.0f) {
45 hsv[1] = 0.0f;
46 }
47 hsv[2] *= val;
48 if (hsv[2] > 1.0f) {
49 hsv[2] = 1.0f;
50 }
51 else if (hsv[2] < 0.0f) {
52 hsv[2] = 0.0f;
53 }
54 hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col + 1, col + 2);
55
56 out[0] = mfac * in[0] + fac * col[0];
57 out[1] = mfac * in[1] + fac * col[1];
58 out[2] = mfac * in[2] + fac * col[2];
59 }
60 else {
61 copy_v4_v4(out, in);
62 }
63}
64
65static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
66{
67 float hue = tex_input_value(in[0], p, thread);
68 float sat = tex_input_value(in[1], p, thread);
69 float val = tex_input_value(in[2], p, thread);
70 float fac = tex_input_value(in[3], p, thread);
71
72 float col[4];
73 tex_input_rgba(col, in[4], p, thread);
74
75 hue += 0.5f; /* [-0.5, 0.5] -> [0, 1] */
76
77 do_hue_sat_fac(node, out, hue, sat, val, col, fac);
78
79 out[3] = col[3];
80}
81
82static void exec(void *data,
83 int /*thread*/,
84 bNode *node,
85 bNodeExecData *execdata,
86 bNodeStack **in,
87 bNodeStack **out)
88{
89 tex_output(node, execdata, in, out[0], &colorfn, static_cast<TexCallData *>(data));
90}
91
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:406
#define TEX_NODE_HUE_SAT
Definition BKE_node.hh:1146
void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v)
void hsv_to_rgb(float h, float s, float v, float *r_r, float *r_g, float *r_b)
Definition math_color.cc:21
MINLINE void copy_v4_v4(float r[4], const float a[4])
@ 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 Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture 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.hh:136
uint col
void node_type_size_preset(bNodeType *ntype, eNodeSizePreset size)
Definition node.cc:4614
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 blender::bke::bNodeSocketTemplate outputs[]
static void colorfn(float *out, TexParams *p, bNode *, bNodeStack **in, short thread)
static void exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static blender::bke::bNodeSocketTemplate inputs[]
static void exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static void do_hue_sat_fac(bNode *, float *out, float hue, float sat, float val, float *in, float fac)
static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
void register_node_type_tex_hue_sat()
void tex_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
float tex_input_value(bNodeStack *in, TexParams *params, short thread)
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)
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
#define N_(msgid)