Blender V2.61 - r43446

node_shader_invert.c

Go to the documentation of this file.
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) 2005 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_shader_util.h"
00034 
00035 
00036 
00037 /* **************** INVERT ******************** */ 
00038 static bNodeSocketTemplate sh_node_invert_in[]= { 
00039     { SOCK_FLOAT, 1, "Fac", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, 
00040     { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f}, 
00041     { -1, 0, "" } 
00042 };
00043 
00044 static bNodeSocketTemplate sh_node_invert_out[]= { 
00045     { SOCK_RGBA, 0, "Color"}, 
00046     { -1, 0, "" } 
00047 };
00048 
00049 static void node_shader_exec_invert(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **in, 
00050 bNodeStack **out) 
00051 {
00052     float col[3], facm;
00053 
00054     col[0] = 1.0f - in[1]->vec[0];
00055     col[1] = 1.0f - in[1]->vec[1];
00056     col[2] = 1.0f - in[1]->vec[2];
00057     
00058     /* if fac, blend result against original input */
00059     if (in[0]->vec[0] < 1.0f) {
00060         facm = 1.0f - in[0]->vec[0];
00061 
00062         col[0] = in[0]->vec[0]*col[0] + (facm*in[1]->vec[0]);
00063         col[1] = in[0]->vec[0]*col[1] + (facm*in[1]->vec[1]);
00064         col[2] = in[0]->vec[0]*col[2] + (facm*in[1]->vec[2]);
00065     }
00066     
00067     copy_v3_v3(out[0]->vec, col);
00068 }
00069 
00070 static int gpu_shader_invert(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out)
00071 {
00072     return GPU_stack_link(mat, "invert", in, out);
00073 }
00074 
00075 void register_node_type_sh_invert(bNodeTreeType *ttype)
00076 {
00077     static bNodeType ntype;
00078 
00079     node_type_base(ttype, &ntype, SH_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR, NODE_OPTIONS);
00080     node_type_compatibility(&ntype, NODE_OLD_SHADING|NODE_NEW_SHADING);
00081     node_type_socket_templates(&ntype, sh_node_invert_in, sh_node_invert_out);
00082     node_type_size(&ntype, 90, 80, 100);
00083     node_type_exec(&ntype, node_shader_exec_invert);
00084     node_type_gpu(&ntype, gpu_shader_invert);
00085 
00086     nodeRegisterType(ttype, &ntype);
00087 }