Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorSebastian Parborg <darkdefende@gmail.com>2020-05-25 19:52:34 +0300
committerSebastian Parborg <darkdefende@gmail.com>2020-05-25 19:59:14 +0300
commit4464a9425be9608f7e03e7f3ad7c61468d3c1da3 (patch)
treee58c578b2e441136392c559d803e28fae4832f64 /source
parentc19cc7ef81798cc60f1e1d03f82fd586f64ca597 (diff)
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
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenlib/intern/math_geom.c28
1 files changed, 26 insertions, 2 deletions
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;