Commit: d270a43984c568ea7f7e7dc860bb69b4aadd6e74
Author: Habib Gahbiche
Date:   Sun Feb 28 12:20:46 2021 +0100
Branches: compositor-anti-aliasing
https://developer.blender.org/rBd270a43984c568ea7f7e7dc860bb69b4aadd6e74

Compositor anti-aliasing: map values between 0 and 1

expose values in ranges between 0 and 1 to user

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

M       source/blender/compositor/CMakeLists.txt
R100    source/blender/compositor/nodes/COM_AntiAliasingNode.cpp        
source/blender/compositor/nodes/COM_AntiAliasingNode.cc
R097    source/blender/compositor/operations/COM_SMAAOperation.cpp      
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/compositor/CMakeLists.txt 
b/source/blender/compositor/CMakeLists.txt
index c007accee77..f3f0e351b76 100644
--- a/source/blender/compositor/CMakeLists.txt
+++ b/source/blender/compositor/CMakeLists.txt
@@ -298,8 +298,8 @@ set(SRC
   nodes/COM_InpaintNode.h
   nodes/COM_AntiAliasingNode.cc
   nodes/COM_AntiAliasingNode.h
-  
-  operations/COM_BlurBaseOperation.cpp
+
+  operations/COM_BlurBaseOperation.cc
   operations/COM_BlurBaseOperation.h
   operations/COM_BokehBlurOperation.cc
   operations/COM_BokehBlurOperation.h
@@ -327,7 +327,7 @@ set(SRC
   operations/COM_VariableSizeBokehBlurOperation.h
   operations/COM_SMAAOperation.cc
   operations/COM_SMAAOperation.h
-  
+
   # Matte nodes
   nodes/COM_BoxMaskNode.cc
   nodes/COM_BoxMaskNode.h
diff --git a/source/blender/compositor/nodes/COM_AntiAliasingNode.cpp 
b/source/blender/compositor/nodes/COM_AntiAliasingNode.cc
similarity index 100%
rename from source/blender/compositor/nodes/COM_AntiAliasingNode.cpp
rename to source/blender/compositor/nodes/COM_AntiAliasingNode.cc
diff --git a/source/blender/compositor/operations/COM_SMAAOperation.cpp 
b/source/blender/compositor/operations/COM_SMAAOperation.cc
similarity index 97%
rename from source/blender/compositor/operations/COM_SMAAOperation.cpp
rename to source/blender/compositor/operations/COM_SMAAOperation.cc
index 9005c49bfe2..ef4e1862760 100644
--- a/source/blender/compositor/operations/COM_SMAAOperation.cpp
+++ b/source/blender/compositor/operations/COM_SMAAOperation.cc
@@ -175,6 +175,17 @@ void SMAAEdgeDetectionOperation::deinitExecution()
        this->m_valueReader = NULL;
 }
 
+void SMAAEdgeDetectionOperation::setThreshold(float threshold)
+{
+       m_threshold = threshold * 0.5;
+}
+
+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;
+}
+
 bool SMAAEdgeDetectionOperation::determineDependingAreaOfInterest(rcti *input,
                                                                  
ReadBufferOperation *readOperation, rcti *output)
 {
@@ -398,6 +409,11 @@ void 
SMAABlendingWeightCalculationOperation::initExecution()
        this->m_imageReader = this->getInputSocketReader(0);
 }
 
+void SMAABlendingWeightCalculationOperation::setCornerRounding(float rounding)
+{
+       m_corner_rounding = static_cast<int>(rounding * 100);
+}
+
 void SMAABlendingWeightCalculationOperation::executePixel(float output[4], int 
x, int y, void */*data*/)
 {
        float edges[4], c[4];
@@ -490,13 +506,13 @@ bool 
SMAABlendingWeightCalculationOperation::determineDependingAreaOfInterest(rc
 {
        rcti newInput;
 
-       newInput.xmax = input->xmax + max(SMAA_MAX_SEARCH_STEPS,
+       newInput.xmax = input->xmax + fmax(SMAA_MAX_SEARCH_STEPS,
                                          SMAA_MAX_SEARCH_STEPS_DIAG + 1);
-       newInput.xmin = input->xmin - max(max(SMAA_MAX_SEARCH_STEPS - 1, 1),
+       newInput.xmin = input->xmin - fmax(fmax(SMAA_MAX_SEARCH_STEPS - 1, 1),
                                          SMAA_MAX_SEARCH_STEPS_DIAG + 1);
-       newInput.ymax = input->ymax + max(SMAA_MAX_SEARCH_STEPS,
+       newInput.ymax = input->ymax + fmax(SMAA_MAX_SEARCH_STEPS,
                                          SMAA_MAX_SEARCH_STEPS_DIAG);
-       newInput.ymin = input->ymin - max(max(SMAA_MAX_SEARCH_STEPS - 1, 1),
+       newInput.ymin = input->ymin - fmax(fmax(SMAA_MAX_SEARCH_STEPS - 1, 1),
                                          SMAA_MAX_SEARCH_STEPS_DIAG);
 
        return NodeOperation::determineDependingAreaOfInterest(&newInput, 
readOperation, output);
diff --git a/source/blender/compositor/operations/COM_SMAAOperation.h 
b/source/blender/compositor/operations/COM_SMAAOperation.h
index d8468bdeca3..a48bbdef27c 100644
--- a/source/blender/compositor/operations/COM_SMAAOperation.h
+++ b/source/blender/compositor/operations/COM_SMAAOperation.h
@@ -50,8 +50,14 @@ public:
         */
        void deinitExecution();
 
-       void setThreshold(float threshold) { m_threshold = threshold; }
-       void setLocalContrastAdaptationFactor(float factor) { 
m_local_contrast_adaptation_factor = factor; }
+       /**
+        * 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);
 };
@@ -99,7 +105,10 @@ public:
         */
        void deinitExecution();
 
-       void setCornerRounding(int rounding) { m_corner_rounding = rounding; }
+       /**
+        * Map from [0, 1] to [0, 100]
+        */
+       void setCornerRounding(float rounding);
 
        bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation 
*readOperation, rcti *output);
 private:
diff --git a/source/blender/makesdna/DNA_node_types.h 
b/source/blender/makesdna/DNA_node_types.h
index a0ba2d4d6e7..4b4e3d1cf5d 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -718,9 +718,10 @@ typedef struct NodeAntiAliasingData {
   float thresh;
   float val_thresh;
   float adapt_fac;
-  short rounding;
+  float rounding;
   char detect_type;
   char corner;
+  char _pad[2];
 } 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 979e356fe87..e09356162ef 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -8444,20 +8444,21 @@ static void def_cmp_antialiasing(StructRNA *srna)
 
        prop = RNA_def_property(srna, "threshold", PROP_FLOAT, PROP_UNSIGNED);
        RNA_def_property_float_sdna(prop, NULL, "thresh");
-       RNA_def_property_ui_range(prop, 0.0f, 0.5f, 1.0, 3);
+       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_range(prop, 1.0f, FLT_MAX);
-       RNA_def_property_ui_range(prop, 1.0f, 10.0f, 1.0, 3);
+       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_INT, 
PROP_UNSIGNED);
-       RNA_def_property_int_sdna(prop, NULL, "rounding");
-       RNA_def_property_range(prop, 0, 100);
+       prop = RNA_def_property(srna, "corner_rounding", PROP_FLOAT, 
PROP_UNSIGNED);
+       RNA_def_property_float_sdna(prop, NULL, "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");
        RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
diff --git a/source/blender/nodes/composite/nodes/node_composite_antialiasing.c 
b/source/blender/nodes/composite/nodes/node_composite_antialiasing.c
index 372a6f3fc06..557a1d78fa3 100644
--- a/source/blender/nodes/composite/nodes/node_composite_antialiasing.c
+++ b/source/blender/nodes/composite/nodes/node_composite_antialiasing.c
@@ -49,11 +49,11 @@ static void node_composit_init_antialiasing(bNodeTree 
*UNUSED(ntree), bNode *nod
   NodeAntiAliasingData *data = MEM_callocN(sizeof(NodeAntiAliasingData), "node 
antialiasing data");
 
   data->detect_type = CMP_NODE_ANTIALIASING_COLOR;
-  data->thresh = 0.5f;
+  data->thresh = 1;// 0.5f;
   data->val_thresh = 0.1f;
-  data->adapt_fac = 2.0f;
+  data->adapt_fac = 0.2; // 2.0f;
   data->corner = true;
-  data->rounding = 25;
+  data->rounding = 0.25; // 25;
 
   node->storage = data;
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to