[Bf-blender-cvs] [4f0e6c3aa30] geometry-nodes-curve-support: Cleanup: Vectorize bezier forward differencing

Hans Goudey noreply at git.blender.org
Tue Apr 6 05:47:53 CEST 2021


Commit: 4f0e6c3aa30569954439b24e8aa8e5e0a95a1581
Author: Hans Goudey
Date:   Mon Apr 5 22:47:42 2021 -0500
Branches: geometry-nodes-curve-support
https://developer.blender.org/rB4f0e6c3aa30569954439b24e8aa8e5e0a95a1581

Cleanup: Vectorize bezier forward differencing

It's a bit strange no one had done this already. This also solves the
problem of `BKE_curve_forward_diff_bezier` always affecting one
more points than you asked for, which was causing another problem.

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

M	source/blender/blenkernel/intern/derived_curve.cc

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

diff --git a/source/blender/blenkernel/intern/derived_curve.cc b/source/blender/blenkernel/intern/derived_curve.cc
index df766b75ea8..3422bb7e5ae 100644
--- a/source/blender/blenkernel/intern/derived_curve.cc
+++ b/source/blender/blenkernel/intern/derived_curve.cc
@@ -158,16 +158,25 @@ static void evaluate_bezier_section_3d(const float3 &point_0,
                                        MutableSpan<float3> result)
 {
   BLI_assert(result.size() > 0);
-  /* TODO: This can probably be vectorized... no one has done this already? */
-  float *data = (float *)result.data();
-  for (const int axis : {0, 1, 2}) {
-    BKE_curve_forward_diff_bezier(point_0[axis],
-                                  point_1[axis],
-                                  point_2[axis],
-                                  point_3[axis],
-                                  data + axis,
-                                  result.size(),
-                                  sizeof(float3));
+
+  float f = static_cast<float>(result.size());
+  float3 rt0 = point_0;
+  float3 rt1 = 3.0f * (point_1 - point_0) / f;
+  f *= f;
+  float3 rt2 = 3.0f * (point_0 - 2.0f * point_1 + point_2) / f;
+  f *= result.size();
+  float3 rt3 = (point_3 - point_0 + 3.0f * (point_1 - point_2)) / f;
+
+  float3 q0 = rt0;
+  float3 q1 = rt1 + rt2 + rt3;
+  float3 q2 = 2.0f * rt2 + 6.0f * rt3;
+  float3 q3 = 6.0f * rt3;
+
+  for (const int i : result.index_range()) {
+    result[i] = q0;
+    q0 += q1;
+    q1 += q2;
+    q2 += q3;
   }
 }
 
@@ -186,7 +195,7 @@ static void evaluate_segment_positions(const BezierPoint &point,
                                point.handle_position_b,
                                next.handle_position_a,
                                next.position,
-                               positions.slice(offset, resolution - 1));
+                               positions.slice(offset, resolution));
     offset += resolution;
   }
 }



More information about the Bf-blender-cvs mailing list