[Bf-blender-cvs] [98c4224ff03] master: Fix T49944: Compositor ID Mask Anti-Aliasing not working

Aidan Haile noreply at git.blender.org
Thu Jul 15 22:25:32 CEST 2021


Commit: 98c4224ff032a746a54cc04b6d9a485620de0f4a
Author: Aidan Haile
Date:   Thu Jul 15 22:15:47 2021 +0200
Branches: master
https://developer.blender.org/rB98c4224ff032a746a54cc04b6d9a485620de0f4a

Fix T49944: Compositor ID Mask Anti-Aliasing not working

Replaces current ID Mask node Anti-Aliasing operation by SMAA
operations with default settings as proposed by Jeroen Bakker.
SMAA produces smoother edges.

Reviewed By: manzanilla

Differential Revision: https://developer.blender.org/D11881

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

M	source/blender/blenkernel/BKE_node.h
M	source/blender/compositor/nodes/COM_IDMaskNode.cc
M	source/blender/compositor/operations/COM_SMAAOperation.cc
M	source/blender/nodes/composite/nodes/node_composite_antialiasing.c

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

diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index b1a38ec5700..63b11a194ff 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1274,6 +1274,11 @@ void ntreeGPUMaterialNodes(struct bNodeTree *localtree,
 #define CMP_CRYPTOMATTE_SRC_RENDER 0
 #define CMP_CRYPTOMATTE_SRC_IMAGE 1
 
+/* Default SMAA configuration values. */
+#define CMP_DEFAULT_SMAA_THRESHOLD 1.0f
+#define CMP_DEFAULT_SMAA_CONTRAST_LIMIT 0.2f
+#define CMP_DEFAULT_SMAA_CORNER_ROUNDING 0.25f
+
 /* API */
 void ntreeCompositExecTree(struct Scene *scene,
                            struct bNodeTree *ntree,
diff --git a/source/blender/compositor/nodes/COM_IDMaskNode.cc b/source/blender/compositor/nodes/COM_IDMaskNode.cc
index 9798dabd035..b51e79f2dea 100644
--- a/source/blender/compositor/nodes/COM_IDMaskNode.cc
+++ b/source/blender/compositor/nodes/COM_IDMaskNode.cc
@@ -17,9 +17,9 @@
  */
 
 #include "COM_IDMaskNode.h"
-#include "COM_AntiAliasOperation.h"
 #include "COM_ExecutionSystem.h"
 #include "COM_IDMaskOperation.h"
+#include "COM_SMAAOperation.h"
 
 namespace blender::compositor {
 
@@ -42,11 +42,27 @@ void IDMaskNode::convertToOperations(NodeConverter &converter,
     converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket(0));
   }
   else {
-    AntiAliasOperation *antiAliasOperation = new AntiAliasOperation();
-    converter.addOperation(antiAliasOperation);
+    SMAAEdgeDetectionOperation *operation1 = nullptr;
 
-    converter.addLink(operation->getOutputSocket(), antiAliasOperation->getInputSocket(0));
-    converter.mapOutputSocket(getOutputSocket(0), antiAliasOperation->getOutputSocket(0));
+    operation1 = new SMAAEdgeDetectionOperation();
+    converter.addOperation(operation1);
+
+    converter.addLink(operation->getOutputSocket(0), operation1->getInputSocket(0));
+
+    /* Blending Weight Calculation Pixel Shader (Second Pass). */
+    SMAABlendingWeightCalculationOperation *operation2 =
+        new SMAABlendingWeightCalculationOperation();
+    converter.addOperation(operation2);
+
+    converter.addLink(operation1->getOutputSocket(), operation2->getInputSocket(0));
+
+    /* Neighborhood Blending Pixel Shader (Third Pass). */
+    SMAANeighborhoodBlendingOperation *operation3 = new SMAANeighborhoodBlendingOperation();
+    converter.addOperation(operation3);
+
+    converter.addLink(operation->getOutputSocket(0), operation3->getInputSocket(0));
+    converter.addLink(operation2->getOutputSocket(), operation3->getInputSocket(1));
+    converter.mapOutputSocket(getOutputSocket(0), operation3->getOutputSocket());
   }
 }
 
diff --git a/source/blender/compositor/operations/COM_SMAAOperation.cc b/source/blender/compositor/operations/COM_SMAAOperation.cc
index c3647a39909..3c753591ced 100644
--- a/source/blender/compositor/operations/COM_SMAAOperation.cc
+++ b/source/blender/compositor/operations/COM_SMAAOperation.cc
@@ -21,6 +21,7 @@
 #include "COM_SMAAOperation.h"
 #include "BLI_math.h"
 #include "COM_SMAAAreaTexture.h"
+#include "BKE_node.h"
 
 extern "C" {
 #include "IMB_colormanagement.h"
@@ -166,8 +167,8 @@ SMAAEdgeDetectionOperation::SMAAEdgeDetectionOperation()
   this->flags.complex = true;
   this->m_imageReader = nullptr;
   this->m_valueReader = nullptr;
-  this->m_threshold = 0.1f;
-  this->m_contrast_limit = 2.0f;
+  this->setThreshold(CMP_DEFAULT_SMAA_THRESHOLD);
+  this->setLocalContrastAdaptationFactor(CMP_DEFAULT_SMAA_CONTRAST_LIMIT);
 }
 
 void SMAAEdgeDetectionOperation::initExecution()
@@ -297,7 +298,7 @@ SMAABlendingWeightCalculationOperation::SMAABlendingWeightCalculationOperation()
   this->addOutputSocket(DataType::Color);
   this->flags.complex = true;
   this->m_imageReader = nullptr;
-  this->m_corner_rounding = 25;
+  this->setCornerRounding(CMP_DEFAULT_SMAA_CORNER_ROUNDING);
 }
 
 void *SMAABlendingWeightCalculationOperation::initializeTileData(rcti *rect)
diff --git a/source/blender/nodes/composite/nodes/node_composite_antialiasing.c b/source/blender/nodes/composite/nodes/node_composite_antialiasing.c
index 7437496d878..fa276e9a794 100644
--- a/source/blender/nodes/composite/nodes/node_composite_antialiasing.c
+++ b/source/blender/nodes/composite/nodes/node_composite_antialiasing.c
@@ -42,9 +42,9 @@ static void node_composit_init_antialiasing(bNodeTree *UNUSED(ntree), bNode *nod
 {
   NodeAntiAliasingData *data = MEM_callocN(sizeof(NodeAntiAliasingData), "node antialiasing data");
 
-  data->threshold = 1.0f;
-  data->contrast_limit = 0.2f;
-  data->corner_rounding = 0.25f;
+  data->threshold = CMP_DEFAULT_SMAA_THRESHOLD;
+  data->contrast_limit = CMP_DEFAULT_SMAA_CONTRAST_LIMIT;
+  data->corner_rounding = CMP_DEFAULT_SMAA_CORNER_ROUNDING;
 
   node->storage = data;
 }



More information about the Bf-blender-cvs mailing list