Fix #33113: cycles not rendering motion blur correct with dying particles.

There were a bunch of other issues with dupli motion blur and syncing, the problem
being that there was no proper way to detect corresponding duplis between frames
or updates. As a solution, a persistent_id was added to the DupliObject. It's an
extension of the previous index value, with one index for each dupli level. This
can be used to reliably find matching dupli objects between frames. Works with
nested duplis, multiple particle systems, etc.
This commit is contained in:
Brecht Van Lommel 2012-11-08 16:35:28 +00:00
parent e73408f247
commit 863291bc8e
10 changed files with 226 additions and 267 deletions

@ -86,11 +86,11 @@ static uint object_ray_visibility(BL::Object b_ob)
/* Light */
void BlenderSync::sync_light(BL::Object b_parent, int b_index, BL::Object b_ob, Transform& tfm)
void BlenderSync::sync_light(BL::Object b_parent, int persistent_id[OBJECT_PERSISTENT_ID_SIZE], BL::Object b_ob, Transform& tfm)
{
/* test if we need to sync */
Light *light;
ObjectKey key(b_parent, b_index, b_ob);
ObjectKey key(b_parent, persistent_id, b_ob);
if(!light_map.sync(&light, b_ob, b_parent, key))
return;
@ -196,23 +196,24 @@ void BlenderSync::sync_background_light()
/* Object */
void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::DupliObject b_dupli_ob, Transform& tfm, uint layer_flag, int motion, int particle_id)
Object *BlenderSync::sync_object(BL::Object b_parent, int persistent_id[OBJECT_PERSISTENT_ID_SIZE], BL::DupliObject b_dupli_ob, Transform& tfm, uint layer_flag, int motion)
{
BL::Object b_ob = (b_dupli_ob ? b_dupli_ob.object() : b_parent);
/* light is handled separately */
if(object_is_light(b_ob)) {
if(!motion)
sync_light(b_parent, b_index, b_ob, tfm);
return;
sync_light(b_parent, persistent_id, b_ob, tfm);
return NULL;
}
/* only interested in object that we can create meshes from */
if(!object_is_mesh(b_ob))
return;
return NULL;
/* key to lookup object */
ObjectKey key(b_parent, b_index, b_ob);
ObjectKey key(b_parent, persistent_id, b_ob);
Object *object;
/* motion vector case */
@ -234,7 +235,7 @@ void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::DupliObject
sync_mesh_motion(b_ob, object->mesh, motion);
}
return;
return object;
}
/* test if we need to sync */
@ -248,13 +249,14 @@ void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::DupliObject
/* mesh sync */
object->mesh = sync_mesh(b_ob, object_updated);
/* sspecial case not tracked by object update flags */
if(use_holdout != object->use_holdout) {
object->use_holdout = use_holdout;
scene->object_manager->tag_update(scene);
}
/* object sync */
/* transform comparison should not be needed, but duplis don't work perfect
/* object sync
* transform comparison should not be needed, but duplis don't work perfect
* in the depsgraph and may not signal changes, so this is a workaround */
if(object_updated || (object->mesh && object->mesh->need_update) || tfm != object->tfm) {
object->name = b_ob.name().c_str();
@ -264,7 +266,10 @@ void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::DupliObject
object->motion.post = tfm;
object->use_motion = false;
object->random_id = hash_int_2d(hash_string(object->name.c_str()), b_index);
object->random_id = hash_string(object->name.c_str());
if(persistent_id)
for(int i = 0; i < OBJECT_PERSISTENT_ID_SIZE; i++)
object->random_id = hash_int_2d(object->random_id, persistent_id[i]);
/* visibility flags for both parent */
object->visibility = object_ray_visibility(b_ob) & PATH_RAY_ALL;
@ -289,10 +294,10 @@ void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::DupliObject
object->dupli_uv = make_float2(0.0f, 0.0f);
}
object->particle_id = particle_id;
object->tag_update(scene);
}
return object;
}
/* Object Loop */
@ -314,7 +319,9 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d, int motion)
/* object loop */
BL::Scene::objects_iterator b_ob;
BL::Scene b_sce = b_scene;
int particle_offset = 1; /* first particle is dummy for regular, non-instanced objects */
/* global particle index counter */
int particle_id = 1;
bool cancel = false;
@ -327,16 +334,14 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d, int motion)
if(!hide) {
progress.set_sync_status("Synchronizing object", (*b_ob).name());
int num_particles = object_count_particles(*b_ob);
if(b_ob->is_duplicator()) {
hide = true; /* duplicators hidden by default */
/* duplicators hidden by default */
hide = true;
/* dupli objects */
b_ob->dupli_list_create(b_scene, 2);
BL::Object::dupli_list_iterator b_dup;
int b_index = 0;
for(b_ob->dupli_list.begin(b_dup); b_dup != b_ob->dupli_list.end(); ++b_dup) {
Transform tfm = get_transform(b_dup->matrix());
@ -345,7 +350,8 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d, int motion)
bool emitter_hide = false;
if(b_dup_ob.is_duplicator()) {
emitter_hide = true; /* duplicators hidden by default */
/* duplicators hidden by default */
emitter_hide = true;
/* check if we should render or hide particle emitter */
BL::Object::particle_systems_iterator b_psys;
@ -355,21 +361,34 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d, int motion)
}
if(!(b_dup->hide() || dup_hide || emitter_hide)) {
sync_object(*b_ob, b_index, *b_dup, tfm, ob_layer, motion, b_dup->particle_index() + particle_offset);
/* the persistent_id allows us to match dupli objects
* between frames and updates */
BL::Array<int, OBJECT_PERSISTENT_ID_SIZE> persistent_id = b_dup->persistent_id();
/* sync object and mesh or light data */
Object *object = sync_object(*b_ob, persistent_id.data, *b_dup, tfm, ob_layer, motion);
/* sync possible particle data, note particle_id
* starts counting at 1, first is dummy particle */
if(!motion && object && sync_dupli_particle(*b_ob, *b_dup, object)) {
if(particle_id != object->particle_id) {
object->particle_id = particle_id;
scene->object_manager->tag_update(scene);
}
particle_id++;
}
}
++b_index;
}
b_ob->dupli_list_clear();
}
/* sync particles and check if we should render or hide particle emitter */
/* check if we should render or hide particle emitter */
BL::Object::particle_systems_iterator b_psys;
for(b_ob->particle_systems.begin(b_psys); b_psys != b_ob->particle_systems.end(); ++b_psys) {
if(!motion)
sync_particles(*b_ob, *b_psys);
for(b_ob->particle_systems.begin(b_psys); b_psys != b_ob->particle_systems.end(); ++b_psys) {
if(b_psys->settings().use_render_emitter())
hide = false;
}
@ -377,10 +396,8 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d, int motion)
if(!hide) {
/* object itself */
Transform tfm = get_transform(b_ob->matrix_world());
sync_object(*b_ob, 0, PointerRNA_NULL, tfm, ob_layer, motion, 0);
sync_object(*b_ob, NULL, PointerRNA_NULL, tfm, ob_layer, motion);
}
particle_offset += num_particles;
}
cancel = progress.get_cancel();

@ -17,6 +17,7 @@
*/
#include "mesh.h"
#include "object.h"
#include "particles.h"
#include "blender_sync.h"
@ -28,170 +29,57 @@ CCL_NAMESPACE_BEGIN
/* Utilities */
/* Particles Sync */
bool BlenderSync::psys_need_update(BL::ParticleSystem b_psys)
bool BlenderSync::sync_dupli_particle(BL::Object b_ob, BL::DupliObject b_dup, Object *object)
{
/* Particle data is only needed for
* a) Billboard render mode if object's own material uses particle info
* b) object/group render mode if any dupli object's material uses particle info
*
* Note: Meshes have to be synced at this point!
*/
bool need_update = false;
switch (b_psys.settings().render_type()) {
/* XXX not implemented yet!
* billboards/strands would become part of the mesh data (?),
* so the mesh attributes would store whether particle info is required.
*/
#if 0
case BL::ParticleSettings::render_type_BILLBOARD:
case BL::ParticleSettings::render_type_PATH: { /* for strand rendering */
BL::ID key = (BKE_object_is_modified(b_ob))? b_ob: b_ob.data();
Mesh *mesh = mesh_map.find(key);
if(mesh) {
need_update |= mesh->need_attribute(scene, ATTR_STD_PARTICLE) && mesh->need_update;
}
break;
}
#endif
case BL::ParticleSettings::render_type_OBJECT: {
BL::Object b_dupli_ob = b_psys.settings().dupli_object();
if(b_dupli_ob) {
BL::ID key = (BKE_object_is_modified(b_dupli_ob))? b_dupli_ob: b_dupli_ob.data();
Mesh *mesh = mesh_map.find(key);
if(mesh) {
need_update |= mesh->need_attribute(scene, ATTR_STD_PARTICLE) && mesh->need_update;
}
}
break;
}
case BL::ParticleSettings::render_type_GROUP: {
BL::Group b_dupli_group = b_psys.settings().dupli_group();
if(b_dupli_group) {
BL::Group::objects_iterator b_gob;
for (b_dupli_group.objects.begin(b_gob); b_gob != b_dupli_group.objects.end(); ++b_gob) {
BL::ID key = (BKE_object_is_modified(*b_gob))? *b_gob: b_gob->data();
Mesh *mesh = mesh_map.find(key);
if(mesh) {
need_update |= mesh->need_attribute(scene, ATTR_STD_PARTICLE) && mesh->need_update;
}
}
}
break;
}
default:
/* avoid compiler warning */
break;
/* test if this dupli was generated from a particle sytem */
BL::ParticleSystem b_psys = b_dup.particle_system();
if(!b_psys)
return false;
/* test if we need particle data */
if(!object->mesh->need_attribute(scene, ATTR_STD_PARTICLE))
return false;
/* don't handle child particles yet */
BL::Array<int, OBJECT_PERSISTENT_ID_SIZE> persistent_id = b_dup.persistent_id();
if(persistent_id[0] >= b_psys.particles.length())
return false;
/* find particle system */
ParticleSystemKey key(b_ob, persistent_id);
ParticleSystem *psys;
bool first_use = !particle_system_map.is_used(key);
bool need_update = particle_system_map.sync(&psys, b_ob, b_dup.object(), key);
/* no update needed? */
if(!need_update && !object->mesh->need_update && !scene->object_manager->need_update)
return true;
/* first time used in this sync loop? clear and tag update */
if(first_use) {
psys->particles.clear();
psys->tag_update(scene);
}
return need_update;
}
static bool use_particle_system(BL::ParticleSystem b_psys)
{
/* only use duplicator particles? disabled particle info for
* halo and billboard to reduce particle count.
* Probably not necessary since particles don't contain a huge amount
* of data compared to other textures.
*/
#if 0
int render_type = b_psys->settings().render_type();
return (render_type == BL::ParticleSettings::render_type_OBJECT
|| render_type == BL::ParticleSettings::render_type_GROUP);
#endif
/* add particle */
BL::Particle b_pa = b_psys.particles[persistent_id[0]];
Particle pa;
pa.index = persistent_id[0];
pa.age = b_scene.frame_current() - b_pa.birth_time();
pa.lifetime = b_pa.lifetime();
pa.location = get_float3(b_pa.location());
pa.rotation = get_float4(b_pa.rotation());
pa.size = b_pa.size();
pa.velocity = get_float3(b_pa.velocity());
pa.angular_velocity = get_float3(b_pa.angular_velocity());
psys->particles.push_back(pa);
/* return that this object has particle data */
return true;
}
static bool use_particle(BL::Particle b_pa, bool preview, bool show_unborn, bool use_dead)
{
return b_pa.is_exist() && (!preview || b_pa.is_visible()) &&
(b_pa.alive_state() != BL::Particle::alive_state_UNBORN || show_unborn) &&
(b_pa.alive_state() != BL::Particle::alive_state_DEAD || use_dead);
}
static int psys_count_particles(BL::ParticleSystem b_psys, bool preview)
{
BL::ParticleSystem::particles_iterator b_pa;
bool show_unborn = b_psys.settings().show_unborn();
bool use_dead = b_psys.settings().use_dead();
int num = 0;
for(b_psys.particles.begin(b_pa); b_pa != b_psys.particles.end(); ++b_pa)
if(use_particle(*b_pa, preview, show_unborn, use_dead))
++num;
return num;
}
int BlenderSync::object_count_particles(BL::Object b_ob)
{
BL::Object::particle_systems_iterator b_psys;
int num = 0;
for(b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys)
if(use_particle_system(*b_psys))
num += psys_count_particles(*b_psys, preview);
return num;
}
void BlenderSync::sync_particles(BL::Object b_ob, BL::ParticleSystem b_psys)
{
/* depending on settings the psys may not even be rendered */
if(!use_particle_system(b_psys))
return;
/* key to lookup particle system */
ParticleSystemKey key(b_ob, b_psys);
ParticleSystem *psys;
/* test if we need to sync */
bool object_updated = false;
if(particle_system_map.sync(&psys, b_ob, b_ob, key))
object_updated = true;
bool need_update = psys_need_update(b_psys);
if(object_updated || need_update) {
bool show_unborn = b_psys.settings().show_unborn();
bool use_dead = b_psys.settings().use_dead();
int num = psys_count_particles(b_psys, preview);
psys->particles.clear();
psys->particles.reserve(num);
BL::ParticleSystem::particles_iterator b_pa;
int index = 0;
for(b_psys.particles.begin(b_pa); b_pa != b_psys.particles.end(); ++b_pa) {
if(use_particle(*b_pa, preview, show_unborn, use_dead)) {
Particle pa;
pa.index = index;
pa.age = b_scene.frame_current() - b_pa->birth_time();
pa.lifetime = b_pa->lifetime();
pa.location = get_float3(b_pa->location());
pa.rotation = get_float4(b_pa->rotation());
pa.size = b_pa->size();
pa.velocity = get_float3(b_pa->velocity());
pa.angular_velocity = get_float3(b_pa->angular_velocity());
psys->particles.push_back(pa);
}
++index;
}
psys->tag_update(scene);
}
}
CCL_NAMESPACE_END

@ -42,6 +42,7 @@ class Film;
class Light;
class Mesh;
class Object;
class ParticleSystem;
class Scene;
class Shader;
class ShaderGraph;
@ -80,20 +81,20 @@ private:
void sync_nodes(Shader *shader, BL::ShaderNodeTree b_ntree);
Mesh *sync_mesh(BL::Object b_ob, bool object_updated);
void sync_object(BL::Object b_parent, int b_index, BL::DupliObject b_dupli_object, Transform& tfm, uint layer_flag, int motion, int particle_id);
void sync_light(BL::Object b_parent, int b_index, BL::Object b_ob, Transform& tfm);
Object *sync_object(BL::Object b_parent, int persistent_id[OBJECT_PERSISTENT_ID_SIZE], BL::DupliObject b_dupli_object, Transform& tfm, uint layer_flag, int motion);
void sync_light(BL::Object b_parent, int persistent_id[OBJECT_PERSISTENT_ID_SIZE], BL::Object b_ob, Transform& tfm);
void sync_background_light();
void sync_mesh_motion(BL::Object b_ob, Mesh *mesh, int motion);
void sync_camera_motion(BL::Object b_ob, int motion);
void sync_particles(BL::Object b_ob, BL::ParticleSystem b_psys);
/* particles */
bool sync_dupli_particle(BL::Object b_ob, BL::DupliObject b_dup, Object *object);
/* util */
void find_shader(BL::ID id, vector<uint>& used_shaders, int default_shader);
bool BKE_object_is_modified(BL::Object b_ob);
bool object_is_mesh(BL::Object b_ob);
bool object_is_light(BL::Object b_ob);
bool psys_need_update(BL::ParticleSystem b_psys);
int object_count_particles(BL::Object b_ob);
/* variables */
BL::RenderEngine b_engine;

@ -284,6 +284,12 @@ public:
return recalc;
}
bool is_used(const K& key)
{
T *data = find(key);
return (data)? used_set.find(data) != used_set.end(): NULL;
}
void used(T *data)
{
/* tag data as still in use */
@ -343,27 +349,49 @@ protected:
/* Object Key */
enum { OBJECT_PERSISTENT_ID_SIZE = 8 };
struct ObjectKey {
void *parent;
int index;
int id[OBJECT_PERSISTENT_ID_SIZE];
void *ob;
ObjectKey(void *parent_, int index_, void *ob_)
: parent(parent_), index(index_), ob(ob_) {}
ObjectKey(void *parent_, int id_[OBJECT_PERSISTENT_ID_SIZE], void *ob_)
: parent(parent_), ob(ob_)
{
if(id_)
memcpy(id, id_, sizeof(id));
else
memset(id, 0, sizeof(id));
}
bool operator<(const ObjectKey& k) const
{ return (parent < k.parent || (parent == k.parent && (index < k.index || (index == k.index && ob < k.ob)))); }
{
return (parent < k.parent) ||
(parent == k.parent && (memcmp(id, k.id, sizeof(id)) < 0)) ||
(memcmp(id, k.id, sizeof(id)) == 0 && ob < k.ob);
}
};
struct ParticleSystemKey {
void *ob;
void *psys;
int id[OBJECT_PERSISTENT_ID_SIZE];
ParticleSystemKey(void *ob_, void *psys_)
: ob(ob_), psys(psys_) {}
ParticleSystemKey(void *ob_, int id_[OBJECT_PERSISTENT_ID_SIZE])
: ob(ob_)
{
if(id_)
memcpy(id, id_, sizeof(id));
else
memset(id, 0, sizeof(id));
}
bool operator<(const ParticleSystemKey& k) const
{ return (ob < k.ob && psys < k.psys); }
{
/* first id is particle index, we don't compare that */
return (ob < k.ob) ||
(ob == k.ob && (memcmp(id+1, k.id+1, sizeof(int)*(OBJECT_PERSISTENT_ID_SIZE-1)) < 0));
}
};
CCL_NAMESPACE_END

@ -57,8 +57,7 @@ void ParticleSystemManager::device_update_particles(Device *device, DeviceScene
{
/* count particles.
* adds one dummy particle at the beginning to avoid invalid lookups,
* in case a shader uses particle info without actual particle data.
*/
* in case a shader uses particle info without actual particle data. */
int num_particles = 1;
foreach(ParticleSystem *psys, scene->particle_systems)
num_particles += psys->particles.size();

@ -76,8 +76,8 @@
/* --------------------- */
/* forward declarations */
static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4], int par_index,
int level, short flag);
static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4],
int persistent_id[MAX_DUPLI_RECUR], int level, int index, short flag);
/* ******************************************************************** */
/* Animation Visualization */
@ -706,31 +706,39 @@ int where_on_path(Object *ob, float ctime, float vec[4], float dir[3], float qua
#define DUPLILIST_FOR_RENDER 2
#define DUPLILIST_ANIMATED 4
static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], int lay, int index, int par_index, int type, short flag)
static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], int lay,
int persistent_id[MAX_DUPLI_RECUR], int level, int index, int type, short flag)
{
DupliObject *dob = MEM_callocN(sizeof(DupliObject), "dupliobject");
int i;
BLI_addtail(lb, dob);
dob->ob = ob;
copy_m4_m4(dob->mat, mat);
copy_m4_m4(dob->omat, ob->obmat);
dob->origlay = ob->lay;
dob->index = index;
dob->particle_index = par_index;
dob->type = type;
dob->animated = (type == OB_DUPLIGROUP) && (flag & DUPLILIST_ANIMATED);
ob->lay = lay;
/* set persistent id, which is an array with a persistent index for each level
* (particle number, vertex number, ..). by comparing this we can find the same
* dupli object between frames, which is needed for motion blur. last level
* goes first in the array. */
dob->persistent_id[0] = index;
for(i = 1; i < level; i++)
dob->persistent_id[i] = persistent_id[level-1-i];
return dob;
}
static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_index,
static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int persistent_id[MAX_DUPLI_RECUR],
int level, short flag)
{
DupliObject *dob;
Group *group;
GroupObject *go;
float mat[4][4], tmat[4][4];
float mat[4][4], tmat[4][4], id;
if (ob->dup_group == NULL) return;
group = ob->dup_group;
@ -750,7 +758,7 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_inde
if (group_is_animated(ob, group))
flag |= DUPLILIST_ANIMATED;
for (go = group->gobject.first; go; go = go->next) {
for (go = group->gobject.first, id = 0; go; go = go->next, id++) {
/* note, if you check on layer here, render goes wrong... it still deforms verts and uses parent imat */
if (go->ob != ob) {
@ -764,7 +772,7 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_inde
mult_m4_m4m4(mat, ob->obmat, go->ob->obmat);
}
dob = new_dupli_object(lb, go->ob, mat, ob->lay, 0, par_index, OB_DUPLIGROUP, flag);
dob = new_dupli_object(lb, go->ob, mat, ob->lay, persistent_id, level, id, OB_DUPLIGROUP, flag);
/* check the group instance and object layers match, also that the object visible flags are ok. */
if ((dob->origlay & group->layer) == 0 ||
@ -779,14 +787,14 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_inde
if (go->ob->transflag & OB_DUPLI) {
copy_m4_m4(dob->ob->obmat, dob->mat);
object_duplilist_recursive(&group->id, scene, go->ob, lb, ob->obmat, par_index, level + 1, flag);
object_duplilist_recursive(&group->id, scene, go->ob, lb, ob->obmat, persistent_id, level + 1, id, flag);
copy_m4_m4(dob->ob->obmat, dob->omat);
}
}
}
}
static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_index, int level, short flag)
static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int persistent_id[MAX_DUPLI_RECUR], int level, short flag)
{
extern int enable_cu_speed; /* object.c */
Object copyob;
@ -834,7 +842,7 @@ static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_ind
BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, (float)scene->r.cfra, ADT_RECALC_ANIM); /* ob-eval will do drivers, so we don't need to do them */
BKE_object_where_is_calc_time(scene, ob, (float)scene->r.cfra);
dob = new_dupli_object(lb, ob, ob->obmat, ob->lay, scene->r.cfra, par_index, OB_DUPLIFRAMES, flag);
dob = new_dupli_object(lb, ob, ob->obmat, ob->lay, persistent_id, level, scene->r.cfra, OB_DUPLIFRAMES, flag);
copy_m4_m4(dob->omat, copyob.obmat);
}
}
@ -865,7 +873,7 @@ typedef struct VertexDupliData {
Scene *scene;
Object *ob, *par;
float (*orco)[3];
int par_index;
int *persistent_id;
} VertexDupliData;
/* ------------- */
@ -902,7 +910,7 @@ static void vertex_dupli__mapFunc(void *userData, int index, const float co[3],
origlay = vdd->ob->lay;
dob = new_dupli_object(vdd->lb, vdd->ob, obmat, vdd->par->lay, index, vdd->par_index, OB_DUPLIVERTS, vdd->flag);
dob = new_dupli_object(vdd->lb, vdd->ob, obmat, vdd->par->lay, vdd->persistent_id, vdd->level, index, OB_DUPLIVERTS, vdd->flag);
/* restore the original layer so that each dupli will have proper dob->origlay */
vdd->ob->lay = origlay;
@ -914,12 +922,12 @@ static void vertex_dupli__mapFunc(void *userData, int index, const float co[3],
float tmpmat[4][4];
copy_m4_m4(tmpmat, vdd->ob->obmat);
copy_m4_m4(vdd->ob->obmat, obmat); /* pretend we are really this mat */
object_duplilist_recursive((ID *)vdd->id, vdd->scene, vdd->ob, vdd->lb, obmat, vdd->par_index, vdd->level + 1, vdd->flag);
object_duplilist_recursive((ID *)vdd->id, vdd->scene, vdd->ob, vdd->lb, obmat, vdd->persistent_id, vdd->level + 1, index, vdd->flag);
copy_m4_m4(vdd->ob->obmat, tmpmat);
}
}
static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int par_index,
static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int persistent_id[MAX_DUPLI_RECUR],
int level, short flag)
{
Object *ob, *ob_iter;
@ -1004,7 +1012,7 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl
vdd.scene = scene;
vdd.par = par;
copy_m4_m4(vdd.pmat, pmat);
vdd.par_index = par_index;
vdd.persistent_id = persistent_id;
/* mballs have a different dupli handling */
if (ob->type != OB_MBALL) ob->flag |= OB_DONE; /* doesnt render */
@ -1043,7 +1051,7 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl
dm->release(dm);
}
static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int par_index,
static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int persistent_id[MAX_DUPLI_RECUR],
int level, short flag)
{
Object *ob, *ob_iter;
@ -1186,7 +1194,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
copy_m4_m4(tmat, obmat);
mul_m4_m4m3(obmat, tmat, mat);
dob = new_dupli_object(lb, ob, obmat, par->lay, a, par_index, OB_DUPLIFACES, (flag & DUPLILIST_ANIMATED));
dob = new_dupli_object(lb, ob, obmat, par->lay, persistent_id, level, a, OB_DUPLIFACES, (flag & DUPLILIST_ANIMATED));
if (flag & DUPLILIST_FOR_RENDER) {
w = 1.0f / (float)mp->totloop;
@ -1209,7 +1217,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
float tmpmat[4][4];
copy_m4_m4(tmpmat, ob->obmat);
copy_m4_m4(ob->obmat, obmat); /* pretend we are really this mat */
object_duplilist_recursive((ID *)id, scene, ob, lb, ob->obmat, par_index, level + 1, flag);
object_duplilist_recursive((ID *)id, scene, ob, lb, ob->obmat, persistent_id, level + 1, a, flag);
copy_m4_m4(ob->obmat, tmpmat);
}
}
@ -1229,7 +1237,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa
dm->release(dm);
}
static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int UNUSED(par_index), ParticleSystem *psys,
static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int persistent_id[MAX_DUPLI_RECUR], ParticleSystem *psys,
int level, short flag)
{
GroupObject *go;
@ -1244,7 +1252,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
float ctime, pa_time, scale = 1.0f;
float tmat[4][4], mat[4][4], pamat[4][4], vec[3], size = 0.0;
float (*obmat)[4], (*oldobmat)[4];
int a, b, counter, index, hair = 0;
int a, b, hair = 0;
int totpart, totchild, totgroup = 0 /*, pa_num */;
int no_draw_flag = PARS_UNEXIST;
@ -1360,8 +1368,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
else
a = totpart;
index = 0;
for (pa = psys->particles, counter = 0; a < totpart + totchild; a++, pa++, counter++) {
for (pa = psys->particles; a < totpart + totchild; a++, pa++) {
if (a < totpart) {
/* handle parent particle */
if (pa->flag & no_draw_flag)
@ -1456,7 +1463,8 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
else
copy_m4_m4(mat, tmat);
dob = new_dupli_object(lb, go->ob, mat, par->lay, counter, index, OB_DUPLIPARTS, (flag & DUPLILIST_ANIMATED));
dob = new_dupli_object(lb, go->ob, mat, par->lay, persistent_id, level, a, OB_DUPLIPARTS, (flag & DUPLILIST_ANIMATED));
dob->particle_system = psys;
copy_m4_m4(dob->omat, obcopylist[b].obmat);
if (flag & DUPLILIST_FOR_RENDER)
psys_get_dupli_texture(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco);
@ -1516,14 +1524,12 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p
if (part->draw & PART_DRAW_GLOBAL_OB)
add_v3_v3v3(mat[3], mat[3], vec);
dob = new_dupli_object(lb, ob, mat, ob->lay, counter, index, GS(id->name) == ID_GR ? OB_DUPLIGROUP : OB_DUPLIPARTS, (flag & DUPLILIST_ANIMATED));
dob = new_dupli_object(lb, ob, mat, ob->lay, persistent_id, level, a, GS(id->name) == ID_GR ? OB_DUPLIGROUP : OB_DUPLIPARTS, (flag & DUPLILIST_ANIMATED));
dob->particle_system = psys;
copy_m4_m4(dob->omat, oldobmat);
if (flag & DUPLILIST_FOR_RENDER)
psys_get_dupli_texture(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco);
}
/* only counts visible particles */
index++;
}
/* restore objects since they were changed in BKE_object_where_is_calc_time */
@ -1570,7 +1576,7 @@ static Object *find_family_object(Object **obar, char *family, char ch)
}
static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int par_index, int level, short flag)
static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int persistent_id[MAX_DUPLI_RECUR], int level, short flag)
{
Object *ob, *obar[256] = {NULL};
Curve *cu;
@ -1609,7 +1615,7 @@ static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int par_inde
copy_m4_m4(obmat, par->obmat);
copy_v3_v3(obmat[3], vec);
new_dupli_object(lb, ob, obmat, par->lay, a, par_index, OB_DUPLIVERTS, flag);
new_dupli_object(lb, ob, obmat, par->lay, persistent_id, level, a, OB_DUPLIVERTS, flag);
}
}
@ -1618,8 +1624,8 @@ static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int par_inde
/* ------------- */
static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4], int par_index,
int level, short flag)
static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4],
int persistent_id[MAX_DUPLI_RECUR], int level, int index, short flag)
{
if ((ob->transflag & OB_DUPLI) == 0)
return;
@ -1636,34 +1642,45 @@ static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBas
}
}
/* keep track of persistent id */
if(level > 0)
persistent_id[level-1] = index;
if (ob->transflag & OB_DUPLIPARTS) {
ParticleSystem *psys = ob->particlesystem.first;
for (; psys; psys = psys->next)
new_particle_duplilist(duplilist, id, scene, ob, par_space_mat, par_index, psys, level + 1, flag);
int psysid = 0;
/* particle system take up one level in id, the particles another */
for (; psys; psys = psys->next, psysid++) {
persistent_id[level] = psysid;
new_particle_duplilist(duplilist, id, scene, ob, par_space_mat, persistent_id, psys, level + 2, flag);
}
persistent_id[level] = 0;
}
else if (ob->transflag & OB_DUPLIVERTS) {
if (ob->type == OB_MESH) {
vertex_duplilist(duplilist, id, scene, ob, par_space_mat, par_index, level + 1, flag);
vertex_duplilist(duplilist, id, scene, ob, par_space_mat, persistent_id, level + 1, flag);
}
else if (ob->type == OB_FONT) {
if (GS(id->name) == ID_SCE) { /* TODO - support dupligroups */
font_duplilist(duplilist, scene, ob, par_index, level + 1, flag);
font_duplilist(duplilist, scene, ob, persistent_id, level + 1, flag);
}
}
}
else if (ob->transflag & OB_DUPLIFACES) {
if (ob->type == OB_MESH)
face_duplilist(duplilist, id, scene, ob, par_space_mat, par_index, level + 1, flag);
face_duplilist(duplilist, id, scene, ob, par_space_mat, persistent_id, level + 1, flag);
}
else if (ob->transflag & OB_DUPLIFRAMES) {
if (GS(id->name) == ID_SCE) { /* TODO - support dupligroups */
frames_duplilist(duplilist, scene, ob, par_index, level + 1, flag);
frames_duplilist(duplilist, scene, ob, persistent_id, level + 1, flag);
}
}
else if (ob->transflag & OB_DUPLIGROUP) {
DupliObject *dob;
group_duplilist(duplilist, scene, ob, par_index, level + 1, flag); /* now recursive */
group_duplilist(duplilist, scene, ob, persistent_id, level + 1, flag); /* now recursive */
if (level == 0) {
for (dob = duplilist->first; dob; dob = dob->next)
@ -1671,6 +1688,10 @@ static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBas
copy_m4_m4(dob->ob->obmat, dob->mat);
}
}
/* clear persistent id */
if(level > 0)
persistent_id[level-1] = 0;
}
/* Returns a list of DupliObject
@ -1678,13 +1699,14 @@ static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBas
ListBase *object_duplilist_ex(Scene *sce, Object *ob, int update, int for_render)
{
ListBase *duplilist = MEM_mallocN(sizeof(ListBase), "duplilist");
int persistent_id[MAX_DUPLI_RECUR] = {0};
int flag = 0;
if (update) flag |= DUPLILIST_DO_UPDATE;
if (for_render) flag |= DUPLILIST_FOR_RENDER;
duplilist->first = duplilist->last = NULL;
object_duplilist_recursive((ID *)sce, sce, ob, duplilist, NULL, 0, 0, flag);
object_duplilist_recursive((ID *)sce, sce, ob, duplilist, NULL, persistent_id, 0, 0, flag);
return duplilist;
}

@ -1136,7 +1136,7 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base,
if (dupli_gh)
BLI_ghash_insert(dupli_gh, dob, ob);
if (parent_gh)
BLI_ghash_insert(parent_gh, BLI_ghashutil_pairalloc(dob->ob, SET_INT_IN_POINTER(dob->index)), ob);
BLI_ghash_insert(parent_gh, BLI_ghashutil_pairalloc(dob->ob, SET_INT_IN_POINTER(dob->persistent_id[0])), ob);
}
if (use_hierarchy) {
@ -1150,7 +1150,7 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base,
/* find parent that was also made real */
if (ob_src_par) {
GHashPair *pair = BLI_ghashutil_pairalloc(ob_src_par, SET_INT_IN_POINTER(dob->index));
GHashPair *pair = BLI_ghashutil_pairalloc(ob_src_par, SET_INT_IN_POINTER(dob->persistent_id[0]));
ob_dst_par = BLI_ghash_lookup(parent_gh, pair);
BLI_ghashutil_pairfree(pair);
}

@ -297,22 +297,19 @@ typedef struct ObHook {
typedef struct DupliObject {
struct DupliObject *next, *prev;
struct Object *ob;
unsigned int origlay;
int index;
unsigned int origlay, pad;
float mat[4][4], omat[4][4];
float orco[3], uv[2];
short type; /* from Object.transflag */
char no_draw, animated;
/* Lowest-level particle index.
* Note: This is needed for particle info in shaders.
* Otherwise dupli groups in particle systems would override the
* index value from higher dupli levels. Would be nice to have full generic access
* to all dupli levels somehow, but for now this should cover most use-cases.
*/
int particle_index;
int pad;
/* persistent identifier for a dupli object, for inter-frame matching of
* objects with motion blur, or inter-update matching for syncing */
int persistent_id[8]; /* MAX_DUPLI_RECUR */
/* particle this dupli was generated from */
struct ParticleSystem *particle_system;
} DupliObject;
/* **************** OBJECT ********************* */

@ -1419,6 +1419,12 @@ int rna_Camera_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
return ((Object *)value.id.data)->type == OB_CAMERA;
}
int rna_DupliObject_index_get(PointerRNA *ptr)
{
DupliObject *dob = (DupliObject *)ptr->data;
return dob->persistent_id[0];
}
#else
static int rna_matrix_dimsize_4x4[] = {4, 4};
@ -2653,22 +2659,23 @@ static void rna_def_dupli_object(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Hide", "Don't show dupli object in viewport or render");
prop = RNA_def_property(srna, "index", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "index");
RNA_def_property_int_funcs(prop, "rna_DupliObject_index_get", NULL, NULL);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Index", "Index in the lowest-level dupli list");
prop = RNA_def_property(srna, "particle_index", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "particle_index");
prop = RNA_def_property(srna, "persistent_id", PROP_INT, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Particle Index", "Index in the lowest-level particle dupli list");
RNA_def_property_ui_text(prop, "Persistent ID", "Persistent identifier for inter-frame matching of objects with motion blur");
prop = RNA_def_property(srna, "particle_system", PROP_POINTER, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Particle System", "Particle system that this dupli object was instanced from");
prop = RNA_def_property(srna, "orco", PROP_FLOAT, PROP_TRANSLATION);
RNA_def_property_float_sdna(prop, NULL, "orco");
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Generated Coordinates", "Generated coordinates in parent object space");
prop = RNA_def_property(srna, "uv", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "uv");
RNA_def_property_array(prop, 2);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
RNA_def_property_ui_text(prop, "UV Coordinates", "UV coordinates in parent object space");

@ -4501,7 +4501,7 @@ static void add_render_object(Render *re, Object *ob, Object *par, DupliObject *
ParticleSystem *psys;
int show_emitter, allow_render= 1, index, psysindex, i;
index= (dob)? dob->index: 0;
index= (dob)? dob->persistent_id[0]: 0;
/* the emitter has to be processed first (render levels of modifiers) */
/* so here we only check if the emitter should be rendered */
@ -4900,7 +4900,7 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp
if (dob->type != OB_DUPLIGROUP || (obr=find_dupligroup_dupli(re, obd, 0))) {
mult_m4_m4m4(mat, re->viewmat, dob->mat);
/* ob = particle system, use that layer */
obi= RE_addRenderInstance(re, NULL, obd, ob, dob->index, 0, mat, ob->lay);
obi= RE_addRenderInstance(re, NULL, obd, ob, dob->persistent_id[0], 0, mat, ob->lay);
/* fill in instance variables for texturing */
set_dupli_tex_mat(re, obi, dob);
@ -4927,7 +4927,7 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp
if (dob->type != OB_DUPLIGROUP || (obr=find_dupligroup_dupli(re, obd, psysindex))) {
if (obi == NULL)
mult_m4_m4m4(mat, re->viewmat, dob->mat);
obi= RE_addRenderInstance(re, NULL, obd, ob, dob->index, psysindex++, mat, obd->lay);
obi= RE_addRenderInstance(re, NULL, obd, ob, dob->persistent_id[0], psysindex++, mat, obd->lay);
set_dupli_tex_mat(re, obi, dob);
if (dob->type != OB_DUPLIGROUP) {