forked from blender/blender
Fix rendering of Final render for Storm delegate #61
@ -1,6 +1,8 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0
|
||||
* Copyright 2011-2022 Blender Foundation */
|
||||
|
||||
#include <pxr/imaging/glf/drawTarget.h>
|
||||
|
||||
#include "BKE_lib_id.h"
|
||||
#include "BLI_timecode.h"
|
||||
#include "DEG_depsgraph_query.h"
|
||||
@ -16,14 +18,11 @@ namespace blender::render::hydra {
|
||||
void FinalEngine::render(Depsgraph *depsgraph)
|
||||
{
|
||||
prepare_for_render(depsgraph);
|
||||
render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color);
|
||||
|
||||
engine_->Execute(render_index_.get(), &tasks_);
|
||||
|
||||
std::vector<float> &pixels = render_images_["Combined"];
|
||||
|
||||
{
|
||||
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
|
||||
engine_->Execute(render_index_.get(), &tasks_);
|
||||
}
|
||||
|
||||
char elapsed_time[32];
|
||||
double time_begin = PIL_check_seconds_timer();
|
||||
float percent_done = 0.0;
|
||||
@ -34,10 +33,8 @@ void FinalEngine::render(Depsgraph *depsgraph)
|
||||
}
|
||||
|
||||
percent_done = renderer_percent_done();
|
||||
|
||||
BLI_timecode_string_from_time_simple(
|
||||
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
|
||||
|
||||
notify_status(percent_done / 100.0,
|
||||
scene_name_ + ": " + layer_name_,
|
||||
std::string("Render Time: ") + elapsed_time +
|
||||
@ -105,7 +102,6 @@ void FinalEngine::prepare_for_render(Depsgraph *depsgraph)
|
||||
free_camera_delegate_->SetCamera(camera);
|
||||
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());
|
||||
@ -118,13 +114,11 @@ void FinalEngine::prepare_for_render(Depsgraph *depsgraph)
|
||||
std::vector<float>(resolution_[0] * resolution_[1] * 4)); /* 4 - number of channels. */
|
||||
}
|
||||
|
||||
void FinalEngineGL::render(Depsgraph *depsgraph)
|
||||
void FinalEngineGL::render0(Depsgraph *depsgraph)
|
||||
{
|
||||
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_hydra_render_final");
|
||||
GPUTexture *texture = GPU_texture_create_2d("tex_hydra_render_final",
|
||||
resolution_[0],
|
||||
resolution_[1],
|
||||
@ -140,11 +134,9 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
||||
float clear_color[4] = {0.0, 0.0, 0.0, 0.0};
|
||||
GPU_framebuffer_clear_color_depth(framebuffer, clear_color, 1.0);
|
||||
|
||||
{
|
||||
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
|
||||
engine_->Execute(render_index_.get(), &tasks_);
|
||||
}
|
||||
engine_->Execute(render_index_.get(), &tasks_);
|
||||
|
||||
std::vector<float> &pixels = render_images_["Combined"];
|
||||
char elapsed_time[32];
|
||||
double time_begin = PIL_check_seconds_timer();
|
||||
float percent_done = 0.0;
|
||||
@ -183,4 +175,115 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
||||
GPU_texture_free(texture);
|
||||
}
|
||||
|
||||
void FinalEngineGL::render(Depsgraph *depsgraph)
|
||||
{
|
||||
prepare_for_render(depsgraph);
|
||||
|
||||
GLuint framebuffer_name = 0;
|
||||
glGenFramebuffers(1, &framebuffer_name);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_name);
|
||||
|
||||
// The texture we're going to render to
|
||||
GLuint rendered_texture;
|
||||
glGenTextures(1, &rendered_texture);
|
||||
|
||||
// "Bind" the newly created texture : all future texture functions will modify this texture
|
||||
glBindTexture(GL_TEXTURE_2D, rendered_texture);
|
||||
|
||||
// Give an empty image to OpenGL ( the last "0" )
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D, 0, GL_RGBA32F, resolution_[0], resolution_[1], 0, GL_RGBA, GL_FLOAT, 0);
|
||||
|
||||
// Poor filtering. Needed !
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
// Set "rendered_texture" as our colour attachement #0
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, rendered_texture, 0);
|
||||
|
||||
// Generate vertex array
|
||||
GLuint vao;
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
|
||||
engine_->Execute(render_index_.get(), &tasks_);
|
||||
|
||||
std::vector<float> &pixels = render_images_["Combined"];
|
||||
char elapsed_time[32];
|
||||
double time_begin = PIL_check_seconds_timer();
|
||||
float percent_done = 0.0;
|
||||
|
||||
while (true) {
|
||||
if (RE_engine_test_break(bl_engine_)) {
|
||||
break;
|
||||
}
|
||||
|
||||
percent_done = renderer_percent_done();
|
||||
|
||||
BLI_timecode_string_from_time_simple(
|
||||
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
|
||||
|
||||
notify_status(percent_done / 100.0,
|
||||
scene_name_ + ": " + layer_name_,
|
||||
std::string("Render Time: ") + elapsed_time +
|
||||
" | Done: " + std::to_string(int(percent_done)) + "%");
|
||||
|
||||
if (render_task_delegate_->is_converged()) {
|
||||
break;
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, rendered_texture);
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data());
|
||||
update_render_result();
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, rendered_texture);
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data());
|
||||
update_render_result();
|
||||
}
|
||||
|
||||
void FinalEngineGL::render1(Depsgraph *depsgraph)
|
||||
{
|
||||
prepare_for_render(depsgraph);
|
||||
|
||||
//pxr::TraceCollector::GetInstance().SetEnabled(true);
|
||||
|
||||
auto d = pxr::GlfDrawTarget::New(resolution_);
|
||||
d->Bind();
|
||||
d->AddAttachment("color", GL_RGBA, GL_FLOAT, GL_RGBA);
|
||||
engine_->Execute(render_index_.get(), &tasks_);
|
||||
//d->Unbind();
|
||||
|
||||
std::vector<float> &pixels = render_images_["Combined"];
|
||||
char elapsed_time[32];
|
||||
double time_begin = PIL_check_seconds_timer();
|
||||
float percent_done = 0.0;
|
||||
|
||||
while (true) {
|
||||
if (RE_engine_test_break(bl_engine_)) {
|
||||
break;
|
||||
}
|
||||
|
||||
percent_done = renderer_percent_done();
|
||||
|
||||
BLI_timecode_string_from_time_simple(
|
||||
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
|
||||
|
||||
notify_status(percent_done / 100.0,
|
||||
scene_name_ + ": " + layer_name_,
|
||||
std::string("Render Time: ") + elapsed_time +
|
||||
" | Done: " + std::to_string(int(percent_done)) + "%");
|
||||
|
||||
if (render_task_delegate_->is_converged()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GLuint rendered_texture;
|
||||
|
||||
//glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, pixels.data());
|
||||
//update_render_result();
|
||||
pxr::TraceCollector::GetInstance().SetEnabled(false);
|
||||
}
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -30,6 +30,8 @@ class FinalEngineGL : public FinalEngine {
|
||||
public:
|
||||
using FinalEngine::FinalEngine;
|
||||
|
||||
void render0(Depsgraph *depsgraph);
|
||||
void render1(Depsgraph *depsgraph);
|
||||
void render(Depsgraph *depsgraph) override;
|
||||
};
|
||||
|
||||
|
@ -43,7 +43,7 @@ class MeshData : public ObjectData {
|
||||
void available_materials(Set<pxr::SdfPath> &paths) const;
|
||||
pxr::SdfPathVector submesh_paths() const;
|
||||
|
||||
pxr::HdCullStyle cull_style = pxr::HdCullStyleBackUnlessDoubleSided;
|
||||
pxr::HdCullStyle cull_style = pxr::HdCullStyleBack;
|
||||
|
||||
private:
|
||||
pxr::SdfPath submesh_prim_id(int index) const;
|
||||
|
Loading…
Reference in New Issue
Block a user