From 91af828e8bfaa04cbd49f1859e06a1f76749102d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 15 Oct 2020 19:38:20 +0200 Subject: 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. --- source/blender/blenkernel/intern/curve.c | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'source/blender/blenkernel/intern/curve.c') 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) -- cgit v1.2.3