[Bf-blender-cvs] [e6d77587e33] compositor-anti-aliasing: Cleanup: Compositor anti-aliasing: rename and delete unused variables

Habib Gahbiche noreply at git.blender.org
Sun Mar 14 17:21:16 CET 2021


Commit: e6d77587e333f501ee153f57de5175130b6e817f
Author: Habib Gahbiche
Date:   Sun Mar 14 17:18:03 2021 +0100
Branches: compositor-anti-aliasing
https://developer.blender.org/rBe6d77587e333f501ee153f57de5175130b6e817f

Cleanup: Compositor anti-aliasing: rename and delete unused variables

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

M	source/blender/blenlib/intern/math_base_inline.c
M	source/blender/compositor/nodes/COM_AntiAliasingNode.cc
M	source/blender/compositor/operations/COM_SMAAOperation.cc
M	source/blender/compositor/operations/COM_SMAAOperation.h
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/composite/nodes/node_composite_antialiasing.c

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

diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c
index 39945960e68..553f67eac40 100644
--- a/source/blender/blenlib/intern/math_base_inline.c
+++ b/source/blender/blenlib/intern/math_base_inline.c
@@ -180,6 +180,13 @@ MINLINE double interpd(double target, double origin, double fac)
   return (fac * target) + (1.0f - fac) * origin;
 }
 
+/* Map a normalized value, i.e. from interval [0, 1] to interval [a, b]  */
+MINLINE float scalenorm(float a, float b, float x)
+{
+  BLI_assert(x <= 1 && x >= 0);
+  return (x * (b-a)) + a;
+}
+
 /* used for zoom values*/
 MINLINE float power_of_2(float val)
 {
diff --git a/source/blender/compositor/nodes/COM_AntiAliasingNode.cc b/source/blender/compositor/nodes/COM_AntiAliasingNode.cc
index 6fafc57a324..90d6543270c 100644
--- a/source/blender/compositor/nodes/COM_AntiAliasingNode.cc
+++ b/source/blender/compositor/nodes/COM_AntiAliasingNode.cc
@@ -30,45 +30,20 @@ void AntiAliasingNode::convertToOperations(NodeConverter &converter, const Compo
 	/* Edge Detection (First Pass) */
 	SMAAEdgeDetectionOperation *operation1 = NULL;
 
-	/*
-	switch (data->detect_type) {
-	case CMP_NODE_ANTIALIASING_LUMA:
-		operation1 = new SMAALumaEdgeDetectionOperation();
-		operation1->setThreshold(data->thresh);
-		operation1->setLocalContrastAdaptationFactor(data->adapt_fac);
-		break;
-	case CMP_NODE_ANTIALIASING_COLOR:
-		operation1 = new SMAAColorEdgeDetectionOperation();
-		operation1->setThreshold(data->thresh);
-		operation1->setLocalContrastAdaptationFactor(data->adapt_fac);
-		break;
-	case CMP_NODE_ANTIALIASING_VALUE:
-		operation1 = new SMAADepthEdgeDetectionOperation();
-		operation1->setThreshold(data->val_thresh);
-		break;
-	}
-	*/
-
 	operation1 = new SMAALumaEdgeDetectionOperation();
-	operation1->setThreshold(data->thresh);
-	operation1->setLocalContrastAdaptationFactor(data->adapt_fac);
+	operation1->setThreshold(data->threshold);
+	operation1->setLocalContrastAdaptationFactor(data->local_contrast_adaptation_factor);
 	converter.addOperation(operation1);
 
 	converter.mapInputSocket(getInputSocket(0), operation1->getInputSocket(0));
-	/* converter.mapInputSocket(getInputSocket(1), operation1->getInputSocket(1)); */
-	/* converter.mapOutputSocket(getOutputSocket(1), operation1->getOutputSocket()); */
 
 	/* Blending Weight Calculation Pixel Shader (Second Pass) */
 	SMAABlendingWeightCalculationOperation *operation2 = new SMAABlendingWeightCalculationOperation();
-	/* operation2->setEnableCornerDetection(data->corner); */
-	operation2->setCornerRounding(data->rounding);
+	operation2->setCornerRounding(data->corner_rounding);
 	converter.addOperation(operation2);
 
 	converter.addLink(operation1->getOutputSocket(), operation2->getInputSocket(0));
 
-	/* this may be needed for debugging */
-	// converter.mapOutputSocket(getOutputSocket(2), operation2->getOutputSocket());
-
 	/* Neighborhood Blending Pixel Shader (Third Pass) */
 	SMAANeighborhoodBlendingOperation *operation3 = new SMAANeighborhoodBlendingOperation();
 	converter.addOperation(operation3);
diff --git a/source/blender/compositor/operations/COM_SMAAOperation.cc b/source/blender/compositor/operations/COM_SMAAOperation.cc
index ef4e1862760..f0920158620 100644
--- a/source/blender/compositor/operations/COM_SMAAOperation.cc
+++ b/source/blender/compositor/operations/COM_SMAAOperation.cc
@@ -177,13 +177,14 @@ void SMAAEdgeDetectionOperation::deinitExecution()
 
 void SMAAEdgeDetectionOperation::setThreshold(float threshold)
 {
-	m_threshold = threshold * 0.5;
+	/* UI values are between 0 and 1 for simplicity but algorithm expects values between 0 and 0.5 */
+	m_threshold = scalenorm(0, 0.5, threshold);
 }
 
 void SMAAEdgeDetectionOperation::setLocalContrastAdaptationFactor(float factor)
 {
-	// todo (habib): replace with generic interval mapping function, e.g. from BLI_
-	m_local_contrast_adaptation_factor = (factor * 9) + 1;
+	/* UI values are between 0 and 1 for simplicity but algorithm expects values between 1 and 10 */
+	m_local_contrast_adaptation_factor = scalenorm(1, 10, factor);
 }
 
 bool SMAAEdgeDetectionOperation::determineDependingAreaOfInterest(rcti *input,
@@ -411,7 +412,8 @@ void SMAABlendingWeightCalculationOperation::initExecution()
 
 void SMAABlendingWeightCalculationOperation::setCornerRounding(float rounding)
 {
-	m_corner_rounding = static_cast<int>(rounding * 100);
+	/* UI values are between 0 and 1 for simplicity but algorithm expects values between 0 and 100 */
+	m_corner_rounding = static_cast<int>(scalenorm(0, 100, rounding));
 }
 
 void SMAABlendingWeightCalculationOperation::executePixel(float output[4], int x, int y, void */*data*/)
diff --git a/source/blender/compositor/operations/COM_SMAAOperation.h b/source/blender/compositor/operations/COM_SMAAOperation.h
index a48bbdef27c..33b4c655c0f 100644
--- a/source/blender/compositor/operations/COM_SMAAOperation.h
+++ b/source/blender/compositor/operations/COM_SMAAOperation.h
@@ -50,13 +50,8 @@ public:
 	 */
 	void deinitExecution();
 
-	/**
-	 * map from [0, 1] to [0, 0.5]
-	 */
 	void setThreshold(float threshold);
-	/**
-	 * map to [0, 1] to [1, 10]
-	 */
+
 	void setLocalContrastAdaptationFactor(float factor);
 
 	bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
@@ -105,9 +100,6 @@ public:
 	 */
 	void deinitExecution();
 
-	/**
-	 * Map from [0, 1] to [0, 100]
-	 */
 	void setCornerRounding(float rounding);
 
 	bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 4b4e3d1cf5d..22900970bee 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -715,13 +715,9 @@ typedef struct NodeBilateralBlurData {
 } NodeBilateralBlurData;
 
 typedef struct NodeAntiAliasingData {
-  float thresh;
-  float val_thresh;
-  float adapt_fac;
-  float rounding;
-  char detect_type;
-  char corner;
-  char _pad[2];
+  float threshold;
+  float local_contrast_adaptation_factor;
+  float corner_rounding;
 } NodeAntiAliasingData;
 
 /* NOTE: Only for do-version code. */
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index e09356162ef..0c30e0c2f48 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -8443,20 +8443,20 @@ static void def_cmp_antialiasing(StructRNA *srna)
 	RNA_def_struct_sdna_from(srna, "NodeAntiAliasingData", "storage");
 
 	prop = RNA_def_property(srna, "threshold", PROP_FLOAT, PROP_UNSIGNED);
-	RNA_def_property_float_sdna(prop, NULL, "thresh");
+	RNA_def_property_float_sdna(prop, NULL, "threshold");
 	RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.1, 3);
 	RNA_def_property_ui_text(prop, "Threshold", "Threshold to detect edges (smaller threshold makes more sensitive detection)");
 	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 
 	prop = RNA_def_property(srna, "local_contrast_adaptation_factor", PROP_FLOAT, PROP_UNSIGNED);
-	RNA_def_property_float_sdna(prop, NULL, "adapt_fac");
+	RNA_def_property_float_sdna(prop, NULL, "local_contrast_adaptation_factor");
 	RNA_def_property_range(prop, 0.0f, 1.0f);
 	RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.1, 3);
 	RNA_def_property_ui_text(prop, "Local Contrast Adaptation Factor", "How much to eliminate spurious edges to avoid artifacts (the larger value makes less active; the value 2.0, for example, means discard a detected edge if there is a neighboring edge that has 2.0 times bigger contrast than the current one)");
 	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 
 	prop = RNA_def_property(srna, "corner_rounding", PROP_FLOAT, PROP_UNSIGNED);
-	RNA_def_property_float_sdna(prop, NULL, "rounding");
+	RNA_def_property_float_sdna(prop, NULL, "corner_rounding");
   RNA_def_property_range(prop, 0.0f, 1.0f);
 	RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.1, 3);
 	RNA_def_property_ui_text(prop, "Corner Rounding", "How much sharp corners will be rounded");
diff --git a/source/blender/nodes/composite/nodes/node_composite_antialiasing.c b/source/blender/nodes/composite/nodes/node_composite_antialiasing.c
index 557a1d78fa3..999bca911db 100644
--- a/source/blender/nodes/composite/nodes/node_composite_antialiasing.c
+++ b/source/blender/nodes/composite/nodes/node_composite_antialiasing.c
@@ -35,25 +35,19 @@
 
 static bNodeSocketTemplate cmp_node_antialiasing_in[] = {
     {SOCK_RGBA, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f},
-    /* {SOCK_FLOAT, N_("Value"), 1.0f, 1.0f, 1.0f, 1.0f}, */
     {-1, ""}};
 
 static bNodeSocketTemplate cmp_node_antialiasing_out[] = {
     {SOCK_RGBA, N_("Image")},
-    //{SOCK_RGBA, N_("Edges")},
-    /* {   SOCK_RGBA, N_("Blending Weights")}, */
     {-1, ""}};
 
 static void node_composit_init_antialiasing(bNodeTree *UNUSED(ntree), bNode *node)
 {
   NodeAntiAliasingData *data = MEM_callocN(sizeof(NodeAntiAliasingData), "node antialiasing data");
 
-  data->detect_type = CMP_NODE_ANTIALIASING_COLOR;
-  data->thresh = 1;// 0.5f;
-  data->val_thresh = 0.1f;
-  data->adapt_fac = 0.2; // 2.0f;
-  data->corner = true;
-  data->rounding = 0.25; // 25;
+  data->threshold = 1;
+  data->local_contrast_adaptation_factor = 0.2;
+  data->corner_rounding = 0.25;
 
   node->storage = data;
 }



More information about the Bf-blender-cvs mailing list