Blender  V2.93
node_shader_sepcombHSV.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) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "node_shader_util.h"
25 
26 /* **************** SEPARATE HSV ******************** */
28  {SOCK_RGBA, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f},
29  {-1, ""},
30 };
32  {SOCK_FLOAT, N_("H")},
33  {SOCK_FLOAT, N_("S")},
34  {SOCK_FLOAT, N_("V")},
35  {-1, ""},
36 };
37 
38 static void node_shader_exec_sephsv(void *UNUSED(data),
39  int UNUSED(thread),
40  bNode *UNUSED(node),
41  bNodeExecData *UNUSED(execdata),
42  bNodeStack **in,
43  bNodeStack **out)
44 {
45  float col[3];
47 
48  rgb_to_hsv(col[0], col[1], col[2], &out[0]->vec[0], &out[1]->vec[0], &out[2]->vec[0]);
49 }
50 
52  bNode *node,
53  bNodeExecData *UNUSED(execdata),
54  GPUNodeStack *in,
55  GPUNodeStack *out)
56 {
57  return GPU_stack_link(mat, node, "separate_hsv", in, out);
58 }
59 
61 {
62  static bNodeType ntype;
63 
64  sh_node_type_base(&ntype, SH_NODE_SEPHSV, "Separate HSV", NODE_CLASS_CONVERTOR, 0);
68 
69  nodeRegisterType(&ntype);
70 }
71 
72 /* **************** COMBINE HSV ******************** */
74  {SOCK_FLOAT, N_("H"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED},
75  {SOCK_FLOAT, N_("S"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED},
76  {SOCK_FLOAT, N_("V"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED},
77  {-1, ""},
78 };
80  {SOCK_RGBA, N_("Color")},
81  {-1, ""},
82 };
83 
85  int UNUSED(thread),
86  bNode *UNUSED(node),
87  bNodeExecData *UNUSED(execdata),
88  bNodeStack **in,
89  bNodeStack **out)
90 {
91  float h, s, v;
92  nodestack_get_vec(&h, SOCK_FLOAT, in[0]);
93  nodestack_get_vec(&s, SOCK_FLOAT, in[1]);
94  nodestack_get_vec(&v, SOCK_FLOAT, in[2]);
95 
96  hsv_to_rgb(h, s, v, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2]);
97 }
98 
100  bNode *node,
101  bNodeExecData *UNUSED(execdata),
102  GPUNodeStack *in,
103  GPUNodeStack *out)
104 {
105  return GPU_stack_link(mat, node, "combine_hsv", in, out);
106 }
107 
109 {
110  static bNodeType ntype;
111 
112  sh_node_type_base(&ntype, SH_NODE_COMBHSV, "Combine HSV", NODE_CLASS_CONVERTOR, 0);
116 
117  nodeRegisterType(&ntype);
118 }
#define SH_NODE_SEPHSV
Definition: BKE_node.h:1048
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4645
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
#define NODE_CLASS_CONVERTOR
Definition: BKE_node.h:341
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
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
#define UNUSED(x)
#define N_(msgid)
@ SOCK_VECTOR
@ SOCK_FLOAT
@ SOCK_RGBA
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector SH_NODE_COMBHSV
@ PROP_UNSIGNED
Definition: RNA_types.h:129
ATTR_WARN_UNUSED_RESULT const BMVert * v
OperationNode * node
uint col
static bNodeSocketTemplate sh_node_combhsv_out[]
static int gpu_shader_sephsv(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_exec_sephsv(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out)
static int gpu_shader_combhsv(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static bNodeSocketTemplate sh_node_combhsv_in[]
static bNodeSocketTemplate sh_node_sephsv_out[]
static bNodeSocketTemplate sh_node_sephsv_in[]
void register_node_type_sh_combhsv(void)
static void node_shader_exec_combhsv(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out)
void register_node_type_sh_sephsv(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