|
Blender
V2.59
|
00001 /* 00002 * $Id: SHD_curves.c 36276 2011-04-21 15:53:30Z 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 /* **************** CURVE VEC ******************** */ 00039 static bNodeSocketType sh_node_curve_vec_in[]= { 00040 { SOCK_VALUE, 0, "Fac", 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f}, 00041 { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, 00042 { -1, 0, "" } 00043 }; 00044 00045 static bNodeSocketType sh_node_curve_vec_out[]= { 00046 { SOCK_VECTOR, 0, "Vector", 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f}, 00047 { -1, 0, "" } 00048 }; 00049 00050 static void node_shader_exec_curve_vec(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) 00051 { 00052 float vec[3]; 00053 00054 /* stack order input: vec */ 00055 /* stack order output: vec */ 00056 nodestack_get_vec(vec, SOCK_VECTOR, in[1]); 00057 curvemapping_evaluate3F(node->storage, out[0]->vec, vec); 00058 } 00059 00060 static void node_shader_init_curve_vec(bNode* node) 00061 { 00062 node->storage= curvemapping_add(3, -1.0f, -1.0f, 1.0f, 1.0f); 00063 } 00064 00065 static int gpu_shader_curve_vec(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) 00066 { 00067 float *array; 00068 int size; 00069 00070 curvemapping_table_RGBA(node->storage, &array, &size); 00071 return GPU_stack_link(mat, "curves_vec", in, out, GPU_texture(size, array)); 00072 } 00073 00074 void register_node_type_sh_curve_vec(ListBase *lb) 00075 { 00076 static bNodeType ntype; 00077 00078 node_type_base(&ntype, SH_NODE_CURVE_VEC, "Vector Curves", NODE_CLASS_OP_VECTOR, NODE_OPTIONS, 00079 sh_node_curve_vec_in, sh_node_curve_vec_out); 00080 node_type_size(&ntype, 200, 140, 320); 00081 node_type_init(&ntype, node_shader_init_curve_vec); 00082 node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); 00083 node_type_exec(&ntype, node_shader_exec_curve_vec); 00084 node_type_gpu(&ntype, gpu_shader_curve_vec); 00085 00086 nodeRegisterType(lb, &ntype); 00087 } 00088 00089 00090 /* **************** CURVE RGB ******************** */ 00091 static bNodeSocketType sh_node_curve_rgb_in[]= { 00092 { SOCK_VALUE, 1, "Fac", 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, 00093 { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, 00094 { -1, 0, "" } 00095 }; 00096 00097 static bNodeSocketType sh_node_curve_rgb_out[]= { 00098 { SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f}, 00099 { -1, 0, "" } 00100 }; 00101 00102 static void node_shader_exec_curve_rgb(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out) 00103 { 00104 float vec[3]; 00105 00106 /* stack order input: vec */ 00107 /* stack order output: vec */ 00108 nodestack_get_vec(vec, SOCK_VECTOR, in[1]); 00109 curvemapping_evaluateRGBF(node->storage, out[0]->vec, vec); 00110 if(in[0]->vec[0] != 1.0f) { 00111 interp_v3_v3v3(out[0]->vec, vec, out[0]->vec, *in[0]->vec); 00112 } 00113 } 00114 00115 static void node_shader_init_curve_rgb(bNode *node) 00116 { 00117 node->storage= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f); 00118 } 00119 00120 static int gpu_shader_curve_rgb(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) 00121 { 00122 float *array; 00123 int size; 00124 curvemapping_table_RGBA(node->storage, &array, &size); 00125 return GPU_stack_link(mat, "curves_rgb", in, out, GPU_texture(size, array)); 00126 } 00127 00128 void register_node_type_sh_curve_rgb(ListBase *lb) 00129 { 00130 static bNodeType ntype; 00131 00132 node_type_base(&ntype, SH_NODE_CURVE_RGB, "RGB Curves", NODE_CLASS_OP_COLOR, NODE_OPTIONS, 00133 sh_node_curve_rgb_in, sh_node_curve_rgb_out); 00134 node_type_size(&ntype, 200, 140, 320); 00135 node_type_init(&ntype, node_shader_init_curve_rgb); 00136 node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves); 00137 node_type_exec(&ntype, node_shader_exec_curve_rgb); 00138 node_type_gpu(&ntype, gpu_shader_curve_rgb); 00139 00140 nodeRegisterType(lb, &ntype); 00141 } 00142