diff options
author | Jacques Lucke <jacques@blender.org> | 2020-11-25 14:24:32 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-11-25 14:24:44 +0300 |
commit | 1c86d32fa7d4c367370d06b7983410f4c33d58a2 (patch) | |
tree | cdf9c9eb7de3b3e03da649f0be07026670837fa0 /source/blender | |
parent | 9e77fc533c1387776900fcc91ed9591f33dd8bf2 (diff) |
Nodes: deduplicate ping pong math operation
The formula did not change. The only side effect of this change should be
that the compositor node now does not divide by zero in some cases.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/intern/math_base_inline.c | 8 | ||||
-rw-r--r-- | source/blender/compositor/operations/COM_MathBaseOperation.cpp | 4 | ||||
-rw-r--r-- | source/blender/nodes/texture/nodes/node_texture_math.c | 7 |
3 files changed, 10 insertions, 9 deletions
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index 8cc5c31a4c7..1dc7c21f1d4 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -387,6 +387,14 @@ MINLINE float wrapf(float value, float max, float min) return (range != 0.0f) ? value - (range * floorf((value - min) / range)) : min; } +MINLINE float pingpongf(float value, float scale) +{ + if (scale == 0.0f) { + return 0.0f; + } + return fabsf(fractf((value - scale) / (scale * 2.0f)) * scale * 2.0f - scale); +} + // Square. MINLINE int square_s(short a) diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.cpp b/source/blender/compositor/operations/COM_MathBaseOperation.cpp index edd5bb6d139..dbec6dd1874 100644 --- a/source/blender/compositor/operations/COM_MathBaseOperation.cpp +++ b/source/blender/compositor/operations/COM_MathBaseOperation.cpp @@ -671,9 +671,7 @@ void MathPingpongOperation::executePixelSampled(float output[4], this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler); this->m_inputValue2Operation->readSampled(inputValue2, x, y, sampler); - output[0] = fabsf(fractf((inputValue1[0] - inputValue2[0]) / (inputValue2[0] * 2.0f)) * - inputValue2[0] * 2.0f - - inputValue2[0]); + output[0] = pingpongf(inputValue1[0], inputValue2[0]); clampIfNeeded(output); } diff --git a/source/blender/nodes/texture/nodes/node_texture_math.c b/source/blender/nodes/texture/nodes/node_texture_math.c index 134a0ebb093..53022c9e120 100644 --- a/source/blender/nodes/texture/nodes/node_texture_math.c +++ b/source/blender/nodes/texture/nodes/node_texture_math.c @@ -282,12 +282,7 @@ static void valuefn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor } case NODE_MATH_PINGPONG: { - if (in1 == 0.0f) { - *out = 0.0f; - } - else { - *out = fabsf(fractf((in0 - in1) / (in1 * 2.0f)) * in1 * 2.0f - in1); - } + *out = pingpongf(in0, in1); break; } |