[Bf-blender-cvs] [bf725bbb92d] compositor-full-frame: Compositor: Full frame Glare node

Manuel Castilla noreply at git.blender.org
Thu Aug 12 22:35:58 CEST 2021


Commit: bf725bbb92df7be5729c1ece92a2ca2c8415a9bb
Author: Manuel Castilla
Date:   Thu Aug 12 22:00:09 2021 +0200
Branches: compositor-full-frame
https://developer.blender.org/rBbf725bbb92df7be5729c1ece92a2ca2c8415a9bb

Compositor: Full frame Glare node

Due to current limitation of scaling up causing cropping,
quality is always "High" independently of the selected
one. This will be fixed once scaling is implemented with
canvas adjustment.

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

M	source/blender/compositor/operations/COM_GlareBaseOperation.cc
M	source/blender/compositor/operations/COM_GlareBaseOperation.h
M	source/blender/compositor/operations/COM_GlareThresholdOperation.cc
M	source/blender/compositor/operations/COM_GlareThresholdOperation.h

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

diff --git a/source/blender/compositor/operations/COM_GlareBaseOperation.cc b/source/blender/compositor/operations/COM_GlareBaseOperation.cc
index 90755d9f27a..b151663f278 100644
--- a/source/blender/compositor/operations/COM_GlareBaseOperation.cc
+++ b/source/blender/compositor/operations/COM_GlareBaseOperation.cc
@@ -26,6 +26,8 @@ GlareBaseOperation::GlareBaseOperation()
   this->addInputSocket(DataType::Color);
   this->addOutputSocket(DataType::Color);
   this->m_settings = nullptr;
+  flags.is_fullframe_operation = true;
+  is_output_rendered_ = false;
 }
 void GlareBaseOperation::initExecution()
 {
@@ -69,4 +71,38 @@ bool GlareBaseOperation::determineDependingAreaOfInterest(rcti * /*input*/,
   return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
 }
 
+void GlareBaseOperation::get_area_of_interest(const int input_idx,
+                                              const rcti &UNUSED(output_area),
+                                              rcti &r_input_area)
+{
+  BLI_assert(input_idx == 0);
+  UNUSED_VARS_NDEBUG(input_idx);
+  r_input_area.xmin = 0;
+  r_input_area.xmax = this->getWidth();
+  r_input_area.ymin = 0;
+  r_input_area.ymax = this->getHeight();
+}
+
+void GlareBaseOperation::update_memory_buffer(MemoryBuffer *output,
+                                              const rcti &UNUSED(area),
+                                              Span<MemoryBuffer *> inputs)
+{
+  /* TODO(manzanilla): once tiled implmentation is removed, make inheriting operations
+   * multi-threaded with support for single elem buffers if possible. */
+  if (!is_output_rendered_) {
+    MemoryBuffer *input = inputs[0];
+    const bool is_input_inflated = input->is_a_single_elem();
+    if (is_input_inflated) {
+      input = input->inflate();
+    }
+
+    this->generateGlare(output->getBuffer(), input, m_settings);
+    is_output_rendered_ = true;
+
+    if (is_input_inflated) {
+      delete input;
+    }
+  }
+}
+
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_GlareBaseOperation.h b/source/blender/compositor/operations/COM_GlareBaseOperation.h
index 6dac6f5ecc7..5ca240a9e66 100644
--- a/source/blender/compositor/operations/COM_GlareBaseOperation.h
+++ b/source/blender/compositor/operations/COM_GlareBaseOperation.h
@@ -49,6 +49,8 @@ class GlareBaseOperation : public SingleThreadedOperation {
    */
   NodeGlare *m_settings;
 
+  bool is_output_rendered_;
+
  public:
   /**
    * Initialize the execution
@@ -68,6 +70,14 @@ class GlareBaseOperation : public SingleThreadedOperation {
                                         ReadBufferOperation *readOperation,
                                         rcti *output) override;
 
+  void get_area_of_interest(const int input_idx,
+                            const rcti &output_area,
+                            rcti &r_input_area) final;
+
+  void update_memory_buffer(MemoryBuffer *output,
+                            const rcti &area,
+                            Span<MemoryBuffer *> inputs) final;
+
  protected:
   GlareBaseOperation();
 
diff --git a/source/blender/compositor/operations/COM_GlareThresholdOperation.cc b/source/blender/compositor/operations/COM_GlareThresholdOperation.cc
index 1d3402f5b7b..becf6c586ac 100644
--- a/source/blender/compositor/operations/COM_GlareThresholdOperation.cc
+++ b/source/blender/compositor/operations/COM_GlareThresholdOperation.cc
@@ -34,8 +34,18 @@ void GlareThresholdOperation::determineResolution(unsigned int resolution[2],
                                                   unsigned int preferredResolution[2])
 {
   NodeOperation::determineResolution(resolution, preferredResolution);
-  resolution[0] = resolution[0] / (1 << this->m_settings->quality);
-  resolution[1] = resolution[1] / (1 << this->m_settings->quality);
+  switch (execution_model_) {
+    case eExecutionModel::Tiled:
+      resolution[0] = resolution[0] / (1 << this->m_settings->quality);
+      resolution[1] = resolution[1] / (1 << this->m_settings->quality);
+      break;
+    case eExecutionModel::FullFrame:
+      /* TODO(manzanilla): Currently scaling up always crop so it's not possible to use a lower
+       * resolution for lower quality to later scale up. Once scaling supports adapting canvas, use
+       * same implementation as #eExecutionModel::Tiled. This makes glare node to be always high
+       * quality. */
+      break;
+  }
 }
 
 void GlareThresholdOperation::initExecution()
@@ -70,4 +80,24 @@ void GlareThresholdOperation::deinitExecution()
   this->m_inputProgram = nullptr;
 }
 
+void GlareThresholdOperation::update_memory_buffer_partial(MemoryBuffer *output,
+                                                           const rcti &area,
+                                                           Span<MemoryBuffer *> inputs)
+{
+  const float threshold = this->m_settings->threshold;
+  for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {
+    const float *color = it.in(0);
+    if (IMB_colormanagement_get_luminance(color) >= threshold) {
+      it.out[0] = color[0] - threshold;
+      it.out[1] = color[1] - threshold;
+      it.out[2] = color[2] - threshold;
+
+      CLAMP3_MIN(it.out, 0.0f);
+    }
+    else {
+      zero_v3(it.out);
+    }
+  }
+}
+
 }  // namespace blender::compositor
diff --git a/source/blender/compositor/operations/COM_GlareThresholdOperation.h b/source/blender/compositor/operations/COM_GlareThresholdOperation.h
index a6e971dada7..3c7101814ec 100644
--- a/source/blender/compositor/operations/COM_GlareThresholdOperation.h
+++ b/source/blender/compositor/operations/COM_GlareThresholdOperation.h
@@ -18,12 +18,12 @@
 
 #pragma once
 
-#include "COM_NodeOperation.h"
+#include "COM_MultiThreadedOperation.h"
 #include "DNA_light_types.h"
 
 namespace blender::compositor {
 
-class GlareThresholdOperation : public NodeOperation {
+class GlareThresholdOperation : public MultiThreadedOperation {
  private:
   /**
    * \brief Cached reference to the inputProgram
@@ -60,6 +60,10 @@ class GlareThresholdOperation : public NodeOperation {
 
   void determineResolution(unsigned int resolution[2],
                            unsigned int preferredResolution[2]) override;
+
+  void update_memory_buffer_partial(MemoryBuffer *output,
+                                    const rcti &area,
+                                    Span<MemoryBuffer *> inputs) override;
 };
 
 }  // namespace blender::compositor



More information about the Bf-blender-cvs mailing list