Blender V2.61 - r43446

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