2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* The Original Code is Copyright (C) 2006 Blender Foundation.
19
* All rights reserved.
21
* The Original Code is: all of this file.
23
* Contributor(s): none yet.
25
* ***** END GPL LICENSE BLOCK *****
28
/** \file blender/nodes/composite/nodes/node_composite_mapValue.c
33
#include "node_composite_util.h"
35
/* **************** MAP VALUE ******************** */
36
static bNodeSocketTemplate cmp_node_map_value_in[]= {
37
{ SOCK_FLOAT, 1, "Value", 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE},
40
static bNodeSocketTemplate cmp_node_map_value_out[]= {
41
{ SOCK_FLOAT, 0, "Value"},
45
static void do_map_value(bNode *node, float *out, float *src)
47
TexMapping *texmap= node->storage;
49
out[0]= (src[0] + texmap->loc[0])*texmap->size[0];
50
if (texmap->flag & TEXMAP_CLIP_MIN)
51
if (out[0]<texmap->min[0])
52
out[0]= texmap->min[0];
53
if (texmap->flag & TEXMAP_CLIP_MAX)
54
if (out[0]>texmap->max[0])
55
out[0]= texmap->max[0];
58
static void node_composit_exec_map_value(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
60
/* stack order in: valbuf */
61
/* stack order out: valbuf */
62
if (out[0]->hasoutput==0) return;
64
/* input no image? then only value operation */
65
if (in[0]->data==NULL) {
66
do_map_value(node, out[0]->vec, in[0]->vec);
69
/* make output size of input image */
70
CompBuf *cbuf= in[0]->data;
71
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */
73
composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_map_value, CB_VAL);
75
out[0]->data= stackbuf;
80
static void node_composit_init_map_value(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
82
node->storage= add_tex_mapping();
85
void register_node_type_cmp_map_value(bNodeTreeType *ttype)
87
static bNodeType ntype;
89
node_type_base(ttype, &ntype, CMP_NODE_MAP_VALUE, "Map Value", NODE_CLASS_OP_VECTOR, NODE_OPTIONS);
90
node_type_socket_templates(&ntype, cmp_node_map_value_in, cmp_node_map_value_out);
91
node_type_size(&ntype, 100, 60, 150);
92
node_type_init(&ntype, node_composit_init_map_value);
93
node_type_storage(&ntype, "TexMapping", node_free_standard_storage, node_copy_standard_storage);
94
node_type_exec(&ntype, node_composit_exec_map_value);
96
nodeRegisterType(ttype, &ntype);