[d4ac58d] master: Fix T43694, by Krzysztof Rećko (chrisr), reviewed in D1177.

Lukas Tönne noreply at git.blender.org
Wed Mar 25 18:36:59 CET 2015


Commit: d4ac58d04989e8c2e1951a55519cfba53011d494
Author: Lukas Tönne
Date:   Wed Mar 25 18:34:52 2015 +0100
Branches: master
https://developer.blender.org/rBd4ac58d04989e8c2e1951a55519cfba53011d494

Fix T43694, by Krzysztof Rećko (chrisr), reviewed in D1177.

Added some guards to prevent clumping to non existing particles. Also, adjusted threaded child path evaluation, so each child is evaluated once - previously virtual parents were done twice.

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

M	source/blender/blenkernel/BKE_particle.h
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenkernel/intern/particle_distribute.c
M	source/blender/blenkernel/intern/particle_system.c

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

diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index 0f1389b..619c061 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -361,7 +361,7 @@ void psys_get_dupli_path_transform(struct ParticleSimulationData *sim, struct Pa
 
 void psys_thread_context_init(struct ParticleThreadContext *ctx, struct ParticleSimulationData *sim);
 void psys_thread_context_free(struct ParticleThreadContext *ctx);
-void psys_tasks_create(struct ParticleThreadContext *ctx, int totpart, struct ParticleTask **r_tasks, int *r_numtasks);
+void psys_tasks_create(struct ParticleThreadContext *ctx, int startpart, int endpart, struct ParticleTask **r_tasks, int *r_numtasks);
 void psys_tasks_free(struct ParticleTask *tasks, int numtasks);
 
 void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3], float zvec[3], float center[3]);
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 291efd0..5d553f5 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -103,6 +103,8 @@ void psys_init_rng(void)
 
 static void get_child_modifier_parameters(ParticleSettings *part, ParticleThreadContext *ctx,
                                           ChildParticle *cpa, short cpa_from, int cpa_num, float *cpa_fuv, float *orco, ParticleTexture *ptex);
+static void get_cpa_texture(DerivedMesh *dm, ParticleSystem *psys, ParticleSettings *part, ParticleData *par,
+							int child_index, int face_index, const float fw[4], float *orco, ParticleTexture *ptex, int event, float cfra);
 extern void do_child_modifiers(ParticleSimulationData *sim,
                                ParticleTexture *ptex, const float par_co[3], const float par_vel[3], const float par_rot[4], const float par_orco[3],
                                ChildParticle *cpa, const float orco[3], float mat[4][4], ParticleKey *state, float t);
@@ -1943,9 +1945,11 @@ float *psys_cache_vgroup(DerivedMesh *dm, ParticleSystem *psys, int vgroup)
 }
 void psys_find_parents(ParticleSimulationData *sim)
 {
+	ParticleSystem *psys = sim->psys;
 	ParticleSettings *part = sim->psys->part;
 	KDTree *tree;
 	ChildParticle *cpa;
+	ParticleTexture ptex;
 	int p, totparent, totchild = sim->psys->totchild;
 	float co[3], orco[3];
 	int from = PART_FROM_FACE;
@@ -1963,7 +1967,13 @@ void psys_find_parents(ParticleSimulationData *sim)
 
 	for (p = 0, cpa = sim->psys->child; p < totparent; p++, cpa++) {
 		psys_particle_on_emitter(sim->psmd, from, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, co, 0, 0, 0, orco, 0);
-		BLI_kdtree_insert(tree, p, orco);
+
+		/* Check if particle doesn't exist because of texture influence. Insert only existing particles into kdtree. */
+		get_cpa_texture(sim->psmd->dm, psys, part, psys->particles + cpa->pa[0], p, cpa->num, cpa->fuv, orco, &ptex, PAMAP_DENS | PAMAP_CHILD, psys->cfra);
+
+		if (ptex.exist >= psys_frand(psys, p + 24)) {
+			BLI_kdtree_insert(tree, p, orco);
+		}
 	}
 
 	BLI_kdtree_balance(tree);
@@ -2273,7 +2283,7 @@ static void psys_thread_create_path(ParticleTask *task, struct ChildParticle *cp
 		ParticleCacheKey *par = NULL;
 		float par_co[3];
 		float par_orco[3];
-		
+
 		if (ctx->totparent) {
 			if (i >= ctx->totparent) {
 				pa = &psys->particles[cpa->parent];
@@ -2284,6 +2294,16 @@ static void psys_thread_create_path(ParticleTask *task, struct ChildParticle *cp
 		else if (cpa->parent >= 0) {
 			pa = &psys->particles[cpa->parent];
 			par = pcache[cpa->parent];
+
+			/* If particle is unexisting, try to pick a viable parent from particles used for interpolation. */
+			for (k = 0; k < 4 && pa && (pa->flag & PARS_UNEXIST); k++) {
+				if (cpa->pa[k] >= 0) {
+					pa = &psys->particles[cpa->pa[k]];
+					par = pcache[cpa->pa[k]];
+				}
+			}
+
+			if (pa->flag & PARS_UNEXIST) pa = NULL;
 		}
 		
 		if (pa) {
@@ -2353,7 +2373,7 @@ void psys_cache_child_paths(ParticleSimulationData *sim, float cfra, int editupd
 	
 	/* cache parent paths */
 	ctx.parent_pass = 1;
-	psys_tasks_create(&ctx, totparent, &tasks_parent, &numtasks_parent);
+	psys_tasks_create(&ctx, 0, totparent, &tasks_parent, &numtasks_parent);
 	for (i = 0; i < numtasks_parent; ++i) {
 		ParticleTask *task = &tasks_parent[i];
 		
@@ -2364,7 +2384,7 @@ void psys_cache_child_paths(ParticleSimulationData *sim, float cfra, int editupd
 	
 	/* cache child paths */
 	ctx.parent_pass = 0;
-	psys_tasks_create(&ctx, totchild, &tasks_child, &numtasks_child);
+	psys_tasks_create(&ctx, totparent, totchild, &tasks_child, &numtasks_child);
 	for (i = 0; i < numtasks_child; ++i) {
 		ParticleTask *task = &tasks_child[i];
 		
diff --git a/source/blender/blenkernel/intern/particle_distribute.c b/source/blender/blenkernel/intern/particle_distribute.c
index 245c243..1429d3b 100644
--- a/source/blender/blenkernel/intern/particle_distribute.c
+++ b/source/blender/blenkernel/intern/particle_distribute.c
@@ -1121,7 +1121,7 @@ static void distribute_particles_on_dm(ParticleSimulationData *sim, int from)
 	task_pool = BLI_task_pool_create(task_scheduler, &ctx);
 	
 	totpart = (from == PART_FROM_CHILD ? sim->psys->totchild : sim->psys->totpart);
-	psys_tasks_create(&ctx, totpart, &tasks, &numtasks);
+	psys_tasks_create(&ctx, 0, totpart, &tasks, &numtasks);
 	for (i = 0; i < numtasks; ++i) {
 		ParticleTask *task = &tasks[i];
 		
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index b7ebcfa..5a263e2 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -448,24 +448,24 @@ BLI_INLINE int ceil_ii(int a, int b)
 	return (a + b - 1) / b;
 }
 
-void psys_tasks_create(ParticleThreadContext *ctx, int totpart, ParticleTask **r_tasks, int *r_numtasks)
+void psys_tasks_create(ParticleThreadContext *ctx, int startpart, int endpart, ParticleTask **r_tasks, int *r_numtasks)
 {
 	ParticleTask *tasks;
-	int numtasks = ceil_ii(totpart, MAX_PARTICLES_PER_TASK);
-	float particles_per_task = (float)totpart / (float)numtasks, p, pnext;
+	int numtasks = ceil_ii((endpart - startpart), MAX_PARTICLES_PER_TASK);
+	float particles_per_task = (float)(endpart - startpart) / (float)numtasks, p, pnext;
 	int i;
 	
 	tasks = MEM_callocN(sizeof(ParticleTask) * numtasks, "ParticleThread");
 	*r_numtasks = numtasks;
 	*r_tasks = tasks;
 	
-	p = 0.0f;
+	p = (float)startpart;
 	for (i = 0; i < numtasks; i++, p = pnext) {
 		pnext = p + particles_per_task;
 		
 		tasks[i].ctx = ctx;
 		tasks[i].begin = (int)p;
-		tasks[i].end = min_ii((int)pnext, totpart);
+		tasks[i].end = min_ii((int)pnext, endpart);
 	}
 }




More information about the Bf-blender-cvs mailing list