diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-01-04 01:43:51 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-01-04 01:43:51 +0300 |
commit | 56faf73e3c914972effd12be1f26b1b7602a5de0 (patch) | |
tree | bd108c6d6e1796cefb9ef9dd52e068daaabf17dc /source | |
parent | 86471f8b72d2a6ac8f6078b92f701da1eeab2525 (diff) |
- Bugfix for flickering shadow with strand simplification.
- On non-edited hair, don't generate child particles for
each step, only at the end.
- Small optimization in the kd-tree.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/particle.c | 17 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle_system.c | 8 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_kdtree.c | 34 | ||||
-rw-r--r-- | source/blender/render/intern/source/convertblender.c | 4 |
4 files changed, 46 insertions, 17 deletions
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 87d6f0968eb..8dcdee5d19e 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -536,7 +536,7 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot) ParticleRenderData *data; ParticleRenderElem *elems, *elem; ParticleSettings *part= ctx->psys->part; - float *facearea, (*facecenter)[3], size[3], fac, powrate; + float *facearea, (*facecenter)[3], size[3], fac, powrate, scaleclamp; float co1[3], co2[3], co3[3], co4[3], lambda, arearatio, t, area, viewport; double vprate; int *origindex, *facetotvert; @@ -562,6 +562,9 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot) elems= MEM_callocN(sizeof(ParticleRenderElem)*totorigface, "SimplifyFaceElem"); data= ctx->psys->renderdata; + if(data->elems) + MEM_freeN(data->elems); + data->dosimplify= 1; data->elems= elems; data->origindex= origindex; @@ -619,11 +622,13 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot) area = psys_render_projected_area(ctx->psys, facecenter[a], facearea[a], vprate, &viewport); arearatio= fac*area/facearea[a]; - if(arearatio < 1.0f || viewport < 1.0f) { + if((arearatio < 1.0f || viewport < 1.0f) && elem->totchild) { /* lambda is percentage of elements to keep */ lambda= (arearatio < 1.0f)? pow(arearatio, powrate): 1.0f; lambda *= viewport; + lambda= MAX2(lambda, 1.0f/elem->totchild); + /* compute transition region */ t= part->simplify_transition; elem->t= (lambda-t < 0.0f)? lambda: (lambda+t > 1.0f)? 1.0f-lambda: t; @@ -633,6 +638,14 @@ int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot) elem->scalemax= (lambda+t < 1.0f)? 1.0f/lambda: 1.0f/(1.0f - elem->t*elem->t/t); elem->scalemin= (lambda+t < 1.0f)? 0.0f: elem->scalemax*(1.0f-elem->t/t); + elem->scalemin= sqrt(elem->scalemin); + elem->scalemax= sqrt(elem->scalemax); + + /* clamp scaling */ + scaleclamp= MIN2(elem->totchild, 10.0f); + elem->scalemin= MIN2(scaleclamp, elem->scalemin); + elem->scalemax= MIN2(scaleclamp, elem->scalemax); + /* extend lambda to include transition */ lambda= lambda + elem->t; if(lambda > 1.0f) diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index e8dcfc036c9..1235d9f5391 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -4247,7 +4247,8 @@ static void psys_update_path_cache(Object *ob, ParticleSystemModifierData *psmd, /* for render, child particle paths are computed on the fly */ if(part->childtype) { if(((psys->totchild!=0)) || (psys_in_edit_mode(psys) && (pset->flag&PE_SHOW_CHILD))) - psys_cache_child_paths(ob, psys, cfra, 0); + if(!(psys->part->type == PART_HAIR) || (psys->flag & PSYS_HAIR_DONE)) + psys_cache_child_paths(ob, psys, cfra, 0); } } else if(psys->pathcache) @@ -4459,8 +4460,9 @@ static void system_step(Object *ob, ParticleSystem *psys, ParticleSystemModifier distribute_particles(ob, psys, part->from); - if(get_alloc_child_particles_tot(psys)) - distribute_particles(ob, psys, PART_FROM_CHILD); + if(!(psys->part->type == PART_HAIR) || (psys->flag & PSYS_HAIR_DONE)) + if(get_alloc_child_particles_tot(psys)) + distribute_particles(ob, psys, PART_FROM_CHILD); } initialize_all_particles(ob, psys, psmd); diff --git a/source/blender/blenlib/intern/BLI_kdtree.c b/source/blender/blenlib/intern/BLI_kdtree.c index dbb9e95d379..80e92cb8809 100644 --- a/source/blender/blenlib/intern/BLI_kdtree.c +++ b/source/blender/blenlib/intern/BLI_kdtree.c @@ -166,11 +166,18 @@ int BLI_kdtree_find_nearest(KDTree *tree, float *co, float *nor, KDTreeNearest * min_node= root; min_dist= squared_distance(root->co,co,root->nor,nor); - if(root->left) - stack[cur++]=root->left; - - if(root->right) - stack[cur++]=root->right; + if(co[root->d] < root->co[root->d]) { + if(root->right) + stack[cur++]=root->right; + if(root->left) + stack[cur++]=root->left; + } + else { + if(root->left) + stack[cur++]=root->left; + if(root->right) + stack[cur++]=root->right; + } while(cur--){ node=stack[cur]; @@ -266,11 +273,18 @@ int BLI_kdtree_find_n_nearest(KDTree *tree, int n, float *co, float *nor, KDTree cur_dist= squared_distance(root->co,co,root->nor,nor); add_nearest(nearest,&found,n,root->index,cur_dist,root->co); - if(root->left) - stack[cur++]=root->left; - - if(root->right) - stack[cur++]=root->right; + if(co[root->d] < root->co[root->d]) { + if(root->right) + stack[cur++]=root->right; + if(root->left) + stack[cur++]=root->left; + } + else { + if(root->left) + stack[cur++]=root->left; + if(root->right) + stack[cur++]=root->right; + } while(cur--){ node=stack[cur]; diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index 68c32ee2d8b..5fd90c7f88e 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -1695,10 +1695,10 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem /* get orco */ if(tpsys && (part->from==PART_FROM_PARTICLE || part->phystype==PART_PHYS_NO)){ tpa=tpsys->particles+pa->num; - psys_particle_on_emitter(ob, psmd,tpart->from,tpa->num, -1,tpa->fuv,tpa->foffset,co,nor,0,0,orco,0); + psys_particle_on_emitter(ob, psmd,tpart->from,tpa->num,pa->num_dmcache,tpa->fuv,tpa->foffset,co,nor,0,0,orco,0); } else - psys_particle_on_emitter(ob, psmd,part->from,pa->num,-1,pa->fuv,pa->foffset,co,nor,0,0,orco,0); + psys_particle_on_emitter(ob, psmd,part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,nor,0,0,orco,0); if(uvco && ELEM(part->from,PART_FROM_FACE,PART_FROM_VOLUME)){ layer=psmd->dm->faceData.layers + CustomData_get_layer_index(&psmd->dm->faceData,CD_MFACE); |