Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2006 Blender Foundation. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #include "node_composite_util.h" 00034 00035 00036 /* **************** NORMAL ******************** */ 00037 static bNodeSocketTemplate cmp_node_normal_in[]= { 00038 { SOCK_VECTOR, 1, "Normal", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_DIRECTION}, 00039 { -1, 0, "" } 00040 }; 00041 00042 static bNodeSocketTemplate cmp_node_normal_out[]= { 00043 { SOCK_VECTOR, 0, "Normal"}, 00044 { SOCK_FLOAT, 0, "Dot"}, 00045 { -1, 0, "" } 00046 }; 00047 00048 static void do_normal(bNode *node, float *out, float *in) 00049 { 00050 bNodeSocket *sock= node->outputs.first; 00051 float *nor= ((bNodeSocketValueVector*)sock->default_value)->value; 00052 00053 /* render normals point inside... the widget points outside */ 00054 out[0]= -INPR(nor, in); 00055 } 00056 00057 /* generates normal, does dot product */ 00058 static void node_composit_exec_normal(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) 00059 { 00060 bNodeSocket *sock= node->outputs.first; 00061 float *nor= ((bNodeSocketValueVector*)sock->default_value)->value; 00062 /* stack order input: normal */ 00063 /* stack order output: normal, value */ 00064 00065 /* input no image? then only vector op */ 00066 if(in[0]->data==NULL) { 00067 copy_v3_v3(out[0]->vec, nor); 00068 /* render normals point inside... the widget points outside */ 00069 out[1]->vec[0]= -dot_v3v3(out[0]->vec, in[0]->vec); 00070 } 00071 else if(out[1]->hasoutput) { 00072 /* make output size of input image */ 00073 CompBuf *cbuf= in[0]->data; 00074 CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */ 00075 00076 composit1_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, do_normal, CB_VEC3); 00077 00078 out[1]->data= stackbuf; 00079 } 00080 00081 00082 } 00083 00084 static void init(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp)) 00085 { 00086 bNodeSocket *sock= node->outputs.first; 00087 float *nor= ((bNodeSocketValueVector*)sock->default_value)->value; 00088 00089 nor[0] = 0.0f; 00090 nor[1] = 0.0f; 00091 nor[2] = 1.0f; 00092 } 00093 00094 void register_node_type_cmp_normal(bNodeTreeType *ttype) 00095 { 00096 static bNodeType ntype; 00097 00098 node_type_base(ttype, &ntype, CMP_NODE_NORMAL, "Normal", NODE_CLASS_OP_VECTOR, NODE_OPTIONS); 00099 node_type_socket_templates(&ntype, cmp_node_normal_in, cmp_node_normal_out); 00100 node_type_init(&ntype, init); 00101 node_type_size(&ntype, 100, 60, 200); 00102 node_type_exec(&ntype, node_composit_exec_normal); 00103 00104 nodeRegisterType(ttype, &ntype); 00105 }