[Bf-blender-cvs] [91af828e8bf] master: Fix T81743: Changed behaviour in RGB Curves node interpolation

Sybren A. Stüvel noreply at git.blender.org
Thu Oct 15 19:48:22 CEST 2020


Commit: 91af828e8bfaa04cbd49f1859e06a1f76749102d
Author: Sybren A. Stüvel
Date:   Thu Oct 15 19:38:20 2020 +0200
Branches: master
https://developer.blender.org/rB91af828e8bfaa04cbd49f1859e06a1f76749102d

Fix T81743: Changed behaviour in RGB Curves node interpolation

Restore the old `correct_bezpart()` (pre-rBda95d1d851b4) function as
`BKE_curve_correct_bezpart()`, and use that where the old behaviour was
desired (that is, curve maps like used by the RGB Curves shader node).

The new (post-rBda95d1d851b4) function is also renamed to
`BKE_fcurve_correct_bezpart()` to avoid confusion.

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

M	source/blender/blenkernel/BKE_curve.h
M	source/blender/blenkernel/BKE_fcurve.h
M	source/blender/blenkernel/intern/colortools.c
M	source/blender/blenkernel/intern/curve.c
M	source/blender/blenkernel/intern/fcurve.c
M	source/blender/editors/animation/anim_draw.c
M	source/blender/editors/space_graph/graph_draw.c

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

diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h
index d9138db2769..dcb4a993da1 100644
--- a/source/blender/blenkernel/BKE_curve.h
+++ b/source/blender/blenkernel/BKE_curve.h
@@ -158,6 +158,8 @@ void BKE_curve_rect_from_textbox(const struct Curve *cu,
                                  const struct TextBox *tb,
                                  struct rctf *r_rect);
 
+void BKE_curve_correct_bezpart(const float v1[2], float v2[2], float v3[2], const float v4[2]);
+
 /* ** Nurbs ** */
 
 bool BKE_nurbList_index_get_co(struct ListBase *editnurb, const int index, float r_co[3]);
diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h
index e0c0f91b34b..c9bc5e83a1f 100644
--- a/source/blender/blenkernel/BKE_fcurve.h
+++ b/source/blender/blenkernel/BKE_fcurve.h
@@ -285,7 +285,7 @@ void testhandles_fcurve(struct FCurve *fcu, eBezTriple_Flag sel_flag, const bool
 void sort_time_fcurve(struct FCurve *fcu);
 bool test_time_fcurve(struct FCurve *fcu);
 
-void correct_bezpart(const float v1[2], float v2[2], float v3[2], const float v4[2]);
+void BKE_fcurve_correct_bezpart(const float v1[2], float v2[2], float v3[2], const float v4[2]);
 
 /* -------- Evaluation --------  */
 
diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c
index 77a29bf41b8..34e8e8bc6fb 100644
--- a/source/blender/blenkernel/intern/colortools.c
+++ b/source/blender/blenkernel/intern/colortools.c
@@ -715,7 +715,8 @@ static void curvemap_make_table(const CurveMapping *cumap, CurveMap *cuma)
   float *point = allpoints;
 
   for (int a = 0; a < cuma->totpoint - 1; a++, point += 2 * CM_RESOL) {
-    correct_bezpart(bezt[a].vec[1], bezt[a].vec[2], bezt[a + 1].vec[0], bezt[a + 1].vec[1]);
+    BKE_curve_correct_bezpart(
+        bezt[a].vec[1], bezt[a].vec[2], bezt[a + 1].vec[0], bezt[a + 1].vec[1]);
     BKE_curve_forward_diff_bezier(bezt[a].vec[1][0],
                                   bezt[a].vec[2][0],
                                   bezt[a + 1].vec[0][0],
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index c0da1f41c88..01636c7eb2b 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -5566,6 +5566,47 @@ void BKE_curve_rect_from_textbox(const struct Curve *cu,
   r_rect->ymin = r_rect->ymax - tb->h;
 }
 
+/* This function is almost the same as BKE_fcurve_correct_bezpart(), but doesn't allow as large a
+ * tangent. */
+void BKE_curve_correct_bezpart(const float v1[2], float v2[2], float v3[2], const float v4[2])
+{
+  float h1[2], h2[2], len1, len2, len, fac;
+
+  /* Calculate handle deltas. */
+  h1[0] = v1[0] - v2[0];
+  h1[1] = v1[1] - v2[1];
+
+  h2[0] = v4[0] - v3[0];
+  h2[1] = v4[1] - v3[1];
+
+  /* Calculate distances:
+   * - len  = span of time between keyframes
+   * - len1 = length of handle of start key
+   * - len2 = length of handle of end key
+   */
+  len = v4[0] - v1[0];
+  len1 = fabsf(h1[0]);
+  len2 = fabsf(h2[0]);
+
+  /* If the handles have no length, no need to do any corrections. */
+  if ((len1 + len2) == 0.0f) {
+    return;
+  }
+
+  /* the two handles cross over each other, so force them
+   * apart using the proportion they overlap
+   */
+  if ((len1 + len2) > len) {
+    fac = len / (len1 + len2);
+
+    v2[0] = (v1[0] - fac * h1[0]);
+    v2[1] = (v1[1] - fac * h1[1]);
+
+    v3[0] = (v4[0] - fac * h2[0]);
+    v3[1] = (v4[1] - fac * h2[1]);
+  }
+}
+
 /* **** Depsgraph evaluation **** */
 
 void BKE_curve_eval_geometry(Depsgraph *depsgraph, Curve *curve)
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index 18e6479ea07..2287170c29d 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -1355,8 +1355,11 @@ bool test_time_fcurve(FCurve *fcu)
 /* The length of each handle is not allowed to be more
  * than the horizontal distance between (v1-v4).
  * This is to prevent curve loops.
+ *
+ * This function is very similar to BKE_curve_correct_bezpart(), but allows a steeper tangent for
+ * more snappy animations. This is not desired for other areas in which curves are used, though.
  */
-void correct_bezpart(const float v1[2], float v2[2], float v3[2], const float v4[2])
+void BKE_fcurve_correct_bezpart(const float v1[2], float v2[2], float v3[2], const float v4[2])
 {
   float h1[2], h2[2], len1, len2, len, fac;
 
@@ -1566,7 +1569,7 @@ bool BKE_fcurve_bezt_subdivide_handles(struct BezTriple *bezt,
   }
 
   /* Apply evaluation-time limits and compute the effective curve. */
-  correct_bezpart(prev_coords, prev_handle_right, next_handle_left, next_coords);
+  BKE_fcurve_correct_bezpart(prev_coords, prev_handle_right, next_handle_left, next_coords);
   float roots[4];
   if (!findzero(new_coords[0],
                 prev_coords[0],
@@ -1750,7 +1753,7 @@ static float fcurve_eval_keyframes_interpolate(FCurve *fcu, BezTriple *bezts, fl
         return v1[1];
       }
       /* adjust handles so that they don't overlap (forming a loop) */
-      correct_bezpart(v1, v2, v3, v4);
+      BKE_fcurve_correct_bezpart(v1, v2, v3, v4);
 
       /* try to get a value for this position - if failure, try another set of points */
       if (!findzero(evaltime, v1[0], v2[0], v3[0], v4[0], opl)) {
diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c
index b2eb41f7480..aca332ff0fe 100644
--- a/source/blender/editors/animation/anim_draw.c
+++ b/source/blender/editors/animation/anim_draw.c
@@ -397,7 +397,7 @@ static float normalization_factor_get(Scene *scene, FCurve *fcu, short flag, flo
               v4[0] = bezt->vec[1][0];
               v4[1] = bezt->vec[1][1];
 
-              correct_bezpart(v1, v2, v3, v4);
+              BKE_fcurve_correct_bezpart(v1, v2, v3, v4);
 
               BKE_curve_forward_diff_bezier(
                   v1[0], v2[0], v3[0], v4[0], data, resol, sizeof(float[3]));
diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c
index c6acc8260b7..d430e331b6c 100644
--- a/source/blender/editors/space_graph/graph_draw.c
+++ b/source/blender/editors/space_graph/graph_draw.c
@@ -880,7 +880,7 @@ static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2
         v4[0] = bezt->vec[1][0];
         v4[1] = bezt->vec[1][1];
 
-        correct_bezpart(v1, v2, v3, v4);
+        BKE_fcurve_correct_bezpart(v1, v2, v3, v4);
 
         BKE_curve_forward_diff_bezier(v1[0], v2[0], v3[0], v4[0], data, resol, sizeof(float[3]));
         BKE_curve_forward_diff_bezier(



More information about the Bf-blender-cvs mailing list