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 fdd6c5476743..7cc48f1e2b47 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -122,6 +122,18 @@ bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id) return object_data(id)->visible; } +bool BlenderSceneDelegate::GetDoubleSided(pxr::SdfPath const &id) +{ + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText()); + return mesh_data(id)->double_sided(); +} + +pxr::HdCullStyle BlenderSceneDelegate::GetCullStyle(pxr::SdfPath const &id) +{ + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText()); + return mesh_data(id)->cull_style; +} + pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &prim_id) { CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", prim_id.GetText()); diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 1ad18348564e..9457b577d842 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -21,8 +21,9 @@ namespace blender::render::hydra { extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE; /* BSD - Blender Scene Delegate */ class BlenderSceneDelegate : public pxr::HdSceneDelegate { - friend ObjectData; /* has access to instances */ - friend MeshData; /* has access to materials */ + friend ObjectData; /* has access to instances */ + friend MeshData; /* has access to materials */ + friend MaterialData; /* has access to objects and instancers */ public: enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW }; @@ -43,6 +44,8 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { pxr::SdfPath GetMaterialId(pxr::SdfPath const &rprim_id) override; pxr::VtValue GetMaterialResource(pxr::SdfPath const &material_id) override; bool GetVisible(pxr::SdfPath const &id) override; + bool GetDoubleSided(pxr::SdfPath const &id) override; + pxr::HdCullStyle GetCullStyle(pxr::SdfPath const &id) override; pxr::SdfPath GetInstancerId(pxr::SdfPath const &prim_id) override; pxr::SdfPathVector GetInstancerPrototypes(pxr::SdfPath const &instancer_id) override; pxr::VtIntArray GetInstanceIndices(pxr::SdfPath const &instancer_id, diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 9ed24aa6f6f0..70ae1551d417 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -228,6 +228,13 @@ void InstancerData::update_as_parent() prim_id, pxr::HdChangeTracker::AllDirty); } +void InstancerData::update_double_sided(MaterialData *mat_data) +{ + for (auto &it : mesh_instances_) { + it.second.data->update_double_sided(mat_data); + } +} + pxr::SdfPath InstancerData::object_prim_id(Object *object) const { /* Making id of object in form like _ */ diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index cb9410768431..d0454903abf8 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -43,6 +43,7 @@ class InstancerData : public ObjectData { void check_remove(std::set &available_objects); void available_materials(std::set &paths) const; void update_as_parent(); + void update_double_sided(MaterialData *mat_data); private: pxr::SdfPath object_prim_id(Object *object) const; diff --git a/source/blender/render/hydra/scene_delegate/material.cc b/source/blender/render/hydra/scene_delegate/material.cc index 9033c25cfea5..cac62eda0be5 100644 --- a/source/blender/render/hydra/scene_delegate/material.cc +++ b/source/blender/render/hydra/scene_delegate/material.cc @@ -30,7 +30,7 @@ MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, void MaterialData::init() { ID_LOG(2, ""); - + double_sided = (((Material *)id)->blend_flag & MA_BL_CULL_BACKFACE) == 0; material_network_map_ = pxr::VtValue(); /* Call of python function hydra.export_mtlx() */ @@ -120,9 +120,21 @@ void MaterialData::remove() void MaterialData::update() { ID_LOG(2, ""); + bool prev_double_sided = double_sided; init(); scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, pxr::HdMaterial::AllDirty); + if (prev_double_sided != double_sided) { + for (auto &it : scene_delegate_->objects_) { + MeshData *m_data = dynamic_cast(it.second.get()); + if (m_data) { + m_data->update_double_sided(this); + } + } + for (auto &it : scene_delegate_->instancers_) { + it.second->update_double_sided(this); + } + } } pxr::VtValue MaterialData::get_data(pxr::TfToken const &key) const diff --git a/source/blender/render/hydra/scene_delegate/material.h b/source/blender/render/hydra/scene_delegate/material.h index 985e95acb786..f70a7ef11c5f 100644 --- a/source/blender/render/hydra/scene_delegate/material.h +++ b/source/blender/render/hydra/scene_delegate/material.h @@ -27,6 +27,8 @@ class MaterialData : public IdData { pxr::VtValue get_data(pxr::TfToken const &key) const override; pxr::VtValue get_material_resource() const; + bool double_sided = true; + private: pxr::SdfAssetPath mtlx_path_; pxr::VtValue material_network_map_; diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index be5636d08888..0bae621a101b 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -74,7 +74,7 @@ void MeshData::update() else { if (id->recalc & ID_RECALC_SHADING) { write_material(); - bits |= pxr::HdChangeTracker::DirtyMaterialId; + bits |= pxr::HdChangeTracker::DirtyMaterialId | pxr::HdChangeTracker::DirtyDoubleSided; } if (id->recalc & ID_RECALC_TRANSFORM) { write_transform(); @@ -119,6 +119,7 @@ bool MeshData::update_visibility() { bool ret = ObjectData::update_visibility(); if (ret) { + ID_LOG(2, ""); scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty( prim_id, pxr::HdChangeTracker::DirtyVisibility); } @@ -164,6 +165,23 @@ pxr::SdfPath MeshData::material_id() const return mat_data_->prim_id; } +bool MeshData::double_sided() const +{ + if (mat_data_) { + return mat_data_->double_sided; + } + return true; +} + +void MeshData::update_double_sided(MaterialData *mat_data) +{ + if (mat_data_ == mat_data) { + ID_LOG(2, ""); + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty( + prim_id, pxr::HdChangeTracker::DirtyDoubleSided); + } +} + void MeshData::write_mesh(Mesh *mesh) { face_vertex_counts_.clear(); diff --git a/source/blender/render/hydra/scene_delegate/mesh.h b/source/blender/render/hydra/scene_delegate/mesh.h index da62c1f70003..e9a66dd7bdcb 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.h +++ b/source/blender/render/hydra/scene_delegate/mesh.h @@ -28,6 +28,10 @@ class MeshData : public ObjectData { pxr::HdMeshTopology mesh_topology() const; pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const; pxr::SdfPath material_id() const; + bool double_sided() const; + void update_double_sided(MaterialData *mat_data); + + pxr::HdCullStyle cull_style = pxr::HdCullStyleBackUnlessDoubleSided; private: void write_mesh(Mesh *mesh);