Blender V4.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
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,
41 bNodeStack **out)
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
67
68/* **************** CURVE RGB ******************** */
70 {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
71 {-1, ""},
72};
73
75 {SOCK_RGBA, N_("Color")},
76 {-1, ""},
77};
78
79static void rgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
80{
81 float cin[4];
82 tex_input_rgba(cin, in[0], p, thread);
83
84 BKE_curvemapping_evaluateRGBF(static_cast<CurveMapping *>(node->storage), out, cin);
85 out[3] = cin[3];
86}
87
88static void rgb_exec(void *data,
89 int /*thread*/,
90 bNode *node,
91 bNodeExecData *execdata,
92 bNodeStack **in,
93 bNodeStack **out)
94{
95 tex_output(node, execdata, in, out[0], &rgb_colorfn, static_cast<TexCallData *>(data));
96}
97
98static void rgb_init(bNodeTree * /*ntree*/, bNode *node)
99{
100 node->storage = BKE_curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
101}
102
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:90
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:406
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
@ SOCK_FLOAT
@ SOCK_RGBA
void node_type_size_preset(bNodeType *ntype, eNodeSizePreset size)
Definition node.cc:4614
void node_type_socket_templates(bNodeType *ntype, bNodeSocketTemplate *inputs, bNodeSocketTemplate *outputs)
Definition node.cc:4570
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
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_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
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)
void * node_initexec_curves(bNodeExecContext *, bNode *node, bNodeInstanceKey)
Definition node_util.cc:65
void node_copy_curves(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:53
void node_free_curves(bNode *node)
Definition node_util.cc:41
Compact definition of a node socket.
Definition BKE_node.hh:103
Defines a node type.
Definition BKE_node.hh:218
NodeExecFunction exec_fn
Definition BKE_node.hh:316
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
NodeInitExecFunction init_exec_fn
Definition BKE_node.hh:314
#define N_(msgid)