[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [52014] trunk/blender: Fix #33113: cycles not rendering motion blur correct with dying particles.

Brecht Van Lommel brechtvanlommel at pandora.be
Thu Nov 8 17:35:28 CET 2012


Revision: 52014
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52014
Author:   blendix
Date:     2012-11-08 16:35:28 +0000 (Thu, 08 Nov 2012)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/intern/cycles/blender/blender_object.cpp
    trunk/blender/intern/cycles/blender/blender_particles.cpp
    trunk/blender/intern/cycles/blender/blender_sync.h
    trunk/blender/intern/cycles/blender/blender_util.h
    trunk/blender/intern/cycles/render/particles.cpp
    trunk/blender/source/blender/blenkernel/intern/anim.c
    trunk/blender/source/blender/editors/object/object_add.c
    trunk/blender/source/blender/makesdna/DNA_object_types.h
    trunk/blender/source/blender/makesrna/intern/rna_object.c
    trunk/blender/source/blender/render/intern/source/convertblender.c

Modified: trunk/blender/intern/cycles/blender/blender_object.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_object.cpp	2012-11-08 16:35:20 UTC (rev 52013)
+++ trunk/blender/intern/cycles/blender/blender_object.cpp	2012-11-08 16:35:28 UTC (rev 52014)
@@ -86,11 +86,11 @@
 
 /* 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 @@
 
 /* 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 @@
 				sync_mesh_motion(b_ob, object->mesh, motion);
 		}
 
-		return;
+		return object;
 	}
 
 	/* test if we need to sync */
@@ -248,13 +249,14 @@
 	/* 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 @@
 		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 @@
 			object->dupli_uv = make_float2(0.0f, 0.0f);
 		}
 
-		object->particle_id = particle_id;
-
 		object->tag_update(scene);
 	}
+
+	return object;
 }
 
 /* Object Loop */
@@ -314,8 +319,10 @@
 	/* 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;
 
 	for(; b_sce && !cancel; b_sce = b_sce.background_set()) {
@@ -327,16 +334,14 @@
 			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 @@
 						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 @@
 						}
 
 						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);
-
 					if(b_psys->settings().use_render_emitter())
 						hide = false;
 				}
@@ -377,10 +396,8 @@
 				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();

Modified: trunk/blender/intern/cycles/blender/blender_particles.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_particles.cpp	2012-11-08 16:35:20 UTC (rev 52013)
+++ trunk/blender/intern/cycles/blender/blender_particles.cpp	2012-11-08 16:35:28 UTC (rev 52014)
@@ -17,6 +17,7 @@
  */
 
 #include "mesh.h"
+#include "object.h"
 #include "particles.h"
 
 #include "blender_sync.h"
@@ -28,170 +29,57 @@
 
 /* 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;
-	}
-	
-	return need_update;
-}
+	/* test if this dupli was generated from a particle sytem */
+	BL::ParticleSystem b_psys = b_dup.particle_system();
+	if(!b_psys)
+		return false;
 
-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
-	
-	return true;
-}
+	/* test if we need particle data */
+	if(!object->mesh->need_attribute(scene, ATTR_STD_PARTICLE))
+		return false;
 
-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);
-}
+	/* don't handle child particles yet */
+	BL::Array<int, OBJECT_PERSISTENT_ID_SIZE> persistent_id = b_dup.persistent_id();
 
-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;
+	if(persistent_id[0] >= b_psys.particles.length())
+		return false;
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list