Blender V5.0
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
15/* **************** CURVE Time ******************** */
16
17/* custom1 = start-frame, custom2 = end-frame. */
19
20static void time_colorfn(
21 float *out, TexParams *p, bNode *node, bNodeStack ** /*in*/, short /*thread*/)
22{
23 /* stack order output: fac */
24 float fac = 0.0f;
25
26 if (node->custom1 < node->custom2) {
27 fac = (p->cfra - node->custom1) / float(node->custom2 - node->custom1);
28 }
29
30 CurveMapping *mapping = static_cast<CurveMapping *>(node->storage);
31 BKE_curvemapping_init(mapping);
32 fac = BKE_curvemapping_evaluateF(mapping, 0, fac);
33 out[0] = std::clamp(fac, 0.0f, 1.0f);
34}
35
36static void time_exec(void *data,
37 int /*thread*/,
38 bNode *node,
39 bNodeExecData *execdata,
40 bNodeStack **in,
42{
43 tex_output(node, execdata, in, out[0], &time_colorfn, static_cast<TexCallData *>(data));
44}
45
46static void time_init(bNodeTree * /*ntree*/, bNode *node)
47{
48 node->custom1 = 1;
49 node->custom2 = 250;
50 node->storage = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
51}
52
70
71/* **************** CURVE RGB ******************** */
73 {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
74 {-1, ""},
75};
76
78 {SOCK_RGBA, N_("Color")},
79 {-1, ""},
80};
81
82static void rgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
83{
84 float cin[4];
85 tex_input_rgba(cin, in[0], p, thread);
86
87 BKE_curvemapping_evaluateRGBF(static_cast<CurveMapping *>(node->storage), out, cin);
88 out[3] = cin[3];
89}
90
91static void rgb_exec(void *data,
92 int /*thread*/,
93 bNode *node,
94 bNodeExecData *execdata,
95 bNodeStack **in,
97{
98 tex_output(node, execdata, in, out[0], &rgb_colorfn, static_cast<TexCallData *>(data));
99}
100
101static void rgb_init(bNodeTree * /*ntree*/, bNode *node)
102{
103 node->storage = BKE_curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
104}
105
float BKE_curvemapping_evaluateF(const CurveMapping *cumap, int cur, float value)
void BKE_curvemapping_evaluateRGBF(const CurveMapping *cumap, float vecout[3], const float vecin[3])
void BKE_curvemapping_init(CurveMapping *cumap)
CurveMapping * BKE_curvemapping_add(int tot, float minx, float miny, float maxx, float maxy)
Definition colortools.cc:89
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:449
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define TEX_NODE_CURVE_TIME
#define TEX_NODE_CURVE_RGB
@ SOCK_FLOAT
@ SOCK_RGBA
BMesh const char void * data
#define in
#define out
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void node_type_socket_templates(bNodeType *ntype, bNodeSocketTemplate *inputs, bNodeSocketTemplate *outputs)
Definition node.cc:5352
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:5414
void node_type_size_preset(bNodeType &ntype, eNodeSizePreset size)
Definition node.cc:5396
static void rgb_exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static blender::bke::bNodeSocketTemplate rgb_inputs[]
static void time_exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static void rgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
static void time_init(bNodeTree *, bNode *node)
void register_node_type_tex_curve_time()
void register_node_type_tex_curve_rgb()
static blender::bke::bNodeSocketTemplate time_outputs[]
static blender::bke::bNodeSocketTemplate rgb_outputs[]
static void time_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **, short)
static void rgb_init(bNodeTree *, bNode *node)
void tex_output(bNode *node, bNodeExecData *, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
void tex_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void * node_initexec_curves(bNodeExecContext *, bNode *node, bNodeInstanceKey)
Definition node_util.cc:61
void node_copy_curves(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:49
void node_free_curves(bNode *node)
Definition node_util.cc:37
int16_t custom1
void * storage
int16_t custom2
Compact definition of a node socket.
Definition BKE_node.hh:99
Defines a node type.
Definition BKE_node.hh:238
NodeExecFunction exec_fn
Definition BKE_node.hh:340
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeInitExecFunction init_exec_fn
Definition BKE_node.hh:338
#define N_(msgid)