[Bf-blender-cvs] [94dd73b] texture_nodes_refactor: Support some more nodes
Sergey Sharybin
noreply at git.blender.org
Sat Oct 11 18:58:06 CEST 2014
Commit: 94dd73b9950d6fd206db351f55d0c40da398fafc
Author: Sergey Sharybin
Date: Sat Oct 11 22:57:53 2014 +0600
Branches: texture_nodes_refactor
https://developer.blender.org/rB94dd73b9950d6fd206db351f55d0c40da398fafc
Support some more nodes
===================================================================
M source/blender/nodes/texture/nodes/node_texture_math.c
M source/blender/nodes/texture/nodes/node_texture_mixRgb.c
M source/blender/nodes/texture/nodes/node_texture_output.c
M source/blender/nodes/texture/nodes/node_texture_viewer.c
===================================================================
diff --git a/source/blender/nodes/texture/nodes/node_texture_math.c b/source/blender/nodes/texture/nodes/node_texture_math.c
index 654ae9e..022e5db 100644
--- a/source/blender/nodes/texture/nodes/node_texture_math.c
+++ b/source/blender/nodes/texture/nodes/node_texture_math.c
@@ -46,7 +46,12 @@ static bNodeSocketTemplate outputs[] = {
{ -1, 0, "" }
};
-static void valuefn(float *out, TexParams *UNUSED(p), bNode *node, bNodeStack **in, short UNUSED(thread))
+static void exec(void *UNUSED(data),
+ int UNUSED(thread),
+ bNode *node,
+ bNodeExecData *UNUSED(execdata),
+ bNodeStack **in,
+ bNodeStack **out)
{
float in0 = tex_input_value(in[0]);
float in1 = tex_input_value(in[1]);
@@ -54,73 +59,73 @@ static void valuefn(float *out, TexParams *UNUSED(p), bNode *node, bNodeStack **
switch (node->custom1) {
case 0: /* Add */
- *out = in0 + in1;
+ out[0]->vec[0] = in0 + in1;
break;
case 1: /* Subtract */
- *out = in0 - in1;
+ out[0]->vec[0] = in0 - in1;
break;
case 2: /* Multiply */
- *out = in0 * in1;
+ out[0]->vec[0] = in0 * in1;
break;
case 3: /* Divide */
{
if (in1 == 0) /* We don't want to divide by zero. */
- *out = 0.0;
+ out[0]->vec[0] = 0.0f;
else
- *out = in0 / in1;
+ out[0]->vec[0] = in0 / in1;
break;
}
case 4: /* Sine */
{
- *out = sinf(in0);
+ out[0]->vec[0] = sinf(in0);
break;
}
case 5: /* Cosine */
{
- *out = cosf(in0);
+ out[0]->vec[0] = cosf(in0);
break;
}
case 6: /* Tangent */
{
- *out = tanf(in0);
+ out[0]->vec[0] = tanf(in0);
break;
}
case 7: /* Arc-Sine */
{
/* Can't do the impossible... */
- if (in0 <= 1 && in0 >= -1)
- *out = asinf(in0);
+ if (in0 <= 1.0f && in0 >= -1.0f)
+ out[0]->vec[0] = asinf(in0);
else
- *out = 0.0;
+ out[0]->vec[0] = 0.0f;
break;
}
case 8: /* Arc-Cosine */
{
/* Can't do the impossible... */
- if (in0 <= 1 && in0 >= -1)
- *out = acosf(in0);
+ if (in0 <= 1.0f && in0 >= -1.0f)
+ out[0]->vec[0]= acosf(in0);
else
- *out = 0.0;
+ out[0]->vec[0] = 0.0;
break;
}
case 9: /* Arc-Tangent */
{
- *out = atan(in0);
+ out[0]->vec[0] = atan(in0);
break;
}
case 10: /* Power */
{
/* Only raise negative numbers by full integers */
- if (in0 >= 0) {
- out[0] = pow(in0, in1);
+ if (in0 >= 0.0f) {
+ out[0]->vec[0] = pow(in0, in1);
}
else {
- float y_mod_1 = fmod(in1, 1);
+ float y_mod_1 = fmod(in1, 1.0f);
if (y_mod_1 > 0.999f || y_mod_1 < 0.001f) {
- *out = pow(in0, floor(in1 + 0.5f));
+ out[0]->vec[0] = powf(in0, floor(in1 + 0.5f));
}
else {
- *out = 0.0;
+ out[0]->vec[0] = 0.0f;
}
}
break;
@@ -128,64 +133,64 @@ static void valuefn(float *out, TexParams *UNUSED(p), bNode *node, bNodeStack **
case 11: /* Logarithm */
{
/* Don't want any imaginary numbers... */
- if (in0 > 0 && in1 > 0)
- *out = log(in0) / log(in1);
+ if (in0 > 0.0f && in1 > 0.0f)
+ out[0]->vec[0] = log(in0) / log(in1);
else
- *out = 0.0;
+ out[0]->vec[0] = 0.0;
break;
}
case 12: /* Minimum */
{
if (in0 < in1)
- *out = in0;
+ out[0]->vec[0] = in0;
else
- *out = in1;
+ out[0]->vec[0] = in1;
break;
}
case 13: /* Maximum */
{
if (in0 > in1)
- *out = in0;
+ out[0]->vec[0] = in0;
else
- *out = in1;
+ out[0]->vec[0] = in1;
break;
}
case 14: /* Round */
{
- *out = (in0 < 0) ? (int)(in0 - 0.5f) : (int)(in0 + 0.5f);
+ out[0]->vec[0] = (in0 < 0.0f) ? (int)(in0 - 0.5f) : (int)(in0 + 0.5f);
break;
}
case 15: /* Less Than */
{
if (in0 < in1)
- *out = 1.0f;
+ out[0]->vec[0] = 1.0f;
else
- *out = 0.0f;
+ out[0]->vec[0] = 0.0f;
break;
}
case 16: /* Greater Than */
{
if (in0 > in1)
- *out = 1.0f;
+ out[0]->vec[0] = 1.0f;
else
- *out = 0.0f;
+ out[0]->vec[0] = 0.0f;
break;
}
case 17: /* Modulo */
{
if (in1 == 0.0f)
- *out = 0.0f;
+ out[0]->vec[0] = 0.0f;
else
- *out = fmod(in0, in1);
+ out[0]->vec[0] = fmod(in0, in1);
break;
}
case 18: /* Absolute */
{
- *out = fabsf(in0);
+ out[0]->vec[0] = fabsf(in0);
break;
}
@@ -197,11 +202,6 @@ static void valuefn(float *out, TexParams *UNUSED(p), bNode *node, bNodeStack **
}
}
-static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
-{
- tex_output(node, execdata, in, out[0], &valuefn, data);
-}
-
void register_node_type_tex_math(void)
{
static bNodeType ntype;
diff --git a/source/blender/nodes/texture/nodes/node_texture_mixRgb.c b/source/blender/nodes/texture/nodes/node_texture_mixRgb.c
index 0126b3d..66b2361 100644
--- a/source/blender/nodes/texture/nodes/node_texture_mixRgb.c
+++ b/source/blender/nodes/texture/nodes/node_texture_mixRgb.c
@@ -4,7 +4,7 @@
* 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.
+ * 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
@@ -45,37 +45,37 @@ static bNodeSocketTemplate outputs[] = {
{ -1, 0, "" }
};
-static void colorfn(float *out, TexParams *UNUSED(p), bNode *node, bNodeStack **in, short UNUSED(thread))
+static void exec(void *UNUSED(data),
+ int UNUSED(thread),
+ bNode *node,
+ bNodeExecData *UNUSED(execdata),
+ bNodeStack **in,
+ bNodeStack **out)
{
float fac = tex_input_value(in[0]);
float col1[4], col2[4];
-
+
tex_input_rgba(col1, in[1]);
tex_input_rgba(col2, in[2]);
/* use alpha */
if (node->custom2 & 1)
fac *= col2[3];
-
+
CLAMP(fac, 0.0f, 1.0f);
-
- copy_v4_v4(out, col1);
- ramp_blend(node->custom1, out, fac, col2);
-}
-static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
-{
- tex_output(node, execdata, in, out[0], &colorfn, data);
+ copy_v4_v4(out[0]->vec, col1);
+ ramp_blend(node->custom1, out[0]->vec, fac, col2);
}
void register_node_type_tex_mix_rgb(void)
{
static bNodeType ntype;
-
+
tex_node_type_base(&ntype, TEX_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR, 0);
node_type_socket_templates(&ntype, inputs, outputs);
node_type_label(&ntype, node_blend_label);
node_type_exec(&ntype, NULL, NULL, exec);
-
+
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/texture/nodes/node_texture_output.c b/source/blender/nodes/texture/nodes/node_texture_output.c
index 7761468..970cb34 100644
--- a/source/blender/nodes/texture/nodes/node_texture_output.c
+++ b/source/blender/nodes/texture/nodes/node_texture_output.c
@@ -4,7 +4,7 @@
* 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.
+ * 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
@@ -41,29 +41,31 @@ static bNodeSocketTemplate inputs[] = {
};
/* applies to render pipeline */
-static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **UNUSED(out))
+static void exec(void *data,
+ int UNUSED(thread),
+ bNode *node,
+ bNodeExecData *execdata,
+ bNodeStack **in,
+ bNodeStack **UNUSED(out))
{
TexCallData *cdata = (TexCallData *)data;
TexResult *target = cdata->target;
-
- if (cdata->do_preview) {
- TexParams params;
- params_from_cdata(¶ms, cdata);
+ if (cdata->do_preview) {
if (in[1] && in[1]->hasinput && !in[0]->hasinput)
tex_input_rgba(&target->tr, in[1]);
else
tex_input_rgba(&target->tr, in[0]);
- tex_do_preview(execdata->preview, params.co, &target->tr, cdata->do_manage);
+ tex_do_preview(execdata->preview, cdata->co, &target->tr, cdata->do_manage);
}
else {
/* 0 means don't care, so just use first */
if (cdata->which_output == node->custom1 || (cdata->which_output == 0 && node->custom1 == 1)) {
tex_input_rgba(&target->tr, in[0]);
-
+
target->tin = (target->tr + target->tg + target->tb) / 3.0f;
target->talpha = true;
-
+
if (target->nor) {
if (in[1] && in[1]->hasinput)
tex_input_vec(target->nor, in[1]);
@@ -82,7 +84,7 @@ static void unique_name(bNode *node)
int suffix;
bNode *i;
const char *name = tno->name;
-
+
new_name[0] = '\0';
i = node;
while (i->prev) i = i->prev;
@@ -111,7 +113,7 @@ static void unique_name(bNode *node)
}
sprintf(new_name + new_len - 4, ".%03d", ++suffix);
}
-
+
if (new_name[0] != '\0') {
BLI_strncpy(tno->name, new_name, sizeof(tno->name));
}
@@ -121,19 +123,21 @@ 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)
+ for (; tnode; tnode = tnode->next) {
+ if (tnode->type == TEX_NODE_OUTPUT && tnode != node) {
if (tnode->custom1 == index) {
index++;
goto check_index;
}
-
+ }
+ }
+
node->custom1 = index;
}
@@ -141,7 +145,7 @@ static void init(bNodeTree *UNUSED(ntree), bNode *node)
{
TexNodeOutput *tno = MEM_callocN(sizeof(TexNodeOutput), "TEX_output");
node->storage = tno;
-
+
strcpy(tno->name, "Default");
unique_name(node);
assign_index(node);
@@ -157,16 +161,16 @@ static void copy(bNodeTree *dest_ntree, bNode *dest_node, bNode *src_node)
void register_node_type_tex_output(void
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list