Blender V5.3
node_texture_curves.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 <algorithm>
10
11#include "BKE_colortools.hh"
12#include "node_texture_util.hh"
13#include "node_util.hh"
14
15namespace blender {
16
17/* **************** CURVE Time ******************** */
18
19/* custom1 = start-frame, custom2 = end-frame. */
20static bke::bNodeSocketTemplate time_outputs[] = {{SOCK_FLOAT, N_("Value")}, {-1, ""}};
21
22static void time_colorfn(
23 float *out, TexParams *p, bNode *node, bNodeStack ** /*in*/, short /*thread*/)
24{
25 /* stack order output: fac */
26 float fac = 0.0f;
27
28 if (node->custom1 < node->custom2) {
29 fac = (p->cfra - node->custom1) / float(node->custom2 - node->custom1);
30 }
31
32 CurveMapping *mapping = static_cast<CurveMapping *>(node->storage);
33 BKE_curvemapping_init(mapping);
34 fac = BKE_curvemapping_evaluateF(mapping, 0, fac);
35 out[0] = std::clamp(fac, 0.0f, 1.0f);
36}
37
38static void time_exec(void *data,
39 int /*thread*/,
40 bNode *node,
41 bNodeExecData *execdata,
42 bNodeStack **in,
44{
45 tex_output(node, execdata, in, out[0], &time_colorfn, static_cast<TexCallData *>(data));
46}
47
48static void time_init(bNodeTree * /*ntree*/, bNode *node)
49{
50 node->custom1 = 1;
51 node->custom2 = 250;
52 node->storage = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
53}
54
56{
57 static bke::bNodeType ntype;
58
59 tex_node_type_base(&ntype, "TextureNodeCurveTime"_ustr, TEX_NODE_CURVE_TIME);
60 ntype.ui_name = "Time";
61 ntype.enum_name_legacy = "CURVE_TIME";
65 ntype.initfunc = time_init;
68 ntype.exec_fn = time_exec;
69
71}
72
73/* **************** CURVE RGB ******************** */
75 {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
76 {-1, ""},
77};
78
80 {SOCK_RGBA, N_("Color")},
81 {-1, ""},
82};
83
84static void rgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
85{
86 float cin[4];
87 tex_input_rgba(cin, in[0], p, thread);
88
89 BKE_curvemapping_evaluateRGBF(static_cast<CurveMapping *>(node->storage), out, cin);
90 out[3] = cin[3];
91}
92
93static void rgb_exec(void *data,
94 int /*thread*/,
95 bNode *node,
96 bNodeExecData *execdata,
97 bNodeStack **in,
99{
100 tex_output(node, execdata, in, out[0], &rgb_colorfn, static_cast<TexCallData *>(data));
101}
102
103static void rgb_init(bNodeTree * /*ntree*/, bNode *node)
104{
105 node->storage = BKE_curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
106}
107
109{
110 static bke::bNodeType ntype;
111
112 tex_node_type_base(&ntype, "TextureNodeCurveRGB"_ustr, TEX_NODE_CURVE_RGB);
113 ntype.ui_name = "RGB Curves";
114 ntype.enum_name_legacy = "CURVE_RGB";
118 ntype.initfunc = rgb_init;
121 ntype.exec_fn = rgb_exec;
122
124}
125
126} // namespace blender
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:480
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define TEX_NODE_CURVE_TIME
#define TEX_NODE_CURVE_RGB
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.
CurveMapping * BKE_curvemapping_add(int tot, float minx, float miny, float maxx, float maxy)
Definition colortools.cc:99
static bke::bNodeSocketTemplate rgb_inputs[]
void BKE_curvemapping_evaluateRGBF(const CurveMapping *cumap, float vecout[3], const float vecin[3])
static bke::bNodeSocketTemplate rgb_outputs[]
static void rgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
static bke::bNodeSocketTemplate time_outputs[]
void register_node_type_tex_curve_rgb()
void BKE_curvemapping_init(CurveMapping *cumap)
static void rgb_init(bNodeTree *, bNode *node)
BMesh const char void * data
void tex_output(bNode *node, bNodeExecData *, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
void node_free_curves(bNode *node)
Definition node_util.cc:40
void register_node_type_tex_curve_time()
void node_copy_curves(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:52
void tex_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
static void time_exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
void * node_initexec_curves(bNodeExecContext *, bNode *node, bNodeInstanceKey)
Definition node_util.cc:64
static void time_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **, short)
static void time_init(bNodeTree *, bNode *node)
float BKE_curvemapping_evaluateF(const CurveMapping *cumap, int cur, float value)
static void rgb_exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
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
NodeInitExecFunction init_exec_fn
Definition BKE_node.hh:369
#define N_(msgid)