36
36
/* **************** NORMALIZE single channel, useful for Z buffer ******************** */
37
static bNodeSocketTemplate cmp_node_normalize_in[]= {
38
{ SOCK_FLOAT, 1, "Value", 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE},
41
static bNodeSocketTemplate cmp_node_normalize_out[]= {
42
{ SOCK_FLOAT, 0, "Value"},
46
static void do_normalize(bNode *UNUSED(node), float *out, float *src, float *min, float *mult)
49
res = (src[0] - min[0]) * mult[0];
53
else if (res < 0.0f) {
61
/* The code below assumes all data is inside range +- this, and that input buffer is single channel */
62
#define BLENDER_ZMAX 10000.0f
64
static void node_composit_exec_normalize(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
66
/* stack order in: valbuf */
67
/* stack order out: valbuf */
68
if (out[0]->hasoutput==0) return;
70
/* Input has no image buffer? Then pass the value */
71
if (in[0]->data==NULL) {
72
copy_v4_v4(out[0]->vec, in[0]->vec);
75
float min = 1.0f+BLENDER_ZMAX;
76
float max = -1.0f-BLENDER_ZMAX;
79
/* make output size of input image */
80
CompBuf *cbuf= in[0]->data;
81
int tot= cbuf->x*cbuf->y;
82
CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_VAL, 1); /* allocs */
84
for (val = cbuf->rect; tot; tot--, val++) {
85
if ((*val > max) && (*val <= BLENDER_ZMAX)) {
88
if ((*val < min) && (*val >= -BLENDER_ZMAX)) {
92
/* In the rare case of flat buffer, which would cause a divide by 0, just pass the input to the output */
93
if ((max-min) != 0.0f) {
94
mult = 1.0f/(max-min);
95
composit3_pixel_processor(node, stackbuf, in[0]->data, in[0]->vec, NULL, &min, NULL, &mult, do_normalize, CB_VAL, CB_VAL, CB_VAL);
98
memcpy(stackbuf->rect, cbuf->rect, sizeof(float) * cbuf->x * cbuf->y);
101
out[0]->data= stackbuf;
37
static bNodeSocketTemplate cmp_node_normalize_in[] = {
38
{ SOCK_FLOAT, 1, N_("Value"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE},
41
static bNodeSocketTemplate cmp_node_normalize_out[] = {
42
{ SOCK_FLOAT, 0, N_("Value")},
105
46
void register_node_type_cmp_normalize(bNodeTreeType *ttype)
109
50
node_type_base(ttype, &ntype, CMP_NODE_NORMALIZE, "Normalize", NODE_CLASS_OP_VECTOR, NODE_OPTIONS);
110
51
node_type_socket_templates(&ntype, cmp_node_normalize_in, cmp_node_normalize_out);
111
52
node_type_size(&ntype, 100, 60, 150);
112
node_type_exec(&ntype, node_composit_exec_normalize);
114
54
nodeRegisterType(ttype, &ntype);