From 058eacc7a54fbef0bde8cbd2b55a1e75c2be604c Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 19 May 2023 19:52:11 +0300 Subject: [PATCH 01/14] working viewport --- .../scene_delegate/blender_scene_delegate.cc | 20 ++++----- .../render/hydra/scene_delegate/instancer.cc | 27 ++++++++++- .../render/hydra/scene_delegate/instancer.h | 5 ++- .../render/hydra/scene_delegate/object.cc | 45 ++++++++++++++----- .../render/hydra/scene_delegate/object.h | 1 + 5 files changed, 72 insertions(+), 26 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 7cc48f1e2b47..3380581cfdbb 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -301,9 +301,7 @@ void BlenderSceneDelegate::update_objects(Object *object) if (obj_data) { obj_data->update_parent(); obj_data->update(); - return; - } - if (view3d && !BKE_object_is_visible_in_viewport(view3d, object)) { + obj_data->update_visibility(); return; } objects_[id] = ObjectData::create(this, object, id); @@ -336,14 +334,10 @@ void BlenderSceneDelegate::update_instancers(Object *object) if ((object->transflag & OB_DUPLI) == 0) { return; } - if (view3d && !BKE_object_is_visible_in_viewport(view3d, object)) { - return; - } instancers_[id] = std::make_unique(this, object, id); i_data = instancer_data(id); i_data->init(); i_data->insert(); - i_data->update_visibility(); } void BlenderSceneDelegate::update_world() @@ -388,8 +382,8 @@ void BlenderSceneDelegate::check_updates() switch (GS(id->name)) { case ID_OB: { Object *object = (Object *)id; - update_objects(object); update_instancers(object); + update_objects(object); } break; case ID_MA: { @@ -406,6 +400,10 @@ void BlenderSceneDelegate::check_updates() } break; case ID_SCE: { + if (id->recalc & ID_RECALC_COPY_ON_WRITE && !(id->recalc & ID_RECALC_SELECT)) { + do_update_collection = true; + do_update_visibility = true; + } if (id->recalc & ID_RECALC_BASE_FLAGS) { do_update_visibility = true; } @@ -440,7 +438,7 @@ void BlenderSceneDelegate::add_new_objects() { DEGObjectIterSettings settings = {0}; settings.depsgraph = depsgraph; - settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_VISIBLE | + settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; DEGObjectIterData data = {0}; data.settings = &settings; @@ -535,9 +533,7 @@ void BlenderSceneDelegate::update_visibility() { for (auto &it : objects_) { it.second->update_visibility(); - } - for (auto &it : instancers_) { - it.second->update_visibility(); + it.second->update_parent(); } /* Add objects which were invisible before and not added yet */ diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index e10cd9972574..b1a3edab77c7 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -4,6 +4,9 @@ #include #include +#include "BKE_object.h" +#include "DEG_depsgraph_query.h" + #include "blender_scene_delegate.h" #include "instancer.h" @@ -33,6 +36,23 @@ bool InstancerData::is_supported(Object *object) return false; } +bool InstancerData::is_visible(BlenderSceneDelegate *scene_delegate, + Object *object, + Object *child_object) +{ + bool ret = true; + eEvaluationMode deg_mode = DEG_get_mode(scene_delegate->depsgraph); + ret = BKE_object_visibility(object, deg_mode) & (OB_VISIBLE_SELF | OB_VISIBLE_INSTANCES); + if (ret && child_object && child_object->transflag & OB_DUPLI) + { + int flag = deg_mode == DAG_EVAL_VIEWPORT ? OB_DUPLI_FLAG_VIEWPORT : OB_DUPLI_FLAG_RENDER; + + ret = child_object->duplicator_visibility_flag & flag; + } + return ret; +} + + void InstancerData::init() { ID_LOG(2, ""); @@ -83,9 +103,12 @@ pxr::VtValue InstancerData::get_data(pxr::TfToken const &key) const return ret; } -bool InstancerData::update_visibility() +bool InstancerData::update_visibility(Object *child_object) { - bool ret = ObjectData::update_visibility(); + bool prev_visible = visible; + visible = is_visible(scene_delegate_, (Object *)id, child_object); + bool ret = visible != prev_visible; + if (ret) { auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility); diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index d0454903abf8..af027cea09b2 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -25,6 +25,9 @@ class InstancerData : public ObjectData { public: InstancerData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id); static bool is_supported(Object *object); + static bool is_visible(BlenderSceneDelegate *scene_delegate, + Object *object, + Object *child_object); void init() override; void insert() override; @@ -32,7 +35,7 @@ class InstancerData : public ObjectData { void update() override; pxr::VtValue get_data(pxr::TfToken const &key) const override; - bool update_visibility() override; + bool update_visibility(Object *child_object); pxr::GfMatrix4d get_transform(pxr::SdfPath const &id) const; pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const; diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 3e750df0c72b..e50bae3e2561 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -2,6 +2,7 @@ * Copyright 2011-2022 Blender Foundation */ #include "BKE_object.h" +#include "DEG_depsgraph_query.h" #include "blender_scene_delegate.h" #include "light.h" @@ -59,14 +60,31 @@ bool ObjectData::is_supported(Object *object) return false; } +bool ObjectData::is_visible(BlenderSceneDelegate* scene_delegate, Object* object) { + bool ret = true; + + if (DEG_get_mode(scene_delegate->depsgraph) == DAG_EVAL_VIEWPORT) { + ret = BKE_object_is_visible_in_viewport(scene_delegate->view3d, object); + if (ret && object->transflag & OB_DUPLI) { + ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT; + } + } + /* + else { + if (object->transflag & OB_DUPLI) { + ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; + } + if (object->parent && (object->parent->transflag & OB_DUPLI)) { + ret = false; + } + }*/ + return ret; + } + bool ObjectData::update_visibility() { - if (!scene_delegate_->view3d) { - return false; - } - bool prev_visible = visible; - visible = BKE_object_is_visible_in_viewport(scene_delegate_->view3d, (Object *)id); + visible = is_visible(scene_delegate_, (Object *)id); bool ret = visible != prev_visible; if (ret) { ID_LOG(2, ""); @@ -76,19 +94,24 @@ bool ObjectData::update_visibility() void ObjectData::update_parent() { + bool update_parent = false; Object *object = (Object *)id; if (parent_ != object->parent) { ID_LOG(2, ""); parent_ = object->parent; + update_parent = true; + } - /* Looking for corresponded instancer and update it as parent */ - for (Object *ob = parent_; ob != nullptr; ob = ob->parent) { - InstancerData *i_data = scene_delegate_->instancer_data( - scene_delegate_->instancer_prim_id(ob)); - if (i_data) { + /* Looking for corresponded instancer and update it as parent */ + for (Object *ob = parent_; ob != nullptr; ob = ob->parent) { + InstancerData *i_data = scene_delegate_->instancer_data( + scene_delegate_->instancer_prim_id(ob)); + if (i_data) { + if (update_parent) { i_data->update_as_parent(); - break; } + i_data->update_visibility((Object *)id); + break; } } } diff --git a/source/blender/render/hydra/scene_delegate/object.h b/source/blender/render/hydra/scene_delegate/object.h index b6d5e4e48d5e..6ed40aa579a3 100644 --- a/source/blender/render/hydra/scene_delegate/object.h +++ b/source/blender/render/hydra/scene_delegate/object.h @@ -22,6 +22,7 @@ class ObjectData : public IdData { Object *object, pxr::SdfPath const &prim_id); static bool is_supported(Object *object); + static bool is_visible(BlenderSceneDelegate *scene_delegate, Object *object); virtual bool update_visibility(); void update_parent(); -- 2.30.2 From c4d3435b9e221009e6b4c0aea62d097021ff6b0f Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 19 May 2023 20:05:04 +0300 Subject: [PATCH 02/14] final render --- .../blender/render/hydra/scene_delegate/object.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index e50bae3e2561..e55feaabfa82 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -69,15 +69,16 @@ bool ObjectData::is_visible(BlenderSceneDelegate* scene_delegate, Object* object ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT; } } - /* else { - if (object->transflag & OB_DUPLI) { - ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; - } - if (object->parent && (object->parent->transflag & OB_DUPLI)) { + if (object->parent) { ret = false; } - }*/ + else { + if (object->transflag & OB_DUPLI) { + ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; + } + } + } return ret; } -- 2.30.2 From 14e0207e5e10044b28202020e4a8f762cfef483a Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 19 May 2023 20:06:55 +0300 Subject: [PATCH 03/14] make format --- .../scene_delegate/blender_scene_delegate.cc | 16 +++++++++------- .../render/hydra/scene_delegate/instancer.cc | 11 +++++------ .../blender/render/hydra/scene_delegate/mesh.cc | 3 ++- .../render/hydra/scene_delegate/object.cc | 5 +++-- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 3380581cfdbb..235c6d2228e4 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -370,8 +370,8 @@ void BlenderSceneDelegate::check_updates() DEGIDIterData data = {0}; data.graph = depsgraph; data.only_updated = true; - ITER_BEGIN ( - DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) { + ITER_BEGIN (DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) + { CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, @@ -438,8 +438,7 @@ void BlenderSceneDelegate::add_new_objects() { DEGObjectIterSettings settings = {0}; settings.depsgraph = depsgraph; - settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | - DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; + settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; DEGObjectIterData data = {0}; data.settings = &settings; data.graph = settings.depsgraph; @@ -449,7 +448,8 @@ void BlenderSceneDelegate::add_new_objects() DEG_iterator_objects_end, &data, Object *, - object) { + object) + { update_objects(object); update_instancers(object); @@ -474,7 +474,8 @@ void BlenderSceneDelegate::remove_unused_objects() DEG_iterator_objects_end, &data, Object *, - object) { + object) + { if (ObjectData::is_supported(object)) { available_objects.insert(object_prim_id(object).GetName()); } @@ -550,7 +551,8 @@ void BlenderSceneDelegate::update_visibility() DEG_iterator_objects_end, &data, Object *, - object) { + object) + { if (!object_data(object_prim_id(object))) { update_objects(object); diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index b1a3edab77c7..7d0ab382051e 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -43,16 +43,13 @@ bool InstancerData::is_visible(BlenderSceneDelegate *scene_delegate, bool ret = true; eEvaluationMode deg_mode = DEG_get_mode(scene_delegate->depsgraph); ret = BKE_object_visibility(object, deg_mode) & (OB_VISIBLE_SELF | OB_VISIBLE_INSTANCES); - if (ret && child_object && child_object->transflag & OB_DUPLI) - { + if (ret && child_object && child_object->transflag & OB_DUPLI) { int flag = deg_mode == DAG_EVAL_VIEWPORT ? OB_DUPLI_FLAG_VIEWPORT : OB_DUPLI_FLAG_RENDER; - ret = child_object->duplicator_visibility_flag & flag; } return ret; } - void InstancerData::init() { ID_LOG(2, ""); @@ -86,7 +83,8 @@ void InstancerData::update() Object *object = (Object *)id; if (id->recalc & ID_RECALC_GEOMETRY || (object->data && ((ID *)object->data)->recalc & ID_RECALC_GEOMETRY) || - id->recalc & ID_RECALC_TRANSFORM) { + id->recalc & ID_RECALC_TRANSFORM) + { set_instances(); scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty( prim_id, pxr::HdChangeTracker::AllDirty); @@ -197,7 +195,8 @@ void InstancerData::check_update(Object *object) if (l_it != light_instances_.end()) { Object *obj = (Object *)l_it->second.data->id; if (obj->id.recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY) || - ((ID *)obj->data)->recalc & ID_RECALC_GEOMETRY) { + ((ID *)obj->data)->recalc & ID_RECALC_GEOMETRY) + { set_instances(); } return; diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index 0bae621a101b..dcb47524b7d3 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -27,7 +27,8 @@ void MeshData::init() Object *object = (Object *)id; if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT && - BLI_listbase_is_empty(&object->modifiers)) { + BLI_listbase_is_empty(&object->modifiers)) + { write_mesh((Mesh *)object->data); } else { diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index e55feaabfa82..54a98f2298ae 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -60,7 +60,8 @@ bool ObjectData::is_supported(Object *object) return false; } -bool ObjectData::is_visible(BlenderSceneDelegate* scene_delegate, Object* object) { +bool ObjectData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object) +{ bool ret = true; if (DEG_get_mode(scene_delegate->depsgraph) == DAG_EVAL_VIEWPORT) { @@ -80,7 +81,7 @@ bool ObjectData::is_visible(BlenderSceneDelegate* scene_delegate, Object* object } } return ret; - } +} bool ObjectData::update_visibility() { -- 2.30.2 From 5fb554257704886d5b5a734fe326be35a75a88aa Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 19 May 2023 20:09:31 +0300 Subject: [PATCH 04/14] removed extra line --- source/blender/render/hydra/scene_delegate/instancer.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 7d0ab382051e..1e5a72a2ebb9 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -106,7 +106,6 @@ bool InstancerData::update_visibility(Object *child_object) bool prev_visible = visible; visible = is_visible(scene_delegate_, (Object *)id, child_object); bool ret = visible != prev_visible; - if (ret) { auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility); -- 2.30.2 From 374845b9c150b3d3ab65758ebb3863582ca0a900 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 19 May 2023 20:14:03 +0300 Subject: [PATCH 05/14] changed lines back (no needed to did it) --- .../render/hydra/scene_delegate/blender_scene_delegate.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 235c6d2228e4..539204d377a9 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -382,8 +382,8 @@ void BlenderSceneDelegate::check_updates() switch (GS(id->name)) { case ID_OB: { Object *object = (Object *)id; - update_instancers(object); update_objects(object); + update_instancers(object); } break; case ID_MA: { -- 2.30.2 From 465ef3022b28dd73ade5564bb0155862b30b7b13 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Mon, 22 May 2023 09:54:43 +0300 Subject: [PATCH 06/14] Fixing export of visible objects --- .../scene_delegate/blender_scene_delegate.cc | 34 ++++++++++++++----- .../render/hydra/scene_delegate/instancer.cc | 16 +++++++-- .../render/hydra/scene_delegate/instancer.h | 3 +- .../render/hydra/scene_delegate/object.cc | 23 ++++--------- 4 files changed, 48 insertions(+), 28 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index c3e367a982fe..c7f96ea713a7 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -300,6 +300,7 @@ void BlenderSceneDelegate::update_objects(Object *object) if (!ObjectData::is_supported(object)) { return; } + pxr::SdfPath id = object_prim_id(object); ObjectData *obj_data = object_data(id); if (obj_data) { @@ -308,12 +309,17 @@ void BlenderSceneDelegate::update_objects(Object *object) obj_data->update_visibility(); return; } + + if (!ObjectData::is_visible(this, object)) { + /* Do not export new object if it is invisible */ + return; + } + objects_[id] = ObjectData::create(this, object, id); obj_data = object_data(id); obj_data->update_parent(); obj_data->init(); obj_data->insert(); - obj_data->update_visibility(); } void BlenderSceneDelegate::update_instancers(Object *object) @@ -326,18 +332,26 @@ void BlenderSceneDelegate::update_instancers(Object *object) pxr::SdfPath id = instancer_prim_id(object); InstancerData *i_data = instancer_data(id); if (i_data) { - if (object->transflag & OB_DUPLI) { - i_data->update(); - } - else { + if ((object->transflag & OB_DUPLI) == 0) { + /* Object isn't instancer anymore and should be removed */ i_data->remove(); instancers_.erase(id); + return; } + + i_data->update(); return; } + if ((object->transflag & OB_DUPLI) == 0) { return; } + + if (!InstancerData::is_visible(this, object)) { + /* Do not export new instancer if it is invisible */ + return; + } + instancers_[id] = std::make_unique(this, object, id); i_data = instancer_data(id); i_data->init(); @@ -536,16 +550,18 @@ void BlenderSceneDelegate::remove_unused_objects() void BlenderSceneDelegate::update_visibility() { + /* Updating visibility of existing objects/instancers */ for (auto &it : objects_) { it.second->update_visibility(); - it.second->update_parent(); + } + for (auto &it : instancers_) { + it.second->update_visibility(); } - /* Add objects which were invisible before and not added yet */ + /* Add objects/instancers which were invisible before and not added yet */ DEGObjectIterSettings settings = {0}; settings.depsgraph = depsgraph; - settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_VISIBLE | - DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; + settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET; DEGObjectIterData data = {0}; data.settings = &settings; data.graph = settings.depsgraph; diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 1e5a72a2ebb9..943bcb24d780 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -36,6 +36,17 @@ bool InstancerData::is_supported(Object *object) return false; } +bool InstancerData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object) +{ + bool ret = true; + if (DEG_get_mode(scene_delegate->depsgraph) == DAG_EVAL_VIEWPORT) { + ret = BKE_object_is_visible_in_viewport(scene_delegate->view3d, object); + } + else { + } + return ret; +} + bool InstancerData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object, Object *child_object) @@ -101,11 +112,12 @@ pxr::VtValue InstancerData::get_data(pxr::TfToken const &key) const return ret; } -bool InstancerData::update_visibility(Object *child_object) +bool InstancerData::update_visibility() { bool prev_visible = visible; - visible = is_visible(scene_delegate_, (Object *)id, child_object); + visible = is_visible(scene_delegate_, (Object *)id); bool ret = visible != prev_visible; + if (ret) { auto &change_tracker = scene_delegate_->GetRenderIndex().GetChangeTracker(); change_tracker.MarkInstancerDirty(prim_id, pxr::HdChangeTracker::DirtyVisibility); diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index af027cea09b2..4cee695c4897 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -25,6 +25,7 @@ class InstancerData : public ObjectData { public: InstancerData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id); static bool is_supported(Object *object); + static bool is_visible(BlenderSceneDelegate *scene_delegate, Object *object); static bool is_visible(BlenderSceneDelegate *scene_delegate, Object *object, Object *child_object); @@ -35,7 +36,7 @@ class InstancerData : public ObjectData { void update() override; pxr::VtValue get_data(pxr::TfToken const &key) const override; - bool update_visibility(Object *child_object); + bool update_visibility() override; pxr::GfMatrix4d get_transform(pxr::SdfPath const &id) const; pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const; diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 54a98f2298ae..6474310acc5c 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -87,33 +87,24 @@ bool ObjectData::update_visibility() { bool prev_visible = visible; visible = is_visible(scene_delegate_, (Object *)id); - bool ret = visible != prev_visible; - if (ret) { - ID_LOG(2, ""); - } - return ret; + return visible != prev_visible; } void ObjectData::update_parent() { - bool update_parent = false; Object *object = (Object *)id; if (parent_ != object->parent) { ID_LOG(2, ""); parent_ = object->parent; - update_parent = true; - } - /* Looking for corresponded instancer and update it as parent */ - for (Object *ob = parent_; ob != nullptr; ob = ob->parent) { - InstancerData *i_data = scene_delegate_->instancer_data( - scene_delegate_->instancer_prim_id(ob)); - if (i_data) { - if (update_parent) { + /* Looking for corresponded instancer and update it as parent */ + for (Object *ob = parent_; ob != nullptr; ob = ob->parent) { + InstancerData *i_data = scene_delegate_->instancer_data( + scene_delegate_->instancer_prim_id(ob)); + if (i_data) { i_data->update_as_parent(); + break; } - i_data->update_visibility((Object *)id); - break; } } } -- 2.30.2 From a18ac61a0b3cb0d97708c3af727f9ccb69f8e55a Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Mon, 22 May 2023 11:41:55 +0300 Subject: [PATCH 07/14] Fixed visibility for Final render --- .../render/hydra/scene_delegate/instancer.cc | 19 ++++-------------- .../render/hydra/scene_delegate/instancer.h | 3 --- .../render/hydra/scene_delegate/object.cc | 20 ++++++++++++------- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 943bcb24d780..24b12c1c9f06 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -39,24 +39,13 @@ bool InstancerData::is_supported(Object *object) bool InstancerData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object) { bool ret = true; - if (DEG_get_mode(scene_delegate->depsgraph) == DAG_EVAL_VIEWPORT) { + eEvaluationMode deg_mode = DEG_get_mode(scene_delegate->depsgraph); + if (deg_mode == DAG_EVAL_VIEWPORT) { ret = BKE_object_is_visible_in_viewport(scene_delegate->view3d, object); } else { - } - return ret; -} - -bool InstancerData::is_visible(BlenderSceneDelegate *scene_delegate, - Object *object, - Object *child_object) -{ - bool ret = true; - eEvaluationMode deg_mode = DEG_get_mode(scene_delegate->depsgraph); - ret = BKE_object_visibility(object, deg_mode) & (OB_VISIBLE_SELF | OB_VISIBLE_INSTANCES); - if (ret && child_object && child_object->transflag & OB_DUPLI) { - int flag = deg_mode == DAG_EVAL_VIEWPORT ? OB_DUPLI_FLAG_VIEWPORT : OB_DUPLI_FLAG_RENDER; - ret = child_object->duplicator_visibility_flag & flag; + int vis = BKE_object_visibility(object, deg_mode); + ret = vis & (OB_VISIBLE_SELF | OB_VISIBLE_INSTANCES); } return ret; } diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index 4cee695c4897..749ea85632b1 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -26,9 +26,6 @@ class InstancerData : public ObjectData { InstancerData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id); static bool is_supported(Object *object); static bool is_visible(BlenderSceneDelegate *scene_delegate, Object *object); - static bool is_visible(BlenderSceneDelegate *scene_delegate, - Object *object, - Object *child_object); void init() override; void insert() override; diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 6474310acc5c..521c7b64ca3c 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -63,20 +63,26 @@ bool ObjectData::is_supported(Object *object) bool ObjectData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object) { bool ret = true; - - if (DEG_get_mode(scene_delegate->depsgraph) == DAG_EVAL_VIEWPORT) { + eEvaluationMode deg_mode = DEG_get_mode(scene_delegate->depsgraph); + if (deg_mode == DAG_EVAL_VIEWPORT) { ret = BKE_object_is_visible_in_viewport(scene_delegate->view3d, object); if (ret && object->transflag & OB_DUPLI) { ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT; } } else { - if (object->parent) { - ret = false; + int vis = BKE_object_visibility(object, deg_mode); + ret = vis & OB_VISIBLE_SELF; + if (ret && object->transflag & OB_DUPLI) { + ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; } - else { - if (object->transflag & OB_DUPLI) { - ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; + if (ret) { + /* If some of parent object is instacer, then object is invisible in Final render */ + for (Object *ob = object->parent; ob != nullptr; ob = ob->parent) { + if (ob->transflag & OB_DUPLI) { + ret = false; + break; + } } } } -- 2.30.2 From af51ff7dfea9492c84ce84eff8c7a3779e27b60c Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Tue, 23 May 2023 15:07:24 +0300 Subject: [PATCH 08/14] Added logs for visibility check. Added InstancerData::is_instance_visible() --- .../scene_delegate/blender_scene_delegate.cc | 26 +++++++++++++-- .../render/hydra/scene_delegate/instancer.cc | 32 +++++++++++++++++++ .../render/hydra/scene_delegate/instancer.h | 1 + 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index c7f96ea713a7..7afff358848c 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -3,6 +3,7 @@ #include +#include "BKE_object.h" #include "DEG_depsgraph_query.h" #include "DNA_scene_types.h" @@ -388,9 +389,10 @@ void BlenderSceneDelegate::check_updates() DEGIDIterData data = {0}; data.graph = depsgraph; data.only_updated = true; + eEvaluationMode deg_mode = DEG_get_mode(depsgraph); + ITER_BEGIN (DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) { - CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "Update: %s [%s]", @@ -400,6 +402,11 @@ void BlenderSceneDelegate::check_updates() switch (GS(id->name)) { case ID_OB: { Object *object = (Object *)id; + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, + 2, + "Visibility: %s [%s]", + object->id.name, + std::bitset<3>(BKE_object_visibility(object, deg_mode)).to_string().c_str()); update_objects(object); update_instancers(object); } break; @@ -461,6 +468,8 @@ void BlenderSceneDelegate::add_new_objects() data.settings = &settings; data.graph = settings.depsgraph; data.flag = settings.flags; + eEvaluationMode deg_mode = DEG_get_mode(depsgraph); + ITER_BEGIN (DEG_iterator_objects_begin, DEG_iterator_objects_next, DEG_iterator_objects_end, @@ -468,7 +477,11 @@ void BlenderSceneDelegate::add_new_objects() Object *, object) { - + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, + 2, + "Visibility: %s [%s]", + object->id.name, + std::bitset<3>(BKE_object_visibility(object, deg_mode)).to_string().c_str()); update_objects(object); update_instancers(object); } @@ -487,6 +500,7 @@ void BlenderSceneDelegate::remove_unused_objects() data.settings = &settings; data.graph = settings.depsgraph; data.flag = settings.flags; + ITER_BEGIN (DEG_iterator_objects_begin, DEG_iterator_objects_next, DEG_iterator_objects_end, @@ -566,6 +580,8 @@ void BlenderSceneDelegate::update_visibility() data.settings = &settings; data.graph = settings.depsgraph; data.flag = settings.flags; + eEvaluationMode deg_mode = DEG_get_mode(depsgraph); + ITER_BEGIN (DEG_iterator_objects_begin, DEG_iterator_objects_next, DEG_iterator_objects_end, @@ -573,7 +589,11 @@ void BlenderSceneDelegate::update_visibility() Object *, object) { - + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, + 2, + "Visibility: %s [%s]", + object->id.name, + std::bitset<3>(BKE_object_visibility(object, deg_mode)).to_string().c_str()); if (!object_data(object_prim_id(object))) { update_objects(object); } diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 24b12c1c9f06..cf6751656493 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -257,6 +257,35 @@ void InstancerData::update_double_sided(MaterialData *mat_data) } } +bool InstancerData::is_instance_visible(Object *object) +{ + bool ret = true; + eEvaluationMode deg_mode = DEG_get_mode(scene_delegate_->depsgraph); + if (deg_mode == DAG_EVAL_VIEWPORT) { + ret = BKE_object_is_visible_in_viewport(scene_delegate_->view3d, object); + if (ret && object->transflag & OB_DUPLI) { + ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT; + } + } + else { + int vis = BKE_object_visibility(object, deg_mode); + ret = vis & OB_VISIBLE_SELF; + if (ret && object->transflag & OB_DUPLI) { + ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; + } + //if (ret) { + // /* If some of parent object is instacer, then object is invisible in Final render */ + // for (Object *ob = object->parent; ob != nullptr; ob = ob->parent) { + // if (ob->transflag & OB_DUPLI) { + // ret = false; + // break; + // } + // } + //} + } + return ret; +} + pxr::SdfPath InstancerData::object_prim_id(Object *object) const { /* Making id of object in form like _ */ @@ -296,6 +325,9 @@ void InstancerData::set_instances() if (!is_supported(ob)) { continue; } + if (!is_instance_visible(ob)) { + continue; + } pxr::SdfPath p_id = object_prim_id(ob); if (ob->type == OB_LAMP) { diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index 749ea85632b1..c04b3f65ff90 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -47,6 +47,7 @@ class InstancerData : public ObjectData { void update_double_sided(MaterialData *mat_data); private: + bool is_instance_visible(Object *object); pxr::SdfPath object_prim_id(Object *object) const; pxr::SdfPath light_prim_id(LightInstance const &inst, int index) const; int light_prim_id_index(pxr::SdfPath const &id) const; -- 2.30.2 From aec4f0a1920cb9afdfdc185aa825005b24c2292b Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Tue, 23 May 2023 15:47:38 +0300 Subject: [PATCH 09/14] Fixed viewport visibility --- .../render/hydra/scene_delegate/instancer.cc | 16 +++++++++------- .../render/hydra/scene_delegate/object.cc | 11 ++++++----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index cf6751656493..6fc0414736dc 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -40,11 +40,13 @@ bool InstancerData::is_visible(BlenderSceneDelegate *scene_delegate, Object *obj { bool ret = true; eEvaluationMode deg_mode = DEG_get_mode(scene_delegate->depsgraph); + int vis = BKE_object_visibility(object, deg_mode); if (deg_mode == DAG_EVAL_VIEWPORT) { - ret = BKE_object_is_visible_in_viewport(scene_delegate->view3d, object); + ret = BKE_object_is_visible_in_viewport(scene_delegate->view3d, object) && + (vis & OB_VISIBLE_INSTANCES); } else { - int vis = BKE_object_visibility(object, deg_mode); + vis = BKE_object_visibility(object, deg_mode); ret = vis & (OB_VISIBLE_SELF | OB_VISIBLE_INSTANCES); } return ret; @@ -261,14 +263,14 @@ bool InstancerData::is_instance_visible(Object *object) { bool ret = true; eEvaluationMode deg_mode = DEG_get_mode(scene_delegate_->depsgraph); + int vis = BKE_object_visibility(object, deg_mode); if (deg_mode == DAG_EVAL_VIEWPORT) { - ret = BKE_object_is_visible_in_viewport(scene_delegate_->view3d, object); - if (ret && object->transflag & OB_DUPLI) { - ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT; - } + ret = vis & OB_VISIBLE_SELF; + //if (ret && object->transflag & OB_DUPLI) { + // ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT; + //} } else { - int vis = BKE_object_visibility(object, deg_mode); ret = vis & OB_VISIBLE_SELF; if (ret && object->transflag & OB_DUPLI) { ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 521c7b64ca3c..03f7e099e196 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -64,14 +64,15 @@ bool ObjectData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object { bool ret = true; eEvaluationMode deg_mode = DEG_get_mode(scene_delegate->depsgraph); + int vis = BKE_object_visibility(object, deg_mode); if (deg_mode == DAG_EVAL_VIEWPORT) { - ret = BKE_object_is_visible_in_viewport(scene_delegate->view3d, object); - if (ret && object->transflag & OB_DUPLI) { - ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT; - } + ret = BKE_object_is_visible_in_viewport(scene_delegate->view3d, object) && + (vis & OB_VISIBLE_SELF); + //if (ret && object->transflag & OB_DUPLI) { + // ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT; + //} } else { - int vis = BKE_object_visibility(object, deg_mode); ret = vis & OB_VISIBLE_SELF; if (ret && object->transflag & OB_DUPLI) { ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; -- 2.30.2 From e6874d2199e9b09850faa529d4b70790d722da7b Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Tue, 23 May 2023 17:09:43 +0300 Subject: [PATCH 10/14] Fixed visibility in Final render --- .../render/hydra/scene_delegate/instancer.cc | 44 ++++++------------- .../render/hydra/scene_delegate/object.cc | 15 ++----- 2 files changed, 18 insertions(+), 41 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 6fc0414736dc..21b007abe9b1 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -38,16 +38,23 @@ bool InstancerData::is_supported(Object *object) bool InstancerData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object) { - bool ret = true; eEvaluationMode deg_mode = DEG_get_mode(scene_delegate->depsgraph); int vis = BKE_object_visibility(object, deg_mode); + bool ret = vis & OB_VISIBLE_INSTANCES; if (deg_mode == DAG_EVAL_VIEWPORT) { - ret = BKE_object_is_visible_in_viewport(scene_delegate->view3d, object) && - (vis & OB_VISIBLE_INSTANCES); + ret &= BKE_object_is_visible_in_viewport(scene_delegate->view3d, object); } else { - vis = BKE_object_visibility(object, deg_mode); - ret = vis & (OB_VISIBLE_SELF | OB_VISIBLE_INSTANCES); + if (ret) { + /* If some of parent object is instancer, then currenct object as instancer + * is invisible in Final render */ + for (Object *ob = object->parent; ob != nullptr; ob = ob->parent) { + if (ob->transflag & OB_DUPLI) { + ret = false; + break; + } + } + } } return ret; } @@ -261,31 +268,8 @@ void InstancerData::update_double_sided(MaterialData *mat_data) bool InstancerData::is_instance_visible(Object *object) { - bool ret = true; - eEvaluationMode deg_mode = DEG_get_mode(scene_delegate_->depsgraph); - int vis = BKE_object_visibility(object, deg_mode); - if (deg_mode == DAG_EVAL_VIEWPORT) { - ret = vis & OB_VISIBLE_SELF; - //if (ret && object->transflag & OB_DUPLI) { - // ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT; - //} - } - else { - ret = vis & OB_VISIBLE_SELF; - if (ret && object->transflag & OB_DUPLI) { - ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; - } - //if (ret) { - // /* If some of parent object is instacer, then object is invisible in Final render */ - // for (Object *ob = object->parent; ob != nullptr; ob = ob->parent) { - // if (ob->transflag & OB_DUPLI) { - // ret = false; - // break; - // } - // } - //} - } - return ret; + int vis = BKE_object_visibility(object, DEG_get_mode(scene_delegate_->depsgraph)); + return vis & OB_VISIBLE_SELF; } pxr::SdfPath InstancerData::object_prim_id(Object *object) const diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 03f7e099e196..a39052061a00 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -62,23 +62,16 @@ bool ObjectData::is_supported(Object *object) bool ObjectData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object) { - bool ret = true; eEvaluationMode deg_mode = DEG_get_mode(scene_delegate->depsgraph); int vis = BKE_object_visibility(object, deg_mode); + bool ret = vis & OB_VISIBLE_SELF; if (deg_mode == DAG_EVAL_VIEWPORT) { - ret = BKE_object_is_visible_in_viewport(scene_delegate->view3d, object) && - (vis & OB_VISIBLE_SELF); - //if (ret && object->transflag & OB_DUPLI) { - // ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT; - //} + ret &= BKE_object_is_visible_in_viewport(scene_delegate->view3d, object); } else { - ret = vis & OB_VISIBLE_SELF; - if (ret && object->transflag & OB_DUPLI) { - ret = object->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER; - } if (ret) { - /* If some of parent object is instacer, then object is invisible in Final render */ + /* If some of parent object is instancer, then currenct object + * is invisible in Final render */ for (Object *ob = object->parent; ob != nullptr; ob = ob->parent) { if (ob->transflag & OB_DUPLI) { ret = false; -- 2.30.2 From 9692e36fc2ed66aaac9a3a6c340804d6544bb727 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Tue, 23 May 2023 17:42:44 +0300 Subject: [PATCH 11/14] Fixed instance's visibility --- .../blender/render/hydra/scene_delegate/instancer.cc | 11 +++++++++-- source/blender/render/hydra/scene_delegate/object.cc | 1 - 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 21b007abe9b1..aceb38a6965a 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -268,8 +268,15 @@ void InstancerData::update_double_sided(MaterialData *mat_data) bool InstancerData::is_instance_visible(Object *object) { - int vis = BKE_object_visibility(object, DEG_get_mode(scene_delegate_->depsgraph)); - return vis & OB_VISIBLE_SELF; + eEvaluationMode deg_mode = DEG_get_mode(scene_delegate_->depsgraph); + int vis = BKE_object_visibility(object, deg_mode); + bool ret = vis & OB_VISIBLE_SELF; + if (deg_mode == DAG_EVAL_VIEWPORT) { + if (!ret && (object->transflag & OB_DUPLI) == 0) { + ret = true; + } + } + return ret; } pxr::SdfPath InstancerData::object_prim_id(Object *object) const diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index a39052061a00..8bb14cdae268 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -103,7 +103,6 @@ void ObjectData::update_parent() scene_delegate_->instancer_prim_id(ob)); if (i_data) { i_data->update_as_parent(); - break; } } } -- 2.30.2 From 0e028845b44f0867785e550cf3a73f34a4e8d127 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Tue, 23 May 2023 20:07:49 +0300 Subject: [PATCH 12/14] Fixed instance visibility update in viewport --- .../render/hydra/scene_delegate/instancer.cc | 45 +++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index aceb38a6965a..dc5bcb60e297 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -188,8 +188,18 @@ pxr::SdfPathVector InstancerData::prototypes() const void InstancerData::check_update(Object *object) { pxr::SdfPath path = object_prim_id(object); + + /* Checking object in existing mesh_instances_ */ auto m_it = mesh_instances_.find(path); if (m_it != mesh_instances_.end()) { + if (!is_instance_visible(object)) { + m_it->second.data->remove(); + mesh_instances_.erase(m_it); + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty( + prim_id, pxr::HdChangeTracker::AllDirty); + return; + } + m_it->second.data->update(); if (m_it->second.data->id->recalc & ID_RECALC_TRANSFORM) { @@ -200,8 +210,16 @@ void InstancerData::check_update(Object *object) return; } + /* Checking object in existing light_instances_ */ auto l_it = light_instances_.find(path); if (l_it != light_instances_.end()) { + if (!is_instance_visible(object)) { + l_it->second.transforms.clear(); + update_light_instance(l_it->second); + light_instances_.erase(l_it); + return; + } + Object *obj = (Object *)l_it->second.data->id; if (obj->id.recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY) || ((ID *)obj->data)->recalc & ID_RECALC_GEOMETRY) @@ -210,6 +228,28 @@ void InstancerData::check_update(Object *object) } return; } + + /* Checking if object wasn't added to instances before */ + if (is_supported(object) && is_instance_visible(object)) { + bool do_set_instances = false; + ListBase *lb = object_duplilist( + scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id); + LISTBASE_FOREACH (DupliObject *, dupli, lb) { + if (dupli->ob == object) { + do_set_instances = true; + break; + } + } + free_object_duplilist(lb); + + if (do_set_instances) { + set_instances(); + if (!mesh_instances_.empty()) { + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty( + prim_id, pxr::HdChangeTracker::AllDirty); + } + } + } } void InstancerData::check_remove(std::set &available_objects) @@ -315,10 +355,7 @@ void InstancerData::set_instances() scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id); LISTBASE_FOREACH (DupliObject *, dupli, lb) { Object *ob = dupli->ob; - if (!is_supported(ob)) { - continue; - } - if (!is_instance_visible(ob)) { + if (!is_supported(ob) || !is_instance_visible(ob)) { continue; } -- 2.30.2 From 5b0747e76369e2375e820e8db1d412de0b9652d1 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Wed, 24 May 2023 09:49:56 +0300 Subject: [PATCH 13/14] Adjustments after fixing merge conflicts --- .../blender/render/hydra/scene_delegate/instancer.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 10991766be5d..15e429ae1282 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -88,7 +88,6 @@ void InstancerData::remove() void InstancerData::update() { ID_LOG(2, ""); - Object *object = (Object *)id; if (id->recalc & ID_RECALC_GEOMETRY || (object->data && ((ID *)object->data)->recalc & ID_RECALC_GEOMETRY) || @@ -215,7 +214,7 @@ void InstancerData::check_update(Object *object) if (l_inst) { if (!is_instance_visible(object)) { l_inst->transforms.clear(); - update_light_instance(l_it->second); + update_light_instance(*l_inst); light_instances_.erase(path); return; } @@ -231,19 +230,19 @@ void InstancerData::check_update(Object *object) /* Checking if object wasn't added to instances before */ if (is_supported(object) && is_instance_visible(object)) { - bool do_set_instances = false; + bool do_write_instances = false; ListBase *lb = object_duplilist( scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id); LISTBASE_FOREACH (DupliObject *, dupli, lb) { if (dupli->ob == object) { - do_set_instances = true; + do_write_instances = true; break; } } free_object_duplilist(lb); - if (do_set_instances) { - set_instances(); + if (do_write_instances) { + write_instances(); if (!mesh_instances_.empty()) { scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty( prim_id, pxr::HdChangeTracker::AllDirty); -- 2.30.2 From 46ab05f3780ab8ef209829918a6460f82054d389 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Wed, 24 May 2023 13:23:19 +0300 Subject: [PATCH 14/14] Fixed instance visibility in special case --- source/blender/render/hydra/scene_delegate/instancer.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 15e429ae1282..6f0177b4299e 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -308,7 +308,10 @@ bool InstancerData::is_instance_visible(Object *object) int vis = BKE_object_visibility(object, deg_mode); bool ret = vis & OB_VISIBLE_SELF; if (deg_mode == DAG_EVAL_VIEWPORT) { - if (!ret && (object->transflag & OB_DUPLI) == 0) { + if (!ret && ((object->transflag & OB_DUPLI) == 0 || + (object->transflag & OB_DUPLI && + object->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT))) + { ret = true; } } -- 2.30.2