Blender  V2.59
CMP_normal.c
Go to the documentation of this file.
00001 /*
00002  * $Id: CMP_normal.c 35237 2011-02-27 20:13:22Z jesterking $
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) 2006 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 "../CMP_util.h"
00036 
00037 
00038 /* **************** NORMAL  ******************** */
00039 static bNodeSocketType cmp_node_normal_in[]= {
00040         {       SOCK_VECTOR, 1, "Normal",       0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},
00041         {       -1, 0, ""       }
00042 };
00043 
00044 static bNodeSocketType cmp_node_normal_out[]= {
00045         {       SOCK_VECTOR, 0, "Normal",       0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f},
00046         {       SOCK_VALUE, 0, "Dot",           1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00047         {       -1, 0, ""       }
00048 };
00049 
00050 static void do_normal(bNode *node, float *out, float *in)
00051 {
00052         bNodeSocket *sock= node->outputs.first;
00053         float *nor= sock->ns.vec;
00054         
00055         /* render normals point inside... the widget points outside */
00056         out[0]= -INPR(nor, in);
00057 }
00058 
00059 /* generates normal, does dot product */
00060 static void node_composit_exec_normal(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
00061 {
00062         bNodeSocket *sock= node->outputs.first;
00063         /* stack order input:  normal */
00064         /* stack order output: normal, value */
00065         
00066         /* input no image? then only vector op */
00067         if(in[0]->data==NULL) {
00068                 VECCOPY(out[0]->vec, sock->ns.vec);
00069                 /* render normals point inside... the widget points outside */
00070                 out[1]->vec[0]= -INPR(out[0]->vec, in[0]->vec);
00071         }
00072         else if(out[1]->hasoutput) {
00073                 /* make output size of input image */
00074                 CompBuf *cbuf= in[0]->data;
00075                 CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */
00076                 
00077                 composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_normal, CB_VEC3);
00078                 
00079                 out[1]->data= stackbuf;
00080         }
00081         
00082         
00083 }
00084 
00085 void register_node_type_cmp_normal(ListBase *lb)
00086 {
00087         static bNodeType ntype;
00088 
00089         node_type_base(&ntype, CMP_NODE_NORMAL, "Normal", NODE_CLASS_OP_VECTOR, NODE_OPTIONS,
00090                 cmp_node_normal_in, cmp_node_normal_out);
00091         node_type_size(&ntype, 100, 60, 200);
00092         node_type_exec(&ntype, node_composit_exec_normal);
00093 
00094         nodeRegisterType(lb, &ntype);
00095 }
00096 
00097