Blender V2.61 - r43446

node_texture_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): Robin Allen
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #include "node_texture_util.h"
00034 #include "NOD_texture.h"
00035 
00036 /* **************** VALTORGB ******************** */
00037 static bNodeSocketTemplate valtorgb_in[]= {
00038     {   SOCK_FLOAT, 1, "Fac",           0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
00039     {   -1, 0, ""   }
00040 };
00041 static bNodeSocketTemplate valtorgb_out[]= {
00042     {   SOCK_RGBA, 0, "Color"},
00043     {   -1, 0, ""   }
00044 };
00045 
00046 static void valtorgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
00047 {
00048     if(node->storage) {
00049         float fac = tex_input_value(in[0], p, thread);
00050 
00051         do_colorband(node->storage, fac, out);
00052     }
00053 }
00054 
00055 static void valtorgb_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) 
00056 {
00057     tex_output(node, in, out[0], &valtorgb_colorfn, data);
00058 }
00059 
00060 static void valtorgb_init(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
00061 {
00062     node->storage = add_colorband(1);
00063 }
00064 
00065 void register_node_type_tex_valtorgb(bNodeTreeType *ttype)
00066 {
00067     static bNodeType ntype;
00068     
00069     node_type_base(ttype, &ntype, TEX_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, NODE_OPTIONS);
00070     node_type_socket_templates(&ntype, valtorgb_in, valtorgb_out);
00071     node_type_size(&ntype, 240, 200, 300);
00072     node_type_init(&ntype, valtorgb_init);
00073     node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage);
00074     node_type_exec(&ntype, valtorgb_exec);
00075     
00076     nodeRegisterType(ttype, &ntype);
00077 }
00078 
00079 /* **************** RGBTOBW ******************** */
00080 static bNodeSocketTemplate rgbtobw_in[]= {
00081     {   SOCK_RGBA, 1, "Color",          0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f},
00082     {   -1, 0, ""   }
00083 };
00084 static bNodeSocketTemplate rgbtobw_out[]= {
00085     {   SOCK_FLOAT, 0, "Val",           0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
00086     {   -1, 0, ""   }
00087 };
00088 
00089 
00090 static void rgbtobw_valuefn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
00091 {
00092     float cin[4];
00093     tex_input_rgba(cin, in[0], p, thread);
00094     
00095     *out = cin[0] * 0.35f + cin[1] * 0.45f + cin[2] * 0.2f;
00096 }
00097 
00098 static void rgbtobw_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
00099 {
00100     tex_output(node, in, out[0], &rgbtobw_valuefn, data);
00101 }
00102 
00103 void register_node_type_tex_rgbtobw(bNodeTreeType *ttype)
00104 {
00105     static bNodeType ntype;
00106     
00107     node_type_base(ttype, &ntype, TEX_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0);
00108     node_type_socket_templates(&ntype, rgbtobw_in, rgbtobw_out);
00109     node_type_size(&ntype, 80, 40, 120);
00110     node_type_exec(&ntype, rgbtobw_exec);
00111     
00112     nodeRegisterType(ttype, &ntype);
00113 }