diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2016-07-04 17:10:40 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2016-07-04 17:10:40 +0300 |
commit | 99683f25e8e8bd9b1e9d8f4a0966cc6268c98fb0 (patch) | |
tree | 3afdadc391b113e8ff922abde4584beb46aa52f5 /source/blender/blenkernel/intern/particle_distribute.c | |
parent | d3b27bd19c688b297d952f7c27c721dc079612b6 (diff) |
And one more fix to particle distribution!
As pointed by Brecht, previous fix in rB61b49de44940 was actually incomplete,
we could still hit float rounding issue and hence same value in more than one consecutive
items of element_sum.
New solution is a bit different, we remove the 'minimal weight' check, and rather simply
ignores an item when the sum of its normalized weight to previous item's sum does not add
anything. Shall be safe and 100% effective this time!
Diffstat (limited to 'source/blender/blenkernel/intern/particle_distribute.c')
-rw-r--r-- | source/blender/blenkernel/intern/particle_distribute.c | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/source/blender/blenkernel/intern/particle_distribute.c b/source/blender/blenkernel/intern/particle_distribute.c index c814713f3f4..44cf5b119c1 100644 --- a/source/blender/blenkernel/intern/particle_distribute.c +++ b/source/blender/blenkernel/intern/particle_distribute.c @@ -1007,13 +1007,11 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti MEM_freeN(vweight); } -#define MIN_WEIGHT 1e-7f /* Weights too small cause issues e.g. with binary search... */ - /* Calculate total weight of all elements */ int totmapped = 0; totweight = 0.0f; for (i = 0; i < totelem; i++) { - if (element_weight[i] > MIN_WEIGHT) { + if (element_weight[i] > 0.0f) { totmapped++; totweight += element_weight[i]; } @@ -1036,22 +1034,21 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti int *element_map = MEM_mallocN(sizeof(*element_map) * totmapped, __func__); int i_mapped = 0; - for (i = 0; i < totelem && element_weight[i] <= MIN_WEIGHT; i++); + for (i = 0; i < totelem && element_weight[i] == 0.0f; i++); element_sum[i_mapped] = element_weight[i] * inv_totweight; element_map[i_mapped] = i; i_mapped++; for (i++; i < totelem; i++) { - if (element_weight[i] > MIN_WEIGHT) { + if (element_weight[i] > 0.0f) { element_sum[i_mapped] = element_sum[i_mapped - 1] + element_weight[i] * inv_totweight; - BLI_assert(element_sum[i_mapped] > element_sum[i_mapped - 1]); - element_map[i_mapped] = i; - i_mapped++; + /* Skip elements which weight is so small that it does not affect the sum. */ + if (element_sum[i_mapped] > element_sum[i_mapped - 1]) { + element_map[i_mapped] = i; + i_mapped++; + } } } - - BLI_assert(i_mapped == totmapped); - -#undef MIN_WEIGHT + totmapped = i_mapped; /* Finally assign elements to particles */ if ((part->flag & PART_TRAND) || (part->simplify_flag & PART_SIMPLIFY_ENABLE)) { |