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
7 changed files with 96 additions and 1 deletions
Showing only changes of commit dee103b084 - Show all commits

View File

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

View File

@ -53,6 +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>(
render_index_.get(),
pxr::SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask"));

View File

@ -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<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<pxr::HdEngine> engine_;
};

View File

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

View File

@ -0,0 +1,47 @@
/* 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

@ -0,0 +1,27 @@
/* 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,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());
}