forked from blender/blender
WIP: Support more AOVs #72
@ -31,6 +31,10 @@ class CustomHydraRenderEngine(HydraRenderEngine):
|
|||||||
'enableTinyPrimCulling': True,
|
'enableTinyPrimCulling': True,
|
||||||
'maxLights': 8,
|
'maxLights': 8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 +145,10 @@ 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. """
|
||||||
|
@ -11,22 +11,28 @@
|
|||||||
#include "GPU_framebuffer.h"
|
#include "GPU_framebuffer.h"
|
||||||
#include "GPU_texture.h"
|
#include "GPU_texture.h"
|
||||||
#include "PIL_time.h"
|
#include "PIL_time.h"
|
||||||
|
#include "BLI_map.hh"
|
||||||
#include "IMB_imbuf_types.h"
|
#include "IMB_imbuf_types.h"
|
||||||
|
|
||||||
#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)
|
||||||
{
|
{
|
||||||
prepare_for_render(depsgraph);
|
prepare_for_render(depsgraph);
|
||||||
render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color);
|
|
||||||
|
for (auto &it : render_images_) {
|
||||||
|
render_task_delegate_->set_renderer_aov(aovs_map_.lookup(it.first));
|
||||||
|
}
|
||||||
|
|
||||||
engine_->Execute(render_index_.get(), &tasks_);
|
engine_->Execute(render_index_.get(), &tasks_);
|
||||||
|
|
||||||
std::vector<float> &pixels = render_images_["Combined"];
|
|
||||||
char elapsed_time[32];
|
char elapsed_time[32];
|
||||||
double time_begin = PIL_check_seconds_timer();
|
double time_begin = PIL_check_seconds_timer();
|
||||||
float percent_done = 0.0;
|
float percent_done = 0.0;
|
||||||
@ -47,12 +53,14 @@ void FinalEngine::render(Depsgraph *depsgraph)
|
|||||||
if (render_task_delegate_->is_converged()) {
|
if (render_task_delegate_->is_converged()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
for (auto &it : render_images_) {
|
||||||
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
|
render_task_delegate_->get_renderer_aov_data(aovs_map_.lookup(it.first), it.second.data());
|
||||||
|
}
|
||||||
update_render_result();
|
update_render_result();
|
||||||
}
|
}
|
||||||
|
for (auto &it : render_images_) {
|
||||||
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
|
render_task_delegate_->get_renderer_aov_data(aovs_map_.lookup(it.first), it.second.data());
|
||||||
|
}
|
||||||
update_render_result();
|
update_render_result();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,11 +119,25 @@ void FinalEngine::prepare_for_render(Depsgraph *depsgraph)
|
|||||||
free_camera_delegate_->GetCameraId(), pxr::GfVec4d(0, 0, resolution_[0], resolution_[1]));
|
free_camera_delegate_->GetCameraId(), pxr::GfVec4d(0, 0, resolution_[0], resolution_[1]));
|
||||||
tasks_ = light_tasks_delegate_->get_tasks();
|
tasks_ = light_tasks_delegate_->get_tasks();
|
||||||
}
|
}
|
||||||
tasks_.push_back(render_task_delegate_->get_task());
|
for (auto &task : render_task_delegate_->get_tasks()) {
|
||||||
|
tasks_.push_back(task);
|
||||||
|
}
|
||||||
|
|
||||||
render_images_.emplace(
|
aovs_map_.add_new("Combined", pxr::HdAovTokens->color);
|
||||||
"Combined",
|
aovs_map_.add_new("Depth", pxr::HdAovTokens->depth);
|
||||||
std::vector<float>(resolution_[0] * resolution_[1] * 4)); /* 4 - number of channels. */
|
|
||||||
|
if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) {
|
||||||
|
aovs_map_.add_new("Normal", pxr::HdAovTokens->normal);
|
||||||
|
aovs_map_.add_new("Position", pxr::tokens_->worldCoordinate);
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
if (aovs_map_.lookup_key_ptr(pass->name)) {
|
||||||
|
render_images_.emplace(pass->name, std::vector<float>(pass->rectx * pass->recty * pass->channels));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FinalEngineGPU::render(Depsgraph *depsgraph)
|
void FinalEngineGPU::render(Depsgraph *depsgraph)
|
||||||
@ -134,7 +156,7 @@ void FinalEngineGPU::render(Depsgraph *depsgraph)
|
|||||||
resolution_[0],
|
resolution_[0],
|
||||||
resolution_[1],
|
resolution_[1],
|
||||||
1,
|
1,
|
||||||
GPU_DEPTH32F_STENCIL8,
|
GPU_DEPTH_COMPONENT32F,
|
||||||
GPU_TEXTURE_USAGE_GENERAL,
|
GPU_TEXTURE_USAGE_GENERAL,
|
||||||
nullptr);
|
nullptr);
|
||||||
GPU_texture_filter_mode(tex_color, true);
|
GPU_texture_filter_mode(tex_color, true);
|
||||||
@ -159,10 +181,10 @@ void FinalEngineGPU::render(Depsgraph *depsgraph)
|
|||||||
|
|
||||||
engine_->Execute(render_index_.get(), &tasks_);
|
engine_->Execute(render_index_.get(), &tasks_);
|
||||||
|
|
||||||
std::vector<float> &pixels = render_images_["Combined"];
|
|
||||||
char elapsed_time[32];
|
char elapsed_time[32];
|
||||||
double time_begin = PIL_check_seconds_timer();
|
double time_begin = PIL_check_seconds_timer();
|
||||||
float percent_done = 0.0;
|
float percent_done = 0.0;
|
||||||
|
void *data;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (RE_engine_test_break(bl_engine_)) {
|
if (RE_engine_test_break(bl_engine_)) {
|
||||||
@ -183,16 +205,37 @@ void FinalEngineGPU::render(Depsgraph *depsgraph)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *data = GPU_texture_read(tex_color, GPU_DATA_FLOAT, 0);
|
for (auto &it : render_images_) {
|
||||||
memcpy(pixels.data(), data, pixels.size() * sizeof(float));
|
if (it.first == "Comdined") {
|
||||||
|
data = GPU_texture_read(tex_color, GPU_DATA_FLOAT, 0);
|
||||||
|
memcpy(it.second.data(), data, it.second.size() * sizeof(float));
|
||||||
|
MEM_freeN(data);
|
||||||
|
update_render_result();
|
||||||
|
|
||||||
|
}
|
||||||
|
if (it.first == "Depth") {
|
||||||
|
data = GPU_texture_read(tex_depth, GPU_DATA_FLOAT, 0);
|
||||||
|
memcpy(it.second.data(), data, it.second.size() * sizeof(float));
|
||||||
MEM_freeN(data);
|
MEM_freeN(data);
|
||||||
update_render_result();
|
update_render_result();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void *data = GPU_texture_read(tex_color, GPU_DATA_FLOAT, 0);
|
for (auto &it : render_images_) {
|
||||||
memcpy(pixels.data(), data, pixels.size() * sizeof(float));
|
if (it.first == "Combined") {
|
||||||
|
data = GPU_texture_read(tex_color, GPU_DATA_FLOAT, 0);
|
||||||
|
memcpy(it.second.data(), data, it.second.size() * sizeof(float));
|
||||||
MEM_freeN(data);
|
MEM_freeN(data);
|
||||||
update_render_result();
|
update_render_result();
|
||||||
|
}
|
||||||
|
if (it.first == "Depth") {
|
||||||
|
data = GPU_texture_read(tex_depth, GPU_DATA_FLOAT, 0);
|
||||||
|
memcpy(it.second.data(), data, it.second.size() * sizeof(float));
|
||||||
|
MEM_freeN(data);
|
||||||
|
update_render_result();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
glDeleteVertexArrays(1, &VAO);
|
glDeleteVertexArrays(1, &VAO);
|
||||||
GPU_framebuffer_free(framebuffer);
|
GPU_framebuffer_free(framebuffer);
|
||||||
|
@ -24,6 +24,7 @@ class FinalEngine : public Engine {
|
|||||||
std::string layer_name_;
|
std::string layer_name_;
|
||||||
std::map<std::string, std::vector<float>> render_images_;
|
std::map<std::string, std::vector<float>> render_images_;
|
||||||
pxr::GfVec2i resolution_;
|
pxr::GfVec2i resolution_;
|
||||||
|
Map<std::string, pxr::TfToken> aovs_map_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FinalEngineGPU : public FinalEngine {
|
class FinalEngineGPU : public FinalEngine {
|
||||||
|
@ -15,20 +15,28 @@ RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parent_index,
|
|||||||
pxr::SdfPath const &delegate_id)
|
pxr::SdfPath const &delegate_id)
|
||||||
: pxr::HdSceneDelegate(parent_index, delegate_id)
|
: pxr::HdSceneDelegate(parent_index, delegate_id)
|
||||||
{
|
{
|
||||||
pxr::SdfPath render_task_id = get_task_id();
|
render_task_id_ = GetDelegateID().AppendElementString("task");
|
||||||
GetRenderIndex().InsertTask<pxr::HdxRenderTask>(this, render_task_id);
|
GetRenderIndex().InsertTask<pxr::HdxRenderTask>(this, render_task_id_);
|
||||||
GetRenderIndex().GetChangeTracker().MarkTaskDirty(render_task_id,
|
GetRenderIndex().GetChangeTracker().MarkTaskDirty(render_task_id_,
|
||||||
pxr::HdChangeTracker::DirtyCollection);
|
pxr::HdChangeTracker::DirtyCollection);
|
||||||
GetRenderIndex().GetChangeTracker().MarkTaskDirty(render_task_id,
|
GetRenderIndex().GetChangeTracker().MarkTaskDirty(render_task_id_,
|
||||||
pxr::HdChangeTracker::DirtyRenderTags);
|
pxr::HdChangeTracker::DirtyRenderTags);
|
||||||
|
|
||||||
|
|
||||||
task_params_.enableLighting = true;
|
task_params_.enableLighting = true;
|
||||||
task_params_.alphaThreshold = 0.1f;
|
task_params_.alphaThreshold = 0.1f;
|
||||||
|
|
||||||
|
aov_task_id_ = GetDelegateID().AppendElementString("aovTask");
|
||||||
|
GetRenderIndex().InsertTask<pxr::HdxVisualizeAovTask>(this, aov_task_id_);
|
||||||
|
GetRenderIndex().GetChangeTracker().MarkTaskDirty(aov_task_id_,
|
||||||
|
pxr::HdChangeTracker::DirtyCollection);
|
||||||
|
GetRenderIndex().GetChangeTracker().MarkTaskDirty(aov_task_id_,
|
||||||
|
pxr::HdChangeTracker::DirtyRenderTags);
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::SdfPath RenderTaskDelegate::get_task_id() const
|
pxr::HdTaskSharedPtrVector RenderTaskDelegate::get_tasks()
|
||||||
{
|
{
|
||||||
return GetDelegateID().AppendElementString("task");
|
return {GetRenderIndex().GetTask(aov_task_id_), GetRenderIndex().GetTask(render_task_id_)};
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::SdfPath RenderTaskDelegate::get_aov_id(pxr::TfToken const &aov) const
|
pxr::SdfPath RenderTaskDelegate::get_aov_id(pxr::TfToken const &aov) const
|
||||||
@ -38,7 +46,7 @@ pxr::SdfPath RenderTaskDelegate::get_aov_id(pxr::TfToken const &aov) const
|
|||||||
|
|
||||||
bool RenderTaskDelegate::is_converged()
|
bool RenderTaskDelegate::is_converged()
|
||||||
{
|
{
|
||||||
pxr::HdTaskSharedPtr renderTask = GetRenderIndex().GetTask(get_task_id());
|
pxr::HdTaskSharedPtr renderTask = GetRenderIndex().GetTask(render_task_id_);
|
||||||
return ((pxr::HdxRenderTask &)*renderTask).IsConverged();
|
return ((pxr::HdxRenderTask &)*renderTask).IsConverged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +72,7 @@ void RenderTaskDelegate::set_renderer_aov(pxr::TfToken const &aov)
|
|||||||
binding.aovSettings = aov_desc.aovSettings;
|
binding.aovSettings = aov_desc.aovSettings;
|
||||||
task_params_.aovBindings.push_back(binding);
|
task_params_.aovBindings.push_back(binding);
|
||||||
|
|
||||||
GetRenderIndex().GetChangeTracker().MarkTaskDirty(get_task_id(),
|
GetRenderIndex().GetChangeTracker().MarkTaskDirty(render_task_id_,
|
||||||
pxr::HdChangeTracker::DirtyParams);
|
pxr::HdChangeTracker::DirtyParams);
|
||||||
}
|
}
|
||||||
else if (buffer_descriptors_[buffer_id] != desc) {
|
else if (buffer_descriptors_[buffer_id] != desc) {
|
||||||
@ -90,27 +98,28 @@ void RenderTaskDelegate::get_renderer_aov_data(pxr::TfToken const &aov, void *da
|
|||||||
buffer->Unmap();
|
buffer->Unmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::HdTaskSharedPtr RenderTaskDelegate::get_task()
|
|
||||||
{
|
|
||||||
return GetRenderIndex().GetTask(get_task_id());
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderTaskDelegate::set_camera_and_viewport(pxr::SdfPath const &camera_id,
|
void RenderTaskDelegate::set_camera_and_viewport(pxr::SdfPath const &camera_id,
|
||||||
pxr::GfVec4d const &viewport)
|
pxr::GfVec4d const &viewport)
|
||||||
{
|
{
|
||||||
if (task_params_.viewport != viewport || task_params_.camera != camera_id) {
|
if (task_params_.viewport != viewport || task_params_.camera != camera_id) {
|
||||||
task_params_.viewport = viewport;
|
task_params_.viewport = viewport;
|
||||||
task_params_.camera = camera_id;
|
task_params_.camera = camera_id;
|
||||||
GetRenderIndex().GetChangeTracker().MarkTaskDirty(get_task_id(),
|
GetRenderIndex().GetChangeTracker().MarkTaskDirty(render_task_id_,
|
||||||
pxr::HdChangeTracker::DirtyParams);
|
pxr::HdChangeTracker::DirtyParams);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const & /*id*/, pxr::TfToken const &key)
|
pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key)
|
||||||
{
|
{
|
||||||
if (key == pxr::HdTokens->params) {
|
if (key == pxr::HdTokens->params) {
|
||||||
|
if (id == aov_task_id_) {
|
||||||
|
aov_task_params_.aovName = pxr::HdAovTokens->depth;
|
||||||
|
return pxr::VtValue(aov_task_params_);
|
||||||
|
}
|
||||||
|
else if (id == render_task_id_) {
|
||||||
return pxr::VtValue(task_params_);
|
return pxr::VtValue(task_params_);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (key == pxr::HdTokens->collection) {
|
if (key == pxr::HdTokens->collection) {
|
||||||
pxr::HdRprimCollection rprim_collection(pxr::HdTokens->geometry,
|
pxr::HdRprimCollection rprim_collection(pxr::HdTokens->geometry,
|
||||||
pxr::HdReprSelector(pxr::HdReprTokens->smoothHull),
|
pxr::HdReprSelector(pxr::HdReprTokens->smoothHull),
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <pxr/imaging/hd/sceneDelegate.h>
|
#include <pxr/imaging/hd/sceneDelegate.h>
|
||||||
#include <pxr/imaging/hdx/renderSetupTask.h>
|
#include <pxr/imaging/hdx/renderSetupTask.h>
|
||||||
|
#include <pxr/imaging/hdx/visualizeAovTask.h>
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ class RenderTaskDelegate : public pxr::HdSceneDelegate {
|
|||||||
RenderTaskDelegate(pxr::HdRenderIndex *parent_index, pxr::SdfPath const &delegate_id);
|
RenderTaskDelegate(pxr::HdRenderIndex *parent_index, pxr::SdfPath const &delegate_id);
|
||||||
~RenderTaskDelegate() override = default;
|
~RenderTaskDelegate() override = default;
|
||||||
|
|
||||||
pxr::SdfPath get_task_id() const;
|
pxr::HdTaskSharedPtrVector get_tasks();
|
||||||
pxr::SdfPath get_aov_id(pxr::TfToken const &aov) const;
|
pxr::SdfPath get_aov_id(pxr::TfToken const &aov) const;
|
||||||
|
|
||||||
bool is_converged();
|
bool is_converged();
|
||||||
@ -21,7 +22,6 @@ class RenderTaskDelegate : public pxr::HdSceneDelegate {
|
|||||||
pxr::HdRenderBuffer *get_renderer_aov(pxr::TfToken const &id);
|
pxr::HdRenderBuffer *get_renderer_aov(pxr::TfToken const &id);
|
||||||
void get_renderer_aov_data(pxr::TfToken const &id, void *buf);
|
void get_renderer_aov_data(pxr::TfToken const &id, void *buf);
|
||||||
|
|
||||||
pxr::HdTaskSharedPtr get_task();
|
|
||||||
void set_camera_and_viewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport);
|
void set_camera_and_viewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport);
|
||||||
|
|
||||||
/* Delegate methods */
|
/* Delegate methods */
|
||||||
@ -30,6 +30,9 @@ class RenderTaskDelegate : public pxr::HdSceneDelegate {
|
|||||||
pxr::TfTokenVector GetTaskRenderTags(pxr::SdfPath const &taskId) override;
|
pxr::TfTokenVector GetTaskRenderTags(pxr::SdfPath const &taskId) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
pxr::SdfPath aov_task_id_;
|
||||||
|
pxr::SdfPath render_task_id_;
|
||||||
|
pxr::HdxVisualizeAovTaskParams aov_task_params_;
|
||||||
pxr::HdxRenderTaskParams task_params_;
|
pxr::HdxRenderTaskParams task_params_;
|
||||||
pxr::TfHashMap<pxr::SdfPath, pxr::HdRenderBufferDescriptor, pxr::SdfPath::Hash>
|
pxr::TfHashMap<pxr::SdfPath, pxr::HdRenderBufferDescriptor, pxr::SdfPath::Hash>
|
||||||
buffer_descriptors_;
|
buffer_descriptors_;
|
||||||
|
@ -256,7 +256,9 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context)
|
|||||||
if (light_tasks_delegate_) {
|
if (light_tasks_delegate_) {
|
||||||
tasks = light_tasks_delegate_->get_tasks();
|
tasks = light_tasks_delegate_->get_tasks();
|
||||||
}
|
}
|
||||||
tasks.push_back(render_task_delegate_->get_task());
|
for (auto &task : render_task_delegate_->get_tasks()) {
|
||||||
|
tasks.push_back(task);
|
||||||
|
}
|
||||||
|
|
||||||
engine_->Execute(render_index_.get(), &tasks);
|
engine_->Execute(render_index_.get(), &tasks);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user