Blender  V2.93
node_texture_curves.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2005 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "NOD_texture.h"
25 #include "node_texture_util.h"
26 
27 /* **************** CURVE Time ******************** */
28 
29 /* custom1 = sfra, custom2 = efra */
30 static bNodeSocketTemplate time_outputs[] = {{SOCK_FLOAT, N_("Value")}, {-1, ""}};
31 
32 static void time_colorfn(
33  float *out, TexParams *p, bNode *node, bNodeStack **UNUSED(in), short UNUSED(thread))
34 {
35  /* stack order output: fac */
36  float fac = 0.0f;
37 
38  if (node->custom1 < node->custom2) {
39  fac = (p->cfra - node->custom1) / (float)(node->custom2 - node->custom1);
40  }
41 
42  BKE_curvemapping_init(node->storage);
43  fac = BKE_curvemapping_evaluateF(node->storage, 0, fac);
44  out[0] = CLAMPIS(fac, 0.0f, 1.0f);
45 }
46 
47 static void time_exec(void *data,
48  int UNUSED(thread),
49  bNode *node,
50  bNodeExecData *execdata,
51  bNodeStack **in,
52  bNodeStack **out)
53 {
54  tex_output(node, execdata, in, out[0], &time_colorfn, data);
55 }
56 
58 {
59  node->custom1 = 1;
60  node->custom2 = 250;
61  node->storage = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
62 }
63 
65 {
66  static bNodeType ntype;
67 
71  node_type_init(&ntype, time_init);
72  node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
74 
75  nodeRegisterType(&ntype);
76 }
77 
78 /* **************** CURVE RGB ******************** */
80  {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
81  {-1, ""},
82 };
83 
85  {SOCK_RGBA, N_("Color")},
86  {-1, ""},
87 };
88 
89 static void rgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
90 {
91  float cin[4];
92  tex_input_rgba(cin, in[0], p, thread);
93 
94  BKE_curvemapping_evaluateRGBF(node->storage, out, cin);
95  out[3] = cin[3];
96 }
97 
98 static void rgb_exec(void *data,
99  int UNUSED(thread),
100  bNode *node,
101  bNodeExecData *execdata,
102  bNodeStack **in,
103  bNodeStack **out)
104 {
105  tex_output(node, execdata, in, out[0], &rgb_colorfn, data);
106 }
107 
109 {
110  node->storage = BKE_curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
111 }
112 
114 {
115  static bNodeType ntype;
116 
117  tex_node_type_base(&ntype, TEX_NODE_CURVE_RGB, "RGB Curves", NODE_CLASS_OP_COLOR, 0);
120  node_type_init(&ntype, rgb_init);
121  node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
123 
124  nodeRegisterType(&ntype);
125 }
void BKE_curvemapping_init(struct CurveMapping *cumap)
Definition: colortools.c:1200
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:88
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4559
void node_type_size_preset(struct bNodeType *ntype, eNodeSizePreset size)
Definition: node.cc:4577
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:4599
#define TEX_NODE_CURVE_TIME
Definition: BKE_node.h:1337
#define NODE_CLASS_OP_COLOR
Definition: BKE_node.h:336
#define NODE_CLASS_INPUT
Definition: BKE_node.h:334
void node_type_exec(struct bNodeType *ntype, NodeInitExecFunction init_exec_fn, NodeFreeExecFunction free_exec_fn, NodeExecFunction exec_fn)
Definition: node.cc:4635
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
@ NODE_SIZE_LARGE
Definition: BKE_node.h:373
#define CLAMPIS(a, b, c)
#define UNUSED(x)
#define N_(msgid)
@ SOCK_FLOAT
@ SOCK_RGBA
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix TEX_NODE_CURVE_RGB
OperationNode * node
bNodeTree * ntree
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_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag)
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_copy_curves(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:62
void * node_initexec_curves(bNodeExecContext *UNUSED(context), bNode *node, bNodeInstanceKey UNUSED(key))
Definition: node_util.c:74
void node_free_curves(bNode *node)
Definition: node_util.c:50
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221