|
Blender
V2.59
|
00001 /* 00002 * $Id: SHD_invert.c 35853 2011-03-28 17:08:33Z campbellbarton $ 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 00038 00039 /* **************** INVERT ******************** */ 00040 static bNodeSocketType sh_node_invert_in[]= { 00041 { SOCK_VALUE, 1, "Fac", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, 00042 { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, 00043 { -1, 0, "" } 00044 }; 00045 00046 static bNodeSocketType sh_node_invert_out[]= { 00047 { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, 00048 { -1, 0, "" } 00049 }; 00050 00051 static void node_shader_exec_invert(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **in, 00052 bNodeStack **out) 00053 { 00054 float col[3], facm; 00055 00056 col[0] = 1.0f - in[1]->vec[0]; 00057 col[1] = 1.0f - in[1]->vec[1]; 00058 col[2] = 1.0f - in[1]->vec[2]; 00059 00060 /* if fac, blend result against original input */ 00061 if (in[0]->vec[0] < 1.0f) { 00062 facm = 1.0f - in[0]->vec[0]; 00063 00064 col[0] = in[0]->vec[0]*col[0] + (facm*in[1]->vec[0]); 00065 col[1] = in[0]->vec[0]*col[1] + (facm*in[1]->vec[1]); 00066 col[2] = in[0]->vec[0]*col[2] + (facm*in[1]->vec[2]); 00067 } 00068 00069 VECCOPY(out[0]->vec, col); 00070 } 00071 00072 static int gpu_shader_invert(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out) 00073 { 00074 return GPU_stack_link(mat, "invert", in, out); 00075 } 00076 00077 void register_node_type_sh_invert(ListBase *lb) 00078 { 00079 static bNodeType ntype; 00080 00081 node_type_base(&ntype, SH_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR, NODE_OPTIONS, 00082 sh_node_invert_in, sh_node_invert_out); 00083 node_type_size(&ntype, 90, 80, 100); 00084 node_type_exec(&ntype, node_shader_exec_invert); 00085 node_type_gpu(&ntype, gpu_shader_invert); 00086 00087 nodeRegisterType(lb, &ntype); 00088 } 00089 00090