Blender  V3.3
node_texture_curves.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
8 #include "NOD_texture.h"
9 #include "node_texture_util.h"
10 
11 /* **************** CURVE Time ******************** */
12 
13 /* custom1 = start-frame, custom2 = end-frame. */
14 static bNodeSocketTemplate time_outputs[] = {{SOCK_FLOAT, N_("Value")}, {-1, ""}};
15 
16 static void time_colorfn(
17  float *out, TexParams *p, bNode *node, bNodeStack **UNUSED(in), short UNUSED(thread))
18 {
19  /* stack order output: fac */
20  float fac = 0.0f;
21 
22  if (node->custom1 < node->custom2) {
23  fac = (p->cfra - node->custom1) / (float)(node->custom2 - node->custom1);
24  }
25 
26  BKE_curvemapping_init(node->storage);
27  fac = BKE_curvemapping_evaluateF(node->storage, 0, fac);
28  out[0] = CLAMPIS(fac, 0.0f, 1.0f);
29 }
30 
31 static void time_exec(void *data,
32  int UNUSED(thread),
33  bNode *node,
34  bNodeExecData *execdata,
35  bNodeStack **in,
36  bNodeStack **out)
37 {
38  tex_output(node, execdata, in, out[0], &time_colorfn, data);
39 }
40 
42 {
43  node->custom1 = 1;
44  node->custom2 = 250;
45  node->storage = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
46 }
47 
49 {
50  static bNodeType ntype;
51 
55  node_type_init(&ntype, time_init);
56  node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
58 
59  nodeRegisterType(&ntype);
60 }
61 
62 /* **************** CURVE RGB ******************** */
64  {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
65  {-1, ""},
66 };
67 
69  {SOCK_RGBA, N_("Color")},
70  {-1, ""},
71 };
72 
73 static void rgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
74 {
75  float cin[4];
76  tex_input_rgba(cin, in[0], p, thread);
77 
78  BKE_curvemapping_evaluateRGBF(node->storage, out, cin);
79  out[3] = cin[3];
80 }
81 
82 static void rgb_exec(void *data,
83  int UNUSED(thread),
84  bNode *node,
85  bNodeExecData *execdata,
86  bNodeStack **in,
87  bNodeStack **out)
88 {
89  tex_output(node, execdata, in, out[0], &rgb_colorfn, data);
90 }
91 
93 {
94  node->storage = BKE_curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
95 }
96 
98 {
99  static bNodeType ntype;
100 
104  node_type_init(&ntype, rgb_init);
105  node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
107 
108  nodeRegisterType(&ntype);
109 }
void BKE_curvemapping_init(struct CurveMapping *cumap)
Definition: colortools.c:1235
void BKE_curvemapping_evaluateRGBF(const struct CurveMapping *cumap, float vecout[3], const float vecin[3])
float BKE_curvemapping_evaluateF(const struct CurveMapping *cumap, int cur, float value)
struct CurveMapping * BKE_curvemapping_add(int tot, float minx, float miny, float maxx, float maxy)
Definition: colortools.c:72
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4358
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
void node_type_size_preset(struct bNodeType *ntype, eNodeSizePreset size)
Definition: node.cc:4408
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:4426
#define TEX_NODE_CURVE_TIME
Definition: BKE_node.h:1359
#define NODE_CLASS_OP_COLOR
Definition: BKE_node.h:347
#define NODE_CLASS_INPUT
Definition: BKE_node.h:345
void node_type_exec(struct bNodeType *ntype, NodeInitExecFunction init_exec_fn, NodeFreeExecFunction free_exec_fn, NodeExecFunction exec_fn)
Definition: node.cc:4455
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
@ NODE_SIZE_LARGE
Definition: BKE_node.h:367
#define TEX_NODE_CURVE_RGB
Definition: BKE_node.h:1356
#define CLAMPIS(a, b, c)
#define UNUSED(x)
@ SOCK_FLOAT
@ SOCK_RGBA
Definition: thread.h:34
OperationNode * node
bNodeTree * ntree
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static void time_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **UNUSED(in), short UNUSED(thread))
static void rgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
void register_node_type_tex_curve_rgb(void)
void register_node_type_tex_curve_time(void)
static void time_exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static void rgb_exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static bNodeSocketTemplate rgb_inputs[]
static bNodeSocketTemplate rgb_outputs[]
static void rgb_init(bNodeTree *UNUSED(ntree), bNode *node)
static bNodeSocketTemplate time_outputs[]
static void time_init(bNodeTree *UNUSED(ntree), bNode *node)
void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
void tex_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass)
void tex_output(bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
void node_copy_curves(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:50
void * node_initexec_curves(bNodeExecContext *UNUSED(context), bNode *node, bNodeInstanceKey UNUSED(key))
Definition: node_util.c:62
void node_free_curves(bNode *node)
Definition: node_util.c:38
Compact definition of a node socket.
Definition: BKE_node.h:84
Defines a node type.
Definition: BKE_node.h:226
#define N_(msgid)