From dee103b084c1c2a6761a908ce4e4f098d1ab79dc Mon Sep 17 00:00:00 2001 From: Vasyl-Pidhirskyi Date: Tue, 18 Jul 2023 16:46:35 +0300 Subject: [PATCH 1/5] Implemented SkydomeTaskDelegate. Updates CMakeLists.txt with skydome_task_delegate.h, skydome_task_delegate.cc. Appended HdTaskSharedPtrVector with skydome_task_delegate_. --- source/blender/render/hydra/CMakeLists.txt | 2 + source/blender/render/hydra/engine.cc | 3 ++ source/blender/render/hydra/engine.h | 2 + source/blender/render/hydra/final_engine.cc | 6 ++- .../render/hydra/skydome_task_delegate.cc | 47 +++++++++++++++++++ .../render/hydra/skydome_task_delegate.h | 27 +++++++++++ .../blender/render/hydra/viewport_engine.cc | 10 ++++ 7 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 source/blender/render/hydra/skydome_task_delegate.cc create mode 100644 source/blender/render/hydra/skydome_task_delegate.h diff --git a/source/blender/render/hydra/CMakeLists.txt b/source/blender/render/hydra/CMakeLists.txt index 3da25f21f4b0..ab3f251c160a 100644 --- a/source/blender/render/hydra/CMakeLists.txt +++ b/source/blender/render/hydra/CMakeLists.txt @@ -90,6 +90,8 @@ set(SRC render_task_delegate.h simple_light_task_delegate.cc simple_light_task_delegate.h + skydome_task_delegate.cc + skydome_task_delegate.h scene_delegate/blender_scene_delegate.cc scene_delegate/blender_scene_delegate.h diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 618a7b96072d..ec598f3d7191 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -53,6 +53,9 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name) render_task_delegate_ = std::make_unique( render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); if (render_delegate_name == "HdStormRendererPlugin") { + skydome_task_delegate_ = std::make_unique( + render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("skydomeTask")); + simple_light_task_delegate_ = std::make_unique( render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask")); diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index d2b4776d5ef2..40ea088d73ea 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -19,6 +19,7 @@ #include "render_task_delegate.h" #include "simple_light_task_delegate.h" +#include "skydome_task_delegate.h" #include "scene_delegate/blender_scene_delegate.h" #include "scene_delegate/usd_scene_delegate.hh" @@ -58,6 +59,7 @@ class Engine { std::unique_ptr render_task_delegate_; std::unique_ptr free_camera_delegate_; std::unique_ptr simple_light_task_delegate_; + std::unique_ptr skydome_task_delegate_; std::unique_ptr engine_; }; diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index e6b48744a9e5..d5afd46e0198 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -106,7 +106,11 @@ void FinalEngine::prepare_for_render(Depsgraph *depsgraph) free_camera_delegate_->SetCamera(camera); render_task_delegate_->set_camera_and_viewport( free_camera_delegate_->GetCameraId(), pxr::GfVec4d(0, 0, resolution_[0], resolution_[1])); - + if (skydome_task_delegate_) { + skydome_task_delegate_->set_camera_and_viewport( + free_camera_delegate_->GetCameraId(), pxr::GfVec4d(0, 0, resolution_[0], resolution_[1])); + tasks_.push_back(skydome_task_delegate_->get_task()); + } if (simple_light_task_delegate_) { simple_light_task_delegate_->set_camera_path(free_camera_delegate_->GetCameraId()); tasks_.push_back(simple_light_task_delegate_->get_task()); diff --git a/source/blender/render/hydra/skydome_task_delegate.cc b/source/blender/render/hydra/skydome_task_delegate.cc new file mode 100644 index 000000000000..5f9712fb1ba6 --- /dev/null +++ b/source/blender/render/hydra/skydome_task_delegate.cc @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: Apache-2.0 + * Copyright 2011-2022 Blender Foundation */ + +#include + +#include "skydome_task_delegate.h" + +namespace blender::render::hydra { + +SkydomeTaskDelegate::SkydomeTaskDelegate(pxr::HdRenderIndex *parent_index, + pxr::SdfPath const &delegate_id) + : pxr::HdSceneDelegate(parent_index, delegate_id) +{ + pxr::SdfPath task_id = get_task_id(); + GetRenderIndex().InsertTask(this, task_id); +} + +void SkydomeTaskDelegate::set_camera_and_viewport(pxr::SdfPath const &camera_id, + pxr::GfVec4d const &viewport) +{ + if (task_params_.viewport != viewport || task_params_.camera != camera_id) { + task_params_.viewport = viewport; + task_params_.camera = camera_id; + GetRenderIndex().GetChangeTracker().MarkTaskDirty(get_task_id(), + pxr::HdChangeTracker::DirtyParams); + } +} + +pxr::VtValue SkydomeTaskDelegate::Get(pxr::SdfPath const & /*id*/, pxr::TfToken const &key) +{ + if (key == pxr::HdTokens->params) { + return pxr::VtValue(task_params_); + } + return pxr::VtValue(); +} + +pxr::SdfPath SkydomeTaskDelegate::get_task_id() const +{ + return GetDelegateID().AppendElementString("task"); +} + +pxr::HdTaskSharedPtr SkydomeTaskDelegate::get_task() +{ + return GetRenderIndex().GetTask(get_task_id()); +} + +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/skydome_task_delegate.h b/source/blender/render/hydra/skydome_task_delegate.h new file mode 100644 index 000000000000..4cf0b91ea624 --- /dev/null +++ b/source/blender/render/hydra/skydome_task_delegate.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: Apache-2.0 + * Copyright 2011-2022 Blender Foundation */ + +#pragma once + +#include +#include + +namespace blender::render::hydra { + +class SkydomeTaskDelegate : public pxr::HdSceneDelegate { + public: + SkydomeTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegate_id); + ~SkydomeTaskDelegate() override = default; + + pxr::SdfPath get_task_id() const; + pxr::HdTaskSharedPtr get_task(); + void set_camera_and_viewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport); + + /* Delegate methods */ + pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override; + + private: + pxr::HdxRenderTaskParams task_params_; +}; + +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 75306e459e6a..716ec71cbbe0 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -236,6 +236,13 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context) view_settings.border[1], view_settings.border[2], view_settings.border[3])); + if (skydome_task_delegate_) { + skydome_task_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(), + pxr::GfVec4d(view_settings.border[0], + view_settings.border[1], + view_settings.border[2], + view_settings.border[3])); + } if (simple_light_task_delegate_) { simple_light_task_delegate_->set_camera_path(free_camera_delegate_->GetCameraId()); } @@ -248,6 +255,9 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context) GPU_shader_bind(shader); pxr::HdTaskSharedPtrVector tasks; + if (skydome_task_delegate_) { + tasks.push_back(skydome_task_delegate_->get_task()); + } if (simple_light_task_delegate_) { tasks.push_back(simple_light_task_delegate_->get_task()); } -- 2.30.2 From 1fd428b393eab51d765e66bbe3a91d61e23f5d8f Mon Sep 17 00:00:00 2001 From: Vasyl-Pidhirskyi Date: Thu, 20 Jul 2023 11:43:15 +0300 Subject: [PATCH 2/5] Combined SkydomeTaskDelegate and SimpleLightTaskDelegate to one class LightTaskDelegate. --- source/blender/render/hydra/CMakeLists.txt | 6 +- source/blender/render/hydra/engine.cc | 7 +-- source/blender/render/hydra/engine.h | 6 +- source/blender/render/hydra/final_engine.cc | 14 ++--- .../render/hydra/light_tasks_delegate.cc | 58 +++++++++++++++++++ .../render/hydra/light_tasks_delegate.h | 31 ++++++++++ .../hydra/simple_light_task_delegate.cc | 41 ------------- .../render/hydra/simple_light_task_delegate.h | 28 --------- .../render/hydra/skydome_task_delegate.cc | 47 --------------- .../render/hydra/skydome_task_delegate.h | 27 --------- .../blender/render/hydra/viewport_engine.cc | 16 ++--- 11 files changed, 107 insertions(+), 174 deletions(-) create mode 100644 source/blender/render/hydra/light_tasks_delegate.cc create mode 100644 source/blender/render/hydra/light_tasks_delegate.h delete mode 100644 source/blender/render/hydra/simple_light_task_delegate.cc delete mode 100644 source/blender/render/hydra/simple_light_task_delegate.h delete mode 100644 source/blender/render/hydra/skydome_task_delegate.cc delete mode 100644 source/blender/render/hydra/skydome_task_delegate.h diff --git a/source/blender/render/hydra/CMakeLists.txt b/source/blender/render/hydra/CMakeLists.txt index ab3f251c160a..b48afc4feb21 100644 --- a/source/blender/render/hydra/CMakeLists.txt +++ b/source/blender/render/hydra/CMakeLists.txt @@ -88,10 +88,8 @@ set(SRC render_task_delegate.cc render_task_delegate.h - simple_light_task_delegate.cc - simple_light_task_delegate.h - skydome_task_delegate.cc - skydome_task_delegate.h + light_tasks_delegate.cc + light_tasks_delegate.h scene_delegate/blender_scene_delegate.cc scene_delegate/blender_scene_delegate.h diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index ec598f3d7191..630385465537 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -53,12 +53,9 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name) render_task_delegate_ = std::make_unique( render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); if (render_delegate_name == "HdStormRendererPlugin") { - skydome_task_delegate_ = std::make_unique( - render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("skydomeTask")); - - simple_light_task_delegate_ = std::make_unique( + light_tasks_delegate_ = std::make_unique( render_index_.get(), - pxr::SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask")); + pxr::SdfPath::AbsoluteRootPath().AppendElementString("lightTasks")); } engine_ = std::make_unique(); diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index 40ea088d73ea..9c8bc33e290e 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -18,8 +18,7 @@ #include "CLG_log.h" #include "render_task_delegate.h" -#include "simple_light_task_delegate.h" -#include "skydome_task_delegate.h" +#include "light_tasks_delegate.h" #include "scene_delegate/blender_scene_delegate.h" #include "scene_delegate/usd_scene_delegate.hh" @@ -58,8 +57,7 @@ class Engine { std::unique_ptr render_task_delegate_; std::unique_ptr free_camera_delegate_; - std::unique_ptr simple_light_task_delegate_; - std::unique_ptr skydome_task_delegate_; + std::unique_ptr light_tasks_delegate_; std::unique_ptr engine_; }; diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index d5afd46e0198..4c8597c26be6 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -106,14 +106,12 @@ void FinalEngine::prepare_for_render(Depsgraph *depsgraph) free_camera_delegate_->SetCamera(camera); render_task_delegate_->set_camera_and_viewport( free_camera_delegate_->GetCameraId(), pxr::GfVec4d(0, 0, resolution_[0], resolution_[1])); - if (skydome_task_delegate_) { - skydome_task_delegate_->set_camera_and_viewport( - free_camera_delegate_->GetCameraId(), pxr::GfVec4d(0, 0, resolution_[0], resolution_[1])); - tasks_.push_back(skydome_task_delegate_->get_task()); - } - if (simple_light_task_delegate_) { - simple_light_task_delegate_->set_camera_path(free_camera_delegate_->GetCameraId()); - tasks_.push_back(simple_light_task_delegate_->get_task()); + if (light_tasks_delegate_) { + light_tasks_delegate_->set_camera_path(free_camera_delegate_->GetCameraId()); + light_tasks_delegate_->set_camera_and_viewport( + free_camera_delegate_->GetCameraId(), pxr::GfVec4d(0, 0, resolution_[0], + resolution_[1])); + tasks_ = light_tasks_delegate_->get_tasks(); } tasks_.push_back(render_task_delegate_->get_task()); diff --git a/source/blender/render/hydra/light_tasks_delegate.cc b/source/blender/render/hydra/light_tasks_delegate.cc new file mode 100644 index 000000000000..a56e8b75c6eb --- /dev/null +++ b/source/blender/render/hydra/light_tasks_delegate.cc @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: Apache-2.0 + * Copyright 2011-2022 Blender Foundation */ + +#include +#include + +#include "light_tasks_delegate.h" + +namespace blender::render::hydra { + +LightTasksDelegate::LightTasksDelegate(pxr::HdRenderIndex *parent_index, + pxr::SdfPath const &delegate_id) + : pxr::HdSceneDelegate(parent_index, delegate_id) +{ + skydome_task = GetDelegateID().AppendElementString("simpleLightTask"); + simple_light_task = GetDelegateID().AppendElementString("skydomeTask"); + GetRenderIndex().InsertTask(this, skydome_task); + GetRenderIndex().InsertTask(this, simple_light_task); +} + +pxr::HdTaskSharedPtrVector LightTasksDelegate::get_tasks() +{ + return { + GetRenderIndex().GetTask(skydome_task), + GetRenderIndex().GetTask(simple_light_task) + }; +} + +void LightTasksDelegate::set_camera_path(pxr::SdfPath const &camera_path) +{ + simple_light_task_params_.cameraPath = camera_path; +} + +void LightTasksDelegate::set_camera_and_viewport(pxr::SdfPath const &camera_id, + pxr::GfVec4d const &viewport) +{ + if (skydome_task_params_.viewport != viewport || skydome_task_params_.camera != camera_id) { + skydome_task_params_.viewport = viewport; + skydome_task_params_.camera = camera_id; + GetRenderIndex().GetChangeTracker().MarkTaskDirty(skydome_task, + pxr::HdChangeTracker::DirtyParams); + } +} + +pxr::VtValue LightTasksDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) +{ + if (key == pxr::HdTokens->params) { + if (id == simple_light_task) { + return pxr::VtValue(simple_light_task_params_); + } + else if (id == skydome_task) { + return pxr::VtValue(skydome_task_params_); + } + } + return pxr::VtValue(); +} + +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/light_tasks_delegate.h b/source/blender/render/hydra/light_tasks_delegate.h new file mode 100644 index 000000000000..022d730f3aba --- /dev/null +++ b/source/blender/render/hydra/light_tasks_delegate.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: Apache-2.0 + * Copyright 2011-2022 Blender Foundation */ + +#pragma once + +#include +#include +#include + +namespace blender::render::hydra { + +class LightTasksDelegate : public pxr::HdSceneDelegate { + public: + LightTasksDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegate_id); + ~LightTasksDelegate() override = default; + + pxr::HdTaskSharedPtrVector get_tasks(); + void set_camera_path(pxr::SdfPath const &); + void set_camera_and_viewport(pxr::SdfPath const &camera_id, pxr::GfVec4d const &viewport); + + /* Delegate methods */ + pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override; + + private: + pxr::SdfPath simple_light_task; + pxr::SdfPath skydome_task; + pxr::HdxSimpleLightTaskParams simple_light_task_params_; + pxr::HdxRenderTaskParams skydome_task_params_; +}; + +} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/simple_light_task_delegate.cc b/source/blender/render/hydra/simple_light_task_delegate.cc deleted file mode 100644 index 574bce126d28..000000000000 --- a/source/blender/render/hydra/simple_light_task_delegate.cc +++ /dev/null @@ -1,41 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 - * Copyright 2011-2022 Blender Foundation */ - -#include - -#include "simple_light_task_delegate.h" - -namespace blender::render::hydra { - -SimpleLightTaskDelegate::SimpleLightTaskDelegate(pxr::HdRenderIndex *parent_index, - pxr::SdfPath const &delegate_id) - : pxr::HdSceneDelegate(parent_index, delegate_id) -{ - pxr::SdfPath task_id = get_task_id(); - GetRenderIndex().InsertTask(this, task_id); -} - -pxr::SdfPath SimpleLightTaskDelegate::get_task_id() const -{ - return GetDelegateID().AppendElementString("task"); -} - -pxr::HdTaskSharedPtr SimpleLightTaskDelegate::get_task() -{ - return GetRenderIndex().GetTask(get_task_id()); -} - -void SimpleLightTaskDelegate::set_camera_path(pxr::SdfPath const &camera_path) -{ - task_params_.cameraPath = camera_path; -} - -pxr::VtValue SimpleLightTaskDelegate::Get(pxr::SdfPath const & /*id*/, pxr::TfToken const &key) -{ - if (key == pxr::HdTokens->params) { - return pxr::VtValue(task_params_); - } - return pxr::VtValue(); -} - -} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/simple_light_task_delegate.h b/source/blender/render/hydra/simple_light_task_delegate.h deleted file mode 100644 index 376876b7f17b..000000000000 --- a/source/blender/render/hydra/simple_light_task_delegate.h +++ /dev/null @@ -1,28 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 - * Copyright 2011-2022 Blender Foundation */ - -#pragma once - -#include -#include - -namespace blender::render::hydra { - -class SimpleLightTaskDelegate : public pxr::HdSceneDelegate { - public: - SimpleLightTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegate_id); - ~SimpleLightTaskDelegate() override = default; - - pxr::SdfPath get_task_id() const; - - pxr::HdTaskSharedPtr get_task(); - void set_camera_path(pxr::SdfPath const &); - - /* Delegate methods */ - pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override; - - private: - pxr::HdxSimpleLightTaskParams task_params_; -}; - -} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/skydome_task_delegate.cc b/source/blender/render/hydra/skydome_task_delegate.cc deleted file mode 100644 index 5f9712fb1ba6..000000000000 --- a/source/blender/render/hydra/skydome_task_delegate.cc +++ /dev/null @@ -1,47 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 - * Copyright 2011-2022 Blender Foundation */ - -#include - -#include "skydome_task_delegate.h" - -namespace blender::render::hydra { - -SkydomeTaskDelegate::SkydomeTaskDelegate(pxr::HdRenderIndex *parent_index, - pxr::SdfPath const &delegate_id) - : pxr::HdSceneDelegate(parent_index, delegate_id) -{ - pxr::SdfPath task_id = get_task_id(); - GetRenderIndex().InsertTask(this, task_id); -} - -void SkydomeTaskDelegate::set_camera_and_viewport(pxr::SdfPath const &camera_id, - pxr::GfVec4d const &viewport) -{ - if (task_params_.viewport != viewport || task_params_.camera != camera_id) { - task_params_.viewport = viewport; - task_params_.camera = camera_id; - GetRenderIndex().GetChangeTracker().MarkTaskDirty(get_task_id(), - pxr::HdChangeTracker::DirtyParams); - } -} - -pxr::VtValue SkydomeTaskDelegate::Get(pxr::SdfPath const & /*id*/, pxr::TfToken const &key) -{ - if (key == pxr::HdTokens->params) { - return pxr::VtValue(task_params_); - } - return pxr::VtValue(); -} - -pxr::SdfPath SkydomeTaskDelegate::get_task_id() const -{ - return GetDelegateID().AppendElementString("task"); -} - -pxr::HdTaskSharedPtr SkydomeTaskDelegate::get_task() -{ - return GetRenderIndex().GetTask(get_task_id()); -} - -} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/skydome_task_delegate.h b/source/blender/render/hydra/skydome_task_delegate.h deleted file mode 100644 index 4cf0b91ea624..000000000000 --- a/source/blender/render/hydra/skydome_task_delegate.h +++ /dev/null @@ -1,27 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 - * Copyright 2011-2022 Blender Foundation */ - -#pragma once - -#include -#include - -namespace blender::render::hydra { - -class SkydomeTaskDelegate : public pxr::HdSceneDelegate { - public: - SkydomeTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegate_id); - ~SkydomeTaskDelegate() override = default; - - pxr::SdfPath get_task_id() const; - pxr::HdTaskSharedPtr get_task(); - void set_camera_and_viewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport); - - /* Delegate methods */ - pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override; - - private: - pxr::HdxRenderTaskParams task_params_; -}; - -} // namespace blender::render::hydra diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 716ec71cbbe0..6d747f3cd257 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -236,16 +236,15 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context) view_settings.border[1], view_settings.border[2], view_settings.border[3])); - if (skydome_task_delegate_) { - skydome_task_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(), + + if (light_tasks_delegate_) { + light_tasks_delegate_->set_camera_path(free_camera_delegate_->GetCameraId()); + light_tasks_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(), pxr::GfVec4d(view_settings.border[0], view_settings.border[1], view_settings.border[2], view_settings.border[3])); } - if (simple_light_task_delegate_) { - simple_light_task_delegate_->set_camera_path(free_camera_delegate_->GetCameraId()); - } if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) { render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color); @@ -255,11 +254,8 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context) GPU_shader_bind(shader); pxr::HdTaskSharedPtrVector tasks; - if (skydome_task_delegate_) { - tasks.push_back(skydome_task_delegate_->get_task()); - } - if (simple_light_task_delegate_) { - tasks.push_back(simple_light_task_delegate_->get_task()); + if (light_tasks_delegate_) { + tasks = light_tasks_delegate_->get_tasks(); } tasks.push_back(render_task_delegate_->get_task()); -- 2.30.2 From 18486907b0bb39f1a6e91e57295efd5aeea39040 Mon Sep 17 00:00:00 2001 From: Vasyl-Pidhirskyi Date: Thu, 20 Jul 2023 11:47:14 +0300 Subject: [PATCH 3/5] Make format. --- source/blender/render/hydra/engine.cc | 3 +-- source/blender/render/hydra/engine.h | 2 +- source/blender/render/hydra/final_engine.cc | 3 +-- source/blender/render/hydra/light_tasks_delegate.cc | 9 +++------ source/blender/render/hydra/viewport_engine.cc | 8 ++++---- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 630385465537..7be85fb22430 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -54,8 +54,7 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name) render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); if (render_delegate_name == "HdStormRendererPlugin") { light_tasks_delegate_ = std::make_unique( - render_index_.get(), - pxr::SdfPath::AbsoluteRootPath().AppendElementString("lightTasks")); + render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("lightTasks")); } engine_ = std::make_unique(); diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index 9c8bc33e290e..ebfb32a4a7a1 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -17,8 +17,8 @@ #include "CLG_log.h" -#include "render_task_delegate.h" #include "light_tasks_delegate.h" +#include "render_task_delegate.h" #include "scene_delegate/blender_scene_delegate.h" #include "scene_delegate/usd_scene_delegate.hh" diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index 4c8597c26be6..4b7a27bcc000 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -109,8 +109,7 @@ void FinalEngine::prepare_for_render(Depsgraph *depsgraph) if (light_tasks_delegate_) { light_tasks_delegate_->set_camera_path(free_camera_delegate_->GetCameraId()); light_tasks_delegate_->set_camera_and_viewport( - free_camera_delegate_->GetCameraId(), pxr::GfVec4d(0, 0, resolution_[0], - resolution_[1])); + free_camera_delegate_->GetCameraId(), pxr::GfVec4d(0, 0, resolution_[0], resolution_[1])); tasks_ = light_tasks_delegate_->get_tasks(); } tasks_.push_back(render_task_delegate_->get_task()); diff --git a/source/blender/render/hydra/light_tasks_delegate.cc b/source/blender/render/hydra/light_tasks_delegate.cc index a56e8b75c6eb..174620178e3d 100644 --- a/source/blender/render/hydra/light_tasks_delegate.cc +++ b/source/blender/render/hydra/light_tasks_delegate.cc @@ -9,7 +9,7 @@ namespace blender::render::hydra { LightTasksDelegate::LightTasksDelegate(pxr::HdRenderIndex *parent_index, - pxr::SdfPath const &delegate_id) + pxr::SdfPath const &delegate_id) : pxr::HdSceneDelegate(parent_index, delegate_id) { skydome_task = GetDelegateID().AppendElementString("simpleLightTask"); @@ -20,10 +20,7 @@ LightTasksDelegate::LightTasksDelegate(pxr::HdRenderIndex *parent_index, pxr::HdTaskSharedPtrVector LightTasksDelegate::get_tasks() { - return { - GetRenderIndex().GetTask(skydome_task), - GetRenderIndex().GetTask(simple_light_task) - }; + return {GetRenderIndex().GetTask(skydome_task), GetRenderIndex().GetTask(simple_light_task)}; } void LightTasksDelegate::set_camera_path(pxr::SdfPath const &camera_path) @@ -32,7 +29,7 @@ void LightTasksDelegate::set_camera_path(pxr::SdfPath const &camera_path) } void LightTasksDelegate::set_camera_and_viewport(pxr::SdfPath const &camera_id, - pxr::GfVec4d const &viewport) + pxr::GfVec4d const &viewport) { if (skydome_task_params_.viewport != viewport || skydome_task_params_.camera != camera_id) { skydome_task_params_.viewport = viewport; diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 6d747f3cd257..e5a72b0aef29 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -240,10 +240,10 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context) if (light_tasks_delegate_) { light_tasks_delegate_->set_camera_path(free_camera_delegate_->GetCameraId()); light_tasks_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(), - pxr::GfVec4d(view_settings.border[0], - view_settings.border[1], - view_settings.border[2], - view_settings.border[3])); + pxr::GfVec4d(view_settings.border[0], + view_settings.border[1], + view_settings.border[2], + view_settings.border[3])); } if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) { -- 2.30.2 From da188a4276735b7857804c3d9d7309df6a42206f Mon Sep 17 00:00:00 2001 From: Vasyl-Pidhirskyi Date: Thu, 20 Jul 2023 12:40:34 +0300 Subject: [PATCH 4/5] Improved naming. Removed workaround. --- source/blender/render/hydra/final_engine.cc | 15 ---------- .../render/hydra/light_tasks_delegate.cc | 28 +++++++++---------- .../render/hydra/light_tasks_delegate.h | 7 ++--- .../blender/render/hydra/viewport_engine.cc | 1 - 4 files changed, 17 insertions(+), 34 deletions(-) diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index 4b7a27bcc000..ebc6d91c9218 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -107,7 +107,6 @@ void FinalEngine::prepare_for_render(Depsgraph *depsgraph) render_task_delegate_->set_camera_and_viewport( free_camera_delegate_->GetCameraId(), pxr::GfVec4d(0, 0, resolution_[0], resolution_[1])); if (light_tasks_delegate_) { - light_tasks_delegate_->set_camera_path(free_camera_delegate_->GetCameraId()); light_tasks_delegate_->set_camera_and_viewport( free_camera_delegate_->GetCameraId(), pxr::GfVec4d(0, 0, resolution_[0], resolution_[1])); tasks_ = light_tasks_delegate_->get_tasks(); @@ -150,20 +149,6 @@ void FinalEngineGPU::render(Depsgraph *depsgraph) float clear_color[4] = {0.0f, 0.0f, 0.0f, 1.0f}; - /* Workaround Storm rendering with transparent background. Does not currently work for - * USD, and should probably be optional depending on the Blender film transparency setting. */ - if (hydra_scene_delegate_ && render_delegate_name == "HdStormRendererPlugin") { - pxr::VtValue world_color = hydra_scene_delegate_->GetLightParamValue( - hydra_scene_delegate_->GetDelegateID().AppendElementString("World"), - pxr::HdLightTokens->color); - if (!world_color.IsEmpty()) { - auto &c = world_color.Get(); - clear_color[0] = c[0]; - clear_color[1] = c[1]; - clear_color[2] = c[2]; - } - } - GPU_framebuffer_clear_color_depth(framebuffer, clear_color, 1.0f); /* Important: we have to create and bind at least one Vertex Array Object (VAO) before render diff --git a/source/blender/render/hydra/light_tasks_delegate.cc b/source/blender/render/hydra/light_tasks_delegate.cc index 174620178e3d..eb99d1a1fd61 100644 --- a/source/blender/render/hydra/light_tasks_delegate.cc +++ b/source/blender/render/hydra/light_tasks_delegate.cc @@ -12,29 +12,29 @@ LightTasksDelegate::LightTasksDelegate(pxr::HdRenderIndex *parent_index, pxr::SdfPath const &delegate_id) : pxr::HdSceneDelegate(parent_index, delegate_id) { - skydome_task = GetDelegateID().AppendElementString("simpleLightTask"); - simple_light_task = GetDelegateID().AppendElementString("skydomeTask"); - GetRenderIndex().InsertTask(this, skydome_task); - GetRenderIndex().InsertTask(this, simple_light_task); + skydome_task_id_ = GetDelegateID().AppendElementString("simpleLightTask"); + simple_task_id_ = GetDelegateID().AppendElementString("skydomeTask"); + GetRenderIndex().InsertTask(this, skydome_task_id_); + GetRenderIndex().InsertTask(this, simple_task_id_); } pxr::HdTaskSharedPtrVector LightTasksDelegate::get_tasks() { - return {GetRenderIndex().GetTask(skydome_task), GetRenderIndex().GetTask(simple_light_task)}; -} - -void LightTasksDelegate::set_camera_path(pxr::SdfPath const &camera_path) -{ - simple_light_task_params_.cameraPath = camera_path; + return {GetRenderIndex().GetTask(skydome_task_id_), GetRenderIndex().GetTask(simple_task_id_)}; } void LightTasksDelegate::set_camera_and_viewport(pxr::SdfPath const &camera_id, pxr::GfVec4d const &viewport) { + if (simple_task_params_.cameraPath != camera_id) { + simple_task_params_.cameraPath = camera_id; + GetRenderIndex().GetChangeTracker().MarkTaskDirty(simple_task_id_, + pxr::HdChangeTracker::DirtyParams); + } if (skydome_task_params_.viewport != viewport || skydome_task_params_.camera != camera_id) { skydome_task_params_.viewport = viewport; skydome_task_params_.camera = camera_id; - GetRenderIndex().GetChangeTracker().MarkTaskDirty(skydome_task, + GetRenderIndex().GetChangeTracker().MarkTaskDirty(skydome_task_id_, pxr::HdChangeTracker::DirtyParams); } } @@ -42,10 +42,10 @@ void LightTasksDelegate::set_camera_and_viewport(pxr::SdfPath const &camera_id, pxr::VtValue LightTasksDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) { if (key == pxr::HdTokens->params) { - if (id == simple_light_task) { - return pxr::VtValue(simple_light_task_params_); + if (id == simple_task_id_) { + return pxr::VtValue(simple_task_params_); } - else if (id == skydome_task) { + else if (id == skydome_task_id_) { return pxr::VtValue(skydome_task_params_); } } diff --git a/source/blender/render/hydra/light_tasks_delegate.h b/source/blender/render/hydra/light_tasks_delegate.h index 022d730f3aba..ac99e4932623 100644 --- a/source/blender/render/hydra/light_tasks_delegate.h +++ b/source/blender/render/hydra/light_tasks_delegate.h @@ -15,16 +15,15 @@ class LightTasksDelegate : public pxr::HdSceneDelegate { ~LightTasksDelegate() override = default; pxr::HdTaskSharedPtrVector get_tasks(); - void set_camera_path(pxr::SdfPath const &); void set_camera_and_viewport(pxr::SdfPath const &camera_id, pxr::GfVec4d const &viewport); /* Delegate methods */ pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override; private: - pxr::SdfPath simple_light_task; - pxr::SdfPath skydome_task; - pxr::HdxSimpleLightTaskParams simple_light_task_params_; + pxr::SdfPath simple_task_id_; + pxr::SdfPath skydome_task_id_; + pxr::HdxSimpleLightTaskParams simple_task_params_; pxr::HdxRenderTaskParams skydome_task_params_; }; diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index e5a72b0aef29..b16c4ad776ae 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -238,7 +238,6 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context) view_settings.border[3])); if (light_tasks_delegate_) { - light_tasks_delegate_->set_camera_path(free_camera_delegate_->GetCameraId()); light_tasks_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(), pxr::GfVec4d(view_settings.border[0], view_settings.border[1], -- 2.30.2 From 008c9d2b147cebfd9118c192948d95a20e890778 Mon Sep 17 00:00:00 2001 From: Vasyl-Pidhirskyi Date: Thu, 20 Jul 2023 12:59:44 +0300 Subject: [PATCH 5/5] Added comment. --- source/blender/render/hydra/light_tasks_delegate.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/blender/render/hydra/light_tasks_delegate.cc b/source/blender/render/hydra/light_tasks_delegate.cc index eb99d1a1fd61..237ac8b0fc4b 100644 --- a/source/blender/render/hydra/light_tasks_delegate.cc +++ b/source/blender/render/hydra/light_tasks_delegate.cc @@ -20,6 +20,9 @@ LightTasksDelegate::LightTasksDelegate(pxr::HdRenderIndex *parent_index, pxr::HdTaskSharedPtrVector LightTasksDelegate::get_tasks() { + /*Note that this task is intended to be the first "Render Task", + so that the AOV's are properly cleared, however it + does not spawn a HdRenderPass.*/ return {GetRenderIndex().GetTask(skydome_task_id_), GetRenderIndex().GetTask(simple_task_id_)}; } -- 2.30.2