Support more AOVs #78

Merged
Bogdan Nagirniak merged 11 commits from DagerD/blender:BLEN-462_3 into hydra-render 2023-07-29 14:45:16 +02:00
10 changed files with 33 additions and 65 deletions
Showing only changes of commit 7d1f4838e0 - Show all commits

View File

@ -30,7 +30,12 @@ class CustomHydraRenderEngine(HydraRenderEngine):
return { return {
'enableTinyPrimCulling': True, 'enableTinyPrimCulling': True,
'maxLights': 8, 'maxLights': 8,
'aov:Depth': "depth",
} }
def update_render_passes(self, scene, render_layer):
if render_layer.use_pass_z:
self.register_pass(scene, render_layer, 'Depth', 1, 'Z', 'VALUE')
``` ```
""" """
@ -141,6 +146,9 @@ class HydraRenderEngine(bpy.types.RenderEngine):
_bpy_hydra.engine_view_draw(self.engine_ptr, depsgraph.as_pointer(), context.as_pointer()) _bpy_hydra.engine_view_draw(self.engine_ptr, depsgraph.as_pointer(), context.as_pointer())
def update_render_passes(self, scene, render_layer):
""" Register supported AOVs for render. Must be overridden in child classes. """
pass
def export_mtlx(material): def export_mtlx(material):
""" Exports material to .mtlx file. It is called from Blender source code. """ """ Exports material to .mtlx file. It is called from Blender source code. """

View File

@ -91,6 +91,8 @@ set(SRC
light_tasks_delegate.cc light_tasks_delegate.cc
light_tasks_delegate.h light_tasks_delegate.h
settings.h
scene_delegate/blender_scene_delegate.cc scene_delegate/blender_scene_delegate.cc
scene_delegate/blender_scene_delegate.h scene_delegate/blender_scene_delegate.h
scene_delegate/curves.cc scene_delegate/curves.cc
@ -111,7 +113,6 @@ set(SRC
scene_delegate/mtlx_hydra_adapter.h scene_delegate/mtlx_hydra_adapter.h
scene_delegate/object.cc scene_delegate/object.cc
scene_delegate/object.h scene_delegate/object.h
scene_delegate/settings.h
scene_delegate/usd_scene_delegate.cc scene_delegate/usd_scene_delegate.cc
scene_delegate/usd_scene_delegate.hh scene_delegate/usd_scene_delegate.hh
scene_delegate/volume.cc scene_delegate/volume.cc

View File

@ -112,7 +112,12 @@ void Engine::set_sync_setting(const std::string &key, const pxr::VtValue &val)
void Engine::set_render_setting(const std::string &key, const pxr::VtValue &val) void Engine::set_render_setting(const std::string &key, const pxr::VtValue &val)
{ {
render_delegate_->SetRenderSetting(pxr::TfToken(key), val); if (key._Starts_with("aov:")) {
render_delegate_settings_.aovs.add_new(key.substr(key.find(":") + 1), pxr::TfToken(val.UncheckedGet<std::string>()));
}
else {
render_delegate_->SetRenderSetting(pxr::TfToken(key), val);
}
} }
float Engine::renderer_percent_done() float Engine::renderer_percent_done()

View File

@ -55,6 +55,7 @@ class Engine {
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_;
RenderDelegateSettings render_delegate_settings_;
std::unique_ptr<RenderTaskDelegate> render_task_delegate_; std::unique_ptr<RenderTaskDelegate> render_task_delegate_;
std::unique_ptr<pxr::HdxFreeCameraSceneDelegate> free_camera_delegate_; std::unique_ptr<pxr::HdxFreeCameraSceneDelegate> free_camera_delegate_;
std::unique_ptr<LightTasksDelegate> light_tasks_delegate_; std::unique_ptr<LightTasksDelegate> light_tasks_delegate_;

View File

@ -14,10 +14,6 @@
#include "camera.h" #include "camera.h"
#include "final_engine.h" #include "final_engine.h"
PXR_NAMESPACE_OPEN_SCOPE
TF_DEFINE_PRIVATE_TOKENS(tokens_, (worldCoordinate));
PXR_NAMESPACE_CLOSE_SCOPE
namespace blender::render::hydra { namespace blender::render::hydra {
void FinalEngine::render(Depsgraph *depsgraph) void FinalEngine::render(Depsgraph *depsgraph)
@ -49,15 +45,15 @@ void FinalEngine::render(Depsgraph *depsgraph)
light_tasks_delegate_->set_viewport(pxr::GfVec4d(0, 0, resolution_[0], resolution_[1])); light_tasks_delegate_->set_viewport(pxr::GfVec4d(0, 0, resolution_[0], resolution_[1]));
} }
aovs_map_.add_new("Combined", pxr::HdAovTokens->color); render_task_delegate_->add_aov(pxr::HdAovTokens->color);
aovs_map_.add_new("Depth", pxr::HdAovTokens->depth); if (bl_engine_->type->flag & RE_USE_GPU_CONTEXT) {
aovs_map_.add_new("Normal", pxr::HdAovTokens->normal); render_task_delegate_->add_aov(pxr::HdAovTokens->depth);
aovs_map_.add_new("Position", pxr::tokens_->worldCoordinate); }
RenderResult *result = RE_engine_get_result(bl_engine_); RenderResult *result = RE_engine_get_result(bl_engine_);
RenderLayer *layer = (RenderLayer *)result->layers.first; RenderLayer *layer = (RenderLayer *)result->layers.first;
for (RenderPass *pass = (RenderPass *)layer->passes.first; pass != nullptr; pass = pass->next) { for (RenderPass *pass = (RenderPass *)layer->passes.first; pass != nullptr; pass = pass->next) {
pxr::TfToken *aov_token = aovs_map_.lookup_ptr(pass->name); pxr::TfToken *aov_token = render_delegate_settings_.aovs.lookup_ptr(pass->name);
if (aov_token) { if (aov_token) {
render_task_delegate_->add_aov(*aov_token); render_task_delegate_->add_aov(*aov_token);
} }
@ -72,10 +68,7 @@ void FinalEngine::render(Depsgraph *depsgraph)
} }
tasks.push_back(light_tasks_delegate_->simple_task()); tasks.push_back(light_tasks_delegate_->simple_task());
} }
if (bl_engine_->type->flag & RE_USE_GPU_CONTEXT) { tasks.push_back(render_task_delegate_->task());
tasks.push_back(static_cast<GPURenderTaskDelegate *>(render_task_delegate_.get())->aov_task());
}
tasks.push_back(render_task_delegate_->render_task());
engine_->Execute(render_index_.get(), &tasks); engine_->Execute(render_index_.get(), &tasks);
char elapsed_time[32]; char elapsed_time[32];
@ -95,7 +88,7 @@ void FinalEngine::render(Depsgraph *depsgraph)
std::string("Render Time: ") + elapsed_time + std::string("Render Time: ") + elapsed_time +
" | Done: " + std::to_string(int(percent_done)) + "%"); " | Done: " + std::to_string(int(percent_done)) + "%");
if (render_task_delegate_->is_converged(render_task_delegate_->render_task())) { if (render_task_delegate_->is_converged()) {
break; break;
} }
@ -120,7 +113,7 @@ void FinalEngine::update_render_result()
/* TODO: only for the first render layer */ /* TODO: only for the first render layer */
RenderLayer *layer = (RenderLayer *)result->layers.first; RenderLayer *layer = (RenderLayer *)result->layers.first;
for (RenderPass *pass = (RenderPass *)layer->passes.first; pass != nullptr; pass = pass->next) { for (RenderPass *pass = (RenderPass *)layer->passes.first; pass != nullptr; pass = pass->next) {
pxr::TfToken *aov_token = aovs_map_.lookup_ptr(pass->name); pxr::TfToken *aov_token = render_delegate_settings_.aovs.lookup_ptr(pass->name);
if (aov_token) { if (aov_token) {
render_task_delegate_->read_aov(*aov_token, pass->ibuf->float_buffer.data); render_task_delegate_->read_aov(*aov_token, pass->ibuf->float_buffer.data);
} }

View File

@ -20,9 +20,6 @@ class FinalEngine : public Engine {
std::string scene_name_; std::string scene_name_;
std::string layer_name_; std::string layer_name_;
pxr::GfVec2i resolution_; pxr::GfVec2i resolution_;
/* Map supported Blender AOV to corresponded Hydra AOV token */
Map<std::string, pxr::TfToken> aovs_map_;
}; };
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -55,7 +55,7 @@ pxr::HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(pxr:
return buffer_descriptors_[id]; return buffer_descriptors_[id];
} }
pxr::HdTaskSharedPtr RenderTaskDelegate::render_task() pxr::HdTaskSharedPtr RenderTaskDelegate::task()
{ {
return GetRenderIndex().GetTask(render_task_id_); return GetRenderIndex().GetTask(render_task_id_);
} }
@ -70,9 +70,9 @@ void RenderTaskDelegate::set_camera(pxr::SdfPath const &camera_id)
pxr::HdChangeTracker::DirtyParams); pxr::HdChangeTracker::DirtyParams);
} }
bool RenderTaskDelegate::is_converged(pxr::HdTaskSharedPtr task) bool RenderTaskDelegate::is_converged()
{ {
return ((pxr::HdxRenderTask *)task.get())->IsConverged(); return ((pxr::HdxRenderTask *)task().get())->IsConverged();
} }
void RenderTaskDelegate::set_viewport(pxr::GfVec4d const &viewport) void RenderTaskDelegate::set_viewport(pxr::GfVec4d const &viewport)
@ -160,36 +160,6 @@ pxr::SdfPath RenderTaskDelegate::buffer_id(pxr::TfToken const &aov_key) const
return GetDelegateID().AppendElementString("aov_" + aov_key.GetString()); return GetDelegateID().AppendElementString("aov_" + aov_key.GetString());
} }
GPURenderTaskDelegate::GPURenderTaskDelegate(pxr::HdRenderIndex *parent_index,
pxr::SdfPath const &delegate_id)
: RenderTaskDelegate(parent_index, delegate_id)
{
aov_task_id_ = GetDelegateID().AppendElementString("aovTask");
GetRenderIndex().InsertTask<pxr::HdxVisualizeAovTask>(this, aov_task_id_);
CLOG_INFO(LOG_RENDER_HYDRA, 1, "%s", aov_task_id_.GetText());
}
pxr::VtValue GPURenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key)
{
CLOG_INFO(LOG_RENDER_HYDRA, 3, "%s, %s", id.GetText(), key.GetText());
if (id == render_task_id_) {
return RenderTaskDelegate::Get(id, key);
}
if (key == pxr::HdTokens->params) {
return pxr::VtValue(aov_task_params_);
}
return pxr::VtValue();
}
pxr::HdTaskSharedPtr GPURenderTaskDelegate::aov_task()
{
return GetRenderIndex().GetTask(aov_task_id_);
}
void GPURenderTaskDelegate::set_viewport(pxr::GfVec4d const &viewport) void GPURenderTaskDelegate::set_viewport(pxr::GfVec4d const &viewport)
{ {
if (render_task_params_.viewport == viewport) { if (render_task_params_.viewport == viewport) {

View File

@ -22,9 +22,9 @@ class RenderTaskDelegate : public pxr::HdSceneDelegate {
pxr::TfTokenVector GetTaskRenderTags(pxr::SdfPath const &id) override; pxr::TfTokenVector GetTaskRenderTags(pxr::SdfPath const &id) override;
pxr::HdRenderBufferDescriptor GetRenderBufferDescriptor(pxr::SdfPath const &id) override; pxr::HdRenderBufferDescriptor GetRenderBufferDescriptor(pxr::SdfPath const &id) override;
pxr::HdTaskSharedPtr render_task(); pxr::HdTaskSharedPtr task();
bool is_converged(pxr::HdTaskSharedPtr task);
void set_camera(pxr::SdfPath const &camera_id); void set_camera(pxr::SdfPath const &camera_id);
virtual bool is_converged();
virtual void set_viewport(pxr::GfVec4d const &viewport); virtual void set_viewport(pxr::GfVec4d const &viewport);
virtual void add_aov(pxr::TfToken const &aov_key); virtual void add_aov(pxr::TfToken const &aov_key);
virtual void read_aov(pxr::TfToken const &aov_key, void *data); virtual void read_aov(pxr::TfToken const &aov_key, void *data);
@ -43,13 +43,8 @@ class RenderTaskDelegate : public pxr::HdSceneDelegate {
class GPURenderTaskDelegate : public RenderTaskDelegate { class GPURenderTaskDelegate : public RenderTaskDelegate {
public: public:
GPURenderTaskDelegate(pxr::HdRenderIndex *parent_index, pxr::SdfPath const &delegate_id); using RenderTaskDelegate::RenderTaskDelegate;
~GPURenderTaskDelegate() override = default;
/* Delegate methods */
pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override;
pxr::HdTaskSharedPtr aov_task();
void set_viewport(pxr::GfVec4d const &viewport) override; void set_viewport(pxr::GfVec4d const &viewport) override;
void add_aov(pxr::TfToken const &aov_key) override; void add_aov(pxr::TfToken const &aov_key) override;
void read_aov(pxr::TfToken const &aov_key, void *data) override; void read_aov(pxr::TfToken const &aov_key, void *data) override;
@ -58,8 +53,6 @@ class GPURenderTaskDelegate : public RenderTaskDelegate {
void unbind() override; void unbind() override;
private: private:
pxr::SdfPath aov_task_id_;
pxr::HdxVisualizeAovTaskParams aov_task_params_;
GPUFrameBuffer *framebuffer_ = nullptr; GPUFrameBuffer *framebuffer_ = nullptr;
GPUTexture *tex_color_ = nullptr; GPUTexture *tex_color_ = nullptr;
GPUTexture *tex_depth_ = nullptr; GPUTexture *tex_depth_ = nullptr;

View File

@ -242,7 +242,7 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
} }
tasks.push_back(light_tasks_delegate_->simple_task()); tasks.push_back(light_tasks_delegate_->simple_task());
} }
tasks.push_back(render_task_delegate_->render_task()); tasks.push_back(render_task_delegate_->task());
engine_->Execute(render_index_.get(), &tasks); engine_->Execute(render_index_.get(), &tasks);
if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) { if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) {
@ -262,7 +262,7 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
BLI_timecode_string_from_time_simple( BLI_timecode_string_from_time_simple(
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin_); elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin_);
if (!render_task_delegate_->is_converged(render_task_delegate_->render_task())) { if (!render_task_delegate_->is_converged()) {
notify_status(std::string("Time: ") + elapsed_time + notify_status(std::string("Time: ") + elapsed_time +
" | Done: " + std::to_string(int(renderer_percent_done())) + "%", " | Done: " + std::to_string(int(renderer_percent_done())) + "%",
"Render"); "Render");