98a23534f9036181962b7f46877cbe91d3ce50c5
[blender.git] / source / blender / nodes / shader / nodes / node_shader_output.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
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. 
8  *
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.
13  *
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.
17  *
18  * The Original Code is Copyright (C) 2005 Blender Foundation.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/nodes/shader/nodes/node_shader_output.c
29  *  \ingroup shdnodes
30  */
31
32
33 #include "node_shader_util.h"
34
35 /* **************** OUTPUT ******************** */
36 static bNodeSocketTemplate sh_node_output_in[]= {
37         {       SOCK_RGBA, 1, "Color",          0.0f, 0.0f, 0.0f, 1.0f},
38         {       SOCK_FLOAT, 1, "Alpha",         1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
39         {       -1, 0, ""       }
40 };
41
42 static void node_shader_exec_output(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out))
43 {
44         if(data) {
45                 ShadeInput *shi= ((ShaderCallData *)data)->shi;
46                 float col[4];
47                 
48                 /* stack order input sockets: col, alpha, normal */
49                 nodestack_get_vec(col, SOCK_VECTOR, in[0]);
50                 nodestack_get_vec(col+3, SOCK_FLOAT, in[1]);
51                 
52                 if(shi->do_preview) {
53                         nodeAddToPreview(node, col, shi->xs, shi->ys, shi->do_manage);
54                         node->lasty= shi->ys;
55                 }
56                 
57                 if(node->flag & NODE_DO_OUTPUT) {
58                         ShadeResult *shr= ((ShaderCallData *)data)->shr;
59                         
60                         QUATCOPY(shr->combined, col);
61                         shr->alpha= col[3];
62                         
63                         //      VECCOPY(shr->nor, in[3]->vec);
64                 }
65         }       
66 }
67
68 static int gpu_shader_output(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out)
69 {
70         GPUNodeLink *outlink;
71
72         /*if(in[1].hasinput)
73                 GPU_material_enable_alpha(mat);*/
74
75         GPU_stack_link(mat, "output_node", in, out, &outlink);
76         GPU_material_output_link(mat, outlink);
77
78         return 1;
79 }
80
81 void register_node_type_sh_output(ListBase *lb)
82 {
83         static bNodeType ntype;
84
85         node_type_base(&ntype, SH_NODE_OUTPUT, "Output", NODE_CLASS_OUTPUT, NODE_PREVIEW);
86         node_type_socket_templates(&ntype, sh_node_output_in, NULL);
87         node_type_size(&ntype, 80, 60, 200);
88         node_type_exec(&ntype, node_shader_exec_output);
89         node_type_gpu(&ntype, gpu_shader_output);
90
91         nodeRegisterType(lb, &ntype);
92 }
93
94