Make DomeLight visible for Storm delegate #68

Merged
Bogdan Nagirniak merged 5 commits from Vasyl-Pidhirskyi/blender_bn:BLEN-460 into hydra-render 2023-07-20 22:35:48 +02:00
11 changed files with 107 additions and 174 deletions
Showing only changes of commit 1fd428b393 - Show all commits

View File

@ -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

View File

@ -53,12 +53,9 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name)
render_task_delegate_ = std::make_unique<RenderTaskDelegate>(
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask"));
if (render_delegate_name == "HdStormRendererPlugin") {
skydome_task_delegate_ = std::make_unique<SkydomeTaskDelegate>(
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("skydomeTask"));
simple_light_task_delegate_ = std::make_unique<SimpleLightTaskDelegate>(
light_tasks_delegate_ = std::make_unique<LightTasksDelegate>(
render_index_.get(),
pxr::SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask"));
pxr::SdfPath::AbsoluteRootPath().AppendElementString("lightTasks"));
}
engine_ = std::make_unique<pxr::HdEngine>();

View File

@ -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<RenderTaskDelegate> render_task_delegate_;
std::unique_ptr<pxr::HdxFreeCameraSceneDelegate> free_camera_delegate_;
std::unique_ptr<SimpleLightTaskDelegate> simple_light_task_delegate_;
std::unique_ptr<SkydomeTaskDelegate> skydome_task_delegate_;
std::unique_ptr<LightTasksDelegate> light_tasks_delegate_;
std::unique_ptr<pxr::HdEngine> engine_;
};

View File

@ -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());

View File

@ -0,0 +1,58 @@
/* SPDX-License-Identifier: Apache-2.0
* Copyright 2011-2022 Blender Foundation */
#include <pxr/imaging/hdx/simpleLightTask.h>
#include <pxr/imaging/hdx/skydomeTask.h>
#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<pxr::HdxSkydomeTask>(this, skydome_task);
GetRenderIndex().InsertTask<pxr::HdxSimpleLightTask>(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

View File

@ -0,0 +1,31 @@
/* SPDX-License-Identifier: Apache-2.0
* Copyright 2011-2022 Blender Foundation */
#pragma once
#include <pxr/imaging/hd/sceneDelegate.h>
#include <pxr/imaging/hdx/renderSetupTask.h>
#include <pxr/imaging/hdx/simpleLightTask.h>
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

View File

@ -1,41 +0,0 @@
/* SPDX-License-Identifier: Apache-2.0
* Copyright 2011-2022 Blender Foundation */
#include <pxr/imaging/hdx/simpleLightTask.h>
#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<pxr::HdxSimpleLightTask>(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

View File

@ -1,28 +0,0 @@
/* SPDX-License-Identifier: Apache-2.0
* Copyright 2011-2022 Blender Foundation */
#pragma once
#include <pxr/imaging/hd/sceneDelegate.h>
#include <pxr/imaging/hdx/simpleLightTask.h>
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

View File

@ -1,47 +0,0 @@
/* SPDX-License-Identifier: Apache-2.0
* Copyright 2011-2022 Blender Foundation */
#include <pxr/imaging/hdx/skydomeTask.h>
#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<pxr::HdxSkydomeTask>(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

View File

@ -1,27 +0,0 @@
/* SPDX-License-Identifier: Apache-2.0
* Copyright 2011-2022 Blender Foundation */
#pragma once
#include <pxr/imaging/hd/sceneDelegate.h>
#include <pxr/imaging/hdx/skydomeTask.h>
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

View File

@ -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());