Implement transparent background for Storm delegate #71

Merged
Bogdan Nagirniak merged 3 commits from Vasyl-Pidhirskyi/blender_bn:BLEN-463 into hydra-render 2023-07-23 21:03:02 +02:00
6 changed files with 19 additions and 10 deletions
Showing only changes of commit 84764add0b - Show all commits

View File

@ -71,7 +71,7 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context)
if (!hydra_scene_delegate_) { if (!hydra_scene_delegate_) {
pxr::SdfPath scene_path = pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"); pxr::SdfPath scene_path = pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene");
hydra_scene_delegate_ = std::make_unique<BlenderSceneDelegate>( hydra_scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
render_index_.get(), scene_path, scene_delegate_settings_); render_index_.get(), scene_path, scene_delegate_settings);
} }
hydra_scene_delegate_->populate(depsgraph, context); hydra_scene_delegate_->populate(depsgraph, context);
} }
@ -86,7 +86,7 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context)
if (!usd_scene_delegate_) { if (!usd_scene_delegate_) {
pxr::SdfPath scene_path = pxr::SdfPath::AbsoluteRootPath().AppendElementString("usd_scene"); pxr::SdfPath scene_path = pxr::SdfPath::AbsoluteRootPath().AppendElementString("usd_scene");
usd_scene_delegate_ = std::make_unique<USDSceneDelegate>( usd_scene_delegate_ = std::make_unique<USDSceneDelegate>(
render_index_.get(), scene_path, scene_delegate_settings_); render_index_.get(), scene_path, scene_delegate_settings);
} }
usd_scene_delegate_->populate(depsgraph, context); 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) void Engine::set_sync_setting(const std::string &key, const pxr::VtValue &val)
{ {
if (key == "MaterialXFilenameKey") { if (key == "MaterialXFilenameKey") {
scene_delegate_settings_.mx_filename_key = pxr::TfToken(val.Get<std::string>()); scene_delegate_settings.mx_filename_key = pxr::TfToken(val.Get<std::string>());
} }
else { else {
scene_delegate_settings_.render_tokens.add_overwrite(pxr::TfToken(key), val); scene_delegate_settings.render_tokens.add_overwrite(pxr::TfToken(key), val);
} }
} }

View File

@ -39,6 +39,7 @@ class Engine {
void set_render_setting(const std::string &key, const pxr::VtValue &val); void set_render_setting(const std::string &key, const pxr::VtValue &val);
std::string render_delegate_name; std::string render_delegate_name;
SceneDelegateSettings scene_delegate_settings;
Vasyl-Pidhirskyi marked this conversation as resolved Outdated

That's not a good idea to change structure of engine just for using skydome task from light_tasks_delegate_.

That's not a good idea to change structure of engine just for using skydome task from `light_tasks_delegate_`.
protected: protected:
float renderer_percent_done(); float renderer_percent_done();
@ -51,7 +52,6 @@ class Engine {
pxr::HdPluginRenderDelegateUniqueHandle render_delegate_; pxr::HdPluginRenderDelegateUniqueHandle render_delegate_;
std::unique_ptr<pxr::HdRenderIndex> render_index_; std::unique_ptr<pxr::HdRenderIndex> render_index_;
SceneDelegateSettings scene_delegate_settings_;
std::unique_ptr<BlenderSceneDelegate> hydra_scene_delegate_; std::unique_ptr<BlenderSceneDelegate> hydra_scene_delegate_;
std::unique_ptr<USDSceneDelegate> usd_scene_delegate_; std::unique_ptr<USDSceneDelegate> usd_scene_delegate_;

View File

@ -109,7 +109,7 @@ void FinalEngine::prepare_for_render(Depsgraph *depsgraph)
if (light_tasks_delegate_) { if (light_tasks_delegate_) {
light_tasks_delegate_->set_camera_and_viewport( 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_ = light_tasks_delegate_->get_tasks(scene_delegate_settings);
Vasyl-Pidhirskyi marked this conversation as resolved Outdated

Find corresponded c++ setting for scene.render.film_transparent

Find corresponded c++ setting for `scene.render.film_transparent`
} }
tasks_.push_back(render_task_delegate_->get_task()); tasks_.push_back(render_task_delegate_->get_task());

View File

@ -1,6 +1,7 @@
/* SPDX-License-Identifier: Apache-2.0 /* SPDX-License-Identifier: Apache-2.0
* Copyright 2011-2022 Blender Foundation */ * Copyright 2011-2022 Blender Foundation */
#include "BLI_map.hh"
#include <pxr/imaging/hdx/simpleLightTask.h> #include <pxr/imaging/hdx/simpleLightTask.h>
#include <pxr/imaging/hdx/skydomeTask.h> #include <pxr/imaging/hdx/skydomeTask.h>
@ -18,12 +19,18 @@ LightTasksDelegate::LightTasksDelegate(pxr::HdRenderIndex *parent_index,
GetRenderIndex().InsertTask<pxr::HdxSimpleLightTask>(this, simple_task_id_); GetRenderIndex().InsertTask<pxr::HdxSimpleLightTask>(this, simple_task_id_);
} }
pxr::HdTaskSharedPtrVector LightTasksDelegate::get_tasks() pxr::HdTaskSharedPtrVector LightTasksDelegate::get_tasks(const SceneDelegateSettings &settings)
Vasyl-Pidhirskyi marked this conversation as resolved Outdated

simplify by using something like bool transparent_background

simplify by using something like `bool transparent_background`
{ {
/*Note that this task is intended to be the first "Render Task", /*Note that this task is intended to be the first "Render Task",
so that the AOV's are properly cleared, however it so that the AOV's are properly cleared, however it
does not spawn a HdRenderPass.*/ 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<bool>()) {
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, void LightTasksDelegate::set_camera_and_viewport(pxr::SdfPath const &camera_id,

View File

@ -3,6 +3,8 @@
#pragma once #pragma once
#include "scene_delegate/blender_scene_delegate.h"
#include "scene_delegate/usd_scene_delegate.hh"
#include <pxr/imaging/hd/sceneDelegate.h> #include <pxr/imaging/hd/sceneDelegate.h>
#include <pxr/imaging/hdx/renderSetupTask.h> #include <pxr/imaging/hdx/renderSetupTask.h>
#include <pxr/imaging/hdx/simpleLightTask.h> #include <pxr/imaging/hdx/simpleLightTask.h>
@ -14,7 +16,7 @@ class LightTasksDelegate : public pxr::HdSceneDelegate {
LightTasksDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegate_id); LightTasksDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegate_id);
~LightTasksDelegate() override = default; ~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); void set_camera_and_viewport(pxr::SdfPath const &camera_id, pxr::GfVec4d const &viewport);
/* Delegate methods */ /* Delegate methods */

View File

@ -254,7 +254,7 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context)
pxr::HdTaskSharedPtrVector tasks; pxr::HdTaskSharedPtrVector tasks;
if (light_tasks_delegate_) { 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()); tasks.push_back(render_task_delegate_->get_task());