Blender  V2.59
SHD_output.c
Go to the documentation of this file.
00001 /*
00002  * $Id: SHD_output.c 35385 2011-03-07 11:51:09Z ton $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version. 
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2005 Blender Foundation.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00035 #include "../SHD_util.h"
00036 
00037 /* **************** OUTPUT ******************** */
00038 static bNodeSocketType sh_node_output_in[]= {
00039         {       SOCK_RGBA, 1, "Color",          0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00040         {       SOCK_VALUE, 1, "Alpha",         1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
00041         {       -1, 0, ""       }
00042 };
00043 
00044 static void node_shader_exec_output(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out))
00045 {
00046         if(data) {
00047                 ShadeInput *shi= ((ShaderCallData *)data)->shi;
00048                 float col[4];
00049                 
00050                 /* stack order input sockets: col, alpha, normal */
00051                 nodestack_get_vec(col, SOCK_VECTOR, in[0]);
00052                 nodestack_get_vec(col+3, SOCK_VALUE, in[1]);
00053                 
00054                 if(shi->do_preview) {
00055                         nodeAddToPreview(node, col, shi->xs, shi->ys, shi->do_manage);
00056                         node->lasty= shi->ys;
00057                 }
00058                 
00059                 if(node->flag & NODE_DO_OUTPUT) {
00060                         ShadeResult *shr= ((ShaderCallData *)data)->shr;
00061                         
00062                         QUATCOPY(shr->combined, col);
00063                         shr->alpha= col[3];
00064                         
00065                         //      VECCOPY(shr->nor, in[3]->vec);
00066                 }
00067         }       
00068 }
00069 
00070 static int gpu_shader_output(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out)
00071 {
00072         GPUNodeLink *outlink;
00073 
00074         /*if(in[1].hasinput)
00075                 GPU_material_enable_alpha(mat);*/
00076 
00077         GPU_stack_link(mat, "output_node", in, out, &outlink);
00078         GPU_material_output_link(mat, outlink);
00079 
00080         return 1;
00081 }
00082 
00083 void register_node_type_sh_output(ListBase *lb)
00084 {
00085         static bNodeType ntype;
00086 
00087         node_type_base(&ntype, SH_NODE_OUTPUT, "Output", NODE_CLASS_OUTPUT, NODE_PREVIEW,
00088                 sh_node_output_in, NULL);
00089         node_type_size(&ntype, 80, 60, 200);
00090         node_type_exec(&ntype, node_shader_exec_output);
00091         node_type_gpu(&ntype, gpu_shader_output);
00092 
00093         nodeRegisterType(lb, &ntype);
00094 }
00095 
00096