Blender  V2.93
node_texture_valToRgb.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) 2005 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "IMB_colormanagement.h"
25 #include "NOD_texture.h"
26 #include "node_texture_util.h"
27 
28 /* **************** VALTORGB ******************** */
30  {SOCK_FLOAT, N_("Fac"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
31  {-1, ""},
32 };
34  {SOCK_RGBA, N_("Color")},
35  {-1, ""},
36 };
37 
38 static void valtorgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
39 {
40  if (node->storage) {
41  float fac = tex_input_value(in[0], p, thread);
42 
43  BKE_colorband_evaluate(node->storage, fac, out);
44  }
45 }
46 
47 static void valtorgb_exec(void *data,
48  int UNUSED(thread),
49  bNode *node,
50  bNodeExecData *execdata,
51  bNodeStack **in,
52  bNodeStack **out)
53 {
54  tex_output(node, execdata, in, out[0], &valtorgb_colorfn, data);
55 }
56 
58 {
59  node->storage = BKE_colorband_add(true);
60 }
61 
63 {
64  static bNodeType ntype;
65 
72 
73  nodeRegisterType(&ntype);
74 }
75 
76 /* **************** RGBTOBW ******************** */
78  {SOCK_RGBA, N_("Color"), 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f},
79  {-1, ""},
80 };
82  {SOCK_FLOAT, N_("Val"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
83  {-1, ""},
84 };
85 
86 static void rgbtobw_valuefn(
87  float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
88 {
89  float cin[4];
90  tex_input_rgba(cin, in[0], p, thread);
92 }
93 
94 static void rgbtobw_exec(void *data,
95  int UNUSED(thread),
96  bNode *node,
97  bNodeExecData *execdata,
98  bNodeStack **in,
99  bNodeStack **out)
100 {
101  tex_output(node, execdata, in, out[0], &rgbtobw_valuefn, data);
102 }
103 
105 {
106  static bNodeType ntype;
107 
108  tex_node_type_base(&ntype, TEX_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0);
111 
112  nodeRegisterType(&ntype);
113 }
struct ColorBand * BKE_colorband_add(bool rangetype)
Definition: colorband.c:312
bool BKE_colorband_evaluate(const struct ColorBand *coba, float in, float out[4])
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4559
#define NODE_CLASS_CONVERTOR
Definition: BKE_node.h:341
void node_type_size_preset(struct bNodeType *ntype, eNodeSizePreset size)
Definition: node.cc:4577
#define TEX_NODE_RGBTOBW
Definition: BKE_node.h:1331
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
Definition: node.cc:4599
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_LARGE
Definition: BKE_node.h:373
#define UNUSED(x)
#define N_(msgid)
@ SOCK_FLOAT
@ SOCK_RGBA
BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3])
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 Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix TEX_NODE_VALTORGB
@ PROP_FACTOR
Definition: RNA_types.h:131
OperationNode * node
bNodeTree * ntree
void tex_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag)
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)
static bNodeSocketTemplate valtorgb_in[]
static void rgbtobw_valuefn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
static bNodeSocketTemplate rgbtobw_out[]
static void valtorgb_init(bNodeTree *UNUSED(ntree), bNode *node)
static bNodeSocketTemplate valtorgb_out[]
void register_node_type_tex_rgbtobw(void)
static void valtorgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
void register_node_type_tex_valtorgb(void)
static void rgbtobw_exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static bNodeSocketTemplate rgbtobw_in[]
static void valtorgb_exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:67
void node_free_standard_storage(bNode *node)
Definition: node_util.c:55
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221