Fix T35247: Particle texture behaves incorrectly after changing the number of particles
Root of the issue goes to the order of particle initialization which does texture evaluation (which does depend on particle coordinate) and particle birth coordinate calculation. So basically what happened is: * Changing number of particles re-allocated all the particles, which sets their coordinate to (0,0,0) * Texture evaluation used this non-initialized coordinate * Coordinates were calculated for particles Reshuffled code a bit so now texture evaluation happens after particles. coordinate calculation. Basically moved texture evaluation to particle reset function. Reset happens after initialization anyway and it does know particle coordinates. Also, if reset is being called without init then it's also kind of logical to re-evaluate texture because particle coordinates might change.
This commit is contained in:
@@ -376,7 +376,7 @@ void psys_particle_on_dm(struct DerivedMesh *dm, int from, int index, int index_
|
||||
float orco[3], float ornor[3]);
|
||||
|
||||
/* particle_system.c */
|
||||
void initialize_particle(struct ParticleSimulationData *sim, struct ParticleData *pa, int p);
|
||||
void initialize_particle(struct ParticleData *pa);
|
||||
void psys_calc_dmcache(struct Object *ob, struct DerivedMesh *dm, struct ParticleSystem *psys);
|
||||
int psys_particle_dm_face_lookup(struct Object *ob, struct DerivedMesh *dm, int index, const float fw[4], struct LinkNode *node);
|
||||
|
||||
|
||||
@@ -1540,23 +1540,26 @@ void psys_threads_free(ParticleThread *threads)
|
||||
MEM_freeN(threads);
|
||||
}
|
||||
|
||||
/* set particle parameters that don't change during particle's life */
|
||||
void initialize_particle(ParticleSimulationData *sim, ParticleData *pa, int p)
|
||||
static void initialize_particle_texture(ParticleSimulationData *sim, ParticleData *pa, int p)
|
||||
{
|
||||
ParticleSystem *psys = sim->psys;
|
||||
ParticleSettings *part = psys->part;
|
||||
ParticleTexture ptex;
|
||||
|
||||
pa->flag &= ~PARS_UNEXIST;
|
||||
|
||||
if (part->type != PART_FLUID) {
|
||||
psys_get_texture(sim, pa, &ptex, PAMAP_INIT, 0.f);
|
||||
|
||||
|
||||
if (ptex.exist < PSYS_FRAND(p+125))
|
||||
pa->flag |= PARS_UNEXIST;
|
||||
|
||||
pa->time = (part->type == PART_HAIR) ? 0.f : part->sta + (part->end - part->sta)*ptex.time;
|
||||
}
|
||||
}
|
||||
|
||||
/* set particle parameters that don't change during particle's life */
|
||||
void initialize_particle(ParticleData *pa)
|
||||
{
|
||||
pa->flag &= ~PARS_UNEXIST;
|
||||
|
||||
pa->hair_index = 0;
|
||||
/* we can't reset to -1 anymore since we've figured out correct index in distribute_particles */
|
||||
@@ -1572,7 +1575,7 @@ static void initialize_all_particles(ParticleSimulationData *sim)
|
||||
|
||||
LOOP_PARTICLES {
|
||||
if ((pa->flag & PARS_UNEXIST)==0)
|
||||
initialize_particle(sim, pa, p);
|
||||
initialize_particle(pa);
|
||||
|
||||
if (pa->flag & PARS_UNEXIST)
|
||||
psys->totunexist++;
|
||||
@@ -1984,6 +1987,13 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime,
|
||||
|
||||
psys_get_birth_coordinates(sim, pa, &pa->state, dtime, cfra);
|
||||
|
||||
/* Initialize particle settings which depends on texture.
|
||||
*
|
||||
* We could only do it now because we'll need to know coordinate
|
||||
* before sampling the texture.
|
||||
*/
|
||||
initialize_particle_texture(sim, pa, p);
|
||||
|
||||
if (part->phystype==PART_PHYS_BOIDS && pa->boid) {
|
||||
BoidParticle *bpa = pa->boid;
|
||||
|
||||
|
||||
@@ -3458,7 +3458,7 @@ static int brush_add(PEData *data, short number)
|
||||
}
|
||||
|
||||
pa->size= 1.0f;
|
||||
initialize_particle(&sim, pa, i);
|
||||
initialize_particle(pa);
|
||||
reset_particle(&sim, pa, 0.0, 1.0);
|
||||
point->flag |= PEP_EDIT_RECALC;
|
||||
if (pe_x_mirror(ob))
|
||||
|
||||
Reference in New Issue
Block a user