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) 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 /* **************** MIX RGB ******************** */ 00036 static bNodeSocketTemplate sh_node_mix_rgb_in[]= { 00037 { SOCK_FLOAT, 1, "Fac", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, 00038 { SOCK_RGBA, 1, "Color1", 0.5f, 0.5f, 0.5f, 1.0f}, 00039 { SOCK_RGBA, 1, "Color2", 0.5f, 0.5f, 0.5f, 1.0f}, 00040 { -1, 0, "" } 00041 }; 00042 static bNodeSocketTemplate sh_node_mix_rgb_out[]= { 00043 { SOCK_RGBA, 0, "Color"}, 00044 { -1, 0, "" } 00045 }; 00046 00047 static void node_shader_exec_mix_rgb(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) 00048 { 00049 /* stack order in: fac, col1, col2 */ 00050 /* stack order out: col */ 00051 float col[3]; 00052 float fac; 00053 float vec[3]; 00054 00055 nodestack_get_vec(&fac, SOCK_FLOAT, in[0]); 00056 CLAMP(fac, 0.0f, 1.0f); 00057 00058 nodestack_get_vec(col, SOCK_VECTOR, in[1]); 00059 nodestack_get_vec(vec, SOCK_VECTOR, in[2]); 00060 00061 ramp_blend(node->custom1, col, fac, vec); 00062 copy_v3_v3(out[0]->vec, col); 00063 } 00064 00065 static int gpu_shader_mix_rgb(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) 00066 { 00067 static const char *names[] = {"mix_blend", "mix_add", "mix_mult", "mix_sub", 00068 "mix_screen", "mix_div", "mix_diff", "mix_dark", "mix_light", 00069 "mix_overlay", "mix_dodge", "mix_burn", "mix_hue", "mix_sat", 00070 "mix_val", "mix_color", "mix_soft", "mix_linear"}; 00071 00072 return GPU_stack_link(mat, names[node->custom1], in, out); 00073 } 00074 00075 00076 void register_node_type_sh_mix_rgb(bNodeTreeType *ttype) 00077 { 00078 static bNodeType ntype; 00079 00080 node_type_base(ttype, &ntype, SH_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, NODE_OPTIONS); 00081 node_type_compatibility(&ntype, NODE_OLD_SHADING|NODE_NEW_SHADING); 00082 node_type_socket_templates(&ntype, sh_node_mix_rgb_in, sh_node_mix_rgb_out); 00083 node_type_size(&ntype, 100, 60, 150); 00084 node_type_label(&ntype, node_blend_label); 00085 node_type_exec(&ntype, node_shader_exec_mix_rgb); 00086 node_type_gpu(&ntype, gpu_shader_mix_rgb); 00087 00088 nodeRegisterType(ttype, &ntype); 00089 }