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
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2018-06-12 15:20:46 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2018-06-12 15:30:50 +0300
commitc2abb6d3fc0238cc1a8526d9fc3f6b603ee51f3a (patch)
tree52cd0fbd316e698ef7438bf0113076565ec2d9cc /source/blender/blenkernel/intern/particle_distribute.c
parent49b39ea851be0ca82da675dea5971185e297df47 (diff)
Particles: Use local RNG
Currently only obvious cases, but is already a progress.
Diffstat (limited to 'source/blender/blenkernel/intern/particle_distribute.c')
-rw-r--r--source/blender/blenkernel/intern/particle_distribute.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/source/blender/blenkernel/intern/particle_distribute.c b/source/blender/blenkernel/intern/particle_distribute.c
index 846afd48064..6c23036256b 100644
--- a/source/blender/blenkernel/intern/particle_distribute.c
+++ b/source/blender/blenkernel/intern/particle_distribute.c
@@ -85,6 +85,7 @@ static void distribute_simple_children(Scene *scene, Object *ob, Mesh *final_mes
int i, p;
int child_nbr= psys_get_child_number(scene, psys, use_render_params);
int totpart= psys_get_tot_child(scene, psys, use_render_params);
+ RNG *rng = BLI_rng_new_srandom(31415926 + psys->seed + psys->child_seed);
alloc_child_particles(psys, totpart);
@@ -96,9 +97,9 @@ static void distribute_simple_children(Scene *scene, Object *ob, Mesh *final_mes
/* create even spherical distribution inside unit sphere */
while (length>=1.0f) {
- cpa->fuv[0]=2.0f*BLI_frand()-1.0f;
- cpa->fuv[1]=2.0f*BLI_frand()-1.0f;
- cpa->fuv[2]=2.0f*BLI_frand()-1.0f;
+ cpa->fuv[0]=2.0f*BLI_rng_get_float(rng)-1.0f;
+ cpa->fuv[1]=2.0f*BLI_rng_get_float(rng)-1.0f;
+ cpa->fuv[2]=2.0f*BLI_rng_get_float(rng)-1.0f;
length=len_v3(cpa->fuv);
}
@@ -107,6 +108,8 @@ static void distribute_simple_children(Scene *scene, Object *ob, Mesh *final_mes
}
/* dmcache must be updated for parent particles if children from faces is used */
psys_calc_dmcache(ob, final_mesh, deform_mesh, psys);
+
+ BLI_rng_free(rng);
}
static void distribute_grid(Mesh *mesh, ParticleSystem *psys)
{
@@ -818,6 +821,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti
int jitlevel= 1, distr;
float *element_weight=NULL,*jitter_offset=NULL, *vweight=NULL;
float cur, maxweight=0.0, tweight, totweight, inv_totweight, co[3], nor[3], orco[3];
+ RNG *rng = NULL;
if (ELEM(NULL, ob, psys, psys->part))
return 0;
@@ -846,7 +850,6 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti
if (from == PART_FROM_CHILD) {
/* Simple children */
if (part->childtype != PART_CHILD_FACES) {
- BLI_srandom(31415926 + psys->seed + psys->child_seed);
distribute_simple_children(scene, ob, final_mesh, sim->psmd->mesh_original, psys, use_render_params);
return 0;
}
@@ -854,8 +857,6 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti
else {
/* Grid distribution */
if (part->distr==PART_DISTR_GRID && from != PART_FROM_VERT) {
- BLI_srandom(31415926 + psys->seed);
-
if (psys->part->use_modifier_stack) {
mesh = final_mesh;
}
@@ -882,8 +883,8 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti
/* Create trees and original coordinates if needed */
if (from == PART_FROM_CHILD) {
- distr=PART_DISTR_RAND;
- BLI_srandom(31415926 + psys->seed + psys->child_seed);
+ distr = PART_DISTR_RAND;
+ rng = BLI_rng_new_srandom(31415926 + psys->seed + psys->child_seed);
mesh= final_mesh;
/* BMESH ONLY */
@@ -906,7 +907,8 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti
}
else {
distr = part->distr;
- BLI_srandom(31415926 + psys->seed);
+
+ rng = BLI_rng_new_srandom(31415926 + psys->seed);
if (psys->part->use_modifier_stack)
mesh = final_mesh;
@@ -958,6 +960,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti
if (mesh != final_mesh) BKE_id_free(NULL, mesh);
BLI_kdtree_free(tree);
+ BLI_rng_free(rng);
return 0;
}
@@ -1098,7 +1101,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti
for (p = 0; p < totpart; p++) {
/* In theory element_sum[totmapped - 1] should be 1.0,
* but due to float errors this is not necessarily always true, so scale pos accordingly. */
- const float pos = BLI_frand() * element_sum[totmapped - 1];
+ const float pos = BLI_rng_get_float(rng) * element_sum[totmapped - 1];
const int eidx = distribute_binary_search(element_sum, totmapped, pos);
particle_element[p] = element_map[eidx];
BLI_assert(pos <= element_sum[eidx]);
@@ -1191,6 +1194,8 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti
alloc_child_particles(psys, totpart);
}
+ BLI_rng_free(rng);
+
return 1;
}