[Bf-blender-cvs] [e09bae21e79] compositor-full-frame: Compositor: Full frame Math node

Manuel Castilla noreply at git.blender.org
Tue Jul 27 23:26:02 CEST 2021


Commit: e09bae21e7908e46b341801b25da163b6ae2fd76
Author: Manuel Castilla
Date:   Sat Jul 24 23:48:50 2021 +0200
Branches: compositor-full-frame
https://developer.blender.org/rBe09bae21e7908e46b341801b25da163b6ae2fd76

Compositor: Full frame Math node

Adds full frame implementation to this node operations.
No functional changes.

===================================================================

M	source/blender/compositor/operations/COM_MathBaseOperation.cc
M	source/blender/compositor/operations/COM_MathBaseOperation.h

===================================================================

diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.cc b/source/blender/compositor/operations/COM_MathBaseOperation.cc
index a94c14347fb..67246a0f243 100644
--- a/source/blender/compositor/operations/COM_MathBaseOperation.cc
+++ b/source/blender/compositor/operations/COM_MathBaseOperation.cc
@@ -18,12 +18,12 @@
 
 #include "COM_MathBaseOperation.h"
 
-#include "BLI_math.h"
-
 namespace blender::compositor {
 
 MathBaseOperation::MathBaseOperation()
 {
+  /* TODO(manzanilla): After removing tiled implementation, template this class to only add needed
+   * number of inputs. */
   this->addInputSocket(DataType::Value);
   this->addInputSocket(DataType::Value);
   this->addInputSocket(DataType::Value);
@@ -32,6 +32,7 @@ MathBaseOperation::MathBaseOperation()
   this->m_inputValue2Operation = nullptr;
   this->m_inputValue3Operation = nullptr;
   this->m_useClamp = false;
+  this->flags.can_be_constant = true;
 }
 
 void MathBaseOperation::initExecution()
@@ -73,6 +74,21 @@ void MathBaseOperation::clampIfNeeded(float *color)
   }
 }
 
+void MathBaseOperation::update_memory_buffer_partial(MemoryBuffer *output,
+                                                     const rcti &area,
+                                                     Span<MemoryBuffer *> inputs)
+{
+  {
+    BuffersIterator<float> it = output->iterate_with(inputs, area);
+    update_memory_buffer_partial(it);
+  }
+  if (this->m_useClamp) {
+    for (BuffersIterator<float> it = output->iterate_with({}, area); !it.is_end(); ++it) {
+      CLAMP(*it.out, 0.0f, 1.0f);
+    }
+  }
+}
+
 void MathAddOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
 {
   float inputValue1[4];
@@ -139,6 +155,14 @@ void MathDivideOperation::executePixelSampled(float output[4],
   clampIfNeeded(output);
 }
 
+void MathDivideOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+  for (; !it.is_end(); ++it) {
+    const float divisor = *it.in(1);
+    *it.out = (divisor == 0) ? 0 : *it.in(0) / divisor;
+  }
+}
+
 void MathSineOperation::executePixelSampled(float output[4],
                                             float x,
                                             float y,
@@ -155,6 +179,13 @@ void MathSineOperation::executePixelSampled(float output[4],
   clampIfNeeded(output);
 }
 
+void MathSineOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+  for (; !it.is_end(); ++it) {
+    *it.out = sin(*it.in(0));
+  }
+}
+
 void MathCosineOperation::executePixelSampled(float output[4],
                                               float x,
                                               float y,
@@ -171,6 +202,13 @@ void MathCosineOperation::executePixelSampled(float output[4],
   clampIfNeeded(output);
 }
 
+void MathCosineOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+  for (; !it.is_end(); ++it) {
+    *it.out = cos(*it.in(0));
+  }
+}
+
 void MathTangentOperation::executePixelSampled(float output[4],
                                                float x,
                                                float y,
@@ -187,6 +225,13 @@ void MathTangentOperation::executePixelSampled(float output[4],
   clampIfNeeded(output);
 }
 
+void MathTangentOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+  for (; !it.is_end(); ++it) {
+    *it.out = tan(*it.in(0));
+  }
+}
+
 void MathHyperbolicSineOperation::executePixelSampled(float output[4],
                                                       float x,
                                                       float y,
@@ -203,6 +248,13 @@ void MathHyperbolicSineOperation::executePixelSampled(float output[4],
   clampIfNeeded(output);
 }
 
+void MathHyperbolicSineOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+  for (; !it.is_end(); ++it) {
+    *it.out = sinh(*it.in(0));
+  }
+}
+
 void MathHyperbolicCosineOperation::executePixelSampled(float output[4],
                                                         float x,
                                                         float y,
@@ -219,6 +271,13 @@ void MathHyperbolicCosineOperation::executePixelSampled(float output[4],
   clampIfNeeded(output);
 }
 
+void MathHyperbolicCosineOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+  for (; !it.is_end(); ++it) {
+    *it.out = cosh(*it.in(0));
+  }
+}
+
 void MathHyperbolicTangentOperation::executePixelSampled(float output[4],
                                                          float x,
                                                          float y,
@@ -235,6 +294,13 @@ void MathHyperbolicTangentOperation::executePixelSampled(float output[4],
   clampIfNeeded(output);
 }
 
+void MathHyperbolicTangentOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+  for (; !it.is_end(); ++it) {
+    *it.out = tanh(*it.in(0));
+  }
+}
+
 void MathArcSineOperation::executePixelSampled(float output[4],
                                                float x,
                                                float y,
@@ -256,6 +322,14 @@ void MathArcSineOperation::executePixelSampled(float output[4],
   clampIfNeeded(output);
 }
 
+void MathArcSineOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+  for (; !it.is_end(); ++it) {
+    float value1 = *it.in(0);
+    *it.out = (value1 <= 1 && value1 >= -1) ? asin(value1) : 0.0f;
+  }
+}
+
 void MathArcCosineOperation::executePixelSampled(float output[4],
                                                  float x,
                                                  float y,
@@ -277,6 +351,14 @@ void MathArcCosineOperation::executePixelSampled(float output[4],
   clampIfNeeded(output);
 }
 
+void MathArcCosineOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+  for (; !it.is_end(); ++it) {
+    float value1 = *it.in(0);
+    *it.out = (value1 <= 1 && value1 >= -1) ? acos(value1) : 0.0f;
+  }
+}
+
 void MathArcTangentOperation::executePixelSampled(float output[4],
                                                   float x,
                                                   float y,
@@ -293,6 +375,13 @@ void MathArcTangentOperation::executePixelSampled(float output[4],
   clampIfNeeded(output);
 }
 
+void MathArcTangentOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+  for (; !it.is_end(); ++it) {
+    *it.out = atan(*it.in(0));
+  }
+}
+
 void MathPowerOperation::executePixelSampled(float output[4],
                                              float x,
                                              float y,
@@ -321,6 +410,28 @@ void MathPowerOperation::executePixelSampled(float output[4],
   clampIfNeeded(output);
 }
 
+void MathPowerOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+  for (; !it.is_end(); ++it) {
+    const float value1 = *it.in(0);
+    const float value2 = *it.in(1);
+    if (value1 >= 0) {
+      *it.out = pow(value1, value2);
+    }
+    else {
+      const float y_mod_1 = fmod(value2, 1);
+      /* If input value is not nearly an integer, fall back to zero, nicer than straight rounding.
+       */
+      if (y_mod_1 > 0.999f || y_mod_1 < 0.001f) {
+        *it.out = pow(value1, floorf(value2 + 0.5f));
+      }
+      else {
+        *it.out = 0.0f;
+      }
+    }
+  }
+}
+
 void MathLogarithmOperation::executePixelSampled(float output[4],
                                                  float x,
                                                  float y,
@@ -342,6 +453,20 @@ void MathLogarithmOperation::executePixelSampled(float output[4],
   clampIfNeeded(output);
 }
 
+void MathLogarithmOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+  for (; !it.is_end(); ++it) {
+    const float value1 = *it.in(0);
+    const float value2 = *it.in(1);
+    if (value1 > 0 && value2 > 0) {
+      *it.out = log(value1) / log(value2);
+    }
+    else {
+      *it.out = 0.0;
+    }
+  }
+}
+
 void MathMinimumOperation::executePixelSampled(float output[4],
                                                float x,
                                                float y,
@@ -358,6 +483,13 @@ void MathMinimumOperation::executePixelSampled(float output[4],
   clampIfNeeded(output);
 }
 
+void MathMinimumOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+  for (; !it.is_end(); ++it) {
+    *it.out = MIN2(*it.in(0), *it.in(1));
+  }
+}
+
 void MathMaximumOperation::executePixelSampled(float output[4],
                                                float x,
                                                float y,
@@ -374,6 +506,13 @@ void MathMaximumOperation::executePixelSampled(float output[4],
   clampIfNeeded(output);
 }
 
+void MathMaximumOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+  for (; !it.is_end(); ++it) {
+    *it.out = MAX2(*it.in(0), *it.in(1));
+  }
+}
+
 void MathRoundOperation::executePixelSampled(float output[4],
                                              float x,
                                              float y,
@@ -390,6 +529,13 @@ void MathRoundOperation::executePixelSampled(float output[4],
   clampIfNeeded(output);
 }
 
+void MathRoundOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+  for (; !it.is_end(); ++it) {
+    *it.out = round(*it.in(0));
+  }
+}
+
 void MathLessThanOperation::executePixelSampled(float output[4],
                                                 float x,
                                                 float y,
@@ -443,6 +589,14 @@ void MathModuloOperation::executePixelSampled(float output[4],
   clampIfNeeded(output);
 }
 
+void MathModuloOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
+{
+  for (; !it.is_end(); ++it) {
+    const float value2 = *it.in(1);
+    *it.out = (value2 == 0) ? 0 : fmod(*it.in(0), value2);
+  }
+}
+
 void MathAbsoluteOperation::executePixelSampled(float output[4],
                                                 float x,
                                                 float y,
@@ -457,6 +611,13 @@ void MathAbsoluteOperation::executePixelSampled(float output[4],
   clampIfNeeded(output);
 }
 
+void MathAbsoluteOperation::update_memory_buffer_partial(Buff

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list