--Value Squeeze Node--

This material node takes an input value of any size and fits it to a sigmoid curve (value between 0 and 1) The width of the curve can set to make the sigmoid fall off faster (bigger number) or slower (smaller number) and the centerpoint (what value is mapped to 0.5) can be adjusted as well. Anyone smarter than me can feel free to tweak this and make it better.
This commit is contained in:
2006-08-03 13:22:51 +00:00
parent c22260a7cb
commit 8dbefad451
2 changed files with 33 additions and 1 deletions

View File

@@ -180,7 +180,7 @@ struct ShadeResult;
#define SH_NODE_CAMERA 114
#define SH_NODE_MATH 115
#define SH_NODE_VECT_MATH 116
#define SH_NODE_SQUEEZE 117
/* custom defines: options for Material node */
#define SH_NODE_MAT_DIFF 1
#define SH_NODE_MAT_SPEC 2

View File

@@ -634,6 +634,37 @@ static bNodeType sh_node_math= {
/* execfunc */ node_shader_exec_math
};
/* **************** VALUE SQUEEZE ******************** */
static bNodeSocketType sh_node_squeeze_in[]= {
{ SOCK_VALUE, 1, "Value", 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f},
{ SOCK_VALUE, 1, "Width", 1.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f},
{ SOCK_VALUE, 1, "Center", 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f},
{ -1, 0, "" }
};
static bNodeSocketType sh_node_squeeze_out[]= {
{ SOCK_VALUE, 0, "Value", 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
{ -1, 0, "" }
};
static void node_shader_exec_squeeze(void *data, bNode *node, bNodeStack **in,
bNodeStack **out)
{
out[0]->vec[0] = 1 / (1 + pow(2.71828183,-((in[0]->vec[0]-in[2]->vec[0])*in[1]->vec[0]))) ;
}
static bNodeType sh_node_squeeze= {
/* type code */ SH_NODE_SQUEEZE,
/* name */ "Squeeze Value",
/* width+range */ 120, 110, 160,
/* class+opts */ NODE_CLASS_CONVERTOR, NODE_OPTIONS,
/* input sock */ sh_node_squeeze_in,
/* output sock */ sh_node_squeeze_out,
/* storage */ "node_squeeze",
/* execfunc */ node_shader_exec_squeeze
};
/* **************** VECTOR MATH ******************** */
static bNodeSocketType sh_node_vect_math_in[]= {
@@ -983,6 +1014,7 @@ bNodeType *node_all_shaders[]= {
&sh_node_curve_rgb,
&sh_node_math,
&sh_node_vect_math,
&sh_node_squeeze,
NULL
};