forked from blender/blender
Fix review comments 2 #31
@ -17,12 +17,13 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA, "render.hydra");
|
CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA, "render.hydra");
|
||||||
|
|
||||||
Engine::Engine(RenderEngine *bl_engine, const std::string &delegate_id) : bl_engine_(bl_engine)
|
Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name)
|
||||||
|
: bl_engine_(bl_engine), render_delegate_name_(render_delegate_name)
|
||||||
{
|
{
|
||||||
pxr::HdRendererPluginRegistry ®istry = pxr::HdRendererPluginRegistry::GetInstance();
|
pxr::HdRendererPluginRegistry ®istry = pxr::HdRendererPluginRegistry::GetInstance();
|
||||||
|
|
||||||
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||||
render_delegate_ = registry.CreateRenderDelegate(pxr::TfToken(delegate_id));
|
render_delegate_ = registry.CreateRenderDelegate(pxr::TfToken(render_delegate_name_));
|
||||||
|
|
||||||
/* Current USD (23.02) has limited support for Vulkan. To make it works USD should be built
|
/* Current USD (23.02) has limited support for Vulkan. To make it works USD should be built
|
||||||
* with PXR_ENABLE_VULKAN_SUPPORT=TRUE which is not possible now */
|
* with PXR_ENABLE_VULKAN_SUPPORT=TRUE which is not possible now */
|
||||||
@ -44,7 +45,7 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &delegate_id) : bl_eng
|
|||||||
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("freeCamera"));
|
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("freeCamera"));
|
||||||
render_task_delegate_ = std::make_unique<RenderTaskDelegate>(
|
render_task_delegate_ = std::make_unique<RenderTaskDelegate>(
|
||||||
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask"));
|
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask"));
|
||||||
if (render_delegate_->GetRendererDisplayName() == "GL") {
|
if (render_delegate_name_ == "HdStormRendererPlugin") {
|
||||||
simple_light_task_delegate_ = std::make_unique<SimpleLightTaskDelegate>(
|
simple_light_task_delegate_ = std::make_unique<SimpleLightTaskDelegate>(
|
||||||
render_index_.get(),
|
render_index_.get(),
|
||||||
pxr::SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask"));
|
pxr::SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask"));
|
||||||
|
@ -25,7 +25,7 @@ extern struct CLG_LogRef *LOG_RENDER_HYDRA; /* EN - Engine */
|
|||||||
|
|
||||||
class Engine {
|
class Engine {
|
||||||
public:
|
public:
|
||||||
Engine(RenderEngine *bl_engine, const std::string &render_delegate_id);
|
Engine(RenderEngine *bl_engine, const std::string &render_delegate_name);
|
||||||
virtual ~Engine() = default;
|
virtual ~Engine() = default;
|
||||||
|
|
||||||
virtual void sync(Depsgraph *depsgraph,
|
virtual void sync(Depsgraph *depsgraph,
|
||||||
@ -37,6 +37,7 @@ class Engine {
|
|||||||
float renderer_percent_done();
|
float renderer_percent_done();
|
||||||
|
|
||||||
RenderEngine *bl_engine_;
|
RenderEngine *bl_engine_;
|
||||||
|
std::string render_delegate_name_;
|
||||||
|
|
||||||
/* The order is important due to deletion order */
|
/* The order is important due to deletion order */
|
||||||
pxr::HgiUniquePtr hgi_;
|
pxr::HgiUniquePtr hgi_;
|
||||||
|
@ -20,7 +20,8 @@ void FinalEngine::sync(Depsgraph *depsgraph,
|
|||||||
scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
|
scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
|
||||||
render_index_.get(),
|
render_index_.get(),
|
||||||
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||||
BlenderSceneDelegate::EngineType::FINAL);
|
BlenderSceneDelegate::EngineType::FINAL,
|
||||||
|
render_delegate_name_);
|
||||||
scene_delegate_->populate(depsgraph, context);
|
scene_delegate_->populate(depsgraph, context);
|
||||||
|
|
||||||
for (auto const &setting : render_settings) {
|
for (auto const &setting : render_settings) {
|
||||||
@ -30,48 +31,14 @@ void FinalEngine::sync(Depsgraph *depsgraph,
|
|||||||
|
|
||||||
void FinalEngine::render(Depsgraph *depsgraph)
|
void FinalEngine::render(Depsgraph *depsgraph)
|
||||||
{
|
{
|
||||||
const Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
prepare_for_render(depsgraph);
|
||||||
const ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
|
|
||||||
|
|
||||||
std::string scene_name(MAX_ID_FULL_NAME, 0);
|
std::vector<float> &pixels = render_images_["Combined"];
|
||||||
BKE_id_full_name_get(scene_name.data(), (ID *)scene, 0);
|
|
||||||
std::string layer_name = view_layer->name;
|
|
||||||
|
|
||||||
const RenderData &r = scene->r;
|
|
||||||
pxr::GfVec4f border(0, 0, 1, 1);
|
|
||||||
if (r.mode & R_BORDER) {
|
|
||||||
border = pxr::GfVec4f(r.border.xmin,
|
|
||||||
r.border.ymin,
|
|
||||||
r.border.xmax - r.border.xmin,
|
|
||||||
r.border.ymax - r.border.ymin);
|
|
||||||
}
|
|
||||||
pxr::GfVec2i image_res(r.xsch * r.size / 100, r.ysch * r.size / 100);
|
|
||||||
pxr::GfVec2i res(int(image_res[0] * border[2]), int(image_res[1] * border[3]));
|
|
||||||
pxr::GfCamera camera =
|
|
||||||
CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border);
|
|
||||||
|
|
||||||
free_camera_delegate_->SetCamera(camera);
|
|
||||||
render_task_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(),
|
|
||||||
pxr::GfVec4d(0, 0, res[0], res[1]));
|
|
||||||
render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color);
|
|
||||||
if (simple_light_task_delegate_) {
|
|
||||||
simple_light_task_delegate_->set_camera_path(free_camera_delegate_->GetCameraId());
|
|
||||||
}
|
|
||||||
|
|
||||||
pxr::HdTaskSharedPtrVector tasks;
|
|
||||||
if (simple_light_task_delegate_) {
|
|
||||||
tasks.push_back(simple_light_task_delegate_->get_task());
|
|
||||||
}
|
|
||||||
tasks.push_back(render_task_delegate_->get_task());
|
|
||||||
|
|
||||||
std::map<std::string, std::vector<float>> render_images{
|
|
||||||
{"Combined", std::vector<float>(res[0] * res[1] * 4)}}; /* 4 - number of channels. */
|
|
||||||
std::vector<float> &pixels = render_images["Combined"];
|
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
|
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
|
||||||
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||||
engine_->Execute(render_index_.get(), &tasks);
|
engine_->Execute(render_index_.get(), &tasks_);
|
||||||
}
|
}
|
||||||
|
|
||||||
char elapsed_time[32];
|
char elapsed_time[32];
|
||||||
@ -89,7 +56,7 @@ void FinalEngine::render(Depsgraph *depsgraph)
|
|||||||
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
|
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
|
||||||
|
|
||||||
notify_status(percent_done / 100.0,
|
notify_status(percent_done / 100.0,
|
||||||
scene_name + ": " + layer_name,
|
scene_name_ + ": " + layer_name_,
|
||||||
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)) + "%");
|
||||||
|
|
||||||
@ -98,38 +65,23 @@ void FinalEngine::render(Depsgraph *depsgraph)
|
|||||||
}
|
}
|
||||||
|
|
||||||
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
|
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
|
||||||
update_render_result(render_images, layer_name, res[0], res[1]);
|
update_render_result();
|
||||||
}
|
}
|
||||||
|
|
||||||
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
|
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
|
||||||
update_render_result(render_images, layer_name, res[0], res[1]);
|
update_render_result();
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::GfVec2i FinalEngine::get_resolution(Scene *scene)
|
void FinalEngine::update_render_result()
|
||||||
{
|
|
||||||
RenderData &r = scene->r;
|
|
||||||
float border_w = 1.0, border_h = 1.0;
|
|
||||||
if (r.mode & R_BORDER) {
|
|
||||||
border_w = r.border.xmax - r.border.xmin;
|
|
||||||
border_h = r.border.ymax - r.border.ymin;
|
|
||||||
}
|
|
||||||
return pxr::GfVec2i(int(r.xsch * border_w * r.size / 100),
|
|
||||||
int(r.ysch * border_h * r.size / 100));
|
|
||||||
}
|
|
||||||
|
|
||||||
void FinalEngine::update_render_result(std::map<std::string, std::vector<float>> &render_images,
|
|
||||||
const std::string &layer_name,
|
|
||||||
int width,
|
|
||||||
int height)
|
|
||||||
{
|
{
|
||||||
RenderResult *result = RE_engine_begin_result(
|
RenderResult *result = RE_engine_begin_result(
|
||||||
bl_engine_, 0, 0, width, height, layer_name.c_str(), nullptr);
|
bl_engine_, 0, 0, resolution_[0], resolution_[1], layer_name_.c_str(), nullptr);
|
||||||
|
|
||||||
/* 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) {
|
||||||
auto it_image = render_images.find(pass->name);
|
auto it_image = render_images_.find(pass->name);
|
||||||
if (it_image == render_images.end()) {
|
if (it_image == render_images_.end()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
memcpy(pass->rect,
|
memcpy(pass->rect,
|
||||||
@ -146,52 +98,53 @@ void FinalEngine::notify_status(float progress, const std::string &title, const
|
|||||||
RE_engine_update_stats(bl_engine_, title.c_str(), info.c_str());
|
RE_engine_update_stats(bl_engine_, title.c_str(), info.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FinalEngineGL::render(Depsgraph *depsgraph)
|
void FinalEngine::prepare_for_render(Depsgraph *depsgraph)
|
||||||
{
|
{
|
||||||
const Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
const Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
||||||
const ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
|
const ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
|
||||||
|
|
||||||
std::string scene_name(MAX_ID_FULL_NAME, 0);
|
BKE_id_full_name_get(scene_name_.data(), (ID *)scene, 0);
|
||||||
BKE_id_full_name_get(scene_name.data(), (ID *)scene, 0);
|
layer_name_ = view_layer->name;
|
||||||
std::string layer_name = view_layer->name;
|
|
||||||
|
|
||||||
const RenderData &r = scene->r;
|
const RenderData &r = scene->r;
|
||||||
pxr::GfVec4f border(0, 0, 1, 1);
|
pxr::GfVec4f border(0, 0, 1, 1);
|
||||||
if (r.mode & R_BORDER) {
|
if (r.mode & R_BORDER) {
|
||||||
border = pxr::GfVec4f(r.border.xmin,
|
border.Set(r.border.xmin,
|
||||||
r.border.ymin,
|
r.border.ymin,
|
||||||
r.border.xmax - r.border.xmin,
|
r.border.xmax - r.border.xmin,
|
||||||
r.border.ymax - r.border.ymin);
|
r.border.ymax - r.border.ymin);
|
||||||
}
|
}
|
||||||
pxr::GfVec2i image_res = {r.xsch * r.size / 100, r.ysch * r.size / 100};
|
pxr::GfVec2i image_res(r.xsch * r.size / 100, r.ysch * r.size / 100);
|
||||||
pxr::GfVec2i res = {int(image_res[0] * border[2]), int(image_res[1] * border[3])};
|
resolution_ = pxr::GfVec2i(int(image_res[0] * border[2]), int(image_res[1] * border[3]));
|
||||||
pxr::GfCamera camera =
|
pxr::GfCamera camera =
|
||||||
CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border);
|
CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border);
|
||||||
|
|
||||||
free_camera_delegate_->SetCamera(camera);
|
free_camera_delegate_->SetCamera(camera);
|
||||||
render_task_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(),
|
render_task_delegate_->set_camera_and_viewport(
|
||||||
pxr::GfVec4d(0, 0, res[0], res[1]));
|
free_camera_delegate_->GetCameraId(), pxr::GfVec4d(0, 0, resolution_[0], resolution_[1]));
|
||||||
|
render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color);
|
||||||
|
|
||||||
if (simple_light_task_delegate_) {
|
if (simple_light_task_delegate_) {
|
||||||
simple_light_task_delegate_->set_camera_path(free_camera_delegate_->GetCameraId());
|
simple_light_task_delegate_->set_camera_path(free_camera_delegate_->GetCameraId());
|
||||||
|
tasks_.push_back(simple_light_task_delegate_->get_task());
|
||||||
}
|
}
|
||||||
|
tasks_.push_back(render_task_delegate_->get_task());
|
||||||
|
|
||||||
pxr::HdTaskSharedPtrVector tasks;
|
render_images_.emplace(
|
||||||
if (simple_light_task_delegate_) {
|
"Combined",
|
||||||
/* TODO: Uncomment this and fix GL error:
|
std::vector<float>(resolution_[0] * resolution_[1] * 4)); /* 4 - number of channels. */
|
||||||
* invalid operation, reported from void __cdecl
|
}
|
||||||
* pxrInternal_v0_22__pxrReserved__::HgiGLResourceBindings::BindResources(void) */
|
|
||||||
// tasks.push_back(simple_light_task_delegate_->get_task());
|
|
||||||
}
|
|
||||||
tasks.push_back(render_task_delegate_->get_task());
|
|
||||||
|
|
||||||
std::map<std::string, std::vector<float>> render_images{
|
void FinalEngineGL::render(Depsgraph *depsgraph)
|
||||||
{"Combined", std::vector<float>(res[0] * res[1] * 4)}}; /* 4 - number of channels. */
|
{
|
||||||
std::vector<float> &pixels = render_images["Combined"];
|
prepare_for_render(depsgraph);
|
||||||
|
|
||||||
|
std::vector<float> &pixels = render_images_["Combined"];
|
||||||
|
|
||||||
GPUFrameBuffer *framebuffer = GPU_framebuffer_create("fb_hdyra_render_final");
|
GPUFrameBuffer *framebuffer = GPU_framebuffer_create("fb_hdyra_render_final");
|
||||||
GPUTexture *texture = GPU_texture_create_2d("tex_hydra_render_final",
|
GPUTexture *texture = GPU_texture_create_2d("tex_hydra_render_final",
|
||||||
res[0],
|
resolution_[0],
|
||||||
res[1],
|
resolution_[1],
|
||||||
1,
|
1,
|
||||||
GPU_RGBA32F,
|
GPU_RGBA32F,
|
||||||
GPU_TEXTURE_USAGE_GENERAL,
|
GPU_TEXTURE_USAGE_GENERAL,
|
||||||
@ -207,7 +160,7 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
|||||||
{
|
{
|
||||||
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
|
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
|
||||||
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||||
engine_->Execute(render_index_.get(), &tasks);
|
engine_->Execute(render_index_.get(), &tasks_);
|
||||||
}
|
}
|
||||||
|
|
||||||
char elapsed_time[32];
|
char elapsed_time[32];
|
||||||
@ -225,7 +178,7 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
|||||||
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
|
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
|
||||||
|
|
||||||
notify_status(percent_done / 100.0,
|
notify_status(percent_done / 100.0,
|
||||||
scene_name + ": " + layer_name,
|
scene_name_ + ": " + layer_name_,
|
||||||
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)) + "%");
|
||||||
|
|
||||||
@ -236,13 +189,13 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
|||||||
void *data = GPU_texture_read(texture, GPU_DATA_FLOAT, 0);
|
void *data = GPU_texture_read(texture, GPU_DATA_FLOAT, 0);
|
||||||
memcpy(pixels.data(), data, pixels.size() * sizeof(float));
|
memcpy(pixels.data(), data, pixels.size() * sizeof(float));
|
||||||
MEM_freeN(data);
|
MEM_freeN(data);
|
||||||
update_render_result(render_images, layer_name, res[0], res[1]);
|
update_render_result();
|
||||||
}
|
}
|
||||||
|
|
||||||
void *data = GPU_texture_read(texture, GPU_DATA_FLOAT, 0);
|
void *data = GPU_texture_read(texture, GPU_DATA_FLOAT, 0);
|
||||||
memcpy(pixels.data(), data, pixels.size() * sizeof(float));
|
memcpy(pixels.data(), data, pixels.size() * sizeof(float));
|
||||||
MEM_freeN(data);
|
MEM_freeN(data);
|
||||||
update_render_result(render_images, layer_name, res[0], res[1]);
|
update_render_result();
|
||||||
|
|
||||||
GPU_framebuffer_free(framebuffer);
|
GPU_framebuffer_free(framebuffer);
|
||||||
GPU_texture_free(texture);
|
GPU_texture_free(texture);
|
||||||
|
@ -17,14 +17,16 @@ class FinalEngine : public Engine {
|
|||||||
virtual void render(Depsgraph *b_depsgraph) override;
|
virtual void render(Depsgraph *b_depsgraph) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
pxr::GfVec2i get_resolution(Scene *scene);
|
void update_render_result();
|
||||||
void update_render_result(std::map<std::string, std::vector<float>> &render_images,
|
|
||||||
const std::string &layer_name,
|
|
||||||
int width,
|
|
||||||
int height);
|
|
||||||
void notify_status(float progress, const std::string &title, const std::string &info);
|
void notify_status(float progress, const std::string &title, const std::string &info);
|
||||||
|
void prepare_for_render(Depsgraph *depsgraph);
|
||||||
|
|
||||||
pxr::HdRenderSettingsMap render_settings_;
|
pxr::HdRenderSettingsMap render_settings_;
|
||||||
|
pxr::HdTaskSharedPtrVector tasks_;
|
||||||
|
std::string scene_name_;
|
||||||
|
std::string layer_name_;
|
||||||
|
std::map<std::string, std::vector<float>> render_images_;
|
||||||
|
pxr::GfVec2i resolution_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FinalEngineGL : public FinalEngine {
|
class FinalEngineGL : public FinalEngine {
|
||||||
|
@ -44,7 +44,8 @@ void PreviewEngine::sync(Depsgraph *depsgraph,
|
|||||||
scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
|
scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
|
||||||
render_index_.get(),
|
render_index_.get(),
|
||||||
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||||
BlenderSceneDelegate::EngineType::PREVIEW);
|
BlenderSceneDelegate::EngineType::PREVIEW,
|
||||||
|
render_delegate_name_);
|
||||||
}
|
}
|
||||||
scene_delegate_->clear();
|
scene_delegate_->clear();
|
||||||
scene_delegate_->populate(depsgraph, context);
|
scene_delegate_->populate(depsgraph, context);
|
||||||
@ -56,33 +57,14 @@ void PreviewEngine::sync(Depsgraph *depsgraph,
|
|||||||
|
|
||||||
void PreviewEngine::render(Depsgraph *depsgraph)
|
void PreviewEngine::render(Depsgraph *depsgraph)
|
||||||
{
|
{
|
||||||
const Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
prepare_for_render(depsgraph);
|
||||||
const ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
|
|
||||||
|
|
||||||
std::string layer_name = view_layer->name;
|
std::vector<float> &pixels = render_images_["Combined"];
|
||||||
pxr::GfVec2i res(scene->r.xsch, scene->r.ysch);
|
|
||||||
|
|
||||||
pxr::GfCamera camera =
|
|
||||||
CameraData(scene->camera, res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(pxr::GfVec4f(0, 0, 1, 1));
|
|
||||||
|
|
||||||
free_camera_delegate_->SetCamera(camera);
|
|
||||||
render_task_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(),
|
|
||||||
pxr::GfVec4d(0, 0, res[0], res[1]));
|
|
||||||
render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color);
|
|
||||||
|
|
||||||
pxr::HdTaskSharedPtrVector tasks;
|
|
||||||
if (simple_light_task_delegate_) {
|
|
||||||
tasks.push_back(simple_light_task_delegate_->get_task());
|
|
||||||
}
|
|
||||||
tasks.push_back(render_task_delegate_->get_task());
|
|
||||||
|
|
||||||
std::vector<float> pixels = std::vector<float>(res[0] * res[1] *
|
|
||||||
4); /* 4 - number of channels. */
|
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
|
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
|
||||||
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||||
engine_->Execute(render_index_.get(), &tasks);
|
engine_->Execute(render_index_.get(), &tasks_);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -95,11 +77,11 @@ void PreviewEngine::render(Depsgraph *depsgraph)
|
|||||||
}
|
}
|
||||||
|
|
||||||
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
|
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
|
||||||
update_render_result(layer_name, res[0], res[1], pixels);
|
update_render_result(pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
|
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
|
||||||
update_render_result(layer_name, res[0], res[1], pixels);
|
update_render_result(pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
double PreviewEngine::free_instance(uintptr_t uuid, void *user_data)
|
double PreviewEngine::free_instance(uintptr_t uuid, void *user_data)
|
||||||
@ -120,13 +102,10 @@ void PreviewEngine::update(RenderEngine *bl_engine, const std::string &render_de
|
|||||||
/* TODO: recreate render_delegate when render_delegate_id is changed */
|
/* TODO: recreate render_delegate when render_delegate_id is changed */
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewEngine::update_render_result(const std::string &layer_name,
|
void PreviewEngine::update_render_result(std::vector<float> &pixels)
|
||||||
int width,
|
|
||||||
int height,
|
|
||||||
std::vector<float> &pixels)
|
|
||||||
{
|
{
|
||||||
RenderResult *result = RE_engine_begin_result(
|
RenderResult *result = RE_engine_begin_result(
|
||||||
bl_engine_, 0, 0, width, height, layer_name.c_str(), nullptr);
|
bl_engine_, 0, 0, resolution_[0], resolution_[1], layer_name_.c_str(), nullptr);
|
||||||
|
|
||||||
RenderLayer *layer = (RenderLayer *)result->layers.first;
|
RenderLayer *layer = (RenderLayer *)result->layers.first;
|
||||||
RenderPass *pass = (RenderPass *)layer->passes.first;
|
RenderPass *pass = (RenderPass *)layer->passes.first;
|
||||||
|
@ -26,10 +26,7 @@ class PreviewEngine : public FinalEngine {
|
|||||||
static std::unique_ptr<PreviewEngine> instance_;
|
static std::unique_ptr<PreviewEngine> instance_;
|
||||||
|
|
||||||
void update(RenderEngine *bl_engine, const std::string &render_delegate_id);
|
void update(RenderEngine *bl_engine, const std::string &render_delegate_id);
|
||||||
void update_render_result(const std::string &layer_name,
|
void update_render_result(std::vector<float> &pixels);
|
||||||
int width,
|
|
||||||
int height,
|
|
||||||
std::vector<float> &pixels);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -15,8 +15,11 @@ CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA_SCENE, "render.hydra.scene");
|
|||||||
|
|
||||||
BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
|
BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
|
||||||
pxr::SdfPath const &delegate_id,
|
pxr::SdfPath const &delegate_id,
|
||||||
BlenderSceneDelegate::EngineType engine_type)
|
BlenderSceneDelegate::EngineType engine_type,
|
||||||
: HdSceneDelegate(parent_index, delegate_id), engine_type(engine_type)
|
std::string render_delegate_name)
|
||||||
|
: HdSceneDelegate(parent_index, delegate_id),
|
||||||
|
engine_type(engine_type),
|
||||||
|
render_delegate_name(render_delegate_name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,8 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
|
|
||||||
BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
|
BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
|
||||||
pxr::SdfPath const &delegate_id,
|
pxr::SdfPath const &delegate_id,
|
||||||
BlenderSceneDelegate::EngineType engine_type);
|
BlenderSceneDelegate::EngineType engine_type,
|
||||||
|
std::string render_delegate_name);
|
||||||
~BlenderSceneDelegate() override = default;
|
~BlenderSceneDelegate() override = default;
|
||||||
|
|
||||||
/* Delegate methods */
|
/* Delegate methods */
|
||||||
@ -56,6 +57,8 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
View3D *view3d = nullptr;
|
View3D *view3d = nullptr;
|
||||||
Scene *scene = nullptr;
|
Scene *scene = nullptr;
|
||||||
|
|
||||||
|
std::string render_delegate_name;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pxr::SdfPath prim_id(ID *id, const char *prefix) const;
|
pxr::SdfPath prim_id(ID *id, const char *prefix) const;
|
||||||
pxr::SdfPath object_prim_id(Object *object) const;
|
pxr::SdfPath object_prim_id(Object *object) const;
|
||||||
|
@ -162,7 +162,7 @@ void WorldData::write_transform()
|
|||||||
transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), pxr::GfVec3d());
|
transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), pxr::GfVec3d());
|
||||||
|
|
||||||
/* TODO : do this check via RenderSettings*/
|
/* TODO : do this check via RenderSettings*/
|
||||||
if (scene_delegate_->GetRenderIndex().GetRenderDelegate()->GetRendererDisplayName() == "RPR") {
|
if (scene_delegate_->render_delegate_name == "HdRprPlugin") {
|
||||||
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180),
|
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180),
|
||||||
pxr::GfVec3d());
|
pxr::GfVec3d());
|
||||||
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0),
|
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0),
|
||||||
|
@ -225,7 +225,8 @@ void ViewportEngine::sync(Depsgraph *depsgraph,
|
|||||||
scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
|
scene_delegate_ = std::make_unique<BlenderSceneDelegate>(
|
||||||
render_index_.get(),
|
render_index_.get(),
|
||||||
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||||
BlenderSceneDelegate::EngineType::VIEWPORT);
|
BlenderSceneDelegate::EngineType::VIEWPORT,
|
||||||
|
render_delegate_name_);
|
||||||
}
|
}
|
||||||
scene_delegate_->populate(depsgraph, context);
|
scene_delegate_->populate(depsgraph, context);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user