[Bf-blender-cvs] [4464a9425be] master: Calculate epsilon values for interp_weights_poly to improve accuracy

Sebastian Parborg noreply at git.blender.org
Mon May 25 18:59:36 CEST 2020


Commit: 4464a9425be9608f7e03e7f3ad7c61468d3c1da3
Author: Sebastian Parborg
Date:   Mon May 25 18:52:34 2020 +0200
Branches: master
https://developer.blender.org/rB4464a9425be9608f7e03e7f3ad7c61468d3c1da3

Calculate epsilon values for interp_weights_poly to improve accuracy

interp_weights_poly_v2 would have too large epsilon values for small
polygons. To solve this we now calculate the appropriate epsilon value
so it can gracefully handle big and small values.

To make sure there was no regression, these changes were tested with the
files in T36105, T31581. Also with a surface deform modifier test file
attached in the differential below.

Reviewed By: Brecht

Differential Revision: http://developer.blender.org/D7772

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

M	source/blender/blenlib/intern/math_geom.c

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

diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index a26824bd2b5..e7c1fc8c2d9 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -4220,7 +4220,19 @@ static float mean_value_half_tan_v2(const struct Float2_Len *d_curr,
 
 void interp_weights_poly_v3(float *w, float v[][3], const int n, const float co[3])
 {
-  const float eps = 1e-5f; /* take care, low values cause [#36105] */
+  /* Before starting to calculate the weight, we need to figure out the floating point precision we
+   * can expect from the supplied data. */
+  float max_value = 0;
+
+  for (int i = 0; i < n; i++) {
+    max_value = max_ff(max_value, fabsf(v[i][0] - co[0]));
+    max_value = max_ff(max_value, fabsf(v[i][1] - co[1]));
+    max_value = max_ff(max_value, fabsf(v[i][2] - co[2]));
+  }
+
+  /* These to values we derived by empirically testing different values that works for the test
+   * files in D7772. */
+  const float eps = 16.0f * FLT_EPSILON * max_value;
   const float eps_sq = eps * eps;
   const float *v_curr, *v_next;
   float ht_prev, ht; /* half tangents */
@@ -4293,8 +4305,20 @@ void interp_weights_poly_v3(float *w, float v[][3], const int n, const float co[
 
 void interp_weights_poly_v2(float *w, float v[][2], const int n, const float co[2])
 {
-  const float eps = 1e-5f; /* take care, low values cause [#36105] */
+  /* Before starting to calculate the weight, we need to figure out the floating point precision we
+   * can expect from the supplied data. */
+  float max_value = 0;
+
+  for (int i = 0; i < n; i++) {
+    max_value = max_ff(max_value, fabsf(v[i][0] - co[0]));
+    max_value = max_ff(max_value, fabsf(v[i][1] - co[1]));
+  }
+
+  /* These to values we derived by empirically testing different values that works for the test
+   * files in D7772. */
+  const float eps = 16.0f * FLT_EPSILON * max_value;
   const float eps_sq = eps * eps;
+
   const float *v_curr, *v_next;
   float ht_prev, ht; /* half tangents */
   float totweight = 0.0f;



More information about the Bf-blender-cvs mailing list