Cycles: make node with multiple input sockets with the same name work. Previously
[blender.git] / source / blender / nodes / shader / nodes / node_shader_mixRgb.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2005 Blender Foundation.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 /** \file blender/nodes/shader/nodes/node_shader_mixRgb.c
31  *  \ingroup shdnodes
32  */
33
34
35 #include "node_shader_util.h"
36
37 /* **************** MIX RGB ******************** */
38 static bNodeSocketTemplate sh_node_mix_rgb_in[]= {
39         {       SOCK_FLOAT, 1, "Fac",                   0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
40         {       SOCK_RGBA, 1, "Color",                  0.5f, 0.5f, 0.5f, 1.0f},
41         {       SOCK_RGBA, 1, "Color",                  0.5f, 0.5f, 0.5f, 1.0f},
42         {       -1, 0, ""       }
43 };
44 static bNodeSocketTemplate sh_node_mix_rgb_out[]= {
45         {       SOCK_RGBA, 0, "Color"},
46         {       -1, 0, ""       }
47 };
48
49 static void node_shader_exec_mix_rgb(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
50 {
51         /* stack order in: fac, col1, col2 */
52         /* stack order out: col */
53         float col[3];
54         float fac;
55         float vec[3];
56
57         nodestack_get_vec(&fac, SOCK_FLOAT, in[0]);
58         CLAMP(fac, 0.0f, 1.0f);
59         
60         nodestack_get_vec(col, SOCK_VECTOR, in[1]);
61         nodestack_get_vec(vec, SOCK_VECTOR, in[2]);
62
63         ramp_blend(node->custom1, col, col+1, col+2, fac, vec);
64         VECCOPY(out[0]->vec, col);
65 }
66
67 static int gpu_shader_mix_rgb(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
68 {
69         static const char *names[] = {"mix_blend", "mix_add", "mix_mult", "mix_sub",
70                 "mix_screen", "mix_div", "mix_diff", "mix_dark", "mix_light",
71                 "mix_overlay", "mix_dodge", "mix_burn", "mix_hue", "mix_sat",
72                 "mix_val", "mix_color", "mix_soft", "mix_linear"};
73
74         return GPU_stack_link(mat, names[node->custom1], in, out);
75 }
76
77
78 void register_node_type_sh_mix_rgb(ListBase *lb)
79 {
80         static bNodeType ntype;
81
82         node_type_base(&ntype, SH_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, NODE_OPTIONS);
83         node_type_socket_templates(&ntype, sh_node_mix_rgb_in, sh_node_mix_rgb_out);
84         node_type_size(&ntype, 100, 60, 150);
85         node_type_label(&ntype, node_blend_label);
86         node_type_exec(&ntype, node_shader_exec_mix_rgb);
87         node_type_gpu(&ntype, gpu_shader_mix_rgb);
88
89         nodeRegisterType(lb, &ntype);
90 }
91