Blender V2.61 - r43446

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