diff options
author | Matt Heimlich <matt.heimlich@gmail.com> | 2014-05-07 18:20:17 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2014-05-07 18:43:59 +0400 |
commit | 3fbc984b069fed441cccdd3416ec71e064235e36 (patch) | |
tree | 1c95f9d57457069eb3918deb727fc62b4c83dee5 /source/blender | |
parent | 8b8d5a441f5815e83f83bacf8023e2cc3fbb2a04 (diff) |
Nodes: add absolute value operation to all math nodes
Reviewed By: dingto, brecht
Differential Revision: https://developer.blender.org/D507
Diffstat (limited to 'source/blender')
7 files changed, 41 insertions, 3 deletions
diff --git a/source/blender/compositor/nodes/COM_MathNode.cpp b/source/blender/compositor/nodes/COM_MathNode.cpp index 42a8cb032ce..ac1c2b3c159 100644 --- a/source/blender/compositor/nodes/COM_MathNode.cpp +++ b/source/blender/compositor/nodes/COM_MathNode.cpp @@ -83,6 +83,9 @@ void MathNode::convertToOperations(NodeConverter &converter, const CompositorCon case 17: /* Modulo */ operation = new MathModuloOperation(); break; + case 18: /* Absolute Value */ + operation = new MathAbsoluteOperation(); + break; } if (operation) { diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.cpp b/source/blender/compositor/operations/COM_MathBaseOperation.cpp index 9da55df476d..cbc60b5091d 100644 --- a/source/blender/compositor/operations/COM_MathBaseOperation.cpp +++ b/source/blender/compositor/operations/COM_MathBaseOperation.cpp @@ -333,3 +333,14 @@ void MathModuloOperation::executePixelSampled(float output[4], float x, float y, clampIfNeeded(output); } +void MathAbsoluteOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler) +{ + float inputValue1[4]; + + this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler); + + output[0] = fabs(inputValue1[0]); + + clampIfNeeded(output); +} + diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.h b/source/blender/compositor/operations/COM_MathBaseOperation.h index 4ea7c43a67d..05d2bb054d3 100644 --- a/source/blender/compositor/operations/COM_MathBaseOperation.h +++ b/source/blender/compositor/operations/COM_MathBaseOperation.h @@ -163,4 +163,10 @@ public: void executePixelSampled(float output[4], float x, float y, PixelSampler sampler); }; +class MathAbsoluteOperation : public MathBaseOperation { +public: + MathAbsoluteOperation() : MathBaseOperation() {} + void executePixelSampled(float output[4], float x, float y, PixelSampler sampler); +}; + #endif diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index 4452d4e06c3..a224f8e979a 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -299,6 +299,11 @@ void math_modulo(float val1, float val2, out float outval) outval = mod(val1, val2); } +void math_abs(float val1, out float outval) +{ + outval = abs(val1); +} + void squeeze(float val, float width, float center, out float outval) { outval = 1.0/(1.0 + pow(2.71828183, -((val-center)*width))); diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 0f2380cbad4..c39d3826d8b 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -129,7 +129,8 @@ EnumPropertyItem node_math_items[] = { {14, "ROUND", 0, "Round", ""}, {15, "LESS_THAN", 0, "Less Than", ""}, {16, "GREATER_THAN", 0, "Greater Than", ""}, - {17, "MODULO", 0, "Modulo", ""}, + {17, "MODULO", 0, "Modulo", ""}, + {18, "ABSOLUTE", 0, "Absolute", ""}, {0, NULL, 0, NULL, NULL} }; diff --git a/source/blender/nodes/shader/nodes/node_shader_math.c b/source/blender/nodes/shader/nodes/node_shader_math.c index b6c755571c0..ed88e800d33 100644 --- a/source/blender/nodes/shader/nodes/node_shader_math.c +++ b/source/blender/nodes/shader/nodes/node_shader_math.c @@ -216,6 +216,11 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode r = fmod(a, b); break; } + case 18: /* Absolute */ + { + r = fabs(a); + break; + } } out[0]->vec[0] = r; @@ -226,7 +231,7 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED( static const char *names[] = {"math_add", "math_subtract", "math_multiply", "math_divide", "math_sine", "math_cosine", "math_tangent", "math_asin", "math_acos", "math_atan", "math_pow", "math_log", "math_min", "math_max", - "math_round", "math_less_than", "math_greater_than", "math_modulo"}; + "math_round", "math_less_than", "math_greater_than", "math_modulo", "math_absolute"}; switch (node->custom1) { case 0: diff --git a/source/blender/nodes/texture/nodes/node_texture_math.c b/source/blender/nodes/texture/nodes/node_texture_math.c index 8d69d79d847..86d693f7dfa 100644 --- a/source/blender/nodes/texture/nodes/node_texture_math.c +++ b/source/blender/nodes/texture/nodes/node_texture_math.c @@ -174,7 +174,7 @@ static void valuefn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor break; } - case 17: /* Modulo */ + case 17: /* Modulo */ { if (in1 == 0.0f) *out = 0.0f; @@ -182,6 +182,13 @@ static void valuefn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor *out = fmod(in0, in1); break; } + + case 18: /* Absolute */ + { + *out = fabs(in0); + break; + } + default: { BLI_assert(0); |