diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-12-18 20:18:00 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-12-21 18:05:48 +0300 |
commit | 0edd93effbc1c0adf7aa9c5647ef69845496f669 (patch) | |
tree | 66cf32ac697824226fa8de790b0d70ada5ce42b5 /source/blender/blenkernel | |
parent | adec52a8a843a5224e1e59a1dfdcff4986d7dc18 (diff) |
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
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_object.h | 15 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 43 |
2 files changed, 33 insertions, 25 deletions
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)) { + visibility &= ~OB_VISIBLE_SELF; + } + break; + case DAG_EVAL_RENDER: + if (!(ob->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER)) { + visibility &= ~OB_VISIBLE_SELF; + } + break; + } } + + return visibility; } bool BKE_object_exists_check(Main *bmain, const Object *obtest) |