[Bf-blender-cvs] [b928f588495] temp_bmesh_multires: Made vcol boundary tool avoid perfectly degenerate triangles.

Joseph Eagar noreply at git.blender.org
Fri Nov 6 10:36:18 CET 2020


Commit: b928f588495275f53c5f66ae63f50dd50f1174bf
Author: Joseph Eagar
Date:   Fri Nov 6 01:35:52 2020 -0800
Branches: temp_bmesh_multires
https://developer.blender.org/rBb928f588495275f53c5f66ae63f50dd50f1174bf

Made vcol boundary tool avoid perfectly degenerate triangles.

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

M	source/blender/editors/sculpt_paint/sculpt_smooth.c

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

diff --git a/source/blender/editors/sculpt_paint/sculpt_smooth.c b/source/blender/editors/sculpt_paint/sculpt_smooth.c
index 10186dceac5..030e01079e1 100644
--- a/source/blender/editors/sculpt_paint/sculpt_smooth.c
+++ b/source/blender/editors/sculpt_paint/sculpt_smooth.c
@@ -746,38 +746,82 @@ static void do_smooth_vcol_boundary_brush_task_cb_ex(void *__restrict userdata,
         continue;
       }
 
-      float avg2[3], val[3];
-      float tot2 = 0.0f;
-
-      zero_v3(avg2);
+      float avg2[3], avg3[3], val[3];
+      float tot2 = 0.0f, tot4 = 0.0f;
 
       copy_v4_v4(avg, vd.col);
 
+      zero_v3(avg2);
+      zero_v3(avg3);
+
       madd_v3_v3fl(avg2, vd.co, 0.5f);
       tot2 += 0.5f;
 
+#ifdef SHARPEN_VCOL_BOUNDARY
+      float ntot = 0.0f;
+      float colavg[4], tot3 = 0.0f;
+      zero_v4(colavg);
+#endif
+
       SculptVertexNeighborIter ni;
       SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, vd.vertex, ni) {
         const float *col = SCULPT_vertex_color_get(ss, ni.vertex);
         const float *co = SCULPT_vertex_co_get(ss, ni.vertex);
 
-        // simple color metric
+        // simple color metric.  TODO: plug in appropriate color space code?
         float dv[4];
         sub_v4_v4v4(dv, col, avg);
         float w = (fabs(dv[0]) + fabs(dv[1]) + fabs(dv[2]) + fabs(dv[3])) / 4.0;
 
         w *= w;
 
+#ifdef SHARPEN_VCOL_BOUNDARY
+        float w2 = -1.0f;
+        madd_v4_v4fl(colavg, col, w2);
+        tot3 += w2;
+        ntot += 1.0f;
+#endif
+
+        madd_v3_v3fl(avg3, co, 1.0f);
+        tot4 += 1.0f;
+
         madd_v3_v3fl(avg2, co, w);
         tot2 += w;
       }
       SCULPT_VERTEX_NEIGHBORS_ITER_END(ni);
 
-      if (tot2 == 0.0) {
+      if (tot2 == 0.0f) {
         continue;
       }
 
-      mul_v3_fl(avg2, 1.0 / tot2);
+      if (tot4 > 0.0f) {
+        mul_v3_fl(avg3, 1.0f / tot4);
+      }
+
+#ifdef SHARPEN_VCOL_BOUNDARY
+      float w2 = ntot*40.0f;
+      madd_v4_v4fl(colavg, vd.col, w2);
+      tot3 += w2;
+
+      if (tot3 > 0.0f) {
+        mul_v4_fl(colavg, 1.0f / tot3);
+      }
+
+      //clamp_v4(colavg, 0.0f, 1.0f);
+      //negative numbers are undesirable, but dunno if I should clip above 1.0 or not except for alpha
+      for (int i=0; i<4; i++) {
+        colavg[i] = MAX2(colavg[i], 0.0f);
+        colavg[i] = MIN2(colavg[i], 1.0f);
+      }
+      //colavg[3] = MIN2(colavg[3], 1.0f);
+
+      interp_v4_v4v4(vd.col, vd.col, colavg, fade*0.01);
+#endif
+
+      //try to avoid perfectly colinear triangles, and the normal discontinuities they create,
+      //by blending slightly with unweighted smoothed position
+      mul_v3_fl(avg2, 1.0f / tot2);
+      interp_v3_v3v3(avg2, avg2, avg3, 0.01);
 
       sub_v3_v3v3(val, avg2, vd.co);
       madd_v3_v3v3fl(val, vd.co, val, fade);



More information about the Bf-blender-cvs mailing list