Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Jolly <charlie>2019-12-06 02:02:05 +0300
committerCharlie Jolly <mistajolly@gmail.com>2019-12-07 15:33:07 +0300
commit0406eb110332a863811d7fb6228f9a7ca514e022 (patch)
tree9809062966699e31c785ae0dc97ccb6e9f6c60f7 /source/blender/compositor/operations/COM_MathBaseOperation.cpp
parent6a78ace569ec7c0e076e5af34d9496ce3363b81e (diff)
Maths Node: Additional functions
When creating shaders and using maths functions it is expected that Blender should match functions in other DCC applications, game engines and shading languages such as GLSL and OSL. This patch adds missing functions to the Blender maths node. Ideally, it would be nice to have these functions available to vectors too but that is not part of this patch. This patch adds the following functions trunc, snap, wrap, compare, pingpong, sign, radians, degrees, cosh, sinh, tanh, exp, smoothmin and inversesqrt. Sign function is based on GLSL and OSL functions and returns zero when x == 0. Differential Revision: https://developer.blender.org/D5957
Diffstat (limited to 'source/blender/compositor/operations/COM_MathBaseOperation.cpp')
-rw-r--r--source/blender/compositor/operations/COM_MathBaseOperation.cpp271
1 files changed, 271 insertions, 0 deletions
diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.cpp b/source/blender/compositor/operations/COM_MathBaseOperation.cpp
index 15dbd4e2ac9..d103cc3cf0d 100644
--- a/source/blender/compositor/operations/COM_MathBaseOperation.cpp
+++ b/source/blender/compositor/operations/COM_MathBaseOperation.cpp
@@ -25,9 +25,11 @@ MathBaseOperation::MathBaseOperation() : NodeOperation()
{
this->addInputSocket(COM_DT_VALUE);
this->addInputSocket(COM_DT_VALUE);
+ this->addInputSocket(COM_DT_VALUE);
this->addOutputSocket(COM_DT_VALUE);
this->m_inputValue1Operation = NULL;
this->m_inputValue2Operation = NULL;
+ this->m_inputValue3Operation = NULL;
this->m_useClamp = false;
}
@@ -35,12 +37,14 @@ void MathBaseOperation::initExecution()
{
this->m_inputValue1Operation = this->getInputSocketReader(0);
this->m_inputValue2Operation = this->getInputSocketReader(1);
+ this->m_inputValue3Operation = this->getInputSocketReader(2);
}
void MathBaseOperation::deinitExecution()
{
this->m_inputValue1Operation = NULL;
this->m_inputValue2Operation = NULL;
+ this->m_inputValue3Operation = NULL;
}
void MathBaseOperation::determineResolution(unsigned int resolution[2],
@@ -182,6 +186,54 @@ void MathTangentOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathHyperbolicSineOperation::executePixelSampled(float output[4],
+ float x,
+ float y,
+ PixelSampler sampler)
+{
+ float inputValue1[4];
+ float inputValue2[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+ this->m_inputValue2Operation->readSampled(inputValue2, x, y, sampler);
+
+ output[0] = sinh(inputValue1[0]);
+
+ clampIfNeeded(output);
+}
+
+void MathHyperbolicCosineOperation::executePixelSampled(float output[4],
+ float x,
+ float y,
+ PixelSampler sampler)
+{
+ float inputValue1[4];
+ float inputValue2[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+ this->m_inputValue2Operation->readSampled(inputValue2, x, y, sampler);
+
+ output[0] = cosh(inputValue1[0]);
+
+ clampIfNeeded(output);
+}
+
+void MathHyperbolicTangentOperation::executePixelSampled(float output[4],
+ float x,
+ float y,
+ PixelSampler sampler)
+{
+ float inputValue1[4];
+ float inputValue2[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+ this->m_inputValue2Operation->readSampled(inputValue2, x, y, sampler);
+
+ output[0] = tanh(inputValue1[0]);
+
+ clampIfNeeded(output);
+}
+
void MathArcSineOperation::executePixelSampled(float output[4],
float x,
float y,
@@ -404,6 +456,34 @@ void MathAbsoluteOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+void MathRadiansOperation::executePixelSampled(float output[4],
+ float x,
+ float y,
+ PixelSampler sampler)
+{
+ float inputValue1[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+
+ output[0] = DEG2RADF(inputValue1[0]);
+
+ clampIfNeeded(output);
+}
+
+void MathDegreesOperation::executePixelSampled(float output[4],
+ float x,
+ float y,
+ PixelSampler sampler)
+{
+ float inputValue1[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+
+ output[0] = RAD2DEGF(inputValue1[0]);
+
+ clampIfNeeded(output);
+}
+
void MathArcTan2Operation::executePixelSampled(float output[4],
float x,
float y,
@@ -480,3 +560,194 @@ void MathSqrtOperation::executePixelSampled(float output[4],
clampIfNeeded(output);
}
+
+void MathInverseSqrtOperation::executePixelSampled(float output[4],
+ float x,
+ float y,
+ PixelSampler sampler)
+{
+ float inputValue1[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+
+ if (inputValue1[0] > 0) {
+ output[0] = 1.0f / sqrt(inputValue1[0]);
+ }
+ else {
+ output[0] = 0.0f;
+ }
+
+ clampIfNeeded(output);
+}
+
+void MathSignOperation::executePixelSampled(float output[4],
+ float x,
+ float y,
+ PixelSampler sampler)
+{
+ float inputValue1[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+
+ output[0] = compatible_signf(inputValue1[0]);
+
+ clampIfNeeded(output);
+}
+
+void MathExponentOperation::executePixelSampled(float output[4],
+ float x,
+ float y,
+ PixelSampler sampler)
+{
+ float inputValue1[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+
+ output[0] = expf(inputValue1[0]);
+
+ clampIfNeeded(output);
+}
+
+void MathTruncOperation::executePixelSampled(float output[4],
+ float x,
+ float y,
+ PixelSampler sampler)
+{
+ float inputValue1[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+
+ output[0] = (inputValue1[0] >= 0.0f) ? floor(inputValue1[0]) : ceil(inputValue1[0]);
+
+ clampIfNeeded(output);
+}
+
+void MathSnapOperation::executePixelSampled(float output[4],
+ float x,
+ float y,
+ PixelSampler sampler)
+{
+ float inputValue1[4];
+ float inputValue2[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+ this->m_inputValue2Operation->readSampled(inputValue2, x, y, sampler);
+
+ if (inputValue1[0] == 0 || inputValue2[0] == 0) { /* We don't want to divide by zero. */
+ output[0] = 0.0f;
+ }
+ else {
+ output[0] = floorf(inputValue1[0] / inputValue2[0]) * inputValue2[0];
+ }
+
+ clampIfNeeded(output);
+}
+
+void MathWrapOperation::executePixelSampled(float output[4],
+ float x,
+ float y,
+ PixelSampler sampler)
+{
+ float inputValue1[4];
+ float inputValue2[4];
+ float inputValue3[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+ this->m_inputValue2Operation->readSampled(inputValue2, x, y, sampler);
+ this->m_inputValue3Operation->readSampled(inputValue3, x, y, sampler);
+
+ output[0] = wrapf(inputValue1[0], inputValue2[0], inputValue3[0]);
+
+ clampIfNeeded(output);
+}
+
+void MathPingpongOperation::executePixelSampled(float output[4],
+ float x,
+ float y,
+ PixelSampler sampler)
+{
+ float inputValue1[4];
+ float inputValue2[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+ this->m_inputValue2Operation->readSampled(inputValue2, x, y, sampler);
+
+ output[0] = output[0] = fabsf(
+ fractf((inputValue1[0] - inputValue2[0]) / (inputValue2[0] * 2.0f)) * inputValue2[0] * 2.0f -
+ inputValue2[0]);
+
+ clampIfNeeded(output);
+}
+
+void MathCompareOperation::executePixelSampled(float output[4],
+ float x,
+ float y,
+ PixelSampler sampler)
+{
+ float inputValue1[4];
+ float inputValue2[4];
+ float inputValue3[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+ this->m_inputValue2Operation->readSampled(inputValue2, x, y, sampler);
+ this->m_inputValue3Operation->readSampled(inputValue3, x, y, sampler);
+
+ output[0] = (fabsf(inputValue1[0] - inputValue2[0]) <= MAX2(inputValue3[0], 1e-5f)) ? 1.0f :
+ 0.0f;
+
+ clampIfNeeded(output);
+}
+
+void MathMultiplyAddOperation::executePixelSampled(float output[4],
+ float x,
+ float y,
+ PixelSampler sampler)
+{
+ float inputValue1[4];
+ float inputValue2[4];
+ float inputValue3[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+ this->m_inputValue2Operation->readSampled(inputValue2, x, y, sampler);
+ this->m_inputValue3Operation->readSampled(inputValue3, x, y, sampler);
+
+ output[0] = inputValue1[0] * inputValue2[0] + inputValue3[0];
+
+ clampIfNeeded(output);
+}
+
+void MathSmoothMinOperation::executePixelSampled(float output[4],
+ float x,
+ float y,
+ PixelSampler sampler)
+{
+ float inputValue1[4];
+ float inputValue2[4];
+ float inputValue3[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+ this->m_inputValue2Operation->readSampled(inputValue2, x, y, sampler);
+ this->m_inputValue3Operation->readSampled(inputValue3, x, y, sampler);
+
+ output[0] = smoothminf(inputValue1[0], inputValue2[0], inputValue3[0]);
+
+ clampIfNeeded(output);
+}
+
+void MathSmoothMaxOperation::executePixelSampled(float output[4],
+ float x,
+ float y,
+ PixelSampler sampler)
+{
+ float inputValue1[4];
+ float inputValue2[4];
+ float inputValue3[4];
+
+ this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
+ this->m_inputValue2Operation->readSampled(inputValue2, x, y, sampler);
+ this->m_inputValue3Operation->readSampled(inputValue3, x, y, sampler);
+
+ output[0] = -smoothminf(-inputValue1[0], -inputValue2[0], inputValue3[0]);
+
+ clampIfNeeded(output);
+}