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.
This commit is contained in:
Jacques Lucke 2020-11-25 12:24:32 +01:00
parent 9e77fc533c
commit 1c86d32fa7
3 changed files with 10 additions and 9 deletions

View File

@ -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)

View File

@ -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);
}

View File

@ -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;
}