forked from blender/blender
Make DomeLight visible for Storm delegate #68
@ -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
|
||||
|
@ -53,9 +53,8 @@ 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") {
|
||||
simple_light_task_delegate_ = std::make_unique<SimpleLightTaskDelegate>(
|
||||
render_index_.get(),
|
||||
pxr::SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask"));
|
||||
light_tasks_delegate_ = std::make_unique<LightTasksDelegate>(
|
||||
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("lightTasks"));
|
||||
}
|
||||
|
||||
engine_ = std::make_unique<pxr::HdEngine>();
|
||||
|
@ -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<RenderTaskDelegate> render_task_delegate_;
|
||||
std::unique_ptr<pxr::HdxFreeCameraSceneDelegate> free_camera_delegate_;
|
||||
std::unique_ptr<SimpleLightTaskDelegate> simple_light_task_delegate_;
|
||||
std::unique_ptr<LightTasksDelegate> light_tasks_delegate_;
|
||||
std::unique_ptr<pxr::HdEngine> engine_;
|
||||
};
|
||||
|
||||
|
@ -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<pxr::GfVec3f>();
|
||||
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
|
||||
|
58
source/blender/render/hydra/light_tasks_delegate.cc
Normal file
58
source/blender/render/hydra/light_tasks_delegate.cc
Normal 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_id_ = GetDelegateID().AppendElementString("simpleLightTask");
|
||||
simple_task_id_ = GetDelegateID().AppendElementString("skydomeTask");
|
||||
GetRenderIndex().InsertTask<pxr::HdxSkydomeTask>(this, skydome_task_id_);
|
||||
GetRenderIndex().InsertTask<pxr::HdxSimpleLightTask>(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
|
30
source/blender/render/hydra/light_tasks_delegate.h
Normal file
30
source/blender/render/hydra/light_tasks_delegate.h
Normal file
@ -0,0 +1,30 @@
|
||||
/* 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_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
|
@ -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
|
@ -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
|
@ -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());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user