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
11 changed files with 72 additions and 26 deletions

View File

@ -28,6 +28,7 @@ class CustomHydraRenderEngine(bpy.types.HydraRenderEngine):
return { return {
'myBoolean': True, 'myBoolean': True,
'myValue': 8, 'myValue': 8,
'aovToken:Depth': "depth",
} }
# Settings used by the synchronization process. # Settings used by the synchronization process.
@ -43,6 +44,11 @@ class CustomHydraRenderEngine(bpy.types.HydraRenderEngine):
super().update(data, depsgraph) super().update(data, depsgraph)
# Do extra work here # Do extra work here
def update_render_passes(self, scene, render_layer):
if render_layer.use_pass_z:
self.register_pass(scene, render_layer, 'Depth', 1, 'Z', 'VALUE')
# Registration # Registration
def register(): def register():
bpy.utils.register_class(CustomHydraRenderEngine) bpy.utils.register_class(CustomHydraRenderEngine)

View File

@ -1283,6 +1283,7 @@ class HydraRenderEngine(RenderEngine):
# Final render. # Final render.
def update(self, data, depsgraph): def update(self, data, depsgraph):
import _bpy_hydra import _bpy_hydra
import bpy
engine_type = 'PREVIEW' if self.is_preview else 'FINAL' engine_type = 'PREVIEW' if self.is_preview else 'FINAL'
if not self.engine_ptr: if not self.engine_ptr:
@ -1293,7 +1294,7 @@ class HydraRenderEngine(RenderEngine):
for key, val in self.get_sync_settings(engine_type).items(): for key, val in self.get_sync_settings(engine_type).items():
_bpy_hydra.engine_set_sync_setting(self.engine_ptr, key, val) _bpy_hydra.engine_set_sync_setting(self.engine_ptr, key, val)
_bpy_hydra.engine_update(self.engine_ptr, depsgraph, None) _bpy_hydra.engine_update(self.engine_ptr, depsgraph, bpy.context)
for key, val in self.get_render_settings('PREVIEW' if self.is_preview else 'FINAL').items(): for key, val in self.get_render_settings('PREVIEW' if self.is_preview else 'FINAL').items():
_bpy_hydra.engine_set_render_setting(self.engine_ptr, key, val) _bpy_hydra.engine_set_render_setting(self.engine_ptr, key, val)

View File

@ -245,7 +245,7 @@ pxr::GfCamera CameraData::gf_camera(pxr::GfVec4f tile)
switch (mode_) { switch (mode_) {
case CAM_PERSP: case CAM_PERSP:
case CAM_PANO: { case CAM_PANO: {
/* TODO: store panoramic camera settings */ /* TODO: store panoramic camera settings */
gf_camera.SetProjection(pxr::GfCamera::Projection::Perspective); gf_camera.SetProjection(pxr::GfCamera::Projection::Perspective);
gf_camera.SetFocalLength(focal_length_); gf_camera.SetFocalLength(focal_length_);

View File

@ -45,11 +45,11 @@ class InstancerData : public IdData {
void update_double_sided(MaterialData *mat_data); void update_double_sided(MaterialData *mat_data);
/* Following update functions are working together: /* Following update functions are working together:
pre_update() * pre_update()
update_instance() * update_instance()
update_instance() * update_instance()
... * ...
post_update() */ * post_update() */
void pre_update(); void pre_update();
void update_instance(Object *parent_ob, DupliObject *dupli); void update_instance(Object *parent_ob, DupliObject *dupli);
void post_update(); void post_update();

View File

@ -33,8 +33,6 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name)
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
/* USD has limited support for Vulkan. To make it works USD should be built
* with PXR_ENABLE_VULKAN_SUPPORT=TRUE which is not possible now */
if (GPU_backend_get_type() == GPU_BACKEND_VULKAN) { if (GPU_backend_get_type() == GPU_BACKEND_VULKAN) {
BLI_setenv("HGI_ENABLE_VULKAN", "1"); BLI_setenv("HGI_ENABLE_VULKAN", "1");
} }
@ -120,7 +118,13 @@ 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 (STRPREFIX(key.c_str(), "aovToken:")) {
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

@ -29,6 +29,10 @@ namespace blender::render::hydra {
extern struct CLG_LogRef *LOG_RENDER_HYDRA; extern struct CLG_LogRef *LOG_RENDER_HYDRA;
struct RenderDelegateSettings {
Map<std::string, pxr::TfToken> aovs;
};
class Engine { class Engine {
protected: protected:
std::string render_delegate_name_; std::string render_delegate_name_;
@ -44,6 +48,7 @@ class Engine {
std::unique_ptr<io::hydra::HydraSceneDelegate> hydra_scene_delegate_; std::unique_ptr<io::hydra::HydraSceneDelegate> hydra_scene_delegate_;
std::unique_ptr<io::hydra::USDSceneDelegate> usd_scene_delegate_; std::unique_ptr<io::hydra::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

@ -23,8 +23,6 @@
namespace blender::render::hydra { namespace blender::render::hydra {
/* FinalEngine implementation */
void FinalEngine::render(Depsgraph *depsgraph) void FinalEngine::render(Depsgraph *depsgraph)
{ {
const Scene *scene = DEG_get_evaluated_scene(depsgraph); const Scene *scene = DEG_get_evaluated_scene(depsgraph);
@ -55,7 +53,18 @@ void FinalEngine::render(Depsgraph *depsgraph)
} }
render_task_delegate_->add_aov(pxr::HdAovTokens->color); render_task_delegate_->add_aov(pxr::HdAovTokens->color);
render_task_delegate_->add_aov(pxr::HdAovTokens->depth); if (bl_engine_->type->flag & RE_USE_GPU_CONTEXT) {
render_task_delegate_->add_aov(pxr::HdAovTokens->depth);
}
RenderResult *result = RE_engine_get_result(bl_engine_);
RenderLayer *layer = (RenderLayer *)result->layers.first;
for (RenderPass *pass = (RenderPass *)layer->passes.first; pass != nullptr; pass = pass->next) {
pxr::TfToken *aov_token = render_delegate_settings_.aovs.lookup_ptr(pass->name);
if (aov_token) {
render_task_delegate_->add_aov(*aov_token);
}
}
pxr::HdTaskSharedPtrVector tasks; pxr::HdTaskSharedPtrVector tasks;
if (light_tasks_delegate_) { if (light_tasks_delegate_) {
@ -114,14 +123,10 @@ void FinalEngine::update_render_result()
if (rlayer) { if (rlayer) {
LISTBASE_FOREACH (RenderPass *, rpass, &rlayer->passes) { LISTBASE_FOREACH (RenderPass *, rpass, &rlayer->passes) {
pxr::TfToken aov_key; pxr::TfToken *aov_token = render_delegate_settings_.aovs.lookup_ptr(rpass->name);
if (STREQ(rpass->name, "Combined")) { if (aov_token) {
aov_key = pxr::HdAovTokens->color; render_task_delegate_->read_aov(*aov_token, rpass->ibuf->float_buffer.data);
} }
else if (STREQ(rpass->name, "Depth")) {
aov_key = pxr::HdAovTokens->depth;
}
render_task_delegate_->read_aov(aov_key, rpass->ibuf->float_buffer.data);
} }
} }

View File

@ -2,6 +2,7 @@
* SPDX-FileCopyrightText: 2011-2022 Blender Foundation */ * SPDX-FileCopyrightText: 2011-2022 Blender Foundation */
#include "light_tasks_delegate.h" #include "light_tasks_delegate.h"
#include "engine.h"
namespace blender::render::hydra { namespace blender::render::hydra {
@ -13,10 +14,15 @@ LightTasksDelegate::LightTasksDelegate(pxr::HdRenderIndex *parent_index,
GetRenderIndex().InsertTask<pxr::HdxSimpleLightTask>(this, simple_task_id_); GetRenderIndex().InsertTask<pxr::HdxSimpleLightTask>(this, simple_task_id_);
skydome_task_id_ = GetDelegateID().AppendElementString("skydomeTask"); skydome_task_id_ = GetDelegateID().AppendElementString("skydomeTask");
GetRenderIndex().InsertTask<pxr::HdxSkydomeTask>(this, skydome_task_id_); GetRenderIndex().InsertTask<pxr::HdxSkydomeTask>(this, skydome_task_id_);
CLOG_INFO(LOG_RENDER_HYDRA, 1, "%s", simple_task_id_.GetText());
CLOG_INFO(LOG_RENDER_HYDRA, 1, "%s", skydome_task_id_.GetText());
} }
pxr::VtValue LightTasksDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) pxr::VtValue LightTasksDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key)
{ {
CLOG_INFO(LOG_RENDER_HYDRA, 3, "%s, %s", id.GetText(), key.GetText());
if (key == pxr::HdTokens->params) { if (key == pxr::HdTokens->params) {
if (id == simple_task_id_) { if (id == simple_task_id_) {
return pxr::VtValue(simple_task_params_); return pxr::VtValue(simple_task_params_);
@ -36,8 +42,8 @@ pxr::HdTaskSharedPtr LightTasksDelegate::simple_task()
pxr::HdTaskSharedPtr LightTasksDelegate::skydome_task() pxr::HdTaskSharedPtr LightTasksDelegate::skydome_task()
{ {
/* 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_); return GetRenderIndex().GetTask(skydome_task_id_);
} }

View File

@ -13,6 +13,9 @@
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
#include "engine.h"
#include "render_task_delegate.h"
namespace blender::render::hydra { namespace blender::render::hydra {
RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parent_index, RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parent_index,
@ -24,10 +27,14 @@ RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parent_index,
task_params_.enableLighting = true; task_params_.enableLighting = true;
task_params_.alphaThreshold = 0.1f; task_params_.alphaThreshold = 0.1f;
CLOG_INFO(LOG_RENDER_HYDRA, 1, "%s", task_id_.GetText());
} }
pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const & /*id*/, pxr::TfToken const &key) pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key)
{ {
CLOG_INFO(LOG_RENDER_HYDRA, 3, "%s, %s", id.GetText(), key.GetText());
if (key == pxr::HdTokens->params) { if (key == pxr::HdTokens->params) {
return pxr::VtValue(task_params_); return pxr::VtValue(task_params_);
} }
@ -38,13 +45,17 @@ pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const & /*id*/, pxr::TfToken c
return pxr::VtValue(); return pxr::VtValue();
} }
pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const & /*id*/) pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const &id)
{ {
CLOG_INFO(LOG_RENDER_HYDRA, 3, "%s", id.GetText());
return {pxr::HdRenderTagTokens->geometry}; return {pxr::HdRenderTagTokens->geometry};
} }
pxr::HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(pxr::SdfPath const &id) pxr::HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(pxr::SdfPath const &id)
{ {
CLOG_INFO(LOG_RENDER_HYDRA, 3, "%s", id.GetText());
return buffer_descriptors_[id]; return buffer_descriptors_[id];
} }
@ -95,6 +106,10 @@ void RenderTaskDelegate::add_aov(pxr::TfToken const &aov_key)
pxr::HdAovDescriptor aov_desc = render_index.GetRenderDelegate()->GetDefaultAovDescriptor( pxr::HdAovDescriptor aov_desc = render_index.GetRenderDelegate()->GetDefaultAovDescriptor(
aov_key); aov_key);
if (aov_desc.format == pxr::HdFormatInvalid) {
return;
}
int w = task_params_.viewport[2] - task_params_.viewport[0]; int w = task_params_.viewport[2] - task_params_.viewport[0];
int h = task_params_.viewport[3] - task_params_.viewport[1]; int h = task_params_.viewport[3] - task_params_.viewport[1];
render_index.InsertBprim(pxr::HdPrimTypeTokens->renderBuffer, this, buf_id); render_index.InsertBprim(pxr::HdPrimTypeTokens->renderBuffer, this, buf_id);
@ -108,6 +123,8 @@ void RenderTaskDelegate::add_aov(pxr::TfToken const &aov_key)
binding.clearValue = pxr::VtValue(pxr::GfVec4f(0)); binding.clearValue = pxr::VtValue(pxr::GfVec4f(0));
task_params_.aovBindings.push_back(binding); task_params_.aovBindings.push_back(binding);
render_index.GetChangeTracker().MarkTaskDirty(task_id_, pxr::HdChangeTracker::DirtyParams); render_index.GetChangeTracker().MarkTaskDirty(task_id_, pxr::HdChangeTracker::DirtyParams);
CLOG_INFO(LOG_RENDER_HYDRA, 1, "%s", aov_key.GetText());
} }
void RenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, void *data) void RenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, void *data)
@ -189,7 +206,7 @@ void GPURenderTaskDelegate::add_aov(pxr::TfToken const &aov_key)
tex = &tex_color_; tex = &tex_color_;
} }
else if (aov_key == pxr::HdAovTokens->depth) { else if (aov_key == pxr::HdAovTokens->depth) {
format = GPU_DEPTH32F_STENCIL8; format = GPU_DEPTH_COMPONENT32F;
tex = &tex_depth_; tex = &tex_depth_;
} }
else { else {
@ -207,6 +224,8 @@ void GPURenderTaskDelegate::add_aov(pxr::TfToken const &aov_key)
format, format,
GPU_TEXTURE_USAGE_GENERAL, GPU_TEXTURE_USAGE_GENERAL,
nullptr); nullptr);
CLOG_INFO(LOG_RENDER_HYDRA, 1, "%s", aov_key.GetText());
} }
void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, void *data) void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, void *data)

View File

@ -30,8 +30,8 @@ class RenderTaskDelegate : public pxr::HdSceneDelegate {
pxr::HdRenderBufferDescriptor GetRenderBufferDescriptor(pxr::SdfPath const &id) override; pxr::HdRenderBufferDescriptor GetRenderBufferDescriptor(pxr::SdfPath const &id) override;
pxr::HdTaskSharedPtr task(); pxr::HdTaskSharedPtr task();
bool is_converged();
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);

View File