From 84764add0b4d49466a3c58606e55e9ecc3447e7c Mon Sep 17 00:00:00 2001 From: Vasyl-Pidhirskyi Date: Fri, 21 Jul 2023 17:42:36 +0300 Subject: [PATCH 1/2] Moved scene_delegate_settings_ to public as scene_delegate_settings. Adjusted get_tasks with condition for sky dome tast and added argument scene_delegate_settings. --- source/blender/render/hydra/engine.cc | 8 ++++---- source/blender/render/hydra/engine.h | 2 +- source/blender/render/hydra/final_engine.cc | 2 +- source/blender/render/hydra/light_tasks_delegate.cc | 11 +++++++++-- source/blender/render/hydra/light_tasks_delegate.h | 4 +++- source/blender/render/hydra/viewport_engine.cc | 2 +- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 7be85fb22430..8c64d903a703 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -71,7 +71,7 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context) if (!hydra_scene_delegate_) { pxr::SdfPath scene_path = pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"); hydra_scene_delegate_ = std::make_unique( - render_index_.get(), scene_path, scene_delegate_settings_); + render_index_.get(), scene_path, scene_delegate_settings); } hydra_scene_delegate_->populate(depsgraph, context); } @@ -86,7 +86,7 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context) if (!usd_scene_delegate_) { pxr::SdfPath scene_path = pxr::SdfPath::AbsoluteRootPath().AppendElementString("usd_scene"); usd_scene_delegate_ = std::make_unique( - render_index_.get(), scene_path, scene_delegate_settings_); + render_index_.get(), scene_path, scene_delegate_settings); } usd_scene_delegate_->populate(depsgraph, context); } @@ -95,10 +95,10 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context) void Engine::set_sync_setting(const std::string &key, const pxr::VtValue &val) { if (key == "MaterialXFilenameKey") { - scene_delegate_settings_.mx_filename_key = pxr::TfToken(val.Get()); + scene_delegate_settings.mx_filename_key = pxr::TfToken(val.Get()); } else { - scene_delegate_settings_.render_tokens.add_overwrite(pxr::TfToken(key), val); + scene_delegate_settings.render_tokens.add_overwrite(pxr::TfToken(key), val); } } diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index ebfb32a4a7a1..0dcfe5c9e7e3 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -39,6 +39,7 @@ class Engine { void set_render_setting(const std::string &key, const pxr::VtValue &val); std::string render_delegate_name; + SceneDelegateSettings scene_delegate_settings; protected: float renderer_percent_done(); @@ -51,7 +52,6 @@ class Engine { pxr::HdPluginRenderDelegateUniqueHandle render_delegate_; std::unique_ptr render_index_; - SceneDelegateSettings scene_delegate_settings_; std::unique_ptr hydra_scene_delegate_; std::unique_ptr usd_scene_delegate_; diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index ebc6d91c9218..74242d5278e6 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -109,7 +109,7 @@ void FinalEngine::prepare_for_render(Depsgraph *depsgraph) 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_ = light_tasks_delegate_->get_tasks(scene_delegate_settings); } 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 237ac8b0fc4b..84d83f487757 100644 --- a/source/blender/render/hydra/light_tasks_delegate.cc +++ b/source/blender/render/hydra/light_tasks_delegate.cc @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: Apache-2.0 * Copyright 2011-2022 Blender Foundation */ +#include "BLI_map.hh" #include #include @@ -18,12 +19,18 @@ LightTasksDelegate::LightTasksDelegate(pxr::HdRenderIndex *parent_index, GetRenderIndex().InsertTask(this, simple_task_id_); } -pxr::HdTaskSharedPtrVector LightTasksDelegate::get_tasks() +pxr::HdTaskSharedPtrVector LightTasksDelegate::get_tasks(const SceneDelegateSettings &settings) { /*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_)}; + pxr::HdTaskSharedPtrVector tasks; + const pxr::VtValue *ret_ptr = settings.render_tokens.lookup_ptr(pxr::TfToken("enableAlpha")); + if (ret_ptr->Get()) { + tasks.push_back(GetRenderIndex().GetTask(skydome_task_id_)); + } + tasks.push_back(GetRenderIndex().GetTask(simple_task_id_)); + return tasks; } void LightTasksDelegate::set_camera_and_viewport(pxr::SdfPath const &camera_id, diff --git a/source/blender/render/hydra/light_tasks_delegate.h b/source/blender/render/hydra/light_tasks_delegate.h index ac99e4932623..a3d99f6f996d 100644 --- a/source/blender/render/hydra/light_tasks_delegate.h +++ b/source/blender/render/hydra/light_tasks_delegate.h @@ -3,6 +3,8 @@ #pragma once +#include "scene_delegate/blender_scene_delegate.h" +#include "scene_delegate/usd_scene_delegate.hh" #include #include #include @@ -14,7 +16,7 @@ class LightTasksDelegate : public pxr::HdSceneDelegate { LightTasksDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegate_id); ~LightTasksDelegate() override = default; - pxr::HdTaskSharedPtrVector get_tasks(); + pxr::HdTaskSharedPtrVector get_tasks(const SceneDelegateSettings &settings); void set_camera_and_viewport(pxr::SdfPath const &camera_id, pxr::GfVec4d const &viewport); /* Delegate methods */ diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index b16c4ad776ae..15b3f1feb25e 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -254,7 +254,7 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context) pxr::HdTaskSharedPtrVector tasks; if (light_tasks_delegate_) { - tasks = light_tasks_delegate_->get_tasks(); + tasks = light_tasks_delegate_->get_tasks(scene_delegate_settings); } tasks.push_back(render_task_delegate_->get_task()); -- 2.30.2 From c2a8dc5209360b3058f7e199a105c85e3a2b1165 Mon Sep 17 00:00:00 2001 From: Vasyl-Pidhirskyi Date: Sun, 23 Jul 2023 17:37:43 +0300 Subject: [PATCH 2/2] Revert changes. Utilized scene.render.film_transparent build-in blender property for Storm delegate. Adjusted clear_color to alpha 0.0 for final render. --- source/blender/render/hydra/engine.cc | 8 ++++---- source/blender/render/hydra/engine.h | 2 +- source/blender/render/hydra/final_engine.cc | 4 ++-- source/blender/render/hydra/light_tasks_delegate.cc | 6 ++---- source/blender/render/hydra/light_tasks_delegate.h | 4 +--- source/blender/render/hydra/viewport_engine.cc | 5 +++-- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 8c64d903a703..7be85fb22430 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -71,7 +71,7 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context) if (!hydra_scene_delegate_) { pxr::SdfPath scene_path = pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"); hydra_scene_delegate_ = std::make_unique( - render_index_.get(), scene_path, scene_delegate_settings); + render_index_.get(), scene_path, scene_delegate_settings_); } hydra_scene_delegate_->populate(depsgraph, context); } @@ -86,7 +86,7 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context) if (!usd_scene_delegate_) { pxr::SdfPath scene_path = pxr::SdfPath::AbsoluteRootPath().AppendElementString("usd_scene"); usd_scene_delegate_ = std::make_unique( - render_index_.get(), scene_path, scene_delegate_settings); + render_index_.get(), scene_path, scene_delegate_settings_); } usd_scene_delegate_->populate(depsgraph, context); } @@ -95,10 +95,10 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context) void Engine::set_sync_setting(const std::string &key, const pxr::VtValue &val) { if (key == "MaterialXFilenameKey") { - scene_delegate_settings.mx_filename_key = pxr::TfToken(val.Get()); + scene_delegate_settings_.mx_filename_key = pxr::TfToken(val.Get()); } else { - scene_delegate_settings.render_tokens.add_overwrite(pxr::TfToken(key), val); + scene_delegate_settings_.render_tokens.add_overwrite(pxr::TfToken(key), val); } } diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index 0dcfe5c9e7e3..ebfb32a4a7a1 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -39,7 +39,6 @@ class Engine { void set_render_setting(const std::string &key, const pxr::VtValue &val); std::string render_delegate_name; - SceneDelegateSettings scene_delegate_settings; protected: float renderer_percent_done(); @@ -52,6 +51,7 @@ class Engine { pxr::HdPluginRenderDelegateUniqueHandle render_delegate_; std::unique_ptr render_index_; + SceneDelegateSettings scene_delegate_settings_; std::unique_ptr hydra_scene_delegate_; std::unique_ptr usd_scene_delegate_; diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index 74242d5278e6..88a4d451402c 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -109,7 +109,7 @@ void FinalEngine::prepare_for_render(Depsgraph *depsgraph) 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(scene_delegate_settings); + tasks_ = light_tasks_delegate_->get_tasks(scene->r.alphamode == R_ALPHAPREMUL); } tasks_.push_back(render_task_delegate_->get_task()); @@ -147,7 +147,7 @@ void FinalEngineGPU::render(Depsgraph *depsgraph) GPU_framebuffer_bind(framebuffer); - float clear_color[4] = {0.0f, 0.0f, 0.0f, 1.0f}; + float clear_color[4] = {0.0f, 0.0f, 0.0f, 0.0f}; GPU_framebuffer_clear_color_depth(framebuffer, clear_color, 1.0f); diff --git a/source/blender/render/hydra/light_tasks_delegate.cc b/source/blender/render/hydra/light_tasks_delegate.cc index 84d83f487757..dc817d17ce2a 100644 --- a/source/blender/render/hydra/light_tasks_delegate.cc +++ b/source/blender/render/hydra/light_tasks_delegate.cc @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: Apache-2.0 * Copyright 2011-2022 Blender Foundation */ -#include "BLI_map.hh" #include #include @@ -19,14 +18,13 @@ LightTasksDelegate::LightTasksDelegate(pxr::HdRenderIndex *parent_index, GetRenderIndex().InsertTask(this, simple_task_id_); } -pxr::HdTaskSharedPtrVector LightTasksDelegate::get_tasks(const SceneDelegateSettings &settings) +pxr::HdTaskSharedPtrVector LightTasksDelegate::get_tasks(const bool isTransparent) { /*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.*/ pxr::HdTaskSharedPtrVector tasks; - const pxr::VtValue *ret_ptr = settings.render_tokens.lookup_ptr(pxr::TfToken("enableAlpha")); - if (ret_ptr->Get()) { + if (!isTransparent) { tasks.push_back(GetRenderIndex().GetTask(skydome_task_id_)); } tasks.push_back(GetRenderIndex().GetTask(simple_task_id_)); diff --git a/source/blender/render/hydra/light_tasks_delegate.h b/source/blender/render/hydra/light_tasks_delegate.h index a3d99f6f996d..ea1db5adba43 100644 --- a/source/blender/render/hydra/light_tasks_delegate.h +++ b/source/blender/render/hydra/light_tasks_delegate.h @@ -3,8 +3,6 @@ #pragma once -#include "scene_delegate/blender_scene_delegate.h" -#include "scene_delegate/usd_scene_delegate.hh" #include #include #include @@ -16,7 +14,7 @@ class LightTasksDelegate : public pxr::HdSceneDelegate { LightTasksDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegate_id); ~LightTasksDelegate() override = default; - pxr::HdTaskSharedPtrVector get_tasks(const SceneDelegateSettings &settings); + pxr::HdTaskSharedPtrVector get_tasks(const bool isTransparent); void set_camera_and_viewport(pxr::SdfPath const &camera_id, pxr::GfVec4d const &viewport); /* Delegate methods */ diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 15b3f1feb25e..1d02441fcea5 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -222,9 +222,10 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */) /* Empty function */ } -void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context) +void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) { ViewSettings view_settings(context); + const Scene *scene = DEG_get_evaluated_scene(depsgraph); if (view_settings.width() * view_settings.height() == 0) { return; }; @@ -254,7 +255,7 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context) pxr::HdTaskSharedPtrVector tasks; if (light_tasks_delegate_) { - tasks = light_tasks_delegate_->get_tasks(scene_delegate_settings); + tasks = light_tasks_delegate_->get_tasks(scene->r.alphamode == R_ALPHAPREMUL); } tasks.push_back(render_task_delegate_->get_task()); -- 2.30.2