[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50294] trunk/blender/intern/cycles: Fix for #32184 and redesign of particle storage in Cycles.

Lukas Toenne lukas.toenne at googlemail.com
Fri Aug 31 19:27:09 CEST 2012


Revision: 50294
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50294
Author:   lukastoenne
Date:     2012-08-31 17:27:08 +0000 (Fri, 31 Aug 2012)
Log Message:
-----------
Fix for #32184 and redesign of particle storage in Cycles.

The particle data used by the Particle Info node was stored in cycles as a list in each object. This is a problem when the particle emitter mesh is hidden: Objects in cycles are only intended as instances of renderable meshes, so when hiding the emitter mesh the particle data doesn't get stored either. Also the particle data can potentially be copied to multiple instances of the same object, which is a waste of texture space.

The solution in this patch is to make a completely separate list of particle systems in the Cycles scene data. This way the particle data can be generated even when the emitter object itself is not visible.

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.cpp
    trunk/blender/intern/cycles/blender/blender_sync.h
    trunk/blender/intern/cycles/blender/blender_util.h
    trunk/blender/intern/cycles/render/CMakeLists.txt
    trunk/blender/intern/cycles/render/object.cpp
    trunk/blender/intern/cycles/render/object.h
    trunk/blender/intern/cycles/render/scene.cpp
    trunk/blender/intern/cycles/render/scene.h

Added Paths:
-----------
    trunk/blender/intern/cycles/render/particles.cpp
    trunk/blender/intern/cycles/render/particles.h

Modified: trunk/blender/intern/cycles/blender/blender_object.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_object.cpp	2012-08-31 16:10:13 UTC (rev 50293)
+++ trunk/blender/intern/cycles/blender/blender_object.cpp	2012-08-31 17:27:08 UTC (rev 50294)
@@ -247,11 +247,8 @@
 		scene->object_manager->tag_update(scene);
 	}
 
-	/* updated dupli objects require particle sync */
-	bool need_particle_update = object_need_particle_update(b_ob);
-
 	/* object sync */
-	if(object_updated || (object->mesh && object->mesh->need_update) || need_particle_update) {
+	if(object_updated || (object->mesh && object->mesh->need_update)) {
 		object->name = b_ob.name().c_str();
 		object->pass_id = b_ob.pass_index();
 		object->tfm = tfm;
@@ -277,10 +274,6 @@
 
 		object->particle_id = particle_id;
 
-		/* particle sync */
-		if (need_particle_update)
-			sync_particles(object, b_ob);
-	
 		object->tag_update(scene);
 	}
 }

Modified: trunk/blender/intern/cycles/blender/blender_particles.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_particles.cpp	2012-08-31 16:10:13 UTC (rev 50293)
+++ trunk/blender/intern/cycles/blender/blender_particles.cpp	2012-08-31 17:27:08 UTC (rev 50294)
@@ -16,9 +16,9 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include "object.h"
+#include "mesh.h"
+#include "particles.h"
 
-#include "mesh.h"
 #include "blender_sync.h"
 #include "blender_util.h"
 
@@ -31,7 +31,7 @@
 
 /* Particles Sync */
 
-bool BlenderSync::object_need_particle_update(BL::Object b_ob)
+bool BlenderSync::psys_need_update(BL::ParticleSystem b_psys)
 {
 	/* Particle data is only needed for
 	 * a) Billboard render mode if object's own material uses particle info
@@ -41,9 +41,7 @@
 	 */
 	bool need_update = false;
 	
-	BL::Object::particle_systems_iterator b_psys;
-	for (b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys) {
-		switch (b_psys->settings().render_type()) {
+	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.
@@ -61,7 +59,7 @@
 		#endif
 		
 		case BL::ParticleSettings::render_type_OBJECT: {
-			BL::Object b_dupli_ob = b_psys->settings().dupli_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);
@@ -73,7 +71,7 @@
 		}
 		
 		case BL::ParticleSettings::render_type_GROUP: {
-			BL::Group b_dupli_group = b_psys->settings().dupli_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) {
@@ -90,7 +88,6 @@
 		default:
 			/* avoid compiler warning */
 			break;
-		}
 	}
 	
 	return need_update;
@@ -117,50 +114,98 @@
 	return b_pa.is_exist() && b_pa.is_visible() && b_pa.alive_state()==BL::Particle::alive_state_ALIVE;
 }
 
+static int psys_count_particles(BL::ParticleSystem b_psys)
+{
+	int tot = 0;
+	BL::ParticleSystem::particles_iterator b_pa;
+	for(b_psys.particles.begin(b_pa); b_pa != b_psys.particles.end(); ++b_pa) {
+		if(use_particle(*b_pa))
+			++tot;
+	}
+	return tot;
+}
+
 int BlenderSync::object_count_particles(BL::Object b_ob)
 {
 	int tot = 0;
 	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 (use_particle_system(*b_psys)) {
-			BL::ParticleSystem::particles_iterator b_pa;
-			for(b_psys->particles.begin(b_pa); b_pa != b_psys->particles.end(); ++b_pa) {
-				if(use_particle(*b_pa))
-					++tot;
-			}
-		}
+		if (use_particle_system(*b_psys))
+			tot += psys_count_particles(*b_psys);
 	}
 	return tot;
 }
 
-void BlenderSync::sync_particles(Object *ob, BL::Object b_ob)
+void BlenderSync::sync_particles(BL::Object b_ob, BL::ParticleSystem b_psys)
 {
-	int tot = object_count_particles(b_ob);
+	/* depending on settings the psys may not even be rendered */
+	if (!use_particle_system(b_psys))
+		return;
 	
-	ob->particles.clear();
-	ob->particles.reserve(tot);
+	/* key to lookup particle system */
+	ParticleSystemKey key(b_ob, b_psys);
+	ParticleSystem *psys;
 	
-	int index;
-	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 (use_particle_system(*b_psys)) {
-			int pa_index = 0;
-			BL::ParticleSystem::particles_iterator b_pa;
-			for(b_psys->particles.begin(b_pa), index = 0; b_pa != b_psys->particles.end(); ++b_pa, ++index) {
-				if(use_particle(*b_pa)) {
-					Particle pa;
-					
-					pa.index = pa_index;
-					pa.age = b_scene.frame_current() - b_pa->birth_time();
-					pa.lifetime = b_pa->lifetime();
-					
-					ob->particles.push_back(pa);
-				}
+	/* 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) {
+		int tot = psys_count_particles(b_psys);
+		psys->particles.clear();
+		psys->particles.reserve(tot);
+		
+		int index = 0;
+		BL::ParticleSystem::particles_iterator b_pa;
+		for(b_psys.particles.begin(b_pa); b_pa != b_psys.particles.end(); ++b_pa) {
+			if(use_particle(*b_pa)) {
+				Particle pa;
 				
-				++pa_index;
+				pa.index = index;
+				pa.age = b_scene.frame_current() - b_pa->birth_time();
+				pa.lifetime = b_pa->lifetime();
+				
+				psys->particles.push_back(pa);
 			}
+			
+			++index;
 		}
 	}
 }
 
+void BlenderSync::sync_particle_systems()
+{
+	/* layer data */
+	uint scene_layer = render_layer.scene_layer;
+	
+	particle_system_map.pre_sync();
+
+	/* object loop */
+	BL::Scene::objects_iterator b_ob;
+	BL::Scene b_sce = b_scene;
+
+	for(; b_sce; b_sce = b_sce.background_set()) {
+		for(b_sce.objects.begin(b_ob); b_ob != b_sce.objects.end(); ++b_ob) {
+			bool hide = (render_layer.use_viewport_visibility)? b_ob->hide(): b_ob->hide_render();
+			uint ob_layer = get_layer(b_ob->layers(), b_ob->layers_local_view(), object_is_light(*b_ob));
+			CYCLES_LOCAL_LAYER_HACK(render_layer.use_localview, ob_layer);
+			hide = hide || !(ob_layer & scene_layer);
+
+			if(!hide) {
+				BL::Object::particle_systems_iterator b_psys;
+				for(b_ob->particle_systems.begin(b_psys); b_psys != b_ob->particle_systems.end(); ++b_psys)
+					sync_particles(*b_ob, *b_psys);
+			}
+		}
+	}
+
+	/* handle removed data and modified pointers */
+	if(particle_system_map.post_sync())
+		scene->particle_system_manager->tag_update(scene);
+}
+
 CCL_NAMESPACE_END

Modified: trunk/blender/intern/cycles/blender/blender_sync.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_sync.cpp	2012-08-31 16:10:13 UTC (rev 50293)
+++ trunk/blender/intern/cycles/blender/blender_sync.cpp	2012-08-31 17:27:08 UTC (rev 50294)
@@ -46,6 +46,7 @@
   object_map(&scene_->objects),
   mesh_map(&scene_->meshes),
   light_map(&scene_->lights),
+  particle_system_map(&scene_->particle_systems),
   world_map(NULL),
   world_recalc(false),
   experimental(false)
@@ -95,6 +96,12 @@
 			if(b_ob->is_updated_data() || b_ob->data().is_updated())
 				light_map.set_recalc(*b_ob);
 		}
+		
+		if(b_ob->is_updated_data() || b_ob->data().is_updated()) {
+			BL::Object::particle_systems_iterator b_psys;
+			for (b_ob->particle_systems.begin(b_psys); b_psys != b_ob->particle_systems.end(); ++b_psys)
+				particle_system_map.set_recalc(*b_ob);
+		}
 	}
 
 	BL::BlendData::meshes_iterator b_mesh;
@@ -118,6 +125,7 @@
 		object_map.has_recalc() ||
 		light_map.has_recalc() ||
 		mesh_map.has_recalc() ||
+		particle_system_map.has_recalc() ||
 		BlendDataObjects_is_updated_get(&b_data.ptr) ||
 		world_recalc;
 
@@ -131,6 +139,7 @@
 	sync_film();
 	sync_shaders();
 	sync_objects(b_v3d);
+	sync_particle_systems();
 	sync_motion(b_v3d, b_override);
 }
 

Modified: trunk/blender/intern/cycles/blender/blender_sync.h
===================================================================
--- trunk/blender/intern/cycles/blender/blender_sync.h	2012-08-31 16:10:13 UTC (rev 50293)
+++ trunk/blender/intern/cycles/blender/blender_sync.h	2012-08-31 17:27:08 UTC (rev 50294)
@@ -77,6 +77,7 @@
 	void sync_world();
 	void sync_render_layers(BL::SpaceView3D b_v3d, const char *layer);
 	void sync_shaders();
+	void sync_particle_systems();
 
 	void sync_nodes(Shader *shader, BL::ShaderNodeTree b_ntree);
 	Mesh *sync_mesh(BL::Object b_ob, bool object_updated);
@@ -85,14 +86,14 @@
 	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(Object *ob, BL::Object b_ob);
+	void sync_particles(BL::Object b_ob, BL::ParticleSystem b_psys);
 
 	/* 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 object_need_particle_update(BL::Object b_ob);
+	bool psys_need_update(BL::ParticleSystem b_psys);
 	int object_count_particles(BL::Object b_ob);
 
 	/* variables */
@@ -103,6 +104,7 @@
 	id_map<ObjectKey, Object> object_map;
 	id_map<void*, Mesh> mesh_map;
 	id_map<ObjectKey, Light> light_map;
+	id_map<ParticleSystemKey, ParticleSystem> particle_system_map;
 	set<Mesh*> mesh_synced;
 	void *world_map;
 	bool world_recalc;

Modified: trunk/blender/intern/cycles/blender/blender_util.h
===================================================================
--- trunk/blender/intern/cycles/blender/blender_util.h	2012-08-31 16:10:13 UTC (rev 50293)
+++ trunk/blender/intern/cycles/blender/blender_util.h	2012-08-31 17:27:08 UTC (rev 50294)
@@ -389,6 +389,17 @@
 	{ return (parent < k.parent || (parent == k.parent && (index < k.index || (index == k.index && ob < k.ob)))); }
 };
 
+struct ParticleSystemKey {
+	void *ob;
+	void *psys;
+
+	ParticleSystemKey(void *ob_, void *psys_)
+	: ob(ob_), psys(psys_) {}
+
+	bool operator<(const ParticleSystemKey& k) const
+	{ return (ob < k.ob && psys < k.psys); }
+};
+
 CCL_NAMESPACE_END
 
 #endif /* __BLENDER_UTIL_H__ */


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list