Fix review comments 2 #31

Merged
Bogdan Nagirniak merged 8 commits from BLEN-397 into hydra-render 2023-04-27 09:05:38 +02:00
2 changed files with 39 additions and 63 deletions
Showing only changes of commit 7484aefea2 - Show all commits

View File

@ -31,42 +31,12 @@ void FinalEngine::sync(Depsgraph *depsgraph,
void FinalEngine::render(Depsgraph *depsgraph)
{
const Scene *scene = DEG_get_evaluated_scene(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);
std::string layer_name = view_layer->name;
const RenderData &r = scene->r;
pxr::GfVec4f border = get_resolution(scene);
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"];
prepare_for_render(depsgraph);
{
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
engine_->Execute(render_index_.get(), &tasks);
engine_->Execute(render_index_.get(), &tasks_);
}
char elapsed_time[32];
@ -84,7 +54,7 @@ void FinalEngine::render(Depsgraph *depsgraph)
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
notify_status(percent_done / 100.0,
scene_name + ": " + layer_name,
scene_name_ + ": " + layer_name_,
std::string("Render Time: ") + elapsed_time +
" | Done: " + std::to_string(int(percent_done)) + "%");
@ -92,12 +62,12 @@ void FinalEngine::render(Depsgraph *depsgraph)
break;
}
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
update_render_result(render_images, layer_name, res[0], res[1]);
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels_.data());
update_render_result(render_images_, layer_name_, resolution_[0], resolution_[1]);
}
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
update_render_result(render_images, layer_name, res[0], res[1]);
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels_.data());
update_render_result(render_images_, layer_name_, resolution_[0], resolution_[1]);
}
pxr::GfVec4f FinalEngine::get_resolution(const Scene *scene)
@ -140,46 +110,45 @@ void FinalEngine::notify_status(float progress, const std::string &title, const
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 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);
std::string layer_name = view_layer->name;
BKE_id_full_name_get(scene_name_.data(), (ID *)scene, 0);
layer_name_ = view_layer->name;
const RenderData &r = scene->r;
pxr::GfVec4f border = get_resolution(scene);
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 =
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_camera_and_viewport(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_) {
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());
render_images_.emplace(
"Combined",
std::vector<float>(resolution_[0] * resolution_[1] * 4)); /* 4 - number of channels. */
pixels_ = render_images_["Combined"];
}
pxr::HdTaskSharedPtrVector tasks;
if (simple_light_task_delegate_) {
/* TODO: Uncomment this and fix GL error:
* 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{
{"Combined", std::vector<float>(res[0] * res[1] * 4)}}; /* 4 - number of channels. */
std::vector<float> &pixels = render_images["Combined"];
void FinalEngineGL::render(Depsgraph *depsgraph)
{
prepare_for_render(depsgraph);
GPUFrameBuffer *framebuffer = GPU_framebuffer_create("fb_hdyra_render_final");
GPUTexture *texture = GPU_texture_create_2d("tex_hydra_render_final",
res[0],
res[1],
resolution_[0],
resolution_[1],
1,
GPU_RGBA32F,
GPU_TEXTURE_USAGE_GENERAL,
@ -195,7 +164,7 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
{
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
engine_->Execute(render_index_.get(), &tasks);
engine_->Execute(render_index_.get(), &tasks_);
}
char elapsed_time[32];
@ -213,7 +182,7 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
notify_status(percent_done / 100.0,
scene_name + ": " + layer_name,
scene_name_ + ": " + layer_name_,
std::string("Render Time: ") + elapsed_time +
" | Done: " + std::to_string(int(percent_done)) + "%");
@ -222,15 +191,15 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
}
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);
update_render_result(render_images, layer_name, res[0], res[1]);
update_render_result(render_images_, layer_name_, resolution_[0], resolution_[1]);
}
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);
update_render_result(render_images, layer_name, res[0], res[1]);
update_render_result(render_images_, layer_name_, resolution_[0], resolution_[1]);
GPU_framebuffer_free(framebuffer);
GPU_texture_free(texture);

View File

@ -23,8 +23,15 @@ class FinalEngine : public Engine {
int width,
int height);
void notify_status(float progress, const std::string &title, const std::string &info);
void prepare_for_render(Depsgraph *depsgraph);
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_;
std::vector<float> pixels_;
};
class FinalEngineGL : public FinalEngine {