diff --git a/source/blender/render/hydra/CMakeLists.txt b/source/blender/render/hydra/CMakeLists.txt index 3da25f21f4b0..b48afc4feb21 100644 --- a/source/blender/render/hydra/CMakeLists.txt +++ b/source/blender/render/hydra/CMakeLists.txt @@ -88,8 +88,8 @@ set(SRC render_task_delegate.cc render_task_delegate.h - simple_light_task_delegate.cc - simple_light_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 618a7b96072d..7be85fb22430 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -53,9 +53,8 @@ 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") { - simple_light_task_delegate_ = std::make_unique( - render_index_.get(), - pxr::SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask")); + light_tasks_delegate_ = std::make_unique( + 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 d2b4776d5ef2..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 "light_tasks_delegate.h" #include "render_task_delegate.h" -#include "simple_light_task_delegate.h" #include "scene_delegate/blender_scene_delegate.h" #include "scene_delegate/usd_scene_delegate.hh" @@ -57,7 +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 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 e6b48744a9e5..ebc6d91c9218 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -106,10 +106,10 @@ 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 (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_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()); @@ -149,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 new file mode 100644 index 000000000000..237ac8b0fc4b --- /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_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() +{ + /*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_)}; +} + +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_id_, + pxr::HdChangeTracker::DirtyParams); + } +} + +pxr::VtValue LightTasksDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) +{ + if (key == pxr::HdTokens->params) { + if (id == simple_task_id_) { + return pxr::VtValue(simple_task_params_); + } + else if (id == skydome_task_id_) { + 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..ac99e4932623 --- /dev/null +++ b/source/blender/render/hydra/light_tasks_delegate.h @@ -0,0 +1,30 @@ +/* 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_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_task_id_; + pxr::SdfPath skydome_task_id_; + pxr::HdxSimpleLightTaskParams simple_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/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 75306e459e6a..b16c4ad776ae 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -236,8 +236,13 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context) 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 (light_tasks_delegate_) { + 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 ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) { @@ -248,8 +253,8 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context) GPU_shader_bind(shader); pxr::HdTaskSharedPtrVector tasks; - 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());