Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Toenne <lukas.toenne@googlemail.com>2011-09-06 01:01:50 +0400
committerLukas Toenne <lukas.toenne@googlemail.com>2011-09-06 01:01:50 +0400
commit8e0fe8bff72e2dc2926618577eaffdd3417a8304 (patch)
tree43b933c88cac451518dc68846c1119acacffca4f /source/blender/nodes/texture
parent6e9ff495eb082aeb49e6a1da23a7827d3fcd0fde (diff)
Merged the particles-2010 branch with node improvements into trunk.
This branch adds mostly organizational improvements to the node system by renaming the node folders and files. A couple of internal features have been added too. Detailed information can be found on the wiki page: http://wiki.blender.org/index.php/User:Phonybone/Particles2010
Diffstat (limited to 'source/blender/nodes/texture')
-rw-r--r--source/blender/nodes/texture/node_texture_tree.c237
-rw-r--r--source/blender/nodes/texture/node_texture_util.c172
-rw-r--r--source/blender/nodes/texture/node_texture_util.h123
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_at.c72
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_bricks.c134
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_checker.c83
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_common.c271
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_compose.c71
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_coord.c65
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_curves.c127
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_decompose.c92
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_distance.c76
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_hueSatVal.c106
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_image.c112
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_invert.c78
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_math.c201
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_mixRgb.c79
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_output.c173
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_proc.c326
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_rotate.c109
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_scale.c82
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_texture.c103
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_translate.c78
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_valToNor.c94
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_valToRgb.c116
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_viewer.c70
26 files changed, 3250 insertions, 0 deletions
diff --git a/source/blender/nodes/texture/node_texture_tree.c b/source/blender/nodes/texture/node_texture_tree.c
new file mode 100644
index 00000000000..75a57c64f2f
--- /dev/null
+++ b/source/blender/nodes/texture/node_texture_tree.c
@@ -0,0 +1,237 @@
+/**
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2007 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s):
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/node_texture_tree.c
+ * \ingroup nodes
+ */
+
+
+#include <string.h>
+
+#include "DNA_texture_types.h"
+#include "DNA_node_types.h"
+
+#include "BLI_listbase.h"
+#include "BLI_threads.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_global.h"
+#include "BKE_main.h"
+#include "BKE_node.h"
+
+#include "node_exec.h"
+#include "node_util.h"
+#include "NOD_texture.h"
+#include "node_texture_util.h"
+
+#include "RE_pipeline.h"
+#include "RE_shader_ext.h"
+
+
+static void foreach_nodetree(Main *main, void *calldata, bNodeTreeCallback func)
+{
+ Tex *tx;
+ for(tx= main->tex.first; tx; tx= tx->id.next) {
+ if(tx->nodetree) {
+ func(calldata, &tx->id, tx->nodetree);
+ }
+ }
+}
+
+static void local_sync(bNodeTree *localtree, bNodeTree *ntree)
+{
+ bNode *lnode;
+
+ /* copy over contents of previews */
+ for(lnode= localtree->nodes.first; lnode; lnode= lnode->next) {
+ if(ntreeNodeExists(ntree, lnode->new_node)) {
+ bNode *node= lnode->new_node;
+
+ if(node->preview && node->preview->rect) {
+ if(lnode->preview && lnode->preview->rect) {
+ int xsize= node->preview->xsize;
+ int ysize= node->preview->ysize;
+ memcpy(node->preview->rect, lnode->preview->rect, 4*xsize + xsize*ysize*sizeof(char)*4);
+ }
+ }
+ }
+ }
+}
+
+bNodeTreeType ntreeType_Texture = {
+ /* type */ NTREE_TEXTURE,
+ /* id_name */ "NTTexture Nodetree",
+
+ /* node_types */ { NULL, NULL },
+
+ /* free_cache */ NULL,
+ /* free_node_cache */ NULL,
+ /* foreach_nodetree */ foreach_nodetree,
+ /* localize */ NULL,
+ /* local_sync */ local_sync,
+ /* local_merge */ NULL,
+ /* update */ NULL,
+ /* update_node */ NULL
+};
+
+int ntreeTexTagAnimated(bNodeTree *ntree)
+{
+ bNode *node;
+
+ if(ntree==NULL) return 0;
+
+ for(node= ntree->nodes.first; node; node= node->next) {
+ if(node->type==TEX_NODE_CURVE_TIME) {
+ NodeTagChanged(ntree, node);
+ return 1;
+ }
+ else if(node->type==NODE_GROUP) {
+ if( ntreeTexTagAnimated((bNodeTree *)node->id) ) {
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+bNodeTreeExec *ntreeTexBeginExecTree(bNodeTree *ntree)
+{
+ bNodeTreeExec *exec;
+ bNode *node;
+
+ /* XXX hack: prevent exec data from being generated twice.
+ * this should be handled by the renderer!
+ */
+ if (ntree->execdata)
+ return ntree->execdata;
+
+ /* common base initialization */
+ exec = ntree_exec_begin(ntree);
+
+ /* allocate the thread stack listbase array */
+ exec->threadstack= MEM_callocN(BLENDER_MAX_THREADS*sizeof(ListBase), "thread stack array");
+
+ for(node= exec->nodetree->nodes.first; node; node= node->next)
+ node->need_exec= 1;
+
+ /* XXX this should not be necessary, but is still used for cmp/sha/tex nodes,
+ * which only store the ntree pointer. Should be fixed at some point!
+ */
+ ntree->execdata = exec;
+
+ return exec;
+}
+
+/* free texture delegates */
+static void tex_free_delegates(bNodeTreeExec *exec)
+{
+ bNodeThreadStack *nts;
+ bNodeStack *ns;
+ int th, a;
+
+ for(th=0; th<BLENDER_MAX_THREADS; th++)
+ for(nts=exec->threadstack[th].first; nts; nts=nts->next)
+ for(ns= nts->stack, a=0; a<exec->stacksize; a++, ns++)
+ if(ns->data && !ns->is_copy)
+ MEM_freeN(ns->data);
+}
+
+void ntreeTexEndExecTree(bNodeTreeExec *exec)
+{
+ if(exec) {
+ bNodeTree *ntree= exec->nodetree;
+ bNodeThreadStack *nts;
+ int a;
+
+ if(exec->threadstack) {
+ tex_free_delegates(exec);
+
+ for(a=0; a<BLENDER_MAX_THREADS; a++) {
+ for(nts=exec->threadstack[a].first; nts; nts=nts->next)
+ if (nts->stack) MEM_freeN(nts->stack);
+ BLI_freelistN(&exec->threadstack[a]);
+ }
+
+ MEM_freeN(exec->threadstack);
+ exec->threadstack= NULL;
+ }
+
+ ntree_exec_end(exec);
+
+ /* XXX clear nodetree backpointer to exec data, same problem as noted in ntreeBeginExecTree */
+ ntree->execdata = NULL;
+ }
+}
+
+int ntreeTexExecTree(
+ bNodeTree *nodes,
+ TexResult *texres,
+ float *co,
+ float *dxt, float *dyt,
+ int osatex,
+ short thread,
+ Tex *UNUSED(tex),
+ short which_output,
+ int cfra,
+ int preview,
+ ShadeInput *shi,
+ MTex *mtex
+){
+ TexCallData data;
+ float *nor= texres->nor;
+ int retval = TEX_INT;
+ bNodeThreadStack *nts = NULL;
+ bNodeTreeExec *exec= nodes->execdata;
+
+ data.co = co;
+ data.dxt = dxt;
+ data.dyt = dyt;
+ data.osatex = osatex;
+ data.target = texres;
+ data.do_preview = preview;
+ data.thread = thread;
+ data.which_output = which_output;
+ data.cfra= cfra;
+ data.mtex= mtex;
+ data.shi= shi;
+
+ if (!exec)
+ exec = ntreeTexBeginExecTree(nodes);
+
+ nts= ntreeGetThreadStack(exec, thread);
+ ntreeExecThreadNodes(exec, nts, &data, thread);
+ ntreeReleaseThreadStack(nts);
+
+ if(texres->nor) retval |= TEX_NOR;
+ retval |= TEX_RGB;
+ /* confusing stuff; the texture output node sets this to NULL to indicate no normal socket was set
+ however, the texture code checks this for other reasons (namely, a normal is required for material) */
+ texres->nor= nor;
+
+ return retval;
+}
diff --git a/source/blender/nodes/texture/node_texture_util.c b/source/blender/nodes/texture/node_texture_util.c
new file mode 100644
index 00000000000..5aedd8681ab
--- /dev/null
+++ b/source/blender/nodes/texture/node_texture_util.c
@@ -0,0 +1,172 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/node_texture_util.c
+ * \ingroup nodes
+ */
+
+
+/*
+ HOW TEXTURE NODES WORK
+
+ In contrast to Shader nodes, which place a color into the output
+ stack when executed, Texture nodes place a TexDelegate* there. To
+ obtain a color value from this, a node further up the chain reads
+ the TexDelegate* from its input stack, and uses tex_call_delegate to
+ retrieve the color from the delegate.
+
+ comments: (ton)
+
+ This system needs recode, a node system should rely on the stack, and
+ callbacks for nodes only should evaluate own node, not recursively go
+ over other previous ones.
+*/
+
+#include <assert.h>
+#include "node_texture_util.h"
+
+#define PREV_RES 128 /* default preview resolution */
+
+static void tex_call_delegate(TexDelegate *dg, float *out, TexParams *params, short thread)
+{
+ if(dg->node->need_exec) {
+ dg->fn(out, params, dg->node, dg->in, thread);
+
+ if(dg->cdata->do_preview)
+ tex_do_preview(dg->node, params->previewco, out);
+ }
+}
+
+static void tex_input(float *out, int sz, bNodeStack *in, TexParams *params, short thread)
+{
+ TexDelegate *dg = in->data;
+ if(dg) {
+ tex_call_delegate(dg, in->vec, params, thread);
+
+ if(in->hasoutput && in->sockettype == SOCK_FLOAT)
+ in->vec[1] = in->vec[2] = in->vec[0];
+ }
+ memcpy(out, in->vec, sz * sizeof(float));
+}
+
+void tex_input_vec(float *out, bNodeStack *in, TexParams *params, short thread)
+{
+ tex_input(out, 3, in, params, thread);
+}
+
+void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread)
+{
+ tex_input(out, 4, in, params, thread);
+
+ if(in->hasoutput && in->sockettype == SOCK_FLOAT)
+ {
+ out[1] = out[2] = out[0];
+ out[3] = 1;
+ }
+
+ if(in->hasoutput && in->sockettype == SOCK_VECTOR) {
+ out[0] = out[0] * .5f + .5f;
+ out[1] = out[1] * .5f + .5f;
+ out[2] = out[2] * .5f + .5f;
+ out[3] = 1;
+ }
+}
+
+float tex_input_value(bNodeStack *in, TexParams *params, short thread)
+{
+ float out[4];
+ tex_input_vec(out, in, params, thread);
+ return out[0];
+}
+
+void params_from_cdata(TexParams *out, TexCallData *in)
+{
+ out->co = in->co;
+ out->dxt = in->dxt;
+ out->dyt = in->dyt;
+ out->previewco = in->co;
+ out->osatex = in->osatex;
+ out->cfra = in->cfra;
+ out->shi = in->shi;
+ out->mtex = in->mtex;
+}
+
+void tex_do_preview(bNode *node, float *co, float *col)
+{
+ bNodePreview *preview= node->preview;
+
+ if(preview) {
+ int xs= ((co[0] + 1.0f)*0.5f)*preview->xsize;
+ int ys= ((co[1] + 1.0f)*0.5f)*preview->ysize;
+
+ nodeAddToPreview(node, col, xs, ys, 0); /* 0 = no color management */
+ }
+}
+
+void tex_output(bNode *node, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
+{
+ TexDelegate *dg;
+ if(!out->data)
+ /* Freed in tex_end_exec (node.c) */
+ dg = out->data = MEM_mallocN(sizeof(TexDelegate), "tex delegate");
+ else
+ dg = out->data;
+
+ dg->cdata= cdata;
+ dg->fn = texfn;
+ dg->node = node;
+ memcpy(dg->in, in, MAX_SOCKET * sizeof(bNodeStack*));
+ dg->type = out->sockettype;
+}
+
+void ntreeTexCheckCyclics(struct bNodeTree *ntree)
+{
+ bNode *node;
+ for(node= ntree->nodes.first; node; node= node->next) {
+
+ if(node->type == TEX_NODE_TEXTURE && node->id)
+ {
+ /* custom2 stops the node from rendering */
+ if(node->custom1) {
+ node->custom2 = 1;
+ node->custom1 = 0;
+ } else {
+ Tex *tex = (Tex *)node->id;
+
+ node->custom2 = 0;
+
+ node->custom1 = 1;
+ if(tex->use_nodes && tex->nodetree) {
+ ntreeTexCheckCyclics(tex->nodetree);
+ }
+ node->custom1 = 0;
+ }
+ }
+
+ }
+}
diff --git a/source/blender/nodes/texture/node_texture_util.h b/source/blender/nodes/texture/node_texture_util.h
new file mode 100644
index 00000000000..867b4142052
--- /dev/null
+++ b/source/blender/nodes/texture/node_texture_util.h
@@ -0,0 +1,123 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/node_texture_util.h
+ * \ingroup nodes
+ */
+
+
+#ifndef NODE_TEXTURE_UTIL_H_
+#define NODE_TEXTURE_UTIL_H_
+
+#include <math.h>
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_color_types.h"
+#include "DNA_ipo_types.h"
+#include "DNA_ID.h"
+#include "DNA_image_types.h"
+#include "DNA_material_types.h"
+#include "DNA_node_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_texture_types.h"
+
+#include "BKE_blender.h"
+#include "BKE_colortools.h"
+#include "BKE_global.h"
+#include "BKE_image.h"
+#include "BKE_main.h"
+#include "BKE_material.h"
+#include "BKE_node.h"
+#include "BKE_texture.h"
+
+#include "BKE_library.h"
+
+#include "node_util.h"
+
+#include "BLI_math.h"
+#include "BLI_blenlib.h"
+#include "BLI_rand.h"
+#include "BLI_threads.h"
+#include "BLI_utildefines.h"
+
+#include "IMB_imbuf_types.h"
+#include "IMB_imbuf.h"
+
+#include "RE_pipeline.h"
+#include "RE_shader_ext.h"
+
+typedef struct TexCallData {
+ TexResult *target;
+ float *co;
+ float *dxt, *dyt;
+ int osatex;
+ char do_preview;
+ short thread;
+ short which_output;
+ int cfra;
+
+ ShadeInput *shi;
+ MTex *mtex;
+} TexCallData;
+
+typedef struct TexParams {
+ float *co;
+ float *dxt, *dyt;
+ float *previewco;
+ int cfra;
+ int osatex;
+
+ /* optional. we don't really want these here, but image
+ textures need to do mapping & color correction */
+ ShadeInput *shi;
+ MTex *mtex;
+} TexParams;
+
+typedef void(*TexFn) (float *out, TexParams *params, bNode *node, bNodeStack **in, short thread);
+
+typedef struct TexDelegate {
+ TexCallData *cdata;
+ TexFn fn;
+ bNode *node;
+ bNodeStack *in[MAX_SOCKET];
+ int type;
+} TexDelegate;
+
+void tex_input_rgba(float *out, bNodeStack *in, TexParams *params, short thread);
+void tex_input_vec(float *out, bNodeStack *in, TexParams *params, short thread);
+float tex_input_value(bNodeStack *in, TexParams *params, short thread);
+
+void tex_output(bNode *node, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *data);
+void tex_do_preview(bNode *node, float *coord, float *col);
+
+void params_from_cdata(TexParams *out, TexCallData *in);
+
+#endif
diff --git a/source/blender/nodes/texture/nodes/node_texture_at.c b/source/blender/nodes/texture/nodes/node_texture_at.c
new file mode 100644
index 00000000000..f3275f2bcdf
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_at.c
@@ -0,0 +1,72 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): R Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_at.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+static bNodeSocketTemplate inputs[]= {
+ { SOCK_RGBA, 1, "Texture", 0.0f, 0.0f, 0.0f, 1.0f },
+ { SOCK_VECTOR, 1, "Coordinates", 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE },
+ { -1, 0, "" }
+};
+static bNodeSocketTemplate outputs[]= {
+ { SOCK_RGBA, 0, "Texture" },
+ { -1, 0, "" }
+};
+
+static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
+{
+ TexParams np = *p;
+ float new_co[3];
+ np.co = new_co;
+
+ tex_input_vec(new_co, in[1], p, thread);
+ tex_input_rgba(out, in[0], &np, thread);
+}
+
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &colorfn, data);
+}
+
+void register_node_type_tex_at(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_AT, "At", NODE_CLASS_DISTORT, 0);
+ node_type_socket_templates(&ntype, inputs, outputs);
+ node_type_size(&ntype, 140, 100, 320);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
diff --git a/source/blender/nodes/texture/nodes/node_texture_bricks.c b/source/blender/nodes/texture/nodes/node_texture_bricks.c
new file mode 100644
index 00000000000..060ed791871
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_bricks.c
@@ -0,0 +1,134 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Robin Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_bricks.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+#include <math.h>
+
+static bNodeSocketTemplate inputs[]= {
+ { SOCK_RGBA, 1, "Bricks 1", 0.596f, 0.282f, 0.0f, 1.0f },
+ { SOCK_RGBA, 1, "Bricks 2", 0.632f, 0.504f, 0.05f, 1.0f },
+ { SOCK_RGBA, 1, "Mortar", 0.0f, 0.0f, 0.0f, 1.0f },
+ { SOCK_FLOAT, 1, "Thickness", 0.02f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED },
+ { SOCK_FLOAT, 1, "Bias", 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE },
+ { SOCK_FLOAT, 1, "Brick Width", 0.5f, 0.0f, 0.0f, 0.0f, 0.001f, 99.0f, PROP_UNSIGNED },
+ { SOCK_FLOAT, 1, "Row Height", 0.25f, 0.0f, 0.0f, 0.0f, 0.001f, 99.0f, PROP_UNSIGNED },
+ { -1, 0, "" }
+};
+static bNodeSocketTemplate outputs[]= {
+ { SOCK_RGBA, 0, "Color"},
+ { -1, 0, "" }
+};
+
+static void init(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
+{
+ node->custom3 = 0.5; /* offset */
+ node->custom4 = 1.0; /* squash */
+}
+
+static float noise(int n) /* fast integer noise */
+{
+ int nn;
+ n = (n >> 13) ^ n;
+ nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
+ return 0.5f * ((float)nn / 1073741824.0f);
+}
+
+static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
+{
+ float *co = p->co;
+
+ float x = co[0];
+ float y = co[1];
+
+ int bricknum, rownum;
+ float offset = 0;
+ float ins_x, ins_y;
+ float tint;
+
+ float bricks1[4];
+ float bricks2[4];
+ float mortar[4];
+
+ float mortar_thickness = tex_input_value(in[3], p, thread);
+ float bias = tex_input_value(in[4], p, thread);
+ float brick_width = tex_input_value(in[5], p, thread);
+ float row_height = tex_input_value(in[6], p, thread);
+
+ tex_input_rgba(bricks1, in[0], p, thread);
+ tex_input_rgba(bricks2, in[1], p, thread);
+ tex_input_rgba(mortar, in[2], p, thread);
+
+ rownum = (int)floor(y / row_height);
+
+ if( node->custom1 && node->custom2 ) {
+ brick_width *= ((int)(rownum) % node->custom2 ) ? 1.0f : node->custom4; /* squash */
+ offset = ((int)(rownum) % node->custom1 ) ? 0 : (brick_width*node->custom3); /* offset */
+ }
+
+ bricknum = (int)floor((x+offset) / brick_width);
+
+ ins_x = (x+offset) - brick_width*bricknum;
+ ins_y = y - row_height*rownum;
+
+ tint = noise((rownum << 16) + (bricknum & 0xFFFF)) + bias;
+ CLAMP(tint,0.0f,1.0f);
+
+ if( ins_x < mortar_thickness || ins_y < mortar_thickness ||
+ ins_x > (brick_width - mortar_thickness) ||
+ ins_y > (row_height - mortar_thickness) ) {
+ QUATCOPY( out, mortar );
+ } else {
+ QUATCOPY( out, bricks1 );
+ ramp_blend( MA_RAMP_BLEND, out, out+1, out+2, tint, bricks2 );
+ }
+}
+
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &colorfn, data);
+}
+
+void register_node_type_tex_bricks(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_BRICKS, "Bricks", NODE_CLASS_PATTERN, NODE_PREVIEW|NODE_OPTIONS);
+ node_type_socket_templates(&ntype, inputs, outputs);
+ node_type_size(&ntype, 150, 60, 150);
+ node_type_init(&ntype, init);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
diff --git a/source/blender/nodes/texture/nodes/node_texture_checker.c b/source/blender/nodes/texture/nodes/node_texture_checker.c
new file mode 100644
index 00000000000..916ee80d66b
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_checker.c
@@ -0,0 +1,83 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Robin Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_checker.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+#include <math.h>
+
+static bNodeSocketTemplate inputs[]= {
+ { SOCK_RGBA, 1, "Color1", 1.0f, 0.0f, 0.0f, 1.0f },
+ { SOCK_RGBA, 1, "Color2", 1.0f, 1.0f, 1.0f, 1.0f },
+ { SOCK_FLOAT, 1, "Size", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 100.0f, PROP_UNSIGNED },
+ { -1, 0, "" }
+};
+static bNodeSocketTemplate outputs[]= {
+ { SOCK_RGBA, 0, "Color" },
+ { -1, 0, "" }
+};
+
+static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
+{
+ float x = p->co[0];
+ float y = p->co[1];
+ float z = p->co[2];
+ float sz = tex_input_value(in[2], p, thread);
+
+ /* 0.00001 because of unit sized stuff */
+ int xi = (int)fabs(floor(0.00001f + x / sz));
+ int yi = (int)fabs(floor(0.00001f + y / sz));
+ int zi = (int)fabs(floor(0.00001f + z / sz));
+
+ if( (xi % 2 == yi % 2) == (zi % 2) ) {
+ tex_input_rgba(out, in[0], p, thread);
+ } else {
+ tex_input_rgba(out, in[1], p, thread);
+ }
+}
+
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &colorfn, data);
+}
+
+void register_node_type_tex_checker(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_CHECKER, "Checker", NODE_CLASS_PATTERN, NODE_PREVIEW|NODE_OPTIONS);
+ node_type_socket_templates(&ntype, inputs, outputs);
+ node_type_size(&ntype, 100, 60, 150);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
diff --git a/source/blender/nodes/texture/nodes/node_texture_common.c b/source/blender/nodes/texture/nodes/node_texture_common.c
new file mode 100644
index 00000000000..cb5102bae4e
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_common.c
@@ -0,0 +1,271 @@
+/*
+ * $Id: CMP_blur.c 35562 2011-03-15 20:10:32Z lukastoenne $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2006 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Campbell Barton, Alfredo de Greef, David Millan Escriva,
+ * Juho Vepsäläinen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_common.c
+ * \ingroup texnodes
+ */
+
+
+#include "DNA_node_types.h"
+
+#include "BKE_node.h"
+
+#include "node_texture_util.h"
+#include "node_common.h"
+#include "node_exec.h"
+
+static void copy_stack(bNodeStack *to, bNodeStack *from)
+{
+ if (to != from) {
+ copy_v4_v4(to->vec, from->vec);
+ to->data = from->data;
+ to->datatype = from->datatype;
+
+ /* tag as copy to prevent freeing */
+ to->is_copy = 1;
+ }
+}
+
+/**** GROUP ****/
+
+static void *group_initexec(bNode *node)
+{
+ bNodeTree *ngroup= (bNodeTree*)node->id;
+ void *exec;
+
+ /* initialize the internal node tree execution */
+ exec = ntreeTexBeginExecTree(ngroup);
+
+ return exec;
+}
+
+static void group_freeexec(bNode *UNUSED(node), void *nodedata)
+{
+ bNodeTreeExec*gexec= (bNodeTreeExec*)nodedata;
+
+ ntreeTexEndExecTree(gexec);
+}
+
+/* Copy inputs to the internal stack.
+ * This is a shallow copy, no buffers are duplicated here!
+ */
+static void group_copy_inputs(bNode *node, bNodeStack **in, bNodeStack *gstack)
+{
+ bNodeSocket *sock;
+ bNodeStack *ns;
+ int a;
+ for (sock=node->inputs.first, a=0; sock; sock=sock->next, ++a) {
+ if (sock->groupsock) {
+ ns = node_get_socket_stack(gstack, sock->groupsock);
+ copy_stack(ns, in[a]);
+ }
+ }
+}
+
+/* Copy internal results to the external outputs.
+ */
+static void group_copy_outputs(bNode *node, bNodeStack **out, bNodeStack *gstack)
+{
+ bNodeSocket *sock;
+ bNodeStack *ns;
+ int a;
+ for (sock=node->outputs.first, a=0; sock; sock=sock->next, ++a) {
+ if (sock->groupsock) {
+ ns = node_get_socket_stack(gstack, sock->groupsock);
+ copy_stack(out[a], ns);
+ }
+ }
+}
+
+static void group_execute(void *data, int thread, struct bNode *node, void *nodedata, struct bNodeStack **in, struct bNodeStack **out)
+{
+ bNodeTreeExec *exec= (bNodeTreeExec*)nodedata;
+ bNodeThreadStack *nts;
+
+ /* XXX same behavior as trunk: all nodes inside group are executed.
+ * it's stupid, but just makes it work. compo redesign will do this better.
+ */
+ {
+ bNode *inode;
+ for (inode=exec->nodetree->nodes.first; inode; inode=inode->next)
+ inode->need_exec = 1;
+ }
+
+ nts = ntreeGetThreadStack(exec, thread);
+
+ group_copy_inputs(node, in, nts->stack);
+ ntreeExecThreadNodes(exec, nts, data, thread);
+ group_copy_outputs(node, out, nts->stack);
+
+ ntreeReleaseThreadStack(nts);
+}
+
+void register_node_type_tex_group(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, NODE_GROUP, "Group", NODE_CLASS_GROUP, NODE_OPTIONS|NODE_CONST_OUTPUT);
+ node_type_socket_templates(&ntype, NULL, NULL);
+ node_type_size(&ntype, 120, 60, 200);
+ node_type_label(&ntype, node_group_label);
+ node_type_init(&ntype, node_group_init);
+ node_type_valid(&ntype, node_group_valid);
+ node_type_template(&ntype, node_group_template);
+ node_type_update(&ntype, NULL, node_group_verify);
+ node_type_group_edit(&ntype, node_group_edit_get, node_group_edit_set, node_group_edit_clear);
+ node_type_exec_new(&ntype, group_initexec, group_freeexec, group_execute);
+
+ nodeRegisterType(lb, &ntype);
+}
+
+
+/**** FOR LOOP ****/
+
+#if 0 /* XXX loop nodes don't work nicely with current trees */
+static void forloop_execute(void *data, int thread, struct bNode *node, void *nodedata, struct bNodeStack **in, struct bNodeStack **out)
+{
+ bNodeTreeExec *exec= (bNodeTreeExec*)nodedata;
+ bNodeThreadStack *nts;
+ int iterations= (int)in[0]->vec[0];
+ bNodeSocket *sock;
+ bNodeStack *ns;
+ int iteration;
+
+ /* XXX same behavior as trunk: all nodes inside group are executed.
+ * it's stupid, but just makes it work. compo redesign will do this better.
+ */
+ {
+ bNode *inode;
+ for (inode=exec->nodetree->nodes.first; inode; inode=inode->next)
+ inode->need_exec = 1;
+ }
+
+ nts = ntreeGetThreadStack(exec, thread);
+
+ /* "Iteration" socket */
+ sock = exec->nodetree->inputs.first;
+ ns = node_get_socket_stack(nts->stack, sock);
+
+// group_copy_inputs(node, in, nts->stack);
+ for (iteration=0; iteration < iterations; ++iteration) {
+ /* first input contains current iteration counter */
+ ns->vec[0] = (float)iteration;
+ ns->vec[1]=ns->vec[2]=ns->vec[3] = 0.0f;
+
+// if (iteration > 0)
+// loop_init_iteration(exec->nodetree, nts->stack);
+// ntreeExecThreadNodes(exec, nts, data, thread);
+ }
+// loop_copy_outputs(node, in, out, exec->stack);
+
+ ntreeReleaseThreadStack(nts);
+}
+
+void register_node_type_tex_forloop(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, NODE_FORLOOP, "For", NODE_CLASS_GROUP, NODE_OPTIONS);
+ node_type_socket_templates(&ntype, NULL, NULL);
+ node_type_size(&ntype, 120, 60, 200);
+ node_type_label(&ntype, node_group_label);
+ node_type_init(&ntype, node_forloop_init);
+ node_type_valid(&ntype, node_group_valid);
+ node_type_template(&ntype, node_forloop_template);
+ node_type_update(&ntype, NULL, node_group_verify);
+ node_type_tree(&ntype, node_forloop_init_tree, node_loop_update_tree);
+ node_type_group_edit(&ntype, node_group_edit_get, node_group_edit_set, node_group_edit_clear);
+ node_type_exec_new(&ntype, group_initexec, group_freeexec, forloop_execute);
+
+ nodeRegisterType(lb, &ntype);
+}
+#endif
+
+/**** WHILE LOOP ****/
+
+#if 0 /* XXX loop nodes don't work nicely with current trees */
+static void whileloop_execute(void *data, int thread, struct bNode *node, void *nodedata, struct bNodeStack **in, struct bNodeStack **out)
+{
+ bNodeTreeExec *exec= (bNodeTreeExec*)nodedata;
+ bNodeThreadStack *nts;
+ int condition= (in[0]->vec[0] > 0.0f);
+ bNodeSocket *sock;
+ bNodeStack *ns;
+ int iteration;
+
+ /* XXX same behavior as trunk: all nodes inside group are executed.
+ * it's stupid, but just makes it work. compo redesign will do this better.
+ */
+ {
+ bNode *inode;
+ for (inode=exec->nodetree->nodes.first; inode; inode=inode->next)
+ inode->need_exec = 1;
+ }
+
+ nts = ntreeGetThreadStack(exec, thread);
+
+ /* "Condition" socket */
+ sock = exec->nodetree->outputs.first;
+ ns = node_get_socket_stack(nts->stack, sock);
+
+ iteration = 0;
+// group_copy_inputs(node, in, nts->stack);
+ while (condition && iteration < node->custom1) {
+// if (iteration > 0)
+// loop_init_iteration(exec->nodetree, nts->stack);
+// ntreeExecThreadNodes(exec, nts, data, thread);
+
+ condition = (ns->vec[0] > 0.0f);
+ ++iteration;
+ }
+// loop_copy_outputs(node, in, out, exec->stack);
+
+ ntreeReleaseThreadStack(nts);
+}
+
+void register_node_type_tex_whileloop(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, NODE_WHILELOOP, "While", NODE_CLASS_GROUP, NODE_OPTIONS);
+ node_type_socket_templates(&ntype, NULL, NULL);
+ node_type_size(&ntype, 120, 60, 200);
+ node_type_label(&ntype, node_group_label);
+ node_type_init(&ntype, node_whileloop_init);
+ node_type_valid(&ntype, node_group_valid);
+ node_type_template(&ntype, node_whileloop_template);
+ node_type_update(&ntype, NULL, node_group_verify);
+ node_type_tree(&ntype, node_whileloop_init_tree, node_loop_update_tree);
+ node_type_group_edit(&ntype, node_group_edit_get, node_group_edit_set, node_group_edit_clear);
+ node_type_exec_new(&ntype, group_initexec, group_freeexec, whileloop_execute);
+
+ nodeRegisterType(lb, &ntype);
+}
+#endif
diff --git a/source/blender/nodes/texture/nodes/node_texture_compose.c b/source/blender/nodes/texture/nodes/node_texture_compose.c
new file mode 100644
index 00000000000..a11769173a3
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_compose.c
@@ -0,0 +1,71 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Robin Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_compose.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+static bNodeSocketTemplate inputs[]= {
+ { SOCK_FLOAT, 1, "Red", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED },
+ { SOCK_FLOAT, 1, "Green", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED },
+ { SOCK_FLOAT, 1, "Blue", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED },
+ { SOCK_FLOAT, 1, "Alpha", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_UNSIGNED },
+ { -1, 0, "" }
+};
+static bNodeSocketTemplate outputs[]= {
+ { SOCK_RGBA, 0, "Color" },
+ { -1, 0, "" }
+};
+
+static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
+{
+ int i;
+ for(i = 0; i < 4; i++)
+ out[i] = tex_input_value(in[i], p, thread);
+}
+
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &colorfn, data);
+}
+
+void register_node_type_tex_compose(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_COMPOSE, "Compose RGBA", NODE_CLASS_OP_COLOR, 0);
+ node_type_socket_templates(&ntype, inputs, outputs);
+ node_type_size(&ntype, 100, 60, 150);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
diff --git a/source/blender/nodes/texture/nodes/node_texture_coord.c b/source/blender/nodes/texture/nodes/node_texture_coord.c
new file mode 100644
index 00000000000..b2d9cecc164
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_coord.c
@@ -0,0 +1,65 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Mathias Panzenböck (panzi) <grosser.meister.morti@gmx.net>.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_coord.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+static bNodeSocketTemplate outputs[]= {
+ { SOCK_VECTOR, 0, "Coordinates" },
+ { -1, 0, "" }
+};
+
+static void vectorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **UNUSED(in), short UNUSED(thread))
+{
+ out[0] = p->co[0];
+ out[1] = p->co[1];
+ out[2] = p->co[2];
+}
+
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &vectorfn, data);
+}
+
+void register_node_type_tex_coord(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_COORD, "Coordinates", NODE_CLASS_INPUT, NODE_OPTIONS);
+ node_type_socket_templates(&ntype, NULL, outputs);
+ node_type_size(&ntype, 120, 110, 160);
+ node_type_storage(&ntype, "node_coord", NULL, NULL);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
diff --git a/source/blender/nodes/texture/nodes/node_texture_curves.c b/source/blender/nodes/texture/nodes/node_texture_curves.c
new file mode 100644
index 00000000000..af6d880cc18
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_curves.c
@@ -0,0 +1,127 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Robin Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_curves.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+/* **************** CURVE Time ******************** */
+
+/* custom1 = sfra, custom2 = efra */
+static bNodeSocketTemplate time_outputs[]= {
+ { SOCK_FLOAT, 0, "Value" },
+ { -1, 0, "" }
+};
+
+static void time_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **UNUSED(in), short UNUSED(thread))
+{
+ /* stack order output: fac */
+ float fac= 0.0f;
+
+ if(node->custom1 < node->custom2)
+ fac = (p->cfra - node->custom1)/(float)(node->custom2-node->custom1);
+
+ fac = curvemapping_evaluateF(node->storage, 0, fac);
+ out[0] = CLAMPIS(fac, 0.0f, 1.0f);
+}
+
+static void time_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &time_colorfn, data);
+}
+
+
+static void time_init(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
+{
+ node->custom1= 1;
+ node->custom2= 250;
+ node->storage= curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
+}
+
+void register_node_type_tex_curve_time(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_CURVE_TIME, "Time", NODE_CLASS_INPUT, NODE_OPTIONS);
+ node_type_socket_templates(&ntype, NULL, time_outputs);
+ node_type_size(&ntype, 140, 100, 320);
+ node_type_init(&ntype, time_init);
+ node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
+ node_type_exec(&ntype, time_exec);
+
+ nodeRegisterType(lb, &ntype);
+}
+
+/* **************** CURVE RGB ******************** */
+static bNodeSocketTemplate rgb_inputs[]= {
+ { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f},
+ { -1, 0, "" }
+};
+
+static bNodeSocketTemplate rgb_outputs[]= {
+ { SOCK_RGBA, 0, "Color"},
+ { -1, 0, "" }
+};
+
+static void rgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
+{
+ float cin[4];
+ tex_input_rgba(cin, in[0], p, thread);
+
+ curvemapping_evaluateRGBF(node->storage, out, cin);
+ out[3] = cin[3];
+}
+
+static void rgb_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &rgb_colorfn, data);
+}
+
+static void rgb_init(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
+{
+ node->storage= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
+}
+
+void register_node_type_tex_curve_rgb(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_CURVE_RGB, "RGB Curves", NODE_CLASS_OP_COLOR, NODE_OPTIONS);
+ node_type_socket_templates(&ntype, rgb_inputs, rgb_outputs);
+ node_type_size(&ntype, 200, 140, 320);
+ node_type_init(&ntype, rgb_init);
+ node_type_storage(&ntype, "CurveMapping", node_free_curves, node_copy_curves);
+ node_type_exec(&ntype, rgb_exec);
+
+ nodeRegisterType(lb, &ntype);
+}
+
diff --git a/source/blender/nodes/texture/nodes/node_texture_decompose.c b/source/blender/nodes/texture/nodes/node_texture_decompose.c
new file mode 100644
index 00000000000..312765f866e
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_decompose.c
@@ -0,0 +1,92 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Robin Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_decompose.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+#include <math.h>
+
+static bNodeSocketTemplate inputs[]= {
+ { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f },
+ { -1, 0, "" }
+};
+static bNodeSocketTemplate outputs[]= {
+ { SOCK_FLOAT, 0, "Red" },
+ { SOCK_FLOAT, 0, "Green" },
+ { SOCK_FLOAT, 0, "Blue" },
+ { SOCK_FLOAT, 0, "Alpha" },
+ { -1, 0, "" }
+};
+
+static void valuefn_r(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
+{
+ tex_input_rgba(out, in[0], p, thread);
+ *out = out[0];
+}
+
+static void valuefn_g(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
+{
+ tex_input_rgba(out, in[0], p, thread);
+ *out = out[1];
+}
+
+static void valuefn_b(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
+{
+ tex_input_rgba(out, in[0], p, thread);
+ *out = out[2];
+}
+
+static void valuefn_a(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
+{
+ tex_input_rgba(out, in[0], p, thread);
+ *out = out[3];
+}
+
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &valuefn_r, data);
+ tex_output(node, in, out[1], &valuefn_g, data);
+ tex_output(node, in, out[2], &valuefn_b, data);
+ tex_output(node, in, out[3], &valuefn_a, data);
+}
+
+void register_node_type_tex_decompose(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_DECOMPOSE, "Decompose RGBA", NODE_CLASS_OP_COLOR, 0);
+ node_type_socket_templates(&ntype, inputs, outputs);
+ node_type_size(&ntype, 100, 60, 150);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
diff --git a/source/blender/nodes/texture/nodes/node_texture_distance.c b/source/blender/nodes/texture/nodes/node_texture_distance.c
new file mode 100644
index 00000000000..fe524baaa96
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_distance.c
@@ -0,0 +1,76 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Mathias Panzenböck (panzi) <grosser.meister.morti@gmx.net>.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_distance.c
+ * \ingroup texnodes
+ */
+
+
+#include <math.h>
+#include "BLI_math.h"
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+static bNodeSocketTemplate inputs[]= {
+ { SOCK_VECTOR, 1, "Coordinate 1", 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE },
+ { SOCK_VECTOR, 1, "Coordinate 2", 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE },
+ { -1, 0, "" }
+};
+
+static bNodeSocketTemplate outputs[]= {
+ { SOCK_FLOAT, 0, "Value" },
+ { -1, 0, "" }
+};
+
+static void valuefn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
+{
+ float co1[3], co2[3];
+
+ tex_input_vec(co1, in[0], p, thread);
+ tex_input_vec(co2, in[1], p, thread);
+
+ *out = len_v3v3(co2, co1);
+}
+
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &valuefn, data);
+}
+
+void register_node_type_tex_distance(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_DISTANCE, "Distance", NODE_CLASS_CONVERTOR, NODE_OPTIONS);
+ node_type_socket_templates(&ntype, inputs, outputs);
+ node_type_size(&ntype, 120, 110, 160);
+ node_type_storage(&ntype, "node_distance", NULL, NULL);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
diff --git a/source/blender/nodes/texture/nodes/node_texture_hueSatVal.c b/source/blender/nodes/texture/nodes/node_texture_hueSatVal.c
new file mode 100644
index 00000000000..ebc2501cee3
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_hueSatVal.c
@@ -0,0 +1,106 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2006 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Juho Vepsäläinen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_hueSatVal.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+
+static bNodeSocketTemplate inputs[]= {
+ { SOCK_FLOAT, 1, "Hue", 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.5f, PROP_NONE },
+ { SOCK_FLOAT, 1, "Saturation", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_FACTOR },
+ { SOCK_FLOAT, 1, "Value", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_FACTOR },
+ { SOCK_FLOAT, 1, "Factor", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR },
+ { SOCK_RGBA, 1, "Color", 0.8f, 0.8f, 0.8f, 1.0f },
+ { -1, 0, "" }
+};
+static bNodeSocketTemplate outputs[]= {
+ { SOCK_RGBA, 0, "Color" },
+ { -1, 0, "" }
+};
+
+static void do_hue_sat_fac(bNode *UNUSED(node), float *out, float hue, float sat, float val, float *in, float fac)
+{
+ if(fac != 0 && (hue != 0.5f || sat != 1 || val != 1)) {
+ float col[3], hsv[3], mfac= 1.0f - fac;
+
+ rgb_to_hsv(in[0], in[1], in[2], hsv, hsv+1, hsv+2);
+ hsv[0]+= (hue - 0.5f);
+ if(hsv[0]>1.0f) hsv[0]-=1.0f; else if(hsv[0]<0.0f) hsv[0]+= 1.0f;
+ hsv[1]*= sat;
+ if(hsv[1]>1.0f) hsv[1]= 1.0f; else if(hsv[1]<0.0f) hsv[1]= 0.0f;
+ hsv[2]*= val;
+ if(hsv[2]>1.0f) hsv[2]= 1.0f; else if(hsv[2]<0.0f) hsv[2]= 0.0f;
+ hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col+1, col+2);
+
+ out[0]= mfac*in[0] + fac*col[0];
+ out[1]= mfac*in[1] + fac*col[1];
+ out[2]= mfac*in[2] + fac*col[2];
+ }
+ else {
+ QUATCOPY(out, in);
+ }
+}
+
+static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
+{
+ float hue = tex_input_value(in[0], p, thread);
+ float sat = tex_input_value(in[1], p, thread);
+ float val = tex_input_value(in[2], p, thread);
+ float fac = tex_input_value(in[3], p, thread);
+
+ float col[4];
+ tex_input_rgba(col, in[4], p, thread);
+
+ hue += 0.5f; /* [-.5, .5] -> [0, 1] */
+
+ do_hue_sat_fac(node, out, hue, sat, val, col, fac);
+
+ out[3] = col[3];
+}
+
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &colorfn, data);
+}
+
+void register_node_type_tex_hue_sat(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_HUE_SAT, "Hue Saturation Value", NODE_CLASS_OP_COLOR, NODE_OPTIONS);
+ node_type_socket_templates(&ntype, inputs, outputs);
+ node_type_size(&ntype, 150, 80, 250);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
diff --git a/source/blender/nodes/texture/nodes/node_texture_image.c b/source/blender/nodes/texture/nodes/node_texture_image.c
new file mode 100644
index 00000000000..1359cf4275f
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_image.c
@@ -0,0 +1,112 @@
+/*
+ * $Id: TEX_image.c 36481 2011-05-04 11:42:25Z lukastoenne $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2006 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Robin Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_image.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+static bNodeSocketTemplate outputs[]= {
+ { SOCK_RGBA, 0, "Image"},
+ { -1, 0, "" }
+};
+
+static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **UNUSED(in), short UNUSED(thread))
+{
+ float x = p->co[0];
+ float y = p->co[1];
+ Image *ima= (Image *)node->id;
+ ImageUser *iuser= (ImageUser *)node->storage;
+
+ if( ima ) {
+ ImBuf *ibuf = BKE_image_get_ibuf(ima, iuser);
+ if( ibuf ) {
+ float xsize, ysize;
+ float xoff, yoff;
+ int px, py;
+
+ float *result;
+
+ xsize = ibuf->x / 2;
+ ysize = ibuf->y / 2;
+ xoff = yoff = -1;
+
+ px = (int)( (x-xoff) * xsize );
+ py = (int)( (y-yoff) * ysize );
+
+ if( (!xsize) || (!ysize) ) return;
+
+ if( !ibuf->rect_float ) {
+ BLI_lock_thread(LOCK_IMAGE);
+ if( !ibuf->rect_float )
+ IMB_float_from_rect(ibuf);
+ BLI_unlock_thread(LOCK_IMAGE);
+ }
+
+ while( px < 0 ) px += ibuf->x;
+ while( py < 0 ) py += ibuf->y;
+ while( px >= ibuf->x ) px -= ibuf->x;
+ while( py >= ibuf->y ) py -= ibuf->y;
+
+ result = ibuf->rect_float + py*ibuf->x*4 + px*4;
+ QUATCOPY( out, result );
+ }
+ }
+}
+
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &colorfn, data);
+}
+
+static void init(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
+{
+ ImageUser *iuser= MEM_callocN(sizeof(ImageUser), "node image user");
+ node->storage= iuser;
+ iuser->sfra= 1;
+ iuser->fie_ima= 2;
+ iuser->ok= 1;
+}
+
+void register_node_type_tex_image(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_IMAGE, "Image", NODE_CLASS_INPUT, NODE_PREVIEW|NODE_OPTIONS);
+ node_type_socket_templates(&ntype, NULL, outputs);
+ node_type_size(&ntype, 120, 80, 300);
+ node_type_init(&ntype, init);
+ node_type_storage(&ntype, "ImageUser", node_free_standard_storage, node_copy_standard_storage);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
diff --git a/source/blender/nodes/texture/nodes/node_texture_invert.c b/source/blender/nodes/texture/nodes/node_texture_invert.c
new file mode 100644
index 00000000000..8ba4f292fec
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_invert.c
@@ -0,0 +1,78 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Robin Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_invert.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+/* **************** INVERT ******************** */
+static bNodeSocketTemplate inputs[]= {
+ { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f},
+ { -1, 0, "" }
+};
+
+static bNodeSocketTemplate outputs[]= {
+ { SOCK_RGBA, 0, "Color"},
+ { -1, 0, "" }
+};
+
+static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
+{
+ float col[4];
+
+ tex_input_rgba(col, in[0], p, thread);
+
+ col[0] = 1.0f - col[0];
+ col[1] = 1.0f - col[1];
+ col[2] = 1.0f - col[2];
+
+ VECCOPY(out, col);
+ out[3] = col[3];
+}
+
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &colorfn, data);
+}
+
+void register_node_type_tex_invert(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_INVERT, "Invert", NODE_CLASS_OP_COLOR, NODE_OPTIONS);
+ node_type_socket_templates(&ntype, inputs, outputs);
+ node_type_size(&ntype, 90, 80, 100);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
+
diff --git a/source/blender/nodes/texture/nodes/node_texture_math.c b/source/blender/nodes/texture/nodes/node_texture_math.c
new file mode 100644
index 00000000000..182bc37978f
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_math.c
@@ -0,0 +1,201 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Robin Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_math.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+
+/* **************** SCALAR MATH ******************** */
+static bNodeSocketTemplate inputs[]= {
+ { SOCK_FLOAT, 1, "Value", 0.5f, 0.5f, 0.5f, 1.0f, -100.0f, 100.0f, PROP_NONE},
+ { SOCK_FLOAT, 1, "Value", 0.5f, 0.5f, 0.5f, 1.0f, -100.0f, 100.0f, PROP_NONE},
+ { -1, 0, "" }
+};
+
+static bNodeSocketTemplate outputs[]= {
+ { SOCK_FLOAT, 0, "Value"},
+ { -1, 0, "" }
+};
+
+static void valuefn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
+{
+ float in0 = tex_input_value(in[0], p, thread);
+ float in1 = tex_input_value(in[1], p, thread);
+
+ switch(node->custom1){
+
+ case 0: /* Add */
+ *out= in0 + in1;
+ break;
+ case 1: /* Subtract */
+ *out= in0 - in1;
+ break;
+ case 2: /* Multiply */
+ *out= in0 * in1;
+ break;
+ case 3: /* Divide */
+ {
+ if(in1==0) /* We don't want to divide by zero. */
+ *out= 0.0;
+ else
+ *out= in0 / in1;
+ }
+ break;
+ case 4: /* Sine */
+ {
+ *out= sin(in0);
+ }
+ break;
+ case 5: /* Cosine */
+ {
+ *out= cos(in0);
+ }
+ break;
+ case 6: /* Tangent */
+ {
+ *out= tan(in0);
+ }
+ break;
+ case 7: /* Arc-Sine */
+ {
+ /* Can't do the impossible... */
+ if( in0 <= 1 && in0 >= -1 )
+ *out= asin(in0);
+ else
+ *out= 0.0;
+ }
+ break;
+ case 8: /* Arc-Cosine */
+ {
+ /* Can't do the impossible... */
+ if( in0 <= 1 && in0 >= -1 )
+ *out= acos(in0);
+ else
+ *out= 0.0;
+ }
+ break;
+ case 9: /* Arc-Tangent */
+ {
+ *out= atan(in0);
+ }
+ break;
+ case 10: /* Power */
+ {
+ /* Only raise negative numbers by full integers */
+ if( in0 >= 0 ) {
+ out[0]= pow(in0, in1);
+ } else {
+ float y_mod_1 = fmod(in1, 1);
+ if (y_mod_1 > 0.999f || y_mod_1 < 0.001f) {
+ *out = pow(in0, floor(in1 + 0.5f));
+ } else {
+ *out = 0.0;
+ }
+ }
+ }
+ break;
+ case 11: /* Logarithm */
+ {
+ /* Don't want any imaginary numbers... */
+ if( in0 > 0 && in1 > 0 )
+ *out= log(in0) / log(in1);
+ else
+ *out= 0.0;
+ }
+ break;
+ case 12: /* Minimum */
+ {
+ if( in0 < in1 )
+ *out= in0;
+ else
+ *out= in1;
+ }
+ break;
+ case 13: /* Maximum */
+ {
+ if( in0 > in1 )
+ *out= in0;
+ else
+ *out= in1;
+ }
+ break;
+ case 14: /* Round */
+ {
+ *out= (in0<0)?(int)(in0 - 0.5f):(int)(in0 + 0.5f);
+ }
+ break;
+
+ case 15: /* Less Than */
+ {
+ if( in0 < in1 )
+ *out= 1.0f;
+ else
+ *out= 0.0f;
+ }
+ break;
+
+ case 16: /* Greater Than */
+ {
+ if( in0 > in1 )
+ *out= 1.0f;
+ else
+ *out= 0.0f;
+ }
+ break;
+
+ default:
+ fprintf(stderr,
+ "%s:%d: unhandeld value in switch statement: %d\n",
+ __FILE__, __LINE__, node->custom1);
+ }
+}
+
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &valuefn, data);
+}
+
+void register_node_type_tex_math(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_MATH, "Math", NODE_CLASS_CONVERTOR, NODE_OPTIONS);
+ node_type_socket_templates(&ntype, inputs, outputs);
+ node_type_size(&ntype, 120, 110, 160);
+ node_type_label(&ntype, node_math_label);
+ node_type_storage(&ntype, "node_math", NULL, NULL);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
+
diff --git a/source/blender/nodes/texture/nodes/node_texture_mixRgb.c b/source/blender/nodes/texture/nodes/node_texture_mixRgb.c
new file mode 100644
index 00000000000..8baac682b18
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_mixRgb.c
@@ -0,0 +1,79 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Robin Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_mixRgb.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+/* **************** MIX RGB ******************** */
+static bNodeSocketTemplate inputs[]= {
+ { SOCK_FLOAT, 1, "Factor", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR },
+ { SOCK_RGBA, 1, "Color1", 0.5f, 0.5f, 0.5f, 1.0f },
+ { SOCK_RGBA , 1, "Color2", 0.5f, 0.5f, 0.5f, 1.0f },
+ { -1, 0, "" }
+};
+static bNodeSocketTemplate outputs[]= {
+ { SOCK_RGBA, 0, "Color" },
+ { -1, 0, "" }
+};
+
+static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
+{
+ float fac = tex_input_value(in[0], p, thread);
+ float col1[4], col2[4];
+
+ tex_input_rgba(col1, in[1], p, thread);
+ tex_input_rgba(col2, in[2], p, thread);
+
+ CLAMP(fac, 0.0f, 1.0f);
+
+ QUATCOPY(out, col1);
+ ramp_blend(node->custom1, out, out+1, out+2, fac, col2);
+}
+
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &colorfn, data);
+}
+
+void register_node_type_tex_mix_rgb(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, NODE_OPTIONS);
+ node_type_socket_templates(&ntype, inputs, outputs);
+ node_type_size(&ntype, 100, 60, 150);
+ node_type_label(&ntype, node_blend_label);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
diff --git a/source/blender/nodes/texture/nodes/node_texture_output.c b/source/blender/nodes/texture/nodes/node_texture_output.c
new file mode 100644
index 00000000000..c321f5738a1
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_output.c
@@ -0,0 +1,173 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2006 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Robin Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_output.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+/* **************** COMPOSITE ******************** */
+static bNodeSocketTemplate inputs[]= {
+ { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f},
+ { SOCK_VECTOR, 1, "Normal", 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, PROP_DIRECTION},
+ { -1, 0, "" }
+};
+
+/* applies to render pipeline */
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out))
+{
+ TexCallData *cdata = (TexCallData *)data;
+ TexResult *target = cdata->target;
+
+ if(cdata->do_preview) {
+ TexParams params;
+ params_from_cdata(&params, cdata);
+
+ if(in[1] && in[1]->hasinput && !in[0]->hasinput)
+ tex_input_rgba(&target->tr, in[1], &params, cdata->thread);
+ else
+ tex_input_rgba(&target->tr, in[0], &params, cdata->thread);
+ tex_do_preview(node, params.co, &target->tr);
+ }
+ else {
+ /* 0 means don't care, so just use first */
+ if(cdata->which_output == node->custom1 || (cdata->which_output == 0 && node->custom1 == 1)) {
+ TexParams params;
+ params_from_cdata(&params, cdata);
+
+ tex_input_rgba(&target->tr, in[0], &params, cdata->thread);
+
+ target->tin = (target->tr + target->tg + target->tb) / 3.0f;
+ target->talpha = 1;
+
+ if(target->nor) {
+ if(in[1] && in[1]->hasinput)
+ tex_input_vec(target->nor, in[1], &params, cdata->thread);
+ else
+ target->nor = NULL;
+ }
+ }
+ }
+}
+
+static void unique_name(bNode *node)
+{
+ TexNodeOutput *tno = (TexNodeOutput *)node->storage;
+ char *new_name = NULL;
+ int new_len = 0;
+ int suffix;
+ bNode *i;
+ char *name = tno->name;
+
+ i = node;
+ while(i->prev) i = i->prev;
+ for(; i; i=i->next) {
+ if(
+ i == node ||
+ i->type != TEX_NODE_OUTPUT ||
+ strcmp(name, ((TexNodeOutput*)(i->storage))->name)
+ )
+ continue;
+
+ if(!new_name) {
+ int len = strlen(name);
+ if(len >= 4 && sscanf(name + len - 4, ".%03d", &suffix) == 1) {
+ new_len = len;
+ } else {
+ suffix = 0;
+ new_len = len + 4;
+ if(new_len > 31)
+ new_len = 31;
+ }
+
+ new_name = MEM_mallocN(new_len + 1, "new_name");
+ strcpy(new_name, name);
+ name = new_name;
+ }
+ sprintf(new_name + new_len - 4, ".%03d", ++suffix);
+ }
+
+ if(new_name) {
+ strcpy(tno->name, new_name);
+ MEM_freeN(new_name);
+ }
+}
+
+static void assign_index(struct bNode *node)
+{
+ bNode *tnode;
+ int index = 1;
+
+ tnode = node;
+ while(tnode->prev)
+ tnode = tnode->prev;
+
+ check_index:
+ for(; tnode; tnode= tnode->next)
+ if(tnode->type == TEX_NODE_OUTPUT && tnode != node)
+ if(tnode->custom1 == index) {
+ index ++;
+ goto check_index;
+ }
+
+ node->custom1 = index;
+}
+
+static void init(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
+{
+ TexNodeOutput *tno = MEM_callocN(sizeof(TexNodeOutput), "TEX_output");
+ node->storage= tno;
+
+ strcpy(tno->name, "Default");
+ unique_name(node);
+ assign_index(node);
+}
+
+static void copy(bNode *orig, bNode *new)
+{
+ node_copy_standard_storage(orig, new);
+ unique_name(new);
+ assign_index(new);
+}
+
+void register_node_type_tex_output(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_OUTPUT, "Output", NODE_CLASS_OUTPUT, NODE_PREVIEW|NODE_OPTIONS);
+ node_type_socket_templates(&ntype, inputs, NULL);
+ node_type_size(&ntype, 150, 60, 200);
+ node_type_init(&ntype, init);
+ node_type_storage(&ntype, "TexNodeOutput", node_free_standard_storage, copy);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
diff --git a/source/blender/nodes/texture/nodes/node_texture_proc.c b/source/blender/nodes/texture/nodes/node_texture_proc.c
new file mode 100644
index 00000000000..8b4c25d85c9
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_proc.c
@@ -0,0 +1,326 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Robin Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_proc.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+#include "RE_shader_ext.h"
+
+/*
+ In this file: wrappers to use procedural textures as nodes
+*/
+
+
+static bNodeSocketTemplate outputs_both[]= {
+ { SOCK_RGBA, 0, "Color", 1.0f, 0.0f, 0.0f, 1.0f },
+ { SOCK_VECTOR, 0, "Normal", 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, PROP_DIRECTION },
+ { -1, 0, "" }
+};
+static bNodeSocketTemplate outputs_color_only[]= {
+ { SOCK_RGBA, 0, "Color" },
+ { -1, 0, "" }
+};
+
+/* Inputs common to all, #defined because nodes will need their own inputs too */
+#define I 2 /* count */
+#define COMMON_INPUTS \
+ { SOCK_RGBA, 1, "Color 1", 0.0f, 0.0f, 0.0f, 1.0f }, \
+ { SOCK_RGBA, 1, "Color 2", 1.0f, 1.0f, 1.0f, 1.0f }
+
+/* Calls multitex and copies the result to the outputs. Called by xxx_exec, which handles inputs. */
+static void do_proc(float *result, TexParams *p, float *col1, float *col2, char is_normal, Tex *tex, short thread)
+{
+ TexResult texres;
+ int textype;
+
+ if(is_normal) {
+ texres.nor = result;
+ }
+ else
+ texres.nor = NULL;
+
+ textype = multitex_nodes(tex, p->co, p->dxt, p->dyt, p->osatex,
+ &texres, thread, 0, p->shi, p->mtex);
+
+ if(is_normal)
+ return;
+
+ if(textype & TEX_RGB) {
+ QUATCOPY(result, &texres.tr);
+ }
+ else {
+ QUATCOPY(result, col1);
+ ramp_blend(MA_RAMP_BLEND, result, result+1, result+2, texres.tin, col2);
+ }
+}
+
+typedef void (*MapFn) (Tex *tex, bNodeStack **in, TexParams *p, short thread);
+
+static void texfn(
+ float *result,
+ TexParams *p,
+ bNode *node,
+ bNodeStack **in,
+ char is_normal,
+ MapFn map_inputs,
+ short thread)
+{
+ Tex tex = *((Tex*)(node->storage));
+ float col1[4], col2[4];
+ tex_input_rgba(col1, in[0], p, thread);
+ tex_input_rgba(col2, in[1], p, thread);
+
+ map_inputs(&tex, in, p, thread);
+
+ do_proc(result, p, col1, col2, is_normal, &tex, thread);
+}
+
+static int count_outputs(bNode *node)
+{
+ bNodeSocket *sock;
+ int num = 0;
+ for(sock= node->outputs.first; sock; sock= sock->next) {
+ num++;
+ }
+ return num;
+}
+
+/* Boilerplate generators */
+
+#define ProcNoInputs(name) \
+ static void name##_map_inputs(Tex *UNUSED(tex), bNodeStack **UNUSED(in), TexParams *UNUSED(p), short UNUSED(thread)) \
+ {}
+
+#define ProcDef(name) \
+ static void name##_colorfn(float *result, TexParams *p, bNode *node, bNodeStack **in, short thread) \
+ { \
+ texfn(result, p, node, in, 0, &name##_map_inputs, thread); \
+ } \
+ static void name##_normalfn(float *result, TexParams *p, bNode *node, bNodeStack **in, short thread) \
+ { \
+ texfn(result, p, node, in, 1, &name##_map_inputs, thread); \
+ } \
+ static void name##_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) \
+ { \
+ int outs = count_outputs(node); \
+ if(outs >= 1) tex_output(node, in, out[0], &name##_colorfn, data); \
+ if(outs >= 2) tex_output(node, in, out[1], &name##_normalfn, data); \
+ }
+
+
+/* --- VORONOI -- */
+static bNodeSocketTemplate voronoi_inputs[]= {
+ COMMON_INPUTS,
+ { SOCK_FLOAT, 1, "W1", 1.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE },
+ { SOCK_FLOAT, 1, "W2", 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE },
+ { SOCK_FLOAT, 1, "W3", 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE },
+ { SOCK_FLOAT, 1, "W4", 0.0f, 0.0f, 0.0f, 0.0f, -2.0f, 2.0f, PROP_NONE },
+
+ { SOCK_FLOAT, 1, "iScale", 1.0f, 0.0f, 0.0f, 0.0f, 0.01f, 10.0f, PROP_UNSIGNED },
+ { SOCK_FLOAT, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 4.0f, PROP_UNSIGNED },
+
+ { -1, 0, "" }
+};
+static void voronoi_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
+{
+ tex->vn_w1 = tex_input_value(in[I+0], p, thread);
+ tex->vn_w2 = tex_input_value(in[I+1], p, thread);
+ tex->vn_w3 = tex_input_value(in[I+2], p, thread);
+ tex->vn_w4 = tex_input_value(in[I+3], p, thread);
+
+ tex->ns_outscale = tex_input_value(in[I+4], p, thread);
+ tex->noisesize = tex_input_value(in[I+5], p, thread);
+}
+ProcDef(voronoi)
+
+/* --- BLEND -- */
+static bNodeSocketTemplate blend_inputs[]= {
+ COMMON_INPUTS,
+ { -1, 0, "" }
+};
+ProcNoInputs(blend)
+ProcDef(blend)
+
+/* -- MAGIC -- */
+static bNodeSocketTemplate magic_inputs[]= {
+ COMMON_INPUTS,
+ { SOCK_FLOAT, 1, "Turbulence", 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED },
+ { -1, 0, "" }
+};
+static void magic_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
+{
+ tex->turbul = tex_input_value(in[I+0], p, thread);
+}
+ProcDef(magic)
+
+/* --- MARBLE --- */
+static bNodeSocketTemplate marble_inputs[]= {
+ COMMON_INPUTS,
+ { SOCK_FLOAT, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED },
+ { SOCK_FLOAT, 1, "Turbulence", 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED },
+ { -1, 0, "" }
+};
+static void marble_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
+{
+ tex->noisesize = tex_input_value(in[I+0], p, thread);
+ tex->turbul = tex_input_value(in[I+1], p, thread);
+}
+ProcDef(marble)
+
+/* --- CLOUDS --- */
+static bNodeSocketTemplate clouds_inputs[]= {
+ COMMON_INPUTS,
+ { SOCK_FLOAT, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED },
+ { -1, 0, "" }
+};
+static void clouds_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
+{
+ tex->noisesize = tex_input_value(in[I+0], p, thread);
+}
+ProcDef(clouds)
+
+/* --- DISTORTED NOISE --- */
+static bNodeSocketTemplate distnoise_inputs[]= {
+ COMMON_INPUTS,
+ { SOCK_FLOAT, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED },
+ { SOCK_FLOAT, 1, "Distortion", 1.00f, 0.0f, 0.0f, 0.0f, 0.0000f, 10.0f, PROP_UNSIGNED },
+ { -1, 0, "" }
+};
+static void distnoise_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
+{
+ tex->noisesize = tex_input_value(in[I+0], p, thread);
+ tex->dist_amount = tex_input_value(in[I+1], p, thread);
+}
+ProcDef(distnoise)
+
+/* --- WOOD --- */
+static bNodeSocketTemplate wood_inputs[]= {
+ COMMON_INPUTS,
+ { SOCK_FLOAT, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED },
+ { SOCK_FLOAT, 1, "Turbulence", 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED },
+ { -1, 0, "" }
+};
+static void wood_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
+{
+ tex->noisesize = tex_input_value(in[I+0], p, thread);
+ tex->turbul = tex_input_value(in[I+1], p, thread);
+}
+ProcDef(wood)
+
+/* --- MUSGRAVE --- */
+static bNodeSocketTemplate musgrave_inputs[]= {
+ COMMON_INPUTS,
+ { SOCK_FLOAT, 1, "H", 1.0f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED },
+ { SOCK_FLOAT, 1, "Lacunarity", 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 6.0f, PROP_UNSIGNED },
+ { SOCK_FLOAT, 1, "Octaves", 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 8.0f, PROP_UNSIGNED },
+
+ { SOCK_FLOAT, 1, "iScale", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f, PROP_UNSIGNED },
+ { SOCK_FLOAT, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED },
+ { -1, 0, "" }
+};
+static void musgrave_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
+{
+ tex->mg_H = tex_input_value(in[I+0], p, thread);
+ tex->mg_lacunarity = tex_input_value(in[I+1], p, thread);
+ tex->mg_octaves = tex_input_value(in[I+2], p, thread);
+ tex->ns_outscale = tex_input_value(in[I+3], p, thread);
+ tex->noisesize = tex_input_value(in[I+4], p, thread);
+}
+ProcDef(musgrave)
+
+/* --- NOISE --- */
+static bNodeSocketTemplate noise_inputs[]= {
+ COMMON_INPUTS,
+ { -1, 0, "" }
+};
+ProcNoInputs(noise)
+ProcDef(noise)
+
+/* --- STUCCI --- */
+static bNodeSocketTemplate stucci_inputs[]= {
+ COMMON_INPUTS,
+ { SOCK_FLOAT, 1, "Size", 0.25f, 0.0f, 0.0f, 0.0f, 0.0001f, 2.0f, PROP_UNSIGNED },
+ { SOCK_FLOAT, 1, "Turbulence", 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 200.0f, PROP_UNSIGNED },
+ { -1, 0, "" }
+};
+static void stucci_map_inputs(Tex *tex, bNodeStack **in, TexParams *p, short thread)
+{
+ tex->noisesize = tex_input_value(in[I+0], p, thread);
+ tex->turbul = tex_input_value(in[I+1], p, thread);
+}
+ProcDef(stucci)
+
+/* --- */
+
+static void init(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
+{
+ Tex *tex = MEM_callocN(sizeof(Tex), "Tex");
+ node->storage= tex;
+
+ default_tex(tex);
+ tex->type = node->type - TEX_NODE_PROC;
+
+ if(tex->type == TEX_WOOD)
+ tex->stype = TEX_BANDNOISE;
+
+}
+
+/* Node type definitions */
+#define TexDef(TEXTYPE, outputs, name, Name) \
+void register_node_type_tex_proc_##name(ListBase *lb) \
+{ \
+ static bNodeType ntype; \
+ \
+ node_type_base(&ntype, TEX_NODE_PROC+TEXTYPE, Name, NODE_CLASS_TEXTURE, NODE_PREVIEW|NODE_OPTIONS); \
+ node_type_socket_templates(&ntype, name##_inputs, outputs); \
+ node_type_size(&ntype, 140, 80, 140); \
+ node_type_init(&ntype, init); \
+ node_type_storage(&ntype, "Tex", node_free_standard_storage, node_copy_standard_storage); \
+ node_type_exec(&ntype, name##_exec); \
+ \
+ nodeRegisterType(lb, &ntype); \
+}
+
+#define C outputs_color_only
+#define CV outputs_both
+
+TexDef(TEX_VORONOI, CV, voronoi, "Voronoi" )
+TexDef(TEX_BLEND, C, blend, "Blend" )
+TexDef(TEX_MAGIC, C, magic, "Magic" )
+TexDef(TEX_MARBLE, CV, marble, "Marble" )
+TexDef(TEX_CLOUDS, CV, clouds, "Clouds" )
+TexDef(TEX_WOOD, CV, wood, "Wood" )
+TexDef(TEX_MUSGRAVE, CV, musgrave, "Musgrave" )
+TexDef(TEX_NOISE, C, noise, "Noise" )
+TexDef(TEX_STUCCI, CV, stucci, "Stucci" )
+TexDef(TEX_DISTNOISE, CV, distnoise, "Distorted Noise" )
diff --git a/source/blender/nodes/texture/nodes/node_texture_rotate.c b/source/blender/nodes/texture/nodes/node_texture_rotate.c
new file mode 100644
index 00000000000..a788b9cbbde
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_rotate.c
@@ -0,0 +1,109 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Robin Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_rotate.c
+ * \ingroup texnodes
+ */
+
+
+#include <math.h>
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+static bNodeSocketTemplate inputs[]= {
+ { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f},
+ { SOCK_FLOAT, 1, "Turns", 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_NONE },
+ { SOCK_VECTOR, 1, "Axis", 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_DIRECTION },
+ { -1, 0, "" }
+};
+
+static bNodeSocketTemplate outputs[]= {
+ { SOCK_RGBA, 0, "Color"},
+ { -1, 0, "" }
+};
+
+static void rotate(float new_co[3], float a, float ax[3], float co[3])
+{
+ float para[3];
+ float perp[3];
+ float cp[3];
+
+ float cos_a = cos(a * (float)(2*M_PI));
+ float sin_a = sin(a * (float)(2*M_PI));
+
+ // x' = xcosa + n(n.x)(1-cosa) + (x*n)sina
+
+ mul_v3_v3fl(perp, co, cos_a);
+ mul_v3_v3fl(para, ax, dot_v3v3(co, ax)*(1 - cos_a));
+
+ cross_v3_v3v3(cp, ax, co);
+ mul_v3_fl(cp, sin_a);
+
+ new_co[0] = para[0] + perp[0] + cp[0];
+ new_co[1] = para[1] + perp[1] + cp[1];
+ new_co[2] = para[2] + perp[2] + cp[2];
+}
+
+static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
+{
+ float new_co[3], new_dxt[3], new_dyt[3], a, ax[3];
+
+ a= tex_input_value(in[1], p, thread);
+ tex_input_vec(ax, in[2], p, thread);
+
+ rotate(new_co, a, ax, p->co);
+ if (p->osatex) {
+ rotate(new_dxt, a, ax, p->dxt);
+ rotate(new_dyt, a, ax, p->dyt);
+ }
+
+ {
+ TexParams np = *p;
+ np.co = new_co;
+ np.dxt = new_dxt;
+ np.dyt = new_dyt;
+ tex_input_rgba(out, in[0], &np, thread);
+ }
+}
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &colorfn, data);
+}
+
+void register_node_type_tex_rotate(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_ROTATE, "Rotate", NODE_CLASS_DISTORT, NODE_OPTIONS);
+ node_type_socket_templates(&ntype, inputs, outputs);
+ node_type_size(&ntype, 140, 100, 320);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
diff --git a/source/blender/nodes/texture/nodes/node_texture_scale.c b/source/blender/nodes/texture/nodes/node_texture_scale.c
new file mode 100644
index 00000000000..136dde0d52f
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_scale.c
@@ -0,0 +1,82 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Robin Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_scale.c
+ * \ingroup texnodes
+ */
+
+
+#include <math.h>
+#include "node_texture_util.h"
+
+static bNodeSocketTemplate inputs[]= {
+ { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f },
+ { SOCK_VECTOR, 1, "Scale", 1.0f, 1.0f, 1.0f, 0.0f, -10.0f, 10.0f, PROP_FACTOR },
+ { -1, 0, "" }
+};
+
+static bNodeSocketTemplate outputs[]= {
+ { SOCK_RGBA, 0, "Color"},
+ { -1, 0, "" }
+};
+
+static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
+{
+ float scale[3], new_co[3], new_dxt[3], new_dyt[3];
+ TexParams np = *p;
+
+ np.co = new_co;
+ np.dxt = new_dxt;
+ np.dyt = new_dyt;
+
+ tex_input_vec(scale, in[1], p, thread);
+
+ mul_v3_v3v3(new_co, p->co, scale);
+ if (p->osatex) {
+ mul_v3_v3v3(new_dxt, p->dxt, scale);
+ mul_v3_v3v3(new_dyt, p->dyt, scale);
+ }
+
+ tex_input_rgba(out, in[0], &np, thread);
+}
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &colorfn, data);
+}
+
+void register_node_type_tex_scale(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_SCALE, "Scale", NODE_CLASS_DISTORT, NODE_OPTIONS);
+ node_type_socket_templates(&ntype, inputs, outputs);
+ node_type_size(&ntype, 90, 80, 100);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
diff --git a/source/blender/nodes/texture/nodes/node_texture_texture.c b/source/blender/nodes/texture/nodes/node_texture_texture.c
new file mode 100644
index 00000000000..10b9b8979f8
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_texture.c
@@ -0,0 +1,103 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Robin Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_texture.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+#include "RE_shader_ext.h"
+
+static bNodeSocketTemplate inputs[]= {
+ { SOCK_RGBA, 1, "Color1", 1.0f, 1.0f, 1.0f, 1.0f },
+ { SOCK_RGBA, 1, "Color2", 0.0f, 0.0f, 0.0f, 1.0f },
+ { -1, 0, "" }
+};
+
+static bNodeSocketTemplate outputs[]= {
+ { SOCK_RGBA, 0, "Color" },
+ { -1, 0, "" }
+};
+
+static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
+{
+ Tex *nodetex = (Tex *)node->id;
+ static float red[] = {1,0,0,1};
+ static float white[] = {1,1,1,1};
+ float co[3], dxt[3], dyt[3];
+
+ copy_v3_v3(co, p->co);
+ copy_v3_v3(dxt, p->dxt);
+ copy_v3_v3(dyt, p->dyt);
+
+ if(node->custom2 || node->need_exec==0) {
+ /* this node refers to its own texture tree! */
+ QUATCOPY(out, (fabs(co[0] - co[1]) < .01) ? white : red );
+ }
+ else if(nodetex) {
+ TexResult texres;
+ int textype;
+ float nor[] = {0,0,0};
+ float col1[4], col2[4];
+
+ tex_input_rgba(col1, in[0], p, thread);
+ tex_input_rgba(col2, in[1], p, thread);
+
+ texres.nor = nor;
+ textype = multitex_nodes(nodetex, co, dxt, dyt, p->osatex,
+ &texres, thread, 0, p->shi, p->mtex);
+
+ if(textype & TEX_RGB) {
+ QUATCOPY(out, &texres.tr);
+ }
+ else {
+ QUATCOPY(out, col1);
+ ramp_blend(MA_RAMP_BLEND, out, out+1, out+2, texres.tin, col2);
+ }
+ }
+}
+
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &colorfn, data);
+}
+
+void register_node_type_tex_texture(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_TEXTURE, "Texture", NODE_CLASS_INPUT, NODE_PREVIEW|NODE_OPTIONS);
+ node_type_socket_templates(&ntype, inputs, outputs);
+ node_type_size(&ntype, 120, 80, 240);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
diff --git a/source/blender/nodes/texture/nodes/node_texture_translate.c b/source/blender/nodes/texture/nodes/node_texture_translate.c
new file mode 100644
index 00000000000..395404a9411
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_translate.c
@@ -0,0 +1,78 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Robin Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_translate.c
+ * \ingroup texnodes
+ */
+
+
+#include <math.h>
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+static bNodeSocketTemplate inputs[]= {
+ { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f},
+ { SOCK_VECTOR, 1, "Offset", 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_TRANSLATION },
+ { -1, 0, "" }
+};
+
+static bNodeSocketTemplate outputs[]= {
+ { SOCK_RGBA, 0, "Color"},
+ { -1, 0, "" }
+};
+
+static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
+{
+ float offset[3], new_co[3];
+ TexParams np = *p;
+ np.co = new_co;
+
+ tex_input_vec(offset, in[1], p, thread);
+
+ new_co[0] = p->co[0] + offset[0];
+ new_co[1] = p->co[1] + offset[1];
+ new_co[2] = p->co[2] + offset[2];
+
+ tex_input_rgba(out, in[0], &np, thread);
+}
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &colorfn, data);
+}
+
+void register_node_type_tex_translate(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_TRANSLATE, "Translate", NODE_CLASS_DISTORT, NODE_OPTIONS);
+ node_type_socket_templates(&ntype, inputs, outputs);
+ node_type_size(&ntype, 90, 80, 100);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
diff --git a/source/blender/nodes/texture/nodes/node_texture_valToNor.c b/source/blender/nodes/texture/nodes/node_texture_valToNor.c
new file mode 100644
index 00000000000..62b457bc862
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_valToNor.c
@@ -0,0 +1,94 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Jucas.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_valToNor.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+static bNodeSocketTemplate inputs[]= {
+ { SOCK_FLOAT, 1, "Val", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE },
+ { SOCK_FLOAT, 1, "Nabla", 0.025f, 0.0f, 0.0f, 0.0f, 0.001f, 0.1f, PROP_UNSIGNED },
+ { -1, 0, "" }
+};
+
+static bNodeSocketTemplate outputs[]= {
+ { SOCK_VECTOR, 0, "Normal" },
+ { -1, 0, "" }
+};
+
+static void normalfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
+{
+ float new_co[3];
+ float *co = p->co;
+
+ float nabla = tex_input_value(in[1], p, thread);
+ float val;
+ float nor[3];
+
+ TexParams np = *p;
+ np.co = new_co;
+
+ val = tex_input_value(in[0], p, thread);
+
+ new_co[0] = co[0] + nabla;
+ new_co[1] = co[1];
+ new_co[2] = co[2];
+ nor[0] = tex_input_value(in[0], &np, thread);
+
+ new_co[0] = co[0];
+ new_co[1] = co[1] + nabla;
+ nor[1] = tex_input_value(in[0], &np, thread);
+
+ new_co[1] = co[1];
+ new_co[2] = co[2] + nabla;
+ nor[2] = tex_input_value(in[0], &np, thread);
+
+ out[0] = val-nor[0];
+ out[1] = val-nor[1];
+ out[2] = val-nor[2];
+}
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &normalfn, data);
+}
+
+void register_node_type_tex_valtonor(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_VALTONOR, "Value to Normal", NODE_CLASS_CONVERTOR, NODE_OPTIONS);
+ node_type_socket_templates(&ntype, inputs, outputs);
+ node_type_size(&ntype, 90, 80, 100);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}
diff --git a/source/blender/nodes/texture/nodes/node_texture_valToRgb.c b/source/blender/nodes/texture/nodes/node_texture_valToRgb.c
new file mode 100644
index 00000000000..caca6fa97a4
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_valToRgb.c
@@ -0,0 +1,116 @@
+/*
+ * $Id: TEX_valToRgb.c 36593 2011-05-10 11:19:26Z lukastoenne $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Robin Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_valToRgb.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+
+/* **************** VALTORGB ******************** */
+static bNodeSocketTemplate valtorgb_in[]= {
+ { SOCK_FLOAT, 1, "Fac", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
+ { -1, 0, "" }
+};
+static bNodeSocketTemplate valtorgb_out[]= {
+ { SOCK_RGBA, 0, "Color"},
+ { -1, 0, "" }
+};
+
+static void valtorgb_colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
+{
+ if(node->storage) {
+ float fac = tex_input_value(in[0], p, thread);
+
+ do_colorband(node->storage, fac, out);
+ }
+}
+
+static void valtorgb_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &valtorgb_colorfn, data);
+}
+
+static void valtorgb_init(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
+{
+ node->storage = add_colorband(1);
+}
+
+void register_node_type_tex_valtorgb(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTOR, NODE_OPTIONS);
+ node_type_socket_templates(&ntype, valtorgb_in, valtorgb_out);
+ node_type_size(&ntype, 240, 200, 300);
+ node_type_init(&ntype, valtorgb_init);
+ node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage);
+ node_type_exec(&ntype, valtorgb_exec);
+
+ nodeRegisterType(lb, &ntype);
+}
+
+/* **************** RGBTOBW ******************** */
+static bNodeSocketTemplate rgbtobw_in[]= {
+ { SOCK_RGBA, 1, "Color", 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f},
+ { -1, 0, "" }
+};
+static bNodeSocketTemplate rgbtobw_out[]= {
+ { SOCK_FLOAT, 0, "Val", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
+ { -1, 0, "" }
+};
+
+
+static void rgbtobw_valuefn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
+{
+ float cin[4];
+ tex_input_rgba(cin, in[0], p, thread);
+
+ *out = cin[0] * 0.35f + cin[1] * 0.45f + cin[2] * 0.2f;
+}
+
+static void rgbtobw_exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ tex_output(node, in, out[0], &rgbtobw_valuefn, data);
+}
+
+void register_node_type_tex_rgbtobw(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTOR, 0);
+ node_type_socket_templates(&ntype, rgbtobw_in, rgbtobw_out);
+ node_type_size(&ntype, 80, 40, 120);
+ node_type_exec(&ntype, rgbtobw_exec);
+
+ nodeRegisterType(lb, &ntype);
+}
+
diff --git a/source/blender/nodes/texture/nodes/node_texture_viewer.c b/source/blender/nodes/texture/nodes/node_texture_viewer.c
new file mode 100644
index 00000000000..01734f56937
--- /dev/null
+++ b/source/blender/nodes/texture/nodes/node_texture_viewer.c
@@ -0,0 +1,70 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Robin Allen
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/texture/nodes/node_texture_viewer.c
+ * \ingroup texnodes
+ */
+
+
+#include "node_texture_util.h"
+#include "NOD_texture.h"
+#include <math.h>
+
+static bNodeSocketTemplate inputs[]= {
+ { SOCK_RGBA, 1, "Color", 1.0f, 0.0f, 0.0f, 1.0f },
+ { -1, 0, "" }
+};
+static bNodeSocketTemplate outputs[]= {
+ { -1, 0, "" }
+};
+
+static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out))
+{
+ TexCallData *cdata = (TexCallData *)data;
+
+ if(cdata->do_preview) {
+ TexParams params;
+ float col[4];
+ params_from_cdata(&params, cdata);
+
+ tex_input_rgba(col, in[0], &params, cdata->thread);
+ tex_do_preview(node, params.previewco, col);
+ }
+}
+
+void register_node_type_tex_viewer(ListBase *lb)
+{
+ static bNodeType ntype;
+
+ node_type_base(&ntype, TEX_NODE_VIEWER, "Viewer", NODE_CLASS_OUTPUT, NODE_PREVIEW);
+ node_type_socket_templates(&ntype, inputs, outputs);
+ node_type_size(&ntype, 100, 60, 150);
+ node_type_exec(&ntype, exec);
+
+ nodeRegisterType(lb, &ntype);
+}