[Bf-blender-cvs] [0edd93effbc] master: Fix inconsistent/broken Cycles object visibility for instances.

Brecht Van Lommel noreply at git.blender.org
Fri Dec 21 16:06:44 CET 2018


Commit: 0edd93effbc1c0adf7aa9c5647ef69845496f669
Author: Brecht Van Lommel
Date:   Tue Dec 18 18:18:00 2018 +0100
Branches: master
https://developer.blender.org/rB0edd93effbc1c0adf7aa9c5647ef69845496f669

Fix inconsistent/broken Cycles object visibility for instances.

Object visibility is now handled by the depsgraph iterator, but this API
was incomplete as it made no distinction for visibility of the object itself,
particles and generated instances.

The depsgraph iterator API now includes information about which part of the
object is visible, and this is used by Cycles to replace the old custom logic.
Cycles and EEVEE visibility should now be consistent, which unfortunately does
means some subtle compatibility breakage for both.

Fixes T58956, T58202, T59284.

Differential Revision: https://developer.blender.org/D4109

===================================================================

M	intern/cycles/blender/blender_mesh.cpp
M	intern/cycles/blender/blender_object.cpp
M	intern/cycles/blender/blender_sync.h
M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/intern/object.c
M	source/blender/depsgraph/DEG_depsgraph_query.h
M	source/blender/depsgraph/intern/depsgraph_query_iter.cc
M	source/blender/draw/engines/eevee/eevee_engine.c
M	source/blender/draw/engines/eevee/eevee_lightcache.c
M	source/blender/draw/engines/eevee/eevee_render.c
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_render.c
M	source/blender/draw/engines/workbench/workbench_deferred.c
M	source/blender/draw/engines/workbench/workbench_forward.c
M	source/blender/draw/intern/DRW_render.h
M	source/blender/draw/intern/draw_manager.c
M	source/blender/draw/modes/object_mode.c
M	source/blender/makesdna/DNA_object_types.h
M	source/blender/makesrna/intern/rna_depsgraph.c

===================================================================

diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index b27de775c54..701dba61b50 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -979,7 +979,8 @@ Mesh *BlenderSync::sync_mesh(BL::Depsgraph& b_depsgraph,
                              BL::Object& b_ob,
                              BL::Object& b_ob_instance,
                              bool object_updated,
-                             bool hide_tris)
+                             bool show_self,
+                             bool show_particles)
 {
 	/* test if we can instance or if the object is modified */
 	BL::ID b_ob_data = b_ob.data();
@@ -1086,7 +1087,7 @@ Mesh *BlenderSync::sync_mesh(BL::Depsgraph& b_depsgraph,
 		                                 mesh->subdivision_type);
 
 		if(b_mesh) {
-			if(view_layer.use_surfaces && !hide_tris) {
+			if(view_layer.use_surfaces && show_self) {
 				if(mesh->subdivision_type != Mesh::SUBDIVISION_NONE)
 					create_subd_mesh(scene, mesh, b_ob, b_mesh, used_shaders,
 					                 dicing_rate, max_subdivisions);
@@ -1096,7 +1097,7 @@ Mesh *BlenderSync::sync_mesh(BL::Depsgraph& b_depsgraph,
 				create_mesh_volume_attributes(scene, b_ob, mesh, b_scene.frame_current());
 			}
 
-			if(view_layer.use_hair && mesh->subdivision_type == Mesh::SUBDIVISION_NONE)
+			if(view_layer.use_hair && show_particles && mesh->subdivision_type == Mesh::SUBDIVISION_NONE)
 				sync_curves(mesh, b_mesh, b_ob, false);
 
 			/* free derived mesh */
diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp
index bcab5276060..0f9994847c0 100644
--- a/intern/cycles/blender/blender_object.cpp
+++ b/intern/cycles/blender/blender_object.cpp
@@ -295,7 +295,8 @@ Object *BlenderSync::sync_object(BL::Depsgraph& b_depsgraph,
                                  BL::ViewLayer& b_view_layer,
                                  BL::DepsgraphObjectInstance& b_instance,
                                  float motion_time,
-                                 bool hide_tris,
+                                 bool show_self,
+                                 bool show_particles,
                                  BlenderObjectCulling& culling,
                                  bool *use_portal)
 {
@@ -403,7 +404,7 @@ Object *BlenderSync::sync_object(BL::Depsgraph& b_depsgraph,
 		object_updated = true;
 
 	/* mesh sync */
-	object->mesh = sync_mesh(b_depsgraph, b_ob, b_ob_instance, object_updated, hide_tris);
+	object->mesh = sync_mesh(b_depsgraph, b_ob, b_ob_instance, object_updated, show_self, show_particles);
 
 	/* special case not tracked by object update flags */
 
@@ -505,82 +506,6 @@ Object *BlenderSync::sync_object(BL::Depsgraph& b_depsgraph,
 	return object;
 }
 
-static bool object_render_hide_original(BL::Object::type_enum ob_type,
-                                        BL::Object::instance_type_enum dupli_type)
-{
-	/* metaball exception, they duplicate self */
-	if(ob_type == BL::Object::type_META)
-		return false;
-
-	return (dupli_type == BL::Object::instance_type_VERTS ||
-	        dupli_type == BL::Object::instance_type_FACES ||
-	        dupli_type == BL::Object::instance_type_FRAMES);
-}
-
-static bool object_render_hide(BL::Object& b_ob,
-                               bool top_level,
-                               bool parent_hide,
-                               bool& hide_triangles,
-                               BL::Depsgraph::mode_enum depsgraph_mode)
-{
-	/* check if we should render or hide particle emitter */
-	BL::Object::particle_systems_iterator b_psys;
-
-	bool hair_present = false;
-	bool has_particles = false;
-	bool show_emitter = false;
-	bool hide_emitter = false;
-	bool hide_as_dupli_parent = false;
-	bool hide_as_dupli_child_original = false;
-
-	for(b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys) {
-		if((b_psys->settings().render_type() == BL::ParticleSettings::render_type_PATH) &&
-		   (b_psys->settings().type()==BL::ParticleSettings::type_HAIR))
-			hair_present = true;
-		has_particles = true;
-	}
-
-	/* Both mode_PREVIEW and mode_VIEWPORT are treated the same here.*/
-	const bool show_instancer = depsgraph_mode == BL::Depsgraph::mode_RENDER
-	                             ? b_ob.show_instancer_for_render()
-	                             : b_ob.show_instancer_for_viewport();
-
-	if(has_particles) {
-		show_emitter = show_instancer;
-		hide_emitter = !show_emitter;
-	} else if(b_ob.is_instancer()) {
-		if(top_level || show_instancer) {
-			hide_as_dupli_parent = true;
-		}
-	}
-
-	/* hide original object for duplis */
-	BL::Object parent = b_ob.parent();
-	while(parent) {
-		if(object_render_hide_original(b_ob.type(),
-		                               parent.instance_type()))
-		{
-			if(parent_hide) {
-				hide_as_dupli_child_original = true;
-				break;
-			}
-		}
-		parent = parent.parent();
-	}
-
-	hide_triangles = hide_emitter;
-
-	if(show_emitter) {
-		return false;
-	}
-	else if(hair_present) {
-		return hide_as_dupli_child_original;
-	}
-	else {
-		return (hide_as_dupli_parent || hide_as_dupli_child_original);
-	}
-}
-
 /* Object Loop */
 
 void BlenderSync::sync_objects(BL::Depsgraph& b_depsgraph, float motion_time)
@@ -608,7 +533,6 @@ void BlenderSync::sync_objects(BL::Depsgraph& b_depsgraph, float motion_time)
 	bool use_portal = false;
 
 	BL::ViewLayer b_view_layer = b_depsgraph.view_layer_eval();
-	BL::Depsgraph::mode_enum depsgraph_mode = b_depsgraph.mode();
 
 	BL::Depsgraph::object_instances_iterator b_instance_iter;
 	for(b_depsgraph.object_instances.begin(b_instance_iter);
@@ -624,15 +548,17 @@ void BlenderSync::sync_objects(BL::Depsgraph& b_depsgraph, float motion_time)
 		culling.init_object(scene, b_ob);
 
 		/* test if object needs to be hidden */
-		bool hide_tris;
+		const bool show_self = b_instance.show_self();
+		const bool show_particles = b_instance.show_particles();
 
-		 if(!object_render_hide(b_ob, true, true, hide_tris, depsgraph_mode)) {
+		 if(show_self || show_particles) {
 			/* object itself */
 			sync_object(b_depsgraph,
 			            b_view_layer,
 			            b_instance,
 			            motion_time,
-			            hide_tris,
+			            show_self,
+			            show_particles,
 			            culling,
 			            &use_portal);
 		 }
diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h
index 8af0de39a47..7290ea0cee0 100644
--- a/intern/cycles/blender/blender_sync.h
+++ b/intern/cycles/blender/blender_sync.h
@@ -117,7 +117,8 @@ private:
 	                BL::Object& b_ob,
 	                BL::Object& b_ob_instance,
 	                bool object_updated,
-	                bool hide_tris);
+	                bool show_self,
+	                bool show_particles);
 	void sync_curves(Mesh *mesh,
 	                 BL::Mesh& b_mesh,
 	                 BL::Object& b_ob,
@@ -127,7 +128,8 @@ private:
 	                    BL::ViewLayer& b_view_layer,
 	                    BL::DepsgraphObjectInstance& b_instance,
 	                    float motion_time,
-	                    bool hide_tris,
+	                    bool show_self,
+	                    bool show_particles,
 	                    BlenderObjectCulling& culling,
 	                    bool *use_portal);
 	void sync_light(BL::Object& b_parent,
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 0b405b52a17..50e095720e0 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -97,13 +97,14 @@ bool BKE_object_is_mode_compat(const struct Object *ob, eObjectMode object_mode)
 
 bool BKE_object_data_is_in_editmode(const struct ID *id);
 
-typedef enum eObjectVisibilityCheck {
-	OB_VISIBILITY_CHECK_FOR_VIEWPORT,
-	OB_VISIBILITY_CHECK_FOR_RENDER,
-	OB_VISIBILITY_CHECK_UNKNOWN_RENDER_MODE,
-} eObjectVisibilityCheck;
-
-bool BKE_object_is_visible(const struct Object *ob, const eObjectVisibilityCheck mode);
+typedef enum eObjectVisibilityResult {
+	OB_VISIBLE_SELF = 1,
+	OB_VISIBLE_PARTICLES = 2,
+	OB_VISIBLE_INSTANCES = 4,
+	OB_VISIBLE_ALL = (OB_VISIBLE_SELF | OB_VISIBLE_PARTICLES | OB_VISIBLE_INSTANCES),
+} eObjectVisibilityResult;
+
+int BKE_object_visibility(const struct Object *ob, const int dag_eval_mode);
 
 void BKE_object_init(struct Object *ob);
 struct Object *BKE_object_add_only_object(
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 3d341f5d82f..fd047c50d2c 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -714,33 +714,40 @@ bool BKE_object_is_mode_compat(const struct Object *ob, eObjectMode object_mode)
 }
 
 /**
- * Return if the object is visible, as evaluated by depsgraph
+ * Return which parts of the object are visible, as evaluated by depsgraph
  */
-bool BKE_object_is_visible(const Object *ob, const eObjectVisibilityCheck mode)
+int BKE_object_visibility(const Object *ob, const int dag_eval_mode)
 {
 	if ((ob->base_flag & BASE_VISIBLE) == 0) {
-		return false;
+		return 0;
 	}
 
-	if (mode == OB_VISIBILITY_CHECK_UNKNOWN_RENDER_MODE) {
-		return true;
+	/* Test which components the object has. */
+	int visibility = OB_VISIBLE_SELF;
+	if (ob->particlesystem.first) {
+		visibility |= OB_VISIBLE_INSTANCES | OB_VISIBLE_PARTICLES;
 	}
-
-	if (((ob->transflag & OB_DUPLI) == 0) &&
-	    (ob->particlesystem.first == NULL))
-	{
-		return true;
+	else if (ob->transflag & OB_DUPLI) {
+		visibility |= OB_VISIBLE_INSTANCES;
 	}
 
-	switch (mode) {
-		case OB_VISIBILITY_CHECK_FOR_VIEWPORT:
-			return ((ob->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT) != 0);
-		case OB_VISIBILITY_CHECK_FOR_RENDER:
-			return ((ob->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER) != 0);
-		default:
-			BLI_assert(!"Object visible test mode not supported.");
-			return false;
+	/* Optional hiding of self if there are particles or instancers. */
+	if (visibility & (OB_VISIBLE_PARTICLES | OB_VISIBLE_INSTANCES)) {
+		switch ((eEvaluationMode)dag_eval_mode) {
+			case DAG_EVAL_VIEWPORT:
+				if (!(ob->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT)) {


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list