forked from blender/blender
WIP: Support more AOVs #72
@ -119,12 +119,17 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
aovs_map_.add_new("Combined", pxr::HdAovTokens->color);
|
aovs_map_.add_new("Combined", pxr::HdAovTokens->color);
|
||||||
aovs_map_.add_new("Depth", pxr::HdAovTokens->depth);
|
aovs_map_.add_new("Depth", pxr::HdAovTokens->depth);
|
||||||
|
|
||||||
|
if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) {
|
||||||
aovs_map_.add_new("Normal", pxr::HdAovTokens->normal);
|
aovs_map_.add_new("Normal", pxr::HdAovTokens->normal);
|
||||||
aovs_map_.add_new("Position", pxr::tokens_->worldCoordinate);
|
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;
|
||||||
@ -151,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);
|
||||||
@ -176,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_)) {
|
||||||
@ -200,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);
|
||||||
|
@ -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