Blender  V2.59
SHD_valToRgb.c
Go to the documentation of this file.
00001 /*
00002  * $Id: SHD_valToRgb.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 /* **************** VALTORGB ******************** */
00038 static bNodeSocketType sh_node_valtorgb_in[]= {
00039         {       SOCK_VALUE, 1, "Fac",                   0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
00040         {       -1, 0, ""       }
00041 };
00042 static bNodeSocketType sh_node_valtorgb_out[]= {
00043         {       SOCK_RGBA, 0, "Color",                  0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00044         {       SOCK_VALUE, 0, "Alpha",                 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
00045         {       -1, 0, ""       }
00046 };
00047 
00048 static void node_shader_exec_valtorgb(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
00049 {
00050         /* stack order in: fac */
00051         /* stack order out: col, alpha */
00052         
00053         if(node->storage) {
00054                 float fac;
00055                 nodestack_get_vec(&fac, SOCK_VALUE, in[0]);
00056 
00057                 do_colorband(node->storage, fac, out[0]->vec);
00058                 out[1]->vec[0]= out[0]->vec[3];
00059         }
00060 }
00061 
00062 static void node_shader_init_valtorgb(bNode *node)
00063 {
00064         node->storage= add_colorband(1);
00065 }
00066 
00067 static int gpu_shader_valtorgb(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
00068 {
00069         float *array;
00070         int size;
00071 
00072         colorband_table_RGBA(node->storage, &array, &size);
00073         return GPU_stack_link(mat, "valtorgb", in, out, GPU_texture(size, array));
00074 }
00075 
00076 void register_node_type_sh_valtorgb(ListBase *lb)
00077 {
00078         static bNodeType ntype;
00079 
00080         node_type_base(&ntype, SH_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, NODE_OPTIONS,
00081                 sh_node_valtorgb_in, sh_node_valtorgb_out);
00082         node_type_size(&ntype, 240, 200, 300);
00083         node_type_init(&ntype, node_shader_init_valtorgb);
00084         node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage);
00085         node_type_exec(&ntype, node_shader_exec_valtorgb);
00086         node_type_gpu(&ntype, gpu_shader_valtorgb);
00087 
00088         nodeRegisterType(lb, &ntype);
00089 }
00090 
00091 
00092 /* **************** RGBTOBW ******************** */
00093 static bNodeSocketType sh_node_rgbtobw_in[]= {
00094    {    SOCK_RGBA, 1, "Color",                  0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f},
00095    {    -1, 0, ""       }
00096 };
00097 static bNodeSocketType sh_node_rgbtobw_out[]= {
00098    {    SOCK_VALUE, 0, "Val",                   0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00099    {    -1, 0, ""       }
00100 };
00101 
00102 
00103 static void node_shader_exec_rgbtobw(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **in, bNodeStack **out)
00104 {
00105         /* stack order out: bw */
00106         /* stack order in: col */
00107 
00108         out[0]->vec[0]= in[0]->vec[0]*0.35f + in[0]->vec[1]*0.45f + in[0]->vec[2]*0.2f;
00109 }
00110 
00111 static int gpu_shader_rgbtobw(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out)
00112 {
00113         return GPU_stack_link(mat, "rgbtobw", in, out);
00114 }
00115 
00116 void register_node_type_sh_rgbtobw(ListBase *lb)
00117 {
00118         static bNodeType ntype;
00119 
00120         node_type_base(&ntype, SH_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0,
00121                 sh_node_rgbtobw_in, sh_node_rgbtobw_out);
00122         node_type_size(&ntype, 80, 40, 120);
00123         node_type_exec(&ntype, node_shader_exec_rgbtobw);
00124         node_type_gpu(&ntype, gpu_shader_rgbtobw);
00125 
00126         nodeRegisterType(lb, &ntype);
00127 }
00128 
00129