Blender V5.3
node_texture_valToRgb.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BKE_colorband.hh"
11#include "node_texture_util.hh"
12#include "node_util.hh"
13
14namespace blender {
15
16/* **************** VALTORGB ******************** */
18 {SOCK_FLOAT, N_("Fac"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
19 {-1, ""},
20};
22 {SOCK_RGBA, N_("Color")},
23 {-1, ""},
24};
25
26static void valtorgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
27{
28 if (node->storage) {
29 float fac = tex_input_value(in[0], p, thread);
30
31 BKE_colorband_evaluate(static_cast<const ColorBand *>(node->storage), fac, out);
32 }
33}
34
35static void valtorgb_exec(void *data,
36 int /*thread*/,
37 bNode *node,
38 bNodeExecData *execdata,
39 bNodeStack **in,
41{
42 tex_output(node, execdata, in, out[0], &valtorgb_colorfn, static_cast<TexCallData *>(data));
43}
44
45static void valtorgb_init(bNodeTree * /*ntree*/, bNode *node)
46{
47 node->storage = BKE_colorband_add(true);
48}
49
51{
52 static bke::bNodeType ntype;
53
54 tex_node_type_base(&ntype, "TextureNodeValToRGB"_ustr, TEX_NODE_VALTORGB);
55 ntype.ui_name = "Color Ramp";
56 ntype.enum_name_legacy = "VALTORGB";
60 ntype.initfunc = valtorgb_init;
63 ntype.exec_fn = valtorgb_exec;
64
66}
67
68/* **************** RGBTOBW ******************** */
70 {SOCK_RGBA, N_("Color"), 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f},
71 {-1, ""},
72};
74 {SOCK_FLOAT, N_("Val"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
75 {-1, ""},
76};
77
78static void rgbtobw_valuefn(
79 float *out, TexParams *p, bNode * /*node*/, bNodeStack **in, short thread)
80{
81 float cin[4];
82 tex_input_rgba(cin, in[0], p, thread);
84}
85
86static void rgbtobw_exec(void *data,
87 int /*thread*/,
88 bNode *node,
89 bNodeExecData *execdata,
90 bNodeStack **in,
92{
93 tex_output(node, execdata, in, out[0], &rgbtobw_valuefn, static_cast<TexCallData *>(data));
94}
95
97{
98 static bke::bNodeType ntype;
99
100 tex_node_type_base(&ntype, "TextureNodeRGBToBW"_ustr, TEX_NODE_RGBTOBW);
101 ntype.ui_name = "RGB to BW";
102 ntype.enum_name_legacy = "RGBTOBW";
105 ntype.exec_fn = rgbtobw_exec;
106
108}
109
110} // namespace blender
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define TEX_NODE_RGBTOBW
#define TEX_NODE_VALTORGB
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_socket_templates(bNodeType *ntype, bNodeSocketTemplate *inputs, bNodeSocketTemplate *outputs)
Definition node.cc:6134
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:6166
BMesh Iterators.
static void valtorgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
static bke::bNodeSocketTemplate rgbtobw_in[]
void register_node_type_tex_valtorgb()
void register_node_type_tex_rgbtobw()
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
ColorBand * BKE_colorband_add(bool rangetype)
Definition colorband.cc:301
bool BKE_colorband_evaluate(const ColorBand *coba, float in, float out[4])
Definition colorband.cc:399
static void valtorgb_init(bNodeTree *, bNode *node)
static bke::bNodeSocketTemplate valtorgb_in[]
BMesh const char void * data
void tex_output(bNode *node, bNodeExecData *, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
static bke::bNodeSocketTemplate valtorgb_out[]
static void rgbtobw_valuefn(float *out, TexParams *p, bNode *, bNodeStack **in, short thread)
void tex_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
static void rgbtobw_exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static bke::bNodeSocketTemplate rgbtobw_out[]
BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3])
float tex_input_value(bNodeStack *in, TexParams *params, short thread)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
static void valtorgb_exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
@ PROP_FACTOR
Definition RNA_types.hh:308
static constexpr int _240
Definition BKE_node.hh:250
Compact definition of a node socket.
Definition BKE_node.hh:102
Defines a node type.
Definition BKE_node.hh:265
NodeExecFunction exec_fn
Definition BKE_node.hh:371
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
#define N_(msgid)